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/mac/carbon/private.h"
40 #include "wx/arrimpl.cpp"
41 WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray
)
42 WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
)
46 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
)
47 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
)
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
)
52 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
)
57 IMPLEMENT_CLASS(wxAuiNotebook
, wxControl
)
58 IMPLEMENT_CLASS(wxAuiTabCtrl
, wxControl
)
59 IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent
, wxEvent
)
65 // these functions live in dockart.cpp -- they'll eventually
66 // be moved to a new utility cpp file
68 wxColor
wxAuiStepColour(const wxColor
& c
, int percent
);
70 wxBitmap
wxAuiBitmapFromBits(const unsigned char bits
[], int w
, int h
,
71 const wxColour
& color
);
73 wxString
wxAuiChopText(wxDC
& dc
, const wxString
& text
, int max_size
);
75 static void DrawButtons(wxDC
& dc
,
78 const wxColour
& bkcolour
,
83 if (button_state
== wxAUI_BUTTON_STATE_PRESSED
)
89 if (button_state
== wxAUI_BUTTON_STATE_HOVER
||
90 button_state
== wxAUI_BUTTON_STATE_PRESSED
)
92 dc
.SetBrush(wxBrush(wxAuiStepColour(bkcolour
, 120)));
93 dc
.SetPen(wxPen(wxAuiStepColour(bkcolour
, 75)));
95 // draw the background behind the button
96 dc
.DrawRectangle(rect
.x
, rect
.y
, 15, 15);
99 // draw the button itself
100 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
103 static void IndentPressedBitmap(wxRect
* rect
, int button_state
)
105 if (button_state
== wxAUI_BUTTON_STATE_PRESSED
)
114 // -- GUI helper classes and functions --
116 class wxAuiCommandCapture
: public wxEvtHandler
120 wxAuiCommandCapture() { m_last_id
= 0; }
121 int GetCommandId() const { return m_last_id
; }
123 bool ProcessEvent(wxEvent
& evt
)
125 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
127 m_last_id
= evt
.GetId();
131 if (GetNextHandler())
132 return GetNextHandler()->ProcessEvent(evt
);
144 #if defined( __WXMAC__ )
145 static unsigned char close_bits
[]={
146 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0x03, 0xF8, 0x01, 0xF0, 0x19, 0xF3,
147 0xB8, 0xE3, 0xF0, 0xE1, 0xE0, 0xE0, 0xF0, 0xE1, 0xB8, 0xE3, 0x19, 0xF3,
148 0x01, 0xF0, 0x03, 0xF8, 0x0F, 0xFE, 0xFF, 0xFF };
149 #elif defined( __WXGTK__)
150 static unsigned char close_bits
[]={
151 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xfb, 0xef, 0xdb, 0xed, 0x8b, 0xe8,
152 0x1b, 0xec, 0x3b, 0xee, 0x1b, 0xec, 0x8b, 0xe8, 0xdb, 0xed, 0xfb, 0xef,
153 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
155 static unsigned char close_bits
[]={
156 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xf3, 0xcf, 0xf9,
157 0x9f, 0xfc, 0x3f, 0xfe, 0x3f, 0xfe, 0x9f, 0xfc, 0xcf, 0xf9, 0xe7, 0xf3,
158 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
161 static unsigned char left_bits
[] = {
162 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x3f, 0xfe,
163 0x1f, 0xfe, 0x0f, 0xfe, 0x1f, 0xfe, 0x3f, 0xfe, 0x7f, 0xfe, 0xff, 0xfe,
164 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
166 static unsigned char right_bits
[] = {
167 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0x9f, 0xff, 0x1f, 0xff,
168 0x1f, 0xfe, 0x1f, 0xfc, 0x1f, 0xfe, 0x1f, 0xff, 0x9f, 0xff, 0xdf, 0xff,
169 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
171 static unsigned char list_bits
[] = {
172 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
173 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff,
174 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
181 // -- wxAuiDefaultTabArt class implementation --
183 wxAuiDefaultTabArt
::wxAuiDefaultTabArt()
185 m_normal_font
= *wxNORMAL_FONT
;
186 m_selected_font
= *wxNORMAL_FONT
;
187 m_selected_font
.SetWeight(wxBOLD
);
188 m_measuring_font
= m_selected_font
;
190 m_fixed_tab_width
= 100;
191 m_tab_ctrl_height
= 0;
194 wxBrush toolbarbrush
;
195 toolbarbrush
.MacSetTheme( kThemeBrushToolbarBackground
);
196 wxColor base_colour
= toolbarbrush
.GetColour();
198 wxColor base_colour
= wxSystemSettings
::GetColour(wxSYS_COLOUR_3DFACE
);
201 // the base_colour is too pale to use as our base colour,
202 // so darken it a bit --
203 if ((255-base_colour
.Red()) +
204 (255-base_colour
.Green()) +
205 (255-base_colour
.Blue()) < 60)
207 base_colour
= wxAuiStepColour(base_colour
, 92);
210 m_base_colour
= base_colour
;
211 wxColor border_colour
= wxAuiStepColour(base_colour
, 75);
213 m_border_pen
= wxPen(border_colour
);
214 m_base_colour_pen
= wxPen(m_base_colour
);
215 m_base_colour_brush
= wxBrush(m_base_colour
);
217 m_active_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, *wxBLACK
);
218 m_disabled_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, wxColour(128,128,128));
220 m_active_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, *wxBLACK
);
221 m_disabled_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, wxColour(128,128,128));
223 m_active_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, *wxBLACK
);
224 m_disabled_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, wxColour(128,128,128));
226 m_active_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, *wxBLACK
);
227 m_disabled_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, wxColour(128,128,128));
232 wxAuiDefaultTabArt
::~wxAuiDefaultTabArt()
236 wxAuiTabArt
* wxAuiDefaultTabArt
::Clone()
238 wxAuiDefaultTabArt
* art
= new wxAuiDefaultTabArt
;
239 art
->SetNormalFont(m_normal_font
);
240 art
->SetSelectedFont(m_selected_font
);
241 art
->SetMeasuringFont(m_measuring_font
);
246 void wxAuiDefaultTabArt
::SetFlags(unsigned int flags
)
251 void wxAuiDefaultTabArt
::SetSizingInfo(const wxSize
& tab_ctrl_size
,
254 m_fixed_tab_width
= 100;
256 int tot_width
= (int)tab_ctrl_size
.x
- GetIndentSize() - 4;
258 if (m_flags
& wxAUI_NB_CLOSE_BUTTON
)
259 tot_width
-= m_active_close_bmp
.GetWidth();
260 if (m_flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
261 tot_width
-= m_active_windowlist_bmp
.GetWidth();
265 m_fixed_tab_width
= tot_width
/(int)tab_count
;
269 if (m_fixed_tab_width
< 100)
270 m_fixed_tab_width
= 100;
272 if (m_fixed_tab_width
> tot_width
/2)
273 m_fixed_tab_width
= tot_width
/2;
275 if (m_fixed_tab_width
> 220)
276 m_fixed_tab_width
= 220;
278 m_tab_ctrl_height
= tab_ctrl_size
.y
;
282 void wxAuiDefaultTabArt
::DrawBackground(wxDC
& dc
,
283 wxWindow
* WXUNUSED(wnd
),
287 wxRect
r(rect
.x
, rect
.y
, rect
.width
+2, rect
.height
-3);
288 wxColor top_color
= wxAuiStepColour(m_base_colour
, 90);
289 wxColor bottom_color
= wxAuiStepColour(m_base_colour
, 170);
290 dc
.GradientFillLinear(r
, top_color
, bottom_color
, wxSOUTH
);
293 int y
= rect
.GetHeight();
294 int w
= rect
.GetWidth();
295 dc
.SetPen(m_border_pen
);
296 dc
.SetBrush(m_base_colour_brush
);
297 dc
.DrawRectangle(-1, y
-4, w
+2, 4);
301 // DrawTab() draws an individual tab.
304 // in_rect - rectangle the tab should be confined to
305 // caption - tab's caption
306 // active - whether or not the tab is active
307 // out_rect - actual output rectangle
308 // x_extent - the advance x; where the next tab should start
310 void wxAuiDefaultTabArt
::DrawTab(wxDC
& dc
,
312 const wxAuiNotebookPage
& page
,
313 const wxRect
& in_rect
,
314 int close_button_state
,
315 wxRect
* out_tab_rect
,
316 wxRect
* out_button_rect
,
319 wxCoord normal_textx
, normal_texty
;
320 wxCoord selected_textx
, selected_texty
;
323 // if the caption is empty, measure some temporary text
324 wxString caption
= page
.caption
;
328 dc
.SetFont(m_selected_font
);
329 dc
.GetTextExtent(caption
, &selected_textx
, &selected_texty
);
331 dc
.SetFont(m_normal_font
);
332 dc
.GetTextExtent(caption
, &normal_textx
, &normal_texty
);
334 // figure out the size of the tab
335 wxSize tab_size
= GetTabSize(dc
,
343 wxCoord tab_height
= m_tab_ctrl_height
- 3;
344 wxCoord tab_width
= tab_size
.x
;
345 wxCoord tab_x
= in_rect
.x
;
346 wxCoord tab_y
= in_rect
.y
+ in_rect
.height
- tab_height
;
349 caption
= page
.caption
;
352 // select pen, brush and font for the tab to be drawn
356 dc
.SetFont(m_selected_font
);
357 texty
= selected_texty
;
361 dc
.SetFont(m_normal_font
);
362 texty
= normal_texty
;
366 // create points that will make the tab outline
368 int clip_width
= tab_width
;
369 if (tab_x
+ clip_width
> in_rect
.x
+ in_rect
.width
)
370 clip_width
= (in_rect
.x
+ in_rect
.width
) - tab_x
;
373 wxPoint clip_points[6];
374 clip_points[0] = wxPoint(tab_x, tab_y+tab_height-3);
375 clip_points[1] = wxPoint(tab_x, tab_y+2);
376 clip_points[2] = wxPoint(tab_x+2, tab_y);
377 clip_points[3] = wxPoint(tab_x+clip_width-1, tab_y);
378 clip_points[4] = wxPoint(tab_x+clip_width+1, tab_y+2);
379 clip_points[5] = wxPoint(tab_x+clip_width+1, tab_y+tab_height-3);
381 // FIXME: these ports don't provide wxRegion ctor from array of points
382 #if !defined(__WXDFB__) && !defined(__WXCOCOA__)
383 // set the clipping region for the tab --
384 wxRegion clipping_region(WXSIZEOF(clip_points), clip_points);
385 dc.SetClippingRegion(clipping_region);
386 #endif // !wxDFB && !wxCocoa
388 // since the above code above doesn't play well with WXDFB or WXCOCOA,
389 // we'll just use a rectangle for the clipping region for now --
390 dc
.SetClippingRegion(tab_x
, tab_y
, clip_width
+1, tab_height
-3);
393 wxPoint border_points
[6];
394 border_points
[0] = wxPoint(tab_x
, tab_y
+tab_height
-4);
395 border_points
[1] = wxPoint(tab_x
, tab_y
+2);
396 border_points
[2] = wxPoint(tab_x
+2, tab_y
);
397 border_points
[3] = wxPoint(tab_x
+tab_width
-2, tab_y
);
398 border_points
[4] = wxPoint(tab_x
+tab_width
, tab_y
+2);
399 border_points
[5] = wxPoint(tab_x
+tab_width
, tab_y
+tab_height
-4);
402 int drawn_tab_yoff
= border_points
[1].y
;
403 int drawn_tab_height
= border_points
[0].y
- border_points
[1].y
;
410 // draw base background color
411 wxRect
r(tab_x
, tab_y
, tab_width
, tab_height
);
412 dc
.SetPen(m_base_colour_pen
);
413 dc
.SetBrush(m_base_colour_brush
);
414 dc
.DrawRectangle(r
.x
+1, r
.y
+1, r
.width
-1, r
.height
-4);
416 // this white helps fill out the gradient at the top of the tab
417 dc
.SetPen(*wxWHITE_PEN
);
418 dc
.SetBrush(*wxWHITE_BRUSH
);
419 dc
.DrawRectangle(r
.x
+2, r
.y
+1, r
.width
-3, r
.height
-4);
421 // these two points help the rounded corners appear more antialiased
422 dc
.SetPen(m_base_colour_pen
);
423 dc
.DrawPoint(r
.x
+2, r
.y
+1);
424 dc
.DrawPoint(r
.x
+r
.width
-2, r
.y
+1);
426 // set rectangle down a bit for gradient drawing
427 r
.SetHeight(r
.GetHeight()/2);
433 // draw gradient background
434 wxColor top_color
= *wxWHITE
;
435 wxColor bottom_color
= m_base_colour
;
436 dc
.GradientFillLinear(r
, bottom_color
, top_color
, wxNORTH
);
442 wxRect
r(tab_x
, tab_y
+1, tab_width
, tab_height
-3);
444 // start the gradent up a bit and leave the inside border inset
445 // by a pixel for a 3D look. Only the top half of the inactive
446 // tab will have a slight gradient
453 // -- draw top gradient fill for glossy look
454 wxColor top_color
= m_base_colour
;
455 wxColor bottom_color
= wxAuiStepColour(top_color
, 160);
456 dc
.GradientFillLinear(r
, bottom_color
, top_color
, wxNORTH
);
461 // -- draw bottom fill for glossy look
462 top_color
= m_base_colour
;
463 bottom_color
= m_base_colour
;
464 dc
.GradientFillLinear(r
, top_color
, bottom_color
, wxSOUTH
);
468 dc
.SetPen(m_border_pen
);
469 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
470 dc
.DrawPolygon(WXSIZEOF(border_points
), border_points
);
472 // there are two horizontal grey lines at the bottom of the tab control,
473 // this gets rid of the top one of those lines in the tab control
476 dc
.SetPen(m_base_colour_pen
);
477 dc
.DrawLine(border_points
[0].x
+1,
484 int text_offset
= tab_x
+ 8;
485 int close_button_width
= 0;
486 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
488 close_button_width
= m_active_close_bmp
.GetWidth();
491 int bitmap_offset
= 0;
492 if (page
.bitmap
.IsOk())
494 bitmap_offset
= tab_x
+ 8;
497 dc
.DrawBitmap(page
.bitmap
,
499 drawn_tab_yoff
+ (drawn_tab_height
/2) - (page
.bitmap
.GetHeight()/2),
502 text_offset
= bitmap_offset
+ page
.bitmap
.GetWidth();
503 text_offset
+= 3; // bitmap padding
508 text_offset
= tab_x
+ 8;
512 wxString draw_text
= wxAuiChopText(dc
,
514 tab_width
- (text_offset
-tab_x
) - close_button_width
);
517 dc
.DrawText(draw_text
,
519 drawn_tab_yoff
+ (drawn_tab_height
)/2 - (texty
/2) - 1);
521 // draw focus rectangle
522 if (page
.active
&& (wnd
->FindFocus() == wnd
))
524 wxRect
focusRectText(text_offset
, (drawn_tab_yoff
+ (drawn_tab_height
)/2 - (texty
/2) - 1),
525 selected_textx
, selected_texty
);
528 wxRect focusRectBitmap
;
530 if (page
.bitmap
.IsOk())
531 focusRectBitmap
= wxRect(bitmap_offset
, drawn_tab_yoff
+ (drawn_tab_height
/2) - (page
.bitmap
.GetHeight()/2),
532 page
.bitmap
.GetWidth(), page
.bitmap
.GetHeight());
534 if (page
.bitmap
.IsOk() && draw_text
.IsEmpty())
535 focusRect
= focusRectBitmap
;
536 else if (!page
.bitmap
.IsOk() && !draw_text
.IsEmpty())
537 focusRect
= focusRectText
;
538 else if (page
.bitmap
.IsOk() && !draw_text
.IsEmpty())
539 focusRect
= focusRectText
.Union(focusRectBitmap
);
541 focusRect
.Inflate(2, 2);
543 wxRendererNative
::Get().DrawFocusRect(wnd
, dc
, focusRect
, 0);
546 // draw close button if necessary
547 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
549 wxBitmap bmp
= m_disabled_close_bmp
;
551 if (close_button_state
== wxAUI_BUTTON_STATE_HOVER
||
552 close_button_state
== wxAUI_BUTTON_STATE_PRESSED
)
554 bmp
= m_active_close_bmp
;
557 wxRect
rect(tab_x
+ tab_width
- close_button_width
- 1,
558 tab_y
+ (tab_height
/2) - (bmp
.GetHeight()/2),
561 IndentPressedBitmap(&rect
, close_button_state
);
562 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
564 *out_button_rect
= rect
;
567 *out_tab_rect
= wxRect(tab_x
, tab_y
, tab_width
, tab_height
);
569 dc
.DestroyClippingRegion();
572 int wxAuiDefaultTabArt
::GetIndentSize()
577 wxSize wxAuiDefaultTabArt
::GetTabSize(wxDC
& dc
,
578 wxWindow
* WXUNUSED(wnd
),
579 const wxString
& caption
,
580 const wxBitmap
& bitmap
,
581 bool WXUNUSED(active
),
582 int close_button_state
,
585 wxCoord measured_textx
, measured_texty
, tmp
;
587 dc
.SetFont(m_measuring_font
);
588 dc
.GetTextExtent(caption
, &measured_textx
, &measured_texty
);
590 dc
.GetTextExtent(wxT("ABCDEFXj"), &tmp
, &measured_texty
);
592 // add padding around the text
593 wxCoord tab_width
= measured_textx
;
594 wxCoord tab_height
= measured_texty
;
596 // if the close button is showing, add space for it
597 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
598 tab_width
+= m_active_close_bmp
.GetWidth() + 3;
600 // if there's a bitmap, add space for it
603 tab_width
+= bitmap
.GetWidth();
604 tab_width
+= 3; // right side bitmap padding
605 tab_height
= wxMax(tab_height
, bitmap
.GetHeight());
612 if (m_flags
& wxAUI_NB_TAB_FIXED_WIDTH
)
614 tab_width
= m_fixed_tab_width
;
617 *x_extent
= tab_width
;
619 return wxSize(tab_width
, tab_height
);
623 void wxAuiDefaultTabArt
::DrawButton(wxDC
& dc
,
624 wxWindow
* WXUNUSED(wnd
),
625 const wxRect
& in_rect
,
636 case wxAUI_BUTTON_CLOSE
:
637 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
638 bmp
= m_disabled_close_bmp
;
640 bmp
= m_active_close_bmp
;
642 case wxAUI_BUTTON_LEFT
:
643 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
644 bmp
= m_disabled_left_bmp
;
646 bmp
= m_active_left_bmp
;
648 case wxAUI_BUTTON_RIGHT
:
649 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
650 bmp
= m_disabled_right_bmp
;
652 bmp
= m_active_right_bmp
;
654 case wxAUI_BUTTON_WINDOWLIST
:
655 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
656 bmp
= m_disabled_windowlist_bmp
;
658 bmp
= m_active_windowlist_bmp
;
668 if (orientation
== wxLEFT
)
670 rect
.SetX(in_rect
.x
);
671 rect
.SetY(((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2));
672 rect
.SetWidth(bmp
.GetWidth());
673 rect
.SetHeight(bmp
.GetHeight());
677 rect
= wxRect(in_rect
.x
+ in_rect
.width
- bmp
.GetWidth(),
678 ((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2),
679 bmp
.GetWidth(), bmp
.GetHeight());
682 IndentPressedBitmap(&rect
, button_state
);
683 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
688 int wxAuiDefaultTabArt
::ShowDropDown(wxWindow
* wnd
,
689 const wxAuiNotebookPageArray
& pages
,
694 size_t i
, count
= pages
.GetCount();
695 for (i
= 0; i
< count
; ++i
)
697 const wxAuiNotebookPage
& page
= pages
.Item(i
);
698 wxString caption
= page
.caption
;
700 // if there is no caption, make it a space. This will prevent
701 // an assert in the menu code.
702 if (caption
.IsEmpty())
705 menuPopup
.AppendCheckItem(1000+i
, caption
);
708 if (active_idx
!= -1)
710 menuPopup
.Check(1000+active_idx
, true);
713 // find out where to put the popup menu of window items
714 wxPoint pt
= ::wxGetMousePosition();
715 pt
= wnd
->ScreenToClient(pt
);
717 // find out the screen coordinate at the bottom of the tab ctrl
718 wxRect cli_rect
= wnd
->GetClientRect();
719 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
721 wxAuiCommandCapture
* cc
= new wxAuiCommandCapture
;
722 wnd
->PushEventHandler(cc
);
723 wnd
->PopupMenu(&menuPopup
, pt
);
724 int command
= cc
->GetCommandId();
725 wnd
->PopEventHandler(true);
733 int wxAuiDefaultTabArt
::GetBestTabCtrlSize(wxWindow
* wnd
,
734 const wxAuiNotebookPageArray
& pages
,
735 const wxSize
& required_bmp_size
)
738 dc
.SetFont(m_measuring_font
);
740 // sometimes a standard bitmap size needs to be enforced, especially
741 // if some tabs have bitmaps and others don't. This is important because
742 // it prevents the tab control from resizing when tabs are added.
743 wxBitmap measure_bmp
;
744 if (required_bmp_size
.IsFullySpecified())
746 measure_bmp
.Create(required_bmp_size
.x
,
747 required_bmp_size
.y
);
752 size_t i
, page_count
= pages
.GetCount();
753 for (i
= 0; i
< page_count
; ++i
)
755 wxAuiNotebookPage
& page
= pages
.Item(i
);
758 if (measure_bmp
.IsOk())
763 // we don't use the caption text because we don't
764 // want tab heights to be different in the case
765 // of a very short piece of text on one tab and a very
766 // tall piece of text on another tab
768 wxSize s
= GetTabSize(dc
,
773 wxAUI_BUTTON_STATE_HIDDEN
,
776 max_y
= wxMax(max_y
, s
.y
);
782 void wxAuiDefaultTabArt
::SetNormalFont(const wxFont
& font
)
784 m_normal_font
= font
;
787 void wxAuiDefaultTabArt
::SetSelectedFont(const wxFont
& font
)
789 m_selected_font
= font
;
792 void wxAuiDefaultTabArt
::SetMeasuringFont(const wxFont
& font
)
794 m_measuring_font
= font
;
798 // -- wxAuiSimpleTabArt class implementation --
800 wxAuiSimpleTabArt
::wxAuiSimpleTabArt()
802 m_normal_font
= *wxNORMAL_FONT
;
803 m_selected_font
= *wxNORMAL_FONT
;
804 m_selected_font
.SetWeight(wxBOLD
);
805 m_measuring_font
= m_selected_font
;
808 m_fixed_tab_width
= 100;
810 wxColour base_colour
= wxSystemSettings
::GetColour(wxSYS_COLOUR_3DFACE
);
812 wxColour background_colour
= base_colour
;
813 wxColour normaltab_colour
= base_colour
;
814 wxColour selectedtab_colour
= *wxWHITE
;
816 m_bkbrush
= wxBrush(background_colour
);
817 m_normal_bkbrush
= wxBrush(normaltab_colour
);
818 m_normal_bkpen
= wxPen(normaltab_colour
);
819 m_selected_bkbrush
= wxBrush(selectedtab_colour
);
820 m_selected_bkpen
= wxPen(selectedtab_colour
);
822 m_active_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, *wxBLACK
);
823 m_disabled_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, wxColour(128,128,128));
825 m_active_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, *wxBLACK
);
826 m_disabled_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, wxColour(128,128,128));
828 m_active_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, *wxBLACK
);
829 m_disabled_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, wxColour(128,128,128));
831 m_active_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, *wxBLACK
);
832 m_disabled_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, wxColour(128,128,128));
836 wxAuiSimpleTabArt
::~wxAuiSimpleTabArt()
840 wxAuiTabArt
* wxAuiSimpleTabArt
::Clone()
842 return static_cast<wxAuiTabArt
*>(new wxAuiSimpleTabArt
);
846 void wxAuiSimpleTabArt
::SetFlags(unsigned int flags
)
851 void wxAuiSimpleTabArt
::SetSizingInfo(const wxSize
& tab_ctrl_size
,
854 m_fixed_tab_width
= 100;
856 int tot_width
= (int)tab_ctrl_size
.x
- GetIndentSize() - 4;
858 if (m_flags
& wxAUI_NB_CLOSE_BUTTON
)
859 tot_width
-= m_active_close_bmp
.GetWidth();
860 if (m_flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
861 tot_width
-= m_active_windowlist_bmp
.GetWidth();
865 m_fixed_tab_width
= tot_width
/(int)tab_count
;
869 if (m_fixed_tab_width
< 100)
870 m_fixed_tab_width
= 100;
872 if (m_fixed_tab_width
> tot_width
/2)
873 m_fixed_tab_width
= tot_width
/2;
875 if (m_fixed_tab_width
> 220)
876 m_fixed_tab_width
= 220;
879 void wxAuiSimpleTabArt
::DrawBackground(wxDC
& dc
,
880 wxWindow
* WXUNUSED(wnd
),
884 dc
.SetBrush(m_bkbrush
);
885 dc
.SetPen(*wxTRANSPARENT_PEN
);
886 dc
.DrawRectangle(-1, -1, rect
.GetWidth()+2, rect
.GetHeight()+2);
889 dc
.SetPen(*wxGREY_PEN
);
890 dc
.DrawLine(0, rect
.GetHeight()-1, rect
.GetWidth(), rect
.GetHeight()-1);
894 // DrawTab() draws an individual tab.
897 // in_rect - rectangle the tab should be confined to
898 // caption - tab's caption
899 // active - whether or not the tab is active
900 // out_rect - actual output rectangle
901 // x_extent - the advance x; where the next tab should start
903 void wxAuiSimpleTabArt
::DrawTab(wxDC
& dc
,
905 const wxAuiNotebookPage
& page
,
906 const wxRect
& in_rect
,
907 int close_button_state
,
908 wxRect
* out_tab_rect
,
909 wxRect
* out_button_rect
,
912 wxCoord normal_textx
, normal_texty
;
913 wxCoord selected_textx
, selected_texty
;
914 wxCoord textx
, texty
;
916 // if the caption is empty, measure some temporary text
917 wxString caption
= page
.caption
;
921 dc
.SetFont(m_selected_font
);
922 dc
.GetTextExtent(caption
, &selected_textx
, &selected_texty
);
924 dc
.SetFont(m_normal_font
);
925 dc
.GetTextExtent(caption
, &normal_textx
, &normal_texty
);
927 // figure out the size of the tab
928 wxSize tab_size
= GetTabSize(dc
,
936 wxCoord tab_height
= tab_size
.y
;
937 wxCoord tab_width
= tab_size
.x
;
938 wxCoord tab_x
= in_rect
.x
;
939 wxCoord tab_y
= in_rect
.y
+ in_rect
.height
- tab_height
;
941 caption
= page
.caption
;
943 // select pen, brush and font for the tab to be drawn
947 dc
.SetPen(m_selected_bkpen
);
948 dc
.SetBrush(m_selected_bkbrush
);
949 dc
.SetFont(m_selected_font
);
950 textx
= selected_textx
;
951 texty
= selected_texty
;
955 dc
.SetPen(m_normal_bkpen
);
956 dc
.SetBrush(m_normal_bkbrush
);
957 dc
.SetFont(m_normal_font
);
958 textx
= normal_textx
;
959 texty
= normal_texty
;
967 points
[0].y
= tab_y
+ tab_height
- 1;
968 points
[1].x
= tab_x
+ tab_height
- 3;
969 points
[1].y
= tab_y
+ 2;
970 points
[2].x
= tab_x
+ tab_height
+ 3;
972 points
[3].x
= tab_x
+ tab_width
- 2;
974 points
[4].x
= tab_x
+ tab_width
;
975 points
[4].y
= tab_y
+ 2;
976 points
[5].x
= tab_x
+ tab_width
;
977 points
[5].y
= tab_y
+ tab_height
- 1;
978 points
[6] = points
[0];
980 dc
.SetClippingRegion(in_rect
);
982 dc
.DrawPolygon(WXSIZEOF(points
) - 1, points
);
984 dc
.SetPen(*wxGREY_PEN
);
986 //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points);
987 dc
.DrawLines(WXSIZEOF(points
), points
);
992 int close_button_width
= 0;
993 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
995 close_button_width
= m_active_close_bmp
.GetWidth();
996 text_offset
= tab_x
+ (tab_height
/2) + ((tab_width
-close_button_width
)/2) - (textx
/2);
1000 text_offset
= tab_x
+ (tab_height
/3) + (tab_width
/2) - (textx
/2);
1003 // set minimum text offset
1004 if (text_offset
< tab_x
+ tab_height
)
1005 text_offset
= tab_x
+ tab_height
;
1007 // chop text if necessary
1008 wxString draw_text
= wxAuiChopText(dc
,
1010 tab_width
- (text_offset
-tab_x
) - close_button_width
);
1013 dc
.DrawText(draw_text
,
1015 (tab_y
+ tab_height
)/2 - (texty
/2) + 1);
1018 // draw focus rectangle
1019 if (page
.active
&& (wnd
->FindFocus() == wnd
))
1021 wxRect
focusRect(text_offset
, ((tab_y
+ tab_height
)/2 - (texty
/2) + 1),
1022 selected_textx
, selected_texty
);
1024 focusRect
.Inflate(2, 2);
1026 wxRendererNative
::Get().DrawFocusRect(wnd
, dc
, focusRect
, 0);
1029 // draw close button if necessary
1030 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1034 bmp
= m_active_close_bmp
;
1036 bmp
= m_disabled_close_bmp
;
1038 wxRect
rect(tab_x
+ tab_width
- close_button_width
- 1,
1039 tab_y
+ (tab_height
/2) - (bmp
.GetHeight()/2) + 1,
1042 DrawButtons(dc
, rect
, bmp
, *wxWHITE
, close_button_state
);
1044 *out_button_rect
= rect
;
1048 *out_tab_rect
= wxRect(tab_x
, tab_y
, tab_width
, tab_height
);
1050 dc
.DestroyClippingRegion();
1053 int wxAuiSimpleTabArt
::GetIndentSize()
1058 wxSize wxAuiSimpleTabArt
::GetTabSize(wxDC
& dc
,
1059 wxWindow
* WXUNUSED(wnd
),
1060 const wxString
& caption
,
1061 const wxBitmap
& WXUNUSED(bitmap
),
1062 bool WXUNUSED(active
),
1063 int close_button_state
,
1066 wxCoord measured_textx
, measured_texty
;
1068 dc
.SetFont(m_measuring_font
);
1069 dc
.GetTextExtent(caption
, &measured_textx
, &measured_texty
);
1071 wxCoord tab_height
= measured_texty
+ 4;
1072 wxCoord tab_width
= measured_textx
+ tab_height
+ 5;
1074 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1075 tab_width
+= m_active_close_bmp
.GetWidth();
1077 if (m_flags
& wxAUI_NB_TAB_FIXED_WIDTH
)
1079 tab_width
= m_fixed_tab_width
;
1082 *x_extent
= tab_width
- (tab_height
/2) - 1;
1084 return wxSize(tab_width
, tab_height
);
1088 void wxAuiSimpleTabArt
::DrawButton(wxDC
& dc
,
1089 wxWindow
* WXUNUSED(wnd
),
1090 const wxRect
& in_rect
,
1101 case wxAUI_BUTTON_CLOSE
:
1102 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1103 bmp
= m_disabled_close_bmp
;
1105 bmp
= m_active_close_bmp
;
1107 case wxAUI_BUTTON_LEFT
:
1108 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1109 bmp
= m_disabled_left_bmp
;
1111 bmp
= m_active_left_bmp
;
1113 case wxAUI_BUTTON_RIGHT
:
1114 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1115 bmp
= m_disabled_right_bmp
;
1117 bmp
= m_active_right_bmp
;
1119 case wxAUI_BUTTON_WINDOWLIST
:
1120 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1121 bmp
= m_disabled_windowlist_bmp
;
1123 bmp
= m_active_windowlist_bmp
;
1132 if (orientation
== wxLEFT
)
1134 rect
.SetX(in_rect
.x
);
1135 rect
.SetY(((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2));
1136 rect
.SetWidth(bmp
.GetWidth());
1137 rect
.SetHeight(bmp
.GetHeight());
1141 rect
= wxRect(in_rect
.x
+ in_rect
.width
- bmp
.GetWidth(),
1142 ((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2),
1143 bmp
.GetWidth(), bmp
.GetHeight());
1147 DrawButtons(dc
, rect
, bmp
, *wxWHITE
, button_state
);
1152 int wxAuiSimpleTabArt
::ShowDropDown(wxWindow
* wnd
,
1153 const wxAuiNotebookPageArray
& pages
,
1158 size_t i
, count
= pages
.GetCount();
1159 for (i
= 0; i
< count
; ++i
)
1161 const wxAuiNotebookPage
& page
= pages
.Item(i
);
1162 menuPopup
.AppendCheckItem(1000+i
, page
.caption
);
1165 if (active_idx
!= -1)
1167 menuPopup
.Check(1000+active_idx
, true);
1170 // find out where to put the popup menu of window
1171 // items. Subtract 100 for now to center the menu
1172 // a bit, until a better mechanism can be implemented
1173 wxPoint pt
= ::wxGetMousePosition();
1174 pt
= wnd
->ScreenToClient(pt
);
1180 // find out the screen coordinate at the bottom of the tab ctrl
1181 wxRect cli_rect
= wnd
->GetClientRect();
1182 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
1184 wxAuiCommandCapture
* cc
= new wxAuiCommandCapture
;
1185 wnd
->PushEventHandler(cc
);
1186 wnd
->PopupMenu(&menuPopup
, pt
);
1187 int command
= cc
->GetCommandId();
1188 wnd
->PopEventHandler(true);
1190 if (command
>= 1000)
1191 return command
-1000;
1196 int wxAuiSimpleTabArt
::GetBestTabCtrlSize(wxWindow
* wnd
,
1197 const wxAuiNotebookPageArray
& WXUNUSED(pages
),
1198 const wxSize
& WXUNUSED(required_bmp_size
))
1201 dc
.SetFont(m_measuring_font
);
1203 wxSize s
= GetTabSize(dc
,
1208 wxAUI_BUTTON_STATE_HIDDEN
,
1213 void wxAuiSimpleTabArt
::SetNormalFont(const wxFont
& font
)
1215 m_normal_font
= font
;
1218 void wxAuiSimpleTabArt
::SetSelectedFont(const wxFont
& font
)
1220 m_selected_font
= font
;
1223 void wxAuiSimpleTabArt
::SetMeasuringFont(const wxFont
& font
)
1225 m_measuring_font
= font
;
1231 // -- wxAuiTabContainer class implementation --
1234 // wxAuiTabContainer is a class which contains information about each
1235 // tab. It also can render an entire tab control to a specified DC.
1236 // It's not a window class itself, because this code will be used by
1237 // the wxFrameMananger, where it is disadvantageous to have separate
1238 // windows for each tab control in the case of "docked tabs"
1240 // A derived class, wxAuiTabCtrl, is an actual wxWindow-derived window
1241 // which can be used as a tab control in the normal sense.
1244 wxAuiTabContainer
::wxAuiTabContainer()
1248 m_art
= new wxAuiDefaultTabArt
;
1250 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
1251 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
1252 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
1253 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
1256 wxAuiTabContainer
::~wxAuiTabContainer()
1261 void wxAuiTabContainer
::SetArtProvider(wxAuiTabArt
* art
)
1268 m_art
->SetFlags(m_flags
);
1272 wxAuiTabArt
* wxAuiTabContainer
::GetArtProvider() const
1277 void wxAuiTabContainer
::SetFlags(unsigned int flags
)
1281 // check for new close button settings
1282 RemoveButton(wxAUI_BUTTON_LEFT
);
1283 RemoveButton(wxAUI_BUTTON_RIGHT
);
1284 RemoveButton(wxAUI_BUTTON_WINDOWLIST
);
1285 RemoveButton(wxAUI_BUTTON_CLOSE
);
1288 if (flags
& wxAUI_NB_SCROLL_BUTTONS
)
1290 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
1291 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
1294 if (flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
1296 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
1299 if (flags
& wxAUI_NB_CLOSE_BUTTON
)
1301 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
1306 m_art
->SetFlags(m_flags
);
1310 unsigned int wxAuiTabContainer
::GetFlags() const
1316 void wxAuiTabContainer
::SetNormalFont(const wxFont
& font
)
1318 m_art
->SetNormalFont(font
);
1321 void wxAuiTabContainer
::SetSelectedFont(const wxFont
& font
)
1323 m_art
->SetSelectedFont(font
);
1326 void wxAuiTabContainer
::SetMeasuringFont(const wxFont
& font
)
1328 m_art
->SetMeasuringFont(font
);
1331 void wxAuiTabContainer
::SetRect(const wxRect
& rect
)
1337 m_art
->SetSizingInfo(rect
.GetSize(), m_pages
.GetCount());
1341 bool wxAuiTabContainer
::AddPage(wxWindow
* page
,
1342 const wxAuiNotebookPage
& info
)
1344 wxAuiNotebookPage page_info
;
1346 page_info
.window
= page
;
1348 m_pages
.Add(page_info
);
1350 // let the art provider know how many pages we have
1353 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1359 bool wxAuiTabContainer
::InsertPage(wxWindow
* page
,
1360 const wxAuiNotebookPage
& info
,
1363 wxAuiNotebookPage page_info
;
1365 page_info
.window
= page
;
1367 if (idx
>= m_pages
.GetCount())
1368 m_pages
.Add(page_info
);
1370 m_pages
.Insert(page_info
, idx
);
1372 // let the art provider know how many pages we have
1375 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1381 bool wxAuiTabContainer
::MovePage(wxWindow
* page
,
1384 int idx
= GetIdxFromWindow(page
);
1388 // get page entry, make a copy of it
1389 wxAuiNotebookPage p
= GetPage(idx
);
1391 // remove old page entry
1394 // insert page where it should be
1395 InsertPage(page
, p
, new_idx
);
1400 bool wxAuiTabContainer
::RemovePage(wxWindow
* wnd
)
1402 size_t i
, page_count
= m_pages
.GetCount();
1403 for (i
= 0; i
< page_count
; ++i
)
1405 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1406 if (page
.window
== wnd
)
1408 m_pages
.RemoveAt(i
);
1410 // let the art provider know how many pages we have
1413 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1423 bool wxAuiTabContainer
::SetActivePage(wxWindow
* wnd
)
1427 size_t i
, page_count
= m_pages
.GetCount();
1428 for (i
= 0; i
< page_count
; ++i
)
1430 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1431 if (page
.window
== wnd
)
1438 page
.active
= false;
1445 void wxAuiTabContainer
::SetNoneActive()
1447 size_t i
, page_count
= m_pages
.GetCount();
1448 for (i
= 0; i
< page_count
; ++i
)
1450 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1451 page
.active
= false;
1455 bool wxAuiTabContainer
::SetActivePage(size_t page
)
1457 if (page
>= m_pages
.GetCount())
1460 return SetActivePage(m_pages
.Item(page
).window
);
1463 int wxAuiTabContainer
::GetActivePage() const
1465 size_t i
, page_count
= m_pages
.GetCount();
1466 for (i
= 0; i
< page_count
; ++i
)
1468 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1476 wxWindow
* wxAuiTabContainer
::GetWindowFromIdx(size_t idx
) const
1478 if (idx
>= m_pages
.GetCount())
1481 return m_pages
[idx
].window
;
1484 int wxAuiTabContainer
::GetIdxFromWindow(wxWindow
* wnd
) const
1486 const size_t page_count
= m_pages
.GetCount();
1487 for ( size_t i
= 0; i
< page_count
; ++i
)
1489 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1490 if (page
.window
== wnd
)
1496 wxAuiNotebookPage
& wxAuiTabContainer
::GetPage(size_t idx
)
1498 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
1500 return m_pages
[idx
];
1503 const wxAuiNotebookPage
& wxAuiTabContainer
::GetPage(size_t idx
) const
1505 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
1507 return m_pages
[idx
];
1510 wxAuiNotebookPageArray
& wxAuiTabContainer
::GetPages()
1515 size_t wxAuiTabContainer
::GetPageCount() const
1517 return m_pages
.GetCount();
1520 void wxAuiTabContainer
::AddButton(int id
,
1522 const wxBitmap
& normal_bitmap
,
1523 const wxBitmap
& disabled_bitmap
)
1525 wxAuiTabContainerButton button
;
1527 button
.bitmap
= normal_bitmap
;
1528 button
.dis_bitmap
= disabled_bitmap
;
1529 button
.location
= location
;
1530 button
.cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
1532 m_buttons
.Add(button
);
1535 void wxAuiTabContainer
::RemoveButton(int id
)
1537 size_t i
, button_count
= m_buttons
.GetCount();
1539 for (i
= 0; i
< button_count
; ++i
)
1541 if (m_buttons
.Item(i
).id
== id
)
1543 m_buttons
.RemoveAt(i
);
1551 size_t wxAuiTabContainer
::GetTabOffset() const
1553 return m_tab_offset
;
1556 void wxAuiTabContainer
::SetTabOffset(size_t offset
)
1558 m_tab_offset
= offset
;
1564 // Render() renders the tab catalog to the specified DC
1565 // It is a virtual function and can be overridden to
1566 // provide custom drawing capabilities
1567 void wxAuiTabContainer
::Render(wxDC
* raw_dc
, wxWindow
* wnd
)
1569 if (!raw_dc
|| !raw_dc
->IsOk())
1575 size_t page_count
= m_pages
.GetCount();
1576 size_t button_count
= m_buttons
.GetCount();
1578 // create off-screen bitmap
1579 bmp
.Create(m_rect
.GetWidth(), m_rect
.GetHeight());
1580 dc
.SelectObject(bmp
);
1585 // find out if size of tabs is larger than can be
1586 // afforded on screen
1587 int total_width
= 0;
1588 int visible_width
= 0;
1589 for (i
= 0; i
< page_count
; ++i
)
1591 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1593 // determine if a close button is on this tab
1594 bool close_button
= false;
1595 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1596 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1598 close_button
= true;
1603 wxSize size
= m_art
->GetTabSize(dc
,
1609 wxAUI_BUTTON_STATE_NORMAL
:
1610 wxAUI_BUTTON_STATE_HIDDEN
,
1613 if (i
+1 < page_count
)
1614 total_width
+= x_extent
;
1616 total_width
+= size
.x
;
1618 if (i
>= m_tab_offset
)
1620 if (i
+1 < page_count
)
1621 visible_width
+= x_extent
;
1623 visible_width
+= size
.x
;
1627 if (total_width
> m_rect
.GetWidth() || m_tab_offset
!= 0)
1629 // show left/right buttons
1630 for (i
= 0; i
< button_count
; ++i
)
1632 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1633 if (button
.id
== wxAUI_BUTTON_LEFT
||
1634 button
.id
== wxAUI_BUTTON_RIGHT
)
1636 button
.cur_state
&= ~wxAUI_BUTTON_STATE_HIDDEN
;
1642 // hide left/right buttons
1643 for (i
= 0; i
< button_count
; ++i
)
1645 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1646 if (button
.id
== wxAUI_BUTTON_LEFT
||
1647 button
.id
== wxAUI_BUTTON_RIGHT
)
1649 button
.cur_state
|= wxAUI_BUTTON_STATE_HIDDEN
;
1654 // determine whether left button should be enabled
1655 for (i
= 0; i
< button_count
; ++i
)
1657 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1658 if (button
.id
== wxAUI_BUTTON_LEFT
)
1660 if (m_tab_offset
== 0)
1661 button
.cur_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1663 button
.cur_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1665 if (button
.id
== wxAUI_BUTTON_RIGHT
)
1667 if (visible_width
< m_rect
.GetWidth() - ((int)button_count
*16))
1668 button
.cur_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1670 button
.cur_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1677 m_art
->DrawBackground(dc
, wnd
, m_rect
);
1680 int left_buttons_width
= 0;
1681 int right_buttons_width
= 0;
1685 // draw the buttons on the right side
1686 offset
= m_rect
.x
+ m_rect
.width
;
1687 for (i
= 0; i
< button_count
; ++i
)
1689 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1691 if (button
.location
!= wxRIGHT
)
1693 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1696 wxRect button_rect
= m_rect
;
1697 button_rect
.SetY(1);
1698 button_rect
.SetWidth(offset
);
1700 m_art
->DrawButton(dc
,
1708 offset
-= button
.rect
.GetWidth();
1709 right_buttons_width
+= button
.rect
.GetWidth();
1716 // draw the buttons on the left side
1718 for (i
= 0; i
< button_count
; ++i
)
1720 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1722 if (button
.location
!= wxLEFT
)
1724 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1727 wxRect
button_rect(offset
, 1, 1000, m_rect
.height
);
1729 m_art
->DrawButton(dc
,
1737 offset
+= button
.rect
.GetWidth();
1738 left_buttons_width
+= button
.rect
.GetWidth();
1741 offset
= left_buttons_width
;
1744 offset
+= m_art
->GetIndentSize();
1747 // prepare the tab-close-button array
1748 // make sure tab button entries which aren't used are marked as hidden
1749 for (i
= page_count
; i
< m_tab_close_buttons
.GetCount(); ++i
)
1750 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1752 // make sure there are enough tab button entries to accommodate all tabs
1753 while (m_tab_close_buttons
.GetCount() < page_count
)
1755 wxAuiTabContainerButton tempbtn
;
1756 tempbtn
.id
= wxAUI_BUTTON_CLOSE
;
1757 tempbtn
.location
= wxCENTER
;
1758 tempbtn
.cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1759 m_tab_close_buttons
.Add(tempbtn
);
1763 // buttons before the tab offset must be set to hidden
1764 for (i
= 0; i
< m_tab_offset
; ++i
)
1766 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1772 size_t active
= 999;
1773 int active_offset
= 0;
1777 wxRect rect
= m_rect
;
1779 rect
.height
= m_rect
.height
;
1781 for (i
= m_tab_offset
; i
< page_count
; ++i
)
1783 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1784 wxAuiTabContainerButton
& tab_button
= m_tab_close_buttons
.Item(i
);
1786 // determine if a close button is on this tab
1787 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1788 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1790 if (tab_button
.cur_state
== wxAUI_BUTTON_STATE_HIDDEN
)
1792 tab_button
.id
= wxAUI_BUTTON_CLOSE
;
1793 tab_button
.cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
1794 tab_button
.location
= wxCENTER
;
1799 tab_button
.cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1803 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
1805 if (rect
.width
<= 0)
1812 tab_button
.cur_state
,
1820 active_offset
= offset
;
1828 // make sure to deactivate buttons which are off the screen to the right
1829 for (++i
; i
< m_tab_close_buttons
.GetCount(); ++i
)
1831 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1835 // draw the active tab again so it stands in the foreground
1836 if (active
>= m_tab_offset
&& active
< m_pages
.GetCount())
1838 wxAuiNotebookPage
& page
= m_pages
.Item(active
);
1840 wxAuiTabContainerButton
& tab_button
= m_tab_close_buttons
.Item(active
);
1842 rect
.x
= active_offset
;
1847 tab_button
.cur_state
,
1854 raw_dc
->Blit(m_rect
.x
, m_rect
.y
,
1855 m_rect
.GetWidth(), m_rect
.GetHeight(),
1859 // Is the tab visible?
1860 bool wxAuiTabContainer
::IsTabVisible(int tabPage
, int tabOffset
, wxDC
* dc
, wxWindow
* wnd
)
1862 if (!dc
|| !dc
->IsOk())
1866 size_t page_count
= m_pages
.GetCount();
1867 size_t button_count
= m_buttons
.GetCount();
1869 // Hasn't been rendered yet; assume it's visible
1870 if (m_tab_close_buttons
.GetCount() < page_count
)
1873 // First check if both buttons are disabled - if so, there's no need to
1874 // check further for visibility.
1875 int arrowButtonVisibleCount
= 0;
1876 for (i
= 0; i
< button_count
; ++i
)
1878 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1879 if (button
.id
== wxAUI_BUTTON_LEFT
||
1880 button
.id
== wxAUI_BUTTON_RIGHT
)
1882 if ((button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
) == 0)
1883 arrowButtonVisibleCount
++;
1887 // Tab must be visible
1888 if (arrowButtonVisibleCount
== 0)
1891 // If tab is less than the given offset, it must be invisible by definition
1892 if (tabPage
< tabOffset
)
1896 int left_buttons_width
= 0;
1897 int right_buttons_width
= 0;
1901 // calculate size of the buttons on the right side
1902 offset
= m_rect
.x
+ m_rect
.width
;
1903 for (i
= 0; i
< button_count
; ++i
)
1905 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1907 if (button
.location
!= wxRIGHT
)
1909 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1912 offset
-= button
.rect
.GetWidth();
1913 right_buttons_width
+= button
.rect
.GetWidth();
1918 // calculate size of the buttons on the left side
1919 for (i
= 0; i
< button_count
; ++i
)
1921 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1923 if (button
.location
!= wxLEFT
)
1925 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1928 offset
+= button
.rect
.GetWidth();
1929 left_buttons_width
+= button
.rect
.GetWidth();
1932 offset
= left_buttons_width
;
1935 offset
+= m_art
->GetIndentSize();
1939 wxRect rect
= m_rect
;
1941 rect
.height
= m_rect
.height
;
1943 // See if the given page is visible at the given tab offset (effectively scroll position)
1944 for (i
= tabOffset
; i
< page_count
; ++i
)
1946 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1947 wxAuiTabContainerButton
& tab_button
= m_tab_close_buttons
.Item(i
);
1949 // determine if a close button is on this tab
1950 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1951 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1953 if (tab_button
.cur_state
== wxAUI_BUTTON_STATE_HIDDEN
)
1955 tab_button
.id
= wxAUI_BUTTON_CLOSE
;
1956 tab_button
.cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
1957 tab_button
.location
= wxCENTER
;
1962 tab_button
.cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1966 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
1968 if (rect
.width
<= 0)
1969 return false; // haven't found the tab, and we've run out of space, so return false
1972 wxSize size
= m_art
->GetTabSize(*dc
,
1977 tab_button
.cur_state
,
1982 if (i
== (size_t) tabPage
)
1984 // If not all of the tab is visible, and supposing there's space to display it all,
1985 // we could do better so we return false.
1986 if (((m_rect
.width
- right_buttons_width
- offset
- 2) <= 0) && ((m_rect
.width
- right_buttons_width
- left_buttons_width
) > x_extent
))
1993 // Shouldn't really get here, but if it does, assume the tab is visible to prevent
1994 // further looping in calling code.
1998 // Make the tab visible if it wasn't already
1999 void wxAuiTabContainer
::MakeTabVisible(int tabPage
, wxWindow
* win
)
2002 if (!IsTabVisible(tabPage
, GetTabOffset(), & dc
, win
))
2005 for (i
= 0; i
< (int) m_pages
.GetCount(); i
++)
2007 if (IsTabVisible(tabPage
, i
, & dc
, win
))
2017 // TabHitTest() tests if a tab was hit, passing the window pointer
2018 // back if that condition was fulfilled. The function returns
2019 // true if a tab was hit, otherwise false
2020 bool wxAuiTabContainer
::TabHitTest(int x
, int y
, wxWindow
** hit
) const
2022 if (!m_rect
.Contains(x
,y
))
2025 wxAuiTabContainerButton
* btn
= NULL
;
2026 if (ButtonHitTest(x
, y
, &btn
))
2028 if (m_buttons
.Index(*btn
) != wxNOT_FOUND
)
2032 size_t i
, page_count
= m_pages
.GetCount();
2034 for (i
= m_tab_offset
; i
< page_count
; ++i
)
2036 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
2037 if (page
.rect
.Contains(x
,y
))
2048 // ButtonHitTest() tests if a button was hit. The function returns
2049 // true if a button was hit, otherwise false
2050 bool wxAuiTabContainer
::ButtonHitTest(int x
, int y
,
2051 wxAuiTabContainerButton
** hit
) const
2053 if (!m_rect
.Contains(x
,y
))
2056 size_t i
, button_count
;
2059 button_count
= m_buttons
.GetCount();
2060 for (i
= 0; i
< button_count
; ++i
)
2062 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
2063 if (button
.rect
.Contains(x
,y
) &&
2064 !(button
.cur_state
& (wxAUI_BUTTON_STATE_HIDDEN
|
2065 wxAUI_BUTTON_STATE_DISABLED
)))
2073 button_count
= m_tab_close_buttons
.GetCount();
2074 for (i
= 0; i
< button_count
; ++i
)
2076 wxAuiTabContainerButton
& button
= m_tab_close_buttons
.Item(i
);
2077 if (button
.rect
.Contains(x
,y
) &&
2078 !(button
.cur_state
& (wxAUI_BUTTON_STATE_HIDDEN
|
2079 wxAUI_BUTTON_STATE_DISABLED
)))
2092 // the utility function ShowWnd() is the same as show,
2093 // except it handles wxAuiMDIChildFrame windows as well,
2094 // as the Show() method on this class is "unplugged"
2095 static void ShowWnd(wxWindow
* wnd
, bool show
)
2097 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
2099 wxAuiMDIChildFrame
* cf
= (wxAuiMDIChildFrame
*)wnd
;
2109 // DoShowHide() this function shows the active window, then
2110 // hides all of the other windows (in that order)
2111 void wxAuiTabContainer
::DoShowHide()
2113 wxAuiNotebookPageArray
& pages
= GetPages();
2114 size_t i
, page_count
= pages
.GetCount();
2116 // show new active page first
2117 for (i
= 0; i
< page_count
; ++i
)
2119 wxAuiNotebookPage
& page
= pages
.Item(i
);
2122 ShowWnd(page
.window
, true);
2127 // hide all other pages
2128 for (i
= 0; i
< page_count
; ++i
)
2130 wxAuiNotebookPage
& page
= pages
.Item(i
);
2132 ShowWnd(page
.window
, false);
2141 // -- wxAuiTabCtrl class implementation --
2145 BEGIN_EVENT_TABLE(wxAuiTabCtrl
, wxControl
)
2146 EVT_PAINT(wxAuiTabCtrl
::OnPaint
)
2147 EVT_ERASE_BACKGROUND(wxAuiTabCtrl
::OnEraseBackground
)
2148 EVT_SIZE(wxAuiTabCtrl
::OnSize
)
2149 EVT_LEFT_DOWN(wxAuiTabCtrl
::OnLeftDown
)
2150 EVT_LEFT_DCLICK(wxAuiTabCtrl
::OnLeftDown
)
2151 EVT_LEFT_UP(wxAuiTabCtrl
::OnLeftUp
)
2152 EVT_MIDDLE_DOWN(wxAuiTabCtrl
::OnMiddleDown
)
2153 EVT_MIDDLE_UP(wxAuiTabCtrl
::OnMiddleUp
)
2154 EVT_RIGHT_DOWN(wxAuiTabCtrl
::OnRightDown
)
2155 EVT_RIGHT_UP(wxAuiTabCtrl
::OnRightUp
)
2156 EVT_MOTION(wxAuiTabCtrl
::OnMotion
)
2157 EVT_LEAVE_WINDOW(wxAuiTabCtrl
::OnLeaveWindow
)
2158 EVT_AUINOTEBOOK_BUTTON(wxID_ANY
, wxAuiTabCtrl
::OnButton
)
2159 EVT_SET_FOCUS(wxAuiTabCtrl
::OnSetFocus
)
2160 EVT_KILL_FOCUS(wxAuiTabCtrl
::OnKillFocus
)
2161 EVT_CHAR(wxAuiTabCtrl
::OnChar
)
2165 wxAuiTabCtrl
::wxAuiTabCtrl(wxWindow
* parent
,
2169 long style
) : wxControl(parent
, id
, pos
, size
, style
)
2171 m_click_pt
= wxDefaultPosition
;
2172 m_is_dragging
= false;
2173 m_hover_button
= NULL
;
2174 m_pressed_button
= NULL
;
2177 wxAuiTabCtrl
::~wxAuiTabCtrl()
2181 void wxAuiTabCtrl
::OnPaint(wxPaintEvent
&)
2185 dc
.SetFont(GetFont());
2187 if (GetPageCount() > 0)
2191 void wxAuiTabCtrl
::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2195 void wxAuiTabCtrl
::OnSize(wxSizeEvent
& evt
)
2197 wxSize s
= evt
.GetSize();
2198 wxRect
r(0, 0, s
.GetWidth(), s
.GetHeight());
2202 void wxAuiTabCtrl
::OnLeftDown(wxMouseEvent
& evt
)
2205 m_click_pt
= wxDefaultPosition
;
2206 m_is_dragging
= false;
2208 m_pressed_button
= NULL
;
2212 if (TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2214 int new_selection
= GetIdxFromWindow(wnd
);
2216 // wxAuiNotebooks always want to receive this event
2217 // even if the tab is already active, because they may
2218 // have multiple tab controls
2219 if (new_selection
!= GetActivePage() ||
2220 GetParent()->IsKindOf(CLASSINFO(wxAuiNotebook
)))
2222 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2223 e
.SetSelection(new_selection
);
2224 e
.SetOldSelection(GetActivePage());
2225 e
.SetEventObject(this);
2226 GetEventHandler()->ProcessEvent(e
);
2229 m_click_pt
.x
= evt
.m_x
;
2230 m_click_pt
.y
= evt
.m_y
;
2236 m_pressed_button
= m_hover_button
;
2237 m_pressed_button
->cur_state
= wxAUI_BUTTON_STATE_PRESSED
;
2243 void wxAuiTabCtrl
::OnLeftUp(wxMouseEvent
& evt
)
2245 if (GetCapture() == this)
2250 m_is_dragging
= false;
2252 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
, m_windowId
);
2253 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2254 evt
.SetOldSelection(evt
.GetSelection());
2255 evt
.SetEventObject(this);
2256 GetEventHandler()->ProcessEvent(evt
);
2261 if (m_pressed_button
)
2263 // make sure we're still clicking the button
2264 wxAuiTabContainerButton
* button
= NULL
;
2265 if (!ButtonHitTest(evt
.m_x
, evt
.m_y
, &button
))
2268 if (button
!= m_pressed_button
)
2270 m_pressed_button
= NULL
;
2277 if (!(m_pressed_button
->cur_state
& wxAUI_BUTTON_STATE_DISABLED
))
2279 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
, m_windowId
);
2280 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2281 evt
.SetInt(m_pressed_button
->id
);
2282 evt
.SetEventObject(this);
2283 GetEventHandler()->ProcessEvent(evt
);
2286 m_pressed_button
= NULL
;
2289 m_click_pt
= wxDefaultPosition
;
2290 m_is_dragging
= false;
2294 void wxAuiTabCtrl
::OnMiddleUp(wxMouseEvent
& evt
)
2296 wxWindow
* wnd
= NULL
;
2297 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2300 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, m_windowId
);
2301 e
.SetEventObject(this);
2302 e
.SetSelection(GetIdxFromWindow(wnd
));
2303 GetEventHandler()->ProcessEvent(e
);
2306 void wxAuiTabCtrl
::OnMiddleDown(wxMouseEvent
& evt
)
2308 wxWindow
* wnd
= NULL
;
2309 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2312 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, m_windowId
);
2313 e
.SetEventObject(this);
2314 e
.SetSelection(GetIdxFromWindow(wnd
));
2315 GetEventHandler()->ProcessEvent(e
);
2318 void wxAuiTabCtrl
::OnRightUp(wxMouseEvent
& evt
)
2320 wxWindow
* wnd
= NULL
;
2321 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2324 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, m_windowId
);
2325 e
.SetEventObject(this);
2326 e
.SetSelection(GetIdxFromWindow(wnd
));
2327 GetEventHandler()->ProcessEvent(e
);
2330 void wxAuiTabCtrl
::OnRightDown(wxMouseEvent
& evt
)
2332 wxWindow
* wnd
= NULL
;
2333 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2336 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, m_windowId
);
2337 e
.SetEventObject(this);
2338 e
.SetSelection(GetIdxFromWindow(wnd
));
2339 GetEventHandler()->ProcessEvent(e
);
2342 void wxAuiTabCtrl
::OnMotion(wxMouseEvent
& evt
)
2344 wxPoint pos
= evt
.GetPosition();
2346 // check if the mouse is hovering above a button
2347 wxAuiTabContainerButton
* button
;
2348 if (ButtonHitTest(pos
.x
, pos
.y
, &button
))
2350 if (m_hover_button
&& button
!= m_hover_button
)
2352 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2353 m_hover_button
= NULL
;
2358 if (button
->cur_state
!= wxAUI_BUTTON_STATE_HOVER
)
2360 button
->cur_state
= wxAUI_BUTTON_STATE_HOVER
;
2363 m_hover_button
= button
;
2371 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2372 m_hover_button
= NULL
;
2379 if (!evt
.LeftIsDown() || m_click_pt
== wxDefaultPosition
)
2384 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
, m_windowId
);
2385 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2386 evt
.SetOldSelection(evt
.GetSelection());
2387 evt
.SetEventObject(this);
2388 GetEventHandler()->ProcessEvent(evt
);
2393 int drag_x_threshold
= wxSystemSettings
::GetMetric(wxSYS_DRAG_X
);
2394 int drag_y_threshold
= wxSystemSettings
::GetMetric(wxSYS_DRAG_Y
);
2396 if (abs(pos
.x
- m_click_pt
.x
) > drag_x_threshold
||
2397 abs(pos
.y
- m_click_pt
.y
) > drag_y_threshold
)
2399 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
, m_windowId
);
2400 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2401 evt
.SetOldSelection(evt
.GetSelection());
2402 evt
.SetEventObject(this);
2403 GetEventHandler()->ProcessEvent(evt
);
2405 m_is_dragging
= true;
2409 void wxAuiTabCtrl
::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
2413 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2414 m_hover_button
= NULL
;
2420 void wxAuiTabCtrl
::OnButton(wxAuiNotebookEvent
& event
)
2422 int button
= event
.GetInt();
2424 if (button
== wxAUI_BUTTON_LEFT
|| button
== wxAUI_BUTTON_RIGHT
)
2426 if (button
== wxAUI_BUTTON_LEFT
)
2428 if (GetTabOffset() > 0)
2430 SetTabOffset(GetTabOffset()-1);
2437 SetTabOffset(GetTabOffset()+1);
2442 else if (button
== wxAUI_BUTTON_WINDOWLIST
)
2444 int idx
= GetArtProvider()->ShowDropDown(this, m_pages
, GetActivePage());
2448 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2449 e
.SetSelection(idx
);
2450 e
.SetOldSelection(GetActivePage());
2451 e
.SetEventObject(this);
2452 GetEventHandler()->ProcessEvent(e
);
2461 void wxAuiTabCtrl
::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
2466 void wxAuiTabCtrl
::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
2471 void wxAuiTabCtrl
::OnChar(wxKeyEvent
& event
)
2473 if (GetActivePage() == -1)
2479 // We can't leave tab processing to the system; on Windows, tabs and keys
2480 // get eaten by the system and not processed properly if we specify both
2481 // wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL,
2482 // we don't key arrow key events.
2484 int key
= event
.GetKeyCode();
2486 if (key
== WXK_NUMPAD_PAGEUP
)
2488 if (key
== WXK_NUMPAD_PAGEDOWN
)
2490 if (key
== WXK_NUMPAD_HOME
)
2492 if (key
== WXK_NUMPAD_END
)
2494 if (key
== WXK_NUMPAD_LEFT
)
2496 if (key
== WXK_NUMPAD_RIGHT
)
2499 if (key
== WXK_TAB
|| key
== WXK_PAGEUP
|| key
== WXK_PAGEDOWN
)
2501 bool bCtrlDown
= event
.ControlDown();
2502 bool bShiftDown
= event
.ShiftDown();
2504 bool bForward
= (key
== WXK_TAB
&& !bShiftDown
) || (key
== WXK_PAGEDOWN
);
2505 bool bWindowChange
= (key
== WXK_PAGEUP
) || (key
== WXK_PAGEDOWN
) || bCtrlDown
;
2506 bool bFromTab
= (key
== WXK_TAB
);
2508 wxAuiNotebook
* nb
= wxDynamicCast(GetParent(), wxAuiNotebook
);
2515 wxNavigationKeyEvent keyEvent
;
2516 keyEvent
.SetDirection(bForward
);
2517 keyEvent
.SetWindowChange(bWindowChange
);
2518 keyEvent
.SetFromTab(bFromTab
);
2519 keyEvent
.SetEventObject(nb
);
2521 if (!nb
->GetEventHandler()->ProcessEvent(keyEvent
))
2523 // Not processed? Do an explicit tab into the page.
2524 wxWindow
* win
= GetWindowFromIdx(GetActivePage());
2531 if (m_pages
.GetCount() < 2)
2539 if (key
== WXK_RIGHT
)
2541 if (m_pages
.GetCount() > 1)
2543 if (GetActivePage() == -1)
2545 else if (GetActivePage() < (int) (m_pages
.GetCount() - 1))
2546 newPage
= GetActivePage() + 1;
2549 else if (key
== WXK_LEFT
)
2551 if (m_pages
.GetCount() > 1)
2553 if (GetActivePage() == -1)
2554 newPage
= (int) (m_pages
.GetCount() - 1);
2555 else if (GetActivePage() > 0)
2556 newPage
= GetActivePage() - 1;
2559 else if (key
== WXK_HOME
)
2563 else if (key
== WXK_END
)
2565 newPage
= (int) (m_pages
.GetCount() - 1);
2572 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2573 e
.SetSelection(newPage
);
2574 e
.SetOldSelection(newPage
);
2575 e
.SetEventObject(this);
2576 this->GetEventHandler()->ProcessEvent(e
);
2582 // wxTabFrame is an interesting case. It's important that all child pages
2583 // of the multi-notebook control are all actually children of that control
2584 // (and not grandchildren). wxTabFrame facilitates this. There is one
2585 // instance of wxTabFrame for each tab control inside the multi-notebook.
2586 // It's important to know that wxTabFrame is not a real window, but it merely
2587 // used to capture the dimensions/positioning of the internal tab control and
2588 // it's managed page windows
2590 class wxTabFrame
: public wxWindow
2597 m_rect
= wxRect(0,0,200,200);
2598 m_tab_ctrl_height
= 20;
2606 void SetTabCtrlHeight(int h
)
2608 m_tab_ctrl_height
= h
;
2612 void DoSetSize(int x
, int y
,
2613 int width
, int height
,
2614 int WXUNUSED(sizeFlags
= wxSIZE_AUTO
))
2616 m_rect
= wxRect(x
, y
, width
, height
);
2620 void DoGetClientSize(int* x
, int* y
) const
2627 bool Show( bool WXUNUSED(show
= true) ) { return false; }
2634 m_tab_rect
= wxRect(m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tab_ctrl_height
);
2635 m_tabs
->SetSize(m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tab_ctrl_height
);
2636 m_tabs
->SetRect(wxRect(0, 0, m_rect
.width
, m_tab_ctrl_height
));
2640 wxAuiNotebookPageArray
& pages
= m_tabs
->GetPages();
2641 size_t i
, page_count
= pages
.GetCount();
2643 for (i
= 0; i
< page_count
; ++i
)
2645 wxAuiNotebookPage
& page
= pages
.Item(i
);
2646 page
.window
->SetSize(m_rect
.x
, m_rect
.y
+ m_tab_ctrl_height
,
2647 m_rect
.width
, m_rect
.height
- m_tab_ctrl_height
);
2649 if (page
.window
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
2651 wxAuiMDIChildFrame
* wnd
= (wxAuiMDIChildFrame
*)page
.window
;
2652 wnd
->ApplyMDIChildFrameRect();
2658 void DoGetSize(int* x
, int* y
) const
2661 *x
= m_rect
.GetWidth();
2663 *y
= m_rect
.GetHeight();
2674 wxAuiTabCtrl
* m_tabs
;
2675 int m_tab_ctrl_height
;
2679 const int wxAuiBaseTabCtrlId
= 5380;
2682 // -- wxAuiNotebook class implementation --
2684 BEGIN_EVENT_TABLE(wxAuiNotebook
, wxControl
)
2685 EVT_SIZE(wxAuiNotebook
::OnSize
)
2686 EVT_CHILD_FOCUS(wxAuiNotebook
::OnChildFocus
)
2687 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2688 wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
,
2689 wxAuiNotebook
::OnTabClicked
)
2690 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2691 wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
,
2692 wxAuiNotebook
::OnTabBeginDrag
)
2693 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2694 wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
,
2695 wxAuiNotebook
::OnTabEndDrag
)
2696 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2697 wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
,
2698 wxAuiNotebook
::OnTabDragMotion
)
2699 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2700 wxEVT_COMMAND_AUINOTEBOOK_BUTTON
,
2701 wxAuiNotebook
::OnTabButton
)
2702 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2703 wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
,
2704 wxAuiNotebook
::OnTabMiddleDown
)
2705 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2706 wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
,
2707 wxAuiNotebook
::OnTabMiddleUp
)
2708 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2709 wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
,
2710 wxAuiNotebook
::OnTabRightDown
)
2711 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2712 wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
,
2713 wxAuiNotebook
::OnTabRightUp
)
2714 EVT_NAVIGATION_KEY(wxAuiNotebook
::OnNavigationKey
)
2717 wxAuiNotebook
::wxAuiNotebook()
2720 m_tab_id_counter
= wxAuiBaseTabCtrlId
;
2722 m_tab_ctrl_height
= 20;
2723 m_requested_bmp_size
= wxDefaultSize
;
2724 m_requested_tabctrl_height
= -1;
2727 wxAuiNotebook
::wxAuiNotebook(wxWindow
*parent
,
2731 long style
) : wxControl(parent
, id
, pos
, size
, style
)
2734 m_requested_bmp_size
= wxDefaultSize
;
2735 m_requested_tabctrl_height
= -1;
2736 InitNotebook(style
);
2739 bool wxAuiNotebook
::Create(wxWindow
* parent
,
2745 if (!wxControl
::Create(parent
, id
, pos
, size
, style
))
2748 InitNotebook(style
);
2753 // InitNotebook() contains common initialization
2754 // code called by all constructors
2755 void wxAuiNotebook
::InitNotebook(long style
)
2758 m_tab_id_counter
= wxAuiBaseTabCtrlId
;
2760 m_flags
= (unsigned int)style
;
2761 m_tab_ctrl_height
= 20;
2763 m_normal_font
= *wxNORMAL_FONT
;
2764 m_selected_font
= *wxNORMAL_FONT
;
2765 m_selected_font
.SetWeight(wxBOLD
);
2767 SetArtProvider(new wxAuiDefaultTabArt
);
2769 m_dummy_wnd
= new wxWindow(this, wxID_ANY
, wxPoint(0,0), wxSize(0,0));
2770 m_dummy_wnd
->SetSize(200, 200);
2771 m_dummy_wnd
->Show(false);
2773 m_mgr
.SetManagedWindow(this);
2774 m_mgr
.SetFlags(wxAUI_MGR_DEFAULT
);
2775 m_mgr
.SetDockSizeConstraint(1.0, 1.0); // no dock size constraint
2777 m_mgr
.AddPane(m_dummy_wnd
,
2778 wxAuiPaneInfo().Name(wxT("dummy")).Bottom().CaptionVisible(false).Show(false));
2783 wxAuiNotebook
::~wxAuiNotebook()
2788 void wxAuiNotebook
::SetArtProvider(wxAuiTabArt
* art
)
2790 m_tabs
.SetArtProvider(art
);
2792 UpdateTabCtrlHeight();
2795 // SetTabCtrlHeight() is the highest-level override of the
2796 // tab height. A call to this function effectively enforces a
2797 // specified tab ctrl height, overriding all other considerations,
2798 // such as text or bitmap height. It overrides any call to
2799 // SetUniformBitmapSize(). Specifying a height of -1 reverts
2800 // any previous call and returns to the default behavior
2802 void wxAuiNotebook
::SetTabCtrlHeight(int height
)
2804 m_requested_tabctrl_height
= height
;
2806 // if window is already initialized, recalculate the tab height
2809 UpdateTabCtrlHeight();
2814 // SetUniformBitmapSize() ensures that all tabs will have
2815 // the same height, even if some tabs don't have bitmaps
2816 // Passing wxDefaultSize to this function will instruct
2817 // the control to use dynamic tab height-- so when a tab
2818 // with a large bitmap is added, the tab ctrl's height will
2819 // automatically increase to accommodate the bitmap
2821 void wxAuiNotebook
::SetUniformBitmapSize(const wxSize
& size
)
2823 m_requested_bmp_size
= size
;
2825 // if window is already initialized, recalculate the tab height
2828 UpdateTabCtrlHeight();
2832 // UpdateTabCtrlHeight() does the actual tab resizing. It's meant
2833 // to be used interally
2834 void wxAuiNotebook
::UpdateTabCtrlHeight()
2836 // get the tab ctrl height we will use
2837 int height
= CalculateTabCtrlHeight();
2839 // if the tab control height needs to change, update
2840 // all of our tab controls with the new height
2841 if (m_tab_ctrl_height
!= height
)
2843 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
2845 m_tab_ctrl_height
= height
;
2847 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2848 size_t i
, pane_count
= all_panes
.GetCount();
2849 for (i
= 0; i
< pane_count
; ++i
)
2851 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2852 if (pane
.name
== wxT("dummy"))
2854 wxTabFrame
* tab_frame
= (wxTabFrame
*)pane
.window
;
2855 wxAuiTabCtrl
* tabctrl
= tab_frame
->m_tabs
;
2856 tab_frame
->SetTabCtrlHeight(m_tab_ctrl_height
);
2857 tabctrl
->SetArtProvider(art
->Clone());
2858 tab_frame
->DoSizing();
2863 void wxAuiNotebook
::UpdateHintWindowSize()
2865 wxSize size
= CalculateNewSplitSize();
2867 // the placeholder hint window should be set to this size
2868 wxAuiPaneInfo
& info
= m_mgr
.GetPane(wxT("dummy"));
2872 info
.BestSize(size
);
2873 m_dummy_wnd
->SetSize(size
);
2878 // calculates the size of the new split
2879 wxSize wxAuiNotebook
::CalculateNewSplitSize()
2881 // count number of tab controls
2882 int tab_ctrl_count
= 0;
2883 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2884 size_t i
, pane_count
= all_panes
.GetCount();
2885 for (i
= 0; i
< pane_count
; ++i
)
2887 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2888 if (pane
.name
== wxT("dummy"))
2893 wxSize new_split_size
;
2895 // if there is only one tab control, the first split
2896 // should happen around the middle
2897 if (tab_ctrl_count
< 2)
2899 new_split_size
= GetClientSize();
2900 new_split_size
.x
/= 2;
2901 new_split_size
.y
/= 2;
2905 // this is in place of a more complicated calculation
2906 // that needs to be implemented
2907 new_split_size
= wxSize(180,180);
2910 return new_split_size
;
2913 int wxAuiNotebook
::CalculateTabCtrlHeight()
2915 // if a fixed tab ctrl height is specified,
2916 // just return that instead of calculating a
2918 if (m_requested_tabctrl_height
!= -1)
2919 return m_requested_tabctrl_height
;
2921 // find out new best tab height
2922 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
2924 return art
->GetBestTabCtrlSize(this,
2926 m_requested_bmp_size
);
2930 wxAuiTabArt
* wxAuiNotebook
::GetArtProvider() const
2932 return m_tabs
.GetArtProvider();
2935 void wxAuiNotebook
::SetWindowStyleFlag(long style
)
2937 wxControl
::SetWindowStyleFlag(style
);
2939 m_flags
= (unsigned int)style
;
2941 // if the control is already initialized
2942 if (m_mgr
.GetManagedWindow() == (wxWindow
*)this)
2944 // let all of the tab children know about the new style
2946 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2947 size_t i
, pane_count
= all_panes
.GetCount();
2948 for (i
= 0; i
< pane_count
; ++i
)
2950 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2951 if (pane
.name
== wxT("dummy"))
2953 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
2954 wxAuiTabCtrl
* tabctrl
= tabframe
->m_tabs
;
2955 tabctrl
->SetFlags(m_flags
);
2956 tabframe
->DoSizing();
2964 bool wxAuiNotebook
::AddPage(wxWindow
* page
,
2965 const wxString
& caption
,
2967 const wxBitmap
& bitmap
)
2969 return InsertPage(GetPageCount(), page
, caption
, select
, bitmap
);
2972 bool wxAuiNotebook
::InsertPage(size_t page_idx
,
2974 const wxString
& caption
,
2976 const wxBitmap
& bitmap
)
2978 wxAuiNotebookPage info
;
2980 info
.caption
= caption
;
2981 info
.bitmap
= bitmap
;
2982 info
.active
= false;
2984 // if there are currently no tabs, the first added
2985 // tab must be active
2986 if (m_tabs
.GetPageCount() == 0)
2989 m_tabs
.InsertPage(page
, info
, page_idx
);
2991 // if that was the first page added, even if
2992 // select is false, it must become the "current page"
2993 // (though no select events will be fired)
2994 if (!select
&& m_tabs
.GetPageCount() == 1)
2996 //m_curpage = GetPageIndex(page);
2998 wxAuiTabCtrl
* active_tabctrl
= GetActiveTabCtrl();
2999 if (page_idx
>= active_tabctrl
->GetPageCount())
3000 active_tabctrl
->AddPage(page
, info
);
3002 active_tabctrl
->InsertPage(page
, info
, page_idx
);
3004 UpdateTabCtrlHeight();
3006 active_tabctrl
->DoShowHide();
3010 SetSelectionToWindow(page
);
3017 // DeletePage() removes a tab from the multi-notebook,
3018 // and destroys the window as well
3019 bool wxAuiNotebook
::DeletePage(size_t page_idx
)
3021 if (page_idx
>= m_tabs
.GetPageCount())
3024 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
3026 // hide the window in advance, as this will
3028 ShowWnd(wnd
, false);
3030 if (!RemovePage(page_idx
))
3033 // actually destroy the window now
3034 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
3036 // delete the child frame with pending delete, as is
3037 // customary with frame windows
3038 if (!wxPendingDelete
.Member(wnd
))
3039 wxPendingDelete
.Append(wnd
);
3051 // RemovePage() removes a tab from the multi-notebook,
3052 // but does not destroy the window
3053 bool wxAuiNotebook
::RemovePage(size_t page_idx
)
3055 // save active window pointer
3056 wxWindow
* active_wnd
= NULL
;
3058 active_wnd
= m_tabs
.GetWindowFromIdx(m_curpage
);
3060 // save pointer of window being deleted
3061 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
3062 wxWindow
* new_active
= NULL
;
3064 // make sure we found the page
3068 // find out which onscreen tab ctrl owns this tab
3071 if (!FindTab(wnd
, &ctrl
, &ctrl_idx
))
3074 bool is_curpage
= (m_curpage
== (int)page_idx
);
3075 bool is_active_in_split
= ctrl
->GetPage(ctrl_idx
).active
;
3078 // remove the tab from main catalog
3079 if (!m_tabs
.RemovePage(wnd
))
3082 // remove the tab from the onscreen tab ctrl
3083 ctrl
->RemovePage(wnd
);
3085 if (is_active_in_split
)
3087 int ctrl_new_page_count
= (int)ctrl
->GetPageCount();
3089 if (ctrl_idx
>= ctrl_new_page_count
)
3090 ctrl_idx
= ctrl_new_page_count
-1;
3092 if (ctrl_idx
>= 0 && ctrl_idx
< (int)ctrl
->GetPageCount())
3094 // set new page as active in the tab split
3095 ctrl
->SetActivePage(ctrl_idx
);
3097 // if the page deleted was the current page for the
3098 // entire tab control, then record the window
3099 // pointer of the new active page for activation
3102 new_active
= ctrl
->GetWindowFromIdx(ctrl_idx
);
3108 // we are not deleting the active page, so keep it the same
3109 new_active
= active_wnd
;
3115 // we haven't yet found a new page to active,
3116 // so select the next page from the main tab
3119 if (page_idx
< m_tabs
.GetPageCount())
3121 new_active
= m_tabs
.GetPage(page_idx
).window
;
3124 if (!new_active
&& m_tabs
.GetPageCount() > 0)
3126 new_active
= m_tabs
.GetPage(0).window
;
3131 RemoveEmptyTabFrames();
3133 // set new active pane
3137 SetSelectionToWindow(new_active
);
3143 // GetPageIndex() returns the index of the page, or -1 if the
3144 // page could not be located in the notebook
3145 int wxAuiNotebook
::GetPageIndex(wxWindow
* page_wnd
) const
3147 return m_tabs
.GetIdxFromWindow(page_wnd
);
3152 // SetPageText() changes the tab caption of the specified page
3153 bool wxAuiNotebook
::SetPageText(size_t page_idx
, const wxString
& text
)
3155 if (page_idx
>= m_tabs
.GetPageCount())
3158 // update our own tab catalog
3159 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3160 page_info
.caption
= text
;
3162 // update what's on screen
3165 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
3167 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
3168 info
.caption
= text
;
3176 // returns the page caption
3177 wxString wxAuiNotebook
::GetPageText(size_t page_idx
) const
3179 if (page_idx
>= m_tabs
.GetPageCount())
3180 return wxEmptyString
;
3182 // update our own tab catalog
3183 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3184 return page_info
.caption
;
3187 bool wxAuiNotebook
::SetPageBitmap(size_t page_idx
, const wxBitmap
& bitmap
)
3189 if (page_idx
>= m_tabs
.GetPageCount())
3192 // update our own tab catalog
3193 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3194 page_info
.bitmap
= bitmap
;
3196 // tab height might have changed
3197 UpdateTabCtrlHeight();
3199 // update what's on screen
3202 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
3204 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
3205 info
.bitmap
= bitmap
;
3213 // returns the page bitmap
3214 wxBitmap wxAuiNotebook
::GetPageBitmap(size_t page_idx
) const
3216 if (page_idx
>= m_tabs
.GetPageCount())
3219 // update our own tab catalog
3220 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3221 return page_info
.bitmap
;
3224 // GetSelection() returns the index of the currently active page
3225 int wxAuiNotebook
::GetSelection() const
3230 // SetSelection() sets the currently active page
3231 size_t wxAuiNotebook
::SetSelection(size_t new_page
)
3233 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(new_page
);
3237 // don't change the page unless necessary;
3238 // however, clicking again on a tab should give it the focus.
3239 if ((int)new_page
== m_curpage
)
3243 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
3245 if (FindFocus() != ctrl
)
3251 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
3252 evt
.SetSelection(new_page
);
3253 evt
.SetOldSelection(m_curpage
);
3254 evt
.SetEventObject(this);
3255 if (!GetEventHandler()->ProcessEvent(evt
) || evt
.IsAllowed())
3257 int old_curpage
= m_curpage
;
3258 m_curpage
= new_page
;
3260 // program allows the page change
3261 evt
.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
);
3262 (void)GetEventHandler()->ProcessEvent(evt
);
3267 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
3269 m_tabs
.SetActivePage(wnd
);
3271 ctrl
->SetActivePage(ctrl_idx
);
3275 ctrl
->MakeTabVisible(ctrl_idx
, ctrl
);
3278 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3279 size_t i
, pane_count
= all_panes
.GetCount();
3280 for (i
= 0; i
< pane_count
; ++i
)
3282 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
3283 if (pane
.name
== wxT("dummy"))
3285 wxAuiTabCtrl
* tabctrl
= ((wxTabFrame
*)pane
.window
)->m_tabs
;
3286 if (tabctrl
!= ctrl
)
3287 tabctrl
->SetSelectedFont(m_normal_font
);
3289 tabctrl
->SetSelectedFont(m_selected_font
);
3293 // Set the focus to the page if we're not currently focused on the tab.
3294 // This is Firefox-like behaviour.
3295 if (wnd
->IsShownOnScreen() && FindFocus() != ctrl
)
3305 void wxAuiNotebook
::SetSelectionToWindow(wxWindow
*win
)
3307 const int idx
= m_tabs
.GetIdxFromWindow(win
);
3308 wxCHECK_RET( idx
!= wxNOT_FOUND
, _T("invalid notebook page") );
3313 // GetPageCount() returns the total number of
3314 // pages managed by the multi-notebook
3315 size_t wxAuiNotebook
::GetPageCount() const
3317 return m_tabs
.GetPageCount();
3320 // GetPage() returns the wxWindow pointer of the
3322 wxWindow
* wxAuiNotebook
::GetPage(size_t page_idx
) const
3324 wxASSERT(page_idx
< m_tabs
.GetPageCount());
3326 return m_tabs
.GetWindowFromIdx(page_idx
);
3329 // DoSizing() performs all sizing operations in each tab control
3330 void wxAuiNotebook
::DoSizing()
3332 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3333 size_t i
, pane_count
= all_panes
.GetCount();
3334 for (i
= 0; i
< pane_count
; ++i
)
3336 if (all_panes
.Item(i
).name
== wxT("dummy"))
3339 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3340 tabframe
->DoSizing();
3344 // GetActiveTabCtrl() returns the active tab control. It is
3345 // called to determine which control gets new windows being added
3346 wxAuiTabCtrl
* wxAuiNotebook
::GetActiveTabCtrl()
3348 if (m_curpage
>= 0 && m_curpage
< (int)m_tabs
.GetPageCount())
3353 // find the tab ctrl with the current page
3354 if (FindTab(m_tabs
.GetPage(m_curpage
).window
,
3361 // no current page, just find the first tab ctrl
3362 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3363 size_t i
, pane_count
= all_panes
.GetCount();
3364 for (i
= 0; i
< pane_count
; ++i
)
3366 if (all_panes
.Item(i
).name
== wxT("dummy"))
3369 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3370 return tabframe
->m_tabs
;
3373 // If there is no tabframe at all, create one
3374 wxTabFrame
* tabframe
= new wxTabFrame
;
3375 tabframe
->SetTabCtrlHeight(m_tab_ctrl_height
);
3376 tabframe
->m_tabs
= new wxAuiTabCtrl(this,
3380 wxNO_BORDER
|wxWANTS_CHARS
);
3381 tabframe
->m_tabs
->SetFlags(m_flags
);
3382 tabframe
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3383 m_mgr
.AddPane(tabframe
,
3384 wxAuiPaneInfo().Center().CaptionVisible(false));
3388 return tabframe
->m_tabs
;
3391 // FindTab() finds the tab control that currently contains the window as well
3392 // as the index of the window in the tab control. It returns true if the
3393 // window was found, otherwise false.
3394 bool wxAuiNotebook
::FindTab(wxWindow
* page
, wxAuiTabCtrl
** ctrl
, int* idx
)
3396 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3397 size_t i
, pane_count
= all_panes
.GetCount();
3398 for (i
= 0; i
< pane_count
; ++i
)
3400 if (all_panes
.Item(i
).name
== wxT("dummy"))
3403 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3405 int page_idx
= tabframe
->m_tabs
->GetIdxFromWindow(page
);
3408 *ctrl
= tabframe
->m_tabs
;
3417 void wxAuiNotebook
::Split(size_t page
, int direction
)
3419 wxSize cli_size
= GetClientSize();
3421 // get the page's window pointer
3422 wxWindow
* wnd
= GetPage(page
);
3426 // notebooks with 1 or less pages can't be split
3427 if (GetPageCount() < 2)
3430 // find out which tab control the page currently belongs to
3431 wxAuiTabCtrl
*src_tabs
, *dest_tabs
;
3434 if (!FindTab(wnd
, &src_tabs
, &src_idx
))
3436 if (!src_tabs
|| src_idx
== -1)
3439 // choose a split size
3441 if (GetPageCount() > 2)
3443 split_size
= CalculateNewSplitSize();
3447 // because there are two panes, always split them
3449 split_size
= GetClientSize();
3455 // create a new tab frame
3456 wxTabFrame
* new_tabs
= new wxTabFrame
;
3457 new_tabs
->m_rect
= wxRect(wxPoint(0,0), split_size
);
3458 new_tabs
->SetTabCtrlHeight(m_tab_ctrl_height
);
3459 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
3463 wxNO_BORDER
|wxWANTS_CHARS
);
3464 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3465 new_tabs
->m_tabs
->SetFlags(m_flags
);
3466 dest_tabs
= new_tabs
->m_tabs
;
3468 // create a pane info structure with the information
3469 // about where the pane should be added
3470 wxAuiPaneInfo pane_info
= wxAuiPaneInfo().Bottom().CaptionVisible(false);
3473 if (direction
== wxLEFT
)
3476 mouse_pt
= wxPoint(0, cli_size
.y
/2);
3478 else if (direction
== wxRIGHT
)
3481 mouse_pt
= wxPoint(cli_size
.x
, cli_size
.y
/2);
3483 else if (direction
== wxTOP
)
3486 mouse_pt
= wxPoint(cli_size
.x
/2, 0);
3488 else if (direction
== wxBOTTOM
)
3491 mouse_pt
= wxPoint(cli_size
.x
/2, cli_size
.y
);
3494 m_mgr
.AddPane(new_tabs
, pane_info
, mouse_pt
);
3497 // remove the page from the source tabs
3498 wxAuiNotebookPage page_info
= src_tabs
->GetPage(src_idx
);
3499 page_info
.active
= false;
3500 src_tabs
->RemovePage(page_info
.window
);
3501 if (src_tabs
->GetPageCount() > 0)
3503 src_tabs
->SetActivePage((size_t)0);
3504 src_tabs
->DoShowHide();
3505 src_tabs
->Refresh();
3509 // add the page to the destination tabs
3510 dest_tabs
->InsertPage(page_info
.window
, page_info
, 0);
3512 if (src_tabs
->GetPageCount() == 0)
3514 RemoveEmptyTabFrames();
3518 dest_tabs
->DoShowHide();
3519 dest_tabs
->Refresh();
3521 // force the set selection function reset the selection
3524 // set the active page to the one we just split off
3525 SetSelectionToPage(page_info
);
3527 UpdateHintWindowSize();
3531 void wxAuiNotebook
::OnSize(wxSizeEvent
& evt
)
3533 UpdateHintWindowSize();
3538 void wxAuiNotebook
::OnTabClicked(wxCommandEvent
& command_evt
)
3540 wxAuiNotebookEvent
& evt
= (wxAuiNotebookEvent
&)command_evt
;
3542 wxAuiTabCtrl
* ctrl
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3543 wxASSERT(ctrl
!= NULL
);
3545 wxWindow
* wnd
= ctrl
->GetWindowFromIdx(evt
.GetSelection());
3546 wxASSERT(wnd
!= NULL
);
3548 SetSelectionToWindow(wnd
);
3551 void wxAuiNotebook
::OnTabBeginDrag(wxCommandEvent
&)
3556 void wxAuiNotebook
::OnTabDragMotion(wxCommandEvent
& evt
)
3558 wxPoint screen_pt
= ::wxGetMousePosition();
3559 wxPoint client_pt
= ScreenToClient(screen_pt
);
3562 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3563 wxAuiTabCtrl
* dest_tabs
= GetTabCtrlFromPoint(client_pt
);
3565 if (dest_tabs
== src_tabs
)
3569 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
3572 // always hide the hint for inner-tabctrl drag
3575 // if tab moving is not allowed, leave
3576 if (!(m_flags
& wxAUI_NB_TAB_MOVE
))
3581 wxPoint pt
= dest_tabs
->ScreenToClient(screen_pt
);
3582 wxWindow
* dest_location_tab
;
3584 // this is an inner-tab drag/reposition
3585 if (dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &dest_location_tab
))
3587 int src_idx
= evt
.GetSelection();
3588 int dest_idx
= dest_tabs
->GetIdxFromWindow(dest_location_tab
);
3590 // prevent jumpy drag
3591 if ((src_idx
== dest_idx
) || dest_idx
== -1 ||
3592 (src_idx
> dest_idx
&& m_last_drag_x
<= pt
.x
) ||
3593 (src_idx
< dest_idx
&& m_last_drag_x
>= pt
.x
))
3595 m_last_drag_x
= pt
.x
;
3600 wxWindow
* src_tab
= dest_tabs
->GetWindowFromIdx(src_idx
);
3601 dest_tabs
->MovePage(src_tab
, dest_idx
);
3602 dest_tabs
->SetActivePage((size_t)dest_idx
);
3603 dest_tabs
->DoShowHide();
3604 dest_tabs
->Refresh();
3605 m_last_drag_x
= pt
.x
;
3613 // if external drag is allowed, check if the tab is being dragged
3614 // over a different wxAuiNotebook control
3615 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
3617 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(screen_pt
);
3619 // if we aren't over any window, stop here
3623 // make sure we are not over the hint window
3624 if (!tab_ctrl
->IsKindOf(CLASSINFO(wxFrame
)))
3628 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
3630 tab_ctrl
= tab_ctrl
->GetParent();
3635 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
3639 wxRect hint_rect
= tab_ctrl
->GetClientRect();
3640 tab_ctrl
->ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
3641 m_mgr
.ShowHint(hint_rect
);
3650 // we are either over a hint window, or not over a tab
3651 // window, and there is no where to drag to, so exit
3658 // if there are less than two panes, split can't happen, so leave
3659 if (m_tabs
.GetPageCount() < 2)
3662 // if tab moving is not allowed, leave
3663 if (!(m_flags
& wxAUI_NB_TAB_SPLIT
))
3669 src_tabs
->SetCursor(wxCursor(wxCURSOR_SIZING
));
3675 wxRect hint_rect
= dest_tabs
->GetRect();
3676 ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
3677 m_mgr
.ShowHint(hint_rect
);
3681 m_mgr
.DrawHintRect(m_dummy_wnd
, client_pt
, zero
);
3687 void wxAuiNotebook
::OnTabEndDrag(wxCommandEvent
& command_evt
)
3689 wxAuiNotebookEvent
& evt
= (wxAuiNotebookEvent
&)command_evt
;
3694 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3695 wxCHECK_RET( src_tabs
, _T("no source object?") );
3697 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
3699 // get the mouse position, which will be used to determine the drop point
3700 wxPoint mouse_screen_pt
= ::wxGetMousePosition();
3701 wxPoint mouse_client_pt
= ScreenToClient(mouse_screen_pt
);
3705 // check for an external move
3706 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
3708 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(mouse_screen_pt
);
3712 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
3714 tab_ctrl
= tab_ctrl
->GetParent();
3719 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
3723 // find out from the destination control
3724 // if it's ok to drop this tab here
3725 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
, m_windowId
);
3726 e
.SetSelection(evt
.GetSelection());
3727 e
.SetOldSelection(evt
.GetSelection());
3728 e
.SetEventObject(this);
3729 e
.SetDragSource(this);
3730 e
.Veto(); // dropping must be explicitly approved by control owner
3732 nb
->GetEventHandler()->ProcessEvent(e
);
3736 // no answer or negative answer
3742 int src_idx
= evt
.GetSelection();
3743 wxWindow
* src_page
= src_tabs
->GetWindowFromIdx(src_idx
);
3745 // Check that it's not an impossible parent relationship
3747 while (p
&& !p
->IsTopLevel())
3756 // get main index of the page
3757 int main_idx
= m_tabs
.GetIdxFromWindow(src_page
);
3758 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, _T("no source page?") );
3761 // make a copy of the page info
3762 wxAuiNotebookPage page_info
= m_tabs
.GetPage(main_idx
);
3764 // remove the page from the source notebook
3765 RemovePage(main_idx
);
3767 // reparent the page
3768 src_page
->Reparent(nb
);
3771 // found out the insert idx
3772 wxAuiTabCtrl
* dest_tabs
= (wxAuiTabCtrl
*)tab_ctrl
;
3773 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
3775 wxWindow
* target
= NULL
;
3776 int insert_idx
= -1;
3777 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
3780 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
3784 // add the page to the new notebook
3785 if (insert_idx
== -1)
3786 insert_idx
= dest_tabs
->GetPageCount();
3787 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
3788 nb
->m_tabs
.AddPage(page_info
.window
, page_info
);
3791 dest_tabs
->DoShowHide();
3792 dest_tabs
->Refresh();
3794 // set the selection in the destination tab control
3795 nb
->SetSelectionToPage(page_info
);
3805 // only perform a tab split if it's allowed
3806 wxAuiTabCtrl
* dest_tabs
= NULL
;
3808 if ((m_flags
& wxAUI_NB_TAB_SPLIT
) && m_tabs
.GetPageCount() >= 2)
3810 // If the pointer is in an existing tab frame, do a tab insert
3811 wxWindow
* hit_wnd
= ::wxFindWindowAtPoint(mouse_screen_pt
);
3812 wxTabFrame
* tab_frame
= (wxTabFrame
*)GetTabFrameFromTabCtrl(hit_wnd
);
3813 int insert_idx
= -1;
3816 dest_tabs
= tab_frame
->m_tabs
;
3818 if (dest_tabs
== src_tabs
)
3822 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
3823 wxWindow
* target
= NULL
;
3824 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
3827 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
3833 wxRect rect
= m_mgr
.CalculateHintRect(m_dummy_wnd
,
3838 // there is no suitable drop location here, exit out
3842 // If there is no tabframe at all, create one
3843 wxTabFrame
* new_tabs
= new wxTabFrame
;
3844 new_tabs
->m_rect
= wxRect(wxPoint(0,0), CalculateNewSplitSize());
3845 new_tabs
->SetTabCtrlHeight(m_tab_ctrl_height
);
3846 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
3850 wxNO_BORDER
|wxWANTS_CHARS
);
3851 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3852 new_tabs
->m_tabs
->SetFlags(m_flags
);
3854 m_mgr
.AddPane(new_tabs
,
3855 wxAuiPaneInfo().Bottom().CaptionVisible(false),
3858 dest_tabs
= new_tabs
->m_tabs
;
3863 // remove the page from the source tabs
3864 wxAuiNotebookPage page_info
= src_tabs
->GetPage(evt
.GetSelection());
3865 page_info
.active
= false;
3866 src_tabs
->RemovePage(page_info
.window
);
3867 if (src_tabs
->GetPageCount() > 0)
3869 src_tabs
->SetActivePage((size_t)0);
3870 src_tabs
->DoShowHide();
3871 src_tabs
->Refresh();
3876 // add the page to the destination tabs
3877 if (insert_idx
== -1)
3878 insert_idx
= dest_tabs
->GetPageCount();
3879 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
3881 if (src_tabs
->GetPageCount() == 0)
3883 RemoveEmptyTabFrames();
3887 dest_tabs
->DoShowHide();
3888 dest_tabs
->Refresh();
3890 // force the set selection function reset the selection
3893 // set the active page to the one we just split off
3894 SetSelectionToPage(page_info
);
3896 UpdateHintWindowSize();
3902 wxAuiTabCtrl
* wxAuiNotebook
::GetTabCtrlFromPoint(const wxPoint
& pt
)
3904 // if we've just removed the last tab from the source
3905 // tab set, the remove the tab control completely
3906 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3907 size_t i
, pane_count
= all_panes
.GetCount();
3908 for (i
= 0; i
< pane_count
; ++i
)
3910 if (all_panes
.Item(i
).name
== wxT("dummy"))
3913 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3914 if (tabframe
->m_tab_rect
.Contains(pt
))
3915 return tabframe
->m_tabs
;
3921 wxWindow
* wxAuiNotebook
::GetTabFrameFromTabCtrl(wxWindow
* tab_ctrl
)
3923 // if we've just removed the last tab from the source
3924 // tab set, the remove the tab control completely
3925 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3926 size_t i
, pane_count
= all_panes
.GetCount();
3927 for (i
= 0; i
< pane_count
; ++i
)
3929 if (all_panes
.Item(i
).name
== wxT("dummy"))
3932 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3933 if (tabframe
->m_tabs
== tab_ctrl
)
3942 void wxAuiNotebook
::RemoveEmptyTabFrames()
3944 // if we've just removed the last tab from the source
3945 // tab set, the remove the tab control completely
3946 wxAuiPaneInfoArray all_panes
= m_mgr
.GetAllPanes();
3947 size_t i
, pane_count
= all_panes
.GetCount();
3948 for (i
= 0; i
< pane_count
; ++i
)
3950 if (all_panes
.Item(i
).name
== wxT("dummy"))
3953 wxTabFrame
* tab_frame
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3954 if (tab_frame
->m_tabs
->GetPageCount() == 0)
3956 m_mgr
.DetachPane(tab_frame
);
3958 // use pending delete because sometimes during
3959 // window closing, refreshs are pending
3960 if (!wxPendingDelete
.Member(tab_frame
->m_tabs
))
3961 wxPendingDelete
.Append(tab_frame
->m_tabs
);
3963 tab_frame
->m_tabs
= NULL
;
3970 // check to see if there is still a center pane;
3971 // if there isn't, make a frame the center pane
3972 wxAuiPaneInfoArray panes
= m_mgr
.GetAllPanes();
3973 pane_count
= panes
.GetCount();
3974 wxWindow
* first_good
= NULL
;
3975 bool center_found
= false;
3976 for (i
= 0; i
< pane_count
; ++i
)
3978 if (panes
.Item(i
).name
== wxT("dummy"))
3980 if (panes
.Item(i
).dock_direction
== wxAUI_DOCK_CENTRE
)
3981 center_found
= true;
3983 first_good
= panes
.Item(i
).window
;
3986 if (!center_found
&& first_good
)
3988 m_mgr
.GetPane(first_good
).Centre();
3994 void wxAuiNotebook
::OnChildFocus(wxChildFocusEvent
& evt
)
3996 // if we're dragging a tab, don't change the current selection.
3997 // This code prevents a bug that used to happen when the hint window
3998 // was hidden. In the bug, the focus would return to the notebook
3999 // child, which would then enter this handler and call
4000 // SetSelection, which is not desired turn tab dragging.
4002 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
4003 size_t i
, pane_count
= all_panes
.GetCount();
4004 for (i
= 0; i
< pane_count
; ++i
)
4006 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
4007 if (pane
.name
== wxT("dummy"))
4009 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
4010 if (tabframe
->m_tabs
->IsDragging())
4015 // change the tab selection to the child
4016 // which was focused
4017 int idx
= m_tabs
.GetIdxFromWindow(evt
.GetWindow());
4018 if (idx
!= -1 && idx
!= m_curpage
)
4024 void wxAuiNotebook
::OnNavigationKey(wxNavigationKeyEvent
& event
)
4026 if ( event
.IsWindowChange() ) {
4028 // FIXME: the problem with this is that if we have a split notebook,
4029 // we selection may go all over the place.
4030 AdvanceSelection(event
.GetDirection());
4033 // we get this event in 3 cases
4035 // a) one of our pages might have generated it because the user TABbed
4036 // out from it in which case we should propagate the event upwards and
4037 // our parent will take care of setting the focus to prev/next sibling
4041 // b) the parent panel wants to give the focus to us so that we
4042 // forward it to our selected page. We can't deal with this in
4043 // OnSetFocus() because we don't know which direction the focus came
4044 // from in this case and so can't choose between setting the focus to
4045 // first or last panel child
4049 // c) we ourselves (see MSWTranslateMessage) generated the event
4051 wxWindow
* const parent
= GetParent();
4053 // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE
4054 const bool isFromParent
= event
.GetEventObject() == (wxObject
*) parent
;
4055 const bool isFromSelf
= event
.GetEventObject() == (wxObject
*) this;
4057 if ( isFromParent
|| isFromSelf
)
4059 // no, it doesn't come from child, case (b) or (c): forward to a
4060 // page but only if direction is backwards (TAB) or from ourselves,
4061 if ( GetSelection() != wxNOT_FOUND
&&
4062 (!event
.GetDirection() || isFromSelf
) )
4064 // so that the page knows that the event comes from it's parent
4065 // and is being propagated downwards
4066 event
.SetEventObject(this);
4068 wxWindow
*page
= GetPage(GetSelection());
4069 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
4073 //else: page manages focus inside it itself
4075 else // otherwise set the focus to the notebook itself
4082 // it comes from our child, case (a), pass to the parent, but only
4083 // if the direction is forwards. Otherwise set the focus to the
4084 // notebook itself. The notebook is always the 'first' control of a
4086 if ( !event
.GetDirection() )
4092 event
.SetCurrentFocus(this);
4093 parent
->GetEventHandler()->ProcessEvent(event
);
4099 void wxAuiNotebook
::OnTabButton(wxCommandEvent
& command_evt
)
4101 wxAuiNotebookEvent
& evt
= (wxAuiNotebookEvent
&)command_evt
;
4102 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4104 int button_id
= evt
.GetInt();
4106 if (button_id
== wxAUI_BUTTON_CLOSE
)
4108 int selection
= evt
.GetSelection();
4110 if (selection
== -1)
4112 // if the close button is to the right, use the active
4113 // page selection to determine which page to close
4114 selection
= GetSelection();
4117 if (selection
!= -1)
4119 wxWindow
* close_wnd
= tabs
->GetWindowFromIdx(selection
);
4121 // ask owner if it's ok to close the tab
4122 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
, m_windowId
);
4123 e
.SetSelection(m_tabs
.GetIdxFromWindow(close_wnd
));
4124 e
.SetOldSelection(evt
.GetSelection());
4125 e
.SetEventObject(this);
4126 GetEventHandler()->ProcessEvent(e
);
4131 if (close_wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
4137 int main_idx
= m_tabs
.GetIdxFromWindow(close_wnd
);
4138 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, _T("no page to delete?") );
4140 DeletePage(main_idx
);
4147 void wxAuiNotebook
::OnTabMiddleDown(wxCommandEvent
& evt
)
4149 // patch event through to owner
4150 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4151 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4153 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, m_windowId
);
4154 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4155 e
.SetEventObject(this);
4156 GetEventHandler()->ProcessEvent(e
);
4159 void wxAuiNotebook
::OnTabMiddleUp(wxCommandEvent
& evt
)
4161 // if the wxAUI_NB_MIDDLE_CLICK_CLOSE is specified, middle
4162 // click should act like a tab close action. However, first
4163 // give the owner an opportunity to handle the middle up event
4164 // for custom action
4166 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4167 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4169 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, m_windowId
);
4170 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4171 e
.SetEventObject(this);
4172 if (GetEventHandler()->ProcessEvent(e
))
4177 // check if we are supposed to close on middle-up
4178 if ((m_flags
& wxAUI_NB_MIDDLE_CLICK_CLOSE
) == 0)
4181 // simulate the user pressing the close button on the tab
4182 evt
.SetInt(wxAUI_BUTTON_CLOSE
);
4186 void wxAuiNotebook
::OnTabRightDown(wxCommandEvent
& evt
)
4188 // patch event through to owner
4189 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4190 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4192 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, m_windowId
);
4193 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4194 e
.SetEventObject(this);
4195 GetEventHandler()->ProcessEvent(e
);
4198 void wxAuiNotebook
::OnTabRightUp(wxCommandEvent
& evt
)
4200 // patch event through to owner
4201 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4202 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4204 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, m_windowId
);
4205 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4206 e
.SetEventObject(this);
4207 GetEventHandler()->ProcessEvent(e
);
4210 // Sets the normal font
4211 void wxAuiNotebook
::SetNormalFont(const wxFont
& font
)
4213 m_normal_font
= font
;
4214 GetArtProvider()->SetNormalFont(font
);
4217 // Sets the selected tab font
4218 void wxAuiNotebook
::SetSelectedFont(const wxFont
& font
)
4220 m_selected_font
= font
;
4221 GetArtProvider()->SetSelectedFont(font
);
4224 // Sets the measuring font
4225 void wxAuiNotebook
::SetMeasuringFont(const wxFont
& font
)
4227 GetArtProvider()->SetMeasuringFont(font
);
4230 // Sets the tab font
4231 bool wxAuiNotebook
::SetFont(const wxFont
& font
)
4233 wxControl
::SetFont(font
);
4235 wxFont
normalFont(font
);
4236 wxFont
selectedFont(normalFont
);
4237 selectedFont
.SetWeight(wxBOLD
);
4239 SetNormalFont(normalFont
);
4240 SetSelectedFont(selectedFont
);
4241 SetMeasuringFont(selectedFont
);
4246 // Gets the tab control height
4247 int wxAuiNotebook
::GetTabCtrlHeight() const
4249 return m_tab_ctrl_height
;
4252 // Gets the height of the notebook for a given page height
4253 int wxAuiNotebook
::GetHeightForPageHeight(int pageHeight
)
4255 UpdateTabCtrlHeight();
4257 int tabCtrlHeight
= GetTabCtrlHeight();
4258 int decorHeight
= 2;
4259 return tabCtrlHeight
+ pageHeight
+ decorHeight
;
4262 // Advances the selection, generation page selection events
4263 void wxAuiNotebook
::AdvanceSelection(bool forward
)
4265 if (GetPageCount() <= 1)
4268 int currentSelection
= GetSelection();
4272 if (currentSelection
== (int) (GetPageCount() - 1))
4274 else if (currentSelection
== -1)
4275 currentSelection
= 0;
4277 currentSelection
++;
4281 if (currentSelection
<= 0)
4284 currentSelection
--;
4287 SetSelection(currentSelection
);
4290 // Shows the window menu
4291 bool wxAuiNotebook
::ShowWindowMenu()
4293 wxAuiTabCtrl
* tabCtrl
= GetActiveTabCtrl();
4295 int idx
= tabCtrl
->GetArtProvider()->ShowDropDown(tabCtrl
, tabCtrl
->GetPages(), tabCtrl
->GetActivePage());
4299 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, tabCtrl
->GetId());
4300 e
.SetSelection(idx
);
4301 e
.SetOldSelection(tabCtrl
->GetActivePage());
4302 e
.SetEventObject(tabCtrl
);
4303 GetEventHandler()->ProcessEvent(e
);