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 проверить смену скина ибо должно один раз вызываться
19 MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
20 if (!parent->isType<MenuControl>())
21 {
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 {
53
54 MenuControl* child = _widget->castType<MenuControl>(false);
55 if (child != nullptr)
56 {
57 mOwner->_wrapItemChild(this, child);
58 }
59 }
60
62 {
64 mOwner->_notifyUpdateName(this);
65 }
66
67 void MenuItem::setFontName(std::string_view _value)
68 {
70 if (!getCaption().empty())
71 mOwner->_notifyUpdateName(this);
72 }
73
75 {
77 if (!getCaption().empty())
78 mOwner->_notifyUpdateName(this);
79 }
80
82 {
83 return mOwner->getItemName(this);
84 }
85
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")
146
148 else if (_key == "MenuItemType")
149 setItemType(utility::parseValue<MenuItemType>(_value));
150
152 else if (_key == "MenuItemChecked")
153 setItemChecked(utility::parseValue<bool>(_value));
154
155 else
156 {
158 return;
159 }
160
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
195 {
196 mCheckValue = _value;
197 updateCheck();
198 }
199
200} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
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 setItemId(MenuItem *_item, std::string_view _id)
Replace an item id.
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 setItemChildVisible(MenuItem *_item, bool _visible)
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
EventHandle_WidgetStringString eventChangeProperty
virtual void setVisible(bool _value)
void assignWidget(T *&_widget, std::string_view _name)
void setNeedKeyFocus(bool _value)