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"
35 #include "wx/mac/carbon/private.h"
38 #include "wx/arrimpl.cpp"
39 WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray
)
40 WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray
)
42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
)
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
)
46 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
)
47 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
)
52 IMPLEMENT_CLASS(wxAuiNotebook
, wxControl
)
53 IMPLEMENT_CLASS(wxAuiTabCtrl
, wxControl
)
54 IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent
, wxEvent
)
60 // these functions live in dockart.cpp -- they'll eventually
61 // be moved to a new utility cpp file
63 wxColor
wxAuiStepColour(const wxColor
& c
, int percent
);
65 wxBitmap
wxAuiBitmapFromBits(const unsigned char bits
[], int w
, int h
,
66 const wxColour
& color
);
68 wxString
wxAuiChopText(wxDC
& dc
, const wxString
& text
, int max_size
);
70 static void DrawButtons(wxDC
& dc
,
73 const wxColour
& bkcolour
,
78 if (button_state
== wxAUI_BUTTON_STATE_PRESSED
)
84 if (button_state
== wxAUI_BUTTON_STATE_HOVER
||
85 button_state
== wxAUI_BUTTON_STATE_PRESSED
)
87 dc
.SetBrush(wxBrush(wxAuiStepColour(bkcolour
, 120)));
88 dc
.SetPen(wxPen(wxAuiStepColour(bkcolour
, 75)));
90 // draw the background behind the button
91 dc
.DrawRectangle(rect
.x
, rect
.y
, 15, 15);
94 // draw the button itself
95 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
98 static void IndentPressedBitmap(wxRect
* rect
, int button_state
)
100 if (button_state
== wxAUI_BUTTON_STATE_PRESSED
)
109 // -- GUI helper classes and functions --
111 class wxAuiCommandCapture
: public wxEvtHandler
115 wxAuiCommandCapture() { m_last_id
= 0; }
116 int GetCommandId() const { return m_last_id
; }
118 bool ProcessEvent(wxEvent
& evt
)
120 if (evt
.GetEventType() == wxEVT_COMMAND_MENU_SELECTED
)
122 m_last_id
= evt
.GetId();
126 if (GetNextHandler())
127 return GetNextHandler()->ProcessEvent(evt
);
139 #if defined( __WXMAC__ )
140 static unsigned char close_bits
[]={
141 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0x03, 0xF8, 0x01, 0xF0, 0x19, 0xF3,
142 0xB8, 0xE3, 0xF0, 0xE1, 0xE0, 0xE0, 0xF0, 0xE1, 0xB8, 0xE3, 0x19, 0xF3,
143 0x01, 0xF0, 0x03, 0xF8, 0x0F, 0xFE, 0xFF, 0xFF };
144 #elif defined( __WXGTK__)
145 static unsigned char close_bits
[]={
146 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xfb, 0xef, 0xdb, 0xed, 0x8b, 0xe8,
147 0x1b, 0xec, 0x3b, 0xee, 0x1b, 0xec, 0x8b, 0xe8, 0xdb, 0xed, 0xfb, 0xef,
148 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
150 static unsigned char close_bits
[]={
151 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xf3, 0xcf, 0xf9,
152 0x9f, 0xfc, 0x3f, 0xfe, 0x3f, 0xfe, 0x9f, 0xfc, 0xcf, 0xf9, 0xe7, 0xf3,
153 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
156 static unsigned char left_bits
[] = {
157 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x3f, 0xfe,
158 0x1f, 0xfe, 0x0f, 0xfe, 0x1f, 0xfe, 0x3f, 0xfe, 0x7f, 0xfe, 0xff, 0xfe,
159 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
161 static unsigned char right_bits
[] = {
162 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0x9f, 0xff, 0x1f, 0xff,
163 0x1f, 0xfe, 0x1f, 0xfc, 0x1f, 0xfe, 0x1f, 0xff, 0x9f, 0xff, 0xdf, 0xff,
164 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
166 static unsigned char list_bits
[] = {
167 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
168 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff,
169 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
176 // -- wxAuiDefaultTabArt class implementation --
178 wxAuiDefaultTabArt::wxAuiDefaultTabArt()
180 m_normal_font
= *wxNORMAL_FONT
;
181 m_selected_font
= *wxNORMAL_FONT
;
182 m_selected_font
.SetWeight(wxBOLD
);
183 m_measuring_font
= m_selected_font
;
185 m_fixed_tab_width
= 100;
186 m_tab_ctrl_height
= 0;
189 wxBrush toolbarbrush
;
190 toolbarbrush
.MacSetTheme( kThemeBrushToolbarBackground
);
191 wxColor base_colour
= toolbarbrush
.GetColour();
193 wxColor base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
196 // the base_colour is too pale to use as our base colour,
197 // so darken it a bit --
198 if ((255-base_colour
.Red()) +
199 (255-base_colour
.Green()) +
200 (255-base_colour
.Blue()) < 60)
202 base_colour
= wxAuiStepColour(base_colour
, 92);
205 m_base_colour
= base_colour
;
206 wxColor border_colour
= wxAuiStepColour(base_colour
, 75);
208 m_border_pen
= wxPen(border_colour
);
209 m_base_colour_pen
= wxPen(m_base_colour
);
210 m_base_colour_brush
= wxBrush(m_base_colour
);
212 m_active_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, *wxBLACK
);
213 m_disabled_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, wxColour(128,128,128));
215 m_active_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, *wxBLACK
);
216 m_disabled_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, wxColour(128,128,128));
218 m_active_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, *wxBLACK
);
219 m_disabled_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, wxColour(128,128,128));
221 m_active_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, *wxBLACK
);
222 m_disabled_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, wxColour(128,128,128));
227 wxAuiDefaultTabArt::~wxAuiDefaultTabArt()
231 wxAuiTabArt
* wxAuiDefaultTabArt::Clone()
233 return static_cast<wxAuiTabArt
*>(new wxAuiDefaultTabArt
);
236 void wxAuiDefaultTabArt::SetFlags(unsigned int flags
)
241 void wxAuiDefaultTabArt::SetSizingInfo(const wxSize
& tab_ctrl_size
,
244 m_fixed_tab_width
= 100;
246 int tot_width
= (int)tab_ctrl_size
.x
- GetIndentSize() - 4;
248 if (m_flags
& wxAUI_NB_CLOSE_BUTTON
)
249 tot_width
-= m_active_close_bmp
.GetWidth();
250 if (m_flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
251 tot_width
-= m_active_windowlist_bmp
.GetWidth();
255 m_fixed_tab_width
= tot_width
/(int)tab_count
;
259 if (m_fixed_tab_width
< 100)
260 m_fixed_tab_width
= 100;
262 if (m_fixed_tab_width
> tot_width
/2)
263 m_fixed_tab_width
= tot_width
/2;
265 if (m_fixed_tab_width
> 220)
266 m_fixed_tab_width
= 220;
268 m_tab_ctrl_height
= tab_ctrl_size
.y
;
272 void wxAuiDefaultTabArt::DrawBackground(wxDC
& dc
,
273 wxWindow
* WXUNUSED(wnd
),
277 wxRect
r(rect
.x
, rect
.y
, rect
.width
+2, rect
.height
-3);
278 wxColor top_color
= wxAuiStepColour(m_base_colour
, 90);
279 wxColor bottom_color
= wxAuiStepColour(m_base_colour
, 170);
280 dc
.GradientFillLinear(r
, top_color
, bottom_color
, wxSOUTH
);
283 int y
= rect
.GetHeight();
284 int w
= rect
.GetWidth();
285 dc
.SetPen(m_border_pen
);
286 dc
.SetBrush(m_base_colour_brush
);
287 dc
.DrawRectangle(-1, y
-4, w
+2, 4);
291 // DrawTab() draws an individual tab.
294 // in_rect - rectangle the tab should be confined to
295 // caption - tab's caption
296 // active - whether or not the tab is active
297 // out_rect - actual output rectangle
298 // x_extent - the advance x; where the next tab should start
300 void wxAuiDefaultTabArt::DrawTab(wxDC
& dc
,
302 const wxAuiNotebookPage
& page
,
303 const wxRect
& in_rect
,
304 int close_button_state
,
305 wxRect
* out_tab_rect
,
306 wxRect
* out_button_rect
,
309 wxCoord normal_textx
, normal_texty
;
310 wxCoord selected_textx
, selected_texty
;
311 wxCoord textx
, texty
;
313 // if the caption is empty, measure some temporary text
314 wxString caption
= page
.caption
;
318 dc
.SetFont(m_selected_font
);
319 dc
.GetTextExtent(caption
, &selected_textx
, &selected_texty
);
321 dc
.SetFont(m_normal_font
);
322 dc
.GetTextExtent(caption
, &normal_textx
, &normal_texty
);
324 // figure out the size of the tab
325 wxSize tab_size
= GetTabSize(dc
,
333 wxCoord tab_height
= m_tab_ctrl_height
- 3;
334 wxCoord tab_width
= tab_size
.x
;
335 wxCoord tab_x
= in_rect
.x
;
336 wxCoord tab_y
= in_rect
.y
+ in_rect
.height
- tab_height
;
339 caption
= page
.caption
;
342 // select pen, brush and font for the tab to be drawn
346 dc
.SetFont(m_selected_font
);
347 textx
= selected_textx
;
348 texty
= selected_texty
;
352 dc
.SetFont(m_normal_font
);
353 textx
= normal_textx
;
354 texty
= normal_texty
;
358 // create points that will make the tab outline
360 int clip_width
= tab_width
;
361 if (tab_x
+ clip_width
> in_rect
.x
+ in_rect
.width
)
362 clip_width
= (in_rect
.x
+ in_rect
.width
) - tab_x
;
365 wxPoint clip_points[6];
366 clip_points[0] = wxPoint(tab_x, tab_y+tab_height-3);
367 clip_points[1] = wxPoint(tab_x, tab_y+2);
368 clip_points[2] = wxPoint(tab_x+2, tab_y);
369 clip_points[3] = wxPoint(tab_x+clip_width-1, tab_y);
370 clip_points[4] = wxPoint(tab_x+clip_width+1, tab_y+2);
371 clip_points[5] = wxPoint(tab_x+clip_width+1, tab_y+tab_height-3);
373 // FIXME: these ports don't provide wxRegion ctor from array of points
374 #if !defined(__WXDFB__) && !defined(__WXCOCOA__)
375 // set the clipping region for the tab --
376 wxRegion clipping_region(WXSIZEOF(clip_points), clip_points);
377 dc.SetClippingRegion(clipping_region);
378 #endif // !wxDFB && !wxCocoa
380 // since the above code above doesn't play well with WXDFB or WXCOCOA,
381 // we'll just use a rectangle for the clipping region for now --
382 dc
.SetClippingRegion(tab_x
, tab_y
, clip_width
+1, tab_height
-3);
385 wxPoint border_points
[6];
386 border_points
[0] = wxPoint(tab_x
, tab_y
+tab_height
-4);
387 border_points
[1] = wxPoint(tab_x
, tab_y
+2);
388 border_points
[2] = wxPoint(tab_x
+2, tab_y
);
389 border_points
[3] = wxPoint(tab_x
+tab_width
-2, tab_y
);
390 border_points
[4] = wxPoint(tab_x
+tab_width
, tab_y
+2);
391 border_points
[5] = wxPoint(tab_x
+tab_width
, tab_y
+tab_height
-4);
394 int drawn_tab_yoff
= border_points
[1].y
;
395 int drawn_tab_height
= border_points
[0].y
- border_points
[1].y
;
402 // draw base background color
403 wxRect
r(tab_x
, tab_y
, tab_width
, tab_height
);
404 dc
.SetPen(m_base_colour_pen
);
405 dc
.SetBrush(m_base_colour_brush
);
406 dc
.DrawRectangle(r
.x
+1, r
.y
+1, r
.width
-1, r
.height
-4);
408 // this white helps fill out the gradient at the top of the tab
409 dc
.SetPen(*wxWHITE_PEN
);
410 dc
.SetBrush(*wxWHITE_BRUSH
);
411 dc
.DrawRectangle(r
.x
+2, r
.y
+1, r
.width
-3, r
.height
-4);
413 // these two points help the rounded corners appear more antialiased
414 dc
.SetPen(m_base_colour_pen
);
415 dc
.DrawPoint(r
.x
+2, r
.y
+1);
416 dc
.DrawPoint(r
.x
+r
.width
-2, r
.y
+1);
418 // set rectangle down a bit for gradient drawing
419 r
.SetHeight(r
.GetHeight()/2);
425 // draw gradient background
426 wxColor top_color
= *wxWHITE
;
427 wxColor bottom_color
= m_base_colour
;
428 dc
.GradientFillLinear(r
, bottom_color
, top_color
, wxNORTH
);
434 wxRect
r(tab_x
, tab_y
+1, tab_width
, tab_height
-3);
436 // start the gradent up a bit and leave the inside border inset
437 // by a pixel for a 3D look. Only the top half of the inactive
438 // tab will have a slight gradient
445 // -- draw top gradient fill for glossy look
446 wxColor top_color
= m_base_colour
;
447 wxColor bottom_color
= wxAuiStepColour(top_color
, 160);
448 dc
.GradientFillLinear(r
, bottom_color
, top_color
, wxNORTH
);
453 // -- draw bottom fill for glossy look
454 top_color
= m_base_colour
;
455 bottom_color
= m_base_colour
;
456 dc
.GradientFillLinear(r
, top_color
, bottom_color
, wxSOUTH
);
460 dc
.SetPen(m_border_pen
);
461 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
462 dc
.DrawPolygon(WXSIZEOF(border_points
), border_points
);
464 // there are two horizontal grey lines at the bottom of the tab control,
465 // this gets rid of the top one of those lines in the tab control
468 wxColor start_color
= m_base_colour
;
469 dc
.SetPen(m_base_colour_pen
);
470 dc
.DrawLine(border_points
[0].x
+1,
477 int text_offset
= tab_x
+ 8;
478 int close_button_width
= 0;
479 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
481 close_button_width
= m_active_close_bmp
.GetWidth();
485 if (page
.bitmap
.IsOk())
487 int bitmap_offset
= tab_x
+ 8;
490 dc
.DrawBitmap(page
.bitmap
,
492 drawn_tab_yoff
+ (drawn_tab_height
/2) - (page
.bitmap
.GetHeight()/2),
495 text_offset
= bitmap_offset
+ page
.bitmap
.GetWidth();
496 text_offset
+= 3; // bitmap padding
500 text_offset
= tab_x
+ 8;
504 wxString draw_text
= wxAuiChopText(dc
,
506 tab_width
- (text_offset
-tab_x
) - close_button_width
);
509 dc
.DrawText(draw_text
,
511 drawn_tab_yoff
+ (drawn_tab_height
)/2 - (texty
/2) - 1);
516 // draw close button if necessary
517 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
519 wxBitmap bmp
= m_disabled_close_bmp
;
521 if (close_button_state
== wxAUI_BUTTON_STATE_HOVER
||
522 close_button_state
== wxAUI_BUTTON_STATE_PRESSED
)
524 bmp
= m_active_close_bmp
;
527 wxRect
rect(tab_x
+ tab_width
- close_button_width
- 1,
528 tab_y
+ (tab_height
/2) - (bmp
.GetHeight()/2),
531 IndentPressedBitmap(&rect
, close_button_state
);
532 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
534 *out_button_rect
= rect
;
537 *out_tab_rect
= wxRect(tab_x
, tab_y
, tab_width
, tab_height
);
539 dc
.DestroyClippingRegion();
542 int wxAuiDefaultTabArt::GetIndentSize()
547 wxSize
wxAuiDefaultTabArt::GetTabSize(wxDC
& dc
,
548 wxWindow
* WXUNUSED(wnd
),
549 const wxString
& caption
,
550 const wxBitmap
& bitmap
,
551 bool WXUNUSED(active
),
552 int close_button_state
,
555 wxCoord measured_textx
, measured_texty
, tmp
;
557 dc
.SetFont(m_measuring_font
);
558 dc
.GetTextExtent(caption
, &measured_textx
, &measured_texty
);
560 dc
.GetTextExtent(wxT("ABCDEFXj"), &tmp
, &measured_texty
);
562 // add padding around the text
563 wxCoord tab_width
= measured_textx
;
564 wxCoord tab_height
= measured_texty
;
566 // if the close button is showing, add space for it
567 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
568 tab_width
+= m_active_close_bmp
.GetWidth() + 3;
570 // if there's a bitmap, add space for it
573 tab_width
+= bitmap
.GetWidth();
574 tab_width
+= 3; // right side bitmap padding
575 tab_height
= wxMax(tab_height
, bitmap
.GetHeight());
582 if (m_flags
& wxAUI_NB_TAB_FIXED_WIDTH
)
584 tab_width
= m_fixed_tab_width
;
587 *x_extent
= tab_width
;
589 return wxSize(tab_width
, tab_height
);
593 void wxAuiDefaultTabArt::DrawButton(wxDC
& dc
,
594 wxWindow
* WXUNUSED(wnd
),
595 const wxRect
& in_rect
,
606 case wxAUI_BUTTON_CLOSE
:
607 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
608 bmp
= m_disabled_close_bmp
;
610 bmp
= m_active_close_bmp
;
612 case wxAUI_BUTTON_LEFT
:
613 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
614 bmp
= m_disabled_left_bmp
;
616 bmp
= m_active_left_bmp
;
618 case wxAUI_BUTTON_RIGHT
:
619 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
620 bmp
= m_disabled_right_bmp
;
622 bmp
= m_active_right_bmp
;
624 case wxAUI_BUTTON_WINDOWLIST
:
625 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
626 bmp
= m_disabled_windowlist_bmp
;
628 bmp
= m_active_windowlist_bmp
;
638 if (orientation
== wxLEFT
)
640 rect
.SetX(in_rect
.x
);
641 rect
.SetY(((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2));
642 rect
.SetWidth(bmp
.GetWidth());
643 rect
.SetHeight(bmp
.GetHeight());
647 rect
= wxRect(in_rect
.x
+ in_rect
.width
- bmp
.GetWidth(),
648 ((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2),
649 bmp
.GetWidth(), bmp
.GetHeight());
652 IndentPressedBitmap(&rect
, button_state
);
653 dc
.DrawBitmap(bmp
, rect
.x
, rect
.y
, true);
659 int wxAuiDefaultTabArt::ShowDropDown(wxWindow
* wnd
,
660 const wxAuiNotebookPageArray
& pages
,
665 size_t i
, count
= pages
.GetCount();
666 for (i
= 0; i
< count
; ++i
)
668 const wxAuiNotebookPage
& page
= pages
.Item(i
);
669 menuPopup
.AppendCheckItem(1000+i
, page
.caption
);
672 if (active_idx
!= -1)
674 menuPopup
.Check(1000+active_idx
, true);
677 // find out where to put the popup menu of window items
678 wxPoint pt
= ::wxGetMousePosition();
679 pt
= wnd
->ScreenToClient(pt
);
681 // find out the screen coordinate at the bottom of the tab ctrl
682 wxRect cli_rect
= wnd
->GetClientRect();
683 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
685 wxAuiCommandCapture
* cc
= new wxAuiCommandCapture
;
686 wnd
->PushEventHandler(cc
);
687 wnd
->PopupMenu(&menuPopup
, pt
);
688 int command
= cc
->GetCommandId();
689 wnd
->PopEventHandler(true);
697 int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow
* wnd
,
698 const wxAuiNotebookPageArray
& pages
,
699 const wxSize
& required_bmp_size
)
702 dc
.SetFont(m_measuring_font
);
704 // sometimes a standard bitmap size needs to be enforced, especially
705 // if some tabs have bitmaps and others don't. This is important because
706 // it prevents the tab control from resizing when tabs are added.
707 wxBitmap measure_bmp
;
708 if (required_bmp_size
.IsFullySpecified())
710 measure_bmp
.Create(required_bmp_size
.x
,
711 required_bmp_size
.y
);
716 size_t i
, page_count
= pages
.GetCount();
717 for (i
= 0; i
< page_count
; ++i
)
719 wxAuiNotebookPage
& page
= pages
.Item(i
);
722 if (measure_bmp
.IsOk())
727 // we don't use the caption text because we don't
728 // want tab heights to be different in the case
729 // of a very short piece of text on one tab and a very
730 // tall piece of text on another tab
732 wxSize s
= GetTabSize(dc
,
737 wxAUI_BUTTON_STATE_HIDDEN
,
740 max_y
= wxMax(max_y
, s
.y
);
746 void wxAuiDefaultTabArt::SetNormalFont(const wxFont
& font
)
748 m_normal_font
= font
;
751 void wxAuiDefaultTabArt::SetSelectedFont(const wxFont
& font
)
753 m_selected_font
= font
;
756 void wxAuiDefaultTabArt::SetMeasuringFont(const wxFont
& font
)
758 m_measuring_font
= font
;
762 // -- wxAuiSimpleTabArt class implementation --
764 wxAuiSimpleTabArt::wxAuiSimpleTabArt()
766 m_normal_font
= *wxNORMAL_FONT
;
767 m_selected_font
= *wxNORMAL_FONT
;
768 m_selected_font
.SetWeight(wxBOLD
);
769 m_measuring_font
= m_selected_font
;
772 m_fixed_tab_width
= 100;
774 wxColour base_colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
776 wxColour background_colour
= base_colour
;
777 wxColour normaltab_colour
= base_colour
;
778 wxColour selectedtab_colour
= *wxWHITE
;
780 m_bkbrush
= wxBrush(background_colour
);
781 m_normal_bkbrush
= wxBrush(normaltab_colour
);
782 m_normal_bkpen
= wxPen(normaltab_colour
);
783 m_selected_bkbrush
= wxBrush(selectedtab_colour
);
784 m_selected_bkpen
= wxPen(selectedtab_colour
);
786 m_active_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, *wxBLACK
);
787 m_disabled_close_bmp
= wxAuiBitmapFromBits(close_bits
, 16, 16, wxColour(128,128,128));
789 m_active_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, *wxBLACK
);
790 m_disabled_left_bmp
= wxAuiBitmapFromBits(left_bits
, 16, 16, wxColour(128,128,128));
792 m_active_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, *wxBLACK
);
793 m_disabled_right_bmp
= wxAuiBitmapFromBits(right_bits
, 16, 16, wxColour(128,128,128));
795 m_active_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, *wxBLACK
);
796 m_disabled_windowlist_bmp
= wxAuiBitmapFromBits(list_bits
, 16, 16, wxColour(128,128,128));
800 wxAuiSimpleTabArt::~wxAuiSimpleTabArt()
804 wxAuiTabArt
* wxAuiSimpleTabArt::Clone()
806 return static_cast<wxAuiTabArt
*>(new wxAuiSimpleTabArt
);
810 void wxAuiSimpleTabArt::SetFlags(unsigned int flags
)
815 void wxAuiSimpleTabArt::SetSizingInfo(const wxSize
& tab_ctrl_size
,
818 m_fixed_tab_width
= 100;
820 int tot_width
= (int)tab_ctrl_size
.x
- GetIndentSize() - 4;
822 if (m_flags
& wxAUI_NB_CLOSE_BUTTON
)
823 tot_width
-= m_active_close_bmp
.GetWidth();
824 if (m_flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
825 tot_width
-= m_active_windowlist_bmp
.GetWidth();
829 m_fixed_tab_width
= tot_width
/(int)tab_count
;
833 if (m_fixed_tab_width
< 100)
834 m_fixed_tab_width
= 100;
836 if (m_fixed_tab_width
> tot_width
/2)
837 m_fixed_tab_width
= tot_width
/2;
839 if (m_fixed_tab_width
> 220)
840 m_fixed_tab_width
= 220;
843 void wxAuiSimpleTabArt::DrawBackground(wxDC
& dc
,
844 wxWindow
* WXUNUSED(wnd
),
848 dc
.SetBrush(m_bkbrush
);
849 dc
.SetPen(*wxTRANSPARENT_PEN
);
850 dc
.DrawRectangle(-1, -1, rect
.GetWidth()+2, rect
.GetHeight()+2);
853 dc
.SetPen(*wxGREY_PEN
);
854 dc
.DrawLine(0, rect
.GetHeight()-1, rect
.GetWidth(), rect
.GetHeight()-1);
858 // DrawTab() draws an individual tab.
861 // in_rect - rectangle the tab should be confined to
862 // caption - tab's caption
863 // active - whether or not the tab is active
864 // out_rect - actual output rectangle
865 // x_extent - the advance x; where the next tab should start
867 void wxAuiSimpleTabArt::DrawTab(wxDC
& dc
,
869 const wxAuiNotebookPage
& page
,
870 const wxRect
& in_rect
,
871 int close_button_state
,
872 wxRect
* out_tab_rect
,
873 wxRect
* out_button_rect
,
876 wxCoord normal_textx
, normal_texty
;
877 wxCoord selected_textx
, selected_texty
;
878 wxCoord textx
, texty
;
880 // if the caption is empty, measure some temporary text
881 wxString caption
= page
.caption
;
885 dc
.SetFont(m_selected_font
);
886 dc
.GetTextExtent(caption
, &selected_textx
, &selected_texty
);
888 dc
.SetFont(m_normal_font
);
889 dc
.GetTextExtent(caption
, &normal_textx
, &normal_texty
);
891 // figure out the size of the tab
892 wxSize tab_size
= GetTabSize(dc
,
900 wxCoord tab_height
= tab_size
.y
;
901 wxCoord tab_width
= tab_size
.x
;
902 wxCoord tab_x
= in_rect
.x
;
903 wxCoord tab_y
= in_rect
.y
+ in_rect
.height
- tab_height
;
905 caption
= page
.caption
;
907 // select pen, brush and font for the tab to be drawn
911 dc
.SetPen(m_selected_bkpen
);
912 dc
.SetBrush(m_selected_bkbrush
);
913 dc
.SetFont(m_selected_font
);
914 textx
= selected_textx
;
915 texty
= selected_texty
;
919 dc
.SetPen(m_normal_bkpen
);
920 dc
.SetBrush(m_normal_bkbrush
);
921 dc
.SetFont(m_normal_font
);
922 textx
= normal_textx
;
923 texty
= normal_texty
;
931 points
[0].y
= tab_y
+ tab_height
- 1;
932 points
[1].x
= tab_x
+ tab_height
- 3;
933 points
[1].y
= tab_y
+ 2;
934 points
[2].x
= tab_x
+ tab_height
+ 3;
936 points
[3].x
= tab_x
+ tab_width
- 2;
938 points
[4].x
= tab_x
+ tab_width
;
939 points
[4].y
= tab_y
+ 2;
940 points
[5].x
= tab_x
+ tab_width
;
941 points
[5].y
= tab_y
+ tab_height
- 1;
942 points
[6] = points
[0];
944 dc
.SetClippingRegion(in_rect
);
946 dc
.DrawPolygon(WXSIZEOF(points
) - 1, points
);
948 dc
.SetPen(*wxGREY_PEN
);
950 //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points);
951 dc
.DrawLines(WXSIZEOF(points
), points
);
956 int close_button_width
= 0;
957 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
959 close_button_width
= m_active_close_bmp
.GetWidth();
960 text_offset
= tab_x
+ (tab_height
/2) + ((tab_width
-close_button_width
)/2) - (textx
/2);
964 text_offset
= tab_x
+ (tab_height
/3) + (tab_width
/2) - (textx
/2);
967 // set minimum text offset
968 if (text_offset
< tab_x
+ tab_height
)
969 text_offset
= tab_x
+ tab_height
;
971 // chop text if necessary
972 wxString draw_text
= wxAuiChopText(dc
,
974 tab_width
- (text_offset
-tab_x
) - close_button_width
);
977 dc
.DrawText(draw_text
,
979 (tab_y
+ tab_height
)/2 - (texty
/2) + 1);
982 // draw close button if necessary
983 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
987 bmp
= m_active_close_bmp
;
989 bmp
= m_disabled_close_bmp
;
991 wxRect
rect(tab_x
+ tab_width
- close_button_width
- 1,
992 tab_y
+ (tab_height
/2) - (bmp
.GetHeight()/2) + 1,
995 DrawButtons(dc
, rect
, bmp
, *wxWHITE
, close_button_state
);
997 *out_button_rect
= rect
;
1001 *out_tab_rect
= wxRect(tab_x
, tab_y
, tab_width
, tab_height
);
1003 dc
.DestroyClippingRegion();
1006 int wxAuiSimpleTabArt::GetIndentSize()
1011 wxSize
wxAuiSimpleTabArt::GetTabSize(wxDC
& dc
,
1012 wxWindow
* WXUNUSED(wnd
),
1013 const wxString
& caption
,
1014 const wxBitmap
& WXUNUSED(bitmap
),
1015 bool WXUNUSED(active
),
1016 int close_button_state
,
1019 wxCoord measured_textx
, measured_texty
;
1021 dc
.SetFont(m_measuring_font
);
1022 dc
.GetTextExtent(caption
, &measured_textx
, &measured_texty
);
1024 wxCoord tab_height
= measured_texty
+ 4;
1025 wxCoord tab_width
= measured_textx
+ tab_height
+ 5;
1027 if (close_button_state
!= wxAUI_BUTTON_STATE_HIDDEN
)
1028 tab_width
+= m_active_close_bmp
.GetWidth();
1030 if (m_flags
& wxAUI_NB_TAB_FIXED_WIDTH
)
1032 tab_width
= m_fixed_tab_width
;
1035 *x_extent
= tab_width
- (tab_height
/2) - 1;
1037 return wxSize(tab_width
, tab_height
);
1041 void wxAuiSimpleTabArt::DrawButton(wxDC
& dc
,
1042 wxWindow
* WXUNUSED(wnd
),
1043 const wxRect
& in_rect
,
1054 case wxAUI_BUTTON_CLOSE
:
1055 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1056 bmp
= m_disabled_close_bmp
;
1058 bmp
= m_active_close_bmp
;
1060 case wxAUI_BUTTON_LEFT
:
1061 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1062 bmp
= m_disabled_left_bmp
;
1064 bmp
= m_active_left_bmp
;
1066 case wxAUI_BUTTON_RIGHT
:
1067 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1068 bmp
= m_disabled_right_bmp
;
1070 bmp
= m_active_right_bmp
;
1072 case wxAUI_BUTTON_WINDOWLIST
:
1073 if (button_state
& wxAUI_BUTTON_STATE_DISABLED
)
1074 bmp
= m_disabled_windowlist_bmp
;
1076 bmp
= m_active_windowlist_bmp
;
1085 if (orientation
== wxLEFT
)
1087 rect
.SetX(in_rect
.x
);
1088 rect
.SetY(((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2));
1089 rect
.SetWidth(bmp
.GetWidth());
1090 rect
.SetHeight(bmp
.GetHeight());
1094 rect
= wxRect(in_rect
.x
+ in_rect
.width
- bmp
.GetWidth(),
1095 ((in_rect
.y
+ in_rect
.height
)/2) - (bmp
.GetHeight()/2),
1096 bmp
.GetWidth(), bmp
.GetHeight());
1100 DrawButtons(dc
, rect
, bmp
, *wxWHITE
, button_state
);
1106 int wxAuiSimpleTabArt::ShowDropDown(wxWindow
* wnd
,
1107 const wxAuiNotebookPageArray
& pages
,
1112 size_t i
, count
= pages
.GetCount();
1113 for (i
= 0; i
< count
; ++i
)
1115 const wxAuiNotebookPage
& page
= pages
.Item(i
);
1116 menuPopup
.AppendCheckItem(1000+i
, page
.caption
);
1119 if (active_idx
!= -1)
1121 menuPopup
.Check(1000+active_idx
, true);
1124 // find out where to put the popup menu of window
1125 // items. Subtract 100 for now to center the menu
1126 // a bit, until a better mechanism can be implemented
1127 wxPoint pt
= ::wxGetMousePosition();
1128 pt
= wnd
->ScreenToClient(pt
);
1134 // find out the screen coordinate at the bottom of the tab ctrl
1135 wxRect cli_rect
= wnd
->GetClientRect();
1136 pt
.y
= cli_rect
.y
+ cli_rect
.height
;
1138 wxAuiCommandCapture
* cc
= new wxAuiCommandCapture
;
1139 wnd
->PushEventHandler(cc
);
1140 wnd
->PopupMenu(&menuPopup
, pt
);
1141 int command
= cc
->GetCommandId();
1142 wnd
->PopEventHandler(true);
1144 if (command
>= 1000)
1145 return command
-1000;
1150 int wxAuiSimpleTabArt::GetBestTabCtrlSize(wxWindow
* wnd
,
1151 const wxAuiNotebookPageArray
& WXUNUSED(pages
),
1152 const wxSize
& WXUNUSED(required_bmp_size
))
1155 dc
.SetFont(m_measuring_font
);
1157 wxSize s
= GetTabSize(dc
,
1162 wxAUI_BUTTON_STATE_HIDDEN
,
1167 void wxAuiSimpleTabArt::SetNormalFont(const wxFont
& font
)
1169 m_normal_font
= font
;
1172 void wxAuiSimpleTabArt::SetSelectedFont(const wxFont
& font
)
1174 m_selected_font
= font
;
1177 void wxAuiSimpleTabArt::SetMeasuringFont(const wxFont
& font
)
1179 m_measuring_font
= font
;
1185 // -- wxAuiTabContainer class implementation --
1188 // wxAuiTabContainer is a class which contains information about each
1189 // tab. It also can render an entire tab control to a specified DC.
1190 // It's not a window class itself, because this code will be used by
1191 // the wxFrameMananger, where it is disadvantageous to have separate
1192 // windows for each tab control in the case of "docked tabs"
1194 // A derived class, wxAuiTabCtrl, is an actual wxWindow-derived window
1195 // which can be used as a tab control in the normal sense.
1198 wxAuiTabContainer::wxAuiTabContainer()
1202 m_art
= new wxAuiDefaultTabArt
;
1204 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
1205 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
1206 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
1207 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
1210 wxAuiTabContainer::~wxAuiTabContainer()
1215 void wxAuiTabContainer::SetArtProvider(wxAuiTabArt
* art
)
1222 m_art
->SetFlags(m_flags
);
1226 wxAuiTabArt
* wxAuiTabContainer::GetArtProvider() const
1231 void wxAuiTabContainer::SetFlags(unsigned int flags
)
1235 // check for new close button settings
1236 RemoveButton(wxAUI_BUTTON_LEFT
);
1237 RemoveButton(wxAUI_BUTTON_RIGHT
);
1238 RemoveButton(wxAUI_BUTTON_WINDOWLIST
);
1239 RemoveButton(wxAUI_BUTTON_CLOSE
);
1242 if (flags
& wxAUI_NB_SCROLL_BUTTONS
)
1244 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
1245 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
1248 if (flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
1250 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
1253 if (flags
& wxAUI_NB_CLOSE_BUTTON
)
1255 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
1260 m_art
->SetFlags(m_flags
);
1264 unsigned int wxAuiTabContainer::GetFlags() const
1270 void wxAuiTabContainer::SetNormalFont(const wxFont
& font
)
1272 m_art
->SetNormalFont(font
);
1275 void wxAuiTabContainer::SetSelectedFont(const wxFont
& font
)
1277 m_art
->SetSelectedFont(font
);
1280 void wxAuiTabContainer::SetMeasuringFont(const wxFont
& font
)
1282 m_art
->SetMeasuringFont(font
);
1285 void wxAuiTabContainer::SetRect(const wxRect
& rect
)
1291 m_art
->SetSizingInfo(rect
.GetSize(), m_pages
.GetCount());
1295 bool wxAuiTabContainer::AddPage(wxWindow
* page
,
1296 const wxAuiNotebookPage
& info
)
1298 wxAuiNotebookPage page_info
;
1300 page_info
.window
= page
;
1302 m_pages
.Add(page_info
);
1304 // let the art provider know how many pages we have
1307 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1313 bool wxAuiTabContainer::InsertPage(wxWindow
* page
,
1314 const wxAuiNotebookPage
& info
,
1317 wxAuiNotebookPage page_info
;
1319 page_info
.window
= page
;
1321 if (idx
>= m_pages
.GetCount())
1322 m_pages
.Add(page_info
);
1324 m_pages
.Insert(page_info
, idx
);
1326 // let the art provider know how many pages we have
1329 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1335 bool wxAuiTabContainer::MovePage(wxWindow
* page
,
1338 int idx
= GetIdxFromWindow(page
);
1342 // get page entry, make a copy of it
1343 wxAuiNotebookPage p
= GetPage(idx
);
1345 // remove old page entry
1348 // insert page where it should be
1349 InsertPage(page
, p
, new_idx
);
1354 bool wxAuiTabContainer::RemovePage(wxWindow
* wnd
)
1356 size_t i
, page_count
= m_pages
.GetCount();
1357 for (i
= 0; i
< page_count
; ++i
)
1359 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1360 if (page
.window
== wnd
)
1362 m_pages
.RemoveAt(i
);
1364 // let the art provider know how many pages we have
1367 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
1377 bool wxAuiTabContainer::SetActivePage(wxWindow
* wnd
)
1381 size_t i
, page_count
= m_pages
.GetCount();
1382 for (i
= 0; i
< page_count
; ++i
)
1384 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1385 if (page
.window
== wnd
)
1392 page
.active
= false;
1399 void wxAuiTabContainer::SetNoneActive()
1401 size_t i
, page_count
= m_pages
.GetCount();
1402 for (i
= 0; i
< page_count
; ++i
)
1404 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1405 page
.active
= false;
1409 bool wxAuiTabContainer::SetActivePage(size_t page
)
1411 if (page
>= m_pages
.GetCount())
1414 return SetActivePage(m_pages
.Item(page
).window
);
1417 int wxAuiTabContainer::GetActivePage() const
1419 size_t i
, page_count
= m_pages
.GetCount();
1420 for (i
= 0; i
< page_count
; ++i
)
1422 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1430 wxWindow
* wxAuiTabContainer::GetWindowFromIdx(size_t idx
) const
1432 if (idx
>= m_pages
.GetCount())
1435 return m_pages
[idx
].window
;
1438 int wxAuiTabContainer::GetIdxFromWindow(wxWindow
* wnd
) const
1440 const size_t page_count
= m_pages
.GetCount();
1441 for ( size_t i
= 0; i
< page_count
; ++i
)
1443 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1444 if (page
.window
== wnd
)
1450 wxAuiNotebookPage
& wxAuiTabContainer::GetPage(size_t idx
)
1452 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
1454 return m_pages
[idx
];
1457 const wxAuiNotebookPage
& wxAuiTabContainer::GetPage(size_t idx
) const
1459 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
1461 return m_pages
[idx
];
1464 wxAuiNotebookPageArray
& wxAuiTabContainer::GetPages()
1469 size_t wxAuiTabContainer::GetPageCount() const
1471 return m_pages
.GetCount();
1474 void wxAuiTabContainer::AddButton(int id
,
1476 const wxBitmap
& normal_bitmap
,
1477 const wxBitmap
& disabled_bitmap
)
1479 wxAuiTabContainerButton button
;
1481 button
.bitmap
= normal_bitmap
;
1482 button
.dis_bitmap
= disabled_bitmap
;
1483 button
.location
= location
;
1484 button
.cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
1486 m_buttons
.Add(button
);
1489 void wxAuiTabContainer::RemoveButton(int id
)
1491 size_t i
, button_count
= m_buttons
.GetCount();
1493 for (i
= 0; i
< button_count
; ++i
)
1495 if (m_buttons
.Item(i
).id
== id
)
1497 m_buttons
.RemoveAt(i
);
1505 size_t wxAuiTabContainer::GetTabOffset() const
1507 return m_tab_offset
;
1510 void wxAuiTabContainer::SetTabOffset(size_t offset
)
1512 m_tab_offset
= offset
;
1518 // Render() renders the tab catalog to the specified DC
1519 // It is a virtual function and can be overridden to
1520 // provide custom drawing capabilities
1521 void wxAuiTabContainer::Render(wxDC
* raw_dc
, wxWindow
* wnd
)
1523 if (!raw_dc
|| !raw_dc
->IsOk())
1529 size_t page_count
= m_pages
.GetCount();
1530 size_t button_count
= m_buttons
.GetCount();
1532 // create off-screen bitmap
1533 bmp
.Create(m_rect
.GetWidth(), m_rect
.GetHeight());
1534 dc
.SelectObject(bmp
);
1539 // find out if size of tabs is larger than can be
1540 // afforded on screen
1541 int total_width
= 0;
1542 int visible_width
= 0;
1543 for (i
= 0; i
< page_count
; ++i
)
1545 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1547 // determine if a close button is on this tab
1548 bool close_button
= false;
1549 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1550 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1552 close_button
= true;
1557 wxSize size
= m_art
->GetTabSize(dc
,
1563 wxAUI_BUTTON_STATE_NORMAL
:
1564 wxAUI_BUTTON_STATE_HIDDEN
,
1567 if (i
+1 < page_count
)
1568 total_width
+= x_extent
;
1570 total_width
+= size
.x
;
1572 if (i
>= m_tab_offset
)
1574 if (i
+1 < page_count
)
1575 visible_width
+= x_extent
;
1577 visible_width
+= size
.x
;
1581 if (total_width
> m_rect
.GetWidth() || m_tab_offset
!= 0)
1583 // show left/right buttons
1584 for (i
= 0; i
< button_count
; ++i
)
1586 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1587 if (button
.id
== wxAUI_BUTTON_LEFT
||
1588 button
.id
== wxAUI_BUTTON_RIGHT
)
1590 button
.cur_state
&= ~wxAUI_BUTTON_STATE_HIDDEN
;
1596 // hide left/right buttons
1597 for (i
= 0; i
< button_count
; ++i
)
1599 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1600 if (button
.id
== wxAUI_BUTTON_LEFT
||
1601 button
.id
== wxAUI_BUTTON_RIGHT
)
1603 button
.cur_state
|= wxAUI_BUTTON_STATE_HIDDEN
;
1608 // determine whether left button should be enabled
1609 for (i
= 0; i
< button_count
; ++i
)
1611 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1612 if (button
.id
== wxAUI_BUTTON_LEFT
)
1614 if (m_tab_offset
== 0)
1615 button
.cur_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1617 button
.cur_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1619 if (button
.id
== wxAUI_BUTTON_RIGHT
)
1621 if (visible_width
< m_rect
.GetWidth() - ((int)button_count
*16))
1622 button
.cur_state
|= wxAUI_BUTTON_STATE_DISABLED
;
1624 button
.cur_state
&= ~wxAUI_BUTTON_STATE_DISABLED
;
1631 m_art
->DrawBackground(dc
, wnd
, m_rect
);
1634 int left_buttons_width
= 0;
1635 int right_buttons_width
= 0;
1639 // draw the buttons on the right side
1640 offset
= m_rect
.x
+ m_rect
.width
;
1641 for (i
= 0; i
< button_count
; ++i
)
1643 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1645 if (button
.location
!= wxRIGHT
)
1647 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1650 wxRect button_rect
= m_rect
;
1651 button_rect
.SetY(1);
1652 button_rect
.SetWidth(offset
);
1654 m_art
->DrawButton(dc
,
1662 offset
-= button
.rect
.GetWidth();
1663 right_buttons_width
+= button
.rect
.GetWidth();
1670 // draw the buttons on the left side
1672 for (i
= 0; i
< button_count
; ++i
)
1674 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
1676 if (button
.location
!= wxLEFT
)
1678 if (button
.cur_state
& wxAUI_BUTTON_STATE_HIDDEN
)
1681 wxRect
button_rect(offset
, 1, 1000, m_rect
.height
);
1683 m_art
->DrawButton(dc
,
1691 offset
+= button
.rect
.GetWidth();
1692 left_buttons_width
+= button
.rect
.GetWidth();
1695 offset
= left_buttons_width
;
1698 offset
+= m_art
->GetIndentSize();
1701 // prepare the tab-close-button array
1702 // make sure tab button entries which aren't used are marked as hidden
1703 for (i
= page_count
; i
< m_tab_close_buttons
.GetCount(); ++i
)
1704 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1706 // make sure there are enough tab button entries to accommodate all tabs
1707 while (m_tab_close_buttons
.GetCount() < page_count
)
1709 wxAuiTabContainerButton tempbtn
;
1710 tempbtn
.id
= wxAUI_BUTTON_CLOSE
;
1711 tempbtn
.location
= wxCENTER
;
1712 tempbtn
.cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1713 m_tab_close_buttons
.Add(tempbtn
);
1717 // buttons before the tab offset must be set to hidden
1718 for (i
= 0; i
< m_tab_offset
; ++i
)
1720 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1726 size_t active
= 999;
1727 int active_offset
= 0;
1731 wxRect rect
= m_rect
;
1733 rect
.height
= m_rect
.height
;
1735 for (i
= m_tab_offset
; i
< page_count
; ++i
)
1737 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1738 wxAuiTabContainerButton
& tab_button
= m_tab_close_buttons
.Item(i
);
1740 // determine if a close button is on this tab
1741 bool close_button
= false;
1742 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1743 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1745 close_button
= true;
1746 if (tab_button
.cur_state
== wxAUI_BUTTON_STATE_HIDDEN
)
1748 tab_button
.id
= wxAUI_BUTTON_CLOSE
;
1749 tab_button
.cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
1750 tab_button
.location
= wxCENTER
;
1755 tab_button
.cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1759 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
1761 if (rect
.width
<= 0)
1768 tab_button
.cur_state
,
1776 active_offset
= offset
;
1784 // make sure to deactivate buttons which are off the screen to the right
1785 for (++i
; i
< m_tab_close_buttons
.GetCount(); ++i
)
1787 m_tab_close_buttons
.Item(i
).cur_state
= wxAUI_BUTTON_STATE_HIDDEN
;
1791 // draw the active tab again so it stands in the foreground
1792 if (active
>= m_tab_offset
&& active
< m_pages
.GetCount())
1794 wxAuiNotebookPage
& page
= m_pages
.Item(active
);
1796 wxAuiTabContainerButton
& tab_button
= m_tab_close_buttons
.Item(active
);
1798 // determine if a close button is on this tab
1799 bool close_button
= false;
1800 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
1801 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
1803 close_button
= true;
1806 rect
.x
= active_offset
;
1811 tab_button
.cur_state
,
1818 raw_dc
->Blit(m_rect
.x
, m_rect
.y
,
1819 m_rect
.GetWidth(), m_rect
.GetHeight(),
1824 // TabHitTest() tests if a tab was hit, passing the window pointer
1825 // back if that condition was fulfilled. The function returns
1826 // true if a tab was hit, otherwise false
1827 bool wxAuiTabContainer::TabHitTest(int x
, int y
, wxWindow
** hit
) const
1829 if (!m_rect
.Contains(x
,y
))
1832 wxAuiTabContainerButton
* btn
= NULL
;
1833 if (ButtonHitTest(x
, y
, &btn
))
1835 if (m_buttons
.Index(*btn
) != wxNOT_FOUND
)
1839 size_t i
, page_count
= m_pages
.GetCount();
1841 for (i
= m_tab_offset
; i
< page_count
; ++i
)
1843 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
1844 if (page
.rect
.Contains(x
,y
))
1855 // ButtonHitTest() tests if a button was hit. The function returns
1856 // true if a button was hit, otherwise false
1857 bool wxAuiTabContainer::ButtonHitTest(int x
, int y
,
1858 wxAuiTabContainerButton
** hit
) const
1860 if (!m_rect
.Contains(x
,y
))
1863 size_t i
, button_count
;
1866 button_count
= m_buttons
.GetCount();
1867 for (i
= 0; i
< button_count
; ++i
)
1869 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
1870 if (button
.rect
.Contains(x
,y
) &&
1871 !(button
.cur_state
& (wxAUI_BUTTON_STATE_HIDDEN
|
1872 wxAUI_BUTTON_STATE_DISABLED
)))
1880 button_count
= m_tab_close_buttons
.GetCount();
1881 for (i
= 0; i
< button_count
; ++i
)
1883 wxAuiTabContainerButton
& button
= m_tab_close_buttons
.Item(i
);
1884 if (button
.rect
.Contains(x
,y
) &&
1885 !(button
.cur_state
& (wxAUI_BUTTON_STATE_HIDDEN
|
1886 wxAUI_BUTTON_STATE_DISABLED
)))
1899 // the utility function ShowWnd() is the same as show,
1900 // except it handles wxAuiMDIChildFrame windows as well,
1901 // as the Show() method on this class is "unplugged"
1902 static void ShowWnd(wxWindow
* wnd
, bool show
)
1904 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
1906 wxAuiMDIChildFrame
* cf
= (wxAuiMDIChildFrame
*)wnd
;
1916 // DoShowHide() this function shows the active window, then
1917 // hides all of the other windows (in that order)
1918 void wxAuiTabContainer::DoShowHide()
1920 wxAuiNotebookPageArray
& pages
= GetPages();
1921 size_t i
, page_count
= pages
.GetCount();
1923 // show new active page first
1924 for (i
= 0; i
< page_count
; ++i
)
1926 wxAuiNotebookPage
& page
= pages
.Item(i
);
1929 ShowWnd(page
.window
, true);
1934 // hide all other pages
1935 for (i
= 0; i
< page_count
; ++i
)
1937 wxAuiNotebookPage
& page
= pages
.Item(i
);
1939 ShowWnd(page
.window
, false);
1948 // -- wxAuiTabCtrl class implementation --
1952 BEGIN_EVENT_TABLE(wxAuiTabCtrl
, wxControl
)
1953 EVT_PAINT(wxAuiTabCtrl::OnPaint
)
1954 EVT_ERASE_BACKGROUND(wxAuiTabCtrl::OnEraseBackground
)
1955 EVT_SIZE(wxAuiTabCtrl::OnSize
)
1956 EVT_LEFT_DOWN(wxAuiTabCtrl::OnLeftDown
)
1957 EVT_LEFT_DCLICK(wxAuiTabCtrl::OnLeftDown
)
1958 EVT_LEFT_UP(wxAuiTabCtrl::OnLeftUp
)
1959 EVT_MOTION(wxAuiTabCtrl::OnMotion
)
1960 EVT_LEAVE_WINDOW(wxAuiTabCtrl::OnLeaveWindow
)
1961 EVT_AUINOTEBOOK_BUTTON(wxID_ANY
, wxAuiTabCtrl::OnButton
)
1965 wxAuiTabCtrl::wxAuiTabCtrl(wxWindow
* parent
,
1969 long style
) : wxControl(parent
, id
, pos
, size
, style
)
1971 m_click_pt
= wxDefaultPosition
;
1972 m_is_dragging
= false;
1973 m_hover_button
= NULL
;
1974 m_pressed_button
= NULL
;
1977 wxAuiTabCtrl::~wxAuiTabCtrl()
1981 void wxAuiTabCtrl::OnPaint(wxPaintEvent
&)
1985 dc
.SetFont(GetFont());
1987 if (GetPageCount() > 0)
1991 void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
1995 void wxAuiTabCtrl::OnSize(wxSizeEvent
& evt
)
1997 wxSize s
= evt
.GetSize();
1998 wxRect
r(0, 0, s
.GetWidth(), s
.GetHeight());
2002 void wxAuiTabCtrl::OnLeftDown(wxMouseEvent
& evt
)
2005 m_click_pt
= wxDefaultPosition
;
2006 m_is_dragging
= false;
2008 m_pressed_button
= NULL
;
2012 if (TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
2014 int new_selection
= GetIdxFromWindow(wnd
);
2016 // wxAuiNotebooks always want to receive this event
2017 // even if the tab is already active, because they may
2018 // have multiple tab controls
2019 if (new_selection
!= GetActivePage() ||
2020 GetParent()->IsKindOf(CLASSINFO(wxAuiNotebook
)))
2022 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2023 e
.SetSelection(new_selection
);
2024 e
.SetOldSelection(GetActivePage());
2025 e
.SetEventObject(this);
2026 GetEventHandler()->ProcessEvent(e
);
2029 m_click_pt
.x
= evt
.m_x
;
2030 m_click_pt
.y
= evt
.m_y
;
2036 m_pressed_button
= m_hover_button
;
2037 m_pressed_button
->cur_state
= wxAUI_BUTTON_STATE_PRESSED
;
2043 void wxAuiTabCtrl::OnLeftUp(wxMouseEvent
& evt
)
2045 if (GetCapture() == this)
2050 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
, m_windowId
);
2051 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2052 evt
.SetOldSelection(evt
.GetSelection());
2053 evt
.SetEventObject(this);
2054 GetEventHandler()->ProcessEvent(evt
);
2058 if (m_pressed_button
)
2060 // make sure we're still clicking the button
2061 wxAuiTabContainerButton
* button
= NULL
;
2062 if (!ButtonHitTest(evt
.m_x
, evt
.m_y
, &button
))
2065 if (button
!= m_pressed_button
)
2067 m_pressed_button
= NULL
;
2074 if (!(m_pressed_button
->cur_state
& wxAUI_BUTTON_STATE_DISABLED
))
2076 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
, m_windowId
);
2077 evt
.SetInt(m_pressed_button
->id
);
2078 evt
.SetEventObject(this);
2079 GetEventHandler()->ProcessEvent(evt
);
2082 m_pressed_button
= NULL
;
2085 m_click_pt
= wxDefaultPosition
;
2086 m_is_dragging
= false;
2090 void wxAuiTabCtrl::OnMotion(wxMouseEvent
& evt
)
2092 wxPoint pos
= evt
.GetPosition();
2094 // check if the mouse is hovering above a button
2095 wxAuiTabContainerButton
* button
;
2096 if (ButtonHitTest(pos
.x
, pos
.y
, &button
))
2098 if (m_hover_button
&& button
!= m_hover_button
)
2100 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2101 m_hover_button
= NULL
;
2106 if (button
->cur_state
!= wxAUI_BUTTON_STATE_HOVER
)
2108 button
->cur_state
= wxAUI_BUTTON_STATE_HOVER
;
2111 m_hover_button
= button
;
2119 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2120 m_hover_button
= NULL
;
2127 if (!evt
.LeftIsDown() || m_click_pt
== wxDefaultPosition
)
2132 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
, m_windowId
);
2133 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2134 evt
.SetOldSelection(evt
.GetSelection());
2135 evt
.SetEventObject(this);
2136 GetEventHandler()->ProcessEvent(evt
);
2141 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
2142 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
2144 if (abs(pos
.x
- m_click_pt
.x
) > drag_x_threshold
||
2145 abs(pos
.y
- m_click_pt
.y
) > drag_y_threshold
)
2147 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
, m_windowId
);
2148 evt
.SetSelection(GetIdxFromWindow(m_click_tab
));
2149 evt
.SetOldSelection(evt
.GetSelection());
2150 evt
.SetEventObject(this);
2151 GetEventHandler()->ProcessEvent(evt
);
2153 m_is_dragging
= true;
2157 void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
2161 m_hover_button
->cur_state
= wxAUI_BUTTON_STATE_NORMAL
;
2162 m_hover_button
= NULL
;
2168 void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent
& event
)
2170 int button
= event
.GetInt();
2172 if (button
== wxAUI_BUTTON_LEFT
|| button
== wxAUI_BUTTON_RIGHT
)
2174 if (button
== wxAUI_BUTTON_LEFT
)
2176 if (GetTabOffset() > 0)
2178 SetTabOffset(GetTabOffset()-1);
2185 SetTabOffset(GetTabOffset()+1);
2190 else if (button
== wxAUI_BUTTON_WINDOWLIST
)
2192 int idx
= GetArtProvider()->ShowDropDown(this, m_pages
, GetActivePage());
2196 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2197 e
.SetSelection(idx
);
2198 e
.SetOldSelection(GetActivePage());
2199 e
.SetEventObject(this);
2200 GetEventHandler()->ProcessEvent(e
);
2209 // wxTabFrame is an interesting case. It's important that all child pages
2210 // of the multi-notebook control are all actually children of that control
2211 // (and not grandchildren). wxTabFrame facilitates this. There is one
2212 // instance of wxTabFrame for each tab control inside the multi-notebook.
2213 // It's important to know that wxTabFrame is not a real window, but it merely
2214 // used to capture the dimensions/positioning of the internal tab control and
2215 // it's managed page windows
2217 class wxTabFrame
: public wxWindow
2224 m_rect
= wxRect(0,0,200,200);
2225 m_tab_ctrl_height
= 20;
2228 void SetTabCtrlHeight(int h
)
2230 m_tab_ctrl_height
= h
;
2233 void DoSetSize(int x
, int y
,
2234 int width
, int height
,
2235 int WXUNUSED(sizeFlags
= wxSIZE_AUTO
))
2237 m_rect
= wxRect(x
, y
, width
, height
);
2241 void DoGetClientSize(int* x
, int* y
) const
2247 bool Show( bool WXUNUSED(show
= true) ) { return false; }
2254 m_tab_rect
= wxRect(m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tab_ctrl_height
);
2255 m_tabs
->SetSize(m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tab_ctrl_height
);
2256 m_tabs
->SetRect(wxRect(0, 0, m_rect
.width
, m_tab_ctrl_height
));
2260 wxAuiNotebookPageArray
& pages
= m_tabs
->GetPages();
2261 size_t i
, page_count
= pages
.GetCount();
2263 for (i
= 0; i
< page_count
; ++i
)
2265 wxAuiNotebookPage
& page
= pages
.Item(i
);
2266 page
.window
->SetSize(m_rect
.x
, m_rect
.y
+ m_tab_ctrl_height
,
2267 m_rect
.width
, m_rect
.height
- m_tab_ctrl_height
);
2269 if (page
.window
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
2271 wxAuiMDIChildFrame
* wnd
= (wxAuiMDIChildFrame
*)page
.window
;
2272 wnd
->ApplyMDIChildFrameRect();
2277 void DoGetSize(int* x
, int* y
) const
2280 *x
= m_rect
.GetWidth();
2282 *y
= m_rect
.GetHeight();
2294 wxAuiTabCtrl
* m_tabs
;
2295 int m_tab_ctrl_height
;
2299 const int wxAuiBaseTabCtrlId
= 5380;
2302 // -- wxAuiNotebook class implementation --
2304 BEGIN_EVENT_TABLE(wxAuiNotebook
, wxControl
)
2305 EVT_SIZE(wxAuiNotebook::OnSize
)
2306 EVT_CHILD_FOCUS(wxAuiNotebook::OnChildFocus
)
2307 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2308 wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
,
2309 wxAuiNotebook::OnTabClicked
)
2310 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2311 wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
,
2312 wxAuiNotebook::OnTabBeginDrag
)
2313 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2314 wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
,
2315 wxAuiNotebook::OnTabEndDrag
)
2316 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2317 wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
,
2318 wxAuiNotebook::OnTabDragMotion
)
2319 EVT_COMMAND_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
2320 wxEVT_COMMAND_AUINOTEBOOK_BUTTON
,
2321 wxAuiNotebook::OnTabButton
)
2324 wxAuiNotebook::wxAuiNotebook()
2327 m_tab_id_counter
= wxAuiBaseTabCtrlId
;
2329 m_tab_ctrl_height
= 20;
2330 m_requested_bmp_size
= wxDefaultSize
;
2331 m_requested_tabctrl_height
= -1;
2334 wxAuiNotebook::wxAuiNotebook(wxWindow
*parent
,
2338 long style
) : wxControl(parent
, id
, pos
, size
, style
)
2341 m_requested_bmp_size
= wxDefaultSize
;
2342 m_requested_tabctrl_height
= -1;
2343 InitNotebook(style
);
2346 bool wxAuiNotebook::Create(wxWindow
* parent
,
2352 if (!wxControl::Create(parent
, id
, pos
, size
, style
))
2355 InitNotebook(style
);
2360 // InitNotebook() contains common initialization
2361 // code called by all constructors
2362 void wxAuiNotebook::InitNotebook(long style
)
2365 m_tab_id_counter
= wxAuiBaseTabCtrlId
;
2367 m_flags
= (unsigned int)style
;
2368 m_tab_ctrl_height
= 20;
2370 m_normal_font
= *wxNORMAL_FONT
;
2371 m_selected_font
= *wxNORMAL_FONT
;
2372 m_selected_font
.SetWeight(wxBOLD
);
2374 SetArtProvider(new wxAuiDefaultTabArt
);
2376 m_dummy_wnd
= new wxWindow(this, wxID_ANY
, wxPoint(0,0), wxSize(0,0));
2377 m_dummy_wnd
->SetSize(200, 200);
2378 m_dummy_wnd
->Show(false);
2380 m_mgr
.SetManagedWindow(this);
2381 m_mgr
.SetFlags(wxAUI_MGR_DEFAULT
);
2382 m_mgr
.SetDockSizeConstraint(1.0, 1.0); // no dock size constraint
2384 m_mgr
.AddPane(m_dummy_wnd
,
2385 wxAuiPaneInfo().Name(wxT("dummy")).Bottom().CaptionVisible(false).Show(false));
2390 wxAuiNotebook::~wxAuiNotebook()
2395 void wxAuiNotebook::SetArtProvider(wxAuiTabArt
* art
)
2397 m_tabs
.SetArtProvider(art
);
2399 UpdateTabCtrlHeight();
2402 // SetTabCtrlHeight() is the highest-level override of the
2403 // tab height. A call to this function effectively enforces a
2404 // specified tab ctrl height, overriding all other considerations,
2405 // such as text or bitmap height. It overrides any call to
2406 // SetUniformBitmapSize(). Specifying a height of -1 reverts
2407 // any previous call and returns to the default behavior
2409 void wxAuiNotebook::SetTabCtrlHeight(int height
)
2411 m_requested_tabctrl_height
= height
;
2413 // if window is already initialized, recalculate the tab height
2416 UpdateTabCtrlHeight();
2421 // SetUniformBitmapSize() ensures that all tabs will have
2422 // the same height, even if some tabs don't have bitmaps
2423 // Passing wxDefaultSize to this function will instruct
2424 // the control to use dynamic tab height-- so when a tab
2425 // with a large bitmap is added, the tab ctrl's height will
2426 // automatically increase to accommodate the bitmap
2428 void wxAuiNotebook::SetUniformBitmapSize(const wxSize
& size
)
2430 m_requested_bmp_size
= size
;
2432 // if window is already initialized, recalculate the tab height
2435 UpdateTabCtrlHeight();
2439 // UpdateTabCtrlHeight() does the actual tab resizing. It's meant
2440 // to be used interally
2441 void wxAuiNotebook::UpdateTabCtrlHeight()
2443 // get the tab ctrl height we will use
2444 int height
= CalculateTabCtrlHeight();
2446 // if the tab control height needs to change, update
2447 // all of our tab controls with the new height
2448 if (m_tab_ctrl_height
!= height
)
2450 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
2452 m_tab_ctrl_height
= height
;
2454 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2455 size_t i
, pane_count
= all_panes
.GetCount();
2456 for (i
= 0; i
< pane_count
; ++i
)
2458 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2459 if (pane
.name
== wxT("dummy"))
2461 wxTabFrame
* tab_frame
= (wxTabFrame
*)pane
.window
;
2462 wxAuiTabCtrl
* tabctrl
= tab_frame
->m_tabs
;
2463 tab_frame
->SetTabCtrlHeight(m_tab_ctrl_height
);
2464 tabctrl
->SetArtProvider(art
->Clone());
2465 tab_frame
->DoSizing();
2470 void wxAuiNotebook::UpdateHintWindowSize()
2472 wxSize size
= CalculateNewSplitSize();
2474 // the placeholder hint window should be set to this size
2475 wxAuiPaneInfo
& info
= m_mgr
.GetPane(wxT("dummy"));
2479 info
.BestSize(size
);
2480 m_dummy_wnd
->SetSize(size
);
2485 // calculates the size of the new split
2486 wxSize
wxAuiNotebook::CalculateNewSplitSize()
2488 // count number of tab controls
2489 int tab_ctrl_count
= 0;
2490 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2491 size_t i
, pane_count
= all_panes
.GetCount();
2492 for (i
= 0; i
< pane_count
; ++i
)
2494 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2495 if (pane
.name
== wxT("dummy"))
2500 wxSize new_split_size
;
2502 // if there is only one tab control, the first split
2503 // should happen around the middle
2504 if (tab_ctrl_count
< 2)
2506 new_split_size
= GetClientSize();
2507 new_split_size
.x
/= 2;
2508 new_split_size
.y
/= 2;
2512 // this is in place of a more complicated calculation
2513 // that needs to be implemented
2514 new_split_size
= wxSize(180,180);
2517 return new_split_size
;
2520 int wxAuiNotebook::CalculateTabCtrlHeight()
2522 // if a fixed tab ctrl height is specified,
2523 // just return that instead of calculating a
2525 if (m_requested_tabctrl_height
!= -1)
2526 return m_requested_tabctrl_height
;
2528 // find out new best tab height
2529 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
2531 return art
->GetBestTabCtrlSize(this,
2533 m_requested_bmp_size
);
2537 wxAuiTabArt
* wxAuiNotebook::GetArtProvider() const
2539 return m_tabs
.GetArtProvider();
2542 void wxAuiNotebook::SetWindowStyleFlag(long style
)
2544 wxControl::SetWindowStyleFlag(style
);
2546 m_flags
= (unsigned int)style
;
2548 // if the control is already initialized
2549 if (m_mgr
.GetManagedWindow() == (wxWindow
*)this)
2551 // let all of the tab children know about the new style
2553 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2554 size_t i
, pane_count
= all_panes
.GetCount();
2555 for (i
= 0; i
< pane_count
; ++i
)
2557 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2558 if (pane
.name
== wxT("dummy"))
2560 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
2561 wxAuiTabCtrl
* tabctrl
= tabframe
->m_tabs
;
2562 tabctrl
->SetFlags(m_flags
);
2563 tabframe
->DoSizing();
2571 bool wxAuiNotebook::AddPage(wxWindow
* page
,
2572 const wxString
& caption
,
2574 const wxBitmap
& bitmap
)
2576 return InsertPage(GetPageCount(), page
, caption
, select
, bitmap
);
2579 bool wxAuiNotebook::InsertPage(size_t page_idx
,
2581 const wxString
& caption
,
2583 const wxBitmap
& bitmap
)
2585 wxAuiNotebookPage info
;
2587 info
.caption
= caption
;
2588 info
.bitmap
= bitmap
;
2589 info
.active
= false;
2591 // if there are currently no tabs, the first added
2592 // tab must be active
2593 if (m_tabs
.GetPageCount() == 0)
2596 m_tabs
.InsertPage(page
, info
, page_idx
);
2598 // if that was the first page added, even if
2599 // select is false, it must become the "current page"
2600 // (though no select events will be fired)
2601 if (!select
&& m_tabs
.GetPageCount() == 1)
2603 //m_curpage = GetPageIndex(page);
2605 wxAuiTabCtrl
* active_tabctrl
= GetActiveTabCtrl();
2606 if (page_idx
>= active_tabctrl
->GetPageCount())
2607 active_tabctrl
->AddPage(page
, info
);
2609 active_tabctrl
->InsertPage(page
, info
, page_idx
);
2611 UpdateTabCtrlHeight();
2613 active_tabctrl
->DoShowHide();
2617 SetSelectionToWindow(page
);
2624 // DeletePage() removes a tab from the multi-notebook,
2625 // and destroys the window as well
2626 bool wxAuiNotebook::DeletePage(size_t page_idx
)
2628 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
2630 if (!RemovePage(page_idx
))
2633 // actually destroy the window now
2634 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
2636 // delete the child frame with pending delete, as is
2637 // customary with frame windows
2638 if (!wxPendingDelete
.Member(wnd
))
2639 wxPendingDelete
.Append(wnd
);
2651 // RemovePage() removes a tab from the multi-notebook,
2652 // but does not destroy the window
2653 bool wxAuiNotebook::RemovePage(size_t page_idx
)
2655 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
2656 wxWindow
* new_active
= NULL
;
2658 // find out which onscreen tab ctrl owns this tab
2661 if (!FindTab(wnd
, &ctrl
, &ctrl_idx
))
2664 // find a new page and set it as active
2665 int new_idx
= ctrl_idx
+1;
2666 if (new_idx
>= (int)ctrl
->GetPageCount())
2667 new_idx
= ctrl_idx
-1;
2669 if (new_idx
>= 0 && new_idx
< (int)ctrl
->GetPageCount())
2671 new_active
= ctrl
->GetWindowFromIdx(new_idx
);
2675 // set the active page to the first page that
2676 // isn't the one being deleted
2677 size_t i
, page_count
= m_tabs
.GetPageCount();
2678 for (i
= 0; i
< page_count
; ++i
)
2680 wxWindow
* w
= m_tabs
.GetWindowFromIdx(i
);
2683 new_active
= m_tabs
.GetWindowFromIdx(i
);
2689 // remove the tab from main catalog
2690 if (!m_tabs
.RemovePage(wnd
))
2693 // remove the tab from the onscreen tab ctrl
2694 ctrl
->RemovePage(wnd
);
2697 RemoveEmptyTabFrames();
2699 // set new active pane
2703 SetSelectionToWindow(new_active
);
2709 // GetPageIndex() returns the index of the page, or -1 if the
2710 // page could not be located in the notebook
2711 int wxAuiNotebook::GetPageIndex(wxWindow
* page_wnd
) const
2713 return m_tabs
.GetIdxFromWindow(page_wnd
);
2718 // SetPageText() changes the tab caption of the specified page
2719 bool wxAuiNotebook::SetPageText(size_t page_idx
, const wxString
& text
)
2721 if (page_idx
>= m_tabs
.GetPageCount())
2724 // update our own tab catalog
2725 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2726 page_info
.caption
= text
;
2728 // update what's on screen
2731 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
2733 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
2734 info
.caption
= text
;
2742 // returns the page caption
2743 wxString
wxAuiNotebook::GetPageText(size_t page_idx
) const
2745 if (page_idx
>= m_tabs
.GetPageCount())
2746 return wxEmptyString
;
2748 // update our own tab catalog
2749 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2750 return page_info
.caption
;
2753 bool wxAuiNotebook::SetPageBitmap(size_t page_idx
, const wxBitmap
& bitmap
)
2755 if (page_idx
>= m_tabs
.GetPageCount())
2758 // update our own tab catalog
2759 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2760 page_info
.bitmap
= bitmap
;
2762 // tab height might have changed
2763 UpdateTabCtrlHeight();
2765 // update what's on screen
2768 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
2770 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
2771 info
.bitmap
= bitmap
;
2779 // returns the page bitmap
2780 wxBitmap
wxAuiNotebook::GetPageBitmap(size_t page_idx
) const
2782 if (page_idx
>= m_tabs
.GetPageCount())
2785 // update our own tab catalog
2786 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2787 return page_info
.bitmap
;
2790 // GetSelection() returns the index of the currently active page
2791 int wxAuiNotebook::GetSelection() const
2796 // SetSelection() sets the currently active page
2797 size_t wxAuiNotebook::SetSelection(size_t new_page
)
2799 // don't change the page unless necessary
2800 if ((int)new_page
== m_curpage
)
2803 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(new_page
);
2807 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
2808 evt
.SetSelection(new_page
);
2809 evt
.SetOldSelection(m_curpage
);
2810 evt
.SetEventObject(this);
2811 if (!GetEventHandler()->ProcessEvent(evt
) || evt
.IsAllowed())
2813 int old_curpage
= m_curpage
;
2814 m_curpage
= new_page
;
2816 // program allows the page change
2817 evt
.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
);
2818 (void)GetEventHandler()->ProcessEvent(evt
);
2823 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
2825 m_tabs
.SetActivePage(wnd
);
2827 ctrl
->SetActivePage(ctrl_idx
);
2834 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2835 size_t i
, pane_count
= all_panes
.GetCount();
2836 for (i
= 0; i
< pane_count
; ++i
)
2838 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2839 if (pane
.name
== wxT("dummy"))
2841 wxAuiTabCtrl
* tabctrl
= ((wxTabFrame
*)pane
.window
)->m_tabs
;
2842 if (tabctrl
!= ctrl
)
2843 tabctrl
->SetSelectedFont(m_normal_font
);
2845 tabctrl
->SetSelectedFont(m_selected_font
);
2858 void wxAuiNotebook::SetSelectionToWindow(wxWindow
*win
)
2860 const int idx
= m_tabs
.GetIdxFromWindow(win
);
2861 wxCHECK_RET( idx
!= wxNOT_FOUND
, _T("invalid notebook page") );
2866 // GetPageCount() returns the total number of
2867 // pages managed by the multi-notebook
2868 size_t wxAuiNotebook::GetPageCount() const
2870 return m_tabs
.GetPageCount();
2873 // GetPage() returns the wxWindow pointer of the
2875 wxWindow
* wxAuiNotebook::GetPage(size_t page_idx
) const
2877 wxASSERT(page_idx
< m_tabs
.GetPageCount());
2879 return m_tabs
.GetWindowFromIdx(page_idx
);
2882 // DoSizing() performs all sizing operations in each tab control
2883 void wxAuiNotebook::DoSizing()
2885 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2886 size_t i
, pane_count
= all_panes
.GetCount();
2887 for (i
= 0; i
< pane_count
; ++i
)
2889 if (all_panes
.Item(i
).name
== wxT("dummy"))
2892 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2893 tabframe
->DoSizing();
2897 // GetActiveTabCtrl() returns the active tab control. It is
2898 // called to determine which control gets new windows being added
2899 wxAuiTabCtrl
* wxAuiNotebook::GetActiveTabCtrl()
2901 if (m_curpage
>= 0 && m_curpage
< (int)m_tabs
.GetPageCount())
2906 // find the tab ctrl with the current page
2907 if (FindTab(m_tabs
.GetPage(m_curpage
).window
,
2914 // no current page, just find the first tab ctrl
2915 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2916 size_t i
, pane_count
= all_panes
.GetCount();
2917 for (i
= 0; i
< pane_count
; ++i
)
2919 if (all_panes
.Item(i
).name
== wxT("dummy"))
2922 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2923 return tabframe
->m_tabs
;
2926 // If there is no tabframe at all, create one
2927 wxTabFrame
* tabframe
= new wxTabFrame
;
2928 tabframe
->SetTabCtrlHeight(m_tab_ctrl_height
);
2929 tabframe
->m_tabs
= new wxAuiTabCtrl(this,
2934 tabframe
->m_tabs
->SetFlags(m_flags
);
2935 tabframe
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
2936 m_mgr
.AddPane(tabframe
,
2937 wxAuiPaneInfo().Center().CaptionVisible(false));
2941 return tabframe
->m_tabs
;
2944 // FindTab() finds the tab control that currently contains the window as well
2945 // as the index of the window in the tab control. It returns true if the
2946 // window was found, otherwise false.
2947 bool wxAuiNotebook::FindTab(wxWindow
* page
, wxAuiTabCtrl
** ctrl
, int* idx
)
2949 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2950 size_t i
, pane_count
= all_panes
.GetCount();
2951 for (i
= 0; i
< pane_count
; ++i
)
2953 if (all_panes
.Item(i
).name
== wxT("dummy"))
2956 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2958 int page_idx
= tabframe
->m_tabs
->GetIdxFromWindow(page
);
2961 *ctrl
= tabframe
->m_tabs
;
2970 void wxAuiNotebook::Split(size_t page
, int direction
)
2972 wxSize cli_size
= GetClientSize();
2974 // get the page's window pointer
2975 wxWindow
* wnd
= GetPage(page
);
2979 // notebooks with 1 or less pages can't be split
2980 if (GetPageCount() < 2)
2983 // find out which tab control the page currently belongs to
2984 wxAuiTabCtrl
*src_tabs
, *dest_tabs
;
2987 if (!FindTab(wnd
, &src_tabs
, &src_idx
))
2989 if (!src_tabs
|| src_idx
== -1)
2992 // choose a split size
2994 if (GetPageCount() > 2)
2996 split_size
= CalculateNewSplitSize();
3000 // because there are two panes, always split them
3002 split_size
= GetClientSize();
3008 // create a new tab frame
3009 wxTabFrame
* new_tabs
= new wxTabFrame
;
3010 new_tabs
->m_rect
= wxRect(wxPoint(0,0), split_size
);
3011 new_tabs
->SetTabCtrlHeight(m_tab_ctrl_height
);
3012 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
3017 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3018 new_tabs
->m_tabs
->SetFlags(m_flags
);
3019 dest_tabs
= new_tabs
->m_tabs
;
3021 // create a pane info structure with the information
3022 // about where the pane should be added
3023 wxAuiPaneInfo pane_info
= wxAuiPaneInfo().Bottom().CaptionVisible(false);
3026 if (direction
== wxLEFT
)
3029 mouse_pt
= wxPoint(0, cli_size
.y
/2);
3031 else if (direction
== wxRIGHT
)
3034 mouse_pt
= wxPoint(cli_size
.x
, cli_size
.y
/2);
3036 else if (direction
== wxTOP
)
3039 mouse_pt
= wxPoint(cli_size
.x
/2, 0);
3041 else if (direction
== wxBOTTOM
)
3044 mouse_pt
= wxPoint(cli_size
.x
/2, cli_size
.y
);
3047 m_mgr
.AddPane(new_tabs
, pane_info
, mouse_pt
);
3050 // remove the page from the source tabs
3051 wxAuiNotebookPage page_info
= src_tabs
->GetPage(src_idx
);
3052 page_info
.active
= false;
3053 src_tabs
->RemovePage(page_info
.window
);
3054 if (src_tabs
->GetPageCount() > 0)
3056 src_tabs
->SetActivePage((size_t)0);
3057 src_tabs
->DoShowHide();
3058 src_tabs
->Refresh();
3062 // add the page to the destination tabs
3063 dest_tabs
->InsertPage(page_info
.window
, page_info
, 0);
3065 if (src_tabs
->GetPageCount() == 0)
3067 RemoveEmptyTabFrames();
3071 dest_tabs
->DoShowHide();
3072 dest_tabs
->Refresh();
3074 // force the set selection function reset the selection
3077 // set the active page to the one we just split off
3078 SetSelectionToPage(page_info
);
3080 UpdateHintWindowSize();
3084 void wxAuiNotebook::OnSize(wxSizeEvent
& evt
)
3086 UpdateHintWindowSize();
3091 void wxAuiNotebook::OnTabClicked(wxCommandEvent
& command_evt
)
3093 wxAuiNotebookEvent
& evt
= (wxAuiNotebookEvent
&)command_evt
;
3095 wxAuiTabCtrl
* ctrl
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3096 wxASSERT(ctrl
!= NULL
);
3098 wxWindow
* wnd
= ctrl
->GetWindowFromIdx(evt
.GetSelection());
3099 wxASSERT(wnd
!= NULL
);
3101 SetSelectionToWindow(wnd
);
3104 void wxAuiNotebook::OnTabBeginDrag(wxCommandEvent
&)
3109 void wxAuiNotebook::OnTabDragMotion(wxCommandEvent
& evt
)
3111 wxPoint screen_pt
= ::wxGetMousePosition();
3112 wxPoint client_pt
= ScreenToClient(screen_pt
);
3115 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3116 wxAuiTabCtrl
* dest_tabs
= GetTabCtrlFromPoint(client_pt
);
3118 if (dest_tabs
== src_tabs
)
3122 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
3125 // always hide the hint for inner-tabctrl drag
3128 // if tab moving is not allowed, leave
3129 if (!(m_flags
& wxAUI_NB_TAB_MOVE
))
3134 wxPoint pt
= dest_tabs
->ScreenToClient(screen_pt
);
3135 wxWindow
* dest_location_tab
;
3137 // this is an inner-tab drag/reposition
3138 if (dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &dest_location_tab
))
3140 int src_idx
= evt
.GetSelection();
3141 int dest_idx
= dest_tabs
->GetIdxFromWindow(dest_location_tab
);
3143 // prevent jumpy drag
3144 if ((src_idx
== dest_idx
) || dest_idx
== -1 ||
3145 (src_idx
> dest_idx
&& m_last_drag_x
<= pt
.x
) ||
3146 (src_idx
< dest_idx
&& m_last_drag_x
>= pt
.x
))
3148 m_last_drag_x
= pt
.x
;
3153 wxWindow
* src_tab
= dest_tabs
->GetWindowFromIdx(src_idx
);
3154 dest_tabs
->MovePage(src_tab
, dest_idx
);
3155 dest_tabs
->SetActivePage((size_t)dest_idx
);
3156 dest_tabs
->DoShowHide();
3157 dest_tabs
->Refresh();
3158 m_last_drag_x
= pt
.x
;
3166 // if external drag is allowed, check if the tab is being dragged
3167 // over a different wxAuiNotebook control
3168 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
3170 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(screen_pt
);
3172 // if we aren't over any window, stop here
3176 // make sure we are not over the hint window
3177 if (!tab_ctrl
->IsKindOf(CLASSINFO(wxFrame
)))
3181 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
3183 tab_ctrl
= tab_ctrl
->GetParent();
3188 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
3192 wxRect hint_rect
= tab_ctrl
->GetClientRect();
3193 tab_ctrl
->ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
3194 m_mgr
.ShowHint(hint_rect
);
3203 // we are either over a hint window, or not over a tab
3204 // window, and there is no where to drag to, so exit
3211 // if there are less than two panes, split can't happen, so leave
3212 if (m_tabs
.GetPageCount() < 2)
3215 // if tab moving is not allowed, leave
3216 if (!(m_flags
& wxAUI_NB_TAB_SPLIT
))
3222 src_tabs
->SetCursor(wxCursor(wxCURSOR_SIZING
));
3228 wxRect hint_rect
= dest_tabs
->GetRect();
3229 ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
3230 m_mgr
.ShowHint(hint_rect
);
3234 m_mgr
.DrawHintRect(m_dummy_wnd
, client_pt
, zero
);
3240 void wxAuiNotebook::OnTabEndDrag(wxCommandEvent
& command_evt
)
3242 wxAuiNotebookEvent
& evt
= (wxAuiNotebookEvent
&)command_evt
;
3247 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3248 wxCHECK_RET( src_tabs
, _T("no source object?") );
3250 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
3252 // get the mouse position, which will be used to determine the drop point
3253 wxPoint mouse_screen_pt
= ::wxGetMousePosition();
3254 wxPoint mouse_client_pt
= ScreenToClient(mouse_screen_pt
);
3258 // check for an external move
3259 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
3261 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(mouse_screen_pt
);
3265 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
3267 tab_ctrl
= tab_ctrl
->GetParent();
3272 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
3276 // find out from the destination control
3277 // if it's ok to drop this tab here
3278 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
, m_windowId
);
3279 e
.SetSelection(evt
.GetSelection());
3280 e
.SetOldSelection(evt
.GetSelection());
3281 e
.SetEventObject(this);
3282 e
.SetDragSource(this);
3283 e
.Veto(); // dropping must be explicitly approved by control owner
3285 nb
->GetEventHandler()->ProcessEvent(e
);
3289 // no answer or negative answer
3295 int src_idx
= evt
.GetSelection();
3296 wxWindow
* src_page
= src_tabs
->GetWindowFromIdx(src_idx
);
3298 // get main index of the page
3299 int main_idx
= m_tabs
.GetIdxFromWindow(src_page
);
3300 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, _T("no source page?") );
3303 // make a copy of the page info
3304 wxAuiNotebookPage page_info
= m_tabs
.GetPage(main_idx
);
3306 // remove the page from the source notebook
3307 RemovePage(main_idx
);
3309 // reparent the page
3310 src_page
->Reparent(nb
);
3313 // found out the insert idx
3314 wxAuiTabCtrl
* dest_tabs
= (wxAuiTabCtrl
*)tab_ctrl
;
3315 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
3317 wxWindow
* target
= NULL
;
3318 int insert_idx
= -1;
3319 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
3322 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
3326 // add the page to the new notebook
3327 if (insert_idx
== -1)
3328 insert_idx
= dest_tabs
->GetPageCount();
3329 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
3330 nb
->m_tabs
.AddPage(page_info
.window
, page_info
);
3333 dest_tabs
->DoShowHide();
3334 dest_tabs
->Refresh();
3336 // set the selection in the destination tab control
3337 nb
->SetSelectionToPage(page_info
);
3347 // only perform a tab split if it's allowed
3348 wxAuiTabCtrl
* dest_tabs
= NULL
;
3350 if ((m_flags
& wxAUI_NB_TAB_SPLIT
) && m_tabs
.GetPageCount() >= 2)
3352 // If the pointer is in an existing tab frame, do a tab insert
3353 wxWindow
* hit_wnd
= ::wxFindWindowAtPoint(mouse_screen_pt
);
3354 wxTabFrame
* tab_frame
= (wxTabFrame
*)GetTabFrameFromTabCtrl(hit_wnd
);
3355 int insert_idx
= -1;
3358 dest_tabs
= tab_frame
->m_tabs
;
3360 if (dest_tabs
== src_tabs
)
3364 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
3365 wxWindow
* target
= NULL
;
3366 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
3369 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
3375 wxRect rect
= m_mgr
.CalculateHintRect(m_dummy_wnd
,
3380 // there is no suitable drop location here, exit out
3384 // If there is no tabframe at all, create one
3385 wxTabFrame
* new_tabs
= new wxTabFrame
;
3386 new_tabs
->m_rect
= wxRect(wxPoint(0,0), CalculateNewSplitSize());
3387 new_tabs
->SetTabCtrlHeight(m_tab_ctrl_height
);
3388 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
3393 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
3394 new_tabs
->m_tabs
->SetFlags(m_flags
);
3396 m_mgr
.AddPane(new_tabs
,
3397 wxAuiPaneInfo().Bottom().CaptionVisible(false),
3400 dest_tabs
= new_tabs
->m_tabs
;
3405 // remove the page from the source tabs
3406 wxAuiNotebookPage page_info
= src_tabs
->GetPage(evt
.GetSelection());
3407 page_info
.active
= false;
3408 src_tabs
->RemovePage(page_info
.window
);
3409 if (src_tabs
->GetPageCount() > 0)
3411 src_tabs
->SetActivePage((size_t)0);
3412 src_tabs
->DoShowHide();
3413 src_tabs
->Refresh();
3418 // add the page to the destination tabs
3419 if (insert_idx
== -1)
3420 insert_idx
= dest_tabs
->GetPageCount();
3421 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
3423 if (src_tabs
->GetPageCount() == 0)
3425 RemoveEmptyTabFrames();
3429 dest_tabs
->DoShowHide();
3430 dest_tabs
->Refresh();
3432 // force the set selection function reset the selection
3435 // set the active page to the one we just split off
3436 SetSelectionToPage(page_info
);
3438 UpdateHintWindowSize();
3444 wxAuiTabCtrl
* wxAuiNotebook::GetTabCtrlFromPoint(const wxPoint
& pt
)
3446 // if we've just removed the last tab from the source
3447 // tab set, the remove the tab control completely
3448 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3449 size_t i
, pane_count
= all_panes
.GetCount();
3450 for (i
= 0; i
< pane_count
; ++i
)
3452 if (all_panes
.Item(i
).name
== wxT("dummy"))
3455 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3456 if (tabframe
->m_tab_rect
.Contains(pt
))
3457 return tabframe
->m_tabs
;
3463 wxWindow
* wxAuiNotebook::GetTabFrameFromTabCtrl(wxWindow
* tab_ctrl
)
3465 // if we've just removed the last tab from the source
3466 // tab set, the remove the tab control completely
3467 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3468 size_t i
, pane_count
= all_panes
.GetCount();
3469 for (i
= 0; i
< pane_count
; ++i
)
3471 if (all_panes
.Item(i
).name
== wxT("dummy"))
3474 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3475 if (tabframe
->m_tabs
== tab_ctrl
)
3484 void wxAuiNotebook::RemoveEmptyTabFrames()
3486 // if we've just removed the last tab from the source
3487 // tab set, the remove the tab control completely
3488 wxAuiPaneInfoArray all_panes
= m_mgr
.GetAllPanes();
3489 size_t i
, pane_count
= all_panes
.GetCount();
3490 for (i
= 0; i
< pane_count
; ++i
)
3492 if (all_panes
.Item(i
).name
== wxT("dummy"))
3495 wxTabFrame
* tab_frame
= (wxTabFrame
*)all_panes
.Item(i
).window
;
3496 if (tab_frame
->m_tabs
->GetPageCount() == 0)
3498 m_mgr
.DetachPane(tab_frame
);
3500 // use pending delete because sometimes during
3501 // window closing, refreshs are pending
3502 if (!wxPendingDelete
.Member(tab_frame
->m_tabs
))
3503 wxPendingDelete
.Append(tab_frame
->m_tabs
);
3504 //tab_frame->m_tabs->Destroy();
3511 // check to see if there is still a center pane;
3512 // if there isn't, make a frame the center pane
3513 wxAuiPaneInfoArray panes
= m_mgr
.GetAllPanes();
3514 pane_count
= panes
.GetCount();
3515 wxWindow
* first_good
= NULL
;
3516 bool center_found
= false;
3517 for (i
= 0; i
< pane_count
; ++i
)
3519 if (panes
.Item(i
).name
== wxT("dummy"))
3521 if (panes
.Item(i
).dock_direction
== wxAUI_DOCK_CENTRE
)
3522 center_found
= true;
3524 first_good
= panes
.Item(i
).window
;
3527 if (!center_found
&& first_good
)
3529 m_mgr
.GetPane(first_good
).Centre();
3535 void wxAuiNotebook::OnChildFocus(wxChildFocusEvent
& evt
)
3537 int idx
= m_tabs
.GetIdxFromWindow(evt
.GetWindow());
3538 if (idx
!= -1 && idx
!= m_curpage
)
3545 void wxAuiNotebook::OnTabButton(wxCommandEvent
& command_evt
)
3547 wxAuiNotebookEvent
& evt
= (wxAuiNotebookEvent
&)command_evt
;
3548 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3550 int button_id
= evt
.GetInt();
3552 if (button_id
== wxAUI_BUTTON_CLOSE
)
3554 int selection
= tabs
->GetActivePage();
3556 if (selection
!= -1)
3558 wxWindow
* close_wnd
= tabs
->GetWindowFromIdx(selection
);
3561 // ask owner if it's ok to close the tab
3562 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
, m_windowId
);
3563 e
.SetSelection(m_tabs
.GetIdxFromWindow(close_wnd
));
3564 e
.SetOldSelection(evt
.GetSelection());
3565 e
.SetEventObject(this);
3566 GetEventHandler()->ProcessEvent(e
);
3571 if (close_wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
3577 int main_idx
= m_tabs
.GetIdxFromWindow(close_wnd
);
3578 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, _T("no page to delete?") );
3580 DeletePage(main_idx
);