]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/aui/auibook.cpp | |
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 | // headers | |
13 | // ---------------------------------------------------------------------------- | |
14 | ||
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
21 | #if wxUSE_AUI | |
22 | ||
23 | #include "wx/aui/auibook.h" | |
24 | ||
25 | #ifndef WX_PRECOMP | |
26 | #include "wx/settings.h" | |
27 | #include "wx/image.h" | |
28 | #include "wx/menu.h" | |
29 | #endif | |
30 | ||
31 | #include "wx/aui/tabmdi.h" | |
32 | #include "wx/dcbuffer.h" | |
33 | ||
34 | #include "wx/renderer.h" | |
35 | ||
36 | #ifdef __WXMAC__ | |
37 | #include "wx/osx/private.h" | |
38 | #endif | |
39 | ||
40 | #include "wx/arrimpl.cpp" | |
41 | WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray) | |
42 | WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray) | |
43 | ||
44 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEvent); | |
45 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEvent); | |
46 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, wxAuiNotebookEvent); | |
47 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEvent); | |
48 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, wxAuiNotebookEvent); | |
49 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, wxAuiNotebookEvent); | |
50 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEvent); | |
51 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, wxAuiNotebookEvent); | |
52 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, wxAuiNotebookEvent); | |
53 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, wxAuiNotebookEvent); | |
54 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEvent); | |
55 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, wxAuiNotebookEvent); | |
56 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, wxAuiNotebookEvent); | |
57 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, wxAuiNotebookEvent); | |
58 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, wxAuiNotebookEvent); | |
59 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, wxAuiNotebookEvent); | |
60 | ||
61 | IMPLEMENT_CLASS(wxAuiNotebook, wxControl) | |
62 | IMPLEMENT_CLASS(wxAuiTabCtrl, wxControl) | |
63 | IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent, wxEvent) | |
64 | ||
65 | ||
66 | ||
67 | ||
68 | ||
69 | // these functions live in dockart.cpp -- they'll eventually | |
70 | // be moved to a new utility cpp file | |
71 | ||
72 | wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h, | |
73 | const wxColour& color); | |
74 | ||
75 | wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size); | |
76 | ||
77 | static void DrawButtons(wxDC& dc, | |
78 | const wxRect& _rect, | |
79 | const wxBitmap& bmp, | |
80 | const wxColour& bkcolour, | |
81 | int button_state) | |
82 | { | |
83 | wxRect rect = _rect; | |
84 | ||
85 | if (button_state == wxAUI_BUTTON_STATE_PRESSED) | |
86 | { | |
87 | rect.x++; | |
88 | rect.y++; | |
89 | } | |
90 | ||
91 | if (button_state == wxAUI_BUTTON_STATE_HOVER || | |
92 | button_state == wxAUI_BUTTON_STATE_PRESSED) | |
93 | { | |
94 | dc.SetBrush(wxBrush(bkcolour.ChangeLightness(120))); | |
95 | dc.SetPen(wxPen(bkcolour.ChangeLightness(75))); | |
96 | ||
97 | // draw the background behind the button | |
98 | dc.DrawRectangle(rect.x, rect.y, 15, 15); | |
99 | } | |
100 | ||
101 | // draw the button itself | |
102 | dc.DrawBitmap(bmp, rect.x, rect.y, true); | |
103 | } | |
104 | ||
105 | static void IndentPressedBitmap(wxRect* rect, int button_state) | |
106 | { | |
107 | if (button_state == wxAUI_BUTTON_STATE_PRESSED) | |
108 | { | |
109 | rect->x++; | |
110 | rect->y++; | |
111 | } | |
112 | } | |
113 | ||
114 | ||
115 | ||
116 | // -- GUI helper classes and functions -- | |
117 | ||
118 | class wxAuiCommandCapture : public wxEvtHandler | |
119 | { | |
120 | public: | |
121 | ||
122 | wxAuiCommandCapture() { m_last_id = 0; } | |
123 | int GetCommandId() const { return m_last_id; } | |
124 | ||
125 | bool ProcessEvent(wxEvent& evt) | |
126 | { | |
127 | if (evt.GetEventType() == wxEVT_COMMAND_MENU_SELECTED) | |
128 | { | |
129 | m_last_id = evt.GetId(); | |
130 | return true; | |
131 | } | |
132 | ||
133 | if (GetNextHandler()) | |
134 | return GetNextHandler()->ProcessEvent(evt); | |
135 | ||
136 | return false; | |
137 | } | |
138 | ||
139 | private: | |
140 | int m_last_id; | |
141 | }; | |
142 | ||
143 | ||
144 | // -- bitmaps -- | |
145 | ||
146 | #if defined( __WXMAC__ ) | |
147 | static const unsigned char close_bits[]={ | |
148 | 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0x03, 0xF8, 0x01, 0xF0, 0x19, 0xF3, | |
149 | 0xB8, 0xE3, 0xF0, 0xE1, 0xE0, 0xE0, 0xF0, 0xE1, 0xB8, 0xE3, 0x19, 0xF3, | |
150 | 0x01, 0xF0, 0x03, 0xF8, 0x0F, 0xFE, 0xFF, 0xFF }; | |
151 | #elif defined( __WXGTK__) | |
152 | static const unsigned char close_bits[]={ | |
153 | 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xfb, 0xef, 0xdb, 0xed, 0x8b, 0xe8, | |
154 | 0x1b, 0xec, 0x3b, 0xee, 0x1b, 0xec, 0x8b, 0xe8, 0xdb, 0xed, 0xfb, 0xef, | |
155 | 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
156 | #else | |
157 | static const unsigned char close_bits[]={ | |
158 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xf3, 0xcf, 0xf9, | |
159 | 0x9f, 0xfc, 0x3f, 0xfe, 0x3f, 0xfe, 0x9f, 0xfc, 0xcf, 0xf9, 0xe7, 0xf3, | |
160 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
161 | #endif | |
162 | ||
163 | static const unsigned char left_bits[] = { | |
164 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x3f, 0xfe, | |
165 | 0x1f, 0xfe, 0x0f, 0xfe, 0x1f, 0xfe, 0x3f, 0xfe, 0x7f, 0xfe, 0xff, 0xfe, | |
166 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
167 | ||
168 | static const unsigned char right_bits[] = { | |
169 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0x9f, 0xff, 0x1f, 0xff, | |
170 | 0x1f, 0xfe, 0x1f, 0xfc, 0x1f, 0xfe, 0x1f, 0xff, 0x9f, 0xff, 0xdf, 0xff, | |
171 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
172 | ||
173 | static const unsigned char list_bits[] = { | |
174 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | |
175 | 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff, | |
176 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
177 | ||
178 | ||
179 | ||
180 | ||
181 | ||
182 | ||
183 | // -- wxAuiDefaultTabArt class implementation -- | |
184 | ||
185 | wxAuiDefaultTabArt::wxAuiDefaultTabArt() | |
186 | { | |
187 | m_normal_font = *wxNORMAL_FONT; | |
188 | m_selected_font = *wxNORMAL_FONT; | |
189 | m_selected_font.SetWeight(wxBOLD); | |
190 | m_measuring_font = m_selected_font; | |
191 | ||
192 | m_fixed_tab_width = 100; | |
193 | m_tab_ctrl_height = 0; | |
194 | ||
195 | #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON | |
196 | wxColor base_colour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground)); | |
197 | #else | |
198 | wxColor base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); | |
199 | #endif | |
200 | ||
201 | // the base_colour is too pale to use as our base colour, | |
202 | // so darken it a bit -- | |
203 | if ((255-base_colour.Red()) + | |
204 | (255-base_colour.Green()) + | |
205 | (255-base_colour.Blue()) < 60) | |
206 | { | |
207 | base_colour = base_colour.ChangeLightness(92); | |
208 | } | |
209 | ||
210 | m_active_colour = base_colour; | |
211 | m_base_colour = base_colour; | |
212 | wxColor border_colour = base_colour.ChangeLightness(75); | |
213 | ||
214 | m_border_pen = wxPen(border_colour); | |
215 | m_base_colour_pen = wxPen(m_base_colour); | |
216 | m_base_colour_brush = wxBrush(m_base_colour); | |
217 | ||
218 | m_active_close_bmp = wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK); | |
219 | m_disabled_close_bmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128)); | |
220 | ||
221 | m_active_left_bmp = wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK); | |
222 | m_disabled_left_bmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128)); | |
223 | ||
224 | m_active_right_bmp = wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK); | |
225 | m_disabled_right_bmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128)); | |
226 | ||
227 | m_active_windowlist_bmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK); | |
228 | m_disabled_windowlist_bmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128)); | |
229 | ||
230 | m_flags = 0; | |
231 | } | |
232 | ||
233 | wxAuiDefaultTabArt::~wxAuiDefaultTabArt() | |
234 | { | |
235 | } | |
236 | ||
237 | wxAuiTabArt* wxAuiDefaultTabArt::Clone() | |
238 | { | |
239 | return new wxAuiDefaultTabArt(*this); | |
240 | } | |
241 | ||
242 | void wxAuiDefaultTabArt::SetFlags(unsigned int flags) | |
243 | { | |
244 | m_flags = flags; | |
245 | } | |
246 | ||
247 | void wxAuiDefaultTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, | |
248 | size_t tab_count) | |
249 | { | |
250 | m_fixed_tab_width = 100; | |
251 | ||
252 | int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - 4; | |
253 | ||
254 | if (m_flags & wxAUI_NB_CLOSE_BUTTON) | |
255 | tot_width -= m_active_close_bmp.GetWidth(); | |
256 | if (m_flags & wxAUI_NB_WINDOWLIST_BUTTON) | |
257 | tot_width -= m_active_windowlist_bmp.GetWidth(); | |
258 | ||
259 | if (tab_count > 0) | |
260 | { | |
261 | m_fixed_tab_width = tot_width/(int)tab_count; | |
262 | } | |
263 | ||
264 | ||
265 | if (m_fixed_tab_width < 100) | |
266 | m_fixed_tab_width = 100; | |
267 | ||
268 | if (m_fixed_tab_width > tot_width/2) | |
269 | m_fixed_tab_width = tot_width/2; | |
270 | ||
271 | if (m_fixed_tab_width > 220) | |
272 | m_fixed_tab_width = 220; | |
273 | ||
274 | m_tab_ctrl_height = tab_ctrl_size.y; | |
275 | } | |
276 | ||
277 | ||
278 | void wxAuiDefaultTabArt::DrawBackground(wxDC& dc, | |
279 | wxWindow* WXUNUSED(wnd), | |
280 | const wxRect& rect) | |
281 | { | |
282 | // draw background | |
283 | ||
284 | wxColor top_color = m_base_colour.ChangeLightness(90); | |
285 | wxColor bottom_color = m_base_colour.ChangeLightness(170); | |
286 | wxRect r; | |
287 | ||
288 | if (m_flags &wxAUI_NB_BOTTOM) | |
289 | r = wxRect(rect.x, rect.y, rect.width+2, rect.height); | |
290 | // TODO: else if (m_flags &wxAUI_NB_LEFT) {} | |
291 | // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} | |
292 | else //for wxAUI_NB_TOP | |
293 | r = wxRect(rect.x, rect.y, rect.width+2, rect.height-3); | |
294 | ||
295 | dc.GradientFillLinear(r, top_color, bottom_color, wxSOUTH); | |
296 | ||
297 | ||
298 | // draw base lines | |
299 | ||
300 | dc.SetPen(m_border_pen); | |
301 | int y = rect.GetHeight(); | |
302 | int w = rect.GetWidth(); | |
303 | ||
304 | if (m_flags &wxAUI_NB_BOTTOM) | |
305 | { | |
306 | dc.SetBrush(wxBrush(bottom_color)); | |
307 | dc.DrawRectangle(-1, 0, w+2, 4); | |
308 | } | |
309 | // TODO: else if (m_flags &wxAUI_NB_LEFT) {} | |
310 | // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} | |
311 | else //for wxAUI_NB_TOP | |
312 | { | |
313 | dc.SetBrush(m_base_colour_brush); | |
314 | dc.DrawRectangle(-1, y-4, w+2, 4); | |
315 | } | |
316 | } | |
317 | ||
318 | ||
319 | // DrawTab() draws an individual tab. | |
320 | // | |
321 | // dc - output dc | |
322 | // in_rect - rectangle the tab should be confined to | |
323 | // caption - tab's caption | |
324 | // active - whether or not the tab is active | |
325 | // out_rect - actual output rectangle | |
326 | // x_extent - the advance x; where the next tab should start | |
327 | ||
328 | void wxAuiDefaultTabArt::DrawTab(wxDC& dc, | |
329 | wxWindow* wnd, | |
330 | const wxAuiNotebookPage& page, | |
331 | const wxRect& in_rect, | |
332 | int close_button_state, | |
333 | wxRect* out_tab_rect, | |
334 | wxRect* out_button_rect, | |
335 | int* x_extent) | |
336 | { | |
337 | wxCoord normal_textx, normal_texty; | |
338 | wxCoord selected_textx, selected_texty; | |
339 | wxCoord texty; | |
340 | ||
341 | // if the caption is empty, measure some temporary text | |
342 | wxString caption = page.caption; | |
343 | if (caption.empty()) | |
344 | caption = wxT("Xj"); | |
345 | ||
346 | dc.SetFont(m_selected_font); | |
347 | dc.GetTextExtent(caption, &selected_textx, &selected_texty); | |
348 | ||
349 | dc.SetFont(m_normal_font); | |
350 | dc.GetTextExtent(caption, &normal_textx, &normal_texty); | |
351 | ||
352 | // figure out the size of the tab | |
353 | wxSize tab_size = GetTabSize(dc, | |
354 | wnd, | |
355 | page.caption, | |
356 | page.bitmap, | |
357 | page.active, | |
358 | close_button_state, | |
359 | x_extent); | |
360 | ||
361 | wxCoord tab_height = m_tab_ctrl_height - 3; | |
362 | wxCoord tab_width = tab_size.x; | |
363 | wxCoord tab_x = in_rect.x; | |
364 | wxCoord tab_y = in_rect.y + in_rect.height - tab_height; | |
365 | ||
366 | ||
367 | caption = page.caption; | |
368 | ||
369 | ||
370 | // select pen, brush and font for the tab to be drawn | |
371 | ||
372 | if (page.active) | |
373 | { | |
374 | dc.SetFont(m_selected_font); | |
375 | texty = selected_texty; | |
376 | } | |
377 | else | |
378 | { | |
379 | dc.SetFont(m_normal_font); | |
380 | texty = normal_texty; | |
381 | } | |
382 | ||
383 | ||
384 | // create points that will make the tab outline | |
385 | ||
386 | int clip_width = tab_width; | |
387 | if (tab_x + clip_width > in_rect.x + in_rect.width) | |
388 | clip_width = (in_rect.x + in_rect.width) - tab_x; | |
389 | ||
390 | /* | |
391 | wxPoint clip_points[6]; | |
392 | clip_points[0] = wxPoint(tab_x, tab_y+tab_height-3); | |
393 | clip_points[1] = wxPoint(tab_x, tab_y+2); | |
394 | clip_points[2] = wxPoint(tab_x+2, tab_y); | |
395 | clip_points[3] = wxPoint(tab_x+clip_width-1, tab_y); | |
396 | clip_points[4] = wxPoint(tab_x+clip_width+1, tab_y+2); | |
397 | clip_points[5] = wxPoint(tab_x+clip_width+1, tab_y+tab_height-3); | |
398 | ||
399 | // FIXME: these ports don't provide wxRegion ctor from array of points | |
400 | #if !defined(__WXDFB__) && !defined(__WXCOCOA__) | |
401 | // set the clipping region for the tab -- | |
402 | wxRegion clipping_region(WXSIZEOF(clip_points), clip_points); | |
403 | dc.SetClippingRegion(clipping_region); | |
404 | #endif // !wxDFB && !wxCocoa | |
405 | */ | |
406 | // since the above code above doesn't play well with WXDFB or WXCOCOA, | |
407 | // we'll just use a rectangle for the clipping region for now -- | |
408 | dc.SetClippingRegion(tab_x, tab_y, clip_width+1, tab_height-3); | |
409 | ||
410 | ||
411 | wxPoint border_points[6]; | |
412 | if (m_flags &wxAUI_NB_BOTTOM) | |
413 | { | |
414 | border_points[0] = wxPoint(tab_x, tab_y); | |
415 | border_points[1] = wxPoint(tab_x, tab_y+tab_height-6); | |
416 | border_points[2] = wxPoint(tab_x+2, tab_y+tab_height-4); | |
417 | border_points[3] = wxPoint(tab_x+tab_width-2, tab_y+tab_height-4); | |
418 | border_points[4] = wxPoint(tab_x+tab_width, tab_y+tab_height-6); | |
419 | border_points[5] = wxPoint(tab_x+tab_width, tab_y); | |
420 | } | |
421 | else //if (m_flags & wxAUI_NB_TOP) {} | |
422 | { | |
423 | border_points[0] = wxPoint(tab_x, tab_y+tab_height-4); | |
424 | border_points[1] = wxPoint(tab_x, tab_y+2); | |
425 | border_points[2] = wxPoint(tab_x+2, tab_y); | |
426 | border_points[3] = wxPoint(tab_x+tab_width-2, tab_y); | |
427 | border_points[4] = wxPoint(tab_x+tab_width, tab_y+2); | |
428 | border_points[5] = wxPoint(tab_x+tab_width, tab_y+tab_height-4); | |
429 | } | |
430 | // TODO: else if (m_flags &wxAUI_NB_LEFT) {} | |
431 | // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} | |
432 | ||
433 | int drawn_tab_yoff = border_points[1].y; | |
434 | int drawn_tab_height = border_points[0].y - border_points[1].y; | |
435 | ||
436 | ||
437 | if (page.active) | |
438 | { | |
439 | // draw active tab | |
440 | ||
441 | // draw base background color | |
442 | wxRect r(tab_x, tab_y, tab_width, tab_height); | |
443 | dc.SetPen(wxPen(m_active_colour)); | |
444 | dc.SetBrush(wxBrush(m_active_colour)); | |
445 | dc.DrawRectangle(r.x+1, r.y+1, r.width-1, r.height-4); | |
446 | ||
447 | // this white helps fill out the gradient at the top of the tab | |
448 | dc.SetPen(*wxWHITE_PEN); | |
449 | dc.SetBrush(*wxWHITE_BRUSH); | |
450 | dc.DrawRectangle(r.x+2, r.y+1, r.width-3, r.height-4); | |
451 | ||
452 | // these two points help the rounded corners appear more antialiased | |
453 | dc.SetPen(wxPen(m_active_colour)); | |
454 | dc.DrawPoint(r.x+2, r.y+1); | |
455 | dc.DrawPoint(r.x+r.width-2, r.y+1); | |
456 | ||
457 | // set rectangle down a bit for gradient drawing | |
458 | r.SetHeight(r.GetHeight()/2); | |
459 | r.x += 2; | |
460 | r.width -= 3; | |
461 | r.y += r.height; | |
462 | r.y -= 2; | |
463 | ||
464 | // draw gradient background | |
465 | wxColor top_color = *wxWHITE; | |
466 | wxColor bottom_color = m_active_colour; | |
467 | dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH); | |
468 | } | |
469 | else | |
470 | { | |
471 | // draw inactive tab | |
472 | ||
473 | wxRect r(tab_x, tab_y+1, tab_width, tab_height-3); | |
474 | ||
475 | // start the gradent up a bit and leave the inside border inset | |
476 | // by a pixel for a 3D look. Only the top half of the inactive | |
477 | // tab will have a slight gradient | |
478 | r.x += 3; | |
479 | r.y++; | |
480 | r.width -= 4; | |
481 | r.height /= 2; | |
482 | r.height--; | |
483 | ||
484 | // -- draw top gradient fill for glossy look | |
485 | wxColor top_color = m_base_colour; | |
486 | wxColor bottom_color = top_color.ChangeLightness(160); | |
487 | dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH); | |
488 | ||
489 | r.y += r.height; | |
490 | r.y--; | |
491 | ||
492 | // -- draw bottom fill for glossy look | |
493 | top_color = m_base_colour; | |
494 | bottom_color = m_base_colour; | |
495 | dc.GradientFillLinear(r, top_color, bottom_color, wxSOUTH); | |
496 | } | |
497 | ||
498 | // draw tab outline | |
499 | dc.SetPen(m_border_pen); | |
500 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
501 | dc.DrawPolygon(WXSIZEOF(border_points), border_points); | |
502 | ||
503 | // there are two horizontal grey lines at the bottom of the tab control, | |
504 | // this gets rid of the top one of those lines in the tab control | |
505 | if (page.active) | |
506 | { | |
507 | if (m_flags &wxAUI_NB_BOTTOM) | |
508 | dc.SetPen(wxPen(m_base_colour.ChangeLightness(170))); | |
509 | // TODO: else if (m_flags &wxAUI_NB_LEFT) {} | |
510 | // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} | |
511 | else //for wxAUI_NB_TOP | |
512 | dc.SetPen(m_base_colour_pen); | |
513 | dc.DrawLine(border_points[0].x+1, | |
514 | border_points[0].y, | |
515 | border_points[5].x, | |
516 | border_points[5].y); | |
517 | } | |
518 | ||
519 | ||
520 | int text_offset = tab_x + 8; | |
521 | int close_button_width = 0; | |
522 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) | |
523 | { | |
524 | close_button_width = m_active_close_bmp.GetWidth(); | |
525 | } | |
526 | ||
527 | int bitmap_offset = 0; | |
528 | if (page.bitmap.IsOk()) | |
529 | { | |
530 | bitmap_offset = tab_x + 8; | |
531 | ||
532 | // draw bitmap | |
533 | dc.DrawBitmap(page.bitmap, | |
534 | bitmap_offset, | |
535 | drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), | |
536 | true); | |
537 | ||
538 | text_offset = bitmap_offset + page.bitmap.GetWidth(); | |
539 | text_offset += 3; // bitmap padding | |
540 | ||
541 | } | |
542 | else | |
543 | { | |
544 | text_offset = tab_x + 8; | |
545 | } | |
546 | ||
547 | ||
548 | wxString draw_text = wxAuiChopText(dc, | |
549 | caption, | |
550 | tab_width - (text_offset-tab_x) - close_button_width); | |
551 | ||
552 | // draw tab text | |
553 | dc.DrawText(draw_text, | |
554 | text_offset, | |
555 | drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1); | |
556 | ||
557 | // draw focus rectangle | |
558 | if (page.active && (wnd->FindFocus() == wnd)) | |
559 | { | |
560 | wxRect focusRectText(text_offset, (drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1), | |
561 | selected_textx, selected_texty); | |
562 | ||
563 | wxRect focusRect; | |
564 | wxRect focusRectBitmap; | |
565 | ||
566 | if (page.bitmap.IsOk()) | |
567 | focusRectBitmap = wxRect(bitmap_offset, drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), | |
568 | page.bitmap.GetWidth(), page.bitmap.GetHeight()); | |
569 | ||
570 | if (page.bitmap.IsOk() && draw_text.IsEmpty()) | |
571 | focusRect = focusRectBitmap; | |
572 | else if (!page.bitmap.IsOk() && !draw_text.IsEmpty()) | |
573 | focusRect = focusRectText; | |
574 | else if (page.bitmap.IsOk() && !draw_text.IsEmpty()) | |
575 | focusRect = focusRectText.Union(focusRectBitmap); | |
576 | ||
577 | focusRect.Inflate(2, 2); | |
578 | ||
579 | wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); | |
580 | } | |
581 | ||
582 | // draw close button if necessary | |
583 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) | |
584 | { | |
585 | wxBitmap bmp = m_disabled_close_bmp; | |
586 | ||
587 | if (close_button_state == wxAUI_BUTTON_STATE_HOVER || | |
588 | close_button_state == wxAUI_BUTTON_STATE_PRESSED) | |
589 | { | |
590 | bmp = m_active_close_bmp; | |
591 | } | |
592 | ||
593 | int offsetY = tab_y-1; | |
594 | if (m_flags & wxAUI_NB_BOTTOM) | |
595 | offsetY = 1; | |
596 | ||
597 | wxRect rect(tab_x + tab_width - close_button_width - 1, | |
598 | offsetY + (tab_height/2) - (bmp.GetHeight()/2), | |
599 | close_button_width, | |
600 | tab_height); | |
601 | ||
602 | IndentPressedBitmap(&rect, close_button_state); | |
603 | dc.DrawBitmap(bmp, rect.x, rect.y, true); | |
604 | ||
605 | *out_button_rect = rect; | |
606 | } | |
607 | ||
608 | *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); | |
609 | ||
610 | dc.DestroyClippingRegion(); | |
611 | } | |
612 | ||
613 | int wxAuiDefaultTabArt::GetIndentSize() | |
614 | { | |
615 | return 5; | |
616 | } | |
617 | ||
618 | wxSize wxAuiDefaultTabArt::GetTabSize(wxDC& dc, | |
619 | wxWindow* WXUNUSED(wnd), | |
620 | const wxString& caption, | |
621 | const wxBitmap& bitmap, | |
622 | bool WXUNUSED(active), | |
623 | int close_button_state, | |
624 | int* x_extent) | |
625 | { | |
626 | wxCoord measured_textx, measured_texty, tmp; | |
627 | ||
628 | dc.SetFont(m_measuring_font); | |
629 | dc.GetTextExtent(caption, &measured_textx, &measured_texty); | |
630 | ||
631 | dc.GetTextExtent(wxT("ABCDEFXj"), &tmp, &measured_texty); | |
632 | ||
633 | // add padding around the text | |
634 | wxCoord tab_width = measured_textx; | |
635 | wxCoord tab_height = measured_texty; | |
636 | ||
637 | // if the close button is showing, add space for it | |
638 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) | |
639 | tab_width += m_active_close_bmp.GetWidth() + 3; | |
640 | ||
641 | // if there's a bitmap, add space for it | |
642 | if (bitmap.IsOk()) | |
643 | { | |
644 | tab_width += bitmap.GetWidth(); | |
645 | tab_width += 3; // right side bitmap padding | |
646 | tab_height = wxMax(tab_height, bitmap.GetHeight()); | |
647 | } | |
648 | ||
649 | // add padding | |
650 | tab_width += 16; | |
651 | tab_height += 10; | |
652 | ||
653 | if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH) | |
654 | { | |
655 | tab_width = m_fixed_tab_width; | |
656 | } | |
657 | ||
658 | *x_extent = tab_width; | |
659 | ||
660 | return wxSize(tab_width, tab_height); | |
661 | } | |
662 | ||
663 | ||
664 | void wxAuiDefaultTabArt::DrawButton(wxDC& dc, | |
665 | wxWindow* WXUNUSED(wnd), | |
666 | const wxRect& in_rect, | |
667 | int bitmap_id, | |
668 | int button_state, | |
669 | int orientation, | |
670 | wxRect* out_rect) | |
671 | { | |
672 | wxBitmap bmp; | |
673 | wxRect rect; | |
674 | ||
675 | switch (bitmap_id) | |
676 | { | |
677 | case wxAUI_BUTTON_CLOSE: | |
678 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
679 | bmp = m_disabled_close_bmp; | |
680 | else | |
681 | bmp = m_active_close_bmp; | |
682 | break; | |
683 | case wxAUI_BUTTON_LEFT: | |
684 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
685 | bmp = m_disabled_left_bmp; | |
686 | else | |
687 | bmp = m_active_left_bmp; | |
688 | break; | |
689 | case wxAUI_BUTTON_RIGHT: | |
690 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
691 | bmp = m_disabled_right_bmp; | |
692 | else | |
693 | bmp = m_active_right_bmp; | |
694 | break; | |
695 | case wxAUI_BUTTON_WINDOWLIST: | |
696 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
697 | bmp = m_disabled_windowlist_bmp; | |
698 | else | |
699 | bmp = m_active_windowlist_bmp; | |
700 | break; | |
701 | } | |
702 | ||
703 | ||
704 | if (!bmp.IsOk()) | |
705 | return; | |
706 | ||
707 | rect = in_rect; | |
708 | ||
709 | if (orientation == wxLEFT) | |
710 | { | |
711 | rect.SetX(in_rect.x); | |
712 | rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2)); | |
713 | rect.SetWidth(bmp.GetWidth()); | |
714 | rect.SetHeight(bmp.GetHeight()); | |
715 | } | |
716 | else | |
717 | { | |
718 | rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(), | |
719 | ((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2), | |
720 | bmp.GetWidth(), bmp.GetHeight()); | |
721 | } | |
722 | ||
723 | IndentPressedBitmap(&rect, button_state); | |
724 | dc.DrawBitmap(bmp, rect.x, rect.y, true); | |
725 | ||
726 | *out_rect = rect; | |
727 | } | |
728 | ||
729 | int wxAuiDefaultTabArt::ShowDropDown(wxWindow* wnd, | |
730 | const wxAuiNotebookPageArray& pages, | |
731 | int /*active_idx*/) | |
732 | { | |
733 | wxMenu menuPopup; | |
734 | ||
735 | size_t i, count = pages.GetCount(); | |
736 | for (i = 0; i < count; ++i) | |
737 | { | |
738 | const wxAuiNotebookPage& page = pages.Item(i); | |
739 | wxString caption = page.caption; | |
740 | ||
741 | // if there is no caption, make it a space. This will prevent | |
742 | // an assert in the menu code. | |
743 | if (caption.IsEmpty()) | |
744 | caption = wxT(" "); | |
745 | ||
746 | wxMenuItem* item = new wxMenuItem(NULL, 1000+i, caption); | |
747 | if (page.bitmap.IsOk()) | |
748 | item->SetBitmap(page.bitmap); | |
749 | menuPopup.Append(item); | |
750 | } | |
751 | ||
752 | // find out where to put the popup menu of window items | |
753 | wxPoint pt = ::wxGetMousePosition(); | |
754 | pt = wnd->ScreenToClient(pt); | |
755 | ||
756 | // find out the screen coordinate at the bottom of the tab ctrl | |
757 | wxRect cli_rect = wnd->GetClientRect(); | |
758 | pt.y = cli_rect.y + cli_rect.height; | |
759 | ||
760 | wxAuiCommandCapture* cc = new wxAuiCommandCapture; | |
761 | wnd->PushEventHandler(cc); | |
762 | wnd->PopupMenu(&menuPopup, pt); | |
763 | int command = cc->GetCommandId(); | |
764 | wnd->PopEventHandler(true); | |
765 | ||
766 | if (command >= 1000) | |
767 | return command-1000; | |
768 | ||
769 | return -1; | |
770 | } | |
771 | ||
772 | int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow* wnd, | |
773 | const wxAuiNotebookPageArray& pages, | |
774 | const wxSize& required_bmp_size) | |
775 | { | |
776 | wxClientDC dc(wnd); | |
777 | dc.SetFont(m_measuring_font); | |
778 | ||
779 | // sometimes a standard bitmap size needs to be enforced, especially | |
780 | // if some tabs have bitmaps and others don't. This is important because | |
781 | // it prevents the tab control from resizing when tabs are added. | |
782 | wxBitmap measure_bmp; | |
783 | if (required_bmp_size.IsFullySpecified()) | |
784 | { | |
785 | measure_bmp.Create(required_bmp_size.x, | |
786 | required_bmp_size.y); | |
787 | } | |
788 | ||
789 | ||
790 | int max_y = 0; | |
791 | size_t i, page_count = pages.GetCount(); | |
792 | for (i = 0; i < page_count; ++i) | |
793 | { | |
794 | wxAuiNotebookPage& page = pages.Item(i); | |
795 | ||
796 | wxBitmap bmp; | |
797 | if (measure_bmp.IsOk()) | |
798 | bmp = measure_bmp; | |
799 | else | |
800 | bmp = page.bitmap; | |
801 | ||
802 | // we don't use the caption text because we don't | |
803 | // want tab heights to be different in the case | |
804 | // of a very short piece of text on one tab and a very | |
805 | // tall piece of text on another tab | |
806 | int x_ext = 0; | |
807 | wxSize s = GetTabSize(dc, | |
808 | wnd, | |
809 | wxT("ABCDEFGHIj"), | |
810 | bmp, | |
811 | true, | |
812 | wxAUI_BUTTON_STATE_HIDDEN, | |
813 | &x_ext); | |
814 | ||
815 | max_y = wxMax(max_y, s.y); | |
816 | } | |
817 | ||
818 | return max_y+2; | |
819 | } | |
820 | ||
821 | void wxAuiDefaultTabArt::SetNormalFont(const wxFont& font) | |
822 | { | |
823 | m_normal_font = font; | |
824 | } | |
825 | ||
826 | void wxAuiDefaultTabArt::SetSelectedFont(const wxFont& font) | |
827 | { | |
828 | m_selected_font = font; | |
829 | } | |
830 | ||
831 | void wxAuiDefaultTabArt::SetMeasuringFont(const wxFont& font) | |
832 | { | |
833 | m_measuring_font = font; | |
834 | } | |
835 | ||
836 | void wxAuiDefaultTabArt::SetColour(const wxColour& colour) | |
837 | { | |
838 | m_base_colour = colour; | |
839 | m_border_pen = wxPen(m_base_colour.ChangeLightness(75)); | |
840 | m_base_colour_pen = wxPen(m_base_colour); | |
841 | m_base_colour_brush = wxBrush(m_base_colour); | |
842 | } | |
843 | ||
844 | void wxAuiDefaultTabArt::SetActiveColour(const wxColour& colour) | |
845 | { | |
846 | m_active_colour = colour; | |
847 | } | |
848 | ||
849 | // -- wxAuiSimpleTabArt class implementation -- | |
850 | ||
851 | wxAuiSimpleTabArt::wxAuiSimpleTabArt() | |
852 | { | |
853 | m_normal_font = *wxNORMAL_FONT; | |
854 | m_selected_font = *wxNORMAL_FONT; | |
855 | m_selected_font.SetWeight(wxBOLD); | |
856 | m_measuring_font = m_selected_font; | |
857 | ||
858 | m_flags = 0; | |
859 | m_fixed_tab_width = 100; | |
860 | ||
861 | wxColour base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); | |
862 | ||
863 | wxColour background_colour = base_colour; | |
864 | wxColour normaltab_colour = base_colour; | |
865 | wxColour selectedtab_colour = *wxWHITE; | |
866 | ||
867 | m_bkbrush = wxBrush(background_colour); | |
868 | m_normal_bkbrush = wxBrush(normaltab_colour); | |
869 | m_normal_bkpen = wxPen(normaltab_colour); | |
870 | m_selected_bkbrush = wxBrush(selectedtab_colour); | |
871 | m_selected_bkpen = wxPen(selectedtab_colour); | |
872 | ||
873 | m_active_close_bmp = wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK); | |
874 | m_disabled_close_bmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128)); | |
875 | ||
876 | m_active_left_bmp = wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK); | |
877 | m_disabled_left_bmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128)); | |
878 | ||
879 | m_active_right_bmp = wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK); | |
880 | m_disabled_right_bmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128)); | |
881 | ||
882 | m_active_windowlist_bmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK); | |
883 | m_disabled_windowlist_bmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128)); | |
884 | ||
885 | } | |
886 | ||
887 | wxAuiSimpleTabArt::~wxAuiSimpleTabArt() | |
888 | { | |
889 | } | |
890 | ||
891 | wxAuiTabArt* wxAuiSimpleTabArt::Clone() | |
892 | { | |
893 | return new wxAuiSimpleTabArt(*this); | |
894 | } | |
895 | ||
896 | void wxAuiSimpleTabArt::SetFlags(unsigned int flags) | |
897 | { | |
898 | m_flags = flags; | |
899 | } | |
900 | ||
901 | void wxAuiSimpleTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, | |
902 | size_t tab_count) | |
903 | { | |
904 | m_fixed_tab_width = 100; | |
905 | ||
906 | int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - 4; | |
907 | ||
908 | if (m_flags & wxAUI_NB_CLOSE_BUTTON) | |
909 | tot_width -= m_active_close_bmp.GetWidth(); | |
910 | if (m_flags & wxAUI_NB_WINDOWLIST_BUTTON) | |
911 | tot_width -= m_active_windowlist_bmp.GetWidth(); | |
912 | ||
913 | if (tab_count > 0) | |
914 | { | |
915 | m_fixed_tab_width = tot_width/(int)tab_count; | |
916 | } | |
917 | ||
918 | ||
919 | if (m_fixed_tab_width < 100) | |
920 | m_fixed_tab_width = 100; | |
921 | ||
922 | if (m_fixed_tab_width > tot_width/2) | |
923 | m_fixed_tab_width = tot_width/2; | |
924 | ||
925 | if (m_fixed_tab_width > 220) | |
926 | m_fixed_tab_width = 220; | |
927 | } | |
928 | ||
929 | void wxAuiSimpleTabArt::SetColour(const wxColour& colour) | |
930 | { | |
931 | m_bkbrush = wxBrush(colour); | |
932 | m_normal_bkbrush = wxBrush(colour); | |
933 | m_normal_bkpen = wxPen(colour); | |
934 | } | |
935 | ||
936 | void wxAuiSimpleTabArt::SetActiveColour(const wxColour& colour) | |
937 | { | |
938 | m_selected_bkbrush = wxBrush(colour); | |
939 | m_selected_bkpen = wxPen(colour); | |
940 | } | |
941 | ||
942 | void wxAuiSimpleTabArt::DrawBackground(wxDC& dc, | |
943 | wxWindow* WXUNUSED(wnd), | |
944 | const wxRect& rect) | |
945 | { | |
946 | // draw background | |
947 | dc.SetBrush(m_bkbrush); | |
948 | dc.SetPen(*wxTRANSPARENT_PEN); | |
949 | dc.DrawRectangle(-1, -1, rect.GetWidth()+2, rect.GetHeight()+2); | |
950 | ||
951 | // draw base line | |
952 | dc.SetPen(*wxGREY_PEN); | |
953 | dc.DrawLine(0, rect.GetHeight()-1, rect.GetWidth(), rect.GetHeight()-1); | |
954 | } | |
955 | ||
956 | ||
957 | // DrawTab() draws an individual tab. | |
958 | // | |
959 | // dc - output dc | |
960 | // in_rect - rectangle the tab should be confined to | |
961 | // caption - tab's caption | |
962 | // active - whether or not the tab is active | |
963 | // out_rect - actual output rectangle | |
964 | // x_extent - the advance x; where the next tab should start | |
965 | ||
966 | void wxAuiSimpleTabArt::DrawTab(wxDC& dc, | |
967 | wxWindow* wnd, | |
968 | const wxAuiNotebookPage& page, | |
969 | const wxRect& in_rect, | |
970 | int close_button_state, | |
971 | wxRect* out_tab_rect, | |
972 | wxRect* out_button_rect, | |
973 | int* x_extent) | |
974 | { | |
975 | wxCoord normal_textx, normal_texty; | |
976 | wxCoord selected_textx, selected_texty; | |
977 | wxCoord textx, texty; | |
978 | ||
979 | // if the caption is empty, measure some temporary text | |
980 | wxString caption = page.caption; | |
981 | if (caption.empty()) | |
982 | caption = wxT("Xj"); | |
983 | ||
984 | dc.SetFont(m_selected_font); | |
985 | dc.GetTextExtent(caption, &selected_textx, &selected_texty); | |
986 | ||
987 | dc.SetFont(m_normal_font); | |
988 | dc.GetTextExtent(caption, &normal_textx, &normal_texty); | |
989 | ||
990 | // figure out the size of the tab | |
991 | wxSize tab_size = GetTabSize(dc, | |
992 | wnd, | |
993 | page.caption, | |
994 | page.bitmap, | |
995 | page.active, | |
996 | close_button_state, | |
997 | x_extent); | |
998 | ||
999 | wxCoord tab_height = tab_size.y; | |
1000 | wxCoord tab_width = tab_size.x; | |
1001 | wxCoord tab_x = in_rect.x; | |
1002 | wxCoord tab_y = in_rect.y + in_rect.height - tab_height; | |
1003 | ||
1004 | caption = page.caption; | |
1005 | ||
1006 | // select pen, brush and font for the tab to be drawn | |
1007 | ||
1008 | if (page.active) | |
1009 | { | |
1010 | dc.SetPen(m_selected_bkpen); | |
1011 | dc.SetBrush(m_selected_bkbrush); | |
1012 | dc.SetFont(m_selected_font); | |
1013 | textx = selected_textx; | |
1014 | texty = selected_texty; | |
1015 | } | |
1016 | else | |
1017 | { | |
1018 | dc.SetPen(m_normal_bkpen); | |
1019 | dc.SetBrush(m_normal_bkbrush); | |
1020 | dc.SetFont(m_normal_font); | |
1021 | textx = normal_textx; | |
1022 | texty = normal_texty; | |
1023 | } | |
1024 | ||
1025 | ||
1026 | // -- draw line -- | |
1027 | ||
1028 | wxPoint points[7]; | |
1029 | points[0].x = tab_x; | |
1030 | points[0].y = tab_y + tab_height - 1; | |
1031 | points[1].x = tab_x + tab_height - 3; | |
1032 | points[1].y = tab_y + 2; | |
1033 | points[2].x = tab_x + tab_height + 3; | |
1034 | points[2].y = tab_y; | |
1035 | points[3].x = tab_x + tab_width - 2; | |
1036 | points[3].y = tab_y; | |
1037 | points[4].x = tab_x + tab_width; | |
1038 | points[4].y = tab_y + 2; | |
1039 | points[5].x = tab_x + tab_width; | |
1040 | points[5].y = tab_y + tab_height - 1; | |
1041 | points[6] = points[0]; | |
1042 | ||
1043 | dc.SetClippingRegion(in_rect); | |
1044 | ||
1045 | dc.DrawPolygon(WXSIZEOF(points) - 1, points); | |
1046 | ||
1047 | dc.SetPen(*wxGREY_PEN); | |
1048 | ||
1049 | //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points); | |
1050 | dc.DrawLines(WXSIZEOF(points), points); | |
1051 | ||
1052 | ||
1053 | int text_offset; | |
1054 | ||
1055 | int close_button_width = 0; | |
1056 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) | |
1057 | { | |
1058 | close_button_width = m_active_close_bmp.GetWidth(); | |
1059 | text_offset = tab_x + (tab_height/2) + ((tab_width-close_button_width)/2) - (textx/2); | |
1060 | } | |
1061 | else | |
1062 | { | |
1063 | text_offset = tab_x + (tab_height/3) + (tab_width/2) - (textx/2); | |
1064 | } | |
1065 | ||
1066 | // set minimum text offset | |
1067 | if (text_offset < tab_x + tab_height) | |
1068 | text_offset = tab_x + tab_height; | |
1069 | ||
1070 | // chop text if necessary | |
1071 | wxString draw_text = wxAuiChopText(dc, | |
1072 | caption, | |
1073 | tab_width - (text_offset-tab_x) - close_button_width); | |
1074 | ||
1075 | // draw tab text | |
1076 | dc.DrawText(draw_text, | |
1077 | text_offset, | |
1078 | (tab_y + tab_height)/2 - (texty/2) + 1); | |
1079 | ||
1080 | ||
1081 | // draw focus rectangle | |
1082 | if (page.active && (wnd->FindFocus() == wnd)) | |
1083 | { | |
1084 | wxRect focusRect(text_offset, ((tab_y + tab_height)/2 - (texty/2) + 1), | |
1085 | selected_textx, selected_texty); | |
1086 | ||
1087 | focusRect.Inflate(2, 2); | |
1088 | ||
1089 | wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); | |
1090 | } | |
1091 | ||
1092 | // draw close button if necessary | |
1093 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) | |
1094 | { | |
1095 | wxBitmap bmp; | |
1096 | if (page.active) | |
1097 | bmp = m_active_close_bmp; | |
1098 | else | |
1099 | bmp = m_disabled_close_bmp; | |
1100 | ||
1101 | wxRect rect(tab_x + tab_width - close_button_width - 1, | |
1102 | tab_y + (tab_height/2) - (bmp.GetHeight()/2) + 1, | |
1103 | close_button_width, | |
1104 | tab_height - 1); | |
1105 | DrawButtons(dc, rect, bmp, *wxWHITE, close_button_state); | |
1106 | ||
1107 | *out_button_rect = rect; | |
1108 | } | |
1109 | ||
1110 | ||
1111 | *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); | |
1112 | ||
1113 | dc.DestroyClippingRegion(); | |
1114 | } | |
1115 | ||
1116 | int wxAuiSimpleTabArt::GetIndentSize() | |
1117 | { | |
1118 | return 0; | |
1119 | } | |
1120 | ||
1121 | wxSize wxAuiSimpleTabArt::GetTabSize(wxDC& dc, | |
1122 | wxWindow* WXUNUSED(wnd), | |
1123 | const wxString& caption, | |
1124 | const wxBitmap& WXUNUSED(bitmap), | |
1125 | bool WXUNUSED(active), | |
1126 | int close_button_state, | |
1127 | int* x_extent) | |
1128 | { | |
1129 | wxCoord measured_textx, measured_texty; | |
1130 | ||
1131 | dc.SetFont(m_measuring_font); | |
1132 | dc.GetTextExtent(caption, &measured_textx, &measured_texty); | |
1133 | ||
1134 | wxCoord tab_height = measured_texty + 4; | |
1135 | wxCoord tab_width = measured_textx + tab_height + 5; | |
1136 | ||
1137 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) | |
1138 | tab_width += m_active_close_bmp.GetWidth(); | |
1139 | ||
1140 | if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH) | |
1141 | { | |
1142 | tab_width = m_fixed_tab_width; | |
1143 | } | |
1144 | ||
1145 | *x_extent = tab_width - (tab_height/2) - 1; | |
1146 | ||
1147 | return wxSize(tab_width, tab_height); | |
1148 | } | |
1149 | ||
1150 | ||
1151 | void wxAuiSimpleTabArt::DrawButton(wxDC& dc, | |
1152 | wxWindow* WXUNUSED(wnd), | |
1153 | const wxRect& in_rect, | |
1154 | int bitmap_id, | |
1155 | int button_state, | |
1156 | int orientation, | |
1157 | wxRect* out_rect) | |
1158 | { | |
1159 | wxBitmap bmp; | |
1160 | wxRect rect; | |
1161 | ||
1162 | switch (bitmap_id) | |
1163 | { | |
1164 | case wxAUI_BUTTON_CLOSE: | |
1165 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
1166 | bmp = m_disabled_close_bmp; | |
1167 | else | |
1168 | bmp = m_active_close_bmp; | |
1169 | break; | |
1170 | case wxAUI_BUTTON_LEFT: | |
1171 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
1172 | bmp = m_disabled_left_bmp; | |
1173 | else | |
1174 | bmp = m_active_left_bmp; | |
1175 | break; | |
1176 | case wxAUI_BUTTON_RIGHT: | |
1177 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
1178 | bmp = m_disabled_right_bmp; | |
1179 | else | |
1180 | bmp = m_active_right_bmp; | |
1181 | break; | |
1182 | case wxAUI_BUTTON_WINDOWLIST: | |
1183 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
1184 | bmp = m_disabled_windowlist_bmp; | |
1185 | else | |
1186 | bmp = m_active_windowlist_bmp; | |
1187 | break; | |
1188 | } | |
1189 | ||
1190 | if (!bmp.IsOk()) | |
1191 | return; | |
1192 | ||
1193 | rect = in_rect; | |
1194 | ||
1195 | if (orientation == wxLEFT) | |
1196 | { | |
1197 | rect.SetX(in_rect.x); | |
1198 | rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2)); | |
1199 | rect.SetWidth(bmp.GetWidth()); | |
1200 | rect.SetHeight(bmp.GetHeight()); | |
1201 | } | |
1202 | else | |
1203 | { | |
1204 | rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(), | |
1205 | ((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2), | |
1206 | bmp.GetWidth(), bmp.GetHeight()); | |
1207 | } | |
1208 | ||
1209 | ||
1210 | DrawButtons(dc, rect, bmp, *wxWHITE, button_state); | |
1211 | ||
1212 | *out_rect = rect; | |
1213 | } | |
1214 | ||
1215 | int wxAuiSimpleTabArt::ShowDropDown(wxWindow* wnd, | |
1216 | const wxAuiNotebookPageArray& pages, | |
1217 | int active_idx) | |
1218 | { | |
1219 | wxMenu menuPopup; | |
1220 | ||
1221 | size_t i, count = pages.GetCount(); | |
1222 | for (i = 0; i < count; ++i) | |
1223 | { | |
1224 | const wxAuiNotebookPage& page = pages.Item(i); | |
1225 | menuPopup.AppendCheckItem(1000+i, page.caption); | |
1226 | } | |
1227 | ||
1228 | if (active_idx != -1) | |
1229 | { | |
1230 | menuPopup.Check(1000+active_idx, true); | |
1231 | } | |
1232 | ||
1233 | // find out where to put the popup menu of window | |
1234 | // items. Subtract 100 for now to center the menu | |
1235 | // a bit, until a better mechanism can be implemented | |
1236 | wxPoint pt = ::wxGetMousePosition(); | |
1237 | pt = wnd->ScreenToClient(pt); | |
1238 | if (pt.x < 100) | |
1239 | pt.x = 0; | |
1240 | else | |
1241 | pt.x -= 100; | |
1242 | ||
1243 | // find out the screen coordinate at the bottom of the tab ctrl | |
1244 | wxRect cli_rect = wnd->GetClientRect(); | |
1245 | pt.y = cli_rect.y + cli_rect.height; | |
1246 | ||
1247 | wxAuiCommandCapture* cc = new wxAuiCommandCapture; | |
1248 | wnd->PushEventHandler(cc); | |
1249 | wnd->PopupMenu(&menuPopup, pt); | |
1250 | int command = cc->GetCommandId(); | |
1251 | wnd->PopEventHandler(true); | |
1252 | ||
1253 | if (command >= 1000) | |
1254 | return command-1000; | |
1255 | ||
1256 | return -1; | |
1257 | } | |
1258 | ||
1259 | int wxAuiSimpleTabArt::GetBestTabCtrlSize(wxWindow* wnd, | |
1260 | const wxAuiNotebookPageArray& WXUNUSED(pages), | |
1261 | const wxSize& WXUNUSED(required_bmp_size)) | |
1262 | { | |
1263 | wxClientDC dc(wnd); | |
1264 | dc.SetFont(m_measuring_font); | |
1265 | int x_ext = 0; | |
1266 | wxSize s = GetTabSize(dc, | |
1267 | wnd, | |
1268 | wxT("ABCDEFGHIj"), | |
1269 | wxNullBitmap, | |
1270 | true, | |
1271 | wxAUI_BUTTON_STATE_HIDDEN, | |
1272 | &x_ext); | |
1273 | return s.y+3; | |
1274 | } | |
1275 | ||
1276 | void wxAuiSimpleTabArt::SetNormalFont(const wxFont& font) | |
1277 | { | |
1278 | m_normal_font = font; | |
1279 | } | |
1280 | ||
1281 | void wxAuiSimpleTabArt::SetSelectedFont(const wxFont& font) | |
1282 | { | |
1283 | m_selected_font = font; | |
1284 | } | |
1285 | ||
1286 | void wxAuiSimpleTabArt::SetMeasuringFont(const wxFont& font) | |
1287 | { | |
1288 | m_measuring_font = font; | |
1289 | } | |
1290 | ||
1291 | ||
1292 | ||
1293 | ||
1294 | // -- wxAuiTabContainer class implementation -- | |
1295 | ||
1296 | ||
1297 | // wxAuiTabContainer is a class which contains information about each | |
1298 | // tab. It also can render an entire tab control to a specified DC. | |
1299 | // It's not a window class itself, because this code will be used by | |
1300 | // the wxFrameMananger, where it is disadvantageous to have separate | |
1301 | // windows for each tab control in the case of "docked tabs" | |
1302 | ||
1303 | // A derived class, wxAuiTabCtrl, is an actual wxWindow-derived window | |
1304 | // which can be used as a tab control in the normal sense. | |
1305 | ||
1306 | ||
1307 | wxAuiTabContainer::wxAuiTabContainer() | |
1308 | { | |
1309 | m_tab_offset = 0; | |
1310 | m_flags = 0; | |
1311 | m_art = new wxAuiDefaultTabArt; | |
1312 | ||
1313 | AddButton(wxAUI_BUTTON_LEFT, wxLEFT); | |
1314 | AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT); | |
1315 | AddButton(wxAUI_BUTTON_WINDOWLIST, wxRIGHT); | |
1316 | AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT); | |
1317 | } | |
1318 | ||
1319 | wxAuiTabContainer::~wxAuiTabContainer() | |
1320 | { | |
1321 | delete m_art; | |
1322 | } | |
1323 | ||
1324 | void wxAuiTabContainer::SetArtProvider(wxAuiTabArt* art) | |
1325 | { | |
1326 | delete m_art; | |
1327 | m_art = art; | |
1328 | ||
1329 | if (m_art) | |
1330 | { | |
1331 | m_art->SetFlags(m_flags); | |
1332 | } | |
1333 | } | |
1334 | ||
1335 | wxAuiTabArt* wxAuiTabContainer::GetArtProvider() const | |
1336 | { | |
1337 | return m_art; | |
1338 | } | |
1339 | ||
1340 | void wxAuiTabContainer::SetFlags(unsigned int flags) | |
1341 | { | |
1342 | m_flags = flags; | |
1343 | ||
1344 | // check for new close button settings | |
1345 | RemoveButton(wxAUI_BUTTON_LEFT); | |
1346 | RemoveButton(wxAUI_BUTTON_RIGHT); | |
1347 | RemoveButton(wxAUI_BUTTON_WINDOWLIST); | |
1348 | RemoveButton(wxAUI_BUTTON_CLOSE); | |
1349 | ||
1350 | ||
1351 | if (flags & wxAUI_NB_SCROLL_BUTTONS) | |
1352 | { | |
1353 | AddButton(wxAUI_BUTTON_LEFT, wxLEFT); | |
1354 | AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT); | |
1355 | } | |
1356 | ||
1357 | if (flags & wxAUI_NB_WINDOWLIST_BUTTON) | |
1358 | { | |
1359 | AddButton(wxAUI_BUTTON_WINDOWLIST, wxRIGHT); | |
1360 | } | |
1361 | ||
1362 | if (flags & wxAUI_NB_CLOSE_BUTTON) | |
1363 | { | |
1364 | AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT); | |
1365 | } | |
1366 | ||
1367 | if (m_art) | |
1368 | { | |
1369 | m_art->SetFlags(m_flags); | |
1370 | } | |
1371 | } | |
1372 | ||
1373 | unsigned int wxAuiTabContainer::GetFlags() const | |
1374 | { | |
1375 | return m_flags; | |
1376 | } | |
1377 | ||
1378 | ||
1379 | void wxAuiTabContainer::SetNormalFont(const wxFont& font) | |
1380 | { | |
1381 | m_art->SetNormalFont(font); | |
1382 | } | |
1383 | ||
1384 | void wxAuiTabContainer::SetSelectedFont(const wxFont& font) | |
1385 | { | |
1386 | m_art->SetSelectedFont(font); | |
1387 | } | |
1388 | ||
1389 | void wxAuiTabContainer::SetMeasuringFont(const wxFont& font) | |
1390 | { | |
1391 | m_art->SetMeasuringFont(font); | |
1392 | } | |
1393 | ||
1394 | void wxAuiTabContainer::SetColour(const wxColour& colour) | |
1395 | { | |
1396 | m_art->SetColour(colour); | |
1397 | } | |
1398 | ||
1399 | void wxAuiTabContainer::SetActiveColour(const wxColour& colour) | |
1400 | { | |
1401 | m_art->SetActiveColour(colour); | |
1402 | } | |
1403 | ||
1404 | void wxAuiTabContainer::SetRect(const wxRect& rect) | |
1405 | { | |
1406 | m_rect = rect; | |
1407 | ||
1408 | if (m_art) | |
1409 | { | |
1410 | m_art->SetSizingInfo(rect.GetSize(), m_pages.GetCount()); | |
1411 | } | |
1412 | } | |
1413 | ||
1414 | bool wxAuiTabContainer::AddPage(wxWindow* page, | |
1415 | const wxAuiNotebookPage& info) | |
1416 | { | |
1417 | wxAuiNotebookPage page_info; | |
1418 | page_info = info; | |
1419 | page_info.window = page; | |
1420 | ||
1421 | m_pages.Add(page_info); | |
1422 | ||
1423 | // let the art provider know how many pages we have | |
1424 | if (m_art) | |
1425 | { | |
1426 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
1427 | } | |
1428 | ||
1429 | return true; | |
1430 | } | |
1431 | ||
1432 | bool wxAuiTabContainer::InsertPage(wxWindow* page, | |
1433 | const wxAuiNotebookPage& info, | |
1434 | size_t idx) | |
1435 | { | |
1436 | wxAuiNotebookPage page_info; | |
1437 | page_info = info; | |
1438 | page_info.window = page; | |
1439 | ||
1440 | if (idx >= m_pages.GetCount()) | |
1441 | m_pages.Add(page_info); | |
1442 | else | |
1443 | m_pages.Insert(page_info, idx); | |
1444 | ||
1445 | // let the art provider know how many pages we have | |
1446 | if (m_art) | |
1447 | { | |
1448 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
1449 | } | |
1450 | ||
1451 | return true; | |
1452 | } | |
1453 | ||
1454 | bool wxAuiTabContainer::MovePage(wxWindow* page, | |
1455 | size_t new_idx) | |
1456 | { | |
1457 | int idx = GetIdxFromWindow(page); | |
1458 | if (idx == -1) | |
1459 | return false; | |
1460 | ||
1461 | // get page entry, make a copy of it | |
1462 | wxAuiNotebookPage p = GetPage(idx); | |
1463 | ||
1464 | // remove old page entry | |
1465 | RemovePage(page); | |
1466 | ||
1467 | // insert page where it should be | |
1468 | InsertPage(page, p, new_idx); | |
1469 | ||
1470 | return true; | |
1471 | } | |
1472 | ||
1473 | bool wxAuiTabContainer::RemovePage(wxWindow* wnd) | |
1474 | { | |
1475 | size_t i, page_count = m_pages.GetCount(); | |
1476 | for (i = 0; i < page_count; ++i) | |
1477 | { | |
1478 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1479 | if (page.window == wnd) | |
1480 | { | |
1481 | m_pages.RemoveAt(i); | |
1482 | ||
1483 | // let the art provider know how many pages we have | |
1484 | if (m_art) | |
1485 | { | |
1486 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
1487 | } | |
1488 | ||
1489 | return true; | |
1490 | } | |
1491 | } | |
1492 | ||
1493 | return false; | |
1494 | } | |
1495 | ||
1496 | bool wxAuiTabContainer::SetActivePage(wxWindow* wnd) | |
1497 | { | |
1498 | bool found = false; | |
1499 | ||
1500 | size_t i, page_count = m_pages.GetCount(); | |
1501 | for (i = 0; i < page_count; ++i) | |
1502 | { | |
1503 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1504 | if (page.window == wnd) | |
1505 | { | |
1506 | page.active = true; | |
1507 | found = true; | |
1508 | } | |
1509 | else | |
1510 | { | |
1511 | page.active = false; | |
1512 | } | |
1513 | } | |
1514 | ||
1515 | return found; | |
1516 | } | |
1517 | ||
1518 | void wxAuiTabContainer::SetNoneActive() | |
1519 | { | |
1520 | size_t i, page_count = m_pages.GetCount(); | |
1521 | for (i = 0; i < page_count; ++i) | |
1522 | { | |
1523 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1524 | page.active = false; | |
1525 | } | |
1526 | } | |
1527 | ||
1528 | bool wxAuiTabContainer::SetActivePage(size_t page) | |
1529 | { | |
1530 | if (page >= m_pages.GetCount()) | |
1531 | return false; | |
1532 | ||
1533 | return SetActivePage(m_pages.Item(page).window); | |
1534 | } | |
1535 | ||
1536 | int wxAuiTabContainer::GetActivePage() const | |
1537 | { | |
1538 | size_t i, page_count = m_pages.GetCount(); | |
1539 | for (i = 0; i < page_count; ++i) | |
1540 | { | |
1541 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1542 | if (page.active) | |
1543 | return i; | |
1544 | } | |
1545 | ||
1546 | return -1; | |
1547 | } | |
1548 | ||
1549 | wxWindow* wxAuiTabContainer::GetWindowFromIdx(size_t idx) const | |
1550 | { | |
1551 | if (idx >= m_pages.GetCount()) | |
1552 | return NULL; | |
1553 | ||
1554 | return m_pages[idx].window; | |
1555 | } | |
1556 | ||
1557 | int wxAuiTabContainer::GetIdxFromWindow(wxWindow* wnd) const | |
1558 | { | |
1559 | const size_t page_count = m_pages.GetCount(); | |
1560 | for ( size_t i = 0; i < page_count; ++i ) | |
1561 | { | |
1562 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1563 | if (page.window == wnd) | |
1564 | return i; | |
1565 | } | |
1566 | return wxNOT_FOUND; | |
1567 | } | |
1568 | ||
1569 | wxAuiNotebookPage& wxAuiTabContainer::GetPage(size_t idx) | |
1570 | { | |
1571 | wxASSERT_MSG(idx < m_pages.GetCount(), wxT("Invalid Page index")); | |
1572 | ||
1573 | return m_pages[idx]; | |
1574 | } | |
1575 | ||
1576 | const wxAuiNotebookPage& wxAuiTabContainer::GetPage(size_t idx) const | |
1577 | { | |
1578 | wxASSERT_MSG(idx < m_pages.GetCount(), wxT("Invalid Page index")); | |
1579 | ||
1580 | return m_pages[idx]; | |
1581 | } | |
1582 | ||
1583 | wxAuiNotebookPageArray& wxAuiTabContainer::GetPages() | |
1584 | { | |
1585 | return m_pages; | |
1586 | } | |
1587 | ||
1588 | size_t wxAuiTabContainer::GetPageCount() const | |
1589 | { | |
1590 | return m_pages.GetCount(); | |
1591 | } | |
1592 | ||
1593 | void wxAuiTabContainer::AddButton(int id, | |
1594 | int location, | |
1595 | const wxBitmap& normal_bitmap, | |
1596 | const wxBitmap& disabled_bitmap) | |
1597 | { | |
1598 | wxAuiTabContainerButton button; | |
1599 | button.id = id; | |
1600 | button.bitmap = normal_bitmap; | |
1601 | button.dis_bitmap = disabled_bitmap; | |
1602 | button.location = location; | |
1603 | button.cur_state = wxAUI_BUTTON_STATE_NORMAL; | |
1604 | ||
1605 | m_buttons.Add(button); | |
1606 | } | |
1607 | ||
1608 | void wxAuiTabContainer::RemoveButton(int id) | |
1609 | { | |
1610 | size_t i, button_count = m_buttons.GetCount(); | |
1611 | ||
1612 | for (i = 0; i < button_count; ++i) | |
1613 | { | |
1614 | if (m_buttons.Item(i).id == id) | |
1615 | { | |
1616 | m_buttons.RemoveAt(i); | |
1617 | return; | |
1618 | } | |
1619 | } | |
1620 | } | |
1621 | ||
1622 | ||
1623 | ||
1624 | size_t wxAuiTabContainer::GetTabOffset() const | |
1625 | { | |
1626 | return m_tab_offset; | |
1627 | } | |
1628 | ||
1629 | void wxAuiTabContainer::SetTabOffset(size_t offset) | |
1630 | { | |
1631 | m_tab_offset = offset; | |
1632 | } | |
1633 | ||
1634 | ||
1635 | ||
1636 | ||
1637 | // Render() renders the tab catalog to the specified DC | |
1638 | // It is a virtual function and can be overridden to | |
1639 | // provide custom drawing capabilities | |
1640 | void wxAuiTabContainer::Render(wxDC* raw_dc, wxWindow* wnd) | |
1641 | { | |
1642 | if (!raw_dc || !raw_dc->IsOk()) | |
1643 | return; | |
1644 | ||
1645 | wxMemoryDC dc; | |
1646 | ||
1647 | // use the same layout direction as the window DC uses to ensure that the | |
1648 | // text is rendered correctly | |
1649 | dc.SetLayoutDirection(raw_dc->GetLayoutDirection()); | |
1650 | ||
1651 | wxBitmap bmp; | |
1652 | size_t i; | |
1653 | size_t page_count = m_pages.GetCount(); | |
1654 | size_t button_count = m_buttons.GetCount(); | |
1655 | ||
1656 | // create off-screen bitmap | |
1657 | bmp.Create(m_rect.GetWidth(), m_rect.GetHeight()); | |
1658 | dc.SelectObject(bmp); | |
1659 | ||
1660 | if (!dc.IsOk()) | |
1661 | return; | |
1662 | ||
1663 | // find out if size of tabs is larger than can be | |
1664 | // afforded on screen | |
1665 | int total_width = 0; | |
1666 | int visible_width = 0; | |
1667 | for (i = 0; i < page_count; ++i) | |
1668 | { | |
1669 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1670 | ||
1671 | // determine if a close button is on this tab | |
1672 | bool close_button = false; | |
1673 | if ((m_flags & wxAUI_NB_CLOSE_ON_ALL_TABS) != 0 || | |
1674 | ((m_flags & wxAUI_NB_CLOSE_ON_ACTIVE_TAB) != 0 && page.active)) | |
1675 | { | |
1676 | close_button = true; | |
1677 | } | |
1678 | ||
1679 | ||
1680 | int x_extent = 0; | |
1681 | wxSize size = m_art->GetTabSize(dc, | |
1682 | wnd, | |
1683 | page.caption, | |
1684 | page.bitmap, | |
1685 | page.active, | |
1686 | close_button ? | |
1687 | wxAUI_BUTTON_STATE_NORMAL : | |
1688 | wxAUI_BUTTON_STATE_HIDDEN, | |
1689 | &x_extent); | |
1690 | ||
1691 | if (i+1 < page_count) | |
1692 | total_width += x_extent; | |
1693 | else | |
1694 | total_width += size.x; | |
1695 | ||
1696 | if (i >= m_tab_offset) | |
1697 | { | |
1698 | if (i+1 < page_count) | |
1699 | visible_width += x_extent; | |
1700 | else | |
1701 | visible_width += size.x; | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | if (total_width > m_rect.GetWidth() || m_tab_offset != 0) | |
1706 | { | |
1707 | // show left/right buttons | |
1708 | for (i = 0; i < button_count; ++i) | |
1709 | { | |
1710 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
1711 | if (button.id == wxAUI_BUTTON_LEFT || | |
1712 | button.id == wxAUI_BUTTON_RIGHT) | |
1713 | { | |
1714 | button.cur_state &= ~wxAUI_BUTTON_STATE_HIDDEN; | |
1715 | } | |
1716 | } | |
1717 | } | |
1718 | else | |
1719 | { | |
1720 | // hide left/right buttons | |
1721 | for (i = 0; i < button_count; ++i) | |
1722 | { | |
1723 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
1724 | if (button.id == wxAUI_BUTTON_LEFT || | |
1725 | button.id == wxAUI_BUTTON_RIGHT) | |
1726 | { | |
1727 | button.cur_state |= wxAUI_BUTTON_STATE_HIDDEN; | |
1728 | } | |
1729 | } | |
1730 | } | |
1731 | ||
1732 | // determine whether left button should be enabled | |
1733 | for (i = 0; i < button_count; ++i) | |
1734 | { | |
1735 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
1736 | if (button.id == wxAUI_BUTTON_LEFT) | |
1737 | { | |
1738 | if (m_tab_offset == 0) | |
1739 | button.cur_state |= wxAUI_BUTTON_STATE_DISABLED; | |
1740 | else | |
1741 | button.cur_state &= ~wxAUI_BUTTON_STATE_DISABLED; | |
1742 | } | |
1743 | if (button.id == wxAUI_BUTTON_RIGHT) | |
1744 | { | |
1745 | if (visible_width < m_rect.GetWidth() - ((int)button_count*16)) | |
1746 | button.cur_state |= wxAUI_BUTTON_STATE_DISABLED; | |
1747 | else | |
1748 | button.cur_state &= ~wxAUI_BUTTON_STATE_DISABLED; | |
1749 | } | |
1750 | } | |
1751 | ||
1752 | ||
1753 | ||
1754 | // draw background | |
1755 | m_art->DrawBackground(dc, wnd, m_rect); | |
1756 | ||
1757 | // draw buttons | |
1758 | int left_buttons_width = 0; | |
1759 | int right_buttons_width = 0; | |
1760 | ||
1761 | int offset = 0; | |
1762 | ||
1763 | // draw the buttons on the right side | |
1764 | offset = m_rect.x + m_rect.width; | |
1765 | for (i = 0; i < button_count; ++i) | |
1766 | { | |
1767 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
1768 | ||
1769 | if (button.location != wxRIGHT) | |
1770 | continue; | |
1771 | if (button.cur_state & wxAUI_BUTTON_STATE_HIDDEN) | |
1772 | continue; | |
1773 | ||
1774 | wxRect button_rect = m_rect; | |
1775 | button_rect.SetY(1); | |
1776 | button_rect.SetWidth(offset); | |
1777 | ||
1778 | m_art->DrawButton(dc, | |
1779 | wnd, | |
1780 | button_rect, | |
1781 | button.id, | |
1782 | button.cur_state, | |
1783 | wxRIGHT, | |
1784 | &button.rect); | |
1785 | ||
1786 | offset -= button.rect.GetWidth(); | |
1787 | right_buttons_width += button.rect.GetWidth(); | |
1788 | } | |
1789 | ||
1790 | ||
1791 | ||
1792 | offset = 0; | |
1793 | ||
1794 | // draw the buttons on the left side | |
1795 | ||
1796 | for (i = 0; i < button_count; ++i) | |
1797 | { | |
1798 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
1799 | ||
1800 | if (button.location != wxLEFT) | |
1801 | continue; | |
1802 | if (button.cur_state & wxAUI_BUTTON_STATE_HIDDEN) | |
1803 | continue; | |
1804 | ||
1805 | wxRect button_rect(offset, 1, 1000, m_rect.height); | |
1806 | ||
1807 | m_art->DrawButton(dc, | |
1808 | wnd, | |
1809 | button_rect, | |
1810 | button.id, | |
1811 | button.cur_state, | |
1812 | wxLEFT, | |
1813 | &button.rect); | |
1814 | ||
1815 | offset += button.rect.GetWidth(); | |
1816 | left_buttons_width += button.rect.GetWidth(); | |
1817 | } | |
1818 | ||
1819 | offset = left_buttons_width; | |
1820 | ||
1821 | if (offset == 0) | |
1822 | offset += m_art->GetIndentSize(); | |
1823 | ||
1824 | ||
1825 | // prepare the tab-close-button array | |
1826 | // make sure tab button entries which aren't used are marked as hidden | |
1827 | for (i = page_count; i < m_tab_close_buttons.GetCount(); ++i) | |
1828 | m_tab_close_buttons.Item(i).cur_state = wxAUI_BUTTON_STATE_HIDDEN; | |
1829 | ||
1830 | // make sure there are enough tab button entries to accommodate all tabs | |
1831 | while (m_tab_close_buttons.GetCount() < page_count) | |
1832 | { | |
1833 | wxAuiTabContainerButton tempbtn; | |
1834 | tempbtn.id = wxAUI_BUTTON_CLOSE; | |
1835 | tempbtn.location = wxCENTER; | |
1836 | tempbtn.cur_state = wxAUI_BUTTON_STATE_HIDDEN; | |
1837 | m_tab_close_buttons.Add(tempbtn); | |
1838 | } | |
1839 | ||
1840 | ||
1841 | // buttons before the tab offset must be set to hidden | |
1842 | for (i = 0; i < m_tab_offset; ++i) | |
1843 | { | |
1844 | m_tab_close_buttons.Item(i).cur_state = wxAUI_BUTTON_STATE_HIDDEN; | |
1845 | } | |
1846 | ||
1847 | ||
1848 | // draw the tabs | |
1849 | ||
1850 | size_t active = 999; | |
1851 | int active_offset = 0; | |
1852 | wxRect active_rect; | |
1853 | ||
1854 | int x_extent = 0; | |
1855 | wxRect rect = m_rect; | |
1856 | rect.y = 0; | |
1857 | rect.height = m_rect.height; | |
1858 | ||
1859 | for (i = m_tab_offset; i < page_count; ++i) | |
1860 | { | |
1861 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1862 | wxAuiTabContainerButton& tab_button = m_tab_close_buttons.Item(i); | |
1863 | ||
1864 | // determine if a close button is on this tab | |
1865 | if ((m_flags & wxAUI_NB_CLOSE_ON_ALL_TABS) != 0 || | |
1866 | ((m_flags & wxAUI_NB_CLOSE_ON_ACTIVE_TAB) != 0 && page.active)) | |
1867 | { | |
1868 | if (tab_button.cur_state == wxAUI_BUTTON_STATE_HIDDEN) | |
1869 | { | |
1870 | tab_button.id = wxAUI_BUTTON_CLOSE; | |
1871 | tab_button.cur_state = wxAUI_BUTTON_STATE_NORMAL; | |
1872 | tab_button.location = wxCENTER; | |
1873 | } | |
1874 | } | |
1875 | else | |
1876 | { | |
1877 | tab_button.cur_state = wxAUI_BUTTON_STATE_HIDDEN; | |
1878 | } | |
1879 | ||
1880 | rect.x = offset; | |
1881 | rect.width = m_rect.width - right_buttons_width - offset - 2; | |
1882 | ||
1883 | if (rect.width <= 0) | |
1884 | break; | |
1885 | ||
1886 | m_art->DrawTab(dc, | |
1887 | wnd, | |
1888 | page, | |
1889 | rect, | |
1890 | tab_button.cur_state, | |
1891 | &page.rect, | |
1892 | &tab_button.rect, | |
1893 | &x_extent); | |
1894 | ||
1895 | if (page.active) | |
1896 | { | |
1897 | active = i; | |
1898 | active_offset = offset; | |
1899 | active_rect = rect; | |
1900 | } | |
1901 | ||
1902 | offset += x_extent; | |
1903 | } | |
1904 | ||
1905 | ||
1906 | // make sure to deactivate buttons which are off the screen to the right | |
1907 | for (++i; i < m_tab_close_buttons.GetCount(); ++i) | |
1908 | { | |
1909 | m_tab_close_buttons.Item(i).cur_state = wxAUI_BUTTON_STATE_HIDDEN; | |
1910 | } | |
1911 | ||
1912 | ||
1913 | // draw the active tab again so it stands in the foreground | |
1914 | if (active >= m_tab_offset && active < m_pages.GetCount()) | |
1915 | { | |
1916 | wxAuiNotebookPage& page = m_pages.Item(active); | |
1917 | ||
1918 | wxAuiTabContainerButton& tab_button = m_tab_close_buttons.Item(active); | |
1919 | ||
1920 | rect.x = active_offset; | |
1921 | m_art->DrawTab(dc, | |
1922 | wnd, | |
1923 | page, | |
1924 | active_rect, | |
1925 | tab_button.cur_state, | |
1926 | &page.rect, | |
1927 | &tab_button.rect, | |
1928 | &x_extent); | |
1929 | } | |
1930 | ||
1931 | ||
1932 | raw_dc->Blit(m_rect.x, m_rect.y, | |
1933 | m_rect.GetWidth(), m_rect.GetHeight(), | |
1934 | &dc, 0, 0); | |
1935 | } | |
1936 | ||
1937 | // Is the tab visible? | |
1938 | bool wxAuiTabContainer::IsTabVisible(int tabPage, int tabOffset, wxDC* dc, wxWindow* wnd) | |
1939 | { | |
1940 | if (!dc || !dc->IsOk()) | |
1941 | return false; | |
1942 | ||
1943 | size_t i; | |
1944 | size_t page_count = m_pages.GetCount(); | |
1945 | size_t button_count = m_buttons.GetCount(); | |
1946 | ||
1947 | // Hasn't been rendered yet; assume it's visible | |
1948 | if (m_tab_close_buttons.GetCount() < page_count) | |
1949 | return true; | |
1950 | ||
1951 | // First check if both buttons are disabled - if so, there's no need to | |
1952 | // check further for visibility. | |
1953 | int arrowButtonVisibleCount = 0; | |
1954 | for (i = 0; i < button_count; ++i) | |
1955 | { | |
1956 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
1957 | if (button.id == wxAUI_BUTTON_LEFT || | |
1958 | button.id == wxAUI_BUTTON_RIGHT) | |
1959 | { | |
1960 | if ((button.cur_state & wxAUI_BUTTON_STATE_HIDDEN) == 0) | |
1961 | arrowButtonVisibleCount ++; | |
1962 | } | |
1963 | } | |
1964 | ||
1965 | // Tab must be visible | |
1966 | if (arrowButtonVisibleCount == 0) | |
1967 | return true; | |
1968 | ||
1969 | // If tab is less than the given offset, it must be invisible by definition | |
1970 | if (tabPage < tabOffset) | |
1971 | return false; | |
1972 | ||
1973 | // draw buttons | |
1974 | int left_buttons_width = 0; | |
1975 | int right_buttons_width = 0; | |
1976 | ||
1977 | int offset = 0; | |
1978 | ||
1979 | // calculate size of the buttons on the right side | |
1980 | offset = m_rect.x + m_rect.width; | |
1981 | for (i = 0; i < button_count; ++i) | |
1982 | { | |
1983 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
1984 | ||
1985 | if (button.location != wxRIGHT) | |
1986 | continue; | |
1987 | if (button.cur_state & wxAUI_BUTTON_STATE_HIDDEN) | |
1988 | continue; | |
1989 | ||
1990 | offset -= button.rect.GetWidth(); | |
1991 | right_buttons_width += button.rect.GetWidth(); | |
1992 | } | |
1993 | ||
1994 | offset = 0; | |
1995 | ||
1996 | // calculate size of the buttons on the left side | |
1997 | for (i = 0; i < button_count; ++i) | |
1998 | { | |
1999 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
2000 | ||
2001 | if (button.location != wxLEFT) | |
2002 | continue; | |
2003 | if (button.cur_state & wxAUI_BUTTON_STATE_HIDDEN) | |
2004 | continue; | |
2005 | ||
2006 | offset += button.rect.GetWidth(); | |
2007 | left_buttons_width += button.rect.GetWidth(); | |
2008 | } | |
2009 | ||
2010 | offset = left_buttons_width; | |
2011 | ||
2012 | if (offset == 0) | |
2013 | offset += m_art->GetIndentSize(); | |
2014 | ||
2015 | wxRect active_rect; | |
2016 | ||
2017 | wxRect rect = m_rect; | |
2018 | rect.y = 0; | |
2019 | rect.height = m_rect.height; | |
2020 | ||
2021 | // See if the given page is visible at the given tab offset (effectively scroll position) | |
2022 | for (i = tabOffset; i < page_count; ++i) | |
2023 | { | |
2024 | wxAuiNotebookPage& page = m_pages.Item(i); | |
2025 | wxAuiTabContainerButton& tab_button = m_tab_close_buttons.Item(i); | |
2026 | ||
2027 | rect.x = offset; | |
2028 | rect.width = m_rect.width - right_buttons_width - offset - 2; | |
2029 | ||
2030 | if (rect.width <= 0) | |
2031 | return false; // haven't found the tab, and we've run out of space, so return false | |
2032 | ||
2033 | int x_extent = 0; | |
2034 | wxSize size = m_art->GetTabSize(*dc, | |
2035 | wnd, | |
2036 | page.caption, | |
2037 | page.bitmap, | |
2038 | page.active, | |
2039 | tab_button.cur_state, | |
2040 | &x_extent); | |
2041 | ||
2042 | offset += x_extent; | |
2043 | ||
2044 | if (i == (size_t) tabPage) | |
2045 | { | |
2046 | // If not all of the tab is visible, and supposing there's space to display it all, | |
2047 | // we could do better so we return false. | |
2048 | if (((m_rect.width - right_buttons_width - offset - 2) <= 0) && ((m_rect.width - right_buttons_width - left_buttons_width) > x_extent)) | |
2049 | return false; | |
2050 | else | |
2051 | return true; | |
2052 | } | |
2053 | } | |
2054 | ||
2055 | // Shouldn't really get here, but if it does, assume the tab is visible to prevent | |
2056 | // further looping in calling code. | |
2057 | return true; | |
2058 | } | |
2059 | ||
2060 | // Make the tab visible if it wasn't already | |
2061 | void wxAuiTabContainer::MakeTabVisible(int tabPage, wxWindow* win) | |
2062 | { | |
2063 | wxClientDC dc(win); | |
2064 | if (!IsTabVisible(tabPage, GetTabOffset(), & dc, win)) | |
2065 | { | |
2066 | int i; | |
2067 | for (i = 0; i < (int) m_pages.GetCount(); i++) | |
2068 | { | |
2069 | if (IsTabVisible(tabPage, i, & dc, win)) | |
2070 | { | |
2071 | SetTabOffset(i); | |
2072 | win->Refresh(); | |
2073 | return; | |
2074 | } | |
2075 | } | |
2076 | } | |
2077 | } | |
2078 | ||
2079 | // TabHitTest() tests if a tab was hit, passing the window pointer | |
2080 | // back if that condition was fulfilled. The function returns | |
2081 | // true if a tab was hit, otherwise false | |
2082 | bool wxAuiTabContainer::TabHitTest(int x, int y, wxWindow** hit) const | |
2083 | { | |
2084 | if (!m_rect.Contains(x,y)) | |
2085 | return false; | |
2086 | ||
2087 | wxAuiTabContainerButton* btn = NULL; | |
2088 | if (ButtonHitTest(x, y, &btn) && !(btn->cur_state & wxAUI_BUTTON_STATE_DISABLED)) | |
2089 | { | |
2090 | if (m_buttons.Index(*btn) != wxNOT_FOUND) | |
2091 | return false; | |
2092 | } | |
2093 | ||
2094 | size_t i, page_count = m_pages.GetCount(); | |
2095 | ||
2096 | for (i = m_tab_offset; i < page_count; ++i) | |
2097 | { | |
2098 | wxAuiNotebookPage& page = m_pages.Item(i); | |
2099 | if (page.rect.Contains(x,y)) | |
2100 | { | |
2101 | if (hit) | |
2102 | *hit = page.window; | |
2103 | return true; | |
2104 | } | |
2105 | } | |
2106 | ||
2107 | return false; | |
2108 | } | |
2109 | ||
2110 | // ButtonHitTest() tests if a button was hit. The function returns | |
2111 | // true if a button was hit, otherwise false | |
2112 | bool wxAuiTabContainer::ButtonHitTest(int x, int y, | |
2113 | wxAuiTabContainerButton** hit) const | |
2114 | { | |
2115 | if (!m_rect.Contains(x,y)) | |
2116 | return false; | |
2117 | ||
2118 | size_t i, button_count; | |
2119 | ||
2120 | ||
2121 | button_count = m_buttons.GetCount(); | |
2122 | for (i = 0; i < button_count; ++i) | |
2123 | { | |
2124 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
2125 | if (button.rect.Contains(x,y) && | |
2126 | !(button.cur_state & wxAUI_BUTTON_STATE_HIDDEN )) | |
2127 | { | |
2128 | if (hit) | |
2129 | *hit = &button; | |
2130 | return true; | |
2131 | } | |
2132 | } | |
2133 | ||
2134 | button_count = m_tab_close_buttons.GetCount(); | |
2135 | for (i = 0; i < button_count; ++i) | |
2136 | { | |
2137 | wxAuiTabContainerButton& button = m_tab_close_buttons.Item(i); | |
2138 | if (button.rect.Contains(x,y) && | |
2139 | !(button.cur_state & (wxAUI_BUTTON_STATE_HIDDEN | | |
2140 | wxAUI_BUTTON_STATE_DISABLED))) | |
2141 | { | |
2142 | if (hit) | |
2143 | *hit = &button; | |
2144 | return true; | |
2145 | } | |
2146 | } | |
2147 | ||
2148 | return false; | |
2149 | } | |
2150 | ||
2151 | ||
2152 | ||
2153 | // the utility function ShowWnd() is the same as show, | |
2154 | // except it handles wxAuiMDIChildFrame windows as well, | |
2155 | // as the Show() method on this class is "unplugged" | |
2156 | static void ShowWnd(wxWindow* wnd, bool show) | |
2157 | { | |
2158 | #if wxUSE_MDI | |
2159 | if (wnd->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) | |
2160 | { | |
2161 | wxAuiMDIChildFrame* cf = (wxAuiMDIChildFrame*)wnd; | |
2162 | cf->DoShow(show); | |
2163 | } | |
2164 | else | |
2165 | #endif | |
2166 | { | |
2167 | wnd->Show(show); | |
2168 | } | |
2169 | } | |
2170 | ||
2171 | ||
2172 | // DoShowHide() this function shows the active window, then | |
2173 | // hides all of the other windows (in that order) | |
2174 | void wxAuiTabContainer::DoShowHide() | |
2175 | { | |
2176 | wxAuiNotebookPageArray& pages = GetPages(); | |
2177 | size_t i, page_count = pages.GetCount(); | |
2178 | ||
2179 | // show new active page first | |
2180 | for (i = 0; i < page_count; ++i) | |
2181 | { | |
2182 | wxAuiNotebookPage& page = pages.Item(i); | |
2183 | if (page.active) | |
2184 | { | |
2185 | ShowWnd(page.window, true); | |
2186 | break; | |
2187 | } | |
2188 | } | |
2189 | ||
2190 | // hide all other pages | |
2191 | for (i = 0; i < page_count; ++i) | |
2192 | { | |
2193 | wxAuiNotebookPage& page = pages.Item(i); | |
2194 | if (!page.active) | |
2195 | ShowWnd(page.window, false); | |
2196 | } | |
2197 | } | |
2198 | ||
2199 | ||
2200 | ||
2201 | ||
2202 | ||
2203 | ||
2204 | // -- wxAuiTabCtrl class implementation -- | |
2205 | ||
2206 | ||
2207 | ||
2208 | BEGIN_EVENT_TABLE(wxAuiTabCtrl, wxControl) | |
2209 | EVT_PAINT(wxAuiTabCtrl::OnPaint) | |
2210 | EVT_ERASE_BACKGROUND(wxAuiTabCtrl::OnEraseBackground) | |
2211 | EVT_SIZE(wxAuiTabCtrl::OnSize) | |
2212 | EVT_LEFT_DOWN(wxAuiTabCtrl::OnLeftDown) | |
2213 | EVT_LEFT_DCLICK(wxAuiTabCtrl::OnLeftDClick) | |
2214 | EVT_LEFT_UP(wxAuiTabCtrl::OnLeftUp) | |
2215 | EVT_MIDDLE_DOWN(wxAuiTabCtrl::OnMiddleDown) | |
2216 | EVT_MIDDLE_UP(wxAuiTabCtrl::OnMiddleUp) | |
2217 | EVT_RIGHT_DOWN(wxAuiTabCtrl::OnRightDown) | |
2218 | EVT_RIGHT_UP(wxAuiTabCtrl::OnRightUp) | |
2219 | EVT_MOTION(wxAuiTabCtrl::OnMotion) | |
2220 | EVT_LEAVE_WINDOW(wxAuiTabCtrl::OnLeaveWindow) | |
2221 | EVT_AUINOTEBOOK_BUTTON(wxID_ANY, wxAuiTabCtrl::OnButton) | |
2222 | EVT_SET_FOCUS(wxAuiTabCtrl::OnSetFocus) | |
2223 | EVT_KILL_FOCUS(wxAuiTabCtrl::OnKillFocus) | |
2224 | EVT_CHAR(wxAuiTabCtrl::OnChar) | |
2225 | EVT_MOUSE_CAPTURE_LOST(wxAuiTabCtrl::OnCaptureLost) | |
2226 | END_EVENT_TABLE() | |
2227 | ||
2228 | ||
2229 | wxAuiTabCtrl::wxAuiTabCtrl(wxWindow* parent, | |
2230 | wxWindowID id, | |
2231 | const wxPoint& pos, | |
2232 | const wxSize& size, | |
2233 | long style) : wxControl(parent, id, pos, size, style) | |
2234 | { | |
2235 | SetName(wxT("wxAuiTabCtrl")); | |
2236 | m_click_pt = wxDefaultPosition; | |
2237 | m_is_dragging = false; | |
2238 | m_hover_button = NULL; | |
2239 | m_pressed_button = NULL; | |
2240 | } | |
2241 | ||
2242 | wxAuiTabCtrl::~wxAuiTabCtrl() | |
2243 | { | |
2244 | } | |
2245 | ||
2246 | void wxAuiTabCtrl::OnPaint(wxPaintEvent&) | |
2247 | { | |
2248 | wxPaintDC dc(this); | |
2249 | ||
2250 | dc.SetFont(GetFont()); | |
2251 | ||
2252 | if (GetPageCount() > 0) | |
2253 | Render(&dc, this); | |
2254 | } | |
2255 | ||
2256 | void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) | |
2257 | { | |
2258 | } | |
2259 | ||
2260 | void wxAuiTabCtrl::OnSize(wxSizeEvent& evt) | |
2261 | { | |
2262 | wxSize s = evt.GetSize(); | |
2263 | wxRect r(0, 0, s.GetWidth(), s.GetHeight()); | |
2264 | SetRect(r); | |
2265 | } | |
2266 | ||
2267 | void wxAuiTabCtrl::OnLeftDown(wxMouseEvent& evt) | |
2268 | { | |
2269 | CaptureMouse(); | |
2270 | m_click_pt = wxDefaultPosition; | |
2271 | m_is_dragging = false; | |
2272 | m_click_tab = NULL; | |
2273 | m_pressed_button = NULL; | |
2274 | ||
2275 | ||
2276 | wxWindow* wnd; | |
2277 | if (TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2278 | { | |
2279 | int new_selection = GetIdxFromWindow(wnd); | |
2280 | ||
2281 | // wxAuiNotebooks always want to receive this event | |
2282 | // even if the tab is already active, because they may | |
2283 | // have multiple tab controls | |
2284 | if (new_selection != GetActivePage() || | |
2285 | GetParent()->IsKindOf(CLASSINFO(wxAuiNotebook))) | |
2286 | { | |
2287 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
2288 | e.SetSelection(new_selection); | |
2289 | e.SetOldSelection(GetActivePage()); | |
2290 | e.SetEventObject(this); | |
2291 | GetEventHandler()->ProcessEvent(e); | |
2292 | } | |
2293 | ||
2294 | m_click_pt.x = evt.m_x; | |
2295 | m_click_pt.y = evt.m_y; | |
2296 | m_click_tab = wnd; | |
2297 | } | |
2298 | ||
2299 | if (m_hover_button) | |
2300 | { | |
2301 | m_pressed_button = m_hover_button; | |
2302 | m_pressed_button->cur_state = wxAUI_BUTTON_STATE_PRESSED; | |
2303 | Refresh(); | |
2304 | Update(); | |
2305 | } | |
2306 | } | |
2307 | ||
2308 | void wxAuiTabCtrl::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) | |
2309 | { | |
2310 | if (m_is_dragging) | |
2311 | { | |
2312 | m_is_dragging = false; | |
2313 | ||
2314 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, m_windowId); | |
2315 | evt.SetSelection(GetIdxFromWindow(m_click_tab)); | |
2316 | evt.SetOldSelection(evt.GetSelection()); | |
2317 | evt.SetEventObject(this); | |
2318 | GetEventHandler()->ProcessEvent(evt); | |
2319 | } | |
2320 | } | |
2321 | ||
2322 | void wxAuiTabCtrl::OnLeftUp(wxMouseEvent& evt) | |
2323 | { | |
2324 | if (GetCapture() == this) | |
2325 | ReleaseMouse(); | |
2326 | ||
2327 | if (m_is_dragging) | |
2328 | { | |
2329 | m_is_dragging = false; | |
2330 | ||
2331 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, m_windowId); | |
2332 | evt.SetSelection(GetIdxFromWindow(m_click_tab)); | |
2333 | evt.SetOldSelection(evt.GetSelection()); | |
2334 | evt.SetEventObject(this); | |
2335 | GetEventHandler()->ProcessEvent(evt); | |
2336 | ||
2337 | return; | |
2338 | } | |
2339 | ||
2340 | if (m_pressed_button) | |
2341 | { | |
2342 | // make sure we're still clicking the button | |
2343 | wxAuiTabContainerButton* button = NULL; | |
2344 | if (!ButtonHitTest(evt.m_x, evt.m_y, &button) || | |
2345 | button->cur_state & wxAUI_BUTTON_STATE_DISABLED) | |
2346 | return; | |
2347 | ||
2348 | if (button != m_pressed_button) | |
2349 | { | |
2350 | m_pressed_button = NULL; | |
2351 | return; | |
2352 | } | |
2353 | ||
2354 | Refresh(); | |
2355 | Update(); | |
2356 | ||
2357 | if (!(m_pressed_button->cur_state & wxAUI_BUTTON_STATE_DISABLED)) | |
2358 | { | |
2359 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, m_windowId); | |
2360 | evt.SetSelection(GetIdxFromWindow(m_click_tab)); | |
2361 | evt.SetInt(m_pressed_button->id); | |
2362 | evt.SetEventObject(this); | |
2363 | GetEventHandler()->ProcessEvent(evt); | |
2364 | } | |
2365 | ||
2366 | m_pressed_button = NULL; | |
2367 | } | |
2368 | ||
2369 | m_click_pt = wxDefaultPosition; | |
2370 | m_is_dragging = false; | |
2371 | m_click_tab = NULL; | |
2372 | } | |
2373 | ||
2374 | void wxAuiTabCtrl::OnMiddleUp(wxMouseEvent& evt) | |
2375 | { | |
2376 | wxWindow* wnd = NULL; | |
2377 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2378 | return; | |
2379 | ||
2380 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, m_windowId); | |
2381 | e.SetEventObject(this); | |
2382 | e.SetSelection(GetIdxFromWindow(wnd)); | |
2383 | GetEventHandler()->ProcessEvent(e); | |
2384 | } | |
2385 | ||
2386 | void wxAuiTabCtrl::OnMiddleDown(wxMouseEvent& evt) | |
2387 | { | |
2388 | wxWindow* wnd = NULL; | |
2389 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2390 | return; | |
2391 | ||
2392 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, m_windowId); | |
2393 | e.SetEventObject(this); | |
2394 | e.SetSelection(GetIdxFromWindow(wnd)); | |
2395 | GetEventHandler()->ProcessEvent(e); | |
2396 | } | |
2397 | ||
2398 | void wxAuiTabCtrl::OnRightUp(wxMouseEvent& evt) | |
2399 | { | |
2400 | wxWindow* wnd = NULL; | |
2401 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2402 | return; | |
2403 | ||
2404 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, m_windowId); | |
2405 | e.SetEventObject(this); | |
2406 | e.SetSelection(GetIdxFromWindow(wnd)); | |
2407 | GetEventHandler()->ProcessEvent(e); | |
2408 | } | |
2409 | ||
2410 | void wxAuiTabCtrl::OnRightDown(wxMouseEvent& evt) | |
2411 | { | |
2412 | wxWindow* wnd = NULL; | |
2413 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2414 | return; | |
2415 | ||
2416 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, m_windowId); | |
2417 | e.SetEventObject(this); | |
2418 | e.SetSelection(GetIdxFromWindow(wnd)); | |
2419 | GetEventHandler()->ProcessEvent(e); | |
2420 | } | |
2421 | ||
2422 | void wxAuiTabCtrl::OnLeftDClick(wxMouseEvent& evt) | |
2423 | { | |
2424 | wxWindow* wnd; | |
2425 | wxAuiTabContainerButton* button; | |
2426 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd) && !ButtonHitTest(evt.m_x, evt.m_y, &button)) | |
2427 | { | |
2428 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, m_windowId); | |
2429 | e.SetEventObject(this); | |
2430 | GetEventHandler()->ProcessEvent(e); | |
2431 | } | |
2432 | } | |
2433 | ||
2434 | void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt) | |
2435 | { | |
2436 | wxPoint pos = evt.GetPosition(); | |
2437 | ||
2438 | // check if the mouse is hovering above a button | |
2439 | wxAuiTabContainerButton* button; | |
2440 | if (ButtonHitTest(pos.x, pos.y, &button) && !(button->cur_state & wxAUI_BUTTON_STATE_DISABLED)) | |
2441 | { | |
2442 | if (m_hover_button && button != m_hover_button) | |
2443 | { | |
2444 | m_hover_button->cur_state = wxAUI_BUTTON_STATE_NORMAL; | |
2445 | m_hover_button = NULL; | |
2446 | Refresh(); | |
2447 | Update(); | |
2448 | } | |
2449 | ||
2450 | if (button->cur_state != wxAUI_BUTTON_STATE_HOVER) | |
2451 | { | |
2452 | button->cur_state = wxAUI_BUTTON_STATE_HOVER; | |
2453 | Refresh(); | |
2454 | Update(); | |
2455 | m_hover_button = button; | |
2456 | return; | |
2457 | } | |
2458 | } | |
2459 | else | |
2460 | { | |
2461 | if (m_hover_button) | |
2462 | { | |
2463 | m_hover_button->cur_state = wxAUI_BUTTON_STATE_NORMAL; | |
2464 | m_hover_button = NULL; | |
2465 | Refresh(); | |
2466 | Update(); | |
2467 | } | |
2468 | } | |
2469 | ||
2470 | ||
2471 | if (!evt.LeftIsDown() || m_click_pt == wxDefaultPosition) | |
2472 | return; | |
2473 | ||
2474 | if (m_is_dragging) | |
2475 | { | |
2476 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, m_windowId); | |
2477 | evt.SetSelection(GetIdxFromWindow(m_click_tab)); | |
2478 | evt.SetOldSelection(evt.GetSelection()); | |
2479 | evt.SetEventObject(this); | |
2480 | GetEventHandler()->ProcessEvent(evt); | |
2481 | return; | |
2482 | } | |
2483 | ||
2484 | ||
2485 | int drag_x_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_X); | |
2486 | int drag_y_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_Y); | |
2487 | ||
2488 | if (abs(pos.x - m_click_pt.x) > drag_x_threshold || | |
2489 | abs(pos.y - m_click_pt.y) > drag_y_threshold) | |
2490 | { | |
2491 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, m_windowId); | |
2492 | evt.SetSelection(GetIdxFromWindow(m_click_tab)); | |
2493 | evt.SetOldSelection(evt.GetSelection()); | |
2494 | evt.SetEventObject(this); | |
2495 | GetEventHandler()->ProcessEvent(evt); | |
2496 | ||
2497 | m_is_dragging = true; | |
2498 | } | |
2499 | } | |
2500 | ||
2501 | void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent& WXUNUSED(event)) | |
2502 | { | |
2503 | if (m_hover_button) | |
2504 | { | |
2505 | m_hover_button->cur_state = wxAUI_BUTTON_STATE_NORMAL; | |
2506 | m_hover_button = NULL; | |
2507 | Refresh(); | |
2508 | Update(); | |
2509 | } | |
2510 | } | |
2511 | ||
2512 | void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent& event) | |
2513 | { | |
2514 | int button = event.GetInt(); | |
2515 | ||
2516 | if (button == wxAUI_BUTTON_LEFT || button == wxAUI_BUTTON_RIGHT) | |
2517 | { | |
2518 | if (button == wxAUI_BUTTON_LEFT) | |
2519 | { | |
2520 | if (GetTabOffset() > 0) | |
2521 | { | |
2522 | SetTabOffset(GetTabOffset()-1); | |
2523 | Refresh(); | |
2524 | Update(); | |
2525 | } | |
2526 | } | |
2527 | else | |
2528 | { | |
2529 | SetTabOffset(GetTabOffset()+1); | |
2530 | Refresh(); | |
2531 | Update(); | |
2532 | } | |
2533 | } | |
2534 | else if (button == wxAUI_BUTTON_WINDOWLIST) | |
2535 | { | |
2536 | int idx = GetArtProvider()->ShowDropDown(this, m_pages, GetActivePage()); | |
2537 | ||
2538 | if (idx != -1) | |
2539 | { | |
2540 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
2541 | e.SetSelection(idx); | |
2542 | e.SetOldSelection(GetActivePage()); | |
2543 | e.SetEventObject(this); | |
2544 | GetEventHandler()->ProcessEvent(e); | |
2545 | } | |
2546 | } | |
2547 | else | |
2548 | { | |
2549 | event.Skip(); | |
2550 | } | |
2551 | } | |
2552 | ||
2553 | void wxAuiTabCtrl::OnSetFocus(wxFocusEvent& WXUNUSED(event)) | |
2554 | { | |
2555 | Refresh(); | |
2556 | } | |
2557 | ||
2558 | void wxAuiTabCtrl::OnKillFocus(wxFocusEvent& WXUNUSED(event)) | |
2559 | { | |
2560 | Refresh(); | |
2561 | } | |
2562 | ||
2563 | void wxAuiTabCtrl::OnChar(wxKeyEvent& event) | |
2564 | { | |
2565 | if (GetActivePage() == -1) | |
2566 | { | |
2567 | event.Skip(); | |
2568 | return; | |
2569 | } | |
2570 | ||
2571 | // We can't leave tab processing to the system; on Windows, tabs and keys | |
2572 | // get eaten by the system and not processed properly if we specify both | |
2573 | // wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL, | |
2574 | // we don't key arrow key events. | |
2575 | ||
2576 | int key = event.GetKeyCode(); | |
2577 | ||
2578 | if (key == WXK_NUMPAD_PAGEUP) | |
2579 | key = WXK_PAGEUP; | |
2580 | if (key == WXK_NUMPAD_PAGEDOWN) | |
2581 | key = WXK_PAGEDOWN; | |
2582 | if (key == WXK_NUMPAD_HOME) | |
2583 | key = WXK_HOME; | |
2584 | if (key == WXK_NUMPAD_END) | |
2585 | key = WXK_END; | |
2586 | if (key == WXK_NUMPAD_LEFT) | |
2587 | key = WXK_LEFT; | |
2588 | if (key == WXK_NUMPAD_RIGHT) | |
2589 | key = WXK_RIGHT; | |
2590 | ||
2591 | if (key == WXK_TAB || key == WXK_PAGEUP || key == WXK_PAGEDOWN) | |
2592 | { | |
2593 | bool bCtrlDown = event.ControlDown(); | |
2594 | bool bShiftDown = event.ShiftDown(); | |
2595 | ||
2596 | bool bForward = (key == WXK_TAB && !bShiftDown) || (key == WXK_PAGEDOWN); | |
2597 | bool bWindowChange = (key == WXK_PAGEUP) || (key == WXK_PAGEDOWN) || bCtrlDown; | |
2598 | bool bFromTab = (key == WXK_TAB); | |
2599 | ||
2600 | wxAuiNotebook* nb = wxDynamicCast(GetParent(), wxAuiNotebook); | |
2601 | if (!nb) | |
2602 | { | |
2603 | event.Skip(); | |
2604 | return; | |
2605 | } | |
2606 | ||
2607 | wxNavigationKeyEvent keyEvent; | |
2608 | keyEvent.SetDirection(bForward); | |
2609 | keyEvent.SetWindowChange(bWindowChange); | |
2610 | keyEvent.SetFromTab(bFromTab); | |
2611 | keyEvent.SetEventObject(nb); | |
2612 | ||
2613 | if (!nb->GetEventHandler()->ProcessEvent(keyEvent)) | |
2614 | { | |
2615 | // Not processed? Do an explicit tab into the page. | |
2616 | wxWindow* win = GetWindowFromIdx(GetActivePage()); | |
2617 | if (win) | |
2618 | win->SetFocus(); | |
2619 | } | |
2620 | return; | |
2621 | } | |
2622 | ||
2623 | if (m_pages.GetCount() < 2) | |
2624 | { | |
2625 | event.Skip(); | |
2626 | return; | |
2627 | } | |
2628 | ||
2629 | int newPage = -1; | |
2630 | ||
2631 | int forwardKey, backwardKey; | |
2632 | if (GetLayoutDirection() == wxLayout_RightToLeft) | |
2633 | { | |
2634 | forwardKey = WXK_LEFT; | |
2635 | backwardKey = WXK_RIGHT; | |
2636 | } | |
2637 | else | |
2638 | { | |
2639 | forwardKey = WXK_RIGHT; | |
2640 | backwardKey = WXK_LEFT; | |
2641 | } | |
2642 | ||
2643 | if (key == forwardKey) | |
2644 | { | |
2645 | if (m_pages.GetCount() > 1) | |
2646 | { | |
2647 | if (GetActivePage() == -1) | |
2648 | newPage = 0; | |
2649 | else if (GetActivePage() < (int) (m_pages.GetCount() - 1)) | |
2650 | newPage = GetActivePage() + 1; | |
2651 | } | |
2652 | } | |
2653 | else if (key == backwardKey) | |
2654 | { | |
2655 | if (m_pages.GetCount() > 1) | |
2656 | { | |
2657 | if (GetActivePage() == -1) | |
2658 | newPage = (int) (m_pages.GetCount() - 1); | |
2659 | else if (GetActivePage() > 0) | |
2660 | newPage = GetActivePage() - 1; | |
2661 | } | |
2662 | } | |
2663 | else if (key == WXK_HOME) | |
2664 | { | |
2665 | newPage = 0; | |
2666 | } | |
2667 | else if (key == WXK_END) | |
2668 | { | |
2669 | newPage = (int) (m_pages.GetCount() - 1); | |
2670 | } | |
2671 | else | |
2672 | event.Skip(); | |
2673 | ||
2674 | if (newPage != -1) | |
2675 | { | |
2676 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
2677 | e.SetSelection(newPage); | |
2678 | e.SetOldSelection(newPage); | |
2679 | e.SetEventObject(this); | |
2680 | this->GetEventHandler()->ProcessEvent(e); | |
2681 | } | |
2682 | else | |
2683 | event.Skip(); | |
2684 | } | |
2685 | ||
2686 | // wxTabFrame is an interesting case. It's important that all child pages | |
2687 | // of the multi-notebook control are all actually children of that control | |
2688 | // (and not grandchildren). wxTabFrame facilitates this. There is one | |
2689 | // instance of wxTabFrame for each tab control inside the multi-notebook. | |
2690 | // It's important to know that wxTabFrame is not a real window, but it merely | |
2691 | // used to capture the dimensions/positioning of the internal tab control and | |
2692 | // it's managed page windows | |
2693 | ||
2694 | class wxTabFrame : public wxWindow | |
2695 | { | |
2696 | public: | |
2697 | ||
2698 | wxTabFrame() | |
2699 | { | |
2700 | m_tabs = NULL; | |
2701 | m_rect = wxRect(0,0,200,200); | |
2702 | m_tab_ctrl_height = 20; | |
2703 | } | |
2704 | ||
2705 | ~wxTabFrame() | |
2706 | { | |
2707 | wxDELETE(m_tabs); | |
2708 | } | |
2709 | ||
2710 | void SetTabCtrlHeight(int h) | |
2711 | { | |
2712 | m_tab_ctrl_height = h; | |
2713 | } | |
2714 | ||
2715 | protected: | |
2716 | void DoSetSize(int x, int y, | |
2717 | int width, int height, | |
2718 | int WXUNUSED(sizeFlags = wxSIZE_AUTO)) | |
2719 | { | |
2720 | m_rect = wxRect(x, y, width, height); | |
2721 | DoSizing(); | |
2722 | } | |
2723 | ||
2724 | void DoGetClientSize(int* x, int* y) const | |
2725 | { | |
2726 | *x = m_rect.width; | |
2727 | *y = m_rect.height; | |
2728 | } | |
2729 | ||
2730 | public: | |
2731 | bool Show( bool WXUNUSED(show = true) ) { return false; } | |
2732 | ||
2733 | void DoSizing() | |
2734 | { | |
2735 | if (!m_tabs) | |
2736 | return; | |
2737 | ||
2738 | if (m_tabs->IsFrozen() || m_tabs->GetParent()->IsFrozen()) | |
2739 | return; | |
2740 | ||
2741 | m_tab_rect = wxRect(m_rect.x, m_rect.y, m_rect.width, m_tab_ctrl_height); | |
2742 | if (m_tabs->GetFlags() & wxAUI_NB_BOTTOM) | |
2743 | { | |
2744 | m_tab_rect = wxRect (m_rect.x, m_rect.y + m_rect.height - m_tab_ctrl_height, m_rect.width, m_tab_ctrl_height); | |
2745 | m_tabs->SetSize (m_rect.x, m_rect.y + m_rect.height - m_tab_ctrl_height, m_rect.width, m_tab_ctrl_height); | |
2746 | m_tabs->SetRect (wxRect(0, 0, m_rect.width, m_tab_ctrl_height)); | |
2747 | } | |
2748 | else //TODO: if (GetFlags() & wxAUI_NB_TOP) | |
2749 | { | |
2750 | m_tab_rect = wxRect (m_rect.x, m_rect.y, m_rect.width, m_tab_ctrl_height); | |
2751 | m_tabs->SetSize (m_rect.x, m_rect.y, m_rect.width, m_tab_ctrl_height); | |
2752 | m_tabs->SetRect (wxRect(0, 0, m_rect.width, m_tab_ctrl_height)); | |
2753 | } | |
2754 | // TODO: else if (GetFlags() & wxAUI_NB_LEFT){} | |
2755 | // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){} | |
2756 | ||
2757 | m_tabs->Refresh(); | |
2758 | m_tabs->Update(); | |
2759 | ||
2760 | wxAuiNotebookPageArray& pages = m_tabs->GetPages(); | |
2761 | size_t i, page_count = pages.GetCount(); | |
2762 | ||
2763 | for (i = 0; i < page_count; ++i) | |
2764 | { | |
2765 | int height = m_rect.height - m_tab_ctrl_height; | |
2766 | if ( height < 0 ) | |
2767 | { | |
2768 | // avoid passing negative height to wxWindow::SetSize(), this | |
2769 | // results in assert failures/GTK+ warnings | |
2770 | height = 0; | |
2771 | } | |
2772 | ||
2773 | wxAuiNotebookPage& page = pages.Item(i); | |
2774 | if (m_tabs->GetFlags() & wxAUI_NB_BOTTOM) | |
2775 | { | |
2776 | page.window->SetSize(m_rect.x, m_rect.y, m_rect.width, height); | |
2777 | } | |
2778 | else //TODO: if (GetFlags() & wxAUI_NB_TOP) | |
2779 | { | |
2780 | page.window->SetSize(m_rect.x, m_rect.y + m_tab_ctrl_height, | |
2781 | m_rect.width, height); | |
2782 | } | |
2783 | // TODO: else if (GetFlags() & wxAUI_NB_LEFT){} | |
2784 | // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){} | |
2785 | ||
2786 | #if wxUSE_MDI | |
2787 | if (page.window->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) | |
2788 | { | |
2789 | wxAuiMDIChildFrame* wnd = (wxAuiMDIChildFrame*)page.window; | |
2790 | wnd->ApplyMDIChildFrameRect(); | |
2791 | } | |
2792 | #endif | |
2793 | } | |
2794 | } | |
2795 | ||
2796 | protected: | |
2797 | void DoGetSize(int* x, int* y) const | |
2798 | { | |
2799 | if (x) | |
2800 | *x = m_rect.GetWidth(); | |
2801 | if (y) | |
2802 | *y = m_rect.GetHeight(); | |
2803 | } | |
2804 | ||
2805 | public: | |
2806 | void Update() | |
2807 | { | |
2808 | // does nothing | |
2809 | } | |
2810 | ||
2811 | wxRect m_rect; | |
2812 | wxRect m_tab_rect; | |
2813 | wxAuiTabCtrl* m_tabs; | |
2814 | int m_tab_ctrl_height; | |
2815 | }; | |
2816 | ||
2817 | ||
2818 | const int wxAuiBaseTabCtrlId = 5380; | |
2819 | ||
2820 | ||
2821 | // -- wxAuiNotebook class implementation -- | |
2822 | ||
2823 | #define EVT_AUI_RANGE(id1, id2, event, func) \ | |
2824 | wx__DECLARE_EVT2(event, id1, id2, wxAuiNotebookEventHandler(func)) | |
2825 | ||
2826 | BEGIN_EVENT_TABLE(wxAuiNotebook, wxControl) | |
2827 | EVT_SIZE(wxAuiNotebook::OnSize) | |
2828 | EVT_CHILD_FOCUS(wxAuiNotebook::OnChildFocusNotebook) | |
2829 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2830 | wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, | |
2831 | wxAuiNotebook::OnTabClicked) | |
2832 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2833 | wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, | |
2834 | wxAuiNotebook::OnTabBeginDrag) | |
2835 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2836 | wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, | |
2837 | wxAuiNotebook::OnTabEndDrag) | |
2838 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2839 | wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, | |
2840 | wxAuiNotebook::OnTabCancelDrag) | |
2841 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2842 | wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, | |
2843 | wxAuiNotebook::OnTabDragMotion) | |
2844 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2845 | wxEVT_COMMAND_AUINOTEBOOK_BUTTON, | |
2846 | wxAuiNotebook::OnTabButton) | |
2847 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2848 | wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, | |
2849 | wxAuiNotebook::OnTabMiddleDown) | |
2850 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2851 | wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, | |
2852 | wxAuiNotebook::OnTabMiddleUp) | |
2853 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2854 | wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, | |
2855 | wxAuiNotebook::OnTabRightDown) | |
2856 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2857 | wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, | |
2858 | wxAuiNotebook::OnTabRightUp) | |
2859 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, | |
2860 | wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, | |
2861 | wxAuiNotebook::OnTabBgDClick) | |
2862 | EVT_NAVIGATION_KEY(wxAuiNotebook::OnNavigationKeyNotebook) | |
2863 | ||
2864 | #ifdef wxHAS_NATIVE_TAB_TRAVERSAL | |
2865 | WX_EVENT_TABLE_CONTROL_CONTAINER(wxAuiNotebook) | |
2866 | #else | |
2867 | // Avoid clash with container event handler functions | |
2868 | EVT_SET_FOCUS(wxAuiNotebook::OnFocus) | |
2869 | #endif | |
2870 | END_EVENT_TABLE() | |
2871 | ||
2872 | WX_DELEGATE_TO_CONTROL_CONTAINER(wxAuiNotebook, wxControl) | |
2873 | ||
2874 | wxAuiNotebook::wxAuiNotebook() | |
2875 | { | |
2876 | m_curpage = -1; | |
2877 | m_tab_id_counter = wxAuiBaseTabCtrlId; | |
2878 | m_dummy_wnd = NULL; | |
2879 | m_tab_ctrl_height = 20; | |
2880 | m_requested_bmp_size = wxDefaultSize; | |
2881 | m_requested_tabctrl_height = -1; | |
2882 | } | |
2883 | ||
2884 | wxAuiNotebook::wxAuiNotebook(wxWindow *parent, | |
2885 | wxWindowID id, | |
2886 | const wxPoint& pos, | |
2887 | const wxSize& size, | |
2888 | long style) : wxControl(parent, id, pos, size, style) | |
2889 | { | |
2890 | m_dummy_wnd = NULL; | |
2891 | m_requested_bmp_size = wxDefaultSize; | |
2892 | m_requested_tabctrl_height = -1; | |
2893 | InitNotebook(style); | |
2894 | } | |
2895 | ||
2896 | bool wxAuiNotebook::Create(wxWindow* parent, | |
2897 | wxWindowID id, | |
2898 | const wxPoint& pos, | |
2899 | const wxSize& size, | |
2900 | long style) | |
2901 | { | |
2902 | if (!wxControl::Create(parent, id, pos, size, style)) | |
2903 | return false; | |
2904 | ||
2905 | InitNotebook(style); | |
2906 | ||
2907 | return true; | |
2908 | } | |
2909 | ||
2910 | // InitNotebook() contains common initialization | |
2911 | // code called by all constructors | |
2912 | void wxAuiNotebook::InitNotebook(long style) | |
2913 | { | |
2914 | WX_INIT_CONTROL_CONTAINER(); | |
2915 | // SetCanFocus(false); | |
2916 | ||
2917 | SetName(wxT("wxAuiNotebook")); | |
2918 | m_curpage = -1; | |
2919 | m_tab_id_counter = wxAuiBaseTabCtrlId; | |
2920 | m_dummy_wnd = NULL; | |
2921 | m_flags = (unsigned int)style; | |
2922 | m_tab_ctrl_height = 20; | |
2923 | ||
2924 | m_normal_font = *wxNORMAL_FONT; | |
2925 | m_selected_font = *wxNORMAL_FONT; | |
2926 | m_selected_font.SetWeight(wxBOLD); | |
2927 | ||
2928 | SetArtProvider(new wxAuiDefaultTabArt); | |
2929 | ||
2930 | m_dummy_wnd = new wxWindow(this, wxID_ANY, wxPoint(0,0), wxSize(0,0)); | |
2931 | m_dummy_wnd->SetSize(200, 200); | |
2932 | m_dummy_wnd->Show(false); | |
2933 | ||
2934 | m_mgr.SetManagedWindow(this); | |
2935 | m_mgr.SetFlags(wxAUI_MGR_DEFAULT); | |
2936 | m_mgr.SetDockSizeConstraint(1.0, 1.0); // no dock size constraint | |
2937 | ||
2938 | m_mgr.AddPane(m_dummy_wnd, | |
2939 | wxAuiPaneInfo().Name(wxT("dummy")).Bottom().CaptionVisible(false).Show(false)); | |
2940 | ||
2941 | m_mgr.Update(); | |
2942 | } | |
2943 | ||
2944 | wxAuiNotebook::~wxAuiNotebook() | |
2945 | { | |
2946 | // Indicate we're deleting pages | |
2947 | SendDestroyEvent(); | |
2948 | ||
2949 | while ( GetPageCount() > 0 ) | |
2950 | DeletePage(0); | |
2951 | ||
2952 | m_mgr.UnInit(); | |
2953 | } | |
2954 | ||
2955 | void wxAuiNotebook::SetArtProvider(wxAuiTabArt* art) | |
2956 | { | |
2957 | m_tabs.SetArtProvider(art); | |
2958 | ||
2959 | // Update the height and do nothing else if it did something but otherwise | |
2960 | // (i.e. if the new art provider uses the same height as the old one) we | |
2961 | // need to manually set the art provider for all tabs ourselves. | |
2962 | if ( !UpdateTabCtrlHeight() ) | |
2963 | { | |
2964 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
2965 | const size_t pane_count = all_panes.GetCount(); | |
2966 | for (size_t i = 0; i < pane_count; ++i) | |
2967 | { | |
2968 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
2969 | if (pane.name == wxT("dummy")) | |
2970 | continue; | |
2971 | wxTabFrame* tab_frame = (wxTabFrame*)pane.window; | |
2972 | wxAuiTabCtrl* tabctrl = tab_frame->m_tabs; | |
2973 | tabctrl->SetArtProvider(art->Clone()); | |
2974 | } | |
2975 | } | |
2976 | } | |
2977 | ||
2978 | // SetTabCtrlHeight() is the highest-level override of the | |
2979 | // tab height. A call to this function effectively enforces a | |
2980 | // specified tab ctrl height, overriding all other considerations, | |
2981 | // such as text or bitmap height. It overrides any call to | |
2982 | // SetUniformBitmapSize(). Specifying a height of -1 reverts | |
2983 | // any previous call and returns to the default behaviour | |
2984 | ||
2985 | void wxAuiNotebook::SetTabCtrlHeight(int height) | |
2986 | { | |
2987 | m_requested_tabctrl_height = height; | |
2988 | ||
2989 | // if window is already initialized, recalculate the tab height | |
2990 | if (m_dummy_wnd) | |
2991 | { | |
2992 | UpdateTabCtrlHeight(); | |
2993 | } | |
2994 | } | |
2995 | ||
2996 | ||
2997 | // SetUniformBitmapSize() ensures that all tabs will have | |
2998 | // the same height, even if some tabs don't have bitmaps | |
2999 | // Passing wxDefaultSize to this function will instruct | |
3000 | // the control to use dynamic tab height-- so when a tab | |
3001 | // with a large bitmap is added, the tab ctrl's height will | |
3002 | // automatically increase to accommodate the bitmap | |
3003 | ||
3004 | void wxAuiNotebook::SetUniformBitmapSize(const wxSize& size) | |
3005 | { | |
3006 | m_requested_bmp_size = size; | |
3007 | ||
3008 | // if window is already initialized, recalculate the tab height | |
3009 | if (m_dummy_wnd) | |
3010 | { | |
3011 | UpdateTabCtrlHeight(); | |
3012 | } | |
3013 | } | |
3014 | ||
3015 | // UpdateTabCtrlHeight() does the actual tab resizing. It's meant | |
3016 | // to be used internally | |
3017 | bool wxAuiNotebook::UpdateTabCtrlHeight() | |
3018 | { | |
3019 | // get the tab ctrl height we will use | |
3020 | int height = CalculateTabCtrlHeight(); | |
3021 | ||
3022 | // if the tab control height needs to change, update | |
3023 | // all of our tab controls with the new height | |
3024 | if (m_tab_ctrl_height == height) | |
3025 | return false; | |
3026 | ||
3027 | wxAuiTabArt* art = m_tabs.GetArtProvider(); | |
3028 | ||
3029 | m_tab_ctrl_height = height; | |
3030 | ||
3031 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3032 | size_t i, pane_count = all_panes.GetCount(); | |
3033 | for (i = 0; i < pane_count; ++i) | |
3034 | { | |
3035 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
3036 | if (pane.name == wxT("dummy")) | |
3037 | continue; | |
3038 | wxTabFrame* tab_frame = (wxTabFrame*)pane.window; | |
3039 | wxAuiTabCtrl* tabctrl = tab_frame->m_tabs; | |
3040 | tab_frame->SetTabCtrlHeight(m_tab_ctrl_height); | |
3041 | tabctrl->SetArtProvider(art->Clone()); | |
3042 | tab_frame->DoSizing(); | |
3043 | } | |
3044 | ||
3045 | return true; | |
3046 | } | |
3047 | ||
3048 | void wxAuiNotebook::UpdateHintWindowSize() | |
3049 | { | |
3050 | wxSize size = CalculateNewSplitSize(); | |
3051 | ||
3052 | // the placeholder hint window should be set to this size | |
3053 | wxAuiPaneInfo& info = m_mgr.GetPane(wxT("dummy")); | |
3054 | if (info.IsOk()) | |
3055 | { | |
3056 | info.MinSize(size); | |
3057 | info.BestSize(size); | |
3058 | m_dummy_wnd->SetSize(size); | |
3059 | } | |
3060 | } | |
3061 | ||
3062 | ||
3063 | // calculates the size of the new split | |
3064 | wxSize wxAuiNotebook::CalculateNewSplitSize() | |
3065 | { | |
3066 | // count number of tab controls | |
3067 | int tab_ctrl_count = 0; | |
3068 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3069 | size_t i, pane_count = all_panes.GetCount(); | |
3070 | for (i = 0; i < pane_count; ++i) | |
3071 | { | |
3072 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
3073 | if (pane.name == wxT("dummy")) | |
3074 | continue; | |
3075 | tab_ctrl_count++; | |
3076 | } | |
3077 | ||
3078 | wxSize new_split_size; | |
3079 | ||
3080 | // if there is only one tab control, the first split | |
3081 | // should happen around the middle | |
3082 | if (tab_ctrl_count < 2) | |
3083 | { | |
3084 | new_split_size = GetClientSize(); | |
3085 | new_split_size.x /= 2; | |
3086 | new_split_size.y /= 2; | |
3087 | } | |
3088 | else | |
3089 | { | |
3090 | // this is in place of a more complicated calculation | |
3091 | // that needs to be implemented | |
3092 | new_split_size = wxSize(180,180); | |
3093 | } | |
3094 | ||
3095 | return new_split_size; | |
3096 | } | |
3097 | ||
3098 | int wxAuiNotebook::CalculateTabCtrlHeight() | |
3099 | { | |
3100 | // if a fixed tab ctrl height is specified, | |
3101 | // just return that instead of calculating a | |
3102 | // tab height | |
3103 | if (m_requested_tabctrl_height != -1) | |
3104 | return m_requested_tabctrl_height; | |
3105 | ||
3106 | // find out new best tab height | |
3107 | wxAuiTabArt* art = m_tabs.GetArtProvider(); | |
3108 | ||
3109 | return art->GetBestTabCtrlSize(this, | |
3110 | m_tabs.GetPages(), | |
3111 | m_requested_bmp_size); | |
3112 | } | |
3113 | ||
3114 | ||
3115 | wxAuiTabArt* wxAuiNotebook::GetArtProvider() const | |
3116 | { | |
3117 | return m_tabs.GetArtProvider(); | |
3118 | } | |
3119 | ||
3120 | void wxAuiNotebook::SetWindowStyleFlag(long style) | |
3121 | { | |
3122 | wxControl::SetWindowStyleFlag(style); | |
3123 | ||
3124 | m_flags = (unsigned int)style; | |
3125 | ||
3126 | // if the control is already initialized | |
3127 | if (m_mgr.GetManagedWindow() == (wxWindow*)this) | |
3128 | { | |
3129 | // let all of the tab children know about the new style | |
3130 | ||
3131 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3132 | size_t i, pane_count = all_panes.GetCount(); | |
3133 | for (i = 0; i < pane_count; ++i) | |
3134 | { | |
3135 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
3136 | if (pane.name == wxT("dummy")) | |
3137 | continue; | |
3138 | wxTabFrame* tabframe = (wxTabFrame*)pane.window; | |
3139 | wxAuiTabCtrl* tabctrl = tabframe->m_tabs; | |
3140 | tabctrl->SetFlags(m_flags); | |
3141 | tabframe->DoSizing(); | |
3142 | tabctrl->Refresh(); | |
3143 | tabctrl->Update(); | |
3144 | } | |
3145 | } | |
3146 | } | |
3147 | ||
3148 | ||
3149 | bool wxAuiNotebook::AddPage(wxWindow* page, | |
3150 | const wxString& caption, | |
3151 | bool select, | |
3152 | const wxBitmap& bitmap) | |
3153 | { | |
3154 | return InsertPage(GetPageCount(), page, caption, select, bitmap); | |
3155 | } | |
3156 | ||
3157 | bool wxAuiNotebook::InsertPage(size_t page_idx, | |
3158 | wxWindow* page, | |
3159 | const wxString& caption, | |
3160 | bool select, | |
3161 | const wxBitmap& bitmap) | |
3162 | { | |
3163 | wxASSERT_MSG(page, wxT("page pointer must be non-NULL")); | |
3164 | if (!page) | |
3165 | return false; | |
3166 | ||
3167 | page->Reparent(this); | |
3168 | ||
3169 | wxAuiNotebookPage info; | |
3170 | info.window = page; | |
3171 | info.caption = caption; | |
3172 | info.bitmap = bitmap; | |
3173 | info.active = false; | |
3174 | ||
3175 | // if there are currently no tabs, the first added | |
3176 | // tab must be active | |
3177 | if (m_tabs.GetPageCount() == 0) | |
3178 | info.active = true; | |
3179 | ||
3180 | m_tabs.InsertPage(page, info, page_idx); | |
3181 | ||
3182 | // if that was the first page added, even if | |
3183 | // select is false, it must become the "current page" | |
3184 | // (though no select events will be fired) | |
3185 | if (!select && m_tabs.GetPageCount() == 1) | |
3186 | select = true; | |
3187 | //m_curpage = GetPageIndex(page); | |
3188 | ||
3189 | wxAuiTabCtrl* active_tabctrl = GetActiveTabCtrl(); | |
3190 | if (page_idx >= active_tabctrl->GetPageCount()) | |
3191 | active_tabctrl->AddPage(page, info); | |
3192 | else | |
3193 | active_tabctrl->InsertPage(page, info, page_idx); | |
3194 | ||
3195 | UpdateTabCtrlHeight(); | |
3196 | DoSizing(); | |
3197 | active_tabctrl->DoShowHide(); | |
3198 | ||
3199 | // adjust selected index | |
3200 | if(m_curpage >= (int) page_idx) | |
3201 | m_curpage++; | |
3202 | ||
3203 | if (select) | |
3204 | { | |
3205 | SetSelectionToWindow(page); | |
3206 | } | |
3207 | ||
3208 | return true; | |
3209 | } | |
3210 | ||
3211 | ||
3212 | // DeletePage() removes a tab from the multi-notebook, | |
3213 | // and destroys the window as well | |
3214 | bool wxAuiNotebook::DeletePage(size_t page_idx) | |
3215 | { | |
3216 | if (page_idx >= m_tabs.GetPageCount()) | |
3217 | return false; | |
3218 | ||
3219 | wxWindow* wnd = m_tabs.GetWindowFromIdx(page_idx); | |
3220 | ||
3221 | // hide the window in advance, as this will | |
3222 | // prevent flicker | |
3223 | ShowWnd(wnd, false); | |
3224 | ||
3225 | if (!RemovePage(page_idx)) | |
3226 | return false; | |
3227 | ||
3228 | #if wxUSE_MDI | |
3229 | // actually destroy the window now | |
3230 | if (wnd->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) | |
3231 | { | |
3232 | // delete the child frame with pending delete, as is | |
3233 | // customary with frame windows | |
3234 | if (!wxPendingDelete.Member(wnd)) | |
3235 | wxPendingDelete.Append(wnd); | |
3236 | } | |
3237 | else | |
3238 | #endif | |
3239 | { | |
3240 | wnd->Destroy(); | |
3241 | } | |
3242 | ||
3243 | return true; | |
3244 | } | |
3245 | ||
3246 | ||
3247 | ||
3248 | // RemovePage() removes a tab from the multi-notebook, | |
3249 | // but does not destroy the window | |
3250 | bool wxAuiNotebook::RemovePage(size_t page_idx) | |
3251 | { | |
3252 | // save active window pointer | |
3253 | wxWindow* active_wnd = NULL; | |
3254 | if (m_curpage >= 0) | |
3255 | active_wnd = m_tabs.GetWindowFromIdx(m_curpage); | |
3256 | ||
3257 | // save pointer of window being deleted | |
3258 | wxWindow* wnd = m_tabs.GetWindowFromIdx(page_idx); | |
3259 | wxWindow* new_active = NULL; | |
3260 | ||
3261 | // make sure we found the page | |
3262 | if (!wnd) | |
3263 | return false; | |
3264 | ||
3265 | // find out which onscreen tab ctrl owns this tab | |
3266 | wxAuiTabCtrl* ctrl; | |
3267 | int ctrl_idx; | |
3268 | if (!FindTab(wnd, &ctrl, &ctrl_idx)) | |
3269 | return false; | |
3270 | ||
3271 | bool is_curpage = (m_curpage == (int)page_idx); | |
3272 | bool is_active_in_split = ctrl->GetPage(ctrl_idx).active; | |
3273 | ||
3274 | ||
3275 | // remove the tab from main catalog | |
3276 | if (!m_tabs.RemovePage(wnd)) | |
3277 | return false; | |
3278 | ||
3279 | // remove the tab from the onscreen tab ctrl | |
3280 | ctrl->RemovePage(wnd); | |
3281 | ||
3282 | if (is_active_in_split) | |
3283 | { | |
3284 | int ctrl_new_page_count = (int)ctrl->GetPageCount(); | |
3285 | ||
3286 | if (ctrl_idx >= ctrl_new_page_count) | |
3287 | ctrl_idx = ctrl_new_page_count-1; | |
3288 | ||
3289 | if (ctrl_idx >= 0 && ctrl_idx < (int)ctrl->GetPageCount()) | |
3290 | { | |
3291 | // set new page as active in the tab split | |
3292 | ctrl->SetActivePage(ctrl_idx); | |
3293 | ||
3294 | // if the page deleted was the current page for the | |
3295 | // entire tab control, then record the window | |
3296 | // pointer of the new active page for activation | |
3297 | if (is_curpage) | |
3298 | { | |
3299 | new_active = ctrl->GetWindowFromIdx(ctrl_idx); | |
3300 | } | |
3301 | } | |
3302 | } | |
3303 | else | |
3304 | { | |
3305 | // we are not deleting the active page, so keep it the same | |
3306 | new_active = active_wnd; | |
3307 | } | |
3308 | ||
3309 | ||
3310 | if (!new_active) | |
3311 | { | |
3312 | // we haven't yet found a new page to active, | |
3313 | // so select the next page from the main tab | |
3314 | // catalogue | |
3315 | ||
3316 | if (page_idx < m_tabs.GetPageCount()) | |
3317 | { | |
3318 | new_active = m_tabs.GetPage(page_idx).window; | |
3319 | } | |
3320 | ||
3321 | if (!new_active && m_tabs.GetPageCount() > 0) | |
3322 | { | |
3323 | new_active = m_tabs.GetPage(0).window; | |
3324 | } | |
3325 | } | |
3326 | ||
3327 | ||
3328 | RemoveEmptyTabFrames(); | |
3329 | ||
3330 | m_curpage = wxNOT_FOUND; | |
3331 | ||
3332 | // set new active pane unless we're being destroyed anyhow | |
3333 | if (new_active && !m_isBeingDeleted) | |
3334 | SetSelectionToWindow(new_active); | |
3335 | ||
3336 | return true; | |
3337 | } | |
3338 | ||
3339 | // GetPageIndex() returns the index of the page, or -1 if the | |
3340 | // page could not be located in the notebook | |
3341 | int wxAuiNotebook::GetPageIndex(wxWindow* page_wnd) const | |
3342 | { | |
3343 | return m_tabs.GetIdxFromWindow(page_wnd); | |
3344 | } | |
3345 | ||
3346 | ||
3347 | ||
3348 | // SetPageText() changes the tab caption of the specified page | |
3349 | bool wxAuiNotebook::SetPageText(size_t page_idx, const wxString& text) | |
3350 | { | |
3351 | if (page_idx >= m_tabs.GetPageCount()) | |
3352 | return false; | |
3353 | ||
3354 | // update our own tab catalog | |
3355 | wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
3356 | page_info.caption = text; | |
3357 | ||
3358 | // update what's on screen | |
3359 | wxAuiTabCtrl* ctrl; | |
3360 | int ctrl_idx; | |
3361 | if (FindTab(page_info.window, &ctrl, &ctrl_idx)) | |
3362 | { | |
3363 | wxAuiNotebookPage& info = ctrl->GetPage(ctrl_idx); | |
3364 | info.caption = text; | |
3365 | ctrl->Refresh(); | |
3366 | ctrl->Update(); | |
3367 | } | |
3368 | ||
3369 | return true; | |
3370 | } | |
3371 | ||
3372 | // returns the page caption | |
3373 | wxString wxAuiNotebook::GetPageText(size_t page_idx) const | |
3374 | { | |
3375 | if (page_idx >= m_tabs.GetPageCount()) | |
3376 | return wxEmptyString; | |
3377 | ||
3378 | // update our own tab catalog | |
3379 | const wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
3380 | return page_info.caption; | |
3381 | } | |
3382 | ||
3383 | bool wxAuiNotebook::SetPageBitmap(size_t page_idx, const wxBitmap& bitmap) | |
3384 | { | |
3385 | if (page_idx >= m_tabs.GetPageCount()) | |
3386 | return false; | |
3387 | ||
3388 | // update our own tab catalog | |
3389 | wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
3390 | page_info.bitmap = bitmap; | |
3391 | ||
3392 | // tab height might have changed | |
3393 | UpdateTabCtrlHeight(); | |
3394 | ||
3395 | // update what's on screen | |
3396 | wxAuiTabCtrl* ctrl; | |
3397 | int ctrl_idx; | |
3398 | if (FindTab(page_info.window, &ctrl, &ctrl_idx)) | |
3399 | { | |
3400 | wxAuiNotebookPage& info = ctrl->GetPage(ctrl_idx); | |
3401 | info.bitmap = bitmap; | |
3402 | ctrl->Refresh(); | |
3403 | ctrl->Update(); | |
3404 | } | |
3405 | ||
3406 | return true; | |
3407 | } | |
3408 | ||
3409 | // returns the page bitmap | |
3410 | wxBitmap wxAuiNotebook::GetPageBitmap(size_t page_idx) const | |
3411 | { | |
3412 | if (page_idx >= m_tabs.GetPageCount()) | |
3413 | return wxBitmap(); | |
3414 | ||
3415 | // update our own tab catalog | |
3416 | const wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
3417 | return page_info.bitmap; | |
3418 | } | |
3419 | ||
3420 | // GetSelection() returns the index of the currently active page | |
3421 | int wxAuiNotebook::GetSelection() const | |
3422 | { | |
3423 | return m_curpage; | |
3424 | } | |
3425 | ||
3426 | // SetSelection() sets the currently active page | |
3427 | size_t wxAuiNotebook::SetSelection(size_t new_page) | |
3428 | { | |
3429 | wxWindow* wnd = m_tabs.GetWindowFromIdx(new_page); | |
3430 | if (!wnd) | |
3431 | return m_curpage; | |
3432 | ||
3433 | // don't change the page unless necessary; | |
3434 | // however, clicking again on a tab should give it the focus. | |
3435 | if ((int)new_page == m_curpage) | |
3436 | { | |
3437 | wxAuiTabCtrl* ctrl; | |
3438 | int ctrl_idx; | |
3439 | if (FindTab(wnd, &ctrl, &ctrl_idx)) | |
3440 | { | |
3441 | if (FindFocus() != ctrl) | |
3442 | ctrl->SetFocus(); | |
3443 | } | |
3444 | return m_curpage; | |
3445 | } | |
3446 | ||
3447 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
3448 | evt.SetSelection(new_page); | |
3449 | evt.SetOldSelection(m_curpage); | |
3450 | evt.SetEventObject(this); | |
3451 | if (!GetEventHandler()->ProcessEvent(evt) || evt.IsAllowed()) | |
3452 | { | |
3453 | int old_curpage = m_curpage; | |
3454 | m_curpage = new_page; | |
3455 | ||
3456 | // program allows the page change | |
3457 | evt.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED); | |
3458 | (void)GetEventHandler()->ProcessEvent(evt); | |
3459 | ||
3460 | ||
3461 | wxAuiTabCtrl* ctrl; | |
3462 | int ctrl_idx; | |
3463 | if (FindTab(wnd, &ctrl, &ctrl_idx)) | |
3464 | { | |
3465 | m_tabs.SetActivePage(wnd); | |
3466 | ||
3467 | ctrl->SetActivePage(ctrl_idx); | |
3468 | DoSizing(); | |
3469 | ctrl->DoShowHide(); | |
3470 | ||
3471 | ctrl->MakeTabVisible(ctrl_idx, ctrl); | |
3472 | ||
3473 | // set fonts | |
3474 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3475 | size_t i, pane_count = all_panes.GetCount(); | |
3476 | for (i = 0; i < pane_count; ++i) | |
3477 | { | |
3478 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
3479 | if (pane.name == wxT("dummy")) | |
3480 | continue; | |
3481 | wxAuiTabCtrl* tabctrl = ((wxTabFrame*)pane.window)->m_tabs; | |
3482 | if (tabctrl != ctrl) | |
3483 | tabctrl->SetSelectedFont(m_normal_font); | |
3484 | else | |
3485 | tabctrl->SetSelectedFont(m_selected_font); | |
3486 | tabctrl->Refresh(); | |
3487 | } | |
3488 | ||
3489 | // Set the focus to the page if we're not currently focused on the tab. | |
3490 | // This is Firefox-like behaviour. | |
3491 | if (wnd->IsShownOnScreen() && FindFocus() != ctrl) | |
3492 | wnd->SetFocus(); | |
3493 | ||
3494 | return old_curpage; | |
3495 | } | |
3496 | } | |
3497 | ||
3498 | return m_curpage; | |
3499 | } | |
3500 | ||
3501 | void wxAuiNotebook::SetSelectionToWindow(wxWindow *win) | |
3502 | { | |
3503 | const int idx = m_tabs.GetIdxFromWindow(win); | |
3504 | wxCHECK_RET( idx != wxNOT_FOUND, wxT("invalid notebook page") ); | |
3505 | ||
3506 | ||
3507 | // since a tab was clicked, let the parent know that we received | |
3508 | // the focus, even if we will assign that focus immediately | |
3509 | // to the child tab in the SetSelection call below | |
3510 | // (the child focus event will also let wxAuiManager, if any, | |
3511 | // know that the notebook control has been activated) | |
3512 | ||
3513 | wxWindow* parent = GetParent(); | |
3514 | if (parent) | |
3515 | { | |
3516 | wxChildFocusEvent eventFocus(this); | |
3517 | parent->GetEventHandler()->ProcessEvent(eventFocus); | |
3518 | } | |
3519 | ||
3520 | ||
3521 | SetSelection(idx); | |
3522 | } | |
3523 | ||
3524 | // GetPageCount() returns the total number of | |
3525 | // pages managed by the multi-notebook | |
3526 | size_t wxAuiNotebook::GetPageCount() const | |
3527 | { | |
3528 | return m_tabs.GetPageCount(); | |
3529 | } | |
3530 | ||
3531 | // GetPage() returns the wxWindow pointer of the | |
3532 | // specified page | |
3533 | wxWindow* wxAuiNotebook::GetPage(size_t page_idx) const | |
3534 | { | |
3535 | wxASSERT(page_idx < m_tabs.GetPageCount()); | |
3536 | ||
3537 | return m_tabs.GetWindowFromIdx(page_idx); | |
3538 | } | |
3539 | ||
3540 | // DoSizing() performs all sizing operations in each tab control | |
3541 | void wxAuiNotebook::DoSizing() | |
3542 | { | |
3543 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3544 | size_t i, pane_count = all_panes.GetCount(); | |
3545 | for (i = 0; i < pane_count; ++i) | |
3546 | { | |
3547 | if (all_panes.Item(i).name == wxT("dummy")) | |
3548 | continue; | |
3549 | ||
3550 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; | |
3551 | tabframe->DoSizing(); | |
3552 | } | |
3553 | } | |
3554 | ||
3555 | // GetActiveTabCtrl() returns the active tab control. It is | |
3556 | // called to determine which control gets new windows being added | |
3557 | wxAuiTabCtrl* wxAuiNotebook::GetActiveTabCtrl() | |
3558 | { | |
3559 | if (m_curpage >= 0 && m_curpage < (int)m_tabs.GetPageCount()) | |
3560 | { | |
3561 | wxAuiTabCtrl* ctrl; | |
3562 | int idx; | |
3563 | ||
3564 | // find the tab ctrl with the current page | |
3565 | if (FindTab(m_tabs.GetPage(m_curpage).window, | |
3566 | &ctrl, &idx)) | |
3567 | { | |
3568 | return ctrl; | |
3569 | } | |
3570 | } | |
3571 | ||
3572 | // no current page, just find the first tab ctrl | |
3573 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3574 | size_t i, pane_count = all_panes.GetCount(); | |
3575 | for (i = 0; i < pane_count; ++i) | |
3576 | { | |
3577 | if (all_panes.Item(i).name == wxT("dummy")) | |
3578 | continue; | |
3579 | ||
3580 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; | |
3581 | return tabframe->m_tabs; | |
3582 | } | |
3583 | ||
3584 | // If there is no tabframe at all, create one | |
3585 | wxTabFrame* tabframe = new wxTabFrame; | |
3586 | tabframe->SetTabCtrlHeight(m_tab_ctrl_height); | |
3587 | tabframe->m_tabs = new wxAuiTabCtrl(this, | |
3588 | m_tab_id_counter++, | |
3589 | wxDefaultPosition, | |
3590 | wxDefaultSize, | |
3591 | wxNO_BORDER|wxWANTS_CHARS); | |
3592 | tabframe->m_tabs->SetFlags(m_flags); | |
3593 | tabframe->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); | |
3594 | m_mgr.AddPane(tabframe, | |
3595 | wxAuiPaneInfo().Center().CaptionVisible(false)); | |
3596 | ||
3597 | m_mgr.Update(); | |
3598 | ||
3599 | return tabframe->m_tabs; | |
3600 | } | |
3601 | ||
3602 | // FindTab() finds the tab control that currently contains the window as well | |
3603 | // as the index of the window in the tab control. It returns true if the | |
3604 | // window was found, otherwise false. | |
3605 | bool wxAuiNotebook::FindTab(wxWindow* page, wxAuiTabCtrl** ctrl, int* idx) | |
3606 | { | |
3607 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3608 | size_t i, pane_count = all_panes.GetCount(); | |
3609 | for (i = 0; i < pane_count; ++i) | |
3610 | { | |
3611 | if (all_panes.Item(i).name == wxT("dummy")) | |
3612 | continue; | |
3613 | ||
3614 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; | |
3615 | ||
3616 | int page_idx = tabframe->m_tabs->GetIdxFromWindow(page); | |
3617 | if (page_idx != -1) | |
3618 | { | |
3619 | *ctrl = tabframe->m_tabs; | |
3620 | *idx = page_idx; | |
3621 | return true; | |
3622 | } | |
3623 | } | |
3624 | ||
3625 | return false; | |
3626 | } | |
3627 | ||
3628 | void wxAuiNotebook::Split(size_t page, int direction) | |
3629 | { | |
3630 | wxSize cli_size = GetClientSize(); | |
3631 | ||
3632 | // get the page's window pointer | |
3633 | wxWindow* wnd = GetPage(page); | |
3634 | if (!wnd) | |
3635 | return; | |
3636 | ||
3637 | // notebooks with 1 or less pages can't be split | |
3638 | if (GetPageCount() < 2) | |
3639 | return; | |
3640 | ||
3641 | // find out which tab control the page currently belongs to | |
3642 | wxAuiTabCtrl *src_tabs, *dest_tabs; | |
3643 | int src_idx = -1; | |
3644 | src_tabs = NULL; | |
3645 | if (!FindTab(wnd, &src_tabs, &src_idx)) | |
3646 | return; | |
3647 | if (!src_tabs || src_idx == -1) | |
3648 | return; | |
3649 | ||
3650 | // choose a split size | |
3651 | wxSize split_size; | |
3652 | if (GetPageCount() > 2) | |
3653 | { | |
3654 | split_size = CalculateNewSplitSize(); | |
3655 | } | |
3656 | else | |
3657 | { | |
3658 | // because there are two panes, always split them | |
3659 | // equally | |
3660 | split_size = GetClientSize(); | |
3661 | split_size.x /= 2; | |
3662 | split_size.y /= 2; | |
3663 | } | |
3664 | ||
3665 | ||
3666 | // create a new tab frame | |
3667 | wxTabFrame* new_tabs = new wxTabFrame; | |
3668 | new_tabs->m_rect = wxRect(wxPoint(0,0), split_size); | |
3669 | new_tabs->SetTabCtrlHeight(m_tab_ctrl_height); | |
3670 | new_tabs->m_tabs = new wxAuiTabCtrl(this, | |
3671 | m_tab_id_counter++, | |
3672 | wxDefaultPosition, | |
3673 | wxDefaultSize, | |
3674 | wxNO_BORDER|wxWANTS_CHARS); | |
3675 | new_tabs->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); | |
3676 | new_tabs->m_tabs->SetFlags(m_flags); | |
3677 | dest_tabs = new_tabs->m_tabs; | |
3678 | ||
3679 | // create a pane info structure with the information | |
3680 | // about where the pane should be added | |
3681 | wxAuiPaneInfo pane_info = wxAuiPaneInfo().Bottom().CaptionVisible(false); | |
3682 | wxPoint mouse_pt; | |
3683 | ||
3684 | if (direction == wxLEFT) | |
3685 | { | |
3686 | pane_info.Left(); | |
3687 | mouse_pt = wxPoint(0, cli_size.y/2); | |
3688 | } | |
3689 | else if (direction == wxRIGHT) | |
3690 | { | |
3691 | pane_info.Right(); | |
3692 | mouse_pt = wxPoint(cli_size.x, cli_size.y/2); | |
3693 | } | |
3694 | else if (direction == wxTOP) | |
3695 | { | |
3696 | pane_info.Top(); | |
3697 | mouse_pt = wxPoint(cli_size.x/2, 0); | |
3698 | } | |
3699 | else if (direction == wxBOTTOM) | |
3700 | { | |
3701 | pane_info.Bottom(); | |
3702 | mouse_pt = wxPoint(cli_size.x/2, cli_size.y); | |
3703 | } | |
3704 | ||
3705 | m_mgr.AddPane(new_tabs, pane_info, mouse_pt); | |
3706 | m_mgr.Update(); | |
3707 | ||
3708 | // remove the page from the source tabs | |
3709 | wxAuiNotebookPage page_info = src_tabs->GetPage(src_idx); | |
3710 | page_info.active = false; | |
3711 | src_tabs->RemovePage(page_info.window); | |
3712 | if (src_tabs->GetPageCount() > 0) | |
3713 | { | |
3714 | src_tabs->SetActivePage((size_t)0); | |
3715 | src_tabs->DoShowHide(); | |
3716 | src_tabs->Refresh(); | |
3717 | } | |
3718 | ||
3719 | ||
3720 | // add the page to the destination tabs | |
3721 | dest_tabs->InsertPage(page_info.window, page_info, 0); | |
3722 | ||
3723 | if (src_tabs->GetPageCount() == 0) | |
3724 | { | |
3725 | RemoveEmptyTabFrames(); | |
3726 | } | |
3727 | ||
3728 | DoSizing(); | |
3729 | dest_tabs->DoShowHide(); | |
3730 | dest_tabs->Refresh(); | |
3731 | ||
3732 | // force the set selection function reset the selection | |
3733 | m_curpage = -1; | |
3734 | ||
3735 | // set the active page to the one we just split off | |
3736 | SetSelectionToPage(page_info); | |
3737 | ||
3738 | UpdateHintWindowSize(); | |
3739 | } | |
3740 | ||
3741 | ||
3742 | void wxAuiNotebook::OnSize(wxSizeEvent& evt) | |
3743 | { | |
3744 | UpdateHintWindowSize(); | |
3745 | ||
3746 | evt.Skip(); | |
3747 | } | |
3748 | ||
3749 | void wxAuiNotebook::OnTabClicked(wxAuiNotebookEvent& evt) | |
3750 | { | |
3751 | wxAuiTabCtrl* ctrl = (wxAuiTabCtrl*)evt.GetEventObject(); | |
3752 | wxASSERT(ctrl != NULL); | |
3753 | ||
3754 | wxWindow* wnd = ctrl->GetWindowFromIdx(evt.GetSelection()); | |
3755 | wxASSERT(wnd != NULL); | |
3756 | ||
3757 | SetSelectionToWindow(wnd); | |
3758 | } | |
3759 | ||
3760 | void wxAuiNotebook::OnTabBgDClick(wxAuiNotebookEvent& WXUNUSED(evt)) | |
3761 | { | |
3762 | // notify owner that the tabbar background has been double-clicked | |
3763 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, m_windowId); | |
3764 | e.SetEventObject(this); | |
3765 | GetEventHandler()->ProcessEvent(e); | |
3766 | } | |
3767 | ||
3768 | void wxAuiNotebook::OnTabBeginDrag(wxAuiNotebookEvent&) | |
3769 | { | |
3770 | m_last_drag_x = 0; | |
3771 | } | |
3772 | ||
3773 | void wxAuiNotebook::OnTabDragMotion(wxAuiNotebookEvent& evt) | |
3774 | { | |
3775 | wxPoint screen_pt = ::wxGetMousePosition(); | |
3776 | wxPoint client_pt = ScreenToClient(screen_pt); | |
3777 | wxPoint zero(0,0); | |
3778 | ||
3779 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
3780 | wxAuiTabCtrl* dest_tabs = GetTabCtrlFromPoint(client_pt); | |
3781 | ||
3782 | if (dest_tabs == src_tabs) | |
3783 | { | |
3784 | if (src_tabs) | |
3785 | { | |
3786 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
3787 | } | |
3788 | ||
3789 | // always hide the hint for inner-tabctrl drag | |
3790 | m_mgr.HideHint(); | |
3791 | ||
3792 | // if tab moving is not allowed, leave | |
3793 | if (!(m_flags & wxAUI_NB_TAB_MOVE)) | |
3794 | { | |
3795 | return; | |
3796 | } | |
3797 | ||
3798 | wxPoint pt = dest_tabs->ScreenToClient(screen_pt); | |
3799 | wxWindow* dest_location_tab; | |
3800 | ||
3801 | // this is an inner-tab drag/reposition | |
3802 | if (dest_tabs->TabHitTest(pt.x, pt.y, &dest_location_tab)) | |
3803 | { | |
3804 | int src_idx = evt.GetSelection(); | |
3805 | int dest_idx = dest_tabs->GetIdxFromWindow(dest_location_tab); | |
3806 | ||
3807 | // prevent jumpy drag | |
3808 | if ((src_idx == dest_idx) || dest_idx == -1 || | |
3809 | (src_idx > dest_idx && m_last_drag_x <= pt.x) || | |
3810 | (src_idx < dest_idx && m_last_drag_x >= pt.x)) | |
3811 | { | |
3812 | m_last_drag_x = pt.x; | |
3813 | return; | |
3814 | } | |
3815 | ||
3816 | ||
3817 | wxWindow* src_tab = dest_tabs->GetWindowFromIdx(src_idx); | |
3818 | dest_tabs->MovePage(src_tab, dest_idx); | |
3819 | dest_tabs->SetActivePage((size_t)dest_idx); | |
3820 | dest_tabs->DoShowHide(); | |
3821 | dest_tabs->Refresh(); | |
3822 | m_last_drag_x = pt.x; | |
3823 | ||
3824 | } | |
3825 | ||
3826 | return; | |
3827 | } | |
3828 | ||
3829 | ||
3830 | // if external drag is allowed, check if the tab is being dragged | |
3831 | // over a different wxAuiNotebook control | |
3832 | if (m_flags & wxAUI_NB_TAB_EXTERNAL_MOVE) | |
3833 | { | |
3834 | wxWindow* tab_ctrl = ::wxFindWindowAtPoint(screen_pt); | |
3835 | ||
3836 | // if we aren't over any window, stop here | |
3837 | if (!tab_ctrl) | |
3838 | return; | |
3839 | ||
3840 | // make sure we are not over the hint window | |
3841 | if (!tab_ctrl->IsKindOf(CLASSINFO(wxFrame))) | |
3842 | { | |
3843 | while (tab_ctrl) | |
3844 | { | |
3845 | if (tab_ctrl->IsKindOf(CLASSINFO(wxAuiTabCtrl))) | |
3846 | break; | |
3847 | tab_ctrl = tab_ctrl->GetParent(); | |
3848 | } | |
3849 | ||
3850 | if (tab_ctrl) | |
3851 | { | |
3852 | wxAuiNotebook* nb = (wxAuiNotebook*)tab_ctrl->GetParent(); | |
3853 | ||
3854 | if (nb != this) | |
3855 | { | |
3856 | wxRect hint_rect = tab_ctrl->GetClientRect(); | |
3857 | tab_ctrl->ClientToScreen(&hint_rect.x, &hint_rect.y); | |
3858 | m_mgr.ShowHint(hint_rect); | |
3859 | return; | |
3860 | } | |
3861 | } | |
3862 | } | |
3863 | else | |
3864 | { | |
3865 | if (!dest_tabs) | |
3866 | { | |
3867 | // we are either over a hint window, or not over a tab | |
3868 | // window, and there is no where to drag to, so exit | |
3869 | return; | |
3870 | } | |
3871 | } | |
3872 | } | |
3873 | ||
3874 | ||
3875 | // if there are less than two panes, split can't happen, so leave | |
3876 | if (m_tabs.GetPageCount() < 2) | |
3877 | return; | |
3878 | ||
3879 | // if tab moving is not allowed, leave | |
3880 | if (!(m_flags & wxAUI_NB_TAB_SPLIT)) | |
3881 | return; | |
3882 | ||
3883 | ||
3884 | if (src_tabs) | |
3885 | { | |
3886 | src_tabs->SetCursor(wxCursor(wxCURSOR_SIZING)); | |
3887 | } | |
3888 | ||
3889 | ||
3890 | if (dest_tabs) | |
3891 | { | |
3892 | wxRect hint_rect = dest_tabs->GetRect(); | |
3893 | ClientToScreen(&hint_rect.x, &hint_rect.y); | |
3894 | m_mgr.ShowHint(hint_rect); | |
3895 | } | |
3896 | else | |
3897 | { | |
3898 | m_mgr.DrawHintRect(m_dummy_wnd, client_pt, zero); | |
3899 | } | |
3900 | } | |
3901 | ||
3902 | ||
3903 | ||
3904 | void wxAuiNotebook::OnTabEndDrag(wxAuiNotebookEvent& evt) | |
3905 | { | |
3906 | m_mgr.HideHint(); | |
3907 | ||
3908 | ||
3909 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
3910 | wxCHECK_RET( src_tabs, wxT("no source object?") ); | |
3911 | ||
3912 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
3913 | ||
3914 | // get the mouse position, which will be used to determine the drop point | |
3915 | wxPoint mouse_screen_pt = ::wxGetMousePosition(); | |
3916 | wxPoint mouse_client_pt = ScreenToClient(mouse_screen_pt); | |
3917 | ||
3918 | ||
3919 | ||
3920 | // check for an external move | |
3921 | if (m_flags & wxAUI_NB_TAB_EXTERNAL_MOVE) | |
3922 | { | |
3923 | wxWindow* tab_ctrl = ::wxFindWindowAtPoint(mouse_screen_pt); | |
3924 | ||
3925 | while (tab_ctrl) | |
3926 | { | |
3927 | if (tab_ctrl->IsKindOf(CLASSINFO(wxAuiTabCtrl))) | |
3928 | break; | |
3929 | tab_ctrl = tab_ctrl->GetParent(); | |
3930 | } | |
3931 | ||
3932 | if (tab_ctrl) | |
3933 | { | |
3934 | wxAuiNotebook* nb = (wxAuiNotebook*)tab_ctrl->GetParent(); | |
3935 | ||
3936 | if (nb != this) | |
3937 | { | |
3938 | // find out from the destination control | |
3939 | // if it's ok to drop this tab here | |
3940 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, m_windowId); | |
3941 | e.SetSelection(evt.GetSelection()); | |
3942 | e.SetOldSelection(evt.GetSelection()); | |
3943 | e.SetEventObject(this); | |
3944 | e.SetDragSource(this); | |
3945 | e.Veto(); // dropping must be explicitly approved by control owner | |
3946 | ||
3947 | nb->GetEventHandler()->ProcessEvent(e); | |
3948 | ||
3949 | if (!e.IsAllowed()) | |
3950 | { | |
3951 | // no answer or negative answer | |
3952 | m_mgr.HideHint(); | |
3953 | return; | |
3954 | } | |
3955 | ||
3956 | // drop was allowed | |
3957 | int src_idx = evt.GetSelection(); | |
3958 | wxWindow* src_page = src_tabs->GetWindowFromIdx(src_idx); | |
3959 | ||
3960 | // Check that it's not an impossible parent relationship | |
3961 | wxWindow* p = nb; | |
3962 | while (p && !p->IsTopLevel()) | |
3963 | { | |
3964 | if (p == src_page) | |
3965 | { | |
3966 | return; | |
3967 | } | |
3968 | p = p->GetParent(); | |
3969 | } | |
3970 | ||
3971 | // get main index of the page | |
3972 | int main_idx = m_tabs.GetIdxFromWindow(src_page); | |
3973 | wxCHECK_RET( main_idx != wxNOT_FOUND, wxT("no source page?") ); | |
3974 | ||
3975 | ||
3976 | // make a copy of the page info | |
3977 | wxAuiNotebookPage page_info = m_tabs.GetPage(main_idx); | |
3978 | ||
3979 | // remove the page from the source notebook | |
3980 | RemovePage(main_idx); | |
3981 | ||
3982 | // reparent the page | |
3983 | src_page->Reparent(nb); | |
3984 | ||
3985 | ||
3986 | // found out the insert idx | |
3987 | wxAuiTabCtrl* dest_tabs = (wxAuiTabCtrl*)tab_ctrl; | |
3988 | wxPoint pt = dest_tabs->ScreenToClient(mouse_screen_pt); | |
3989 | ||
3990 | wxWindow* target = NULL; | |
3991 | int insert_idx = -1; | |
3992 | dest_tabs->TabHitTest(pt.x, pt.y, &target); | |
3993 | if (target) | |
3994 | { | |
3995 | insert_idx = dest_tabs->GetIdxFromWindow(target); | |
3996 | } | |
3997 | ||
3998 | ||
3999 | // add the page to the new notebook | |
4000 | if (insert_idx == -1) | |
4001 | insert_idx = dest_tabs->GetPageCount(); | |
4002 | dest_tabs->InsertPage(page_info.window, page_info, insert_idx); | |
4003 | nb->m_tabs.AddPage(page_info.window, page_info); | |
4004 | ||
4005 | nb->DoSizing(); | |
4006 | dest_tabs->DoShowHide(); | |
4007 | dest_tabs->Refresh(); | |
4008 | ||
4009 | // set the selection in the destination tab control | |
4010 | nb->SetSelectionToPage(page_info); | |
4011 | ||
4012 | // notify owner that the tab has been dragged | |
4013 | wxAuiNotebookEvent e2(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, m_windowId); | |
4014 | e2.SetSelection(evt.GetSelection()); | |
4015 | e2.SetOldSelection(evt.GetSelection()); | |
4016 | e2.SetEventObject(this); | |
4017 | GetEventHandler()->ProcessEvent(e2); | |
4018 | ||
4019 | return; | |
4020 | } | |
4021 | } | |
4022 | } | |
4023 | ||
4024 | ||
4025 | ||
4026 | ||
4027 | // only perform a tab split if it's allowed | |
4028 | wxAuiTabCtrl* dest_tabs = NULL; | |
4029 | ||
4030 | if ((m_flags & wxAUI_NB_TAB_SPLIT) && m_tabs.GetPageCount() >= 2) | |
4031 | { | |
4032 | // If the pointer is in an existing tab frame, do a tab insert | |
4033 | wxWindow* hit_wnd = ::wxFindWindowAtPoint(mouse_screen_pt); | |
4034 | wxTabFrame* tab_frame = (wxTabFrame*)GetTabFrameFromTabCtrl(hit_wnd); | |
4035 | int insert_idx = -1; | |
4036 | if (tab_frame) | |
4037 | { | |
4038 | dest_tabs = tab_frame->m_tabs; | |
4039 | ||
4040 | if (dest_tabs == src_tabs) | |
4041 | return; | |
4042 | ||
4043 | ||
4044 | wxPoint pt = dest_tabs->ScreenToClient(mouse_screen_pt); | |
4045 | wxWindow* target = NULL; | |
4046 | dest_tabs->TabHitTest(pt.x, pt.y, &target); | |
4047 | if (target) | |
4048 | { | |
4049 | insert_idx = dest_tabs->GetIdxFromWindow(target); | |
4050 | } | |
4051 | } | |
4052 | else | |
4053 | { | |
4054 | wxPoint zero(0,0); | |
4055 | wxRect rect = m_mgr.CalculateHintRect(m_dummy_wnd, | |
4056 | mouse_client_pt, | |
4057 | zero); | |
4058 | if (rect.IsEmpty()) | |
4059 | { | |
4060 | // there is no suitable drop location here, exit out | |
4061 | return; | |
4062 | } | |
4063 | ||
4064 | // If there is no tabframe at all, create one | |
4065 | wxTabFrame* new_tabs = new wxTabFrame; | |
4066 | new_tabs->m_rect = wxRect(wxPoint(0,0), CalculateNewSplitSize()); | |
4067 | new_tabs->SetTabCtrlHeight(m_tab_ctrl_height); | |
4068 | new_tabs->m_tabs = new wxAuiTabCtrl(this, | |
4069 | m_tab_id_counter++, | |
4070 | wxDefaultPosition, | |
4071 | wxDefaultSize, | |
4072 | wxNO_BORDER|wxWANTS_CHARS); | |
4073 | new_tabs->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); | |
4074 | new_tabs->m_tabs->SetFlags(m_flags); | |
4075 | ||
4076 | m_mgr.AddPane(new_tabs, | |
4077 | wxAuiPaneInfo().Bottom().CaptionVisible(false), | |
4078 | mouse_client_pt); | |
4079 | m_mgr.Update(); | |
4080 | dest_tabs = new_tabs->m_tabs; | |
4081 | } | |
4082 | ||
4083 | ||
4084 | ||
4085 | // remove the page from the source tabs | |
4086 | wxAuiNotebookPage page_info = src_tabs->GetPage(evt.GetSelection()); | |
4087 | page_info.active = false; | |
4088 | src_tabs->RemovePage(page_info.window); | |
4089 | if (src_tabs->GetPageCount() > 0) | |
4090 | { | |
4091 | src_tabs->SetActivePage((size_t)0); | |
4092 | src_tabs->DoShowHide(); | |
4093 | src_tabs->Refresh(); | |
4094 | } | |
4095 | ||
4096 | ||
4097 | ||
4098 | // add the page to the destination tabs | |
4099 | if (insert_idx == -1) | |
4100 | insert_idx = dest_tabs->GetPageCount(); | |
4101 | dest_tabs->InsertPage(page_info.window, page_info, insert_idx); | |
4102 | ||
4103 | if (src_tabs->GetPageCount() == 0) | |
4104 | { | |
4105 | RemoveEmptyTabFrames(); | |
4106 | } | |
4107 | ||
4108 | DoSizing(); | |
4109 | dest_tabs->DoShowHide(); | |
4110 | dest_tabs->Refresh(); | |
4111 | ||
4112 | // force the set selection function reset the selection | |
4113 | m_curpage = -1; | |
4114 | ||
4115 | // set the active page to the one we just split off | |
4116 | SetSelectionToPage(page_info); | |
4117 | ||
4118 | UpdateHintWindowSize(); | |
4119 | } | |
4120 | ||
4121 | // notify owner that the tab has been dragged | |
4122 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, m_windowId); | |
4123 | e.SetSelection(evt.GetSelection()); | |
4124 | e.SetOldSelection(evt.GetSelection()); | |
4125 | e.SetEventObject(this); | |
4126 | GetEventHandler()->ProcessEvent(e); | |
4127 | } | |
4128 | ||
4129 | ||
4130 | ||
4131 | void wxAuiNotebook::OnTabCancelDrag(wxAuiNotebookEvent& command_evt) | |
4132 | { | |
4133 | wxAuiNotebookEvent& evt = (wxAuiNotebookEvent&)command_evt; | |
4134 | ||
4135 | m_mgr.HideHint(); | |
4136 | ||
4137 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4138 | wxCHECK_RET( src_tabs, _T("no source object?") ); | |
4139 | ||
4140 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
4141 | } | |
4142 | ||
4143 | wxAuiTabCtrl* wxAuiNotebook::GetTabCtrlFromPoint(const wxPoint& pt) | |
4144 | { | |
4145 | // if we've just removed the last tab from the source | |
4146 | // tab set, the remove the tab control completely | |
4147 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
4148 | size_t i, pane_count = all_panes.GetCount(); | |
4149 | for (i = 0; i < pane_count; ++i) | |
4150 | { | |
4151 | if (all_panes.Item(i).name == wxT("dummy")) | |
4152 | continue; | |
4153 | ||
4154 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; | |
4155 | if (tabframe->m_tab_rect.Contains(pt)) | |
4156 | return tabframe->m_tabs; | |
4157 | } | |
4158 | ||
4159 | return NULL; | |
4160 | } | |
4161 | ||
4162 | wxWindow* wxAuiNotebook::GetTabFrameFromTabCtrl(wxWindow* tab_ctrl) | |
4163 | { | |
4164 | // if we've just removed the last tab from the source | |
4165 | // tab set, the remove the tab control completely | |
4166 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
4167 | size_t i, pane_count = all_panes.GetCount(); | |
4168 | for (i = 0; i < pane_count; ++i) | |
4169 | { | |
4170 | if (all_panes.Item(i).name == wxT("dummy")) | |
4171 | continue; | |
4172 | ||
4173 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; | |
4174 | if (tabframe->m_tabs == tab_ctrl) | |
4175 | { | |
4176 | return tabframe; | |
4177 | } | |
4178 | } | |
4179 | ||
4180 | return NULL; | |
4181 | } | |
4182 | ||
4183 | void wxAuiNotebook::RemoveEmptyTabFrames() | |
4184 | { | |
4185 | // if we've just removed the last tab from the source | |
4186 | // tab set, the remove the tab control completely | |
4187 | wxAuiPaneInfoArray all_panes = m_mgr.GetAllPanes(); | |
4188 | size_t i, pane_count = all_panes.GetCount(); | |
4189 | for (i = 0; i < pane_count; ++i) | |
4190 | { | |
4191 | if (all_panes.Item(i).name == wxT("dummy")) | |
4192 | continue; | |
4193 | ||
4194 | wxTabFrame* tab_frame = (wxTabFrame*)all_panes.Item(i).window; | |
4195 | if (tab_frame->m_tabs->GetPageCount() == 0) | |
4196 | { | |
4197 | m_mgr.DetachPane(tab_frame); | |
4198 | ||
4199 | // use pending delete because sometimes during | |
4200 | // window closing, refreshs are pending | |
4201 | if (!wxPendingDelete.Member(tab_frame->m_tabs)) | |
4202 | wxPendingDelete.Append(tab_frame->m_tabs); | |
4203 | ||
4204 | tab_frame->m_tabs = NULL; | |
4205 | ||
4206 | delete tab_frame; | |
4207 | } | |
4208 | } | |
4209 | ||
4210 | ||
4211 | // check to see if there is still a center pane; | |
4212 | // if there isn't, make a frame the center pane | |
4213 | wxAuiPaneInfoArray panes = m_mgr.GetAllPanes(); | |
4214 | pane_count = panes.GetCount(); | |
4215 | wxWindow* first_good = NULL; | |
4216 | bool center_found = false; | |
4217 | for (i = 0; i < pane_count; ++i) | |
4218 | { | |
4219 | if (panes.Item(i).name == wxT("dummy")) | |
4220 | continue; | |
4221 | if (panes.Item(i).dock_direction == wxAUI_DOCK_CENTRE) | |
4222 | center_found = true; | |
4223 | if (!first_good) | |
4224 | first_good = panes.Item(i).window; | |
4225 | } | |
4226 | ||
4227 | if (!center_found && first_good) | |
4228 | { | |
4229 | m_mgr.GetPane(first_good).Centre(); | |
4230 | } | |
4231 | ||
4232 | if (!m_isBeingDeleted) | |
4233 | m_mgr.Update(); | |
4234 | } | |
4235 | ||
4236 | void wxAuiNotebook::OnChildFocusNotebook(wxChildFocusEvent& evt) | |
4237 | { | |
4238 | evt.Skip(); | |
4239 | ||
4240 | // if we're dragging a tab, don't change the current selection. | |
4241 | // This code prevents a bug that used to happen when the hint window | |
4242 | // was hidden. In the bug, the focus would return to the notebook | |
4243 | // child, which would then enter this handler and call | |
4244 | // SetSelection, which is not desired turn tab dragging. | |
4245 | ||
4246 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
4247 | size_t i, pane_count = all_panes.GetCount(); | |
4248 | for (i = 0; i < pane_count; ++i) | |
4249 | { | |
4250 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
4251 | if (pane.name == wxT("dummy")) | |
4252 | continue; | |
4253 | wxTabFrame* tabframe = (wxTabFrame*)pane.window; | |
4254 | if (tabframe->m_tabs->IsDragging()) | |
4255 | return; | |
4256 | } | |
4257 | ||
4258 | ||
4259 | // change the tab selection to the child | |
4260 | // which was focused | |
4261 | int idx = m_tabs.GetIdxFromWindow(evt.GetWindow()); | |
4262 | if (idx != -1 && idx != m_curpage) | |
4263 | { | |
4264 | SetSelection(idx); | |
4265 | } | |
4266 | } | |
4267 | ||
4268 | void wxAuiNotebook::OnNavigationKeyNotebook(wxNavigationKeyEvent& event) | |
4269 | { | |
4270 | if ( event.IsWindowChange() ) { | |
4271 | // change pages | |
4272 | // FIXME: the problem with this is that if we have a split notebook, | |
4273 | // we selection may go all over the place. | |
4274 | AdvanceSelection(event.GetDirection()); | |
4275 | } | |
4276 | else { | |
4277 | // we get this event in 3 cases | |
4278 | // | |
4279 | // a) one of our pages might have generated it because the user TABbed | |
4280 | // out from it in which case we should propagate the event upwards and | |
4281 | // our parent will take care of setting the focus to prev/next sibling | |
4282 | // | |
4283 | // or | |
4284 | // | |
4285 | // b) the parent panel wants to give the focus to us so that we | |
4286 | // forward it to our selected page. We can't deal with this in | |
4287 | // OnSetFocus() because we don't know which direction the focus came | |
4288 | // from in this case and so can't choose between setting the focus to | |
4289 | // first or last panel child | |
4290 | // | |
4291 | // or | |
4292 | // | |
4293 | // c) we ourselves (see MSWTranslateMessage) generated the event | |
4294 | // | |
4295 | wxWindow * const parent = GetParent(); | |
4296 | ||
4297 | // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE | |
4298 | const bool isFromParent = event.GetEventObject() == (wxObject*) parent; | |
4299 | const bool isFromSelf = event.GetEventObject() == (wxObject*) this; | |
4300 | ||
4301 | if ( isFromParent || isFromSelf ) | |
4302 | { | |
4303 | // no, it doesn't come from child, case (b) or (c): forward to a | |
4304 | // page but only if direction is backwards (TAB) or from ourselves, | |
4305 | if ( GetSelection() != wxNOT_FOUND && | |
4306 | (!event.GetDirection() || isFromSelf) ) | |
4307 | { | |
4308 | // so that the page knows that the event comes from it's parent | |
4309 | // and is being propagated downwards | |
4310 | event.SetEventObject(this); | |
4311 | ||
4312 | wxWindow *page = GetPage(GetSelection()); | |
4313 | if ( !page->GetEventHandler()->ProcessEvent(event) ) | |
4314 | { | |
4315 | page->SetFocus(); | |
4316 | } | |
4317 | //else: page manages focus inside it itself | |
4318 | } | |
4319 | else // otherwise set the focus to the notebook itself | |
4320 | { | |
4321 | SetFocus(); | |
4322 | } | |
4323 | } | |
4324 | else | |
4325 | { | |
4326 | // it comes from our child, case (a), pass to the parent, but only | |
4327 | // if the direction is forwards. Otherwise set the focus to the | |
4328 | // notebook itself. The notebook is always the 'first' control of a | |
4329 | // page. | |
4330 | if ( !event.GetDirection() ) | |
4331 | { | |
4332 | SetFocus(); | |
4333 | } | |
4334 | else if ( parent ) | |
4335 | { | |
4336 | event.SetCurrentFocus(this); | |
4337 | parent->GetEventHandler()->ProcessEvent(event); | |
4338 | } | |
4339 | } | |
4340 | } | |
4341 | } | |
4342 | ||
4343 | void wxAuiNotebook::OnTabButton(wxAuiNotebookEvent& evt) | |
4344 | { | |
4345 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4346 | ||
4347 | int button_id = evt.GetInt(); | |
4348 | ||
4349 | if (button_id == wxAUI_BUTTON_CLOSE) | |
4350 | { | |
4351 | int selection = evt.GetSelection(); | |
4352 | ||
4353 | if (selection == -1) | |
4354 | { | |
4355 | // if the close button is to the right, use the active | |
4356 | // page selection to determine which page to close | |
4357 | selection = tabs->GetActivePage(); | |
4358 | } | |
4359 | ||
4360 | if (selection != -1) | |
4361 | { | |
4362 | wxWindow* close_wnd = tabs->GetWindowFromIdx(selection); | |
4363 | ||
4364 | // ask owner if it's ok to close the tab | |
4365 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, m_windowId); | |
4366 | e.SetSelection(m_tabs.GetIdxFromWindow(close_wnd)); | |
4367 | const int idx = m_tabs.GetIdxFromWindow(close_wnd); | |
4368 | e.SetSelection(idx); | |
4369 | e.SetOldSelection(evt.GetSelection()); | |
4370 | e.SetEventObject(this); | |
4371 | GetEventHandler()->ProcessEvent(e); | |
4372 | if (!e.IsAllowed()) | |
4373 | return; | |
4374 | ||
4375 | ||
4376 | #if wxUSE_MDI | |
4377 | if (close_wnd->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) | |
4378 | { | |
4379 | close_wnd->Close(); | |
4380 | } | |
4381 | else | |
4382 | #endif | |
4383 | { | |
4384 | int main_idx = m_tabs.GetIdxFromWindow(close_wnd); | |
4385 | wxCHECK_RET( main_idx != wxNOT_FOUND, wxT("no page to delete?") ); | |
4386 | ||
4387 | DeletePage(main_idx); | |
4388 | } | |
4389 | ||
4390 | // notify owner that the tab has been closed | |
4391 | wxAuiNotebookEvent e2(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, m_windowId); | |
4392 | e2.SetSelection(idx); | |
4393 | e2.SetEventObject(this); | |
4394 | GetEventHandler()->ProcessEvent(e2); | |
4395 | } | |
4396 | } | |
4397 | } | |
4398 | ||
4399 | ||
4400 | void wxAuiNotebook::OnTabMiddleDown(wxAuiNotebookEvent& evt) | |
4401 | { | |
4402 | // patch event through to owner | |
4403 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4404 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
4405 | ||
4406 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, m_windowId); | |
4407 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
4408 | e.SetEventObject(this); | |
4409 | GetEventHandler()->ProcessEvent(e); | |
4410 | } | |
4411 | ||
4412 | void wxAuiNotebook::OnTabMiddleUp(wxAuiNotebookEvent& evt) | |
4413 | { | |
4414 | // if the wxAUI_NB_MIDDLE_CLICK_CLOSE is specified, middle | |
4415 | // click should act like a tab close action. However, first | |
4416 | // give the owner an opportunity to handle the middle up event | |
4417 | // for custom action | |
4418 | ||
4419 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4420 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
4421 | ||
4422 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, m_windowId); | |
4423 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
4424 | e.SetEventObject(this); | |
4425 | if (GetEventHandler()->ProcessEvent(e)) | |
4426 | return; | |
4427 | if (!e.IsAllowed()) | |
4428 | return; | |
4429 | ||
4430 | // check if we are supposed to close on middle-up | |
4431 | if ((m_flags & wxAUI_NB_MIDDLE_CLICK_CLOSE) == 0) | |
4432 | return; | |
4433 | ||
4434 | // simulate the user pressing the close button on the tab | |
4435 | evt.SetInt(wxAUI_BUTTON_CLOSE); | |
4436 | OnTabButton(evt); | |
4437 | } | |
4438 | ||
4439 | void wxAuiNotebook::OnTabRightDown(wxAuiNotebookEvent& evt) | |
4440 | { | |
4441 | // patch event through to owner | |
4442 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4443 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
4444 | ||
4445 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, m_windowId); | |
4446 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
4447 | e.SetEventObject(this); | |
4448 | GetEventHandler()->ProcessEvent(e); | |
4449 | } | |
4450 | ||
4451 | void wxAuiNotebook::OnTabRightUp(wxAuiNotebookEvent& evt) | |
4452 | { | |
4453 | // patch event through to owner | |
4454 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4455 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
4456 | ||
4457 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, m_windowId); | |
4458 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
4459 | e.SetEventObject(this); | |
4460 | GetEventHandler()->ProcessEvent(e); | |
4461 | } | |
4462 | ||
4463 | // Sets the normal font | |
4464 | void wxAuiNotebook::SetNormalFont(const wxFont& font) | |
4465 | { | |
4466 | m_normal_font = font; | |
4467 | GetArtProvider()->SetNormalFont(font); | |
4468 | } | |
4469 | ||
4470 | // Sets the selected tab font | |
4471 | void wxAuiNotebook::SetSelectedFont(const wxFont& font) | |
4472 | { | |
4473 | m_selected_font = font; | |
4474 | GetArtProvider()->SetSelectedFont(font); | |
4475 | } | |
4476 | ||
4477 | // Sets the measuring font | |
4478 | void wxAuiNotebook::SetMeasuringFont(const wxFont& font) | |
4479 | { | |
4480 | GetArtProvider()->SetMeasuringFont(font); | |
4481 | } | |
4482 | ||
4483 | // Sets the tab font | |
4484 | bool wxAuiNotebook::SetFont(const wxFont& font) | |
4485 | { | |
4486 | wxControl::SetFont(font); | |
4487 | ||
4488 | wxFont normalFont(font); | |
4489 | wxFont selectedFont(normalFont); | |
4490 | selectedFont.SetWeight(wxBOLD); | |
4491 | ||
4492 | SetNormalFont(normalFont); | |
4493 | SetSelectedFont(selectedFont); | |
4494 | SetMeasuringFont(selectedFont); | |
4495 | ||
4496 | return true; | |
4497 | } | |
4498 | ||
4499 | // Gets the tab control height | |
4500 | int wxAuiNotebook::GetTabCtrlHeight() const | |
4501 | { | |
4502 | return m_tab_ctrl_height; | |
4503 | } | |
4504 | ||
4505 | // Gets the height of the notebook for a given page height | |
4506 | int wxAuiNotebook::GetHeightForPageHeight(int pageHeight) | |
4507 | { | |
4508 | UpdateTabCtrlHeight(); | |
4509 | ||
4510 | int tabCtrlHeight = GetTabCtrlHeight(); | |
4511 | int decorHeight = 2; | |
4512 | return tabCtrlHeight + pageHeight + decorHeight; | |
4513 | } | |
4514 | ||
4515 | // Advances the selection, generation page selection events | |
4516 | void wxAuiNotebook::AdvanceSelection(bool forward) | |
4517 | { | |
4518 | if (GetPageCount() <= 1) | |
4519 | return; | |
4520 | ||
4521 | int currentSelection = GetSelection(); | |
4522 | ||
4523 | if (forward) | |
4524 | { | |
4525 | if (currentSelection == (int) (GetPageCount() - 1)) | |
4526 | return; | |
4527 | else if (currentSelection == -1) | |
4528 | currentSelection = 0; | |
4529 | else | |
4530 | currentSelection ++; | |
4531 | } | |
4532 | else | |
4533 | { | |
4534 | if (currentSelection <= 0) | |
4535 | return; | |
4536 | else | |
4537 | currentSelection --; | |
4538 | } | |
4539 | ||
4540 | SetSelection(currentSelection); | |
4541 | } | |
4542 | ||
4543 | // Shows the window menu | |
4544 | bool wxAuiNotebook::ShowWindowMenu() | |
4545 | { | |
4546 | wxAuiTabCtrl* tabCtrl = GetActiveTabCtrl(); | |
4547 | ||
4548 | int idx = tabCtrl->GetArtProvider()->ShowDropDown(tabCtrl, tabCtrl->GetPages(), tabCtrl->GetActivePage()); | |
4549 | ||
4550 | if (idx != -1) | |
4551 | { | |
4552 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, tabCtrl->GetId()); | |
4553 | e.SetSelection(idx); | |
4554 | e.SetOldSelection(tabCtrl->GetActivePage()); | |
4555 | e.SetEventObject(tabCtrl); | |
4556 | GetEventHandler()->ProcessEvent(e); | |
4557 | ||
4558 | return true; | |
4559 | } | |
4560 | else | |
4561 | return false; | |
4562 | } | |
4563 | ||
4564 | void wxAuiNotebook::Thaw() | |
4565 | { | |
4566 | DoSizing(); | |
4567 | ||
4568 | wxControl::Thaw(); | |
4569 | } | |
4570 | ||
4571 | #endif // wxUSE_AUI |