1 | /************************************************************************
|
---|
2 | filename: CEGUITabControl.h
|
---|
3 | created: 08/08/2004
|
---|
4 | author: Steve Streeting
|
---|
5 |
|
---|
6 | purpose: Interface to base class for TabControl widget
|
---|
7 | *************************************************************************/
|
---|
8 | /*************************************************************************
|
---|
9 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
11 |
|
---|
12 | This library is free software; you can redistribute it and/or
|
---|
13 | modify it under the terms of the GNU Lesser General Public
|
---|
14 | License as published by the Free Software Foundation; either
|
---|
15 | version 2.1 of the License, or (at your option) any later version.
|
---|
16 |
|
---|
17 | This library is distributed in the hope that it will be useful,
|
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | Lesser General Public License for more details.
|
---|
21 |
|
---|
22 | You should have received a copy of the GNU Lesser General Public
|
---|
23 | License along with this library; if not, write to the Free Software
|
---|
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
25 | *************************************************************************/
|
---|
26 | #ifndef _CEGUITabControl_h_
|
---|
27 | #define _CEGUITabControl_h_
|
---|
28 |
|
---|
29 | #include "CEGUIBase.h"
|
---|
30 | #include "CEGUIWindow.h"
|
---|
31 | #include "elements/CEGUITabControlProperties.h"
|
---|
32 | #include "elements/CEGUITabPane.h"
|
---|
33 | #include <vector>
|
---|
34 |
|
---|
35 |
|
---|
36 | #if defined(_MSC_VER)
|
---|
37 | # pragma warning(push)
|
---|
38 | # pragma warning(disable : 4251)
|
---|
39 | #endif
|
---|
40 |
|
---|
41 |
|
---|
42 | // Start of CEGUI namespace section
|
---|
43 | namespace CEGUI
|
---|
44 | {
|
---|
45 |
|
---|
46 | // Forward declaration
|
---|
47 | class TabButton;
|
---|
48 |
|
---|
49 | /*!
|
---|
50 | \brief
|
---|
51 | Base class for standard Tab Control widget.
|
---|
52 | */
|
---|
53 | class CEGUIEXPORT TabControl : public Window
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | static const String EventNamespace; //!< Namespace for global events
|
---|
57 |
|
---|
58 |
|
---|
59 | /*************************************************************************
|
---|
60 | Constants
|
---|
61 | *************************************************************************/
|
---|
62 | // event names
|
---|
63 | static const String EventSelectionChanged; //!< Event triggered when there is a change to the currently selected tab.
|
---|
64 |
|
---|
65 |
|
---|
66 | /*************************************************************************
|
---|
67 | Accessor Methods
|
---|
68 | *************************************************************************/
|
---|
69 | /*!
|
---|
70 | \brief
|
---|
71 | Return number of tabs
|
---|
72 |
|
---|
73 | \return
|
---|
74 | the number of tabs currently present.
|
---|
75 | */
|
---|
76 | uint getTabCount(void) const;
|
---|
77 |
|
---|
78 |
|
---|
79 | /*!
|
---|
80 | \brief
|
---|
81 | Set the selected tab by the name of the root window within it.
|
---|
82 | \exception InvalidRequestException thrown if \a index is out of range.
|
---|
83 | */
|
---|
84 | void setSelectedTab(const String &name);
|
---|
85 |
|
---|
86 | /*!
|
---|
87 | \brief
|
---|
88 | Set the selected tab by the ID of the root window within it.
|
---|
89 | \exception InvalidRequestException thrown if \a index is out of range.
|
---|
90 | */
|
---|
91 | void setSelectedTab(uint ID);
|
---|
92 |
|
---|
93 | /*!
|
---|
94 | \brief
|
---|
95 | Set the selected tab by the index position in the tab control.
|
---|
96 | \exception InvalidRequestException thrown if \a index is out of range.
|
---|
97 | */
|
---|
98 | void setSelectedTabAtIndex(uint index);
|
---|
99 |
|
---|
100 | /*!
|
---|
101 | \brief
|
---|
102 | Return the Window which is the first child of the tab at index position \a index.
|
---|
103 |
|
---|
104 | \param index
|
---|
105 | Zero based index of the item to be returned.
|
---|
106 |
|
---|
107 | \return
|
---|
108 | Pointer to the Window at index position \a index in the tab control.
|
---|
109 |
|
---|
110 | \exception InvalidRequestException thrown if \a index is out of range.
|
---|
111 | */
|
---|
112 | Window* getTabContentsAtIndex(uint index) const;
|
---|
113 |
|
---|
114 | /*!
|
---|
115 | \brief
|
---|
116 | Return the Window which is the tab content with the given name.
|
---|
117 |
|
---|
118 | \param name
|
---|
119 | Name of the Window which was attached as a tab content.
|
---|
120 |
|
---|
121 | \return
|
---|
122 | Pointer to the named Window in the tab control.
|
---|
123 |
|
---|
124 | \exception InvalidRequestException thrown if content is not found.
|
---|
125 | */
|
---|
126 | Window* getTabContents(const String& name) const;
|
---|
127 |
|
---|
128 | /*!
|
---|
129 | \brief
|
---|
130 | Return the Window which is the tab content with the given ID.
|
---|
131 |
|
---|
132 | \param ID
|
---|
133 | ID of the Window which was attached as a tab content.
|
---|
134 |
|
---|
135 | \return
|
---|
136 | Pointer to the Window with the given ID in the tab control.
|
---|
137 |
|
---|
138 | \exception InvalidRequestException thrown if content is not found.
|
---|
139 | */
|
---|
140 | Window* getTabContents(uint ID) const;
|
---|
141 |
|
---|
142 | /*!
|
---|
143 | \brief
|
---|
144 | Return whether the tab contents window is currently selected.
|
---|
145 |
|
---|
146 | \param wnd
|
---|
147 | The tab contents window to query.
|
---|
148 |
|
---|
149 | \return
|
---|
150 | true if the tab is currently selected, false otherwise.
|
---|
151 |
|
---|
152 | \exception InvalidRequestException thrown if \a wnd is not a valid tab contents window.
|
---|
153 | */
|
---|
154 | bool isTabContentsSelected(Window* wnd) const;
|
---|
155 |
|
---|
156 | /*!
|
---|
157 | \brief
|
---|
158 | Return the index of the currently selected tab.
|
---|
159 |
|
---|
160 | \return
|
---|
161 | index of the currently selected tab.
|
---|
162 | */
|
---|
163 | uint getSelectedTabIndex() const;
|
---|
164 |
|
---|
165 | /*!
|
---|
166 | \brief
|
---|
167 | Return the relative height of the tabs
|
---|
168 | */
|
---|
169 | float getRelativeTabHeight(void) const { return d_rel_tabHeight; }
|
---|
170 | /*!
|
---|
171 | \brief
|
---|
172 | Return the absolute height of the tabs
|
---|
173 | */
|
---|
174 | float getAbsoluteTabHeight(void) const { return d_abs_tabHeight; }
|
---|
175 | /*!
|
---|
176 | \brief
|
---|
177 | Return the height of the tabs in the current metrics mode
|
---|
178 | */
|
---|
179 | float getTabHeight(void) const;
|
---|
180 | /*!
|
---|
181 | \brief
|
---|
182 | Return the amount of padding to add either side of the text in the tab,
|
---|
183 | according to the current metrics mode.
|
---|
184 | */
|
---|
185 | float getTabTextPadding(void) const;
|
---|
186 | /*!
|
---|
187 | \brief
|
---|
188 | Return the relative amount of padding to add either side of the text in the tab
|
---|
189 | */
|
---|
190 | float getRelativeTabTextPadding(void) const { return d_rel_tabPadding; }
|
---|
191 | /*!
|
---|
192 | \brief
|
---|
193 | Return the absolute amount of padding to add either side of the text in the tab
|
---|
194 | */
|
---|
195 | float getAbsoluteTabTextPadding(void) const { return d_abs_tabPadding; }
|
---|
196 |
|
---|
197 |
|
---|
198 | /*************************************************************************
|
---|
199 | Manipulator Methods
|
---|
200 | *************************************************************************/
|
---|
201 | /*!
|
---|
202 | \brief
|
---|
203 | Initialise the Window based object ready for use.
|
---|
204 |
|
---|
205 | \note
|
---|
206 | This must be called for every window created. Normally this is handled automatically by the WindowFactory for each Window type.
|
---|
207 |
|
---|
208 | \return
|
---|
209 | Nothing
|
---|
210 | */
|
---|
211 | virtual void initialise(void);
|
---|
212 |
|
---|
213 | /*!
|
---|
214 | \brief
|
---|
215 | Set the relative height of the tabs
|
---|
216 | */
|
---|
217 | void setRelativeTabHeight(float height);
|
---|
218 | /*!
|
---|
219 | \brief
|
---|
220 | Set the absolute height of the tabs
|
---|
221 | */
|
---|
222 | void setAbsoluteTabHeight(float height);
|
---|
223 | /*!
|
---|
224 | \brief
|
---|
225 | Set the height of the tabs in the current metrics mode
|
---|
226 | */
|
---|
227 | void setTabHeight(float height);
|
---|
228 |
|
---|
229 | /*!
|
---|
230 | \brief
|
---|
231 | Set the amount of padding to add either side of the text in the tab,
|
---|
232 | according to the current metrics mode.
|
---|
233 | */
|
---|
234 | void setTabTextPadding(float);
|
---|
235 | /*!
|
---|
236 | \brief
|
---|
237 | Set the relative amount of padding to add either side of the text in the tab
|
---|
238 | */
|
---|
239 | void setRelativeTabTextPadding(float);
|
---|
240 | /*!
|
---|
241 | \brief
|
---|
242 | Set the absolute amount of padding to add either side of the text in the tab
|
---|
243 | */
|
---|
244 | void setAbsoluteTabTextPadding(float);
|
---|
245 | /*!
|
---|
246 | \brief
|
---|
247 | Add a new tab to the tab control.
|
---|
248 | \par
|
---|
249 | The new tab will be added with the same text as the window passed in.
|
---|
250 | \param wnd
|
---|
251 | The Window which will be placed in the content area of this new tab.
|
---|
252 | */
|
---|
253 | void addTab(Window* wnd);
|
---|
254 | /*!
|
---|
255 | \brief
|
---|
256 | Remove the named tab from the tab control.
|
---|
257 | \par
|
---|
258 | The tab content will be destroyed.
|
---|
259 | */
|
---|
260 | void removeTab(const String& name);
|
---|
261 | /*!
|
---|
262 | \brief
|
---|
263 | Remove the tab with the given ID from the tab control.
|
---|
264 | \par
|
---|
265 | The tab content will be destroyed.
|
---|
266 | */
|
---|
267 | void removeTab(uint ID);
|
---|
268 |
|
---|
269 |
|
---|
270 | /*************************************************************************
|
---|
271 | Construction and Destruction
|
---|
272 | *************************************************************************/
|
---|
273 | /*!
|
---|
274 | \brief
|
---|
275 | Constructor for TabControl base class.
|
---|
276 | */
|
---|
277 | TabControl(const String& type, const String& name);
|
---|
278 |
|
---|
279 |
|
---|
280 | /*!
|
---|
281 | \brief
|
---|
282 | Destructor for Listbox base class.
|
---|
283 | */
|
---|
284 | virtual ~TabControl(void);
|
---|
285 |
|
---|
286 |
|
---|
287 | protected:
|
---|
288 |
|
---|
289 | /*************************************************************************
|
---|
290 | Implementation Functions
|
---|
291 | *************************************************************************/
|
---|
292 | /*!
|
---|
293 | \brief
|
---|
294 | Perform the actual rendering for this Window.
|
---|
295 |
|
---|
296 | \param z
|
---|
297 | float value specifying the base Z co-ordinate that should be used when rendering
|
---|
298 |
|
---|
299 | \return
|
---|
300 | Nothing
|
---|
301 | */
|
---|
302 | virtual void drawSelf(float z) { /* do nothing; rendering handled by children */ }
|
---|
303 |
|
---|
304 | /*!
|
---|
305 | \brief
|
---|
306 | Add tab control specific events
|
---|
307 | */
|
---|
308 | void addTabControlEvents(void);
|
---|
309 |
|
---|
310 | /*!
|
---|
311 | \brief
|
---|
312 | Add a TabButton for the specified child Window.
|
---|
313 | */
|
---|
314 | virtual void addButtonForTabContent(Window* wnd);
|
---|
315 | /*!
|
---|
316 | \brief
|
---|
317 | Remove the TabButton for the specified child Window.
|
---|
318 | */
|
---|
319 | virtual void removeButtonForTabContent(Window* wnd);
|
---|
320 | /*!
|
---|
321 | \brief
|
---|
322 | Return the TabButton associated with this Window.
|
---|
323 | \exception InvalidRequestException thrown if content is not found.
|
---|
324 | */
|
---|
325 | TabButton* getButtonForTabContents(Window* wnd) const;
|
---|
326 | /*!
|
---|
327 | \brief
|
---|
328 | Construct a button name to handle a window.
|
---|
329 | */
|
---|
330 | String makeButtonName(Window* wnd);
|
---|
331 |
|
---|
332 | /*!
|
---|
333 | \brief
|
---|
334 | Internal implementation of select tab.
|
---|
335 | \param wnd
|
---|
336 | Pointer to a Window which is the root of the tab content to select
|
---|
337 | */
|
---|
338 | virtual void selectTab_impl(Window* wnd);
|
---|
339 |
|
---|
340 |
|
---|
341 | /*!
|
---|
342 | \brief
|
---|
343 | Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
|
---|
344 |
|
---|
345 | \param class_name
|
---|
346 | The class name that is to be checked.
|
---|
347 |
|
---|
348 | \return
|
---|
349 | true if this window was inherited from \a class_name. false if not.
|
---|
350 | */
|
---|
351 | virtual bool testClassName_impl(const String& class_name) const
|
---|
352 | {
|
---|
353 | if (class_name==(const utf8*)"TabControl") return true;
|
---|
354 | return Window::testClassName_impl(class_name);
|
---|
355 | }
|
---|
356 |
|
---|
357 | void performChildWindowLayout();
|
---|
358 | int writeChildWindowsXML(OutStream& out_stream) const;
|
---|
359 |
|
---|
360 | /*************************************************************************
|
---|
361 | New event handlers
|
---|
362 | *************************************************************************/
|
---|
363 |
|
---|
364 | /*!
|
---|
365 | \brief
|
---|
366 | Handler called internally when the currently selected item or items changes.
|
---|
367 | */
|
---|
368 | virtual void onSelectionChanged(WindowEventArgs& e);
|
---|
369 |
|
---|
370 | /*!
|
---|
371 | \brief
|
---|
372 | Handler called when the window's font is changed.
|
---|
373 |
|
---|
374 | \param e
|
---|
375 | WindowEventArgs object whose 'window' pointer field is set to the window that triggered the event. For this
|
---|
376 | event the trigger window is always 'this'.
|
---|
377 | */
|
---|
378 | virtual void onFontChanged(WindowEventArgs& e);
|
---|
379 |
|
---|
380 | /*************************************************************************
|
---|
381 | Implementation Data
|
---|
382 | *************************************************************************/
|
---|
383 | Window* d_tabButtonPane; //!< The area containing the tab buttons
|
---|
384 | TabPane* d_tabContentPane; //!< The content area window
|
---|
385 | float d_abs_tabHeight; //!< The height of the tabs in pixels
|
---|
386 | float d_rel_tabHeight; //!< The height of the tabs relative to parent
|
---|
387 | float d_abs_tabPadding; //!< The padding of the tabs in pixels
|
---|
388 | float d_rel_tabPadding; //!< The padding of the tabs relative to parent
|
---|
389 | uint d_nextTabIndex; //!< The index to give the next tab
|
---|
390 | typedef std::map<uint, TabButton*> TabButtonIndexMap;
|
---|
391 | TabButtonIndexMap d_tabButtonIndexMap; //!< Sorting for tabs
|
---|
392 | /*************************************************************************
|
---|
393 | Abstract Implementation Functions (must be provided by derived class)
|
---|
394 | *************************************************************************/
|
---|
395 | /*!
|
---|
396 | \brief
|
---|
397 | create and return a pointer to a TabPane widget for use as content area
|
---|
398 |
|
---|
399 | \param name
|
---|
400 | String holding the name to be given to the new component.
|
---|
401 |
|
---|
402 | \return
|
---|
403 | Pointer to a TabPane to be used for holding the main content.
|
---|
404 | */
|
---|
405 | virtual TabPane* createTabContentPane(const String& name) const = 0;
|
---|
406 |
|
---|
407 | /*!
|
---|
408 | \brief
|
---|
409 | create and return a pointer to a widget for use as tab button area
|
---|
410 |
|
---|
411 | \param name
|
---|
412 | String holding the name to be given to the new component.
|
---|
413 |
|
---|
414 | \return
|
---|
415 | Pointer to a Static to be used for holding the tab buttons.
|
---|
416 | */
|
---|
417 | virtual Window* createTabButtonPane(const String& name) const;
|
---|
418 |
|
---|
419 | /*!
|
---|
420 | \brief
|
---|
421 | create and return a pointer to a TabButton widget for use as a clickable tab header
|
---|
422 | \param name
|
---|
423 | Button name
|
---|
424 | \return
|
---|
425 | Pointer to a TabButton to be used for changing tabs.
|
---|
426 | */
|
---|
427 | virtual TabButton* createTabButton(const String& name) const = 0;
|
---|
428 |
|
---|
429 | /*!
|
---|
430 | \brief
|
---|
431 | Calculate the correct position and size of a tab button, based on the
|
---|
432 | index it is due to be placed at.
|
---|
433 | \param btn
|
---|
434 | Pointer to a button to calculate the size and position for. This button
|
---|
435 | will be updated in place with these metrics.
|
---|
436 | \param targetIndex
|
---|
437 | The index at which the tab is/will be placed. Tabs must exist for all the
|
---|
438 | indexes before this.
|
---|
439 | */
|
---|
440 | void calculateTabButtonSizePosition(TabButton* btn, uint targetIndex);
|
---|
441 |
|
---|
442 | protected:
|
---|
443 | /*************************************************************************
|
---|
444 | Static Properties for this class
|
---|
445 | *************************************************************************/
|
---|
446 | static TabControlProperties::TabHeight d_tabHeightProperty;
|
---|
447 | static TabControlProperties::AbsoluteTabHeight d_absoluteTabHeightProperty;
|
---|
448 | static TabControlProperties::RelativeTabHeight d_relativeTabHeightProperty;
|
---|
449 |
|
---|
450 | static TabControlProperties::TabTextPadding d_tabTextPaddingProperty;
|
---|
451 | static TabControlProperties::AbsoluteTabTextPadding d_absoluteTabTextPaddingProperty;
|
---|
452 | static TabControlProperties::RelativeTabTextPadding d_relativeTabTextPaddingProperty;
|
---|
453 | /*************************************************************************
|
---|
454 | Private methods
|
---|
455 | *************************************************************************/
|
---|
456 | void addTabControlProperties(void);
|
---|
457 |
|
---|
458 | void addChild_impl(Window* wnd);
|
---|
459 | void removeChild_impl(Window* wnd);
|
---|
460 |
|
---|
461 | /*************************************************************************
|
---|
462 | Event handlers
|
---|
463 | *************************************************************************/
|
---|
464 | bool handleContentWindowTextChanged(const EventArgs& args);
|
---|
465 | bool handleTabButtonClicked(const EventArgs& args);
|
---|
466 | };
|
---|
467 |
|
---|
468 |
|
---|
469 |
|
---|
470 | } // End of CEGUI namespace section
|
---|
471 |
|
---|
472 |
|
---|
473 | #if defined(_MSC_VER)
|
---|
474 | # pragma warning(pop)
|
---|
475 | #endif
|
---|
476 |
|
---|
477 | #endif // end of guard _CEGUITabControl_h_
|
---|