• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_MenuCtrl.cpp

Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009     
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014     
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019     
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_MenuCtrl.h"
00025 #include "MyGUI_ResourceSkin.h"
00026 #include "MyGUI_MenuItem.h"
00027 #include "MyGUI_StaticImage.h"
00028 #include "MyGUI_MenuBar.h"
00029 #include "MyGUI_WidgetManager.h"
00030 #include "MyGUI_LayerManager.h"
00031 #include "MyGUI_ControllerManager.h"
00032 #include "MyGUI_InputManager.h"
00033 #include "MyGUI_Gui.h"
00034 
00035 namespace MyGUI
00036 {
00037 
00038     const float POPUP_MENU_SPEED_COEF = 3.0f;
00039 
00040     MenuCtrl::MenuCtrl() :
00041         mHideByAccept(true),
00042         mMenuDropMode(false),
00043         mIsMenuDrop(true),
00044         mHideByLostKey(false),
00045         mHeightLine(1),
00046         mSubmenuImageSize(0),
00047         mShutdown(false),
00048         mSeparatorHeight(0),
00049         mAlignVert(true),
00050         mDistanceButton(0),
00051         mPopupAccept(false),
00052         mOwner(nullptr),
00053         mAnimateSmooth(false)
00054     {
00055     }
00056 
00057     void MenuCtrl::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, WidgetPtr _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name)
00058     {
00059         Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name);
00060 
00061         // инициализируем овнера
00062         WidgetPtr parent = getParent();
00063         if (parent)
00064         {
00065             mOwner = parent->castType<MenuItem>(false);
00066             if ( ! mOwner )
00067             {
00068                 WidgetPtr client = parent;
00069                 parent = client->getParent();
00070                 if (parent && parent->getClientWidget())
00071                 {
00072                     mOwner = parent->castType<MenuItem>(false);
00073                 }
00074             }
00075         }
00076 
00077         initialiseWidgetSkin(_info);
00078     }
00079 
00080     MenuCtrl::~MenuCtrl()
00081     {
00082         mShutdown = true;
00083         shutdownWidgetSkin();
00084     }
00085 
00086     void MenuCtrl::baseChangeWidgetSkin(ResourceSkin* _info)
00087     {
00088         shutdownWidgetSkin();
00089         Base::baseChangeWidgetSkin(_info);
00090         initialiseWidgetSkin(_info);
00091     }
00092 
00093     void MenuCtrl::initialiseWidgetSkin(ResourceSkin* _info)
00094     {
00095         // нам нужен фокус клавы
00096         mNeedKeyFocus = true;
00097 
00098         for (VectorWidgetPtr::iterator iter=mWidgetChildSkin.begin(); iter!=mWidgetChildSkin.end(); ++iter)
00099         {
00100             if (*(*iter)->_getInternalData<std::string>() == "Client")
00101             {
00102                 MYGUI_DEBUG_ASSERT( ! mWidgetClient, "widget already assigned");
00103                 mWidgetClient = (*iter);
00104             }
00105         }
00106         MYGUI_ASSERT(nullptr != mWidgetClient, "Child Widget Client not found in skin (MenuCtrl must have Client)");
00107 
00108         // парсим свойства
00109         const MapString& properties = _info->getProperties();
00110         MapString::const_iterator iterS = properties.find("SkinLine");
00111         if (iterS != properties.end()) mSkinLine = iterS->second;
00112         MYGUI_ASSERT(false == mSkinLine.empty(), "SkinLine property not found (MenuCtrl must have SkinLine property)");
00113 
00114         iterS = properties.find("HeightLine");
00115         if (iterS != properties.end()) mHeightLine = utility::parseInt(iterS->second);
00116         if (mHeightLine < 1)
00117         {
00118             MYGUI_LOG(Warning, "MenuCtrl HeightLine can't be less thah 1. Set to 1.");
00119             mHeightLine = 1;
00120         }
00121 
00122         iterS = properties.find("SeparatorHeight");
00123         if (iterS != properties.end()) mSeparatorHeight = utility::parseInt(iterS->second);
00124         iterS = properties.find("SeparatorSkin");
00125         if (iterS != properties.end()) mSeparatorSkin = iterS->second;
00126 
00127         iterS = properties.find("SubmenuImageSize");
00128         if (iterS != properties.end()) mSubmenuImageSize = utility::parseInt(iterS->second);
00129 
00130         iterS = properties.find("SubMenuSkin");
00131         if (iterS != properties.end()) mSubMenuSkin = iterS->second;
00132         MYGUI_ASSERT(false == mSubMenuSkin.empty(), "SubMenuSkin property not found (MenuCtrl must have SubMenuSkin property)");
00133 
00134         iterS = properties.find("SubMenuLayer");
00135         if (iterS != properties.end()) mSubMenuLayer = iterS->second;
00136         MYGUI_ASSERT(false == mSubMenuLayer.empty(), "SubMenuLayer property not found (MenuCtrl must have SubMenuLayer property)");
00137 
00138         iterS = properties.find("AlignVert");
00139         if (iterS != properties.end()) mAlignVert = utility::parseBool(iterS->second);
00140         iterS = properties.find("DistanceButton");
00141         if (iterS != properties.end()) mDistanceButton = utility::parseInt(iterS->second);
00142 
00143         if (mSeparatorHeight < 1) mSeparatorHeight = mHeightLine;
00144     }
00145 
00146     void MenuCtrl::shutdownWidgetSkin()
00147     {
00148         mWidgetClient = nullptr;
00149     }
00150 
00151     WidgetPtr MenuCtrl::baseCreateWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name)
00152     {
00153         WidgetPtr widget = mWidgetClient->createWidgetT(_style, _type, _skin, _coord, _align, _layer, _name);
00154         MenuItemPtr child = widget->castType<MenuItem>(false);
00155         if (child)
00156         {
00157             _wrapItem(child, mItemsInfo.size(), "", MenuItemType::Normal, "", Any::Null);
00158         }
00159         return widget;
00160     }
00161 
00162     MenuItemPtr MenuCtrl::insertItemAt(size_t _index, const UString& _name, MenuItemType _type, const std::string& _id, Any _data)
00163     {
00164         MYGUI_ASSERT_RANGE_INSERT(_index, mItemsInfo.size(), "MenuCtrl::insertItemAt");
00165         if (_index == ITEM_NONE) _index = mItemsInfo.size();
00166 
00167         MenuItemPtr item = mWidgetClient->createWidget<MenuItem>(getSkinByType(_type), IntCoord(), Align::Default);
00168         _wrapItem(item, _index, _name, _type, _id, _data);
00169 
00170         return item;
00171     }
00172 
00173     void MenuCtrl::removeItemAt(size_t _index)
00174     {
00175         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::removeItemAt");
00176 
00177         if ( mItemsInfo[_index].submenu )
00178         {
00179             WidgetManager::getInstance().destroyWidget(mItemsInfo[_index].submenu);
00180         }
00181         WidgetManager::getInstance().destroyWidget(mItemsInfo[_index].item);
00182     }
00183 
00184     void MenuCtrl::removeAllItems()
00185     {
00186         while (mItemsInfo.size() > 0)
00187         {
00188             if ( mItemsInfo.back().submenu )
00189             {
00190                 WidgetManager::getInstance().destroyWidget(mItemsInfo.back().submenu);
00191             }
00192             WidgetManager::getInstance().destroyWidget(mItemsInfo.back().item);
00193         }
00194     }
00195 
00196     const UString& MenuCtrl::getItemNameAt(size_t _index)
00197     {
00198         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::getItemNameAt");
00199         return mItemsInfo[_index].name;
00200     }
00201 
00202     void MenuCtrl::setButtonImageIndex(ButtonPtr _button, size_t _index)
00203     {
00204         StaticImagePtr image = _button->getStaticImage();
00205         if ( nullptr == image ) return;
00206         if (image->getItemResource())
00207         {
00208             static const size_t CountIcons = 2;
00209             static const char * IconNames[CountIcons + 1] = { "None", "Popup", "" };
00210             if (_index >= CountIcons) _index = CountIcons;
00211             image->setItemName(IconNames[_index]);
00212         }
00213         else
00214         {
00215             image->setItemSelect(_index);
00216         }
00217     }
00218 
00219     void MenuCtrl::update()
00220     {
00221         IntSize size;
00222 
00223         if (mAlignVert)
00224         {
00225             for (VectorMenuItemInfo::iterator iter=mItemsInfo.begin(); iter!=mItemsInfo.end(); ++iter)
00226             {
00227                 int height = iter->type == MenuItemType::Separator ? mSeparatorHeight : mHeightLine;
00228                 iter->item->setCoord(0, size.height, this->mWidgetClient->getWidth(), height);
00229                 size.height += height + mDistanceButton;
00230 
00231                 int width = iter->width;
00232                 if (width > size.width) size.width = width;
00233             }
00234 
00235         }
00236         else
00237         {
00238             for (VectorMenuItemInfo::iterator iter=mItemsInfo.begin(); iter!=mItemsInfo.end(); ++iter)
00239             {
00240                 int width = iter->type == MenuItemType::Separator ? mSeparatorHeight : iter->width;
00241                 iter->item->setCoord(size.width, 0, width, mHeightLine);
00242                 size.width += width + mDistanceButton;
00243             }
00244             size.height = mHeightLine;
00245             size.width = mCoord.width;
00246         }
00247 
00248         setSize(size + mCoord.size() - mWidgetClient->getSize());
00249     }
00250 
00251     void MenuCtrl::setItemDataAt(size_t _index, Any _data)
00252     {
00253         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::setItemDataAt");
00254         mItemsInfo[_index].data = _data;
00255     }
00256 
00257     MenuCtrlPtr MenuCtrl::getItemChildAt(size_t _index)
00258     {
00259         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::getItemChildAt");
00260         return mItemsInfo[_index].submenu;
00261     }
00262 
00263     void MenuCtrl::removeItemChildAt(size_t _index)
00264     {
00265         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::removeItemChildAt");
00266 
00267         if (mItemsInfo[_index].submenu != nullptr)
00268         {
00269             WidgetManager::getInstance().destroyWidget(mItemsInfo[_index].submenu);
00270             mItemsInfo[_index].submenu = nullptr;
00271         }
00272 
00273         update();
00274     }
00275 
00276     void MenuCtrl::setItemNameAt(size_t _index, const UString& _name)
00277     {
00278         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::setItemNameAt");
00279 
00280         mItemsInfo[_index].name = _name;
00281         MenuItemPtr item = mItemsInfo[_index].item;
00282         item->setCaption(_name);
00283 
00284         update();
00285     }
00286 
00287     void MenuCtrl::setItemIdAt(size_t _index, const std::string& _id)
00288     {
00289         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::setItemIdAt");
00290         mItemsInfo[_index].id = _id;
00291     }
00292 
00293     const std::string& MenuCtrl::getItemIdAt(size_t _index)
00294     {
00295         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::getItemIdAt");
00296         return mItemsInfo[_index].id;
00297     }
00298 
00299     void MenuCtrl::_notifyDeleteItem(MenuItemPtr _item)
00300     {
00301         // общий шутдаун виджета
00302         if (mShutdown) return;
00303 
00304         size_t index = getItemIndex(_item);
00305         mItemsInfo.erase(mItemsInfo.begin() + index);
00306         update();
00307     }
00308 
00309     void MenuCtrl::_notifyUpdateName(MenuItemPtr _item)
00310     {
00311         size_t index = getItemIndex(_item);
00312         mItemsInfo[index].name = _item->getCaption();
00313 
00314         ISubWidgetText* text = _item->getSubWidgetText();
00315         mItemsInfo[index].width = text ? (text->getTextSize().width + _item->getSize().width - text->getWidth()) : 0;
00316         update();
00317     }
00318 
00319     MenuItemType MenuCtrl::getItemTypeAt(size_t _index)
00320     {
00321         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::getItemTypeAt");
00322         return mItemsInfo[_index].type;
00323     }
00324 
00325     void MenuCtrl::setItemTypeAt(size_t _index, MenuItemType _type)
00326     {
00327         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::setItemTypeAt");
00328         ItemInfo& info = mItemsInfo[_index];
00329         if (info.type == _type) return;
00330 
00331         // сохраняем данные
00332         info.type = _type;
00333         info.item->changeWidgetSkin(getSkinByType(_type));
00334         setButtonImageIndex(info.item, getIconIndexByType(_type ));
00335         info.item->setCaption(info.name);
00336 
00337         update();
00338     }
00339 
00340     void MenuCtrl::notifyMenuCtrlAccept(MenuItemPtr _item)
00341     {
00342         WidgetPtr sender = this;
00343 
00344         WidgetManager::getInstance().addWidgetToUnlink(sender);
00345         eventMenuCtrlAccept(this, _item);
00346         WidgetManager::getInstance().removeWidgetFromUnlink(sender);
00347 
00348         // нас удалили
00349         if (sender == nullptr) return;
00350 
00351         WidgetManager::getInstance().addWidgetToUnlink(sender);
00352 
00353         MenuItemPtr parent_item = getMenuItemParent();
00354         if (parent_item)
00355         {
00356             MenuCtrlPtr parent_ctrl = parent_item->getMenuCtrlParent();
00357             if (parent_ctrl)
00358             {
00359                 parent_ctrl->notifyMenuCtrlAccept(_item);
00360             }
00361         }
00362 
00363         WidgetManager::getInstance().removeWidgetFromUnlink(sender);
00364 
00365         // нас удалили
00366         if (sender == nullptr) return;
00367 
00368 
00369         if (mHideByAccept)
00370         {
00371             setVisibleSmooth(false);
00372             // блокируем
00373             /*setEnabledSilent(false);
00374             // медленно скрываем
00375             ControllerFadeAlpha * controller = new ControllerFadeAlpha(ALPHA_MIN, POPUP_MENU_SPEED_COEF, false);
00376             controller->eventPostAction = newDelegate(this, &MenuCtrl::actionWidgetHide);
00377             ControllerManager::getInstance().addItem(this, controller);*/
00378         }
00379         else
00380         {
00381             InputManager::getInstance().setKeyFocusWidget(nullptr);
00382         }
00383     }
00384 
00385     void MenuCtrl::setItemChildVisibleAt(size_t _index, bool _visible)
00386     {
00387         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::setItemChildVisibleAt");
00388 
00389         if (_visible)
00390         {
00391             if (mItemsInfo[_index].submenu && mItemsInfo[_index].submenu->getItemCount())
00392             {
00393 
00394                 int offset = mItemsInfo[0].item->getAbsoluteTop() - this->getAbsoluteTop();
00395 
00396                 const IntCoord& coord = mItemsInfo[_index].item->getAbsoluteCoord();
00397                 IntPoint point(this->getAbsoluteRect().right, coord.top - offset);
00398 
00399                 MenuCtrlPtr menu = mItemsInfo[_index].submenu;
00400 
00401                 if (this->mAlignVert)
00402                 {
00403                     if (point.left + menu->getWidth() > MyGUI::Gui::getInstance().getViewSize().width)
00404                         point.left -= menu->getWidth();
00405                     if (point.top + menu->getHeight() > MyGUI::Gui::getInstance().getViewSize().height)
00406                         point.top -= menu->getHeight();
00407                 }
00408                 else
00409                 {
00410                     point.set(coord.left, this->getAbsoluteRect().bottom);
00411                 }
00412 
00413                 menu->setPosition(point);
00414                 menu->setVisibleSmooth(true);
00415             }
00416         }
00417         else
00418         {
00419             if (mItemsInfo[_index].submenu)
00420             {
00421                 mItemsInfo[_index].submenu->setVisibleSmooth(false);
00422             }
00423         }
00424     }
00425 
00426     void MenuCtrl::notifyRootKeyChangeFocus(WidgetPtr _sender, bool _focus)
00427     {
00428         MenuItemPtr item = _sender->castType<MenuItem>();
00429         if (item->getItemType() == MenuItemType::Popup)
00430         {
00431             if (_focus)
00432             {
00433                 if (!mMenuDropMode || mIsMenuDrop)
00434                 {
00435                     item->setItemChildVisible(true);
00436                     item->setButtonPressed(true);
00437                 }
00438             }
00439             else
00440             {
00441                 item->setItemChildVisible(false);
00442                 item->setButtonPressed(false);
00443             }
00444         }
00445     }
00446 
00447     WidgetPtr MenuCtrl::createItemChildByType(size_t _index, const std::string& _type)
00448     {
00449         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::createItemChildByType");
00450         removeItemChildAt(_index);
00451         WidgetPtr child = mItemsInfo[_index].item->createWidgetT(WidgetStyle::Popup, _type, mSubMenuSkin, IntCoord(), Align::Default, mSubMenuLayer);
00452         MYGUI_ASSERT(child->isType<MenuCtrl>(), "child must have MenuCtrl base type");
00453         return child;
00454     }
00455 
00456     void MenuCtrl::notifyMouseButtonClick(WidgetPtr _sender)
00457     {
00458         MenuItemPtr item = _sender->castType<MenuItem>();
00459         if (mMenuDropMode)
00460         {
00461             if (mIsMenuDrop)
00462             {
00463                 if (item->getItemType() == MenuItemType::Popup)
00464                 {
00465                     item->setButtonPressed(false);
00466                     item->setItemChildVisible(false);
00467                     mIsMenuDrop = false;
00468                 }
00469             }
00470             else
00471             {
00472                 if (item->getItemType() == MenuItemType::Popup)
00473                 {
00474                     mIsMenuDrop = true;
00475                     item->setButtonPressed(true);
00476                     item->setItemChildVisible(true);
00477                     InputManager::getInstance().setKeyFocusWidget(item);
00478                 }
00479             }
00480         }
00481         else
00482         {
00483             if ((item->getItemType() == MenuItemType::Popup && mPopupAccept) ||
00484                 item->getItemType() == MenuItemType::Normal)
00485             {
00486                 notifyMenuCtrlAccept(item);
00487             }
00488         }
00489 
00490     }
00491 
00492     void MenuCtrl::onKeyChangeRootFocus(bool _focus)
00493     {
00494         if (mMenuDropMode)
00495         {
00496             mIsMenuDrop = false;
00497         }
00498         if ( ! _focus && mHideByLostKey)
00499         {
00500             setVisibleSmooth(false);
00501             eventMenuCtrlClose(this);
00502         }
00503         Base::onKeyChangeRootFocus(_focus);
00504     }
00505 
00506     void MenuCtrl::notifyMouseSetFocus(WidgetPtr _sender, WidgetPtr _new)
00507     {
00508         // unused
00509         //MenuItemPtr item = _sender->castType<MenuItem>();
00510         InputManager::getInstance().setKeyFocusWidget(_sender);
00511     }
00512 
00513     void MenuCtrl::_wrapItemChild(MenuItemPtr _item, MenuCtrlPtr _widget)
00514     {
00515         // заменяем
00516         size_t index = getItemIndex(_item);
00517         if (mItemsInfo[index].submenu != nullptr)
00518         {
00519             WidgetManager::getInstance().destroyWidget(mItemsInfo[index].submenu);
00520         }
00521         mItemsInfo[index].submenu = _widget;
00522         // скрываем менюшку
00523         mItemsInfo[index].submenu->setVisible(false);
00524 
00525         update();
00526     }
00527 
00528     void MenuCtrl::_wrapItem(MenuItemPtr _item, size_t _index, const UString& _name, MenuItemType _type, const std::string& _id, Any _data)
00529     {
00530         _item->setAlign(mAlignVert ? Align::Top | Align::HStretch : Align::Default);
00531         _item->setCoord(0, 0, mWidgetClient->getWidth(), mHeightLine);
00532         _item->eventRootKeyChangeFocus = newDelegate(this, &MenuCtrl::notifyRootKeyChangeFocus);
00533         _item->eventMouseButtonClick = newDelegate(this, &MenuCtrl::notifyMouseButtonClick);
00534         _item->eventMouseSetFocus = newDelegate(this, &MenuCtrl::notifyMouseSetFocus);
00535 
00536         setButtonImageIndex(_item, getIconIndexByType(_type ));
00537 
00538         MenuCtrlPtr submenu = nullptr;
00539 
00540         ItemInfo info = ItemInfo(_item, _name, _type, submenu, _id, _data);
00541 
00542         mItemsInfo.insert(mItemsInfo.begin() + _index, info);
00543 
00544         // его сет капшен, обновит размер
00545         _item->setCaption(_name);
00546 
00547         update();
00548     }
00549 
00550     void MenuCtrl::setVisible(bool _visible)
00551     {
00552 
00553         if (mAnimateSmooth)
00554         {
00555             ControllerManager::getInstance().removeItem(this);
00556             setAlpha(ALPHA_MAX);
00557             setEnabledSilent(true);
00558             mAnimateSmooth = false;
00559         }
00560 
00561         if (_visible)
00562         {
00563             if (mOwner == nullptr && mHideByLostKey)
00564             {
00565                 MyGUI::InputManager::getInstance().setKeyFocusWidget(this);
00566             }
00567         }
00568 
00569         Base::setVisible(_visible);
00570     }
00571 
00572     void MenuCtrl::setVisibleSmooth(bool _visible)
00573     {
00574         mAnimateSmooth = true;
00575         ControllerManager::getInstance().removeItem(this);
00576 
00577         if (_visible)
00578         {
00579             setEnabledSilent(true);
00580             if ( ! isVisible() )
00581             {
00582                 setAlpha(ALPHA_MIN);
00583                 Base::setVisible(true);
00584             }
00585 
00586             ControllerFadeAlpha* controller = createControllerFadeAlpha(ALPHA_MAX, POPUP_MENU_SPEED_COEF, true);
00587             controller->eventPostAction = newDelegate(action::actionWidgetShow);
00588             ControllerManager::getInstance().addItem(this, controller);
00589         }
00590         else
00591         {
00592             setEnabledSilent(false);
00593 
00594             ControllerFadeAlpha* controller = createControllerFadeAlpha(ALPHA_MIN, POPUP_MENU_SPEED_COEF, false);
00595             controller->eventPostAction = newDelegate(action::actionWidgetHide);
00596             ControllerManager::getInstance().addItem(this, controller);
00597         }
00598     }
00599 
00600     ControllerFadeAlpha* MenuCtrl::createControllerFadeAlpha(float _alpha, float _coef, bool _enable)
00601     {
00602         ControllerItem* item = ControllerManager::getInstance().createItem(ControllerFadeAlpha::getClassTypeName());
00603         ControllerFadeAlpha* controller = item->castType<ControllerFadeAlpha>();
00604 
00605         controller->setAlpha(_alpha);
00606         controller->setCoef(_coef);
00607         controller->setEnabled(_enable);
00608 
00609         return controller;
00610     }
00611 
00612     MenuItemPtr MenuCtrl::insertItem(MenuItemPtr _to, const UString& _name, MenuItemType _type, const std::string& _id, Any _data)
00613     {
00614         return insertItemAt(getItemIndex(_to), _name, _type, _id, _data);
00615     }
00616 
00617     MenuItemPtr MenuCtrl::addItem(const UString& _name, MenuItemType _type, const std::string& _id, Any _data)
00618     {
00619         return insertItemAt(ITEM_NONE, _name, _type, _id, _data);
00620     }
00621 
00622     void MenuCtrl::removeItem(MenuItemPtr _item)
00623     {
00624         removeItemAt(getItemIndex(_item));
00625     }
00626 
00627     MenuItemPtr MenuCtrl::getItemAt(size_t _index)
00628     {
00629         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "MenuCtrl::getItemAt");
00630         return mItemsInfo[_index].item;
00631     }
00632 
00633     size_t MenuCtrl::getItemIndex(MenuItemPtr _item)
00634     {
00635         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00636         {
00637             if (mItemsInfo[pos].item == _item) return pos;
00638         }
00639         MYGUI_EXCEPT("item (" << _item << ") not found, source 'MenuCtrl::getItemIndex'");
00640     }
00641 
00642     MenuItemPtr MenuCtrl::findItemWith(const UString& _name)
00643     {
00644         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00645         {
00646             if (mItemsInfo[pos].name == _name) return mItemsInfo[pos].item;
00647         }
00648         return nullptr;
00649     }
00650 
00651     MenuItemPtr MenuCtrl::getItemById(const std::string& _id)
00652     {
00653         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00654         {
00655             if (mItemsInfo[pos].id == _id) return mItemsInfo[pos].item;
00656         }
00657         MYGUI_EXCEPT("item id (" << _id << ") not found, source 'MenuCtrl::getItemById'");
00658     }
00659 
00660     size_t MenuCtrl::getItemIndexById(const std::string& _id)
00661     {
00662         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00663         {
00664             if (mItemsInfo[pos].id == _id) return pos;
00665         }
00666         MYGUI_EXCEPT("item id (" << _id << ") not found, source 'MenuCtrl::getItemById'");
00667     }
00668 
00669     size_t MenuCtrl::findItemIndexWith(const UString& _name)
00670     {
00671         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00672         {
00673             if (mItemsInfo[pos].name == _name) return pos;
00674         }
00675         return ITEM_NONE;
00676     }
00677 
00678 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1