1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/auibook.cpp
3 // Purpose: wxaui: wx advanced user interface - notebook
4 // Author: Benjamin I. Williams
7 // Copyright: (C) Copyright 2006, Kirix Corporation, All Rights Reserved
8 // Licence: wxWindows Library Licence, Version 3.1
9 ///////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
15 #include "wx/wxprec.h"
23 #include "wx/aui/auibook.h"
26 #include "wx/settings.h"
31 #include "wx/aui/tabmdi.h"
32 #include "wx/dcbuffer.h"
34 #include "wx/renderer.h"
37 #include "wx/osx/private.h"
40 #include "wx/arrimpl.cpp"
41 WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray
)
42 WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray
)
44 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
, wxAuiNotebookEvent
);
45 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED
, wxAuiNotebookEvent
);
46 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, wxAuiNotebookEvent
);
47 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
, wxAuiNotebookEvent
);
48 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
, wxAuiNotebookEvent
);
49 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
, wxAuiNotebookEvent
);
50 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
, wxAuiNotebookEvent
);
51 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
, wxAuiNotebookEvent
);
52 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
, wxAuiNotebookEvent
);
53 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, wxAuiNotebookEvent
);
54 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, wxAuiNotebookEvent
);
55 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, wxAuiNotebookEvent
);
56 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, wxAuiNotebookEvent
);
57 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, wxAuiNotebookEvent
);
58 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, wxAuiNotebookEvent
);
60 IMPLEMENT_CLASS(wxAuiNotebook
, wxControl
)
61 IMPLEMENT_CLASS(wxAuiTabCtrl
, wxControl
)
62 IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent
, wxEvent
)
68 // these functions live in dockart.cpp -- they'll eventually
69 // be moved to a new utility cpp file
71 wxColor
wxAuiStepColour(const wxColor
& c
, int percent
);
73 wxBitmap
wxAuiBitmapFromBits(const unsigned char bits
[], int w
, int h
,
74 const wxColour
& color
);
76 wxString
wxAuiChopText(wxDC
& dc
, const wxString
& text
, int max_size
);
78 static void DrawButtons(wxDC
& dc
,
81 const wxColour
& bkcolour
,
86 if (button_state
== wxAUI_BUTTON_STATE_PRESSED
)
92 if (button_state
== wxAUI_BUTTON_STATE_HOVER
||
93 button_state
== wxAUI_BUTTON_STATE_PRESSED
)
95 dc
.SetBrush(wxBrush(wxAuiStepColour(bkcolour
, 120)));
96 dc
.SetPen(wxPen(wxAuiStepColour(bkcolour
, 75)));
98 // draw the background behind the button
99 dc
.DrawRectangle(rect
.x
, rect
.y
, 15, 15);
102 // draw the button itself
103 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
106 static void IndentPressedBitmap(wxRect
* rect
, int button_state
)
108 if (button_state
== wxAUI_BUTTON_STATE_PRESSED
)
117 // -- GUI helper classes and functions --
119 class wxAuiCommandCapture
: public wxEvtHandler
123 wxAuiCommandCapture() { m_last_id
= 0; }
124 int GetCommandId() const { return m_last_id
; }
126 bool ProcessEvent(wxEvent
& evt
)
128 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
130 m_last_id
= evt
.GetId();
134 if (GetNextHandler())
135 return GetNextHandler()->ProcessEvent(evt
);
147 #if defined( __WXMAC__ )
148 static const 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 const 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 };
158 static const 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};
164 static const 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};
169 static const 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};
174 static const 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};
184 // -- wxAuiDefaultTabArt class implementation --
186 wxAuiDefaultTabArt::wxAuiDefaultTabArt()
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
;
193 m_fixed_tab_width
= 100;
194 m_tab_ctrl_height
= 0;
196 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
197 wxColor base_colour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
199 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
202 // the base_colour is too pale to use as our base colour,
203 // so darken it a bit --
204 if ((255-base_colour
.Red()) +
205 (255-base_colour
.Green()) +
206 (255-base_colour
.Blue()) < 60)
208 base_colour
= wxAuiStepColour(base_colour
, 92);
211 m_base_colour
= base_colour
;
212 wxColor border_colour
= wxAuiStepColour(base_colour
, 75);
214 m_border_pen
= wxPen(border_colour
);
215 m_base_colour_pen
= wxPen(m_base_colour
);
216 m_base_colour_brush
= wxBrush(m_base_colour
);
218 m_active_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, *wxBLACK
);
219 m_disabled_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, wxColour(128,128,128));
221 m_active_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, *wxBLACK
);
222 m_disabled_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, wxColour(128,128,128));
224 m_active_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, *wxBLACK
);
225 m_disabled_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, wxColour(128,128,128));
227 m_active_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, *wxBLACK
);
228 m_disabled_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, wxColour(128,128,128));
233 wxAuiDefaultTabArt::~wxAuiDefaultTabArt()
237 wxAuiTabArt
* wxAuiDefaultTabArt::Clone()
239 return new wxAuiDefaultTabArt(*this);
242 void wxAuiDefaultTabArt::SetFlags(unsigned int flags
)
247 void wxAuiDefaultTabArt::SetSizingInfo(const wxSize
& tab_ctrl_size
,
250 m_fixed_tab_width
= 100;
252 int tot_width
= (int)tab_ctrl_size
.x
- GetIndentSize() - 4;
254 if (m_flags
& wxAUI_NB_CLOSE_BUTTON
)
255 tot_width
-= m_active_close_bmp
.GetWidth();
256 if (m_flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
257 tot_width
-= m_active_windowlist_bmp
.GetWidth();
261 m_fixed_tab_width
= tot_width
/(int)tab_count
;
265 if (m_fixed_tab_width
< 100)
266 m_fixed_tab_width
= 100;
268 if (m_fixed_tab_width
> tot_width
/2)
269 m_fixed_tab_width
= tot_width
/2;
271 if (m_fixed_tab_width
> 220)
272 m_fixed_tab_width
= 220;
274 m_tab_ctrl_height
= tab_ctrl_size
.y
;
278 void wxAuiDefaultTabArt::DrawBackground(wxDC
& dc
,
279 wxWindow
* WXUNUSED(wnd
),
284 wxColor top_color
= wxAuiStepColour(m_base_colour
, 90);
285 wxColor bottom_color
= wxAuiStepColour(m_base_colour
, 170);
288 if (m_flags
&wxAUI_NB_BOTTOM
)
289 r
= wxRect(rect
.x
, rect
.y
, rect
.width
+2, rect
.height
);
290 // TODO: else if (m_flags &wxAUI_NB_LEFT) {}
291 // TODO: else if (m_flags &wxAUI_NB_RIGHT) {}
292 else //for wxAUI_NB_TOP
293 r
= wxRect(rect
.x
, rect
.y
, rect
.width
+2, rect
.height
-3);
295 dc
.GradientFillLinear(r
, top_color
, bottom_color
, wxSOUTH
);
300 dc
.SetPen(m_border_pen
);
301 int y
= rect
.GetHeight();
302 int w
= rect
.GetWidth();
304 if (m_flags
&wxAUI_NB_BOTTOM
)
306 dc
.SetBrush(wxBrush(bottom_color
));
307 dc
.DrawRectangle(-1, 0, w
+2, 4);
309 // TODO: else if (m_flags &wxAUI_NB_LEFT) {}
310 // TODO: else if (m_flags &wxAUI_NB_RIGHT) {}
311 else //for wxAUI_NB_TOP
313 dc
.SetBrush(m_base_colour_brush
);
314 dc
.DrawRectangle(-1, y
-4, w
+2, 4);
319 // DrawTab() draws an individual tab.
322 // in_rect - rectangle the tab should be confined to
323 // caption - tab's caption
324 // active - whether or not the tab is active
325 // out_rect - actual output rectangle
326 // x_extent - the advance x; where the next tab should start
328 void wxAuiDefaultTabArt::DrawTab(wxDC
& dc
,
330 const wxAuiNotebookPage
& page
,
331 const wxRect
& in_rect
,
332 int close_button_state
,
333 wxRect
* out_tab_rect
,
334 wxRect
* out_button_rect
,
337 wxCoord normal_textx
, normal_texty
;
338 wxCoord selected_textx
, selected_texty
;
341 // if the caption is empty, measure some temporary text
342 wxString caption
= page
.caption
;
346 dc
.SetFont(m_selected_font
);
347 dc
.GetTextExtent(caption
, &selected_textx
, &selected_texty
);
349 dc
.SetFont(m_normal_font
);
350 dc
.GetTextExtent(caption
, &normal_textx
, &normal_texty
);
352 // figure out the size of the tab
353 wxSize tab_size
= GetTabSize(dc
,
361 wxCoord tab_height
= m_tab_ctrl_height
- 3;
362 wxCoord tab_width
= tab_size
.x
;
363 wxCoord tab_x
= in_rect
.x
;
364 wxCoord tab_y
= in_rect
.y
+ in_rect
.height
- tab_height
;
367 caption
= page
.caption
;
370 // select pen, brush and font for the tab to be drawn
374 dc
.SetFont(m_selected_font
);
375 texty
= selected_texty
;
379 dc
.SetFont(m_normal_font
);
380 texty
= normal_texty
;
384 // create points that will make the tab outline
386 int clip_width
= tab_width
;
387 if (tab_x
+ clip_width
> in_rect
.x
+ in_rect
.width
)
388 clip_width
= (in_rect
.x
+ in_rect
.width
) - tab_x
;
391 wxPoint clip_points[6];
392 clip_points[0] = wxPoint(tab_x, tab_y+tab_height-3);
393 clip_points[1] = wxPoint(tab_x, tab_y+2);
394 clip_points[2] = wxPoint(tab_x+2, tab_y);
395 clip_points[3] = wxPoint(tab_x+clip_width-1, tab_y);
396 clip_points[4] = wxPoint(tab_x+clip_width+1, tab_y+2);
397 clip_points[5] = wxPoint(tab_x+clip_width+1, tab_y+tab_height-3);
399 // FIXME: these ports don't provide wxRegion ctor from array of points
400 #if !defined(__WXDFB__) && !defined(__WXCOCOA__)
401 // set the clipping region for the tab --
402 wxRegion clipping_region(WXSIZEOF(clip_points), clip_points);
403 dc.SetClippingRegion(clipping_region);
404 #endif // !wxDFB && !wxCocoa
406 // since the above code above doesn't play well with WXDFB or WXCOCOA,
407 // we'll just use a rectangle for the clipping region for now --
408 dc
.SetClippingRegion(tab_x
, tab_y
, clip_width
+1, tab_height
-3);
411 wxPoint border_points
[6];
412 if (m_flags
&wxAUI_NB_BOTTOM
)
414 border_points
[0] = wxPoint(tab_x
, tab_y
);
415 border_points
[1] = wxPoint(tab_x
, tab_y
+tab_height
-6);
416 border_points
[2] = wxPoint(tab_x
+2, tab_y
+tab_height
-4);
417 border_points
[3] = wxPoint(tab_x
+tab_width
-2, tab_y
+tab_height
-4);
418 border_points
[4] = wxPoint(tab_x
+tab_width
, tab_y
+tab_height
-6);
419 border_points
[5] = wxPoint(tab_x
+tab_width
, tab_y
);
421 else //if (m_flags & wxAUI_NB_TOP) {}
423 border_points
[0] = wxPoint(tab_x
, tab_y
+tab_height
-4);
424 border_points
[1] = wxPoint(tab_x
, tab_y
+2);
425 border_points
[2] = wxPoint(tab_x
+2, tab_y
);
426 border_points
[3] = wxPoint(tab_x
+tab_width
-2, tab_y
);
427 border_points
[4] = wxPoint(tab_x
+tab_width
, tab_y
+2);
428 border_points
[5] = wxPoint(tab_x
+tab_width
, tab_y
+tab_height
-4);
430 // TODO: else if (m_flags &wxAUI_NB_LEFT) {}
431 // TODO: else if (m_flags &wxAUI_NB_RIGHT) {}
433 int drawn_tab_yoff
= border_points
[1].y
;
434 int drawn_tab_height
= border_points
[0].y
- border_points
[1].y
;
441 // draw base background color
442 wxRect
r(tab_x
, tab_y
, tab_width
, tab_height
);
443 dc
.SetPen(m_base_colour_pen
);
444 dc
.SetBrush(m_base_colour_brush
);
445 dc
.DrawRectangle(r
.x
+1, r
.y
+1, r
.width
-1, r
.height
-4);
447 // this white helps fill out the gradient at the top of the tab
448 dc
.SetPen(*wxWHITE_PEN
);
449 dc
.SetBrush(*wxWHITE_BRUSH
);
450 dc
.DrawRectangle(r
.x
+2, r
.y
+1, r
.width
-3, r
.height
-4);
452 // these two points help the rounded corners appear more antialiased
453 dc
.SetPen(m_base_colour_pen
);
454 dc
.DrawPoint(r
.x
+2, r
.y
+1);
455 dc
.DrawPoint(r
.x
+r
.width
-2, r
.y
+1);
457 // set rectangle down a bit for gradient drawing
458 r
.SetHeight(r
.GetHeight()/2);
464 // draw gradient background
465 wxColor top_color
= *wxWHITE
;
466 wxColor bottom_color
= m_base_colour
;
467 dc
.GradientFillLinear(r
, bottom_color
, top_color
, wxNORTH
);
473 wxRect
r(tab_x
, tab_y
+1, tab_width
, tab_height
-3);
475 // start the gradent up a bit and leave the inside border inset
476 // by a pixel for a 3D look. Only the top half of the inactive
477 // tab will have a slight gradient
484 // -- draw top gradient fill for glossy look
485 wxColor top_color
= m_base_colour
;
486 wxColor bottom_color
= wxAuiStepColour(top_color
, 160);
487 dc
.GradientFillLinear(r
, bottom_color
, top_color
, wxNORTH
);
492 // -- draw bottom fill for glossy look
493 top_color
= m_base_colour
;
494 bottom_color
= m_base_colour
;
495 dc
.GradientFillLinear(r
, top_color
, bottom_color
, wxSOUTH
);
499 dc
.SetPen(m_border_pen
);
500 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
501 dc
.DrawPolygon(WXSIZEOF(border_points
), border_points
);
503 // there are two horizontal grey lines at the bottom of the tab control,
504 // this gets rid of the top one of those lines in the tab control
507 if (m_flags
&wxAUI_NB_BOTTOM
)
508 dc
.SetPen(wxPen(wxColour(wxAuiStepColour(m_base_colour
, 170))));
509 // TODO: else if (m_flags &wxAUI_NB_LEFT) {}
510 // TODO: else if (m_flags &wxAUI_NB_RIGHT) {}
511 else //for wxAUI_NB_TOP
512 dc
.SetPen(m_base_colour_pen
);
513 dc
.DrawLine(border_points
[0].x
+1,
520 int text_offset
= tab_x
+ 8;
521 int close_button_width
= 0;
522 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
524 close_button_width
= m_active_close_bmp
.GetWidth();
527 int bitmap_offset
= 0;
528 if (page
.bitmap
.IsOk())
530 bitmap_offset
= tab_x
+ 8;
533 dc
.DrawBitmap(page
.bitmap
,
535 drawn_tab_yoff
+ (drawn_tab_height
/2) - (page
.bitmap
.GetHeight()/2),
538 text_offset
= bitmap_offset
+ page
.bitmap
.GetWidth();
539 text_offset
+= 3; // bitmap padding
544 text_offset
= tab_x
+ 8;
548 wxString draw_text
= wxAuiChopText(dc
,
550 tab_width
- (text_offset
-tab_x
) - close_button_width
);
553 dc
.DrawText(draw_text
,
555 drawn_tab_yoff
+ (drawn_tab_height
)/2 - (texty
/2) - 1);
557 // draw focus rectangle
558 if (page
.active
&& (wnd
->FindFocus() == wnd
))
560 wxRect
focusRectText(text_offset
, (drawn_tab_yoff
+ (drawn_tab_height
)/2 - (texty
/2) - 1),
561 selected_textx
, selected_texty
);
564 wxRect focusRectBitmap
;
566 if (page
.bitmap
.IsOk())
567 focusRectBitmap
= wxRect(bitmap_offset
, drawn_tab_yoff
+ (drawn_tab_height
/2) - (page
.bitmap
.GetHeight()/2),
568 page
.bitmap
.GetWidth(), page
.bitmap
.GetHeight());
570 if (page
.bitmap
.IsOk() && draw_text
.IsEmpty())
571 focusRect
= focusRectBitmap
;
572 else if (!page
.bitmap
.IsOk() && !draw_text
.IsEmpty())
573 focusRect
= focusRectText
;
574 else if (page
.bitmap
.IsOk() && !draw_text
.IsEmpty())
575 focusRect
= focusRectText
.Union(focusRectBitmap
);
577 focusRect
.Inflate(2, 2);
579 wxRendererNative::Get().DrawFocusRect(wnd
, dc
, focusRect
, 0);
582 // draw close button if necessary
583 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
585 wxBitmap bmp
= m_disabled_close_bmp
;
587 if (close_button_state
== wxAUI_BUTTON_STATE_HOVER
||
588 close_button_state
== wxAUI_BUTTON_STATE_PRESSED
)
590 bmp
= m_active_close_bmp
;
593 int offsetY
= tab_y
-1;
594 if (m_flags
& wxAUI_NB_BOTTOM
)
597 wxRect
rect(tab_x
+ tab_width
- close_button_width
- 1,
598 offsetY
+ (tab_height
/2) - (bmp
.GetHeight()/2),
602 IndentPressedBitmap(&rect
, close_button_state
);
603 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
605 *out_button_rect
= rect
;
608 *out_tab_rect
= wxRect(tab_x
, tab_y
, tab_width
, tab_height
);
610 dc
.DestroyClippingRegion();
613 int wxAuiDefaultTabArt::GetIndentSize()
618 wxSize
wxAuiDefaultTabArt::GetTabSize(wxDC
& dc
,
619 wxWindow
* WXUNUSED(wnd
),
620 const wxString
& caption
,
621 const wxBitmap
& bitmap
,
622 bool WXUNUSED(active
),
623 int close_button_state
,
626 wxCoord measured_textx
, measured_texty
, tmp
;
628 dc
.SetFont(m_measuring_font
);
629 dc
.GetTextExtent(caption
, &measured_textx
, &measured_texty
);
631 dc
.GetTextExtent(wxT("ABCDEFXj"), &tmp
, &measured_texty
);
633 // add padding around the text
634 wxCoord tab_width
= measured_textx
;
635 wxCoord tab_height
= measured_texty
;
637 // if the close button is showing, add space for it
638 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
639 tab_width
+= m_active_close_bmp
.GetWidth() + 3;
641 // if there's a bitmap, add space for it
644 tab_width
+= bitmap
.GetWidth();
645 tab_width
+= 3; // right side bitmap padding
646 tab_height
= wxMax(tab_height
, bitmap
.GetHeight());
653 if (m_flags
& wxAUI_NB_TAB_FIXED_WIDTH
)
655 tab_width
= m_fixed_tab_width
;
658 *x_extent
= tab_width
;
660 return wxSize(tab_width
, tab_height
);
664 void wxAuiDefaultTabArt::DrawButton(wxDC
& dc
,
665 wxWindow
* WXUNUSED(wnd
),
666 const wxRect
& in_rect
,
677 case wxAUI_BUTTON_CLOSE
:
678 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
679 bmp
= m_disabled_close_bmp
;
681 bmp
= m_active_close_bmp
;
683 case wxAUI_BUTTON_LEFT
:
684 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
685 bmp
= m_disabled_left_bmp
;
687 bmp
= m_active_left_bmp
;
689 case wxAUI_BUTTON_RIGHT
:
690 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
691 bmp
= m_disabled_right_bmp
;
693 bmp
= m_active_right_bmp
;
695 case wxAUI_BUTTON_WINDOWLIST
:
696 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
697 bmp
= m_disabled_windowlist_bmp
;
699 bmp
= m_active_windowlist_bmp
;
709 if (orientation
== wxLEFT
)
711 rect
.SetX(in_rect
.x
);
712 rect
.SetY(((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2));
713 rect
.SetWidth(bmp
.GetWidth());
714 rect
.SetHeight(bmp
.GetHeight());
718 rect
= wxRect(in_rect
.x
+ in_rect
.width
- bmp
.GetWidth(),
719 ((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2),
720 bmp
.GetWidth(), bmp
.GetHeight());
723 IndentPressedBitmap(&rect
, button_state
);
724 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
729 int wxAuiDefaultTabArt::ShowDropDown(wxWindow
* wnd
,
730 const wxAuiNotebookPageArray
& pages
,
735 size_t i
, count
= pages
.GetCount();
736 for (i
= 0; i
< count
; ++i
)
738 const wxAuiNotebookPage
& page
= pages
.Item(i
);
739 wxString caption
= page
.caption
;
741 // if there is no caption, make it a space. This will prevent
742 // an assert in the menu code.
743 if (caption
.IsEmpty())
746 wxMenuItem
* item
= new wxMenuItem(NULL
, 1000+i
, caption
);
747 if (page
.bitmap
.IsOk())
748 item
->SetBitmap(page
.bitmap
);
749 menuPopup
.Append(item
);
752 // find out where to put the popup menu of window items
753 wxPoint pt
= ::wxGetMousePosition();
754 pt
= wnd
->ScreenToClient(pt
);
756 // find out the screen coordinate at the bottom of the tab ctrl
757 wxRect cli_rect
= wnd
->GetClientRect();
758 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
760 wxAuiCommandCapture
* cc
= new wxAuiCommandCapture
;
761 wnd
->PushEventHandler(cc
);
762 wnd
->PopupMenu(&menuPopup
, pt
);
763 int command
= cc
->GetCommandId();
764 wnd
->PopEventHandler(true);
772 int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow
* wnd
,
773 const wxAuiNotebookPageArray
& pages
,
774 const wxSize
& required_bmp_size
)
777 dc
.SetFont(m_measuring_font
);
779 // sometimes a standard bitmap size needs to be enforced, especially
780 // if some tabs have bitmaps and others don't. This is important because
781 // it prevents the tab control from resizing when tabs are added.
782 wxBitmap measure_bmp
;
783 if (required_bmp_size
.IsFullySpecified())
785 measure_bmp
.Create(required_bmp_size
.x
,
786 required_bmp_size
.y
);
791 size_t i
, page_count
= pages
.GetCount();
792 for (i
= 0; i
< page_count
; ++i
)
794 wxAuiNotebookPage
& page
= pages
.Item(i
);
797 if (measure_bmp
.IsOk())
802 // we don't use the caption text because we don't
803 // want tab heights to be different in the case
804 // of a very short piece of text on one tab and a very
805 // tall piece of text on another tab
807 wxSize s
= GetTabSize(dc
,
812 wxAUI_BUTTON_STATE_HIDDEN
,
815 max_y
= wxMax(max_y
, s
.y
);
821 void wxAuiDefaultTabArt::SetNormalFont(const wxFont
& font
)
823 m_normal_font
= font
;
826 void wxAuiDefaultTabArt::SetSelectedFont(const wxFont
& font
)
828 m_selected_font
= font
;
831 void wxAuiDefaultTabArt::SetMeasuringFont(const wxFont
& font
)
833 m_measuring_font
= font
;
837 // -- wxAuiSimpleTabArt class implementation --
839 wxAuiSimpleTabArt::wxAuiSimpleTabArt()
841 m_normal_font
= *wxNORMAL_FONT
;
842 m_selected_font
= *wxNORMAL_FONT
;
843 m_selected_font
.SetWeight(wxBOLD
);
844 m_measuring_font
= m_selected_font
;
847 m_fixed_tab_width
= 100;
849 wxColour base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
851 wxColour background_colour
= base_colour
;
852 wxColour normaltab_colour
= base_colour
;
853 wxColour selectedtab_colour
= *wxWHITE
;
855 m_bkbrush
= wxBrush(background_colour
);
856 m_normal_bkbrush
= wxBrush(normaltab_colour
);
857 m_normal_bkpen
= wxPen(normaltab_colour
);
858 m_selected_bkbrush
= wxBrush(selectedtab_colour
);
859 m_selected_bkpen
= wxPen(selectedtab_colour
);
861 m_active_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, *wxBLACK
);
862 m_disabled_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, wxColour(128,128,128));
864 m_active_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, *wxBLACK
);
865 m_disabled_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, wxColour(128,128,128));
867 m_active_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, *wxBLACK
);
868 m_disabled_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, wxColour(128,128,128));
870 m_active_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, *wxBLACK
);
871 m_disabled_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, wxColour(128,128,128));
875 wxAuiSimpleTabArt::~wxAuiSimpleTabArt()
879 wxAuiTabArt
* wxAuiSimpleTabArt::Clone()
881 return static_cast<wxAuiTabArt
*>(new wxAuiSimpleTabArt
);
885 void wxAuiSimpleTabArt::SetFlags(unsigned int flags
)
890 void wxAuiSimpleTabArt::SetSizingInfo(const wxSize
& tab_ctrl_size
,
893 m_fixed_tab_width
= 100;
895 int tot_width
= (int)tab_ctrl_size
.x
- GetIndentSize() - 4;
897 if (m_flags
& wxAUI_NB_CLOSE_BUTTON
)
898 tot_width
-= m_active_close_bmp
.GetWidth();
899 if (m_flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
900 tot_width
-= m_active_windowlist_bmp
.GetWidth();
904 m_fixed_tab_width
= tot_width
/(int)tab_count
;
908 if (m_fixed_tab_width
< 100)
909 m_fixed_tab_width
= 100;
911 if (m_fixed_tab_width
> tot_width
/2)
912 m_fixed_tab_width
= tot_width
/2;
914 if (m_fixed_tab_width
> 220)
915 m_fixed_tab_width
= 220;
918 void wxAuiSimpleTabArt::DrawBackground(wxDC
& dc
,
919 wxWindow
* WXUNUSED(wnd
),
923 dc
.SetBrush(m_bkbrush
);
924 dc
.SetPen(*wxTRANSPARENT_PEN
);
925 dc
.DrawRectangle(-1, -1, rect
.GetWidth()+2, rect
.GetHeight()+2);
928 dc
.SetPen(*wxGREY_PEN
);
929 dc
.DrawLine(0, rect
.GetHeight()-1, rect
.GetWidth(), rect
.GetHeight()-1);
933 // DrawTab() draws an individual tab.
936 // in_rect - rectangle the tab should be confined to
937 // caption - tab's caption
938 // active - whether or not the tab is active
939 // out_rect - actual output rectangle
940 // x_extent - the advance x; where the next tab should start
942 void wxAuiSimpleTabArt::DrawTab(wxDC
& dc
,
944 const wxAuiNotebookPage
& page
,
945 const wxRect
& in_rect
,
946 int close_button_state
,
947 wxRect
* out_tab_rect
,
948 wxRect
* out_button_rect
,
951 wxCoord normal_textx
, normal_texty
;
952 wxCoord selected_textx
, selected_texty
;
953 wxCoord textx
, texty
;
955 // if the caption is empty, measure some temporary text
956 wxString caption
= page
.caption
;
960 dc
.SetFont(m_selected_font
);
961 dc
.GetTextExtent(caption
, &selected_textx
, &selected_texty
);
963 dc
.SetFont(m_normal_font
);
964 dc
.GetTextExtent(caption
, &normal_textx
, &normal_texty
);
966 // figure out the size of the tab
967 wxSize tab_size
= GetTabSize(dc
,
975 wxCoord tab_height
= tab_size
.y
;
976 wxCoord tab_width
= tab_size
.x
;
977 wxCoord tab_x
= in_rect
.x
;
978 wxCoord tab_y
= in_rect
.y
+ in_rect
.height
- tab_height
;
980 caption
= page
.caption
;
982 // select pen, brush and font for the tab to be drawn
986 dc
.SetPen(m_selected_bkpen
);
987 dc
.SetBrush(m_selected_bkbrush
);
988 dc
.SetFont(m_selected_font
);
989 textx
= selected_textx
;
990 texty
= selected_texty
;
994 dc
.SetPen(m_normal_bkpen
);
995 dc
.SetBrush(m_normal_bkbrush
);
996 dc
.SetFont(m_normal_font
);
997 textx
= normal_textx
;
998 texty
= normal_texty
;
1005 points
[0].x
= tab_x
;
1006 points
[0].y
= tab_y
+ tab_height
- 1;
1007 points
[1].x
= tab_x
+ tab_height
- 3;
1008 points
[1].y
= tab_y
+ 2;
1009 points
[2].x
= tab_x
+ tab_height
+ 3;
1010 points
[2].y
= tab_y
;
1011 points
[3].x
= tab_x
+ tab_width
- 2;
1012 points
[3].y
= tab_y
;
1013 points
[4].x
= tab_x
+ tab_width
;
1014 points
[4].y
= tab_y
+ 2;
1015 points
[5].x
= tab_x
+ tab_width
;
1016 points
[5].y
= tab_y
+ tab_height
- 1;
1017 points
[6] = points
[0];
1019 dc
.SetClippingRegion(in_rect
);
1021 dc
.DrawPolygon(WXSIZEOF(points
) - 1, points
);
1023 dc
.SetPen(*wxGREY_PEN
);
1025 //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points);
1026 dc
.DrawLines(WXSIZEOF(points
), points
);
1031 int close_button_width
= 0;
1032 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1034 close_button_width
= m_active_close_bmp
.GetWidth();
1035 text_offset
= tab_x
+ (tab_height
/2) + ((tab_width
-close_button_width
)/2) - (textx
/2);
1039 text_offset
= tab_x
+ (tab_height
/3) + (tab_width
/2) - (textx
/2);
1042 // set minimum text offset
1043 if (text_offset
< tab_x
+ tab_height
)
1044 text_offset
= tab_x
+ tab_height
;
1046 // chop text if necessary
1047 wxString draw_text
= wxAuiChopText(dc
,
1049 tab_width
- (text_offset
-tab_x
) - close_button_width
);
1052 dc
.DrawText(draw_text
,
1054 (tab_y
+ tab_height
)/2 - (texty
/2) + 1);
1057 // draw focus rectangle
1058 if (page
.active
&& (wnd
->FindFocus() == wnd
))
1060 wxRect
focusRect(text_offset
, ((tab_y
+ tab_height
)/2 - (texty
/2) + 1),
1061 selected_textx
, selected_texty
);
1063 focusRect
.Inflate(2, 2);
1065 wxRendererNative::Get().DrawFocusRect(wnd
, dc
, focusRect
, 0);
1068 // draw close button if necessary
1069 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1073 bmp
= m_active_close_bmp
;
1075 bmp
= m_disabled_close_bmp
;
1077 wxRect
rect(tab_x
+ tab_width
- close_button_width
- 1,
1078 tab_y
+ (tab_height
/2) - (bmp
.GetHeight()/2) + 1,
1081 DrawButtons(dc
, rect
, bmp
, *wxWHITE
, close_button_state
);
1083 *out_button_rect
= rect
;
1087 *out_tab_rect
= wxRect(tab_x
, tab_y
, tab_width
, tab_height
);
1089 dc
.DestroyClippingRegion();
1092 int wxAuiSimpleTabArt::GetIndentSize()
1097 wxSize
wxAuiSimpleTabArt::GetTabSize(wxDC
& dc
,
1098 wxWindow
* WXUNUSED(wnd
),
1099 const wxString
& caption
,
1100 const wxBitmap
& WXUNUSED(bitmap
),
1101 bool WXUNUSED(active
),
1102 int close_button_state
,
1105 wxCoord measured_textx
, measured_texty
;
1107 dc
.SetFont(m_measuring_font
);
1108 dc
.GetTextExtent(caption
, &measured_textx
, &measured_texty
);
1110 wxCoord tab_height
= measured_texty
+ 4;
1111 wxCoord tab_width
= measured_textx
+ tab_height
+ 5;
1113 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1114 tab_width
+= m_active_close_bmp
.GetWidth();
1116 if (m_flags
& wxAUI_NB_TAB_FIXED_WIDTH
)
1118 tab_width
= m_fixed_tab_width
;
1121 *x_extent
= tab_width
- (tab_height
/2) - 1;
1123 return wxSize(tab_width
, tab_height
);
1127 void wxAuiSimpleTabArt::DrawButton(wxDC
& dc
,
1128 wxWindow
* WXUNUSED(wnd
),
1129 const wxRect
& in_rect
,
1140 case wxAUI_BUTTON_CLOSE
:
1141 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1142 bmp
= m_disabled_close_bmp
;
1144 bmp
= m_active_close_bmp
;
1146 case wxAUI_BUTTON_LEFT
:
1147 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1148 bmp
= m_disabled_left_bmp
;
1150 bmp
= m_active_left_bmp
;
1152 case wxAUI_BUTTON_RIGHT
:
1153 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1154 bmp
= m_disabled_right_bmp
;
1156 bmp
= m_active_right_bmp
;
1158 case wxAUI_BUTTON_WINDOWLIST
:
1159 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1160 bmp
= m_disabled_windowlist_bmp
;
1162 bmp
= m_active_windowlist_bmp
;
1171 if (orientation
== wxLEFT
)
1173 rect
.SetX(in_rect
.x
);
1174 rect
.SetY(((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2));
1175 rect
.SetWidth(bmp
.GetWidth());
1176 rect
.SetHeight(bmp
.GetHeight());
1180 rect
= wxRect(in_rect
.x
+ in_rect
.width
- bmp
.GetWidth(),
1181 ((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2),
1182 bmp
.GetWidth(), bmp
.GetHeight());
1186 DrawButtons(dc
, rect
, bmp
, *wxWHITE
, button_state
);
1191 int wxAuiSimpleTabArt::ShowDropDown(wxWindow
* wnd
,
1192 const wxAuiNotebookPageArray
& pages
,
1197 size_t i
, count
= pages
.GetCount();
1198 for (i
= 0; i
< count
; ++i
)
1200 const wxAuiNotebookPage
& page
= pages
.Item(i
);
1201 menuPopup
.AppendCheckItem(1000+i
, page
.caption
);
1204 if (active_idx
!= -1)
1206 menuPopup
.Check(1000+active_idx
, true);
1209 // find out where to put the popup menu of window
1210 // items. Subtract 100 for now to center the menu
1211 // a bit, until a better mechanism can be implemented
1212 wxPoint pt
= ::wxGetMousePosition();
1213 pt
= wnd
->ScreenToClient(pt
);
1219 // find out the screen coordinate at the bottom of the tab ctrl
1220 wxRect cli_rect
= wnd
->GetClientRect();
1221 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
1223 wxAuiCommandCapture
* cc
= new wxAuiCommandCapture
;
1224 wnd
->PushEventHandler(cc
);
1225 wnd
->PopupMenu(&menuPopup
, pt
);
1226 int command
= cc
->GetCommandId();
1227 wnd
->PopEventHandler(true);
1229 if (command
>= 1000)
1230 return command
-1000;
1235 int wxAuiSimpleTabArt::GetBestTabCtrlSize(wxWindow
* wnd
,
1236 const wxAuiNotebookPageArray
& WXUNUSED(pages
),
1237 const wxSize
& WXUNUSED(required_bmp_size
))
1240 dc
.SetFont(m_measuring_font
);
1242 wxSize s
= GetTabSize(dc
,
1247 wxAUI_BUTTON_STATE_HIDDEN
,
1252 void wxAuiSimpleTabArt::SetNormalFont(const wxFont
& font
)
1254 m_normal_font
= font
;
1257 void wxAuiSimpleTabArt::SetSelectedFont(const wxFont
& font
)
1259 m_selected_font
= font
;
1262 void wxAuiSimpleTabArt::SetMeasuringFont(const wxFont
& font
)
1264 m_measuring_font
= font
;
1270 // -- wxAuiTabContainer class implementation --
1273 // wxAuiTabContainer is a class which contains information about each
1274 // tab. It also can render an entire tab control to a specified DC.
1275 // It's not a window class itself, because this code will be used by
1276 // the wxFrameMananger, where it is disadvantageous to have separate
1277 // windows for each tab control in the case of "docked tabs"
1279 // A derived class, wxAuiTabCtrl, is an actual wxWindow-derived window
1280 // which can be used as a tab control in the normal sense.
1283 wxAuiTabContainer::wxAuiTabContainer()
1287 m_art
= new wxAuiDefaultTabArt
;
1289 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
1290 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
1291 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
1292 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
1295 wxAuiTabContainer::~wxAuiTabContainer()
1300 void wxAuiTabContainer::SetArtProvider(wxAuiTabArt
* art
)
1307 m_art
->SetFlags(m_flags
);
1311 wxAuiTabArt
* wxAuiTabContainer::GetArtProvider() const
1316 void wxAuiTabContainer::SetFlags(unsigned int flags
)
1320 // check for new close button settings
1321 RemoveButton(wxAUI_BUTTON_LEFT
);
1322 RemoveButton(wxAUI_BUTTON_RIGHT
);
1323 RemoveButton(wxAUI_BUTTON_WINDOWLIST
);
1324 RemoveButton(wxAUI_BUTTON_CLOSE
);
1327 if (flags
& wxAUI_NB_SCROLL_BUTTONS
)
1329 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
1330 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
1333 if (flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
1335 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
1338 if (flags
& wxAUI_NB_CLOSE_BUTTON
)
1340 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
1345 m_art
->SetFlags(m_flags
);
1349 unsigned int wxAuiTabContainer::GetFlags() const
1355 void wxAuiTabContainer::SetNormalFont(const wxFont
& font
)
1357 m_art
->SetNormalFont(font
);
1360 void wxAuiTabContainer::SetSelectedFont(const wxFont
& font
)
1362 m_art
->SetSelectedFont(font
);
1365 void wxAuiTabContainer::SetMeasuringFont(const wxFont
& font
)
1367 m_art
->SetMeasuringFont(font
);
1370 void wxAuiTabContainer::SetRect(const wxRect
& rect
)
1376 m_art
->SetSizingInfo(rect
.GetSize(), m_pages
.GetCount());
1380 bool wxAuiTabContainer::AddPage(wxWindow
* page
,
1381 const wxAuiNotebookPage
& info
)
1383 wxAuiNotebookPage page_info
;
1385 page_info
.window
= page
;
1387 m_pages
.Add(page_info
);
1389 // let the art provider know how many pages we have
1392 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1398 bool wxAuiTabContainer::InsertPage(wxWindow
* page
,
1399 const wxAuiNotebookPage
& info
,
1402 wxAuiNotebookPage page_info
;
1404 page_info
.window
= page
;
1406 if (idx
>= m_pages
.GetCount())
1407 m_pages
.Add(page_info
);
1409 m_pages
.Insert(page_info
, idx
);
1411 // let the art provider know how many pages we have
1414 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1420 bool wxAuiTabContainer::MovePage(wxWindow
* page
,
1423 int idx
= GetIdxFromWindow(page
);
1427 // get page entry, make a copy of it
1428 wxAuiNotebookPage p
= GetPage(idx
);
1430 // remove old page entry
1433 // insert page where it should be
1434 InsertPage(page
, p
, new_idx
);
1439 bool wxAuiTabContainer::RemovePage(wxWindow
* wnd
)
1441 size_t i
, page_count
= m_pages
.GetCount();
1442 for (i
= 0; i
< page_count
; ++i
)
1444 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1445 if (page
.window
== wnd
)
1447 m_pages
.RemoveAt(i
);
1449 // let the art provider know how many pages we have
1452 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1462 bool wxAuiTabContainer::SetActivePage(wxWindow
* wnd
)
1466 size_t i
, page_count
= m_pages
.GetCount();
1467 for (i
= 0; i
< page_count
; ++i
)
1469 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1470 if (page
.window
== wnd
)
1477 page
.active
= false;
1484 void wxAuiTabContainer::SetNoneActive()
1486 size_t i
, page_count
= m_pages
.GetCount();
1487 for (i
= 0; i
< page_count
; ++i
)
1489 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1490 page
.active
= false;
1494 bool wxAuiTabContainer::SetActivePage(size_t page
)
1496 if (page
>= m_pages
.GetCount())
1499 return SetActivePage(m_pages
.Item(page
).window
);
1502 int wxAuiTabContainer::GetActivePage() const
1504 size_t i
, page_count
= m_pages
.GetCount();
1505 for (i
= 0; i
< page_count
; ++i
)
1507 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1515 wxWindow
* wxAuiTabContainer::GetWindowFromIdx(size_t idx
) const
1517 if (idx
>= m_pages
.GetCount())
1520 return m_pages
[idx
].window
;
1523 int wxAuiTabContainer::GetIdxFromWindow(wxWindow
* wnd
) const
1525 const size_t page_count
= m_pages
.GetCount();
1526 for ( size_t i
= 0; i
< page_count
; ++i
)
1528 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1529 if (page
.window
== wnd
)
1535 wxAuiNotebookPage
& wxAuiTabContainer::GetPage(size_t idx
)
1537 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
1539 return m_pages
[idx
];
1542 const wxAuiNotebookPage
& wxAuiTabContainer::GetPage(size_t idx
) const
1544 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
1546 return m_pages
[idx
];
1549 wxAuiNotebookPageArray
& wxAuiTabContainer::GetPages()
1554 size_t wxAuiTabContainer::GetPageCount() const
1556 return m_pages
.GetCount();
1559 void wxAuiTabContainer::AddButton(int id
,
1561 const wxBitmap
& normal_bitmap
,
1562 const wxBitmap
& disabled_bitmap
)
1564 wxAuiTabContainerButton button
;
1566 button
.bitmap
= normal_bitmap
;
1567 button
.dis_bitmap
= disabled_bitmap
;
1568 button
.location
= location
;
1569 button
.cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
1571 m_buttons
.Add(button
);
1574 void wxAuiTabContainer::RemoveButton(int id
)
1576 size_t i
, button_count
= m_buttons
.GetCount();
1578 for (i
= 0; i
< button_count
; ++i
)
1580 if (m_buttons
.Item(i
).id
== id
)
1582 m_buttons
.RemoveAt(i
);
1590 size_t wxAuiTabContainer::GetTabOffset() const
1592 return m_tab_offset
;
1595 void wxAuiTabContainer::SetTabOffset(size_t offset
)
1597 m_tab_offset
= offset
;
1603 // Render() renders the tab catalog to the specified DC
1604 // It is a virtual function and can be overridden to
1605 // provide custom drawing capabilities
1606 void wxAuiTabContainer::Render(wxDC
* raw_dc
, wxWindow
* wnd
)
1608 if (!raw_dc
|| !raw_dc
->IsOk())
1613 // use the same layout direction as the window DC uses to ensure that the
1614 // text is rendered correctly
1615 dc
.SetLayoutDirection(raw_dc
->GetLayoutDirection());
1619 size_t page_count
= m_pages
.GetCount();
1620 size_t button_count
= m_buttons
.GetCount();
1622 // create off-screen bitmap
1623 bmp
.Create(m_rect
.GetWidth(), m_rect
.GetHeight());
1624 dc
.SelectObject(bmp
);
1629 // find out if size of tabs is larger than can be
1630 // afforded on screen
1631 int total_width
= 0;
1632 int visible_width
= 0;
1633 for (i
= 0; i
< page_count
; ++i
)
1635 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1637 // determine if a close button is on this tab
1638 bool close_button
= false;
1639 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1640 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1642 close_button
= true;
1647 wxSize size
= m_art
->GetTabSize(dc
,
1653 wxAUI_BUTTON_STATE_NORMAL
:
1654 wxAUI_BUTTON_STATE_HIDDEN
,
1657 if (i
+1 < page_count
)
1658 total_width
+= x_extent
;
1660 total_width
+= size
.x
;
1662 if (i
>= m_tab_offset
)
1664 if (i
+1 < page_count
)
1665 visible_width
+= x_extent
;
1667 visible_width
+= size
.x
;
1671 if (total_width
> m_rect
.GetWidth() || m_tab_offset
!= 0)
1673 // show left/right buttons
1674 for (i
= 0; i
< button_count
; ++i
)
1676 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1677 if (button
.id
== wxAUI_BUTTON_LEFT
||
1678 button
.id
== wxAUI_BUTTON_RIGHT
)
1680 button
.cur_state
&= ~wxAUI_BUTTON_STATE_HIDDEN
;
1686 // hide left/right buttons
1687 for (i
= 0; i
< button_count
; ++i
)
1689 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1690 if (button
.id
== wxAUI_BUTTON_LEFT
||
1691 button
.id
== wxAUI_BUTTON_RIGHT
)
1693 button
.cur_state
|= wxAUI_BUTTON_STATE_HIDDEN
;
1698 // determine whether left button should be enabled
1699 for (i
= 0; i
< button_count
; ++i
)
1701 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1702 if (button
.id
== wxAUI_BUTTON_LEFT
)
1704 if (m_tab_offset
== 0)
1705 button
.cur_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1707 button
.cur_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1709 if (button
.id
== wxAUI_BUTTON_RIGHT
)
1711 if (visible_width
< m_rect
.GetWidth() - ((int)button_count
*16))
1712 button
.cur_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1714 button
.cur_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1721 m_art
->DrawBackground(dc
, wnd
, m_rect
);
1724 int left_buttons_width
= 0;
1725 int right_buttons_width
= 0;
1729 // draw the buttons on the right side
1730 offset
= m_rect
.x
+ m_rect
.width
;
1731 for (i
= 0; i
< button_count
; ++i
)
1733 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1735 if (button
.location
!= wxRIGHT
)
1737 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1740 wxRect button_rect
= m_rect
;
1741 button_rect
.SetY(1);
1742 button_rect
.SetWidth(offset
);
1744 m_art
->DrawButton(dc
,
1752 offset
-= button
.rect
.GetWidth();
1753 right_buttons_width
+= button
.rect
.GetWidth();
1760 // draw the buttons on the left side
1762 for (i
= 0; i
< button_count
; ++i
)
1764 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1766 if (button
.location
!= wxLEFT
)
1768 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1771 wxRect
button_rect(offset
, 1, 1000, m_rect
.height
);
1773 m_art
->DrawButton(dc
,
1781 offset
+= button
.rect
.GetWidth();
1782 left_buttons_width
+= button
.rect
.GetWidth();
1785 offset
= left_buttons_width
;
1788 offset
+= m_art
->GetIndentSize();
1791 // prepare the tab-close-button array
1792 // make sure tab button entries which aren't used are marked as hidden
1793 for (i
= page_count
; i
< m_tab_close_buttons
.GetCount(); ++i
)
1794 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1796 // make sure there are enough tab button entries to accommodate all tabs
1797 while (m_tab_close_buttons
.GetCount() < page_count
)
1799 wxAuiTabContainerButton tempbtn
;
1800 tempbtn
.id
= wxAUI_BUTTON_CLOSE
;
1801 tempbtn
.location
= wxCENTER
;
1802 tempbtn
.cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1803 m_tab_close_buttons
.Add(tempbtn
);
1807 // buttons before the tab offset must be set to hidden
1808 for (i
= 0; i
< m_tab_offset
; ++i
)
1810 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1816 size_t active
= 999;
1817 int active_offset
= 0;
1821 wxRect rect
= m_rect
;
1823 rect
.height
= m_rect
.height
;
1825 for (i
= m_tab_offset
; i
< page_count
; ++i
)
1827 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1828 wxAuiTabContainerButton
& tab_button
= m_tab_close_buttons
.Item(i
);
1830 // determine if a close button is on this tab
1831 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1832 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1834 if (tab_button
.cur_state
== wxAUI_BUTTON_STATE_HIDDEN
)
1836 tab_button
.id
= wxAUI_BUTTON_CLOSE
;
1837 tab_button
.cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
1838 tab_button
.location
= wxCENTER
;
1843 tab_button
.cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1847 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
1849 if (rect
.width
<= 0)
1856 tab_button
.cur_state
,
1864 active_offset
= offset
;
1872 // make sure to deactivate buttons which are off the screen to the right
1873 for (++i
; i
< m_tab_close_buttons
.GetCount(); ++i
)
1875 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1879 // draw the active tab again so it stands in the foreground
1880 if (active
>= m_tab_offset
&& active
< m_pages
.GetCount())
1882 wxAuiNotebookPage
& page
= m_pages
.Item(active
);
1884 wxAuiTabContainerButton
& tab_button
= m_tab_close_buttons
.Item(active
);
1886 rect
.x
= active_offset
;
1891 tab_button
.cur_state
,
1898 raw_dc
->Blit(m_rect
.x
, m_rect
.y
,
1899 m_rect
.GetWidth(), m_rect
.GetHeight(),
1903 // Is the tab visible?
1904 bool wxAuiTabContainer::IsTabVisible(int tabPage
, int tabOffset
, wxDC
* dc
, wxWindow
* wnd
)
1906 if (!dc
|| !dc
->IsOk())
1910 size_t page_count
= m_pages
.GetCount();
1911 size_t button_count
= m_buttons
.GetCount();
1913 // Hasn't been rendered yet; assume it's visible
1914 if (m_tab_close_buttons
.GetCount() < page_count
)
1917 // First check if both buttons are disabled - if so, there's no need to
1918 // check further for visibility.
1919 int arrowButtonVisibleCount
= 0;
1920 for (i
= 0; i
< button_count
; ++i
)
1922 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1923 if (button
.id
== wxAUI_BUTTON_LEFT
||
1924 button
.id
== wxAUI_BUTTON_RIGHT
)
1926 if ((button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
) == 0)
1927 arrowButtonVisibleCount
++;
1931 // Tab must be visible
1932 if (arrowButtonVisibleCount
== 0)
1935 // If tab is less than the given offset, it must be invisible by definition
1936 if (tabPage
< tabOffset
)
1940 int left_buttons_width
= 0;
1941 int right_buttons_width
= 0;
1945 // calculate size of the buttons on the right side
1946 offset
= m_rect
.x
+ m_rect
.width
;
1947 for (i
= 0; i
< button_count
; ++i
)
1949 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1951 if (button
.location
!= wxRIGHT
)
1953 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1956 offset
-= button
.rect
.GetWidth();
1957 right_buttons_width
+= button
.rect
.GetWidth();
1962 // calculate size of the buttons on the left side
1963 for (i
= 0; i
< button_count
; ++i
)
1965 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1967 if (button
.location
!= wxLEFT
)
1969 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1972 offset
+= button
.rect
.GetWidth();
1973 left_buttons_width
+= button
.rect
.GetWidth();
1976 offset
= left_buttons_width
;
1979 offset
+= m_art
->GetIndentSize();
1983 wxRect rect
= m_rect
;
1985 rect
.height
= m_rect
.height
;
1987 // See if the given page is visible at the given tab offset (effectively scroll position)
1988 for (i
= tabOffset
; i
< page_count
; ++i
)
1990 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1991 wxAuiTabContainerButton
& tab_button
= m_tab_close_buttons
.Item(i
);
1994 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
1996 if (rect
.width
<= 0)
1997 return false; // haven't found the tab, and we've run out of space, so return false
2000 wxSize size
= m_art
->GetTabSize(*dc
,
2005 tab_button
.cur_state
,
2010 if (i
== (size_t) tabPage
)
2012 // If not all of the tab is visible, and supposing there's space to display it all,
2013 // we could do better so we return false.
2014 if (((m_rect
.width
- right_buttons_width
- offset
- 2) <= 0) && ((m_rect
.width
- right_buttons_width
- left_buttons_width
) > x_extent
))
2021 // Shouldn't really get here, but if it does, assume the tab is visible to prevent
2022 // further looping in calling code.
2026 // Make the tab visible if it wasn't already
2027 void wxAuiTabContainer::MakeTabVisible(int tabPage
, wxWindow
* win
)
2030 if (!IsTabVisible(tabPage
, GetTabOffset(), & dc
, win
))
2033 for (i
= 0; i
< (int) m_pages
.GetCount(); i
++)
2035 if (IsTabVisible(tabPage
, i
, & dc
, win
))
2045 // TabHitTest() tests if a tab was hit, passing the window pointer
2046 // back if that condition was fulfilled. The function returns
2047 // true if a tab was hit, otherwise false
2048 bool wxAuiTabContainer::TabHitTest(int x
, int y
, wxWindow
** hit
) const
2050 if (!m_rect
.Contains(x
,y
))
2053 wxAuiTabContainerButton
* btn
= NULL
;
2054 if (ButtonHitTest(x
, y
, &btn
) && !(btn
->cur_state
& wxAUI_BUTTON_STATE_DISABLED
))
2056 if (m_buttons
.Index(*btn
) != wxNOT_FOUND
)
2060 size_t i
, page_count
= m_pages
.GetCount();
2062 for (i
= m_tab_offset
; i
< page_count
; ++i
)
2064 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
2065 if (page
.rect
.Contains(x
,y
))
2076 // ButtonHitTest() tests if a button was hit. The function returns
2077 // true if a button was hit, otherwise false
2078 bool wxAuiTabContainer::ButtonHitTest(int x
, int y
,
2079 wxAuiTabContainerButton
** hit
) const
2081 if (!m_rect
.Contains(x
,y
))
2084 size_t i
, button_count
;
2087 button_count
= m_buttons
.GetCount();
2088 for (i
= 0; i
< button_count
; ++i
)
2090 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
2091 if (button
.rect
.Contains(x
,y
) &&
2092 !(button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
))
2100 button_count
= m_tab_close_buttons
.GetCount();
2101 for (i
= 0; i
< button_count
; ++i
)
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
)))
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
)
2125 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
2127 wxAuiMDIChildFrame
* cf
= (wxAuiMDIChildFrame
*)wnd
;
2138 // DoShowHide() this function shows the active window, then
2139 // hides all of the other windows (in that order)
2140 void wxAuiTabContainer::DoShowHide()
2142 wxAuiNotebookPageArray
& pages
= GetPages();
2143 size_t i
, page_count
= pages
.GetCount();
2145 // show new active page first
2146 for (i
= 0; i
< page_count
; ++i
)
2148 wxAuiNotebookPage
& page
= pages
.Item(i
);
2151 ShowWnd(page
.window
, true);
2156 // hide all other pages
2157 for (i
= 0; i
< page_count
; ++i
)
2159 wxAuiNotebookPage
& page
= pages
.Item(i
);
2161 ShowWnd(page
.window
, false);
2170 // -- wxAuiTabCtrl class implementation --
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 EVT_MOUSE_CAPTURE_LOST(wxAuiTabCtrl::OnCaptureLost
)
2195 wxAuiTabCtrl::wxAuiTabCtrl(wxWindow
* parent
,
2199 long style
) : wxControl(parent
, id
, pos
, size
, style
)
2201 SetName(wxT("wxAuiTabCtrl"));
2202 m_click_pt
= wxDefaultPosition
;
2203 m_is_dragging
= false;
2204 m_hover_button
= NULL
;
2205 m_pressed_button
= NULL
;
2208 wxAuiTabCtrl::~wxAuiTabCtrl()
2212 void wxAuiTabCtrl::OnPaint(wxPaintEvent
&)
2216 dc
.SetFont(GetFont());
2218 if (GetPageCount() > 0)
2222 void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2226 void wxAuiTabCtrl::OnSize(wxSizeEvent
& evt
)
2228 wxSize s
= evt
.GetSize();
2229 wxRect
r(0, 0, s
.GetWidth(), s
.GetHeight());
2233 void wxAuiTabCtrl::OnLeftDown(wxMouseEvent
& evt
)
2236 m_click_pt
= wxDefaultPosition
;
2237 m_is_dragging
= false;
2239 m_pressed_button
= NULL
;
2243 if (TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2245 int new_selection
= GetIdxFromWindow(wnd
);
2247 // wxAuiNotebooks always want to receive this event
2248 // even if the tab is already active, because they may
2249 // have multiple tab controls
2250 if (new_selection
!= GetActivePage() ||
2251 GetParent()->IsKindOf(CLASSINFO(wxAuiNotebook
)))
2253 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2254 e
.SetSelection(new_selection
);
2255 e
.SetOldSelection(GetActivePage());
2256 e
.SetEventObject(this);
2257 GetEventHandler()->ProcessEvent(e
);
2260 m_click_pt
.x
= evt
.m_x
;
2261 m_click_pt
.y
= evt
.m_y
;
2267 m_pressed_button
= m_hover_button
;
2268 m_pressed_button
->cur_state
= wxAUI_BUTTON_STATE_PRESSED
;
2274 void wxAuiTabCtrl::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
2278 void wxAuiTabCtrl::OnLeftUp(wxMouseEvent
& evt
)
2280 if (GetCapture() == this)
2285 m_is_dragging
= false;
2287 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
, m_windowId
);
2288 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2289 evt
.SetOldSelection(evt
.GetSelection());
2290 evt
.SetEventObject(this);
2291 GetEventHandler()->ProcessEvent(evt
);
2296 if (m_pressed_button
)
2298 // make sure we're still clicking the button
2299 wxAuiTabContainerButton
* button
= NULL
;
2300 if (!ButtonHitTest(evt
.m_x
, evt
.m_y
, &button
) ||
2301 button
->cur_state
& wxAUI_BUTTON_STATE_DISABLED
)
2304 if (button
!= m_pressed_button
)
2306 m_pressed_button
= NULL
;
2313 if (!(m_pressed_button
->cur_state
& wxAUI_BUTTON_STATE_DISABLED
))
2315 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
, m_windowId
);
2316 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2317 evt
.SetInt(m_pressed_button
->id
);
2318 evt
.SetEventObject(this);
2319 GetEventHandler()->ProcessEvent(evt
);
2322 m_pressed_button
= NULL
;
2325 m_click_pt
= wxDefaultPosition
;
2326 m_is_dragging
= false;
2330 void wxAuiTabCtrl::OnMiddleUp(wxMouseEvent
& evt
)
2332 wxWindow
* wnd
= NULL
;
2333 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2336 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, m_windowId
);
2337 e
.SetEventObject(this);
2338 e
.SetSelection(GetIdxFromWindow(wnd
));
2339 GetEventHandler()->ProcessEvent(e
);
2342 void wxAuiTabCtrl::OnMiddleDown(wxMouseEvent
& evt
)
2344 wxWindow
* wnd
= NULL
;
2345 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2348 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, m_windowId
);
2349 e
.SetEventObject(this);
2350 e
.SetSelection(GetIdxFromWindow(wnd
));
2351 GetEventHandler()->ProcessEvent(e
);
2354 void wxAuiTabCtrl::OnRightUp(wxMouseEvent
& evt
)
2356 wxWindow
* wnd
= NULL
;
2357 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2360 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, m_windowId
);
2361 e
.SetEventObject(this);
2362 e
.SetSelection(GetIdxFromWindow(wnd
));
2363 GetEventHandler()->ProcessEvent(e
);
2366 void wxAuiTabCtrl::OnRightDown(wxMouseEvent
& evt
)
2368 wxWindow
* wnd
= NULL
;
2369 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2372 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, m_windowId
);
2373 e
.SetEventObject(this);
2374 e
.SetSelection(GetIdxFromWindow(wnd
));
2375 GetEventHandler()->ProcessEvent(e
);
2378 void wxAuiTabCtrl::OnLeftDClick(wxMouseEvent
& evt
)
2381 wxAuiTabContainerButton
* button
;
2382 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
) && !ButtonHitTest(evt
.m_x
, evt
.m_y
, &button
))
2384 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, m_windowId
);
2385 e
.SetEventObject(this);
2386 GetEventHandler()->ProcessEvent(e
);
2390 void wxAuiTabCtrl::OnMotion(wxMouseEvent
& evt
)
2392 wxPoint pos
= evt
.GetPosition();
2394 // check if the mouse is hovering above a button
2395 wxAuiTabContainerButton
* button
;
2396 if (ButtonHitTest(pos
.x
, pos
.y
, &button
) && !(button
->cur_state
& wxAUI_BUTTON_STATE_DISABLED
))
2398 if (m_hover_button
&& button
!= m_hover_button
)
2400 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2401 m_hover_button
= NULL
;
2406 if (button
->cur_state
!= wxAUI_BUTTON_STATE_HOVER
)
2408 button
->cur_state
= wxAUI_BUTTON_STATE_HOVER
;
2411 m_hover_button
= button
;
2419 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2420 m_hover_button
= NULL
;
2427 if (!evt
.LeftIsDown() || m_click_pt
== wxDefaultPosition
)
2432 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
, m_windowId
);
2433 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2434 evt
.SetOldSelection(evt
.GetSelection());
2435 evt
.SetEventObject(this);
2436 GetEventHandler()->ProcessEvent(evt
);
2441 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
2442 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
2444 if (abs(pos
.x
- m_click_pt
.x
) > drag_x_threshold
||
2445 abs(pos
.y
- m_click_pt
.y
) > drag_y_threshold
)
2447 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
, m_windowId
);
2448 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2449 evt
.SetOldSelection(evt
.GetSelection());
2450 evt
.SetEventObject(this);
2451 GetEventHandler()->ProcessEvent(evt
);
2453 m_is_dragging
= true;
2457 void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
2461 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2462 m_hover_button
= NULL
;
2468 void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent
& event
)
2470 int button
= event
.GetInt();
2472 if (button
== wxAUI_BUTTON_LEFT
|| button
== wxAUI_BUTTON_RIGHT
)
2474 if (button
== wxAUI_BUTTON_LEFT
)
2476 if (GetTabOffset() > 0)
2478 SetTabOffset(GetTabOffset()-1);
2485 SetTabOffset(GetTabOffset()+1);
2490 else if (button
== wxAUI_BUTTON_WINDOWLIST
)
2492 int idx
= GetArtProvider()->ShowDropDown(this, m_pages
, GetActivePage());
2496 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2497 e
.SetSelection(idx
);
2498 e
.SetOldSelection(GetActivePage());
2499 e
.SetEventObject(this);
2500 GetEventHandler()->ProcessEvent(e
);
2509 void wxAuiTabCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
2514 void wxAuiTabCtrl::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
2519 void wxAuiTabCtrl::OnChar(wxKeyEvent
& event
)
2521 if (GetActivePage() == -1)
2527 // We can't leave tab processing to the system; on Windows, tabs and keys
2528 // get eaten by the system and not processed properly if we specify both
2529 // wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL,
2530 // we don't key arrow key events.
2532 int key
= event
.GetKeyCode();
2534 if (key
== WXK_NUMPAD_PAGEUP
)
2536 if (key
== WXK_NUMPAD_PAGEDOWN
)
2538 if (key
== WXK_NUMPAD_HOME
)
2540 if (key
== WXK_NUMPAD_END
)
2542 if (key
== WXK_NUMPAD_LEFT
)
2544 if (key
== WXK_NUMPAD_RIGHT
)
2547 if (key
== WXK_TAB
|| key
== WXK_PAGEUP
|| key
== WXK_PAGEDOWN
)
2549 bool bCtrlDown
= event
.ControlDown();
2550 bool bShiftDown
= event
.ShiftDown();
2552 bool bForward
= (key
== WXK_TAB
&& !bShiftDown
) || (key
== WXK_PAGEDOWN
);
2553 bool bWindowChange
= (key
== WXK_PAGEUP
) || (key
== WXK_PAGEDOWN
) || bCtrlDown
;
2554 bool bFromTab
= (key
== WXK_TAB
);
2556 wxAuiNotebook
* nb
= wxDynamicCast(GetParent(), wxAuiNotebook
);
2563 wxNavigationKeyEvent keyEvent
;
2564 keyEvent
.SetDirection(bForward
);
2565 keyEvent
.SetWindowChange(bWindowChange
);
2566 keyEvent
.SetFromTab(bFromTab
);
2567 keyEvent
.SetEventObject(nb
);
2569 if (!nb
->GetEventHandler()->ProcessEvent(keyEvent
))
2571 // Not processed? Do an explicit tab into the page.
2572 wxWindow
* win
= GetWindowFromIdx(GetActivePage());
2579 if (m_pages
.GetCount() < 2)
2587 int forwardKey
, backwardKey
;
2588 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2590 forwardKey
= WXK_LEFT
;
2591 backwardKey
= WXK_RIGHT
;
2595 forwardKey
= WXK_RIGHT
;
2596 backwardKey
= WXK_LEFT
;
2599 if (key
== forwardKey
)
2601 if (m_pages
.GetCount() > 1)
2603 if (GetActivePage() == -1)
2605 else if (GetActivePage() < (int) (m_pages
.GetCount() - 1))
2606 newPage
= GetActivePage() + 1;
2609 else if (key
== backwardKey
)
2611 if (m_pages
.GetCount() > 1)
2613 if (GetActivePage() == -1)
2614 newPage
= (int) (m_pages
.GetCount() - 1);
2615 else if (GetActivePage() > 0)
2616 newPage
= GetActivePage() - 1;
2619 else if (key
== WXK_HOME
)
2623 else if (key
== WXK_END
)
2625 newPage
= (int) (m_pages
.GetCount() - 1);
2632 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2633 e
.SetSelection(newPage
);
2634 e
.SetOldSelection(newPage
);
2635 e
.SetEventObject(this);
2636 this->GetEventHandler()->ProcessEvent(e
);
2642 // wxTabFrame is an interesting case. It's important that all child pages
2643 // of the multi-notebook control are all actually children of that control
2644 // (and not grandchildren). wxTabFrame facilitates this. There is one
2645 // instance of wxTabFrame for each tab control inside the multi-notebook.
2646 // It's important to know that wxTabFrame is not a real window, but it merely
2647 // used to capture the dimensions/positioning of the internal tab control and
2648 // it's managed page windows
2650 class wxTabFrame
: public wxWindow
2657 m_rect
= wxRect(0,0,200,200);
2658 m_tab_ctrl_height
= 20;
2666 void SetTabCtrlHeight(int h
)
2668 m_tab_ctrl_height
= h
;
2672 void DoSetSize(int x
, int y
,
2673 int width
, int height
,
2674 int WXUNUSED(sizeFlags
= wxSIZE_AUTO
))
2676 m_rect
= wxRect(x
, y
, width
, height
);
2680 void DoGetClientSize(int* x
, int* y
) const
2687 bool Show( bool WXUNUSED(show
= true) ) { return false; }
2694 if (m_tabs
->IsFrozen() || m_tabs
->GetParent()->IsFrozen())
2697 m_tab_rect
= wxRect(m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tab_ctrl_height
);
2698 if (m_tabs
->GetFlags() & wxAUI_NB_BOTTOM
)
2700 m_tab_rect
= wxRect (m_rect
.x
, m_rect
.y
+ m_rect
.height
- m_tab_ctrl_height
, m_rect
.width
, m_tab_ctrl_height
);
2701 m_tabs
->SetSize (m_rect
.x
, m_rect
.y
+ m_rect
.height
- m_tab_ctrl_height
, m_rect
.width
, m_tab_ctrl_height
);
2702 m_tabs
->SetRect (wxRect(0, 0, m_rect
.width
, m_tab_ctrl_height
));
2704 else //TODO: if (GetFlags() & wxAUI_NB_TOP)
2706 m_tab_rect
= wxRect (m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tab_ctrl_height
);
2707 m_tabs
->SetSize (m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tab_ctrl_height
);
2708 m_tabs
->SetRect (wxRect(0, 0, m_rect
.width
, m_tab_ctrl_height
));
2710 // TODO: else if (GetFlags() & wxAUI_NB_LEFT){}
2711 // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){}
2716 wxAuiNotebookPageArray
& pages
= m_tabs
->GetPages();
2717 size_t i
, page_count
= pages
.GetCount();
2719 for (i
= 0; i
< page_count
; ++i
)
2721 int height
= m_rect
.height
- m_tab_ctrl_height
;
2724 // avoid passing negative height to wxWindow::SetSize(), this
2725 // results in assert failures/GTK+ warnings
2729 wxAuiNotebookPage
& page
= pages
.Item(i
);
2730 if (m_tabs
->GetFlags() & wxAUI_NB_BOTTOM
)
2732 page
.window
->SetSize(m_rect
.x
, m_rect
.y
, m_rect
.width
, height
);
2734 else //TODO: if (GetFlags() & wxAUI_NB_TOP)
2736 page
.window
->SetSize(m_rect
.x
, m_rect
.y
+ m_tab_ctrl_height
,
2737 m_rect
.width
, height
);
2739 // TODO: else if (GetFlags() & wxAUI_NB_LEFT){}
2740 // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){}
2743 if (page
.window
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
2745 wxAuiMDIChildFrame
* wnd
= (wxAuiMDIChildFrame
*)page
.window
;
2746 wnd
->ApplyMDIChildFrameRect();
2753 void DoGetSize(int* x
, int* y
) const
2756 *x
= m_rect
.GetWidth();
2758 *y
= m_rect
.GetHeight();
2769 wxAuiTabCtrl
* m_tabs
;
2770 int m_tab_ctrl_height
;
2774 const int wxAuiBaseTabCtrlId
= 5380;
2777 // -- wxAuiNotebook class implementation --
2779 #define EVT_AUI_RANGE(id1, id2, event, func) \
2780 wx__DECLARE_EVT2(event, id1, id2, wxAuiNotebookEventHandler(func))
2782 BEGIN_EVENT_TABLE(wxAuiNotebook
, wxControl
)
2783 EVT_SIZE(wxAuiNotebook::OnSize
)
2784 EVT_CHILD_FOCUS(wxAuiNotebook::OnChildFocusNotebook
)
2785 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2786 wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
,
2787 wxAuiNotebook::OnTabClicked
)
2788 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2789 wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
,
2790 wxAuiNotebook::OnTabBeginDrag
)
2791 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2792 wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
,
2793 wxAuiNotebook::OnTabEndDrag
)
2794 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2795 wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
,
2796 wxAuiNotebook::OnTabDragMotion
)
2797 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2798 wxEVT_COMMAND_AUINOTEBOOK_BUTTON
,
2799 wxAuiNotebook::OnTabButton
)
2800 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2801 wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
,
2802 wxAuiNotebook::OnTabMiddleDown
)
2803 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2804 wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
,
2805 wxAuiNotebook::OnTabMiddleUp
)
2806 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2807 wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
,
2808 wxAuiNotebook::OnTabRightDown
)
2809 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2810 wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
,
2811 wxAuiNotebook::OnTabRightUp
)
2812 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2813 wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
,
2814 wxAuiNotebook::OnTabBgDClick
)
2815 EVT_NAVIGATION_KEY(wxAuiNotebook::OnNavigationKeyNotebook
)
2817 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2818 WX_EVENT_TABLE_CONTROL_CONTAINER(wxAuiNotebook
)
2820 // Avoid clash with container event handler functions
2821 EVT_SET_FOCUS(wxAuiNotebook::OnFocus
)
2825 WX_DELEGATE_TO_CONTROL_CONTAINER(wxAuiNotebook
, wxControl
)
2827 wxAuiNotebook::wxAuiNotebook()
2830 m_tab_id_counter
= wxAuiBaseTabCtrlId
;
2832 m_tab_ctrl_height
= 20;
2833 m_requested_bmp_size
= wxDefaultSize
;
2834 m_requested_tabctrl_height
= -1;
2837 wxAuiNotebook::wxAuiNotebook(wxWindow
*parent
,
2841 long style
) : wxControl(parent
, id
, pos
, size
, style
)
2844 m_requested_bmp_size
= wxDefaultSize
;
2845 m_requested_tabctrl_height
= -1;
2846 InitNotebook(style
);
2849 bool wxAuiNotebook::Create(wxWindow
* parent
,
2855 if (!wxControl::Create(parent
, id
, pos
, size
, style
))
2858 InitNotebook(style
);
2863 // InitNotebook() contains common initialization
2864 // code called by all constructors
2865 void wxAuiNotebook::InitNotebook(long style
)
2867 WX_INIT_CONTROL_CONTAINER();
2868 // SetCanFocus(false);
2870 SetName(wxT("wxAuiNotebook"));
2872 m_tab_id_counter
= wxAuiBaseTabCtrlId
;
2874 m_flags
= (unsigned int)style
;
2875 m_tab_ctrl_height
= 20;
2877 m_normal_font
= *wxNORMAL_FONT
;
2878 m_selected_font
= *wxNORMAL_FONT
;
2879 m_selected_font
.SetWeight(wxBOLD
);
2881 SetArtProvider(new wxAuiDefaultTabArt
);
2883 m_dummy_wnd
= new wxWindow(this, wxID_ANY
, wxPoint(0,0), wxSize(0,0));
2884 m_dummy_wnd
->SetSize(200, 200);
2885 m_dummy_wnd
->Show(false);
2887 m_mgr
.SetManagedWindow(this);
2888 m_mgr
.SetFlags(wxAUI_MGR_DEFAULT
);
2889 m_mgr
.SetDockSizeConstraint(1.0, 1.0); // no dock size constraint
2891 m_mgr
.AddPane(m_dummy_wnd
,
2892 wxAuiPaneInfo().Name(wxT("dummy")).Bottom().CaptionVisible(false).Show(false));
2897 wxAuiNotebook::~wxAuiNotebook()
2899 // Indicate we're deleting pages
2902 while ( GetPageCount() > 0 )
2908 void wxAuiNotebook::SetArtProvider(wxAuiTabArt
* art
)
2910 m_tabs
.SetArtProvider(art
);
2912 // Update the height and do nothing else if it did something but otherwise
2913 // (i.e. if the new art provider uses the same height as the old one) we
2914 // need to manually set the art provider for all tabs ourselves.
2915 if ( !UpdateTabCtrlHeight() )
2917 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2918 const size_t pane_count
= all_panes
.GetCount();
2919 for (size_t i
= 0; i
< pane_count
; ++i
)
2921 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2922 if (pane
.name
== wxT("dummy"))
2924 wxTabFrame
* tab_frame
= (wxTabFrame
*)pane
.window
;
2925 wxAuiTabCtrl
* tabctrl
= tab_frame
->m_tabs
;
2926 tabctrl
->SetArtProvider(art
->Clone());
2931 // SetTabCtrlHeight() is the highest-level override of the
2932 // tab height. A call to this function effectively enforces a
2933 // specified tab ctrl height, overriding all other considerations,
2934 // such as text or bitmap height. It overrides any call to
2935 // SetUniformBitmapSize(). Specifying a height of -1 reverts
2936 // any previous call and returns to the default behavior
2938 void wxAuiNotebook::SetTabCtrlHeight(int height
)
2940 m_requested_tabctrl_height
= height
;
2942 // if window is already initialized, recalculate the tab height
2945 UpdateTabCtrlHeight();
2950 // SetUniformBitmapSize() ensures that all tabs will have
2951 // the same height, even if some tabs don't have bitmaps
2952 // Passing wxDefaultSize to this function will instruct
2953 // the control to use dynamic tab height-- so when a tab
2954 // with a large bitmap is added, the tab ctrl's height will
2955 // automatically increase to accommodate the bitmap
2957 void wxAuiNotebook::SetUniformBitmapSize(const wxSize
& size
)
2959 m_requested_bmp_size
= size
;
2961 // if window is already initialized, recalculate the tab height
2964 UpdateTabCtrlHeight();
2968 // UpdateTabCtrlHeight() does the actual tab resizing. It's meant
2969 // to be used internally
2970 bool wxAuiNotebook::UpdateTabCtrlHeight()
2972 // get the tab ctrl height we will use
2973 int height
= CalculateTabCtrlHeight();
2975 // if the tab control height needs to change, update
2976 // all of our tab controls with the new height
2977 if (m_tab_ctrl_height
== height
)
2980 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
2982 m_tab_ctrl_height
= height
;
2984 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2985 size_t i
, pane_count
= all_panes
.GetCount();
2986 for (i
= 0; i
< pane_count
; ++i
)
2988 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2989 if (pane
.name
== wxT("dummy"))
2991 wxTabFrame
* tab_frame
= (wxTabFrame
*)pane
.window
;
2992 wxAuiTabCtrl
* tabctrl
= tab_frame
->m_tabs
;
2993 tab_frame
->SetTabCtrlHeight(m_tab_ctrl_height
);
2994 tabctrl
->SetArtProvider(art
->Clone());
2995 tab_frame
->DoSizing();
3001 void wxAuiNotebook::UpdateHintWindowSize()
3003 wxSize size
= CalculateNewSplitSize();
3005 // the placeholder hint window should be set to this size
3006 wxAuiPaneInfo
& info
= m_mgr
.GetPane(wxT("dummy"));
3010 info
.BestSize(size
);
3011 m_dummy_wnd
->SetSize(size
);
3016 // calculates the size of the new split
3017 wxSize
wxAuiNotebook::CalculateNewSplitSize()
3019 // count number of tab controls
3020 int tab_ctrl_count
= 0;
3021 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3022 size_t i
, pane_count
= all_panes
.GetCount();
3023 for (i
= 0; i
< pane_count
; ++i
)
3025 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
3026 if (pane
.name
== wxT("dummy"))
3031 wxSize new_split_size
;
3033 // if there is only one tab control, the first split
3034 // should happen around the middle
3035 if (tab_ctrl_count
< 2)
3037 new_split_size
= GetClientSize();
3038 new_split_size
.x
/= 2;
3039 new_split_size
.y
/= 2;
3043 // this is in place of a more complicated calculation
3044 // that needs to be implemented
3045 new_split_size
= wxSize(180,180);
3048 return new_split_size
;
3051 int wxAuiNotebook::CalculateTabCtrlHeight()
3053 // if a fixed tab ctrl height is specified,
3054 // just return that instead of calculating a
3056 if (m_requested_tabctrl_height
!= -1)
3057 return m_requested_tabctrl_height
;
3059 // find out new best tab height
3060 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
3062 return art
->GetBestTabCtrlSize(this,
3064 m_requested_bmp_size
);
3068 wxAuiTabArt
* wxAuiNotebook::GetArtProvider() const
3070 return m_tabs
.GetArtProvider();
3073 void wxAuiNotebook::SetWindowStyleFlag(long style
)
3075 wxControl::SetWindowStyleFlag(style
);
3077 m_flags
= (unsigned int)style
;
3079 // if the control is already initialized
3080 if (m_mgr
.GetManagedWindow() == (wxWindow
*)this)
3082 // let all of the tab children know about the new style
3084 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3085 size_t i
, pane_count
= all_panes
.GetCount();
3086 for (i
= 0; i
< pane_count
; ++i
)
3088 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
3089 if (pane
.name
== wxT("dummy"))
3091 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
3092 wxAuiTabCtrl
* tabctrl
= tabframe
->m_tabs
;
3093 tabctrl
->SetFlags(m_flags
);
3094 tabframe
->DoSizing();
3102 bool wxAuiNotebook::AddPage(wxWindow
* page
,
3103 const wxString
& caption
,
3105 const wxBitmap
& bitmap
)
3107 return InsertPage(GetPageCount(), page
, caption
, select
, bitmap
);
3110 bool wxAuiNotebook::InsertPage(size_t page_idx
,
3112 const wxString
& caption
,
3114 const wxBitmap
& bitmap
)
3116 wxASSERT_MSG(page
, wxT("page pointer must be non-NULL"));
3120 page
->Reparent(this);
3122 wxAuiNotebookPage info
;
3124 info
.caption
= caption
;
3125 info
.bitmap
= bitmap
;
3126 info
.active
= false;
3128 // if there are currently no tabs, the first added
3129 // tab must be active
3130 if (m_tabs
.GetPageCount() == 0)
3133 m_tabs
.InsertPage(page
, info
, page_idx
);
3135 // if that was the first page added, even if
3136 // select is false, it must become the "current page"
3137 // (though no select events will be fired)
3138 if (!select
&& m_tabs
.GetPageCount() == 1)
3140 //m_curpage = GetPageIndex(page);
3142 wxAuiTabCtrl
* active_tabctrl
= GetActiveTabCtrl();
3143 if (page_idx
>= active_tabctrl
->GetPageCount())
3144 active_tabctrl
->AddPage(page
, info
);
3146 active_tabctrl
->InsertPage(page
, info
, page_idx
);
3148 UpdateTabCtrlHeight();
3150 active_tabctrl
->DoShowHide();
3152 // adjust selected index
3153 if(m_curpage
>= (int) page_idx
)
3158 SetSelectionToWindow(page
);
3165 // DeletePage() removes a tab from the multi-notebook,
3166 // and destroys the window as well
3167 bool wxAuiNotebook::DeletePage(size_t page_idx
)
3169 if (page_idx
>= m_tabs
.GetPageCount())
3172 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
3174 // hide the window in advance, as this will
3176 ShowWnd(wnd
, false);
3178 if (!RemovePage(page_idx
))
3182 // actually destroy the window now
3183 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
3185 // delete the child frame with pending delete, as is
3186 // customary with frame windows
3187 if (!wxPendingDelete
.Member(wnd
))
3188 wxPendingDelete
.Append(wnd
);
3201 // RemovePage() removes a tab from the multi-notebook,
3202 // but does not destroy the window
3203 bool wxAuiNotebook::RemovePage(size_t page_idx
)
3205 // save active window pointer
3206 wxWindow
* active_wnd
= NULL
;
3208 active_wnd
= m_tabs
.GetWindowFromIdx(m_curpage
);
3210 // save pointer of window being deleted
3211 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
3212 wxWindow
* new_active
= NULL
;
3214 // make sure we found the page
3218 // find out which onscreen tab ctrl owns this tab
3221 if (!FindTab(wnd
, &ctrl
, &ctrl_idx
))
3224 bool is_curpage
= (m_curpage
== (int)page_idx
);
3225 bool is_active_in_split
= ctrl
->GetPage(ctrl_idx
).active
;
3228 // remove the tab from main catalog
3229 if (!m_tabs
.RemovePage(wnd
))
3232 // remove the tab from the onscreen tab ctrl
3233 ctrl
->RemovePage(wnd
);
3235 if (is_active_in_split
)
3237 int ctrl_new_page_count
= (int)ctrl
->GetPageCount();
3239 if (ctrl_idx
>= ctrl_new_page_count
)
3240 ctrl_idx
= ctrl_new_page_count
-1;
3242 if (ctrl_idx
>= 0 && ctrl_idx
< (int)ctrl
->GetPageCount())
3244 // set new page as active in the tab split
3245 ctrl
->SetActivePage(ctrl_idx
);
3247 // if the page deleted was the current page for the
3248 // entire tab control, then record the window
3249 // pointer of the new active page for activation
3252 new_active
= ctrl
->GetWindowFromIdx(ctrl_idx
);
3258 // we are not deleting the active page, so keep it the same
3259 new_active
= active_wnd
;
3265 // we haven't yet found a new page to active,
3266 // so select the next page from the main tab
3269 if (page_idx
< m_tabs
.GetPageCount())
3271 new_active
= m_tabs
.GetPage(page_idx
).window
;
3274 if (!new_active
&& m_tabs
.GetPageCount() > 0)
3276 new_active
= m_tabs
.GetPage(0).window
;
3281 RemoveEmptyTabFrames();
3283 m_curpage
= wxNOT_FOUND
;
3285 // set new active pane unless we're being destroyed anyhow
3286 if (new_active
&& !m_isBeingDeleted
)
3287 SetSelectionToWindow(new_active
);
3292 // GetPageIndex() returns the index of the page, or -1 if the
3293 // page could not be located in the notebook
3294 int wxAuiNotebook::GetPageIndex(wxWindow
* page_wnd
) const
3296 return m_tabs
.GetIdxFromWindow(page_wnd
);
3301 // SetPageText() changes the tab caption of the specified page
3302 bool wxAuiNotebook::SetPageText(size_t page_idx
, const wxString
& text
)
3304 if (page_idx
>= m_tabs
.GetPageCount())
3307 // update our own tab catalog
3308 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3309 page_info
.caption
= text
;
3311 // update what's on screen
3314 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
3316 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
3317 info
.caption
= text
;
3325 // returns the page caption
3326 wxString
wxAuiNotebook::GetPageText(size_t page_idx
) const
3328 if (page_idx
>= m_tabs
.GetPageCount())
3329 return wxEmptyString
;
3331 // update our own tab catalog
3332 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3333 return page_info
.caption
;
3336 bool wxAuiNotebook::SetPageBitmap(size_t page_idx
, const wxBitmap
& bitmap
)
3338 if (page_idx
>= m_tabs
.GetPageCount())
3341 // update our own tab catalog
3342 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3343 page_info
.bitmap
= bitmap
;
3345 // tab height might have changed
3346 UpdateTabCtrlHeight();
3348 // update what's on screen
3351 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
3353 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
3354 info
.bitmap
= bitmap
;
3362 // returns the page bitmap
3363 wxBitmap
wxAuiNotebook::GetPageBitmap(size_t page_idx
) const
3365 if (page_idx
>= m_tabs
.GetPageCount())
3368 // update our own tab catalog
3369 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3370 return page_info
.bitmap
;
3373 // GetSelection() returns the index of the currently active page
3374 int wxAuiNotebook::GetSelection() const
3379 // SetSelection() sets the currently active page
3380 size_t wxAuiNotebook::SetSelection(size_t new_page
)
3382 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(new_page
);
3386 // don't change the page unless necessary;
3387 // however, clicking again on a tab should give it the focus.
3388 if ((int)new_page
== m_curpage
)
3392 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
3394 if (FindFocus() != ctrl
)
3400 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
3401 evt
.SetSelection(new_page
);
3402 evt
.SetOldSelection(m_curpage
);
3403 evt
.SetEventObject(this);
3404 if (!GetEventHandler()->ProcessEvent(evt
) || evt
.IsAllowed())
3406 int old_curpage
= m_curpage
;
3407 m_curpage
= new_page
;
3409 // program allows the page change
3410 evt
.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
);
3411 (void)GetEventHandler()->ProcessEvent(evt
);
3416 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
3418 m_tabs
.SetActivePage(wnd
);
3420 ctrl
->SetActivePage(ctrl_idx
);
3424 ctrl
->MakeTabVisible(ctrl_idx
, ctrl
);
3427 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3428 size_t i
, pane_count
= all_panes
.GetCount();
3429 for (i
= 0; i
< pane_count
; ++i
)
3431 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
3432 if (pane
.name
== wxT("dummy"))
3434 wxAuiTabCtrl
* tabctrl
= ((wxTabFrame
*)pane
.window
)->m_tabs
;
3435 if (tabctrl
!= ctrl
)
3436 tabctrl
->SetSelectedFont(m_normal_font
);
3438 tabctrl
->SetSelectedFont(m_selected_font
);
3442 // Set the focus to the page if we're not currently focused on the tab.
3443 // This is Firefox-like behaviour.
3444 if (wnd
->IsShownOnScreen() && FindFocus() != ctrl
)
3454 void wxAuiNotebook::SetSelectionToWindow(wxWindow
*win
)
3456 const int idx
= m_tabs
.GetIdxFromWindow(win
);
3457 wxCHECK_RET( idx
!= wxNOT_FOUND
, wxT("invalid notebook page") );
3460 // since a tab was clicked, let the parent know that we received
3461 // the focus, even if we will assign that focus immediately
3462 // to the child tab in the SetSelection call below
3463 // (the child focus event will also let wxAuiManager, if any,
3464 // know that the notebook control has been activated)
3466 wxWindow
* parent
= GetParent();
3469 wxChildFocusEvent
eventFocus(this);
3470 parent
->GetEventHandler()->ProcessEvent(eventFocus
);
3477 // GetPageCount() returns the total number of
3478 // pages managed by the multi-notebook
3479 size_t wxAuiNotebook::GetPageCount() const
3481 return m_tabs
.GetPageCount();
3484 // GetPage() returns the wxWindow pointer of the
3486 wxWindow
* wxAuiNotebook::GetPage(size_t page_idx
) const
3488 wxASSERT(page_idx
< m_tabs
.GetPageCount());
3490 return m_tabs
.GetWindowFromIdx(page_idx
);
3493 // DoSizing() performs all sizing operations in each tab control
3494 void wxAuiNotebook::DoSizing()
3496 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3497 size_t i
, pane_count
= all_panes
.GetCount();
3498 for (i
= 0; i
< pane_count
; ++i
)
3500 if (all_panes
.Item(i
).name
== wxT("dummy"))
3503 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3504 tabframe
->DoSizing();
3508 // GetActiveTabCtrl() returns the active tab control. It is
3509 // called to determine which control gets new windows being added
3510 wxAuiTabCtrl
* wxAuiNotebook::GetActiveTabCtrl()
3512 if (m_curpage
>= 0 && m_curpage
< (int)m_tabs
.GetPageCount())
3517 // find the tab ctrl with the current page
3518 if (FindTab(m_tabs
.GetPage(m_curpage
).window
,
3525 // no current page, just find the first tab ctrl
3526 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3527 size_t i
, pane_count
= all_panes
.GetCount();
3528 for (i
= 0; i
< pane_count
; ++i
)
3530 if (all_panes
.Item(i
).name
== wxT("dummy"))
3533 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3534 return tabframe
->m_tabs
;
3537 // If there is no tabframe at all, create one
3538 wxTabFrame
* tabframe
= new wxTabFrame
;
3539 tabframe
->SetTabCtrlHeight(m_tab_ctrl_height
);
3540 tabframe
->m_tabs
= new wxAuiTabCtrl(this,
3544 wxNO_BORDER
|wxWANTS_CHARS
);
3545 tabframe
->m_tabs
->SetFlags(m_flags
);
3546 tabframe
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3547 m_mgr
.AddPane(tabframe
,
3548 wxAuiPaneInfo().Center().CaptionVisible(false));
3552 return tabframe
->m_tabs
;
3555 // FindTab() finds the tab control that currently contains the window as well
3556 // as the index of the window in the tab control. It returns true if the
3557 // window was found, otherwise false.
3558 bool wxAuiNotebook::FindTab(wxWindow
* page
, wxAuiTabCtrl
** ctrl
, int* idx
)
3560 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3561 size_t i
, pane_count
= all_panes
.GetCount();
3562 for (i
= 0; i
< pane_count
; ++i
)
3564 if (all_panes
.Item(i
).name
== wxT("dummy"))
3567 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3569 int page_idx
= tabframe
->m_tabs
->GetIdxFromWindow(page
);
3572 *ctrl
= tabframe
->m_tabs
;
3581 void wxAuiNotebook::Split(size_t page
, int direction
)
3583 wxSize cli_size
= GetClientSize();
3585 // get the page's window pointer
3586 wxWindow
* wnd
= GetPage(page
);
3590 // notebooks with 1 or less pages can't be split
3591 if (GetPageCount() < 2)
3594 // find out which tab control the page currently belongs to
3595 wxAuiTabCtrl
*src_tabs
, *dest_tabs
;
3598 if (!FindTab(wnd
, &src_tabs
, &src_idx
))
3600 if (!src_tabs
|| src_idx
== -1)
3603 // choose a split size
3605 if (GetPageCount() > 2)
3607 split_size
= CalculateNewSplitSize();
3611 // because there are two panes, always split them
3613 split_size
= GetClientSize();
3619 // create a new tab frame
3620 wxTabFrame
* new_tabs
= new wxTabFrame
;
3621 new_tabs
->m_rect
= wxRect(wxPoint(0,0), split_size
);
3622 new_tabs
->SetTabCtrlHeight(m_tab_ctrl_height
);
3623 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
3627 wxNO_BORDER
|wxWANTS_CHARS
);
3628 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3629 new_tabs
->m_tabs
->SetFlags(m_flags
);
3630 dest_tabs
= new_tabs
->m_tabs
;
3632 // create a pane info structure with the information
3633 // about where the pane should be added
3634 wxAuiPaneInfo pane_info
= wxAuiPaneInfo().Bottom().CaptionVisible(false);
3637 if (direction
== wxLEFT
)
3640 mouse_pt
= wxPoint(0, cli_size
.y
/2);
3642 else if (direction
== wxRIGHT
)
3645 mouse_pt
= wxPoint(cli_size
.x
, cli_size
.y
/2);
3647 else if (direction
== wxTOP
)
3650 mouse_pt
= wxPoint(cli_size
.x
/2, 0);
3652 else if (direction
== wxBOTTOM
)
3655 mouse_pt
= wxPoint(cli_size
.x
/2, cli_size
.y
);
3658 m_mgr
.AddPane(new_tabs
, pane_info
, mouse_pt
);
3661 // remove the page from the source tabs
3662 wxAuiNotebookPage page_info
= src_tabs
->GetPage(src_idx
);
3663 page_info
.active
= false;
3664 src_tabs
->RemovePage(page_info
.window
);
3665 if (src_tabs
->GetPageCount() > 0)
3667 src_tabs
->SetActivePage((size_t)0);
3668 src_tabs
->DoShowHide();
3669 src_tabs
->Refresh();
3673 // add the page to the destination tabs
3674 dest_tabs
->InsertPage(page_info
.window
, page_info
, 0);
3676 if (src_tabs
->GetPageCount() == 0)
3678 RemoveEmptyTabFrames();
3682 dest_tabs
->DoShowHide();
3683 dest_tabs
->Refresh();
3685 // force the set selection function reset the selection
3688 // set the active page to the one we just split off
3689 SetSelectionToPage(page_info
);
3691 UpdateHintWindowSize();
3695 void wxAuiNotebook::OnSize(wxSizeEvent
& evt
)
3697 UpdateHintWindowSize();
3702 void wxAuiNotebook::OnTabClicked(wxAuiNotebookEvent
& evt
)
3704 wxAuiTabCtrl
* ctrl
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3705 wxASSERT(ctrl
!= NULL
);
3707 wxWindow
* wnd
= ctrl
->GetWindowFromIdx(evt
.GetSelection());
3708 wxASSERT(wnd
!= NULL
);
3710 SetSelectionToWindow(wnd
);
3713 void wxAuiNotebook::OnTabBgDClick(wxAuiNotebookEvent
& WXUNUSED(evt
))
3715 // notify owner that the tabbar background has been double-clicked
3716 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, m_windowId
);
3717 e
.SetEventObject(this);
3718 GetEventHandler()->ProcessEvent(e
);
3721 void wxAuiNotebook::OnTabBeginDrag(wxAuiNotebookEvent
&)
3726 void wxAuiNotebook::OnTabDragMotion(wxAuiNotebookEvent
& evt
)
3728 wxPoint screen_pt
= ::wxGetMousePosition();
3729 wxPoint client_pt
= ScreenToClient(screen_pt
);
3732 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3733 wxAuiTabCtrl
* dest_tabs
= GetTabCtrlFromPoint(client_pt
);
3735 if (dest_tabs
== src_tabs
)
3739 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
3742 // always hide the hint for inner-tabctrl drag
3745 // if tab moving is not allowed, leave
3746 if (!(m_flags
& wxAUI_NB_TAB_MOVE
))
3751 wxPoint pt
= dest_tabs
->ScreenToClient(screen_pt
);
3752 wxWindow
* dest_location_tab
;
3754 // this is an inner-tab drag/reposition
3755 if (dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &dest_location_tab
))
3757 int src_idx
= evt
.GetSelection();
3758 int dest_idx
= dest_tabs
->GetIdxFromWindow(dest_location_tab
);
3760 // prevent jumpy drag
3761 if ((src_idx
== dest_idx
) || dest_idx
== -1 ||
3762 (src_idx
> dest_idx
&& m_last_drag_x
<= pt
.x
) ||
3763 (src_idx
< dest_idx
&& m_last_drag_x
>= pt
.x
))
3765 m_last_drag_x
= pt
.x
;
3770 wxWindow
* src_tab
= dest_tabs
->GetWindowFromIdx(src_idx
);
3771 dest_tabs
->MovePage(src_tab
, dest_idx
);
3772 dest_tabs
->SetActivePage((size_t)dest_idx
);
3773 dest_tabs
->DoShowHide();
3774 dest_tabs
->Refresh();
3775 m_last_drag_x
= pt
.x
;
3783 // if external drag is allowed, check if the tab is being dragged
3784 // over a different wxAuiNotebook control
3785 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
3787 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(screen_pt
);
3789 // if we aren't over any window, stop here
3793 // make sure we are not over the hint window
3794 if (!tab_ctrl
->IsKindOf(CLASSINFO(wxFrame
)))
3798 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
3800 tab_ctrl
= tab_ctrl
->GetParent();
3805 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
3809 wxRect hint_rect
= tab_ctrl
->GetClientRect();
3810 tab_ctrl
->ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
3811 m_mgr
.ShowHint(hint_rect
);
3820 // we are either over a hint window, or not over a tab
3821 // window, and there is no where to drag to, so exit
3828 // if there are less than two panes, split can't happen, so leave
3829 if (m_tabs
.GetPageCount() < 2)
3832 // if tab moving is not allowed, leave
3833 if (!(m_flags
& wxAUI_NB_TAB_SPLIT
))
3839 src_tabs
->SetCursor(wxCursor(wxCURSOR_SIZING
));
3845 wxRect hint_rect
= dest_tabs
->GetRect();
3846 ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
3847 m_mgr
.ShowHint(hint_rect
);
3851 m_mgr
.DrawHintRect(m_dummy_wnd
, client_pt
, zero
);
3857 void wxAuiNotebook::OnTabEndDrag(wxAuiNotebookEvent
& evt
)
3862 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3863 wxCHECK_RET( src_tabs
, wxT("no source object?") );
3865 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
3867 // get the mouse position, which will be used to determine the drop point
3868 wxPoint mouse_screen_pt
= ::wxGetMousePosition();
3869 wxPoint mouse_client_pt
= ScreenToClient(mouse_screen_pt
);
3873 // check for an external move
3874 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
3876 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(mouse_screen_pt
);
3880 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
3882 tab_ctrl
= tab_ctrl
->GetParent();
3887 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
3891 // find out from the destination control
3892 // if it's ok to drop this tab here
3893 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
, m_windowId
);
3894 e
.SetSelection(evt
.GetSelection());
3895 e
.SetOldSelection(evt
.GetSelection());
3896 e
.SetEventObject(this);
3897 e
.SetDragSource(this);
3898 e
.Veto(); // dropping must be explicitly approved by control owner
3900 nb
->GetEventHandler()->ProcessEvent(e
);
3904 // no answer or negative answer
3910 int src_idx
= evt
.GetSelection();
3911 wxWindow
* src_page
= src_tabs
->GetWindowFromIdx(src_idx
);
3913 // Check that it's not an impossible parent relationship
3915 while (p
&& !p
->IsTopLevel())
3924 // get main index of the page
3925 int main_idx
= m_tabs
.GetIdxFromWindow(src_page
);
3926 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, wxT("no source page?") );
3929 // make a copy of the page info
3930 wxAuiNotebookPage page_info
= m_tabs
.GetPage(main_idx
);
3932 // remove the page from the source notebook
3933 RemovePage(main_idx
);
3935 // reparent the page
3936 src_page
->Reparent(nb
);
3939 // found out the insert idx
3940 wxAuiTabCtrl
* dest_tabs
= (wxAuiTabCtrl
*)tab_ctrl
;
3941 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
3943 wxWindow
* target
= NULL
;
3944 int insert_idx
= -1;
3945 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
3948 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
3952 // add the page to the new notebook
3953 if (insert_idx
== -1)
3954 insert_idx
= dest_tabs
->GetPageCount();
3955 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
3956 nb
->m_tabs
.AddPage(page_info
.window
, page_info
);
3959 dest_tabs
->DoShowHide();
3960 dest_tabs
->Refresh();
3962 // set the selection in the destination tab control
3963 nb
->SetSelectionToPage(page_info
);
3965 // notify owner that the tab has been dragged
3966 wxAuiNotebookEvent
e2(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, m_windowId
);
3967 e2
.SetSelection(evt
.GetSelection());
3968 e2
.SetOldSelection(evt
.GetSelection());
3969 e2
.SetEventObject(this);
3970 GetEventHandler()->ProcessEvent(e2
);
3980 // only perform a tab split if it's allowed
3981 wxAuiTabCtrl
* dest_tabs
= NULL
;
3983 if ((m_flags
& wxAUI_NB_TAB_SPLIT
) && m_tabs
.GetPageCount() >= 2)
3985 // If the pointer is in an existing tab frame, do a tab insert
3986 wxWindow
* hit_wnd
= ::wxFindWindowAtPoint(mouse_screen_pt
);
3987 wxTabFrame
* tab_frame
= (wxTabFrame
*)GetTabFrameFromTabCtrl(hit_wnd
);
3988 int insert_idx
= -1;
3991 dest_tabs
= tab_frame
->m_tabs
;
3993 if (dest_tabs
== src_tabs
)
3997 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
3998 wxWindow
* target
= NULL
;
3999 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
4002 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
4008 wxRect rect
= m_mgr
.CalculateHintRect(m_dummy_wnd
,
4013 // there is no suitable drop location here, exit out
4017 // If there is no tabframe at all, create one
4018 wxTabFrame
* new_tabs
= new wxTabFrame
;
4019 new_tabs
->m_rect
= wxRect(wxPoint(0,0), CalculateNewSplitSize());
4020 new_tabs
->SetTabCtrlHeight(m_tab_ctrl_height
);
4021 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
4025 wxNO_BORDER
|wxWANTS_CHARS
);
4026 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
4027 new_tabs
->m_tabs
->SetFlags(m_flags
);
4029 m_mgr
.AddPane(new_tabs
,
4030 wxAuiPaneInfo().Bottom().CaptionVisible(false),
4033 dest_tabs
= new_tabs
->m_tabs
;
4038 // remove the page from the source tabs
4039 wxAuiNotebookPage page_info
= src_tabs
->GetPage(evt
.GetSelection());
4040 page_info
.active
= false;
4041 src_tabs
->RemovePage(page_info
.window
);
4042 if (src_tabs
->GetPageCount() > 0)
4044 src_tabs
->SetActivePage((size_t)0);
4045 src_tabs
->DoShowHide();
4046 src_tabs
->Refresh();
4051 // add the page to the destination tabs
4052 if (insert_idx
== -1)
4053 insert_idx
= dest_tabs
->GetPageCount();
4054 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
4056 if (src_tabs
->GetPageCount() == 0)
4058 RemoveEmptyTabFrames();
4062 dest_tabs
->DoShowHide();
4063 dest_tabs
->Refresh();
4065 // force the set selection function reset the selection
4068 // set the active page to the one we just split off
4069 SetSelectionToPage(page_info
);
4071 UpdateHintWindowSize();
4074 // notify owner that the tab has been dragged
4075 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, m_windowId
);
4076 e
.SetSelection(evt
.GetSelection());
4077 e
.SetOldSelection(evt
.GetSelection());
4078 e
.SetEventObject(this);
4079 GetEventHandler()->ProcessEvent(e
);
4084 wxAuiTabCtrl
* wxAuiNotebook::GetTabCtrlFromPoint(const wxPoint
& pt
)
4086 // if we've just removed the last tab from the source
4087 // tab set, the remove the tab control completely
4088 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
4089 size_t i
, pane_count
= all_panes
.GetCount();
4090 for (i
= 0; i
< pane_count
; ++i
)
4092 if (all_panes
.Item(i
).name
== wxT("dummy"))
4095 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
4096 if (tabframe
->m_tab_rect
.Contains(pt
))
4097 return tabframe
->m_tabs
;
4103 wxWindow
* wxAuiNotebook::GetTabFrameFromTabCtrl(wxWindow
* tab_ctrl
)
4105 // if we've just removed the last tab from the source
4106 // tab set, the remove the tab control completely
4107 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
4108 size_t i
, pane_count
= all_panes
.GetCount();
4109 for (i
= 0; i
< pane_count
; ++i
)
4111 if (all_panes
.Item(i
).name
== wxT("dummy"))
4114 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
4115 if (tabframe
->m_tabs
== tab_ctrl
)
4124 void wxAuiNotebook::RemoveEmptyTabFrames()
4126 // if we've just removed the last tab from the source
4127 // tab set, the remove the tab control completely
4128 wxAuiPaneInfoArray all_panes
= m_mgr
.GetAllPanes();
4129 size_t i
, pane_count
= all_panes
.GetCount();
4130 for (i
= 0; i
< pane_count
; ++i
)
4132 if (all_panes
.Item(i
).name
== wxT("dummy"))
4135 wxTabFrame
* tab_frame
= (wxTabFrame
*)all_panes
.Item(i
).window
;
4136 if (tab_frame
->m_tabs
->GetPageCount() == 0)
4138 m_mgr
.DetachPane(tab_frame
);
4140 // use pending delete because sometimes during
4141 // window closing, refreshs are pending
4142 if (!wxPendingDelete
.Member(tab_frame
->m_tabs
))
4143 wxPendingDelete
.Append(tab_frame
->m_tabs
);
4145 tab_frame
->m_tabs
= NULL
;
4152 // check to see if there is still a center pane;
4153 // if there isn't, make a frame the center pane
4154 wxAuiPaneInfoArray panes
= m_mgr
.GetAllPanes();
4155 pane_count
= panes
.GetCount();
4156 wxWindow
* first_good
= NULL
;
4157 bool center_found
= false;
4158 for (i
= 0; i
< pane_count
; ++i
)
4160 if (panes
.Item(i
).name
== wxT("dummy"))
4162 if (panes
.Item(i
).dock_direction
== wxAUI_DOCK_CENTRE
)
4163 center_found
= true;
4165 first_good
= panes
.Item(i
).window
;
4168 if (!center_found
&& first_good
)
4170 m_mgr
.GetPane(first_good
).Centre();
4173 if (!m_isBeingDeleted
)
4177 void wxAuiNotebook::OnChildFocusNotebook(wxChildFocusEvent
& evt
)
4181 // if we're dragging a tab, don't change the current selection.
4182 // This code prevents a bug that used to happen when the hint window
4183 // was hidden. In the bug, the focus would return to the notebook
4184 // child, which would then enter this handler and call
4185 // SetSelection, which is not desired turn tab dragging.
4187 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
4188 size_t i
, pane_count
= all_panes
.GetCount();
4189 for (i
= 0; i
< pane_count
; ++i
)
4191 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
4192 if (pane
.name
== wxT("dummy"))
4194 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
4195 if (tabframe
->m_tabs
->IsDragging())
4200 // change the tab selection to the child
4201 // which was focused
4202 int idx
= m_tabs
.GetIdxFromWindow(evt
.GetWindow());
4203 if (idx
!= -1 && idx
!= m_curpage
)
4209 void wxAuiNotebook::OnNavigationKeyNotebook(wxNavigationKeyEvent
& event
)
4211 if ( event
.IsWindowChange() ) {
4213 // FIXME: the problem with this is that if we have a split notebook,
4214 // we selection may go all over the place.
4215 AdvanceSelection(event
.GetDirection());
4218 // we get this event in 3 cases
4220 // a) one of our pages might have generated it because the user TABbed
4221 // out from it in which case we should propagate the event upwards and
4222 // our parent will take care of setting the focus to prev/next sibling
4226 // b) the parent panel wants to give the focus to us so that we
4227 // forward it to our selected page. We can't deal with this in
4228 // OnSetFocus() because we don't know which direction the focus came
4229 // from in this case and so can't choose between setting the focus to
4230 // first or last panel child
4234 // c) we ourselves (see MSWTranslateMessage) generated the event
4236 wxWindow
* const parent
= GetParent();
4238 // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE
4239 const bool isFromParent
= event
.GetEventObject() == (wxObject
*) parent
;
4240 const bool isFromSelf
= event
.GetEventObject() == (wxObject
*) this;
4242 if ( isFromParent
|| isFromSelf
)
4244 // no, it doesn't come from child, case (b) or (c): forward to a
4245 // page but only if direction is backwards (TAB) or from ourselves,
4246 if ( GetSelection() != wxNOT_FOUND
&&
4247 (!event
.GetDirection() || isFromSelf
) )
4249 // so that the page knows that the event comes from it's parent
4250 // and is being propagated downwards
4251 event
.SetEventObject(this);
4253 wxWindow
*page
= GetPage(GetSelection());
4254 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
4258 //else: page manages focus inside it itself
4260 else // otherwise set the focus to the notebook itself
4267 // it comes from our child, case (a), pass to the parent, but only
4268 // if the direction is forwards. Otherwise set the focus to the
4269 // notebook itself. The notebook is always the 'first' control of a
4271 if ( !event
.GetDirection() )
4277 event
.SetCurrentFocus(this);
4278 parent
->GetEventHandler()->ProcessEvent(event
);
4284 void wxAuiNotebook::OnTabButton(wxAuiNotebookEvent
& evt
)
4286 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4288 int button_id
= evt
.GetInt();
4290 if (button_id
== wxAUI_BUTTON_CLOSE
)
4292 int selection
= evt
.GetSelection();
4294 if (selection
== -1)
4296 // if the close button is to the right, use the active
4297 // page selection to determine which page to close
4298 selection
= tabs
->GetActivePage();
4301 if (selection
!= -1)
4303 wxWindow
* close_wnd
= tabs
->GetWindowFromIdx(selection
);
4305 // ask owner if it's ok to close the tab
4306 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
, m_windowId
);
4307 e
.SetSelection(m_tabs
.GetIdxFromWindow(close_wnd
));
4308 const int idx
= m_tabs
.GetIdxFromWindow(close_wnd
);
4309 e
.SetSelection(idx
);
4310 e
.SetOldSelection(evt
.GetSelection());
4311 e
.SetEventObject(this);
4312 GetEventHandler()->ProcessEvent(e
);
4318 if (close_wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
4325 int main_idx
= m_tabs
.GetIdxFromWindow(close_wnd
);
4326 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, wxT("no page to delete?") );
4328 DeletePage(main_idx
);
4331 // notify owner that the tab has been closed
4332 wxAuiNotebookEvent
e2(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED
, m_windowId
);
4333 e2
.SetSelection(idx
);
4334 e2
.SetEventObject(this);
4335 GetEventHandler()->ProcessEvent(e2
);
4341 void wxAuiNotebook::OnTabMiddleDown(wxAuiNotebookEvent
& evt
)
4343 // patch event through to owner
4344 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4345 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4347 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, m_windowId
);
4348 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4349 e
.SetEventObject(this);
4350 GetEventHandler()->ProcessEvent(e
);
4353 void wxAuiNotebook::OnTabMiddleUp(wxAuiNotebookEvent
& evt
)
4355 // if the wxAUI_NB_MIDDLE_CLICK_CLOSE is specified, middle
4356 // click should act like a tab close action. However, first
4357 // give the owner an opportunity to handle the middle up event
4358 // for custom action
4360 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4361 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4363 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, m_windowId
);
4364 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4365 e
.SetEventObject(this);
4366 if (GetEventHandler()->ProcessEvent(e
))
4371 // check if we are supposed to close on middle-up
4372 if ((m_flags
& wxAUI_NB_MIDDLE_CLICK_CLOSE
) == 0)
4375 // simulate the user pressing the close button on the tab
4376 evt
.SetInt(wxAUI_BUTTON_CLOSE
);
4380 void wxAuiNotebook::OnTabRightDown(wxAuiNotebookEvent
& evt
)
4382 // patch event through to owner
4383 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4384 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4386 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, m_windowId
);
4387 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4388 e
.SetEventObject(this);
4389 GetEventHandler()->ProcessEvent(e
);
4392 void wxAuiNotebook::OnTabRightUp(wxAuiNotebookEvent
& evt
)
4394 // patch event through to owner
4395 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4396 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4398 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, m_windowId
);
4399 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4400 e
.SetEventObject(this);
4401 GetEventHandler()->ProcessEvent(e
);
4404 // Sets the normal font
4405 void wxAuiNotebook::SetNormalFont(const wxFont
& font
)
4407 m_normal_font
= font
;
4408 GetArtProvider()->SetNormalFont(font
);
4411 // Sets the selected tab font
4412 void wxAuiNotebook::SetSelectedFont(const wxFont
& font
)
4414 m_selected_font
= font
;
4415 GetArtProvider()->SetSelectedFont(font
);
4418 // Sets the measuring font
4419 void wxAuiNotebook::SetMeasuringFont(const wxFont
& font
)
4421 GetArtProvider()->SetMeasuringFont(font
);
4424 // Sets the tab font
4425 bool wxAuiNotebook::SetFont(const wxFont
& font
)
4427 wxControl::SetFont(font
);
4429 wxFont
normalFont(font
);
4430 wxFont
selectedFont(normalFont
);
4431 selectedFont
.SetWeight(wxBOLD
);
4433 SetNormalFont(normalFont
);
4434 SetSelectedFont(selectedFont
);
4435 SetMeasuringFont(selectedFont
);
4440 // Gets the tab control height
4441 int wxAuiNotebook::GetTabCtrlHeight() const
4443 return m_tab_ctrl_height
;
4446 // Gets the height of the notebook for a given page height
4447 int wxAuiNotebook::GetHeightForPageHeight(int pageHeight
)
4449 UpdateTabCtrlHeight();
4451 int tabCtrlHeight
= GetTabCtrlHeight();
4452 int decorHeight
= 2;
4453 return tabCtrlHeight
+ pageHeight
+ decorHeight
;
4456 // Advances the selection, generation page selection events
4457 void wxAuiNotebook::AdvanceSelection(bool forward
)
4459 if (GetPageCount() <= 1)
4462 int currentSelection
= GetSelection();
4466 if (currentSelection
== (int) (GetPageCount() - 1))
4468 else if (currentSelection
== -1)
4469 currentSelection
= 0;
4471 currentSelection
++;
4475 if (currentSelection
<= 0)
4478 currentSelection
--;
4481 SetSelection(currentSelection
);
4484 // Shows the window menu
4485 bool wxAuiNotebook::ShowWindowMenu()
4487 wxAuiTabCtrl
* tabCtrl
= GetActiveTabCtrl();
4489 int idx
= tabCtrl
->GetArtProvider()->ShowDropDown(tabCtrl
, tabCtrl
->GetPages(), tabCtrl
->GetActivePage());
4493 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, tabCtrl
->GetId());
4494 e
.SetSelection(idx
);
4495 e
.SetOldSelection(tabCtrl
->GetActivePage());
4496 e
.SetEventObject(tabCtrl
);
4497 GetEventHandler()->ProcessEvent(e
);
4505 void wxAuiNotebook::Thaw()