Crazy Eddie's GUI System  0.8.4
TabControl.h
00001 /***********************************************************************
00002         created:        08/08/2004
00003         author:         Steve Streeting
00004 
00005         purpose:        Interface to base class for TabControl widget
00006 *************************************************************************/
00007 /***************************************************************************
00008  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00009  *
00010  *   Permission is hereby granted, free of charge, to any person obtaining
00011  *   a copy of this software and associated documentation files (the
00012  *   "Software"), to deal in the Software without restriction, including
00013  *   without limitation the rights to use, copy, modify, merge, publish,
00014  *   distribute, sublicense, and/or sell copies of the Software, and to
00015  *   permit persons to whom the Software is furnished to do so, subject to
00016  *   the following conditions:
00017  *
00018  *   The above copyright notice and this permission notice shall be
00019  *   included in all copies or substantial portions of the Software.
00020  *
00021  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00022  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00023  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00024  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00025  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00026  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00027  *   OTHER DEALINGS IN THE SOFTWARE.
00028  ***************************************************************************/
00029 #ifndef _CEGUITabControl_h_
00030 #define _CEGUITabControl_h_
00031 
00032 #include "../Base.h"
00033 #include "../Window.h"
00034 #include <vector>
00035 
00036 
00037 #if defined(_MSC_VER)
00038 #       pragma warning(push)
00039 #       pragma warning(disable : 4251)
00040 #endif
00041 
00042 
00043 // Start of CEGUI namespace section
00044 namespace CEGUI
00045 {
00046 
00047     // Forward declaration
00048     class TabButton;
00049 
00054 class CEGUIEXPORT TabControlWindowRenderer : public WindowRenderer
00055 {
00056 public:
00061     TabControlWindowRenderer(const String& name);
00062 
00071     virtual TabButton*  createTabButton(const String& name) const       = 0;
00072 };
00073 
00078 class CEGUIEXPORT TabControl : public Window
00079 {
00080 public:
00081         static const String EventNamespace;                             
00082     static const String WidgetTypeName;             
00083 
00084         enum TabPanePosition
00085         {
00086                 Top,
00087                 Bottom
00088         };
00089 
00090         /*************************************************************************
00091                 Constants
00092         *************************************************************************/
00093         // event names
00099         static const String EventSelectionChanged;
00100 
00101     /*************************************************************************
00102         Child Widget name constants
00103     *************************************************************************/
00104     static const String ContentPaneName;   
00105     static const String TabButtonName;     
00106     static const String TabButtonPaneName; 
00107     static const String ButtonScrollLeft;  
00108     static const String ButtonScrollRight; 
00109 
00110 
00111         /*************************************************************************
00112                 Accessor Methods
00113         *************************************************************************/
00121         size_t  getTabCount(void) const;
00122 
00129         TabPanePosition getTabPanePosition(void) const
00130         { return d_tabPanePos; }
00131 
00138         void    setTabPanePosition(TabPanePosition pos);
00139 
00146     void    setSelectedTab(const String &name);
00147 
00154     void    setSelectedTab(uint ID);
00155 
00162     void    setSelectedTabAtIndex(size_t index);
00163 
00169     void    makeTabVisible(const String &name);
00170 
00176     void    makeTabVisible(uint ID);
00177 
00183     void    makeTabVisibleAtIndex(size_t index);
00184 
00197     Window*     getTabContentsAtIndex(size_t index) const;
00198 
00211     Window*     getTabContents(const String& name) const;
00212 
00225     Window*     getTabContents(uint ID) const;
00226 
00239     bool        isTabContentsSelected(Window* wnd) const;
00240 
00248     size_t      getSelectedTabIndex() const;
00249 
00254     const UDim& getTabHeight(void) const { return d_tabHeight; }
00255 
00260     const UDim& getTabTextPadding(void) const { return d_tabPadding; }
00261 
00262 
00263     /*************************************************************************
00264                 Manipulator Methods
00265         *************************************************************************/
00276         virtual void    initialiseComponents(void);
00277 
00282     void setTabHeight(const UDim& height);
00283 
00288     void setTabTextPadding(const UDim& padding);
00289 
00298     void addTab(Window* wnd);
00305     void removeTab(const String& name);
00312     void removeTab(uint ID);
00313 
00314 
00315         /*************************************************************************
00316                 Construction and Destruction
00317         *************************************************************************/
00322         TabControl(const String& type, const String& name);
00323 
00324 
00329         virtual ~TabControl(void);
00330 
00331 
00332 protected:
00333 
00334         /*************************************************************************
00335                 Implementation Functions
00336         *************************************************************************/
00347     virtual     void    drawSelf(const RenderingContext&) { /* do nothing; rendering handled by children */ }
00348 
00353     virtual void addButtonForTabContent(Window* wnd);
00358     virtual void removeButtonForTabContent(Window* wnd);
00364         TabButton* getButtonForTabContents(Window* wnd) const;
00369     String makeButtonName(Window* wnd);
00370 
00377     virtual void selectTab_impl(Window* wnd);
00378 
00379 
00386     virtual void makeTabVisible_impl(Window* wnd);
00387 
00399     Window* getTabButtonPane() const;
00400 
00412     Window* getTabPane() const;
00413 
00414     void performChildWindowLayout(bool nonclient_sized_hint = false,
00415                                   bool client_sized_hint = false);
00416     int writeChildWindowsXML(XMLSerializer& xml_stream) const;
00417 
00418     // validate window renderer
00419     virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
00420 
00429     TabButton*  createTabButton(const String& name) const;
00430 
00432     void removeTab_impl(Window* window);
00433 
00434         /*************************************************************************
00435                 New event handlers
00436         *************************************************************************/
00437 
00442         virtual void    onSelectionChanged(WindowEventArgs& e);
00443 
00452         virtual void    onFontChanged(WindowEventArgs& e);
00453 
00454         /*************************************************************************
00455                 Implementation Data
00456         *************************************************************************/
00457     UDim        d_tabHeight;        
00458     UDim        d_tabPadding;       
00459     typedef std::vector<TabButton*
00460         CEGUI_VECTOR_ALLOC(TabButton*)> TabButtonVector;
00461     TabButtonVector d_tabButtonVector;  
00462     float       d_firstTabOffset;   
00463     TabPanePosition d_tabPanePos;   
00464     float       d_btGrabPos;        
00465 
00466     std::map<Window*, Event::ScopedConnection> d_eventConnections;
00467     /*************************************************************************
00468     Abstract Implementation Functions (must be provided by derived class)
00469     *************************************************************************/
00478     //virtual TabButton*        createTabButton_impl(const String& name) const          = 0;
00479 
00487     void calculateTabButtonSizePosition(size_t index);
00488 
00489 protected:
00490     /*************************************************************************
00491                 Private methods
00492         *************************************************************************/
00493         void    addTabControlProperties(void);
00494 
00495     void    addChild_impl(Element* element);
00496     void    removeChild_impl(Element* element);
00497     
00499     virtual NamedElement* getChildByNamePath_impl(const String& name_path) const;
00500 
00501     /*************************************************************************
00502     Event handlers
00503     *************************************************************************/
00504     bool handleContentWindowTextChanged(const EventArgs& args);
00505     bool handleTabButtonClicked(const EventArgs& args);
00506     bool handleScrollPane(const EventArgs& e);
00507     bool handleDraggedPane(const EventArgs& e);
00508     bool handleWheeledPane(const EventArgs& e);
00509 };
00510 
00511 template<>
00512 class PropertyHelper<TabControl::TabPanePosition>
00513 {
00514 public:
00515     typedef TabControl::TabPanePosition return_type;
00516     typedef return_type safe_method_return_type;
00517     typedef TabControl::TabPanePosition pass_type;
00518     typedef String string_return_type;
00519 
00520     static const String& getDataTypeName()
00521     {
00522         static String type("TabPanePosition");
00523 
00524         return type;
00525     }
00526 
00527     static return_type fromString(const String& str)
00528     {
00529         if (str == "Bottom")
00530         {
00531             return TabControl::Bottom;
00532         }
00533         else
00534         {
00535             return TabControl::Top;
00536         }
00537     }
00538 
00539     static string_return_type toString(pass_type val)
00540     {
00541         if (val == TabControl::Top)
00542         {
00543             return "Top";
00544         }
00545         else if (val == TabControl::Bottom)
00546         {
00547             return "Bottom";
00548         }
00549         else
00550         {
00551             assert(false && "Invalid Tab Pane Position");
00552             return "Top";
00553         }
00554     }
00555 };
00556 } // End of  CEGUI namespace section
00557 
00558 
00559 #if defined(_MSC_VER)
00560 #       pragma warning(pop)
00561 #endif
00562 
00563 #endif  // end of guard _CEGUITabControl_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends