MyGUI 3.0.1
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 #include "MyGUI_Precompiled.h" 00024 #include "MyGUI_MenuItem.h" 00025 #include "MyGUI_SkinManager.h" 00026 #include "MyGUI_SubWidgetManager.h" 00027 00028 namespace MyGUI 00029 { 00030 00031 MenuItem::MenuItem() : 00032 mOwner(nullptr) 00033 { 00034 } 00035 00036 void MenuItem::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name) 00037 { 00038 Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name); 00039 00040 Widget* parent = getParent(); 00041 MYGUI_ASSERT(parent, "MenuItem must have parent MenuCtrl"); 00042 if (!parent->isType<MenuCtrl>()) 00043 { 00044 Widget* client = parent; 00045 parent = client->getParent(); 00046 MYGUI_ASSERT(parent, "MenuItem must have parent MenuCtrl"); 00047 MYGUI_ASSERT(parent->getClientWidget() == client, "MenuItem must have parent MenuCtrl"); 00048 MYGUI_ASSERT(parent->isType<MenuCtrl>(), "MenuItem must have parent MenuCtrl"); 00049 } 00050 mOwner = parent->castType<MenuCtrl>(); 00051 00052 initialiseWidgetSkin(_info); 00053 00054 // нам нуженфокус клавы 00055 this->mNeedKeyFocus = true; 00056 } 00057 00058 MenuItem::~MenuItem() 00059 { 00060 shutdownWidgetSkin(); 00061 mOwner->_notifyDeleteItem(this); 00062 } 00063 00064 Widget* MenuItem::baseCreateWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name) 00065 { 00066 Widget* widget = Base::baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name); 00067 MenuCtrl* child = widget->castType<MenuCtrl>(false); 00068 if (child) mOwner->_wrapItemChild(this, child); 00069 return widget; 00070 } 00071 00072 void MenuItem::baseChangeWidgetSkin(ResourceSkin* _info) 00073 { 00074 shutdownWidgetSkin(); 00075 Button::baseChangeWidgetSkin(_info); 00076 initialiseWidgetSkin(_info); 00077 } 00078 00079 void MenuItem::initialiseWidgetSkin(ResourceSkin* _info) 00080 { 00081 } 00082 00083 void MenuItem::shutdownWidgetSkin() 00084 { 00085 } 00086 00087 void MenuItem::onMouseButtonPressed(int _left, int _top, MouseButton _id) 00088 { 00089 Base::onMouseButtonPressed(_left, _top, _id); 00090 } 00091 00092 void MenuItem::onMouseButtonReleased(int _left, int _top, MouseButton _id) 00093 { 00094 Base::onMouseButtonReleased(_left, _top, _id); 00095 } 00096 00097 void MenuItem::setCaption(const UString& _value) 00098 { 00099 Button::setCaption(_value); 00100 mOwner->_notifyUpdateName(this); 00101 } 00102 00103 const UString& MenuItem::getItemName() 00104 { 00105 return mOwner->getItemName(this); 00106 } 00107 00108 void MenuItem::setItemName(const UString& _value) 00109 { 00110 mOwner->setItemName(this, _value); 00111 } 00112 00113 void MenuItem::setItemData(Any _data) 00114 { 00115 mOwner->setItemData(this, _data); 00116 } 00117 00118 void MenuItem::removeItem() 00119 { 00120 mOwner->removeItem(this); 00121 } 00122 00123 void MenuItem::setItemId(const std::string& _id) 00124 { 00125 mOwner->setItemId(this, _id); 00126 } 00127 00128 const std::string& MenuItem::getItemId() 00129 { 00130 return mOwner->getItemId(this); 00131 } 00132 00133 size_t MenuItem::getItemIndex() 00134 { 00135 return mOwner->getItemIndex(this); 00136 } 00137 00138 MenuCtrl* MenuItem::createItemChild() 00139 { 00140 return mOwner->createItemChild(this); 00141 } 00142 00143 void MenuItem::setItemType(MenuItemType _type) 00144 { 00145 mOwner->setItemType(this, _type); 00146 } 00147 00148 MenuItemType MenuItem::getItemType() 00149 { 00150 return mOwner->getItemType(this); 00151 } 00152 00153 void MenuItem::setItemChildVisible(bool _visible) 00154 { 00155 mOwner->setItemChildVisible(this, _visible); 00156 } 00157 00158 MenuCtrl* MenuItem::getItemChild() 00159 { 00160 return mOwner->getItemChild(this); 00161 } 00162 00163 void MenuItem::setProperty(const std::string& _key, const std::string& _value) 00164 { 00165 if (_key == "MenuItem_Id") setItemId(_value); 00166 else if (_key == "MenuItem_Type") setItemType(utility::parseValue<MenuItemType>(_value)); 00167 else 00168 { 00169 Base::setProperty(_key, _value); 00170 return; 00171 } 00172 eventChangeProperty(this, _key, _value); 00173 } 00174 00175 } // namespace MyGUI