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