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