47 mButtonDefaultWidth(1),
49 mButtonAutoWidth(true),
66 mOffsetTab = utility::parseValue<int>(
getUserString(
"OffsetBar"));
73 if (mWidgetBar !=
nullptr)
79 if (mButtonLeft !=
nullptr)
85 if (mButtonRight !=
nullptr)
92 if (mButtonDecor !=
nullptr)
98 if (mItemTemplate !=
nullptr)
103 #ifndef MYGUI_DONT_USE_OBSOLETE
104 if (mItemTemplate ==
nullptr)
107 if (mItemTemplate !=
nullptr)
112 #endif // MYGUI_DONT_USE_OBSOLETE
115 Widget* showPatch =
nullptr;
117 if (showPatch !=
nullptr)
119 mWidgetsPatch.push_back(showPatch);
127 if (mEmpty ==
nullptr)
142 mWidgetsPatch.clear();
143 mWidgetBar =
nullptr;
144 mButtonLeft =
nullptr;
145 mButtonRight =
nullptr;
146 mButtonDecor =
nullptr;
147 mItemTemplate =
nullptr;
148 mEmptyBarWidget =
nullptr;
150 mHeaderPlace =
nullptr;
165 if (child !=
nullptr)
180 size_t lastIndex = mItemsInfo.size() - 1;
186 return widget->castType<
TabItem>();
194 if (_index1 != _index2)
196 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
224 if (_sender == mButtonLeft)
232 else if (_sender == mButtonRight)
234 if ((mStartIndex + 1) < mItemsInfo.size())
247 if (select == mIndexSelect)
253 size_t old = mIndexSelect;
254 mIndexSelect = select;
257 for (
size_t pos = 0; pos < mItemButton.size(); pos++)
259 Button* button = mItemButton[count]->castType<
Button>();
274 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
275 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
285 if (_getWidgetBar()->
getWidth() < 1)
288 if (_index == mStartIndex)
290 else if (_index < mStartIndex)
292 mStartIndex = _index;
299 for (
size_t pos = mStartIndex; pos <= _index; pos++)
301 width += mItemsInfo[pos].width;
306 while ((mStartIndex < _index) && (width > _getWidgetBar()->
getWidth()))
308 width -= mItemsInfo[mStartIndex].width;
319 mButtonDefaultWidth = _width;
320 if (mButtonDefaultWidth < 1)
321 mButtonDefaultWidth = 1;
327 mButtonAutoWidth = _auto;
329 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
332 if (mButtonAutoWidth)
335 width = mButtonDefaultWidth;
337 mWidthBar += width - mItemsInfo[pos].width;
338 mItemsInfo[pos].width = width;
350 if (mButtonAutoWidth)
353 _width = mButtonDefaultWidth;
356 mWidthBar += _width - mItemsInfo[_index].width;
357 mItemsInfo[_index].width = _width;
365 mItemsInfo[_index].name = _name;
368 if (mButtonAutoWidth)
371 width = mButtonDefaultWidth;
373 mWidthBar += width - mItemsInfo[_index].width;
374 mItemsInfo[_index].width = width;
382 if (mIndexSelect == _index)
384 size_t old = mIndexSelect;
385 mIndexSelect = _index;
392 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
393 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
398 void TabControl::actionWidgetHide(
Widget* _widget)
429 Button* TabControl::createButton()
432 if (mWidgetBar !=
nullptr)
434 else if (mHeaderPlace !=
nullptr)
435 parent = mHeaderPlace;
442 Button* button = createButton();
445 mItemButton.push_back(button);
450 if (mItemButton.empty())
453 UString save = mItemButton[0]->getCaption();
454 mItemButton[0]->setCaption(_text);
460 mItemButton[0]->setCaption(save);
462 return size.
width + mItemButton[0]->getWidth() - coord.
width;
473 mWidthBar -= mItemsInfo[index].width;
474 mItemsInfo.erase(mItemsInfo.begin() + index);
476 if (mItemsInfo.empty())
480 if (index < mIndexSelect)
482 else if (index == mIndexSelect)
484 if (mIndexSelect == mItemsInfo.size())
486 mItemsInfo[mIndexSelect].item->setVisible(
true);
487 mItemsInfo[mIndexSelect].item->setAlpha(
ALPHA_MAX);
497 _index = mItemsInfo.size();
500 int width = (mButtonAutoWidth ?
_getTextWidth(_name) : mButtonDefaultWidth);
503 mItemsInfo.insert(mItemsInfo.begin() + _index,
TabItemInfo(width, _name, _sheet, _data));
506 if (1 == mItemsInfo.size())
511 if (_index <= mIndexSelect)
521 mItemsInfo[_index].data = _data;
527 return mItemsInfo[_index].width;
533 return mItemsInfo[_index].name;
539 return mItemsInfo[_index].item;
550 while (!mItemsInfo.empty())
556 ControllerFadeAlpha* TabControl::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
570 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
572 if (mItemsInfo[pos].item == _item)
575 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'TabControl::getItemIndex'");
580 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
582 if (mItemsInfo[pos].item == _item)
590 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
592 if (mItemsInfo[pos].name == _name)
600 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
602 if (mItemsInfo[pos].name == _name)
603 return mItemsInfo[pos].item;
613 Widget* TabControl::_getWidgetTemplate()
615 return mItemTemplate ==
nullptr ?
this : mItemTemplate;
618 Widget* TabControl::_getWidgetBar()
620 return mWidgetBar ==
nullptr ?
this : mWidgetBar;
625 if (_key ==
"ButtonWidth")
627 else if (_key ==
"ButtonAutoWidth")
629 else if (_key ==
"SmoothShow")
631 else if (_key ==
"SelectItem")
658 return mItemsInfo.size();
746 return mButtonDefaultWidth;
751 return mButtonAutoWidth;
756 mSmoothShow = _value;
796 if (mHeaderPlace !=
nullptr)
802 void TabControl::updateBarOld()
805 if (_getWidgetBar()->
getWidth() < 1)
808 if ((_getWidgetBar()->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
814 if (
nullptr != mButtonLeft)
816 if (
nullptr != mButtonRight)
818 if (
nullptr != mButtonDecor)
820 for (VectorWidgetPtr::iterator iter = mWidgetsPatch.begin(); iter != mWidgetsPatch.end(); ++iter)
821 (*iter)->setVisible(
true);
822 if (mWidgetBar !=
nullptr)
831 if (
nullptr != mButtonLeft)
833 if (
nullptr != mButtonRight)
835 if (
nullptr != mButtonDecor)
837 for (VectorWidgetPtr::iterator iter = mWidgetsPatch.begin(); iter != mWidgetsPatch.end(); ++iter)
838 (*iter)->setVisible(
false);
839 if (mWidgetBar !=
nullptr)
849 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
850 width += mItemsInfo[pos].width;
853 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= _getWidgetBar()->
getWidth()))
856 width += mItemsInfo[mStartIndex].width;
863 size_t pos = mStartIndex;
864 for (; pos < mItemsInfo.size(); pos++)
867 if (width > _getWidgetBar()->
getWidth())
871 TabItemInfo& info = mItemsInfo[pos];
872 if ((width + info.width) > _getWidgetBar()->
getWidth())
878 if (count >= mItemButton.size())
882 Button* button = mItemButton[count]->castType<Button>();
883 button->setVisible(
true);
886 button->setStateSelected(pos == mIndexSelect);
888 if (button->getCaption() != info.name)
889 button->setCaption(info.name);
892 if (coord != button->getCoord())
893 button->setCoord(coord);
900 while (count < mItemButton.size())
902 mItemButton[count]->setVisible(
false);
907 if (pos == mItemsInfo.size())
911 if (mEmptyBarWidget !=
nullptr)
914 if (width < _getWidgetBar()->
getWidth())
926 if (mStartIndex == 0)
928 if (
nullptr != mButtonLeft)
933 if (
nullptr != mButtonLeft)
939 if (
nullptr != mButtonRight)
944 if (
nullptr != mButtonRight)
949 void TabControl::updateBarNew()
955 if (mHeaderPlace ==
nullptr)
958 int widthControls = 0;
959 if (mControls !=
nullptr)
960 widthControls = mControls->
getWidth();
962 if ((mHeaderPlace->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()) && (mHeaderPlace->
getWidth() >= widthControls))
968 if (
nullptr != mControls)
972 if (mControls !=
nullptr)
981 if (
nullptr != mControls)
993 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
994 width += mItemsInfo[pos].width;
997 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= (mHeaderPlace->
getWidth() - widthControls)))
1000 width += mItemsInfo[mStartIndex].width;
1007 size_t pos = mStartIndex;
1008 for (; pos < mItemsInfo.size(); pos++)
1011 if (width > (mHeaderPlace->
getWidth() - widthControls))
1015 TabItemInfo& info = mItemsInfo[pos];
1016 if ((width + info.width) > (mHeaderPlace->
getWidth() - widthControls))
1022 if (count >= mItemButton.size())
1026 Button* button = mItemButton[count];
1027 button->setVisible(
true);
1030 button->setStateSelected(pos == mIndexSelect);
1032 if (button->getCaption() != info.name)
1033 button->setCaption(info.name);
1036 if (coord != button->getCoord())
1037 button->setCoord(coord);
1039 width += info.
width;
1044 while (count < mItemButton.size())
1046 mItemButton[count]->setVisible(
false);
1051 if (pos == mItemsInfo.size())
1054 if (mEmpty !=
nullptr)
1061 if (mStartIndex == 0)
1063 if (
nullptr != mButtonLeft)
1068 if (
nullptr != mButtonLeft)
1074 if (
nullptr != mButtonRight)
1079 if (
nullptr != mButtonRight)