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;
167 Base::onKeyButtonPressed(_key, _char);
175 if (sel != mIndexSelect)
182 if (mWidgetScroll !=
nullptr)
192 Base::onKeyButtonPressed(_key, _char);
198 if (mRangeIndex <= 0)
201 if (mWidgetScroll ==
nullptr)
206 offset += mHeightLine;
208 offset -= mHeightLine;
210 if (offset >= mRangeIndex)
211 offset = mRangeIndex;
241 if (mActivateOnClick)
253 Base::setPosition(_point);
258 Base::setSize(_size);
266 Base::setCoord(_coord);
276 if (mWidgetScroll ==
nullptr)
298 if (!mItemsInfo.empty())
313 int position = mTopIndex * mHeightLine + mOffsetTop;
318 int height = (int)mWidgetLines.size() * mHeightLine - mOffsetTop;
340 mWidgetLines.push_back(line);
341 height += mHeightLine;
345 if (position >= mRangeIndex)
348 if (mRangeIndex <= 0)
351 if (position || mOffsetTop || mTopIndex)
360 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
362 mWidgetLines[pos]->setPosition(0, offset);
363 offset += mHeightLine;
373 if (mOffsetTop == mHeightLine)
379 int top = (int)mItemsInfo.size() - count - 1;
382 int offset = 0 - mOffsetTop;
383 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
385 mWidgetLines[pos]->setPosition(0, offset);
386 offset += mHeightLine;
390 position = top * mHeightLine + mOffsetTop;
393 if (top != mTopIndex)
407 if (mWidgetScroll !=
nullptr)
413#if MYGUI_DEBUG_MODE == 1
414 _checkMapping(
"ListBox::updateLine");
422 for (; pos < mWidgetLines.size(); pos++)
425 size_t index = pos + (size_t)mTopIndex;
428 if (index >= mItemsInfo.size())
431 mLastRedrawLine = pos;
437 mLastRedrawLine = pos;
442 mWidgetLines[pos]->setVisible(
true);
444 mWidgetLines[pos]->setCaption(mItemsInfo[index].first);
447 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(index == mIndexSelect);
451 if (pos >= mWidgetLines.size())
453 mLastRedrawLine = pos;
458 for (; pos < mWidgetLines.size(); pos++)
460 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(
false);
466#if MYGUI_DEBUG_MODE == 1
467 _checkMapping(
"ListBox::_redrawItemRange");
475 if (_index < (
size_t)mTopIndex)
477 _index -= (size_t)mTopIndex;
479 if (_index >= mLastRedrawLine)
484 mWidgetLines[_index]->setCaption(mItemsInfo[_index + mTopIndex].first);
486#if MYGUI_DEBUG_MODE == 1
487 _checkMapping(
"ListBox::_redrawItem");
495 _index = mItemsInfo.size();
498 mItemsInfo.insert(mItemsInfo.begin() + _index, PairItem(_name, _data));
501 if ((mIndexSelect !=
ITEM_NONE) && (_index <= mIndexSelect))
505 if ((_index <= (
size_t)mTopIndex) && (mRangeIndex > 0))
509 if (mWidgetScroll !=
nullptr)
512 if (!mItemsInfo.empty())
516 mRangeIndex += mHeightLine;
521 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
527 if (mWidgetScroll !=
nullptr)
530 if (!mItemsInfo.empty())
534 mRangeIndex += mHeightLine;
548#if MYGUI_DEBUG_MODE == 1
549 _checkMapping(
"ListBox::insertItemAt");
558 mItemsInfo.erase(mItemsInfo.begin() + _index);
561 if (mItemsInfo.empty()) mIndexSelect =
ITEM_NONE;
564 if (_index < mIndexSelect)
566 else if ((_index == mIndexSelect) && (mIndexSelect == (mItemsInfo.size())))
571 if (mWidgetLines.size() > mItemsInfo.size())
573 mWidgetLines[mItemsInfo.size()]->setVisible(
false);
577 if (_index < (
size_t)mTopIndex)
581 if (mWidgetScroll !=
nullptr)
584 if (!mItemsInfo.empty())
588 mRangeIndex -= mHeightLine;
593 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
599 if (mWidgetScroll !=
nullptr)
602 if (!mItemsInfo.empty())
606 mRangeIndex -= mHeightLine;
620#if MYGUI_DEBUG_MODE == 1
621 _checkMapping(
"ListBox::removeItemAt");
628 if (mIndexSelect != _index)
632 mIndexSelect = _index;
641 if (_index < (
size_t)mTopIndex)
644 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
649 size_t index = _index - mTopIndex;
650 if (index < mWidgetLines.size())
653#if MYGUI_DEBUG_MODE == 1
654 _checkMapping(
"ListBox::_selectIndex");
661 if (mRangeIndex <= 0)
664 int offset = (int)_index * mHeightLine;
665 if (offset >= mRangeIndex) offset = mRangeIndex;
667 if (mWidgetScroll !=
nullptr)
675#if MYGUI_DEBUG_MODE == 1
676 _checkMapping(
"ListBox::beginToItemAt");
684 if (_index >= mItemsInfo.size())
687 if (mRangeIndex <= 0)
691 if (_index < (
size_t)mTopIndex)
695 if (_index == (
size_t)mTopIndex)
697 if ((mOffsetTop != 0) && (_fill))
703 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
725 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
727 mWidgetLines[pos]->setVisible(
false);
728 mWidgetLines[pos]->setPosition(0, offset);
729 offset += mHeightLine;
736#if MYGUI_DEBUG_MODE == 1
737 _checkMapping(
"ListBox::removeAllItems");
744 mItemsInfo[_index].first = _name;
751 mItemsInfo[_index].second = _data;
758 return mItemsInfo[_index].first;
764#if MYGUI_DEBUG_MODE == 1
784 static_cast<Button*
>(mWidgetLines[_index])->_setMouseFocus(_focus);
789 if (mNeedVisibleScroll == _visible)
791 mNeedVisibleScroll = _visible;
797 if (mWidgetScroll !=
nullptr)
809 mOffsetTop = ((int)_position % mHeightLine);
812 int offset = 0 - mOffsetTop;
814 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
816 mWidgetLines[pos]->setPosition(
IntPoint(0, offset));
817 offset += mHeightLine;
821 int top = ((int)_position / mHeightLine);
822 if (top != mTopIndex)
844 if (_index1 == _index2)
847 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
853 void ListBox::_checkMapping(
const std::string& _owner)
855 size_t count_pressed = 0;
856 size_t count_show = 0;
858 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
860 MYGUI_ASSERT(pos == *mWidgetLines[pos]->_getInternalData<size_t>(), _owner);
861 if (
static_cast<Button*
>(mWidgetLines[pos])->getStateSelected())
873 int max_height = mItemsInfo.size() * mHeightLine;
878 if (visible_height >= max_height)
883 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
885 if (pos >= mItemsInfo.size())
887 MYGUI_ASSERT(mWidgetLines[pos]->
getTop() == height,
"mWidgetLines[pos]->getTop() == height");
888 height += mWidgetLines[pos]->getHeight();
895 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
897 if (mItemsInfo[pos].first == _name)
910 return mItemsInfo.size();
958 for (
const auto& line : mWidgetLines)
961 return *line->_getInternalData<
size_t>() + mTopIndex;
969 Base::_resetContainer(_update);
974 for (
const auto& line : mWidgetLines)
982 if (_key ==
"AddItem")
984 else if (_key ==
"ActivateOnClick")
988 Base::setPropertyOverride(_key, _value);
1014#if MYGUI_DEBUG_MODE == 1
1015 _checkMapping(
"ListBox::notifyMousePressed");
1022 if (mIndexSelect != index)
1026 mIndexSelect = index;
1060 size_t ListBox::getIndexByWidget(
Widget* _widget)
const
1084 Base::onKeyButtonReleased(_key);
1091 mActivateOnClick = activateOnClick;
1100 size_t index = _index - (size_t)mTopIndex;
1102 if (index < mWidgetLines.size())
1103 return mWidgetLines[index];
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_ASSERT_RANGE_AND_NONE(index, size, owner)
Type * castType(bool _throw=true)
void _setItemNameAt(size_t _index, const UString &_name) override
void addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
void notifyMouseWheel(Widget *_sender, int _rel)
void _removeItemAt(size_t _index) override
void updateLine(bool _reset=false)
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem
void beginToItemAt(size_t _index)
Move all elements so specified becomes visible.
void _redrawItem(size_t _index)
size_t _getItemIndex(Widget *_item) const override
void _setScrollView(size_t _position)
void notifyKeyButtonReleased(Widget *_sender, KeyCode _key)
void notifyMousePressed(Widget *_sender, int _left, int _top, MouseButton _id)
void _sendEventChangeScroll(size_t _position)
void setPosition(const IntPoint &_value) override
void setScrollPosition(size_t _position)
Set scroll position.
void notifyMouseButtonReleased(Widget *_sender, int _left, int _top, MouseButton _id)
bool isItemSelectedVisible(bool _fill=true)
Same as ListBox::isItemVisibleAt for selected item.
void _resetContainer(bool _update) override
const UString & _getItemNameAt(size_t _index) const override
bool isItemVisibleAt(size_t _index, bool _fill=true)
const UString & getItemNameAt(size_t _index) const
Get item name from specified position.
void notifyMouseClick(Widget *_sender)
void setActivateOnClick(bool activateOnClick)
void setPropertyOverride(const std::string &_key, const std::string &_value) override
void clearIndexSelected()
void _addItem(const MyGUI::UString &_name) override
void setScrollVisible(bool _visible)
Set scroll visible when it needed.
void _activateItem(Widget *_sender)
void setSize(const IntSize &_value) override
void _redrawItemRange(size_t _start=0)
void notifyMouseLostFocus(Widget *_sender, Widget *_new)
void shutdownOverride() override
size_t getItemCount() const
Get number of items.
void notifyScrollChangePosition(ScrollBar *_sender, size_t _rel)
void initialiseOverride() override
void notifyMouseSetFocus(Widget *_sender, Widget *_old)
void swapItemsAt(size_t _index1, size_t _index2)
Swap items at a specified positions.
int getOptimalHeight() const
Return optimal height to fit all items in ListBox.
void onKeyButtonReleased(KeyCode _key) override
void insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
void removeAllItems()
Remove all items.
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangePosition
void onMouseWheel(int _rel) override
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
size_t getIndexSelected() const
void _selectIndex(size_t _index, bool _select)
size_t _getItemCount() const override
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemFocus
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
void beginToItemFirst()
Move all elements so first becomes visible.
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangeScroll
void notifyKeyButtonPressed(Widget *_sender, KeyCode _key, Char _char)
void onKeyButtonPressed(KeyCode _key, Char _char) override
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
void notifyMouseDoubleClick(Widget *_sender)
Widget * getWidgetByIndex(size_t _index)
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListSelectAccept
void beginToItemSelected()
Move all elements so selected becomes visible.
void removeItemAt(size_t _index)
Remove item at a specified position.
void setItemNameAt(size_t _index, const UString &_name)
Replace an item name at a specified position.
void setIndexSelected(size_t _index)
void _setItemFocus(size_t _position, bool _focus)
void beginToItemLast()
Move all elements so last becomes visible.
void setCoord(const IntCoord &_value) override
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemActivate
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
bool isUserString(const std::string &_key) const
void _setInternalData(Any _data)
const std::string & getUserString(const std::string &_key) const
ValueType * _getInternalData(bool _throw=true) const
int parseInt(const std::string &_value)
bool parseBool(const std::string &_value)
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
types::TPoint< int > IntPoint