MyGUI  3.2.0
MyGUI_MenuItem.cpp
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_MenuItem.h"
24 
25 namespace MyGUI
26 {
27 
29  mOwner(nullptr),
30  mMinSize(10, 10),
31  mCheck(nullptr),
32  mCheckValue(false)
33  {
34  }
35 
37  {
39 
40  // FIXME проверить смену скина ибо должно один раз вызываться
41  Widget* parent = getParent();
42  MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
43  if (!parent->isType<MenuControl>())
44  {
45  Widget* client = parent;
46  parent = client->getParent();
47  MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
48  MYGUI_ASSERT(parent->getClientWidget() == client, "MenuItem must have parent MenuControl");
49  MYGUI_ASSERT(parent->isType<MenuControl>(), "MenuItem must have parent MenuControl");
50  }
51  mOwner = parent->castType<MenuControl>();
52 
53  assignWidget(mCheck, "Check");
54 
55  //if (isUserString("MinSize"))
56  // mMinSize = IntSize::parse(getUserString("MinSize"));
57 
58  //FIXME нам нуженфокус клавы
59  setNeedKeyFocus(true);
60 
61  updateCheck();
62  }
63 
65  {
66  // FIXME проверить смену скина ибо должно один раз вызываться
67  mOwner->_notifyDeleteItem(this);
68 
70  }
71 
73  {
74  Base::onWidgetCreated(_widget);
75 
76  MenuControl* child = _widget->castType<MenuControl>(false);
77  if (child != nullptr)
78  {
79  mOwner->_wrapItemChild(this, child);
80  }
81  }
82 
83  void MenuItem::setCaption(const UString& _value)
84  {
85  Button::setCaption(_value);
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()
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 
139  void MenuItem::setItemChildVisible(bool _visible)
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  {
151  if (_key == "MenuItemId")
152  setItemId(_value);
153  else if (_key == "MenuItemType")
154  setItemType(utility::parseValue<MenuItemType>(_value));
155  else if (_key == "MenuItemChecked")
156  setItemChecked(utility::parseValue<bool>(_value));
157  else
158  {
159  Base::setPropertyOverride(_key, _value);
160  return;
161  }
162  eventChangeProperty(this, _key, _value);
163  }
164 
166  {
167  return mOwner;
168  }
169 
171  {
172  return mOwner;
173  }
174 
176  {
178  if (text == nullptr)
179  return mMinSize;
180 
181  return text->getTextSize() + (getSize() - text->getSize());
182  }
183 
184  void MenuItem::updateCheck()
185  {
186  if (mCheck != nullptr)
187  mCheck->setVisible(mCheckValue);
188  }
189 
191  {
192  return mCheckValue;
193  }
194 
195  void MenuItem::setItemChecked(bool _value)
196  {
197  mCheckValue = _value;
198  updateCheck();
199  }
200 
201 } // namespace MyGUI