Crazy Eddie's GUI System  0.8.3
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/TabControl.h
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  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUITabControl_h_
31 #define _CEGUITabControl_h_
32 
33 #include "../Base.h"
34 #include "../Window.h"
35 #include <vector>
36 
37 
38 #if defined(_MSC_VER)
39 # pragma warning(push)
40 # pragma warning(disable : 4251)
41 #endif
42 
43 
44 // Start of CEGUI namespace section
45 namespace CEGUI
46 {
47 
48  // Forward declaration
49  class TabButton;
50 
55 class CEGUIEXPORT TabControlWindowRenderer : public WindowRenderer
56 {
57 public:
62  TabControlWindowRenderer(const String& name);
63 
72  virtual TabButton* createTabButton(const String& name) const = 0;
73 };
74 
79 class CEGUIEXPORT TabControl : public Window
80 {
81 public:
82  static const String EventNamespace;
83  static const String WidgetTypeName;
84 
85  enum TabPanePosition
86  {
87  Top,
88  Bottom
89  };
90 
91  /*************************************************************************
92  Constants
93  *************************************************************************/
94  // event names
101 
102  /*************************************************************************
103  Child Widget name constants
104  *************************************************************************/
105  static const String ContentPaneName;
106  static const String TabButtonName;
107  static const String TabButtonPaneName;
108  static const String ButtonScrollLeft;
109  static const String ButtonScrollRight;
110 
111 
112  /*************************************************************************
113  Accessor Methods
114  *************************************************************************/
122  size_t getTabCount(void) const;
123 
130  TabPanePosition getTabPanePosition(void) const
131  { return d_tabPanePos; }
132 
139  void setTabPanePosition(TabPanePosition pos);
140 
147  void setSelectedTab(const String &name);
148 
155  void setSelectedTab(uint ID);
156 
163  void setSelectedTabAtIndex(size_t index);
164 
170  void makeTabVisible(const String &name);
171 
177  void makeTabVisible(uint ID);
178 
184  void makeTabVisibleAtIndex(size_t index);
185 
198  Window* getTabContentsAtIndex(size_t index) const;
199 
212  Window* getTabContents(const String& name) const;
213 
226  Window* getTabContents(uint ID) const;
227 
240  bool isTabContentsSelected(Window* wnd) const;
241 
249  size_t getSelectedTabIndex() const;
250 
255  const UDim& getTabHeight(void) const { return d_tabHeight; }
256 
261  const UDim& getTabTextPadding(void) const { return d_tabPadding; }
262 
263 
264  /*************************************************************************
265  Manipulator Methods
266  *************************************************************************/
277  virtual void initialiseComponents(void);
278 
283  void setTabHeight(const UDim& height);
284 
289  void setTabTextPadding(const UDim& padding);
290 
299  void addTab(Window* wnd);
306  void removeTab(const String& name);
313  void removeTab(uint ID);
314 
315 
316  /*************************************************************************
317  Construction and Destruction
318  *************************************************************************/
323  TabControl(const String& type, const String& name);
324 
325 
330  virtual ~TabControl(void);
331 
332 
333 protected:
334 
335  /*************************************************************************
336  Implementation Functions
337  *************************************************************************/
348  virtual void drawSelf(const RenderingContext&) { /* do nothing; rendering handled by children */ }
349 
354  virtual void addButtonForTabContent(Window* wnd);
359  virtual void removeButtonForTabContent(Window* wnd);
365  TabButton* getButtonForTabContents(Window* wnd) const;
370  String makeButtonName(Window* wnd);
371 
378  virtual void selectTab_impl(Window* wnd);
379 
380 
387  virtual void makeTabVisible_impl(Window* wnd);
388 
400  Window* getTabButtonPane() const;
401 
413  Window* getTabPane() const;
414 
415  void performChildWindowLayout(bool nonclient_sized_hint = false,
416  bool client_sized_hint = false);
417  int writeChildWindowsXML(XMLSerializer& xml_stream) const;
418 
419  // validate window renderer
420  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
421 
430  TabButton* createTabButton(const String& name) const;
431 
433  void removeTab_impl(Window* window);
434 
435  /*************************************************************************
436  New event handlers
437  *************************************************************************/
438 
443  virtual void onSelectionChanged(WindowEventArgs& e);
444 
453  virtual void onFontChanged(WindowEventArgs& e);
454 
455  /*************************************************************************
456  Implementation Data
457  *************************************************************************/
460  typedef std::vector<TabButton*
461  CEGUI_VECTOR_ALLOC(TabButton*)> TabButtonVector;
462  TabButtonVector d_tabButtonVector;
464  TabPanePosition d_tabPanePos;
465  float d_btGrabPos;
466 
467  std::map<Window*, Event::ScopedConnection> d_eventConnections;
468  /*************************************************************************
469  Abstract Implementation Functions (must be provided by derived class)
470  *************************************************************************/
479  //virtual TabButton* createTabButton_impl(const String& name) const = 0;
480 
488  void calculateTabButtonSizePosition(size_t index);
489 
490 protected:
491  /*************************************************************************
492  Private methods
493  *************************************************************************/
494  void addTabControlProperties(void);
495 
496  void addChild_impl(Element* element);
497  void removeChild_impl(Element* element);
498 
500  virtual NamedElement* getChildByNamePath_impl(const String& name_path) const;
501 
502  /*************************************************************************
503  Event handlers
504  *************************************************************************/
505  bool handleContentWindowTextChanged(const EventArgs& args);
506  bool handleTabButtonClicked(const EventArgs& args);
507  bool handleScrollPane(const EventArgs& e);
508  bool handleDraggedPane(const EventArgs& e);
509  bool handleWheeledPane(const EventArgs& e);
510 };
511 
512 template<>
513 class PropertyHelper<TabControl::TabPanePosition>
514 {
515 public:
516  typedef TabControl::TabPanePosition return_type;
517  typedef return_type safe_method_return_type;
518  typedef TabControl::TabPanePosition pass_type;
519  typedef String string_return_type;
520 
521  static const String& getDataTypeName()
522  {
523  static String type("TabPanePosition");
524 
525  return type;
526  }
527 
528  static return_type fromString(const String& str)
529  {
530  if (str == "Bottom")
531  {
532  return TabControl::Bottom;
533  }
534  else
535  {
536  return TabControl::Top;
537  }
538  }
539 
540  static string_return_type toString(pass_type val)
541  {
542  if (val == TabControl::Top)
543  {
544  return "Top";
545  }
546  else if (val == TabControl::Bottom)
547  {
548  return "Bottom";
549  }
550  else
551  {
552  assert(false && "Invalid Tab Pane Position");
553  return "Top";
554  }
555  }
556 };
557 } // End of CEGUI namespace section
558 
559 
560 #if defined(_MSC_VER)
561 # pragma warning(pop)
562 #endif
563 
564 #endif // end of guard _CEGUITabControl_h_