MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #ifndef __MYGUI_MENU_CONTROL_H__ 00023 #define __MYGUI_MENU_CONTROL_H__ 00024 00025 #include "MyGUI_Prerequest.h" 00026 #include "MyGUI_Types.h" 00027 #include "MyGUI_MenuItemType.h" 00028 #include "MyGUI_Widget.h" 00029 #include "MyGUI_Any.h" 00030 #include "MyGUI_EventPair.h" 00031 #include "MyGUI_MenuItemType.h" 00032 #include "MyGUI_ControllerFadeAlpha.h" 00033 #include "MyGUI_IItem.h" 00034 #include "MyGUI_IItemContainer.h" 00035 00036 namespace MyGUI 00037 { 00038 00039 typedef delegates::CMultiDelegate2<MenuControl*, MenuItem*> EventHandle_MenuCtrlPtrMenuItemPtr; 00040 typedef delegates::CMultiDelegate1<MenuControl*> EventHandle_MenuCtrlPtr; 00041 00042 class MYGUI_EXPORT MenuControl : 00043 public Widget, 00044 public IItemContainer, 00045 public MemberObsolete<MenuControl> 00046 { 00047 MYGUI_RTTI_DERIVED( MenuControl ) 00048 00049 public: 00050 MenuControl(); 00051 00052 struct ItemInfo 00053 { 00054 ItemInfo(MenuItem* _item, const UString& _name, MenuItemType _type, MenuControl* _submenu, const std::string& _id, Any _data) : 00055 item(_item), 00056 name(_name), 00057 type(_type), 00058 submenu(_submenu), 00059 id(_id), 00060 data(_data), 00061 width(0) 00062 { 00063 } 00064 00066 MenuItem* item; 00068 UString name; 00070 MenuItemType type; 00072 MenuControl* submenu; 00074 std::string id; 00076 Any data; 00078 int width; 00079 }; 00080 00081 typedef std::vector<ItemInfo> VectorMenuItemInfo; 00082 00083 public: 00085 virtual void setVisible(bool _value); 00086 00088 void setVisibleSmooth(bool _value); 00089 00090 //------------------------------------------------------------------------------// 00091 // манипуляции айтемами 00092 00094 size_t getItemCount() const; 00095 00097 MenuItem* insertItemAt(size_t _index, const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null); 00099 MenuItem* insertItem(MenuItem* _to, const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null); 00100 00102 MenuItem* addItem(const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null); 00103 00105 void removeItemAt(size_t _index); 00107 void removeItem(MenuItem* _item); 00108 00110 void removeAllItems(); 00111 00112 00114 MenuItem* getItemAt(size_t _index); 00115 00117 size_t getItemIndex(MenuItem* _item); 00118 00120 size_t findItemIndex(MenuItem* _item); 00121 00123 MenuItem* findItemWith(const UString& _name); 00124 00125 //------------------------------------------------------------------------------// 00126 // манипуляции данными 00127 00129 void setItemDataAt(size_t _index, Any _data); 00131 void setItemData(MenuItem* _item, Any _data); 00132 00134 void clearItemDataAt(size_t _index); 00136 void clearItemData(MenuItem* _item); 00137 00139 template <typename ValueType> 00140 ValueType* getItemDataAt(size_t _index, bool _throw = true) 00141 { 00142 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemDataAt"); 00143 return mItemsInfo[_index].data.castType<ValueType>(_throw); 00144 } 00146 template <typename ValueType> 00147 ValueType* getItemData(MenuItem* _item, bool _throw = true) 00148 { 00149 return getItemDataAt<ValueType>(getItemIndex(_item), _throw); 00150 } 00151 00153 void setItemIdAt(size_t _index, const std::string& _id); 00155 void setItemId(MenuItem* _item, const std::string& _id); 00156 00158 const std::string& getItemIdAt(size_t _index); 00160 const std::string& getItemId(MenuItem* _item); 00161 00163 MenuItem* getItemById(const std::string& _id); 00164 00166 MenuItem* findItemById(const std::string& _id, bool _recursive = false); 00167 00169 size_t getItemIndexById(const std::string& _id); 00170 //------------------------------------------------------------------------------// 00171 // манипуляции отображением 00172 00174 void setItemNameAt(size_t _index, const UString& _name); 00176 void setItemName(MenuItem* _item, const UString& _name); 00177 00179 const UString& getItemNameAt(size_t _index); 00181 const UString& getItemName(MenuItem* _item); 00182 00184 size_t findItemIndexWith(const UString& _name); 00185 00187 void setItemChildVisibleAt(size_t _index, bool _visible); 00189 void setItemChildVisible(MenuItem* _item, bool _visible); 00190 00191 //------------------------------------------------------------------------------// 00192 // остальные манипуляции 00193 00195 template <typename Type> 00196 Type* createItemChildTAt(size_t _index) 00197 { 00198 return static_cast<Type*>(createItemChildByType(_index, Type::getClassTypeName())); 00199 } 00200 00202 template <typename Type> 00203 Type* createItemChildT(MenuItem* _item) 00204 { 00205 return createItemChildTAt<Type>(getItemIndex(_item)); 00206 } 00207 00209 MenuControl* getItemChildAt(size_t _index); 00210 00212 MenuControl* getItemChild(MenuItem* _item); 00213 00215 MenuControl* createItemChildAt(size_t _index); 00216 00218 MenuControl* createItemChild(MenuItem* _item); 00219 00221 void removeItemChildAt(size_t _index); 00222 00224 void removeItemChild(MenuItem* _item); 00225 00226 00228 MenuItemType getItemTypeAt(size_t _index); 00229 00231 MenuItemType getItemType(MenuItem* _item); 00232 00234 void setItemTypeAt(size_t _index, MenuItemType _type); 00236 void setItemType(MenuItem* _item, MenuItemType _type); 00237 00239 void setPopupAccept(bool _value); 00241 bool getPopupAccept() const; 00242 00244 MenuItem* getMenuItemParent(); 00245 00247 void setVerticalAlignment(bool _value); 00249 bool getVerticalAlignment() const; 00250 00251 00252 /*events:*/ 00258 EventHandle_MenuCtrlPtrMenuItemPtr 00259 eventMenuCtrlAccept; 00260 00265 EventHandle_MenuCtrlPtr 00266 eventMenuCtrlClose; 00267 00268 00269 /*internal:*/ 00270 void _notifyDeleteItem(MenuItem* _item); 00271 void _notifyDeletePopup(MenuItem* _item); 00272 void _notifyUpdateName(MenuItem* _item); 00273 void _wrapItemChild(MenuItem* _item, MenuControl* _widget); 00274 00275 // IItemContainer impl 00276 virtual size_t _getItemCount(); 00277 virtual void _addItem(const MyGUI::UString& _name); 00278 virtual void _removeItemAt(size_t _index); 00279 virtual Widget* _getItemAt(size_t _index); 00280 virtual void _setItemNameAt(size_t _index, const UString& _name); 00281 virtual const UString& _getItemNameAt(size_t _index); 00282 virtual void _setItemSelected(IItem* _item); 00283 00284 void _updateItems(size_t _index); 00285 void _updateSizeForEmpty(); 00286 00287 protected: 00288 virtual void initialiseOverride(); 00289 virtual void shutdownOverride(); 00290 00291 virtual void onKeyChangeRootFocus(bool _focus); 00292 00293 virtual void onWidgetCreated(Widget* _widget); 00294 00295 virtual void setPropertyOverride(const std::string& _key, const std::string& _value); 00296 00297 private: 00298 void notifyRootKeyChangeFocus(Widget* _sender, bool _focus); 00299 void notifyMouseButtonClick(Widget* _sender); 00300 void notifyMouseSetFocus(Widget* _sender, Widget* _new); 00301 00302 const std::string& getSkinByType(MenuItemType _type) const; 00303 std::string getIconIndexByType(MenuItemType _type) const; 00304 00305 void update(); 00306 00307 MenuItemType getItemType(bool _submenu, bool _separator) const; 00308 00309 void notifyMenuCtrlAccept(MenuItem* _item); 00310 00311 Widget* createItemChildByType(size_t _index, const std::string& _type); 00312 00313 void _wrapItem(MenuItem* _item, size_t _index, const UString& _name, MenuItemType _type, const std::string& _id, Any _data); 00314 00315 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable); 00316 00317 Widget* _getClientWidget(); 00318 00319 void _setItemChildVisibleAt(size_t _index, bool _visible, bool _smooth); 00320 00321 protected: 00322 bool mHideByAccept; 00323 // нужно ли выбрасывать по нажатию 00324 bool mMenuDropMode; 00325 bool mIsMenuDrop; 00326 bool mHideByLostKey; 00327 bool mResizeToContent; 00328 00329 private: 00330 VectorMenuItemInfo mItemsInfo; 00331 00332 std::string mItemNormalSkin; 00333 std::string mItemPopupSkin; 00334 std::string mItemSeparatorSkin; 00335 00336 std::string mSubMenuSkin; 00337 std::string mSubMenuLayer; 00338 00339 // флаг, чтобы отсеч уведомления от айтемов, при общем шутдауне виджета 00340 bool mShutdown; 00341 00342 bool mVerticalAlignment; 00343 int mDistanceButton; 00344 bool mPopupAccept; 00345 MenuItem* mOwner; 00346 bool mAnimateSmooth; 00347 00348 bool mChangeChildSkin; 00349 Widget* mClient; 00350 }; 00351 00352 } // namespace MyGUI 00353 00354 #endif // __MYGUI_MENU_CONTROL_H__