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"
27 * A wxTabControl is the internal and visual representation
31 class wxTabControl
: public wxObject
33 DECLARE_DYNAMIC_CLASS(wxTabControl
)
35 wxTabControl(wxTabView
*v
= NULL
);
38 virtual void OnDraw(wxDC
& dc
, bool lastInRow
);
39 inline void SetLabel(const wxString
& str
) { m_controlLabel
= str
; }
40 inline wxString
GetLabel(void) const { return m_controlLabel
; }
42 inline void SetFont(wxFont
*f
) { m_labelFont
= f
; }
43 inline wxFont
*GetFont(void) const { return m_labelFont
; }
45 inline void SetSelected(bool sel
) { m_isSelected
= sel
; }
46 inline bool IsSelected(void) const { return m_isSelected
; }
48 inline void SetPosition(int x
, int y
) { m_offsetX
= x
; m_offsetY
= y
; }
49 inline void SetSize(int x
, int y
) { m_width
= x
; m_height
= y
; }
51 inline void SetRowPosition(int r
) { m_rowPosition
= r
; }
52 inline int GetRowPosition() const { return m_rowPosition
; }
53 inline void SetColPosition(int c
) { m_colPosition
= c
; }
54 inline int GetColPosition() const { return m_colPosition
; }
56 inline int GetX(void) const { return m_offsetX
; }
57 inline int GetY(void) const { return m_offsetY
; }
58 inline int GetWidth(void) const { return m_width
; }
59 inline int GetHeight(void) const { return m_height
; }
61 inline int GetId(void) const { return m_id
; }
62 inline void SetId(int i
) { m_id
= i
; }
64 virtual bool HitTest(int x
, int y
) const ;
68 wxString m_controlLabel
;
71 int m_offsetX
; // Offsets from top-left of tab view area (the area below the tabs)
76 int m_rowPosition
; // Position in row from 0
77 int m_colPosition
; // Position in col from 0
81 * Each wxTabLayer is a list of tabs. E.g. there
82 * are 3 layers in the MS Word Options dialog.
85 class wxTabLayer
: public wxList
87 DECLARE_DYNAMIC_CLASS(wxTabLayer
)
95 * The wxTabView controls and draws the tabbed object
98 #define wxTAB_STYLE_DRAW_BOX 1 // Draws 3D boxes round tab layers
99 #define wxTAB_STYLE_COLOUR_INTERIOR 2 // Colours interior of tabs, otherwise draws outline
101 class wxTabView
: public wxObject
103 DECLARE_DYNAMIC_CLASS(wxTabView
)
105 wxTabView(long style
= wxTAB_STYLE_DRAW_BOX
| wxTAB_STYLE_COLOUR_INTERIOR
);
108 inline int GetNumberOfLayers() const { return m_layers
.Number(); }
109 inline wxList
& GetLayers() { return m_layers
; }
111 inline void SetWindow(wxWindow
* wnd
) { m_window
= wnd
; }
112 inline wxWindow
* GetWindow(void) const { return m_window
; }
114 // Automatically positions tabs
115 wxTabControl
*AddTab(int id
, const wxString
& label
, wxTabControl
*existingTab
= NULL
);
117 void ClearTabs(bool deleteTabs
= TRUE
);
119 // Layout tabs (optional, e.g. if resizing window)
123 virtual void Draw(wxDC
& dc
);
125 // Process mouse event, return FALSE if we didn't process it
126 virtual bool OnEvent(wxMouseEvent
& event
);
128 // Called when a tab is activated
129 virtual void OnTabActivate(int activateId
, int deactivateId
);
131 virtual bool OnTabPreActivate(int WXUNUSED(activateId
), int WXUNUSED(deactivateId
) ) { return TRUE
; };
133 // Allows use of application-supplied wxTabControl classes.
134 virtual wxTabControl
*OnCreateTabControl(void) { return new wxTabControl(this); }
136 void SetHighlightColour(const wxColour
& col
);
137 void SetShadowColour(const wxColour
& col
);
138 void SetBackgroundColour(const wxColour
& col
);
139 inline void SetTextColour(const wxColour
& col
) { m_textColour
= col
; }
141 inline wxColour
GetHighlightColour(void) const { return m_highlightColour
; }
142 inline wxColour
GetShadowColour(void) const { return m_shadowColour
; }
143 inline wxColour
GetBackgroundColour(void) const { return m_backgroundColour
; }
144 inline wxColour
GetTextColour(void) const { return m_textColour
; }
145 inline wxPen
*GetHighlightPen(void) const { return m_highlightPen
; }
146 inline wxPen
*GetShadowPen(void) const { return m_shadowPen
; }
147 inline wxPen
*GetBackgroundPen(void) const { return m_backgroundPen
; }
148 inline wxBrush
*GetBackgroundBrush(void) const { return m_backgroundBrush
; }
150 inline void SetViewRect(const wxRectangle
& rect
) { m_tabViewRect
= rect
; }
151 inline wxRect
GetViewRect(void) const { return m_tabViewRect
; }
153 // Calculate tab width to fit to view, and optionally adjust the view
154 // to fit the tabs exactly.
155 int CalculateTabWidth(int noTabs
, bool adjustView
= FALSE
);
157 inline void SetTabStyle(long style
) { m_tabStyle
= style
; }
158 inline long GetTabStyle(void) const { return m_tabStyle
; }
160 inline void SetTabSize(int w
, int h
) { m_tabWidth
= w
; m_tabHeight
= h
; }
161 inline int GetTabWidth(void) const { return m_tabWidth
; }
162 inline int GetTabHeight(void) const { return m_tabHeight
; }
163 inline void SetTabSelectionHeight(int h
) { m_tabSelectionHeight
= h
; }
164 inline int GetTabSelectionHeight(void) const { return m_tabSelectionHeight
; }
166 inline int GetTopMargin(void) const { return m_topMargin
; }
167 inline void SetTopMargin(int margin
) { m_topMargin
= margin
; }
169 void SetTabSelection(int sel
, bool activateTool
= TRUE
);
170 inline int GetTabSelection() const { return m_tabSelection
; }
172 // Find tab control for id
173 wxTabControl
*FindTabControlForId(int id
) const ;
175 // Find tab control for layer, position (starting from zero)
176 wxTabControl
*FindTabControlForPosition(int layer
, int position
) const ;
178 inline int GetHorizontalTabOffset() const { return m_tabHorizontalOffset
; }
179 inline int GetHorizontalTabSpacing() const { return m_tabHorizontalSpacing
; }
180 inline void SetHorizontalTabOffset(int sp
) { m_tabHorizontalOffset
= sp
; }
181 inline void SetHorizontalTabSpacing(int sp
) { m_tabHorizontalSpacing
= sp
; }
183 inline void SetVerticalTabTextSpacing(int s
) { m_tabVerticalTextSpacing
= s
; }
184 inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing
; }
186 inline wxFont
*GetTabFont() const { return m_tabFont
; }
187 inline void SetTabFont(wxFont
*f
) { m_tabFont
= f
; }
189 inline wxFont
*GetSelectedTabFont() const { return m_tabSelectedFont
; }
190 inline void SetSelectedTabFont(wxFont
*f
) { m_tabSelectedFont
= f
; }
191 // Find the node and the column at which this control is positioned.
192 wxNode
*FindTabNodeAndColumn(wxTabControl
*control
, int *col
) const ;
194 // Do the necessary to change to this tab
195 virtual bool ChangeTab(wxTabControl
*control
);
197 // Move the selected tab to the bottom layer, if necessary,
198 // without calling app activation code
199 bool MoveSelectionTab(wxTabControl
*control
);
201 inline int GetNumberOfTabs() const { return m_noTabs
; }
204 // List of layers, from front to back.
213 // The height of the selected tab
214 int m_tabSelectionHeight
;
219 // Space between tabs
220 int m_tabHorizontalSpacing
;
222 // Space between top of normal tab and text
223 int m_tabVerticalTextSpacing
;
225 // Horizontal offset of each tab row above the first
226 int m_tabHorizontalOffset
;
228 // The distance between the bottom of the first tab row
229 // and the top of the client area (i.e. the margin)
232 // The position and size of the view above which the tabs are placed.
233 // I.e., the internal client area of the sheet.
234 wxRect m_tabViewRect
;
240 wxColour m_highlightColour
;
241 wxColour m_shadowColour
;
242 wxColour m_backgroundColour
;
243 wxColour m_textColour
;
245 // Pen and brush cache
246 wxPen
* m_highlightPen
;
248 wxPen
* m_backgroundPen
;
249 wxBrush
* m_backgroundBrush
;
252 wxFont
* m_tabSelectedFont
;
260 * A dialog box class that is tab-friendly
263 class wxTabbedDialog
: public wxDialog
265 DECLARE_DYNAMIC_CLASS(wxTabbedDialog
)
269 wxTabbedDialog(wxWindow
*parent
, const wxWindowID id
, const wxString
& title
,
270 const wxPoint
& pos
= wxDefaultPosition
,
271 const wxSize
& size
= wxDefaultSize
,
272 const long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= wxDialogNameStr
);
273 ~wxTabbedDialog(void);
275 inline wxTabView
*GetTabView() const { return m_tabView
; }
276 inline void SetTabView(wxTabView
*v
) { m_tabView
= v
; }
278 void OnCloseWindow(wxCloseEvent
& event
);
279 void OnMouseEvent(wxMouseEvent
& event
);
280 void OnPaint(wxPaintEvent
& event
);
283 wxTabView
* m_tabView
;
285 DECLARE_EVENT_TABLE()
289 * A panel class that is tab-friendly
292 class wxTabbedPanel
: public wxPanel
294 DECLARE_DYNAMIC_CLASS(wxTabbedPanel
)
298 wxTabbedPanel(wxWindow
*parent
, const wxWindowID id
,
299 const wxPoint
& pos
= wxDefaultPosition
,
300 const wxSize
& size
= wxDefaultSize
,
301 const long windowStyle
= 0, const wxString
& name
= wxPanelNameStr
);
302 ~wxTabbedPanel(void);
304 inline wxTabView
*GetTabView() const { return m_tabView
; }
305 inline void SetTabView(wxTabView
*v
) { m_tabView
= v
; }
307 void OnMouseEvent(wxMouseEvent
& event
);
308 void OnPaint(wxPaintEvent
& event
);
311 wxTabView
* m_tabView
;
313 DECLARE_EVENT_TABLE()
316 class wxPanelTabView
: public wxTabView
318 DECLARE_DYNAMIC_CLASS(wxPanelTabView
)
320 wxPanelTabView(wxPanel
*pan
, long style
= wxTAB_STYLE_DRAW_BOX
| wxTAB_STYLE_COLOUR_INTERIOR
);
321 ~wxPanelTabView(void);
323 // Called when a tab is activated
324 virtual void OnTabActivate(int activateId
, int deactivateId
);
326 // Specific to this class
327 void AddTabWindow(int id
, wxWindow
*window
);
328 wxWindow
*GetTabWindow(int id
) const ;
329 void ClearWindows(bool deleteWindows
= TRUE
);
330 inline wxWindow
*GetCurrentWindow() const { return m_currentWindow
; }
332 void ShowWindowForTab(int id
);
335 // List of panels, one for each tab. Indexed
338 wxWindow
* m_currentWindow
;