Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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 
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 
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_