]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/tabg.h
some Linux compilation fixes
[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 };
89
90 /*
91 * The wxTabView controls and draws the tabbed object
92 */
93
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
96
97 class WXDLLEXPORT wxTabView: public wxObject
98 {
99 DECLARE_DYNAMIC_CLASS(wxTabView)
100 public:
101 wxTabView(long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
102 ~wxTabView();
103
104 inline int GetNumberOfLayers() const { return m_layers.Number(); }
105 inline wxList& GetLayers() { return m_layers; }
106
107 inline void SetWindow(wxWindow* wnd) { m_window = wnd; }
108 inline wxWindow* GetWindow(void) const { return m_window; }
109
110 // Automatically positions tabs
111 wxTabControl *AddTab(int id, const wxString& label, wxTabControl *existingTab = (wxTabControl *) NULL);
112
113 // Remove the tab without deleting the window
114 bool RemoveTab(int id);
115
116 void ClearTabs(bool deleteTabs = TRUE);
117
118 bool SetTabText(int id, const wxString& label);
119 wxString GetTabText(int id) const;
120
121 // Layout tabs (optional, e.g. if resizing window)
122 void Layout(void);
123
124 // Draw all tabs
125 virtual void Draw(wxDC& dc);
126
127 // Process mouse event, return FALSE if we didn't process it
128 virtual bool OnEvent(wxMouseEvent& event);
129
130 // Called when a tab is activated
131 virtual void OnTabActivate(int activateId, int deactivateId);
132 // Allows vetoing
133 virtual bool OnTabPreActivate(int WXUNUSED(activateId), int WXUNUSED(deactivateId) ) { return TRUE; };
134
135 // Allows use of application-supplied wxTabControl classes.
136 virtual wxTabControl *OnCreateTabControl(void) { return new wxTabControl(this); }
137
138 void SetHighlightColour(const wxColour& col);
139 void SetShadowColour(const wxColour& col);
140 void SetBackgroundColour(const wxColour& col);
141 inline void SetTextColour(const wxColour& col) { m_textColour = col; }
142
143 inline wxColour GetHighlightColour(void) const { return m_highlightColour; }
144 inline wxColour GetShadowColour(void) const { return m_shadowColour; }
145 inline wxColour GetBackgroundColour(void) const { return m_backgroundColour; }
146 inline wxColour GetTextColour(void) const { return m_textColour; }
147 inline wxPen *GetHighlightPen(void) const { return m_highlightPen; }
148 inline wxPen *GetShadowPen(void) const { return m_shadowPen; }
149 inline wxPen *GetBackgroundPen(void) const { return m_backgroundPen; }
150 inline wxBrush *GetBackgroundBrush(void) const { return m_backgroundBrush; }
151
152 inline void SetViewRect(const wxRectangle& rect) { m_tabViewRect = rect; }
153 inline wxRect GetViewRect(void) const { return m_tabViewRect; }
154
155 // Calculate tab width to fit to view, and optionally adjust the view
156 // to fit the tabs exactly.
157 int CalculateTabWidth(int noTabs, bool adjustView = FALSE);
158
159 inline void SetTabStyle(long style) { m_tabStyle = style; }
160 inline long GetTabStyle(void) const { return m_tabStyle; }
161
162 inline void SetTabSize(int w, int h) { m_tabWidth = w; m_tabHeight = h; }
163 inline int GetTabWidth(void) const { return m_tabWidth; }
164 inline int GetTabHeight(void) const { return m_tabHeight; }
165 inline void SetTabSelectionHeight(int h) { m_tabSelectionHeight = h; }
166 inline int GetTabSelectionHeight(void) const { return m_tabSelectionHeight; }
167
168 // Returns the total height of the tabs component -- this may be several
169 // times the height of a tab, if there are several tab layers (rows).
170 int GetTotalTabHeight();
171
172 inline int GetTopMargin(void) const { return m_topMargin; }
173 inline void SetTopMargin(int margin) { m_topMargin = margin; }
174
175 void SetTabSelection(int sel, bool activateTool = TRUE);
176 inline int GetTabSelection() const { return m_tabSelection; }
177
178 // Find tab control for id
179 wxTabControl *FindTabControlForId(int id) const ;
180
181 // Find tab control for layer, position (starting from zero)
182 wxTabControl *FindTabControlForPosition(int layer, int position) const ;
183
184 inline int GetHorizontalTabOffset() const { return m_tabHorizontalOffset; }
185 inline int GetHorizontalTabSpacing() const { return m_tabHorizontalSpacing; }
186 inline void SetHorizontalTabOffset(int sp) { m_tabHorizontalOffset = sp; }
187 inline void SetHorizontalTabSpacing(int sp) { m_tabHorizontalSpacing = sp; }
188
189 inline void SetVerticalTabTextSpacing(int s) { m_tabVerticalTextSpacing = s; }
190 inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing; }
191
192 inline wxFont *GetTabFont() const { return (wxFont*) & m_tabFont; }
193 inline void SetTabFont(const wxFont& f) { m_tabFont = f; }
194
195 inline wxFont *GetSelectedTabFont() const { return (wxFont*) & m_tabSelectedFont; }
196 inline void SetSelectedTabFont(const wxFont& f) { m_tabSelectedFont = f; }
197 // Find the node and the column at which this control is positioned.
198 wxNode *FindTabNodeAndColumn(wxTabControl *control, int *col) const ;
199
200 // Do the necessary to change to this tab
201 virtual bool ChangeTab(wxTabControl *control);
202
203 // Move the selected tab to the bottom layer, if necessary,
204 // without calling app activation code
205 bool MoveSelectionTab(wxTabControl *control);
206
207 inline int GetNumberOfTabs() const { return m_noTabs; }
208
209 protected:
210 // List of layers, from front to back.
211 wxList m_layers;
212
213 // Selected tab
214 int m_tabSelection;
215
216 // Usual tab height
217 int m_tabHeight;
218
219 // The height of the selected tab
220 int m_tabSelectionHeight;
221
222 // Usual tab width
223 int m_tabWidth;
224
225 // Space between tabs
226 int m_tabHorizontalSpacing;
227
228 // Space between top of normal tab and text
229 int m_tabVerticalTextSpacing;
230
231 // Horizontal offset of each tab row above the first
232 int m_tabHorizontalOffset;
233
234 // The distance between the bottom of the first tab row
235 // and the top of the client area (i.e. the margin)
236 int m_topMargin;
237
238 // The position and size of the view above which the tabs are placed.
239 // I.e., the internal client area of the sheet.
240 wxRect m_tabViewRect;
241
242 // Bitlist of styles
243 long m_tabStyle;
244
245 // Colours
246 wxColour m_highlightColour;
247 wxColour m_shadowColour;
248 wxColour m_backgroundColour;
249 wxColour m_textColour;
250
251 // Pen and brush cache
252 wxPen* m_highlightPen;
253 wxPen* m_shadowPen;
254 wxPen* m_backgroundPen;
255 wxBrush* m_backgroundBrush;
256
257 wxFont m_tabFont;
258 wxFont m_tabSelectedFont;
259
260 int m_noTabs;
261
262 wxWindow* m_window;
263 };
264
265 /*
266 * A dialog box class that is tab-friendly
267 */
268
269 class WXDLLEXPORT wxTabbedDialog: public wxDialog
270 {
271 DECLARE_DYNAMIC_CLASS(wxTabbedDialog)
272
273 public:
274
275 wxTabbedDialog(wxWindow *parent, wxWindowID id, const wxString& title,
276 const wxPoint& pos = wxDefaultPosition,
277 const wxSize& size = wxDefaultSize,
278 long windowStyle = wxDEFAULT_DIALOG_STYLE, const wxString& name = wxDialogNameStr);
279 ~wxTabbedDialog(void);
280
281 inline wxTabView *GetTabView() const { return m_tabView; }
282 inline void SetTabView(wxTabView *v) { m_tabView = v; }
283
284 void OnCloseWindow(wxCloseEvent& event);
285 void OnMouseEvent(wxMouseEvent& event);
286 void OnPaint(wxPaintEvent& event);
287
288 protected:
289 wxTabView* m_tabView;
290
291 DECLARE_EVENT_TABLE()
292 };
293
294 /*
295 * A panel class that is tab-friendly
296 */
297
298 class WXDLLEXPORT wxTabbedPanel: public wxPanel
299 {
300 DECLARE_DYNAMIC_CLASS(wxTabbedPanel)
301
302 public:
303
304 wxTabbedPanel(wxWindow *parent, wxWindowID id,
305 const wxPoint& pos = wxDefaultPosition,
306 const wxSize& size = wxDefaultSize,
307 long windowStyle = 0, const wxString& name = wxPanelNameStr);
308 ~wxTabbedPanel(void);
309
310 inline wxTabView *GetTabView() const { return m_tabView; }
311 inline void SetTabView(wxTabView *v) { m_tabView = v; }
312
313 void OnMouseEvent(wxMouseEvent& event);
314 void OnPaint(wxPaintEvent& event);
315
316 protected:
317 wxTabView* m_tabView;
318
319 DECLARE_EVENT_TABLE()
320 };
321
322 class WXDLLEXPORT wxPanelTabView: public wxTabView
323 {
324 DECLARE_DYNAMIC_CLASS(wxPanelTabView)
325 public:
326 wxPanelTabView(wxPanel *pan, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
327 ~wxPanelTabView(void);
328
329 // Called when a tab is activated
330 virtual void OnTabActivate(int activateId, int deactivateId);
331
332 // Specific to this class
333 void AddTabWindow(int id, wxWindow *window);
334 wxWindow *GetTabWindow(int id) const ;
335 void ClearWindows(bool deleteWindows = TRUE);
336 inline wxWindow *GetCurrentWindow() const { return m_currentWindow; }
337
338 void ShowWindowForTab(int id);
339 inline wxList& GetWindows() const { return (wxList&) m_tabWindows; }
340
341 protected:
342 // List of panels, one for each tab. Indexed
343 // by tab ID.
344 wxList m_tabWindows;
345 wxWindow* m_currentWindow;
346 wxPanel* m_panel;
347 };
348
349 #endif
350