MyGUI 3.4.1
MyGUI_MenuControl.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_MENU_CONTROL_H_
8#define MYGUI_MENU_CONTROL_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Types.h"
12#include "MyGUI_MenuItemType.h"
13#include "MyGUI_Widget.h"
14#include "MyGUI_Any.h"
15#include "MyGUI_EventPair.h"
16#include "MyGUI_MenuItemType.h"
18#include "MyGUI_IItem.h"
20
21namespace MyGUI
22{
23
26
31 public Widget,
32 public IItemContainer,
33 public MemberObsolete<MenuControl>
34 {
36
37 public:
39
40 struct ItemInfo
41 {
42 ItemInfo(MenuItem* _item, const UString& _name, MenuItemType _type, MenuControl* _submenu, const std::string& _id, Any _data) :
43 item(_item),
44 name(_name),
45 type(_type),
46 submenu(_submenu),
47 id(_id),
48 data(_data),
49 width(0)
50 {
51 }
52
62 std::string id;
66 int width;
67 };
68
69 typedef std::vector<ItemInfo> VectorMenuItemInfo;
70
71 public:
73 void setVisible(bool _value) override;
74
76 void setVisibleSmooth(bool _value);
77
78 //------------------------------------------------------------------------------//
79 // манипуляции айтемами
80
82 size_t getItemCount() const;
83
85 MenuItem* insertItemAt(size_t _index, const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null);
87 MenuItem* insertItem(MenuItem* _to, const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null);
88
90 MenuItem* addItem(const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null);
91
93 void removeItemAt(size_t _index);
95 void removeItem(MenuItem* _item);
96
98 void removeAllItems();
99
100
102 MenuItem* getItemAt(size_t _index) const;
103
105 size_t getItemIndex(const MenuItem* _item) const;
106
108 size_t findItemIndex(MenuItem* _item);
109
111 MenuItem* findItemWith(const UString& _name);
112
113 //------------------------------------------------------------------------------//
114 // манипуляции данными
115
117 void setItemDataAt(size_t _index, Any _data);
119 void setItemData(MenuItem* _item, Any _data);
120
122 void clearItemDataAt(size_t _index);
124 void clearItemData(MenuItem* _item);
125
127 template <typename ValueType>
128 ValueType* getItemDataAt(size_t _index, bool _throw = true)
129 {
130 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemDataAt");
131 return mItemsInfo[_index].data.castType<ValueType>(_throw);
132 }
134 template <typename ValueType>
135 ValueType* getItemData(MenuItem* _item, bool _throw = true)
136 {
137 return getItemDataAt<ValueType>(getItemIndex(_item), _throw);
138 }
139
141 void setItemIdAt(size_t _index, const std::string& _id);
143 void setItemId(MenuItem* _item, const std::string& _id);
144
146 const std::string& getItemIdAt(size_t _index) const;
148 const std::string& getItemId(const MenuItem* _item) const;
149
151 MenuItem* getItemById(const std::string& _id) const;
152
154 MenuItem* findItemById(const std::string& _id, bool _recursive = false);
155
157 size_t getItemIndexById(const std::string& _id) const;
158 //------------------------------------------------------------------------------//
159 // манипуляции отображением
160
162 void setItemNameAt(size_t _index, const UString& _name);
164 void setItemName(MenuItem* _item, const UString& _name);
165
167 const UString& getItemNameAt(size_t _index) const;
169 const UString& getItemName(const MenuItem* _item) const;
170
172 size_t findItemIndexWith(const UString& _name);
173
175 void setItemChildVisibleAt(size_t _index, bool _visible);
177 void setItemChildVisible(MenuItem* _item, bool _visible);
178
179 //------------------------------------------------------------------------------//
180 // остальные манипуляции
181
183 template <typename Type>
184 Type* createItemChildTAt(size_t _index)
185 {
186 return static_cast<Type*>(createItemChildByType(_index, Type::getClassTypeName()));
187 }
188
190 template <typename Type>
192 {
193 return createItemChildTAt<Type>(getItemIndex(_item));
194 }
195
197 MenuControl* getItemChildAt(size_t _index) const;
198
200 MenuControl* getItemChild(const MenuItem* _item) const;
201
203 MenuControl* createItemChildAt(size_t _index);
204
206 MenuControl* createItemChild(MenuItem* _item);
207
209 void removeItemChildAt(size_t _index);
210
212 void removeItemChild(MenuItem* _item);
213
214
216 MenuItemType getItemTypeAt(size_t _index) const;
217
219 MenuItemType getItemType(const MenuItem* _item) const;
220
222 void setItemTypeAt(size_t _index, MenuItemType _type);
224 void setItemType(MenuItem* _item, MenuItemType _type);
225
227 void setPopupAccept(bool _value);
229 bool getPopupAccept() const;
230
232 MenuItem* getMenuItemParent() const;
233
235 void setVerticalAlignment(bool _value);
237 bool getVerticalAlignment() const;
238
239
240 /*events:*/
247
253
254
255 /*internal:*/
256 void _notifyDeleteItem(MenuItem* _item);
257 void _notifyDeletePopup(MenuItem* _item);
258 void _notifyUpdateName(MenuItem* _item);
259 void _wrapItemChild(MenuItem* _item, MenuControl* _widget);
260
261 // IItemContainer impl
262 size_t _getItemCount() const override;
263 void _addItem(const MyGUI::UString& _name) override;
264 void _removeItemAt(size_t _index) override;
265 Widget* _getItemAt(size_t _index) const override;
266 void _setItemNameAt(size_t _index, const UString& _name) override;
267 const UString& _getItemNameAt(size_t _index) const override;
268 void _setItemSelected(IItem* _item) override;
269
270 void _updateItems(size_t _index);
271 void _updateSizeForEmpty();
272
273 protected:
274 void initialiseOverride() override;
275 void shutdownOverride() override;
276
277 void onKeyChangeRootFocus(bool _focus) override;
278
279 void onWidgetCreated(Widget* _widget) override;
280
281 void setPropertyOverride(const std::string& _key, const std::string& _value) override;
282
283 private:
284 void notifyRootKeyChangeFocus(Widget* _sender, bool _focus) const;
285 void notifyMouseButtonClick(Widget* _sender);
286 void notifyMouseSetFocus(Widget* _sender, Widget* _new);
287
288 const std::string& getSkinByType(MenuItemType _type) const;
289 std::string getIconIndexByType(MenuItemType _type) const;
290
291 void update();
292
293 MenuItemType getItemType(bool _submenu, bool _separator) const;
294
295 void notifyMenuCtrlAccept(MenuItem* _item);
296
297 Widget* createItemChildByType(size_t _index, const std::string& _type);
298
299 void _wrapItem(MenuItem* _item, size_t _index, const UString& _name, MenuItemType _type, const std::string& _id, Any _data);
300
301 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
302
303 void _setItemChildVisibleAt(size_t _index, bool _visible, bool _smooth);
304
305 protected:
307 // нужно ли выбрасывать по нажатию
312
313 private:
314 VectorMenuItemInfo mItemsInfo;
315
316 std::string mItemNormalSkin;
317 std::string mItemPopupSkin;
318 std::string mItemSeparatorSkin;
319
320 std::string mSubMenuSkin;
321 std::string mSubMenuLayer;
322
323 // флаг, чтобы отсеч уведомления от айтемов, при общем шутдауне виджета
324 bool mShutdown;
325
326 bool mVerticalAlignment;
327 int mDistanceButton;
328 bool mPopupAccept;
329 MenuItem* mOwner;
330 bool mAnimateSmooth;
331
332 bool mChangeChildSkin;
333 bool mInternalCreateChild;
334 };
335
336} // namespace MyGUI
337
338#endif // MYGUI_MENU_CONTROL_H_
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_EXPORT
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:48
static AnyEmpty Null
Definition: MyGUI_Any.h:59
widget description should be here.
ValueType * getItemData(MenuItem *_item, bool _throw=true)
Get item data.
Type * createItemChildTAt(size_t _index)
Type * createItemChildT(MenuItem *_item)
std::vector< ItemInfo > VectorMenuItemInfo
EventHandle_MenuCtrlPtr eventMenuCtrlClose
EventHandle_MenuCtrlPtrMenuItemPtr eventMenuCtrlAccept
ValueType * getItemDataAt(size_t _index, bool _throw=true)
Get item data from specified position.
widget description should be here.
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
widget description should be here.
Definition: MyGUI_Widget.h:37
delegates::CMultiDelegate2< MenuControl *, MenuItem * > EventHandle_MenuCtrlPtrMenuItemPtr
delegates::CMultiDelegate1< MenuControl * > EventHandle_MenuCtrlPtr
ItemInfo(MenuItem *_item, const UString &_name, MenuItemType _type, MenuControl *_submenu, const std::string &_id, Any _data)