1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/auibook.cpp
3 // Purpose: wxaui: wx advanced user interface - notebook
4 // Author: Benjamin I. Williams
7 // Copyright: (C) Copyright 2006, Kirix Corporation, All Rights Reserved
8 // Licence: wxWindows Library Licence, Version 3.1
9 ///////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
15 #include "wx/wxprec.h"
23 #include "wx/aui/auibook.h"
26 #include "wx/settings.h"
31 #include "wx/aui/tabmdi.h"
32 #include "wx/dcbuffer.h"
34 #include "wx/renderer.h"
37 #include "wx/osx/private.h"
40 #include "wx/arrimpl.cpp"
41 WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray
)
42 WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray
)
44 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
, wxAuiNotebookEvent
);
45 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED
, wxAuiNotebookEvent
);
46 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, wxAuiNotebookEvent
);
47 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
, wxAuiNotebookEvent
);
48 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
, wxAuiNotebookEvent
);
49 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
, wxAuiNotebookEvent
);
50 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
, wxAuiNotebookEvent
);
51 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG
, wxAuiNotebookEvent
);
52 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
, wxAuiNotebookEvent
);
53 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
, wxAuiNotebookEvent
);
54 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, wxAuiNotebookEvent
);
55 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, wxAuiNotebookEvent
);
56 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, wxAuiNotebookEvent
);
57 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, wxAuiNotebookEvent
);
58 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, wxAuiNotebookEvent
);
59 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, wxAuiNotebookEvent
);
61 IMPLEMENT_CLASS(wxAuiNotebook
, wxControl
)
62 IMPLEMENT_CLASS(wxAuiTabCtrl
, wxControl
)
63 IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent
, wxBookCtrlEvent
)
69 // these functions live in dockart.cpp -- they'll eventually
70 // be moved to a new utility cpp file
72 wxBitmap
wxAuiBitmapFromBits(const unsigned char bits
[], int w
, int h
,
73 const wxColour
& color
);
75 wxString
wxAuiChopText(wxDC
& dc
, const wxString
& text
, int max_size
);
77 static void DrawButtons(wxDC
& dc
,
80 const wxColour
& bkcolour
,
85 if (button_state
== wxAUI_BUTTON_STATE_PRESSED
)
91 if (button_state
== wxAUI_BUTTON_STATE_HOVER
||
92 button_state
== wxAUI_BUTTON_STATE_PRESSED
)
94 dc
.SetBrush(wxBrush(bkcolour
.ChangeLightness(120)));
95 dc
.SetPen(wxPen(bkcolour
.ChangeLightness(75)));
97 // draw the background behind the button
98 dc
.DrawRectangle(rect
.x
, rect
.y
, 15, 15);
101 // draw the button itself
102 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
105 static void IndentPressedBitmap(wxRect
* rect
, int button_state
)
107 if (button_state
== wxAUI_BUTTON_STATE_PRESSED
)
116 // -- GUI helper classes and functions --
118 class wxAuiCommandCapture
: public wxEvtHandler
122 wxAuiCommandCapture() { m_lastId
= 0; }
123 int GetCommandId() const { return m_lastId
; }
125 bool ProcessEvent(wxEvent
& evt
)
127 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
129 m_lastId
= evt
.GetId();
133 if (GetNextHandler())
134 return GetNextHandler()->ProcessEvent(evt
);
146 #if defined( __WXMAC__ )
147 static const unsigned char close_bits
[]={
148 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0x03, 0xF8, 0x01, 0xF0, 0x19, 0xF3,
149 0xB8, 0xE3, 0xF0, 0xE1, 0xE0, 0xE0, 0xF0, 0xE1, 0xB8, 0xE3, 0x19, 0xF3,
150 0x01, 0xF0, 0x03, 0xF8, 0x0F, 0xFE, 0xFF, 0xFF };
151 #elif defined( __WXGTK__)
152 static const unsigned char close_bits
[]={
153 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xfb, 0xef, 0xdb, 0xed, 0x8b, 0xe8,
154 0x1b, 0xec, 0x3b, 0xee, 0x1b, 0xec, 0x8b, 0xe8, 0xdb, 0xed, 0xfb, 0xef,
155 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
157 static const unsigned char close_bits
[]={
158 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xf3, 0xcf, 0xf9,
159 0x9f, 0xfc, 0x3f, 0xfe, 0x3f, 0xfe, 0x9f, 0xfc, 0xcf, 0xf9, 0xe7, 0xf3,
160 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
163 static const unsigned char left_bits
[] = {
164 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x3f, 0xfe,
165 0x1f, 0xfe, 0x0f, 0xfe, 0x1f, 0xfe, 0x3f, 0xfe, 0x7f, 0xfe, 0xff, 0xfe,
166 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
168 static const unsigned char right_bits
[] = {
169 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0x9f, 0xff, 0x1f, 0xff,
170 0x1f, 0xfe, 0x1f, 0xfc, 0x1f, 0xfe, 0x1f, 0xff, 0x9f, 0xff, 0xdf, 0xff,
171 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
173 static const unsigned char list_bits
[] = {
174 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
175 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff,
176 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
183 // -- wxAuiDefaultTabArt class implementation --
185 wxAuiDefaultTabArt::wxAuiDefaultTabArt()
187 m_normalFont
= *wxNORMAL_FONT
;
188 m_selectedFont
= *wxNORMAL_FONT
;
189 m_selectedFont
.SetWeight(wxBOLD
);
190 m_measuringFont
= m_selectedFont
;
192 m_fixedTabWidth
= 100;
195 #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
196 wxColor baseColour
= wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground
));
198 wxColor baseColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
201 // the baseColour is too pale to use as our base colour,
202 // so darken it a bit --
203 if ((255-baseColour
.Red()) +
204 (255-baseColour
.Green()) +
205 (255-baseColour
.Blue()) < 60)
207 baseColour
= baseColour
.ChangeLightness(92);
210 m_activeColour
= baseColour
;
211 m_baseColour
= baseColour
;
212 wxColor borderColour
= baseColour
.ChangeLightness(75);
214 m_borderPen
= wxPen(borderColour
);
215 m_baseColourPen
= wxPen(m_baseColour
);
216 m_baseColourBrush
= wxBrush(m_baseColour
);
218 m_activeCloseBmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, *wxBLACK
);
219 m_disabledCloseBmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, wxColour(128,128,128));
221 m_activeLeftBmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, *wxBLACK
);
222 m_disabledLeftBmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, wxColour(128,128,128));
224 m_activeRightBmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, *wxBLACK
);
225 m_disabledRightBmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, wxColour(128,128,128));
227 m_activeWindowListBmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, *wxBLACK
);
228 m_disabledWindowListBmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, wxColour(128,128,128));
233 wxAuiDefaultTabArt::~wxAuiDefaultTabArt()
237 wxAuiTabArt
* wxAuiDefaultTabArt::Clone()
239 return new wxAuiDefaultTabArt(*this);
242 void wxAuiDefaultTabArt::SetFlags(unsigned int flags
)
247 void wxAuiDefaultTabArt::SetSizingInfo(const wxSize
& tab_ctrl_size
,
250 m_fixedTabWidth
= 100;
252 int tot_width
= (int)tab_ctrl_size
.x
- GetIndentSize() - 4;
254 if (m_flags
& wxAUI_NB_CLOSE_BUTTON
)
255 tot_width
-= m_activeCloseBmp
.GetWidth();
256 if (m_flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
257 tot_width
-= m_activeWindowListBmp
.GetWidth();
261 m_fixedTabWidth
= tot_width
/(int)tab_count
;
265 if (m_fixedTabWidth
< 100)
266 m_fixedTabWidth
= 100;
268 if (m_fixedTabWidth
> tot_width
/2)
269 m_fixedTabWidth
= tot_width
/2;
271 if (m_fixedTabWidth
> 220)
272 m_fixedTabWidth
= 220;
274 m_tabCtrlHeight
= tab_ctrl_size
.y
;
278 void wxAuiDefaultTabArt::DrawBackground(wxDC
& dc
,
279 wxWindow
* WXUNUSED(wnd
),
284 wxColor top_color
= m_baseColour
.ChangeLightness(90);
285 wxColor bottom_color
= m_baseColour
.ChangeLightness(170);
288 if (m_flags
&wxAUI_NB_BOTTOM
)
289 r
= wxRect(rect
.x
, rect
.y
, rect
.width
+2, rect
.height
);
290 // TODO: else if (m_flags &wxAUI_NB_LEFT) {}
291 // TODO: else if (m_flags &wxAUI_NB_RIGHT) {}
292 else //for wxAUI_NB_TOP
293 r
= wxRect(rect
.x
, rect
.y
, rect
.width
+2, rect
.height
-3);
295 dc
.GradientFillLinear(r
, top_color
, bottom_color
, wxSOUTH
);
300 dc
.SetPen(m_borderPen
);
301 int y
= rect
.GetHeight();
302 int w
= rect
.GetWidth();
304 if (m_flags
&wxAUI_NB_BOTTOM
)
306 dc
.SetBrush(wxBrush(bottom_color
));
307 dc
.DrawRectangle(-1, 0, w
+2, 4);
309 // TODO: else if (m_flags &wxAUI_NB_LEFT) {}
310 // TODO: else if (m_flags &wxAUI_NB_RIGHT) {}
311 else //for wxAUI_NB_TOP
313 dc
.SetBrush(m_baseColourBrush
);
314 dc
.DrawRectangle(-1, y
-4, w
+2, 4);
319 // DrawTab() draws an individual tab.
322 // in_rect - rectangle the tab should be confined to
323 // caption - tab's caption
324 // active - whether or not the tab is active
325 // out_rect - actual output rectangle
326 // x_extent - the advance x; where the next tab should start
328 void wxAuiDefaultTabArt::DrawTab(wxDC
& dc
,
330 const wxAuiNotebookPage
& page
,
331 const wxRect
& in_rect
,
332 int close_button_state
,
333 wxRect
* out_tab_rect
,
334 wxRect
* out_button_rect
,
337 wxCoord normal_textx
, normal_texty
;
338 wxCoord selected_textx
, selected_texty
;
341 // if the caption is empty, measure some temporary text
342 wxString caption
= page
.caption
;
346 dc
.SetFont(m_selectedFont
);
347 dc
.GetTextExtent(caption
, &selected_textx
, &selected_texty
);
349 dc
.SetFont(m_normalFont
);
350 dc
.GetTextExtent(caption
, &normal_textx
, &normal_texty
);
352 // figure out the size of the tab
353 wxSize tab_size
= GetTabSize(dc
,
361 wxCoord tab_height
= m_tabCtrlHeight
- 3;
362 wxCoord tab_width
= tab_size
.x
;
363 wxCoord tab_x
= in_rect
.x
;
364 wxCoord tab_y
= in_rect
.y
+ in_rect
.height
- tab_height
;
367 caption
= page
.caption
;
370 // select pen, brush and font for the tab to be drawn
374 dc
.SetFont(m_selectedFont
);
375 texty
= selected_texty
;
379 dc
.SetFont(m_normalFont
);
380 texty
= normal_texty
;
384 // create points that will make the tab outline
386 int clip_width
= tab_width
;
387 if (tab_x
+ clip_width
> in_rect
.x
+ in_rect
.width
)
388 clip_width
= (in_rect
.x
+ in_rect
.width
) - tab_x
;
391 wxPoint clip_points[6];
392 clip_points[0] = wxPoint(tab_x, tab_y+tab_height-3);
393 clip_points[1] = wxPoint(tab_x, tab_y+2);
394 clip_points[2] = wxPoint(tab_x+2, tab_y);
395 clip_points[3] = wxPoint(tab_x+clip_width-1, tab_y);
396 clip_points[4] = wxPoint(tab_x+clip_width+1, tab_y+2);
397 clip_points[5] = wxPoint(tab_x+clip_width+1, tab_y+tab_height-3);
399 // FIXME: these ports don't provide wxRegion ctor from array of points
400 #if !defined(__WXDFB__) && !defined(__WXCOCOA__)
401 // set the clipping region for the tab --
402 wxRegion clipping_region(WXSIZEOF(clip_points), clip_points);
403 dc.SetClippingRegion(clipping_region);
404 #endif // !wxDFB && !wxCocoa
406 // since the above code above doesn't play well with WXDFB or WXCOCOA,
407 // we'll just use a rectangle for the clipping region for now --
408 dc
.SetClippingRegion(tab_x
, tab_y
, clip_width
+1, tab_height
-3);
411 wxPoint border_points
[6];
412 if (m_flags
&wxAUI_NB_BOTTOM
)
414 border_points
[0] = wxPoint(tab_x
, tab_y
);
415 border_points
[1] = wxPoint(tab_x
, tab_y
+tab_height
-6);
416 border_points
[2] = wxPoint(tab_x
+2, tab_y
+tab_height
-4);
417 border_points
[3] = wxPoint(tab_x
+tab_width
-2, tab_y
+tab_height
-4);
418 border_points
[4] = wxPoint(tab_x
+tab_width
, tab_y
+tab_height
-6);
419 border_points
[5] = wxPoint(tab_x
+tab_width
, tab_y
);
421 else //if (m_flags & wxAUI_NB_TOP) {}
423 border_points
[0] = wxPoint(tab_x
, tab_y
+tab_height
-4);
424 border_points
[1] = wxPoint(tab_x
, tab_y
+2);
425 border_points
[2] = wxPoint(tab_x
+2, tab_y
);
426 border_points
[3] = wxPoint(tab_x
+tab_width
-2, tab_y
);
427 border_points
[4] = wxPoint(tab_x
+tab_width
, tab_y
+2);
428 border_points
[5] = wxPoint(tab_x
+tab_width
, tab_y
+tab_height
-4);
430 // TODO: else if (m_flags &wxAUI_NB_LEFT) {}
431 // TODO: else if (m_flags &wxAUI_NB_RIGHT) {}
433 int drawn_tab_yoff
= border_points
[1].y
;
434 int drawn_tab_height
= border_points
[0].y
- border_points
[1].y
;
441 // draw base background color
442 wxRect
r(tab_x
, tab_y
, tab_width
, tab_height
);
443 dc
.SetPen(wxPen(m_activeColour
));
444 dc
.SetBrush(wxBrush(m_activeColour
));
445 dc
.DrawRectangle(r
.x
+1, r
.y
+1, r
.width
-1, r
.height
-4);
447 // this white helps fill out the gradient at the top of the tab
448 dc
.SetPen(*wxWHITE_PEN
);
449 dc
.SetBrush(*wxWHITE_BRUSH
);
450 dc
.DrawRectangle(r
.x
+2, r
.y
+1, r
.width
-3, r
.height
-4);
452 // these two points help the rounded corners appear more antialiased
453 dc
.SetPen(wxPen(m_activeColour
));
454 dc
.DrawPoint(r
.x
+2, r
.y
+1);
455 dc
.DrawPoint(r
.x
+r
.width
-2, r
.y
+1);
457 // set rectangle down a bit for gradient drawing
458 r
.SetHeight(r
.GetHeight()/2);
464 // draw gradient background
465 wxColor top_color
= *wxWHITE
;
466 wxColor bottom_color
= m_activeColour
;
467 dc
.GradientFillLinear(r
, bottom_color
, top_color
, wxNORTH
);
473 wxRect
r(tab_x
, tab_y
+1, tab_width
, tab_height
-3);
475 // start the gradent up a bit and leave the inside border inset
476 // by a pixel for a 3D look. Only the top half of the inactive
477 // tab will have a slight gradient
484 // -- draw top gradient fill for glossy look
485 wxColor top_color
= m_baseColour
;
486 wxColor bottom_color
= top_color
.ChangeLightness(160);
487 dc
.GradientFillLinear(r
, bottom_color
, top_color
, wxNORTH
);
492 // -- draw bottom fill for glossy look
493 top_color
= m_baseColour
;
494 bottom_color
= m_baseColour
;
495 dc
.GradientFillLinear(r
, top_color
, bottom_color
, wxSOUTH
);
499 dc
.SetPen(m_borderPen
);
500 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
501 dc
.DrawPolygon(WXSIZEOF(border_points
), border_points
);
503 // there are two horizontal grey lines at the bottom of the tab control,
504 // this gets rid of the top one of those lines in the tab control
507 if (m_flags
&wxAUI_NB_BOTTOM
)
508 dc
.SetPen(wxPen(m_baseColour
.ChangeLightness(170)));
509 // TODO: else if (m_flags &wxAUI_NB_LEFT) {}
510 // TODO: else if (m_flags &wxAUI_NB_RIGHT) {}
511 else //for wxAUI_NB_TOP
512 dc
.SetPen(m_baseColourPen
);
513 dc
.DrawLine(border_points
[0].x
+1,
520 int text_offset
= tab_x
+ 8;
521 int close_button_width
= 0;
522 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
524 close_button_width
= m_activeCloseBmp
.GetWidth();
527 int bitmap_offset
= 0;
528 if (page
.bitmap
.IsOk())
530 bitmap_offset
= tab_x
+ 8;
533 dc
.DrawBitmap(page
.bitmap
,
535 drawn_tab_yoff
+ (drawn_tab_height
/2) - (page
.bitmap
.GetHeight()/2),
538 text_offset
= bitmap_offset
+ page
.bitmap
.GetWidth();
539 text_offset
+= 3; // bitmap padding
544 text_offset
= tab_x
+ 8;
548 wxString draw_text
= wxAuiChopText(dc
,
550 tab_width
- (text_offset
-tab_x
) - close_button_width
);
553 dc
.DrawText(draw_text
,
555 drawn_tab_yoff
+ (drawn_tab_height
)/2 - (texty
/2) - 1);
557 // draw focus rectangle
558 if (page
.active
&& (wnd
->FindFocus() == wnd
))
560 wxRect
focusRectText(text_offset
, (drawn_tab_yoff
+ (drawn_tab_height
)/2 - (texty
/2) - 1),
561 selected_textx
, selected_texty
);
564 wxRect focusRectBitmap
;
566 if (page
.bitmap
.IsOk())
567 focusRectBitmap
= wxRect(bitmap_offset
, drawn_tab_yoff
+ (drawn_tab_height
/2) - (page
.bitmap
.GetHeight()/2),
568 page
.bitmap
.GetWidth(), page
.bitmap
.GetHeight());
570 if (page
.bitmap
.IsOk() && draw_text
.IsEmpty())
571 focusRect
= focusRectBitmap
;
572 else if (!page
.bitmap
.IsOk() && !draw_text
.IsEmpty())
573 focusRect
= focusRectText
;
574 else if (page
.bitmap
.IsOk() && !draw_text
.IsEmpty())
575 focusRect
= focusRectText
.Union(focusRectBitmap
);
577 focusRect
.Inflate(2, 2);
579 wxRendererNative::Get().DrawFocusRect(wnd
, dc
, focusRect
, 0);
582 // draw close button if necessary
583 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
585 wxBitmap bmp
= m_disabledCloseBmp
;
587 if (close_button_state
== wxAUI_BUTTON_STATE_HOVER
||
588 close_button_state
== wxAUI_BUTTON_STATE_PRESSED
)
590 bmp
= m_activeCloseBmp
;
593 int offsetY
= tab_y
-1;
594 if (m_flags
& wxAUI_NB_BOTTOM
)
597 wxRect
rect(tab_x
+ tab_width
- close_button_width
- 1,
598 offsetY
+ (tab_height
/2) - (bmp
.GetHeight()/2),
602 IndentPressedBitmap(&rect
, close_button_state
);
603 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
605 *out_button_rect
= rect
;
608 *out_tab_rect
= wxRect(tab_x
, tab_y
, tab_width
, tab_height
);
610 dc
.DestroyClippingRegion();
613 int wxAuiDefaultTabArt::GetIndentSize()
618 wxSize
wxAuiDefaultTabArt::GetTabSize(wxDC
& dc
,
619 wxWindow
* WXUNUSED(wnd
),
620 const wxString
& caption
,
621 const wxBitmap
& bitmap
,
622 bool WXUNUSED(active
),
623 int close_button_state
,
626 wxCoord measured_textx
, measured_texty
, tmp
;
628 dc
.SetFont(m_measuringFont
);
629 dc
.GetTextExtent(caption
, &measured_textx
, &measured_texty
);
631 dc
.GetTextExtent(wxT("ABCDEFXj"), &tmp
, &measured_texty
);
633 // add padding around the text
634 wxCoord tab_width
= measured_textx
;
635 wxCoord tab_height
= measured_texty
;
637 // if the close button is showing, add space for it
638 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
639 tab_width
+= m_activeCloseBmp
.GetWidth() + 3;
641 // if there's a bitmap, add space for it
644 tab_width
+= bitmap
.GetWidth();
645 tab_width
+= 3; // right side bitmap padding
646 tab_height
= wxMax(tab_height
, bitmap
.GetHeight());
653 if (m_flags
& wxAUI_NB_TAB_FIXED_WIDTH
)
655 tab_width
= m_fixedTabWidth
;
658 *x_extent
= tab_width
;
660 return wxSize(tab_width
, tab_height
);
664 void wxAuiDefaultTabArt::DrawButton(wxDC
& dc
,
665 wxWindow
* WXUNUSED(wnd
),
666 const wxRect
& in_rect
,
677 case wxAUI_BUTTON_CLOSE
:
678 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
679 bmp
= m_disabledCloseBmp
;
681 bmp
= m_activeCloseBmp
;
683 case wxAUI_BUTTON_LEFT
:
684 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
685 bmp
= m_disabledLeftBmp
;
687 bmp
= m_activeLeftBmp
;
689 case wxAUI_BUTTON_RIGHT
:
690 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
691 bmp
= m_disabledRightBmp
;
693 bmp
= m_activeRightBmp
;
695 case wxAUI_BUTTON_WINDOWLIST
:
696 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
697 bmp
= m_disabledWindowListBmp
;
699 bmp
= m_activeWindowListBmp
;
709 if (orientation
== wxLEFT
)
711 rect
.SetX(in_rect
.x
);
712 rect
.SetY(((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2));
713 rect
.SetWidth(bmp
.GetWidth());
714 rect
.SetHeight(bmp
.GetHeight());
718 rect
= wxRect(in_rect
.x
+ in_rect
.width
- bmp
.GetWidth(),
719 ((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2),
720 bmp
.GetWidth(), bmp
.GetHeight());
723 IndentPressedBitmap(&rect
, button_state
);
724 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
729 int wxAuiDefaultTabArt::ShowDropDown(wxWindow
* wnd
,
730 const wxAuiNotebookPageArray
& pages
,
735 size_t i
, count
= pages
.GetCount();
736 for (i
= 0; i
< count
; ++i
)
738 const wxAuiNotebookPage
& page
= pages
.Item(i
);
739 wxString caption
= page
.caption
;
741 // if there is no caption, make it a space. This will prevent
742 // an assert in the menu code.
743 if (caption
.IsEmpty())
746 wxMenuItem
* item
= new wxMenuItem(NULL
, 1000+i
, caption
);
747 if (page
.bitmap
.IsOk())
748 item
->SetBitmap(page
.bitmap
);
749 menuPopup
.Append(item
);
752 // find out where to put the popup menu of window items
753 wxPoint pt
= ::wxGetMousePosition();
754 pt
= wnd
->ScreenToClient(pt
);
756 // find out the screen coordinate at the bottom of the tab ctrl
757 wxRect cli_rect
= wnd
->GetClientRect();
758 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
760 wxAuiCommandCapture
* cc
= new wxAuiCommandCapture
;
761 wnd
->PushEventHandler(cc
);
762 wnd
->PopupMenu(&menuPopup
, pt
);
763 int command
= cc
->GetCommandId();
764 wnd
->PopEventHandler(true);
772 int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow
* wnd
,
773 const wxAuiNotebookPageArray
& pages
,
774 const wxSize
& requiredBmp_size
)
777 dc
.SetFont(m_measuringFont
);
779 // sometimes a standard bitmap size needs to be enforced, especially
780 // if some tabs have bitmaps and others don't. This is important because
781 // it prevents the tab control from resizing when tabs are added.
783 if (requiredBmp_size
.IsFullySpecified())
785 measureBmp
.Create(requiredBmp_size
.x
,
791 size_t i
, page_count
= pages
.GetCount();
792 for (i
= 0; i
< page_count
; ++i
)
794 wxAuiNotebookPage
& page
= pages
.Item(i
);
797 if (measureBmp
.IsOk())
802 // we don't use the caption text because we don't
803 // want tab heights to be different in the case
804 // of a very short piece of text on one tab and a very
805 // tall piece of text on another tab
807 wxSize s
= GetTabSize(dc
,
812 wxAUI_BUTTON_STATE_HIDDEN
,
815 max_y
= wxMax(max_y
, s
.y
);
821 void wxAuiDefaultTabArt::SetNormalFont(const wxFont
& font
)
826 void wxAuiDefaultTabArt::SetSelectedFont(const wxFont
& font
)
828 m_selectedFont
= font
;
831 void wxAuiDefaultTabArt::SetMeasuringFont(const wxFont
& font
)
833 m_measuringFont
= font
;
836 void wxAuiDefaultTabArt::SetColour(const wxColour
& colour
)
838 m_baseColour
= colour
;
839 m_borderPen
= wxPen(m_baseColour
.ChangeLightness(75));
840 m_baseColourPen
= wxPen(m_baseColour
);
841 m_baseColourBrush
= wxBrush(m_baseColour
);
844 void wxAuiDefaultTabArt::SetActiveColour(const wxColour
& colour
)
846 m_activeColour
= colour
;
849 // -- wxAuiSimpleTabArt class implementation --
851 wxAuiSimpleTabArt::wxAuiSimpleTabArt()
853 m_normalFont
= *wxNORMAL_FONT
;
854 m_selectedFont
= *wxNORMAL_FONT
;
855 m_selectedFont
.SetWeight(wxBOLD
);
856 m_measuringFont
= m_selectedFont
;
859 m_fixedTabWidth
= 100;
861 wxColour baseColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
863 wxColour backgroundColour
= baseColour
;
864 wxColour normaltabColour
= baseColour
;
865 wxColour selectedtabColour
= *wxWHITE
;
867 m_bkBrush
= wxBrush(backgroundColour
);
868 m_normalBkBrush
= wxBrush(normaltabColour
);
869 m_normalBkPen
= wxPen(normaltabColour
);
870 m_selectedBkBrush
= wxBrush(selectedtabColour
);
871 m_selectedBkPen
= wxPen(selectedtabColour
);
873 m_activeCloseBmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, *wxBLACK
);
874 m_disabledCloseBmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, wxColour(128,128,128));
876 m_activeLeftBmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, *wxBLACK
);
877 m_disabledLeftBmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, wxColour(128,128,128));
879 m_activeRightBmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, *wxBLACK
);
880 m_disabledRightBmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, wxColour(128,128,128));
882 m_activeWindowListBmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, *wxBLACK
);
883 m_disabledWindowListBmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, wxColour(128,128,128));
887 wxAuiSimpleTabArt::~wxAuiSimpleTabArt()
891 wxAuiTabArt
* wxAuiSimpleTabArt::Clone()
893 return new wxAuiSimpleTabArt(*this);
896 void wxAuiSimpleTabArt::SetFlags(unsigned int flags
)
901 void wxAuiSimpleTabArt::SetSizingInfo(const wxSize
& tab_ctrl_size
,
904 m_fixedTabWidth
= 100;
906 int tot_width
= (int)tab_ctrl_size
.x
- GetIndentSize() - 4;
908 if (m_flags
& wxAUI_NB_CLOSE_BUTTON
)
909 tot_width
-= m_activeCloseBmp
.GetWidth();
910 if (m_flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
911 tot_width
-= m_activeWindowListBmp
.GetWidth();
915 m_fixedTabWidth
= tot_width
/(int)tab_count
;
919 if (m_fixedTabWidth
< 100)
920 m_fixedTabWidth
= 100;
922 if (m_fixedTabWidth
> tot_width
/2)
923 m_fixedTabWidth
= tot_width
/2;
925 if (m_fixedTabWidth
> 220)
926 m_fixedTabWidth
= 220;
929 void wxAuiSimpleTabArt::SetColour(const wxColour
& colour
)
931 m_bkBrush
= wxBrush(colour
);
932 m_normalBkBrush
= wxBrush(colour
);
933 m_normalBkPen
= wxPen(colour
);
936 void wxAuiSimpleTabArt::SetActiveColour(const wxColour
& colour
)
938 m_selectedBkBrush
= wxBrush(colour
);
939 m_selectedBkPen
= wxPen(colour
);
942 void wxAuiSimpleTabArt::DrawBackground(wxDC
& dc
,
943 wxWindow
* WXUNUSED(wnd
),
947 dc
.SetBrush(m_bkBrush
);
948 dc
.SetPen(*wxTRANSPARENT_PEN
);
949 dc
.DrawRectangle(-1, -1, rect
.GetWidth()+2, rect
.GetHeight()+2);
952 dc
.SetPen(*wxGREY_PEN
);
953 dc
.DrawLine(0, rect
.GetHeight()-1, rect
.GetWidth(), rect
.GetHeight()-1);
957 // DrawTab() draws an individual tab.
960 // in_rect - rectangle the tab should be confined to
961 // caption - tab's caption
962 // active - whether or not the tab is active
963 // out_rect - actual output rectangle
964 // x_extent - the advance x; where the next tab should start
966 void wxAuiSimpleTabArt::DrawTab(wxDC
& dc
,
968 const wxAuiNotebookPage
& page
,
969 const wxRect
& in_rect
,
970 int close_button_state
,
971 wxRect
* out_tab_rect
,
972 wxRect
* out_button_rect
,
975 wxCoord normal_textx
, normal_texty
;
976 wxCoord selected_textx
, selected_texty
;
977 wxCoord textx
, texty
;
979 // if the caption is empty, measure some temporary text
980 wxString caption
= page
.caption
;
984 dc
.SetFont(m_selectedFont
);
985 dc
.GetTextExtent(caption
, &selected_textx
, &selected_texty
);
987 dc
.SetFont(m_normalFont
);
988 dc
.GetTextExtent(caption
, &normal_textx
, &normal_texty
);
990 // figure out the size of the tab
991 wxSize tab_size
= GetTabSize(dc
,
999 wxCoord tab_height
= tab_size
.y
;
1000 wxCoord tab_width
= tab_size
.x
;
1001 wxCoord tab_x
= in_rect
.x
;
1002 wxCoord tab_y
= in_rect
.y
+ in_rect
.height
- tab_height
;
1004 caption
= page
.caption
;
1006 // select pen, brush and font for the tab to be drawn
1010 dc
.SetPen(m_selectedBkPen
);
1011 dc
.SetBrush(m_selectedBkBrush
);
1012 dc
.SetFont(m_selectedFont
);
1013 textx
= selected_textx
;
1014 texty
= selected_texty
;
1018 dc
.SetPen(m_normalBkPen
);
1019 dc
.SetBrush(m_normalBkBrush
);
1020 dc
.SetFont(m_normalFont
);
1021 textx
= normal_textx
;
1022 texty
= normal_texty
;
1029 points
[0].x
= tab_x
;
1030 points
[0].y
= tab_y
+ tab_height
- 1;
1031 points
[1].x
= tab_x
+ tab_height
- 3;
1032 points
[1].y
= tab_y
+ 2;
1033 points
[2].x
= tab_x
+ tab_height
+ 3;
1034 points
[2].y
= tab_y
;
1035 points
[3].x
= tab_x
+ tab_width
- 2;
1036 points
[3].y
= tab_y
;
1037 points
[4].x
= tab_x
+ tab_width
;
1038 points
[4].y
= tab_y
+ 2;
1039 points
[5].x
= tab_x
+ tab_width
;
1040 points
[5].y
= tab_y
+ tab_height
- 1;
1041 points
[6] = points
[0];
1043 dc
.SetClippingRegion(in_rect
);
1045 dc
.DrawPolygon(WXSIZEOF(points
) - 1, points
);
1047 dc
.SetPen(*wxGREY_PEN
);
1049 //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points);
1050 dc
.DrawLines(WXSIZEOF(points
), points
);
1055 int close_button_width
= 0;
1056 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1058 close_button_width
= m_activeCloseBmp
.GetWidth();
1059 text_offset
= tab_x
+ (tab_height
/2) + ((tab_width
-close_button_width
)/2) - (textx
/2);
1063 text_offset
= tab_x
+ (tab_height
/3) + (tab_width
/2) - (textx
/2);
1066 // set minimum text offset
1067 if (text_offset
< tab_x
+ tab_height
)
1068 text_offset
= tab_x
+ tab_height
;
1070 // chop text if necessary
1071 wxString draw_text
= wxAuiChopText(dc
,
1073 tab_width
- (text_offset
-tab_x
) - close_button_width
);
1076 dc
.DrawText(draw_text
,
1078 (tab_y
+ tab_height
)/2 - (texty
/2) + 1);
1081 // draw focus rectangle
1082 if (page
.active
&& (wnd
->FindFocus() == wnd
))
1084 wxRect
focusRect(text_offset
, ((tab_y
+ tab_height
)/2 - (texty
/2) + 1),
1085 selected_textx
, selected_texty
);
1087 focusRect
.Inflate(2, 2);
1089 wxRendererNative::Get().DrawFocusRect(wnd
, dc
, focusRect
, 0);
1092 // draw close button if necessary
1093 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1097 bmp
= m_activeCloseBmp
;
1099 bmp
= m_disabledCloseBmp
;
1101 wxRect
rect(tab_x
+ tab_width
- close_button_width
- 1,
1102 tab_y
+ (tab_height
/2) - (bmp
.GetHeight()/2) + 1,
1105 DrawButtons(dc
, rect
, bmp
, *wxWHITE
, close_button_state
);
1107 *out_button_rect
= rect
;
1111 *out_tab_rect
= wxRect(tab_x
, tab_y
, tab_width
, tab_height
);
1113 dc
.DestroyClippingRegion();
1116 int wxAuiSimpleTabArt::GetIndentSize()
1121 wxSize
wxAuiSimpleTabArt::GetTabSize(wxDC
& dc
,
1122 wxWindow
* WXUNUSED(wnd
),
1123 const wxString
& caption
,
1124 const wxBitmap
& WXUNUSED(bitmap
),
1125 bool WXUNUSED(active
),
1126 int close_button_state
,
1129 wxCoord measured_textx
, measured_texty
;
1131 dc
.SetFont(m_measuringFont
);
1132 dc
.GetTextExtent(caption
, &measured_textx
, &measured_texty
);
1134 wxCoord tab_height
= measured_texty
+ 4;
1135 wxCoord tab_width
= measured_textx
+ tab_height
+ 5;
1137 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1138 tab_width
+= m_activeCloseBmp
.GetWidth();
1140 if (m_flags
& wxAUI_NB_TAB_FIXED_WIDTH
)
1142 tab_width
= m_fixedTabWidth
;
1145 *x_extent
= tab_width
- (tab_height
/2) - 1;
1147 return wxSize(tab_width
, tab_height
);
1151 void wxAuiSimpleTabArt::DrawButton(wxDC
& dc
,
1152 wxWindow
* WXUNUSED(wnd
),
1153 const wxRect
& in_rect
,
1164 case wxAUI_BUTTON_CLOSE
:
1165 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1166 bmp
= m_disabledCloseBmp
;
1168 bmp
= m_activeCloseBmp
;
1170 case wxAUI_BUTTON_LEFT
:
1171 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1172 bmp
= m_disabledLeftBmp
;
1174 bmp
= m_activeLeftBmp
;
1176 case wxAUI_BUTTON_RIGHT
:
1177 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1178 bmp
= m_disabledRightBmp
;
1180 bmp
= m_activeRightBmp
;
1182 case wxAUI_BUTTON_WINDOWLIST
:
1183 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1184 bmp
= m_disabledWindowListBmp
;
1186 bmp
= m_activeWindowListBmp
;
1195 if (orientation
== wxLEFT
)
1197 rect
.SetX(in_rect
.x
);
1198 rect
.SetY(((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2));
1199 rect
.SetWidth(bmp
.GetWidth());
1200 rect
.SetHeight(bmp
.GetHeight());
1204 rect
= wxRect(in_rect
.x
+ in_rect
.width
- bmp
.GetWidth(),
1205 ((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2),
1206 bmp
.GetWidth(), bmp
.GetHeight());
1210 DrawButtons(dc
, rect
, bmp
, *wxWHITE
, button_state
);
1215 int wxAuiSimpleTabArt::ShowDropDown(wxWindow
* wnd
,
1216 const wxAuiNotebookPageArray
& pages
,
1221 size_t i
, count
= pages
.GetCount();
1222 for (i
= 0; i
< count
; ++i
)
1224 const wxAuiNotebookPage
& page
= pages
.Item(i
);
1225 menuPopup
.AppendCheckItem(1000+i
, page
.caption
);
1228 if (active_idx
!= -1)
1230 menuPopup
.Check(1000+active_idx
, true);
1233 // find out where to put the popup menu of window
1234 // items. Subtract 100 for now to center the menu
1235 // a bit, until a better mechanism can be implemented
1236 wxPoint pt
= ::wxGetMousePosition();
1237 pt
= wnd
->ScreenToClient(pt
);
1243 // find out the screen coordinate at the bottom of the tab ctrl
1244 wxRect cli_rect
= wnd
->GetClientRect();
1245 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
1247 wxAuiCommandCapture
* cc
= new wxAuiCommandCapture
;
1248 wnd
->PushEventHandler(cc
);
1249 wnd
->PopupMenu(&menuPopup
, pt
);
1250 int command
= cc
->GetCommandId();
1251 wnd
->PopEventHandler(true);
1253 if (command
>= 1000)
1254 return command
-1000;
1259 int wxAuiSimpleTabArt::GetBestTabCtrlSize(wxWindow
* wnd
,
1260 const wxAuiNotebookPageArray
& WXUNUSED(pages
),
1261 const wxSize
& WXUNUSED(requiredBmp_size
))
1264 dc
.SetFont(m_measuringFont
);
1266 wxSize s
= GetTabSize(dc
,
1271 wxAUI_BUTTON_STATE_HIDDEN
,
1276 void wxAuiSimpleTabArt::SetNormalFont(const wxFont
& font
)
1278 m_normalFont
= font
;
1281 void wxAuiSimpleTabArt::SetSelectedFont(const wxFont
& font
)
1283 m_selectedFont
= font
;
1286 void wxAuiSimpleTabArt::SetMeasuringFont(const wxFont
& font
)
1288 m_measuringFont
= font
;
1294 // -- wxAuiTabContainer class implementation --
1297 // wxAuiTabContainer is a class which contains information about each
1298 // tab. It also can render an entire tab control to a specified DC.
1299 // It's not a window class itself, because this code will be used by
1300 // the wxFrameMananger, where it is disadvantageous to have separate
1301 // windows for each tab control in the case of "docked tabs"
1303 // A derived class, wxAuiTabCtrl, is an actual wxWindow-derived window
1304 // which can be used as a tab control in the normal sense.
1307 wxAuiTabContainer::wxAuiTabContainer()
1311 m_art
= new wxAuiDefaultTabArt
;
1313 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
1314 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
1315 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
1316 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
1319 wxAuiTabContainer::~wxAuiTabContainer()
1324 void wxAuiTabContainer::SetArtProvider(wxAuiTabArt
* art
)
1331 m_art
->SetFlags(m_flags
);
1335 wxAuiTabArt
* wxAuiTabContainer::GetArtProvider() const
1340 void wxAuiTabContainer::SetFlags(unsigned int flags
)
1344 // check for new close button settings
1345 RemoveButton(wxAUI_BUTTON_LEFT
);
1346 RemoveButton(wxAUI_BUTTON_RIGHT
);
1347 RemoveButton(wxAUI_BUTTON_WINDOWLIST
);
1348 RemoveButton(wxAUI_BUTTON_CLOSE
);
1351 if (flags
& wxAUI_NB_SCROLL_BUTTONS
)
1353 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
1354 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
1357 if (flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
1359 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
1362 if (flags
& wxAUI_NB_CLOSE_BUTTON
)
1364 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
1369 m_art
->SetFlags(m_flags
);
1373 unsigned int wxAuiTabContainer::GetFlags() const
1379 void wxAuiTabContainer::SetNormalFont(const wxFont
& font
)
1381 m_art
->SetNormalFont(font
);
1384 void wxAuiTabContainer::SetSelectedFont(const wxFont
& font
)
1386 m_art
->SetSelectedFont(font
);
1389 void wxAuiTabContainer::SetMeasuringFont(const wxFont
& font
)
1391 m_art
->SetMeasuringFont(font
);
1394 void wxAuiTabContainer::SetColour(const wxColour
& colour
)
1396 m_art
->SetColour(colour
);
1399 void wxAuiTabContainer::SetActiveColour(const wxColour
& colour
)
1401 m_art
->SetActiveColour(colour
);
1404 void wxAuiTabContainer::SetRect(const wxRect
& rect
)
1410 m_art
->SetSizingInfo(rect
.GetSize(), m_pages
.GetCount());
1414 bool wxAuiTabContainer::AddPage(wxWindow
* page
,
1415 const wxAuiNotebookPage
& info
)
1417 wxAuiNotebookPage page_info
;
1419 page_info
.window
= page
;
1421 m_pages
.Add(page_info
);
1423 // let the art provider know how many pages we have
1426 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1432 bool wxAuiTabContainer::InsertPage(wxWindow
* page
,
1433 const wxAuiNotebookPage
& info
,
1436 wxAuiNotebookPage page_info
;
1438 page_info
.window
= page
;
1440 if (idx
>= m_pages
.GetCount())
1441 m_pages
.Add(page_info
);
1443 m_pages
.Insert(page_info
, idx
);
1445 // let the art provider know how many pages we have
1448 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1454 bool wxAuiTabContainer::MovePage(wxWindow
* page
,
1457 int idx
= GetIdxFromWindow(page
);
1461 // get page entry, make a copy of it
1462 wxAuiNotebookPage p
= GetPage(idx
);
1464 // remove old page entry
1467 // insert page where it should be
1468 InsertPage(page
, p
, new_idx
);
1473 bool wxAuiTabContainer::RemovePage(wxWindow
* wnd
)
1475 size_t i
, page_count
= m_pages
.GetCount();
1476 for (i
= 0; i
< page_count
; ++i
)
1478 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1479 if (page
.window
== wnd
)
1481 m_pages
.RemoveAt(i
);
1483 // let the art provider know how many pages we have
1486 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1496 bool wxAuiTabContainer::SetActivePage(wxWindow
* wnd
)
1500 size_t i
, page_count
= m_pages
.GetCount();
1501 for (i
= 0; i
< page_count
; ++i
)
1503 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1504 if (page
.window
== wnd
)
1511 page
.active
= false;
1518 void wxAuiTabContainer::SetNoneActive()
1520 size_t i
, page_count
= m_pages
.GetCount();
1521 for (i
= 0; i
< page_count
; ++i
)
1523 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1524 page
.active
= false;
1528 bool wxAuiTabContainer::SetActivePage(size_t page
)
1530 if (page
>= m_pages
.GetCount())
1533 return SetActivePage(m_pages
.Item(page
).window
);
1536 int wxAuiTabContainer::GetActivePage() const
1538 size_t i
, page_count
= m_pages
.GetCount();
1539 for (i
= 0; i
< page_count
; ++i
)
1541 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1549 wxWindow
* wxAuiTabContainer::GetWindowFromIdx(size_t idx
) const
1551 if (idx
>= m_pages
.GetCount())
1554 return m_pages
[idx
].window
;
1557 int wxAuiTabContainer::GetIdxFromWindow(wxWindow
* wnd
) const
1559 const size_t page_count
= m_pages
.GetCount();
1560 for ( size_t i
= 0; i
< page_count
; ++i
)
1562 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1563 if (page
.window
== wnd
)
1569 wxAuiNotebookPage
& wxAuiTabContainer::GetPage(size_t idx
)
1571 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
1573 return m_pages
[idx
];
1576 const wxAuiNotebookPage
& wxAuiTabContainer::GetPage(size_t idx
) const
1578 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
1580 return m_pages
[idx
];
1583 wxAuiNotebookPageArray
& wxAuiTabContainer::GetPages()
1588 size_t wxAuiTabContainer::GetPageCount() const
1590 return m_pages
.GetCount();
1593 void wxAuiTabContainer::AddButton(int id
,
1595 const wxBitmap
& normalBitmap
,
1596 const wxBitmap
& disabledBitmap
)
1598 wxAuiTabContainerButton button
;
1600 button
.bitmap
= normalBitmap
;
1601 button
.disBitmap
= disabledBitmap
;
1602 button
.location
= location
;
1603 button
.curState
= wxAUI_BUTTON_STATE_NORMAL
;
1605 m_buttons
.Add(button
);
1608 void wxAuiTabContainer::RemoveButton(int id
)
1610 size_t i
, button_count
= m_buttons
.GetCount();
1612 for (i
= 0; i
< button_count
; ++i
)
1614 if (m_buttons
.Item(i
).id
== id
)
1616 m_buttons
.RemoveAt(i
);
1624 size_t wxAuiTabContainer::GetTabOffset() const
1629 void wxAuiTabContainer::SetTabOffset(size_t offset
)
1631 m_tabOffset
= offset
;
1637 // Render() renders the tab catalog to the specified DC
1638 // It is a virtual function and can be overridden to
1639 // provide custom drawing capabilities
1640 void wxAuiTabContainer::Render(wxDC
* raw_dc
, wxWindow
* wnd
)
1642 if (!raw_dc
|| !raw_dc
->IsOk())
1647 // use the same layout direction as the window DC uses to ensure that the
1648 // text is rendered correctly
1649 dc
.SetLayoutDirection(raw_dc
->GetLayoutDirection());
1653 size_t page_count
= m_pages
.GetCount();
1654 size_t button_count
= m_buttons
.GetCount();
1656 // create off-screen bitmap
1657 bmp
.Create(m_rect
.GetWidth(), m_rect
.GetHeight());
1658 dc
.SelectObject(bmp
);
1663 // find out if size of tabs is larger than can be
1664 // afforded on screen
1665 int total_width
= 0;
1666 int visible_width
= 0;
1667 for (i
= 0; i
< page_count
; ++i
)
1669 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1671 // determine if a close button is on this tab
1672 bool close_button
= false;
1673 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1674 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1676 close_button
= true;
1681 wxSize size
= m_art
->GetTabSize(dc
,
1687 wxAUI_BUTTON_STATE_NORMAL
:
1688 wxAUI_BUTTON_STATE_HIDDEN
,
1691 if (i
+1 < page_count
)
1692 total_width
+= x_extent
;
1694 total_width
+= size
.x
;
1696 if (i
>= m_tabOffset
)
1698 if (i
+1 < page_count
)
1699 visible_width
+= x_extent
;
1701 visible_width
+= size
.x
;
1705 if (total_width
> m_rect
.GetWidth() || m_tabOffset
!= 0)
1707 // show left/right buttons
1708 for (i
= 0; i
< button_count
; ++i
)
1710 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1711 if (button
.id
== wxAUI_BUTTON_LEFT
||
1712 button
.id
== wxAUI_BUTTON_RIGHT
)
1714 button
.curState
&= ~wxAUI_BUTTON_STATE_HIDDEN
;
1720 // hide left/right buttons
1721 for (i
= 0; i
< button_count
; ++i
)
1723 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1724 if (button
.id
== wxAUI_BUTTON_LEFT
||
1725 button
.id
== wxAUI_BUTTON_RIGHT
)
1727 button
.curState
|= wxAUI_BUTTON_STATE_HIDDEN
;
1732 // determine whether left button should be enabled
1733 for (i
= 0; i
< button_count
; ++i
)
1735 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1736 if (button
.id
== wxAUI_BUTTON_LEFT
)
1738 if (m_tabOffset
== 0)
1739 button
.curState
|= wxAUI_BUTTON_STATE_DISABLED
;
1741 button
.curState
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1743 if (button
.id
== wxAUI_BUTTON_RIGHT
)
1745 if (visible_width
< m_rect
.GetWidth() - ((int)button_count
*16))
1746 button
.curState
|= wxAUI_BUTTON_STATE_DISABLED
;
1748 button
.curState
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1755 m_art
->DrawBackground(dc
, wnd
, m_rect
);
1758 int left_buttons_width
= 0;
1759 int right_buttons_width
= 0;
1763 // draw the buttons on the right side
1764 offset
= m_rect
.x
+ m_rect
.width
;
1765 for (i
= 0; i
< button_count
; ++i
)
1767 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1769 if (button
.location
!= wxRIGHT
)
1771 if (button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
)
1774 wxRect button_rect
= m_rect
;
1775 button_rect
.SetY(1);
1776 button_rect
.SetWidth(offset
);
1778 m_art
->DrawButton(dc
,
1786 offset
-= button
.rect
.GetWidth();
1787 right_buttons_width
+= button
.rect
.GetWidth();
1794 // draw the buttons on the left side
1796 for (i
= 0; i
< button_count
; ++i
)
1798 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1800 if (button
.location
!= wxLEFT
)
1802 if (button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
)
1805 wxRect
button_rect(offset
, 1, 1000, m_rect
.height
);
1807 m_art
->DrawButton(dc
,
1815 offset
+= button
.rect
.GetWidth();
1816 left_buttons_width
+= button
.rect
.GetWidth();
1819 offset
= left_buttons_width
;
1822 offset
+= m_art
->GetIndentSize();
1825 // prepare the tab-close-button array
1826 // make sure tab button entries which aren't used are marked as hidden
1827 for (i
= page_count
; i
< m_tabCloseButtons
.GetCount(); ++i
)
1828 m_tabCloseButtons
.Item(i
).curState
= wxAUI_BUTTON_STATE_HIDDEN
;
1830 // make sure there are enough tab button entries to accommodate all tabs
1831 while (m_tabCloseButtons
.GetCount() < page_count
)
1833 wxAuiTabContainerButton tempbtn
;
1834 tempbtn
.id
= wxAUI_BUTTON_CLOSE
;
1835 tempbtn
.location
= wxCENTER
;
1836 tempbtn
.curState
= wxAUI_BUTTON_STATE_HIDDEN
;
1837 m_tabCloseButtons
.Add(tempbtn
);
1841 // buttons before the tab offset must be set to hidden
1842 for (i
= 0; i
< m_tabOffset
; ++i
)
1844 m_tabCloseButtons
.Item(i
).curState
= wxAUI_BUTTON_STATE_HIDDEN
;
1850 size_t active
= 999;
1851 int active_offset
= 0;
1855 wxRect rect
= m_rect
;
1857 rect
.height
= m_rect
.height
;
1859 for (i
= m_tabOffset
; i
< page_count
; ++i
)
1861 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1862 wxAuiTabContainerButton
& tab_button
= m_tabCloseButtons
.Item(i
);
1864 // determine if a close button is on this tab
1865 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1866 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1868 if (tab_button
.curState
== wxAUI_BUTTON_STATE_HIDDEN
)
1870 tab_button
.id
= wxAUI_BUTTON_CLOSE
;
1871 tab_button
.curState
= wxAUI_BUTTON_STATE_NORMAL
;
1872 tab_button
.location
= wxCENTER
;
1877 tab_button
.curState
= wxAUI_BUTTON_STATE_HIDDEN
;
1881 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
1883 if (rect
.width
<= 0)
1890 tab_button
.curState
,
1898 active_offset
= offset
;
1906 // make sure to deactivate buttons which are off the screen to the right
1907 for (++i
; i
< m_tabCloseButtons
.GetCount(); ++i
)
1909 m_tabCloseButtons
.Item(i
).curState
= wxAUI_BUTTON_STATE_HIDDEN
;
1913 // draw the active tab again so it stands in the foreground
1914 if (active
>= m_tabOffset
&& active
< m_pages
.GetCount())
1916 wxAuiNotebookPage
& page
= m_pages
.Item(active
);
1918 wxAuiTabContainerButton
& tab_button
= m_tabCloseButtons
.Item(active
);
1920 rect
.x
= active_offset
;
1925 tab_button
.curState
,
1932 raw_dc
->Blit(m_rect
.x
, m_rect
.y
,
1933 m_rect
.GetWidth(), m_rect
.GetHeight(),
1937 // Is the tab visible?
1938 bool wxAuiTabContainer::IsTabVisible(int tabPage
, int tabOffset
, wxDC
* dc
, wxWindow
* wnd
)
1940 if (!dc
|| !dc
->IsOk())
1944 size_t page_count
= m_pages
.GetCount();
1945 size_t button_count
= m_buttons
.GetCount();
1947 // Hasn't been rendered yet; assume it's visible
1948 if (m_tabCloseButtons
.GetCount() < page_count
)
1951 // First check if both buttons are disabled - if so, there's no need to
1952 // check further for visibility.
1953 int arrowButtonVisibleCount
= 0;
1954 for (i
= 0; i
< button_count
; ++i
)
1956 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1957 if (button
.id
== wxAUI_BUTTON_LEFT
||
1958 button
.id
== wxAUI_BUTTON_RIGHT
)
1960 if ((button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
) == 0)
1961 arrowButtonVisibleCount
++;
1965 // Tab must be visible
1966 if (arrowButtonVisibleCount
== 0)
1969 // If tab is less than the given offset, it must be invisible by definition
1970 if (tabPage
< tabOffset
)
1974 int left_buttons_width
= 0;
1975 int right_buttons_width
= 0;
1979 // calculate size of the buttons on the right side
1980 offset
= m_rect
.x
+ m_rect
.width
;
1981 for (i
= 0; i
< button_count
; ++i
)
1983 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1985 if (button
.location
!= wxRIGHT
)
1987 if (button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
)
1990 offset
-= button
.rect
.GetWidth();
1991 right_buttons_width
+= button
.rect
.GetWidth();
1996 // calculate size of the buttons on the left side
1997 for (i
= 0; i
< button_count
; ++i
)
1999 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
2001 if (button
.location
!= wxLEFT
)
2003 if (button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
)
2006 offset
+= button
.rect
.GetWidth();
2007 left_buttons_width
+= button
.rect
.GetWidth();
2010 offset
= left_buttons_width
;
2013 offset
+= m_art
->GetIndentSize();
2017 wxRect rect
= m_rect
;
2019 rect
.height
= m_rect
.height
;
2021 // See if the given page is visible at the given tab offset (effectively scroll position)
2022 for (i
= tabOffset
; i
< page_count
; ++i
)
2024 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
2025 wxAuiTabContainerButton
& tab_button
= m_tabCloseButtons
.Item(i
);
2028 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
2030 if (rect
.width
<= 0)
2031 return false; // haven't found the tab, and we've run out of space, so return false
2034 m_art
->GetTabSize(*dc
,
2039 tab_button
.curState
,
2044 if (i
== (size_t) tabPage
)
2046 // If not all of the tab is visible, and supposing there's space to display it all,
2047 // we could do better so we return false.
2048 if (((m_rect
.width
- right_buttons_width
- offset
- 2) <= 0) && ((m_rect
.width
- right_buttons_width
- left_buttons_width
) > x_extent
))
2055 // Shouldn't really get here, but if it does, assume the tab is visible to prevent
2056 // further looping in calling code.
2060 // Make the tab visible if it wasn't already
2061 void wxAuiTabContainer::MakeTabVisible(int tabPage
, wxWindow
* win
)
2064 if (!IsTabVisible(tabPage
, GetTabOffset(), & dc
, win
))
2067 for (i
= 0; i
< (int) m_pages
.GetCount(); i
++)
2069 if (IsTabVisible(tabPage
, i
, & dc
, win
))
2079 // TabHitTest() tests if a tab was hit, passing the window pointer
2080 // back if that condition was fulfilled. The function returns
2081 // true if a tab was hit, otherwise false
2082 bool wxAuiTabContainer::TabHitTest(int x
, int y
, wxWindow
** hit
) const
2084 if (!m_rect
.Contains(x
,y
))
2087 wxAuiTabContainerButton
* btn
= NULL
;
2088 if (ButtonHitTest(x
, y
, &btn
) && !(btn
->curState
& wxAUI_BUTTON_STATE_DISABLED
))
2090 if (m_buttons
.Index(*btn
) != wxNOT_FOUND
)
2094 size_t i
, page_count
= m_pages
.GetCount();
2096 for (i
= m_tabOffset
; i
< page_count
; ++i
)
2098 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
2099 if (page
.rect
.Contains(x
,y
))
2110 // ButtonHitTest() tests if a button was hit. The function returns
2111 // true if a button was hit, otherwise false
2112 bool wxAuiTabContainer::ButtonHitTest(int x
, int y
,
2113 wxAuiTabContainerButton
** hit
) const
2115 if (!m_rect
.Contains(x
,y
))
2118 size_t i
, button_count
;
2121 button_count
= m_buttons
.GetCount();
2122 for (i
= 0; i
< button_count
; ++i
)
2124 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
2125 if (button
.rect
.Contains(x
,y
) &&
2126 !(button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
))
2134 button_count
= m_tabCloseButtons
.GetCount();
2135 for (i
= 0; i
< button_count
; ++i
)
2137 wxAuiTabContainerButton
& button
= m_tabCloseButtons
.Item(i
);
2138 if (button
.rect
.Contains(x
,y
) &&
2139 !(button
.curState
& (wxAUI_BUTTON_STATE_HIDDEN
|
2140 wxAUI_BUTTON_STATE_DISABLED
)))
2153 // the utility function ShowWnd() is the same as show,
2154 // except it handles wxAuiMDIChildFrame windows as well,
2155 // as the Show() method on this class is "unplugged"
2156 static void ShowWnd(wxWindow
* wnd
, bool show
)
2159 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
2161 wxAuiMDIChildFrame
* cf
= (wxAuiMDIChildFrame
*)wnd
;
2172 // DoShowHide() this function shows the active window, then
2173 // hides all of the other windows (in that order)
2174 void wxAuiTabContainer::DoShowHide()
2176 wxAuiNotebookPageArray
& pages
= GetPages();
2177 size_t i
, page_count
= pages
.GetCount();
2179 // show new active page first
2180 for (i
= 0; i
< page_count
; ++i
)
2182 wxAuiNotebookPage
& page
= pages
.Item(i
);
2185 ShowWnd(page
.window
, true);
2190 // hide all other pages
2191 for (i
= 0; i
< page_count
; ++i
)
2193 wxAuiNotebookPage
& page
= pages
.Item(i
);
2195 ShowWnd(page
.window
, false);
2204 // -- wxAuiTabCtrl class implementation --
2208 BEGIN_EVENT_TABLE(wxAuiTabCtrl
, wxControl
)
2209 EVT_PAINT(wxAuiTabCtrl::OnPaint
)
2210 EVT_ERASE_BACKGROUND(wxAuiTabCtrl::OnEraseBackground
)
2211 EVT_SIZE(wxAuiTabCtrl::OnSize
)
2212 EVT_LEFT_DOWN(wxAuiTabCtrl::OnLeftDown
)
2213 EVT_LEFT_DCLICK(wxAuiTabCtrl::OnLeftDClick
)
2214 EVT_LEFT_UP(wxAuiTabCtrl::OnLeftUp
)
2215 EVT_MIDDLE_DOWN(wxAuiTabCtrl::OnMiddleDown
)
2216 EVT_MIDDLE_UP(wxAuiTabCtrl::OnMiddleUp
)
2217 EVT_RIGHT_DOWN(wxAuiTabCtrl::OnRightDown
)
2218 EVT_RIGHT_UP(wxAuiTabCtrl::OnRightUp
)
2219 EVT_MOTION(wxAuiTabCtrl::OnMotion
)
2220 EVT_LEAVE_WINDOW(wxAuiTabCtrl::OnLeaveWindow
)
2221 EVT_AUINOTEBOOK_BUTTON(wxID_ANY
, wxAuiTabCtrl::OnButton
)
2222 EVT_SET_FOCUS(wxAuiTabCtrl::OnSetFocus
)
2223 EVT_KILL_FOCUS(wxAuiTabCtrl::OnKillFocus
)
2224 EVT_CHAR(wxAuiTabCtrl::OnChar
)
2225 EVT_MOUSE_CAPTURE_LOST(wxAuiTabCtrl::OnCaptureLost
)
2229 wxAuiTabCtrl::wxAuiTabCtrl(wxWindow
* parent
,
2233 long style
) : wxControl(parent
, id
, pos
, size
, style
)
2235 SetName(wxT("wxAuiTabCtrl"));
2236 m_clickPt
= wxDefaultPosition
;
2237 m_isDragging
= false;
2238 m_hoverButton
= NULL
;
2239 m_pressedButton
= NULL
;
2242 wxAuiTabCtrl::~wxAuiTabCtrl()
2246 void wxAuiTabCtrl::OnPaint(wxPaintEvent
&)
2250 dc
.SetFont(GetFont());
2252 if (GetPageCount() > 0)
2256 void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
2260 void wxAuiTabCtrl::OnSize(wxSizeEvent
& evt
)
2262 wxSize s
= evt
.GetSize();
2263 wxRect
r(0, 0, s
.GetWidth(), s
.GetHeight());
2267 void wxAuiTabCtrl::OnLeftDown(wxMouseEvent
& evt
)
2270 m_clickPt
= wxDefaultPosition
;
2271 m_isDragging
= false;
2273 m_pressedButton
= NULL
;
2277 if (TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2279 int new_selection
= GetIdxFromWindow(wnd
);
2281 // wxAuiNotebooks always want to receive this event
2282 // even if the tab is already active, because they may
2283 // have multiple tab controls
2284 if (new_selection
!= GetActivePage() ||
2285 GetParent()->IsKindOf(CLASSINFO(wxAuiNotebook
)))
2287 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2288 e
.SetSelection(new_selection
);
2289 e
.SetOldSelection(GetActivePage());
2290 e
.SetEventObject(this);
2291 GetEventHandler()->ProcessEvent(e
);
2294 m_clickPt
.x
= evt
.m_x
;
2295 m_clickPt
.y
= evt
.m_y
;
2301 m_pressedButton
= m_hoverButton
;
2302 m_pressedButton
->curState
= wxAUI_BUTTON_STATE_PRESSED
;
2304 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2310 void wxAuiTabCtrl::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
2314 m_isDragging
= false;
2316 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG
, m_windowId
);
2317 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
2318 evt
.SetOldSelection(evt
.GetSelection());
2319 evt
.SetEventObject(this);
2320 GetEventHandler()->ProcessEvent(evt
);
2324 void wxAuiTabCtrl::OnLeftUp(wxMouseEvent
& evt
)
2326 if (GetCapture() == this)
2331 m_isDragging
= false;
2333 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
, m_windowId
);
2334 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
2335 evt
.SetOldSelection(evt
.GetSelection());
2336 evt
.SetEventObject(this);
2337 GetEventHandler()->ProcessEvent(evt
);
2342 if (m_pressedButton
)
2344 // make sure we're still clicking the button
2345 wxAuiTabContainerButton
* button
= NULL
;
2346 if (!ButtonHitTest(evt
.m_x
, evt
.m_y
, &button
) ||
2347 button
->curState
& wxAUI_BUTTON_STATE_DISABLED
)
2350 if (button
!= m_pressedButton
)
2352 m_pressedButton
= NULL
;
2357 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2361 if (!(m_pressedButton
->curState
& wxAUI_BUTTON_STATE_DISABLED
))
2363 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
, m_windowId
);
2364 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
2365 evt
.SetInt(m_pressedButton
->id
);
2366 evt
.SetEventObject(this);
2367 GetEventHandler()->ProcessEvent(evt
);
2370 m_pressedButton
= NULL
;
2373 m_clickPt
= wxDefaultPosition
;
2374 m_isDragging
= false;
2378 void wxAuiTabCtrl::OnMiddleUp(wxMouseEvent
& evt
)
2380 wxWindow
* wnd
= NULL
;
2381 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2384 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, m_windowId
);
2385 e
.SetEventObject(this);
2386 e
.SetSelection(GetIdxFromWindow(wnd
));
2387 GetEventHandler()->ProcessEvent(e
);
2390 void wxAuiTabCtrl::OnMiddleDown(wxMouseEvent
& evt
)
2392 wxWindow
* wnd
= NULL
;
2393 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2396 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, m_windowId
);
2397 e
.SetEventObject(this);
2398 e
.SetSelection(GetIdxFromWindow(wnd
));
2399 GetEventHandler()->ProcessEvent(e
);
2402 void wxAuiTabCtrl::OnRightUp(wxMouseEvent
& evt
)
2404 wxWindow
* wnd
= NULL
;
2405 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2408 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, m_windowId
);
2409 e
.SetEventObject(this);
2410 e
.SetSelection(GetIdxFromWindow(wnd
));
2411 GetEventHandler()->ProcessEvent(e
);
2414 void wxAuiTabCtrl::OnRightDown(wxMouseEvent
& evt
)
2416 wxWindow
* wnd
= NULL
;
2417 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2420 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, m_windowId
);
2421 e
.SetEventObject(this);
2422 e
.SetSelection(GetIdxFromWindow(wnd
));
2423 GetEventHandler()->ProcessEvent(e
);
2426 void wxAuiTabCtrl::OnLeftDClick(wxMouseEvent
& evt
)
2429 wxAuiTabContainerButton
* button
;
2430 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
) && !ButtonHitTest(evt
.m_x
, evt
.m_y
, &button
))
2432 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, m_windowId
);
2433 e
.SetEventObject(this);
2434 GetEventHandler()->ProcessEvent(e
);
2438 void wxAuiTabCtrl::OnMotion(wxMouseEvent
& evt
)
2440 wxPoint pos
= evt
.GetPosition();
2442 // check if the mouse is hovering above a button
2443 wxAuiTabContainerButton
* button
;
2444 if (ButtonHitTest(pos
.x
, pos
.y
, &button
) && !(button
->curState
& wxAUI_BUTTON_STATE_DISABLED
))
2446 if (m_hoverButton
&& button
!= m_hoverButton
)
2448 m_hoverButton
->curState
= wxAUI_BUTTON_STATE_NORMAL
;
2449 m_hoverButton
= NULL
;
2451 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2456 if (button
->curState
!= wxAUI_BUTTON_STATE_HOVER
)
2458 button
->curState
= wxAUI_BUTTON_STATE_HOVER
;
2460 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2463 m_hoverButton
= button
;
2471 m_hoverButton
->curState
= wxAUI_BUTTON_STATE_NORMAL
;
2472 m_hoverButton
= NULL
;
2474 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2481 if (!evt
.LeftIsDown() || m_clickPt
== wxDefaultPosition
)
2486 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
, m_windowId
);
2487 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
2488 evt
.SetOldSelection(evt
.GetSelection());
2489 evt
.SetEventObject(this);
2490 GetEventHandler()->ProcessEvent(evt
);
2495 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
2496 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
2498 if (abs(pos
.x
- m_clickPt
.x
) > drag_x_threshold
||
2499 abs(pos
.y
- m_clickPt
.y
) > drag_y_threshold
)
2501 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
, m_windowId
);
2502 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
2503 evt
.SetOldSelection(evt
.GetSelection());
2504 evt
.SetEventObject(this);
2505 GetEventHandler()->ProcessEvent(evt
);
2507 m_isDragging
= true;
2511 void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
2515 m_hoverButton
->curState
= wxAUI_BUTTON_STATE_NORMAL
;
2516 m_hoverButton
= NULL
;
2518 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2524 void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent
& event
)
2526 int button
= event
.GetInt();
2528 if (button
== wxAUI_BUTTON_LEFT
|| button
== wxAUI_BUTTON_RIGHT
)
2530 if (button
== wxAUI_BUTTON_LEFT
)
2532 if (GetTabOffset() > 0)
2534 SetTabOffset(GetTabOffset()-1);
2536 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2543 SetTabOffset(GetTabOffset()+1);
2545 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2550 else if (button
== wxAUI_BUTTON_WINDOWLIST
)
2552 int idx
= GetArtProvider()->ShowDropDown(this, m_pages
, GetActivePage());
2556 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2557 e
.SetSelection(idx
);
2558 e
.SetOldSelection(GetActivePage());
2559 e
.SetEventObject(this);
2560 GetEventHandler()->ProcessEvent(e
);
2569 void wxAuiTabCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
2574 void wxAuiTabCtrl::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
2579 void wxAuiTabCtrl::OnChar(wxKeyEvent
& event
)
2581 if (GetActivePage() == -1)
2587 // We can't leave tab processing to the system; on Windows, tabs and keys
2588 // get eaten by the system and not processed properly if we specify both
2589 // wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL,
2590 // we don't key arrow key events.
2592 int key
= event
.GetKeyCode();
2594 if (key
== WXK_NUMPAD_PAGEUP
)
2596 if (key
== WXK_NUMPAD_PAGEDOWN
)
2598 if (key
== WXK_NUMPAD_HOME
)
2600 if (key
== WXK_NUMPAD_END
)
2602 if (key
== WXK_NUMPAD_LEFT
)
2604 if (key
== WXK_NUMPAD_RIGHT
)
2607 if (key
== WXK_TAB
|| key
== WXK_PAGEUP
|| key
== WXK_PAGEDOWN
)
2609 bool bCtrlDown
= event
.ControlDown();
2610 bool bShiftDown
= event
.ShiftDown();
2612 bool bForward
= (key
== WXK_TAB
&& !bShiftDown
) || (key
== WXK_PAGEDOWN
);
2613 bool bWindowChange
= (key
== WXK_PAGEUP
) || (key
== WXK_PAGEDOWN
) || bCtrlDown
;
2614 bool bFromTab
= (key
== WXK_TAB
);
2616 wxAuiNotebook
* nb
= wxDynamicCast(GetParent(), wxAuiNotebook
);
2623 wxNavigationKeyEvent keyEvent
;
2624 keyEvent
.SetDirection(bForward
);
2625 keyEvent
.SetWindowChange(bWindowChange
);
2626 keyEvent
.SetFromTab(bFromTab
);
2627 keyEvent
.SetEventObject(nb
);
2629 if (!nb
->GetEventHandler()->ProcessEvent(keyEvent
))
2631 // Not processed? Do an explicit tab into the page.
2632 wxWindow
* win
= GetWindowFromIdx(GetActivePage());
2639 if (m_pages
.GetCount() < 2)
2647 int forwardKey
, backwardKey
;
2648 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2650 forwardKey
= WXK_LEFT
;
2651 backwardKey
= WXK_RIGHT
;
2655 forwardKey
= WXK_RIGHT
;
2656 backwardKey
= WXK_LEFT
;
2659 if (key
== forwardKey
)
2661 if (m_pages
.GetCount() > 1)
2663 if (GetActivePage() == -1)
2665 else if (GetActivePage() < (int) (m_pages
.GetCount() - 1))
2666 newPage
= GetActivePage() + 1;
2669 else if (key
== backwardKey
)
2671 if (m_pages
.GetCount() > 1)
2673 if (GetActivePage() == -1)
2674 newPage
= (int) (m_pages
.GetCount() - 1);
2675 else if (GetActivePage() > 0)
2676 newPage
= GetActivePage() - 1;
2679 else if (key
== WXK_HOME
)
2683 else if (key
== WXK_END
)
2685 newPage
= (int) (m_pages
.GetCount() - 1);
2692 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2693 e
.SetSelection(newPage
);
2694 e
.SetOldSelection(newPage
);
2695 e
.SetEventObject(this);
2696 this->GetEventHandler()->ProcessEvent(e
);
2702 // wxTabFrame is an interesting case. It's important that all child pages
2703 // of the multi-notebook control are all actually children of that control
2704 // (and not grandchildren). wxTabFrame facilitates this. There is one
2705 // instance of wxTabFrame for each tab control inside the multi-notebook.
2706 // It's important to know that wxTabFrame is not a real window, but it merely
2707 // used to capture the dimensions/positioning of the internal tab control and
2708 // it's managed page windows
2710 class wxTabFrame
: public wxWindow
2717 m_rect
= wxRect(0,0,200,200);
2718 m_tabCtrlHeight
= 20;
2726 void SetTabCtrlHeight(int h
)
2728 m_tabCtrlHeight
= h
;
2732 void DoSetSize(int x
, int y
,
2733 int width
, int height
,
2734 int WXUNUSED(sizeFlags
= wxSIZE_AUTO
))
2736 m_rect
= wxRect(x
, y
, width
, height
);
2740 void DoGetClientSize(int* x
, int* y
) const
2747 bool Show( bool WXUNUSED(show
= true) ) { return false; }
2754 if (m_tabs
->IsFrozen() || m_tabs
->GetParent()->IsFrozen())
2757 m_tab_rect
= wxRect(m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tabCtrlHeight
);
2758 if (m_tabs
->GetFlags() & wxAUI_NB_BOTTOM
)
2760 m_tab_rect
= wxRect (m_rect
.x
, m_rect
.y
+ m_rect
.height
- m_tabCtrlHeight
, m_rect
.width
, m_tabCtrlHeight
);
2761 m_tabs
->SetSize (m_rect
.x
, m_rect
.y
+ m_rect
.height
- m_tabCtrlHeight
, m_rect
.width
, m_tabCtrlHeight
);
2762 m_tabs
->SetRect (wxRect(0, 0, m_rect
.width
, m_tabCtrlHeight
));
2764 else //TODO: if (GetFlags() & wxAUI_NB_TOP)
2766 m_tab_rect
= wxRect (m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tabCtrlHeight
);
2767 m_tabs
->SetSize (m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tabCtrlHeight
);
2768 m_tabs
->SetRect (wxRect(0, 0, m_rect
.width
, m_tabCtrlHeight
));
2770 // TODO: else if (GetFlags() & wxAUI_NB_LEFT){}
2771 // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){}
2774 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
2778 wxAuiNotebookPageArray
& pages
= m_tabs
->GetPages();
2779 size_t i
, page_count
= pages
.GetCount();
2781 for (i
= 0; i
< page_count
; ++i
)
2783 int height
= m_rect
.height
- m_tabCtrlHeight
;
2786 // avoid passing negative height to wxWindow::SetSize(), this
2787 // results in assert failures/GTK+ warnings
2791 wxAuiNotebookPage
& page
= pages
.Item(i
);
2792 if (m_tabs
->GetFlags() & wxAUI_NB_BOTTOM
)
2794 page
.window
->SetSize(m_rect
.x
, m_rect
.y
, m_rect
.width
, height
);
2796 else //TODO: if (GetFlags() & wxAUI_NB_TOP)
2798 page
.window
->SetSize(m_rect
.x
, m_rect
.y
+ m_tabCtrlHeight
,
2799 m_rect
.width
, height
);
2801 // TODO: else if (GetFlags() & wxAUI_NB_LEFT){}
2802 // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){}
2805 if (page
.window
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
2807 wxAuiMDIChildFrame
* wnd
= (wxAuiMDIChildFrame
*)page
.window
;
2808 wnd
->ApplyMDIChildFrameRect();
2815 void DoGetSize(int* x
, int* y
) const
2818 *x
= m_rect
.GetWidth();
2820 *y
= m_rect
.GetHeight();
2831 wxAuiTabCtrl
* m_tabs
;
2832 int m_tabCtrlHeight
;
2836 const int wxAuiBaseTabCtrlId
= 5380;
2839 // -- wxAuiNotebook class implementation --
2841 #define EVT_AUI_RANGE(id1, id2, event, func) \
2842 wx__DECLARE_EVT2(event, id1, id2, wxAuiNotebookEventHandler(func))
2844 BEGIN_EVENT_TABLE(wxAuiNotebook
, wxControl
)
2845 EVT_SIZE(wxAuiNotebook::OnSize
)
2846 EVT_CHILD_FOCUS(wxAuiNotebook::OnChildFocusNotebook
)
2847 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2848 wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
,
2849 wxAuiNotebook::OnTabClicked
)
2850 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2851 wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
,
2852 wxAuiNotebook::OnTabBeginDrag
)
2853 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2854 wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
,
2855 wxAuiNotebook::OnTabEndDrag
)
2856 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2857 wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG
,
2858 wxAuiNotebook::OnTabCancelDrag
)
2859 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2860 wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
,
2861 wxAuiNotebook::OnTabDragMotion
)
2862 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2863 wxEVT_COMMAND_AUINOTEBOOK_BUTTON
,
2864 wxAuiNotebook::OnTabButton
)
2865 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2866 wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
,
2867 wxAuiNotebook::OnTabMiddleDown
)
2868 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2869 wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
,
2870 wxAuiNotebook::OnTabMiddleUp
)
2871 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2872 wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
,
2873 wxAuiNotebook::OnTabRightDown
)
2874 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2875 wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
,
2876 wxAuiNotebook::OnTabRightUp
)
2877 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2878 wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
,
2879 wxAuiNotebook::OnTabBgDClick
)
2880 EVT_NAVIGATION_KEY(wxAuiNotebook::OnNavigationKeyNotebook
)
2883 void wxAuiNotebook::Init()
2886 m_tabIdCounter
= wxAuiBaseTabCtrlId
;
2888 m_tabCtrlHeight
= 20;
2889 m_requestedBmpSize
= wxDefaultSize
;
2890 m_requestedTabCtrlHeight
= -1;
2893 bool wxAuiNotebook::Create(wxWindow
* parent
,
2899 if (!wxControl::Create(parent
, id
, pos
, size
, style
))
2902 InitNotebook(style
);
2907 // InitNotebook() contains common initialization
2908 // code called by all constructors
2909 void wxAuiNotebook::InitNotebook(long style
)
2911 SetName(wxT("wxAuiNotebook"));
2913 m_tabIdCounter
= wxAuiBaseTabCtrlId
;
2915 m_flags
= (unsigned int)style
;
2916 m_tabCtrlHeight
= 20;
2918 m_normalFont
= *wxNORMAL_FONT
;
2919 m_selectedFont
= *wxNORMAL_FONT
;
2920 m_selectedFont
.SetWeight(wxBOLD
);
2922 SetArtProvider(new wxAuiDefaultTabArt
);
2924 m_dummyWnd
= new wxWindow(this, wxID_ANY
, wxPoint(0,0), wxSize(0,0));
2925 m_dummyWnd
->SetSize(200, 200);
2926 m_dummyWnd
->Show(false);
2928 m_mgr
.SetManagedWindow(this);
2929 m_mgr
.SetFlags(wxAUI_MGR_DEFAULT
);
2930 m_mgr
.SetDockSizeConstraint(1.0, 1.0); // no dock size constraint
2932 m_mgr
.AddPane(m_dummyWnd
,
2933 wxAuiPaneInfo().Name(wxT("dummy")).Bottom().CaptionVisible(false).Show(false));
2938 wxAuiNotebook::~wxAuiNotebook()
2940 // Indicate we're deleting pages
2943 while ( GetPageCount() > 0 )
2949 void wxAuiNotebook::SetArtProvider(wxAuiTabArt
* art
)
2951 m_tabs
.SetArtProvider(art
);
2953 // Update the height and do nothing else if it did something but otherwise
2954 // (i.e. if the new art provider uses the same height as the old one) we
2955 // need to manually set the art provider for all tabs ourselves.
2956 if ( !UpdateTabCtrlHeight() )
2958 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2959 const size_t pane_count
= all_panes
.GetCount();
2960 for (size_t i
= 0; i
< pane_count
; ++i
)
2962 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2963 if (pane
.name
== wxT("dummy"))
2965 wxTabFrame
* tab_frame
= (wxTabFrame
*)pane
.window
;
2966 wxAuiTabCtrl
* tabctrl
= tab_frame
->m_tabs
;
2967 tabctrl
->SetArtProvider(art
->Clone());
2972 // SetTabCtrlHeight() is the highest-level override of the
2973 // tab height. A call to this function effectively enforces a
2974 // specified tab ctrl height, overriding all other considerations,
2975 // such as text or bitmap height. It overrides any call to
2976 // SetUniformBitmapSize(). Specifying a height of -1 reverts
2977 // any previous call and returns to the default behaviour
2979 void wxAuiNotebook::SetTabCtrlHeight(int height
)
2981 m_requestedTabCtrlHeight
= height
;
2983 // if window is already initialized, recalculate the tab height
2986 UpdateTabCtrlHeight();
2991 // SetUniformBitmapSize() ensures that all tabs will have
2992 // the same height, even if some tabs don't have bitmaps
2993 // Passing wxDefaultSize to this function will instruct
2994 // the control to use dynamic tab height-- so when a tab
2995 // with a large bitmap is added, the tab ctrl's height will
2996 // automatically increase to accommodate the bitmap
2998 void wxAuiNotebook::SetUniformBitmapSize(const wxSize
& size
)
3000 m_requestedBmpSize
= size
;
3002 // if window is already initialized, recalculate the tab height
3005 UpdateTabCtrlHeight();
3009 // UpdateTabCtrlHeight() does the actual tab resizing. It's meant
3010 // to be used internally
3011 bool wxAuiNotebook::UpdateTabCtrlHeight()
3013 // get the tab ctrl height we will use
3014 int height
= CalculateTabCtrlHeight();
3016 // if the tab control height needs to change, update
3017 // all of our tab controls with the new height
3018 if (m_tabCtrlHeight
== height
)
3021 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
3023 m_tabCtrlHeight
= height
;
3025 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3026 size_t i
, pane_count
= all_panes
.GetCount();
3027 for (i
= 0; i
< pane_count
; ++i
)
3029 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
3030 if (pane
.name
== wxT("dummy"))
3032 wxTabFrame
* tab_frame
= (wxTabFrame
*)pane
.window
;
3033 wxAuiTabCtrl
* tabctrl
= tab_frame
->m_tabs
;
3034 tab_frame
->SetTabCtrlHeight(m_tabCtrlHeight
);
3035 tabctrl
->SetArtProvider(art
->Clone());
3036 tab_frame
->DoSizing();
3042 void wxAuiNotebook::UpdateHintWindowSize()
3044 wxSize size
= CalculateNewSplitSize();
3046 // the placeholder hint window should be set to this size
3047 wxAuiPaneInfo
& info
= m_mgr
.GetPane(wxT("dummy"));
3051 info
.BestSize(size
);
3052 m_dummyWnd
->SetSize(size
);
3057 // calculates the size of the new split
3058 wxSize
wxAuiNotebook::CalculateNewSplitSize()
3060 // count number of tab controls
3061 int tab_ctrl_count
= 0;
3062 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3063 size_t i
, pane_count
= all_panes
.GetCount();
3064 for (i
= 0; i
< pane_count
; ++i
)
3066 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
3067 if (pane
.name
== wxT("dummy"))
3072 wxSize new_split_size
;
3074 // if there is only one tab control, the first split
3075 // should happen around the middle
3076 if (tab_ctrl_count
< 2)
3078 new_split_size
= GetClientSize();
3079 new_split_size
.x
/= 2;
3080 new_split_size
.y
/= 2;
3084 // this is in place of a more complicated calculation
3085 // that needs to be implemented
3086 new_split_size
= wxSize(180,180);
3089 return new_split_size
;
3092 int wxAuiNotebook::CalculateTabCtrlHeight()
3094 // if a fixed tab ctrl height is specified,
3095 // just return that instead of calculating a
3097 if (m_requestedTabCtrlHeight
!= -1)
3098 return m_requestedTabCtrlHeight
;
3100 // find out new best tab height
3101 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
3103 return art
->GetBestTabCtrlSize(this,
3105 m_requestedBmpSize
);
3109 wxAuiTabArt
* wxAuiNotebook::GetArtProvider() const
3111 return m_tabs
.GetArtProvider();
3114 void wxAuiNotebook::SetWindowStyleFlag(long style
)
3116 wxControl::SetWindowStyleFlag(style
);
3118 m_flags
= (unsigned int)style
;
3120 // if the control is already initialized
3121 if (m_mgr
.GetManagedWindow() == (wxWindow
*)this)
3123 // let all of the tab children know about the new style
3125 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3126 size_t i
, pane_count
= all_panes
.GetCount();
3127 for (i
= 0; i
< pane_count
; ++i
)
3129 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
3130 if (pane
.name
== wxT("dummy"))
3132 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
3133 wxAuiTabCtrl
* tabctrl
= tabframe
->m_tabs
;
3134 tabctrl
->SetFlags(m_flags
);
3135 tabframe
->DoSizing();
3137 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
3145 bool wxAuiNotebook::AddPage(wxWindow
* page
,
3146 const wxString
& caption
,
3148 const wxBitmap
& bitmap
)
3150 return InsertPage(GetPageCount(), page
, caption
, select
, bitmap
);
3153 bool wxAuiNotebook::InsertPage(size_t page_idx
,
3155 const wxString
& caption
,
3157 const wxBitmap
& bitmap
)
3159 wxASSERT_MSG(page
, wxT("page pointer must be non-NULL"));
3163 page
->Reparent(this);
3165 wxAuiNotebookPage info
;
3167 info
.caption
= caption
;
3168 info
.bitmap
= bitmap
;
3169 info
.active
= false;
3171 // if there are currently no tabs, the first added
3172 // tab must be active
3173 if (m_tabs
.GetPageCount() == 0)
3176 m_tabs
.InsertPage(page
, info
, page_idx
);
3178 // if that was the first page added, even if
3179 // select is false, it must become the "current page"
3180 // (though no select events will be fired)
3181 if (!select
&& m_tabs
.GetPageCount() == 1)
3183 //m_curPage = GetPageIndex(page);
3185 wxAuiTabCtrl
* active_tabctrl
= GetActiveTabCtrl();
3186 if (page_idx
>= active_tabctrl
->GetPageCount())
3187 active_tabctrl
->AddPage(page
, info
);
3189 active_tabctrl
->InsertPage(page
, info
, page_idx
);
3191 UpdateTabCtrlHeight();
3193 active_tabctrl
->DoShowHide();
3195 // adjust selected index
3196 if(m_curPage
>= (int) page_idx
)
3201 SetSelectionToWindow(page
);
3208 // DeletePage() removes a tab from the multi-notebook,
3209 // and destroys the window as well
3210 bool wxAuiNotebook::DeletePage(size_t page_idx
)
3212 if (page_idx
>= m_tabs
.GetPageCount())
3215 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
3217 // hide the window in advance, as this will
3219 ShowWnd(wnd
, false);
3221 if (!RemovePage(page_idx
))
3225 // actually destroy the window now
3226 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
3228 // delete the child frame with pending delete, as is
3229 // customary with frame windows
3230 if (!wxPendingDelete
.Member(wnd
))
3231 wxPendingDelete
.Append(wnd
);
3244 // RemovePage() removes a tab from the multi-notebook,
3245 // but does not destroy the window
3246 bool wxAuiNotebook::RemovePage(size_t page_idx
)
3248 // save active window pointer
3249 wxWindow
* active_wnd
= NULL
;
3251 active_wnd
= m_tabs
.GetWindowFromIdx(m_curPage
);
3253 // save pointer of window being deleted
3254 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
3255 wxWindow
* new_active
= NULL
;
3257 // make sure we found the page
3261 // find out which onscreen tab ctrl owns this tab
3264 if (!FindTab(wnd
, &ctrl
, &ctrl_idx
))
3267 bool is_curpage
= (m_curPage
== (int)page_idx
);
3268 bool is_active_in_split
= ctrl
->GetPage(ctrl_idx
).active
;
3271 // remove the tab from main catalog
3272 if (!m_tabs
.RemovePage(wnd
))
3275 // remove the tab from the onscreen tab ctrl
3276 ctrl
->RemovePage(wnd
);
3278 if (is_active_in_split
)
3280 int ctrl_new_page_count
= (int)ctrl
->GetPageCount();
3282 if (ctrl_idx
>= ctrl_new_page_count
)
3283 ctrl_idx
= ctrl_new_page_count
-1;
3285 if (ctrl_idx
>= 0 && ctrl_idx
< (int)ctrl
->GetPageCount())
3287 // set new page as active in the tab split
3288 ctrl
->SetActivePage(ctrl_idx
);
3290 // if the page deleted was the current page for the
3291 // entire tab control, then record the window
3292 // pointer of the new active page for activation
3295 new_active
= ctrl
->GetWindowFromIdx(ctrl_idx
);
3301 // we are not deleting the active page, so keep it the same
3302 new_active
= active_wnd
;
3308 // we haven't yet found a new page to active,
3309 // so select the next page from the main tab
3312 if (page_idx
< m_tabs
.GetPageCount())
3314 new_active
= m_tabs
.GetPage(page_idx
).window
;
3317 if (!new_active
&& m_tabs
.GetPageCount() > 0)
3319 new_active
= m_tabs
.GetPage(0).window
;
3324 RemoveEmptyTabFrames();
3326 m_curPage
= wxNOT_FOUND
;
3328 // set new active pane unless we're being destroyed anyhow
3329 if (new_active
&& !m_isBeingDeleted
)
3330 SetSelectionToWindow(new_active
);
3335 // GetPageIndex() returns the index of the page, or -1 if the
3336 // page could not be located in the notebook
3337 int wxAuiNotebook::GetPageIndex(wxWindow
* page_wnd
) const
3339 return m_tabs
.GetIdxFromWindow(page_wnd
);
3344 // SetPageText() changes the tab caption of the specified page
3345 bool wxAuiNotebook::SetPageText(size_t page_idx
, const wxString
& text
)
3347 if (page_idx
>= m_tabs
.GetPageCount())
3350 // update our own tab catalog
3351 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3352 page_info
.caption
= text
;
3354 // update what's on screen
3357 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
3359 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
3360 info
.caption
= text
;
3362 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
3370 // returns the page caption
3371 wxString
wxAuiNotebook::GetPageText(size_t page_idx
) const
3373 if (page_idx
>= m_tabs
.GetPageCount())
3374 return wxEmptyString
;
3376 // update our own tab catalog
3377 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3378 return page_info
.caption
;
3381 bool wxAuiNotebook::SetPageBitmap(size_t page_idx
, const wxBitmap
& bitmap
)
3383 if (page_idx
>= m_tabs
.GetPageCount())
3386 // update our own tab catalog
3387 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3388 page_info
.bitmap
= bitmap
;
3390 // tab height might have changed
3391 UpdateTabCtrlHeight();
3393 // update what's on screen
3396 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
3398 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
3399 info
.bitmap
= bitmap
;
3401 #ifdef TODO_REMOVE_IF_NO_PROBLEMS
3409 // returns the page bitmap
3410 wxBitmap
wxAuiNotebook::GetPageBitmap(size_t page_idx
) const
3412 if (page_idx
>= m_tabs
.GetPageCount())
3415 // update our own tab catalog
3416 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
3417 return page_info
.bitmap
;
3420 // GetSelection() returns the index of the currently active page
3421 int wxAuiNotebook::GetSelection() const
3426 // SetSelection() sets the currently active page
3427 int wxAuiNotebook::SetSelection(size_t new_page
)
3429 return DoModifySelection(new_page
, true);
3432 void wxAuiNotebook::SetSelectionToWindow(wxWindow
*win
)
3434 const int idx
= m_tabs
.GetIdxFromWindow(win
);
3435 wxCHECK_RET( idx
!= wxNOT_FOUND
, wxT("invalid notebook page") );
3438 // since a tab was clicked, let the parent know that we received
3439 // the focus, even if we will assign that focus immediately
3440 // to the child tab in the SetSelection call below
3441 // (the child focus event will also let wxAuiManager, if any,
3442 // know that the notebook control has been activated)
3444 wxWindow
* parent
= GetParent();
3447 wxChildFocusEvent
eventFocus(this);
3448 parent
->GetEventHandler()->ProcessEvent(eventFocus
);
3455 // GetPageCount() returns the total number of
3456 // pages managed by the multi-notebook
3457 size_t wxAuiNotebook::GetPageCount() const
3459 return m_tabs
.GetPageCount();
3462 // GetPage() returns the wxWindow pointer of the
3464 wxWindow
* wxAuiNotebook::GetPage(size_t page_idx
) const
3466 wxASSERT(page_idx
< m_tabs
.GetPageCount());
3468 return m_tabs
.GetWindowFromIdx(page_idx
);
3471 // DoSizing() performs all sizing operations in each tab control
3472 void wxAuiNotebook::DoSizing()
3474 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3475 size_t i
, pane_count
= all_panes
.GetCount();
3476 for (i
= 0; i
< pane_count
; ++i
)
3478 if (all_panes
.Item(i
).name
== wxT("dummy"))
3481 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3482 tabframe
->DoSizing();
3486 // GetActiveTabCtrl() returns the active tab control. It is
3487 // called to determine which control gets new windows being added
3488 wxAuiTabCtrl
* wxAuiNotebook::GetActiveTabCtrl()
3490 if (m_curPage
>= 0 && m_curPage
< (int)m_tabs
.GetPageCount())
3495 // find the tab ctrl with the current page
3496 if (FindTab(m_tabs
.GetPage(m_curPage
).window
,
3503 // no current page, just find the first tab ctrl
3504 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3505 size_t i
, pane_count
= all_panes
.GetCount();
3506 for (i
= 0; i
< pane_count
; ++i
)
3508 if (all_panes
.Item(i
).name
== wxT("dummy"))
3511 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3512 return tabframe
->m_tabs
;
3515 // If there is no tabframe at all, create one
3516 wxTabFrame
* tabframe
= new wxTabFrame
;
3517 tabframe
->SetTabCtrlHeight(m_tabCtrlHeight
);
3518 tabframe
->m_tabs
= new wxAuiTabCtrl(this,
3522 wxNO_BORDER
|wxWANTS_CHARS
);
3523 tabframe
->m_tabs
->SetFlags(m_flags
);
3524 tabframe
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3525 m_mgr
.AddPane(tabframe
,
3526 wxAuiPaneInfo().Center().CaptionVisible(false));
3530 return tabframe
->m_tabs
;
3533 // FindTab() finds the tab control that currently contains the window as well
3534 // as the index of the window in the tab control. It returns true if the
3535 // window was found, otherwise false.
3536 bool wxAuiNotebook::FindTab(wxWindow
* page
, wxAuiTabCtrl
** ctrl
, int* idx
)
3538 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3539 size_t i
, pane_count
= all_panes
.GetCount();
3540 for (i
= 0; i
< pane_count
; ++i
)
3542 if (all_panes
.Item(i
).name
== wxT("dummy"))
3545 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3547 int page_idx
= tabframe
->m_tabs
->GetIdxFromWindow(page
);
3550 *ctrl
= tabframe
->m_tabs
;
3559 void wxAuiNotebook::Split(size_t page
, int direction
)
3561 wxSize cli_size
= GetClientSize();
3563 // get the page's window pointer
3564 wxWindow
* wnd
= GetPage(page
);
3568 // notebooks with 1 or less pages can't be split
3569 if (GetPageCount() < 2)
3572 // find out which tab control the page currently belongs to
3573 wxAuiTabCtrl
*src_tabs
, *dest_tabs
;
3576 if (!FindTab(wnd
, &src_tabs
, &src_idx
))
3578 if (!src_tabs
|| src_idx
== -1)
3581 // choose a split size
3583 if (GetPageCount() > 2)
3585 split_size
= CalculateNewSplitSize();
3589 // because there are two panes, always split them
3591 split_size
= GetClientSize();
3597 // create a new tab frame
3598 wxTabFrame
* new_tabs
= new wxTabFrame
;
3599 new_tabs
->m_rect
= wxRect(wxPoint(0,0), split_size
);
3600 new_tabs
->SetTabCtrlHeight(m_tabCtrlHeight
);
3601 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
3605 wxNO_BORDER
|wxWANTS_CHARS
);
3606 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3607 new_tabs
->m_tabs
->SetFlags(m_flags
);
3608 dest_tabs
= new_tabs
->m_tabs
;
3610 // create a pane info structure with the information
3611 // about where the pane should be added
3612 wxAuiPaneInfo paneInfo
= wxAuiPaneInfo().Bottom().CaptionVisible(false);
3615 if (direction
== wxLEFT
)
3618 mouse_pt
= wxPoint(0, cli_size
.y
/2);
3620 else if (direction
== wxRIGHT
)
3623 mouse_pt
= wxPoint(cli_size
.x
, cli_size
.y
/2);
3625 else if (direction
== wxTOP
)
3628 mouse_pt
= wxPoint(cli_size
.x
/2, 0);
3630 else if (direction
== wxBOTTOM
)
3633 mouse_pt
= wxPoint(cli_size
.x
/2, cli_size
.y
);
3636 m_mgr
.AddPane(new_tabs
, paneInfo
, mouse_pt
);
3639 // remove the page from the source tabs
3640 wxAuiNotebookPage page_info
= src_tabs
->GetPage(src_idx
);
3641 page_info
.active
= false;
3642 src_tabs
->RemovePage(page_info
.window
);
3643 if (src_tabs
->GetPageCount() > 0)
3645 src_tabs
->SetActivePage((size_t)0);
3646 src_tabs
->DoShowHide();
3647 src_tabs
->Refresh();
3651 // add the page to the destination tabs
3652 dest_tabs
->InsertPage(page_info
.window
, page_info
, 0);
3654 if (src_tabs
->GetPageCount() == 0)
3656 RemoveEmptyTabFrames();
3660 dest_tabs
->DoShowHide();
3661 dest_tabs
->Refresh();
3663 // force the set selection function reset the selection
3666 // set the active page to the one we just split off
3667 SetSelectionToPage(page_info
);
3669 UpdateHintWindowSize();
3673 void wxAuiNotebook::OnSize(wxSizeEvent
& evt
)
3675 UpdateHintWindowSize();
3680 void wxAuiNotebook::OnTabClicked(wxAuiNotebookEvent
& evt
)
3682 wxAuiTabCtrl
* ctrl
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3683 wxASSERT(ctrl
!= NULL
);
3685 wxWindow
* wnd
= ctrl
->GetWindowFromIdx(evt
.GetSelection());
3686 wxASSERT(wnd
!= NULL
);
3688 SetSelectionToWindow(wnd
);
3691 void wxAuiNotebook::OnTabBgDClick(wxAuiNotebookEvent
& WXUNUSED(evt
))
3693 // notify owner that the tabbar background has been double-clicked
3694 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, m_windowId
);
3695 e
.SetEventObject(this);
3696 GetEventHandler()->ProcessEvent(e
);
3699 void wxAuiNotebook::OnTabBeginDrag(wxAuiNotebookEvent
&)
3704 void wxAuiNotebook::OnTabDragMotion(wxAuiNotebookEvent
& evt
)
3706 wxPoint screen_pt
= ::wxGetMousePosition();
3707 wxPoint client_pt
= ScreenToClient(screen_pt
);
3710 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3711 wxAuiTabCtrl
* dest_tabs
= GetTabCtrlFromPoint(client_pt
);
3713 if (dest_tabs
== src_tabs
)
3717 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
3720 // always hide the hint for inner-tabctrl drag
3723 // if tab moving is not allowed, leave
3724 if (!(m_flags
& wxAUI_NB_TAB_MOVE
))
3729 wxPoint pt
= dest_tabs
->ScreenToClient(screen_pt
);
3730 wxWindow
* dest_location_tab
;
3732 // this is an inner-tab drag/reposition
3733 if (dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &dest_location_tab
))
3735 int src_idx
= evt
.GetSelection();
3736 int dest_idx
= dest_tabs
->GetIdxFromWindow(dest_location_tab
);
3738 // prevent jumpy drag
3739 if ((src_idx
== dest_idx
) || dest_idx
== -1 ||
3740 (src_idx
> dest_idx
&& m_lastDragX
<= pt
.x
) ||
3741 (src_idx
< dest_idx
&& m_lastDragX
>= pt
.x
))
3748 wxWindow
* src_tab
= dest_tabs
->GetWindowFromIdx(src_idx
);
3749 dest_tabs
->MovePage(src_tab
, dest_idx
);
3750 dest_tabs
->SetActivePage((size_t)dest_idx
);
3751 dest_tabs
->DoShowHide();
3752 dest_tabs
->Refresh();
3761 // if external drag is allowed, check if the tab is being dragged
3762 // over a different wxAuiNotebook control
3763 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
3765 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(screen_pt
);
3767 // if we aren't over any window, stop here
3771 // make sure we are not over the hint window
3772 if (!tab_ctrl
->IsKindOf(CLASSINFO(wxFrame
)))
3776 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
3778 tab_ctrl
= tab_ctrl
->GetParent();
3783 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
3787 wxRect hint_rect
= tab_ctrl
->GetClientRect();
3788 tab_ctrl
->ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
3789 m_mgr
.ShowHint(hint_rect
);
3798 // we are either over a hint window, or not over a tab
3799 // window, and there is no where to drag to, so exit
3806 // if there are less than two panes, split can't happen, so leave
3807 if (m_tabs
.GetPageCount() < 2)
3810 // if tab moving is not allowed, leave
3811 if (!(m_flags
& wxAUI_NB_TAB_SPLIT
))
3817 src_tabs
->SetCursor(wxCursor(wxCURSOR_SIZING
));
3823 wxRect hint_rect
= dest_tabs
->GetRect();
3824 ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
3825 m_mgr
.ShowHint(hint_rect
);
3829 m_mgr
.DrawHintRect(m_dummyWnd
, client_pt
, zero
);
3835 void wxAuiNotebook::OnTabEndDrag(wxAuiNotebookEvent
& evt
)
3840 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3841 wxCHECK_RET( src_tabs
, wxT("no source object?") );
3843 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
3845 // get the mouse position, which will be used to determine the drop point
3846 wxPoint mouse_screen_pt
= ::wxGetMousePosition();
3847 wxPoint mouse_client_pt
= ScreenToClient(mouse_screen_pt
);
3851 // check for an external move
3852 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
3854 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(mouse_screen_pt
);
3858 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
3860 tab_ctrl
= tab_ctrl
->GetParent();
3865 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
3869 // find out from the destination control
3870 // if it's ok to drop this tab here
3871 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
, m_windowId
);
3872 e
.SetSelection(evt
.GetSelection());
3873 e
.SetOldSelection(evt
.GetSelection());
3874 e
.SetEventObject(this);
3875 e
.SetDragSource(this);
3876 e
.Veto(); // dropping must be explicitly approved by control owner
3878 nb
->GetEventHandler()->ProcessEvent(e
);
3882 // no answer or negative answer
3888 int src_idx
= evt
.GetSelection();
3889 wxWindow
* src_page
= src_tabs
->GetWindowFromIdx(src_idx
);
3891 // Check that it's not an impossible parent relationship
3893 while (p
&& !p
->IsTopLevel())
3902 // get main index of the page
3903 int main_idx
= m_tabs
.GetIdxFromWindow(src_page
);
3904 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, wxT("no source page?") );
3907 // make a copy of the page info
3908 wxAuiNotebookPage page_info
= m_tabs
.GetPage(main_idx
);
3910 // remove the page from the source notebook
3911 RemovePage(main_idx
);
3913 // reparent the page
3914 src_page
->Reparent(nb
);
3917 // found out the insert idx
3918 wxAuiTabCtrl
* dest_tabs
= (wxAuiTabCtrl
*)tab_ctrl
;
3919 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
3921 wxWindow
* target
= NULL
;
3922 int insert_idx
= -1;
3923 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
3926 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
3930 // add the page to the new notebook
3931 if (insert_idx
== -1)
3932 insert_idx
= dest_tabs
->GetPageCount();
3933 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
3934 nb
->m_tabs
.AddPage(page_info
.window
, page_info
);
3937 dest_tabs
->DoShowHide();
3938 dest_tabs
->Refresh();
3940 // set the selection in the destination tab control
3941 nb
->SetSelectionToPage(page_info
);
3943 // notify owner that the tab has been dragged
3944 wxAuiNotebookEvent
e2(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, m_windowId
);
3945 e2
.SetSelection(evt
.GetSelection());
3946 e2
.SetOldSelection(evt
.GetSelection());
3947 e2
.SetEventObject(this);
3948 GetEventHandler()->ProcessEvent(e2
);
3958 // only perform a tab split if it's allowed
3959 wxAuiTabCtrl
* dest_tabs
= NULL
;
3961 if ((m_flags
& wxAUI_NB_TAB_SPLIT
) && m_tabs
.GetPageCount() >= 2)
3963 // If the pointer is in an existing tab frame, do a tab insert
3964 wxWindow
* hit_wnd
= ::wxFindWindowAtPoint(mouse_screen_pt
);
3965 wxTabFrame
* tab_frame
= (wxTabFrame
*)GetTabFrameFromTabCtrl(hit_wnd
);
3966 int insert_idx
= -1;
3969 dest_tabs
= tab_frame
->m_tabs
;
3971 if (dest_tabs
== src_tabs
)
3975 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
3976 wxWindow
* target
= NULL
;
3977 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
3980 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
3986 wxRect rect
= m_mgr
.CalculateHintRect(m_dummyWnd
,
3991 // there is no suitable drop location here, exit out
3995 // If there is no tabframe at all, create one
3996 wxTabFrame
* new_tabs
= new wxTabFrame
;
3997 new_tabs
->m_rect
= wxRect(wxPoint(0,0), CalculateNewSplitSize());
3998 new_tabs
->SetTabCtrlHeight(m_tabCtrlHeight
);
3999 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
4003 wxNO_BORDER
|wxWANTS_CHARS
);
4004 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
4005 new_tabs
->m_tabs
->SetFlags(m_flags
);
4007 m_mgr
.AddPane(new_tabs
,
4008 wxAuiPaneInfo().Bottom().CaptionVisible(false),
4011 dest_tabs
= new_tabs
->m_tabs
;
4016 // remove the page from the source tabs
4017 wxAuiNotebookPage page_info
= src_tabs
->GetPage(evt
.GetSelection());
4018 page_info
.active
= false;
4019 src_tabs
->RemovePage(page_info
.window
);
4020 if (src_tabs
->GetPageCount() > 0)
4022 src_tabs
->SetActivePage((size_t)0);
4023 src_tabs
->DoShowHide();
4024 src_tabs
->Refresh();
4029 // add the page to the destination tabs
4030 if (insert_idx
== -1)
4031 insert_idx
= dest_tabs
->GetPageCount();
4032 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
4034 if (src_tabs
->GetPageCount() == 0)
4036 RemoveEmptyTabFrames();
4040 dest_tabs
->DoShowHide();
4041 dest_tabs
->Refresh();
4043 // force the set selection function reset the selection
4046 // set the active page to the one we just split off
4047 SetSelectionToPage(page_info
);
4049 UpdateHintWindowSize();
4052 // notify owner that the tab has been dragged
4053 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, m_windowId
);
4054 e
.SetSelection(evt
.GetSelection());
4055 e
.SetOldSelection(evt
.GetSelection());
4056 e
.SetEventObject(this);
4057 GetEventHandler()->ProcessEvent(e
);
4062 void wxAuiNotebook::OnTabCancelDrag(wxAuiNotebookEvent
& command_evt
)
4064 wxAuiNotebookEvent
& evt
= (wxAuiNotebookEvent
&)command_evt
;
4068 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4069 wxCHECK_RET( src_tabs
, wxT("no source object?") );
4071 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
4074 wxAuiTabCtrl
* wxAuiNotebook::GetTabCtrlFromPoint(const wxPoint
& pt
)
4076 // if we've just removed the last tab from the source
4077 // tab set, the remove the tab control completely
4078 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
4079 size_t i
, pane_count
= all_panes
.GetCount();
4080 for (i
= 0; i
< pane_count
; ++i
)
4082 if (all_panes
.Item(i
).name
== wxT("dummy"))
4085 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
4086 if (tabframe
->m_tab_rect
.Contains(pt
))
4087 return tabframe
->m_tabs
;
4093 wxWindow
* wxAuiNotebook::GetTabFrameFromTabCtrl(wxWindow
* tab_ctrl
)
4095 // if we've just removed the last tab from the source
4096 // tab set, the remove the tab control completely
4097 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
4098 size_t i
, pane_count
= all_panes
.GetCount();
4099 for (i
= 0; i
< pane_count
; ++i
)
4101 if (all_panes
.Item(i
).name
== wxT("dummy"))
4104 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
4105 if (tabframe
->m_tabs
== tab_ctrl
)
4114 void wxAuiNotebook::RemoveEmptyTabFrames()
4116 // if we've just removed the last tab from the source
4117 // tab set, the remove the tab control completely
4118 wxAuiPaneInfoArray all_panes
= m_mgr
.GetAllPanes();
4119 size_t i
, pane_count
= all_panes
.GetCount();
4120 for (i
= 0; i
< pane_count
; ++i
)
4122 if (all_panes
.Item(i
).name
== wxT("dummy"))
4125 wxTabFrame
* tab_frame
= (wxTabFrame
*)all_panes
.Item(i
).window
;
4126 if (tab_frame
->m_tabs
->GetPageCount() == 0)
4128 m_mgr
.DetachPane(tab_frame
);
4130 // use pending delete because sometimes during
4131 // window closing, refreshs are pending
4132 if (!wxPendingDelete
.Member(tab_frame
->m_tabs
))
4133 wxPendingDelete
.Append(tab_frame
->m_tabs
);
4135 tab_frame
->m_tabs
= NULL
;
4142 // check to see if there is still a center pane;
4143 // if there isn't, make a frame the center pane
4144 wxAuiPaneInfoArray panes
= m_mgr
.GetAllPanes();
4145 pane_count
= panes
.GetCount();
4146 wxWindow
* first_good
= NULL
;
4147 bool center_found
= false;
4148 for (i
= 0; i
< pane_count
; ++i
)
4150 if (panes
.Item(i
).name
== wxT("dummy"))
4152 if (panes
.Item(i
).dock_direction
== wxAUI_DOCK_CENTRE
)
4153 center_found
= true;
4155 first_good
= panes
.Item(i
).window
;
4158 if (!center_found
&& first_good
)
4160 m_mgr
.GetPane(first_good
).Centre();
4163 if (!m_isBeingDeleted
)
4167 void wxAuiNotebook::OnChildFocusNotebook(wxChildFocusEvent
& evt
)
4171 // if we're dragging a tab, don't change the current selection.
4172 // This code prevents a bug that used to happen when the hint window
4173 // was hidden. In the bug, the focus would return to the notebook
4174 // child, which would then enter this handler and call
4175 // SetSelection, which is not desired turn tab dragging.
4177 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
4178 size_t i
, pane_count
= all_panes
.GetCount();
4179 for (i
= 0; i
< pane_count
; ++i
)
4181 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
4182 if (pane
.name
== wxT("dummy"))
4184 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
4185 if (tabframe
->m_tabs
->IsDragging())
4190 // change the tab selection to the child
4191 // which was focused
4192 int idx
= m_tabs
.GetIdxFromWindow(evt
.GetWindow());
4193 if (idx
!= -1 && idx
!= m_curPage
)
4199 void wxAuiNotebook::OnNavigationKeyNotebook(wxNavigationKeyEvent
& event
)
4201 if ( event
.IsWindowChange() ) {
4203 // FIXME: the problem with this is that if we have a split notebook,
4204 // we selection may go all over the place.
4205 AdvanceSelection(event
.GetDirection());
4208 // we get this event in 3 cases
4210 // a) one of our pages might have generated it because the user TABbed
4211 // out from it in which case we should propagate the event upwards and
4212 // our parent will take care of setting the focus to prev/next sibling
4216 // b) the parent panel wants to give the focus to us so that we
4217 // forward it to our selected page. We can't deal with this in
4218 // OnSetFocus() because we don't know which direction the focus came
4219 // from in this case and so can't choose between setting the focus to
4220 // first or last panel child
4224 // c) we ourselves (see MSWTranslateMessage) generated the event
4226 wxWindow
* const parent
= GetParent();
4228 // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE
4229 const bool isFromParent
= event
.GetEventObject() == (wxObject
*) parent
;
4230 const bool isFromSelf
= event
.GetEventObject() == (wxObject
*) this;
4232 if ( isFromParent
|| isFromSelf
)
4234 // no, it doesn't come from child, case (b) or (c): forward to a
4235 // page but only if direction is backwards (TAB) or from ourselves,
4236 if ( GetSelection() != wxNOT_FOUND
&&
4237 (!event
.GetDirection() || isFromSelf
) )
4239 // so that the page knows that the event comes from it's parent
4240 // and is being propagated downwards
4241 event
.SetEventObject(this);
4243 wxWindow
*page
= GetPage(GetSelection());
4244 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
4248 //else: page manages focus inside it itself
4250 else // otherwise set the focus to the notebook itself
4257 // it comes from our child, case (a), pass to the parent, but only
4258 // if the direction is forwards. Otherwise set the focus to the
4259 // notebook itself. The notebook is always the 'first' control of a
4261 if ( !event
.GetDirection() )
4267 event
.SetCurrentFocus(this);
4268 parent
->GetEventHandler()->ProcessEvent(event
);
4274 void wxAuiNotebook::OnTabButton(wxAuiNotebookEvent
& evt
)
4276 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4278 int button_id
= evt
.GetInt();
4280 if (button_id
== wxAUI_BUTTON_CLOSE
)
4282 int selection
= evt
.GetSelection();
4284 if (selection
== -1)
4286 // if the close button is to the right, use the active
4287 // page selection to determine which page to close
4288 selection
= tabs
->GetActivePage();
4291 if (selection
!= -1)
4293 wxWindow
* close_wnd
= tabs
->GetWindowFromIdx(selection
);
4295 // ask owner if it's ok to close the tab
4296 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
, m_windowId
);
4297 e
.SetSelection(m_tabs
.GetIdxFromWindow(close_wnd
));
4298 const int idx
= m_tabs
.GetIdxFromWindow(close_wnd
);
4299 e
.SetSelection(idx
);
4300 e
.SetOldSelection(evt
.GetSelection());
4301 e
.SetEventObject(this);
4302 GetEventHandler()->ProcessEvent(e
);
4308 if (close_wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
4315 int main_idx
= m_tabs
.GetIdxFromWindow(close_wnd
);
4316 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, wxT("no page to delete?") );
4318 DeletePage(main_idx
);
4321 // notify owner that the tab has been closed
4322 wxAuiNotebookEvent
e2(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED
, m_windowId
);
4323 e2
.SetSelection(idx
);
4324 e2
.SetEventObject(this);
4325 GetEventHandler()->ProcessEvent(e2
);
4331 void wxAuiNotebook::OnTabMiddleDown(wxAuiNotebookEvent
& evt
)
4333 // patch event through to owner
4334 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4335 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4337 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, m_windowId
);
4338 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4339 e
.SetEventObject(this);
4340 GetEventHandler()->ProcessEvent(e
);
4343 void wxAuiNotebook::OnTabMiddleUp(wxAuiNotebookEvent
& evt
)
4345 // if the wxAUI_NB_MIDDLE_CLICK_CLOSE is specified, middle
4346 // click should act like a tab close action. However, first
4347 // give the owner an opportunity to handle the middle up event
4348 // for custom action
4350 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4351 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4353 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, m_windowId
);
4354 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4355 e
.SetEventObject(this);
4356 if (GetEventHandler()->ProcessEvent(e
))
4361 // check if we are supposed to close on middle-up
4362 if ((m_flags
& wxAUI_NB_MIDDLE_CLICK_CLOSE
) == 0)
4365 // simulate the user pressing the close button on the tab
4366 evt
.SetInt(wxAUI_BUTTON_CLOSE
);
4370 void wxAuiNotebook::OnTabRightDown(wxAuiNotebookEvent
& evt
)
4372 // patch event through to owner
4373 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4374 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4376 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, m_windowId
);
4377 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4378 e
.SetEventObject(this);
4379 GetEventHandler()->ProcessEvent(e
);
4382 void wxAuiNotebook::OnTabRightUp(wxAuiNotebookEvent
& evt
)
4384 // patch event through to owner
4385 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
4386 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
4388 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, m_windowId
);
4389 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
4390 e
.SetEventObject(this);
4391 GetEventHandler()->ProcessEvent(e
);
4394 // Sets the normal font
4395 void wxAuiNotebook::SetNormalFont(const wxFont
& font
)
4397 m_normalFont
= font
;
4398 GetArtProvider()->SetNormalFont(font
);
4401 // Sets the selected tab font
4402 void wxAuiNotebook::SetSelectedFont(const wxFont
& font
)
4404 m_selectedFont
= font
;
4405 GetArtProvider()->SetSelectedFont(font
);
4408 // Sets the measuring font
4409 void wxAuiNotebook::SetMeasuringFont(const wxFont
& font
)
4411 GetArtProvider()->SetMeasuringFont(font
);
4414 // Sets the tab font
4415 bool wxAuiNotebook::SetFont(const wxFont
& font
)
4417 wxControl::SetFont(font
);
4419 wxFont
normalFont(font
);
4420 wxFont
selectedFont(normalFont
);
4421 selectedFont
.SetWeight(wxBOLD
);
4423 SetNormalFont(normalFont
);
4424 SetSelectedFont(selectedFont
);
4425 SetMeasuringFont(selectedFont
);
4430 // Gets the tab control height
4431 int wxAuiNotebook::GetTabCtrlHeight() const
4433 return m_tabCtrlHeight
;
4436 // Gets the height of the notebook for a given page height
4437 int wxAuiNotebook::GetHeightForPageHeight(int pageHeight
)
4439 UpdateTabCtrlHeight();
4441 int tabCtrlHeight
= GetTabCtrlHeight();
4442 int decorHeight
= 2;
4443 return tabCtrlHeight
+ pageHeight
+ decorHeight
;
4446 // Advances the selection, generation page selection events
4447 void wxAuiNotebook::AdvanceSelection(bool forward
)
4449 if (GetPageCount() <= 1)
4452 int currentSelection
= GetSelection();
4456 if (currentSelection
== (int) (GetPageCount() - 1))
4458 else if (currentSelection
== -1)
4459 currentSelection
= 0;
4461 currentSelection
++;
4465 if (currentSelection
<= 0)
4468 currentSelection
--;
4471 SetSelection(currentSelection
);
4474 // Shows the window menu
4475 bool wxAuiNotebook::ShowWindowMenu()
4477 wxAuiTabCtrl
* tabCtrl
= GetActiveTabCtrl();
4479 int idx
= tabCtrl
->GetArtProvider()->ShowDropDown(tabCtrl
, tabCtrl
->GetPages(), tabCtrl
->GetActivePage());
4483 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, tabCtrl
->GetId());
4484 e
.SetSelection(idx
);
4485 e
.SetOldSelection(tabCtrl
->GetActivePage());
4486 e
.SetEventObject(tabCtrl
);
4487 GetEventHandler()->ProcessEvent(e
);
4495 void wxAuiNotebook::Thaw()
4502 void wxAuiNotebook::SetPageSize (const wxSize
& WXUNUSED(size
))
4504 wxFAIL_MSG("Not implemented for wxAuiNotebook");
4507 int wxAuiNotebook::HitTest (const wxPoint
& WXUNUSED(pt
), long* WXUNUSED(flags
)) const
4509 wxFAIL_MSG("Not implemented for wxAuiNotebook");
4513 int wxAuiNotebook::GetPageImage(size_t WXUNUSED(n
)) const
4515 wxFAIL_MSG("Not implemented for wxAuiNotebook");
4519 bool wxAuiNotebook::SetPageImage(size_t n
, int imageId
)
4521 return SetPageBitmap(n
, GetImageList()->GetBitmap(imageId
));
4524 wxWindow
* wxAuiNotebook::GetCurrentPage () const
4526 return GetPage(GetSelection());
4529 int wxAuiNotebook::ChangeSelection(size_t n
)
4531 return DoModifySelection(n
, false);
4534 bool wxAuiNotebook::AddPage(wxWindow
*page
, const wxString
&text
, bool select
,
4539 return AddPage(page
, text
, select
, GetImageList()->GetBitmap(imageId
));
4543 return AddPage(page
, text
, select
, wxNullBitmap
);
4547 bool wxAuiNotebook::DeleteAllPages()
4549 size_t count
= GetPageCount();
4550 for(size_t i
= 0; i
< count
; i
++)
4557 bool wxAuiNotebook::InsertPage(size_t index
, wxWindow
*page
,
4558 const wxString
&text
, bool select
,
4563 return InsertPage(index
, page
, text
, select
,
4564 GetImageList()->GetBitmap(imageId
));
4568 return InsertPage(index
, page
, text
, select
, wxNullBitmap
);
4572 int wxAuiNotebook::DoModifySelection(size_t n
, bool events
)
4574 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(n
);
4578 // don't change the page unless necessary;
4579 // however, clicking again on a tab should give it the focus.
4580 if ((int)n
== m_curPage
)
4584 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
4586 if (FindFocus() != ctrl
)
4592 bool vetoed
= false;
4594 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
4598 evt
.SetSelection(n
);
4599 evt
.SetOldSelection(m_curPage
);
4600 evt
.SetEventObject(this);
4601 GetEventHandler()->ProcessEvent(evt
);
4602 vetoed
= !evt
.IsAllowed();
4607 int old_curpage
= m_curPage
;
4610 // program allows the page change
4613 evt
.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
);
4614 (void)GetEventHandler()->ProcessEvent(evt
);
4620 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
4622 m_tabs
.SetActivePage(wnd
);
4624 ctrl
->SetActivePage(ctrl_idx
);
4628 ctrl
->MakeTabVisible(ctrl_idx
, ctrl
);
4631 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
4632 size_t i
, pane_count
= all_panes
.GetCount();
4633 for (i
= 0; i
< pane_count
; ++i
)
4635 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
4636 if (pane
.name
== wxT("dummy"))
4638 wxAuiTabCtrl
* tabctrl
= ((wxTabFrame
*)pane
.window
)->m_tabs
;
4639 if (tabctrl
!= ctrl
)
4640 tabctrl
->SetSelectedFont(m_normalFont
);
4642 tabctrl
->SetSelectedFont(m_selectedFont
);
4646 // Set the focus to the page if we're not currently focused on the tab.
4647 // This is Firefox-like behaviour.
4648 if (wnd
->IsShownOnScreen() && FindFocus() != ctrl
)