20 mActivateOnClick(false),
28 mNeedVisibleScroll(true),
35 Base::initialiseOverride();
52 if (mClient !=
nullptr)
63 if (mWidgetScroll !=
nullptr)
76 mWidgetScroll =
nullptr;
79 Base::shutdownOverride();
86 Base::onMouseWheel(_rel);
93 Base::onKeyButtonPressed(_key, _char);
99 size_t sel = mIndexSelect;
146 size_t page = _getClientWidget()->
getHeight() / mHeightLine;
164 sel += _getClientWidget()->
getHeight() / mHeightLine;
177 Base::onKeyButtonPressed(_key, _char);
185 if (sel != mIndexSelect)
192 if (mWidgetScroll !=
nullptr)
202 Base::onKeyButtonPressed(_key, _char);
208 if (mRangeIndex <= 0)
211 if (mWidgetScroll ==
nullptr)
216 offset += mHeightLine;
218 offset -= mHeightLine;
220 if (offset >= mRangeIndex)
221 offset = mRangeIndex;
251 if (mActivateOnClick)
263 Base::setPosition(_point);
268 Base::setSize(_size);
276 Base::setCoord(_coord);
284 mRangeIndex = (mHeightLine * (int)mItemsInfo.size()) - _getClientWidget()->
getHeight();
286 if (mWidgetScroll ==
nullptr)
289 if ((!mNeedVisibleScroll) || (mRangeIndex < 1) || (mWidgetScroll->
getLeft() <= _getClientWidget()->
getLeft()))
295 if (mClient !=
nullptr)
301 if (mClient !=
nullptr)
307 if (!mItemsInfo.empty())
322 int position = mTopIndex * mHeightLine + mOffsetTop;
327 int height = (int)mWidgetLines.size() * mHeightLine - mOffsetTop;
330 while ( (height <= (_getClientWidget()->
getHeight() + mHeightLine)) && (mWidgetLines.size() < mItemsInfo.size()) )
349 mWidgetLines.push_back(line);
350 height += mHeightLine;
354 if (position >= mRangeIndex)
357 if (mRangeIndex <= 0)
360 if (position || mOffsetTop || mTopIndex)
369 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
371 mWidgetLines[pos]->setPosition(0, offset);
372 offset += mHeightLine;
379 int count = _getClientWidget()->
getHeight() / mHeightLine;
380 mOffsetTop = mHeightLine - (_getClientWidget()->
getHeight() % mHeightLine);
382 if (mOffsetTop == mHeightLine)
388 int top = (int)mItemsInfo.size() - count - 1;
391 int offset = 0 - mOffsetTop;
392 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
394 mWidgetLines[pos]->setPosition(0, offset);
395 offset += mHeightLine;
399 position = top * mHeightLine + mOffsetTop;
402 if (top != mTopIndex)
416 if (mWidgetScroll !=
nullptr)
422 #if MYGUI_DEBUG_MODE == 1
423 _checkMapping(
"ListBox::updateLine");
431 for (; pos < mWidgetLines.size(); pos++)
434 size_t index = pos + (size_t)mTopIndex;
437 if (index >= mItemsInfo.size())
440 mLastRedrawLine = pos;
446 mLastRedrawLine = pos;
451 mWidgetLines[pos]->setVisible(
true);
453 mWidgetLines[pos]->setCaption(mItemsInfo[index].first);
456 static_cast<Button*>(mWidgetLines[pos])->setStateSelected(index == mIndexSelect);
460 if (pos >= mWidgetLines.size())
462 mLastRedrawLine = pos;
467 for (; pos < mWidgetLines.size(); pos++)
469 static_cast<Button*>(mWidgetLines[pos])->setStateSelected(
false);
470 static_cast<Button*>(mWidgetLines[pos])->setVisible(
false);
475 #if MYGUI_DEBUG_MODE == 1
476 _checkMapping(
"ListBox::_redrawItemRange");
484 if (_index < (
size_t)mTopIndex)
486 _index -= (size_t)mTopIndex;
488 if (_index >= mLastRedrawLine)
493 mWidgetLines[_index]->setCaption(mItemsInfo[_index + mTopIndex].first);
495 #if MYGUI_DEBUG_MODE == 1
496 _checkMapping(
"ListBox::_redrawItem");
504 _index = mItemsInfo.size();
507 mItemsInfo.insert(mItemsInfo.begin() + _index, PairItem(_name, _data));
510 if ((mIndexSelect !=
ITEM_NONE) && (_index <= mIndexSelect))
514 if ((_index <= (
size_t)mTopIndex) && (mRangeIndex > 0))
518 if (mWidgetScroll !=
nullptr)
521 if (!mItemsInfo.empty())
525 mRangeIndex += mHeightLine;
530 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
533 if (_getClientWidget()->
getHeight() < (offset - mHeightLine))
536 if (mWidgetScroll !=
nullptr)
539 if (!mItemsInfo.empty())
543 mRangeIndex += mHeightLine;
557 #if MYGUI_DEBUG_MODE == 1
558 _checkMapping(
"ListBox::insertItemAt");
567 mItemsInfo.erase(mItemsInfo.begin() + _index);
570 if (mItemsInfo.empty()) mIndexSelect =
ITEM_NONE;
573 if (_index < mIndexSelect)
575 else if ((_index == mIndexSelect) && (mIndexSelect == (mItemsInfo.size())))
580 if (mWidgetLines.size() > mItemsInfo.size())
582 mWidgetLines[mItemsInfo.size()]->setVisible(
false);
586 if (_index < (
size_t)mTopIndex)
590 if (mWidgetScroll !=
nullptr)
593 if (!mItemsInfo.empty())
597 mRangeIndex -= mHeightLine;
602 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
605 if (_getClientWidget()->
getHeight() < offset)
608 if (mWidgetScroll !=
nullptr)
611 if (!mItemsInfo.empty())
615 mRangeIndex -= mHeightLine;
629 #if MYGUI_DEBUG_MODE == 1
630 _checkMapping(
"ListBox::removeItemAt");
637 if (mIndexSelect != _index)
641 mIndexSelect = _index;
650 if (_index < (
size_t)mTopIndex)
653 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
655 if (_getClientWidget()->
getHeight() < offset)
658 size_t index = _index - mTopIndex;
659 if (index < mWidgetLines.size())
660 static_cast<Button*>(mWidgetLines[index])->setStateSelected(_select);
662 #if MYGUI_DEBUG_MODE == 1
663 _checkMapping(
"ListBox::_selectIndex");
670 if (mRangeIndex <= 0)
673 int offset = (int)_index * mHeightLine;
674 if (offset >= mRangeIndex) offset = mRangeIndex;
676 if (mWidgetScroll !=
nullptr)
684 #if MYGUI_DEBUG_MODE == 1
685 _checkMapping(
"ListBox::beginToItemAt");
693 if (_index >= mItemsInfo.size())
696 if (mRangeIndex <= 0)
700 if (_index < (
size_t)mTopIndex)
704 if (_index == (
size_t)mTopIndex)
706 if ((mOffsetTop != 0) && (_fill))
712 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
715 if (_getClientWidget()->
getHeight() < offset)
719 if ((_getClientWidget()->
getHeight() < (offset + mHeightLine)) && (_fill))
734 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
736 mWidgetLines[pos]->setVisible(
false);
737 mWidgetLines[pos]->setPosition(0, offset);
738 offset += mHeightLine;
745 #if MYGUI_DEBUG_MODE == 1
746 _checkMapping(
"ListBox::removeAllItems");
753 mItemsInfo[_index].first = _name;
760 mItemsInfo[_index].second = _data;
767 return mItemsInfo[_index].first;
773 #if MYGUI_DEBUG_MODE == 1
783 if ((
nullptr == _new) || (_new->
getParent() != _getClientWidget()))
793 static_cast<Button*>(mWidgetLines[_index])->_setMouseFocus(_focus);
798 if (mNeedVisibleScroll == _visible)
800 mNeedVisibleScroll = _visible;
806 if (mWidgetScroll !=
nullptr)
818 mOffsetTop = ((int)_position % mHeightLine);
821 int offset = 0 - mOffsetTop;
823 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
825 mWidgetLines[pos]->setPosition(
IntPoint(0, offset));
826 offset += mHeightLine;
830 int top = ((int)_position / mHeightLine);
831 if (top != mTopIndex)
853 if (_index1 == _index2)
856 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
862 void ListBox::_checkMapping(
const std::string& _owner)
864 size_t count_pressed = 0;
865 size_t count_show = 0;
867 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
869 MYGUI_ASSERT(pos == *mWidgetLines[pos]->_getInternalData<size_t>(), _owner);
870 if (static_cast<Button*>(mWidgetLines[pos])->getStateSelected())
872 if (static_cast<Button*>(mWidgetLines[pos])->
getVisible())
882 int max_height = mItemsInfo.size() * mHeightLine;
884 int visible_height = _getClientWidget()->
getHeight();
887 if (visible_height >= max_height)
892 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
894 if (pos >= mItemsInfo.size())
896 MYGUI_ASSERT(mWidgetLines[pos]->
getTop() == height,
"mWidgetLines[pos]->getTop() == height");
897 height += mWidgetLines[pos]->getHeight();
904 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
906 if (mItemsInfo[pos].first == _name)
917 Widget* ListBox::_getClientWidget()
919 return mClient ==
nullptr ? this : mClient;
924 return mItemsInfo.size();
987 for (VectorButton::iterator iter = mWidgetLines.begin(); iter != mWidgetLines.end(); ++iter)
989 if ((*iter) == _item)
990 return *(*iter)->_getInternalData<
size_t>() + mTopIndex;
998 Base::_resetContainer(_update);
1003 for (VectorButton::iterator iter = mWidgetLines.begin(); iter != mWidgetLines.end(); ++iter)
1011 if (_key ==
"AddItem")
1013 else if (_key ==
"ActivateOnClick")
1017 Base::setPropertyOverride(_key, _value);
1027 if (_sender == _getClientWidget())
1043 #if MYGUI_DEBUG_MODE == 1
1044 _checkMapping(
"ListBox::notifyMousePressed");
1051 if (mIndexSelect != index)
1055 mIndexSelect = index;
1089 size_t ListBox::getIndexByWidget(
Widget* _widget)
1091 if (_widget == mClient)
1113 Base::onKeyButtonReleased(_key);
1120 mActivateOnClick = activateOnClick;
1129 size_t index = _index + (size_t)mTopIndex;
1131 if (index < mWidgetLines.size())
1132 return mWidgetLines[index];