MyGUI: MyGUI_MenuItem.cpp Source File

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
13 void MenuItem::initialiseOverride()
14 {
15 Base::initialiseOverride();
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
42 void MenuItem::shutdownOverride()
43 {
44 // FIXME проверить смену скина ибо должно один раз вызываться
45 mOwner->_notifyDeleteItem(this);
46
47 Base::shutdownOverride();
48 }
49
50 void MenuItem::onWidgetCreated(Widget* _widget)
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 {
76 Button::setFontHeight(_value);
77 if (!getCaption().empty())
78 mOwner->_notifyUpdateName(this);
79 }
80
81 const UString& MenuItem::getItemName() const
82 {
83 return mOwner->getItemName(this);
84 }
85
86 void MenuItem::setItemName(const UString& _value)
87 {
88 mOwner->setItemName(this, _value);
89 }
90
91 void MenuItem::setItemData(Any _data)
92 {
93 mOwner->setItemData(this, _data);
94 }
95
96 void MenuItem::removeItem()
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
111 size_t MenuItem::getItemIndex() const
112 {
113 return mOwner->getItemIndex(this);
114 }
115
116 MenuControl* MenuItem::createItemChild()
117 {
118 return mOwner->createItemChild(this);
119 }
120
121 void MenuItem::setItemType(MenuItemType _type)
122 {
123 mOwner->setItemType(this, _type);
124 }
125
126 MenuItemType MenuItem::getItemType() const
127 {
128 return mOwner->getItemType(this);
129 }
130
131 void MenuItem::setItemChildVisible(bool _visible)
132 {
133 mOwner->setItemChildVisible(this, _visible);
134 }
135
136 MenuControl* MenuItem::getItemChild() const
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")
149 setItemType(utility::parseValue<MenuItemType>(_value));
150
152 else if (_key == "MenuItemChecked")
153 setItemChecked(utility::parseValue<bool>(_value));
154
155 else
156 {
157 Base::setPropertyOverride(_key, _value);
158 return;
159 }
160
161 eventChangeProperty(this, _key, _value);
162 }
163
164 MenuControl* MenuItem::getMenuCtrlParent() const
165 {
166 return mOwner;
167 }
168
169 IItemContainer* MenuItem::_getItemContainer() const
170 {
171 return mOwner;
172 }
173
174 IntSize MenuItem::_getContentSize() const
175 {
176 ISubWidgetText* text = getSubWidgetText();
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
189 bool MenuItem::getItemChecked() const
190 {
191 return mCheckValue;
192 }
193
194 void MenuItem::setItemChecked(bool _value)
195 {
196 mCheckValue = _value;
197 updateCheck();
198 }
199
200} // namespace MyGUI
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
MyGUI_Precompiled.h
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition MyGUI_ICroppedRectangle.h:51
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:19
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize() const
Definition MyGUI_ISubWidgetText.h:122
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText() const
Definition MyGUI_SkinItem.cpp:148
MyGUI::TextBox::setCaption
virtual void setCaption(const UString &_caption)
Definition MyGUI_TextBox.cpp:73
MyGUI::TextBox::getCaption
virtual const UString & getCaption() const
Definition MyGUI_TextBox.cpp:79
MyGUI::TextBox::setFontName
virtual void setFontName(std::string_view _value)
Definition MyGUI_TextBox.cpp:49
MyGUI::TextBox::setFontHeight
virtual void setFontHeight(int _height)
Definition MyGUI_TextBox.cpp:62
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:144
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::getParent
Widget * getParent() const
Definition MyGUI_Widget.cpp:1352
MyGUI::Widget::isType
virtual bool isType(const std::type_info &_type) const override
Definition MyGUI_Widget.h:44
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::Widget::setVisible
virtual void setVisible(bool _value)
Definition MyGUI_Widget.cpp:1022
MyGUI::Widget::getClientWidget
Widget * getClientWidget()
Definition MyGUI_Widget.cpp:1367
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, std::string_view _name)
Definition MyGUI_Widget.h:413
MyGUI::WidgetInput::setNeedKeyFocus
void setNeedKeyFocus(bool _value)
Definition MyGUI_WidgetInput.cpp:142
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30