source: OGRE/trunk/ogrenew/Dependencies/include/CEGUI/elements/CEGUITabControl.h @ 657

Revision 657, 14.8 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
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    Crazy Eddie's GUI System (http://www.cegui.org.uk)
10    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
11
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2.1 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25*************************************************************************/
26#ifndef _CEGUITabControl_h_
27#define _CEGUITabControl_h_
28
29#include "CEGUIBase.h"
30#include "CEGUIWindow.h"
31#include "elements/CEGUITabControlProperties.h"
32#include "elements/CEGUITabPane.h"
33#include <vector>
34
35
36#if defined(_MSC_VER)
37#       pragma warning(push)
38#       pragma warning(disable : 4251)
39#endif
40
41
42// Start of CEGUI namespace section
43namespace CEGUI
44{
45
46    // Forward declaration
47    class TabButton;
48
49/*!
50\brief
51        Base class for standard Tab Control widget.
52*/
53class CEGUIEXPORT TabControl : public Window
54{
55public:
56        static const String EventNamespace;                             //!< Namespace for global events
57
58
59        /*************************************************************************
60                Constants
61        *************************************************************************/
62        // event names
63        static const String EventSelectionChanged;                      //!< Event triggered when there is a change to the currently selected tab.
64
65
66        /*************************************************************************
67                Accessor Methods
68        *************************************************************************/
69        /*!
70        \brief
71                Return number of tabs
72
73        \return
74                the number of tabs currently present.
75        */
76        uint    getTabCount(void) const;
77
78
79    /*!
80    \brief
81        Set the selected tab by the name of the root window within it.
82    \exception  InvalidRequestException thrown if \a index is out of range.
83    */
84    void    setSelectedTab(const String &name);
85
86    /*!
87    \brief
88        Set the selected tab by the ID of the root window within it.
89    \exception  InvalidRequestException thrown if \a index is out of range.
90    */
91    void    setSelectedTab(uint ID);
92
93    /*!
94    \brief
95        Set the selected tab by the index position in the tab control.
96    \exception  InvalidRequestException thrown if \a index is out of range.
97    */
98    void    setSelectedTabAtIndex(uint index);
99
100    /*!
101        \brief
102                Return the Window which is the first child of the tab at index position \a index.
103
104        \param index
105                Zero based index of the item to be returned.
106
107        \return
108                Pointer to the Window at index position \a index in the tab control.
109
110        \exception      InvalidRequestException thrown if \a index is out of range.
111        */
112    Window*     getTabContentsAtIndex(uint index) const;
113
114    /*!
115    \brief
116        Return the Window which is the tab content with the given name.
117
118    \param name
119        Name of the Window which was attached as a tab content.
120
121    \return
122        Pointer to the named Window in the tab control.
123
124    \exception  InvalidRequestException thrown if content is not found.
125    */
126    Window*     getTabContents(const String& name) const;
127
128    /*!
129    \brief
130        Return the Window which is the tab content with the given ID.
131
132    \param ID
133        ID of the Window which was attached as a tab content.
134
135    \return
136        Pointer to the Window with the given ID in the tab control.
137
138    \exception  InvalidRequestException thrown if content is not found.
139    */
140    Window*     getTabContents(uint ID) const;
141
142    /*!
143        \brief
144                Return whether the tab contents window is currently selected.
145
146    \param wnd
147        The tab contents window to query.
148
149        \return
150                true if the tab is currently selected, false otherwise.
151
152        \exception      InvalidRequestException thrown if \a wnd is not a valid tab contents window.
153        */
154    bool        isTabContentsSelected(Window* wnd) const;
155
156    /*!
157        \brief
158                Return the index of the currently selected tab.
159
160        \return
161                index of the currently selected tab.
162        */
163    uint        getSelectedTabIndex() const;
164       
165    /*!
166    \brief
167        Return the relative height of the tabs
168    */
169    float getRelativeTabHeight(void) const { return d_rel_tabHeight; }
170    /*!
171    \brief
172        Return the absolute height of the tabs
173    */
174    float getAbsoluteTabHeight(void) const { return d_abs_tabHeight; }
175    /*!
176    \brief
177        Return the height of the tabs in the current metrics mode
178    */
179    float getTabHeight(void) const;
180    /*!
181    \brief
182        Return the amount of padding to add either side of the text in the tab,
183        according to the current metrics mode.
184    */
185    float getTabTextPadding(void) const;
186    /*!
187    \brief
188        Return the relative amount of padding to add either side of the text in the tab
189    */
190    float getRelativeTabTextPadding(void) const { return d_rel_tabPadding; }
191    /*!
192    \brief
193        Return the absolute amount of padding to add either side of the text in the tab
194    */
195    float getAbsoluteTabTextPadding(void) const { return d_abs_tabPadding; }
196
197
198    /*************************************************************************
199                Manipulator Methods
200        *************************************************************************/
201        /*!
202        \brief
203                Initialise the Window based object ready for use.
204
205        \note
206                This must be called for every window created.  Normally this is handled automatically by the WindowFactory for each Window type.
207
208        \return
209                Nothing
210        */
211        virtual void    initialise(void);
212
213    /*!
214    \brief
215        Set the relative height of the tabs
216    */
217    void setRelativeTabHeight(float height);
218    /*!
219    \brief
220        Set the absolute height of the tabs
221    */
222    void setAbsoluteTabHeight(float height);
223    /*!
224    \brief
225        Set the height of the tabs in the current metrics mode
226    */
227    void setTabHeight(float height);
228
229    /*!
230    \brief
231        Set the amount of padding to add either side of the text in the tab,
232        according to the current metrics mode.
233    */
234    void setTabTextPadding(float);
235    /*!
236    \brief
237        Set the relative amount of padding to add either side of the text in the tab
238    */
239    void setRelativeTabTextPadding(float);
240    /*!
241    \brief
242        Set the absolute amount of padding to add either side of the text in the tab
243    */
244    void setAbsoluteTabTextPadding(float);
245    /*!
246    \brief
247        Add a new tab to the tab control.
248    \par
249        The new tab will be added with the same text as the window passed in.
250    \param wnd
251        The Window which will be placed in the content area of this new tab.
252    */
253    void addTab(Window* wnd);
254    /*!
255    \brief
256        Remove the named tab from the tab control.
257    \par
258        The tab content will be destroyed.
259    */
260    void removeTab(const String& name);
261    /*!
262    \brief
263    Remove the tab with the given ID from the tab control.
264    \par
265    The tab content will be destroyed.
266    */
267    void removeTab(uint ID);
268
269
270        /*************************************************************************
271                Construction and Destruction
272        *************************************************************************/
273        /*!
274        \brief
275                Constructor for TabControl base class.
276        */
277        TabControl(const String& type, const String& name);
278
279
280        /*!
281        \brief
282                Destructor for Listbox base class.
283        */
284        virtual ~TabControl(void);
285
286
287protected:
288
289        /*************************************************************************
290                Implementation Functions
291        *************************************************************************/
292    /*!
293    \brief
294        Perform the actual rendering for this Window.
295
296    \param z
297        float value specifying the base Z co-ordinate that should be used when rendering
298
299    \return
300        Nothing
301    */
302    virtual     void    drawSelf(float z) { /* do nothing; rendering handled by children */ }
303
304    /*!
305        \brief
306                Add tab control specific events
307        */
308        void    addTabControlEvents(void);
309
310    /*!
311    \brief
312        Add a TabButton for the specified child Window.
313    */
314    virtual void addButtonForTabContent(Window* wnd);
315    /*!
316    \brief
317        Remove the TabButton for the specified child Window.
318    */
319    virtual void removeButtonForTabContent(Window* wnd);
320    /*!
321    \brief
322        Return the TabButton associated with this Window.
323    \exception  InvalidRequestException thrown if content is not found.
324    */
325        TabButton* getButtonForTabContents(Window* wnd) const;
326    /*!
327    \brief
328        Construct a button name to handle a window.
329    */
330    String makeButtonName(Window* wnd);
331   
332    /*!
333    \brief
334        Internal implementation of select tab.
335    \param wnd
336        Pointer to a Window which is the root of the tab content to select
337    */
338    virtual void selectTab_impl(Window* wnd);
339
340
341        /*!
342        \brief
343                Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
344
345        \param class_name
346                The class name that is to be checked.
347
348        \return
349                true if this window was inherited from \a class_name. false if not.
350        */
351        virtual bool    testClassName_impl(const String& class_name) const
352        {
353                if (class_name==(const utf8*)"TabControl")      return true;
354                return Window::testClassName_impl(class_name);
355        }
356
357
358        /*************************************************************************
359                New event handlers
360        *************************************************************************/
361
362        /*!
363        \brief
364                Handler called internally when the currently selected item or items changes.
365        */
366        virtual void    onSelectionChanged(WindowEventArgs& e);
367
368        /*!
369        \brief
370                Handler called when the window's font is changed.
371
372        \param e
373                WindowEventArgs object whose 'window' pointer field is set to the window that triggered the event.  For this
374                event the trigger window is always 'this'.
375        */
376        virtual void    onFontChanged(WindowEventArgs& e);
377        /*************************************************************************
378                Overridden Event handlers
379        *************************************************************************/
380    void onSized(WindowEventArgs& e);
381
382        /*************************************************************************
383                Implementation Data
384        *************************************************************************/
385    Window*     d_tabButtonPane;    //!< The area containing the tab buttons
386    TabPane*    d_tabContentPane;   //!< The content area window
387    float       d_abs_tabHeight;    //!< The height of the tabs in pixels
388    float       d_rel_tabHeight;    //!< The height of the tabs relative to parent
389    float       d_abs_tabPadding;    //!< The padding of the tabs in pixels
390    float       d_rel_tabPadding;    //!< The padding of the tabs relative to parent
391    uint        d_nextTabIndex;     //!< The index to give the next tab
392    typedef std::map<uint, TabButton*> TabButtonIndexMap;
393    TabButtonIndexMap d_tabButtonIndexMap;  //!< Sorting for tabs
394    /*************************************************************************
395    Abstract Implementation Functions (must be provided by derived class)
396    *************************************************************************/
397    /*!
398    \brief
399    create and return a pointer to a TabPane widget for use as content area
400
401    \return
402    Pointer to a TabPane to be used for holding the main content.
403    */
404    virtual TabPane*    createTabContentPane(void) const                = 0;
405
406    /*!
407    \brief
408        create and return a pointer to a widget for use as tab button area
409
410    \return
411        Pointer to a Static to be used for holding the tab buttons.
412    */
413    virtual Window*     createTabButtonPane(void) const;
414
415    /*!
416    \brief
417        create and return a pointer to a TabButton widget for use as a clickable tab header
418    \param name
419        Button name
420    \return
421        Pointer to a TabButton to be used for changing tabs.
422    */
423    virtual TabButton*  createTabButton(const String& name) const               = 0;
424
425    /*!
426    \brief
427        Calculate the correct position and size of a tab button, based on the
428        index it is due to be placed at.
429    \param btn
430        Pointer to a button to calculate the size and position for. This button
431        will be updated in place with these metrics.
432    \param targetIndex
433        The index at which the tab is/will be placed. Tabs must exist for all the
434        indexes before this.
435    */
436    void calculateTabButtonSizePosition(TabButton* btn, uint targetIndex);
437    /*!
438    \brief
439    Setup size and position for the component widgets attached to this TabControl
440
441    \return
442    Nothing.
443    */
444    virtual void        layoutComponentWidgets();
445
446protected:
447        /*************************************************************************
448                Static Properties for this class
449        *************************************************************************/
450        static TabControlProperties::TabHeight                  d_tabHeightProperty;
451    static TabControlProperties::AbsoluteTabHeight      d_absoluteTabHeightProperty;
452    static TabControlProperties::RelativeTabHeight      d_relativeTabHeightProperty;
453
454    static TabControlProperties::TabTextPadding                 d_tabTextPaddingProperty;
455    static TabControlProperties::AbsoluteTabTextPadding d_absoluteTabTextPaddingProperty;
456    static TabControlProperties::RelativeTabTextPadding d_relativeTabTextPaddingProperty;
457        /*************************************************************************
458                Private methods
459        *************************************************************************/
460        void    addTabControlProperties(void);
461
462    /*!
463    \brief
464    Add given window to child list at an appropriate position
465    */
466    void        addChild_impl(Window* wnd);
467
468    /*************************************************************************
469    Event handlers
470    *************************************************************************/
471    bool handleContentWindowTextChanged(const EventArgs& args);
472    bool handleTabButtonClicked(const EventArgs& args);
473};
474
475
476
477} // End of  CEGUI namespace section
478
479
480#if defined(_MSC_VER)
481#       pragma warning(pop)
482#endif
483
484#endif  // end of guard _CEGUITabControl_h_
Note: See TracBrowser for help on using the repository browser.