Crazy Eddies GUI System  0.7.8
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
102 
103  /*************************************************************************
104  Child Widget name suffix constants
105  *************************************************************************/
111 
112 
113  /*************************************************************************
114  Accessor Methods
115  *************************************************************************/
123  size_t getTabCount(void) const;
124 
131  TabPanePosition getTabPanePosition(void) const
132  { return d_tabPanePos; }
133 
140  void setTabPanePosition(TabPanePosition pos);
141 
148  void setSelectedTab(const String &name);
149 
156  void setSelectedTab(uint ID);
157 
164  void setSelectedTabAtIndex(size_t index);
165 
171  void makeTabVisible(const String &name);
172 
178  void makeTabVisible(uint ID);
179 
185  void makeTabVisibleAtIndex(size_t index);
186 
199  Window* getTabContentsAtIndex(size_t index) const;
200 
213  Window* getTabContents(const String& name) const;
214 
227  Window* getTabContents(uint ID) const;
228 
241  bool isTabContentsSelected(Window* wnd) const;
242 
250  size_t getSelectedTabIndex() const;
251 
256  const UDim& getTabHeight(void) const { return d_tabHeight; }
257 
262  const UDim& getTabTextPadding(void) const { return d_tabPadding; }
263 
264 
265  /*************************************************************************
266  Manipulator Methods
267  *************************************************************************/
278  virtual void initialiseComponents(void);
279 
284  void setTabHeight(const UDim& height);
285 
290  void setTabTextPadding(const UDim& padding);
291 
300  void addTab(Window* wnd);
307  void removeTab(const String& name);
314  void removeTab(uint ID);
315 
316 
317  /*************************************************************************
318  Construction and Destruction
319  *************************************************************************/
324  TabControl(const String& type, const String& name);
325 
326 
331  virtual ~TabControl(void);
332 
333 
334 protected:
335 
336  /*************************************************************************
337  Implementation Functions
338  *************************************************************************/
349  virtual void drawSelf(const RenderingContext&) { /* do nothing; rendering handled by children */ }
350 
355  virtual void addButtonForTabContent(Window* wnd);
360  virtual void removeButtonForTabContent(Window* wnd);
366  TabButton* getButtonForTabContents(Window* wnd) const;
371  String makeButtonName(Window* wnd);
372 
379  virtual void selectTab_impl(Window* wnd);
380 
381 
388  virtual void makeTabVisible_impl(Window* wnd);
389 
390 
401  virtual bool testClassName_impl(const String& class_name) const
402  {
403  if (class_name=="TabControl") return true;
404  return Window::testClassName_impl(class_name);
405  }
406 
418  Window* getTabButtonPane() const;
419 
431  Window* getTabPane() const;
432 
433  void performChildWindowLayout();
434  int writeChildWindowsXML(XMLSerializer& xml_stream) const;
435 
436  // validate window renderer
437  virtual bool validateWindowRenderer(const String& name) const
438  {
439  return (name == "TabControl");
440  }
441 
450  TabButton* createTabButton(const String& name) const;
451 
453  void removeTab_impl(Window* window);
454 
455  /*************************************************************************
456  New event handlers
457  *************************************************************************/
458 
463  virtual void onSelectionChanged(WindowEventArgs& e);
464 
473  virtual void onFontChanged(WindowEventArgs& e);
474 
475  /*************************************************************************
476  Implementation Data
477  *************************************************************************/
480  typedef std::vector<TabButton*> TabButtonVector;
481  TabButtonVector d_tabButtonVector;
483  TabPanePosition d_tabPanePos;
484  float d_btGrabPos;
485 
486  std::map<Window*, Event::ScopedConnection> d_eventConnections;
487  /*************************************************************************
488  Abstract Implementation Functions (must be provided by derived class)
489  *************************************************************************/
498  //virtual TabButton* createTabButton_impl(const String& name) const = 0;
499 
507  void calculateTabButtonSizePosition(size_t index);
508 
509 protected:
510  /*************************************************************************
511  Static Properties for this class
512  *************************************************************************/
513  static TabControlProperties::TabHeight d_tabHeightProperty;
514  static TabControlProperties::TabTextPadding d_tabTextPaddingProperty;
515  static TabControlProperties::TabPanePosition d_tabPanePosition;
516 
517  /*************************************************************************
518  Private methods
519  *************************************************************************/
520  void addTabControlProperties(void);
521 
522  void addChild_impl(Window* wnd);
523  void removeChild_impl(Window* wnd);
524 
525  /*************************************************************************
526  Event handlers
527  *************************************************************************/
528  bool handleContentWindowTextChanged(const EventArgs& args);
529  bool handleTabButtonClicked(const EventArgs& args);
530  bool handleScrollPane(const EventArgs& e);
531  bool handleDraggedPane(const EventArgs& e);
532  bool handleWheeledPane(const EventArgs& e);
533 };
534 
535 
536 } // End of CEGUI namespace section
537 
538 
539 #if defined(_MSC_VER)
540 # pragma warning(pop)
541 #endif
542 
543 #endif // end of guard _CEGUITabControl_h_