MyGUI 3.4.3
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 {
16
17 // FIXME проверить смену скина ибо должно один раз вызываться
18 Widget* parent = getParent();
19 MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
20 if (!parent->isType<MenuControl>())
21 {
22 Widget* client = parent;
23 parent = client->getParent();
24 MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
25 MYGUI_ASSERT(parent->getClientWidget() == client, "MenuItem must have parent MenuControl");
26 MYGUI_ASSERT(parent->isType<MenuControl>(), "MenuItem must have parent MenuControl");
27 }
28 mOwner = parent->castType<MenuControl>();
29
31 assignWidget(mCheck, "Check");
32
33 //if (isUserString("MinSize"))
34 // mMinSize = IntSize::parse(getUserString("MinSize"));
35
36 //FIXME нам нужен фокус клавы
37 setNeedKeyFocus(true);
38
39 updateCheck();
40 }
41
43 {
44 // FIXME проверить смену скина ибо должно один раз вызываться
45 mOwner->_notifyDeleteItem(this);
46
48 }
49
51 {
52 Base::onWidgetCreated(_widget);
53
54 MenuControl* child = _widget->castType<MenuControl>(false);
55 if (child != nullptr)
56 {
57 mOwner->_wrapItemChild(this, child);
58 }
59 }
60
61 void MenuItem::setCaption(const UString& _value)
62 {
63 Button::setCaption(_value);
64 mOwner->_notifyUpdateName(this);
65 }
66
67 void MenuItem::setFontName(std::string_view _value)
68 {
69 Button::setFontName(_value);
70 if (!getCaption().empty())
71 mOwner->_notifyUpdateName(this);
72 }
73
74 void MenuItem::setFontHeight(int _value)
75 {
77 if (!getCaption().empty())
78 mOwner->_notifyUpdateName(this);
79 }
80
82 {
83 return mOwner->getItemName(this);
84 }
85
86 void MenuItem::setItemName(const UString& _value)
87 {
88 mOwner->setItemName(this, _value);
89 }
90
92 {
93 mOwner->setItemData(this, _data);
94 }
95
97 {
98 mOwner->removeItem(this);
99 }
100
101 void MenuItem::setItemId(std::string_view _id)
102 {
103 mOwner->setItemId(this, _id);
104 }
105
106 const std::string& MenuItem::getItemId() const
107 {
108 return mOwner->getItemId(this);
109 }
110
112 {
113 return mOwner->getItemIndex(this);
114 }
115
117 {
118 return mOwner->createItemChild(this);
119 }
120
122 {
123 mOwner->setItemType(this, _type);
124 }
125
127 {
128 return mOwner->getItemType(this);
129 }
130
132 {
133 mOwner->setItemChildVisible(this, _visible);
134 }
135
137 {
138 return mOwner->getItemChild(this);
139 }
140
141 void MenuItem::setPropertyOverride(std::string_view _key, std::string_view _value)
142 {
144 if (_key == "MenuItemId")
145 setItemId(_value);
146
148 else if (_key == "MenuItemType")
150
152 else if (_key == "MenuItemChecked")
154
155 else
156 {
157 Base::setPropertyOverride(_key, _value);
158 return;
159 }
160
161 eventChangeProperty(this, _key, _value);
162 }
163
165 {
166 return mOwner;
167 }
168
170 {
171 return mOwner;
172 }
173
175 {
177 if (text == nullptr)
178 return mMinSize;
179
180 return text->getTextSize() + (getSize() - text->getSize());
181 }
182
183 void MenuItem::updateCheck()
184 {
185 if (mCheck != nullptr)
186 mCheck->setVisible(mCheckValue);
187 }
188
190 {
191 return mCheckValue;
192 }
193
194 void MenuItem::setItemChecked(bool _value)
195 {
196 mCheckValue = _value;
197 updateCheck();
198 }
199
200} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
Type * castType(bool _throw=true)
virtual IntSize getTextSize() const
widget description should be here.
MenuControl * createItemChild(MenuItem *_item)
MenuControl * getItemChild(const MenuItem *_item) const
void setItemType(MenuItem *_item, MenuItemType _type)
const std::string & getItemId() const
Get item id from specified position.
void setCaption(const UString &_value) override
MenuControl * createItemChild()
void setItemChecked(bool _value)
void setItemId(std::string_view _id)
Replace an item id at a specified position.
MenuControl * getMenuCtrlParent() const
MenuControl * getItemChild() const
IntSize _getContentSize() const
void initialiseOverride() override
bool getItemChecked() const
void setItemChildVisible(bool _visible)
void setItemName(const UString &_value)
Replace an item name.
void setFontName(std::string_view _value) override
void setItemType(MenuItemType _type)
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 setItemData(Any _data)
Replace an item name.
void removeItem()
Remove item.
void setFontHeight(int _value) override
void setPropertyOverride(std::string_view _key, std::string_view _value) override
ISubWidgetText * getSubWidgetText() const
virtual void setCaption(const UString &_caption)
virtual const UString & getCaption() const
virtual void setFontName(std::string_view _value)
virtual void setFontHeight(int _height)
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
widget description should be here.
Widget * getParent() const
virtual bool isType(const std::type_info &_type) const override
EventHandle_WidgetStringString eventChangeProperty
virtual void setVisible(bool _value)
Widget * getClientWidget()
void assignWidget(T *&_widget, std::string_view _name)
void setNeedKeyFocus(bool _value)
T parseValue(std::string_view _value)
types::TSize< int > IntSize
Definition MyGUI_Types.h:30