MyGUI  3.0.1
MyGUI_Tab.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_Tab.h"
00025 #include "MyGUI_ControllerManager.h"
00026 #include "MyGUI_WidgetManager.h"
00027 #include "MyGUI_Button.h"
00028 #include "MyGUI_TabItem.h"
00029 #include "MyGUI_ResourceSkin.h"
00030 
00031 namespace MyGUI
00032 {
00033 
00034     const float TAB_SPEED_FADE_COEF = 5.0f;
00035 
00036     Tab::Tab() :
00037         mOffsetTab(0),
00038         mButtonShow(false),
00039         mWidthBar(0),
00040         mWidgetBar(nullptr),
00041         mButtonLeft(nullptr),
00042         mButtonRight(nullptr),
00043         mButtonList(nullptr),
00044         mButtonDecor(nullptr),
00045         mEmptyBarWidget(nullptr),
00046         mItemTemplate(nullptr),
00047         mStartIndex(0),
00048         mIndexSelect(ITEM_NONE),
00049         mButtonDefaultWidth(1),
00050         mSmoothShow(true),
00051         mButtonAutoWidth(true),
00052         mShutdown(false)
00053     {
00054     }
00055 
00056     void Tab::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name)
00057     {
00058         Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name);
00059 
00060         initialiseWidgetSkin(_info);
00061     }
00062 
00063     Tab::~Tab()
00064     {
00065         mShutdown = true;
00066         shutdownWidgetSkin();
00067     }
00068 
00069     void Tab::baseChangeWidgetSkin(ResourceSkin* _info)
00070     {
00071         shutdownWidgetSkin();
00072         Base::baseChangeWidgetSkin(_info);
00073         initialiseWidgetSkin(_info);
00074     }
00075 
00076     void Tab::initialiseWidgetSkin(ResourceSkin* _info)
00077     {
00078         // парсим свойства
00079         const MapString& properties = _info->getProperties();
00080         if (!properties.empty())
00081         {
00082             MapString::const_iterator iter = properties.find("OffsetBar");
00083             if (iter != properties.end()) mOffsetTab = utility::parseInt(iter->second);
00084 
00085             iter = properties.find("ButtonSkin");
00086             if (iter != properties.end()) mButtonSkinName = iter->second;
00087             iter = properties.find("EmptyBarSkin");
00088             if (iter != properties.end()) mEmptySkinName = iter->second;
00089         }
00090 
00091         for (VectorWidgetPtr::iterator iter=mWidgetChildSkin.begin(); iter!=mWidgetChildSkin.end(); ++iter)
00092         {
00093             if (*(*iter)->_getInternalData<std::string>() == "Bar")
00094             {
00095                 MYGUI_DEBUG_ASSERT( ! mWidgetBar, "widget already assigned");
00096                 mWidgetBar = (*iter);
00097             }
00098             else if (*(*iter)->_getInternalData<std::string>() == "Left")
00099             {
00100                 MYGUI_DEBUG_ASSERT( ! mButtonLeft, "widget already assigned");
00101                 mButtonLeft = (*iter)->castType<Button>();
00102                 mButtonLeft->setVisible(false);
00103                 mButtonLeft->eventMouseButtonClick = newDelegate(this, &Tab::notifyPressedButtonEvent);
00104             }
00105             else if (*(*iter)->_getInternalData<std::string>() == "Right")
00106             {
00107                 MYGUI_DEBUG_ASSERT( ! mButtonRight, "widget already assigned");
00108                 mButtonRight = (*iter)->castType<Button>();
00109                 mButtonRight->setVisible(false);
00110                 mButtonRight->eventMouseButtonClick = newDelegate(this, &Tab::notifyPressedButtonEvent);
00111             }
00112             else if (*(*iter)->_getInternalData<std::string>() == "List")
00113             {
00114                 MYGUI_DEBUG_ASSERT( ! mButtonList, "widget already assigned");
00115                 mButtonList = (*iter)->castType<Button>();
00116                 mButtonList->setVisible(false);
00117                 mButtonList->eventMouseButtonClick = newDelegate(this, &Tab::notifyPressedButtonEvent);
00118             }
00119             else if (*(*iter)->_getInternalData<std::string>() == "ButtonDecor")
00120             {
00121                 MYGUI_DEBUG_ASSERT( ! mButtonDecor, "widget already assigned");
00122                 mButtonDecor = *iter;
00123                 mButtonDecor->setVisible(false);
00124             }
00125             else if (*(*iter)->_getInternalData<std::string>() == "ShowPatch")
00126             {
00127                 mWidgetsPatch.push_back((*iter));
00128                 (*iter)->setVisible(false);
00129             }
00130             else if ((*(*iter)->_getInternalData<std::string>() == "Sheet") || (*(*iter)->_getInternalData<std::string>() == "TabItem"))
00131             {
00132                 MYGUI_DEBUG_ASSERT( ! mItemTemplate, "widget already assigned");
00133                 mItemTemplate = (*iter);
00134                 mItemTemplate->setVisible(false);
00135             }
00136         }
00137         //MYGUI_ASSERT(nullptr != mWidgetBar, "Child Widget Bar not found in skin (Tab must have Bar)");
00138         //MYGUI_ASSERT(nullptr != mItemTemplate, "Child Widget TabItem not found in skin (Tab must have TabItem (Sheet) )");
00139 
00140         // создаем виджет, носитель скина пустоты бара
00141         mEmptyBarWidget = _getWidgetBar()->createWidget<Widget>(mEmptySkinName, IntCoord(), Align::Left | Align::Top);
00142 
00143         updateBar();
00144     }
00145 
00146     void Tab::shutdownWidgetSkin()
00147     {
00148         mWidgetsPatch.clear();
00149         mWidgetBar = nullptr;
00150         mButtonLeft = nullptr;
00151         mButtonRight = nullptr;
00152         mButtonList = nullptr;
00153         mButtonDecor = nullptr;
00154         mItemTemplate = nullptr;
00155         mEmptyBarWidget = nullptr;
00156     }
00157 
00158 
00159     // переопределяем для особого обслуживания страниц
00160     Widget* Tab::baseCreateWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name)
00161     {
00162         if ((TabItem::getClassTypeName() == _type) || ("Sheet" == _type))
00163         {
00164             TabItem* sheet = static_cast<TabItem*>(Base::baseCreateWidget(_style, TabItem::getClassTypeName(), "Default", _getWidgetTemplate()->getCoord(), _getWidgetTemplate()->getAlign(), "", _name));
00165             _insertItem(ITEM_NONE, _name, sheet, Any::Null);
00166 
00167             return sheet;
00168         }
00169         return Base::baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name);
00170     }
00171 
00172     TabItem* Tab::insertItemAt(size_t _index, const UString& _name, Any _data)
00173     {
00174         MYGUI_ASSERT_RANGE_INSERT(_index, mItemsInfo.size(), "Tab::insertItem");
00175 
00176         TabItem* sheet = static_cast<TabItem*>(Base::baseCreateWidget(WidgetStyle::Child, TabItem::getClassTypeName(), "Default", _getWidgetTemplate()->getCoord(), _getWidgetTemplate()->getAlign(), "", ""));
00177         _insertItem(_index, _name, sheet, _data);
00178 
00179         return sheet;
00180     }
00181 
00182     void Tab::setPosition(const IntPoint& _point)
00183     {
00184         Base::setPosition(_point);
00185 
00186         updateBar();
00187     }
00188 
00189     void Tab::setSize(const IntSize& _size)
00190     {
00191         Base::setSize(_size);
00192 
00193         updateBar();
00194     }
00195 
00196     void Tab::setCoord(const IntCoord& _coord)
00197     {
00198         Base::setCoord(_coord);
00199 
00200         updateBar();
00201     }
00202 
00203     void Tab::updateBar()
00204     {
00205         // подстраховка
00206         if (_getWidgetBar()->getWidth() < 1) return;
00207 
00208         if ((_getWidgetBar()->getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
00209         {
00210             if (!mButtonShow)
00211             {
00212                 mButtonShow = true;
00213                 if (nullptr != mButtonLeft) mButtonLeft->setVisible(true);
00214                 if (nullptr != mButtonRight) mButtonRight->setVisible(true);
00215                 if (nullptr != mButtonList) mButtonList->setVisible(true);
00216                 if (nullptr != mButtonDecor) mButtonDecor->setVisible(true);
00217                 for (VectorWidgetPtr::iterator iter=mWidgetsPatch.begin(); iter!=mWidgetsPatch.end(); ++iter) (*iter)->setVisible(true);
00218                 if (mWidgetBar != nullptr)
00219                     mWidgetBar->setSize(mWidgetBar->getWidth() - mOffsetTab, mWidgetBar->getHeight());
00220             }
00221         }
00222         else
00223         {
00224             if (mButtonShow)
00225             {
00226                 mButtonShow = false;
00227                 if (nullptr != mButtonLeft) mButtonLeft->setVisible(false);
00228                 if (nullptr != mButtonRight) mButtonRight->setVisible(false);
00229                 if (nullptr != mButtonList) mButtonList->setVisible(false);
00230                 if (nullptr != mButtonDecor) mButtonDecor->setVisible(false);
00231                 for (VectorWidgetPtr::iterator iter=mWidgetsPatch.begin(); iter!=mWidgetsPatch.end(); ++iter) (*iter)->setVisible(false);
00232                 if (mWidgetBar != nullptr)
00233                     mWidgetBar->setSize(mWidgetBar->getWidth() + mOffsetTab, mWidgetBar->getHeight());
00234             }
00235         }
00236 
00237         // проверяем правильность стартового индекса
00238         if (mStartIndex > 0)
00239         {
00240             // считаем длинну видимых кнопок
00241             int width = 0;
00242             for (size_t pos=mStartIndex; pos<mItemsInfo.size(); pos++) width += mItemsInfo[pos].width;
00243 
00244             // уменьшаем индекс до тех пор пока кнопка до индекста полностью не влезет в бар
00245             while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex-1].width) <= _getWidgetBar()->getWidth()))
00246             {
00247                 mStartIndex--;
00248                 width += mItemsInfo[mStartIndex].width;
00249             }
00250         }
00251 
00252         // проверяем и обновляем бар
00253         int width = 0;
00254         size_t count = 0;
00255         size_t pos=mStartIndex;
00256         for (; pos<mItemsInfo.size(); pos++)
00257         {
00258             // текущая кнопка не влазиет
00259             if (width > _getWidgetBar()->getWidth()) break;
00260 
00261             // следующая не влазиет
00262             TabItemInfo& info = mItemsInfo[pos];
00263             if ((width + info.width) > _getWidgetBar()->getWidth())
00264             {
00265                 break;
00266             }
00267 
00268             // проверяем физическое наличие кнопки
00269             if (count >= mItemButton.size()) _createItemButton();
00270 
00271             // если кнопка не соответствует, то изменяем ее
00272             Button* button = mItemButton[count]->castType<Button>();
00273             button->setVisible(true);
00274 
00275             // корректируем нажатость кнопки
00276             button->setButtonPressed(pos == mIndexSelect);
00277 
00278             if (button->getCaption() != info.name)
00279                 button->setCaption(info.name);
00280             // положение кнопки
00281             IntCoord coord(width, 0, info.width, _getWidgetBar()->getHeight());
00282             if (coord != button->getCoord())
00283                 button->setCoord(coord);
00284 
00285             width += info.width;
00286             count ++;
00287         }
00288 
00289         // скрываем кнопки что были созданны, но не видны
00290         while (count < mItemButton.size())
00291         {
00292             mItemButton[count]->setVisible(false);
00293             count ++;
00294         }
00295 
00296         bool right = true;
00297         if (pos == mItemsInfo.size()) right = false;
00298 
00299         // корректируем виджет для пустоты
00300         if (width < _getWidgetBar()->getWidth())
00301         {
00302             mEmptyBarWidget->setVisible(true);
00303             mEmptyBarWidget->setCoord(width, 0, _getWidgetBar()->getWidth() - width, _getWidgetBar()->getHeight());
00304         }
00305         else
00306         {
00307             mEmptyBarWidget->setVisible(false);
00308         }
00309 
00310         // корректируем доступность стрелок
00311         if (mStartIndex == 0)
00312         {
00313             if (nullptr != mButtonLeft) mButtonLeft->setEnabled(false);
00314         }
00315         else
00316         {
00317             if (nullptr != mButtonLeft) mButtonLeft->setEnabled(true);
00318         }
00319 
00320         if (right)
00321         {
00322             if (nullptr != mButtonRight) mButtonRight->setEnabled(true);
00323         }
00324         else
00325         {
00326             if (nullptr != mButtonRight) mButtonRight->setEnabled(false);
00327         }
00328 
00329     }
00330 
00331     void Tab::notifyPressedButtonEvent(MyGUI::Widget* _sender)
00332     {
00333         if (_sender == mButtonLeft)
00334         {
00335             if (mStartIndex > 0)
00336             {
00337                 mStartIndex --;
00338                 updateBar();
00339             }
00340         }
00341         else if (_sender == mButtonRight)
00342         {
00343             if ((mStartIndex+1) < mItemsInfo.size())
00344             {
00345                 mStartIndex ++;
00346                 // в updateBar() будет подкорректированно если что
00347                 updateBar();
00348             }
00349         }
00350         else if (_sender == mButtonList)
00351         {
00352         }
00353     }
00354 
00355     void Tab::notifyPressedBarButtonEvent(MyGUI::Widget* _sender)
00356     {
00357         size_t select = *_sender->_getInternalData<size_t>() + mStartIndex;
00358         // щелкнули по той же кнопке
00359         if (select == mIndexSelect)
00360         {
00361             // стараемся показать выделенную кнопку
00362             beginToItemSelected();
00363             return;
00364         }
00365         size_t old = mIndexSelect;
00366         mIndexSelect = select;
00367 
00368         size_t count = 0;
00369         for (size_t pos=0; pos<mItemButton.size(); pos++)
00370         {
00371             Button* button = mItemButton[count]->castType<Button>();
00372             if (button->isVisible())
00373             {
00374                 // корректируем нажатость кнопки
00375                 button->setButtonPressed((pos + mStartIndex) == mIndexSelect);
00376             }
00377             count ++;
00378         }
00379 
00380         // стараемся показать выделенную кнопку
00381         beginToItemSelected();
00382 
00383         // поднимаем страницу для пикинга
00384         _forcePeek(mItemsInfo[mIndexSelect].item);
00385 
00386         _showItem(mItemsInfo[mIndexSelect].item, true, mSmoothShow);
00387         _showItem(mItemsInfo[old].item, false, mSmoothShow);
00388 
00389         eventTabChangeSelect(this, mIndexSelect);
00390     }
00391 
00392     void Tab::beginToItemAt(size_t _index)
00393     {
00394         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::beginToItemAt");
00395 
00396         // подстраховка
00397         if (_getWidgetBar()->getWidth() < 1) return;
00398 
00399         if (_index == mStartIndex) return;
00400         else if (_index < mStartIndex)
00401         {
00402             mStartIndex = _index;
00403             updateBar();
00404         }
00405         else
00406         {
00407             // длинна бара от старт индекса до нужной включительно
00408             int width = 0;
00409             for (size_t pos=mStartIndex; pos<=_index; pos++)
00410             {
00411                 width += mItemsInfo[pos].width;
00412             }
00413 
00414             // уменьшем старт индекс пока не появиться нужная
00415             bool change = false;
00416             while ((mStartIndex < _index) && (width > _getWidgetBar()->getWidth()))
00417             {
00418                 width -= mItemsInfo[mStartIndex].width;
00419                 mStartIndex ++;
00420                 change = true;
00421             }
00422             if (change) updateBar();
00423 
00424         }
00425     }
00426 
00427     void Tab::setButtonDefaultWidth(int _width)
00428     {
00429         mButtonDefaultWidth = _width;
00430         if (mButtonDefaultWidth < 1) mButtonDefaultWidth = 1;
00431         setButtonAutoWidth(false);
00432     }
00433 
00434     void Tab::setButtonAutoWidth(bool _auto)
00435     {
00436         mButtonAutoWidth = _auto;
00437 
00438         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00439         {
00440             int width;
00441             if (mButtonAutoWidth) width = _getTextWidth(mItemsInfo[pos].name);
00442             else width = mButtonDefaultWidth;
00443 
00444             mWidthBar += width - mItemsInfo[pos].width;
00445             mItemsInfo[pos].width = width;
00446         }
00447 
00448         updateBar();
00449     }
00450 
00451     void Tab::setButtonWidthAt(size_t _index, int _width)
00452     {
00453         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::setButtonWidthAt");
00454 
00455         if (_width <= 0)
00456         {
00457             if (mButtonAutoWidth) _width = _getTextWidth(mItemsInfo[_index].name);
00458             else _width = mButtonDefaultWidth;
00459         }
00460 
00461         mWidthBar += _width - mItemsInfo[_index].width;
00462         mItemsInfo[_index].width = _width;
00463 
00464         updateBar();
00465     }
00466 
00467     void Tab::setItemNameAt(size_t _index, const UString& _name)
00468     {
00469         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::setItemNameAt");
00470         mItemsInfo[_index].name = _name;
00471 
00472         int width;
00473         if (mButtonAutoWidth) width = _getTextWidth(_name);
00474         else width = mButtonDefaultWidth;
00475 
00476         mWidthBar += width - mItemsInfo[_index].width;
00477         mItemsInfo[_index].width = width;
00478 
00479         updateBar();
00480     }
00481 
00482     void Tab::setIndexSelected(size_t _index)
00483     {
00484         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::setIndexSelected");
00485         if (mIndexSelect == _index) return;
00486         size_t old = mIndexSelect;
00487         mIndexSelect = _index;
00488         updateBar();
00489 
00490         // поднимаем страницу для пикинга
00491         if (mSmoothShow) _forcePeek(mItemsInfo[mIndexSelect].item);
00492 
00493         _showItem(mItemsInfo[mIndexSelect].item, true, mSmoothShow);
00494         _showItem(mItemsInfo[old].item, false, mSmoothShow);
00495 
00496         beginToItemSelected();
00497     }
00498 
00499     void Tab::actionWidgetHide(Widget* _widget)
00500     {
00501         _widget->setVisible(false);
00502         _widget->setEnabled(true);
00503     }
00504 
00505     void Tab::_showItem(TabItem* _item, bool _show, bool _smooth)
00506     {
00507         if (!_smooth)
00508         {
00509             ControllerManager::getInstance().removeItem(_item);
00510             _item->setAlpha(ALPHA_MAX);
00511 
00512             _item->setVisible(_show);
00513 
00514             return;
00515         }
00516 
00517         if (_show)
00518         {
00519             ControllerFadeAlpha* controller = createControllerFadeAlpha(ALPHA_MAX, TAB_SPEED_FADE_COEF, true);
00520             ControllerManager::getInstance().addItem(_item, controller);
00521         }
00522         else
00523         {
00524             ControllerFadeAlpha* controller = createControllerFadeAlpha(ALPHA_MIN, TAB_SPEED_FADE_COEF, false);
00525             controller->eventPostAction = newDelegate(this, &Tab::actionWidgetHide);
00526             ControllerManager::getInstance().addItem(_item, controller);
00527         }
00528     }
00529 
00530     void Tab::_createItemButton()
00531     {
00532         Button* button = _getWidgetBar()->createWidget<Button>(mButtonSkinName, IntCoord(), Align::Left | Align::Top);
00533         button->eventMouseButtonClick = newDelegate(this, &Tab::notifyPressedBarButtonEvent);
00534         button->_setInternalData(mItemButton.size()); // порядковый номер
00535         mItemButton.push_back(button);
00536     }
00537 
00538     int Tab::_getTextWidth(const UString& _text)
00539     {
00540         if (0 == mItemButton.size()) _createItemButton();
00541 
00542         UString save = mItemButton[0]->getCaption();
00543         mItemButton[0]->setCaption(_text);
00544 
00545         ISubWidgetText* text = mItemButton[0]->getSubWidgetText();
00546         const IntSize& size = text ? text->getTextSize() : IntSize();
00547         const IntCoord& coord = text ? text->getCoord() : IntCoord();
00548 
00549         mItemButton[0]->setCaption(save);
00550 
00551         return size.width + mItemButton[0]->getWidth() - coord.width;
00552     }
00553 
00554     void Tab::_notifyDeleteItem(TabItem* _sheet)
00555     {
00556         // общий шутдаун виджета
00557         if (mShutdown) return;
00558 
00559         size_t index = getItemIndex(_sheet);
00560 
00561         mWidthBar -= mItemsInfo[index].width;
00562         mItemsInfo.erase(mItemsInfo.begin() + index);
00563 
00564         if (0 == mItemsInfo.size()) mIndexSelect = ITEM_NONE;
00565         else
00566         {
00567             if (index < mIndexSelect) mIndexSelect --;
00568             else if (index == mIndexSelect)
00569             {
00570                 if (mIndexSelect == mItemsInfo.size()) mIndexSelect --;
00571                 mItemsInfo[mIndexSelect].item->setVisible(true);
00572                 mItemsInfo[mIndexSelect].item->setAlpha(ALPHA_MAX);
00573             }
00574         }
00575 
00576         updateBar();
00577     }
00578 
00579     void Tab::_insertItem(size_t _index, const UString& _name, TabItem* _sheet, Any _data)
00580     {
00581         if (_index == ITEM_NONE) _index = mItemsInfo.size();
00582 
00583         // добавляем инфу о вкладке
00584         int width = (mButtonAutoWidth ? _getTextWidth(_name) : mButtonDefaultWidth);
00585         mWidthBar += width;
00586 
00587         mItemsInfo.insert(mItemsInfo.begin() + _index, TabItemInfo(width, _name, _sheet, _data));
00588 
00589         // первая вкладка
00590         if (1 == mItemsInfo.size()) mIndexSelect = 0;
00591         else
00592         {
00593             _sheet->setVisible(false);
00594             if (_index <= mIndexSelect) mIndexSelect ++;
00595         }
00596 
00597         updateBar();
00598     }
00599 
00600     void Tab::setItemDataAt(size_t _index, Any _data)
00601     {
00602         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::setItemDataAt");
00603         mItemsInfo[_index].data = _data;
00604     }
00605 
00606     int Tab::getButtonWidthAt(size_t _index)
00607     {
00608         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::getButtonWidthAt");
00609         return mItemsInfo[_index].width;
00610     }
00611 
00612     const UString& Tab::getItemNameAt(size_t _index)
00613     {
00614         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::getItemNameAt");
00615         return mItemsInfo[_index].name;
00616     }
00617 
00618     TabItem* Tab::getItemAt(size_t _index)
00619     {
00620         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::getItemAt");
00621         return mItemsInfo[_index].item;
00622     }
00623 
00624     void Tab::removeItemAt(size_t _index)
00625     {
00626         MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "Tab::removeItemAt");
00627         this->_destroyChildWidget(mItemsInfo[_index].item);
00628     }
00629 
00630     void Tab::removeAllItems()
00631     {
00632         while (mItemsInfo.size() > 0)
00633         {
00634             this->_destroyChildWidget(mItemsInfo.back().item);
00635         }
00636     }
00637 
00638     ControllerFadeAlpha* Tab::createControllerFadeAlpha(float _alpha, float _coef, bool _enable)
00639     {
00640         ControllerItem* item = ControllerManager::getInstance().createItem(ControllerFadeAlpha::getClassTypeName());
00641         ControllerFadeAlpha* controller = item->castType<ControllerFadeAlpha>();
00642 
00643         controller->setAlpha(_alpha);
00644         controller->setCoef(_coef);
00645         controller->setEnabled(_enable);
00646 
00647         return controller;
00648     }
00649 
00650     size_t Tab::getItemIndex(TabItem* _item)
00651     {
00652         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00653         {
00654             if (mItemsInfo[pos].item == _item) return pos;
00655         }
00656         MYGUI_EXCEPT("item (" << _item << ") not found, source 'Tab::getItemIndex'");
00657     }
00658 
00659     size_t Tab::findItemIndex(TabItem* _item)
00660     {
00661         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00662         {
00663             if (mItemsInfo[pos].item == _item) return pos;
00664         }
00665         return ITEM_NONE;
00666     }
00667 
00668     size_t Tab::findItemIndexWith(const UString& _name)
00669     {
00670         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00671         {
00672             if (mItemsInfo[pos].name == _name) return pos;
00673         }
00674         return ITEM_NONE;
00675     }
00676 
00677     TabItem* Tab::findItemWith(const UString& _name)
00678     {
00679         for (size_t pos=0; pos<mItemsInfo.size(); pos++)
00680         {
00681             if (mItemsInfo[pos].name == _name) return mItemsInfo[pos].item;
00682         }
00683         return nullptr;
00684     }
00685 
00686     TabItem* Tab::getItemSelected()
00687     {
00688         return getIndexSelected() != ITEM_NONE ? getItemAt(getIndexSelected()) : nullptr;
00689     }
00690 
00691     void Tab::setProperty(const std::string& _key, const std::string& _value)
00692     {
00693         if (_key == "Tab_ButtonWidth") setButtonDefaultWidth(utility::parseValue<int>(_value));
00694         else if (_key == "Tab_ButtonAutoWidth") setButtonAutoWidth(utility::parseValue<bool>(_value));
00695         else if (_key == "Tab_SmoothShow") setSmoothShow(utility::parseValue<bool>(_value));
00696         else if (_key == "Tab_AddItem") addItem(_value);
00697         else if (_key == "Tab_SelectItem") setIndexSelected(utility::parseValue<size_t>(_value));
00698 
00699 #ifndef MYGUI_DONT_USE_OBSOLETE
00700         else if (_key == "Tab_AddSheet")
00701         {
00702             MYGUI_LOG(Warning, "Tab_AddSheet is obsolete, use Tab_AddItem");
00703             addItem(_value);
00704         }
00705         else if (_key == "Tab_SelectSheet")
00706         {
00707             MYGUI_LOG(Warning, "Tab_SelectSheet is obsolete, use Tab_SelectItem");
00708             setIndexSelected(utility::parseValue<size_t>(_value));
00709         }
00710 #endif // MYGUI_DONT_USE_OBSOLETE
00711 
00712         else
00713         {
00714             Base::setProperty(_key, _value);
00715             return;
00716         }
00717         eventChangeProperty(this, _key, _value);
00718     }
00719 
00720     Widget* Tab::_getWidgetTemplate()
00721     {
00722         return mItemTemplate == nullptr ? this : mItemTemplate;
00723     }
00724 
00725     Widget* Tab::_getWidgetBar()
00726     {
00727         return mWidgetBar == nullptr ? this : mWidgetBar;
00728     }
00729 
00730 } // namespace MyGUI