MyGUI
3.2.1
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
mygui
MyGUIEngine
src
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
10
namespace
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
()
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
()
115
{
116
return
mOwner->
getItemId
(
this
);
117
}
118
119
size_t
MenuItem::getItemIndex
()
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
()
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
()
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
()
173
{
174
return
mOwner;
175
}
176
177
IItemContainer
*
MenuItem::_getItemContainer
()
178
{
179
return
mOwner;
180
}
181
182
IntSize
MenuItem::_getContentSize
()
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
Generated on Wed Aug 20 2014 00:03:33 for MyGUI by
1.8.3.1