29 mHideByLostKey(false),
30 mResizeToContent(true),
32 mVerticalAlignment(true),
36 mAnimateSmooth(false),
37 mChangeChildSkin(false),
39 mInternalCreateChild(false)
45 Base::initialiseOverride();
68 if (mClient !=
nullptr)
77 mItemPopupSkin = mItemNormalSkin;
90 mDistanceButton = utility::parseValue<int>(
getUserString(
"DistanceButton"));
106 if (mOwner !=
nullptr)
109 Base::shutdownOverride();
114 Base::onWidgetCreated(_widget);
117 if (child !=
nullptr && !mInternalCreateChild)
126 if (_index ==
ITEM_NONE) _index = mItemsInfo.size();
128 mInternalCreateChild =
true;
130 mInternalCreateChild =
false;
131 _wrapItem(item, _index, _name, _type, _id, _data);
140 if (mItemsInfo[_index].submenu)
143 mItemsInfo[_index].submenu =
nullptr;
150 while (!mItemsInfo.empty())
152 if (mItemsInfo.back().submenu)
155 mItemsInfo.back().submenu =
nullptr;
164 return mItemsInfo[_index].name;
167 void MenuControl::update()
171 if (mVerticalAlignment)
173 for (VectorMenuItemInfo::iterator iter = mItemsInfo.begin(); iter != mItemsInfo.end(); ++iter)
175 IntSize contentSize = iter->item->_getContentSize();
182 if (!mItemsInfo.empty())
183 size.
height -= mDistanceButton;
188 for (VectorMenuItemInfo::iterator iter = mItemsInfo.begin(); iter != mItemsInfo.end(); ++iter)
190 IntSize contentSize = iter->item->_getContentSize();
191 if (maxHeight < contentSize.height)
192 maxHeight = contentSize.
height;
195 for (VectorMenuItemInfo::iterator iter = mItemsInfo.begin(); iter != mItemsInfo.end(); ++iter)
197 IntSize contentSize = iter->item->_getContentSize();
198 iter->item->setCoord(size.
width, 0, contentSize.width, maxHeight);
199 size.
width += contentSize.width + mDistanceButton;
202 if (!mItemsInfo.empty())
203 size.
width -= mDistanceButton;
213 mItemsInfo[_index].data = _data;
219 return mItemsInfo[_index].submenu;
226 if (mItemsInfo[_index].submenu !=
nullptr)
229 mItemsInfo[_index].submenu =
nullptr;
239 mItemsInfo[_index].name = _name;
240 MenuItem* item = mItemsInfo[_index].item;
249 mItemsInfo[_index].id = _id;
255 return mItemsInfo[_index].id;
261 if (mChangeChildSkin)
269 mItemsInfo.erase(mItemsInfo.begin() + index);
276 mItemsInfo[index].submenu =
nullptr;
292 return mItemsInfo[_index].type;
298 ItemInfo& info = mItemsInfo[_index];
299 if (info.type == _type)
306 mChangeChildSkin =
true;
307 info.item->changeWidgetSkin(getSkinByType(_type));
308 mChangeChildSkin =
false;
310 info.item->setImageName(getIconIndexByType(_type ));
311 info.item->setCaption(info.name);
316 void MenuControl::notifyMenuCtrlAccept(
MenuItem* _item)
330 MenuControl* parent_ctrl = parent_item->getMenuCtrlParent();
333 parent_ctrl->notifyMenuCtrlAccept(_item);
342 _setItemChildVisibleAt(_index, _visible,
true);
345 void MenuControl::_setItemChildVisibleAt(
size_t _index,
bool _visible,
bool _smooth)
351 if (mItemsInfo[_index].submenu && mItemsInfo[_index].submenu->getItemCount())
353 int offset = mItemsInfo[0].item->getAbsoluteTop() -
getAbsoluteTop();
355 const IntCoord& coord = mItemsInfo[_index].item->getAbsoluteCoord();
360 if (mVerticalAlignment)
399 if (mItemsInfo[_index].submenu)
402 mItemsInfo[_index].submenu->setVisibleSmooth(
false);
404 mItemsInfo[_index].submenu->setVisible(
false);
409 void MenuControl::notifyRootKeyChangeFocus(Widget* _sender,
bool _focus)
411 MenuItem* item = _sender->castType<MenuItem>();
418 item->setItemChildVisible(
true);
419 item->setStateSelected(
true);
424 item->setItemChildVisible(
false);
425 item->setStateSelected(
false);
430 Widget* MenuControl::createItemChildByType(
size_t _index,
const std::string& _type)
439 void MenuControl::notifyMouseButtonClick(Widget* _sender)
441 MenuItem* item = _sender->castType<MenuItem>();
448 item->setStateSelected(
false);
449 item->setItemChildVisible(
false);
458 item->setStateSelected(
true);
459 item->setItemChildVisible(
true);
469 notifyMenuCtrlAccept(item);
485 Base::onKeyChangeRootFocus(_focus);
488 void MenuControl::notifyMouseSetFocus(
Widget* _sender,
Widget* _new)
497 if (mItemsInfo[index].submenu !=
nullptr)
500 mItemsInfo[index].submenu =
nullptr;
502 mItemsInfo[index].submenu = _widget;
504 mItemsInfo[index].submenu->setVisible(
false);
520 ItemInfo info = ItemInfo(_item, _name, _type, submenu, _id, _data);
522 mItemsInfo.insert(mItemsInfo.begin() + _index, info);
524 mChangeChildSkin =
true;
526 mChangeChildSkin =
false;
541 mAnimateSmooth =
false;
552 Base::setVisible(_visible);
557 mAnimateSmooth =
true;
566 Base::setVisible(
true);
583 ControllerFadeAlpha* MenuControl::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
613 return mItemsInfo[_index].item;
618 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
620 if (mItemsInfo[pos].item == _item)
623 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'MenuControl::getItemIndex'");
628 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
630 if (mItemsInfo[pos].name == _name)
631 return mItemsInfo[pos].item;
638 for (
size_t index = 0; index < mItemsInfo.size(); index++)
640 if (mItemsInfo[index].
id == _id)
641 return mItemsInfo[index].item;
643 MYGUI_EXCEPT(
"item id (" << _id <<
") not found, source 'MenuControl::getItemById'");
648 for (
size_t index = 0; index < mItemsInfo.size(); index++)
650 if (mItemsInfo[index].
id == _id)
653 MYGUI_EXCEPT(
"item id (" << _id <<
") not found, source 'MenuControl::getItemById'");
658 for (
size_t index = 0; index < mItemsInfo.size(); index++)
660 if (mItemsInfo[index].
id == _id)
661 return mItemsInfo[index].item;
663 if (_recursive && mItemsInfo[index].submenu !=
nullptr)
665 MenuItem* find = mItemsInfo[index].submenu->findItemById(_id, _recursive);
675 for (
size_t index = 0; index < mItemsInfo.size(); index++)
677 if (mItemsInfo[index].name == _name)
685 for (
size_t index = 0; index < mItemsInfo.size(); index++)
687 if (mItemsInfo[index].item == _item)
693 Widget* MenuControl::_getClientWidget()
695 return mClient ==
nullptr ?
this : mClient;
700 return mItemsInfo.size();
750 return createItemChildTAt<MenuControl>(_index);
775 mPopupAccept = _value;
788 const std::string& MenuControl::getSkinByType(
MenuItemType _type)
const
791 return mItemPopupSkin;
793 return mItemSeparatorSkin;
794 return mItemNormalSkin;
797 std::string MenuControl::getIconIndexByType(MenuItemType _type)
const
848 for (VectorMenuItemInfo::iterator iter = mItemsInfo.begin(); iter != mItemsInfo.end(); ++iter)
854 if ((*iter).submenu !=
nullptr)
855 (*iter).submenu->setVisible(
false);
864 _setItemChildVisibleAt(index,
true,
false);
872 if (mItemsInfo[_index].submenu !=
nullptr)
873 mItemsInfo[_index].submenu->_updateSizeForEmpty();
878 if (mItemsInfo.empty())
884 mVerticalAlignment = _value;
891 return mVerticalAlignment;
897 if (_key ==
"VerticalAlignment")
902 Base::setPropertyOverride(_key, _value);