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