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
)
162 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
163 IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo
, wxObject
)
165 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxNotifyEvent
)
167 // ============================================================================
169 // ============================================================================
171 // ----------------------------------------------------------------------------
172 // wxNotebook construction
173 // ----------------------------------------------------------------------------
175 const wxNotebookPageInfoList
& wxNotebook::GetPageInfos() const
177 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
) ;
178 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
) ;
179 for( int i
= 0 ; i
< GetPageCount() ; ++i
)
181 wxNotebookPageInfo
*info
= new wxNotebookPageInfo() ;
182 info
->Create( const_cast<wxNotebook
*>(this)->GetPage(i
) , GetPageText(i
) , GetSelection() == i
, GetPageImage(i
) ) ;
183 list
->Append( info
) ;
188 // common part of all ctors
189 void wxNotebook::Init()
195 // default for dynamic class
196 wxNotebook::wxNotebook()
201 // the same arguments as for wxControl
202 wxNotebook::wxNotebook(wxWindow
*parent
,
207 const wxString
& name
)
211 Create(parent
, id
, pos
, size
, style
, name
);
215 bool wxNotebook::Create(wxWindow
*parent
,
220 const wxString
& name
)
222 // Does ComCtl32 support non-top tabs?
223 int verComCtl32
= wxApp::GetComCtl32Version();
224 if ( verComCtl32
< 470 || verComCtl32
>= 600 )
226 if (style
& wxNB_BOTTOM
)
227 style
&= ~wxNB_BOTTOM
;
229 if (style
& wxNB_LEFT
)
232 if (style
& wxNB_RIGHT
)
233 style
&= ~wxNB_RIGHT
;
236 if ( !CreateControl(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
,
237 wxDefaultValidator
, name
) )
240 if ( !MSWCreateControl(WC_TABCONTROL
, wxEmptyString
, pos
, size
) )
243 SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE
)));
248 WXDWORD
wxNotebook::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
250 WXDWORD tabStyle
= wxControl::MSWGetStyle(style
, exstyle
);
252 tabStyle
|= WS_TABSTOP
| TCS_TABS
;
254 if ( style
& wxNB_MULTILINE
)
255 tabStyle
|= TCS_MULTILINE
;
256 if ( style
& wxNB_FIXEDWIDTH
)
257 tabStyle
|= TCS_FIXEDWIDTH
;
259 if ( style
& wxNB_BOTTOM
)
260 tabStyle
|= TCS_RIGHT
;
261 else if ( style
& wxNB_LEFT
)
262 tabStyle
|= TCS_VERTICAL
;
263 else if ( style
& wxNB_RIGHT
)
264 tabStyle
|= TCS_VERTICAL
| TCS_RIGHT
;
269 // note that we never want to have the default WS_EX_CLIENTEDGE style
270 // as it looks too ugly for the notebooks
277 // ----------------------------------------------------------------------------
278 // wxNotebook accessors
279 // ----------------------------------------------------------------------------
281 int wxNotebook::GetPageCount() const
284 wxASSERT( (int)m_pages
.Count() == TabCtrl_GetItemCount(m_hwnd
) );
286 return m_pages
.Count();
289 int wxNotebook::GetRowCount() const
291 return TabCtrl_GetRowCount(m_hwnd
);
294 int wxNotebook::SetSelection(int nPage
)
296 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
298 if ( nPage
!= m_nSelection
)
300 wxNotebookEvent
event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, m_windowId
);
301 event
.SetSelection(nPage
);
302 event
.SetOldSelection(m_nSelection
);
303 event
.SetEventObject(this);
304 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
306 // program allows the page change
307 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
308 (void)GetEventHandler()->ProcessEvent(event
);
310 TabCtrl_SetCurSel(m_hwnd
, nPage
);
317 bool wxNotebook::SetPageText(int nPage
, const wxString
& strText
)
319 wxCHECK_MSG( IS_VALID_PAGE(nPage
), FALSE
, wxT("notebook page out of range") );
322 tcItem
.mask
= TCIF_TEXT
;
323 tcItem
.pszText
= (wxChar
*)strText
.c_str();
325 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
328 wxString
wxNotebook::GetPageText(int nPage
) const
330 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxEmptyString
, wxT("notebook page out of range") );
334 tcItem
.mask
= TCIF_TEXT
;
335 tcItem
.pszText
= buf
;
336 tcItem
.cchTextMax
= WXSIZEOF(buf
);
339 if ( TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) )
340 str
= tcItem
.pszText
;
345 int wxNotebook::GetPageImage(int nPage
) const
347 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
350 tcItem
.mask
= TCIF_IMAGE
;
352 return TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) ? tcItem
.iImage
: -1;
355 bool wxNotebook::SetPageImage(int nPage
, int nImage
)
357 wxCHECK_MSG( IS_VALID_PAGE(nPage
), FALSE
, wxT("notebook page out of range") );
360 tcItem
.mask
= TCIF_IMAGE
;
361 tcItem
.iImage
= nImage
;
363 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
366 void wxNotebook::SetImageList(wxImageList
* imageList
)
368 wxNotebookBase::SetImageList(imageList
);
372 TabCtrl_SetImageList(m_hwnd
, (HIMAGELIST
)imageList
->GetHIMAGELIST());
376 // ----------------------------------------------------------------------------
377 // wxNotebook size settings
378 // ----------------------------------------------------------------------------
380 void wxNotebook::SetPageSize(const wxSize
& size
)
382 // transform the page size into the notebook size
389 TabCtrl_AdjustRect(GetHwnd(), TRUE
, &rc
);
392 SetSize(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
395 void wxNotebook::SetPadding(const wxSize
& padding
)
397 TabCtrl_SetPadding(GetHwnd(), padding
.x
, padding
.y
);
400 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
402 void wxNotebook::SetTabSize(const wxSize
& sz
)
404 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE
, 0, MAKELPARAM(sz
.x
, sz
.y
));
407 wxSize
wxNotebook::CalcSizeFromPage(const wxSize
& sizePage
) const
409 wxSize sizeTotal
= sizePage
;
411 // We need to make getting tab size part of the wxWindows API.
412 wxSize
tabSize(0, 0);
413 if (GetPageCount() > 0)
416 TabCtrl_GetItemRect((HWND
) GetHWND(), 0, & rect
);
417 tabSize
.x
= rect
.right
- rect
.left
;
418 tabSize
.y
= rect
.bottom
- rect
.top
;
420 if ( HasFlag(wxNB_LEFT
) || HasFlag(wxNB_RIGHT
) )
422 sizeTotal
.x
+= tabSize
.x
+ 7;
428 sizeTotal
.y
+= tabSize
.y
+ 7;
434 void wxNotebook::AdjustPageSize(wxNotebookPage
*page
)
436 wxCHECK_RET( page
, _T("NULL page in wxNotebook::AdjustPageSize") );
442 // get the page size from the notebook size
443 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
444 TabCtrl_AdjustRect(m_hwnd
, FALSE
, &rc
);
446 page
->SetSize(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
449 // ----------------------------------------------------------------------------
450 // wxNotebook operations
451 // ----------------------------------------------------------------------------
453 // remove one page from the notebook, without deleting
454 wxNotebookPage
*wxNotebook::DoRemovePage(int nPage
)
456 wxNotebookPage
*pageRemoved
= wxNotebookBase::DoRemovePage(nPage
);
460 TabCtrl_DeleteItem(m_hwnd
, nPage
);
462 if ( m_pages
.IsEmpty() )
464 // no selection any more, the notebook becamse empty
467 else // notebook still not empty
469 // change the selected page if it was deleted or became invalid
471 if ( m_nSelection
== GetPageCount() )
473 // last page deleted, make the new last page the new selection
474 selNew
= m_nSelection
- 1;
476 else if ( nPage
<= m_nSelection
)
478 // we must show another page, even if it has the same index
479 selNew
= m_nSelection
;
481 else // nothing changes for the currently selected page
485 // we still must refresh the current page: this needs to be done
486 // for some unknown reason if the tab control shows the up-down
487 // control (i.e. when there are too many pages) -- otherwise after
488 // deleting a page nothing at all is shown
489 if (m_nSelection
>= 0)
490 m_pages
[m_nSelection
]->Refresh();
495 // m_nSelection must be always valid so reset it before calling
498 SetSelection(selNew
);
506 bool wxNotebook::DeleteAllPages()
508 int nPageCount
= GetPageCount();
510 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
511 delete m_pages
[nPage
];
515 TabCtrl_DeleteAllItems(m_hwnd
);
522 // same as AddPage() but does it at given position
523 bool wxNotebook::InsertPage(int nPage
,
524 wxNotebookPage
*pPage
,
525 const wxString
& strText
,
529 wxCHECK_MSG( pPage
!= NULL
, FALSE
, _T("NULL page in wxNotebook::InsertPage") );
530 wxCHECK_MSG( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), FALSE
,
531 _T("invalid index in wxNotebook::InsertPage") );
533 wxASSERT_MSG( pPage
->GetParent() == this,
534 _T("notebook pages must have notebook as parent") );
536 #if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO
537 static bool g_TestedForTheme
= FALSE
;
538 static bool g_UseTheme
= FALSE
;
539 if (!g_TestedForTheme
)
541 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
543 g_UseTheme
= (commCtrlVersion
>= 600);
544 g_TestedForTheme
= TRUE
;
547 // Automatically apply the theme background,
548 // changing the colour of the panel to match the
549 // tab page colour. This won't work well with all
550 // themes but it's a start.
551 if (g_UseTheme
&& wxUxThemeEngine::Get() && pPage
->IsKindOf(CLASSINFO(wxPanel
)))
553 ApplyThemeBackground(pPage
, GetThemeBackgroundColour());
557 // add a new tab to the control
558 // ----------------------------
560 // init all fields to 0
562 wxZeroMemory(tcItem
);
564 // set the image, if any
567 tcItem
.mask
|= TCIF_IMAGE
;
568 tcItem
.iImage
= imageId
;
572 if ( !strText
.IsEmpty() )
574 tcItem
.mask
|= TCIF_TEXT
;
575 tcItem
.pszText
= (wxChar
*)strText
.c_str(); // const_cast
578 // fit the notebook page to the tab control's display area: this should be
579 // done before adding it to the notebook or TabCtrl_InsertItem() will
580 // change the notebooks size itself!
581 AdjustPageSize(pPage
);
583 // finally do insert it
584 if ( TabCtrl_InsertItem(m_hwnd
, nPage
, &tcItem
) == -1 )
586 wxLogError(wxT("Can't create the notebook page '%s'."), strText
.c_str());
591 // succeeded: save the pointer to the page
592 m_pages
.Insert(pPage
, nPage
);
594 // for the first page (only) we need to adjust the size again because the
595 // notebook size changed: the tabs which hadn't been there before are now
597 if ( m_pages
.GetCount() == 1 )
599 AdjustPageSize(pPage
);
602 // hide the page: unless it is selected, it shouldn't be shown (and if it
603 // is selected it will be shown later)
604 HWND hwnd
= GetWinHwnd(pPage
);
605 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~WS_VISIBLE
);
607 // this updates internal flag too -- otherwise it would get out of sync
608 // with the real state
612 // now deal with the selection
613 // ---------------------------
615 // if the inserted page is before the selected one, we must update the
616 // index of the selected page
617 if ( nPage
<= m_nSelection
)
619 // one extra page added
623 // some page should be selected: either this one or the first one if there
624 // is still no selection
628 else if ( m_nSelection
== -1 )
632 SetSelection(selNew
);
637 int wxNotebook::HitTest(const wxPoint
& pt
, long *flags
) const
639 TC_HITTESTINFO hitTestInfo
;
640 hitTestInfo
.pt
.x
= pt
.x
;
641 hitTestInfo
.pt
.y
= pt
.y
;
642 int item
= TabCtrl_HitTest(GetHwnd(), &hitTestInfo
);
648 if ((hitTestInfo
.flags
& TCHT_NOWHERE
) == TCHT_NOWHERE
)
649 *flags
|= wxNB_HITTEST_NOWHERE
;
650 if ((hitTestInfo
.flags
& TCHT_ONITEM
) == TCHT_ONITEM
)
651 *flags
|= wxNB_HITTEST_ONITEM
;
652 if ((hitTestInfo
.flags
& TCHT_ONITEMICON
) == TCHT_ONITEMICON
)
653 *flags
|= wxNB_HITTEST_ONICON
;
654 if ((hitTestInfo
.flags
& TCHT_ONITEMLABEL
) == TCHT_ONITEMLABEL
)
655 *flags
|= wxNB_HITTEST_ONLABEL
;
662 // ----------------------------------------------------------------------------
663 // wxNotebook callbacks
664 // ----------------------------------------------------------------------------
666 void wxNotebook::OnSize(wxSizeEvent
& event
)
668 // fit the notebook page to the tab control's display area
670 rc
.left
= rc
.top
= 0;
671 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
673 TabCtrl_AdjustRect(m_hwnd
, FALSE
, &rc
);
675 int width
= rc
.right
- rc
.left
,
676 height
= rc
.bottom
- rc
.top
;
677 size_t nCount
= m_pages
.Count();
678 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ ) {
679 wxNotebookPage
*pPage
= m_pages
[nPage
];
680 pPage
->SetSize(rc
.left
, rc
.top
, width
, height
);
686 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
688 // is it our tab control?
689 if ( event
.GetEventObject() == this )
691 int sel
= event
.GetOldSelection();
693 m_pages
[sel
]->Show(FALSE
);
695 sel
= event
.GetSelection();
698 wxNotebookPage
*pPage
= m_pages
[sel
];
706 // we want to give others a chance to process this message as well
710 void wxNotebook::OnSetFocus(wxFocusEvent
& event
)
712 // this function is only called when the focus is explicitly set (i.e. from
713 // the program) to the notebook - in this case we don't need the
714 // complicated OnNavigationKey() logic because the programmer knows better
717 // set focus to the currently selected page if any
718 if ( m_nSelection
!= -1 )
719 m_pages
[m_nSelection
]->SetFocus();
724 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
726 if ( event
.IsWindowChange() ) {
728 AdvanceSelection(event
.GetDirection());
731 // we get this event in 2 cases
733 // a) one of our pages might have generated it because the user TABbed
734 // out from it in which case we should propagate the event upwards and
735 // our parent will take care of setting the focus to prev/next sibling
739 // b) the parent panel wants to give the focus to us so that we
740 // forward it to our selected page. We can't deal with this in
741 // OnSetFocus() because we don't know which direction the focus came
742 // from in this case and so can't choose between setting the focus to
743 // first or last panel child
744 wxWindow
*parent
= GetParent();
745 // the cast is here to fic a GCC ICE
746 if ( ((wxWindow
*)event
.GetEventObject()) == parent
)
748 // no, it doesn't come from child, case (b): forward to a page
749 if ( m_nSelection
!= -1 )
751 // so that the page knows that the event comes from it's parent
752 // and is being propagated downwards
753 event
.SetEventObject(this);
755 wxWindow
*page
= m_pages
[m_nSelection
];
756 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
760 //else: page manages focus inside it itself
764 // we have no pages - still have to give focus to _something_
770 // it comes from our child, case (a), pass to the parent
772 event
.SetCurrentFocus(this);
773 parent
->GetEventHandler()->ProcessEvent(event
);
779 // ----------------------------------------------------------------------------
780 // wxNotebook base class virtuals
781 // ----------------------------------------------------------------------------
783 #if wxUSE_CONSTRAINTS
785 // override these 2 functions to do nothing: everything is done in OnSize
787 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse
))
789 // don't set the sizes of the pages - their correct size is not yet known
790 wxControl::SetConstraintSizes(FALSE
);
793 bool wxNotebook::DoPhase(int WXUNUSED(nPhase
))
798 #endif // wxUSE_CONSTRAINTS
800 // ----------------------------------------------------------------------------
801 // wxNotebook Windows message handlers
802 // ----------------------------------------------------------------------------
804 bool wxNotebook::MSWOnScroll(int orientation
, WXWORD nSBCode
,
805 WXWORD pos
, WXHWND control
)
807 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
812 return wxNotebookBase::MSWOnScroll(orientation
, nSBCode
, pos
, control
);
815 bool wxNotebook::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
* result
)
817 wxNotebookEvent
event(wxEVT_NULL
, m_windowId
);
819 NMHDR
* hdr
= (NMHDR
*)lParam
;
820 switch ( hdr
->code
) {
822 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
825 case TCN_SELCHANGING
:
826 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
);
830 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
833 event
.SetSelection(TabCtrl_GetCurSel(m_hwnd
));
834 event
.SetOldSelection(m_nSelection
);
835 event
.SetEventObject(this);
836 event
.SetInt(idCtrl
);
838 bool processed
= GetEventHandler()->ProcessEvent(event
);
839 *result
= !event
.IsAllowed();
843 // Windows only: attempts to get colour for UX theme page background
844 wxColour
wxNotebook::GetThemeBackgroundColour()
847 if (wxUxThemeEngine::Get())
849 wxUxThemeHandle
hTheme(this, L
"TAB");
852 // This is total guesswork.
853 // See PlatformSDK\Include\Tmschema.h for values
855 wxUxThemeEngine::Get()->GetThemeColor
860 3821, /* FILLCOLORHINT */
864 wxColour
colour(GetRValue(themeColor
), GetGValue(themeColor
), GetBValue(themeColor
));
868 #endif // wxUSE_UXTHEME
870 return GetBackgroundColour();
873 // Windows only: attempts to apply the UX theme page background to this page
875 void wxNotebook::ApplyThemeBackground(wxWindow
* window
, const wxColour
& colour
)
877 void wxNotebook::ApplyThemeBackground(wxWindow
*, const wxColour
&)
881 // Don't set the background for buttons since this will
882 // switch it into ownerdraw mode
883 if (window
->IsKindOf(CLASSINFO(wxButton
)) && !window
->IsKindOf(CLASSINFO(wxBitmapButton
)))
884 // This is essential, otherwise you'll see dark grey
885 // corners in the buttons.
886 ((wxButton
*)window
)->wxControl::SetBackgroundColour(colour
);
887 else if (window
->IsKindOf(CLASSINFO(wxStaticText
)) ||
888 window
->IsKindOf(CLASSINFO(wxStaticBox
)) ||
889 window
->IsKindOf(CLASSINFO(wxStaticLine
)) ||
890 window
->IsKindOf(CLASSINFO(wxRadioButton
)) ||
891 window
->IsKindOf(CLASSINFO(wxRadioBox
)) ||
892 window
->IsKindOf(CLASSINFO(wxCheckBox
)) ||
893 window
->IsKindOf(CLASSINFO(wxBitmapButton
)) ||
894 window
->IsKindOf(CLASSINFO(wxSlider
)) ||
895 window
->IsKindOf(CLASSINFO(wxPanel
)) ||
896 (window
->IsKindOf(CLASSINFO(wxNotebook
)) && (window
!= this)) ||
897 window
->IsKindOf(CLASSINFO(wxScrolledWindow
))
900 window
->SetBackgroundColour(colour
);
903 for ( wxWindowList::compatibility_iterator node
= window
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
905 wxWindow
*child
= node
->GetData();
906 ApplyThemeBackground(child
, colour
);
911 long wxNotebook::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
913 static bool g_TestedForTheme
= FALSE
;
914 static bool g_UseTheme
= FALSE
;
919 if (!g_TestedForTheme
)
921 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
923 g_UseTheme
= (commCtrlVersion
>= 600);
924 g_TestedForTheme
= TRUE
;
927 // If using XP themes, it seems we can get away
928 // with not drawing a background, which reduces flicker.
934 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
938 #endif // wxUSE_NOTEBOOK