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