42 mNeedVisibleScroll(true),
49 Base::initialiseOverride();
65 if (mClient !=
nullptr)
72 if (mWidgetScroll !=
nullptr)
86 mWidgetScroll =
nullptr;
89 Base::shutdownOverride();
96 Base::onMouseWheel(_rel);
103 Base::onKeyButtonPressed(_key, _char);
108 size_t sel = mIndexSelect;
155 size_t page = _getClientWidget()->
getHeight() / mHeightLine;
173 sel += _getClientWidget()->
getHeight() / mHeightLine;
186 Base::onKeyButtonPressed(_key, _char);
192 if (sel != mIndexSelect)
199 if (mWidgetScroll !=
nullptr)
209 Base::onKeyButtonPressed(_key, _char);
214 if (mRangeIndex <= 0)
217 if (mWidgetScroll ==
nullptr)
222 offset += mHeightLine;
224 offset -= mHeightLine;
226 if (offset >= mRangeIndex)
227 offset = mRangeIndex;
252 if (_sender == mWidgetScroll)
256 if (_sender == _getClientWidget())
272 #if MYGUI_DEBUG_MODE == 1
273 _checkMapping(
"ListBox::notifyMousePressed");
280 if (mIndexSelect != index)
284 mIndexSelect = index;
301 Base::setPosition(_point);
306 Base::setSize(_size);
314 Base::setCoord(_coord);
322 mRangeIndex = (mHeightLine * (int)mItemsInfo.size()) - _getClientWidget()->
getHeight();
324 if (mWidgetScroll ==
nullptr)
327 if ((!mNeedVisibleScroll) || (mRangeIndex < 1) || (mWidgetScroll->
getLeft() <= _getClientWidget()->
getLeft()))
333 if (mClient !=
nullptr)
339 if (mClient !=
nullptr)
345 if (!mItemsInfo.empty())
360 int position = mTopIndex * mHeightLine + mOffsetTop;
365 int height = (int)mWidgetLines.size() * mHeightLine - mOffsetTop;
368 while ( (height <= (_getClientWidget()->
getHeight() + mHeightLine)) && (mWidgetLines.size() < mItemsInfo.size()) )
383 mWidgetLines.push_back(line);
384 height += mHeightLine;
388 if (position >= mRangeIndex)
391 if (mRangeIndex <= 0)
394 if (position || mOffsetTop || mTopIndex)
403 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
405 mWidgetLines[pos]->setPosition(0, offset);
406 offset += mHeightLine;
413 int count = _getClientWidget()->
getHeight() / mHeightLine;
414 mOffsetTop = mHeightLine - (_getClientWidget()->
getHeight() % mHeightLine);
416 if (mOffsetTop == mHeightLine)
422 int top = (int)mItemsInfo.size() - count - 1;
425 int offset = 0 - mOffsetTop;
426 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
428 mWidgetLines[pos]->setPosition(0, offset);
429 offset += mHeightLine;
433 position = top * mHeightLine + mOffsetTop;
436 if (top != mTopIndex)
450 if (mWidgetScroll !=
nullptr)
456 #if MYGUI_DEBUG_MODE == 1
457 _checkMapping(
"ListBox::updateLine");
465 for (; pos < mWidgetLines.size(); pos++)
468 size_t index = pos + (size_t)mTopIndex;
471 if (index >= mItemsInfo.size())
474 mLastRedrawLine = pos;
480 mLastRedrawLine = pos;
485 mWidgetLines[pos]->setVisible(
true);
487 mWidgetLines[pos]->setCaption(mItemsInfo[index].first);
490 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(index == mIndexSelect);
494 if (pos >= mWidgetLines.size())
496 mLastRedrawLine = pos;
501 for (; pos < mWidgetLines.size(); pos++)
503 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(
false);
509 #if MYGUI_DEBUG_MODE == 1
510 _checkMapping(
"ListBox::_redrawItemRange");
518 if (_index < (
size_t)mTopIndex)
520 _index -= (size_t)mTopIndex;
522 if (_index >= mLastRedrawLine)
527 mWidgetLines[_index]->setCaption(mItemsInfo[_index + mTopIndex].first);
529 #if MYGUI_DEBUG_MODE == 1
530 _checkMapping(
"ListBox::_redrawItem");
538 _index = mItemsInfo.size();
541 mItemsInfo.insert(mItemsInfo.begin() + _index, PairItem(_name, _data));
544 if ((mIndexSelect !=
ITEM_NONE) && (_index <= mIndexSelect))
548 if ((_index <= (
size_t)mTopIndex) && (mRangeIndex > 0))
552 if (mWidgetScroll !=
nullptr)
555 if (!mItemsInfo.empty())
559 mRangeIndex += mHeightLine;
564 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
567 if (_getClientWidget()->
getHeight() < (offset - mHeightLine))
570 if (mWidgetScroll !=
nullptr)
573 if (!mItemsInfo.empty())
577 mRangeIndex += mHeightLine;
591 #if MYGUI_DEBUG_MODE == 1
592 _checkMapping(
"ListBox::insertItemAt");
601 mItemsInfo.erase(mItemsInfo.begin() + _index);
604 if (mItemsInfo.empty()) mIndexSelect =
ITEM_NONE;
607 if (_index < mIndexSelect)
609 else if ((_index == mIndexSelect) && (mIndexSelect == (mItemsInfo.size())))
614 if (mWidgetLines.size() > mItemsInfo.size())
616 mWidgetLines[mItemsInfo.size()]->setVisible(
false);
620 if (_index < (
size_t)mTopIndex)
624 if (mWidgetScroll !=
nullptr)
627 if (!mItemsInfo.empty())
631 mRangeIndex -= mHeightLine;
636 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
639 if (_getClientWidget()->
getHeight() < offset)
642 if (mWidgetScroll !=
nullptr)
645 if (!mItemsInfo.empty())
649 mRangeIndex -= mHeightLine;
663 #if MYGUI_DEBUG_MODE == 1
664 _checkMapping(
"ListBox::removeItemAt");
671 if (mIndexSelect != _index)
675 mIndexSelect = _index;
684 if (_index < (
size_t)mTopIndex)
687 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
689 if (_getClientWidget()->
getHeight() < offset)
692 size_t index = _index - mTopIndex;
693 if (index < mWidgetLines.size())
694 static_cast<Button*>(mWidgetLines[index])->setStateSelected(_select);
696 #if MYGUI_DEBUG_MODE == 1
697 _checkMapping(
"ListBox::_selectIndex");
704 if (mRangeIndex <= 0)
707 int offset = (int)_index * mHeightLine;
708 if (offset >= mRangeIndex) offset = mRangeIndex;
710 if (mWidgetScroll !=
nullptr)
718 #if MYGUI_DEBUG_MODE == 1
719 _checkMapping(
"ListBox::beginToItemAt");
727 if (_index >= mItemsInfo.size())
730 if (mRangeIndex <= 0)
734 if (_index < (
size_t)mTopIndex)
738 if (_index == (
size_t)mTopIndex)
740 if ((mOffsetTop != 0) && (_fill))
746 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
749 if (_getClientWidget()->
getHeight() < offset)
753 if ((_getClientWidget()->
getHeight() < (offset + mHeightLine)) && (_fill))
768 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
770 mWidgetLines[pos]->setVisible(
false);
771 mWidgetLines[pos]->setPosition(0, offset);
772 offset += mHeightLine;
779 #if MYGUI_DEBUG_MODE == 1
780 _checkMapping(
"ListBox::removeAllItems");
787 mItemsInfo[_index].first = _name;
794 mItemsInfo[_index].second = _data;
801 return mItemsInfo[_index].first;
807 #if MYGUI_DEBUG_MODE == 1
817 if ((
nullptr == _new) || (_new->
getParent() != _getClientWidget()))
827 static_cast<Button*
>(mWidgetLines[_index])->_setMouseFocus(_focus);
832 if (mNeedVisibleScroll == _visible)
834 mNeedVisibleScroll = _visible;
840 if (mWidgetScroll !=
nullptr)
852 mOffsetTop = ((int)_position % mHeightLine);
855 int offset = 0 - mOffsetTop;
857 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
859 mWidgetLines[pos]->setPosition(
IntPoint(0, offset));
860 offset += mHeightLine;
864 int top = ((int)_position / mHeightLine);
865 if (top != mTopIndex)
887 if (_index1 == _index2)
890 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
896 void ListBox::_checkMapping(
const std::string& _owner)
898 size_t count_pressed = 0;
899 size_t count_show = 0;
901 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
903 MYGUI_ASSERT(pos == *mWidgetLines[pos]->_getInternalData<size_t>(), _owner);
904 static_cast<Button*
>(mWidgetLines[pos])->getStateSelected() ? count_pressed ++ : 0;
914 int max_height = mItemsInfo.size() * mHeightLine;
916 int visible_height = _getClientWidget()->
getHeight();
919 if (visible_height >= max_height)
924 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
926 if (pos >= mItemsInfo.size())
928 MYGUI_ASSERT(mWidgetLines[pos]->
getTop() == height,
"mWidgetLines[pos]->getTop() == height");
929 height += mWidgetLines[pos]->getHeight();
936 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
938 if (mItemsInfo[pos].first == _name)
949 Widget* ListBox::_getClientWidget()
951 return mClient ==
nullptr ?
this : mClient;
956 return mItemsInfo.size();
1019 for (VectorButton::iterator iter = mWidgetLines.begin(); iter != mWidgetLines.end(); ++iter)
1021 if ((*iter) == _item)
1022 return *(*iter)->_getInternalData<
size_t>() + mTopIndex;
1030 Base::_resetContainer(_update);
1035 for (VectorButton::iterator iter = mWidgetLines.begin(); iter != mWidgetLines.end(); ++iter)
1042 if (_key ==
"AddItem")
1046 Base::setPropertyOverride(_key, _value);
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
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
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 _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 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)
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
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.
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
void notifyScrollChangePosition(ScrollBar *_sender, size_t _rel)
ValueType * _getInternalData(bool _throw=true)
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