MyGUI_MenuItem.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_MenuItem.h"
namespace MyGUI
{
void MenuItem::initialiseOverride()
{
Base::initialiseOverride();
// FIXME проверить смену скина ибо должно один раз вызываться
Widget* parent = getParent();
MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
if (!parent->isType<MenuControl>())
{
Widget* client = parent;
parent = client->getParent();
MYGUI_ASSERT(parent, "MenuItem must have parent MenuControl");
MYGUI_ASSERT(parent->getClientWidget() == client, "MenuItem must have parent MenuControl");
MYGUI_ASSERT(parent->isType<MenuControl>(), "MenuItem must have parent MenuControl");
}
mOwner = parent->castType<MenuControl>();
assignWidget(mCheck, "Check");
//if (isUserString("MinSize"))
// mMinSize = IntSize::parse(getUserString("MinSize"));
//FIXME нам нужен фокус клавы
setNeedKeyFocus(true);
updateCheck();
}
void MenuItem::shutdownOverride()
{
// FIXME проверить смену скина ибо должно один раз вызываться
mOwner->_notifyDeleteItem(this);
Base::shutdownOverride();
}
void MenuItem::onWidgetCreated(Widget* _widget)
{
Base::onWidgetCreated(_widget);
MenuControl* child = _widget->castType<MenuControl>(false);
if (child != nullptr)
{
mOwner->_wrapItemChild(this, child);
}
}
void MenuItem::setCaption(const UString& _value)
{
Button::setCaption(_value);
mOwner->_notifyUpdateName(this);
}
void MenuItem::setFontName(std::string_view _value)
{
Button::setFontName(_value);
if (!getCaption().empty())
mOwner->_notifyUpdateName(this);
}
void MenuItem::setFontHeight(int _value)
{
Button::setFontHeight(_value);
if (!getCaption().empty())
mOwner->_notifyUpdateName(this);
}
const UString& MenuItem::getItemName() const
{
return mOwner->getItemName(this);
}
void MenuItem::setItemName(const UString& _value)
{
mOwner->setItemName(this, _value);
}
void MenuItem::setItemData(Any _data)
{
mOwner->setItemData(this, _data);
}
void MenuItem::removeItem()
{
mOwner->removeItem(this);
}
void MenuItem::setItemId(std::string_view _id)
{
mOwner->setItemId(this, _id);
}
const std::string& MenuItem::getItemId() const
{
return mOwner->getItemId(this);
}
size_t MenuItem::getItemIndex() const
{
return mOwner->getItemIndex(this);
}
MenuControl* MenuItem::createItemChild()
{
return mOwner->createItemChild(this);
}
void MenuItem::setItemType(MenuItemType _type)
{
mOwner->setItemType(this, _type);
}
MenuItemType MenuItem::getItemType() const
{
return mOwner->getItemType(this);
}
void MenuItem::setItemChildVisible(bool _visible)
{
mOwner->setItemChildVisible(this, _visible);
}
MenuControl* MenuItem::getItemChild() const
{
return mOwner->getItemChild(this);
}
void MenuItem::setPropertyOverride(std::string_view _key, std::string_view _value)
{
if (_key == "MenuItemId")
setItemId(_value);
else if (_key == "MenuItemType")
setItemType(utility::parseValue<MenuItemType>(_value));
else if (_key == "MenuItemChecked")
setItemChecked(utility::parseValue<bool>(_value));
else
{
Base::setPropertyOverride(_key, _value);
return;
}
eventChangeProperty(this, _key, _value);
}
MenuControl* MenuItem::getMenuCtrlParent() const
{
return mOwner;
}
IItemContainer* MenuItem::_getItemContainer() const
{
return mOwner;
}
IntSize MenuItem::_getContentSize() const
{
ISubWidgetText* text = getSubWidgetText();
if (text == nullptr)
return mMinSize;
return text->getTextSize() + (getSize() - text->getSize());
}
void MenuItem::updateCheck()
{
if (mCheck != nullptr)
mCheck->setVisible(mCheckValue);
}
bool MenuItem::getItemChecked() const
{
return mCheckValue;
}
void MenuItem::setItemChecked(bool _value)
{
mCheckValue = _value;
updateCheck();
}
} // 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