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"
31 #include "wx/imaglist.h"
33 #include "wx/control.h"
34 #include "wx/notebook.h"
37 #include "wx/msw/private.h"
39 // Windows standard headers
41 #error "wxNotebook is only supported Windows 95 and above"
44 #include <windowsx.h> // for SetWindowFont
46 #ifdef __GNUWIN32_OLD__
47 #include "wx/msw/gnuwin32/extra.h"
50 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
54 #include "wx/msw/winundef.h"
57 #include "wx/msw/uxtheme.h"
59 #include "wx/radiobut.h"
60 #include "wx/radiobox.h"
61 #include "wx/checkbox.h"
62 #include "wx/bmpbuttn.h"
63 #include "wx/statline.h"
64 #include "wx/statbox.h"
65 #include "wx/stattext.h"
66 #include "wx/slider.h"
67 #include "wx/scrolwin.h"
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 // check that the page index is valid
76 #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
79 #define m_hwnd (HWND)GetHWND()
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // This is a work-around for missing defines in gcc-2.95 headers
87 #define TCS_RIGHT 0x0002
91 #define TCS_VERTICAL 0x0080
95 #define TCS_BOTTOM TCS_RIGHT
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 #include <wx/listimpl.cpp>
104 WX_DEFINE_LIST( wxNotebookPageInfoList
) ;
106 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
)
107 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
)
109 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
110 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange
)
112 EVT_SIZE(wxNotebook::OnSize
)
114 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey
)
117 #if wxUSE_EXTENDED_RTTI
118 WX_DEFINE_FLAGS( wxNotebookStyle
)
120 wxBEGIN_FLAGS( wxNotebookStyle
)
121 // new style border flags, we put them first to
122 // use them for streaming out
123 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
124 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
125 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
126 wxFLAGS_MEMBER(wxBORDER_RAISED
)
127 wxFLAGS_MEMBER(wxBORDER_STATIC
)
128 wxFLAGS_MEMBER(wxBORDER_NONE
)
130 // old style border flags
131 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
132 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
133 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
134 wxFLAGS_MEMBER(wxRAISED_BORDER
)
135 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
136 wxFLAGS_MEMBER(wxBORDER
)
138 // standard window styles
139 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
140 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
141 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
142 wxFLAGS_MEMBER(wxWANTS_CHARS
)
143 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
144 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
145 wxFLAGS_MEMBER(wxVSCROLL
)
146 wxFLAGS_MEMBER(wxHSCROLL
)
148 wxFLAGS_MEMBER(wxNB_FIXEDWIDTH
)
149 wxFLAGS_MEMBER(wxNB_LEFT
)
150 wxFLAGS_MEMBER(wxNB_RIGHT
)
151 wxFLAGS_MEMBER(wxNB_BOTTOM
)
153 wxEND_FLAGS( wxNotebookStyle
)
155 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook
, wxControl
,"wx/notebook.h")
156 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo
, wxObject
, "wx/notebook.h" )
158 wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo
* , wxNotebookPageInfoList
) ;
160 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList
const &theList
, wxxVariantArray
&value
)
162 wxListCollectionToVariantArray
<wxNotebookPageInfoList::compatibility_iterator
>( theList
, value
) ;
165 wxBEGIN_PROPERTIES_TABLE(wxNotebook
)
166 wxEVENT_PROPERTY( PageChanging
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, wxNotebookEvent
)
167 wxEVENT_PROPERTY( PageChanged
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, wxNotebookEvent
)
169 wxPROPERTY_COLLECTION( PageInfos
, wxNotebookPageInfoList
, wxNotebookPageInfo
* , AddPageInfo
, GetPageInfos
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
170 wxPROPERTY_FLAGS( WindowStyle
, wxNotebookStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
171 wxEND_PROPERTIES_TABLE()
173 wxBEGIN_HANDLERS_TABLE(wxNotebook
)
174 wxEND_HANDLERS_TABLE()
176 wxCONSTRUCTOR_5( wxNotebook
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
179 wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo
)
180 wxREADONLY_PROPERTY( Page
, wxNotebookPage
* , GetPage
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
181 wxREADONLY_PROPERTY( Text
, wxString
, GetText
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
182 wxREADONLY_PROPERTY( Selected
, bool , GetSelected
, false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
183 wxREADONLY_PROPERTY( ImageId
, int , GetImageId
, -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
184 wxEND_PROPERTIES_TABLE()
186 wxBEGIN_HANDLERS_TABLE(wxNotebookPageInfo
)
187 wxEND_HANDLERS_TABLE()
189 wxCONSTRUCTOR_4( wxNotebookPageInfo
, wxNotebookPage
* , Page
, wxString
, Text
, bool , Selected
, int , ImageId
)
192 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
193 IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo
, wxObject
)
195 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxNotifyEvent
)
197 // ============================================================================
199 // ============================================================================
201 // ----------------------------------------------------------------------------
202 // wxNotebook construction
203 // ----------------------------------------------------------------------------
205 const wxNotebookPageInfoList
& wxNotebook::GetPageInfos() const
207 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
) ;
208 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
) ;
209 for( size_t i
= 0 ; i
< GetPageCount() ; ++i
)
211 wxNotebookPageInfo
*info
= new wxNotebookPageInfo() ;
212 info
->Create( const_cast<wxNotebook
*>(this)->GetPage(i
) , GetPageText(i
) , GetSelection() == int(i
) , GetPageImage(i
) ) ;
213 list
->Append( info
) ;
218 // common part of all ctors
219 void wxNotebook::Init()
225 // default for dynamic class
226 wxNotebook::wxNotebook()
231 // the same arguments as for wxControl
232 wxNotebook::wxNotebook(wxWindow
*parent
,
237 const wxString
& name
)
241 Create(parent
, id
, pos
, size
, style
, name
);
245 bool wxNotebook::Create(wxWindow
*parent
,
250 const wxString
& name
)
252 // Does ComCtl32 support non-top tabs?
253 int verComCtl32
= wxApp::GetComCtl32Version();
254 if ( verComCtl32
< 470 || verComCtl32
>= 600 )
256 if (style
& wxNB_BOTTOM
)
257 style
&= ~wxNB_BOTTOM
;
259 if (style
& wxNB_LEFT
)
262 if (style
& wxNB_RIGHT
)
263 style
&= ~wxNB_RIGHT
;
266 if ( !CreateControl(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
,
267 wxDefaultValidator
, name
) )
270 if ( !MSWCreateControl(WC_TABCONTROL
, wxEmptyString
, pos
, size
) )
273 SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE
)));
278 WXDWORD
wxNotebook::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
280 WXDWORD tabStyle
= wxControl::MSWGetStyle(style
, exstyle
);
282 tabStyle
|= WS_TABSTOP
| TCS_TABS
;
284 if ( style
& wxNB_MULTILINE
)
285 tabStyle
|= TCS_MULTILINE
;
286 if ( style
& wxNB_FIXEDWIDTH
)
287 tabStyle
|= TCS_FIXEDWIDTH
;
289 if ( style
& wxNB_BOTTOM
)
290 tabStyle
|= TCS_RIGHT
;
291 else if ( style
& wxNB_LEFT
)
292 tabStyle
|= TCS_VERTICAL
;
293 else if ( style
& wxNB_RIGHT
)
294 tabStyle
|= TCS_VERTICAL
| TCS_RIGHT
;
299 // note that we never want to have the default WS_EX_CLIENTEDGE style
300 // as it looks too ugly for the notebooks
307 // ----------------------------------------------------------------------------
308 // wxNotebook accessors
309 // ----------------------------------------------------------------------------
311 size_t wxNotebook::GetPageCount() const
314 wxASSERT( (int)m_pages
.Count() == TabCtrl_GetItemCount(m_hwnd
) );
316 return m_pages
.Count();
319 int wxNotebook::GetRowCount() const
321 return TabCtrl_GetRowCount(m_hwnd
);
324 int wxNotebook::SetSelection(size_t nPage
)
326 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
328 if ( int(nPage
) != m_nSelection
)
330 wxNotebookEvent
event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, m_windowId
);
331 event
.SetSelection(nPage
);
332 event
.SetOldSelection(m_nSelection
);
333 event
.SetEventObject(this);
334 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
336 // program allows the page change
337 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
338 (void)GetEventHandler()->ProcessEvent(event
);
340 TabCtrl_SetCurSel(m_hwnd
, nPage
);
347 bool wxNotebook::SetPageText(size_t nPage
, const wxString
& strText
)
349 wxCHECK_MSG( IS_VALID_PAGE(nPage
), false, wxT("notebook page out of range") );
352 tcItem
.mask
= TCIF_TEXT
;
353 tcItem
.pszText
= (wxChar
*)strText
.c_str();
355 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
358 wxString
wxNotebook::GetPageText(size_t nPage
) const
360 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxEmptyString
, wxT("notebook page out of range") );
364 tcItem
.mask
= TCIF_TEXT
;
365 tcItem
.pszText
= buf
;
366 tcItem
.cchTextMax
= WXSIZEOF(buf
);
369 if ( TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) )
370 str
= tcItem
.pszText
;
375 int wxNotebook::GetPageImage(size_t nPage
) const
377 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
380 tcItem
.mask
= TCIF_IMAGE
;
382 return TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) ? tcItem
.iImage
: -1;
385 bool wxNotebook::SetPageImage(size_t nPage
, int nImage
)
387 wxCHECK_MSG( IS_VALID_PAGE(nPage
), false, wxT("notebook page out of range") );
390 tcItem
.mask
= TCIF_IMAGE
;
391 tcItem
.iImage
= nImage
;
393 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
396 void wxNotebook::SetImageList(wxImageList
* imageList
)
398 wxNotebookBase::SetImageList(imageList
);
402 TabCtrl_SetImageList(m_hwnd
, (HIMAGELIST
)imageList
->GetHIMAGELIST());
406 // ----------------------------------------------------------------------------
407 // wxNotebook size settings
408 // ----------------------------------------------------------------------------
410 void wxNotebook::SetPageSize(const wxSize
& size
)
412 // transform the page size into the notebook size
419 TabCtrl_AdjustRect(GetHwnd(), true, &rc
);
422 SetSize(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
425 void wxNotebook::SetPadding(const wxSize
& padding
)
427 TabCtrl_SetPadding(GetHwnd(), padding
.x
, padding
.y
);
430 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
432 void wxNotebook::SetTabSize(const wxSize
& sz
)
434 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE
, 0, MAKELPARAM(sz
.x
, sz
.y
));
437 wxSize
wxNotebook::CalcSizeFromPage(const wxSize
& sizePage
) const
439 wxSize sizeTotal
= sizePage
;
441 // We need to make getting tab size part of the wxWidgets API.
442 wxSize
tabSize(0, 0);
443 if (GetPageCount() > 0)
446 TabCtrl_GetItemRect((HWND
) GetHWND(), 0, & rect
);
447 tabSize
.x
= rect
.right
- rect
.left
;
448 tabSize
.y
= rect
.bottom
- rect
.top
;
450 if ( HasFlag(wxNB_LEFT
) || HasFlag(wxNB_RIGHT
) )
452 sizeTotal
.x
+= tabSize
.x
+ 7;
458 sizeTotal
.y
+= tabSize
.y
+ 7;
464 void wxNotebook::AdjustPageSize(wxNotebookPage
*page
)
466 wxCHECK_RET( page
, _T("NULL page in wxNotebook::AdjustPageSize") );
472 // get the page size from the notebook size
473 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
475 // This check is to work around a bug in TabCtrl_AdjustRect which will
476 // cause a crash on win2k, or on XP with themes disabled, if the
477 // wxNB_MULTILINE style is used and the rectangle is very small, (such as
478 // when the notebook is first created.) The value of 20 is just
479 // arbitrarily chosen, if there is a better way to determine this value
480 // then please do so. --RD
481 if (rc
.right
> 20 && rc
.bottom
> 20)
483 TabCtrl_AdjustRect(m_hwnd
, false, &rc
);
484 page
->SetSize(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
488 // ----------------------------------------------------------------------------
489 // wxNotebook operations
490 // ----------------------------------------------------------------------------
492 // remove one page from the notebook, without deleting
493 wxNotebookPage
*wxNotebook::DoRemovePage(size_t nPage
)
495 wxNotebookPage
*pageRemoved
= wxNotebookBase::DoRemovePage(nPage
);
499 TabCtrl_DeleteItem(m_hwnd
, nPage
);
501 if ( m_pages
.IsEmpty() )
503 // no selection any more, the notebook becamse empty
506 else // notebook still not empty
508 int selNew
= TabCtrl_GetCurSel(m_hwnd
);
511 // No selection change, just refresh the current selection.
512 // Because it could be that the slection index changed
513 // we need to update it.
514 // Note: this does not mean the selection it self changed.
515 m_nSelection
= selNew
;
516 m_pages
[m_nSelection
]->Refresh();
518 else if (int(nPage
) == m_nSelection
)
520 // The selection was deleted.
522 // Determine new selection.
523 if (m_nSelection
== int(GetPageCount()))
524 selNew
= m_nSelection
- 1;
526 selNew
= m_nSelection
;
528 // m_nSelection must be always valid so reset it before calling
531 SetSelection(selNew
);
535 wxFAIL
; // Windows did not behave ok.
543 bool wxNotebook::DeleteAllPages()
545 size_t nPageCount
= GetPageCount();
547 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
548 delete m_pages
[nPage
];
552 TabCtrl_DeleteAllItems(m_hwnd
);
559 // same as AddPage() but does it at given position
560 bool wxNotebook::InsertPage(size_t nPage
,
561 wxNotebookPage
*pPage
,
562 const wxString
& strText
,
566 wxCHECK_MSG( pPage
!= NULL
, false, _T("NULL page in wxNotebook::InsertPage") );
567 wxCHECK_MSG( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), false,
568 _T("invalid index in wxNotebook::InsertPage") );
570 wxASSERT_MSG( pPage
->GetParent() == this,
571 _T("notebook pages must have notebook as parent") );
573 #if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO
574 static bool g_TestedForTheme
= false;
575 static bool g_UseTheme
= false;
576 if (!g_TestedForTheme
)
578 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
580 g_UseTheme
= (commCtrlVersion
>= 600);
581 g_TestedForTheme
= true;
584 // Automatically apply the theme background,
585 // changing the colour of the panel to match the
586 // tab page colour. This won't work well with all
587 // themes but it's a start.
588 if (g_UseTheme
&& wxUxThemeEngine::Get() && pPage
->IsKindOf(CLASSINFO(wxPanel
)))
590 ApplyThemeBackground(pPage
, GetThemeBackgroundColour());
594 // add a new tab to the control
595 // ----------------------------
597 // init all fields to 0
599 wxZeroMemory(tcItem
);
601 // set the image, if any
604 tcItem
.mask
|= TCIF_IMAGE
;
605 tcItem
.iImage
= imageId
;
609 if ( !strText
.IsEmpty() )
611 tcItem
.mask
|= TCIF_TEXT
;
612 tcItem
.pszText
= (wxChar
*)strText
.c_str(); // const_cast
615 // fit the notebook page to the tab control's display area: this should be
616 // done before adding it to the notebook or TabCtrl_InsertItem() will
617 // change the notebooks size itself!
618 AdjustPageSize(pPage
);
620 // finally do insert it
621 if ( TabCtrl_InsertItem(m_hwnd
, nPage
, &tcItem
) == -1 )
623 wxLogError(wxT("Can't create the notebook page '%s'."), strText
.c_str());
628 // succeeded: save the pointer to the page
629 m_pages
.Insert(pPage
, nPage
);
631 // we may need to adjust the size again if the notebook size changed:
632 // normally this only happens for the first page we add (the tabs which
633 // hadn't been there before are now shown) but for a multiline notebook it
634 // can happen for any page at all as a new row could have been started
635 if ( m_pages
.GetCount() == 1 || HasFlag(wxNB_MULTILINE
) )
637 AdjustPageSize(pPage
);
640 // hide the page: unless it is selected, it shouldn't be shown (and if it
641 // is selected it will be shown later)
642 HWND hwnd
= GetWinHwnd(pPage
);
643 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~WS_VISIBLE
);
645 // this updates internal flag too -- otherwise it would get out of sync
646 // with the real state
650 // now deal with the selection
651 // ---------------------------
653 // if the inserted page is before the selected one, we must update the
654 // index of the selected page
655 if ( int(nPage
) <= m_nSelection
)
657 // one extra page added
661 // some page should be selected: either this one or the first one if there
662 // is still no selection
666 else if ( m_nSelection
== -1 )
670 SetSelection(selNew
);
675 int wxNotebook::HitTest(const wxPoint
& pt
, long *flags
) const
677 TC_HITTESTINFO hitTestInfo
;
678 hitTestInfo
.pt
.x
= pt
.x
;
679 hitTestInfo
.pt
.y
= pt
.y
;
680 int item
= TabCtrl_HitTest(GetHwnd(), &hitTestInfo
);
686 if ((hitTestInfo
.flags
& TCHT_NOWHERE
) == TCHT_NOWHERE
)
687 *flags
|= wxNB_HITTEST_NOWHERE
;
688 if ((hitTestInfo
.flags
& TCHT_ONITEM
) == TCHT_ONITEM
)
689 *flags
|= wxNB_HITTEST_ONITEM
;
690 if ((hitTestInfo
.flags
& TCHT_ONITEMICON
) == TCHT_ONITEMICON
)
691 *flags
|= wxNB_HITTEST_ONICON
;
692 if ((hitTestInfo
.flags
& TCHT_ONITEMLABEL
) == TCHT_ONITEMLABEL
)
693 *flags
|= wxNB_HITTEST_ONLABEL
;
700 // ----------------------------------------------------------------------------
701 // wxNotebook callbacks
702 // ----------------------------------------------------------------------------
704 void wxNotebook::OnSize(wxSizeEvent
& event
)
706 // fit the notebook page to the tab control's display area
708 rc
.left
= rc
.top
= 0;
709 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
711 // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it
712 // returns completely false values for multiline tab controls after the tabs
713 // are added but before getting the first WM_SIZE (off by ~50 pixels, see
715 // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863
717 // and the only work around I could find was this ugly hack... without it
718 // simply toggling the "multiline" checkbox in the notebook sample resulted
719 // in a noticeable page displacement
720 if ( HasFlag(wxNB_MULTILINE
) )
722 // avoid an infinite recursion: we get another notification too!
723 static bool s_isInOnSize
= false;
728 SendMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
,
729 MAKELPARAM(rc
.right
, rc
.bottom
));
730 s_isInOnSize
= false;
734 TabCtrl_AdjustRect(m_hwnd
, false, &rc
);
736 int width
= rc
.right
- rc
.left
,
737 height
= rc
.bottom
- rc
.top
;
738 size_t nCount
= m_pages
.Count();
739 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ ) {
740 wxNotebookPage
*pPage
= m_pages
[nPage
];
741 pPage
->SetSize(rc
.left
, rc
.top
, width
, height
);
747 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
749 // is it our tab control?
750 if ( event
.GetEventObject() == this )
752 int sel
= event
.GetOldSelection();
754 m_pages
[sel
]->Show(false);
756 sel
= event
.GetSelection();
759 wxNotebookPage
*pPage
= m_pages
[sel
];
763 // If the newly focused window is not a child of the new page,
764 // SetFocus was not successful and the notebook itself should be
766 wxWindow
*currentFocus
= FindFocus();
767 wxWindow
*startFocus
= currentFocus
;
768 while ( currentFocus
&& currentFocus
!= pPage
&& currentFocus
!= this )
769 currentFocus
= currentFocus
->GetParent();
771 if ( startFocus
== pPage
|| currentFocus
!= pPage
)
775 else // no pages in the notebook, give the focus to itself
783 // we want to give others a chance to process this message as well
787 bool wxNotebook::MSWTranslateMessage(WXMSG
*wxmsg
)
789 const MSG
* const msg
= (MSG
*)wxmsg
;
791 // intercept TAB, CTRL+TAB and CTRL+SHIFT+TAB for processing by wxNotebook.
792 // TAB will be passed to the currently selected page, CTRL+TAB and
793 // CTRL+SHIFT+TAB will be processed by the notebook itself. do not
794 // intercept SHIFT+TAB. This goes to the parent of the notebook which will
796 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_TAB
&&
797 msg
->hwnd
== m_hwnd
&&
798 (wxIsCtrlDown() || !wxIsShiftDown()) )
800 return MSWProcessMessage(wxmsg
);
806 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
808 if ( event
.IsWindowChange() ) {
810 AdvanceSelection(event
.GetDirection());
813 // we get this event in 3 cases
815 // a) one of our pages might have generated it because the user TABbed
816 // out from it in which case we should propagate the event upwards and
817 // our parent will take care of setting the focus to prev/next sibling
821 // b) the parent panel wants to give the focus to us so that we
822 // forward it to our selected page. We can't deal with this in
823 // OnSetFocus() because we don't know which direction the focus came
824 // from in this case and so can't choose between setting the focus to
825 // first or last panel child
829 // c) we ourselves (see MSWTranslateMessage) generated the event
831 wxWindow
* const parent
= GetParent();
833 const bool isFromParent
= event
.GetEventObject() == parent
;
834 const bool isFromSelf
= event
.GetEventObject() == this;
836 if ( isFromParent
|| isFromSelf
)
838 // no, it doesn't come from child, case (b) or (c): forward to a
839 // page but only if direction is backwards (TAB) or from ourselves,
840 if ( m_nSelection
!= -1 &&
841 (!event
.GetDirection() || isFromSelf
) )
843 // so that the page knows that the event comes from it's parent
844 // and is being propagated downwards
845 event
.SetEventObject(this);
847 wxWindow
*page
= m_pages
[m_nSelection
];
848 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
852 //else: page manages focus inside it itself
854 else // otherwise set the focus to the notebook itself
861 // it comes from our child, case (a), pass to the parent, but only
862 // if the direction is forwards. Otherwise set the focus to the
863 // notebook itself. The notebook is always the 'first' control of a
865 if ( !event
.GetDirection() )
871 event
.SetCurrentFocus(this);
872 parent
->GetEventHandler()->ProcessEvent(event
);
878 // ----------------------------------------------------------------------------
879 // wxNotebook base class virtuals
880 // ----------------------------------------------------------------------------
882 #if wxUSE_CONSTRAINTS
884 // override these 2 functions to do nothing: everything is done in OnSize
886 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse
))
888 // don't set the sizes of the pages - their correct size is not yet known
889 wxControl::SetConstraintSizes(false);
892 bool wxNotebook::DoPhase(int WXUNUSED(nPhase
))
897 #endif // wxUSE_CONSTRAINTS
899 // ----------------------------------------------------------------------------
900 // wxNotebook Windows message handlers
901 // ----------------------------------------------------------------------------
903 bool wxNotebook::MSWOnScroll(int orientation
, WXWORD nSBCode
,
904 WXWORD pos
, WXHWND control
)
906 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
911 return wxNotebookBase::MSWOnScroll(orientation
, nSBCode
, pos
, control
);
914 bool wxNotebook::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
* result
)
916 wxNotebookEvent
event(wxEVT_NULL
, m_windowId
);
918 NMHDR
* hdr
= (NMHDR
*)lParam
;
919 switch ( hdr
->code
) {
921 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
924 case TCN_SELCHANGING
:
925 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
);
929 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
932 event
.SetSelection(TabCtrl_GetCurSel(m_hwnd
));
933 event
.SetOldSelection(m_nSelection
);
934 event
.SetEventObject(this);
935 event
.SetInt(idCtrl
);
937 bool processed
= GetEventHandler()->ProcessEvent(event
);
938 *result
= !event
.IsAllowed();
942 // Windows only: attempts to get colour for UX theme page background
943 wxColour
wxNotebook::GetThemeBackgroundColour()
946 if (wxUxThemeEngine::Get())
948 wxUxThemeHandle
hTheme(this, L
"TAB");
951 // This is total guesswork.
952 // See PlatformSDK\Include\Tmschema.h for values
954 wxUxThemeEngine::Get()->GetThemeColor(
958 3821 /* FILLCOLORHINT */,
962 [DS] Workaround for WindowBlinds:
963 Some themes return a near black theme color using FILLCOLORHINT,
964 this makes notebook pages have an ugly black background and makes
965 text (usually black) unreadable. Retry again with FILLCOLOR.
967 This workaround potentially breaks appearance of some themes,
968 but in practice it already fixes some themes.
972 wxUxThemeEngine::Get()->GetThemeColor(
976 3802 /* FILLCOLOR */,
980 wxColour
colour(GetRValue(themeColor
), GetGValue(themeColor
), GetBValue(themeColor
));
984 #endif // wxUSE_UXTHEME
986 return GetBackgroundColour();
989 // Windows only: attempts to apply the UX theme page background to this page
991 void wxNotebook::ApplyThemeBackground(wxWindow
* window
, const wxColour
& colour
)
993 void wxNotebook::ApplyThemeBackground(wxWindow
*, const wxColour
&)
998 window
->ApplyParentThemeBackground(colour
);
1000 for ( wxWindowList::compatibility_iterator node
= window
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
1002 wxWindow
*child
= node
->GetData();
1003 ApplyThemeBackground(child
, colour
);
1009 WXLRESULT
wxNotebook::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1011 static bool g_TestedForTheme
= false;
1012 static bool g_supportsThemes
= false;
1017 if (!g_TestedForTheme
)
1019 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
1021 g_supportsThemes
= (commCtrlVersion
>= 600);
1022 g_TestedForTheme
= true;
1025 // If currently an XP theme is active, it seems we can get away
1026 // with not drawing a background, which reduces flicker.
1027 if (g_supportsThemes
)
1029 wxUxThemeEngine
*p
= wxUxThemeEngine::Get();
1030 if (p
&& p
->IsThemeActive() )
1038 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
1040 #endif // #if wxUSE_UXTHEME
1042 #endif // wxUSE_NOTEBOOK