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];
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 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 _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.
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
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