]> git.saurik.com Git - wxWidgets.git/blob - include/wx/aui/auibook.h
wxaui multi-notebook now uses a tab art provider which allows for dynamically switcha...
[wxWidgets.git] / include / wx / aui / auibook.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/aui/auibook.h
3 // Purpose: wxaui: wx advanced user interface - notebook
4 // Author: Benjamin I. Williams
5 // Modified by:
6 // Created: 2006-06-28
7 // Copyright: (C) Copyright 2006, Kirix Corporation, All Rights Reserved.
8 // Licence: wxWindows Library Licence, Version 3.1
9 ///////////////////////////////////////////////////////////////////////////////
10
11
12
13 #ifndef _WX_AUINOTEBOOK_H_
14 #define _WX_AUINOTEBOOK_H_
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/defs.h"
21
22 #if wxUSE_AUI
23
24 #include "wx/aui/framemanager.h"
25 #include "wx/aui/dockart.h"
26 #include "wx/aui/floatpane.h"
27 #include "wx/control.h"
28
29
30 // tab art class
31
32
33 class wxTabArt
34 {
35 public:
36
37 virtual void DrawBackground(
38 wxDC* dc,
39 const wxRect& rect) = 0;
40
41 virtual void DrawTab(wxDC* dc,
42 const wxRect& in_rect,
43 const wxString& caption,
44 bool active,
45 wxRect* out_rect,
46 int* x_extent) = 0;
47
48 virtual void SetNormalFont(const wxFont& font) = 0;
49 virtual void SetSelectedFont(const wxFont& font) = 0;
50 virtual void SetMeasuringFont(const wxFont& font) = 0;
51 };
52
53
54 class wxDefaultTabArt : public wxTabArt
55 {
56
57 public:
58
59 wxDefaultTabArt();
60
61 void DrawBackground(
62 wxDC* dc,
63 const wxRect& rect);
64
65 void DrawTab(wxDC* dc,
66 const wxRect& in_rect,
67 const wxString& caption,
68 bool active,
69 wxRect* out_rect,
70 int* x_extent);
71
72 void SetNormalFont(const wxFont& font);
73 void SetSelectedFont(const wxFont& font);
74 void SetMeasuringFont(const wxFont& font);
75
76 private:
77
78 wxFont m_normal_font;
79 wxFont m_selected_font;
80 wxFont m_measuring_font;
81 wxPen m_normal_bkpen;
82 wxPen m_selected_bkpen;
83 wxBrush m_normal_bkbrush;
84 wxBrush m_selected_bkbrush;
85 wxBrush m_bkbrush;
86 };
87
88
89
90 // event declarations/classes
91
92 class WXDLLIMPEXP_AUI wxAuiNotebookEvent : public wxNotifyEvent
93 {
94 public:
95 wxAuiNotebookEvent(wxEventType command_type = wxEVT_NULL,
96 int win_id = 0)
97 : wxNotifyEvent(command_type, win_id)
98 {
99 }
100 #ifndef SWIG
101 wxAuiNotebookEvent(const wxAuiNotebookEvent& c) : wxNotifyEvent(c)
102 {
103 old_selection = c.old_selection;
104 selection = c.selection;
105 }
106 #endif
107 wxEvent *Clone() const { return new wxAuiNotebookEvent(*this); }
108
109 void SetSelection(int s) { selection = s; }
110 void SetOldSelection(int s) { old_selection = s; }
111 int GetSelection() const { return selection; }
112 int GetOldSelection() const { return old_selection; }
113
114 public:
115 int old_selection;
116 int selection;
117
118 #ifndef SWIG
119 private:
120 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiNotebookEvent)
121 #endif
122 };
123
124
125
126
127
128 class WXDLLIMPEXP_AUI wxAuiNotebookPage
129 {
130 public:
131 wxWindow* window; // page's associated window
132 wxString caption; // caption displayed on the tab
133 wxBitmap bitmap; // tab's bitmap
134 wxRect rect; // tab's hit rectangle
135 bool active; // true if the page is currently active
136 };
137
138 class WXDLLIMPEXP_AUI wxAuiTabContainerButton
139 {
140 public:
141 int id; // button's id
142 int cur_state; // current state (normal, hover, pressed)
143 wxBitmap bitmap; // button's bitmap
144 wxRect rect; // button's hit rectangle
145 };
146
147
148 #ifndef SWIG
149 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiNotebookPage, wxAuiNotebookPageArray, WXDLLIMPEXP_AUI);
150 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiTabContainerButton, wxAuiTabContainerButtonArray, WXDLLIMPEXP_AUI);
151 #endif
152
153
154 class WXDLLIMPEXP_AUI wxAuiTabContainer
155 {
156 public:
157
158 wxAuiTabContainer();
159 virtual ~wxAuiTabContainer();
160
161 void SetArtProvider(wxTabArt* art);
162 wxTabArt* GetArtProvider();
163
164 bool AddPage(wxWindow* page, const wxAuiNotebookPage& info);
165 bool InsertPage(wxWindow* page, const wxAuiNotebookPage& info, size_t idx);
166 bool RemovePage(wxWindow* page);
167 bool SetActivePage(wxWindow* page);
168 bool SetActivePage(size_t page);
169 void SetNoneActive();
170 int GetActivePage() const;
171 bool TabHitTest(int x, int y, wxWindow** hit) const;
172 bool ButtonHitTest(int x, int y, wxAuiTabContainerButton** hit) const;
173 wxWindow* GetWindowFromIdx(size_t idx) const;
174 int GetIdxFromWindow(wxWindow* page) const;
175 size_t GetPageCount() const;
176 wxAuiNotebookPage& GetPage(size_t idx);
177 wxAuiNotebookPageArray& GetPages();
178 void SetNormalFont(const wxFont& normal_font);
179 void SetSelectedFont(const wxFont& selected_font);
180 void SetMeasuringFont(const wxFont& measuring_font);
181 void DoShowHide();
182 void SetRect(const wxRect& rect);
183 void AddButton(int id, const wxBitmap& bmp);
184
185 protected:
186
187 virtual void Render(wxDC* dc);
188
189 private:
190
191 wxTabArt* m_art;
192 wxAuiNotebookPageArray m_pages;
193 wxAuiTabContainerButtonArray m_buttons;
194 wxRect m_rect;
195 };
196
197
198
199 class WXDLLIMPEXP_AUI wxAuiTabCtrl : public wxControl,
200 public wxAuiTabContainer
201 {
202 public:
203
204 wxAuiTabCtrl(wxWindow* parent,
205 wxWindowID id = wxID_ANY,
206 const wxPoint& pos = wxDefaultPosition,
207 const wxSize& size = wxDefaultSize,
208 long style = 0);
209
210 protected:
211
212 void OnPaint(wxPaintEvent& evt);
213 void OnEraseBackground(wxEraseEvent& evt);
214 void OnSize(wxSizeEvent& evt);
215 void OnLeftDown(wxMouseEvent& evt);
216 void OnLeftUp(wxMouseEvent& evt);
217 void OnMotion(wxMouseEvent& evt);
218 void OnLeaveWindow(wxMouseEvent& evt);
219
220 protected:
221
222 wxPoint m_click_pt;
223 int m_click_tab;
224 bool m_is_dragging;
225 wxAuiTabContainerButton* m_hover_button;
226
227 #ifndef SWIG
228 DECLARE_EVENT_TABLE()
229 #endif
230 };
231
232
233
234
235 class WXDLLIMPEXP_AUI wxAuiMultiNotebook : public wxControl
236 {
237
238 public:
239
240 wxAuiMultiNotebook();
241
242 wxAuiMultiNotebook(wxWindow* parent,
243 wxWindowID id = wxID_ANY,
244 const wxPoint& pos = wxDefaultPosition,
245 const wxSize& size = wxDefaultSize,
246 long style = 0);
247
248 virtual ~wxAuiMultiNotebook();
249
250 bool Create(wxWindow* parent,
251 wxWindowID id = wxID_ANY,
252 const wxPoint& pos = wxDefaultPosition,
253 const wxSize& size = wxDefaultSize,
254 long style = 0);
255
256 bool AddPage(wxWindow* page,
257 const wxString& caption,
258 bool select = false,
259 const wxBitmap& bitmap = wxNullBitmap);
260
261 bool InsertPage(size_t page_idx,
262 wxWindow* page,
263 const wxString& caption,
264 bool select = false,
265 const wxBitmap& bitmap = wxNullBitmap);
266
267 bool DeletePage(size_t page);
268 bool RemovePage(size_t page);
269
270 bool SetPageText(size_t page, const wxString& text);
271 size_t SetSelection(size_t new_page);
272 int GetSelection() const;
273 size_t GetPageCount() const;
274 wxWindow* GetPage(size_t page_idx) const;
275
276 void SetArtProvider(wxTabArt* art);
277 wxTabArt* GetArtProvider();
278
279 protected:
280
281 wxAuiTabCtrl* GetTabCtrlFromPoint(const wxPoint& pt);
282 wxWindow* GetTabFrameFromTabCtrl(wxWindow* tab_ctrl);
283 wxAuiTabCtrl* GetActiveTabCtrl();
284 bool FindTab(wxWindow* page, wxAuiTabCtrl** ctrl, int* idx);
285 void RemoveEmptyTabFrames();
286
287 protected:
288
289 void DoSizing();
290 void InitNotebook();
291
292 void OnChildFocus(wxChildFocusEvent& evt);
293 void OnRender(wxFrameManagerEvent& evt);
294 void OnEraseBackground(wxEraseEvent& evt);
295 void OnSize(wxSizeEvent& evt);
296 void OnTabClicked(wxCommandEvent& evt);
297 void OnTabBeginDrag(wxCommandEvent& evt);
298 void OnTabDragMotion(wxCommandEvent& evt);
299 void OnTabEndDrag(wxCommandEvent& evt);
300 void OnTabButton(wxCommandEvent& evt);
301
302 protected:
303
304 wxFrameManager m_mgr;
305 wxAuiTabContainer m_tabs;
306 int m_curpage;
307 int m_tab_id_counter;
308 wxWindow* m_dummy_wnd;
309
310 wxFont m_selected_font;
311 wxFont m_normal_font;
312 int m_tab_ctrl_height;
313
314 #ifndef SWIG
315 DECLARE_EVENT_TABLE()
316 #endif
317 };
318
319
320
321
322 // wx event machinery
323
324 #ifndef SWIG
325
326 BEGIN_DECLARE_EVENT_TYPES()
327 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 0)
328 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 0)
329 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 0)
330 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, 0)
331 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, 0)
332 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, 0)
333 END_DECLARE_EVENT_TYPES()
334
335 typedef void (wxEvtHandler::*wxAuiNotebookEventFunction)(wxAuiNotebookEvent&);
336
337 #define wxAuiNotebookEventHandler(func) \
338 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiNotebookEventFunction, &func)
339
340 #define EVT_AUINOTEBOOK_PAGE_CHANGED(winid, fn) \
341 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, winid, wxAuiNotebookEventHandler(fn))
342 #define EVT_AUINOTEBOOK_PAGE_CHANGING(winid, fn) \
343 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, winid, wxAuiNotebookEventHandler(fn))
344 #define EVT_AUINOTEBOOK_PAGE_BUTTON(winid, fn) \
345 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, winid, wxAuiNotebookEventHandler(fn))
346 #define EVT_AUINOTEBOOK_BEGIN_DRAG(winid, fn) \
347 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, winid, wxAuiNotebookEventHandler(fn))
348 #define EVT_AUINOTEBOOK_END_DRAG(winid, fn) \
349 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, winid, wxAuiNotebookEventHandler(fn))
350 #define EVT_AUINOTEBOOK_DRAG_MOTION(winid, fn) \
351 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, winid, wxAuiNotebookEventHandler(fn))
352
353 #else
354
355 // wxpython/swig event work
356 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED;
357 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING;
358 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_BUTTON;
359 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG;
360 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_END_DRAG;
361 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION;
362
363 %pythoncode {
364 EVT_AUINOTEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 1 )
365 EVT_AUINOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 1 )
366 EVT_AUINOTEBOOK_BUTTON = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 1 )
367 EVT_AUINOTEBOOK_BEGIN_DRAG = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, 1 )
368 EVT_AUINOTEBOOK_END_DRAG = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, 1 )
369 EVT_AUINOTEBOOK_DRAG_MOTION = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, 1 )
370 }
371 #endif
372
373
374 #endif // wxUSE_AUI
375 #endif // _WX_AUINOTEBOOK_H_