]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/tabg.h
Fixed that stupid stream problem.
[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
24 class wxTabView;
25
26 /*
27 * A wxTabControl is the internal and visual representation
28 * of the tab.
29 */
30
31 class wxTabControl: public wxObject
32 {
33 DECLARE_DYNAMIC_CLASS(wxTabControl)
34 public:
35 wxTabControl(wxTabView *v = NULL);
36 ~wxTabControl(void);
37
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; }
41
42 inline void SetFont(wxFont *f) { m_labelFont = f; }
43 inline wxFont *GetFont(void) const { return m_labelFont; }
44
45 inline void SetSelected(bool sel) { m_isSelected = sel; }
46 inline bool IsSelected(void) const { return m_isSelected; }
47
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; }
50
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; }
55
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; }
60
61 inline int GetId(void) const { return m_id; }
62 inline void SetId(int i) { m_id = i; }
63
64 virtual bool HitTest(int x, int y) const ;
65
66 protected:
67 wxTabView* m_view;
68 wxString m_controlLabel;
69 bool m_isSelected;
70 wxFont* m_labelFont;
71 int m_offsetX; // Offsets from top-left of tab view area (the area below the tabs)
72 int m_offsetY;
73 int m_width;
74 int m_height;
75 int m_id;
76 int m_rowPosition; // Position in row from 0
77 int m_colPosition; // Position in col from 0
78 };
79
80 /*
81 * Each wxTabLayer is a list of tabs. E.g. there
82 * are 3 layers in the MS Word Options dialog.
83 */
84
85 class wxTabLayer: public wxList
86 {
87 DECLARE_DYNAMIC_CLASS(wxTabLayer)
88 public:
89 wxTabLayer(void)
90 {
91 }
92 };
93
94 /*
95 * The wxTabView controls and draws the tabbed object
96 */
97
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
100
101 class wxTabView: public wxObject
102 {
103 DECLARE_DYNAMIC_CLASS(wxTabView)
104 public:
105 wxTabView(long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
106 ~wxTabView();
107
108 inline int GetNumberOfLayers() const { return m_layers.Number(); }
109 inline wxList& GetLayers() { return m_layers; }
110
111 inline void SetWindow(wxWindow* wnd) { m_window = wnd; }
112 inline wxWindow* GetWindow(void) const { return m_window; }
113
114 // Automatically positions tabs
115 wxTabControl *AddTab(int id, const wxString& label, wxTabControl *existingTab = NULL);
116
117 void ClearTabs(bool deleteTabs = TRUE);
118
119 // Layout tabs (optional, e.g. if resizing window)
120 void Layout(void);
121
122 // Draw all tabs
123 virtual void Draw(wxDC& dc);
124
125 // Process mouse event, return FALSE if we didn't process it
126 virtual bool OnEvent(wxMouseEvent& event);
127
128 // Called when a tab is activated
129 virtual void OnTabActivate(int activateId, int deactivateId);
130 // Allows vetoing
131 virtual bool OnTabPreActivate(int WXUNUSED(activateId), int WXUNUSED(deactivateId) ) { return TRUE; };
132
133 // Allows use of application-supplied wxTabControl classes.
134 virtual wxTabControl *OnCreateTabControl(void) { return new wxTabControl(this); }
135
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; }
140
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; }
149
150 inline void SetViewRect(const wxRectangle& rect) { m_tabViewRect = rect; }
151 inline wxRect GetViewRect(void) const { return m_tabViewRect; }
152
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);
156
157 inline void SetTabStyle(long style) { m_tabStyle = style; }
158 inline long GetTabStyle(void) const { return m_tabStyle; }
159
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; }
165
166 inline int GetTopMargin(void) const { return m_topMargin; }
167 inline void SetTopMargin(int margin) { m_topMargin = margin; }
168
169 void SetTabSelection(int sel, bool activateTool = TRUE);
170 inline int GetTabSelection() const { return m_tabSelection; }
171
172 // Find tab control for id
173 wxTabControl *FindTabControlForId(int id) const ;
174
175 // Find tab control for layer, position (starting from zero)
176 wxTabControl *FindTabControlForPosition(int layer, int position) const ;
177
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; }
182
183 inline void SetVerticalTabTextSpacing(int s) { m_tabVerticalTextSpacing = s; }
184 inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing; }
185
186 inline wxFont *GetTabFont() const { return m_tabFont; }
187 inline void SetTabFont(wxFont *f) { m_tabFont = f; }
188
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 ;
193
194 // Do the necessary to change to this tab
195 virtual bool ChangeTab(wxTabControl *control);
196
197 // Move the selected tab to the bottom layer, if necessary,
198 // without calling app activation code
199 bool MoveSelectionTab(wxTabControl *control);
200
201 inline int GetNumberOfTabs() const { return m_noTabs; }
202
203 protected:
204 // List of layers, from front to back.
205 wxList m_layers;
206
207 // Selected tab
208 int m_tabSelection;
209
210 // Usual tab height
211 int m_tabHeight;
212
213 // The height of the selected tab
214 int m_tabSelectionHeight;
215
216 // Usual tab width
217 int m_tabWidth;
218
219 // Space between tabs
220 int m_tabHorizontalSpacing;
221
222 // Space between top of normal tab and text
223 int m_tabVerticalTextSpacing;
224
225 // Horizontal offset of each tab row above the first
226 int m_tabHorizontalOffset;
227
228 // The distance between the bottom of the first tab row
229 // and the top of the client area (i.e. the margin)
230 int m_topMargin;
231
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;
235
236 // Bitlist of styles
237 long m_tabStyle;
238
239 // Colours
240 wxColour m_highlightColour;
241 wxColour m_shadowColour;
242 wxColour m_backgroundColour;
243 wxColour m_textColour;
244
245 // Pen and brush cache
246 wxPen* m_highlightPen;
247 wxPen* m_shadowPen;
248 wxPen* m_backgroundPen;
249 wxBrush* m_backgroundBrush;
250
251 wxFont* m_tabFont;
252 wxFont* m_tabSelectedFont;
253
254 int m_noTabs;
255
256 wxWindow* m_window;
257 };
258
259 /*
260 * A dialog box class that is tab-friendly
261 */
262
263 class wxTabbedDialog: public wxDialog
264 {
265 DECLARE_DYNAMIC_CLASS(wxTabbedDialog)
266
267 public:
268
269 wxTabbedDialog(wxWindow *parent, wxWindowID id, const wxString& title,
270 const wxPoint& pos = wxDefaultPosition,
271 const wxSize& size = wxDefaultSize,
272 long windowStyle = wxDEFAULT_DIALOG_STYLE, const wxString& name = wxDialogNameStr);
273 ~wxTabbedDialog(void);
274
275 inline wxTabView *GetTabView() const { return m_tabView; }
276 inline void SetTabView(wxTabView *v) { m_tabView = v; }
277
278 void OnCloseWindow(wxCloseEvent& event);
279 void OnMouseEvent(wxMouseEvent& event);
280 void OnPaint(wxPaintEvent& event);
281
282 protected:
283 wxTabView* m_tabView;
284
285 DECLARE_EVENT_TABLE()
286 };
287
288 /*
289 * A panel class that is tab-friendly
290 */
291
292 class wxTabbedPanel: public wxPanel
293 {
294 DECLARE_DYNAMIC_CLASS(wxTabbedPanel)
295
296 public:
297
298 wxTabbedPanel(wxWindow *parent, wxWindowID id,
299 const wxPoint& pos = wxDefaultPosition,
300 const wxSize& size = wxDefaultSize,
301 long windowStyle = 0, const wxString& name = wxPanelNameStr);
302 ~wxTabbedPanel(void);
303
304 inline wxTabView *GetTabView() const { return m_tabView; }
305 inline void SetTabView(wxTabView *v) { m_tabView = v; }
306
307 void OnMouseEvent(wxMouseEvent& event);
308 void OnPaint(wxPaintEvent& event);
309
310 protected:
311 wxTabView* m_tabView;
312
313 DECLARE_EVENT_TABLE()
314 };
315
316 class wxPanelTabView: public wxTabView
317 {
318 DECLARE_DYNAMIC_CLASS(wxPanelTabView)
319 public:
320 wxPanelTabView(wxPanel *pan, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
321 ~wxPanelTabView(void);
322
323 // Called when a tab is activated
324 virtual void OnTabActivate(int activateId, int deactivateId);
325
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; }
331
332 void ShowWindowForTab(int id);
333
334 protected:
335 // List of panels, one for each tab. Indexed
336 // by tab ID.
337 wxList m_tabWindows;
338 wxWindow* m_currentWindow;
339 wxPanel* m_panel;
340 };
341
342 #endif
343