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