Crazy Eddie's GUI System 0.8.7
widgets/TabControl.h
1/***********************************************************************
2 created: 08/08/2004
3 author: Steve Streeting
4
5 purpose: Interface to base class for TabControl widget
6*************************************************************************/
7/***************************************************************************
8 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 ***************************************************************************/
29#ifndef _CEGUITabControl_h_
30#define _CEGUITabControl_h_
31
32#include "../Base.h"
33#include "../Window.h"
34#include <vector>
35
36
37#if defined(_MSC_VER)
38# pragma warning(push)
39# pragma warning(disable : 4251)
40#endif
41
42
43// Start of CEGUI namespace section
44namespace CEGUI
45{
46
47 // Forward declaration
48 class TabButton;
49
54class CEGUIEXPORT TabControlWindowRenderer : public WindowRenderer
55{
56public:
62
71 virtual TabButton* createTabButton(const String& name) const = 0;
72};
73
78class CEGUIEXPORT TabControl : public Window
79{
80public:
81 static const String EventNamespace;
82 static const String WidgetTypeName;
83
84 enum TabPanePosition
85 {
86 Top,
87 Bottom
88 };
89
90 /*************************************************************************
91 Constants
92 *************************************************************************/
93 // event names
100
101 /*************************************************************************
102 Child Widget name constants
103 *************************************************************************/
104 static const String ContentPaneName;
105 static const String TabButtonName;
109
110
111 /*************************************************************************
112 Accessor Methods
113 *************************************************************************/
121 size_t getTabCount(void) const;
122
129 TabPanePosition getTabPanePosition(void) const
130 { return d_tabPanePos; }
131
138 void setTabPanePosition(TabPanePosition pos);
139
146 void setSelectedTab(const String &name);
147
154 void setSelectedTab(uint ID);
155
162 void setSelectedTabAtIndex(size_t index);
163
169 void makeTabVisible(const String &name);
170
176 void makeTabVisible(uint ID);
177
183 void makeTabVisibleAtIndex(size_t index);
184
197 Window* getTabContentsAtIndex(size_t index) const;
198
211 Window* getTabContents(const String& name) const;
212
225 Window* getTabContents(uint ID) const;
226
240
248 size_t getSelectedTabIndex() const;
249
254 const UDim& getTabHeight(void) const { return d_tabHeight; }
255
260 const UDim& getTabTextPadding(void) const { return d_tabPadding; }
261
262
263 /*************************************************************************
264 Manipulator Methods
265 *************************************************************************/
276 virtual void initialiseComponents(void);
277
282 void setTabHeight(const UDim& height);
283
288 void setTabTextPadding(const UDim& padding);
289
298 void addTab(Window* wnd);
305 void removeTab(const String& name);
312 void removeTab(uint ID);
313
314
315 /*************************************************************************
316 Construction and Destruction
317 *************************************************************************/
322 TabControl(const String& type, const String& name);
323
324
329 virtual ~TabControl(void);
330
331
332protected:
333
334 /*************************************************************************
335 Implementation Functions
336 *************************************************************************/
347 virtual void drawSelf(const RenderingContext&) { /* do nothing; rendering handled by children */ }
348
353 virtual void addButtonForTabContent(Window* wnd);
370
377 virtual void selectTab_impl(Window* wnd);
378
379
386 virtual void makeTabVisible_impl(Window* wnd);
387
400
413
414 void performChildWindowLayout(bool nonclient_sized_hint = false,
415 bool client_sized_hint = false);
416 int writeChildWindowsXML(XMLSerializer& xml_stream) const;
417
418 // validate window renderer
419 virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
420
429 TabButton* createTabButton(const String& name) const;
430
432 void removeTab_impl(Window* window);
433
434 /*************************************************************************
435 New event handlers
436 *************************************************************************/
437
443
453
454 /*************************************************************************
455 Implementation Data
456 *************************************************************************/
459 typedef std::vector<TabButton*
460 CEGUI_VECTOR_ALLOC(TabButton*)> TabButtonVector;
461 TabButtonVector d_tabButtonVector;
463 TabPanePosition d_tabPanePos;
466 std::map<Window*, Event::ScopedConnection> d_eventConnections;
467 /*************************************************************************
468 Abstract Implementation Functions (must be provided by derived class)
469 *************************************************************************/
478 //virtual TabButton* createTabButton_impl(const String& name) const = 0;
479
488
489protected:
490 /*************************************************************************
491 Private methods
492 *************************************************************************/
493 void addTabControlProperties(void);
494
495 void addChild_impl(Element* element);
496 void removeChild_impl(Element* element);
497
499 virtual NamedElement* getChildByNamePath_impl(const String& name_path) const;
500
501 /*************************************************************************
502 Event handlers
503 *************************************************************************/
504 bool handleContentWindowTextChanged(const EventArgs& args);
505 bool handleTabButtonClicked(const EventArgs& args);
506 bool handleScrollPane(const EventArgs& e);
507 bool handleDraggedPane(const EventArgs& e);
508 bool handleWheeledPane(const EventArgs& e);
509};
510
511template<>
512class PropertyHelper<TabControl::TabPanePosition>
513{
514public:
515 typedef TabControl::TabPanePosition return_type;
516 typedef return_type safe_method_return_type;
517 typedef TabControl::TabPanePosition pass_type;
519
520 static const String& getDataTypeName()
521 {
522 static String type("TabPanePosition");
523
524 return type;
525 }
526
527 static return_type fromString(const String& str)
528 {
529 if (str == "Bottom")
530 {
531 return TabControl::Bottom;
532 }
533 else
534 {
535 return TabControl::Top;
536 }
537 }
538
539 static string_return_type toString(pass_type val)
540 {
541 if (val == TabControl::Top)
542 {
543 return "Top";
544 }
545 else if (val == TabControl::Bottom)
546 {
547 return "Bottom";
548 }
549 else
550 {
551 assert(false && "Invalid Tab Pane Position");
552 return "Top";
553 }
554 }
555};
556} // End of CEGUI namespace section
557
558
559#if defined(_MSC_VER)
560# pragma warning(pop)
561#endif
562
563#endif // end of guard _CEGUITabControl_h_
A positioned and sized rectangular node in a tree graph.
Definition: Element.h:246
Base class used as the argument to all subscribers Event object.
Definition: EventArgs.h:51
Adds name to the Element class, including name path traversal.
Definition: NamedElement.h:76
Helper class used to convert various data types to and from the format expected in Property strings.
Definition: ForwardRefs.h:84
String class used within the GUI system.
Definition: String.h:64
Base class for TabButtons. A TabButton based class is used internally as the button that appears at t...
Definition: widgets/TabButton.h:45
Base class for TabControl window renderer objects.
Definition: widgets/TabControl.h:55
TabControlWindowRenderer(const String &name)
Constructor.
virtual TabButton * createTabButton(const String &name) const =0
create and return a pointer to a TabButton widget for use as a clickable tab header
Base class for standard Tab Control widget.
Definition: widgets/TabControl.h:79
void setTabTextPadding(const UDim &padding)
Set the amount of padding to add either side of the text in the tab.
void setTabPanePosition(TabPanePosition pos)
Change the positioning of the tab button pane.
std::map< Window *, Event::ScopedConnection > d_eventConnections
Container used to track event subscriptions to added tab windows.
Definition: widgets/TabControl.h:466
TabPanePosition d_tabPanePos
The position of the tab pane.
Definition: widgets/TabControl.h:463
Window * getTabButtonPane() const
Return a pointer to the tab button pane (Window)for this TabControl.
virtual void drawSelf(const RenderingContext &)
Perform the actual rendering for this Window.
Definition: widgets/TabControl.h:347
virtual void removeButtonForTabContent(Window *wnd)
Remove the TabButton for the specified child Window.
void removeChild_impl(Element *element)
Remove given element from child list.
virtual void selectTab_impl(Window *wnd)
Internal implementation of select tab.
void setSelectedTabAtIndex(size_t index)
Set the selected tab by the index position in the tab control. Also ensures that the tab is made visi...
Window * getTabContents(uint ID) const
Return the Window which is the tab content with the given ID.
Window * getTabPane() const
Return a pointer to the content component widget for this TabControl.
float d_firstTabOffset
The offset in pixels of the first tab.
Definition: widgets/TabControl.h:462
UDim d_tabPadding
The padding of the tabs relative to parent.
Definition: widgets/TabControl.h:458
virtual void addButtonForTabContent(Window *wnd)
Add a TabButton for the specified child Window.
void setSelectedTab(const String &name)
Set the selected tab by the name of the root window within it. Also ensures that the tab is made visi...
static const String TabButtonName
Widget name for the tab button components.
Definition: widgets/TabControl.h:105
static const String ButtonScrollLeft
Widget name for the scroll tabs to right pane component.
Definition: widgets/TabControl.h:107
TabPanePosition getTabPanePosition(void) const
Return the positioning of the tab pane.
Definition: widgets/TabControl.h:129
size_t getSelectedTabIndex() const
Return the index of the currently selected tab.
virtual void initialiseComponents(void)
Initialise the Window based object ready for use.
void calculateTabButtonSizePosition(size_t index)
create and return a pointer to a TabButton widget for use as a clickable tab header
static const String EventSelectionChanged
Definition: widgets/TabControl.h:99
void addTab(Window *wnd)
Add a new tab to the tab control.
TabControl(const String &type, const String &name)
Constructor for TabControl base class.
static const String ButtonScrollRight
Widget name for the scroll tabs to left pane component.
Definition: widgets/TabControl.h:108
static const String TabButtonPaneName
Widget name for the tab button pane component.
Definition: widgets/TabControl.h:106
size_t getTabCount(void) const
Return number of tabs.
virtual void makeTabVisible_impl(Window *wnd)
Internal implementation of make tab visible.
void removeTab(const String &name)
Remove the named tab from the tab control.
String makeButtonName(Window *wnd)
Construct a button name to handle a window.
TabButton * getButtonForTabContents(Window *wnd) const
Return the TabButton associated with this Window.
Window * getTabContents(const String &name) const
Return the Window which is the tab content with the given name.
void setTabHeight(const UDim &height)
Set the height of the tabs.
void removeTab_impl(Window *window)
Implementation function to do main work of removing a tab.
static const String EventNamespace
Namespace for global events.
Definition: widgets/TabControl.h:81
static const String ContentPaneName
Widget name for the tab content pane component.
Definition: widgets/TabControl.h:104
bool isTabContentsSelected(Window *wnd) const
void makeTabVisible(uint ID)
Ensure that the tab by the ID of the root window within it is visible.
float d_btGrabPos
Definition: widgets/TabControl.h:464
const UDim & getTabHeight(void) const
Return the height of the tabs.
Definition: widgets/TabControl.h:254
TabButton * createTabButton(const String &name) const
create and return a pointer to a TabButton widget for use as a clickable tab header
virtual ~TabControl(void)
Destructor for Listbox base class.
virtual void onSelectionChanged(WindowEventArgs &e)
Handler called internally when the currently selected item or items changes.
void addChild_impl(Element *element)
Add given element to child list at an appropriate position.
Window * getTabContentsAtIndex(size_t index) const
Return the Window which is the first child of the tab at index position index.
TabButtonVector d_tabButtonVector
Sorting for tabs.
Definition: widgets/TabControl.h:461
void makeTabVisibleAtIndex(size_t index)
Ensure that the tab by the index position in the tab control is visible.
UDim d_tabHeight
The height of the tabs in pixels.
Definition: widgets/TabControl.h:457
void makeTabVisible(const String &name)
Ensure that the tab by the name of the root window within it is visible.
virtual void onFontChanged(WindowEventArgs &e)
Handler called when the window's font is changed.
const UDim & getTabTextPadding(void) const
Return the amount of padding to add either side of the text in the tab.
Definition: widgets/TabControl.h:260
virtual bool validateWindowRenderer(const WindowRenderer *renderer) const
Function used in checking if a WindowRenderer is valid for this window.
void removeTab(uint ID)
Remove the tab with the given ID from the tab control.
virtual NamedElement * getChildByNamePath_impl(const String &name_path) const
Retrieves a child at name_path or 0 if none such exists.
void performChildWindowLayout(bool nonclient_sized_hint=false, bool client_sized_hint=false)
Layout child window content.
static const String WidgetTypeName
Window factory name.
Definition: widgets/TabControl.h:82
void setSelectedTab(uint ID)
Set the selected tab by the ID of the root window within it. Also ensures that the tab is made visibl...
Dimension that has both a relative 'scale' portion and and absolute 'offset' portion.
Definition: UDim.h:94
EventArgs based class that is used for objects passed to handlers triggered for events concerning som...
Definition: InputEvent.h:252
Base-class for the assignable WindowRenderer object.
Definition: WindowRenderer.h:52
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition: Window.h:151
Class used to create XML Document.
Definition: XMLSerializer.h:87
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
struct that holds some context relating to a RenderingSurface object.
Definition: RenderingContext.h:41