]> git.saurik.com Git - wxWidgets.git/blob - include/wx/aui/auibook.h
wxaui multi-book prep work for left/right buttons on tab bar
[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 int location; // buttons location (wxLEFT or wxRIGHT)
144 wxBitmap bitmap; // button's bitmap
145 wxRect rect; // button's hit rectangle
146 };
147
148
149 #ifndef SWIG
150 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiNotebookPage, wxAuiNotebookPageArray, WXDLLIMPEXP_AUI);
151 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiTabContainerButton, wxAuiTabContainerButtonArray, WXDLLIMPEXP_AUI);
152 #endif
153
154
155 class WXDLLIMPEXP_AUI wxAuiTabContainer
156 {
157 public:
158
159 wxAuiTabContainer();
160 virtual ~wxAuiTabContainer();
161
162 void SetArtProvider(wxTabArt* art);
163 wxTabArt* GetArtProvider();
164
165 bool AddPage(wxWindow* page, const wxAuiNotebookPage& info);
166 bool InsertPage(wxWindow* page, const wxAuiNotebookPage& info, size_t idx);
167 bool RemovePage(wxWindow* page);
168 bool SetActivePage(wxWindow* page);
169 bool SetActivePage(size_t page);
170 void SetNoneActive();
171 int GetActivePage() const;
172 bool TabHitTest(int x, int y, wxWindow** hit) const;
173 bool ButtonHitTest(int x, int y, wxAuiTabContainerButton** hit) const;
174 wxWindow* GetWindowFromIdx(size_t idx) const;
175 int GetIdxFromWindow(wxWindow* page) const;
176 size_t GetPageCount() const;
177 wxAuiNotebookPage& GetPage(size_t idx);
178 wxAuiNotebookPageArray& GetPages();
179 void SetNormalFont(const wxFont& normal_font);
180 void SetSelectedFont(const wxFont& selected_font);
181 void SetMeasuringFont(const wxFont& measuring_font);
182 void DoShowHide();
183 void SetRect(const wxRect& rect);
184 void AddButton(int id, int location, const wxBitmap& bmp);
185
186 protected:
187
188 virtual void Render(wxDC* dc);
189
190 private:
191
192 wxTabArt* m_art;
193 wxAuiNotebookPageArray m_pages;
194 wxAuiTabContainerButtonArray m_buttons;
195 wxRect m_rect;
196 };
197
198
199
200 class WXDLLIMPEXP_AUI wxAuiTabCtrl : public wxControl,
201 public wxAuiTabContainer
202 {
203 public:
204
205 wxAuiTabCtrl(wxWindow* parent,
206 wxWindowID id = wxID_ANY,
207 const wxPoint& pos = wxDefaultPosition,
208 const wxSize& size = wxDefaultSize,
209 long style = 0);
210
211 protected:
212
213 void OnPaint(wxPaintEvent& evt);
214 void OnEraseBackground(wxEraseEvent& evt);
215 void OnSize(wxSizeEvent& evt);
216 void OnLeftDown(wxMouseEvent& evt);
217 void OnLeftUp(wxMouseEvent& evt);
218 void OnMotion(wxMouseEvent& evt);
219 void OnLeaveWindow(wxMouseEvent& evt);
220
221 protected:
222
223 wxPoint m_click_pt;
224 int m_click_tab;
225 bool m_is_dragging;
226 wxAuiTabContainerButton* m_hover_button;
227
228 #ifndef SWIG
229 DECLARE_EVENT_TABLE()
230 #endif
231 };
232
233
234
235
236 class WXDLLIMPEXP_AUI wxAuiMultiNotebook : public wxControl
237 {
238
239 public:
240
241 wxAuiMultiNotebook();
242
243 wxAuiMultiNotebook(wxWindow* parent,
244 wxWindowID id = wxID_ANY,
245 const wxPoint& pos = wxDefaultPosition,
246 const wxSize& size = wxDefaultSize,
247 long style = 0);
248
249 virtual ~wxAuiMultiNotebook();
250
251 bool Create(wxWindow* parent,
252 wxWindowID id = wxID_ANY,
253 const wxPoint& pos = wxDefaultPosition,
254 const wxSize& size = wxDefaultSize,
255 long style = 0);
256
257 bool AddPage(wxWindow* page,
258 const wxString& caption,
259 bool select = false,
260 const wxBitmap& bitmap = wxNullBitmap);
261
262 bool InsertPage(size_t page_idx,
263 wxWindow* page,
264 const wxString& caption,
265 bool select = false,
266 const wxBitmap& bitmap = wxNullBitmap);
267
268 bool DeletePage(size_t page);
269 bool RemovePage(size_t page);
270
271 bool SetPageText(size_t page, const wxString& text);
272 size_t SetSelection(size_t new_page);
273 int GetSelection() const;
274 size_t GetPageCount() const;
275 wxWindow* GetPage(size_t page_idx) const;
276
277 void SetArtProvider(wxTabArt* art);
278 wxTabArt* GetArtProvider();
279
280 protected:
281
282 wxAuiTabCtrl* GetTabCtrlFromPoint(const wxPoint& pt);
283 wxWindow* GetTabFrameFromTabCtrl(wxWindow* tab_ctrl);
284 wxAuiTabCtrl* GetActiveTabCtrl();
285 bool FindTab(wxWindow* page, wxAuiTabCtrl** ctrl, int* idx);
286 void RemoveEmptyTabFrames();
287
288 protected:
289
290 void DoSizing();
291 void InitNotebook();
292
293 void OnChildFocus(wxChildFocusEvent& evt);
294 void OnRender(wxFrameManagerEvent& evt);
295 void OnEraseBackground(wxEraseEvent& evt);
296 void OnSize(wxSizeEvent& evt);
297 void OnTabClicked(wxCommandEvent& evt);
298 void OnTabBeginDrag(wxCommandEvent& evt);
299 void OnTabDragMotion(wxCommandEvent& evt);
300 void OnTabEndDrag(wxCommandEvent& evt);
301 void OnTabButton(wxCommandEvent& evt);
302
303 protected:
304
305 wxFrameManager m_mgr;
306 wxAuiTabContainer m_tabs;
307 int m_curpage;
308 int m_tab_id_counter;
309 wxWindow* m_dummy_wnd;
310
311 wxFont m_selected_font;
312 wxFont m_normal_font;
313 int m_tab_ctrl_height;
314
315 #ifndef SWIG
316 DECLARE_EVENT_TABLE()
317 #endif
318 };
319
320
321
322
323 // wx event machinery
324
325 #ifndef SWIG
326
327 BEGIN_DECLARE_EVENT_TYPES()
328 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 0)
329 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 0)
330 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 0)
331 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, 0)
332 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, 0)
333 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_AUI, wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, 0)
334 END_DECLARE_EVENT_TYPES()
335
336 typedef void (wxEvtHandler::*wxAuiNotebookEventFunction)(wxAuiNotebookEvent&);
337
338 #define wxAuiNotebookEventHandler(func) \
339 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxAuiNotebookEventFunction, &func)
340
341 #define EVT_AUINOTEBOOK_PAGE_CHANGED(winid, fn) \
342 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, winid, wxAuiNotebookEventHandler(fn))
343 #define EVT_AUINOTEBOOK_PAGE_CHANGING(winid, fn) \
344 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, winid, wxAuiNotebookEventHandler(fn))
345 #define EVT_AUINOTEBOOK_PAGE_BUTTON(winid, fn) \
346 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, winid, wxAuiNotebookEventHandler(fn))
347 #define EVT_AUINOTEBOOK_BEGIN_DRAG(winid, fn) \
348 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, winid, wxAuiNotebookEventHandler(fn))
349 #define EVT_AUINOTEBOOK_END_DRAG(winid, fn) \
350 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, winid, wxAuiNotebookEventHandler(fn))
351 #define EVT_AUINOTEBOOK_DRAG_MOTION(winid, fn) \
352 wx__DECLARE_EVT1(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, winid, wxAuiNotebookEventHandler(fn))
353
354 #else
355
356 // wxpython/swig event work
357 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED;
358 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING;
359 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_BUTTON;
360 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG;
361 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_END_DRAG;
362 %constant wxEventType wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION;
363
364 %pythoncode {
365 EVT_AUINOTEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, 1 )
366 EVT_AUINOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, 1 )
367 EVT_AUINOTEBOOK_BUTTON = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_BUTTON, 1 )
368 EVT_AUINOTEBOOK_BEGIN_DRAG = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, 1 )
369 EVT_AUINOTEBOOK_END_DRAG = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, 1 )
370 EVT_AUINOTEBOOK_DRAG_MOTION = wx.PyEventBinder( wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, 1 )
371 }
372 #endif
373
374
375 #endif // wxUSE_AUI
376 #endif // _WX_AUINOTEBOOK_H_