MyGUI 3.2.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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"
17 #include "MyGUI_ControllerFadeAlpha.h"
18 #include "MyGUI_IItem.h"
19 #include "MyGUI_IItemContainer.h"
20
21 namespace MyGUI
22 {
23
24 typedef delegates::CMultiDelegate2<MenuControl*, MenuItem*> EventHandle_MenuCtrlPtrMenuItemPtr;
25 typedef delegates::CMultiDelegate1<MenuControl*> EventHandle_MenuCtrlPtr;
26
30 class MYGUI_EXPORT MenuControl :
31 public Widget,
32 public IItemContainer,
33 public MemberObsolete<MenuControl>
34 {
35 MYGUI_RTTI_DERIVED( MenuControl )
36
37 public:
38 MenuControl();
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
54 MenuItem* item;
56 UString name;
58 MenuItemType type;
60 MenuControl* submenu;
62 std::string id;
64 Any data;
66 int width;
67 };
68
69 typedef std::vector<ItemInfo> VectorMenuItemInfo;
70
71 public:
73 virtual void setVisible(bool _value);
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);
103
105 size_t getItemIndex(MenuItem* _item);
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);
148 const std::string& getItemId(MenuItem* _item);
149
151 MenuItem* getItemById(const std::string& _id);
152
154 MenuItem* findItemById(const std::string& _id, bool _recursive = false);
155
157 size_t getItemIndexById(const std::string& _id);
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);
169 const UString& getItemName(MenuItem* _item);
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>
191 Type* createItemChildT(MenuItem* _item)
192 {
193 return createItemChildTAt<Type>(getItemIndex(_item));
194 }
195
197 MenuControl* getItemChildAt(size_t _index);
198
200 MenuControl* getItemChild(MenuItem* _item);
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);
217
219 MenuItemType getItemType(MenuItem* _item);
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();
233
235 void setVerticalAlignment(bool _value);
237 bool getVerticalAlignment() const;
238
239
240 /*events:*/
246 EventHandle_MenuCtrlPtrMenuItemPtr eventMenuCtrlAccept;
247
252 EventHandle_MenuCtrlPtr eventMenuCtrlClose;
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 virtual size_t _getItemCount();
263 virtual void _addItem(const MyGUI::UString& _name);
264 virtual void _removeItemAt(size_t _index);
265 virtual Widget* _getItemAt(size_t _index);
266 virtual void _setItemNameAt(size_t _index, const UString& _name);
267 virtual const UString& _getItemNameAt(size_t _index);
268 virtual void _setItemSelected(IItem* _item);
269
270 void _updateItems(size_t _index);
271 void _updateSizeForEmpty();
272
273 protected:
274 virtual void initialiseOverride();
275 virtual void shutdownOverride();
276
277 virtual void onKeyChangeRootFocus(bool _focus);
278
279 virtual void onWidgetCreated(Widget* _widget);
280
281 virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
282
283 private:
284 void notifyRootKeyChangeFocus(Widget* _sender, bool _focus);
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 Widget* _getClientWidget();
304
305 void _setItemChildVisibleAt(size_t _index, bool _visible, bool _smooth);
306
307 protected:
308 bool mHideByAccept;
309 // нужно ли выбрасывать по нажатию
310 bool mMenuDropMode;
311 bool mIsMenuDrop;
312 bool mHideByLostKey;
313 bool mResizeToContent;
314
315 private:
316 VectorMenuItemInfo mItemsInfo;
317
318 std::string mItemNormalSkin;
319 std::string mItemPopupSkin;
320 std::string mItemSeparatorSkin;
321
322 std::string mSubMenuSkin;
323 std::string mSubMenuLayer;
324
325 // флаг, чтобы отсеч уведомления от айтемов, при общем шутдауне виджета
326 bool mShutdown;
327
328 bool mVerticalAlignment;
329 int mDistanceButton;
330 bool mPopupAccept;
331 MenuItem* mOwner;
332 bool mAnimateSmooth;
333
334 bool mChangeChildSkin;
335 Widget* mClient;
336 bool mInternalCreateChild;
337 };
338
339 } // namespace MyGUI
340
341 #endif // MYGUI_MENU_CONTROL_H_
MyGUI::Widget
Widget properties. Widget_skin_childs Skin childs. Widget widget description should be here...
Definition: MyGUI_Widget.h:29
MyGUI_IItemContainer.h
MyGUI_Prerequest.h
MyGUI_IItem.h
MyGUI::Any
Definition: MyGUI_Any.h:63
MyGUI::EventHandle_MenuCtrlPtrMenuItemPtr
delegates::CMultiDelegate2< MenuControl *, MenuItem * > EventHandle_MenuCtrlPtrMenuItemPtr
Definition: MyGUI_MenuControl.h:24
MyGUI::IItemContainer
Definition: MyGUI_IItemContainer.h:18
MyGUI_Types.h
MyGUI
Definition: MyGUI_ActionController.h:14
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:65
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103
MyGUI::EventHandle_MenuCtrlPtr
delegates::CMultiDelegate1< MenuControl * > EventHandle_MenuCtrlPtr
Definition: MyGUI_MenuControl.h:25
MyGUI_ControllerFadeAlpha.h
MyGUI_Any.h
MyGUI::delegates::CMultiDelegate2< MenuControl *, MenuItem * >
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition: MyGUI_Diagnostic.h:54
MyGUI::ControllerFadeAlpha
Definition: MyGUI_ControllerFadeAlpha.h:18
MyGUI_Widget.h
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:168
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:13
MyGUI_EventPair.h
MyGUI::IItem
Definition: MyGUI_IItem.h:17
MyGUI::delegates::CMultiDelegate1< MenuControl * >
MyGUI::Any::Null
static AnyEmpty Null
Definition: MyGUI_Any.h:67