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 "elements/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
00096         static const String EventSelectionChanged;                      
00097 
00098     /*************************************************************************
00099         Child Widget name suffix constants
00100     *************************************************************************/
00101     static const String ContentPaneNameSuffix; 
00102     static const String TabButtonNameSuffix;   
00103     static const String TabButtonPaneNameSuffix; 
00104     static const String ButtonScrollLeftSuffix;
00105     static const String ButtonScrollRightSuffix; 
00106 
00107 
00108         /*************************************************************************
00109                 Accessor Methods
00110         *************************************************************************/
00118         size_t  getTabCount(void) const;
00119 
00126         TabPanePosition getTabPanePosition(void) const
00127         { return d_tabPanePos; }
00128 
00135         void    setTabPanePosition(TabPanePosition pos);
00136 
00143     void    setSelectedTab(const String &name);
00144 
00151     void    setSelectedTab(uint ID);
00152 
00159     void    setSelectedTabAtIndex(size_t index);
00160 
00166     void    makeTabVisible(const String &name);
00167 
00173     void    makeTabVisible(uint ID);
00174 
00180     void    makeTabVisibleAtIndex(size_t index);
00181 
00194     Window*     getTabContentsAtIndex(size_t index) const;
00195 
00208     Window*     getTabContents(const String& name) const;
00209 
00222     Window*     getTabContents(uint ID) const;
00223 
00236     bool        isTabContentsSelected(Window* wnd) const;
00237 
00245     size_t      getSelectedTabIndex() const;
00246 
00251     const UDim& getTabHeight(void) const { return d_tabHeight; }
00252 
00257     const UDim& getTabTextPadding(void) const { return d_tabPadding; }
00258 
00259 
00260     /*************************************************************************
00261                 Manipulator Methods
00262         *************************************************************************/
00273         virtual void    initialiseComponents(void);
00274 
00279     void setTabHeight(const UDim& height);
00280 
00285     void setTabTextPadding(const UDim& padding);
00286 
00295     void addTab(Window* wnd);
00302     void removeTab(const String& name);
00309     void removeTab(uint ID);
00310 
00311 
00312         /*************************************************************************
00313                 Construction and Destruction
00314         *************************************************************************/
00319         TabControl(const String& type, const String& name);
00320 
00321 
00326         virtual ~TabControl(void);
00327 
00328 
00329 protected:
00330 
00331         /*************************************************************************
00332                 Implementation Functions
00333         *************************************************************************/
00344     virtual     void    drawSelf(float z) { /* do nothing; rendering handled by children */ }
00345 
00350     virtual void addButtonForTabContent(Window* wnd);
00355     virtual void removeButtonForTabContent(Window* wnd);
00361         TabButton* getButtonForTabContents(Window* wnd) const;
00366     String makeButtonName(Window* wnd);
00367 
00374     virtual void selectTab_impl(Window* wnd);
00375 
00376 
00383     virtual void makeTabVisible_impl(Window* wnd);
00384 
00385 
00396         virtual bool    testClassName_impl(const String& class_name) const
00397         {
00398                 if (class_name=="TabControl")   return true;
00399                 return Window::testClassName_impl(class_name);
00400         }
00401 
00413     Window* getTabButtonPane() const;
00414 
00426     Window* getTabPane() const;
00427 
00428         void performChildWindowLayout();
00429     int writeChildWindowsXML(XMLSerializer& xml_stream) const;
00430 
00431     // validate window renderer
00432     virtual bool validateWindowRenderer(const String& name) const
00433     {
00434         return (name == "TabControl");
00435     }
00436 
00445     TabButton*  createTabButton(const String& name) const;
00446 
00448     void removeTab_impl(Window* window);
00449 
00450         /*************************************************************************
00451                 New event handlers
00452         *************************************************************************/
00453 
00458         virtual void    onSelectionChanged(WindowEventArgs& e);
00459 
00468         virtual void    onFontChanged(WindowEventArgs& e);
00469 
00470         /*************************************************************************
00471                 Implementation Data
00472         *************************************************************************/
00473     UDim        d_tabHeight;        
00474     UDim        d_tabPadding;       
00475     typedef std::vector<TabButton*> TabButtonVector;
00476     TabButtonVector d_tabButtonVector;  
00477     float       d_firstTabOffset;   
00478     TabPanePosition d_tabPanePos;   
00479     float       d_btGrabPos;        
00480 
00481     std::map<Window*, Event::ScopedConnection> d_eventConnections;
00482     /*************************************************************************
00483     Abstract Implementation Functions (must be provided by derived class)
00484     *************************************************************************/
00493     //virtual TabButton*        createTabButton_impl(const String& name) const          = 0;
00494 
00502     void calculateTabButtonSizePosition(size_t index);
00503 
00504 protected:
00505         /*************************************************************************
00506                 Static Properties for this class
00507         *************************************************************************/
00508     static TabControlProperties::TabHeight       d_tabHeightProperty;
00509     static TabControlProperties::TabTextPadding  d_tabTextPaddingProperty;
00510     static TabControlProperties::TabPanePosition d_tabPanePosition;
00511 
00512     /*************************************************************************
00513                 Private methods
00514         *************************************************************************/
00515         void    addTabControlProperties(void);
00516 
00517     void    addChild_impl(Window* wnd);
00518     void    removeChild_impl(Window* wnd);
00519 
00520     /*************************************************************************
00521     Event handlers
00522     *************************************************************************/
00523     bool handleContentWindowTextChanged(const EventArgs& args);
00524     bool handleTabButtonClicked(const EventArgs& args);
00525     bool handleScrollPane(const EventArgs& e);
00526     bool handleDraggedPane(const EventArgs& e);
00527     bool handleWheeledPane(const EventArgs& e);
00528 };
00529 
00530 
00531 } // End of  CEGUI namespace section
00532 
00533 
00534 #if defined(_MSC_VER)
00535 #       pragma warning(pop)
00536 #endif
00537 
00538 #endif  // end of guard _CEGUITabControl_h_

Generated on Sat Jun 28 14:35:44 2008 for Crazy Eddies GUI System by  doxygen 1.5.4