wxaui big class rename
[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
31 enum wxAuiNotebookOption
32 {
33 wxAUI_NB_TOP = 1 << 0,
34 wxAUI_NB_LEFT = 1 << 1, // not implemented yet
35 wxAUI_NB_RIGHT = 1 << 2, // not implemented yet
36 wxAUI_NB_BOTTOM = 1 << 3, // not implemented yet
37 wxAUI_NB_TAB_SPLIT = 1 << 4,
38 wxAUI_NB_TAB_MOVE = 1 << 5,
39 wxAUI_NB_SCROLL_BUTTONS = 1 << 6,
40 wxAUI_NB_CLOSE_BUTTON = 1 << 7,
41 wxAUI_NB_PAGELIST_BUTTON = 1 << 8,
42 wxAUI_NB_CLOSE_ON_ACTIVE_TAB = 1 << 9,
43 wxAUI_NB_CLOSE_ON_ALL_TABS = 1 << 10,
44
45 wxAUI_NB_DEFAULT_STYLE = wxAUI_NB_TOP |
46 wxAUI_NB_TAB_SPLIT |
47 wxAUI_NB_TAB_MOVE |
48 wxAUI_NB_SCROLL_BUTTONS// |
49 //wxAUI_NB_CLOSE_ON_ALL_TABS
50 };
51
52
53
54
55
56 // tab art class
57
58 class WXDLLIMPEXP_AUI wxAuiTabArt
59 {
60 public:
61
62 wxAuiTabArt() { }
63 virtual ~wxAuiTabArt() { }
64
65 virtual void SetNormalFont(const wxFont& font) = 0;
66 virtual void SetSelectedFont(const wxFont& font) = 0;
67 virtual void SetMeasuringFont(const wxFont& font) = 0;
68
69 virtual void DrawBackground(
70 wxDC* dc,
71 const wxRect& rect) = 0;
72
73 virtual void DrawTab(wxDC* dc,
74 const wxRect& in_rect,
75 const wxString& caption,
76 bool active,
77 bool with_close_button,
78 wxRect* out_rect,
79 int* x_extent) = 0;
80
81 virtual void DrawButton(
82 wxDC* dc,
83 const wxRect& in_rect,
84 int bitmap_id,
85 int button_state,
86 int orientation,
87 const wxBitmap& bitmap_override,
88 wxRect* out_rect) = 0;
89
90 virtual wxSize GetTabSize(
91 wxDC* dc,
92 const wxString& caption,
93 bool active,
94 bool with_close_button,
95 int* x_extent) = 0;
96
97 virtual int GetBestTabCtrlSize(wxWindow* wnd) = 0;
98 };
99
100
101 class WXDLLIMPEXP_AUI wxAuiDefaultTabArt : public wxAuiTabArt
102 {
103
104 public:
105
106 wxAuiDefaultTabArt();
107 virtual ~wxAuiDefaultTabArt();
108
109 void SetNormalFont(const wxFont& font);
110 void SetSelectedFont(const wxFont& font);
111 void SetMeasuringFont(const wxFont& font);
112
113 void DrawBackground(
114 wxDC* dc,
115 const wxRect& rect);
116
117 void DrawTab(wxDC* dc,
118 const wxRect& in_rect,
119 const wxString& caption,
120 bool active,
121 bool with_close_button,
122 wxRect* out_rect,
123 int* x_extent);
124
125 void DrawButton(
126 wxDC* dc,
127 const wxRect& in_rect,
128 int bitmap_id,
129 int button_state,
130 int orientation,
131 const wxBitmap& bitmap_override,
132 wxRect* out_rect);
133
134 wxSize GetTabSize(
135 wxDC* dc,
136 const wxString& caption,
137 bool active,
138 bool with_close_button,
139 int* x_extent);
140
141 int GetBestTabCtrlSize(wxWindow* wnd);
142
143 private:
144
145 wxFont m_normal_font;
146 wxFont m_selected_font;
147 wxFont m_measuring_font;
148 wxPen m_normal_bkpen;
149 wxPen m_selected_bkpen;
150 wxBrush m_normal_bkbrush;
151 wxBrush m_selected_bkbrush;
152 wxBrush m_bkbrush;
153 wxBitmap m_active_close_bmp;
154 wxBitmap m_disabled_close_bmp;
155 wxBitmap m_active_left_bmp;
156 wxBitmap m_disabled_left_bmp;
157 wxBitmap m_active_right_bmp;
158 wxBitmap m_disabled_right_bmp;
159 };
160
161
162
163 // event declarations/classes
164
165 class WXDLLIMPEXP_AUI wxAuiNotebookEvent : public wxNotifyEvent
166 {
167 public:
168 wxAuiNotebookEvent(wxEventType command_type = wxEVT_NULL,
169 int win_id = 0)
170 : wxNotifyEvent(command_type, win_id)
171 {
172 }
173 #ifndef SWIG
174 wxAuiNotebookEvent(const wxAuiNotebookEvent& c) : wxNotifyEvent(c)
175 {
176 old_selection = c.old_selection;
177 selection = c.selection;
178 }
179 #endif
180 wxEvent *Clone() const { return new wxAuiNotebookEvent(*this); }
181
182 void SetSelection(int s) { selection = s; m_commandInt = s; }
183 void SetOldSelection(int s) { old_selection = s; }
184 int GetSelection() const { return selection; }
185 int GetOldSelection() const { return old_selection; }
186
187 public:
188 int old_selection;
189 int selection;
190
191 #ifndef SWIG
192 private:
193 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxAuiNotebookEvent)
194 #endif
195 };
196
197
198
199
200
201 class WXDLLIMPEXP_AUI wxAuiNotebookPage
202 {
203 public:
204 wxWindow* window; // page's associated window
205 wxString caption; // caption displayed on the tab
206 wxBitmap bitmap; // tab's bitmap
207 wxRect rect; // tab's hit rectangle
208 bool active; // true if the page is currently active
209 };
210
211 class WXDLLIMPEXP_AUI wxAuiTabContainerButton
212 {
213 public:
214 int id; // button's id
215 int cur_state; // current state (normal, hover, pressed, etc.)
216 int location; // buttons location (wxLEFT or wxRIGHT)
217 wxBitmap bitmap; // button's hover bitmap
218 wxBitmap dis_bitmap; // button's disabled bitmap
219 wxRect rect; // button's hit rectangle
220 };
221
222
223 #ifndef SWIG
224 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiNotebookPage, wxAuiNotebookPageArray, WXDLLIMPEXP_AUI);
225 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiTabContainerButton, wxAuiTabContainerButtonArray, WXDLLIMPEXP_AUI);
226 #endif
227
228
229 class WXDLLIMPEXP_AUI wxAuiTabContainer
230 {
231 public:
232
233 wxAuiTabContainer();
234 virtual ~wxAuiTabContainer();
235
236 void SetArtProvider(wxAuiTabArt* art);
237 wxAuiTabArt* GetArtProvider();
238
239 void SetFlags(unsigned int flags);
240 unsigned int GetFlags() const;
241
242 bool AddPage(wxWindow* page, const wxAuiNotebookPage& info);
243 bool InsertPage(wxWindow* page, const wxAuiNotebookPage& info, size_t idx);
244 bool MovePage(wxWindow* page, size_t new_idx);
245 bool RemovePage(wxWindow* page);
246 bool SetActivePage(wxWindow* page);
247 bool SetActivePage(size_t page);
248 void SetNoneActive();
249 int GetActivePage() const;
250 bool TabHitTest(int x, int y, wxWindow** hit) const;
251 bool ButtonHitTest(int x, int y, wxAuiTabContainerButton** hit) const;
252 wxWindow* GetWindowFromIdx(size_t idx) const;
253 int GetIdxFromWindow(wxWindow* page) const;
254 size_t GetPageCount() const;
255 wxAuiNotebookPage& GetPage(size_t idx);
256 wxAuiNotebookPageArray& GetPages();
257 void SetNormalFont(const wxFont& normal_font);
258 void SetSelectedFont(const wxFont& selected_font);
259 void SetMeasuringFont(const wxFont& measuring_font);
260 void DoShowHide();
261 void SetRect(const wxRect& rect);
262 void AddButton(int id,
263 int location,
264 const wxBitmap& normal_bitmap = wxNullBitmap,
265 const wxBitmap& disabled_bitmap = wxNullBitmap);
266
267 size_t GetTabOffset() const;
268 void SetTabOffset(size_t offset);
269
270 protected:
271
272 virtual void Render(wxDC* dc);
273
274 private:
275
276 wxAuiTabArt* m_art;
277 wxAuiNotebookPageArray m_pages;
278 wxAuiTabContainerButtonArray m_buttons;
279 wxRect m_rect;
280 size_t m_tab_offset;
281 unsigned int m_flags;
282 };
283
284
285
286 class WXDLLIMPEXP_AUI wxAuiTabCtrl : public wxControl,
287 public wxAuiTabContainer
288 {
289 public:
290
291 wxAuiTabCtrl(wxWindow* parent,
292 wxWindowID id = wxID_ANY,
293 const wxPoint& pos = wxDefaultPosition,
294 const wxSize& size = wxDefaultSize,
295 long style = 0);
296
297 ~wxAuiTabCtrl();
298
299 protected:
300
301 void OnPaint(wxPaintEvent& evt);
302 void OnEraseBackground(wxEraseEvent& evt);
303 void OnSize(wxSizeEvent& evt);
304 void OnLeftDown(wxMouseEvent& evt);
305 void OnLeftUp(wxMouseEvent& evt);
306 void OnMotion(wxMouseEvent& evt);
307 void OnLeaveWindow(wxMouseEvent& evt);
308 void OnButton(wxAuiNotebookEvent& evt);
309
310
311 protected:
312
313 wxPoint m_click_pt;
314 wxWindow* m_click_tab;
315 bool m_is_dragging;
316 wxAuiTabContainerButton* m_hover_button;
317
318 #ifndef SWIG
319 DECLARE_EVENT_TABLE()
320 #endif
321 };
322
323
324
325
326 class WXDLLIMPEXP_AUI wxAuiNotebook : public wxControl
327 {
328
329 public:
330
331 wxAuiNotebook();
332
333 wxAuiNotebook(wxWindow* parent,
334 wxWindowID id = wxID_ANY,
335 const wxPoint& pos = wxDefaultPosition,
336 const wxSize& size = wxDefaultSize,
337 long style = wxAUI_NB_DEFAULT_STYLE);
338
339 virtual ~wxAuiNotebook();
340
341 bool Create(wxWindow* parent,
342 wxWindowID id = wxID_ANY,
343 const wxPoint& pos = wxDefaultPosition,
344 const wxSize& size = wxDefaultSize,
345 long style = 0);
346
347 bool AddPage(wxWindow* page,
348 const wxString& caption,
349 bool select = false,
350 const wxBitmap& bitmap = wxNullBitmap);
351
352 bool InsertPage(size_t page_idx,
353 wxWindow* page,
354 const wxString& caption,
355 bool select = false,
356 const wxBitmap& bitmap = wxNullBitmap);
357
358 bool DeletePage(size_t page);
359 bool RemovePage(size_t page);
360
361 bool SetPageText(size_t page, const wxString& text);
362 size_t SetSelection(size_t new_page);
363 int GetSelection() const;
364 size_t GetPageCount() const;
365 wxWindow* GetPage(size_t page_idx) const;
366
367 void SetArtProvider(wxAuiTabArt* art);
368 wxAuiTabArt* GetArtProvider();
369
370 protected:
371
372 wxAuiTabCtrl* GetTabCtrlFromPoint(const wxPoint& pt);
373 wxWindow* GetTabFrameFromTabCtrl(wxWindow* tab_ctrl);
374 wxAuiTabCtrl* GetActiveTabCtrl();
375 bool FindTab(wxWindow* page, wxAuiTabCtrl** ctrl, int* idx);
376 void RemoveEmptyTabFrames();
377
378 protected:
379
380 void DoSizing();
381 void InitNotebook(long style);
382
383 void OnChildFocus(wxChildFocusEvent& evt);
384 void OnRender(wxAuiManagerEvent& evt);
385 void OnEraseBackground(wxEraseEvent& evt);
386 void OnSize(wxSizeEvent& evt);
387 void OnTabClicked(wxCommandEvent& evt);
388 void OnTabBeginDrag(wxCommandEvent& evt);
389 void OnTabDragMotion(wxCommandEvent& evt);
390 void OnTabEndDrag(wxCommandEvent& evt);
391 void OnTabButton(wxCommandEvent& evt);
392
393 protected:
394
395 wxAuiManager m_mgr;
396 wxAuiTabContainer m_tabs;
397 int m_curpage;
398 int m_tab_id_counter;
399 wxWindow* m_dummy_wnd;
400
401 wxFont m_selected_font;
402 wxFont m_normal_font;
403 int m_tab_ctrl_height;
404
405 int m_last_drag_x;
406 unsigned int m_flags;
407
408 #ifndef SWIG
409 DECLARE_EVENT_TABLE()
410 #endif
411 };
412
413
414
415
416 // wx event machinery
417
418 #ifndef SWIG
419
420 BEGIN_DECLARE_EVENT_TYPES()
421 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 0)
422 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 0)
423 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 0)
424 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, 0)
425 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, 0)
426 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, 0)
427 END_DECLARE_EVENT_TYPES()
428
429 typedef void (wxEvtHandler::*wxAuiNotebookEventFunction)(wxAuiNotebookEvent&);
430
431 #define wxAuiNotebookEventHandler(func) \
432 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiNotebookEventFunction, &func)
433
434 #define EVT_AUINOTEBOOK_PAGE_CHANGED(winid, fn) \
435 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, winid, wxAuiNotebookEventHandler(fn))
436 #define EVT_AUINOTEBOOK_PAGE_CHANGING(winid, fn) \
437 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, winid, wxAuiNotebookEventHandler(fn))
438 #define EVT_AUINOTEBOOK_BUTTON(winid, fn) \
439 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, winid, wxAuiNotebookEventHandler(fn))
440 #define EVT_AUINOTEBOOK_BEGIN_DRAG(winid, fn) \
441 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, winid, wxAuiNotebookEventHandler(fn))
442 #define EVT_AUINOTEBOOK_END_DRAG(winid, fn) \
443 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, winid, wxAuiNotebookEventHandler(fn))
444 #define EVT_AUINOTEBOOK_DRAG_MOTION(winid, fn) \
445 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, winid, wxAuiNotebookEventHandler(fn))
446
447 #else
448
449 // wxpython/swig event work
450 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED;
451 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING;
452 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_BUTTON;
453 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG;
454 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_END_DRAG;
455 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION;
456
457 %pythoncode {
458 EVT_AUINOTEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 1 )
459 EVT_AUINOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 1 )
460 EVT_AUINOTEBOOK_BUTTON = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 1 )
461 EVT_AUINOTEBOOK_BEGIN_DRAG = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, 1 )
462 EVT_AUINOTEBOOK_END_DRAG = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, 1 )
463 EVT_AUINOTEBOOK_DRAG_MOTION = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, 1 )
464 }
465 #endif
466
467
468 #endif // wxUSE_AUI
469 #endif // _WX_AUINOTEBOOK_H_