Crazy Eddies GUI System 0.7.6
CEGUITabControl.h
00001 /***********************************************************************
00002         filename:       CEGUITabControl.h
00003         created:        08/08/2004
00004         author:         Steve Streeting
00005 
00006         purpose:        Interface to base class for TabControl widget
00007 *************************************************************************/
00008 /***************************************************************************
00009  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00010  *
00011  *   Permission is hereby granted, free of charge, to any person obtaining
00012  *   a copy of this software and associated documentation files (the
00013  *   "Software"), to deal in the Software without restriction, including
00014  *   without limitation the rights to use, copy, modify, merge, publish,
00015  *   distribute, sublicense, and/or sell copies of the Software, and to
00016  *   permit persons to whom the Software is furnished to do so, subject to
00017  *   the following conditions:
00018  *
00019  *   The above copyright notice and this permission notice shall be
00020  *   included in all copies or substantial portions of the Software.
00021  *
00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00028  *   OTHER DEALINGS IN THE SOFTWARE.
00029  ***************************************************************************/
00030 #ifndef _CEGUITabControl_h_
00031 #define _CEGUITabControl_h_
00032 
00033 #include "../CEGUIBase.h"
00034 #include "../CEGUIWindow.h"
00035 #include "CEGUITabControlProperties.h"
00036 #include <vector>
00037 
00038 
00039 #if defined(_MSC_VER)
00040 #       pragma warning(push)
00041 #       pragma warning(disable : 4251)
00042 #endif
00043 
00044 
00045 // Start of CEGUI namespace section
00046 namespace CEGUI
00047 {
00048 
00049     // Forward declaration
00050     class TabButton;
00051 
00056 class CEGUIEXPORT TabControlWindowRenderer : public WindowRenderer
00057 {
00058 public:
00063     TabControlWindowRenderer(const String& name);
00064 
00073     virtual TabButton*  createTabButton(const String& name) const       = 0;
00074 };
00075 
00080 class CEGUIEXPORT TabControl : public Window
00081 {
00082 public:
00083         static const String EventNamespace;                             
00084     static const String WidgetTypeName;             
00085 
00086         enum TabPanePosition
00087         {
00088                 Top,
00089                 Bottom
00090         };
00091 
00092         /*************************************************************************
00093                 Constants
00094         *************************************************************************/
00095         // event names
00101         static const String EventSelectionChanged;
00102 
00103     /*************************************************************************
00104         Child Widget name suffix constants
00105     *************************************************************************/
00106     static const String ContentPaneNameSuffix; 
00107     static const String TabButtonNameSuffix;   
00108     static const String TabButtonPaneNameSuffix; 
00109     static const String ButtonScrollLeftSuffix;
00110     static const String ButtonScrollRightSuffix; 
00111 
00112 
00113         /*************************************************************************
00114                 Accessor Methods
00115         *************************************************************************/
00123         size_t  getTabCount(void) const;
00124 
00131         TabPanePosition getTabPanePosition(void) const
00132         { return d_tabPanePos; }
00133 
00140         void    setTabPanePosition(TabPanePosition pos);
00141 
00148     void    setSelectedTab(const String &name);
00149 
00156     void    setSelectedTab(uint ID);
00157 
00164     void    setSelectedTabAtIndex(size_t index);
00165 
00171     void    makeTabVisible(const String &name);
00172 
00178     void    makeTabVisible(uint ID);
00179 
00185     void    makeTabVisibleAtIndex(size_t index);
00186 
00199     Window*     getTabContentsAtIndex(size_t index) const;
00200 
00213     Window*     getTabContents(const String& name) const;
00214 
00227     Window*     getTabContents(uint ID) const;
00228 
00241     bool        isTabContentsSelected(Window* wnd) const;
00242 
00250     size_t      getSelectedTabIndex() const;
00251 
00256     const UDim& getTabHeight(void) const { return d_tabHeight; }
00257 
00262     const UDim& getTabTextPadding(void) const { return d_tabPadding; }
00263 
00264 
00265     /*************************************************************************
00266                 Manipulator Methods
00267         *************************************************************************/
00278         virtual void    initialiseComponents(void);
00279 
00284     void setTabHeight(const UDim& height);
00285 
00290     void setTabTextPadding(const UDim& padding);
00291 
00300     void addTab(Window* wnd);
00307     void removeTab(const String& name);
00314     void removeTab(uint ID);
00315 
00316 
00317         /*************************************************************************
00318                 Construction and Destruction
00319         *************************************************************************/
00324         TabControl(const String& type, const String& name);
00325 
00326 
00331         virtual ~TabControl(void);
00332 
00333 
00334 protected:
00335 
00336         /*************************************************************************
00337                 Implementation Functions
00338         *************************************************************************/
00349     virtual     void    drawSelf(const RenderingContext&) { /* do nothing; rendering handled by children */ }
00350 
00355     virtual void addButtonForTabContent(Window* wnd);
00360     virtual void removeButtonForTabContent(Window* wnd);
00366         TabButton* getButtonForTabContents(Window* wnd) const;
00371     String makeButtonName(Window* wnd);
00372 
00379     virtual void selectTab_impl(Window* wnd);
00380 
00381 
00388     virtual void makeTabVisible_impl(Window* wnd);
00389 
00390 
00401         virtual bool    testClassName_impl(const String& class_name) const
00402         {
00403                 if (class_name=="TabControl")   return true;
00404                 return Window::testClassName_impl(class_name);
00405         }
00406 
00418     Window* getTabButtonPane() const;
00419 
00431     Window* getTabPane() const;
00432 
00433         void performChildWindowLayout();
00434     int writeChildWindowsXML(XMLSerializer& xml_stream) const;
00435 
00436     // validate window renderer
00437     virtual bool validateWindowRenderer(const String& name) const
00438     {
00439         return (name == "TabControl");
00440     }
00441 
00450     TabButton*  createTabButton(const String& name) const;
00451 
00453     void removeTab_impl(Window* window);
00454 
00455         /*************************************************************************
00456                 New event handlers
00457         *************************************************************************/
00458 
00463         virtual void    onSelectionChanged(WindowEventArgs& e);
00464 
00473         virtual void    onFontChanged(WindowEventArgs& e);
00474 
00475         /*************************************************************************
00476                 Implementation Data
00477         *************************************************************************/
00478     UDim        d_tabHeight;        
00479     UDim        d_tabPadding;       
00480     typedef std::vector<TabButton*> TabButtonVector;
00481     TabButtonVector d_tabButtonVector;  
00482     float       d_firstTabOffset;   
00483     TabPanePosition d_tabPanePos;   
00484     float       d_btGrabPos;        
00485 
00486     std::map<Window*, Event::ScopedConnection> d_eventConnections;
00487     /*************************************************************************
00488     Abstract Implementation Functions (must be provided by derived class)
00489     *************************************************************************/
00498     //virtual TabButton*        createTabButton_impl(const String& name) const          = 0;
00499 
00507     void calculateTabButtonSizePosition(size_t index);
00508 
00509 protected:
00510         /*************************************************************************
00511                 Static Properties for this class
00512         *************************************************************************/
00513     static TabControlProperties::TabHeight       d_tabHeightProperty;
00514     static TabControlProperties::TabTextPadding  d_tabTextPaddingProperty;
00515     static TabControlProperties::TabPanePosition d_tabPanePosition;
00516 
00517     /*************************************************************************
00518                 Private methods
00519         *************************************************************************/
00520         void    addTabControlProperties(void);
00521 
00522     void    addChild_impl(Window* wnd);
00523     void    removeChild_impl(Window* wnd);
00524 
00525     /*************************************************************************
00526     Event handlers
00527     *************************************************************************/
00528     bool handleContentWindowTextChanged(const EventArgs& args);
00529     bool handleTabButtonClicked(const EventArgs& args);
00530     bool handleScrollPane(const EventArgs& e);
00531     bool handleDraggedPane(const EventArgs& e);
00532     bool handleWheeledPane(const EventArgs& e);
00533 };
00534 
00535 
00536 } // End of  CEGUI namespace section
00537 
00538 
00539 #if defined(_MSC_VER)
00540 #       pragma warning(pop)
00541 #endif
00542 
00543 #endif  // end of guard _CEGUITabControl_h_