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);
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];
void notifyMouseWheel(Widget *_sender, int _rel)
virtual void _addItem(const MyGUI::UString &_name)
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
int parseInt(const std::string &_value)
types::TSize< int > IntSize
void notifyMouseClick(Widget *_sender)
void notifyKeyButtonPressed(Widget *_sender, KeyCode _key, Char _char)
bool isItemVisibleAt(size_t _index, bool _fill=true)
virtual void shutdownOverride()
void clearIndexSelected()
delegates::IDelegate0 * newDelegate(void(*_func)())
static WidgetManager & getInstance()
size_t getItemCount() const
Get number of items.
void setScrollVisible(bool _visible)
Set scroll visible when it needed.
virtual size_t _getItemCount()
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemFocus
void setItemNameAt(size_t _index, const UString &_name)
Replace an item name at a specified position.
virtual const UString & _getItemNameAt(size_t _index)
void _activateItem(Widget *_sender)
void _redrawItem(size_t _index)
void notifyMouseSetFocus(Widget *_sender, Widget *_old)
virtual void _resetContainer(bool _update)
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangePosition
void onKeyButtonReleased(KeyCode _key)
virtual void setPropertyOverride(const std::string &_key, const std::string &_value)
types::TCoord< int > IntCoord
void _sendEventChangeScroll(size_t _position)
void _selectIndex(size_t _index, bool _select)
void swapItemsAt(size_t _index1, size_t _index2)
Swap items at a specified positions.
void setActivateOnClick(bool activateOnClick)
virtual void setCoord(const IntCoord &_value)
void updateLine(bool _reset=false)
void insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
void notifyMouseButtonReleased(Widget *_sender, int _left, int _top, MouseButton _id)
void _setInternalData(Any _data)
#define MYGUI_ASSERT_RANGE_AND_NONE(index, size, owner)
void notifyMouseLostFocus(Widget *_sender, Widget *_new)
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemActivate
const UString & getItemNameAt(size_t _index)
Get item name from specified position.
void notifyKeyButtonReleased(Widget *_sender, KeyCode _key)
void removeItemAt(size_t _index)
Remove item at a specified position.
virtual void _setItemNameAt(size_t _index, const UString &_name)
#define MYGUI_ASSERT(exp, dest)
void beginToItemLast()
Move all elements so last becomes visible.
virtual size_t _getItemIndex(Widget *_item)
Type * castType(bool _throw=true)
void _setItemFocus(size_t _position, bool _focus)
virtual void setPosition(const IntPoint &_value)
void onKeyButtonPressed(KeyCode _key, Char _char)
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem
bool parseBool(const std::string &_value)
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found...
bool isUserString(const std::string &_key) const
#define MYGUI_ASSERT_RANGE(index, size, owner)
int getOptimalHeight()
Return optimal height to fit all items in ListBox.
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
void beginToItemFirst()
Move all elements so first becomes visible.
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListSelectAccept
Widget * getWidgetByIndex(size_t _index)
void _redrawItemRange(size_t _start=0)
void notifyMouseDoubleClick(Widget *_sender)
virtual void setSize(const IntSize &_value)
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
void beginToItemSelected()
Move all elements so selected becomes visible.
void notifyMousePressed(Widget *_sender, int _left, int _top, MouseButton _id)
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangeScroll
virtual void _removeItemAt(size_t _index)
size_t getIndexSelected() const
void setIndexSelected(size_t _index)
void beginToItemAt(size_t _index)
Move all elements so specified becomes visible.
bool isItemSelectedVisible(bool _fill=true)
Same as ListBox::isItemVisibleAt for selected item.
void addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
virtual void initialiseOverride()
void removeAllItems()
Remove all items.
ValueType * _getInternalData(bool _throw=true) const
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
void notifyScrollChangePosition(ScrollBar *_sender, size_t _rel)
void setScrollPosition(size_t _position)
Set scroll position.
const std::string & getUserString(const std::string &_key) const
void _setScrollView(size_t _position)
void onMouseWheel(int _rel)
types::TPoint< int > IntPoint