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