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_SET_FOCUS(wxNotebook::OnSetFocus
)
116 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey
)
119 #if wxUSE_EXTENDED_RTTI
121 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook
, wxControl
,"wx/notebook.h")
122 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo
, wxObject
, "wx/notebook.h" )
124 WX_COLLECTION_TYPE_INFO( wxNotebookPageInfo
* , wxNotebookPageInfoList
) ;
126 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList
const &theList
, wxxVariantArray
&value
)
128 wxListCollectionToVariantArray( theList
, value
) ;
131 WX_BEGIN_PROPERTIES_TABLE(wxNotebook
)
132 WX_PROPERTY_COLLECTION( PageInfos
, wxNotebookPageInfoList
, wxNotebookPageInfo
* , AddPageInfo
, GetPageInfos
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
142 WX_END_PROPERTIES_TABLE()
144 WX_BEGIN_HANDLERS_TABLE(wxNotebook
)
145 WX_END_HANDLERS_TABLE()
147 WX_CONSTRUCTOR_4( wxNotebook
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
150 WX_BEGIN_PROPERTIES_TABLE(wxNotebookPageInfo
)
151 WX_READONLY_PROPERTY( Page
, wxNotebookPage
* , GetPage
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
152 WX_READONLY_PROPERTY( Text
, wxString
, GetText
, wxEmptyString
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
153 WX_READONLY_PROPERTY( Selected
, bool , GetSelected
, false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
154 WX_READONLY_PROPERTY( ImageId
, int , GetImageId
, -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
155 WX_END_PROPERTIES_TABLE()
157 WX_BEGIN_HANDLERS_TABLE(wxNotebookPageInfo
)
158 WX_END_HANDLERS_TABLE()
160 WX_CONSTRUCTOR_4( wxNotebookPageInfo
, wxNotebookPage
* , Page
, wxString
, Text
, bool , Selected
, int , ImageId
)
163 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
164 IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo
, wxObject
)
166 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxNotifyEvent
)
168 // ============================================================================
170 // ============================================================================
172 // ----------------------------------------------------------------------------
173 // wxNotebook construction
174 // ----------------------------------------------------------------------------
176 const wxNotebookPageInfoList
& wxNotebook::GetPageInfos() const
178 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
) ;
179 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
) ;
180 for( size_t i
= 0 ; i
< GetPageCount() ; ++i
)
182 wxNotebookPageInfo
*info
= new wxNotebookPageInfo() ;
183 info
->Create( const_cast<wxNotebook
*>(this)->GetPage(i
) , GetPageText(i
) , GetSelection() == int(i
) , GetPageImage(i
) ) ;
184 list
->Append( info
) ;
189 // common part of all ctors
190 void wxNotebook::Init()
196 // default for dynamic class
197 wxNotebook::wxNotebook()
202 // the same arguments as for wxControl
203 wxNotebook::wxNotebook(wxWindow
*parent
,
208 const wxString
& name
)
212 Create(parent
, id
, pos
, size
, style
, name
);
216 bool wxNotebook::Create(wxWindow
*parent
,
221 const wxString
& name
)
223 // Does ComCtl32 support non-top tabs?
224 int verComCtl32
= wxApp::GetComCtl32Version();
225 if ( verComCtl32
< 470 || verComCtl32
>= 600 )
227 if (style
& wxNB_BOTTOM
)
228 style
&= ~wxNB_BOTTOM
;
230 if (style
& wxNB_LEFT
)
233 if (style
& wxNB_RIGHT
)
234 style
&= ~wxNB_RIGHT
;
237 if ( !CreateControl(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
,
238 wxDefaultValidator
, name
) )
241 if ( !MSWCreateControl(WC_TABCONTROL
, wxEmptyString
, pos
, size
) )
244 SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE
)));
249 WXDWORD
wxNotebook::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
251 WXDWORD tabStyle
= wxControl::MSWGetStyle(style
, exstyle
);
253 tabStyle
|= WS_TABSTOP
| TCS_TABS
;
255 if ( style
& wxNB_MULTILINE
)
256 tabStyle
|= TCS_MULTILINE
;
257 if ( style
& wxNB_FIXEDWIDTH
)
258 tabStyle
|= TCS_FIXEDWIDTH
;
260 if ( style
& wxNB_BOTTOM
)
261 tabStyle
|= TCS_RIGHT
;
262 else if ( style
& wxNB_LEFT
)
263 tabStyle
|= TCS_VERTICAL
;
264 else if ( style
& wxNB_RIGHT
)
265 tabStyle
|= TCS_VERTICAL
| TCS_RIGHT
;
270 // note that we never want to have the default WS_EX_CLIENTEDGE style
271 // as it looks too ugly for the notebooks
278 // ----------------------------------------------------------------------------
279 // wxNotebook accessors
280 // ----------------------------------------------------------------------------
282 size_t wxNotebook::GetPageCount() const
285 wxASSERT( (int)m_pages
.Count() == TabCtrl_GetItemCount(m_hwnd
) );
287 return m_pages
.Count();
290 int wxNotebook::GetRowCount() const
292 return TabCtrl_GetRowCount(m_hwnd
);
295 int wxNotebook::SetSelection(size_t nPage
)
297 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
299 if ( int(nPage
) != m_nSelection
)
301 wxNotebookEvent
event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, m_windowId
);
302 event
.SetSelection(nPage
);
303 event
.SetOldSelection(m_nSelection
);
304 event
.SetEventObject(this);
305 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
307 // program allows the page change
308 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
309 (void)GetEventHandler()->ProcessEvent(event
);
311 TabCtrl_SetCurSel(m_hwnd
, nPage
);
318 bool wxNotebook::SetPageText(size_t nPage
, const wxString
& strText
)
320 wxCHECK_MSG( IS_VALID_PAGE(nPage
), FALSE
, wxT("notebook page out of range") );
323 tcItem
.mask
= TCIF_TEXT
;
324 tcItem
.pszText
= (wxChar
*)strText
.c_str();
326 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
329 wxString
wxNotebook::GetPageText(size_t nPage
) const
331 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxEmptyString
, wxT("notebook page out of range") );
335 tcItem
.mask
= TCIF_TEXT
;
336 tcItem
.pszText
= buf
;
337 tcItem
.cchTextMax
= WXSIZEOF(buf
);
340 if ( TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) )
341 str
= tcItem
.pszText
;
346 int wxNotebook::GetPageImage(size_t nPage
) const
348 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
351 tcItem
.mask
= TCIF_IMAGE
;
353 return TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) ? tcItem
.iImage
: -1;
356 bool wxNotebook::SetPageImage(size_t nPage
, int nImage
)
358 wxCHECK_MSG( IS_VALID_PAGE(nPage
), FALSE
, wxT("notebook page out of range") );
361 tcItem
.mask
= TCIF_IMAGE
;
362 tcItem
.iImage
= nImage
;
364 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
367 void wxNotebook::SetImageList(wxImageList
* imageList
)
369 wxNotebookBase::SetImageList(imageList
);
373 TabCtrl_SetImageList(m_hwnd
, (HIMAGELIST
)imageList
->GetHIMAGELIST());
377 // ----------------------------------------------------------------------------
378 // wxNotebook size settings
379 // ----------------------------------------------------------------------------
381 void wxNotebook::SetPageSize(const wxSize
& size
)
383 // transform the page size into the notebook size
390 TabCtrl_AdjustRect(GetHwnd(), TRUE
, &rc
);
393 SetSize(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
396 void wxNotebook::SetPadding(const wxSize
& padding
)
398 TabCtrl_SetPadding(GetHwnd(), padding
.x
, padding
.y
);
401 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
403 void wxNotebook::SetTabSize(const wxSize
& sz
)
405 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE
, 0, MAKELPARAM(sz
.x
, sz
.y
));
408 wxSize
wxNotebook::CalcSizeFromPage(const wxSize
& sizePage
) const
410 wxSize sizeTotal
= sizePage
;
412 // We need to make getting tab size part of the wxWindows API.
413 wxSize
tabSize(0, 0);
414 if (GetPageCount() > 0)
417 TabCtrl_GetItemRect((HWND
) GetHWND(), 0, & rect
);
418 tabSize
.x
= rect
.right
- rect
.left
;
419 tabSize
.y
= rect
.bottom
- rect
.top
;
421 if ( HasFlag(wxNB_LEFT
) || HasFlag(wxNB_RIGHT
) )
423 sizeTotal
.x
+= tabSize
.x
+ 7;
429 sizeTotal
.y
+= tabSize
.y
+ 7;
435 void wxNotebook::AdjustPageSize(wxNotebookPage
*page
)
437 wxCHECK_RET( page
, _T("NULL page in wxNotebook::AdjustPageSize") );
443 // get the page size from the notebook size
444 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
445 TabCtrl_AdjustRect(m_hwnd
, FALSE
, &rc
);
447 page
->SetSize(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
450 // ----------------------------------------------------------------------------
451 // wxNotebook operations
452 // ----------------------------------------------------------------------------
454 // remove one page from the notebook, without deleting
455 wxNotebookPage
*wxNotebook::DoRemovePage(size_t nPage
)
457 wxNotebookPage
*pageRemoved
= wxNotebookBase::DoRemovePage(nPage
);
461 TabCtrl_DeleteItem(m_hwnd
, nPage
);
463 if ( m_pages
.IsEmpty() )
465 // no selection any more, the notebook becamse empty
468 else // notebook still not empty
470 // change the selected page if it was deleted or became invalid
472 if ( m_nSelection
== int(GetPageCount()) )
474 // last page deleted, make the new last page the new selection
475 selNew
= m_nSelection
- 1;
477 else if ( int(nPage
) <= m_nSelection
)
479 // we must show another page, even if it has the same index
480 selNew
= m_nSelection
;
482 else // nothing changes for the currently selected page
486 // we still must refresh the current page: this needs to be done
487 // for some unknown reason if the tab control shows the up-down
488 // control (i.e. when there are too many pages) -- otherwise after
489 // deleting a page nothing at all is shown
490 if (m_nSelection
>= 0)
491 m_pages
[m_nSelection
]->Refresh();
496 // m_nSelection must be always valid so reset it before calling
499 SetSelection(selNew
);
507 bool wxNotebook::DeleteAllPages()
509 size_t nPageCount
= GetPageCount();
511 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
512 delete m_pages
[nPage
];
516 TabCtrl_DeleteAllItems(m_hwnd
);
523 // same as AddPage() but does it at given position
524 bool wxNotebook::InsertPage(size_t nPage
,
525 wxNotebookPage
*pPage
,
526 const wxString
& strText
,
530 wxCHECK_MSG( pPage
!= NULL
, FALSE
, _T("NULL page in wxNotebook::InsertPage") );
531 wxCHECK_MSG( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), FALSE
,
532 _T("invalid index in wxNotebook::InsertPage") );
534 wxASSERT_MSG( pPage
->GetParent() == this,
535 _T("notebook pages must have notebook as parent") );
537 #if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO
538 static bool g_TestedForTheme
= FALSE
;
539 static bool g_UseTheme
= FALSE
;
540 if (!g_TestedForTheme
)
542 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
544 g_UseTheme
= (commCtrlVersion
>= 600);
545 g_TestedForTheme
= TRUE
;
548 // Automatically apply the theme background,
549 // changing the colour of the panel to match the
550 // tab page colour. This won't work well with all
551 // themes but it's a start.
552 if (g_UseTheme
&& wxUxThemeEngine::Get() && pPage
->IsKindOf(CLASSINFO(wxPanel
)))
554 ApplyThemeBackground(pPage
, GetThemeBackgroundColour());
558 // add a new tab to the control
559 // ----------------------------
561 // init all fields to 0
563 wxZeroMemory(tcItem
);
565 // set the image, if any
568 tcItem
.mask
|= TCIF_IMAGE
;
569 tcItem
.iImage
= imageId
;
573 if ( !strText
.IsEmpty() )
575 tcItem
.mask
|= TCIF_TEXT
;
576 tcItem
.pszText
= (wxChar
*)strText
.c_str(); // const_cast
579 // fit the notebook page to the tab control's display area: this should be
580 // done before adding it to the notebook or TabCtrl_InsertItem() will
581 // change the notebooks size itself!
582 AdjustPageSize(pPage
);
584 // finally do insert it
585 if ( TabCtrl_InsertItem(m_hwnd
, nPage
, &tcItem
) == -1 )
587 wxLogError(wxT("Can't create the notebook page '%s'."), strText
.c_str());
592 // succeeded: save the pointer to the page
593 m_pages
.Insert(pPage
, nPage
);
595 // for the first page (only) we need to adjust the size again because the
596 // notebook size changed: the tabs which hadn't been there before are now
598 if ( m_pages
.GetCount() == 1 )
600 AdjustPageSize(pPage
);
603 // hide the page: unless it is selected, it shouldn't be shown (and if it
604 // is selected it will be shown later)
605 HWND hwnd
= GetWinHwnd(pPage
);
606 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~WS_VISIBLE
);
608 // this updates internal flag too -- otherwise it would get out of sync
609 // with the real state
613 // now deal with the selection
614 // ---------------------------
616 // if the inserted page is before the selected one, we must update the
617 // index of the selected page
618 if ( int(nPage
) <= m_nSelection
)
620 // one extra page added
624 // some page should be selected: either this one or the first one if there
625 // is still no selection
629 else if ( m_nSelection
== -1 )
633 SetSelection(selNew
);
638 int wxNotebook::HitTest(const wxPoint
& pt
, long *flags
) const
640 TC_HITTESTINFO hitTestInfo
;
641 hitTestInfo
.pt
.x
= pt
.x
;
642 hitTestInfo
.pt
.y
= pt
.y
;
643 int item
= TabCtrl_HitTest(GetHwnd(), &hitTestInfo
);
649 if ((hitTestInfo
.flags
& TCHT_NOWHERE
) == TCHT_NOWHERE
)
650 *flags
|= wxNB_HITTEST_NOWHERE
;
651 if ((hitTestInfo
.flags
& TCHT_ONITEM
) == TCHT_ONITEM
)
652 *flags
|= wxNB_HITTEST_ONITEM
;
653 if ((hitTestInfo
.flags
& TCHT_ONITEMICON
) == TCHT_ONITEMICON
)
654 *flags
|= wxNB_HITTEST_ONICON
;
655 if ((hitTestInfo
.flags
& TCHT_ONITEMLABEL
) == TCHT_ONITEMLABEL
)
656 *flags
|= wxNB_HITTEST_ONLABEL
;
663 // ----------------------------------------------------------------------------
664 // wxNotebook callbacks
665 // ----------------------------------------------------------------------------
667 void wxNotebook::OnSize(wxSizeEvent
& event
)
669 // fit the notebook page to the tab control's display area
671 rc
.left
= rc
.top
= 0;
672 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
674 TabCtrl_AdjustRect(m_hwnd
, FALSE
, &rc
);
676 int width
= rc
.right
- rc
.left
,
677 height
= rc
.bottom
- rc
.top
;
678 size_t nCount
= m_pages
.Count();
679 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ ) {
680 wxNotebookPage
*pPage
= m_pages
[nPage
];
681 pPage
->SetSize(rc
.left
, rc
.top
, width
, height
);
687 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
689 // is it our tab control?
690 if ( event
.GetEventObject() == this )
692 int sel
= event
.GetOldSelection();
694 m_pages
[sel
]->Show(FALSE
);
696 sel
= event
.GetSelection();
699 wxNotebookPage
*pPage
= m_pages
[sel
];
707 // we want to give others a chance to process this message as well
711 void wxNotebook::OnSetFocus(wxFocusEvent
& event
)
713 // this function is only called when the focus is explicitly set (i.e. from
714 // the program) to the notebook - in this case we don't need the
715 // complicated OnNavigationKey() logic because the programmer knows better
718 // set focus to the currently selected page if any
719 if ( m_nSelection
!= -1 )
720 m_pages
[m_nSelection
]->SetFocus();
725 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
727 if ( event
.IsWindowChange() ) {
729 AdvanceSelection(event
.GetDirection());
732 // we get this event in 2 cases
734 // a) one of our pages might have generated it because the user TABbed
735 // out from it in which case we should propagate the event upwards and
736 // our parent will take care of setting the focus to prev/next sibling
740 // b) the parent panel wants to give the focus to us so that we
741 // forward it to our selected page. We can't deal with this in
742 // OnSetFocus() because we don't know which direction the focus came
743 // from in this case and so can't choose between setting the focus to
744 // first or last panel child
745 wxWindow
*parent
= GetParent();
746 // the cast is here to fic a GCC ICE
747 if ( ((wxWindow
*)event
.GetEventObject()) == parent
)
749 // no, it doesn't come from child, case (b): forward to a page
750 if ( m_nSelection
!= -1 )
752 // so that the page knows that the event comes from it's parent
753 // and is being propagated downwards
754 event
.SetEventObject(this);
756 wxWindow
*page
= m_pages
[m_nSelection
];
757 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
761 //else: page manages focus inside it itself
765 // we have no pages - still have to give focus to _something_
771 // it comes from our child, case (a), pass to the parent
773 event
.SetCurrentFocus(this);
774 parent
->GetEventHandler()->ProcessEvent(event
);
780 // ----------------------------------------------------------------------------
781 // wxNotebook base class virtuals
782 // ----------------------------------------------------------------------------
784 #if wxUSE_CONSTRAINTS
786 // override these 2 functions to do nothing: everything is done in OnSize
788 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse
))
790 // don't set the sizes of the pages - their correct size is not yet known
791 wxControl::SetConstraintSizes(FALSE
);
794 bool wxNotebook::DoPhase(int WXUNUSED(nPhase
))
799 #endif // wxUSE_CONSTRAINTS
801 // ----------------------------------------------------------------------------
802 // wxNotebook Windows message handlers
803 // ----------------------------------------------------------------------------
805 bool wxNotebook::MSWOnScroll(int orientation
, WXWORD nSBCode
,
806 WXWORD pos
, WXHWND control
)
808 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
813 return wxNotebookBase::MSWOnScroll(orientation
, nSBCode
, pos
, control
);
816 bool wxNotebook::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
* result
)
818 wxNotebookEvent
event(wxEVT_NULL
, m_windowId
);
820 NMHDR
* hdr
= (NMHDR
*)lParam
;
821 switch ( hdr
->code
) {
823 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
826 case TCN_SELCHANGING
:
827 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
);
831 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
834 event
.SetSelection(TabCtrl_GetCurSel(m_hwnd
));
835 event
.SetOldSelection(m_nSelection
);
836 event
.SetEventObject(this);
837 event
.SetInt(idCtrl
);
839 bool processed
= GetEventHandler()->ProcessEvent(event
);
840 *result
= !event
.IsAllowed();
844 // Windows only: attempts to get colour for UX theme page background
845 wxColour
wxNotebook::GetThemeBackgroundColour()
848 if (wxUxThemeEngine::Get())
850 wxUxThemeHandle
hTheme(this, L
"TAB");
853 // This is total guesswork.
854 // See PlatformSDK\Include\Tmschema.h for values
856 wxUxThemeEngine::Get()->GetThemeColor
861 3821, /* FILLCOLORHINT */
865 wxColour
colour(GetRValue(themeColor
), GetGValue(themeColor
), GetBValue(themeColor
));
869 #endif // wxUSE_UXTHEME
871 return GetBackgroundColour();
874 // Windows only: attempts to apply the UX theme page background to this page
876 void wxNotebook::ApplyThemeBackground(wxWindow
* window
, const wxColour
& colour
)
878 void wxNotebook::ApplyThemeBackground(wxWindow
*, const wxColour
&)
882 // Don't set the background for buttons since this will
883 // switch it into ownerdraw mode
884 if (window
->IsKindOf(CLASSINFO(wxButton
)) && !window
->IsKindOf(CLASSINFO(wxBitmapButton
)))
885 // This is essential, otherwise you'll see dark grey
886 // corners in the buttons.
887 ((wxButton
*)window
)->wxControl::SetBackgroundColour(colour
);
888 else if (window
->IsKindOf(CLASSINFO(wxStaticText
)) ||
889 window
->IsKindOf(CLASSINFO(wxStaticBox
)) ||
890 window
->IsKindOf(CLASSINFO(wxStaticLine
)) ||
891 window
->IsKindOf(CLASSINFO(wxRadioButton
)) ||
892 window
->IsKindOf(CLASSINFO(wxRadioBox
)) ||
893 window
->IsKindOf(CLASSINFO(wxCheckBox
)) ||
894 window
->IsKindOf(CLASSINFO(wxBitmapButton
)) ||
895 window
->IsKindOf(CLASSINFO(wxSlider
)) ||
896 window
->IsKindOf(CLASSINFO(wxPanel
)) ||
897 (window
->IsKindOf(CLASSINFO(wxNotebook
)) && (window
!= this)) ||
898 window
->IsKindOf(CLASSINFO(wxScrolledWindow
))
901 window
->SetBackgroundColour(colour
);
904 for ( wxWindowList::compatibility_iterator node
= window
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
906 wxWindow
*child
= node
->GetData();
907 ApplyThemeBackground(child
, colour
);
912 long wxNotebook::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
914 static bool g_TestedForTheme
= FALSE
;
915 static bool g_UseTheme
= FALSE
;
920 if (!g_TestedForTheme
)
922 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
924 g_UseTheme
= (commCtrlVersion
>= 600);
925 g_TestedForTheme
= TRUE
;
928 // If using XP themes, it seems we can get away
929 // with not drawing a background, which reduces flicker.
935 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
939 #endif // wxUSE_NOTEBOOK