MyGUI: MyGUI_ListBox.h Source File

MyGUI 3.4.3

MyGUI_ListBox.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_LIST_BOX_H_
8#define MYGUI_LIST_BOX_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Button.h"
12#include "MyGUI_Any.h"
13#include "MyGUI_EventPair.h"
14#include "MyGUI_IItem.h"
15#include "MyGUI_IItemContainer.h"
16#include "MyGUI_IBItemInfo.h"
17
18namespace MyGUI
19{
20
21 using EventHandle_ListPtrSizeT = delegates::MultiDelegate<ListBox*, size_t>;
22 using EventHandle_ListBoxPtrCIBNotifyCellDataRef = delegates::MultiDelegate<ListBox*, const IBNotifyItemData&>;
23
27 class MYGUI_EXPORT ListBox : public Widget, public IItemContainer, public MemberObsolete<ListBox>
28 {
29 MYGUI_RTTI_DERIVED(ListBox)
30
31 public:
32 //------------------------------------------------------------------------------//
33 // манипуляции айтемами
34
39
40 size_t getItemCount() const;
41
43 void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
44
46 void addItem(const UString& _name, Any _data = Any::Null);
47
49 void removeItemAt(size_t _index);
50
52 void removeAllItems();
53
55 void swapItemsAt(size_t _index1, size_t _index2);
56
57
59 size_t findItemIndexWith(const UString& _name);
61
62 //------------------------------------------------------------------------------//
63 // манипуляции выделениями
64
69
70 size_t getIndexSelected() const;
71
73 void setIndexSelected(size_t _index);
74
76 void clearIndexSelected();
78
79 //------------------------------------------------------------------------------//
80 // манипуляции данными
81
86
87 void setItemDataAt(size_t _index, Any _data);
88
90 void clearItemDataAt(size_t _index);
91
93 template<typename ValueType>
94 ValueType* getItemDataAt(size_t _index, bool _throw = true) const
95 {
96 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::getItemDataAt");
97 return mItemsInfo.at(_index).second.castType<ValueType>(_throw);
98 }
99
100
101 //------------------------------------------------------------------------------//
102 // манипуляции отображением
103
105 void setItemNameAt(size_t _index, const UString& _name);
106
108 const UString& getItemNameAt(size_t _index) const;
109
110
111 //------------------------------------------------------------------------------//
112 // манипуляции выдимостью
113
118
119 void beginToItemAt(size_t _index);
120
122 void beginToItemFirst();
123
125 void beginToItemLast();
126
128 void beginToItemSelected();
129
130 //------------------------------------------------------------------------------//
131
132 // видим ли мы элемент, полностью или нет
141 bool isItemVisibleAt(size_t _index, bool _fill = true);
143 bool isItemSelectedVisible(bool _fill = true);
144
145
147 void setScrollVisible(bool _visible);
149 void setScrollPosition(size_t _position);
151
152 //------------------------------------------------------------------------------------//
153
158
159 void setPosition(const IntPoint& _point) override;
161 void setSize(const IntSize& _size) override;
163 void setCoord(const IntCoord& _coord) override;
164
165 using Widget::setPosition;
166 using Widget::setSize;
167 using Widget::setCoord;
169
171 int getOptimalHeight() const;
172
176 void setActivateOnClick(bool activateOnClick);
177
183 Widget* getWidgetByIndex(size_t _index);
184
185 /*events:*/
191 EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListSelectAccept;
192
198 EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListChangePosition;
199
205 EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListMouseItemActivate;
206
212 EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListMouseItemFocus;
213
219 EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListChangeScroll;
220
226 EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem;
227
228 /*internal:*/
233 // дебажная проверка на правильность выравнивания списка
234 void _checkAlign();
235
236 // вспомогательные методы для составных списков
237 void _setItemFocus(size_t _index, bool _focus);
238 void _sendEventChangeScroll(size_t _position);
239
240 // IItemContainer impl
241 size_t _getItemCount() const override;
242 void _addItem(const MyGUI::UString& _name) override;
243 void _removeItemAt(size_t _index) override;
244 void _setItemNameAt(size_t _index, const UString& _name) override;
245 const UString& _getItemNameAt(size_t _index) const override;
246
247 void _resetContainer(bool _update) override;
249
250 protected:
251 void initialiseOverride() override;
252 void shutdownOverride() override;
253
254 void onMouseWheel(int _rel) override;
255 void onKeyButtonPressed(KeyCode _key, Char _char) override;
256 void onKeyButtonReleased(KeyCode _key) override;
257
258 void notifyScrollChangePosition(ScrollBar* _sender, size_t _position);
259 void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
260 void notifyMouseClick(Widget* _sender);
261 void notifyMouseDoubleClick(Widget* _sender);
262 void notifyMouseWheel(Widget* _sender, int _rel);
263 void notifyMouseSetFocus(Widget* _sender, Widget* _old);
264 void notifyMouseLostFocus(Widget* _sender, Widget* _new);
265 void notifyKeyButtonPressed(Widget* _sender, KeyCode _key, Char _char);
266 void notifyKeyButtonReleased(Widget* _sender, KeyCode _key);
267 void notifyMouseButtonReleased(Widget* _sender, int _left, int _top, MouseButton _id);
268
269 void updateScroll();
270 void updateLine(bool _reset = false);
271
272 void _activateItem(Widget* _sender);
273
274 void _setScrollView(size_t _position);
275
276 // перерисовывает от индекса до низа
277 void _redrawItemRange(size_t _start = 0);
278
279 // перерисовывает индекс
280 void _redrawItem(size_t _index);
281
282 // ищет и выделяет елемент
283 void _selectIndex(size_t _index, bool _select);
284
285 // метод для запроса номера айтема и контейнера
286 size_t _getItemIndex(Widget* _item) const override;
287
288 void setPropertyOverride(std::string_view _key, std::string_view _value) override;
289
290 private:
291 size_t getIndexByWidget(Widget* _widget) const;
292
293 private:
294 std::string mSkinLine;
295 ScrollBar* mWidgetScroll{nullptr};
296
297 // наши дети в строках
298 using VectorButton = std::vector<Button*>;
299 VectorButton mWidgetLines;
300
301 bool mActivateOnClick{false}; // Require a full mouse click rather than only mouse press to activate an item
302
303 int mHeightLine{1}; // высота одной строки
304 int mTopIndex{0}; // индекс самого верхнего элемента
305 int mOffsetTop{0}; // текущее смещение
306 int mRangeIndex{-1}; // размерность скрола
307 size_t mLastRedrawLine{0}; // последняя перерисованная линия
308
309 size_t mIndexSelect{ITEM_NONE}; // текущий выделенный элемент или ITEM_NONE
310 size_t mLineActive{ITEM_NONE}; // текущий виджет над которым мыша
311
312 using PairItem = std::pair<UString, Any>;
313 using VectorItemInfo = std::vector<PairItem>;
314 VectorItemInfo mItemsInfo;
315
316 // имеем ли мы фокус ввода
317 bool mNeedVisibleScroll{true};
318
319 IntSize mOldSize;
320 };
321
322} // namespace MyGUI
323
324#endif // MYGUI_LIST_BOX_H_
MyGUI_Any.h
MyGUI_Button.h
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MyGUI_EventPair.h
MyGUI_IBItemInfo.h
MyGUI_IItem.h
MyGUI_IItemContainer.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::Any::Null
static const Any Null
Definition MyGUI_Any.h:58
MyGUI::EventPair
Definition MyGUI_EventPair.h:99
MyGUI::IItemContainer
Definition MyGUI_IItemContainer.h:19
MyGUI::ListBox
widget description should be here.
Definition MyGUI_ListBox.h:28
MyGUI::ListBox::_setItemNameAt
void _setItemNameAt(size_t _index, const UString &_name) override
Definition MyGUI_ListBox.cpp:1014
MyGUI::ListBox::addItem
void addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
Definition MyGUI_ListBox.cpp:873
MyGUI::ListBox::notifyMouseWheel
void notifyMouseWheel(Widget *_sender, int _rel)
Definition MyGUI_ListBox.cpp:183
MyGUI::ListBox::_removeItemAt
void _removeItemAt(size_t _index) override
Definition MyGUI_ListBox.cpp:1009
MyGUI::ListBox::updateLine
void updateLine(bool _reset=false)
Definition MyGUI_ListBox.cpp:296
MyGUI::ListBox::eventNotifyItem
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem
Definition MyGUI_ListBox.h:226
MyGUI::ListBox::_redrawItem
void _redrawItem(size_t _index)
Definition MyGUI_ListBox.cpp:466
MyGUI::ListBox::_getItemIndex
size_t _getItemIndex(Widget *_item) const override
Definition MyGUI_ListBox.cpp:916
MyGUI::ListBox::_setScrollView
void _setScrollView(size_t _position)
Definition MyGUI_ListBox.cpp:784
MyGUI::ListBox::notifyKeyButtonReleased
void notifyKeyButtonReleased(Widget *_sender, KeyCode _key)
Definition MyGUI_ListBox.cpp:1036
MyGUI::ListBox::notifyMousePressed
void notifyMousePressed(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ListBox.cpp:218
MyGUI::ListBox::_sendEventChangeScroll
void _sendEventChangeScroll(size_t _position)
Definition MyGUI_ListBox.cpp:809
MyGUI::ListBox::getItemDataAt
ValueType * getItemDataAt(size_t _index, bool _throw=true) const
Get item data from specified position.
Definition MyGUI_ListBox.h:94
MyGUI::ListBox::notifyMouseButtonReleased
void notifyMouseButtonReleased(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ListBox.cpp:1041
MyGUI::ListBox::_checkAlign
void _checkAlign()
Definition MyGUI_ListBox.cpp:830
MyGUI::ListBox::_resetContainer
void _resetContainer(bool _update) override
Definition MyGUI_ListBox.cpp:926
MyGUI::ListBox::_getItemNameAt
const UString & _getItemNameAt(size_t _index) const override
Definition MyGUI_ListBox.cpp:1019
MyGUI::ListBox::notifyMouseClick
void notifyMouseClick(Widget *_sender)
Definition MyGUI_ListBox.cpp:228
MyGUI::ListBox::clearIndexSelected
void clearIndexSelected()
Definition MyGUI_ListBox.cpp:883
MyGUI::ListBox::_addItem
void _addItem(const MyGUI::UString &_name) override
Definition MyGUI_ListBox.cpp:1004
MyGUI::ListBox::_activateItem
void _activateItem(Widget *_sender)
Definition MyGUI_ListBox.cpp:955
MyGUI::ListBox::_redrawItemRange
void _redrawItemRange(size_t _start=0)
Definition MyGUI_ListBox.cpp:416
MyGUI::ListBox::notifyMouseLostFocus
void notifyMouseLostFocus(Widget *_sender, Widget *_new)
Definition MyGUI_ListBox.cpp:749
MyGUI::ListBox::shutdownOverride
void shutdownOverride() override
Definition MyGUI_ListBox.cpp:56
MyGUI::ListBox::getItemCount
size_t getItemCount() const
Get number of items.
Definition MyGUI_ListBox.cpp:868
MyGUI::ListBox::initialiseOverride
void initialiseOverride() override
Definition MyGUI_ListBox.cpp:19
MyGUI::ListBox::notifyScrollChangePosition
void notifyScrollChangePosition(ScrollBar *_sender, size_t _position)
Definition MyGUI_ListBox.cpp:212
MyGUI::ListBox::notifyMouseSetFocus
void notifyMouseSetFocus(Widget *_sender, Widget *_old)
Definition MyGUI_ListBox.cpp:739
MyGUI::ListBox::swapItemsAt
void swapItemsAt(size_t _index1, size_t _index2)
Swap items at a specified positions.
Definition MyGUI_ListBox.cpp:816
MyGUI::ListBox::onKeyButtonReleased
void onKeyButtonReleased(KeyCode _key) override
Definition MyGUI_ListBox.cpp:1048
MyGUI::ListBox::insertItemAt
void insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
Definition MyGUI_ListBox.cpp:481
MyGUI::ListBox::removeAllItems
void removeAllItems()
Remove all items.
Definition MyGUI_ListBox.cpp:698
MyGUI::ListBox::eventListChangePosition
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangePosition
Definition MyGUI_ListBox.h:198
MyGUI::ListBox::onMouseWheel
void onMouseWheel(int _rel) override
Definition MyGUI_ListBox.cpp:63
MyGUI::ListBox::clearItemDataAt
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
Definition MyGUI_ListBox.cpp:888
MyGUI::ListBox::updateScroll
void updateScroll()
Definition MyGUI_ListBox.cpp:261
MyGUI::ListBox::getIndexSelected
size_t getIndexSelected() const
Definition MyGUI_ListBox.cpp:878
MyGUI::ListBox::_selectIndex
void _selectIndex(size_t _index, bool _select)
Definition MyGUI_ListBox.cpp:627
MyGUI::ListBox::_getItemCount
size_t _getItemCount() const override
Definition MyGUI_ListBox.cpp:999
MyGUI::ListBox::_setItemFocus
void _setItemFocus(size_t _index, bool _focus)
Definition MyGUI_ListBox.cpp:758
MyGUI::ListBox::eventListMouseItemFocus
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemFocus
Definition MyGUI_ListBox.h:212
MyGUI::ListBox::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_ListBox.cpp:939
MyGUI::ListBox::findItemIndexWith
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
Definition MyGUI_ListBox.cpp:853
MyGUI::ListBox::eventListChangeScroll
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangeScroll
Definition MyGUI_ListBox.h:219
MyGUI::ListBox::notifyKeyButtonPressed
void notifyKeyButtonPressed(Widget *_sender, KeyCode _key, Char _char)
Definition MyGUI_ListBox.cpp:1031
MyGUI::ListBox::onKeyButtonPressed
void onKeyButtonPressed(KeyCode _key, Char _char) override
Definition MyGUI_ListBox.cpp:70
MyGUI::ListBox::setItemDataAt
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
Definition MyGUI_ListBox.cpp:726
MyGUI::ListBox::notifyMouseDoubleClick
void notifyMouseDoubleClick(Widget *_sender)
Definition MyGUI_ListBox.cpp:234
MyGUI::ListBox::eventListSelectAccept
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListSelectAccept
Definition MyGUI_ListBox.h:191
MyGUI::ListBox::removeItemAt
void removeItemAt(size_t _index)
Remove item at a specified position.
Definition MyGUI_ListBox.cpp:543
MyGUI::ListBox::setIndexSelected
void setIndexSelected(size_t _index)
Definition MyGUI_ListBox.cpp:616
MyGUI::ListBox::eventListMouseItemActivate
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemActivate
Definition MyGUI_ListBox.h:205
MyGUI::MemberObsolete
Definition MyGUI_DeprecatedTypes.h:14
MyGUI::ScrollBar
widget description should be here.
Definition MyGUI_ScrollBar.h:24
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:144
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_Widget.cpp:676
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_Widget.cpp:730
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::EventHandle_ListPtrSizeT
delegates::MultiDelegate< ListBox *, size_t > EventHandle_ListPtrSizeT
Definition MyGUI_ListBox.h:21
MyGUI::EventHandle_ListBoxPtrCIBNotifyCellDataRef
delegates::MultiDelegate< ListBox *, const IBNotifyItemData & > EventHandle_ListBoxPtrCIBNotifyCellDataRef
Definition MyGUI_ListBox.h:22
MyGUI::Char
unsigned int Char
Definition MyGUI_Types.h:50
MyGUI::ITEM_NONE
constexpr size_t ITEM_NONE
Definition MyGUI_Macros.h:19
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::KeyCode
Definition MyGUI_KeyCode.h:16
MyGUI::MouseButton
Definition MyGUI_MouseButton.h:16