MyGUI: MyGUI_MenuItem.cpp Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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
10namespace 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() const
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() const
115 {
116 return mOwner->getItemId(this);
117 }
118
119 size_t MenuItem::getItemIndex() const
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() const
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() const
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() const
173 {
174 return mOwner;
175 }
176
177 IItemContainer* MenuItem::_getItemContainer() const
178 {
179 return mOwner;
180 }
181
182 IntSize MenuItem::_getContentSize() const
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_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:29
MyGUI_Precompiled.h
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition MyGUI_ICroppedRectangle.h:56
MyGUI::IItemContainer
Definition MyGUI_IItemContainer.h:19
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::ISubWidgetText
Definition MyGUI_ISubWidgetText.h:20
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize() const
Definition MyGUI_ISubWidgetText.h:109
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText() const
Definition MyGUI_SkinItem.cpp:155
MyGUI::TextBox::setFontHeight
virtual void setFontHeight(int _value)
Definition MyGUI_TextBox.cpp:66
MyGUI::TextBox::getCaption
virtual const UString & getCaption() const
Definition MyGUI_TextBox.cpp:83
MyGUI::TextBox::setFontName
virtual void setFontName(const std::string &_value)
Definition MyGUI_TextBox.cpp:53
MyGUI::TextBox::setCaption
virtual void setCaption(const UString &_value)
Definition MyGUI_TextBox.cpp:77
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:145
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:37
MyGUI::Widget::getParent
Widget * getParent() const
Definition MyGUI_Widget.cpp:1275
MyGUI::Widget::isType
virtual bool isType(const std::type_info &_type) const override
Definition MyGUI_Widget.h:41
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:268
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, const std::string &_name)
Definition MyGUI_Widget.h:336
MyGUI::Widget::setVisible
virtual void setVisible(bool _value)
Definition MyGUI_Widget.cpp:959
MyGUI::Widget::getClientWidget
Widget * getClientWidget()
Definition MyGUI_Widget.cpp:1290
MyGUI::WidgetInput::setNeedKeyFocus
void setNeedKeyFocus(bool _value)
Definition MyGUI_WidgetInput.cpp:152
MyGUI::utility::parseValue
T parseValue(const std::string &_value)
Definition MyGUI_StringUtility.h:112
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::types::TSize< int >