]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/tabg.h
wxMac support added
[wxWidgets.git] / include / wx / generic / tabg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tabg.h
3 // Purpose: Generic tabbed dialogs
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __TABGH_G__
13 #define __TABGH_G__
14
15 #ifdef __GNUG__
16 #pragma interface "tabg.h"
17 #endif
18
19 #define WXTAB_VERSION 1.1
20
21 #include "wx/hash.h"
22 #include "wx/string.h"
23 #include "wx/dialog.h"
24
25 class WXDLLEXPORT wxTabView;
26
27 /*
28 * A wxTabControl is the internal and visual representation
29 * of the tab.
30 */
31
32 class WXDLLEXPORT wxTabControl: public wxObject
33 {
34 DECLARE_DYNAMIC_CLASS(wxTabControl)
35 public:
36 wxTabControl(wxTabView *v = (wxTabView *) NULL);
37 ~wxTabControl(void);
38
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; }
42
43 inline void SetFont(const wxFont& f) { m_labelFont = f; }
44 inline wxFont *GetFont(void) const { return (wxFont*) & m_labelFont; }
45
46 inline void SetSelected(bool sel) { m_isSelected = sel; }
47 inline bool IsSelected(void) const { return m_isSelected; }
48
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; }
51
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; }
56
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; }
61
62 inline int GetId(void) const { return m_id; }
63 inline void SetId(int i) { m_id = i; }
64
65 virtual bool HitTest(int x, int y) const ;
66
67 protected:
68 wxTabView* m_view;
69 wxString m_controlLabel;
70 bool m_isSelected;
71 wxFont m_labelFont;
72 int m_offsetX; // Offsets from top-left of tab view area (the area below the tabs)
73 int m_offsetY;
74 int m_width;
75 int m_height;
76 int m_id;
77 int m_rowPosition; // Position in row from 0
78 int m_colPosition; // Position in col from 0
79 };
80
81 /*
82 * Each wxTabLayer is a list of tabs. E.g. there
83 * are 3 layers in the MS Word Options dialog.
84 */
85
86 class WXDLLEXPORT wxTabLayer: public wxList
87 {
88 // Why did someone remove this, please?
89 DECLARE_DYNAMIC_CLASS(wxTabLayer)
90 wxTabLayer():wxList() {}
91 };
92
93 /*
94 * The wxTabView controls and draws the tabbed object
95 */
96
97 #define wxTAB_STYLE_DRAW_BOX 1 // Draws 3D boxes round tab layers
98 #define wxTAB_STYLE_COLOUR_INTERIOR 2 // Colours interior of tabs, otherwise draws outline
99
100 class WXDLLEXPORT wxTabView: public wxObject
101 {
102 DECLARE_DYNAMIC_CLASS(wxTabView)
103 public:
104 wxTabView(long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
105 ~wxTabView();
106
107 inline int GetNumberOfLayers() const { return m_layers.Number(); }
108 inline wxList& GetLayers() { return m_layers; }
109
110 inline void SetWindow(wxWindow* wnd) { m_window = wnd; }
111 inline wxWindow* GetWindow(void) const { return m_window; }
112
113 // Automatically positions tabs
114 wxTabControl *AddTab(int id, const wxString& label, wxTabControl *existingTab = (wxTabControl *) NULL);
115
116 // Remove the tab without deleting the window
117 bool RemoveTab(int id);
118
119 void ClearTabs(bool deleteTabs = TRUE);
120
121 bool SetTabText(int id, const wxString& label);
122 wxString GetTabText(int id) const;
123
124 // Layout tabs (optional, e.g. if resizing window)
125 void Layout(void);
126
127 // Draw all tabs
128 virtual void Draw(wxDC& dc);
129
130 // Process mouse event, return FALSE if we didn't process it
131 virtual bool OnEvent(wxMouseEvent& event);
132
133 // Called when a tab is activated
134 virtual void OnTabActivate(int activateId, int deactivateId);
135 // Allows vetoing
136 virtual bool OnTabPreActivate(int WXUNUSED(activateId), int WXUNUSED(deactivateId) ) { return TRUE; };
137
138 // Allows use of application-supplied wxTabControl classes.
139 virtual wxTabControl *OnCreateTabControl(void) { return new wxTabControl(this); }
140
141 void SetHighlightColour(const wxColour& col);
142 void SetShadowColour(const wxColour& col);
143 void SetBackgroundColour(const wxColour& col);
144 inline void SetTextColour(const wxColour& col) { m_textColour = col; }
145
146 inline wxColour GetHighlightColour(void) const { return m_highlightColour; }
147 inline wxColour GetShadowColour(void) const { return m_shadowColour; }
148 inline wxColour GetBackgroundColour(void) const { return m_backgroundColour; }
149 inline wxColour GetTextColour(void) const { return m_textColour; }
150 inline wxPen *GetHighlightPen(void) const { return m_highlightPen; }
151 inline wxPen *GetShadowPen(void) const { return m_shadowPen; }
152 inline wxPen *GetBackgroundPen(void) const { return m_backgroundPen; }
153 inline wxBrush *GetBackgroundBrush(void) const { return m_backgroundBrush; }
154
155 inline void SetViewRect(const wxRect& rect) { m_tabViewRect = rect; }
156 inline wxRect GetViewRect(void) const { return m_tabViewRect; }
157
158 // Calculate tab width to fit to view, and optionally adjust the view
159 // to fit the tabs exactly.
160 int CalculateTabWidth(int noTabs, bool adjustView = FALSE);
161
162 inline void SetTabStyle(long style) { m_tabStyle = style; }
163 inline long GetTabStyle(void) const { return m_tabStyle; }
164
165 inline void SetTabSize(int w, int h) { m_tabWidth = w; m_tabHeight = h; }
166 inline int GetTabWidth(void) const { return m_tabWidth; }
167 inline int GetTabHeight(void) const { return m_tabHeight; }
168 inline void SetTabSelectionHeight(int h) { m_tabSelectionHeight = h; }
169 inline int GetTabSelectionHeight(void) const { return m_tabSelectionHeight; }
170
171 // Returns the total height of the tabs component -- this may be several
172 // times the height of a tab, if there are several tab layers (rows).
173 int GetTotalTabHeight();
174
175 inline int GetTopMargin(void) const { return m_topMargin; }
176 inline void SetTopMargin(int margin) { m_topMargin = margin; }
177
178 void SetTabSelection(int sel, bool activateTool = TRUE);
179 inline int GetTabSelection() const { return m_tabSelection; }
180
181 // Find tab control for id
182 wxTabControl *FindTabControlForId(int id) const ;
183
184 // Find tab control for layer, position (starting from zero)
185 wxTabControl *FindTabControlForPosition(int layer, int position) const ;
186
187 inline int GetHorizontalTabOffset() const { return m_tabHorizontalOffset; }
188 inline int GetHorizontalTabSpacing() const { return m_tabHorizontalSpacing; }
189 inline void SetHorizontalTabOffset(int sp) { m_tabHorizontalOffset = sp; }
190 inline void SetHorizontalTabSpacing(int sp) { m_tabHorizontalSpacing = sp; }
191
192 inline void SetVerticalTabTextSpacing(int s) { m_tabVerticalTextSpacing = s; }
193 inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing; }
194
195 inline wxFont *GetTabFont() const { return (wxFont*) & m_tabFont; }
196 inline void SetTabFont(const wxFont& f) { m_tabFont = f; }
197
198 inline wxFont *GetSelectedTabFont() const { return (wxFont*) & m_tabSelectedFont; }
199 inline void SetSelectedTabFont(const wxFont& f) { m_tabSelectedFont = f; }
200 // Find the node and the column at which this control is positioned.
201 wxNode *FindTabNodeAndColumn(wxTabControl *control, int *col) const ;
202
203 // Do the necessary to change to this tab
204 virtual bool ChangeTab(wxTabControl *control);
205
206 // Move the selected tab to the bottom layer, if necessary,
207 // without calling app activation code
208 bool MoveSelectionTab(wxTabControl *control);
209
210 inline int GetNumberOfTabs() const { return m_noTabs; }
211
212 protected:
213 // List of layers, from front to back.
214 wxList m_layers;
215
216 // Selected tab
217 int m_tabSelection;
218
219 // Usual tab height
220 int m_tabHeight;
221
222 // The height of the selected tab
223 int m_tabSelectionHeight;
224
225 // Usual tab width
226 int m_tabWidth;
227
228 // Space between tabs
229 int m_tabHorizontalSpacing;
230
231 // Space between top of normal tab and text
232 int m_tabVerticalTextSpacing;
233
234 // Horizontal offset of each tab row above the first
235 int m_tabHorizontalOffset;
236
237 // The distance between the bottom of the first tab row
238 // and the top of the client area (i.e. the margin)
239 int m_topMargin;
240
241 // The position and size of the view above which the tabs are placed.
242 // I.e., the internal client area of the sheet.
243 wxRect m_tabViewRect;
244
245 // Bitlist of styles
246 long m_tabStyle;
247
248 // Colours
249 wxColour m_highlightColour;
250 wxColour m_shadowColour;
251 wxColour m_backgroundColour;
252 wxColour m_textColour;
253
254 // Pen and brush cache
255 wxPen* m_highlightPen;
256 wxPen* m_shadowPen;
257 wxPen* m_backgroundPen;
258 wxBrush* m_backgroundBrush;
259
260 wxFont m_tabFont;
261 wxFont m_tabSelectedFont;
262
263 int m_noTabs;
264
265 wxWindow* m_window;
266 };
267
268 /*
269 * A dialog box class that is tab-friendly
270 */
271
272 class WXDLLEXPORT wxTabbedDialog: public wxDialog
273 {
274 DECLARE_DYNAMIC_CLASS(wxTabbedDialog)
275
276 public:
277
278 wxTabbedDialog(wxWindow *parent, wxWindowID id, const wxString& title,
279 const wxPoint& pos = wxDefaultPosition,
280 const wxSize& size = wxDefaultSize,
281 long windowStyle = wxDEFAULT_DIALOG_STYLE, const wxString& name = wxDialogNameStr);
282 ~wxTabbedDialog(void);
283
284 inline wxTabView *GetTabView() const { return m_tabView; }
285 inline void SetTabView(wxTabView *v) { m_tabView = v; }
286
287 void OnCloseWindow(wxCloseEvent& event);
288 void OnMouseEvent(wxMouseEvent& event);
289 void OnPaint(wxPaintEvent& event);
290
291 protected:
292 wxTabView* m_tabView;
293
294 DECLARE_EVENT_TABLE()
295 };
296
297 /*
298 * A panel class that is tab-friendly
299 */
300
301 class WXDLLEXPORT wxTabbedPanel: public wxPanel
302 {
303 DECLARE_DYNAMIC_CLASS(wxTabbedPanel)
304
305 public:
306
307 wxTabbedPanel(wxWindow *parent, wxWindowID id,
308 const wxPoint& pos = wxDefaultPosition,
309 const wxSize& size = wxDefaultSize,
310 long windowStyle = 0, const wxString& name = wxPanelNameStr);
311 ~wxTabbedPanel(void);
312
313 inline wxTabView *GetTabView() const { return m_tabView; }
314 inline void SetTabView(wxTabView *v) { m_tabView = v; }
315
316 void OnMouseEvent(wxMouseEvent& event);
317 void OnPaint(wxPaintEvent& event);
318
319 protected:
320 wxTabView* m_tabView;
321
322 DECLARE_EVENT_TABLE()
323 };
324
325 class WXDLLEXPORT wxPanelTabView: public wxTabView
326 {
327 DECLARE_DYNAMIC_CLASS(wxPanelTabView)
328 public:
329 wxPanelTabView(wxPanel *pan, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
330 ~wxPanelTabView(void);
331
332 // Called when a tab is activated
333 virtual void OnTabActivate(int activateId, int deactivateId);
334
335 // Specific to this class
336 void AddTabWindow(int id, wxWindow *window);
337 wxWindow *GetTabWindow(int id) const ;
338 void ClearWindows(bool deleteWindows = TRUE);
339 inline wxWindow *GetCurrentWindow() const { return m_currentWindow; }
340
341 void ShowWindowForTab(int id);
342 inline wxList& GetWindows() const { return (wxList&) m_tabWindows; }
343
344 protected:
345 // List of panels, one for each tab. Indexed
346 // by tab ID.
347 wxList m_tabWindows;
348 wxWindow* m_currentWindow;
349 wxPanel* m_panel;
350 };
351
352 #endif
353