]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/generic/tabg.h |
eed80e5e | 3 | // Purpose: Generic tabbed dialogs; used by wxMotif's wxNotebook |
c801d85f KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
99d80019 | 7 | // Copyright: (c) Julian Smart |
65571936 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef __TABGH_G__ | |
12 | #define __TABGH_G__ | |
13 | ||
c801d85f KB |
14 | #define WXTAB_VERSION 1.1 |
15 | ||
4410d619 | 16 | #include "wx/hashmap.h" |
c801d85f | 17 | #include "wx/string.h" |
4b5f3fe6 | 18 | #include "wx/dialog.h" |
798a4529 | 19 | #include "wx/panel.h" |
4410d619 | 20 | #include "wx/list.h" |
c801d85f | 21 | |
b5dbe15d | 22 | class WXDLLIMPEXP_FWD_CORE wxTabView; |
c801d85f KB |
23 | |
24 | /* | |
25 | * A wxTabControl is the internal and visual representation | |
26 | * of the tab. | |
27 | */ | |
a6f6393c | 28 | |
53a2db12 | 29 | class WXDLLIMPEXP_CORE wxTabControl: public wxObject |
c801d85f KB |
30 | { |
31 | DECLARE_DYNAMIC_CLASS(wxTabControl) | |
32 | public: | |
d3b9f782 | 33 | wxTabControl(wxTabView *v = NULL); |
d3c7fc99 | 34 | virtual ~wxTabControl(void); |
a6f6393c | 35 | |
c801d85f | 36 | virtual void OnDraw(wxDC& dc, bool lastInRow); |
bfc6fde4 VZ |
37 | void SetLabel(const wxString& str) { m_controlLabel = str; } |
38 | wxString GetLabel(void) const { return m_controlLabel; } | |
c801d85f | 39 | |
bfc6fde4 VZ |
40 | void SetFont(const wxFont& f) { m_labelFont = f; } |
41 | wxFont *GetFont(void) const { return (wxFont*) & m_labelFont; } | |
c801d85f | 42 | |
bfc6fde4 VZ |
43 | void SetSelected(bool sel) { m_isSelected = sel; } |
44 | bool IsSelected(void) const { return m_isSelected; } | |
c801d85f | 45 | |
bfc6fde4 VZ |
46 | void SetPosition(int x, int y) { m_offsetX = x; m_offsetY = y; } |
47 | void SetSize(int x, int y) { m_width = x; m_height = y; } | |
a6f6393c | 48 | |
bfc6fde4 VZ |
49 | void SetRowPosition(int r) { m_rowPosition = r; } |
50 | int GetRowPosition() const { return m_rowPosition; } | |
51 | void SetColPosition(int c) { m_colPosition = c; } | |
52 | int GetColPosition() const { return m_colPosition; } | |
a6f6393c | 53 | |
bfc6fde4 VZ |
54 | int GetX(void) const { return m_offsetX; } |
55 | int GetY(void) const { return m_offsetY; } | |
56 | int GetWidth(void) const { return m_width; } | |
57 | int GetHeight(void) const { return m_height; } | |
a6f6393c | 58 | |
bfc6fde4 VZ |
59 | int GetId(void) const { return m_id; } |
60 | void SetId(int i) { m_id = i; } | |
a6f6393c | 61 | |
c801d85f KB |
62 | virtual bool HitTest(int x, int y) const ; |
63 | ||
64 | protected: | |
65 | wxTabView* m_view; | |
66 | wxString m_controlLabel; | |
67 | bool m_isSelected; | |
02800301 | 68 | wxFont m_labelFont; |
c801d85f KB |
69 | int m_offsetX; // Offsets from top-left of tab view area (the area below the tabs) |
70 | int m_offsetY; | |
71 | int m_width; | |
72 | int m_height; | |
73 | int m_id; | |
74 | int m_rowPosition; // Position in row from 0 | |
75 | int m_colPosition; // Position in col from 0 | |
76 | }; | |
a6f6393c | 77 | |
c801d85f KB |
78 | /* |
79 | * Each wxTabLayer is a list of tabs. E.g. there | |
80 | * are 3 layers in the MS Word Options dialog. | |
81 | */ | |
a6f6393c | 82 | |
53a2db12 | 83 | class WXDLLIMPEXP_CORE wxTabLayer: public wxList |
c801d85f | 84 | { |
c801d85f KB |
85 | }; |
86 | ||
87 | /* | |
88 | * The wxTabView controls and draws the tabbed object | |
89 | */ | |
90 | ||
4410d619 MB |
91 | WX_DECLARE_LIST(wxTabLayer, wxTabLayerList); |
92 | ||
c801d85f KB |
93 | #define wxTAB_STYLE_DRAW_BOX 1 // Draws 3D boxes round tab layers |
94 | #define wxTAB_STYLE_COLOUR_INTERIOR 2 // Colours interior of tabs, otherwise draws outline | |
95 | ||
53a2db12 | 96 | class WXDLLIMPEXP_CORE wxTabView: public wxObject |
c801d85f KB |
97 | { |
98 | DECLARE_DYNAMIC_CLASS(wxTabView) | |
99 | public: | |
100 | wxTabView(long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR); | |
d3c7fc99 | 101 | virtual ~wxTabView(); |
c801d85f | 102 | |
0ec6fd04 | 103 | inline int GetNumberOfLayers() const { return m_layers.GetCount(); } |
dabf1d07 | 104 | inline wxTabLayerList& GetLayers() { return m_layers; } |
c801d85f KB |
105 | |
106 | inline void SetWindow(wxWindow* wnd) { m_window = wnd; } | |
107 | inline wxWindow* GetWindow(void) const { return m_window; } | |
ca65c044 | 108 | |
c801d85f | 109 | // Automatically positions tabs |
d3b9f782 | 110 | wxTabControl *AddTab(int id, const wxString& label, wxTabControl *existingTab = NULL); |
621793f4 JS |
111 | |
112 | // Remove the tab without deleting the window | |
113 | bool RemoveTab(int id); | |
ca65c044 WS |
114 | |
115 | void ClearTabs(bool deleteTabs = true); | |
c801d85f | 116 | |
7fe7d506 JS |
117 | bool SetTabText(int id, const wxString& label); |
118 | wxString GetTabText(int id) const; | |
119 | ||
c801d85f | 120 | // Layout tabs (optional, e.g. if resizing window) |
f03fc89f | 121 | void LayoutTabs(); |
c801d85f KB |
122 | |
123 | // Draw all tabs | |
124 | virtual void Draw(wxDC& dc); | |
ca65c044 WS |
125 | |
126 | // Process mouse event, return false if we didn't process it | |
c801d85f KB |
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 | |
6dd0883d | 132 | virtual bool OnTabPreActivate(int WXUNUSED(activateId), int WXUNUSED(deactivateId) ) { return true; } |
c801d85f KB |
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; } | |
ca65c044 | 141 | |
c801d85f KB |
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; } | |
f516d986 VZ |
146 | inline const wxPen *GetHighlightPen(void) const { return m_highlightPen; } |
147 | inline const wxPen *GetShadowPen(void) const { return m_shadowPen; } | |
148 | inline const wxPen *GetBackgroundPen(void) const { return m_backgroundPen; } | |
149 | inline const wxBrush *GetBackgroundBrush(void) const { return m_backgroundBrush; } | |
ca65c044 | 150 | |
16e93305 | 151 | inline void SetViewRect(const wxRect& rect) { m_tabViewRect = rect; } |
c801d85f | 152 | inline wxRect GetViewRect(void) const { return m_tabViewRect; } |
ca65c044 | 153 | |
c801d85f KB |
154 | // Calculate tab width to fit to view, and optionally adjust the view |
155 | // to fit the tabs exactly. | |
ca65c044 | 156 | int CalculateTabWidth(int noTabs, bool adjustView = false); |
c801d85f KB |
157 | |
158 | inline void SetTabStyle(long style) { m_tabStyle = style; } | |
159 | inline long GetTabStyle(void) const { return m_tabStyle; } | |
ca65c044 | 160 | |
c801d85f KB |
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(); | |
ca65c044 | 170 | |
c801d85f KB |
171 | inline int GetTopMargin(void) const { return m_topMargin; } |
172 | inline void SetTopMargin(int margin) { m_topMargin = margin; } | |
ca65c044 WS |
173 | |
174 | void SetTabSelection(int sel, bool activateTool = true); | |
c801d85f | 175 | inline int GetTabSelection() const { return m_tabSelection; } |
ca65c044 | 176 | |
c801d85f KB |
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 ; | |
ca65c044 | 182 | |
c801d85f KB |
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; } | |
ca65c044 | 187 | |
c801d85f KB |
188 | inline void SetVerticalTabTextSpacing(int s) { m_tabVerticalTextSpacing = s; } |
189 | inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing; } | |
ca65c044 | 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 | 196 | // Find the node and the column at which this control is positioned. |
4410d619 | 197 | wxList::compatibility_iterator FindTabNodeAndColumn(wxTabControl *control, int *col) const ; |
ca65c044 | 198 | |
c801d85f KB |
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. | |
4410d619 | 210 | wxTabLayerList m_layers; |
ca65c044 | 211 | |
c801d85f KB |
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; | |
ca65c044 | 223 | |
c801d85f KB |
224 | // Space between tabs |
225 | int m_tabHorizontalSpacing; | |
ca65c044 | 226 | |
c801d85f KB |
227 | // Space between top of normal tab and text |
228 | int m_tabVerticalTextSpacing; | |
ca65c044 | 229 | |
c801d85f KB |
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; | |
ca65c044 | 240 | |
c801d85f KB |
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; | |
ca65c044 | 249 | |
c801d85f | 250 | // Pen and brush cache |
f516d986 VZ |
251 | const wxPen* m_highlightPen; |
252 | const wxPen* m_shadowPen; | |
253 | const wxPen* m_backgroundPen; | |
254 | const wxBrush* m_backgroundBrush; | |
ca65c044 | 255 | |
02800301 JS |
256 | wxFont m_tabFont; |
257 | wxFont m_tabSelectedFont; | |
ca65c044 | 258 | |
c801d85f KB |
259 | int m_noTabs; |
260 | ||
261 | wxWindow* m_window; | |
262 | }; | |
263 | ||
264 | /* | |
265 | * A dialog box class that is tab-friendly | |
266 | */ | |
ca65c044 | 267 | |
53a2db12 | 268 | class WXDLLIMPEXP_CORE wxTabbedDialog : public wxDialog |
c801d85f | 269 | { |
d3c7fc99 | 270 | DECLARE_DYNAMIC_CLASS(wxTabbedDialog) |
ca65c044 | 271 | |
c801d85f | 272 | public: |
d3c7fc99 VZ |
273 | wxTabbedDialog(wxWindow *parent, |
274 | wxWindowID id, | |
275 | const wxString& title, | |
276 | const wxPoint& pos = wxDefaultPosition, | |
277 | const wxSize& size = wxDefaultSize, | |
278 | long windowStyle = wxDEFAULT_DIALOG_STYLE, | |
279 | const wxString& name = wxDialogNameStr); | |
280 | virtual ~wxTabbedDialog(); | |
281 | ||
282 | wxTabView *GetTabView() const { return m_tabView; } | |
283 | void SetTabView(wxTabView *v) { m_tabView = v; } | |
284 | ||
285 | void OnCloseWindow(wxCloseEvent& event); | |
286 | void OnMouseEvent(wxMouseEvent& event); | |
287 | void OnPaint(wxPaintEvent& event); | |
c801d85f KB |
288 | |
289 | protected: | |
d3c7fc99 | 290 | wxTabView* m_tabView; |
ca65c044 | 291 | |
d3c7fc99 VZ |
292 | private: |
293 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
294 | }; |
295 | ||
296 | /* | |
297 | * A panel class that is tab-friendly | |
298 | */ | |
299 | ||
53a2db12 | 300 | class WXDLLIMPEXP_CORE wxTabbedPanel : public wxPanel |
c801d85f | 301 | { |
d3c7fc99 | 302 | DECLARE_DYNAMIC_CLASS(wxTabbedPanel) |
ca65c044 | 303 | |
c801d85f | 304 | public: |
d3c7fc99 VZ |
305 | wxTabbedPanel(wxWindow *parent, |
306 | wxWindowID id, | |
307 | const wxPoint& pos = wxDefaultPosition, | |
308 | const wxSize& size = wxDefaultSize, | |
309 | long windowStyle = 0, | |
310 | const wxString& name = wxPanelNameStr); | |
311 | virtual ~wxTabbedPanel(); | |
c801d85f | 312 | |
d3c7fc99 VZ |
313 | wxTabView *GetTabView() const { return m_tabView; } |
314 | void SetTabView(wxTabView *v) { m_tabView = v; } | |
ca65c044 | 315 | |
d3c7fc99 VZ |
316 | void OnMouseEvent(wxMouseEvent& event); |
317 | void OnPaint(wxPaintEvent& event); | |
c801d85f KB |
318 | |
319 | protected: | |
d3c7fc99 | 320 | wxTabView* m_tabView; |
ca65c044 | 321 | |
d3c7fc99 VZ |
322 | private: |
323 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
324 | }; |
325 | ||
4410d619 MB |
326 | WX_DECLARE_HASH_MAP(int, wxWindow*, wxIntegerHash, wxIntegerEqual, |
327 | wxIntToWindowHashMap); | |
328 | ||
53a2db12 | 329 | class WXDLLIMPEXP_CORE wxPanelTabView : public wxTabView |
c801d85f | 330 | { |
d3c7fc99 VZ |
331 | DECLARE_DYNAMIC_CLASS(wxPanelTabView) |
332 | ||
c801d85f | 333 | public: |
d3c7fc99 VZ |
334 | wxPanelTabView(wxPanel *pan, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR); |
335 | virtual ~wxPanelTabView(void); | |
c801d85f | 336 | |
d3c7fc99 VZ |
337 | // Called when a tab is activated |
338 | virtual void OnTabActivate(int activateId, int deactivateId); | |
c801d85f | 339 | |
d3c7fc99 VZ |
340 | // Specific to this class |
341 | void AddTabWindow(int id, wxWindow *window); | |
342 | wxWindow *GetTabWindow(int id) const ; | |
343 | void ClearWindows(bool deleteWindows = true); | |
344 | wxWindow *GetCurrentWindow() const { return m_currentWindow; } | |
ca65c044 | 345 | |
d3c7fc99 VZ |
346 | void ShowWindowForTab(int id); |
347 | // wxList& GetWindows() const { return (wxList&) m_tabWindows; } | |
c801d85f KB |
348 | |
349 | protected: | |
d3c7fc99 VZ |
350 | // List of panels, one for each tab. Indexed |
351 | // by tab ID. | |
352 | wxIntToWindowHashMap m_tabWindows; | |
353 | wxWindow* m_currentWindow; | |
354 | wxPanel* m_panel; | |
c801d85f KB |
355 | }; |
356 | ||
357 | #endif | |
358 |