MyGUI 3.2.2

MyGUI_TabControl.h
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #ifndef MYGUI_TAB_CONTROL_H_
8 #define MYGUI_TAB_CONTROL_H_
9
10 #include "MyGUI_Prerequest.h"
11 #include "MyGUI_Widget.h"
12 #include "MyGUI_Any.h"
13 #include "MyGUI_EventPair.h"
14 #include "MyGUI_ControllerFadeAlpha.h"
15 #include "MyGUI_IItem.h"
16 #include "MyGUI_IItemContainer.h"
17
18 namespace MyGUI
19 {
20
21 typedef delegates::CMultiDelegate2<TabControl*, size_t> EventHandle_TabPtrSizeT;
22
26 class MYGUI_EXPORT TabControl :
27 public Widget,
28 public IItemContainer,
29 public MemberObsolete<TabControl>
30 {
31 // для уведобления об удалении
32 //FIXME
33 friend class TabItem;
34
35 MYGUI_RTTI_DERIVED( TabControl )
36
37 public:
38 TabControl();
39
40 struct TabItemInfo
41 {
42 TabItemInfo(int _width, const UString& _name, TabItem* _item, Any _data) :
43 width(_width),
44 name(_name),
45 item(_item),
46 data(_data)
47 {
48 }
49
50 int width;
51 UString name;
52 TabItem* item;
53 Any data;
54 };
55
56 typedef std::vector<TabItemInfo> VectorTabItemInfo;
57
59 virtual void setPosition(const IntPoint& _value);
61 virtual void setSize(const IntSize& _value);
63 virtual void setCoord(const IntCoord& _value);
64
66 void setPosition(int _left, int _top);
68 void setSize(int _width, int _height);
70 void setCoord(int _left, int _top, int _width, int _height);
71
72 //------------------------------------------------------------------------------//
73 // манипуляции айтемами
74
76 size_t getItemCount() const;
77
79 TabItem* insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
81 TabItem* insertItem(TabItem* _to, const UString& _name, Any _data = Any::Null);
82
84 TabItem* addItem(const UString& _name, Any _data = Any::Null);
85
87 void removeItemAt(size_t _index);
89 void removeItem(TabItem* _item);
90
92 void removeAllItems();
93
94
96 TabItem* getItemAt(size_t _index);
97
99 size_t getItemIndex(TabItem* _item);
100
102 size_t findItemIndex(TabItem* _item);
103
105 size_t findItemIndexWith(const UString& _name);
106
108 TabItem* findItemWith(const UString& _name);
109
110 void swapItems(size_t _index1, size_t _index2);
111
112 //------------------------------------------------------------------------------//
113 // манипуляции выделениями
114
116 size_t getIndexSelected() const;
117
119 TabItem* getItemSelected();
120
122 void setIndexSelected(size_t _index);
123
125 void setItemSelected(TabItem* _item);
126
127
128 //------------------------------------------------------------------------------//
129 // манипуляции данными
130
132 void setItemDataAt(size_t _index, Any _data);
134 void setItemData(TabItem* _item, Any _data);
135
137 void clearItemDataAt(size_t _index);
139 void clearItemData(TabItem* _item);
140
142 template <typename ValueType>
143 ValueType* getItemDataAt(size_t _index, bool _throw = true)
144 {
145 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::getItemDataAt");
146 return mItemsInfo[_index].data.castType<ValueType>(_throw);
147 }
149 template <typename ValueType>
150 ValueType* getItemData(TabItem* _item, bool _throw = true)
151 {
152 return getItemDataAt<ValueType>(getItemIndex(_item), _throw);
153 }
154
155
156 //------------------------------------------------------------------------------//
157 // манипуляции отображением
158
160 void setItemNameAt(size_t _index, const UString& _name);
161
163 void setItemName(TabItem* _item, const UString& _name);
164
166 const UString& getItemNameAt(size_t _index);
167
169 const UString& getItemName(TabItem* _item);
170
171
172 //------------------------------------------------------------------------------//
173 // манипуляции выдимостью
174
176 void beginToItemAt(size_t _index);
177
179 void beginToItem(TabItem* _item);
181 void beginToItemFirst();
183 void beginToItemLast();
185 void beginToItemSelected();
186
187
188 //------------------------------------------------------------------------------//
189 // остальные манипуляции
190
192 void setButtonWidthAt(size_t _index, int _width = DEFAULT);
194 void setButtonWidth(TabItem* _item, int _width = DEFAULT);
195
197 int getButtonWidthAt(size_t _index);
199 int getButtonWidth(TabItem* _item);
200
201 //------------------------------------------------------------------------------//
202
204 void setButtonDefaultWidth(int _value);
206 int getButtonDefaultWidth() const;
207
209 void setButtonAutoWidth(bool _value);
211 bool getButtonAutoWidth() const;
212
214 void setSmoothShow(bool _value);
216 bool getSmoothShow() const;
217
218 /*events:*/
224 EventPair<EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT> eventTabChangeSelect;
225
226 /*internal:*/
227 // IItemContainer impl
228 virtual size_t _getItemCount();
229 virtual void _addItem(const MyGUI::UString& _name);
230 virtual void _removeItemAt(size_t _index);
231 virtual Widget* _getItemAt(size_t _index);
232 virtual void _setItemNameAt(size_t _index, const UString& _name);
233 virtual const UString& _getItemNameAt(size_t _index);
234
235 protected:
236 virtual void initialiseOverride();
237 virtual void shutdownOverride();
238
239 void updateBar();
240
241 void notifyPressedButtonEvent(MyGUI::Widget* _sender);
242 void notifyPressedBarButtonEvent(MyGUI::Widget* _sender);
243
244 int _getTextWidth(const UString& _text);
245
246 void _showItem(TabItem* _sheet, bool _show, bool _smooth);
247
248 void _createItemButton();
249
250 void _insertItem(size_t _index, const UString& _name, TabItem* _sheet, Any _data);
251
252 // вкладка при удалении уведомляет таб
253 void _notifyDeleteItem(TabItem* _item);
254
255 virtual void onWidgetCreated(Widget* _widget);
256
257 virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
258
259 private:
260 void actionWidgetHide(Widget* _widget, ControllerItem* _controller);
261
262 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
263
264 Widget* _getWidgetTemplate();
265 Widget* _getWidgetBar();
266
267 Button* createButton();
268 void updateBarOld();
269 void updateBarNew();
270
271 private:
272 int mOffsetTab; // смещение бара при показе кнопок
273 bool mButtonShow;
274 int mWidthBar; // ширина в которую помещаються все кнопки
275 std::vector<Button*> mItemButton; // список кнопок, не должно равно списку страниц
276 std::string mButtonSkinName;
277 std::string mEmptySkinName;
278
279 Widget* mWidgetBar;
280 Button* mButtonLeft;
281 Button* mButtonRight;
282 Widget* mButtonDecor;
283 VectorWidgetPtr mWidgetsPatch; // список виджетов которые нужно показать при показе кнопки
284 Widget* mEmptyBarWidget;
285 Widget* mItemTemplate;
286
287 // информация о вкладках
288 VectorTabItemInfo mItemsInfo;
289 size_t mStartIndex;
290 size_t mIndexSelect;
291
292 int mButtonDefaultWidth;
293 bool mSmoothShow;
294 bool mButtonAutoWidth;
295
296 // флаг, чтобы отсеч уведомления от вкладок, при общем шутдауне виджета
297 bool mShutdown;
298
299 Widget* mHeaderPlace;
300 Widget* mControls;
301 Widget* mEmpty;
302 };
303
304 } // namespace MyGUI
305
306 #endif // MYGUI_TAB_CONTROL_H_
MyGUI::types::TCoord< int >
MyGUI::Widget
Widget properties. Widget_skin_childs Skin childs. Widget widget description should be here...
Definition: MyGUI_Widget.h:29
MyGUI::TabControl::VectorTabItemInfo
std::vector< TabItemInfo > VectorTabItemInfo
Definition: MyGUI_TabControl.h:56
MyGUI::TabItem
TabItem properties. TabItem_skin_childs Skin childs. TabItem widget description should be here...
Definition: MyGUI_TabItem.h:20
MyGUI_IItemContainer.h
MyGUI::types::TPoint< int >
MyGUI_Prerequest.h
MyGUI::TabControl::TabItemInfo::width
int width
Definition: MyGUI_TabControl.h:50
MyGUI_IItem.h
MyGUI::types::TSize< int >
MyGUI::action::actionWidgetHide
void actionWidgetHide(Widget *_widget, ControllerItem *_controller)
Definition: MyGUI_ActionController.cpp:18
MyGUI::TabControl::TabItemInfo::item
TabItem * item
Definition: MyGUI_TabControl.h:52
MyGUI::Any
Definition: MyGUI_Any.h:63
MyGUI::TabControl::TabItemInfo::TabItemInfo
TabItemInfo(int _width, const UString &_name, TabItem *_item, Any _data)
Definition: MyGUI_TabControl.h:42
MyGUI::IItemContainer
Definition: MyGUI_IItemContainer.h:18
MyGUI::TabControl::getItemData
ValueType * getItemData(TabItem *_item, bool _throw=true)
Get item data.
Definition: MyGUI_TabControl.h:150
MyGUI::Button
Button properties. Button_skin_childs Skin childs. Button widget description should be here...
Definition: MyGUI_Button.h:19
MyGUI::DEFAULT
const int DEFAULT
Definition: MyGUI_Macros.h:18
MyGUI
Definition: MyGUI_ActionController.h:14
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:65
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103
MyGUI::EventPair
Definition: MyGUI_EventPair.h:16
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition: MyGUI_WidgetDefines.h:19
MyGUI_ControllerFadeAlpha.h
MyGUI_Any.h
MyGUI::TabControl::getItemDataAt
ValueType * getItemDataAt(size_t _index, bool _throw=true)
Get item data from specified position.
Definition: MyGUI_TabControl.h:143
MyGUI::delegates::CMultiDelegate2
Definition: MyGUI_Delegate.h:203
MyGUI::TabControl::TabItemInfo
Definition: MyGUI_TabControl.h:40
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition: MyGUI_Diagnostic.h:54
MyGUI::ControllerFadeAlpha
Definition: MyGUI_ControllerFadeAlpha.h:18
MyGUI_Widget.h
MyGUI::TabControl::eventTabChangeSelect
EventPair< EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT > eventTabChangeSelect
Definition: MyGUI_TabControl.h:224
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:168
MyGUI::ControllerItem
Definition: MyGUI_ControllerItem.h:25
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:13
MyGUI_EventPair.h
MyGUI::EventHandle_TabPtrSizeT
delegates::CMultiDelegate2< TabControl *, size_t > EventHandle_TabPtrSizeT
Definition: MyGUI_TabControl.h:21
MyGUI::TabControl::TabItemInfo::data
Any data
Definition: MyGUI_TabControl.h:53
MyGUI::TabControl
TabControl properties. TabControl_skin_childs Skin childs. TabControl widget description should be h...
Definition: MyGUI_TabControl.h:26
MyGUI::Any::Null
static AnyEmpty Null
Definition: MyGUI_Any.h:67
MyGUI::TabControl::TabItemInfo::name
UString name
Definition: MyGUI_TabControl.h:51