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