MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #ifndef __MYGUI_MENU_CONTROL_H__ 00008 #define __MYGUI_MENU_CONTROL_H__ 00009 00010 #include "MyGUI_Prerequest.h" 00011 #include "MyGUI_Types.h" 00012 #include "MyGUI_MenuItemType.h" 00013 #include "MyGUI_Widget.h" 00014 #include "MyGUI_Any.h" 00015 #include "MyGUI_EventPair.h" 00016 #include "MyGUI_MenuItemType.h" 00017 #include "MyGUI_ControllerFadeAlpha.h" 00018 #include "MyGUI_IItem.h" 00019 #include "MyGUI_IItemContainer.h" 00020 00021 namespace MyGUI 00022 { 00023 00024 typedef delegates::CMultiDelegate2<MenuControl*, MenuItem*> EventHandle_MenuCtrlPtrMenuItemPtr; 00025 typedef delegates::CMultiDelegate1<MenuControl*> EventHandle_MenuCtrlPtr; 00026 00030 class MYGUI_EXPORT MenuControl : 00031 public Widget, 00032 public IItemContainer, 00033 public MemberObsolete<MenuControl> 00034 { 00035 MYGUI_RTTI_DERIVED( MenuControl ) 00036 00037 public: 00038 MenuControl(); 00039 00040 struct ItemInfo 00041 { 00042 ItemInfo(MenuItem* _item, const UString& _name, MenuItemType _type, MenuControl* _submenu, const std::string& _id, Any _data) : 00043 item(_item), 00044 name(_name), 00045 type(_type), 00046 submenu(_submenu), 00047 id(_id), 00048 data(_data), 00049 width(0) 00050 { 00051 } 00052 00054 MenuItem* item; 00056 UString name; 00058 MenuItemType type; 00060 MenuControl* submenu; 00062 std::string id; 00064 Any data; 00066 int width; 00067 }; 00068 00069 typedef std::vector<ItemInfo> VectorMenuItemInfo; 00070 00071 public: 00073 virtual void setVisible(bool _value); 00074 00076 void setVisibleSmooth(bool _value); 00077 00078 //------------------------------------------------------------------------------// 00079 // манипуляции айтемами 00080 00082 size_t getItemCount() const; 00083 00085 MenuItem* insertItemAt(size_t _index, const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null); 00087 MenuItem* insertItem(MenuItem* _to, const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null); 00088 00090 MenuItem* addItem(const UString& _name, MenuItemType _type = MenuItemType::Normal, const std::string& _id = "", Any _data = Any::Null); 00091 00093 void removeItemAt(size_t _index); 00095 void removeItem(MenuItem* _item); 00096 00098 void removeAllItems(); 00099 00100 00102 MenuItem* getItemAt(size_t _index); 00103 00105 size_t getItemIndex(MenuItem* _item); 00106 00108 size_t findItemIndex(MenuItem* _item); 00109 00111 MenuItem* findItemWith(const UString& _name); 00112 00113 //------------------------------------------------------------------------------// 00114 // манипуляции данными 00115 00117 void setItemDataAt(size_t _index, Any _data); 00119 void setItemData(MenuItem* _item, Any _data); 00120 00122 void clearItemDataAt(size_t _index); 00124 void clearItemData(MenuItem* _item); 00125 00127 template <typename ValueType> 00128 ValueType* getItemDataAt(size_t _index, bool _throw = true) 00129 { 00130 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuControl::getItemDataAt"); 00131 return mItemsInfo[_index].data.castType<ValueType>(_throw); 00132 } 00134 template <typename ValueType> 00135 ValueType* getItemData(MenuItem* _item, bool _throw = true) 00136 { 00137 return getItemDataAt<ValueType>(getItemIndex(_item), _throw); 00138 } 00139 00141 void setItemIdAt(size_t _index, const std::string& _id); 00143 void setItemId(MenuItem* _item, const std::string& _id); 00144 00146 const std::string& getItemIdAt(size_t _index); 00148 const std::string& getItemId(MenuItem* _item); 00149 00151 MenuItem* getItemById(const std::string& _id); 00152 00154 MenuItem* findItemById(const std::string& _id, bool _recursive = false); 00155 00157 size_t getItemIndexById(const std::string& _id); 00158 //------------------------------------------------------------------------------// 00159 // манипуляции отображением 00160 00162 void setItemNameAt(size_t _index, const UString& _name); 00164 void setItemName(MenuItem* _item, const UString& _name); 00165 00167 const UString& getItemNameAt(size_t _index); 00169 const UString& getItemName(MenuItem* _item); 00170 00172 size_t findItemIndexWith(const UString& _name); 00173 00175 void setItemChildVisibleAt(size_t _index, bool _visible); 00177 void setItemChildVisible(MenuItem* _item, bool _visible); 00178 00179 //------------------------------------------------------------------------------// 00180 // остальные манипуляции 00181 00183 template <typename Type> 00184 Type* createItemChildTAt(size_t _index) 00185 { 00186 return static_cast<Type*>(createItemChildByType(_index, Type::getClassTypeName())); 00187 } 00188 00190 template <typename Type> 00191 Type* createItemChildT(MenuItem* _item) 00192 { 00193 return createItemChildTAt<Type>(getItemIndex(_item)); 00194 } 00195 00197 MenuControl* getItemChildAt(size_t _index); 00198 00200 MenuControl* getItemChild(MenuItem* _item); 00201 00203 MenuControl* createItemChildAt(size_t _index); 00204 00206 MenuControl* createItemChild(MenuItem* _item); 00207 00209 void removeItemChildAt(size_t _index); 00210 00212 void removeItemChild(MenuItem* _item); 00213 00214 00216 MenuItemType getItemTypeAt(size_t _index); 00217 00219 MenuItemType getItemType(MenuItem* _item); 00220 00222 void setItemTypeAt(size_t _index, MenuItemType _type); 00224 void setItemType(MenuItem* _item, MenuItemType _type); 00225 00227 void setPopupAccept(bool _value); 00229 bool getPopupAccept() const; 00230 00232 MenuItem* getMenuItemParent(); 00233 00235 void setVerticalAlignment(bool _value); 00237 bool getVerticalAlignment() const; 00238 00239 00240 /*events:*/ 00246 EventHandle_MenuCtrlPtrMenuItemPtr eventMenuCtrlAccept; 00247 00252 EventHandle_MenuCtrlPtr eventMenuCtrlClose; 00253 00254 00255 /*internal:*/ 00256 void _notifyDeleteItem(MenuItem* _item); 00257 void _notifyDeletePopup(MenuItem* _item); 00258 void _notifyUpdateName(MenuItem* _item); 00259 void _wrapItemChild(MenuItem* _item, MenuControl* _widget); 00260 00261 // IItemContainer impl 00262 virtual size_t _getItemCount(); 00263 virtual void _addItem(const MyGUI::UString& _name); 00264 virtual void _removeItemAt(size_t _index); 00265 virtual Widget* _getItemAt(size_t _index); 00266 virtual void _setItemNameAt(size_t _index, const UString& _name); 00267 virtual const UString& _getItemNameAt(size_t _index); 00268 virtual void _setItemSelected(IItem* _item); 00269 00270 void _updateItems(size_t _index); 00271 void _updateSizeForEmpty(); 00272 00273 protected: 00274 virtual void initialiseOverride(); 00275 virtual void shutdownOverride(); 00276 00277 virtual void onKeyChangeRootFocus(bool _focus); 00278 00279 virtual void onWidgetCreated(Widget* _widget); 00280 00281 virtual void setPropertyOverride(const std::string& _key, const std::string& _value); 00282 00283 private: 00284 void notifyRootKeyChangeFocus(Widget* _sender, bool _focus); 00285 void notifyMouseButtonClick(Widget* _sender); 00286 void notifyMouseSetFocus(Widget* _sender, Widget* _new); 00287 00288 const std::string& getSkinByType(MenuItemType _type) const; 00289 std::string getIconIndexByType(MenuItemType _type) const; 00290 00291 void update(); 00292 00293 MenuItemType getItemType(bool _submenu, bool _separator) const; 00294 00295 void notifyMenuCtrlAccept(MenuItem* _item); 00296 00297 Widget* createItemChildByType(size_t _index, const std::string& _type); 00298 00299 void _wrapItem(MenuItem* _item, size_t _index, const UString& _name, MenuItemType _type, const std::string& _id, Any _data); 00300 00301 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable); 00302 00303 Widget* _getClientWidget(); 00304 00305 void _setItemChildVisibleAt(size_t _index, bool _visible, bool _smooth); 00306 00307 protected: 00308 bool mHideByAccept; 00309 // нужно ли выбрасывать по нажатию 00310 bool mMenuDropMode; 00311 bool mIsMenuDrop; 00312 bool mHideByLostKey; 00313 bool mResizeToContent; 00314 00315 private: 00316 VectorMenuItemInfo mItemsInfo; 00317 00318 std::string mItemNormalSkin; 00319 std::string mItemPopupSkin; 00320 std::string mItemSeparatorSkin; 00321 00322 std::string mSubMenuSkin; 00323 std::string mSubMenuLayer; 00324 00325 // флаг, чтобы отсеч уведомления от айтемов, при общем шутдауне виджета 00326 bool mShutdown; 00327 00328 bool mVerticalAlignment; 00329 int mDistanceButton; 00330 bool mPopupAccept; 00331 MenuItem* mOwner; 00332 bool mAnimateSmooth; 00333 00334 bool mChangeChildSkin; 00335 Widget* mClient; 00336 bool mInternalCreateChild; 00337 }; 00338 00339 } // namespace MyGUI 00340 00341 #endif // __MYGUI_MENU_CONTROL_H__