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 #include "MyGUI_Precompiled.h" 00023 #include "MyGUI_MenuItem.h" 00024 00025 namespace MyGUI 00026 { 00027 00028 MenuItem::MenuItem() : 00029 mOwner(nullptr), 00030 mMinSize(10, 10), 00031 mCheck(nullptr), 00032 mCheckValue(false) 00033 { 00034 } 00035 00036 void MenuItem::initialiseOverride() 00037 { 00038 Base::initialiseOverride(); 00039 00040 // FIXME проверить смену скина ибо должно один раз вызываться 00041 Widget* parent = getParent(); 00042 MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl"); 00043 if (!parent->isType<MenuControl>()) 00044 { 00045 Widget* client = parent; 00046 parent = client->getParent(); 00047 MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl"); 00048 MYGUI_ASSERT(parent->getClientWidget() == client, "MenuItem must have parent MenuControl"); 00049 MYGUI_ASSERT(parent->isType<MenuControl>(), "MenuItem must have parent MenuControl"); 00050 } 00051 mOwner = parent->castType<MenuControl>(); 00052 00053 assignWidget(mCheck, "Check"); 00054 00055 //if (isUserString("MinSize")) 00056 //mMinSize = IntSize::parse(getUserString("MinSize")); 00057 00058 //FIXME нам нуженфокус клавы 00059 setNeedKeyFocus(true); 00060 00061 updateCheck(); 00062 } 00063 00064 void MenuItem::shutdownOverride() 00065 { 00066 // FIXME проверить смену скина ибо должно один раз вызываться 00067 mOwner->_notifyDeleteItem(this); 00068 00069 Base::shutdownOverride(); 00070 } 00071 00072 void MenuItem::onWidgetCreated(Widget* _widget) 00073 { 00074 Base::onWidgetCreated(_widget); 00075 00076 MenuControl* child = _widget->castType<MenuControl>(false); 00077 if (child != nullptr) 00078 { 00079 mOwner->_wrapItemChild(this, child); 00080 } 00081 } 00082 00083 void MenuItem::setCaption(const UString& _value) 00084 { 00085 Button::setCaption(_value); 00086 mOwner->_notifyUpdateName(this); 00087 } 00088 00089 const UString& MenuItem::getItemName() 00090 { 00091 return mOwner->getItemName(this); 00092 } 00093 00094 void MenuItem::setItemName(const UString& _value) 00095 { 00096 mOwner->setItemName(this, _value); 00097 } 00098 00099 void MenuItem::setItemData(Any _data) 00100 { 00101 mOwner->setItemData(this, _data); 00102 } 00103 00104 void MenuItem::removeItem() 00105 { 00106 mOwner->removeItem(this); 00107 } 00108 00109 void MenuItem::setItemId(const std::string& _id) 00110 { 00111 mOwner->setItemId(this, _id); 00112 } 00113 00114 const std::string& MenuItem::getItemId() 00115 { 00116 return mOwner->getItemId(this); 00117 } 00118 00119 size_t MenuItem::getItemIndex() 00120 { 00121 return mOwner->getItemIndex(this); 00122 } 00123 00124 MenuControl* MenuItem::createItemChild() 00125 { 00126 return mOwner->createItemChild(this); 00127 } 00128 00129 void MenuItem::setItemType(MenuItemType _type) 00130 { 00131 mOwner->setItemType(this, _type); 00132 } 00133 00134 MenuItemType MenuItem::getItemType() 00135 { 00136 return mOwner->getItemType(this); 00137 } 00138 00139 void MenuItem::setItemChildVisible(bool _visible) 00140 { 00141 mOwner->setItemChildVisible(this, _visible); 00142 } 00143 00144 MenuControl* MenuItem::getItemChild() 00145 { 00146 return mOwner->getItemChild(this); 00147 } 00148 00149 void MenuItem::setPropertyOverride(const std::string& _key, const std::string& _value) 00150 { 00151 if (_key == "MenuItemId") 00152 setItemId(_value); 00153 else if (_key == "MenuItemType") 00154 setItemType(utility::parseValue<MenuItemType>(_value)); 00155 else if (_key == "MenuItemChecked") 00156 setItemChecked(utility::parseValue<bool>(_value)); 00157 else 00158 { 00159 Base::setPropertyOverride(_key, _value); 00160 return; 00161 } 00162 eventChangeProperty(this, _key, _value); 00163 } 00164 00165 MenuControl* MenuItem::getMenuCtrlParent() 00166 { 00167 return mOwner; 00168 } 00169 00170 IItemContainer* MenuItem::_getItemContainer() 00171 { 00172 return mOwner; 00173 } 00174 00175 IntSize MenuItem::_getContentSize() 00176 { 00177 ISubWidgetText* text = getSubWidgetText(); 00178 if (text == nullptr) 00179 return mMinSize; 00180 00181 return text->getTextSize() + (getSize() - text->getSize()); 00182 } 00183 00184 void MenuItem::updateCheck() 00185 { 00186 if (mCheck != nullptr) 00187 mCheck->setVisible(mCheckValue); 00188 } 00189 00190 bool MenuItem::getItemChecked() const 00191 { 00192 return mCheckValue; 00193 } 00194 00195 void MenuItem::setItemChecked(bool _value) 00196 { 00197 mCheckValue = _value; 00198 updateCheck(); 00199 } 00200 00201 } // namespace MyGUI