MyGUI  3.4.0
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 
17 namespace MyGUI
18 {
19 
25 
30  public DDContainer,
31  protected ScrollViewBase,
32  public MemberObsolete<ItemBox>
33  {
35 
36  public:
37  ItemBox();
38 
39  //------------------------------------------------------------------------------//
40  // манипуляции айтемами
41 
43  size_t getItemCount() const;
44 
46  void insertItemAt(size_t _index, Any _data = Any::Null, bool update = true);
47 
49  void addItem(Any _data = Any::Null, bool update = true);
50 
52  void removeItemAt(size_t _index, bool update = true);
53 
55  void removeAllItems();
56 
58  void redrawItemAt(size_t _index);
59 
61  void redrawAllItems();
62 
63 
64  //------------------------------------------------------------------------------//
65  // манипуляции выделениями
66 
68  size_t getIndexSelected() const;
69 
71  void setIndexSelected(size_t _index);
72 
74  void clearIndexSelected();
75 
76 
77  //------------------------------------------------------------------------------//
78  // манипуляции данными
79 
81  void setItemDataAt(size_t _index, Any _data);
82 
84  void clearItemDataAt(size_t _index);
85 
87  template <typename ValueType>
88  ValueType* getItemDataAt(size_t _index, bool _throw = true)
89  {
90  MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ItemBox::getItemDataAt");
91  return mItemsInfo[_index].data.castType<ValueType>(_throw);
92  }
93 
94 
96  void setVerticalAlignment(bool _value);
98  bool getVerticalAlignment() const;
99 
101  size_t getIndexByWidget(Widget* _widget);
102 
104  Widget* getWidgetDrag();
105 
111  Widget* getWidgetByIndex(size_t _index);
112 
114  void resetDrag();
115 
117  void setPosition(const IntPoint& _value) override;
119  void setSize(const IntSize& _value) override;
121  void setCoord(const IntCoord& _value) override;
122 
123  using Widget::setPosition;
124  using Widget::setSize;
125  using Widget::setCoord;
126 
128  void setVisibleVScroll(bool _value);
130  bool isVisibleVScroll() const;
131 
133  void setVisibleHScroll(bool _value);
135  bool isVisibleHScroll() const;
136 
138  void setViewOffset(const IntPoint& _value);
140  IntPoint getViewOffset();
141 
142  IntSize getViewSize() override;
143 
144  /*events:*/
151 
159 
167 
174 
181 
188 
195 
196  /*internal:*/
197  void _resetContainer(bool _update) override;
198 
199  protected:
200  void initialiseOverride() override;
201  void shutdownOverride() override;
202 
204  {
205  ItemDataInfo(Any _data) :
206  data(_data) { }
208  };
209  typedef std::vector<ItemDataInfo> VectorItemInfo;
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) 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  // возвращает следующий айтем, если нет его, то создается
246  // запросы только последовательно
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) override;
258 
259  void setPropertyOverride(const std::string& _key, const std::string& _value) override;
260 
261  private:
262  size_t calcIndexByWidget(Widget* _widget);
263 
264  void requestItemSize();
265 
266  IntSize getContentSize() override;
267  IntPoint getContentPosition() override;
268  void eraseContent() override;
269  size_t getHScrollPage() override;
270  size_t getVScrollPage() override;
271  Align getContentAlign() 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;
288  // колличество линий
289  int mCountLines;
290 
291  // самая верхняя строка
292  int mFirstVisibleIndex;
293  // текущее смещение верхнего элемента в пикселях
294  // сколько его пикселей не видно сверху
295  int mFirstOffsetIndex;
296 
297  // текущий выделенный элемент или ITEM_NONE
298  size_t mIndexSelect;
299  // подсвеченный элемент или ITEM_NONE
300  size_t mIndexActive;
301  // индекс со свойством приема или ITEM_NONE
302  size_t mIndexAccept;
303  // индекс со свойством отказа или ITEM_NONE
304  size_t mIndexRefuse;
305 
306  // имеем ли мы фокус ввода
307  bool mIsFocus;
308 
309  // структура данных об айтеме
310  VectorItemInfo mItemsInfo;
311 
312  Widget* mItemDrag;
313  IntPoint mPointDragOffset;
314 
315  bool mAlignVert;
316 
317  std::string mDragLayer;
318  };
319 
320 } // namespace MyGUI
321 
322 #endif // MYGUI_ITEM_BOX_H_
MyGUI::ItemBox::eventMouseItemActivate
EventHandle_ItemBoxPtrSizeT eventMouseItemActivate
Definition: MyGUI_ItemBox.h:187
MyGUI::Char
unsigned int Char
Definition: MyGUI_Types.h:48
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_value) override
Definition: MyGUI_Widget.cpp:630
MyGUI::ScrollBar
ScrollBar properties. Skin childs. ScrollBar widget description should be here.
Definition: MyGUI_ScrollBar.h:26
MyGUI_EventPair.h
MyGUI::ItemBox::VectorItemInfo
std::vector< ItemDataInfo > VectorItemInfo
Definition: MyGUI_ItemBox.h:209
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition: MyGUI_Diagnostic.h:45
MyGUI::ItemBox::ItemDataInfo::ItemDataInfo
ItemDataInfo(Any _data)
Definition: MyGUI_ItemBox.h:205
MyGUI::delegates::MultiDelegate
Definition: MyGUI_Delegate.h:183
MyGUI::Widget
Widget properties. Skin childs. Widget widget description should be here.
Definition: MyGUI_Widget.h:37
MyGUI::EventHandle_ItemBoxPtrSizeT
delegates::CMultiDelegate2< ItemBox *, size_t > EventHandle_ItemBoxPtrSizeT
Definition: MyGUI_ItemBox.h:23
MyGUI::types::TPoint< int >
MyGUI::Any
Definition: MyGUI_Any.h:64
MyGUI::Align
Definition: MyGUI_Align.h:20
MyGUI::delegates::Delegate
Definition: MyGUI_Delegate.h:119
MyGUI::MouseButton
Definition: MyGUI_MouseButton.h:16
MyGUI::ScrollViewBase
Definition: MyGUI_ScrollViewBase.h:17
MyGUI::ItemBox::ItemDataInfo::data
Any data
Definition: MyGUI_ItemBox.h:207
MyGUI_IBItemInfo.h
MyGUI_ScrollViewBase.h
MyGUI_Prerequest.h
MyGUI::ItemBox
ItemBox properties. Skin childs. ItemBox widget description should be here.
Definition: MyGUI_ItemBox.h:33
MyGUI::ItemBox::requestCoordItem
EventHandle_ItemBoxPtrIntCoordRefBool requestCoordItem
Definition: MyGUI_ItemBox.h:158
MyGUI::DDWidgetState
Definition: MyGUI_DDItemInfo.h:100
MyGUI_DDContainer.h
MyGUI::Widget::setSize
void setSize(const IntSize &_value) override
Definition: MyGUI_Widget.cpp:647
MyGUI::ItemBox::eventChangeItemPosition
EventHandle_ItemBoxPtrSizeT eventChangeItemPosition
Definition: MyGUI_ItemBox.h:180
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:48
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:14
MyGUI::types::TSize
Definition: MyGUI_TSize.h:19
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_value) override
Definition: MyGUI_Widget.cpp:684
MyGUI::EventHandle_ItemBoxPtrIntCoordRefBool
delegates::CDelegate3< ItemBox *, IntCoord &, bool > EventHandle_ItemBoxPtrIntCoordRefBool
Definition: MyGUI_ItemBox.h:21
MyGUI::EventHandle_ItemBoxPtrWidgetPtr
delegates::CDelegate2< ItemBox *, Widget * > EventHandle_ItemBoxPtrWidgetPtr
Definition: MyGUI_ItemBox.h:20
MyGUI::ItemBox::getItemDataAt
ValueType * getItemDataAt(size_t _index, bool _throw=true)
Get item data from specified position.
Definition: MyGUI_ItemBox.h:88
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:89
MyGUI::DDContainer
DDContainer properties. Skin childs. DDContainer widget description should be here.
Definition: MyGUI_DDContainer.h:29
MyGUI::ItemBox::requestCreateWidgetItem
EventHandle_ItemBoxPtrWidgetPtr requestCreateWidgetItem
Definition: MyGUI_ItemBox.h:150
MyGUI::ItemBox::ItemDataInfo
Definition: MyGUI_ItemBox.h:204
MyGUI::types::TCoord< int >
MyGUI::ItemBox::eventNotifyItem
EventHandle_ItemBoxPtrCIBNotifyCellDataRef eventNotifyItem
Definition: MyGUI_ItemBox.h:194
MyGUI::ItemBox::eventSelectItemAccept
EventHandle_ItemBoxPtrSizeT eventSelectItemAccept
Definition: MyGUI_ItemBox.h:173
MyGUI::ItemBox::requestDrawItem
EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef requestDrawItem
Definition: MyGUI_ItemBox.h:166
MyGUI::Any::Null
static AnyEmpty Null
Definition: MyGUI_Any.h:67
MyGUI::EventHandle_ItemBoxPtrCIBNotifyCellDataRef
delegates::CMultiDelegate2< ItemBox *, const IBNotifyItemData & > EventHandle_ItemBoxPtrCIBNotifyCellDataRef
Definition: MyGUI_ItemBox.h:24
MyGUI
Definition: MyGUI_ActionController.h:15
MyGUI_Any.h
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition: MyGUI_WidgetDefines.h:20
MyGUI::EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef
delegates::CDelegate3< ItemBox *, Widget *, const IBDrawItemInfo & > EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef
Definition: MyGUI_ItemBox.h:22
MyGUI::KeyCode
Definition: MyGUI_KeyCode.h:16