Crazy Eddies GUI System  0.7.1
CEGUITabControl.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 "../CEGUIBase.h"
34 #include "../CEGUIWindow.h"
35 #include "CEGUITabControlProperties.h"
36 #include <vector>
37 
38 
39 #if defined(_MSC_VER)
40 # pragma warning(push)
41 # pragma warning(disable : 4251)
42 #endif
43 
44 
45 // Start of CEGUI namespace section
46 namespace CEGUI
47 {
48 
49  // Forward declaration
50  class TabButton;
51 
56 class CEGUIEXPORT TabControlWindowRenderer : public WindowRenderer
57 {
58 public:
63  TabControlWindowRenderer(const String& name);
64 
73  virtual TabButton* createTabButton(const String& name) const = 0;
74 };
75 
80 class CEGUIEXPORT TabControl : public Window
81 {
82 public:
83  static const String EventNamespace;
84  static const String WidgetTypeName;
85 
86  enum TabPanePosition
87  {
88  Top,
89  Bottom
90  };
91 
92  /*************************************************************************
93  Constants
94  *************************************************************************/
95  // event names
97 
98  /*************************************************************************
99  Child Widget name suffix constants
100  *************************************************************************/
106 
107 
108  /*************************************************************************
109  Accessor Methods
110  *************************************************************************/
118  size_t getTabCount(void) const;
119 
126  TabPanePosition getTabPanePosition(void) const
127  { return d_tabPanePos; }
128 
135  void setTabPanePosition(TabPanePosition pos);
136 
143  void setSelectedTab(const String &name);
144 
151  void setSelectedTab(uint ID);
152 
159  void setSelectedTabAtIndex(size_t index);
160 
166  void makeTabVisible(const String &name);
167 
173  void makeTabVisible(uint ID);
174 
180  void makeTabVisibleAtIndex(size_t index);
181 
194  Window* getTabContentsAtIndex(size_t index) const;
195 
208  Window* getTabContents(const String& name) const;
209 
222  Window* getTabContents(uint ID) const;
223 
236  bool isTabContentsSelected(Window* wnd) const;
237 
245  size_t getSelectedTabIndex() const;
246 
251  const UDim& getTabHeight(void) const { return d_tabHeight; }
252 
257  const UDim& getTabTextPadding(void) const { return d_tabPadding; }
258 
259 
260  /*************************************************************************
261  Manipulator Methods
262  *************************************************************************/
273  virtual void initialiseComponents(void);
274 
279  void setTabHeight(const UDim& height);
280 
285  void setTabTextPadding(const UDim& padding);
286 
295  void addTab(Window* wnd);
302  void removeTab(const String& name);
309  void removeTab(uint ID);
310 
311 
312  /*************************************************************************
313  Construction and Destruction
314  *************************************************************************/
319  TabControl(const String& type, const String& name);
320 
321 
326  virtual ~TabControl(void);
327 
328 
329 protected:
330 
331  /*************************************************************************
332  Implementation Functions
333  *************************************************************************/
344  virtual void drawSelf(const RenderingContext&) { /* do nothing; rendering handled by children */ }
345 
350  virtual void addButtonForTabContent(Window* wnd);
355  virtual void removeButtonForTabContent(Window* wnd);
361  TabButton* getButtonForTabContents(Window* wnd) const;
366  String makeButtonName(Window* wnd);
367 
374  virtual void selectTab_impl(Window* wnd);
375 
376 
383  virtual void makeTabVisible_impl(Window* wnd);
384 
385 
396  virtual bool testClassName_impl(const String& class_name) const
397  {
398  if (class_name=="TabControl") return true;
399  return Window::testClassName_impl(class_name);
400  }
401 
413  Window* getTabButtonPane() const;
414 
426  Window* getTabPane() const;
427 
428  void performChildWindowLayout();
429  int writeChildWindowsXML(XMLSerializer& xml_stream) const;
430 
431  // validate window renderer
432  virtual bool validateWindowRenderer(const String& name) const
433  {
434  return (name == "TabControl");
435  }
436 
445  TabButton* createTabButton(const String& name) const;
446 
448  void removeTab_impl(Window* window);
449 
450  /*************************************************************************
451  New event handlers
452  *************************************************************************/
453 
458  virtual void onSelectionChanged(WindowEventArgs& e);
459 
468  virtual void onFontChanged(WindowEventArgs& e);
469 
470  /*************************************************************************
471  Implementation Data
472  *************************************************************************/
475  typedef std::vector<TabButton*> TabButtonVector;
476  TabButtonVector d_tabButtonVector;
478  TabPanePosition d_tabPanePos;
479  float d_btGrabPos;
480 
481  std::map<Window*, Event::ScopedConnection> d_eventConnections;
482  /*************************************************************************
483  Abstract Implementation Functions (must be provided by derived class)
484  *************************************************************************/
493  //virtual TabButton* createTabButton_impl(const String& name) const = 0;
494 
502  void calculateTabButtonSizePosition(size_t index);
503 
504 protected:
505  /*************************************************************************
506  Static Properties for this class
507  *************************************************************************/
508  static TabControlProperties::TabHeight d_tabHeightProperty;
509  static TabControlProperties::TabTextPadding d_tabTextPaddingProperty;
510  static TabControlProperties::TabPanePosition d_tabPanePosition;
511 
512  /*************************************************************************
513  Private methods
514  *************************************************************************/
515  void addTabControlProperties(void);
516 
517  void addChild_impl(Window* wnd);
518  void removeChild_impl(Window* wnd);
519 
520  /*************************************************************************
521  Event handlers
522  *************************************************************************/
523  bool handleContentWindowTextChanged(const EventArgs& args);
524  bool handleTabButtonClicked(const EventArgs& args);
525  bool handleScrollPane(const EventArgs& e);
526  bool handleDraggedPane(const EventArgs& e);
527  bool handleWheeledPane(const EventArgs& e);
528 };
529 
530 
531 } // End of CEGUI namespace section
532 
533 
534 #if defined(_MSC_VER)
535 # pragma warning(pop)
536 #endif
537 
538 #endif // end of guard _CEGUITabControl_h_