1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic tabbed dialogs
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #define WXTAB_VERSION 1.1
17 #include "wx/hashmap.h"
18 #include "wx/string.h"
19 #include "wx/dialog.h"
23 class WXDLLEXPORT wxTabView
;
26 * A wxTabControl is the internal and visual representation
30 class WXDLLEXPORT wxTabControl
: public wxObject
32 DECLARE_DYNAMIC_CLASS(wxTabControl
)
34 wxTabControl(wxTabView
*v
= (wxTabView
*) NULL
);
37 virtual void OnDraw(wxDC
& dc
, bool lastInRow
);
38 void SetLabel(const wxString
& str
) { m_controlLabel
= str
; }
39 wxString
GetLabel(void) const { return m_controlLabel
; }
41 void SetFont(const wxFont
& f
) { m_labelFont
= f
; }
42 wxFont
*GetFont(void) const { return (wxFont
*) & m_labelFont
; }
44 void SetSelected(bool sel
) { m_isSelected
= sel
; }
45 bool IsSelected(void) const { return m_isSelected
; }
47 void SetPosition(int x
, int y
) { m_offsetX
= x
; m_offsetY
= y
; }
48 void SetSize(int x
, int y
) { m_width
= x
; m_height
= y
; }
50 void SetRowPosition(int r
) { m_rowPosition
= r
; }
51 int GetRowPosition() const { return m_rowPosition
; }
52 void SetColPosition(int c
) { m_colPosition
= c
; }
53 int GetColPosition() const { return m_colPosition
; }
55 int GetX(void) const { return m_offsetX
; }
56 int GetY(void) const { return m_offsetY
; }
57 int GetWidth(void) const { return m_width
; }
58 int GetHeight(void) const { return m_height
; }
60 int GetId(void) const { return m_id
; }
61 void SetId(int i
) { m_id
= i
; }
63 virtual bool HitTest(int x
, int y
) const ;
67 wxString m_controlLabel
;
70 int m_offsetX
; // Offsets from top-left of tab view area (the area below the tabs)
75 int m_rowPosition
; // Position in row from 0
76 int m_colPosition
; // Position in col from 0
80 * Each wxTabLayer is a list of tabs. E.g. there
81 * are 3 layers in the MS Word Options dialog.
84 class WXDLLEXPORT wxTabLayer
: public wxList
89 * The wxTabView controls and draws the tabbed object
92 WX_DECLARE_LIST(wxTabLayer
, wxTabLayerList
);
94 #define wxTAB_STYLE_DRAW_BOX 1 // Draws 3D boxes round tab layers
95 #define wxTAB_STYLE_COLOUR_INTERIOR 2 // Colours interior of tabs, otherwise draws outline
97 class WXDLLEXPORT wxTabView
: public wxObject
99 DECLARE_DYNAMIC_CLASS(wxTabView
)
101 wxTabView(long style
= wxTAB_STYLE_DRAW_BOX
| wxTAB_STYLE_COLOUR_INTERIOR
);
104 inline int GetNumberOfLayers() const { return m_layers
.GetCount(); }
105 #if WXWIN_COMPATIBILITY_2_4
106 inline wxList
& GetLayers() { return *(wxList
*)&m_layers
; }
108 inline wxTabLayerList
& 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
= (wxTabControl
*) NULL
);
117 // Remove the tab without deleting the window
118 bool RemoveTab(int id
);
120 void ClearTabs(bool deleteTabs
= true);
122 bool SetTabText(int id
, const wxString
& label
);
123 wxString
GetTabText(int id
) const;
125 // Layout tabs (optional, e.g. if resizing window)
129 virtual void Draw(wxDC
& dc
);
131 // Process mouse event, return false if we didn't process it
132 virtual bool OnEvent(wxMouseEvent
& event
);
134 // Called when a tab is activated
135 virtual void OnTabActivate(int activateId
, int deactivateId
);
137 virtual bool OnTabPreActivate(int WXUNUSED(activateId
), int WXUNUSED(deactivateId
) ) { return true; };
139 // Allows use of application-supplied wxTabControl classes.
140 virtual wxTabControl
*OnCreateTabControl(void) { return new wxTabControl(this); }
142 void SetHighlightColour(const wxColour
& col
);
143 void SetShadowColour(const wxColour
& col
);
144 void SetBackgroundColour(const wxColour
& col
);
145 inline void SetTextColour(const wxColour
& col
) { m_textColour
= col
; }
147 inline wxColour
GetHighlightColour(void) const { return m_highlightColour
; }
148 inline wxColour
GetShadowColour(void) const { return m_shadowColour
; }
149 inline wxColour
GetBackgroundColour(void) const { return m_backgroundColour
; }
150 inline wxColour
GetTextColour(void) const { return m_textColour
; }
151 inline const wxPen
*GetHighlightPen(void) const { return m_highlightPen
; }
152 inline const wxPen
*GetShadowPen(void) const { return m_shadowPen
; }
153 inline const wxPen
*GetBackgroundPen(void) const { return m_backgroundPen
; }
154 inline const wxBrush
*GetBackgroundBrush(void) const { return m_backgroundBrush
; }
156 inline void SetViewRect(const wxRect
& rect
) { m_tabViewRect
= rect
; }
157 inline wxRect
GetViewRect(void) const { return m_tabViewRect
; }
159 // Calculate tab width to fit to view, and optionally adjust the view
160 // to fit the tabs exactly.
161 int CalculateTabWidth(int noTabs
, bool adjustView
= false);
163 inline void SetTabStyle(long style
) { m_tabStyle
= style
; }
164 inline long GetTabStyle(void) const { return m_tabStyle
; }
166 inline void SetTabSize(int w
, int h
) { m_tabWidth
= w
; m_tabHeight
= h
; }
167 inline int GetTabWidth(void) const { return m_tabWidth
; }
168 inline int GetTabHeight(void) const { return m_tabHeight
; }
169 inline void SetTabSelectionHeight(int h
) { m_tabSelectionHeight
= h
; }
170 inline int GetTabSelectionHeight(void) const { return m_tabSelectionHeight
; }
172 // Returns the total height of the tabs component -- this may be several
173 // times the height of a tab, if there are several tab layers (rows).
174 int GetTotalTabHeight();
176 inline int GetTopMargin(void) const { return m_topMargin
; }
177 inline void SetTopMargin(int margin
) { m_topMargin
= margin
; }
179 void SetTabSelection(int sel
, bool activateTool
= true);
180 inline int GetTabSelection() const { return m_tabSelection
; }
182 // Find tab control for id
183 wxTabControl
*FindTabControlForId(int id
) const ;
185 // Find tab control for layer, position (starting from zero)
186 wxTabControl
*FindTabControlForPosition(int layer
, int position
) const ;
188 inline int GetHorizontalTabOffset() const { return m_tabHorizontalOffset
; }
189 inline int GetHorizontalTabSpacing() const { return m_tabHorizontalSpacing
; }
190 inline void SetHorizontalTabOffset(int sp
) { m_tabHorizontalOffset
= sp
; }
191 inline void SetHorizontalTabSpacing(int sp
) { m_tabHorizontalSpacing
= sp
; }
193 inline void SetVerticalTabTextSpacing(int s
) { m_tabVerticalTextSpacing
= s
; }
194 inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing
; }
196 inline wxFont
*GetTabFont() const { return (wxFont
*) & m_tabFont
; }
197 inline void SetTabFont(const wxFont
& f
) { m_tabFont
= f
; }
199 inline wxFont
*GetSelectedTabFont() const { return (wxFont
*) & m_tabSelectedFont
; }
200 inline void SetSelectedTabFont(const wxFont
& f
) { m_tabSelectedFont
= f
; }
201 // Find the node and the column at which this control is positioned.
202 wxList::compatibility_iterator
FindTabNodeAndColumn(wxTabControl
*control
, int *col
) const ;
204 // Do the necessary to change to this tab
205 virtual bool ChangeTab(wxTabControl
*control
);
207 // Move the selected tab to the bottom layer, if necessary,
208 // without calling app activation code
209 bool MoveSelectionTab(wxTabControl
*control
);
211 inline int GetNumberOfTabs() const { return m_noTabs
; }
214 // List of layers, from front to back.
215 wxTabLayerList m_layers
;
223 // The height of the selected tab
224 int m_tabSelectionHeight
;
229 // Space between tabs
230 int m_tabHorizontalSpacing
;
232 // Space between top of normal tab and text
233 int m_tabVerticalTextSpacing
;
235 // Horizontal offset of each tab row above the first
236 int m_tabHorizontalOffset
;
238 // The distance between the bottom of the first tab row
239 // and the top of the client area (i.e. the margin)
242 // The position and size of the view above which the tabs are placed.
243 // I.e., the internal client area of the sheet.
244 wxRect m_tabViewRect
;
250 wxColour m_highlightColour
;
251 wxColour m_shadowColour
;
252 wxColour m_backgroundColour
;
253 wxColour m_textColour
;
255 // Pen and brush cache
256 const wxPen
* m_highlightPen
;
257 const wxPen
* m_shadowPen
;
258 const wxPen
* m_backgroundPen
;
259 const wxBrush
* m_backgroundBrush
;
262 wxFont m_tabSelectedFont
;
270 * A dialog box class that is tab-friendly
273 class WXDLLEXPORT wxTabbedDialog
: public wxDialog
275 DECLARE_DYNAMIC_CLASS(wxTabbedDialog
)
279 wxTabbedDialog(wxWindow
*parent
, wxWindowID id
, const wxString
& title
,
280 const wxPoint
& pos
= wxDefaultPosition
,
281 const wxSize
& size
= wxDefaultSize
,
282 long windowStyle
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= wxDialogNameStr
);
283 ~wxTabbedDialog(void);
285 inline wxTabView
*GetTabView() const { return m_tabView
; }
286 inline void SetTabView(wxTabView
*v
) { m_tabView
= v
; }
288 void OnCloseWindow(wxCloseEvent
& event
);
289 void OnMouseEvent(wxMouseEvent
& event
);
290 void OnPaint(wxPaintEvent
& event
);
293 wxTabView
* m_tabView
;
295 DECLARE_EVENT_TABLE()
299 * A panel class that is tab-friendly
302 class WXDLLEXPORT wxTabbedPanel
: public wxPanel
304 DECLARE_DYNAMIC_CLASS(wxTabbedPanel
)
308 wxTabbedPanel(wxWindow
*parent
, wxWindowID id
,
309 const wxPoint
& pos
= wxDefaultPosition
,
310 const wxSize
& size
= wxDefaultSize
,
311 long windowStyle
= 0, const wxString
& name
= wxPanelNameStr
);
312 ~wxTabbedPanel(void);
314 inline wxTabView
*GetTabView() const { return m_tabView
; }
315 inline void SetTabView(wxTabView
*v
) { m_tabView
= v
; }
317 void OnMouseEvent(wxMouseEvent
& event
);
318 void OnPaint(wxPaintEvent
& event
);
321 wxTabView
* m_tabView
;
323 DECLARE_EVENT_TABLE()
326 WX_DECLARE_HASH_MAP(int, wxWindow
*, wxIntegerHash
, wxIntegerEqual
,
327 wxIntToWindowHashMap
);
329 class WXDLLEXPORT wxPanelTabView
: public wxTabView
331 DECLARE_DYNAMIC_CLASS(wxPanelTabView
)
333 wxPanelTabView(wxPanel
*pan
, long style
= wxTAB_STYLE_DRAW_BOX
| wxTAB_STYLE_COLOUR_INTERIOR
);
334 ~wxPanelTabView(void);
336 // Called when a tab is activated
337 virtual void OnTabActivate(int activateId
, int deactivateId
);
339 // Specific to this class
340 void AddTabWindow(int id
, wxWindow
*window
);
341 wxWindow
*GetTabWindow(int id
) const ;
342 void ClearWindows(bool deleteWindows
= true);
343 inline wxWindow
*GetCurrentWindow() const { return m_currentWindow
; }
345 void ShowWindowForTab(int id
);
346 // inline wxList& GetWindows() const { return (wxList&) m_tabWindows; }
349 // List of panels, one for each tab. Indexed
351 wxIntToWindowHashMap m_tabWindows
;
352 wxWindow
* m_currentWindow
;