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