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"
16#include "MyGUI_IBItemInfo.h"
17
18namespace MyGUI
19{
20
23
27 class MYGUI_EXPORT ListBox : public Widget, public IItemContainer, public MemberObsolete<ListBox>
28 {
30
31 public:
32 //------------------------------------------------------------------------------//
33 // манипуляции айтемами
34
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
70 size_t getIndexSelected() const;
71
73 void setIndexSelected(size_t _index);
74
76 void clearIndexSelected();
78
79 //------------------------------------------------------------------------------//
80 // манипуляции данными
81
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 }
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
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
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:*/
192
199
206
213
220
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_
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_EXPORT
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
widget description should be here.
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem
ValueType * getItemDataAt(size_t _index, bool _throw=true) const
Get item data from specified position.
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangePosition
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemFocus
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangeScroll
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListSelectAccept
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemActivate
widget description should be here.
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
widget description should be here.
unsigned int Char
Definition MyGUI_Types.h:50
constexpr size_t ITEM_NONE
types::TSize< int > IntSize
Definition MyGUI_Types.h:30