MyGUI 3.4.1
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
14 mOwner(nullptr),
15 mMinSize(10, 10),
16 mCheck(nullptr),
17 mCheckValue(false)
18 {
19 }
20
22 {
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
51 {
52 // FIXME проверить смену скина ибо должно один раз вызываться
53 mOwner->_notifyDeleteItem(this);
54
56 }
57
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 {
85 if (!getCaption().empty())
86 mOwner->_notifyUpdateName(this);
87 }
88
90 {
91 return mOwner->getItemName(this);
92 }
93
94 void MenuItem::setItemName(const UString& _value)
95 {
96 mOwner->setItemName(this, _value);
97 }
98
100 {
101 mOwner->setItemData(this, _data);
102 }
103
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
120 {
121 return mOwner->getItemIndex(this);
122 }
123
125 {
126 return mOwner->createItemChild(this);
127 }
128
130 {
131 mOwner->setItemType(this, _type);
132 }
133
135 {
136 return mOwner->getItemType(this);
137 }
138
140 {
141 mOwner->setItemChildVisible(this, _visible);
142 }
143
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
173 {
174 return mOwner;
175 }
176
178 {
179 return mOwner;
180 }
181
183 {
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
198 {
199 return mCheckValue;
200 }
201
202 void MenuItem::setItemChecked(bool _value)
203 {
204 mCheckValue = _value;
205 updateCheck();
206 }
207
208} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
void setPropertyOverride(const std::string &_key, const std::string &_value) override
void shutdownOverride() override
void initialiseOverride() override
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
virtual IntSize getTextSize() const
widget description should be here.
MenuControl * createItemChild(MenuItem *_item)
const std::string & getItemId(const MenuItem *_item) const
Get item id.
void setItemName(MenuItem *_item, const UString &_name)
Replace an item name.
void _notifyDeleteItem(MenuItem *_item)
size_t getItemIndex(const MenuItem *_item) const
Get item index.
void removeItem(MenuItem *_item)
Remove item.
void setItemData(MenuItem *_item, Any _data)
Replace an item data.
MenuControl * getItemChild(const MenuItem *_item) const
void _notifyUpdateName(MenuItem *_item)
const UString & getItemName(const MenuItem *_item) const
Get item from specified position.
void setItemType(MenuItem *_item, MenuItemType _type)
MenuItemType getItemType(const MenuItem *_item) const
void _wrapItemChild(MenuItem *_item, MenuControl *_widget)
void setItemId(MenuItem *_item, const std::string &_id)
Replace an item id.
void setItemChildVisible(MenuItem *_item, bool _visible)
const std::string & getItemId() const
Get item id from specified position.
void setFontName(const std::string &_value) override
void setCaption(const UString &_value) override
MenuControl * createItemChild()
void setItemChecked(bool _value)
void setPropertyOverride(const std::string &_key, const std::string &_value) override
MenuControl * getMenuCtrlParent() const
MenuControl * getItemChild() const
IntSize _getContentSize() const
void initialiseOverride() override
bool getItemChecked() const
void setItemName(const UString &_value)
Replace an item name.
void setItemId(const std::string &_value)
Replace an item id at a specified position.
void setItemChildVisible(bool _value)
void setItemData(Any _value)
Replace an item name.
void onWidgetCreated(Widget *_widget) override
MenuItemType getItemType() const
IItemContainer * _getItemContainer() const override
size_t getItemIndex() const
Get item index.
const UString & getItemName() const
Get item name.
void shutdownOverride() override
void removeItem()
Remove item.
void setItemType(MenuItemType _value)
void setFontHeight(int _value) override
ISubWidgetText * getSubWidgetText() const
virtual void setFontHeight(int _value)
virtual const UString & getCaption() const
virtual void setFontName(const std::string &_value)
virtual void setCaption(const UString &_value)
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
widget description should be here.
Definition: MyGUI_Widget.h:37
Widget * getParent() const
virtual bool isType(const std::type_info &_type) const override
Definition: MyGUI_Widget.h:41
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:267
void assignWidget(T *&_widget, const std::string &_name)
Definition: MyGUI_Widget.h:335
virtual void setVisible(bool _value)
Widget * getClientWidget()
virtual void onWidgetCreated(Widget *_widget)
void setNeedKeyFocus(bool _value)