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