1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/notebook.cpp
3 // Purpose: implementation of wxNotebook
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "notebook.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/string.h"
32 #include "wx/imaglist.h"
34 #include "wx/control.h"
35 #include "wx/notebook.h"
36 #include "wx/sysopt.h"
39 #include "wx/msw/private.h"
41 // Windows standard headers
43 #error "wxNotebook is only supported Windows 95 and above"
46 #include <windowsx.h> // for SetWindowFont
48 #ifdef __GNUWIN32_OLD__
49 #include "wx/msw/gnuwin32/extra.h"
52 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
56 #include "wx/msw/winundef.h"
59 #include "wx/msw/uxtheme.h"
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // check that the page index is valid
67 #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
70 #define m_hwnd (HWND)GetHWND()
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 // This is a work-around for missing defines in gcc-2.95 headers
78 #define TCS_RIGHT 0x0002
82 #define TCS_VERTICAL 0x0080
86 #define TCS_BOTTOM TCS_RIGHT
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 #include <wx/listimpl.cpp>
95 WX_DEFINE_LIST( wxNotebookPageInfoList
) ;
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
)
98 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
)
100 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
101 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange
)
103 EVT_SIZE(wxNotebook::OnSize
)
105 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey
)
108 #if wxUSE_EXTENDED_RTTI
109 WX_DEFINE_FLAGS( wxNotebookStyle
)
111 wxBEGIN_FLAGS( wxNotebookStyle
)
112 // new style border flags, we put them first to
113 // use them for streaming out
114 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
115 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
116 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
117 wxFLAGS_MEMBER(wxBORDER_RAISED
)
118 wxFLAGS_MEMBER(wxBORDER_STATIC
)
119 wxFLAGS_MEMBER(wxBORDER_NONE
)
121 // old style border flags
122 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
123 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
124 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
125 wxFLAGS_MEMBER(wxRAISED_BORDER
)
126 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
127 wxFLAGS_MEMBER(wxBORDER
)
129 // standard window styles
130 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
131 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
132 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
133 wxFLAGS_MEMBER(wxWANTS_CHARS
)
134 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
135 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
136 wxFLAGS_MEMBER(wxVSCROLL
)
137 wxFLAGS_MEMBER(wxHSCROLL
)
139 wxFLAGS_MEMBER(wxNB_FIXEDWIDTH
)
140 wxFLAGS_MEMBER(wxNB_LEFT
)
141 wxFLAGS_MEMBER(wxNB_RIGHT
)
142 wxFLAGS_MEMBER(wxNB_BOTTOM
)
144 wxEND_FLAGS( wxNotebookStyle
)
146 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook
, wxControl
,"wx/notebook.h")
147 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo
, wxObject
, "wx/notebook.h" )
149 wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo
* , wxNotebookPageInfoList
) ;
151 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList
const &theList
, wxxVariantArray
&value
)
153 wxListCollectionToVariantArray
<wxNotebookPageInfoList::compatibility_iterator
>( theList
, value
) ;
156 wxBEGIN_PROPERTIES_TABLE(wxNotebook
)
157 wxEVENT_PROPERTY( PageChanging
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, wxNotebookEvent
)
158 wxEVENT_PROPERTY( PageChanged
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, wxNotebookEvent
)
160 wxPROPERTY_COLLECTION( PageInfos
, wxNotebookPageInfoList
, wxNotebookPageInfo
* , AddPageInfo
, GetPageInfos
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
161 wxPROPERTY_FLAGS( WindowStyle
, wxNotebookStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
162 wxEND_PROPERTIES_TABLE()
164 wxBEGIN_HANDLERS_TABLE(wxNotebook
)
165 wxEND_HANDLERS_TABLE()
167 wxCONSTRUCTOR_5( wxNotebook
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
170 wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo
)
171 wxREADONLY_PROPERTY( Page
, wxNotebookPage
* , GetPage
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
172 wxREADONLY_PROPERTY( Text
, wxString
, GetText
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
173 wxREADONLY_PROPERTY( Selected
, bool , GetSelected
, false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
174 wxREADONLY_PROPERTY( ImageId
, int , GetImageId
, -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
175 wxEND_PROPERTIES_TABLE()
177 wxBEGIN_HANDLERS_TABLE(wxNotebookPageInfo
)
178 wxEND_HANDLERS_TABLE()
180 wxCONSTRUCTOR_4( wxNotebookPageInfo
, wxNotebookPage
* , Page
, wxString
, Text
, bool , Selected
, int , ImageId
)
183 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
184 IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo
, wxObject
)
186 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxNotifyEvent
)
188 // ============================================================================
190 // ============================================================================
192 // ----------------------------------------------------------------------------
193 // wxNotebook construction
194 // ----------------------------------------------------------------------------
196 const wxNotebookPageInfoList
& wxNotebook::GetPageInfos() const
198 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
) ;
199 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
) ;
200 for( size_t i
= 0 ; i
< GetPageCount() ; ++i
)
202 wxNotebookPageInfo
*info
= new wxNotebookPageInfo() ;
203 info
->Create( const_cast<wxNotebook
*>(this)->GetPage(i
) , GetPageText(i
) , GetSelection() == int(i
) , GetPageImage(i
) ) ;
204 list
->Append( info
) ;
209 // common part of all ctors
210 void wxNotebook::Init()
216 m_hbrBackground
= NULL
;
217 #endif // wxUSE_UXTHEME
220 // default for dynamic class
221 wxNotebook::wxNotebook()
226 // the same arguments as for wxControl
227 wxNotebook::wxNotebook(wxWindow
*parent
,
232 const wxString
& name
)
236 Create(parent
, id
, pos
, size
, style
, name
);
240 bool wxNotebook::Create(wxWindow
*parent
,
245 const wxString
& name
)
247 // some versions of comctl32.dll 6.0 included with Windows XP don't
248 // support non-top tabs (the control is simply not rendered correctly) but
249 // we can't detect which ones, so be pessimistic by default and disable non
250 // top tabs under XP but allow the user to override this by using a special
252 bool nonTopTabsOk
= wxSystemOptions::GetOptionInt(_T("msw.xp-tab-ok")) != 0;
255 int verComCtl32
= wxApp::GetComCtl32Version();
256 nonTopTabsOk
= verComCtl32
< 470 || verComCtl32
>= 600;
261 style
&= ~(wxNB_BOTTOM
| wxNB_LEFT
| wxNB_RIGHT
);
264 if ( !CreateControl(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
,
265 wxDefaultValidator
, name
) )
268 if ( !MSWCreateControl(WC_TABCONTROL
, wxEmptyString
, pos
, size
) )
274 WXDWORD
wxNotebook::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
276 WXDWORD tabStyle
= wxControl::MSWGetStyle(style
, exstyle
);
278 tabStyle
|= WS_TABSTOP
| TCS_TABS
;
280 if ( style
& wxNB_MULTILINE
)
281 tabStyle
|= TCS_MULTILINE
;
282 if ( style
& wxNB_FIXEDWIDTH
)
283 tabStyle
|= TCS_FIXEDWIDTH
;
285 if ( style
& wxNB_BOTTOM
)
286 tabStyle
|= TCS_RIGHT
;
287 else if ( style
& wxNB_LEFT
)
288 tabStyle
|= TCS_VERTICAL
;
289 else if ( style
& wxNB_RIGHT
)
290 tabStyle
|= TCS_VERTICAL
| TCS_RIGHT
;
295 // note that we never want to have the default WS_EX_CLIENTEDGE style
296 // as it looks too ugly for the notebooks
303 wxNotebook::~wxNotebook()
306 if ( m_hbrBackground
)
307 ::DeleteObject((HBRUSH
)m_hbrBackground
);
308 #endif // wxUSE_UXTHEME
311 // ----------------------------------------------------------------------------
312 // wxNotebook accessors
313 // ----------------------------------------------------------------------------
315 size_t wxNotebook::GetPageCount() const
318 wxASSERT( (int)m_pages
.Count() == TabCtrl_GetItemCount(m_hwnd
) );
320 return m_pages
.Count();
323 int wxNotebook::GetRowCount() const
325 return TabCtrl_GetRowCount(m_hwnd
);
328 int wxNotebook::SetSelection(size_t nPage
)
330 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxNOT_FOUND
, wxT("notebook page out of range") );
332 if ( int(nPage
) != m_nSelection
)
334 wxNotebookEvent
event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, m_windowId
);
335 event
.SetSelection(nPage
);
336 event
.SetOldSelection(m_nSelection
);
337 event
.SetEventObject(this);
338 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
340 // program allows the page change
341 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
342 (void)GetEventHandler()->ProcessEvent(event
);
344 TabCtrl_SetCurSel(m_hwnd
, nPage
);
351 bool wxNotebook::SetPageText(size_t nPage
, const wxString
& strText
)
353 wxCHECK_MSG( IS_VALID_PAGE(nPage
), false, wxT("notebook page out of range") );
356 tcItem
.mask
= TCIF_TEXT
;
357 tcItem
.pszText
= (wxChar
*)strText
.c_str();
359 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
362 wxString
wxNotebook::GetPageText(size_t nPage
) const
364 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxEmptyString
, wxT("notebook page out of range") );
368 tcItem
.mask
= TCIF_TEXT
;
369 tcItem
.pszText
= buf
;
370 tcItem
.cchTextMax
= WXSIZEOF(buf
);
373 if ( TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) )
374 str
= tcItem
.pszText
;
379 int wxNotebook::GetPageImage(size_t nPage
) const
381 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
384 tcItem
.mask
= TCIF_IMAGE
;
386 return TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) ? tcItem
.iImage
: -1;
389 bool wxNotebook::SetPageImage(size_t nPage
, int nImage
)
391 wxCHECK_MSG( IS_VALID_PAGE(nPage
), false, wxT("notebook page out of range") );
394 tcItem
.mask
= TCIF_IMAGE
;
395 tcItem
.iImage
= nImage
;
397 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
400 void wxNotebook::SetImageList(wxImageList
* imageList
)
402 wxNotebookBase::SetImageList(imageList
);
406 TabCtrl_SetImageList(m_hwnd
, (HIMAGELIST
)imageList
->GetHIMAGELIST());
410 // ----------------------------------------------------------------------------
411 // wxNotebook size settings
412 // ----------------------------------------------------------------------------
414 void wxNotebook::SetPageSize(const wxSize
& size
)
416 // transform the page size into the notebook size
423 TabCtrl_AdjustRect(GetHwnd(), true, &rc
);
426 SetSize(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
429 void wxNotebook::SetPadding(const wxSize
& padding
)
431 TabCtrl_SetPadding(GetHwnd(), padding
.x
, padding
.y
);
434 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
436 void wxNotebook::SetTabSize(const wxSize
& sz
)
438 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE
, 0, MAKELPARAM(sz
.x
, sz
.y
));
441 wxSize
wxNotebook::CalcSizeFromPage(const wxSize
& sizePage
) const
443 wxSize sizeTotal
= sizePage
;
445 // We need to make getting tab size part of the wxWidgets API.
446 wxSize
tabSize(0, 0);
447 if (GetPageCount() > 0)
450 TabCtrl_GetItemRect((HWND
) GetHWND(), 0, & rect
);
451 tabSize
.x
= rect
.right
- rect
.left
;
452 tabSize
.y
= rect
.bottom
- rect
.top
;
454 if ( HasFlag(wxNB_LEFT
) || HasFlag(wxNB_RIGHT
) )
456 sizeTotal
.x
+= tabSize
.x
+ 7;
462 sizeTotal
.y
+= tabSize
.y
+ 7;
468 void wxNotebook::AdjustPageSize(wxNotebookPage
*page
)
470 wxCHECK_RET( page
, _T("NULL page in wxNotebook::AdjustPageSize") );
476 // get the page size from the notebook size
477 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
479 // This check is to work around a bug in TabCtrl_AdjustRect which will
480 // cause a crash on win2k, or on XP with themes disabled, if the
481 // wxNB_MULTILINE style is used and the rectangle is very small, (such as
482 // when the notebook is first created.) The value of 20 is just
483 // arbitrarily chosen, if there is a better way to determine this value
484 // then please do so. --RD
485 if (rc
.right
> 20 && rc
.bottom
> 20)
487 TabCtrl_AdjustRect(m_hwnd
, false, &rc
);
488 page
->SetSize(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
492 // ----------------------------------------------------------------------------
493 // wxNotebook operations
494 // ----------------------------------------------------------------------------
496 // remove one page from the notebook, without deleting
497 wxNotebookPage
*wxNotebook::DoRemovePage(size_t nPage
)
499 wxNotebookPage
*pageRemoved
= wxNotebookBase::DoRemovePage(nPage
);
503 TabCtrl_DeleteItem(m_hwnd
, nPage
);
505 if ( m_pages
.IsEmpty() )
507 // no selection any more, the notebook becamse empty
510 else // notebook still not empty
512 int selNew
= TabCtrl_GetCurSel(m_hwnd
);
515 // No selection change, just refresh the current selection.
516 // Because it could be that the slection index changed
517 // we need to update it.
518 // Note: this does not mean the selection it self changed.
519 m_nSelection
= selNew
;
520 m_pages
[m_nSelection
]->Refresh();
522 else if (int(nPage
) == m_nSelection
)
524 // The selection was deleted.
526 // Determine new selection.
527 if (m_nSelection
== int(GetPageCount()))
528 selNew
= m_nSelection
- 1;
530 selNew
= m_nSelection
;
532 // m_nSelection must be always valid so reset it before calling
535 SetSelection(selNew
);
539 wxFAIL
; // Windows did not behave ok.
547 bool wxNotebook::DeleteAllPages()
549 size_t nPageCount
= GetPageCount();
551 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
552 delete m_pages
[nPage
];
556 TabCtrl_DeleteAllItems(m_hwnd
);
560 InvalidateBestSize();
564 // same as AddPage() but does it at given position
565 bool wxNotebook::InsertPage(size_t nPage
,
566 wxNotebookPage
*pPage
,
567 const wxString
& strText
,
571 wxCHECK_MSG( pPage
!= NULL
, false, _T("NULL page in wxNotebook::InsertPage") );
572 wxCHECK_MSG( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), false,
573 _T("invalid index in wxNotebook::InsertPage") );
575 wxASSERT_MSG( pPage
->GetParent() == this,
576 _T("notebook pages must have notebook as parent") );
578 // add a new tab to the control
579 // ----------------------------
581 // init all fields to 0
583 wxZeroMemory(tcItem
);
585 // set the image, if any
588 tcItem
.mask
|= TCIF_IMAGE
;
589 tcItem
.iImage
= imageId
;
593 if ( !strText
.IsEmpty() )
595 tcItem
.mask
|= TCIF_TEXT
;
596 tcItem
.pszText
= (wxChar
*)strText
.c_str(); // const_cast
599 // hide the page: unless it is selected, it shouldn't be shown (and if it
600 // is selected it will be shown later)
601 HWND hwnd
= GetWinHwnd(pPage
);
602 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~WS_VISIBLE
);
604 // this updates internal flag too -- otherwise it would get out of sync
605 // with the real state
609 // fit the notebook page to the tab control's display area: this should be
610 // done before adding it to the notebook or TabCtrl_InsertItem() will
611 // change the notebooks size itself!
612 AdjustPageSize(pPage
);
614 // finally do insert it
615 if ( TabCtrl_InsertItem(m_hwnd
, nPage
, &tcItem
) == -1 )
617 wxLogError(wxT("Can't create the notebook page '%s'."), strText
.c_str());
622 // succeeded: save the pointer to the page
623 m_pages
.Insert(pPage
, nPage
);
625 // we may need to adjust the size again if the notebook size changed:
626 // normally this only happens for the first page we add (the tabs which
627 // hadn't been there before are now shown) but for a multiline notebook it
628 // can happen for any page at all as a new row could have been started
629 if ( m_pages
.GetCount() == 1 || HasFlag(wxNB_MULTILINE
) )
631 AdjustPageSize(pPage
);
634 // now deal with the selection
635 // ---------------------------
637 // if the inserted page is before the selected one, we must update the
638 // index of the selected page
639 if ( int(nPage
) <= m_nSelection
)
641 // one extra page added
645 // some page should be selected: either this one or the first one if there
646 // is still no selection
650 else if ( m_nSelection
== -1 )
654 SetSelection(selNew
);
656 InvalidateBestSize();
660 int wxNotebook::HitTest(const wxPoint
& pt
, long *flags
) const
662 TC_HITTESTINFO hitTestInfo
;
663 hitTestInfo
.pt
.x
= pt
.x
;
664 hitTestInfo
.pt
.y
= pt
.y
;
665 int item
= TabCtrl_HitTest(GetHwnd(), &hitTestInfo
);
671 if ((hitTestInfo
.flags
& TCHT_NOWHERE
) == TCHT_NOWHERE
)
672 *flags
|= wxNB_HITTEST_NOWHERE
;
673 if ((hitTestInfo
.flags
& TCHT_ONITEM
) == TCHT_ONITEM
)
674 *flags
|= wxNB_HITTEST_ONITEM
;
675 if ((hitTestInfo
.flags
& TCHT_ONITEMICON
) == TCHT_ONITEMICON
)
676 *flags
|= wxNB_HITTEST_ONICON
;
677 if ((hitTestInfo
.flags
& TCHT_ONITEMLABEL
) == TCHT_ONITEMLABEL
)
678 *flags
|= wxNB_HITTEST_ONLABEL
;
685 // ----------------------------------------------------------------------------
686 // wxNotebook callbacks
687 // ----------------------------------------------------------------------------
689 void wxNotebook::OnSize(wxSizeEvent
& event
)
691 // fit the notebook page to the tab control's display area
693 rc
.left
= rc
.top
= 0;
694 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
696 // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it
697 // returns completely false values for multiline tab controls after the tabs
698 // are added but before getting the first WM_SIZE (off by ~50 pixels, see
700 // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863
702 // and the only work around I could find was this ugly hack... without it
703 // simply toggling the "multiline" checkbox in the notebook sample resulted
704 // in a noticeable page displacement
705 if ( HasFlag(wxNB_MULTILINE
) )
707 // avoid an infinite recursion: we get another notification too!
708 static bool s_isInOnSize
= false;
713 SendMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
,
714 MAKELPARAM(rc
.right
, rc
.bottom
));
715 s_isInOnSize
= false;
719 TabCtrl_AdjustRect(m_hwnd
, false, &rc
);
721 int width
= rc
.right
- rc
.left
,
722 height
= rc
.bottom
- rc
.top
;
723 size_t nCount
= m_pages
.Count();
724 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ ) {
725 wxNotebookPage
*pPage
= m_pages
[nPage
];
726 pPage
->SetSize(rc
.left
, rc
.top
, width
, height
);
731 #endif // wxUSE_UXTHEME
736 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
738 // is it our tab control?
739 if ( event
.GetEventObject() == this )
741 int sel
= event
.GetOldSelection();
743 m_pages
[sel
]->Show(false);
745 sel
= event
.GetSelection();
748 wxNotebookPage
*pPage
= m_pages
[sel
];
752 // If the newly focused window is not a child of the new page,
753 // SetFocus was not successful and the notebook itself should be
755 wxWindow
*currentFocus
= FindFocus();
756 wxWindow
*startFocus
= currentFocus
;
757 while ( currentFocus
&& currentFocus
!= pPage
&& currentFocus
!= this )
758 currentFocus
= currentFocus
->GetParent();
760 if ( startFocus
== pPage
|| currentFocus
!= pPage
)
764 else // no pages in the notebook, give the focus to itself
772 // we want to give others a chance to process this message as well
776 bool wxNotebook::MSWTranslateMessage(WXMSG
*wxmsg
)
778 const MSG
* const msg
= (MSG
*)wxmsg
;
780 // intercept TAB, CTRL+TAB and CTRL+SHIFT+TAB for processing by wxNotebook.
781 // TAB will be passed to the currently selected page, CTRL+TAB and
782 // CTRL+SHIFT+TAB will be processed by the notebook itself. do not
783 // intercept SHIFT+TAB. This goes to the parent of the notebook which will
785 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_TAB
&&
786 msg
->hwnd
== m_hwnd
&&
787 (wxIsCtrlDown() || !wxIsShiftDown()) )
789 return MSWProcessMessage(wxmsg
);
795 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
797 if ( event
.IsWindowChange() ) {
799 AdvanceSelection(event
.GetDirection());
802 // we get this event in 3 cases
804 // a) one of our pages might have generated it because the user TABbed
805 // out from it in which case we should propagate the event upwards and
806 // our parent will take care of setting the focus to prev/next sibling
810 // b) the parent panel wants to give the focus to us so that we
811 // forward it to our selected page. We can't deal with this in
812 // OnSetFocus() because we don't know which direction the focus came
813 // from in this case and so can't choose between setting the focus to
814 // first or last panel child
818 // c) we ourselves (see MSWTranslateMessage) generated the event
820 wxWindow
* const parent
= GetParent();
822 const bool isFromParent
= event
.GetEventObject() == parent
;
823 const bool isFromSelf
= event
.GetEventObject() == this;
825 if ( isFromParent
|| isFromSelf
)
827 // no, it doesn't come from child, case (b) or (c): forward to a
828 // page but only if direction is backwards (TAB) or from ourselves,
829 if ( m_nSelection
!= -1 &&
830 (!event
.GetDirection() || isFromSelf
) )
832 // so that the page knows that the event comes from it's parent
833 // and is being propagated downwards
834 event
.SetEventObject(this);
836 wxWindow
*page
= m_pages
[m_nSelection
];
837 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
841 //else: page manages focus inside it itself
843 else // otherwise set the focus to the notebook itself
850 // it comes from our child, case (a), pass to the parent, but only
851 // if the direction is forwards. Otherwise set the focus to the
852 // notebook itself. The notebook is always the 'first' control of a
854 if ( !event
.GetDirection() )
860 event
.SetCurrentFocus(this);
861 parent
->GetEventHandler()->ProcessEvent(event
);
869 void wxNotebook::UpdateBgBrush()
871 if ( m_hbrBackground
)
872 ::DeleteObject((HBRUSH
)m_hbrBackground
);
874 if ( wxUxThemeEngine::GetIfActive() )
877 GetWindowRect(GetHwnd(), &rc
);
879 WindowHDC
hDC(GetHwnd());
880 MemoryHDC
hDCMem(hDC
);
881 CompatibleBitmap
hBmp(hDC
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
883 SelectInHDC
selectBmp(hDCMem
, hBmp
);
885 SendMessage(GetHwnd(), WM_PRINTCLIENT
, (WPARAM
)(HDC
)hDCMem
,
886 PRF_ERASEBKGND
| PRF_CLIENT
| PRF_NONCLIENT
);
888 m_hbrBackground
= (WXHBRUSH
)::CreatePatternBrush(hBmp
);
892 m_hbrBackground
= NULL
;
896 WXHBRUSH
wxNotebook::GetThemeBackgroundBrush(WXHDC hDC
, wxWindow
*win
) const
898 if ( m_hbrBackground
)
900 // before drawing with the background brush, we need to position it
903 ::GetWindowRect(GetHwndOf(win
), &rc
);
905 ::MapWindowPoints(NULL
, GetHwnd(), (POINT
*)&rc
, 1);
907 if ( !::SetBrushOrgEx((HDC
)hDC
, -rc
.left
, -rc
.top
, NULL
) )
909 wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)"));
913 return m_hbrBackground
;
916 void wxNotebook::DoEraseBackground(wxEraseEvent
& event
)
918 DoEraseBackground((wxWindow
*)event
.GetEventObject(),
919 (WXHDC
)GetHdcOf(*event
.GetDC()));
922 void wxNotebook::DoEraseBackground(wxWindow
*win
, WXHDC hDC
)
924 // we can either draw the background ourselves or let DrawThemeBackground()
925 // do it, but as we already have the correct brush, let's do it ourselves
926 // (note that we use the same code in wxControl::MSWControlColor(), so if
927 // it breaks, it should at least break in consistent way)
928 WXHBRUSH hbr
= GetThemeBackgroundBrush(hDC
, win
);
932 ::GetClientRect(GetHwndOf(win
), &rectClient
);
933 ::FillRect((HDC
)hDC
, &rectClient
, (HBRUSH
)hbr
);
937 #endif // wxUSE_UXTHEME
939 // ----------------------------------------------------------------------------
940 // wxNotebook base class virtuals
941 // ----------------------------------------------------------------------------
943 #if wxUSE_CONSTRAINTS
945 // override these 2 functions to do nothing: everything is done in OnSize
947 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse
))
949 // don't set the sizes of the pages - their correct size is not yet known
950 wxControl::SetConstraintSizes(false);
953 bool wxNotebook::DoPhase(int WXUNUSED(nPhase
))
958 #endif // wxUSE_CONSTRAINTS
960 // ----------------------------------------------------------------------------
961 // wxNotebook Windows message handlers
962 // ----------------------------------------------------------------------------
964 bool wxNotebook::MSWOnScroll(int orientation
, WXWORD nSBCode
,
965 WXWORD pos
, WXHWND control
)
967 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
972 return wxNotebookBase::MSWOnScroll(orientation
, nSBCode
, pos
, control
);
975 bool wxNotebook::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
* result
)
977 wxNotebookEvent
event(wxEVT_NULL
, m_windowId
);
979 NMHDR
* hdr
= (NMHDR
*)lParam
;
980 switch ( hdr
->code
) {
982 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
985 case TCN_SELCHANGING
:
986 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
);
990 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
993 event
.SetSelection(TabCtrl_GetCurSel(m_hwnd
));
994 event
.SetOldSelection(m_nSelection
);
995 event
.SetEventObject(this);
996 event
.SetInt(idCtrl
);
998 bool processed
= GetEventHandler()->ProcessEvent(event
);
999 *result
= !event
.IsAllowed();
1003 #endif // wxUSE_NOTEBOOK