MyGUI 3.2.0

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

- File List
- Globals

MyGUI_MenuControl.h
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_MENU_CONTROL_H__
23 #define __MYGUI_MENU_CONTROL_H__
24
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Types.h"
27 #include "MyGUI_MenuItemType.h"
28 #include "MyGUI_Widget.h"
29 #include "MyGUI_Any.h"
30 #include "MyGUI_EventPair.h"
31 #include "MyGUI_MenuItemType.h"
32 #include "MyGUI_ControllerFadeAlpha.h"
33 #include "MyGUI_IItem.h"
34 #include "MyGUI_IItemContainer.h"
35
36 namespace MyGUI
37 {
38
39 typedef delegates::CMultiDelegate2<MenuControl*, MenuItem*> EventHandle_MenuCtrlPtrMenuItemPtr;
40 typedef delegates::CMultiDelegate1<MenuControl*> EventHandle_MenuCtrlPtr;
41
42 class MYGUI_EXPORT MenuControl :
43 public Widget,
44 public IItemContainer,
45 public MemberObsolete<MenuControl>
46 {
47 MYGUI_RTTI_DERIVED( MenuControl )
48
49 public:
50 MenuControl();
51
52 struct ItemInfo
53 {
54 ItemInfo(MenuItem* _item, const UString& _name, MenuItemType _type, MenuControl* _submenu, const std::string& _id, Any _data) :
55 item(_item),
56 name(_name),
57 type(_type),
58 submenu(_submenu),
59 id(_id),
60 data(_data),
61 width(0)
62 {
63 }
64
66 MenuItem* item;
68 UString name;
70 MenuItemType type;
72 MenuControl* submenu;
74 std::string id;
76 Any data;
78 int width;
79 };
80
81 typedef std::vector<ItemInfo> VectorMenuItemInfo;
82
83 public:
85 virtual void setVisible(bool _value);
86
88 void setVisibleSmooth(bool _value);
89
90 //------------------------------------------------------------------------------//
91 // манипуляции айтемами
92
94 size_t getItemCount() const;
95
97 MenuItem* insertItemAt(size_t _index, const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null);
99 MenuItem* insertItem(MenuItem* _to, const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null);
100
102 MenuItem* addItem(const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null);
103
105 void removeItemAt(size_t _index);
107 void removeItem(MenuItem* _item);
108
110 void removeAllItems();
111
112
114 MenuItem* getItemAt(size_t _index);
115
117 size_t getItemIndex(MenuItem* _item);
118
120 size_t findItemIndex(MenuItem* _item);
121
123 MenuItem* findItemWith(const UString& _name);
124
125 //------------------------------------------------------------------------------//
126 // манипуляции данными
127
129 void setItemDataAt(size_t _index, Any _data);
131 void setItemData(MenuItem* _item, Any _data);
132
134 void clearItemDataAt(size_t _index);
136 void clearItemData(MenuItem* _item);
137
139 template <typename ValueType>
140 ValueType* getItemDataAt(size_t _index, bool _throw = true)
141 {
142 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemDataAt");
143 return mItemsInfo[_index].data.castType<ValueType>(_throw);
144 }
146 template <typename ValueType>
147 ValueType* getItemData(MenuItem* _item, bool _throw = true)
148 {
149 return getItemDataAt<ValueType>(getItemIndex(_item), _throw);
150 }
151
153 void setItemIdAt(size_t _index, const std::string& _id);
155 void setItemId(MenuItem* _item, const std::string& _id);
156
158 const std::string& getItemIdAt(size_t _index);
160 const std::string& getItemId(MenuItem* _item);
161
163 MenuItem* getItemById(const std::string& _id);
164
166 MenuItem* findItemById(const std::string& _id, bool _recursive = false);
167
169 size_t getItemIndexById(const std::string& _id);
170 //------------------------------------------------------------------------------//
171 // манипуляции отображением
172
174 void setItemNameAt(size_t _index, const UString& _name);
176 void setItemName(MenuItem* _item, const UString& _name);
177
179 const UString& getItemNameAt(size_t _index);
181 const UString& getItemName(MenuItem* _item);
182
184 size_t findItemIndexWith(const UString& _name);
185
187 void setItemChildVisibleAt(size_t _index, bool _visible);
189 void setItemChildVisible(MenuItem* _item, bool _visible);
190
191 //------------------------------------------------------------------------------//
192 // остальные манипуляции
193
195 template <typename Type>
196 Type* createItemChildTAt(size_t _index)
197 {
198 return static_cast<Type*>(createItemChildByType(_index, Type::getClassTypeName()));
199 }
200
202 template <typename Type>
203 Type* createItemChildT(MenuItem* _item)
204 {
205 return createItemChildTAt<Type>(getItemIndex(_item));
206 }
207
209 MenuControl* getItemChildAt(size_t _index);
210
212 MenuControl* getItemChild(MenuItem* _item);
213
215 MenuControl* createItemChildAt(size_t _index);
216
218 MenuControl* createItemChild(MenuItem* _item);
219
221 void removeItemChildAt(size_t _index);
222
224 void removeItemChild(MenuItem* _item);
225
226
228 MenuItemType getItemTypeAt(size_t _index);
229
231 MenuItemType getItemType(MenuItem* _item);
232
234 void setItemTypeAt(size_t _index, MenuItemType _type);
236 void setItemType(MenuItem* _item, MenuItemType _type);
237
239 void setPopupAccept(bool _value);
241 bool getPopupAccept() const;
242
244 MenuItem* getMenuItemParent();
245
247 void setVerticalAlignment(bool _value);
249 bool getVerticalAlignment() const;
250
251
252 /*events:*/
258 EventHandle_MenuCtrlPtrMenuItemPtr
259 eventMenuCtrlAccept;
260
265 EventHandle_MenuCtrlPtr
266 eventMenuCtrlClose;
267
268
269 /*internal:*/
270 void _notifyDeleteItem(MenuItem* _item);
271 void _notifyDeletePopup(MenuItem* _item);
272 void _notifyUpdateName(MenuItem* _item);
273 void _wrapItemChild(MenuItem* _item, MenuControl* _widget);
274
275 // IItemContainer impl
276 virtual size_t _getItemCount();
277 virtual void _addItem(const MyGUI::UString& _name);
278 virtual void _removeItemAt(size_t _index);
279 virtual Widget* _getItemAt(size_t _index);
280 virtual void _setItemNameAt(size_t _index, const UString& _name);
281 virtual const UString& _getItemNameAt(size_t _index);
282 virtual void _setItemSelected(IItem* _item);
283
284 void _updateItems(size_t _index);
285 void _updateSizeForEmpty();
286
287 protected:
288 virtual void initialiseOverride();
289 virtual void shutdownOverride();
290
291 virtual void onKeyChangeRootFocus(bool _focus);
292
293 virtual void onWidgetCreated(Widget* _widget);
294
295 virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
296
297 private:
298 void notifyRootKeyChangeFocus(Widget* _sender, bool _focus);
299 void notifyMouseButtonClick(Widget* _sender);
300 void notifyMouseSetFocus(Widget* _sender, Widget* _new);
301
302 const std::string& getSkinByType(MenuItemType _type) const;
303 std::string getIconIndexByType(MenuItemType _type) const;
304
305 void update();
306
307 MenuItemType getItemType(bool _submenu, bool _separator) const;
308
309 void notifyMenuCtrlAccept(MenuItem* _item);
310
311 Widget* createItemChildByType(size_t _index, const std::string& _type);
312
313 void _wrapItem(MenuItem* _item, size_t _index, const UString& _name, MenuItemType _type, const std::string& _id, Any _data);
314
315 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
316
317 Widget* _getClientWidget();
318
319 void _setItemChildVisibleAt(size_t _index, bool _visible, bool _smooth);
320
321 protected:
322 bool mHideByAccept;
323 // нужно ли выбрасывать по нажатию
324 bool mMenuDropMode;
325 bool mIsMenuDrop;
326 bool mHideByLostKey;
327 bool mResizeToContent;
328
329 private:
330 VectorMenuItemInfo mItemsInfo;
331
332 std::string mItemNormalSkin;
333 std::string mItemPopupSkin;
334 std::string mItemSeparatorSkin;
335
336 std::string mSubMenuSkin;
337 std::string mSubMenuLayer;
338
339 // флаг, чтобы отсеч уведомления от айтемов, при общем шутдауне виджета
340 bool mShutdown;
341
342 bool mVerticalAlignment;
343 int mDistanceButton;
344 bool mPopupAccept;
345 MenuItem* mOwner;
346 bool mAnimateSmooth;
347
348 bool mChangeChildSkin;
349 Widget* mClient;
350 };
351
352 } // namespace MyGUI
353
354 #endif // __MYGUI_MENU_CONTROL_H__
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI_IItemContainer.h
MyGUI_Prerequest.h
MyGUI_IItem.h
MyGUI::Any
Definition: MyGUI_Any.h:81
MyGUI::EventHandle_MenuCtrlPtrMenuItemPtr
delegates::CMultiDelegate2< MenuControl *, MenuItem * > EventHandle_MenuCtrlPtrMenuItemPtr
Definition: MyGUI_MenuControl.h:39
MyGUI::IItemContainer
Definition: MyGUI_IItemContainer.h:33
MyGUI_Types.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:88
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:120
MyGUI::EventHandle_MenuCtrlPtr
delegates::CMultiDelegate1< MenuControl * > EventHandle_MenuCtrlPtr
Definition: MyGUI_MenuControl.h:40
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:70
MyGUI::ControllerFadeAlpha
Definition: MyGUI_ControllerFadeAlpha.h:33
MyGUI_Widget.h
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:169
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:28
MyGUI_EventPair.h
MyGUI::IItem
Definition: MyGUI_IItem.h:32
MyGUI::delegates::CMultiDelegate1< MenuControl * >
MyGUI::Any::Null
static AnyEmpty Null
Definition: MyGUI_Any.h:85