MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_TabControl.h
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_TAB_CONTROL_H__
23 #define __MYGUI_TAB_CONTROL_H__
24
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Widget.h"
27 #include "MyGUI_Any.h"
28 #include "MyGUI_EventPair.h"
29 #include "MyGUI_ControllerFadeAlpha.h"
30 #include "MyGUI_IItem.h"
31 #include "MyGUI_IItemContainer.h"
32
33 namespace MyGUI
34 {
35
36 typedef delegates::CMultiDelegate2<TabControl*, size_t> EventHandle_TabPtrSizeT;
37
38 class MYGUI_EXPORT TabControl :
39 public Widget,
40 public IItemContainer,
41 public MemberObsolete<TabControl>
42 {
43 // для уведобления об удалении
44 //FIXME
45 friend class TabItem;
46
47 MYGUI_RTTI_DERIVED( TabControl )
48
49 public:
50 TabControl();
51
52 struct TabItemInfo
53 {
54 TabItemInfo(int _width, const UString& _name, TabItem* _item, Any _data) :
55 width(_width),
56 name(_name),
57 item(_item),
58 data(_data)
59 {
60 }
61
62 int width;
63 UString name;
64 TabItem* item;
65 Any data;
66 };
67
68 typedef std::vector<TabItemInfo> VectorTabItemInfo;
69
71 virtual void setPosition(const IntPoint& _value);
73 virtual void setSize(const IntSize& _value);
75 virtual void setCoord(const IntCoord& _value);
76
78 void setPosition(int _left, int _top);
80 void setSize(int _width, int _height);
82 void setCoord(int _left, int _top, int _width, int _height);
83
84 //------------------------------------------------------------------------------//
85 // манипуляции айтемами
86
88 size_t getItemCount() const;
89
91 TabItem* insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
93 TabItem* insertItem(TabItem* _to, const UString& _name, Any _data = Any::Null);
94
96 TabItem* addItem(const UString& _name, Any _data = Any::Null);
97
99 void removeItemAt(size_t _index);
101 void removeItem(TabItem* _item);
102
104 void removeAllItems();
105
106
108 TabItem* getItemAt(size_t _index);
109
111 size_t getItemIndex(TabItem* _item);
112
114 size_t findItemIndex(TabItem* _item);
115
117 size_t findItemIndexWith(const UString& _name);
118
120 TabItem* findItemWith(const UString& _name);
121
122 void swapItems(size_t _index1, size_t _index2);
123
124 //------------------------------------------------------------------------------//
125 // манипуляции выделениями
126
128 size_t getIndexSelected() const;
129
131 TabItem* getItemSelected();
132
134 void setIndexSelected(size_t _index);
135
137 void setItemSelected(TabItem* _item);
138
139
140 //------------------------------------------------------------------------------//
141 // манипуляции данными
142
144 void setItemDataAt(size_t _index, Any _data);
146 void setItemData(TabItem* _item, Any _data);
147
149 void clearItemDataAt(size_t _index);
151 void clearItemData(TabItem* _item);
152
154 template <typename ValueType>
155 ValueType* getItemDataAt(size_t _index, bool _throw = true)
156 {
157 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "TabControl::getItemDataAt");
158 return mItemsInfo[_index].data.castType<ValueType>(_throw);
159 }
161 template <typename ValueType>
162 ValueType* getItemData(TabItem* _item, bool _throw = true)
163 {
164 return getItemDataAt<ValueType>(getItemIndex(_item), _throw);
165 }
166
167
168 //------------------------------------------------------------------------------//
169 // манипуляции отображением
170
172 void setItemNameAt(size_t _index, const UString& _name);
173
175 void setItemName(TabItem* _item, const UString& _name);
176
178 const UString& getItemNameAt(size_t _index);
179
181 const UString& getItemName(TabItem* _item);
182
183
184 //------------------------------------------------------------------------------//
185 // манипуляции выдимостью
186
188 void beginToItemAt(size_t _index);
189
191 void beginToItem(TabItem* _item);
193 void beginToItemFirst();
195 void beginToItemLast();
197 void beginToItemSelected();
198
199
200 //------------------------------------------------------------------------------//
201 // остальные манипуляции
202
204 void setButtonWidthAt(size_t _index, int _width = DEFAULT);
206 void setButtonWidth(TabItem* _item, int _width = DEFAULT);
207
209 int getButtonWidthAt(size_t _index);
211 int getButtonWidth(TabItem* _item);
212
213 //------------------------------------------------------------------------------//
214
216 void setButtonDefaultWidth(int _value);
218 int getButtonDefaultWidth() const;
219
221 void setButtonAutoWidth(bool _value);
223 bool getButtonAutoWidth() const;
224
226 void setSmoothShow(bool _value);
228 bool getSmoothShow() const;
229
230 /*events:*/
236 EventPair<EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT>
237 eventTabChangeSelect;
238
239 /*internal:*/
240 // IItemContainer impl
241 virtual size_t _getItemCount();
242 virtual void _addItem(const MyGUI::UString& _name);
243 virtual void _removeItemAt(size_t _index);
244 virtual Widget* _getItemAt(size_t _index);
245 virtual void _setItemNameAt(size_t _index, const UString& _name);
246 virtual const UString& _getItemNameAt(size_t _index);
247
248 protected:
249 virtual void initialiseOverride();
250 virtual void shutdownOverride();
251
252 void updateBar();
253
254 void notifyPressedButtonEvent(MyGUI::Widget* _sender);
255 void notifyPressedBarButtonEvent(MyGUI::Widget* _sender);
256
257 int _getTextWidth(const UString& _text);
258
259 void _showItem(TabItem* _sheet, bool _show, bool _smooth);
260
261 void _createItemButton();
262
263 void _insertItem(size_t _index, const UString& _name, TabItem* _sheet, Any _data);
264
265 // вкладка при удалении уведомляет таб
266 void _notifyDeleteItem(TabItem* _item);
267
268 virtual void onWidgetCreated(Widget* _widget);
269
270 virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
271
272 private:
273 void actionWidgetHide(Widget* _widget);
274
275 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
276
277 Widget* _getWidgetTemplate();
278 Widget* _getWidgetBar();
279
280 Button* createButton();
281 void updateBarOld();
282 void updateBarNew();
283
284 private:
285 int mOffsetTab; // смещение бара при показе кнопок
286 bool mButtonShow;
287 int mWidthBar; // ширина в которую помещаються все кнопки
288 std::vector<Button*> mItemButton; // список кнопок, не должно равно списку страниц
289 std::string mButtonSkinName;
290 std::string mEmptySkinName;
291
292 Widget* mWidgetBar;
293 Button* mButtonLeft;
294 Button* mButtonRight;
295 Widget* mButtonDecor;
296 VectorWidgetPtr mWidgetsPatch; // список виджетов которые нужно показать при показе кнопки
297 Widget* mEmptyBarWidget;
298 Widget* mItemTemplate;
299
300 // информация о вкладках
301 VectorTabItemInfo mItemsInfo;
302 size_t mStartIndex;
303 size_t mIndexSelect;
304
305 int mButtonDefaultWidth;
306 bool mSmoothShow;
307 bool mButtonAutoWidth;
308
309 // флаг, чтобы отсеч уведомления от вкладок, при общем шутдауне виджета
310 bool mShutdown;
311
312 Widget* mHeaderPlace;
313 Widget* mControls;
314 Widget* mEmpty;
315 };
316
317 } // namespace MyGUI
318
319 #endif // __MYGUI_TAB_CONTROL_H__
MyGUI::types::TCoord< int >
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI::TabControl::VectorTabItemInfo
std::vector< TabItemInfo > VectorTabItemInfo
Definition: MyGUI_TabControl.h:68
MyGUI::TabItem
Definition: MyGUI_TabItem.h:32
MyGUI_IItemContainer.h
MyGUI::types::TPoint< int >
MyGUI_Prerequest.h
MyGUI::TabControl::TabItemInfo::width
int width
Definition: MyGUI_TabControl.h:62
MyGUI_IItem.h
MyGUI::types::TSize< int >
MyGUI::TabControl::TabItemInfo::item
TabItem * item
Definition: MyGUI_TabControl.h:64
MyGUI::Any
Definition: MyGUI_Any.h:81
MyGUI::TabControl::TabItemInfo::TabItemInfo
TabItemInfo(int _width, const UString &_name, TabItem *_item, Any _data)
Definition: MyGUI_TabControl.h:54
MyGUI::IItemContainer
Definition: MyGUI_IItemContainer.h:33
MyGUI::TabControl::getItemData
ValueType * getItemData(TabItem *_item, bool _throw=true)
Get item data.
Definition: MyGUI_TabControl.h:162
MyGUI::Button
Definition: MyGUI_Button.h:31
MyGUI::DEFAULT
const int DEFAULT
Definition: MyGUI_Macros.h:33
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:88
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:120
MyGUI::EventPair
Definition: MyGUI_EventPair.h:31
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition: MyGUI_WidgetDefines.h:33
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:155
MyGUI::delegates::CMultiDelegate2
Definition: MyGUI_Delegate.h:239
MyGUI::TabControl::TabItemInfo
Definition: MyGUI_TabControl.h:52
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition: MyGUI_Diagnostic.h:70
MyGUI::ControllerFadeAlpha
Definition: MyGUI_ControllerFadeAlpha.h:33
MyGUI_Widget.h
MyGUI::TabControl::eventTabChangeSelect
EventPair< EventHandle_WidgetSizeT, EventHandle_TabPtrSizeT > eventTabChangeSelect
Definition: MyGUI_TabControl.h:237
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:169
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:28
MyGUI_EventPair.h
MyGUI::EventHandle_TabPtrSizeT
delegates::CMultiDelegate2< TabControl *, size_t > EventHandle_TabPtrSizeT
Definition: MyGUI_TabControl.h:36
MyGUI::action::actionWidgetHide
void actionWidgetHide(Widget *_widget)
Definition: MyGUI_ActionController.cpp:34
MyGUI::TabControl::TabItemInfo::data
Any data
Definition: MyGUI_TabControl.h:65
MyGUI::TabControl
Definition: MyGUI_TabControl.h:38
MyGUI::Any::Null
static AnyEmpty Null
Definition: MyGUI_Any.h:85
MyGUI::TabControl::TabItemInfo::name
UString name
Definition: MyGUI_TabControl.h:63