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
120 WX_DEFINE_FLAGS( wxNotebookStyle
)
122 wxBEGIN_FLAGS( wxNotebookStyle
)
123 // new style border flags, we put them first to
124 // use them for streaming out
125 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
126 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
127 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
128 wxFLAGS_MEMBER(wxBORDER_RAISED
)
129 wxFLAGS_MEMBER(wxBORDER_STATIC
)
130 wxFLAGS_MEMBER(wxBORDER_NONE
)
132 // old style border flags
133 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
134 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
135 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
136 wxFLAGS_MEMBER(wxRAISED_BORDER
)
137 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
138 wxFLAGS_MEMBER(wxNO_BORDER
)
140 // standard window styles
141 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
142 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
143 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
144 wxFLAGS_MEMBER(wxWANTS_CHARS
)
145 wxFLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE
)
146 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
147 wxFLAGS_MEMBER(wxVSCROLL
)
148 wxFLAGS_MEMBER(wxHSCROLL
)
150 wxFLAGS_MEMBER(wxNB_FIXEDWIDTH
)
151 wxFLAGS_MEMBER(wxNB_LEFT
)
152 wxFLAGS_MEMBER(wxNB_RIGHT
)
153 wxFLAGS_MEMBER(wxNB_BOTTOM
)
155 wxEND_FLAGS( wxNotebookStyle
)
157 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook
, wxControl
,"wx/notebook.h")
158 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo
, wxObject
, "wx/notebook.h" )
160 wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo
* , wxNotebookPageInfoList
) ;
162 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList
const &theList
, wxxVariantArray
&value
)
164 wxListCollectionToVariantArray
<wxNotebookPageInfoList::compatibility_iterator
>( theList
, value
) ;
167 wxBEGIN_PROPERTIES_TABLE(wxNotebook
)
168 wxEVENT_PROPERTY( PageChanging
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, wxNotebookEvent
)
169 wxEVENT_PROPERTY( PageChanged
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, wxNotebookEvent
)
171 wxPROPERTY_COLLECTION( PageInfos
, wxNotebookPageInfoList
, wxNotebookPageInfo
* , AddPageInfo
, GetPageInfos
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
172 wxPROPERTY_FLAGS( WindowStyle
, wxNotebookStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
173 wxEND_PROPERTIES_TABLE()
175 wxBEGIN_HANDLERS_TABLE(wxNotebook
)
176 wxEND_HANDLERS_TABLE()
178 wxCONSTRUCTOR_5( wxNotebook
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
181 wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo
)
182 wxREADONLY_PROPERTY( Page
, wxNotebookPage
* , GetPage
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
183 wxREADONLY_PROPERTY( Text
, wxString
, GetText
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
184 wxREADONLY_PROPERTY( Selected
, bool , GetSelected
, false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
185 wxREADONLY_PROPERTY( ImageId
, int , GetImageId
, -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
186 wxEND_PROPERTIES_TABLE()
188 wxBEGIN_HANDLERS_TABLE(wxNotebookPageInfo
)
189 wxEND_HANDLERS_TABLE()
191 wxCONSTRUCTOR_4( wxNotebookPageInfo
, wxNotebookPage
* , Page
, wxString
, Text
, bool , Selected
, int , ImageId
)
194 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
195 IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo
, wxObject
)
197 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxNotifyEvent
)
199 // ============================================================================
201 // ============================================================================
203 // ----------------------------------------------------------------------------
204 // wxNotebook construction
205 // ----------------------------------------------------------------------------
207 const wxNotebookPageInfoList
& wxNotebook::GetPageInfos() const
209 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
) ;
210 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
) ;
211 for( size_t i
= 0 ; i
< GetPageCount() ; ++i
)
213 wxNotebookPageInfo
*info
= new wxNotebookPageInfo() ;
214 info
->Create( const_cast<wxNotebook
*>(this)->GetPage(i
) , GetPageText(i
) , GetSelection() == int(i
) , GetPageImage(i
) ) ;
215 list
->Append( info
) ;
220 // common part of all ctors
221 void wxNotebook::Init()
227 // default for dynamic class
228 wxNotebook::wxNotebook()
233 // the same arguments as for wxControl
234 wxNotebook::wxNotebook(wxWindow
*parent
,
239 const wxString
& name
)
243 Create(parent
, id
, pos
, size
, style
, name
);
247 bool wxNotebook::Create(wxWindow
*parent
,
252 const wxString
& name
)
254 // Does ComCtl32 support non-top tabs?
255 int verComCtl32
= wxApp::GetComCtl32Version();
256 if ( verComCtl32
< 470 || verComCtl32
>= 600 )
258 if (style
& wxNB_BOTTOM
)
259 style
&= ~wxNB_BOTTOM
;
261 if (style
& wxNB_LEFT
)
264 if (style
& wxNB_RIGHT
)
265 style
&= ~wxNB_RIGHT
;
268 if ( !CreateControl(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
,
269 wxDefaultValidator
, name
) )
272 if ( !MSWCreateControl(WC_TABCONTROL
, wxEmptyString
, pos
, size
) )
275 SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE
)));
280 WXDWORD
wxNotebook::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
282 WXDWORD tabStyle
= wxControl::MSWGetStyle(style
, exstyle
);
284 tabStyle
|= WS_TABSTOP
| TCS_TABS
;
286 if ( style
& wxNB_MULTILINE
)
287 tabStyle
|= TCS_MULTILINE
;
288 if ( style
& wxNB_FIXEDWIDTH
)
289 tabStyle
|= TCS_FIXEDWIDTH
;
291 if ( style
& wxNB_BOTTOM
)
292 tabStyle
|= TCS_RIGHT
;
293 else if ( style
& wxNB_LEFT
)
294 tabStyle
|= TCS_VERTICAL
;
295 else if ( style
& wxNB_RIGHT
)
296 tabStyle
|= TCS_VERTICAL
| TCS_RIGHT
;
301 // note that we never want to have the default WS_EX_CLIENTEDGE style
302 // as it looks too ugly for the notebooks
309 // ----------------------------------------------------------------------------
310 // wxNotebook accessors
311 // ----------------------------------------------------------------------------
313 size_t wxNotebook::GetPageCount() const
316 wxASSERT( (int)m_pages
.Count() == TabCtrl_GetItemCount(m_hwnd
) );
318 return m_pages
.Count();
321 int wxNotebook::GetRowCount() const
323 return TabCtrl_GetRowCount(m_hwnd
);
326 int wxNotebook::SetSelection(size_t nPage
)
328 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
330 if ( int(nPage
) != m_nSelection
)
332 wxNotebookEvent
event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, m_windowId
);
333 event
.SetSelection(nPage
);
334 event
.SetOldSelection(m_nSelection
);
335 event
.SetEventObject(this);
336 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
338 // program allows the page change
339 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
340 (void)GetEventHandler()->ProcessEvent(event
);
342 TabCtrl_SetCurSel(m_hwnd
, nPage
);
349 bool wxNotebook::SetPageText(size_t nPage
, const wxString
& strText
)
351 wxCHECK_MSG( IS_VALID_PAGE(nPage
), FALSE
, wxT("notebook page out of range") );
354 tcItem
.mask
= TCIF_TEXT
;
355 tcItem
.pszText
= (wxChar
*)strText
.c_str();
357 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
360 wxString
wxNotebook::GetPageText(size_t nPage
) const
362 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxEmptyString
, wxT("notebook page out of range") );
366 tcItem
.mask
= TCIF_TEXT
;
367 tcItem
.pszText
= buf
;
368 tcItem
.cchTextMax
= WXSIZEOF(buf
);
371 if ( TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) )
372 str
= tcItem
.pszText
;
377 int wxNotebook::GetPageImage(size_t nPage
) const
379 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
382 tcItem
.mask
= TCIF_IMAGE
;
384 return TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) ? tcItem
.iImage
: -1;
387 bool wxNotebook::SetPageImage(size_t nPage
, int nImage
)
389 wxCHECK_MSG( IS_VALID_PAGE(nPage
), FALSE
, wxT("notebook page out of range") );
392 tcItem
.mask
= TCIF_IMAGE
;
393 tcItem
.iImage
= nImage
;
395 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
398 void wxNotebook::SetImageList(wxImageList
* imageList
)
400 wxNotebookBase::SetImageList(imageList
);
404 TabCtrl_SetImageList(m_hwnd
, (HIMAGELIST
)imageList
->GetHIMAGELIST());
408 // ----------------------------------------------------------------------------
409 // wxNotebook size settings
410 // ----------------------------------------------------------------------------
412 void wxNotebook::SetPageSize(const wxSize
& size
)
414 // transform the page size into the notebook size
421 TabCtrl_AdjustRect(GetHwnd(), TRUE
, &rc
);
424 SetSize(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
427 void wxNotebook::SetPadding(const wxSize
& padding
)
429 TabCtrl_SetPadding(GetHwnd(), padding
.x
, padding
.y
);
432 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
434 void wxNotebook::SetTabSize(const wxSize
& sz
)
436 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE
, 0, MAKELPARAM(sz
.x
, sz
.y
));
439 wxSize
wxNotebook::CalcSizeFromPage(const wxSize
& sizePage
) const
441 wxSize sizeTotal
= sizePage
;
443 // We need to make getting tab size part of the wxWindows API.
444 wxSize
tabSize(0, 0);
445 if (GetPageCount() > 0)
448 TabCtrl_GetItemRect((HWND
) GetHWND(), 0, & rect
);
449 tabSize
.x
= rect
.right
- rect
.left
;
450 tabSize
.y
= rect
.bottom
- rect
.top
;
452 if ( HasFlag(wxNB_LEFT
) || HasFlag(wxNB_RIGHT
) )
454 sizeTotal
.x
+= tabSize
.x
+ 7;
460 sizeTotal
.y
+= tabSize
.y
+ 7;
466 void wxNotebook::AdjustPageSize(wxNotebookPage
*page
)
468 wxCHECK_RET( page
, _T("NULL page in wxNotebook::AdjustPageSize") );
474 // get the page size from the notebook size
475 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
476 TabCtrl_AdjustRect(m_hwnd
, FALSE
, &rc
);
478 page
->SetSize(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
481 // ----------------------------------------------------------------------------
482 // wxNotebook operations
483 // ----------------------------------------------------------------------------
485 // remove one page from the notebook, without deleting
486 wxNotebookPage
*wxNotebook::DoRemovePage(size_t nPage
)
488 wxNotebookPage
*pageRemoved
= wxNotebookBase::DoRemovePage(nPage
);
492 TabCtrl_DeleteItem(m_hwnd
, nPage
);
494 if ( m_pages
.IsEmpty() )
496 // no selection any more, the notebook becamse empty
499 else // notebook still not empty
501 // change the selected page if it was deleted or became invalid
503 if ( m_nSelection
== int(GetPageCount()) )
505 // last page deleted, make the new last page the new selection
506 selNew
= m_nSelection
- 1;
508 else if ( int(nPage
) <= m_nSelection
)
510 // we must show another page, even if it has the same index
511 selNew
= m_nSelection
;
513 else // nothing changes for the currently selected page
517 // we still must refresh the current page: this needs to be done
518 // for some unknown reason if the tab control shows the up-down
519 // control (i.e. when there are too many pages) -- otherwise after
520 // deleting a page nothing at all is shown
521 if (m_nSelection
>= 0)
522 m_pages
[m_nSelection
]->Refresh();
527 // m_nSelection must be always valid so reset it before calling
530 SetSelection(selNew
);
538 bool wxNotebook::DeleteAllPages()
540 size_t nPageCount
= GetPageCount();
542 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
543 delete m_pages
[nPage
];
547 TabCtrl_DeleteAllItems(m_hwnd
);
554 // same as AddPage() but does it at given position
555 bool wxNotebook::InsertPage(size_t nPage
,
556 wxNotebookPage
*pPage
,
557 const wxString
& strText
,
561 wxCHECK_MSG( pPage
!= NULL
, FALSE
, _T("NULL page in wxNotebook::InsertPage") );
562 wxCHECK_MSG( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), FALSE
,
563 _T("invalid index in wxNotebook::InsertPage") );
565 wxASSERT_MSG( pPage
->GetParent() == this,
566 _T("notebook pages must have notebook as parent") );
568 #if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO
569 static bool g_TestedForTheme
= FALSE
;
570 static bool g_UseTheme
= FALSE
;
571 if (!g_TestedForTheme
)
573 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
575 g_UseTheme
= (commCtrlVersion
>= 600);
576 g_TestedForTheme
= TRUE
;
579 // Automatically apply the theme background,
580 // changing the colour of the panel to match the
581 // tab page colour. This won't work well with all
582 // themes but it's a start.
583 if (g_UseTheme
&& wxUxThemeEngine::Get() && pPage
->IsKindOf(CLASSINFO(wxPanel
)))
585 ApplyThemeBackground(pPage
, GetThemeBackgroundColour());
589 // add a new tab to the control
590 // ----------------------------
592 // init all fields to 0
594 wxZeroMemory(tcItem
);
596 // set the image, if any
599 tcItem
.mask
|= TCIF_IMAGE
;
600 tcItem
.iImage
= imageId
;
604 if ( !strText
.IsEmpty() )
606 tcItem
.mask
|= TCIF_TEXT
;
607 tcItem
.pszText
= (wxChar
*)strText
.c_str(); // const_cast
610 // fit the notebook page to the tab control's display area: this should be
611 // done before adding it to the notebook or TabCtrl_InsertItem() will
612 // change the notebooks size itself!
613 AdjustPageSize(pPage
);
615 // finally do insert it
616 if ( TabCtrl_InsertItem(m_hwnd
, nPage
, &tcItem
) == -1 )
618 wxLogError(wxT("Can't create the notebook page '%s'."), strText
.c_str());
623 // succeeded: save the pointer to the page
624 m_pages
.Insert(pPage
, nPage
);
626 // for the first page (only) we need to adjust the size again because the
627 // notebook size changed: the tabs which hadn't been there before are now
629 if ( m_pages
.GetCount() == 1 )
631 AdjustPageSize(pPage
);
634 // hide the page: unless it is selected, it shouldn't be shown (and if it
635 // is selected it will be shown later)
636 HWND hwnd
= GetWinHwnd(pPage
);
637 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~WS_VISIBLE
);
639 // this updates internal flag too -- otherwise it would get out of sync
640 // with the real state
644 // now deal with the selection
645 // ---------------------------
647 // if the inserted page is before the selected one, we must update the
648 // index of the selected page
649 if ( int(nPage
) <= m_nSelection
)
651 // one extra page added
655 // some page should be selected: either this one or the first one if there
656 // is still no selection
660 else if ( m_nSelection
== -1 )
664 SetSelection(selNew
);
669 int wxNotebook::HitTest(const wxPoint
& pt
, long *flags
) const
671 TC_HITTESTINFO hitTestInfo
;
672 hitTestInfo
.pt
.x
= pt
.x
;
673 hitTestInfo
.pt
.y
= pt
.y
;
674 int item
= TabCtrl_HitTest(GetHwnd(), &hitTestInfo
);
680 if ((hitTestInfo
.flags
& TCHT_NOWHERE
) == TCHT_NOWHERE
)
681 *flags
|= wxNB_HITTEST_NOWHERE
;
682 if ((hitTestInfo
.flags
& TCHT_ONITEM
) == TCHT_ONITEM
)
683 *flags
|= wxNB_HITTEST_ONITEM
;
684 if ((hitTestInfo
.flags
& TCHT_ONITEMICON
) == TCHT_ONITEMICON
)
685 *flags
|= wxNB_HITTEST_ONICON
;
686 if ((hitTestInfo
.flags
& TCHT_ONITEMLABEL
) == TCHT_ONITEMLABEL
)
687 *flags
|= wxNB_HITTEST_ONLABEL
;
694 // ----------------------------------------------------------------------------
695 // wxNotebook callbacks
696 // ----------------------------------------------------------------------------
698 void wxNotebook::OnSize(wxSizeEvent
& event
)
700 // fit the notebook page to the tab control's display area
702 rc
.left
= rc
.top
= 0;
703 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
705 TabCtrl_AdjustRect(m_hwnd
, FALSE
, &rc
);
707 int width
= rc
.right
- rc
.left
,
708 height
= rc
.bottom
- rc
.top
;
709 size_t nCount
= m_pages
.Count();
710 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ ) {
711 wxNotebookPage
*pPage
= m_pages
[nPage
];
712 pPage
->SetSize(rc
.left
, rc
.top
, width
, height
);
718 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
720 // is it our tab control?
721 if ( event
.GetEventObject() == this )
723 int sel
= event
.GetOldSelection();
725 m_pages
[sel
]->Show(FALSE
);
727 sel
= event
.GetSelection();
730 wxNotebookPage
*pPage
= m_pages
[sel
];
738 // we want to give others a chance to process this message as well
742 void wxNotebook::OnSetFocus(wxFocusEvent
& event
)
744 // this function is only called when the focus is explicitly set (i.e. from
745 // the program) to the notebook - in this case we don't need the
746 // complicated OnNavigationKey() logic because the programmer knows better
749 // set focus to the currently selected page if any
750 if ( m_nSelection
!= -1 )
751 m_pages
[m_nSelection
]->SetFocus();
756 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
758 if ( event
.IsWindowChange() ) {
760 AdvanceSelection(event
.GetDirection());
763 // we get this event in 2 cases
765 // a) one of our pages might have generated it because the user TABbed
766 // out from it in which case we should propagate the event upwards and
767 // our parent will take care of setting the focus to prev/next sibling
771 // b) the parent panel wants to give the focus to us so that we
772 // forward it to our selected page. We can't deal with this in
773 // OnSetFocus() because we don't know which direction the focus came
774 // from in this case and so can't choose between setting the focus to
775 // first or last panel child
776 wxWindow
*parent
= GetParent();
777 // the cast is here to fic a GCC ICE
778 if ( ((wxWindow
*)event
.GetEventObject()) == parent
)
780 // no, it doesn't come from child, case (b): forward to a page
781 if ( m_nSelection
!= -1 )
783 // so that the page knows that the event comes from it's parent
784 // and is being propagated downwards
785 event
.SetEventObject(this);
787 wxWindow
*page
= m_pages
[m_nSelection
];
788 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
792 //else: page manages focus inside it itself
796 // we have no pages - still have to give focus to _something_
802 // it comes from our child, case (a), pass to the parent
804 event
.SetCurrentFocus(this);
805 parent
->GetEventHandler()->ProcessEvent(event
);
811 // ----------------------------------------------------------------------------
812 // wxNotebook base class virtuals
813 // ----------------------------------------------------------------------------
815 #if wxUSE_CONSTRAINTS
817 // override these 2 functions to do nothing: everything is done in OnSize
819 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse
))
821 // don't set the sizes of the pages - their correct size is not yet known
822 wxControl::SetConstraintSizes(FALSE
);
825 bool wxNotebook::DoPhase(int WXUNUSED(nPhase
))
830 #endif // wxUSE_CONSTRAINTS
832 // ----------------------------------------------------------------------------
833 // wxNotebook Windows message handlers
834 // ----------------------------------------------------------------------------
836 bool wxNotebook::MSWOnScroll(int orientation
, WXWORD nSBCode
,
837 WXWORD pos
, WXHWND control
)
839 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
844 return wxNotebookBase::MSWOnScroll(orientation
, nSBCode
, pos
, control
);
847 bool wxNotebook::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
* result
)
849 wxNotebookEvent
event(wxEVT_NULL
, m_windowId
);
851 NMHDR
* hdr
= (NMHDR
*)lParam
;
852 switch ( hdr
->code
) {
854 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
857 case TCN_SELCHANGING
:
858 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
);
862 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
865 event
.SetSelection(TabCtrl_GetCurSel(m_hwnd
));
866 event
.SetOldSelection(m_nSelection
);
867 event
.SetEventObject(this);
868 event
.SetInt(idCtrl
);
870 bool processed
= GetEventHandler()->ProcessEvent(event
);
871 *result
= !event
.IsAllowed();
875 // Windows only: attempts to get colour for UX theme page background
876 wxColour
wxNotebook::GetThemeBackgroundColour()
879 if (wxUxThemeEngine::Get())
881 wxUxThemeHandle
hTheme(this, L
"TAB");
884 // This is total guesswork.
885 // See PlatformSDK\Include\Tmschema.h for values
887 wxUxThemeEngine::Get()->GetThemeColor
892 3821, /* FILLCOLORHINT */
896 wxColour
colour(GetRValue(themeColor
), GetGValue(themeColor
), GetBValue(themeColor
));
900 #endif // wxUSE_UXTHEME
902 return GetBackgroundColour();
905 // Windows only: attempts to apply the UX theme page background to this page
907 void wxNotebook::ApplyThemeBackground(wxWindow
* window
, const wxColour
& colour
)
909 void wxNotebook::ApplyThemeBackground(wxWindow
*, const wxColour
&)
913 // Don't set the background for buttons since this will
914 // switch it into ownerdraw mode
915 if (window
->IsKindOf(CLASSINFO(wxButton
)) && !window
->IsKindOf(CLASSINFO(wxBitmapButton
)))
916 // This is essential, otherwise you'll see dark grey
917 // corners in the buttons.
918 ((wxButton
*)window
)->wxControl::SetBackgroundColour(colour
);
919 else if (window
->IsKindOf(CLASSINFO(wxStaticText
)) ||
920 window
->IsKindOf(CLASSINFO(wxStaticBox
)) ||
921 window
->IsKindOf(CLASSINFO(wxStaticLine
)) ||
922 window
->IsKindOf(CLASSINFO(wxRadioButton
)) ||
923 window
->IsKindOf(CLASSINFO(wxRadioBox
)) ||
924 window
->IsKindOf(CLASSINFO(wxCheckBox
)) ||
925 window
->IsKindOf(CLASSINFO(wxBitmapButton
)) ||
926 window
->IsKindOf(CLASSINFO(wxSlider
)) ||
927 window
->IsKindOf(CLASSINFO(wxPanel
)) ||
928 (window
->IsKindOf(CLASSINFO(wxNotebook
)) && (window
!= this)) ||
929 window
->IsKindOf(CLASSINFO(wxScrolledWindow
))
932 window
->SetBackgroundColour(colour
);
935 for ( wxWindowList::compatibility_iterator node
= window
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
937 wxWindow
*child
= node
->GetData();
938 ApplyThemeBackground(child
, colour
);
943 long wxNotebook::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
945 static bool g_TestedForTheme
= FALSE
;
946 static bool g_UseTheme
= FALSE
;
951 if (!g_TestedForTheme
)
953 int commCtrlVersion
= wxTheApp
->GetComCtl32Version() ;
955 g_UseTheme
= (commCtrlVersion
>= 600);
956 g_TestedForTheme
= TRUE
;
959 // If using XP themes, it seems we can get away
960 // with not drawing a background, which reduces flicker.
966 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
970 #endif // wxUSE_NOTEBOOK