19 mWidgetScroll(nullptr),
20 mActivateOnClick(false),
28 mNeedVisibleScroll(true)
34 Base::initialiseOverride();
59 if (mWidgetScroll !=
nullptr)
71 mWidgetScroll =
nullptr;
73 Base::shutdownOverride();
80 Base::onMouseWheel(_rel);
87 Base::onKeyButtonPressed(_key, _char);
93 size_t sel = mIndexSelect;
171 Base::onKeyButtonPressed(_key, _char);
179 if (sel != mIndexSelect)
186 if (mWidgetScroll !=
nullptr)
196 Base::onKeyButtonPressed(_key, _char);
202 if (mRangeIndex <= 0)
205 if (mWidgetScroll ==
nullptr)
210 offset += mHeightLine;
212 offset -= mHeightLine;
214 if (offset >= mRangeIndex)
215 offset = mRangeIndex;
245 if (mActivateOnClick)
257 Base::setPosition(_point);
262 Base::setSize(_size);
270 Base::setCoord(_coord);
280 if (mWidgetScroll ==
nullptr)
302 if (!mItemsInfo.empty())
317 int position = mTopIndex * mHeightLine + mOffsetTop;
322 int height = (int)mWidgetLines.size() * mHeightLine - mOffsetTop;
344 mWidgetLines.push_back(line);
345 height += mHeightLine;
349 if (position >= mRangeIndex)
352 if (mRangeIndex <= 0)
355 if (position || mOffsetTop || mTopIndex)
364 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
366 mWidgetLines[pos]->setPosition(0, offset);
367 offset += mHeightLine;
377 if (mOffsetTop == mHeightLine)
383 int top = (int)mItemsInfo.size() - count - 1;
386 int offset = 0 - mOffsetTop;
387 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
389 mWidgetLines[pos]->setPosition(0, offset);
390 offset += mHeightLine;
394 position = top * mHeightLine + mOffsetTop;
397 if (top != mTopIndex)
411 if (mWidgetScroll !=
nullptr)
417 #if MYGUI_DEBUG_MODE == 1
418 _checkMapping(
"ListBox::updateLine");
426 for (; pos < mWidgetLines.size(); pos++)
429 size_t index = pos + (size_t)mTopIndex;
432 if (index >= mItemsInfo.size())
435 mLastRedrawLine = pos;
441 mLastRedrawLine = pos;
446 mWidgetLines[pos]->setVisible(
true);
448 mWidgetLines[pos]->setCaption(mItemsInfo[index].first);
451 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(index == mIndexSelect);
455 if (pos >= mWidgetLines.size())
457 mLastRedrawLine = pos;
462 for (; pos < mWidgetLines.size(); pos++)
464 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(
false);
470 #if MYGUI_DEBUG_MODE == 1
471 _checkMapping(
"ListBox::_redrawItemRange");
479 if (_index < (
size_t)mTopIndex)
481 _index -= (size_t)mTopIndex;
483 if (_index >= mLastRedrawLine)
488 mWidgetLines[_index]->setCaption(mItemsInfo[_index + mTopIndex].first);
490 #if MYGUI_DEBUG_MODE == 1
491 _checkMapping(
"ListBox::_redrawItem");
499 _index = mItemsInfo.size();
502 mItemsInfo.insert(mItemsInfo.begin() + _index, PairItem(_name, _data));
505 if ((mIndexSelect !=
ITEM_NONE) && (_index <= mIndexSelect))
509 if ((_index <= (
size_t)mTopIndex) && (mRangeIndex > 0))
513 if (mWidgetScroll !=
nullptr)
516 if (!mItemsInfo.empty())
520 mRangeIndex += mHeightLine;
525 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
531 if (mWidgetScroll !=
nullptr)
534 if (!mItemsInfo.empty())
538 mRangeIndex += mHeightLine;
552 #if MYGUI_DEBUG_MODE == 1
553 _checkMapping(
"ListBox::insertItemAt");
562 mItemsInfo.erase(mItemsInfo.begin() + _index);
565 if (mItemsInfo.empty()) mIndexSelect =
ITEM_NONE;
568 if (_index < mIndexSelect)
570 else if ((_index == mIndexSelect) && (mIndexSelect == (mItemsInfo.size())))
575 if (mWidgetLines.size() > mItemsInfo.size())
577 mWidgetLines[mItemsInfo.size()]->setVisible(
false);
581 if (_index < (
size_t)mTopIndex)
585 if (mWidgetScroll !=
nullptr)
588 if (!mItemsInfo.empty())
592 mRangeIndex -= mHeightLine;
597 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
603 if (mWidgetScroll !=
nullptr)
606 if (!mItemsInfo.empty())
610 mRangeIndex -= mHeightLine;
624 #if MYGUI_DEBUG_MODE == 1
625 _checkMapping(
"ListBox::removeItemAt");
632 if (mIndexSelect != _index)
636 mIndexSelect = _index;
645 if (_index < (
size_t)mTopIndex)
648 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
653 size_t index = _index - mTopIndex;
654 if (index < mWidgetLines.size())
657 #if MYGUI_DEBUG_MODE == 1
658 _checkMapping(
"ListBox::_selectIndex");
665 if (mRangeIndex <= 0)
668 int offset = (int)_index * mHeightLine;
669 if (offset >= mRangeIndex) offset = mRangeIndex;
671 if (mWidgetScroll !=
nullptr)
679 #if MYGUI_DEBUG_MODE == 1
680 _checkMapping(
"ListBox::beginToItemAt");
688 if (_index >= mItemsInfo.size())
691 if (mRangeIndex <= 0)
695 if (_index < (
size_t)mTopIndex)
699 if (_index == (
size_t)mTopIndex)
701 if ((mOffsetTop != 0) && (_fill))
707 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
729 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
731 mWidgetLines[pos]->setVisible(
false);
732 mWidgetLines[pos]->setPosition(0, offset);
733 offset += mHeightLine;
740 #if MYGUI_DEBUG_MODE == 1
741 _checkMapping(
"ListBox::removeAllItems");
748 mItemsInfo[_index].first = _name;
755 mItemsInfo[_index].second = _data;
762 return mItemsInfo[_index].first;
768 #if MYGUI_DEBUG_MODE == 1
788 static_cast<Button*
>(mWidgetLines[_index])->_setMouseFocus(_focus);
793 if (mNeedVisibleScroll == _visible)
795 mNeedVisibleScroll = _visible;
801 if (mWidgetScroll !=
nullptr)
813 mOffsetTop = ((int)_position % mHeightLine);
816 int offset = 0 - mOffsetTop;
818 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
820 mWidgetLines[pos]->setPosition(
IntPoint(0, offset));
821 offset += mHeightLine;
825 int top = ((int)_position / mHeightLine);
826 if (top != mTopIndex)
848 if (_index1 == _index2)
851 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
857 void ListBox::_checkMapping(
const std::string& _owner)
859 size_t count_pressed = 0;
860 size_t count_show = 0;
862 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
864 MYGUI_ASSERT(pos == *mWidgetLines[pos]->_getInternalData<size_t>(), _owner);
865 if (
static_cast<Button*
>(mWidgetLines[pos])->getStateSelected())
877 int max_height = mItemsInfo.size() * mHeightLine;
882 if (visible_height >= max_height)
887 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
889 if (pos >= mItemsInfo.size())
891 MYGUI_ASSERT(mWidgetLines[pos]->
getTop() == height,
"mWidgetLines[pos]->getTop() == height");
892 height += mWidgetLines[pos]->getHeight();
899 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
901 if (mItemsInfo[pos].first == _name)
914 return mItemsInfo.size();
962 for (VectorButton::iterator iter = mWidgetLines.begin(); iter != mWidgetLines.end(); ++iter)
964 if ((*iter) == _item)
965 return *(*iter)->_getInternalData<
size_t>() + mTopIndex;
973 Base::_resetContainer(_update);
978 for (VectorButton::iterator iter = mWidgetLines.begin(); iter != mWidgetLines.end(); ++iter)
986 if (_key ==
"AddItem")
988 else if (_key ==
"ActivateOnClick")
992 Base::setPropertyOverride(_key, _value);
1018 #if MYGUI_DEBUG_MODE == 1
1019 _checkMapping(
"ListBox::notifyMousePressed");
1026 if (mIndexSelect != index)
1030 mIndexSelect = index;
1064 size_t ListBox::getIndexByWidget(
Widget* _widget)
1088 Base::onKeyButtonReleased(_key);
1095 mActivateOnClick = activateOnClick;
1104 size_t index = _index + (size_t)mTopIndex;
1106 if (index < mWidgetLines.size())
1107 return mWidgetLines[index];