Crazy Eddie's GUI System  0.8.6
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
44 namespace CEGUI
45 {
46 
47  // Forward declaration
48  class TabButton;
49 
54 class CEGUIEXPORT TabControlWindowRenderer : public WindowRenderer
55 {
56 public:
61  TabControlWindowRenderer(const String& name);
62 
71  virtual TabButton* createTabButton(const String& name) const = 0;
72 };
73 
78 class CEGUIEXPORT TabControl : public Window
79 {
80 public:
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;
106  static const String TabButtonPaneName;
107  static const String ButtonScrollLeft;
108  static const String ButtonScrollRight;
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 
239  bool isTabContentsSelected(Window* wnd) const;
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 
332 protected:
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);
358  virtual void removeButtonForTabContent(Window* wnd);
364  TabButton* getButtonForTabContents(Window* wnd) const;
369  String makeButtonName(Window* wnd);
370 
377  virtual void selectTab_impl(Window* wnd);
378 
379 
386  virtual void makeTabVisible_impl(Window* wnd);
387 
399  Window* getTabButtonPane() const;
400 
412  Window* getTabPane() const;
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 
442  virtual void onSelectionChanged(WindowEventArgs& e);
443 
452  virtual void onFontChanged(WindowEventArgs& e);
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;
464  float d_btGrabPos;
465  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 
487  void calculateTabButtonSizePosition(size_t index);
488 
489 protected:
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 
511 template<>
512 class PropertyHelper<TabControl::TabPanePosition>
513 {
514 public:
515  typedef TabControl::TabPanePosition return_type;
516  typedef return_type safe_method_return_type;
517  typedef TabControl::TabPanePosition pass_type;
518  typedef String string_return_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_
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
TabButtonVector d_tabButtonVector
Sorting for tabs.
Definition: widgets/TabControl.h:461
Base class for standard Tab Control widget.
Definition: widgets/TabControl.h:78
static const String EventNamespace
Namespace for global events.
Definition: widgets/TabControl.h:81
static const String TabButtonName
Widget name for the tab button components.
Definition: widgets/TabControl.h:105
Adds name to the Element class, including name path traversal.
Definition: NamedElement.h:74
Base class for TabControl window renderer objects.
Definition: widgets/TabControl.h:54
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
A positioned and sized rectangular node in a tree graph.
Definition: Element.h:242
Base class used as the argument to all subscribers Event object.
Definition: EventArgs.h:49
struct that holds some context relating to a RenderingSurface object.
Definition: RenderingContext.h:39
UDim d_tabHeight
The height of the tabs in pixels.
Definition: widgets/TabControl.h:457
static const String TabButtonPaneName
Widget name for the tab button pane component.
Definition: widgets/TabControl.h:106
Base-class for the assignable WindowRenderer object.
Definition: WindowRenderer.h:50
Base class for TabButtons. A TabButton based class is used internally as the button that appears at t...
Definition: widgets/TabButton.h:44
const UDim & getTabHeight(void) const
Return the height of the tabs.
Definition: widgets/TabControl.h:254
float d_btGrabPos
Definition: widgets/TabControl.h:464
virtual void drawSelf(const RenderingContext &)
Perform the actual rendering for this Window.
Definition: widgets/TabControl.h:347
static const String EventSelectionChanged
Definition: widgets/TabControl.h:99
TabPanePosition d_tabPanePos
The position of the tab pane.
Definition: widgets/TabControl.h:463
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition: Window.h:149
static const String WidgetTypeName
Window factory name.
Definition: widgets/TabControl.h:82
Helper class used to convert various data types to and from the format expected in Property strings...
Definition: ForwardRefs.h:84
static const String ButtonScrollRight
Widget name for the scroll tabs to left pane component.
Definition: widgets/TabControl.h:108
static const String ButtonScrollLeft
Widget name for the scroll tabs to right pane component.
Definition: widgets/TabControl.h:107
EventArgs based class that is used for objects passed to handlers triggered for events concerning som...
Definition: InputEvent.h:251
TabPanePosition getTabPanePosition(void) const
Return the positioning of the tab pane.
Definition: widgets/TabControl.h:129
float d_firstTabOffset
The offset in pixels of the first tab.
Definition: widgets/TabControl.h:462
Dimension that has both a relative 'scale' portion and and absolute 'offset' portion.
Definition: UDim.h:92
static const String ContentPaneName
Widget name for the tab content pane component.
Definition: widgets/TabControl.h:104
Class used to create XML Document.
Definition: XMLSerializer.h:85
UDim d_tabPadding
The padding of the tabs relative to parent.
Definition: widgets/TabControl.h:458
String class used within the GUI system.
Definition: String.h:62