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) >= 0) && ((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 template<> const wxTypeInfo
* wxGetTypeInfo( wxNotebookPageInfoList
* )
126 static wxCollectionTypeInfo
s_typeInfo( (wxTypeInfo
*) wxGetTypeInfo( (wxNotebookPageInfo
**) NULL
) ) ;
130 WX_BEGIN_PROPERTIES_TABLE(wxNotebook
)
131 WX_PROPERTY_COLLECTION( PageInfos
, wxNotebookPageInfoList
, wxNotebookPageInfo
* , AddPageInfo
, GetPageInfos
)
141 WX_END_PROPERTIES_TABLE()
143 WX_BEGIN_HANDLERS_TABLE(wxNotebook
)
144 WX_END_HANDLERS_TABLE()
146 WX_CONSTRUCTOR_4( wxNotebook
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
149 WX_BEGIN_PROPERTIES_TABLE(wxNotebookPageInfo
)
150 WX_READONLY_PROPERTY( Page
, wxNotebookPage
* , GetPage
, )
151 WX_READONLY_PROPERTY( Text
, wxString
, GetText
, wxEmptyString
)
152 WX_READONLY_PROPERTY( Selected
, bool , GetSelected
, false )
153 WX_READONLY_PROPERTY( ImageId
, int , GetImageId
, -1 )
154 WX_END_PROPERTIES_TABLE()
156 WX_BEGIN_HANDLERS_TABLE(wxNotebookPageInfo
)
157 WX_END_HANDLERS_TABLE()
159 WX_CONSTRUCTOR_4( wxNotebookPageInfo
, wxNotebookPage
* , Page
, wxString
, Text
, bool , Selected
, int , ImageId
)
161 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList
const &theList
, wxxVariantArray
&value
)
163 wxListCollectionToVariantArray( theList
, value
) ;
167 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
168 IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo
, wxObject
)
170 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxNotifyEvent
)
172 // ============================================================================
174 // ============================================================================
176 // ----------------------------------------------------------------------------
177 // wxNotebook construction
178 // ----------------------------------------------------------------------------
180 const wxNotebookPageInfoList
& wxNotebook::GetPageInfos() const
182 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
) ;
183 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
) ;
184 for( int i
= 0 ; i
< GetPageCount() ; ++i
)
186 wxNotebookPageInfo
*info
= new wxNotebookPageInfo() ;
187 info
->Create( const_cast<wxNotebook
*>(this)->GetPage(i
) , GetPageText(i
) , GetSelection() == i
, GetPageImage(i
) ) ;
188 list
->Append( info
) ;
193 // common part of all ctors
194 void wxNotebook::Init()
200 // default for dynamic class
201 wxNotebook::wxNotebook()
206 // the same arguments as for wxControl
207 wxNotebook::wxNotebook(wxWindow
*parent
,
212 const wxString
& name
)
216 Create(parent
, id
, pos
, size
, style
, name
);
220 bool wxNotebook::Create(wxWindow
*parent
,
225 const wxString
& name
)
227 // Does ComCtl32 support non-top tabs?
228 int verComCtl32
= wxApp::GetComCtl32Version();
229 if ( verComCtl32
< 470 || verComCtl32
>= 600 )
231 if (style
& wxNB_BOTTOM
)
232 style
&= ~wxNB_BOTTOM
;
234 if (style
& wxNB_LEFT
)
237 if (style
& wxNB_RIGHT
)
238 style
&= ~wxNB_RIGHT
;
241 if ( !CreateControl(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
,
242 wxDefaultValidator
, name
) )
245 if ( !MSWCreateControl(WC_TABCONTROL
, wxEmptyString
, pos
, size
) )
248 SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE
)));
253 WXDWORD
wxNotebook::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
255 WXDWORD tabStyle
= wxControl::MSWGetStyle(style
, exstyle
);
257 tabStyle
|= WS_TABSTOP
| TCS_TABS
;
259 if ( style
& wxNB_MULTILINE
)
260 tabStyle
|= TCS_MULTILINE
;
261 if ( style
& wxNB_FIXEDWIDTH
)
262 tabStyle
|= TCS_FIXEDWIDTH
;
264 if ( style
& wxNB_BOTTOM
)
265 tabStyle
|= TCS_RIGHT
;
266 else if ( style
& wxNB_LEFT
)
267 tabStyle
|= TCS_VERTICAL
;
268 else if ( style
& wxNB_RIGHT
)
269 tabStyle
|= TCS_VERTICAL
| TCS_RIGHT
;
274 // note that we never want to have the default WS_EX_CLIENTEDGE style
275 // as it looks too ugly for the notebooks
282 // ----------------------------------------------------------------------------
283 // wxNotebook accessors
284 // ----------------------------------------------------------------------------
286 int wxNotebook::GetPageCount() const
289 wxASSERT( (int)m_pages
.Count() == TabCtrl_GetItemCount(m_hwnd
) );
291 return m_pages
.Count();
294 int wxNotebook::GetRowCount() const
296 return TabCtrl_GetRowCount(m_hwnd
);
299 int wxNotebook::SetSelection(int nPage
)
301 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
303 if ( nPage
!= m_nSelection
)
305 wxNotebookEvent
event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, m_windowId
);
306 event
.SetSelection(nPage
);
307 event
.SetOldSelection(m_nSelection
);
308 event
.SetEventObject(this);
309 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
311 // program allows the page change
312 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
313 (void)GetEventHandler()->ProcessEvent(event
);
315 TabCtrl_SetCurSel(m_hwnd
, nPage
);
322 bool wxNotebook::SetPageText(int nPage
, const wxString
& strText
)
324 wxCHECK_MSG( IS_VALID_PAGE(nPage
), FALSE
, wxT("notebook page out of range") );
327 tcItem
.mask
= TCIF_TEXT
;
328 tcItem
.pszText
= (wxChar
*)strText
.c_str();
330 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
333 wxString
wxNotebook::GetPageText(int nPage
) const
335 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxEmptyString
, wxT("notebook page out of range") );
339 tcItem
.mask
= TCIF_TEXT
;
340 tcItem
.pszText
= buf
;
341 tcItem
.cchTextMax
= WXSIZEOF(buf
);
344 if ( TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) )
345 str
= tcItem
.pszText
;
350 int wxNotebook::GetPageImage(int nPage
) const
352 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
355 tcItem
.mask
= TCIF_IMAGE
;
357 return TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) ? tcItem
.iImage
: -1;
360 bool wxNotebook::SetPageImage(int nPage
, int nImage
)
362 wxCHECK_MSG( IS_VALID_PAGE(nPage
), FALSE
, wxT("notebook page out of range") );
365 tcItem
.mask
= TCIF_IMAGE
;
366 tcItem
.iImage
= nImage
;
368 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
371 void wxNotebook::SetImageList(wxImageList
* imageList
)
373 wxNotebookBase::SetImageList(imageList
);
377 TabCtrl_SetImageList(m_hwnd
, (HIMAGELIST
)imageList
->GetHIMAGELIST());
381 // ----------------------------------------------------------------------------
382 // wxNotebook size settings
383 // ----------------------------------------------------------------------------
385 void wxNotebook::SetPageSize(const wxSize
& size
)
387 // transform the page size into the notebook size
394 TabCtrl_AdjustRect(GetHwnd(), TRUE
, &rc
);
397 SetSize(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
400 void wxNotebook::SetPadding(const wxSize
& padding
)
402 TabCtrl_SetPadding(GetHwnd(), padding
.x
, padding
.y
);
405 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
407 void wxNotebook::SetTabSize(const wxSize
& sz
)
409 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE
, 0, MAKELPARAM(sz
.x
, sz
.y
));
412 wxSize
wxNotebook::CalcSizeFromPage(const wxSize
& sizePage
) const
414 wxSize sizeTotal
= sizePage
;
416 // We need to make getting tab size part of the wxWindows API.
417 wxSize
tabSize(0, 0);
418 if (GetPageCount() > 0)
421 TabCtrl_GetItemRect((HWND
) GetHWND(), 0, & rect
);
422 tabSize
.x
= rect
.right
- rect
.left
;
423 tabSize
.y
= rect
.bottom
- rect
.top
;
425 if ( HasFlag(wxNB_LEFT
) || HasFlag(wxNB_RIGHT
) )
427 sizeTotal
.x
+= tabSize
.x
+ 7;
433 sizeTotal
.y
+= tabSize
.y
+ 7;
439 void wxNotebook::AdjustPageSize(wxNotebookPage
*page
)
441 wxCHECK_RET( page
, _T("NULL page in wxNotebook::AdjustPageSize") );
447 // get the page size from the notebook size
448 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
449 TabCtrl_AdjustRect(m_hwnd
, FALSE
, &rc
);
451 page
->SetSize(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
454 // ----------------------------------------------------------------------------
455 // wxNotebook operations
456 // ----------------------------------------------------------------------------
458 // remove one page from the notebook, without deleting
459 wxNotebookPage
*wxNotebook::DoRemovePage(int nPage
)
461 wxNotebookPage
*pageRemoved
= wxNotebookBase::DoRemovePage(nPage
);
465 TabCtrl_DeleteItem(m_hwnd
, nPage
);
467 if ( m_pages
.IsEmpty() )
469 // no selection any more, the notebook becamse empty
472 else // notebook still not empty
474 // change the selected page if it was deleted or became invalid
476 if ( m_nSelection
== GetPageCount() )
478 // last page deleted, make the new last page the new selection
479 selNew
= m_nSelection
- 1;
481 else if ( nPage
<= m_nSelection
)
483 // we must show another page, even if it has the same index
484 selNew
= m_nSelection
;
486 else // nothing changes for the currently selected page
490 // we still must refresh the current page: this needs to be done
491 // for some unknown reason if the tab control shows the up-down
492 // control (i.e. when there are too many pages) -- otherwise after
493 // deleting a page nothing at all is shown
494 if (m_nSelection
>= 0)
495 m_pages
[m_nSelection
]->Refresh();
500 // m_nSelection must be always valid so reset it before calling
503 SetSelection(selNew
);
511 bool wxNotebook::DeleteAllPages()
513 int nPageCount
= GetPageCount();
515 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
516 delete m_pages
[nPage
];
520 TabCtrl_DeleteAllItems(m_hwnd
);
527 // same as AddPage() but does it at given position
528 bool wxNotebook::InsertPage(int nPage
,
529 wxNotebookPage
*pPage
,
530 const wxString
& strText
,
534 wxCHECK_MSG( pPage
!= NULL
, FALSE
, _T("NULL page in wxNotebook::InsertPage") );
535 wxCHECK_MSG( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), FALSE
,
536 _T("invalid index in wxNotebook::InsertPage") );
538 wxASSERT_MSG( pPage
->GetParent() == this,
539 _T("notebook pages must have notebook as parent") );
541 #if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO
542 static bool g_TestedForTheme
= FALSE
;
543 static bool g_UseTheme
= FALSE
;
544 if (!g_TestedForTheme
)
546 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
548 g_UseTheme
= (commCtrlVersion
>= 600);
549 g_TestedForTheme
= TRUE
;
552 // Automatically apply the theme background,
553 // changing the colour of the panel to match the
554 // tab page colour. This won't work well with all
555 // themes but it's a start.
556 if (g_UseTheme
&& wxUxThemeEngine::Get() && pPage
->IsKindOf(CLASSINFO(wxPanel
)))
558 ApplyThemeBackground(pPage
, GetThemeBackgroundColour());
562 // add a new tab to the control
563 // ----------------------------
565 // init all fields to 0
567 wxZeroMemory(tcItem
);
569 // set the image, if any
572 tcItem
.mask
|= TCIF_IMAGE
;
573 tcItem
.iImage
= imageId
;
577 if ( !strText
.IsEmpty() )
579 tcItem
.mask
|= TCIF_TEXT
;
580 tcItem
.pszText
= (wxChar
*)strText
.c_str(); // const_cast
583 // fit the notebook page to the tab control's display area: this should be
584 // done before adding it to the notebook or TabCtrl_InsertItem() will
585 // change the notebooks size itself!
586 AdjustPageSize(pPage
);
588 // finally do insert it
589 if ( TabCtrl_InsertItem(m_hwnd
, nPage
, &tcItem
) == -1 )
591 wxLogError(wxT("Can't create the notebook page '%s'."), strText
.c_str());
596 // succeeded: save the pointer to the page
597 m_pages
.Insert(pPage
, nPage
);
599 // for the first page (only) we need to adjust the size again because the
600 // notebook size changed: the tabs which hadn't been there before are now
602 if ( m_pages
.GetCount() == 1 )
604 AdjustPageSize(pPage
);
607 // hide the page: unless it is selected, it shouldn't be shown (and if it
608 // is selected it will be shown later)
609 HWND hwnd
= GetWinHwnd(pPage
);
610 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~WS_VISIBLE
);
612 // this updates internal flag too -- otherwise it would get out of sync
613 // with the real state
617 // now deal with the selection
618 // ---------------------------
620 // if the inserted page is before the selected one, we must update the
621 // index of the selected page
622 if ( nPage
<= m_nSelection
)
624 // one extra page added
628 // some page should be selected: either this one or the first one if there
629 // is still no selection
633 else if ( m_nSelection
== -1 )
637 SetSelection(selNew
);
642 int wxNotebook::HitTest(const wxPoint
& pt
, long *flags
) const
644 TC_HITTESTINFO hitTestInfo
;
645 hitTestInfo
.pt
.x
= pt
.x
;
646 hitTestInfo
.pt
.y
= pt
.y
;
647 int item
= TabCtrl_HitTest(GetHwnd(), &hitTestInfo
);
653 if ((hitTestInfo
.flags
& TCHT_NOWHERE
) == TCHT_NOWHERE
)
654 *flags
|= wxNB_HITTEST_NOWHERE
;
655 if ((hitTestInfo
.flags
& TCHT_ONITEM
) == TCHT_ONITEM
)
656 *flags
|= wxNB_HITTEST_ONITEM
;
657 if ((hitTestInfo
.flags
& TCHT_ONITEMICON
) == TCHT_ONITEMICON
)
658 *flags
|= wxNB_HITTEST_ONICON
;
659 if ((hitTestInfo
.flags
& TCHT_ONITEMLABEL
) == TCHT_ONITEMLABEL
)
660 *flags
|= wxNB_HITTEST_ONLABEL
;
667 // ----------------------------------------------------------------------------
668 // wxNotebook callbacks
669 // ----------------------------------------------------------------------------
671 void wxNotebook::OnSize(wxSizeEvent
& event
)
673 // fit the notebook page to the tab control's display area
675 rc
.left
= rc
.top
= 0;
676 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
678 TabCtrl_AdjustRect(m_hwnd
, FALSE
, &rc
);
680 int width
= rc
.right
- rc
.left
,
681 height
= rc
.bottom
- rc
.top
;
682 size_t nCount
= m_pages
.Count();
683 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ ) {
684 wxNotebookPage
*pPage
= m_pages
[nPage
];
685 pPage
->SetSize(rc
.left
, rc
.top
, width
, height
);
691 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
693 // is it our tab control?
694 if ( event
.GetEventObject() == this )
696 int sel
= event
.GetOldSelection();
698 m_pages
[sel
]->Show(FALSE
);
700 sel
= event
.GetSelection();
703 wxNotebookPage
*pPage
= m_pages
[sel
];
711 // we want to give others a chance to process this message as well
715 void wxNotebook::OnSetFocus(wxFocusEvent
& event
)
717 // this function is only called when the focus is explicitly set (i.e. from
718 // the program) to the notebook - in this case we don't need the
719 // complicated OnNavigationKey() logic because the programmer knows better
722 // set focus to the currently selected page if any
723 if ( m_nSelection
!= -1 )
724 m_pages
[m_nSelection
]->SetFocus();
729 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
731 if ( event
.IsWindowChange() ) {
733 AdvanceSelection(event
.GetDirection());
736 // we get this event in 2 cases
738 // a) one of our pages might have generated it because the user TABbed
739 // out from it in which case we should propagate the event upwards and
740 // our parent will take care of setting the focus to prev/next sibling
744 // b) the parent panel wants to give the focus to us so that we
745 // forward it to our selected page. We can't deal with this in
746 // OnSetFocus() because we don't know which direction the focus came
747 // from in this case and so can't choose between setting the focus to
748 // first or last panel child
749 wxWindow
*parent
= GetParent();
750 // the cast is here to fic a GCC ICE
751 if ( ((wxWindow
*)event
.GetEventObject()) == parent
)
753 // no, it doesn't come from child, case (b): forward to a page
754 if ( m_nSelection
!= -1 )
756 // so that the page knows that the event comes from it's parent
757 // and is being propagated downwards
758 event
.SetEventObject(this);
760 wxWindow
*page
= m_pages
[m_nSelection
];
761 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
765 //else: page manages focus inside it itself
769 // we have no pages - still have to give focus to _something_
775 // it comes from our child, case (a), pass to the parent
777 event
.SetCurrentFocus(this);
778 parent
->GetEventHandler()->ProcessEvent(event
);
784 // ----------------------------------------------------------------------------
785 // wxNotebook base class virtuals
786 // ----------------------------------------------------------------------------
788 #if wxUSE_CONSTRAINTS
790 // override these 2 functions to do nothing: everything is done in OnSize
792 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse
))
794 // don't set the sizes of the pages - their correct size is not yet known
795 wxControl::SetConstraintSizes(FALSE
);
798 bool wxNotebook::DoPhase(int WXUNUSED(nPhase
))
803 #endif // wxUSE_CONSTRAINTS
805 // ----------------------------------------------------------------------------
806 // wxNotebook Windows message handlers
807 // ----------------------------------------------------------------------------
809 bool wxNotebook::MSWOnScroll(int orientation
, WXWORD nSBCode
,
810 WXWORD pos
, WXHWND control
)
812 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
817 return wxNotebookBase::MSWOnScroll(orientation
, nSBCode
, pos
, control
);
820 bool wxNotebook::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
* result
)
822 wxNotebookEvent
event(wxEVT_NULL
, m_windowId
);
824 NMHDR
* hdr
= (NMHDR
*)lParam
;
825 switch ( hdr
->code
) {
827 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
830 case TCN_SELCHANGING
:
831 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
);
835 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
838 event
.SetSelection(TabCtrl_GetCurSel(m_hwnd
));
839 event
.SetOldSelection(m_nSelection
);
840 event
.SetEventObject(this);
841 event
.SetInt(idCtrl
);
843 bool processed
= GetEventHandler()->ProcessEvent(event
);
844 *result
= !event
.IsAllowed();
848 // Windows only: attempts to get colour for UX theme page background
849 wxColour
wxNotebook::GetThemeBackgroundColour()
852 if (wxUxThemeEngine::Get())
854 wxUxThemeHandle
hTheme(this, L
"TAB");
857 // This is total guesswork.
858 // See PlatformSDK\Include\Tmschema.h for values
860 wxUxThemeEngine::Get()->GetThemeColor
865 3821, /* FILLCOLORHINT */
869 wxColour
colour(GetRValue(themeColor
), GetGValue(themeColor
), GetBValue(themeColor
));
873 #endif // wxUSE_UXTHEME
875 return GetBackgroundColour();
878 // Windows only: attempts to apply the UX theme page background to this page
880 void wxNotebook::ApplyThemeBackground(wxWindow
* window
, const wxColour
& colour
)
882 void wxNotebook::ApplyThemeBackground(wxWindow
*, const wxColour
&)
886 // Don't set the background for buttons since this will
887 // switch it into ownerdraw mode
888 if (window
->IsKindOf(CLASSINFO(wxButton
)) && !window
->IsKindOf(CLASSINFO(wxBitmapButton
)))
889 // This is essential, otherwise you'll see dark grey
890 // corners in the buttons.
891 ((wxButton
*)window
)->wxControl::SetBackgroundColour(colour
);
892 else if (window
->IsKindOf(CLASSINFO(wxStaticText
)) ||
893 window
->IsKindOf(CLASSINFO(wxStaticBox
)) ||
894 window
->IsKindOf(CLASSINFO(wxStaticLine
)) ||
895 window
->IsKindOf(CLASSINFO(wxRadioButton
)) ||
896 window
->IsKindOf(CLASSINFO(wxRadioBox
)) ||
897 window
->IsKindOf(CLASSINFO(wxCheckBox
)) ||
898 window
->IsKindOf(CLASSINFO(wxBitmapButton
)) ||
899 window
->IsKindOf(CLASSINFO(wxSlider
)) ||
900 window
->IsKindOf(CLASSINFO(wxPanel
)) ||
901 (window
->IsKindOf(CLASSINFO(wxNotebook
)) && (window
!= this)) ||
902 window
->IsKindOf(CLASSINFO(wxScrolledWindow
))
905 window
->SetBackgroundColour(colour
);
908 for ( wxWindowList::compatibility_iterator node
= window
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
910 wxWindow
*child
= node
->GetData();
911 ApplyThemeBackground(child
, colour
);
916 long wxNotebook::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
918 static bool g_TestedForTheme
= FALSE
;
919 static bool g_UseTheme
= FALSE
;
924 if (!g_TestedForTheme
)
926 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
928 g_UseTheme
= (commCtrlVersion
>= 600);
929 g_TestedForTheme
= TRUE
;
932 // If using XP themes, it seems we can get away
933 // with not drawing a background, which reduces flicker.
939 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
943 #endif // wxUSE_NOTEBOOK