1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/auibook.cpp
3 // Purpose: wxaui: wx advanced user interface - notebook
4 // Author: Benjamin I. Williams
5 // Modified by: Jens Lody
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"
27 #include "wx/dcclient.h"
28 #include "wx/dcmemory.h"
31 #include "wx/aui/tabmdi.h"
34 #include "wx/osx/private.h"
37 #include "wx/arrimpl.cpp"
38 WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray
)
39 WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray
)
41 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
, wxAuiNotebookEvent
);
42 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED
, wxAuiNotebookEvent
);
43 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, wxAuiNotebookEvent
);
44 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
, wxAuiNotebookEvent
);
45 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
, wxAuiNotebookEvent
);
46 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
, wxAuiNotebookEvent
);
47 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
, wxAuiNotebookEvent
);
48 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG
, wxAuiNotebookEvent
);
49 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
, wxAuiNotebookEvent
);
50 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
, wxAuiNotebookEvent
);
51 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, wxAuiNotebookEvent
);
52 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, wxAuiNotebookEvent
);
53 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, wxAuiNotebookEvent
);
54 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, wxAuiNotebookEvent
);
55 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, wxAuiNotebookEvent
);
56 wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, wxAuiNotebookEvent
);
58 IMPLEMENT_CLASS(wxAuiNotebook
, wxControl
)
59 IMPLEMENT_CLASS(wxAuiTabCtrl
, wxControl
)
60 IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent
, wxBookCtrlEvent
)
63 // -- wxAuiTabContainer class implementation --
66 // wxAuiTabContainer is a class which contains information about each
67 // tab. It also can render an entire tab control to a specified DC.
68 // It's not a window class itself, because this code will be used by
69 // the wxFrameMananger, where it is disadvantageous to have separate
70 // windows for each tab control in the case of "docked tabs"
72 // A derived class, wxAuiTabCtrl, is an actual wxWindow-derived window
73 // which can be used as a tab control in the normal sense.
76 wxAuiTabContainer::wxAuiTabContainer()
80 m_art
= new wxAuiDefaultTabArt
;
82 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
83 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
84 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
85 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
88 wxAuiTabContainer::~wxAuiTabContainer()
93 void wxAuiTabContainer::SetArtProvider(wxAuiTabArt
* art
)
100 m_art
->SetFlags(m_flags
);
104 wxAuiTabArt
* wxAuiTabContainer::GetArtProvider() const
109 void wxAuiTabContainer::SetFlags(unsigned int flags
)
113 // check for new close button settings
114 RemoveButton(wxAUI_BUTTON_LEFT
);
115 RemoveButton(wxAUI_BUTTON_RIGHT
);
116 RemoveButton(wxAUI_BUTTON_WINDOWLIST
);
117 RemoveButton(wxAUI_BUTTON_CLOSE
);
120 if (flags
& wxAUI_NB_SCROLL_BUTTONS
)
122 AddButton(wxAUI_BUTTON_LEFT
, wxLEFT
);
123 AddButton(wxAUI_BUTTON_RIGHT
, wxRIGHT
);
126 if (flags
& wxAUI_NB_WINDOWLIST_BUTTON
)
128 AddButton(wxAUI_BUTTON_WINDOWLIST
, wxRIGHT
);
131 if (flags
& wxAUI_NB_CLOSE_BUTTON
)
133 AddButton(wxAUI_BUTTON_CLOSE
, wxRIGHT
);
138 m_art
->SetFlags(m_flags
);
142 unsigned int wxAuiTabContainer::GetFlags() const
148 void wxAuiTabContainer::SetNormalFont(const wxFont
& font
)
150 m_art
->SetNormalFont(font
);
153 void wxAuiTabContainer::SetSelectedFont(const wxFont
& font
)
155 m_art
->SetSelectedFont(font
);
158 void wxAuiTabContainer::SetMeasuringFont(const wxFont
& font
)
160 m_art
->SetMeasuringFont(font
);
163 void wxAuiTabContainer::SetColour(const wxColour
& colour
)
165 m_art
->SetColour(colour
);
168 void wxAuiTabContainer::SetActiveColour(const wxColour
& colour
)
170 m_art
->SetActiveColour(colour
);
173 void wxAuiTabContainer::SetRect(const wxRect
& rect
)
179 m_art
->SetSizingInfo(rect
.GetSize(), m_pages
.GetCount());
183 bool wxAuiTabContainer::AddPage(wxWindow
* page
,
184 const wxAuiNotebookPage
& info
)
186 wxAuiNotebookPage page_info
;
188 page_info
.window
= page
;
190 m_pages
.Add(page_info
);
192 // let the art provider know how many pages we have
195 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
201 bool wxAuiTabContainer::InsertPage(wxWindow
* page
,
202 const wxAuiNotebookPage
& info
,
205 wxAuiNotebookPage page_info
;
207 page_info
.window
= page
;
209 if (idx
>= m_pages
.GetCount())
210 m_pages
.Add(page_info
);
212 m_pages
.Insert(page_info
, idx
);
214 // let the art provider know how many pages we have
217 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
223 bool wxAuiTabContainer::MovePage(wxWindow
* page
,
226 int idx
= GetIdxFromWindow(page
);
230 // get page entry, make a copy of it
231 wxAuiNotebookPage p
= GetPage(idx
);
233 // remove old page entry
236 // insert page where it should be
237 InsertPage(page
, p
, new_idx
);
242 bool wxAuiTabContainer::RemovePage(wxWindow
* wnd
)
244 size_t i
, page_count
= m_pages
.GetCount();
245 for (i
= 0; i
< page_count
; ++i
)
247 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
248 if (page
.window
== wnd
)
252 // let the art provider know how many pages we have
255 m_art
->SetSizingInfo(m_rect
.GetSize(), m_pages
.GetCount());
265 bool wxAuiTabContainer::SetActivePage(wxWindow
* wnd
)
269 size_t i
, page_count
= m_pages
.GetCount();
270 for (i
= 0; i
< page_count
; ++i
)
272 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
273 if (page
.window
== wnd
)
287 void wxAuiTabContainer::SetNoneActive()
289 size_t i
, page_count
= m_pages
.GetCount();
290 for (i
= 0; i
< page_count
; ++i
)
292 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
297 bool wxAuiTabContainer::SetActivePage(size_t page
)
299 if (page
>= m_pages
.GetCount())
302 return SetActivePage(m_pages
.Item(page
).window
);
305 int wxAuiTabContainer::GetActivePage() const
307 size_t i
, page_count
= m_pages
.GetCount();
308 for (i
= 0; i
< page_count
; ++i
)
310 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
318 wxWindow
* wxAuiTabContainer::GetWindowFromIdx(size_t idx
) const
320 if (idx
>= m_pages
.GetCount())
323 return m_pages
[idx
].window
;
326 int wxAuiTabContainer::GetIdxFromWindow(wxWindow
* wnd
) const
328 const size_t page_count
= m_pages
.GetCount();
329 for ( size_t i
= 0; i
< page_count
; ++i
)
331 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
332 if (page
.window
== wnd
)
338 wxAuiNotebookPage
& wxAuiTabContainer::GetPage(size_t idx
)
340 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
345 const wxAuiNotebookPage
& wxAuiTabContainer::GetPage(size_t idx
) const
347 wxASSERT_MSG(idx
< m_pages
.GetCount(), wxT("Invalid Page index"));
352 wxAuiNotebookPageArray
& wxAuiTabContainer::GetPages()
357 size_t wxAuiTabContainer::GetPageCount() const
359 return m_pages
.GetCount();
362 void wxAuiTabContainer::AddButton(int id
,
364 const wxBitmap
& normalBitmap
,
365 const wxBitmap
& disabledBitmap
)
367 wxAuiTabContainerButton button
;
369 button
.bitmap
= normalBitmap
;
370 button
.disBitmap
= disabledBitmap
;
371 button
.location
= location
;
372 button
.curState
= wxAUI_BUTTON_STATE_NORMAL
;
374 m_buttons
.Add(button
);
377 void wxAuiTabContainer::RemoveButton(int id
)
379 size_t i
, button_count
= m_buttons
.GetCount();
381 for (i
= 0; i
< button_count
; ++i
)
383 if (m_buttons
.Item(i
).id
== id
)
385 m_buttons
.RemoveAt(i
);
393 size_t wxAuiTabContainer::GetTabOffset() const
398 void wxAuiTabContainer::SetTabOffset(size_t offset
)
400 m_tabOffset
= offset
;
406 // Render() renders the tab catalog to the specified DC
407 // It is a virtual function and can be overridden to
408 // provide custom drawing capabilities
409 void wxAuiTabContainer::Render(wxDC
* raw_dc
, wxWindow
* wnd
)
411 if (!raw_dc
|| !raw_dc
->IsOk())
416 // use the same layout direction as the window DC uses to ensure that the
417 // text is rendered correctly
418 dc
.SetLayoutDirection(raw_dc
->GetLayoutDirection());
422 size_t page_count
= m_pages
.GetCount();
423 size_t button_count
= m_buttons
.GetCount();
425 // create off-screen bitmap
426 bmp
.Create(m_rect
.GetWidth(), m_rect
.GetHeight());
427 dc
.SelectObject(bmp
);
432 // find out if size of tabs is larger than can be
433 // afforded on screen
435 int visible_width
= 0;
436 for (i
= 0; i
< page_count
; ++i
)
438 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
440 // determine if a close button is on this tab
441 bool close_button
= false;
442 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
443 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
450 wxSize size
= m_art
->GetTabSize(dc
,
456 wxAUI_BUTTON_STATE_NORMAL
:
457 wxAUI_BUTTON_STATE_HIDDEN
,
460 if (i
+1 < page_count
)
461 total_width
+= x_extent
;
463 total_width
+= size
.x
;
465 if (i
>= m_tabOffset
)
467 if (i
+1 < page_count
)
468 visible_width
+= x_extent
;
470 visible_width
+= size
.x
;
474 if (total_width
> m_rect
.GetWidth() || m_tabOffset
!= 0)
476 // show left/right buttons
477 for (i
= 0; i
< button_count
; ++i
)
479 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
480 if (button
.id
== wxAUI_BUTTON_LEFT
||
481 button
.id
== wxAUI_BUTTON_RIGHT
)
483 button
.curState
&= ~wxAUI_BUTTON_STATE_HIDDEN
;
489 // hide left/right buttons
490 for (i
= 0; i
< button_count
; ++i
)
492 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
493 if (button
.id
== wxAUI_BUTTON_LEFT
||
494 button
.id
== wxAUI_BUTTON_RIGHT
)
496 button
.curState
|= wxAUI_BUTTON_STATE_HIDDEN
;
501 // determine whether left button should be enabled
502 for (i
= 0; i
< button_count
; ++i
)
504 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
505 if (button
.id
== wxAUI_BUTTON_LEFT
)
507 if (m_tabOffset
== 0)
508 button
.curState
|= wxAUI_BUTTON_STATE_DISABLED
;
510 button
.curState
&= ~wxAUI_BUTTON_STATE_DISABLED
;
512 if (button
.id
== wxAUI_BUTTON_RIGHT
)
514 if (visible_width
< m_rect
.GetWidth() - ((int)button_count
*16))
515 button
.curState
|= wxAUI_BUTTON_STATE_DISABLED
;
517 button
.curState
&= ~wxAUI_BUTTON_STATE_DISABLED
;
524 m_art
->DrawBackground(dc
, wnd
, m_rect
);
527 int left_buttons_width
= 0;
528 int right_buttons_width
= 0;
532 // draw the buttons on the right side
533 offset
= m_rect
.x
+ m_rect
.width
;
534 for (i
= 0; i
< button_count
; ++i
)
536 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
538 if (button
.location
!= wxRIGHT
)
540 if (button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
)
543 wxRect button_rect
= m_rect
;
545 button_rect
.SetWidth(offset
);
547 m_art
->DrawButton(dc
,
555 offset
-= button
.rect
.GetWidth();
556 right_buttons_width
+= button
.rect
.GetWidth();
563 // draw the buttons on the left side
565 for (i
= 0; i
< button_count
; ++i
)
567 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
569 if (button
.location
!= wxLEFT
)
571 if (button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
)
574 wxRect
button_rect(offset
, 1, 1000, m_rect
.height
);
576 m_art
->DrawButton(dc
,
584 offset
+= button
.rect
.GetWidth();
585 left_buttons_width
+= button
.rect
.GetWidth();
588 offset
= left_buttons_width
;
591 offset
+= m_art
->GetIndentSize();
594 // prepare the tab-close-button array
595 // make sure tab button entries which aren't used are marked as hidden
596 for (i
= page_count
; i
< m_tabCloseButtons
.GetCount(); ++i
)
597 m_tabCloseButtons
.Item(i
).curState
= wxAUI_BUTTON_STATE_HIDDEN
;
599 // make sure there are enough tab button entries to accommodate all tabs
600 while (m_tabCloseButtons
.GetCount() < page_count
)
602 wxAuiTabContainerButton tempbtn
;
603 tempbtn
.id
= wxAUI_BUTTON_CLOSE
;
604 tempbtn
.location
= wxCENTER
;
605 tempbtn
.curState
= wxAUI_BUTTON_STATE_HIDDEN
;
606 m_tabCloseButtons
.Add(tempbtn
);
610 // buttons before the tab offset must be set to hidden
611 for (i
= 0; i
< m_tabOffset
; ++i
)
613 m_tabCloseButtons
.Item(i
).curState
= wxAUI_BUTTON_STATE_HIDDEN
;
620 int active_offset
= 0;
624 wxRect rect
= m_rect
;
626 rect
.height
= m_rect
.height
;
628 for (i
= m_tabOffset
; i
< page_count
; ++i
)
630 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
631 wxAuiTabContainerButton
& tab_button
= m_tabCloseButtons
.Item(i
);
633 // determine if a close button is on this tab
634 if ((m_flags
& wxAUI_NB_CLOSE_ON_ALL_TABS
) != 0 ||
635 ((m_flags
& wxAUI_NB_CLOSE_ON_ACTIVE_TAB
) != 0 && page
.active
))
637 if (tab_button
.curState
== wxAUI_BUTTON_STATE_HIDDEN
)
639 tab_button
.id
= wxAUI_BUTTON_CLOSE
;
640 tab_button
.curState
= wxAUI_BUTTON_STATE_NORMAL
;
641 tab_button
.location
= wxCENTER
;
646 tab_button
.curState
= wxAUI_BUTTON_STATE_HIDDEN
;
650 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
667 active_offset
= offset
;
675 // make sure to deactivate buttons which are off the screen to the right
676 for (++i
; i
< m_tabCloseButtons
.GetCount(); ++i
)
678 m_tabCloseButtons
.Item(i
).curState
= wxAUI_BUTTON_STATE_HIDDEN
;
682 // draw the active tab again so it stands in the foreground
683 if (active
>= m_tabOffset
&& active
< m_pages
.GetCount())
685 wxAuiNotebookPage
& page
= m_pages
.Item(active
);
687 wxAuiTabContainerButton
& tab_button
= m_tabCloseButtons
.Item(active
);
689 rect
.x
= active_offset
;
701 raw_dc
->Blit(m_rect
.x
, m_rect
.y
,
702 m_rect
.GetWidth(), m_rect
.GetHeight(),
706 // Is the tab visible?
707 bool wxAuiTabContainer::IsTabVisible(int tabPage
, int tabOffset
, wxDC
* dc
, wxWindow
* wnd
)
709 if (!dc
|| !dc
->IsOk())
713 size_t page_count
= m_pages
.GetCount();
714 size_t button_count
= m_buttons
.GetCount();
716 // Hasn't been rendered yet; assume it's visible
717 if (m_tabCloseButtons
.GetCount() < page_count
)
720 // First check if both buttons are disabled - if so, there's no need to
721 // check further for visibility.
722 int arrowButtonVisibleCount
= 0;
723 for (i
= 0; i
< button_count
; ++i
)
725 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
726 if (button
.id
== wxAUI_BUTTON_LEFT
||
727 button
.id
== wxAUI_BUTTON_RIGHT
)
729 if ((button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
) == 0)
730 arrowButtonVisibleCount
++;
734 // Tab must be visible
735 if (arrowButtonVisibleCount
== 0)
738 // If tab is less than the given offset, it must be invisible by definition
739 if (tabPage
< tabOffset
)
743 int left_buttons_width
= 0;
744 int right_buttons_width
= 0;
748 // calculate size of the buttons on the right side
749 offset
= m_rect
.x
+ m_rect
.width
;
750 for (i
= 0; i
< button_count
; ++i
)
752 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
754 if (button
.location
!= wxRIGHT
)
756 if (button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
)
759 offset
-= button
.rect
.GetWidth();
760 right_buttons_width
+= button
.rect
.GetWidth();
765 // calculate size of the buttons on the left side
766 for (i
= 0; i
< button_count
; ++i
)
768 wxAuiTabContainerButton
& button
= m_buttons
.Item(button_count
- i
- 1);
770 if (button
.location
!= wxLEFT
)
772 if (button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
)
775 offset
+= button
.rect
.GetWidth();
776 left_buttons_width
+= button
.rect
.GetWidth();
779 offset
= left_buttons_width
;
782 offset
+= m_art
->GetIndentSize();
786 wxRect rect
= m_rect
;
788 rect
.height
= m_rect
.height
;
790 // See if the given page is visible at the given tab offset (effectively scroll position)
791 for (i
= tabOffset
; i
< page_count
; ++i
)
793 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
794 wxAuiTabContainerButton
& tab_button
= m_tabCloseButtons
.Item(i
);
797 rect
.width
= m_rect
.width
- right_buttons_width
- offset
- 2;
800 return false; // haven't found the tab, and we've run out of space, so return false
803 m_art
->GetTabSize(*dc
,
813 if (i
== (size_t) tabPage
)
815 // If not all of the tab is visible, and supposing there's space to display it all,
816 // we could do better so we return false.
817 if (((m_rect
.width
- right_buttons_width
- offset
- 2) <= 0) && ((m_rect
.width
- right_buttons_width
- left_buttons_width
) > x_extent
))
824 // Shouldn't really get here, but if it does, assume the tab is visible to prevent
825 // further looping in calling code.
829 // Make the tab visible if it wasn't already
830 void wxAuiTabContainer::MakeTabVisible(int tabPage
, wxWindow
* win
)
833 if (!IsTabVisible(tabPage
, GetTabOffset(), & dc
, win
))
836 for (i
= 0; i
< (int) m_pages
.GetCount(); i
++)
838 if (IsTabVisible(tabPage
, i
, & dc
, win
))
848 // TabHitTest() tests if a tab was hit, passing the window pointer
849 // back if that condition was fulfilled. The function returns
850 // true if a tab was hit, otherwise false
851 bool wxAuiTabContainer::TabHitTest(int x
, int y
, wxWindow
** hit
) const
853 if (!m_rect
.Contains(x
,y
))
856 wxAuiTabContainerButton
* btn
= NULL
;
857 if (ButtonHitTest(x
, y
, &btn
) && !(btn
->curState
& wxAUI_BUTTON_STATE_DISABLED
))
859 if (m_buttons
.Index(*btn
) != wxNOT_FOUND
)
863 size_t i
, page_count
= m_pages
.GetCount();
865 for (i
= m_tabOffset
; i
< page_count
; ++i
)
867 wxAuiNotebookPage
& page
= m_pages
.Item(i
);
868 if (page
.rect
.Contains(x
,y
))
879 // ButtonHitTest() tests if a button was hit. The function returns
880 // true if a button was hit, otherwise false
881 bool wxAuiTabContainer::ButtonHitTest(int x
, int y
,
882 wxAuiTabContainerButton
** hit
) const
884 if (!m_rect
.Contains(x
,y
))
887 size_t i
, button_count
;
890 button_count
= m_buttons
.GetCount();
891 for (i
= 0; i
< button_count
; ++i
)
893 wxAuiTabContainerButton
& button
= m_buttons
.Item(i
);
894 if (button
.rect
.Contains(x
,y
) &&
895 !(button
.curState
& wxAUI_BUTTON_STATE_HIDDEN
))
903 button_count
= m_tabCloseButtons
.GetCount();
904 for (i
= 0; i
< button_count
; ++i
)
906 wxAuiTabContainerButton
& button
= m_tabCloseButtons
.Item(i
);
907 if (button
.rect
.Contains(x
,y
) &&
908 !(button
.curState
& (wxAUI_BUTTON_STATE_HIDDEN
|
909 wxAUI_BUTTON_STATE_DISABLED
)))
922 // the utility function ShowWnd() is the same as show,
923 // except it handles wxAuiMDIChildFrame windows as well,
924 // as the Show() method on this class is "unplugged"
925 static void ShowWnd(wxWindow
* wnd
, bool show
)
928 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
930 wxAuiMDIChildFrame
* cf
= (wxAuiMDIChildFrame
*)wnd
;
941 // DoShowHide() this function shows the active window, then
942 // hides all of the other windows (in that order)
943 void wxAuiTabContainer::DoShowHide()
945 wxAuiNotebookPageArray
& pages
= GetPages();
946 size_t i
, page_count
= pages
.GetCount();
948 // show new active page first
949 for (i
= 0; i
< page_count
; ++i
)
951 wxAuiNotebookPage
& page
= pages
.Item(i
);
954 ShowWnd(page
.window
, true);
959 // hide all other pages
960 for (i
= 0; i
< page_count
; ++i
)
962 wxAuiNotebookPage
& page
= pages
.Item(i
);
964 ShowWnd(page
.window
, false);
973 // -- wxAuiTabCtrl class implementation --
977 BEGIN_EVENT_TABLE(wxAuiTabCtrl
, wxControl
)
978 EVT_PAINT(wxAuiTabCtrl::OnPaint
)
979 EVT_ERASE_BACKGROUND(wxAuiTabCtrl::OnEraseBackground
)
980 EVT_SIZE(wxAuiTabCtrl::OnSize
)
981 EVT_LEFT_DOWN(wxAuiTabCtrl::OnLeftDown
)
982 EVT_LEFT_DCLICK(wxAuiTabCtrl::OnLeftDClick
)
983 EVT_LEFT_UP(wxAuiTabCtrl::OnLeftUp
)
984 EVT_MIDDLE_DOWN(wxAuiTabCtrl::OnMiddleDown
)
985 EVT_MIDDLE_UP(wxAuiTabCtrl::OnMiddleUp
)
986 EVT_RIGHT_DOWN(wxAuiTabCtrl::OnRightDown
)
987 EVT_RIGHT_UP(wxAuiTabCtrl::OnRightUp
)
988 EVT_MOTION(wxAuiTabCtrl::OnMotion
)
989 EVT_LEAVE_WINDOW(wxAuiTabCtrl::OnLeaveWindow
)
990 EVT_AUINOTEBOOK_BUTTON(wxID_ANY
, wxAuiTabCtrl::OnButton
)
991 EVT_SET_FOCUS(wxAuiTabCtrl::OnSetFocus
)
992 EVT_KILL_FOCUS(wxAuiTabCtrl::OnKillFocus
)
993 EVT_CHAR(wxAuiTabCtrl::OnChar
)
994 EVT_MOUSE_CAPTURE_LOST(wxAuiTabCtrl::OnCaptureLost
)
998 wxAuiTabCtrl::wxAuiTabCtrl(wxWindow
* parent
,
1002 long style
) : wxControl(parent
, id
, pos
, size
, style
)
1004 SetName(wxT("wxAuiTabCtrl"));
1005 m_clickPt
= wxDefaultPosition
;
1006 m_isDragging
= false;
1007 m_hoverButton
= NULL
;
1008 m_pressedButton
= NULL
;
1011 wxAuiTabCtrl::~wxAuiTabCtrl()
1015 void wxAuiTabCtrl::OnPaint(wxPaintEvent
&)
1019 dc
.SetFont(GetFont());
1021 if (GetPageCount() > 0)
1025 void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
))
1029 void wxAuiTabCtrl::OnSize(wxSizeEvent
& evt
)
1031 wxSize s
= evt
.GetSize();
1032 wxRect
r(0, 0, s
.GetWidth(), s
.GetHeight());
1036 void wxAuiTabCtrl::OnLeftDown(wxMouseEvent
& evt
)
1039 m_clickPt
= wxDefaultPosition
;
1040 m_isDragging
= false;
1042 m_pressedButton
= NULL
;
1046 if (TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
1048 int new_selection
= GetIdxFromWindow(wnd
);
1050 // wxAuiNotebooks always want to receive this event
1051 // even if the tab is already active, because they may
1052 // have multiple tab controls
1053 if ((new_selection
!= GetActivePage() ||
1054 GetParent()->IsKindOf(CLASSINFO(wxAuiNotebook
))) && !m_hoverButton
)
1056 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
1057 e
.SetSelection(new_selection
);
1058 e
.SetOldSelection(GetActivePage());
1059 e
.SetEventObject(this);
1060 GetEventHandler()->ProcessEvent(e
);
1063 m_clickPt
.x
= evt
.m_x
;
1064 m_clickPt
.y
= evt
.m_y
;
1070 m_pressedButton
= m_hoverButton
;
1071 m_pressedButton
->curState
= wxAUI_BUTTON_STATE_PRESSED
;
1077 void wxAuiTabCtrl::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
1081 m_isDragging
= false;
1083 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG
, m_windowId
);
1084 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
1085 evt
.SetOldSelection(evt
.GetSelection());
1086 evt
.SetEventObject(this);
1087 GetEventHandler()->ProcessEvent(evt
);
1091 void wxAuiTabCtrl::OnLeftUp(wxMouseEvent
& evt
)
1093 if (GetCapture() == this)
1098 m_isDragging
= false;
1100 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
, m_windowId
);
1101 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
1102 evt
.SetOldSelection(evt
.GetSelection());
1103 evt
.SetEventObject(this);
1104 GetEventHandler()->ProcessEvent(evt
);
1109 if (m_pressedButton
)
1111 // make sure we're still clicking the button
1112 wxAuiTabContainerButton
* button
= NULL
;
1113 if (!ButtonHitTest(evt
.m_x
, evt
.m_y
, &button
) ||
1114 button
->curState
& wxAUI_BUTTON_STATE_DISABLED
)
1117 if (button
!= m_pressedButton
)
1119 m_pressedButton
= NULL
;
1126 if (!(m_pressedButton
->curState
& wxAUI_BUTTON_STATE_DISABLED
))
1128 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON
, m_windowId
);
1129 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
1130 evt
.SetInt(m_pressedButton
->id
);
1131 evt
.SetEventObject(this);
1132 GetEventHandler()->ProcessEvent(evt
);
1135 m_pressedButton
= NULL
;
1138 m_clickPt
= wxDefaultPosition
;
1139 m_isDragging
= false;
1143 void wxAuiTabCtrl::OnMiddleUp(wxMouseEvent
& evt
)
1145 wxWindow
* wnd
= NULL
;
1146 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
1149 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, m_windowId
);
1150 e
.SetEventObject(this);
1151 e
.SetSelection(GetIdxFromWindow(wnd
));
1152 GetEventHandler()->ProcessEvent(e
);
1155 void wxAuiTabCtrl::OnMiddleDown(wxMouseEvent
& evt
)
1157 wxWindow
* wnd
= NULL
;
1158 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
1161 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, m_windowId
);
1162 e
.SetEventObject(this);
1163 e
.SetSelection(GetIdxFromWindow(wnd
));
1164 GetEventHandler()->ProcessEvent(e
);
1167 void wxAuiTabCtrl::OnRightUp(wxMouseEvent
& evt
)
1169 wxWindow
* wnd
= NULL
;
1170 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
1173 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, m_windowId
);
1174 e
.SetEventObject(this);
1175 e
.SetSelection(GetIdxFromWindow(wnd
));
1176 GetEventHandler()->ProcessEvent(e
);
1179 void wxAuiTabCtrl::OnRightDown(wxMouseEvent
& evt
)
1181 wxWindow
* wnd
= NULL
;
1182 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
1185 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, m_windowId
);
1186 e
.SetEventObject(this);
1187 e
.SetSelection(GetIdxFromWindow(wnd
));
1188 GetEventHandler()->ProcessEvent(e
);
1191 void wxAuiTabCtrl::OnLeftDClick(wxMouseEvent
& evt
)
1194 wxAuiTabContainerButton
* button
;
1195 if (!TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
) && !ButtonHitTest(evt
.m_x
, evt
.m_y
, &button
))
1197 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, m_windowId
);
1198 e
.SetEventObject(this);
1199 GetEventHandler()->ProcessEvent(e
);
1203 void wxAuiTabCtrl::OnMotion(wxMouseEvent
& evt
)
1205 wxPoint pos
= evt
.GetPosition();
1207 // check if the mouse is hovering above a button
1208 wxAuiTabContainerButton
* button
;
1209 if (ButtonHitTest(pos
.x
, pos
.y
, &button
) && !(button
->curState
& wxAUI_BUTTON_STATE_DISABLED
))
1211 if (m_hoverButton
&& button
!= m_hoverButton
)
1213 m_hoverButton
->curState
= wxAUI_BUTTON_STATE_NORMAL
;
1214 m_hoverButton
= NULL
;
1219 if (button
->curState
!= wxAUI_BUTTON_STATE_HOVER
)
1221 button
->curState
= wxAUI_BUTTON_STATE_HOVER
;
1225 m_hoverButton
= button
;
1233 m_hoverButton
->curState
= wxAUI_BUTTON_STATE_NORMAL
;
1234 m_hoverButton
= NULL
;
1240 wxWindow
* wnd
= NULL
;
1241 if (evt
.Moving() && TabHitTest(evt
.m_x
, evt
.m_y
, &wnd
))
1243 wxString
tooltip(m_pages
[GetIdxFromWindow(wnd
)].tooltip
);
1245 // If the text changes, set it else, keep old, to avoid
1246 // 'moving tooltip' effect
1247 if (GetToolTipText() != tooltip
)
1248 SetToolTip(tooltip
);
1253 if (!evt
.LeftIsDown() || m_clickPt
== wxDefaultPosition
)
1258 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
, m_windowId
);
1259 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
1260 evt
.SetOldSelection(evt
.GetSelection());
1261 evt
.SetEventObject(this);
1262 GetEventHandler()->ProcessEvent(evt
);
1267 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
1268 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
1270 if (abs(pos
.x
- m_clickPt
.x
) > drag_x_threshold
||
1271 abs(pos
.y
- m_clickPt
.y
) > drag_y_threshold
)
1273 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
, m_windowId
);
1274 evt
.SetSelection(GetIdxFromWindow(m_clickTab
));
1275 evt
.SetOldSelection(evt
.GetSelection());
1276 evt
.SetEventObject(this);
1277 GetEventHandler()->ProcessEvent(evt
);
1279 m_isDragging
= true;
1283 void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
1287 m_hoverButton
->curState
= wxAUI_BUTTON_STATE_NORMAL
;
1288 m_hoverButton
= NULL
;
1294 void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent
& event
)
1296 int button
= event
.GetInt();
1298 if (button
== wxAUI_BUTTON_LEFT
|| button
== wxAUI_BUTTON_RIGHT
)
1300 if (button
== wxAUI_BUTTON_LEFT
)
1302 if (GetTabOffset() > 0)
1304 SetTabOffset(GetTabOffset()-1);
1311 SetTabOffset(GetTabOffset()+1);
1316 else if (button
== wxAUI_BUTTON_WINDOWLIST
)
1318 int idx
= GetArtProvider()->ShowDropDown(this, m_pages
, GetActivePage());
1322 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
1323 e
.SetSelection(idx
);
1324 e
.SetOldSelection(GetActivePage());
1325 e
.SetEventObject(this);
1326 GetEventHandler()->ProcessEvent(e
);
1335 void wxAuiTabCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
1340 void wxAuiTabCtrl::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
1345 void wxAuiTabCtrl::OnChar(wxKeyEvent
& event
)
1347 if (GetActivePage() == -1)
1353 // We can't leave tab processing to the system; on Windows, tabs and keys
1354 // get eaten by the system and not processed properly if we specify both
1355 // wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL,
1356 // we don't key arrow key events.
1358 int key
= event
.GetKeyCode();
1360 if (key
== WXK_NUMPAD_PAGEUP
)
1362 if (key
== WXK_NUMPAD_PAGEDOWN
)
1364 if (key
== WXK_NUMPAD_HOME
)
1366 if (key
== WXK_NUMPAD_END
)
1368 if (key
== WXK_NUMPAD_LEFT
)
1370 if (key
== WXK_NUMPAD_RIGHT
)
1373 if (key
== WXK_TAB
|| key
== WXK_PAGEUP
|| key
== WXK_PAGEDOWN
)
1375 bool bCtrlDown
= event
.ControlDown();
1376 bool bShiftDown
= event
.ShiftDown();
1378 bool bForward
= (key
== WXK_TAB
&& !bShiftDown
) || (key
== WXK_PAGEDOWN
);
1379 bool bWindowChange
= (key
== WXK_PAGEUP
) || (key
== WXK_PAGEDOWN
) || bCtrlDown
;
1380 bool bFromTab
= (key
== WXK_TAB
);
1382 wxAuiNotebook
* nb
= wxDynamicCast(GetParent(), wxAuiNotebook
);
1389 wxNavigationKeyEvent keyEvent
;
1390 keyEvent
.SetDirection(bForward
);
1391 keyEvent
.SetWindowChange(bWindowChange
);
1392 keyEvent
.SetFromTab(bFromTab
);
1393 keyEvent
.SetEventObject(nb
);
1395 if (!nb
->GetEventHandler()->ProcessEvent(keyEvent
))
1397 // Not processed? Do an explicit tab into the page.
1398 wxWindow
* win
= GetWindowFromIdx(GetActivePage());
1405 if (m_pages
.GetCount() < 2)
1413 int forwardKey
, backwardKey
;
1414 if (GetLayoutDirection() == wxLayout_RightToLeft
)
1416 forwardKey
= WXK_LEFT
;
1417 backwardKey
= WXK_RIGHT
;
1421 forwardKey
= WXK_RIGHT
;
1422 backwardKey
= WXK_LEFT
;
1425 if (key
== forwardKey
)
1427 if (m_pages
.GetCount() > 1)
1429 if (GetActivePage() == -1)
1431 else if (GetActivePage() < (int) (m_pages
.GetCount() - 1))
1432 newPage
= GetActivePage() + 1;
1435 else if (key
== backwardKey
)
1437 if (m_pages
.GetCount() > 1)
1439 if (GetActivePage() == -1)
1440 newPage
= (int) (m_pages
.GetCount() - 1);
1441 else if (GetActivePage() > 0)
1442 newPage
= GetActivePage() - 1;
1445 else if (key
== WXK_HOME
)
1449 else if (key
== WXK_END
)
1451 newPage
= (int) (m_pages
.GetCount() - 1);
1458 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
1459 e
.SetSelection(newPage
);
1460 e
.SetOldSelection(newPage
);
1461 e
.SetEventObject(this);
1462 this->GetEventHandler()->ProcessEvent(e
);
1468 // wxTabFrame is an interesting case. It's important that all child pages
1469 // of the multi-notebook control are all actually children of that control
1470 // (and not grandchildren). wxTabFrame facilitates this. There is one
1471 // instance of wxTabFrame for each tab control inside the multi-notebook.
1472 // It's important to know that wxTabFrame is not a real window, but it merely
1473 // used to capture the dimensions/positioning of the internal tab control and
1474 // it's managed page windows
1476 class wxTabFrame
: public wxWindow
1483 m_rect
= wxRect(0,0,200,200);
1484 m_tabCtrlHeight
= 20;
1492 void SetTabCtrlHeight(int h
)
1494 m_tabCtrlHeight
= h
;
1498 void DoSetSize(int x
, int y
,
1499 int width
, int height
,
1500 int WXUNUSED(sizeFlags
= wxSIZE_AUTO
))
1502 m_rect
= wxRect(x
, y
, width
, height
);
1506 void DoGetClientSize(int* x
, int* y
) const
1513 bool Show( bool WXUNUSED(show
= true) ) { return false; }
1520 if (m_tabs
->IsFrozen() || m_tabs
->GetParent()->IsFrozen())
1523 m_tab_rect
= wxRect(m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tabCtrlHeight
);
1524 if (m_tabs
->GetFlags() & wxAUI_NB_BOTTOM
)
1526 m_tab_rect
= wxRect (m_rect
.x
, m_rect
.y
+ m_rect
.height
- m_tabCtrlHeight
, m_rect
.width
, m_tabCtrlHeight
);
1527 m_tabs
->SetSize (m_rect
.x
, m_rect
.y
+ m_rect
.height
- m_tabCtrlHeight
, m_rect
.width
, m_tabCtrlHeight
);
1528 m_tabs
->SetRect (wxRect(0, 0, m_rect
.width
, m_tabCtrlHeight
));
1530 else //TODO: if (GetFlags() & wxAUI_NB_TOP)
1532 m_tab_rect
= wxRect (m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tabCtrlHeight
);
1533 m_tabs
->SetSize (m_rect
.x
, m_rect
.y
, m_rect
.width
, m_tabCtrlHeight
);
1534 m_tabs
->SetRect (wxRect(0, 0, m_rect
.width
, m_tabCtrlHeight
));
1536 // TODO: else if (GetFlags() & wxAUI_NB_LEFT){}
1537 // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){}
1542 wxAuiNotebookPageArray
& pages
= m_tabs
->GetPages();
1543 size_t i
, page_count
= pages
.GetCount();
1545 for (i
= 0; i
< page_count
; ++i
)
1547 int height
= m_rect
.height
- m_tabCtrlHeight
;
1550 // avoid passing negative height to wxWindow::SetSize(), this
1551 // results in assert failures/GTK+ warnings
1555 wxAuiNotebookPage
& page
= pages
.Item(i
);
1556 if (m_tabs
->GetFlags() & wxAUI_NB_BOTTOM
)
1558 page
.window
->SetSize(m_rect
.x
, m_rect
.y
, m_rect
.width
, height
);
1560 else //TODO: if (GetFlags() & wxAUI_NB_TOP)
1562 page
.window
->SetSize(m_rect
.x
, m_rect
.y
+ m_tabCtrlHeight
,
1563 m_rect
.width
, height
);
1565 // TODO: else if (GetFlags() & wxAUI_NB_LEFT){}
1566 // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){}
1569 if (page
.window
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
1571 wxAuiMDIChildFrame
* wnd
= (wxAuiMDIChildFrame
*)page
.window
;
1572 wnd
->ApplyMDIChildFrameRect();
1579 void DoGetSize(int* x
, int* y
) const
1582 *x
= m_rect
.GetWidth();
1584 *y
= m_rect
.GetHeight();
1595 wxAuiTabCtrl
* m_tabs
;
1596 int m_tabCtrlHeight
;
1600 const int wxAuiBaseTabCtrlId
= 5380;
1603 // -- wxAuiNotebook class implementation --
1605 #define EVT_AUI_RANGE(id1, id2, event, func) \
1606 wx__DECLARE_EVT2(event, id1, id2, wxAuiNotebookEventHandler(func))
1608 BEGIN_EVENT_TABLE(wxAuiNotebook
, wxControl
)
1609 EVT_SIZE(wxAuiNotebook::OnSize
)
1610 EVT_CHILD_FOCUS(wxAuiNotebook::OnChildFocusNotebook
)
1611 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1612 wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
,
1613 wxAuiNotebook::OnTabClicked
)
1614 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1615 wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG
,
1616 wxAuiNotebook::OnTabBeginDrag
)
1617 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1618 wxEVT_COMMAND_AUINOTEBOOK_END_DRAG
,
1619 wxAuiNotebook::OnTabEndDrag
)
1620 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1621 wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG
,
1622 wxAuiNotebook::OnTabCancelDrag
)
1623 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1624 wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION
,
1625 wxAuiNotebook::OnTabDragMotion
)
1626 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1627 wxEVT_COMMAND_AUINOTEBOOK_BUTTON
,
1628 wxAuiNotebook::OnTabButton
)
1629 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1630 wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
,
1631 wxAuiNotebook::OnTabMiddleDown
)
1632 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1633 wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
,
1634 wxAuiNotebook::OnTabMiddleUp
)
1635 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1636 wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
,
1637 wxAuiNotebook::OnTabRightDown
)
1638 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1639 wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
,
1640 wxAuiNotebook::OnTabRightUp
)
1641 EVT_AUI_RANGE(wxAuiBaseTabCtrlId
, wxAuiBaseTabCtrlId
+500,
1642 wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
,
1643 wxAuiNotebook::OnTabBgDClick
)
1644 EVT_NAVIGATION_KEY(wxAuiNotebook::OnNavigationKeyNotebook
)
1647 void wxAuiNotebook::Init()
1650 m_tabIdCounter
= wxAuiBaseTabCtrlId
;
1652 m_tabCtrlHeight
= 20;
1653 m_requestedBmpSize
= wxDefaultSize
;
1654 m_requestedTabCtrlHeight
= -1;
1657 bool wxAuiNotebook::Create(wxWindow
* parent
,
1663 if (!wxControl::Create(parent
, id
, pos
, size
, style
))
1666 InitNotebook(style
);
1671 // InitNotebook() contains common initialization
1672 // code called by all constructors
1673 void wxAuiNotebook::InitNotebook(long style
)
1675 SetName(wxT("wxAuiNotebook"));
1677 m_tabIdCounter
= wxAuiBaseTabCtrlId
;
1679 m_flags
= (unsigned int)style
;
1680 m_tabCtrlHeight
= 20;
1682 m_normalFont
= *wxNORMAL_FONT
;
1683 m_selectedFont
= *wxNORMAL_FONT
;
1684 m_selectedFont
.SetWeight(wxBOLD
);
1686 SetArtProvider(new wxAuiDefaultTabArt
);
1688 m_dummyWnd
= new wxWindow(this, wxID_ANY
, wxPoint(0,0), wxSize(0,0));
1689 m_dummyWnd
->SetSize(200, 200);
1690 m_dummyWnd
->Show(false);
1692 m_mgr
.SetManagedWindow(this);
1693 m_mgr
.SetFlags(wxAUI_MGR_DEFAULT
);
1694 m_mgr
.SetDockSizeConstraint(1.0, 1.0); // no dock size constraint
1696 m_mgr
.AddPane(m_dummyWnd
,
1697 wxAuiPaneInfo().Name(wxT("dummy")).Bottom().CaptionVisible(false).Show(false));
1702 wxAuiNotebook::~wxAuiNotebook()
1704 // Indicate we're deleting pages
1707 while ( GetPageCount() > 0 )
1713 void wxAuiNotebook::SetArtProvider(wxAuiTabArt
* art
)
1715 m_tabs
.SetArtProvider(art
);
1717 // Update the height and do nothing else if it did something but otherwise
1718 // (i.e. if the new art provider uses the same height as the old one) we
1719 // need to manually set the art provider for all tabs ourselves.
1720 if ( !UpdateTabCtrlHeight() )
1722 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
1723 const size_t pane_count
= all_panes
.GetCount();
1724 for (size_t i
= 0; i
< pane_count
; ++i
)
1726 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
1727 if (pane
.name
== wxT("dummy"))
1729 wxTabFrame
* tab_frame
= (wxTabFrame
*)pane
.window
;
1730 wxAuiTabCtrl
* tabctrl
= tab_frame
->m_tabs
;
1731 tabctrl
->SetArtProvider(art
->Clone());
1736 // SetTabCtrlHeight() is the highest-level override of the
1737 // tab height. A call to this function effectively enforces a
1738 // specified tab ctrl height, overriding all other considerations,
1739 // such as text or bitmap height. It overrides any call to
1740 // SetUniformBitmapSize(). Specifying a height of -1 reverts
1741 // any previous call and returns to the default behaviour
1743 void wxAuiNotebook::SetTabCtrlHeight(int height
)
1745 m_requestedTabCtrlHeight
= height
;
1747 // if window is already initialized, recalculate the tab height
1750 UpdateTabCtrlHeight();
1755 // SetUniformBitmapSize() ensures that all tabs will have
1756 // the same height, even if some tabs don't have bitmaps
1757 // Passing wxDefaultSize to this function will instruct
1758 // the control to use dynamic tab height-- so when a tab
1759 // with a large bitmap is added, the tab ctrl's height will
1760 // automatically increase to accommodate the bitmap
1762 void wxAuiNotebook::SetUniformBitmapSize(const wxSize
& size
)
1764 m_requestedBmpSize
= size
;
1766 // if window is already initialized, recalculate the tab height
1769 UpdateTabCtrlHeight();
1773 // UpdateTabCtrlHeight() does the actual tab resizing. It's meant
1774 // to be used internally
1775 bool wxAuiNotebook::UpdateTabCtrlHeight()
1777 // get the tab ctrl height we will use
1778 int height
= CalculateTabCtrlHeight();
1780 // if the tab control height needs to change, update
1781 // all of our tab controls with the new height
1782 if (m_tabCtrlHeight
== height
)
1785 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
1787 m_tabCtrlHeight
= height
;
1789 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
1790 size_t i
, pane_count
= all_panes
.GetCount();
1791 for (i
= 0; i
< pane_count
; ++i
)
1793 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
1794 if (pane
.name
== wxT("dummy"))
1796 wxTabFrame
* tab_frame
= (wxTabFrame
*)pane
.window
;
1797 wxAuiTabCtrl
* tabctrl
= tab_frame
->m_tabs
;
1798 tab_frame
->SetTabCtrlHeight(m_tabCtrlHeight
);
1799 tabctrl
->SetArtProvider(art
->Clone());
1800 tab_frame
->DoSizing();
1806 void wxAuiNotebook::UpdateHintWindowSize()
1808 wxSize size
= CalculateNewSplitSize();
1810 // the placeholder hint window should be set to this size
1811 wxAuiPaneInfo
& info
= m_mgr
.GetPane(wxT("dummy"));
1815 info
.BestSize(size
);
1816 m_dummyWnd
->SetSize(size
);
1821 // calculates the size of the new split
1822 wxSize
wxAuiNotebook::CalculateNewSplitSize()
1824 // count number of tab controls
1825 int tab_ctrl_count
= 0;
1826 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
1827 size_t i
, pane_count
= all_panes
.GetCount();
1828 for (i
= 0; i
< pane_count
; ++i
)
1830 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
1831 if (pane
.name
== wxT("dummy"))
1836 wxSize new_split_size
;
1838 // if there is only one tab control, the first split
1839 // should happen around the middle
1840 if (tab_ctrl_count
< 2)
1842 new_split_size
= GetClientSize();
1843 new_split_size
.x
/= 2;
1844 new_split_size
.y
/= 2;
1848 // this is in place of a more complicated calculation
1849 // that needs to be implemented
1850 new_split_size
= wxSize(180,180);
1853 return new_split_size
;
1856 int wxAuiNotebook::CalculateTabCtrlHeight()
1858 // if a fixed tab ctrl height is specified,
1859 // just return that instead of calculating a
1861 if (m_requestedTabCtrlHeight
!= -1)
1862 return m_requestedTabCtrlHeight
;
1864 // find out new best tab height
1865 wxAuiTabArt
* art
= m_tabs
.GetArtProvider();
1867 return art
->GetBestTabCtrlSize(this,
1869 m_requestedBmpSize
);
1873 wxAuiTabArt
* wxAuiNotebook::GetArtProvider() const
1875 return m_tabs
.GetArtProvider();
1878 void wxAuiNotebook::SetWindowStyleFlag(long style
)
1880 wxControl::SetWindowStyleFlag(style
);
1882 m_flags
= (unsigned int)style
;
1884 // if the control is already initialized
1885 if (m_mgr
.GetManagedWindow() == (wxWindow
*)this)
1887 // let all of the tab children know about the new style
1889 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
1890 size_t i
, pane_count
= all_panes
.GetCount();
1891 for (i
= 0; i
< pane_count
; ++i
)
1893 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
1894 if (pane
.name
== wxT("dummy"))
1896 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
1897 wxAuiTabCtrl
* tabctrl
= tabframe
->m_tabs
;
1898 tabctrl
->SetFlags(m_flags
);
1899 tabframe
->DoSizing();
1907 bool wxAuiNotebook::AddPage(wxWindow
* page
,
1908 const wxString
& caption
,
1910 const wxBitmap
& bitmap
)
1912 return InsertPage(GetPageCount(), page
, caption
, select
, bitmap
);
1915 bool wxAuiNotebook::InsertPage(size_t page_idx
,
1917 const wxString
& caption
,
1919 const wxBitmap
& bitmap
)
1921 wxASSERT_MSG(page
, wxT("page pointer must be non-NULL"));
1925 page
->Reparent(this);
1927 wxAuiNotebookPage info
;
1929 info
.caption
= caption
;
1930 info
.bitmap
= bitmap
;
1931 info
.active
= false;
1933 // if there are currently no tabs, the first added
1934 // tab must be active
1935 if (m_tabs
.GetPageCount() == 0)
1938 m_tabs
.InsertPage(page
, info
, page_idx
);
1940 // if that was the first page added, even if
1941 // select is false, it must become the "current page"
1942 // (though no select events will be fired)
1943 if (!select
&& m_tabs
.GetPageCount() == 1)
1945 //m_curPage = GetPageIndex(page);
1947 wxAuiTabCtrl
* active_tabctrl
= GetActiveTabCtrl();
1948 if (page_idx
>= active_tabctrl
->GetPageCount())
1949 active_tabctrl
->AddPage(page
, info
);
1951 active_tabctrl
->InsertPage(page
, info
, page_idx
);
1953 UpdateTabCtrlHeight();
1955 active_tabctrl
->DoShowHide();
1957 // adjust selected index
1958 if(m_curPage
>= (int) page_idx
)
1963 SetSelectionToWindow(page
);
1970 // DeletePage() removes a tab from the multi-notebook,
1971 // and destroys the window as well
1972 bool wxAuiNotebook::DeletePage(size_t page_idx
)
1974 if (page_idx
>= m_tabs
.GetPageCount())
1977 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
1979 // hide the window in advance, as this will
1981 ShowWnd(wnd
, false);
1983 if (!RemovePage(page_idx
))
1987 // actually destroy the window now
1988 if (wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
1990 // delete the child frame with pending delete, as is
1991 // customary with frame windows
1992 if (!wxPendingDelete
.Member(wnd
))
1993 wxPendingDelete
.Append(wnd
);
2006 // RemovePage() removes a tab from the multi-notebook,
2007 // but does not destroy the window
2008 bool wxAuiNotebook::RemovePage(size_t page_idx
)
2010 // save active window pointer
2011 wxWindow
* active_wnd
= NULL
;
2013 active_wnd
= m_tabs
.GetWindowFromIdx(m_curPage
);
2015 // save pointer of window being deleted
2016 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(page_idx
);
2017 wxWindow
* new_active
= NULL
;
2019 // make sure we found the page
2023 // find out which onscreen tab ctrl owns this tab
2026 if (!FindTab(wnd
, &ctrl
, &ctrl_idx
))
2029 bool is_curpage
= (m_curPage
== (int)page_idx
);
2030 bool is_active_in_split
= ctrl
->GetPage(ctrl_idx
).active
;
2033 // remove the tab from main catalog
2034 if (!m_tabs
.RemovePage(wnd
))
2037 // remove the tab from the onscreen tab ctrl
2038 ctrl
->RemovePage(wnd
);
2040 if (is_active_in_split
)
2042 int ctrl_new_page_count
= (int)ctrl
->GetPageCount();
2044 if (ctrl_idx
>= ctrl_new_page_count
)
2045 ctrl_idx
= ctrl_new_page_count
-1;
2047 if (ctrl_idx
>= 0 && ctrl_idx
< (int)ctrl
->GetPageCount())
2049 // set new page as active in the tab split
2050 ctrl
->SetActivePage(ctrl_idx
);
2052 // if the page deleted was the current page for the
2053 // entire tab control, then record the window
2054 // pointer of the new active page for activation
2057 new_active
= ctrl
->GetWindowFromIdx(ctrl_idx
);
2063 // we are not deleting the active page, so keep it the same
2064 new_active
= active_wnd
;
2070 // we haven't yet found a new page to active,
2071 // so select the next page from the main tab
2074 if (page_idx
< m_tabs
.GetPageCount())
2076 new_active
= m_tabs
.GetPage(page_idx
).window
;
2079 if (!new_active
&& m_tabs
.GetPageCount() > 0)
2081 new_active
= m_tabs
.GetPage(0).window
;
2086 RemoveEmptyTabFrames();
2088 m_curPage
= wxNOT_FOUND
;
2090 // set new active pane unless we're being destroyed anyhow
2091 if (new_active
&& !m_isBeingDeleted
)
2092 SetSelectionToWindow(new_active
);
2097 // GetPageIndex() returns the index of the page, or -1 if the
2098 // page could not be located in the notebook
2099 int wxAuiNotebook::GetPageIndex(wxWindow
* page_wnd
) const
2101 return m_tabs
.GetIdxFromWindow(page_wnd
);
2106 // SetPageText() changes the tab caption of the specified page
2107 bool wxAuiNotebook::SetPageText(size_t page_idx
, const wxString
& text
)
2109 if (page_idx
>= m_tabs
.GetPageCount())
2112 // update our own tab catalog
2113 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2114 page_info
.caption
= text
;
2116 // update what's on screen
2119 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
2121 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
2122 info
.caption
= text
;
2130 // returns the page caption
2131 wxString
wxAuiNotebook::GetPageText(size_t page_idx
) const
2133 if (page_idx
>= m_tabs
.GetPageCount())
2134 return wxEmptyString
;
2136 // update our own tab catalog
2137 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2138 return page_info
.caption
;
2141 bool wxAuiNotebook::SetPageToolTip(size_t page_idx
, const wxString
& text
)
2143 if (page_idx
>= m_tabs
.GetPageCount())
2146 // update our own tab catalog
2147 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2148 page_info
.tooltip
= text
;
2152 if (!FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
2155 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
2156 info
.tooltip
= text
;
2158 // NB: we don't update the tooltip if it is already being displayed, it
2159 // typically never happens, no need to code that
2163 wxString
wxAuiNotebook::GetPageToolTip(size_t page_idx
) const
2165 if (page_idx
>= m_tabs
.GetPageCount())
2168 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2169 return page_info
.tooltip
;
2172 bool wxAuiNotebook::SetPageBitmap(size_t page_idx
, const wxBitmap
& bitmap
)
2174 if (page_idx
>= m_tabs
.GetPageCount())
2177 // update our own tab catalog
2178 wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2179 page_info
.bitmap
= bitmap
;
2181 // tab height might have changed
2182 UpdateTabCtrlHeight();
2184 // update what's on screen
2187 if (FindTab(page_info
.window
, &ctrl
, &ctrl_idx
))
2189 wxAuiNotebookPage
& info
= ctrl
->GetPage(ctrl_idx
);
2190 info
.bitmap
= bitmap
;
2198 // returns the page bitmap
2199 wxBitmap
wxAuiNotebook::GetPageBitmap(size_t page_idx
) const
2201 if (page_idx
>= m_tabs
.GetPageCount())
2204 // update our own tab catalog
2205 const wxAuiNotebookPage
& page_info
= m_tabs
.GetPage(page_idx
);
2206 return page_info
.bitmap
;
2209 // GetSelection() returns the index of the currently active page
2210 int wxAuiNotebook::GetSelection() const
2215 // SetSelection() sets the currently active page
2216 int wxAuiNotebook::SetSelection(size_t new_page
)
2218 return DoModifySelection(new_page
, true);
2221 void wxAuiNotebook::SetSelectionToWindow(wxWindow
*win
)
2223 const int idx
= m_tabs
.GetIdxFromWindow(win
);
2224 wxCHECK_RET( idx
!= wxNOT_FOUND
, wxT("invalid notebook page") );
2227 // since a tab was clicked, let the parent know that we received
2228 // the focus, even if we will assign that focus immediately
2229 // to the child tab in the SetSelection call below
2230 // (the child focus event will also let wxAuiManager, if any,
2231 // know that the notebook control has been activated)
2233 wxWindow
* parent
= GetParent();
2236 wxChildFocusEvent
eventFocus(this);
2237 parent
->GetEventHandler()->ProcessEvent(eventFocus
);
2244 // GetPageCount() returns the total number of
2245 // pages managed by the multi-notebook
2246 size_t wxAuiNotebook::GetPageCount() const
2248 return m_tabs
.GetPageCount();
2251 // GetPage() returns the wxWindow pointer of the
2253 wxWindow
* wxAuiNotebook::GetPage(size_t page_idx
) const
2255 wxASSERT(page_idx
< m_tabs
.GetPageCount());
2257 return m_tabs
.GetWindowFromIdx(page_idx
);
2260 // DoSizing() performs all sizing operations in each tab control
2261 void wxAuiNotebook::DoSizing()
2263 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2264 size_t i
, pane_count
= all_panes
.GetCount();
2265 for (i
= 0; i
< pane_count
; ++i
)
2267 if (all_panes
.Item(i
).name
== wxT("dummy"))
2270 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2271 tabframe
->DoSizing();
2275 // GetActiveTabCtrl() returns the active tab control. It is
2276 // called to determine which control gets new windows being added
2277 wxAuiTabCtrl
* wxAuiNotebook::GetActiveTabCtrl()
2279 if (m_curPage
>= 0 && m_curPage
< (int)m_tabs
.GetPageCount())
2284 // find the tab ctrl with the current page
2285 if (FindTab(m_tabs
.GetPage(m_curPage
).window
,
2292 // no current page, just find the first tab ctrl
2293 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2294 size_t i
, pane_count
= all_panes
.GetCount();
2295 for (i
= 0; i
< pane_count
; ++i
)
2297 if (all_panes
.Item(i
).name
== wxT("dummy"))
2300 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2301 return tabframe
->m_tabs
;
2304 // If there is no tabframe at all, create one
2305 wxTabFrame
* tabframe
= new wxTabFrame
;
2306 tabframe
->SetTabCtrlHeight(m_tabCtrlHeight
);
2307 tabframe
->m_tabs
= new wxAuiTabCtrl(this,
2311 wxNO_BORDER
|wxWANTS_CHARS
);
2312 tabframe
->m_tabs
->SetFlags(m_flags
);
2313 tabframe
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
2314 m_mgr
.AddPane(tabframe
,
2315 wxAuiPaneInfo().Center().CaptionVisible(false));
2319 return tabframe
->m_tabs
;
2322 // FindTab() finds the tab control that currently contains the window as well
2323 // as the index of the window in the tab control. It returns true if the
2324 // window was found, otherwise false.
2325 bool wxAuiNotebook::FindTab(wxWindow
* page
, wxAuiTabCtrl
** ctrl
, int* idx
)
2327 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2328 size_t i
, pane_count
= all_panes
.GetCount();
2329 for (i
= 0; i
< pane_count
; ++i
)
2331 if (all_panes
.Item(i
).name
== wxT("dummy"))
2334 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2336 int page_idx
= tabframe
->m_tabs
->GetIdxFromWindow(page
);
2339 *ctrl
= tabframe
->m_tabs
;
2348 void wxAuiNotebook::Split(size_t page
, int direction
)
2350 wxSize cli_size
= GetClientSize();
2352 // get the page's window pointer
2353 wxWindow
* wnd
= GetPage(page
);
2357 // notebooks with 1 or less pages can't be split
2358 if (GetPageCount() < 2)
2361 // find out which tab control the page currently belongs to
2362 wxAuiTabCtrl
*src_tabs
, *dest_tabs
;
2365 if (!FindTab(wnd
, &src_tabs
, &src_idx
))
2367 if (!src_tabs
|| src_idx
== -1)
2370 // choose a split size
2372 if (GetPageCount() > 2)
2374 split_size
= CalculateNewSplitSize();
2378 // because there are two panes, always split them
2380 split_size
= GetClientSize();
2386 // create a new tab frame
2387 wxTabFrame
* new_tabs
= new wxTabFrame
;
2388 new_tabs
->m_rect
= wxRect(wxPoint(0,0), split_size
);
2389 new_tabs
->SetTabCtrlHeight(m_tabCtrlHeight
);
2390 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
2394 wxNO_BORDER
|wxWANTS_CHARS
);
2395 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
2396 new_tabs
->m_tabs
->SetFlags(m_flags
);
2397 dest_tabs
= new_tabs
->m_tabs
;
2399 // create a pane info structure with the information
2400 // about where the pane should be added
2401 wxAuiPaneInfo paneInfo
= wxAuiPaneInfo().Bottom().CaptionVisible(false);
2404 if (direction
== wxLEFT
)
2407 mouse_pt
= wxPoint(0, cli_size
.y
/2);
2409 else if (direction
== wxRIGHT
)
2412 mouse_pt
= wxPoint(cli_size
.x
, cli_size
.y
/2);
2414 else if (direction
== wxTOP
)
2417 mouse_pt
= wxPoint(cli_size
.x
/2, 0);
2419 else if (direction
== wxBOTTOM
)
2422 mouse_pt
= wxPoint(cli_size
.x
/2, cli_size
.y
);
2425 m_mgr
.AddPane(new_tabs
, paneInfo
, mouse_pt
);
2428 // remove the page from the source tabs
2429 wxAuiNotebookPage page_info
= src_tabs
->GetPage(src_idx
);
2430 page_info
.active
= false;
2431 src_tabs
->RemovePage(page_info
.window
);
2432 if (src_tabs
->GetPageCount() > 0)
2434 src_tabs
->SetActivePage((size_t)0);
2435 src_tabs
->DoShowHide();
2436 src_tabs
->Refresh();
2440 // add the page to the destination tabs
2441 dest_tabs
->InsertPage(page_info
.window
, page_info
, 0);
2443 if (src_tabs
->GetPageCount() == 0)
2445 RemoveEmptyTabFrames();
2449 dest_tabs
->DoShowHide();
2450 dest_tabs
->Refresh();
2452 // force the set selection function reset the selection
2455 // set the active page to the one we just split off
2456 SetSelectionToPage(page_info
);
2458 UpdateHintWindowSize();
2462 void wxAuiNotebook::OnSize(wxSizeEvent
& evt
)
2464 UpdateHintWindowSize();
2469 void wxAuiNotebook::OnTabClicked(wxAuiNotebookEvent
& evt
)
2471 wxAuiTabCtrl
* ctrl
= (wxAuiTabCtrl
*)evt
.GetEventObject();
2472 wxASSERT(ctrl
!= NULL
);
2474 wxWindow
* wnd
= ctrl
->GetWindowFromIdx(evt
.GetSelection());
2475 wxASSERT(wnd
!= NULL
);
2477 SetSelectionToWindow(wnd
);
2480 void wxAuiNotebook::OnTabBgDClick(wxAuiNotebookEvent
& WXUNUSED(evt
))
2482 // notify owner that the tabbar background has been double-clicked
2483 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK
, m_windowId
);
2484 e
.SetEventObject(this);
2485 GetEventHandler()->ProcessEvent(e
);
2488 void wxAuiNotebook::OnTabBeginDrag(wxAuiNotebookEvent
&)
2493 void wxAuiNotebook::OnTabDragMotion(wxAuiNotebookEvent
& evt
)
2495 wxPoint screen_pt
= ::wxGetMousePosition();
2496 wxPoint client_pt
= ScreenToClient(screen_pt
);
2499 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
2500 wxAuiTabCtrl
* dest_tabs
= GetTabCtrlFromPoint(client_pt
);
2502 if (dest_tabs
== src_tabs
)
2506 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
2509 // always hide the hint for inner-tabctrl drag
2512 // if tab moving is not allowed, leave
2513 if (!(m_flags
& wxAUI_NB_TAB_MOVE
))
2518 wxPoint pt
= dest_tabs
->ScreenToClient(screen_pt
);
2519 wxWindow
* dest_location_tab
;
2521 // this is an inner-tab drag/reposition
2522 if (dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &dest_location_tab
))
2524 int src_idx
= evt
.GetSelection();
2525 int dest_idx
= dest_tabs
->GetIdxFromWindow(dest_location_tab
);
2527 // prevent jumpy drag
2528 if ((src_idx
== dest_idx
) || dest_idx
== -1 ||
2529 (src_idx
> dest_idx
&& m_lastDragX
<= pt
.x
) ||
2530 (src_idx
< dest_idx
&& m_lastDragX
>= pt
.x
))
2537 wxWindow
* src_tab
= dest_tabs
->GetWindowFromIdx(src_idx
);
2538 dest_tabs
->MovePage(src_tab
, dest_idx
);
2539 dest_tabs
->SetActivePage((size_t)dest_idx
);
2540 dest_tabs
->DoShowHide();
2541 dest_tabs
->Refresh();
2550 // if external drag is allowed, check if the tab is being dragged
2551 // over a different wxAuiNotebook control
2552 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
2554 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(screen_pt
);
2556 // if we aren't over any window, stop here
2560 // make sure we are not over the hint window
2561 if (!tab_ctrl
->IsKindOf(CLASSINFO(wxFrame
)))
2565 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
2567 tab_ctrl
= tab_ctrl
->GetParent();
2572 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
2576 wxRect hint_rect
= tab_ctrl
->GetClientRect();
2577 tab_ctrl
->ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
2578 m_mgr
.ShowHint(hint_rect
);
2587 // we are either over a hint window, or not over a tab
2588 // window, and there is no where to drag to, so exit
2595 // if there are less than two panes, split can't happen, so leave
2596 if (m_tabs
.GetPageCount() < 2)
2599 // if tab moving is not allowed, leave
2600 if (!(m_flags
& wxAUI_NB_TAB_SPLIT
))
2606 src_tabs
->SetCursor(wxCursor(wxCURSOR_SIZING
));
2612 wxRect hint_rect
= dest_tabs
->GetRect();
2613 ClientToScreen(&hint_rect
.x
, &hint_rect
.y
);
2614 m_mgr
.ShowHint(hint_rect
);
2618 m_mgr
.DrawHintRect(m_dummyWnd
, client_pt
, zero
);
2624 void wxAuiNotebook::OnTabEndDrag(wxAuiNotebookEvent
& evt
)
2629 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
2630 wxCHECK_RET( src_tabs
, wxT("no source object?") );
2632 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
2634 // get the mouse position, which will be used to determine the drop point
2635 wxPoint mouse_screen_pt
= ::wxGetMousePosition();
2636 wxPoint mouse_client_pt
= ScreenToClient(mouse_screen_pt
);
2640 // check for an external move
2641 if (m_flags
& wxAUI_NB_TAB_EXTERNAL_MOVE
)
2643 wxWindow
* tab_ctrl
= ::wxFindWindowAtPoint(mouse_screen_pt
);
2647 if (tab_ctrl
->IsKindOf(CLASSINFO(wxAuiTabCtrl
)))
2649 tab_ctrl
= tab_ctrl
->GetParent();
2654 wxAuiNotebook
* nb
= (wxAuiNotebook
*)tab_ctrl
->GetParent();
2658 // find out from the destination control
2659 // if it's ok to drop this tab here
2660 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND
, m_windowId
);
2661 e
.SetSelection(evt
.GetSelection());
2662 e
.SetOldSelection(evt
.GetSelection());
2663 e
.SetEventObject(this);
2664 e
.SetDragSource(this);
2665 e
.Veto(); // dropping must be explicitly approved by control owner
2667 nb
->GetEventHandler()->ProcessEvent(e
);
2671 // no answer or negative answer
2677 int src_idx
= evt
.GetSelection();
2678 wxWindow
* src_page
= src_tabs
->GetWindowFromIdx(src_idx
);
2680 // Check that it's not an impossible parent relationship
2682 while (p
&& !p
->IsTopLevel())
2691 // get main index of the page
2692 int main_idx
= m_tabs
.GetIdxFromWindow(src_page
);
2693 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, wxT("no source page?") );
2696 // make a copy of the page info
2697 wxAuiNotebookPage page_info
= m_tabs
.GetPage(main_idx
);
2699 // remove the page from the source notebook
2700 RemovePage(main_idx
);
2702 // reparent the page
2703 src_page
->Reparent(nb
);
2706 // found out the insert idx
2707 wxAuiTabCtrl
* dest_tabs
= (wxAuiTabCtrl
*)tab_ctrl
;
2708 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
2710 wxWindow
* target
= NULL
;
2711 int insert_idx
= -1;
2712 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
2715 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
2719 // add the page to the new notebook
2720 if (insert_idx
== -1)
2721 insert_idx
= dest_tabs
->GetPageCount();
2722 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
2723 nb
->m_tabs
.AddPage(page_info
.window
, page_info
);
2726 dest_tabs
->DoShowHide();
2727 dest_tabs
->Refresh();
2729 // set the selection in the destination tab control
2730 nb
->SetSelectionToPage(page_info
);
2732 // notify owner that the tab has been dragged
2733 wxAuiNotebookEvent
e2(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, m_windowId
);
2734 e2
.SetSelection(evt
.GetSelection());
2735 e2
.SetOldSelection(evt
.GetSelection());
2736 e2
.SetEventObject(this);
2737 GetEventHandler()->ProcessEvent(e2
);
2747 // only perform a tab split if it's allowed
2748 wxAuiTabCtrl
* dest_tabs
= NULL
;
2750 if ((m_flags
& wxAUI_NB_TAB_SPLIT
) && m_tabs
.GetPageCount() >= 2)
2752 // If the pointer is in an existing tab frame, do a tab insert
2753 wxWindow
* hit_wnd
= ::wxFindWindowAtPoint(mouse_screen_pt
);
2754 wxTabFrame
* tab_frame
= (wxTabFrame
*)GetTabFrameFromTabCtrl(hit_wnd
);
2755 int insert_idx
= -1;
2758 dest_tabs
= tab_frame
->m_tabs
;
2760 if (dest_tabs
== src_tabs
)
2764 wxPoint pt
= dest_tabs
->ScreenToClient(mouse_screen_pt
);
2765 wxWindow
* target
= NULL
;
2766 dest_tabs
->TabHitTest(pt
.x
, pt
.y
, &target
);
2769 insert_idx
= dest_tabs
->GetIdxFromWindow(target
);
2775 wxRect rect
= m_mgr
.CalculateHintRect(m_dummyWnd
,
2780 // there is no suitable drop location here, exit out
2784 // If there is no tabframe at all, create one
2785 wxTabFrame
* new_tabs
= new wxTabFrame
;
2786 new_tabs
->m_rect
= wxRect(wxPoint(0,0), CalculateNewSplitSize());
2787 new_tabs
->SetTabCtrlHeight(m_tabCtrlHeight
);
2788 new_tabs
->m_tabs
= new wxAuiTabCtrl(this,
2792 wxNO_BORDER
|wxWANTS_CHARS
);
2793 new_tabs
->m_tabs
->SetArtProvider(m_tabs
.GetArtProvider()->Clone());
2794 new_tabs
->m_tabs
->SetFlags(m_flags
);
2796 m_mgr
.AddPane(new_tabs
,
2797 wxAuiPaneInfo().Bottom().CaptionVisible(false),
2800 dest_tabs
= new_tabs
->m_tabs
;
2805 // remove the page from the source tabs
2806 wxAuiNotebookPage page_info
= src_tabs
->GetPage(evt
.GetSelection());
2807 page_info
.active
= false;
2808 src_tabs
->RemovePage(page_info
.window
);
2809 if (src_tabs
->GetPageCount() > 0)
2811 src_tabs
->SetActivePage((size_t)0);
2812 src_tabs
->DoShowHide();
2813 src_tabs
->Refresh();
2818 // add the page to the destination tabs
2819 if (insert_idx
== -1)
2820 insert_idx
= dest_tabs
->GetPageCount();
2821 dest_tabs
->InsertPage(page_info
.window
, page_info
, insert_idx
);
2823 if (src_tabs
->GetPageCount() == 0)
2825 RemoveEmptyTabFrames();
2829 dest_tabs
->DoShowHide();
2830 dest_tabs
->Refresh();
2832 // force the set selection function reset the selection
2835 // set the active page to the one we just split off
2836 SetSelectionToPage(page_info
);
2838 UpdateHintWindowSize();
2841 // notify owner that the tab has been dragged
2842 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE
, m_windowId
);
2843 e
.SetSelection(evt
.GetSelection());
2844 e
.SetOldSelection(evt
.GetSelection());
2845 e
.SetEventObject(this);
2846 GetEventHandler()->ProcessEvent(e
);
2851 void wxAuiNotebook::OnTabCancelDrag(wxAuiNotebookEvent
& command_evt
)
2853 wxAuiNotebookEvent
& evt
= (wxAuiNotebookEvent
&)command_evt
;
2857 wxAuiTabCtrl
* src_tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
2858 wxCHECK_RET( src_tabs
, wxT("no source object?") );
2860 src_tabs
->SetCursor(wxCursor(wxCURSOR_ARROW
));
2863 wxAuiTabCtrl
* wxAuiNotebook::GetTabCtrlFromPoint(const wxPoint
& pt
)
2865 // if we've just removed the last tab from the source
2866 // tab set, the remove the tab control completely
2867 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2868 size_t i
, pane_count
= all_panes
.GetCount();
2869 for (i
= 0; i
< pane_count
; ++i
)
2871 if (all_panes
.Item(i
).name
== wxT("dummy"))
2874 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2875 if (tabframe
->m_tab_rect
.Contains(pt
))
2876 return tabframe
->m_tabs
;
2882 wxWindow
* wxAuiNotebook::GetTabFrameFromTabCtrl(wxWindow
* tab_ctrl
)
2884 // if we've just removed the last tab from the source
2885 // tab set, the remove the tab control completely
2886 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2887 size_t i
, pane_count
= all_panes
.GetCount();
2888 for (i
= 0; i
< pane_count
; ++i
)
2890 if (all_panes
.Item(i
).name
== wxT("dummy"))
2893 wxTabFrame
* tabframe
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2894 if (tabframe
->m_tabs
== tab_ctrl
)
2903 void wxAuiNotebook::RemoveEmptyTabFrames()
2905 // if we've just removed the last tab from the source
2906 // tab set, the remove the tab control completely
2907 wxAuiPaneInfoArray all_panes
= m_mgr
.GetAllPanes();
2908 size_t i
, pane_count
= all_panes
.GetCount();
2909 for (i
= 0; i
< pane_count
; ++i
)
2911 if (all_panes
.Item(i
).name
== wxT("dummy"))
2914 wxTabFrame
* tab_frame
= (wxTabFrame
*)all_panes
.Item(i
).window
;
2915 if (tab_frame
->m_tabs
->GetPageCount() == 0)
2917 m_mgr
.DetachPane(tab_frame
);
2919 // use pending delete because sometimes during
2920 // window closing, refreshs are pending
2921 if (!wxPendingDelete
.Member(tab_frame
->m_tabs
))
2922 wxPendingDelete
.Append(tab_frame
->m_tabs
);
2924 tab_frame
->m_tabs
= NULL
;
2931 // check to see if there is still a center pane;
2932 // if there isn't, make a frame the center pane
2933 wxAuiPaneInfoArray panes
= m_mgr
.GetAllPanes();
2934 pane_count
= panes
.GetCount();
2935 wxWindow
* first_good
= NULL
;
2936 bool center_found
= false;
2937 for (i
= 0; i
< pane_count
; ++i
)
2939 if (panes
.Item(i
).name
== wxT("dummy"))
2941 if (panes
.Item(i
).dock_direction
== wxAUI_DOCK_CENTRE
)
2942 center_found
= true;
2944 first_good
= panes
.Item(i
).window
;
2947 if (!center_found
&& first_good
)
2949 m_mgr
.GetPane(first_good
).Centre();
2952 if (!m_isBeingDeleted
)
2956 void wxAuiNotebook::OnChildFocusNotebook(wxChildFocusEvent
& evt
)
2960 // if we're dragging a tab, don't change the current selection.
2961 // This code prevents a bug that used to happen when the hint window
2962 // was hidden. In the bug, the focus would return to the notebook
2963 // child, which would then enter this handler and call
2964 // SetSelection, which is not desired turn tab dragging.
2966 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
2967 size_t i
, pane_count
= all_panes
.GetCount();
2968 for (i
= 0; i
< pane_count
; ++i
)
2970 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
2971 if (pane
.name
== wxT("dummy"))
2973 wxTabFrame
* tabframe
= (wxTabFrame
*)pane
.window
;
2974 if (tabframe
->m_tabs
->IsDragging())
2979 // change the tab selection to the child
2980 // which was focused
2981 int idx
= m_tabs
.GetIdxFromWindow(evt
.GetWindow());
2982 if (idx
!= -1 && idx
!= m_curPage
)
2988 void wxAuiNotebook::OnNavigationKeyNotebook(wxNavigationKeyEvent
& event
)
2990 if ( event
.IsWindowChange() ) {
2992 // FIXME: the problem with this is that if we have a split notebook,
2993 // we selection may go all over the place.
2994 AdvanceSelection(event
.GetDirection());
2997 // we get this event in 3 cases
2999 // a) one of our pages might have generated it because the user TABbed
3000 // out from it in which case we should propagate the event upwards and
3001 // our parent will take care of setting the focus to prev/next sibling
3005 // b) the parent panel wants to give the focus to us so that we
3006 // forward it to our selected page. We can't deal with this in
3007 // OnSetFocus() because we don't know which direction the focus came
3008 // from in this case and so can't choose between setting the focus to
3009 // first or last panel child
3013 // c) we ourselves (see MSWTranslateMessage) generated the event
3015 wxWindow
* const parent
= GetParent();
3017 // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE
3018 const bool isFromParent
= event
.GetEventObject() == (wxObject
*) parent
;
3019 const bool isFromSelf
= event
.GetEventObject() == (wxObject
*) this;
3021 if ( isFromParent
|| isFromSelf
)
3023 // no, it doesn't come from child, case (b) or (c): forward to a
3024 // page but only if direction is backwards (TAB) or from ourselves,
3025 if ( GetSelection() != wxNOT_FOUND
&&
3026 (!event
.GetDirection() || isFromSelf
) )
3028 // so that the page knows that the event comes from it's parent
3029 // and is being propagated downwards
3030 event
.SetEventObject(this);
3032 wxWindow
*page
= GetPage(GetSelection());
3033 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
3037 //else: page manages focus inside it itself
3039 else // otherwise set the focus to the notebook itself
3046 // it comes from our child, case (a), pass to the parent, but only
3047 // if the direction is forwards. Otherwise set the focus to the
3048 // notebook itself. The notebook is always the 'first' control of a
3050 if ( !event
.GetDirection() )
3056 event
.SetCurrentFocus(this);
3057 parent
->GetEventHandler()->ProcessEvent(event
);
3063 void wxAuiNotebook::OnTabButton(wxAuiNotebookEvent
& evt
)
3065 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3067 int button_id
= evt
.GetInt();
3069 if (button_id
== wxAUI_BUTTON_CLOSE
)
3071 int selection
= evt
.GetSelection();
3073 if (selection
== -1)
3075 // if the close button is to the right, use the active
3076 // page selection to determine which page to close
3077 selection
= tabs
->GetActivePage();
3080 if (selection
!= -1)
3082 wxWindow
* close_wnd
= tabs
->GetWindowFromIdx(selection
);
3084 // ask owner if it's ok to close the tab
3085 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE
, m_windowId
);
3086 e
.SetSelection(m_tabs
.GetIdxFromWindow(close_wnd
));
3087 const int idx
= m_tabs
.GetIdxFromWindow(close_wnd
);
3088 e
.SetSelection(idx
);
3089 e
.SetOldSelection(evt
.GetSelection());
3090 e
.SetEventObject(this);
3091 GetEventHandler()->ProcessEvent(e
);
3097 if (close_wnd
->IsKindOf(CLASSINFO(wxAuiMDIChildFrame
)))
3104 int main_idx
= m_tabs
.GetIdxFromWindow(close_wnd
);
3105 wxCHECK_RET( main_idx
!= wxNOT_FOUND
, wxT("no page to delete?") );
3107 DeletePage(main_idx
);
3110 // notify owner that the tab has been closed
3111 wxAuiNotebookEvent
e2(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED
, m_windowId
);
3112 e2
.SetSelection(idx
);
3113 e2
.SetEventObject(this);
3114 GetEventHandler()->ProcessEvent(e2
);
3120 void wxAuiNotebook::OnTabMiddleDown(wxAuiNotebookEvent
& evt
)
3122 // patch event through to owner
3123 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3124 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
3126 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN
, m_windowId
);
3127 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
3128 e
.SetEventObject(this);
3129 GetEventHandler()->ProcessEvent(e
);
3132 void wxAuiNotebook::OnTabMiddleUp(wxAuiNotebookEvent
& evt
)
3134 // if the wxAUI_NB_MIDDLE_CLICK_CLOSE is specified, middle
3135 // click should act like a tab close action. However, first
3136 // give the owner an opportunity to handle the middle up event
3137 // for custom action
3139 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3140 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
3142 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP
, m_windowId
);
3143 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
3144 e
.SetEventObject(this);
3145 if (GetEventHandler()->ProcessEvent(e
))
3150 // check if we are supposed to close on middle-up
3151 if ((m_flags
& wxAUI_NB_MIDDLE_CLICK_CLOSE
) == 0)
3154 // simulate the user pressing the close button on the tab
3155 evt
.SetInt(wxAUI_BUTTON_CLOSE
);
3159 void wxAuiNotebook::OnTabRightDown(wxAuiNotebookEvent
& evt
)
3161 // patch event through to owner
3162 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3163 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
3165 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN
, m_windowId
);
3166 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
3167 e
.SetEventObject(this);
3168 GetEventHandler()->ProcessEvent(e
);
3171 void wxAuiNotebook::OnTabRightUp(wxAuiNotebookEvent
& evt
)
3173 // patch event through to owner
3174 wxAuiTabCtrl
* tabs
= (wxAuiTabCtrl
*)evt
.GetEventObject();
3175 wxWindow
* wnd
= tabs
->GetWindowFromIdx(evt
.GetSelection());
3177 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
, m_windowId
);
3178 e
.SetSelection(m_tabs
.GetIdxFromWindow(wnd
));
3179 e
.SetEventObject(this);
3180 GetEventHandler()->ProcessEvent(e
);
3183 // Sets the normal font
3184 void wxAuiNotebook::SetNormalFont(const wxFont
& font
)
3186 m_normalFont
= font
;
3187 GetArtProvider()->SetNormalFont(font
);
3190 // Sets the selected tab font
3191 void wxAuiNotebook::SetSelectedFont(const wxFont
& font
)
3193 m_selectedFont
= font
;
3194 GetArtProvider()->SetSelectedFont(font
);
3197 // Sets the measuring font
3198 void wxAuiNotebook::SetMeasuringFont(const wxFont
& font
)
3200 GetArtProvider()->SetMeasuringFont(font
);
3203 // Sets the tab font
3204 bool wxAuiNotebook::SetFont(const wxFont
& font
)
3206 wxControl::SetFont(font
);
3208 wxFont
normalFont(font
);
3209 wxFont
selectedFont(normalFont
);
3210 selectedFont
.SetWeight(wxBOLD
);
3212 SetNormalFont(normalFont
);
3213 SetSelectedFont(selectedFont
);
3214 SetMeasuringFont(selectedFont
);
3219 // Gets the tab control height
3220 int wxAuiNotebook::GetTabCtrlHeight() const
3222 return m_tabCtrlHeight
;
3225 // Gets the height of the notebook for a given page height
3226 int wxAuiNotebook::GetHeightForPageHeight(int pageHeight
)
3228 UpdateTabCtrlHeight();
3230 int tabCtrlHeight
= GetTabCtrlHeight();
3231 int decorHeight
= 2;
3232 return tabCtrlHeight
+ pageHeight
+ decorHeight
;
3235 // Advances the selection, generation page selection events
3236 void wxAuiNotebook::AdvanceSelection(bool forward
)
3238 if (GetPageCount() <= 1)
3241 int currentSelection
= GetSelection();
3245 if (currentSelection
== (int) (GetPageCount() - 1))
3247 else if (currentSelection
== -1)
3248 currentSelection
= 0;
3250 currentSelection
++;
3254 if (currentSelection
<= 0)
3257 currentSelection
--;
3260 SetSelection(currentSelection
);
3263 // Shows the window menu
3264 bool wxAuiNotebook::ShowWindowMenu()
3266 wxAuiTabCtrl
* tabCtrl
= GetActiveTabCtrl();
3268 int idx
= tabCtrl
->GetArtProvider()->ShowDropDown(tabCtrl
, tabCtrl
->GetPages(), tabCtrl
->GetActivePage());
3272 wxAuiNotebookEvent
e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, tabCtrl
->GetId());
3273 e
.SetSelection(idx
);
3274 e
.SetOldSelection(tabCtrl
->GetActivePage());
3275 e
.SetEventObject(tabCtrl
);
3276 GetEventHandler()->ProcessEvent(e
);
3284 void wxAuiNotebook::DoThaw()
3288 wxBookCtrlBase::DoThaw();
3291 void wxAuiNotebook::SetPageSize (const wxSize
& WXUNUSED(size
))
3293 wxFAIL_MSG("Not implemented for wxAuiNotebook");
3296 int wxAuiNotebook::HitTest (const wxPoint
& WXUNUSED(pt
), long* WXUNUSED(flags
)) const
3298 wxFAIL_MSG("Not implemented for wxAuiNotebook");
3302 int wxAuiNotebook::GetPageImage(size_t WXUNUSED(n
)) const
3304 wxFAIL_MSG("Not implemented for wxAuiNotebook");
3308 bool wxAuiNotebook::SetPageImage(size_t n
, int imageId
)
3310 return SetPageBitmap(n
, GetImageList()->GetBitmap(imageId
));
3313 wxWindow
* wxAuiNotebook::GetCurrentPage () const
3315 const int sel
= GetSelection();
3317 return sel
== wxNOT_FOUND
? NULL
: GetPage(sel
);
3320 int wxAuiNotebook::ChangeSelection(size_t n
)
3322 return DoModifySelection(n
, false);
3325 bool wxAuiNotebook::AddPage(wxWindow
*page
, const wxString
&text
, bool select
,
3330 return AddPage(page
, text
, select
, GetImageList()->GetBitmap(imageId
));
3334 return AddPage(page
, text
, select
, wxNullBitmap
);
3338 bool wxAuiNotebook::DeleteAllPages()
3340 size_t count
= GetPageCount();
3341 for(size_t i
= 0; i
< count
; i
++)
3348 bool wxAuiNotebook::InsertPage(size_t index
, wxWindow
*page
,
3349 const wxString
&text
, bool select
,
3354 return InsertPage(index
, page
, text
, select
,
3355 GetImageList()->GetBitmap(imageId
));
3359 return InsertPage(index
, page
, text
, select
, wxNullBitmap
);
3363 int wxAuiNotebook::DoModifySelection(size_t n
, bool events
)
3365 wxWindow
* wnd
= m_tabs
.GetWindowFromIdx(n
);
3369 // don't change the page unless necessary;
3370 // however, clicking again on a tab should give it the focus.
3371 if ((int)n
== m_curPage
)
3375 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
3377 if (FindFocus() != ctrl
)
3383 bool vetoed
= false;
3385 wxAuiNotebookEvent
evt(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
, m_windowId
);
3389 evt
.SetSelection(n
);
3390 evt
.SetOldSelection(m_curPage
);
3391 evt
.SetEventObject(this);
3392 GetEventHandler()->ProcessEvent(evt
);
3393 vetoed
= !evt
.IsAllowed();
3398 int old_curpage
= m_curPage
;
3401 // program allows the page change
3404 evt
.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
);
3405 (void)GetEventHandler()->ProcessEvent(evt
);
3411 if (FindTab(wnd
, &ctrl
, &ctrl_idx
))
3413 m_tabs
.SetActivePage(wnd
);
3415 ctrl
->SetActivePage(ctrl_idx
);
3419 ctrl
->MakeTabVisible(ctrl_idx
, ctrl
);
3422 wxAuiPaneInfoArray
& all_panes
= m_mgr
.GetAllPanes();
3423 size_t i
, pane_count
= all_panes
.GetCount();
3424 for (i
= 0; i
< pane_count
; ++i
)
3426 wxAuiPaneInfo
& pane
= all_panes
.Item(i
);
3427 if (pane
.name
== wxT("dummy"))
3429 wxAuiTabCtrl
* tabctrl
= ((wxTabFrame
*)pane
.window
)->m_tabs
;
3430 if (tabctrl
!= ctrl
)
3431 tabctrl
->SetSelectedFont(m_normalFont
);
3433 tabctrl
->SetSelectedFont(m_selectedFont
);
3437 // Set the focus to the page if we're not currently focused on the tab.
3438 // This is Firefox-like behaviour.
3439 if (wnd
->IsShownOnScreen() && FindFocus() != ctrl
)