MyGUI 3.2.2

MyGUI_MenuItem.cpp
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #include "MyGUI_Precompiled.h"
8 #include "MyGUI_MenuItem.h"
9
10 namespace MyGUI
11 {
12
13 MenuItem::MenuItem() :
14 mOwner(nullptr),
15 mMinSize(10, 10),
16 mCheck(nullptr),
17 mCheckValue(false)
18 {
19 }
20
21 void MenuItem::initialiseOverride()
22 {
23 Base::initialiseOverride();
24
25 // FIXME проверить смену скина ибо должно один раз вызываться
26 Widget* parent = getParent();
27 MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
28 if (!parent->isType<MenuControl>())
29 {
30 Widget* client = parent;
31 parent = client->getParent();
32 MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
33 MYGUI_ASSERT(parent->getClientWidget() == client, "MenuItem must have parent MenuControl");
34 MYGUI_ASSERT(parent->isType<MenuControl>(), "MenuItem must have parent MenuControl");
35 }
36 mOwner = parent->castType<MenuControl>();
37
39 assignWidget(mCheck, "Check");
40
41 //if (isUserString("MinSize"))
42 // mMinSize = IntSize::parse(getUserString("MinSize"));
43
44 //FIXME нам нужен фокус клавы
45 setNeedKeyFocus(true);
46
47 updateCheck();
48 }
49
50 void MenuItem::shutdownOverride()
51 {
52 // FIXME проверить смену скина ибо должно один раз вызываться
53 mOwner->_notifyDeleteItem(this);
54
55 Base::shutdownOverride();
56 }
57
58 void MenuItem::onWidgetCreated(Widget* _widget)
59 {
60 Base::onWidgetCreated(_widget);
61
62 MenuControl* child = _widget->castType<MenuControl>(false);
63 if (child != nullptr)
64 {
65 mOwner->_wrapItemChild(this, child);
66 }
67 }
68
69 void MenuItem::setCaption(const UString& _value)
70 {
71 Button::setCaption(_value);
72 mOwner->_notifyUpdateName(this);
73 }
74
75 void MenuItem::setFontName(const std::string& _value)
76 {
77 Button::setFontName(_value);
78 if (!getCaption().empty())
79 mOwner->_notifyUpdateName(this);
80 }
81
82 void MenuItem::setFontHeight(int _value)
83 {
84 Button::setFontHeight(_value);
85 if (!getCaption().empty())
86 mOwner->_notifyUpdateName(this);
87 }
88
89 const UString& MenuItem::getItemName()
90 {
91 return mOwner->getItemName(this);
92 }
93
94 void MenuItem::setItemName(const UString& _value)
95 {
96 mOwner->setItemName(this, _value);
97 }
98
99 void MenuItem::setItemData(Any _data)
100 {
101 mOwner->setItemData(this, _data);
102 }
103
104 void MenuItem::removeItem()
105 {
106 mOwner->removeItem(this);
107 }
108
109 void MenuItem::setItemId(const std::string& _id)
110 {
111 mOwner->setItemId(this, _id);
112 }
113
114 const std::string& MenuItem::getItemId()
115 {
116 return mOwner->getItemId(this);
117 }
118
119 size_t MenuItem::getItemIndex()
120 {
121 return mOwner->getItemIndex(this);
122 }
123
124 MenuControl* MenuItem::createItemChild()
125 {
126 return mOwner->createItemChild(this);
127 }
128
129 void MenuItem::setItemType(MenuItemType _type)
130 {
131 mOwner->setItemType(this, _type);
132 }
133
134 MenuItemType MenuItem::getItemType()
135 {
136 return mOwner->getItemType(this);
137 }
138
139 void MenuItem::setItemChildVisible(bool _visible)
140 {
141 mOwner->setItemChildVisible(this, _visible);
142 }
143
144 MenuControl* MenuItem::getItemChild()
145 {
146 return mOwner->getItemChild(this);
147 }
148
149 void MenuItem::setPropertyOverride(const std::string& _key, const std::string& _value)
150 {
152 if (_key == "MenuItemId")
153 setItemId(_value);
154
156 else if (_key == "MenuItemType")
157 setItemType(utility::parseValue<MenuItemType>(_value));
158
160 else if (_key == "MenuItemChecked")
161 setItemChecked(utility::parseValue<bool>(_value));
162
163 else
164 {
165 Base::setPropertyOverride(_key, _value);
166 return;
167 }
168
169 eventChangeProperty(this, _key, _value);
170 }
171
172 MenuControl* MenuItem::getMenuCtrlParent()
173 {
174 return mOwner;
175 }
176
177 IItemContainer* MenuItem::_getItemContainer()
178 {
179 return mOwner;
180 }
181
182 IntSize MenuItem::_getContentSize()
183 {
184 ISubWidgetText* text = getSubWidgetText();
185 if (text == nullptr)
186 return mMinSize;
187
188 return text->getTextSize() + (getSize() - text->getSize());
189 }
190
191 void MenuItem::updateCheck()
192 {
193 if (mCheck != nullptr)
194 mCheck->setVisible(mCheckValue);
195 }
196
197 bool MenuItem::getItemChecked() const
198 {
199 return mCheckValue;
200 }
201
202 void MenuItem::setItemChecked(bool _value)
203 {
204 mCheckValue = _value;
205 updateCheck();
206 }
207
208 } // namespace MyGUI
MyGUI::Widget
Widget properties. Widget_skin_childs Skin childs. Widget widget description should be here...
Definition: MyGUI_Widget.h:29
MyGUI::Button::setPropertyOverride
virtual void setPropertyOverride(const std::string &_key, const std::string &_value)
Definition: MyGUI_Button.cpp:175
MyGUI::TextBox::setFontHeight
virtual void setFontHeight(int _value)
Definition: MyGUI_TextBox.cpp:66
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition: MyGUI_ICroppedRectangle.h:56
MyGUI_Precompiled.h
MyGUI::TextBox::setFontName
virtual void setFontName(const std::string &_value)
Definition: MyGUI_TextBox.cpp:53
MyGUI::Widget::getClientWidget
Widget * getClientWidget()
Definition: MyGUI_Widget.cpp:1290
MyGUI::types::TSize< int >
MyGUI::Widget::isType
virtual bool isType(const std::type_info &_type) const
Definition: MyGUI_Widget.h:41
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, const std::string &_name)
Definition: MyGUI_Widget.h:328
MyGUI::Any
Definition: MyGUI_Any.h:63
MyGUI::Widget::setVisible
virtual void setVisible(bool _value)
Definition: MyGUI_Widget.cpp:965
MyGUI::TextBox::setCaption
virtual void setCaption(const UString &_value)
Definition: MyGUI_TextBox.cpp:77
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:29
MyGUI::IItemContainer
Definition: MyGUI_IItemContainer.h:18
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText()
Definition: MyGUI_SkinItem.cpp:155
MyGUI::TextBox::getCaption
virtual const UString & getCaption()
Definition: MyGUI_TextBox.cpp:83
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:266
MyGUI::Button::shutdownOverride
virtual void shutdownOverride()
Definition: MyGUI_Button.cpp:33
MyGUI::Widget::getParent
Widget * getParent() const
Definition: MyGUI_Widget.cpp:1275
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:42
MyGUI::Button::initialiseOverride
virtual void initialiseOverride()
Definition: MyGUI_Button.cpp:25
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
MyGUI::Widget::onWidgetCreated
virtual void onWidgetCreated(Widget *_widget)
Definition: MyGUI_Widget.cpp:1126
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:168
MyGUI::ISubWidgetText
Definition: MyGUI_ISubWidgetText.h:18
MyGUI::WidgetInput::setNeedKeyFocus
void setNeedKeyFocus(bool _value)
Definition: MyGUI_WidgetInput.cpp:156
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize()
Definition: MyGUI_ISubWidgetText.h:111