MyGUI: MyGUI_ItemBox.h Source File

MyGUI 3.4.3

MyGUI_ItemBox.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_ITEM_BOX_H_
8#define MYGUI_ITEM_BOX_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_DDContainer.h"
12#include "MyGUI_IBItemInfo.h"
13#include "MyGUI_Any.h"
14#include "MyGUI_EventPair.h"
15#include "MyGUI_ScrollViewBase.h"
16
17namespace MyGUI
18{
19
20 using EventHandle_ItemBoxPtrWidgetPtr = delegates::Delegate<ItemBox*, Widget*>;
21 using EventHandle_ItemBoxPtrIntCoordRefBool = delegates::Delegate<ItemBox*, IntCoord&, bool>;
22 using EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef =
23 delegates::Delegate<ItemBox*, Widget*, const IBDrawItemInfo&>;
24 using EventHandle_ItemBoxPtrSizeT = delegates::MultiDelegate<ItemBox*, size_t>;
25 using EventHandle_ItemBoxPtrCIBNotifyCellDataRef = delegates::MultiDelegate<ItemBox*, const IBNotifyItemData&>;
26
30 class MYGUI_EXPORT ItemBox : public DDContainer, protected ScrollViewBase, public MemberObsolete<ItemBox>
31 {
32 MYGUI_RTTI_DERIVED(ItemBox)
33
34 public:
35 ItemBox();
36
37 //------------------------------------------------------------------------------//
38 // манипуляции айтемами
39
41 size_t getItemCount() const;
42
44 void insertItemAt(size_t _index, Any _data = Any::Null, bool update = true);
45
47 void addItem(Any _data = Any::Null, bool update = true);
48
50 void removeItemAt(size_t _index, bool update = true);
51
53 void removeAllItems();
54
56 void redrawItemAt(size_t _index);
57
59 void redrawAllItems();
60
61
62 //------------------------------------------------------------------------------//
63 // манипуляции выделениями
64
66 size_t getIndexSelected() const;
67
69 void setIndexSelected(size_t _index);
70
72 void clearIndexSelected();
73
74
75 //------------------------------------------------------------------------------//
76 // манипуляции данными
77
79 void setItemDataAt(size_t _index, Any _data);
80
82 void clearItemDataAt(size_t _index);
83
85 template<typename ValueType>
86 ValueType* getItemDataAt(size_t _index, bool _throw = true)
87 {
88 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ItemBox::getItemDataAt");
89 return mItemsInfo[_index].data.castType<ValueType>(_throw);
90 }
91
92
94 void setVerticalAlignment(bool _vert);
96 bool getVerticalAlignment() const;
97
99 size_t getIndexByWidget(Widget* _widget) const;
100
102 Widget* getWidgetDrag() const;
103
109 Widget* getWidgetByIndex(size_t _index);
110
112 void resetDrag();
113
115 void setPosition(const IntPoint& _point) override;
117 void setSize(const IntSize& _size) override;
119 void setCoord(const IntCoord& _coord) override;
120
121 using Widget::setPosition;
122 using Widget::setSize;
123 using Widget::setCoord;
124
126 void setVisibleVScroll(bool _value);
128 bool isVisibleVScroll() const;
129
131 void setVisibleHScroll(bool _value);
133 bool isVisibleHScroll() const;
134
136 void setViewOffset(const IntPoint& _value);
138 IntPoint getViewOffset() const;
139
140 IntSize getViewSize() const override;
141
142 /*events:*/
148 EventHandle_ItemBoxPtrWidgetPtr requestCreateWidgetItem;
149
156 EventHandle_ItemBoxPtrIntCoordRefBool requestCoordItem;
157
164 EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef requestDrawItem;
165
171 EventHandle_ItemBoxPtrSizeT eventSelectItemAccept;
172
178 EventHandle_ItemBoxPtrSizeT eventChangeItemPosition;
179
185 EventHandle_ItemBoxPtrSizeT eventMouseItemActivate;
186
192 EventHandle_ItemBoxPtrCIBNotifyCellDataRef eventNotifyItem;
193
194 /*internal:*/
195 void _resetContainer(bool _update) override;
196
197 protected:
198 void initialiseOverride() override;
199 void shutdownOverride() override;
200
201 struct ItemDataInfo
202 {
203 ItemDataInfo(Any _data) :
204 data(_data)
205 {
206 }
207 Any data;
208 };
209 using VectorItemInfo = std::vector<ItemDataInfo>;
210
211 void onMouseButtonPressed(int _left, int _top, MouseButton _id) override;
212 void onMouseButtonReleased(int _left, int _top, MouseButton _id) override;
213 void onKeyButtonPressed(KeyCode _key, Char _char) override;
214 void onKeyButtonReleased(KeyCode _key) override;
215 void onMouseDrag(int _left, int _top, MouseButton _id) override;
216
217 void onMouseWheel(int _rel) override;
218 void onKeyLostFocus(Widget* _new) override;
219 void onKeySetFocus(Widget* _old) override;
220
221 void notifyKeyButtonPressed(Widget* _sender, KeyCode _key, Char _char);
222 void notifyKeyButtonReleased(Widget* _sender, KeyCode _key);
223 void notifyScrollChangePosition(ScrollBar* _sender, size_t _index);
224 void notifyMouseWheel(Widget* _sender, int _rel);
225 void notifyRootMouseChangeFocus(Widget* _sender, bool _focus);
226 void notifyMouseButtonDoubleClick(Widget* _sender);
227 size_t _getItemIndex(Widget* _item) const override;
228 void notifyMouseDrag(Widget* _sender, int _left, int _top, MouseButton _id);
229 void notifyMouseButtonPressed(Widget* _sender, int _left, int _top, MouseButton _id);
230 void notifyMouseButtonReleased(Widget* _sender, int _left, int _top, MouseButton _id);
231
232
233 void removeDropItems() override;
234 void updateDropItems() override;
235 void updateDropItemsState(const DDWidgetState& _state) override;
236
237 // Обновляет данные о айтемах, при изменении размеров
238 void updateMetrics();
239
240 // просто обновляет все виджеты что видны
241 void _updateAllVisible(bool _redraw);
242
243 void updateFromResize();
244
245 // returns next item, create new one if requesting next one
246 // can be requested only sequentially
247 Widget* getItemWidget(size_t _index);
248
249 void _setContainerItemInfo(size_t _index, bool _set, bool _accept) override;
250
251 // сбрасываем старую подсветку
252 void resetCurrentActiveItem();
253 // ищет и устанавливает подсвеченный айтем
254 void findCurrentActiveItem();
255
256 // запрашиваем у конейтера айтем по позиции мыши
257 size_t _getContainerIndex(const IntPoint& _point) const override;
258
259 void setPropertyOverride(std::string_view _key, std::string_view _value) override;
260
261 private:
262 size_t calcIndexByWidget(Widget* _widget) const;
263
264 void requestItemSize();
265
266 IntSize getContentSize() const override;
267 IntPoint getContentPosition() const override;
268 void eraseContent() override;
269 size_t getHScrollPage() const override;
270 size_t getVScrollPage() const override;
271 Align getContentAlign() const override;
272 void setContentPosition(const IntPoint& _point) override;
273
274 private:
275 // наши дети в строках
276 VectorWidgetPtr mVectorItems;
277
278 // размер одного айтема
279 IntSize mSizeItem;
280
281 // размерность скролла в пикселях
282 IntSize mContentSize;
283 // позиция скролла п пикселях
284 IntPoint mContentPosition;
285
286 // колличество айтемов в одной строке
287 int mCountItemInLine{0};
288 // колличество линий
289 int mCountLines{0};
290
291 // самая верхняя строка
292 int mFirstVisibleIndex{0};
293 // текущее смещение верхнего элемента в пикселях
294 // сколько его пикселей не видно сверху
295 int mFirstOffsetIndex{0};
296
297 // текущий выделенный элемент или ITEM_NONE
298 size_t mIndexSelect{ITEM_NONE};
299 // подсвеченный элемент или ITEM_NONE
300 size_t mIndexActive{ITEM_NONE};
301 // индекс со свойством приема или ITEM_NONE
302 size_t mIndexAccept{ITEM_NONE};
303 // индекс со свойством отказа или ITEM_NONE
304 size_t mIndexRefuse{ITEM_NONE};
305
306 // имеем ли мы фокус ввода
307 bool mIsFocus{false};
308
309 // структура данных об айтеме
310 VectorItemInfo mItemsInfo;
311
312 Widget* mItemDrag{nullptr};
313 IntPoint mPointDragOffset;
314
315 bool mAlignVert{true};
316
317 std::string mDragLayer;
318 };
319
320} // namespace MyGUI
321
322#endif // MYGUI_ITEM_BOX_H_
MyGUI_Any.h
MyGUI_DDContainer.h
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MyGUI_EventPair.h
MyGUI_IBItemInfo.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_ScrollViewBase.h
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::Any::Null
static const Any Null
Definition MyGUI_Any.h:58
MyGUI::DDContainer
widget description should be here.
Definition MyGUI_DDContainer.h:31
MyGUI::ItemBox::onMouseButtonPressed
void onMouseButtonPressed(int _left, int _top, MouseButton _id) override
Definition MyGUI_ItemBox.cpp:534
MyGUI::ItemBox::onKeyButtonPressed
void onKeyButtonPressed(KeyCode _key, Char _char) override
Definition MyGUI_ItemBox.cpp:1019
MyGUI::ItemBox::clearItemDataAt
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
Definition MyGUI_ItemBox.cpp:893
MyGUI::ItemBox::notifyMouseDrag
void notifyMouseDrag(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ItemBox.cpp:599
MyGUI::ItemBox::notifyMouseButtonReleased
void notifyMouseButtonReleased(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ItemBox.cpp:642
MyGUI::ItemBox::getItemCount
size_t getItemCount() const
Get number of items.
Definition MyGUI_ItemBox.cpp:873
MyGUI::ItemBox::requestDrawItem
EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef requestDrawItem
Definition MyGUI_ItemBox.h:164
MyGUI::ItemBox::notifyMouseWheel
void notifyMouseWheel(Widget *_sender, int _rel)
Definition MyGUI_ItemBox.cpp:733
MyGUI::ItemBox::updateFromResize
void updateFromResize()
Definition MyGUI_ItemBox.cpp:106
MyGUI::ItemBox::shutdownOverride
void shutdownOverride() override
Definition MyGUI_ItemBox.cpp:68
MyGUI::ItemBox::removeItemAt
void removeItemAt(size_t _index, bool update=true)
Remove item at a specified position.
Definition MyGUI_ItemBox.cpp:355
MyGUI::ItemBox::notifyMouseButtonDoubleClick
void notifyMouseButtonDoubleClick(Widget *_sender)
Definition MyGUI_ItemBox.cpp:449
MyGUI::ItemBox::onKeySetFocus
void onKeySetFocus(Widget *_old) override
Definition MyGUI_ItemBox.cpp:214
MyGUI::ItemBox::redrawItemAt
void redrawItemAt(size_t _index)
Redraw at a specified position.
Definition MyGUI_ItemBox.cpp:405
MyGUI::ItemBox::onMouseWheel
void onMouseWheel(int _rel) override
Definition MyGUI_ItemBox.cpp:207
MyGUI::ItemBox::onKeyButtonReleased
void onKeyButtonReleased(KeyCode _key) override
Definition MyGUI_ItemBox.cpp:1026
MyGUI::ItemBox::notifyScrollChangePosition
void notifyScrollChangePosition(ScrollBar *_sender, size_t _index)
Definition MyGUI_ItemBox.cpp:719
MyGUI::ItemBox::getItemWidget
Widget * getItemWidget(size_t _index)
Definition MyGUI_ItemBox.cpp:171
MyGUI::ItemBox::ItemBox
ItemBox()
Definition MyGUI_ItemBox.cpp:19
MyGUI::ItemBox::setIndexSelected
void setIndexSelected(size_t _index)
Select specified _index.
Definition MyGUI_ItemBox.cpp:417
MyGUI::ItemBox::redrawAllItems
void redrawAllItems()
Redraw all items.
Definition MyGUI_ItemBox.cpp:823
MyGUI::ItemBox::initialiseOverride
void initialiseOverride() override
Definition MyGUI_ItemBox.cpp:24
MyGUI::ItemBox::resetCurrentActiveItem
void resetCurrentActiveItem()
Definition MyGUI_ItemBox.cpp:228
MyGUI::ItemBox::onMouseDrag
void onMouseDrag(int _left, int _top, MouseButton _id) override
Definition MyGUI_ItemBox.cpp:544
MyGUI::ItemBox::onKeyLostFocus
void onKeyLostFocus(Widget *_new) override
Definition MyGUI_ItemBox.cpp:221
MyGUI::ItemBox::insertItemAt
void insertItemAt(size_t _index, Any _data=Any::Null, bool update=true)
Insert an item into a array at a specified position.
Definition MyGUI_ItemBox.cpp:324
MyGUI::ItemBox::_getContainerIndex
size_t _getContainerIndex(const IntPoint &_point) const override
Definition MyGUI_ItemBox.cpp:489
MyGUI::ItemBox::notifyMouseButtonPressed
void notifyMouseButtonPressed(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ItemBox.cpp:604
MyGUI::ItemBox::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_ItemBox.cpp:930
MyGUI::ItemBox::eventMouseItemActivate
EventHandle_ItemBoxPtrSizeT eventMouseItemActivate
Definition MyGUI_ItemBox.h:185
MyGUI::ItemBox::updateMetrics
void updateMetrics()
Definition MyGUI_ItemBox.cpp:686
MyGUI::ItemBox::requestCreateWidgetItem
EventHandle_ItemBoxPtrWidgetPtr requestCreateWidgetItem
Definition MyGUI_ItemBox.h:148
MyGUI::ItemBox::eventSelectItemAccept
EventHandle_ItemBoxPtrSizeT eventSelectItemAccept
Definition MyGUI_ItemBox.h:171
MyGUI::ItemBox::notifyKeyButtonReleased
void notifyKeyButtonReleased(Widget *_sender, KeyCode _key)
Definition MyGUI_ItemBox.cpp:471
MyGUI::ItemBox::VectorItemInfo
std::vector< ItemDataInfo > VectorItemInfo
Definition MyGUI_ItemBox.h:209
MyGUI::ItemBox::setItemDataAt
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
Definition MyGUI_ItemBox.cpp:309
MyGUI::ItemBox::updateDropItems
void updateDropItems() override
Definition MyGUI_ItemBox.cpp:555
MyGUI::ItemBox::_getItemIndex
size_t _getItemIndex(Widget *_item) const override
Definition MyGUI_ItemBox.cpp:282
MyGUI::ItemBox::_updateAllVisible
void _updateAllVisible(bool _redraw)
Definition MyGUI_ItemBox.cpp:117
MyGUI::ItemBox::updateDropItemsState
void updateDropItemsState(const DDWidgetState &_state) override
Definition MyGUI_ItemBox.cpp:583
MyGUI::ItemBox::getIndexSelected
size_t getIndexSelected() const
Get index of selected item (ITEM_NONE if none selected).
Definition MyGUI_ItemBox.cpp:883
MyGUI::ItemBox::_resetContainer
void _resetContainer(bool _update) override
Definition MyGUI_ItemBox.cpp:504
MyGUI::ItemBox::notifyRootMouseChangeFocus
void notifyRootMouseChangeFocus(Widget *_sender, bool _focus)
Definition MyGUI_ItemBox.cpp:653
MyGUI::ItemBox::getItemDataAt
ValueType * getItemDataAt(size_t _index, bool _throw=true)
Get item data from specified position.
Definition MyGUI_ItemBox.h:86
MyGUI::ItemBox::findCurrentActiveItem
void findCurrentActiveItem()
Definition MyGUI_ItemBox.cpp:247
MyGUI::ItemBox::onMouseButtonReleased
void onMouseButtonReleased(int _left, int _top, MouseButton _id) override
Definition MyGUI_ItemBox.cpp:539
MyGUI::ItemBox::removeAllItems
void removeAllItems()
Remove all items.
Definition MyGUI_ItemBox.cpp:388
MyGUI::ItemBox::notifyKeyButtonPressed
void notifyKeyButtonPressed(Widget *_sender, KeyCode _key, Char _char)
Definition MyGUI_ItemBox.cpp:466
MyGUI::ItemBox::removeDropItems
void removeDropItems() override
Definition MyGUI_ItemBox.cpp:549
MyGUI::ItemBox::_setContainerItemInfo
void _setContainerItemInfo(size_t _index, bool _set, bool _accept) override
Definition MyGUI_ItemBox.cpp:292
MyGUI::ItemBox::clearIndexSelected
void clearIndexSelected()
Clear item selection.
Definition MyGUI_ItemBox.cpp:888
MyGUI::ItemBox::addItem
void addItem(Any _data=Any::Null, bool update=true)
Add an item to the end of a array.
Definition MyGUI_ItemBox.cpp:878
MyGUI::ItemBox::requestCoordItem
EventHandle_ItemBoxPtrIntCoordRefBool requestCoordItem
Definition MyGUI_ItemBox.h:156
MyGUI::ItemBox::eventNotifyItem
EventHandle_ItemBoxPtrCIBNotifyCellDataRef eventNotifyItem
Definition MyGUI_ItemBox.h:192
MyGUI::ItemBox::eventChangeItemPosition
EventHandle_ItemBoxPtrSizeT eventChangeItemPosition
Definition MyGUI_ItemBox.h:178
MyGUI::MemberObsolete
Definition MyGUI_DeprecatedTypes.h:14
MyGUI::ScrollBar
widget description should be here.
Definition MyGUI_ScrollBar.h:24
MyGUI::ScrollViewBase
Definition MyGUI_ScrollViewBase.h:17
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::Delegate
Definition MyGUI_Delegate.h:158
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::EventHandle_ItemBoxPtrCIBNotifyCellDataRef
delegates::MultiDelegate< ItemBox *, const IBNotifyItemData & > EventHandle_ItemBoxPtrCIBNotifyCellDataRef
Definition MyGUI_ItemBox.h:25
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::EventHandle_ItemBoxPtrIntCoordRefBool
delegates::Delegate< ItemBox *, IntCoord &, bool > EventHandle_ItemBoxPtrIntCoordRefBool
Definition MyGUI_ItemBox.h:21
MyGUI::EventHandle_ItemBoxPtrWidgetPtr
delegates::Delegate< ItemBox *, Widget * > EventHandle_ItemBoxPtrWidgetPtr
Definition MyGUI_ItemBox.h:20
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::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20
MyGUI::EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef
delegates::Delegate< ItemBox *, Widget *, const IBDrawItemInfo & > EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef
Definition MyGUI_ItemBox.h:22
MyGUI::EventHandle_ItemBoxPtrSizeT
delegates::MultiDelegate< ItemBox *, size_t > EventHandle_ItemBoxPtrSizeT
Definition MyGUI_ItemBox.h:24
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::DDWidgetState
Definition MyGUI_DDItemInfo.h:100
MyGUI::ItemBox::ItemDataInfo::ItemDataInfo
ItemDataInfo(Any _data)
Definition MyGUI_ItemBox.h:203
MyGUI::ItemBox::ItemDataInfo::data
Any data
Definition MyGUI_ItemBox.h:207
MyGUI::KeyCode
Definition MyGUI_KeyCode.h:16
MyGUI::MouseButton
Definition MyGUI_MouseButton.h:16