27 mNeedVisibleScroll(true),
34 Base::initialiseOverride();
51 if (mClient !=
nullptr)
62 if (mWidgetScroll !=
nullptr)
75 mWidgetScroll =
nullptr;
78 Base::shutdownOverride();
85 Base::onMouseWheel(_rel);
92 Base::onKeyButtonPressed(_key, _char);
98 size_t sel = mIndexSelect;
145 size_t page = _getClientWidget()->
getHeight() / mHeightLine;
163 sel += _getClientWidget()->
getHeight() / mHeightLine;
176 Base::onKeyButtonPressed(_key, _char);
184 if (sel != mIndexSelect)
191 if (mWidgetScroll !=
nullptr)
201 Base::onKeyButtonPressed(_key, _char);
207 if (mRangeIndex <= 0)
210 if (mWidgetScroll ==
nullptr)
215 offset += mHeightLine;
217 offset -= mHeightLine;
219 if (offset >= mRangeIndex)
220 offset = mRangeIndex;
245 if (_sender == _getClientWidget())
261 #if MYGUI_DEBUG_MODE == 1
262 _checkMapping(
"ListBox::notifyMousePressed");
269 if (mIndexSelect != index)
273 mIndexSelect = index;
293 Base::setPosition(_point);
298 Base::setSize(_size);
306 Base::setCoord(_coord);
314 mRangeIndex = (mHeightLine * (int)mItemsInfo.size()) - _getClientWidget()->
getHeight();
316 if (mWidgetScroll ==
nullptr)
319 if ((!mNeedVisibleScroll) || (mRangeIndex < 1) || (mWidgetScroll->
getLeft() <= _getClientWidget()->
getLeft()))
325 if (mClient !=
nullptr)
331 if (mClient !=
nullptr)
337 if (!mItemsInfo.empty())
352 int position = mTopIndex * mHeightLine + mOffsetTop;
357 int height = (int)mWidgetLines.size() * mHeightLine - mOffsetTop;
360 while ( (height <= (_getClientWidget()->
getHeight() + mHeightLine)) && (mWidgetLines.size() < mItemsInfo.size()) )
378 mWidgetLines.push_back(line);
379 height += mHeightLine;
383 if (position >= mRangeIndex)
386 if (mRangeIndex <= 0)
389 if (position || mOffsetTop || mTopIndex)
398 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
400 mWidgetLines[pos]->setPosition(0, offset);
401 offset += mHeightLine;
408 int count = _getClientWidget()->
getHeight() / mHeightLine;
409 mOffsetTop = mHeightLine - (_getClientWidget()->
getHeight() % mHeightLine);
411 if (mOffsetTop == mHeightLine)
417 int top = (int)mItemsInfo.size() - count - 1;
420 int offset = 0 - mOffsetTop;
421 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
423 mWidgetLines[pos]->setPosition(0, offset);
424 offset += mHeightLine;
428 position = top * mHeightLine + mOffsetTop;
431 if (top != mTopIndex)
445 if (mWidgetScroll !=
nullptr)
451 #if MYGUI_DEBUG_MODE == 1
452 _checkMapping(
"ListBox::updateLine");
460 for (; pos < mWidgetLines.size(); pos++)
463 size_t index = pos + (size_t)mTopIndex;
466 if (index >= mItemsInfo.size())
469 mLastRedrawLine = pos;
475 mLastRedrawLine = pos;
480 mWidgetLines[pos]->setVisible(
true);
482 mWidgetLines[pos]->setCaption(mItemsInfo[index].first);
485 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(index == mIndexSelect);
489 if (pos >= mWidgetLines.size())
491 mLastRedrawLine = pos;
496 for (; pos < mWidgetLines.size(); pos++)
498 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(
false);
504 #if MYGUI_DEBUG_MODE == 1
505 _checkMapping(
"ListBox::_redrawItemRange");
513 if (_index < (
size_t)mTopIndex)
515 _index -= (size_t)mTopIndex;
517 if (_index >= mLastRedrawLine)
522 mWidgetLines[_index]->setCaption(mItemsInfo[_index + mTopIndex].first);
524 #if MYGUI_DEBUG_MODE == 1
525 _checkMapping(
"ListBox::_redrawItem");
533 _index = mItemsInfo.size();
536 mItemsInfo.insert(mItemsInfo.begin() + _index, PairItem(_name, _data));
539 if ((mIndexSelect !=
ITEM_NONE) && (_index <= mIndexSelect))
543 if ((_index <= (
size_t)mTopIndex) && (mRangeIndex > 0))
547 if (mWidgetScroll !=
nullptr)
550 if (!mItemsInfo.empty())
554 mRangeIndex += mHeightLine;
559 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
562 if (_getClientWidget()->
getHeight() < (offset - mHeightLine))
565 if (mWidgetScroll !=
nullptr)
568 if (!mItemsInfo.empty())
572 mRangeIndex += mHeightLine;
586 #if MYGUI_DEBUG_MODE == 1
587 _checkMapping(
"ListBox::insertItemAt");
596 mItemsInfo.erase(mItemsInfo.begin() + _index);
599 if (mItemsInfo.empty()) mIndexSelect =
ITEM_NONE;
602 if (_index < mIndexSelect)
604 else if ((_index == mIndexSelect) && (mIndexSelect == (mItemsInfo.size())))
609 if (mWidgetLines.size() > mItemsInfo.size())
611 mWidgetLines[mItemsInfo.size()]->setVisible(
false);
615 if (_index < (
size_t)mTopIndex)
619 if (mWidgetScroll !=
nullptr)
622 if (!mItemsInfo.empty())
626 mRangeIndex -= mHeightLine;
631 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
634 if (_getClientWidget()->
getHeight() < offset)
637 if (mWidgetScroll !=
nullptr)
640 if (!mItemsInfo.empty())
644 mRangeIndex -= mHeightLine;
658 #if MYGUI_DEBUG_MODE == 1
659 _checkMapping(
"ListBox::removeItemAt");
666 if (mIndexSelect != _index)
670 mIndexSelect = _index;
679 if (_index < (
size_t)mTopIndex)
682 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
684 if (_getClientWidget()->
getHeight() < offset)
687 size_t index = _index - mTopIndex;
688 if (index < mWidgetLines.size())
689 static_cast<Button*>(mWidgetLines[index])->setStateSelected(_select);
691 #if MYGUI_DEBUG_MODE == 1
692 _checkMapping(
"ListBox::_selectIndex");
699 if (mRangeIndex <= 0)
702 int offset = (int)_index * mHeightLine;
703 if (offset >= mRangeIndex) offset = mRangeIndex;
705 if (mWidgetScroll !=
nullptr)
713 #if MYGUI_DEBUG_MODE == 1
714 _checkMapping(
"ListBox::beginToItemAt");
722 if (_index >= mItemsInfo.size())
725 if (mRangeIndex <= 0)
729 if (_index < (
size_t)mTopIndex)
733 if (_index == (
size_t)mTopIndex)
735 if ((mOffsetTop != 0) && (_fill))
741 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
744 if (_getClientWidget()->
getHeight() < offset)
748 if ((_getClientWidget()->
getHeight() < (offset + mHeightLine)) && (_fill))
763 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
765 mWidgetLines[pos]->setVisible(
false);
766 mWidgetLines[pos]->setPosition(0, offset);
767 offset += mHeightLine;
774 #if MYGUI_DEBUG_MODE == 1
775 _checkMapping(
"ListBox::removeAllItems");
782 mItemsInfo[_index].first = _name;
789 mItemsInfo[_index].second = _data;
796 return mItemsInfo[_index].first;
802 #if MYGUI_DEBUG_MODE == 1
812 if ((
nullptr == _new) || (_new->
getParent() != _getClientWidget()))
822 static_cast<Button*
>(mWidgetLines[_index])->_setMouseFocus(_focus);
827 if (mNeedVisibleScroll == _visible)
829 mNeedVisibleScroll = _visible;
835 if (mWidgetScroll !=
nullptr)
847 mOffsetTop = ((int)_position % mHeightLine);
850 int offset = 0 - mOffsetTop;
852 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
854 mWidgetLines[pos]->setPosition(
IntPoint(0, offset));
855 offset += mHeightLine;
859 int top = ((int)_position / mHeightLine);
860 if (top != mTopIndex)
882 if (_index1 == _index2)
885 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
891 void ListBox::_checkMapping(
const std::string& _owner)
893 size_t count_pressed = 0;
894 size_t count_show = 0;
896 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
898 MYGUI_ASSERT(pos == *mWidgetLines[pos]->_getInternalData<size_t>(), _owner);
899 if (static_cast<Button*>(mWidgetLines[pos])->getStateSelected())
901 if (static_cast<Button*>(mWidgetLines[pos])->
getVisible())
911 int max_height = mItemsInfo.size() * mHeightLine;
913 int visible_height = _getClientWidget()->
getHeight();
916 if (visible_height >= max_height)
921 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
923 if (pos >= mItemsInfo.size())
925 MYGUI_ASSERT(mWidgetLines[pos]->
getTop() == height,
"mWidgetLines[pos]->getTop() == height");
926 height += mWidgetLines[pos]->getHeight();
933 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
935 if (mItemsInfo[pos].first == _name)
946 Widget* ListBox::_getClientWidget()
948 return mClient ==
nullptr ?
this : mClient;
953 return mItemsInfo.size();
1016 for (VectorButton::iterator iter = mWidgetLines.begin(); iter != mWidgetLines.end(); ++iter)
1018 if ((*iter) == _item)
1019 return *(*iter)->_getInternalData<
size_t>() + mTopIndex;
1027 Base::_resetContainer(_update);
1032 for (VectorButton::iterator iter = mWidgetLines.begin(); iter != mWidgetLines.end(); ++iter)
1040 if (_key ==
"AddItem")
1045 Base::setPropertyOverride(_key, _value);
1077 size_t ListBox::getIndexByWidget(
Widget* _widget)
1079 if (_widget == mClient)
1101 Base::onKeyButtonReleased(_key);
1112 size_t index = _index + (size_t)mTopIndex;
1114 if (index < mWidgetLines.size())
1115 return mWidgetLines[index];