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