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