1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic tabbed dialogs
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "tabg.h"
19 #define WXTAB_VERSION 1.1
22 #include "wx/string.h"
23 #include "wx/dialog.h"
25 class WXDLLEXPORT wxTabView
;
28 * A wxTabControl is the internal and visual representation
32 class WXDLLEXPORT wxTabControl
: public wxObject
34 DECLARE_DYNAMIC_CLASS(wxTabControl
)
36 wxTabControl(wxTabView
*v
= (wxTabView
*) NULL
);
39 virtual void OnDraw(wxDC
& dc
, bool lastInRow
);
40 inline void SetLabel(const wxString
& str
) { m_controlLabel
= str
; }
41 inline wxString
GetLabel(void) const { return m_controlLabel
; }
43 inline void SetFont(const wxFont
& f
) { m_labelFont
= f
; }
44 inline wxFont
*GetFont(void) const { return (wxFont
*) & m_labelFont
; }
46 inline void SetSelected(bool sel
) { m_isSelected
= sel
; }
47 inline bool IsSelected(void) const { return m_isSelected
; }
49 inline void SetPosition(int x
, int y
) { m_offsetX
= x
; m_offsetY
= y
; }
50 inline void SetSize(int x
, int y
) { m_width
= x
; m_height
= y
; }
52 inline void SetRowPosition(int r
) { m_rowPosition
= r
; }
53 inline int GetRowPosition() const { return m_rowPosition
; }
54 inline void SetColPosition(int c
) { m_colPosition
= c
; }
55 inline int GetColPosition() const { return m_colPosition
; }
57 inline int GetX(void) const { return m_offsetX
; }
58 inline int GetY(void) const { return m_offsetY
; }
59 inline int GetWidth(void) const { return m_width
; }
60 inline int GetHeight(void) const { return m_height
; }
62 inline int GetId(void) const { return m_id
; }
63 inline void SetId(int i
) { m_id
= i
; }
65 virtual bool HitTest(int x
, int y
) const ;
69 wxString m_controlLabel
;
72 int m_offsetX
; // Offsets from top-left of tab view area (the area below the tabs)
77 int m_rowPosition
; // Position in row from 0
78 int m_colPosition
; // Position in col from 0
82 * Each wxTabLayer is a list of tabs. E.g. there
83 * are 3 layers in the MS Word Options dialog.
86 class WXDLLEXPORT wxTabLayer
: public wxList
88 DECLARE_DYNAMIC_CLASS(wxTabLayer
)
96 * The wxTabView controls and draws the tabbed object
99 #define wxTAB_STYLE_DRAW_BOX 1 // Draws 3D boxes round tab layers
100 #define wxTAB_STYLE_COLOUR_INTERIOR 2 // Colours interior of tabs, otherwise draws outline
102 class WXDLLEXPORT wxTabView
: public wxObject
104 DECLARE_DYNAMIC_CLASS(wxTabView
)
106 wxTabView(long style
= wxTAB_STYLE_DRAW_BOX
| wxTAB_STYLE_COLOUR_INTERIOR
);
109 inline int GetNumberOfLayers() const { return m_layers
.Number(); }
110 inline wxList
& GetLayers() { return m_layers
; }
112 inline void SetWindow(wxWindow
* wnd
) { m_window
= wnd
; }
113 inline wxWindow
* GetWindow(void) const { return m_window
; }
115 // Automatically positions tabs
116 wxTabControl
*AddTab(int id
, const wxString
& label
, wxTabControl
*existingTab
= (wxTabControl
*) NULL
);
118 // Remove the tab without deleting the window
119 bool RemoveTab(int id
);
121 void ClearTabs(bool deleteTabs
= TRUE
);
123 bool SetTabText(int id
, const wxString
& label
);
124 wxString
GetTabText(int id
) const;
126 // Layout tabs (optional, e.g. if resizing window)
130 virtual void Draw(wxDC
& dc
);
132 // Process mouse event, return FALSE if we didn't process it
133 virtual bool OnEvent(wxMouseEvent
& event
);
135 // Called when a tab is activated
136 virtual void OnTabActivate(int activateId
, int deactivateId
);
138 virtual bool OnTabPreActivate(int WXUNUSED(activateId
), int WXUNUSED(deactivateId
) ) { return TRUE
; };
140 // Allows use of application-supplied wxTabControl classes.
141 virtual wxTabControl
*OnCreateTabControl(void) { return new wxTabControl(this); }
143 void SetHighlightColour(const wxColour
& col
);
144 void SetShadowColour(const wxColour
& col
);
145 void SetBackgroundColour(const wxColour
& col
);
146 inline void SetTextColour(const wxColour
& col
) { m_textColour
= col
; }
148 inline wxColour
GetHighlightColour(void) const { return m_highlightColour
; }
149 inline wxColour
GetShadowColour(void) const { return m_shadowColour
; }
150 inline wxColour
GetBackgroundColour(void) const { return m_backgroundColour
; }
151 inline wxColour
GetTextColour(void) const { return m_textColour
; }
152 inline wxPen
*GetHighlightPen(void) const { return m_highlightPen
; }
153 inline wxPen
*GetShadowPen(void) const { return m_shadowPen
; }
154 inline wxPen
*GetBackgroundPen(void) const { return m_backgroundPen
; }
155 inline wxBrush
*GetBackgroundBrush(void) const { return m_backgroundBrush
; }
157 inline void SetViewRect(const wxRectangle
& rect
) { m_tabViewRect
= rect
; }
158 inline wxRect
GetViewRect(void) const { return m_tabViewRect
; }
160 // Calculate tab width to fit to view, and optionally adjust the view
161 // to fit the tabs exactly.
162 int CalculateTabWidth(int noTabs
, bool adjustView
= FALSE
);
164 inline void SetTabStyle(long style
) { m_tabStyle
= style
; }
165 inline long GetTabStyle(void) const { return m_tabStyle
; }
167 inline void SetTabSize(int w
, int h
) { m_tabWidth
= w
; m_tabHeight
= h
; }
168 inline int GetTabWidth(void) const { return m_tabWidth
; }
169 inline int GetTabHeight(void) const { return m_tabHeight
; }
170 inline void SetTabSelectionHeight(int h
) { m_tabSelectionHeight
= h
; }
171 inline int GetTabSelectionHeight(void) const { return m_tabSelectionHeight
; }
173 // Returns the total height of the tabs component -- this may be several
174 // times the height of a tab, if there are several tab layers (rows).
175 int GetTotalTabHeight();
177 inline int GetTopMargin(void) const { return m_topMargin
; }
178 inline void SetTopMargin(int margin
) { m_topMargin
= margin
; }
180 void SetTabSelection(int sel
, bool activateTool
= TRUE
);
181 inline int GetTabSelection() const { return m_tabSelection
; }
183 // Find tab control for id
184 wxTabControl
*FindTabControlForId(int id
) const ;
186 // Find tab control for layer, position (starting from zero)
187 wxTabControl
*FindTabControlForPosition(int layer
, int position
) const ;
189 inline int GetHorizontalTabOffset() const { return m_tabHorizontalOffset
; }
190 inline int GetHorizontalTabSpacing() const { return m_tabHorizontalSpacing
; }
191 inline void SetHorizontalTabOffset(int sp
) { m_tabHorizontalOffset
= sp
; }
192 inline void SetHorizontalTabSpacing(int sp
) { m_tabHorizontalSpacing
= sp
; }
194 inline void SetVerticalTabTextSpacing(int s
) { m_tabVerticalTextSpacing
= s
; }
195 inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing
; }
197 inline wxFont
*GetTabFont() const { return (wxFont
*) & m_tabFont
; }
198 inline void SetTabFont(const wxFont
& f
) { m_tabFont
= f
; }
200 inline wxFont
*GetSelectedTabFont() const { return (wxFont
*) & m_tabSelectedFont
; }
201 inline void SetSelectedTabFont(const wxFont
& f
) { m_tabSelectedFont
= f
; }
202 // Find the node and the column at which this control is positioned.
203 wxNode
*FindTabNodeAndColumn(wxTabControl
*control
, int *col
) const ;
205 // Do the necessary to change to this tab
206 virtual bool ChangeTab(wxTabControl
*control
);
208 // Move the selected tab to the bottom layer, if necessary,
209 // without calling app activation code
210 bool MoveSelectionTab(wxTabControl
*control
);
212 inline int GetNumberOfTabs() const { return m_noTabs
; }
215 // List of layers, from front to back.
224 // The height of the selected tab
225 int m_tabSelectionHeight
;
230 // Space between tabs
231 int m_tabHorizontalSpacing
;
233 // Space between top of normal tab and text
234 int m_tabVerticalTextSpacing
;
236 // Horizontal offset of each tab row above the first
237 int m_tabHorizontalOffset
;
239 // The distance between the bottom of the first tab row
240 // and the top of the client area (i.e. the margin)
243 // The position and size of the view above which the tabs are placed.
244 // I.e., the internal client area of the sheet.
245 wxRect m_tabViewRect
;
251 wxColour m_highlightColour
;
252 wxColour m_shadowColour
;
253 wxColour m_backgroundColour
;
254 wxColour m_textColour
;
256 // Pen and brush cache
257 wxPen
* m_highlightPen
;
259 wxPen
* m_backgroundPen
;
260 wxBrush
* m_backgroundBrush
;
263 wxFont m_tabSelectedFont
;
271 * A dialog box class that is tab-friendly
274 class WXDLLEXPORT wxTabbedDialog
: public wxDialog
276 DECLARE_DYNAMIC_CLASS(wxTabbedDialog
)
280 wxTabbedDialog(wxWindow
*parent
, wxWindowID id
, const wxString
& title
,
281 const wxPoint
& pos
= wxDefaultPosition
,
282 const wxSize
& size
= wxDefaultSize
,
283 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= wxDialogNameStr
);
284 ~wxTabbedDialog(void);
286 inline wxTabView
*GetTabView() const { return m_tabView
; }
287 inline void SetTabView(wxTabView
*v
) { m_tabView
= v
; }
289 void OnCloseWindow(wxCloseEvent
& event
);
290 void OnMouseEvent(wxMouseEvent
& event
);
291 void OnPaint(wxPaintEvent
& event
);
294 wxTabView
* m_tabView
;
296 DECLARE_EVENT_TABLE()
300 * A panel class that is tab-friendly
303 class WXDLLEXPORT wxTabbedPanel
: public wxPanel
305 DECLARE_DYNAMIC_CLASS(wxTabbedPanel
)
309 wxTabbedPanel(wxWindow
*parent
, wxWindowID id
,
310 const wxPoint
& pos
= wxDefaultPosition
,
311 const wxSize
& size
= wxDefaultSize
,
312 long windowStyle
= 0, const wxString
& name
= wxPanelNameStr
);
313 ~wxTabbedPanel(void);
315 inline wxTabView
*GetTabView() const { return m_tabView
; }
316 inline void SetTabView(wxTabView
*v
) { m_tabView
= v
; }
318 void OnMouseEvent(wxMouseEvent
& event
);
319 void OnPaint(wxPaintEvent
& event
);
322 wxTabView
* m_tabView
;
324 DECLARE_EVENT_TABLE()
327 class WXDLLEXPORT wxPanelTabView
: public wxTabView
329 DECLARE_DYNAMIC_CLASS(wxPanelTabView
)
331 wxPanelTabView(wxPanel
*pan
, long style
= wxTAB_STYLE_DRAW_BOX
| wxTAB_STYLE_COLOUR_INTERIOR
);
332 ~wxPanelTabView(void);
334 // Called when a tab is activated
335 virtual void OnTabActivate(int activateId
, int deactivateId
);
337 // Specific to this class
338 void AddTabWindow(int id
, wxWindow
*window
);
339 wxWindow
*GetTabWindow(int id
) const ;
340 void ClearWindows(bool deleteWindows
= TRUE
);
341 inline wxWindow
*GetCurrentWindow() const { return m_currentWindow
; }
343 void ShowWindowForTab(int id
);
344 inline wxList
& GetWindows() const { return (wxList
&) m_tabWindows
; }
347 // List of panels, one for each tab. Indexed
350 wxWindow
* m_currentWindow
;