32 mButtonDefaultWidth(1),
34 mButtonAutoWidth(true),
44 Base::initialiseOverride();
51 mOffsetTab = utility::parseValue<int>(
getUserString(
"OffsetBar"));
59 if (mWidgetBar !=
nullptr)
66 if (mButtonLeft !=
nullptr)
73 if (mButtonRight !=
nullptr)
80 if (mButtonDecor !=
nullptr)
87 if (mItemTemplate !=
nullptr)
92 #ifndef MYGUI_DONT_USE_OBSOLETE
93 if (mItemTemplate ==
nullptr)
96 if (mItemTemplate !=
nullptr)
101 #endif // MYGUI_DONT_USE_OBSOLETE
104 Widget* showPatch =
nullptr;
106 if (showPatch !=
nullptr)
108 mWidgetsPatch.push_back(showPatch);
121 if (mEmpty ==
nullptr)
136 mWidgetsPatch.clear();
137 mWidgetBar =
nullptr;
138 mButtonLeft =
nullptr;
139 mButtonRight =
nullptr;
140 mButtonDecor =
nullptr;
141 mItemTemplate =
nullptr;
142 mEmptyBarWidget =
nullptr;
144 mHeaderPlace =
nullptr;
151 Base::shutdownOverride();
156 Base::onWidgetCreated(_widget);
159 if (child !=
nullptr)
174 size_t lastIndex = mItemsInfo.size() - 1;
180 return widget->castType<
TabItem>();
188 if (_index1 != _index2)
190 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
197 Base::setPosition(_point);
204 Base::setSize(_size);
211 Base::setCoord(_coord);
218 if (_sender == mButtonLeft)
226 else if (_sender == mButtonRight)
228 if ((mStartIndex + 1) < mItemsInfo.size())
241 if (select == mIndexSelect)
247 size_t old = mIndexSelect;
248 mIndexSelect = select;
251 for (
size_t pos = 0; pos < mItemButton.size(); pos++)
253 Button* button = mItemButton[count]->castType<
Button>();
268 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
269 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
279 if (_getWidgetBar()->
getWidth() < 1)
282 if (_index == mStartIndex)
284 else if (_index < mStartIndex)
286 mStartIndex = _index;
293 for (
size_t pos = mStartIndex; pos <= _index; pos++)
295 width += mItemsInfo[pos].width;
300 while ((mStartIndex < _index) && (width > _getWidgetBar()->
getWidth()))
302 width -= mItemsInfo[mStartIndex].width;
313 mButtonDefaultWidth = _width;
314 if (mButtonDefaultWidth < 1)
315 mButtonDefaultWidth = 1;
321 mButtonAutoWidth = _auto;
323 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
326 if (mButtonAutoWidth)
329 width = mButtonDefaultWidth;
331 mWidthBar += width - mItemsInfo[pos].width;
332 mItemsInfo[pos].width = width;
344 if (mButtonAutoWidth)
347 _width = mButtonDefaultWidth;
350 mWidthBar += _width - mItemsInfo[_index].width;
351 mItemsInfo[_index].width = _width;
359 mItemsInfo[_index].name = _name;
362 if (mButtonAutoWidth)
365 width = mButtonDefaultWidth;
367 mWidthBar += width - mItemsInfo[_index].width;
368 mItemsInfo[_index].width = width;
376 if (mIndexSelect == _index)
378 size_t old = mIndexSelect;
379 mIndexSelect = _index;
386 _showItem(mItemsInfo[mIndexSelect].item,
true, mSmoothShow);
387 _showItem(mItemsInfo[old].item,
false, mSmoothShow);
423 Button* TabControl::createButton()
426 if (mWidgetBar !=
nullptr)
428 else if (mHeaderPlace !=
nullptr)
429 parent = mHeaderPlace;
436 Button* button = createButton();
439 mItemButton.push_back(button);
444 if (mItemButton.empty())
447 UString save = mItemButton[0]->getCaption();
448 mItemButton[0]->setCaption(_text);
454 mItemButton[0]->setCaption(save);
456 return size.
width + mItemButton[0]->getWidth() - coord.
width;
467 mWidthBar -= mItemsInfo[index].width;
468 mItemsInfo.erase(mItemsInfo.begin() + index);
470 if (mItemsInfo.empty())
474 if (index < mIndexSelect)
476 else if (index == mIndexSelect)
478 if (mIndexSelect == mItemsInfo.size())
480 mItemsInfo[mIndexSelect].item->setVisible(
true);
481 mItemsInfo[mIndexSelect].item->setAlpha(
ALPHA_MAX);
491 _index = mItemsInfo.size();
494 int width = (mButtonAutoWidth ?
_getTextWidth(_name) : mButtonDefaultWidth);
497 mItemsInfo.insert(mItemsInfo.begin() + _index,
TabItemInfo(width, _name, _sheet, _data));
500 if (1 == mItemsInfo.size())
505 if (_index <= mIndexSelect)
515 mItemsInfo[_index].data = _data;
521 return mItemsInfo[_index].width;
527 return mItemsInfo[_index].name;
533 return mItemsInfo[_index].item;
544 while (!mItemsInfo.empty())
550 ControllerFadeAlpha* TabControl::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
564 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
566 if (mItemsInfo[pos].item == _item)
569 MYGUI_EXCEPT(
"item (" << _item <<
") not found, source 'TabControl::getItemIndex'");
574 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
576 if (mItemsInfo[pos].item == _item)
584 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
586 if (mItemsInfo[pos].name == _name)
594 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
596 if (mItemsInfo[pos].name == _name)
597 return mItemsInfo[pos].item;
607 Widget* TabControl::_getWidgetTemplate()
609 return mItemTemplate ==
nullptr ?
this : mItemTemplate;
612 Widget* TabControl::_getWidgetBar()
614 return mWidgetBar ==
nullptr ?
this : mWidgetBar;
620 if (_key ==
"ButtonWidth")
624 else if (_key ==
"ButtonAutoWidth")
628 else if (_key ==
"SmoothShow")
632 else if (_key ==
"SelectItem")
637 Base::setPropertyOverride(_key, _value);
661 return mItemsInfo.size();
749 return mButtonDefaultWidth;
754 return mButtonAutoWidth;
759 mSmoothShow = _value;
799 if (mHeaderPlace !=
nullptr)
805 void TabControl::updateBarOld()
808 if (_getWidgetBar()->
getWidth() < 1)
811 if ((_getWidgetBar()->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()))
817 if (
nullptr != mButtonLeft)
819 if (
nullptr != mButtonRight)
821 if (
nullptr != mButtonDecor)
823 for (VectorWidgetPtr::iterator iter = mWidgetsPatch.begin(); iter != mWidgetsPatch.end(); ++iter)
824 (*iter)->setVisible(
true);
825 if (mWidgetBar !=
nullptr)
834 if (
nullptr != mButtonLeft)
836 if (
nullptr != mButtonRight)
838 if (
nullptr != mButtonDecor)
840 for (VectorWidgetPtr::iterator iter = mWidgetsPatch.begin(); iter != mWidgetsPatch.end(); ++iter)
841 (*iter)->setVisible(
false);
842 if (mWidgetBar !=
nullptr)
852 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
853 width += mItemsInfo[pos].width;
856 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= _getWidgetBar()->
getWidth()))
859 width += mItemsInfo[mStartIndex].width;
866 size_t pos = mStartIndex;
867 for (; pos < mItemsInfo.size(); pos++)
870 if (width > _getWidgetBar()->
getWidth())
874 TabItemInfo& info = mItemsInfo[pos];
875 if ((width + info.width) > _getWidgetBar()->
getWidth())
881 if (count >= mItemButton.size())
885 Button* button = mItemButton[count]->castType<Button>();
886 button->setVisible(
true);
889 button->setStateSelected(pos == mIndexSelect);
891 if (button->getCaption() != info.name)
892 button->setCaption(info.name);
895 if (coord != button->getCoord())
896 button->setCoord(coord);
903 while (count < mItemButton.size())
905 mItemButton[count]->setVisible(
false);
910 if (pos == mItemsInfo.size())
914 if (mEmptyBarWidget !=
nullptr)
917 if (width < _getWidgetBar()->
getWidth())
929 if (mStartIndex == 0)
931 if (
nullptr != mButtonLeft)
936 if (
nullptr != mButtonLeft)
942 if (
nullptr != mButtonRight)
947 if (
nullptr != mButtonRight)
952 void TabControl::updateBarNew()
954 if (mHeaderPlace ==
nullptr)
961 int widthControls = 0;
962 if (mControls !=
nullptr)
963 widthControls = mControls->
getWidth();
965 if ((mHeaderPlace->
getWidth() < mWidthBar) && (1 < mItemsInfo.size()) && (mHeaderPlace->
getWidth() >= widthControls))
971 if (
nullptr != mControls)
975 if (mControls !=
nullptr)
984 if (
nullptr != mControls)
996 for (
size_t pos = mStartIndex; pos < mItemsInfo.size(); pos++)
997 width += mItemsInfo[pos].width;
1000 while ((mStartIndex > 0) && ((width + mItemsInfo[mStartIndex - 1].width) <= (mHeaderPlace->
getWidth() - widthControls)))
1003 width += mItemsInfo[mStartIndex].width;
1010 size_t pos = mStartIndex;
1011 for (; pos < mItemsInfo.size(); pos++)
1014 if (width > (mHeaderPlace->
getWidth() - widthControls))
1018 TabItemInfo& info = mItemsInfo[pos];
1019 if ((width + info.width) > (mHeaderPlace->
getWidth() - widthControls))
1025 if (count >= mItemButton.size())
1029 Button* button = mItemButton[count];
1030 button->setVisible(
true);
1033 button->setStateSelected(pos == mIndexSelect);
1035 if (button->getCaption() != info.name)
1036 button->setCaption(info.name);
1039 if (coord != button->getCoord())
1040 button->setCoord(coord);
1042 width += info.
width;
1047 while (count < mItemButton.size())
1049 mItemButton[count]->setVisible(
false);
1054 if (pos == mItemsInfo.size())
1057 if (mEmpty !=
nullptr)
1064 if (mStartIndex == 0)
1066 if (
nullptr != mButtonLeft)
1071 if (
nullptr != mButtonLeft)
1077 if (
nullptr != mButtonRight)
1082 if (
nullptr != mButtonRight)