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"
32 #include "wx/imaglist.h"
34 #include "wx/control.h"
35 #include "wx/notebook.h"
38 #include "wx/msw/private.h"
40 // Windows standard headers
42 #error "wxNotebook is only supported Windows 95 and above"
45 #include <windowsx.h> // for SetWindowFont
47 #ifdef __GNUWIN32_OLD__
48 #include "wx/msw/gnuwin32/extra.h"
51 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
55 #include "wx/msw/winundef.h"
58 #include "wx/msw/uxtheme.h"
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 // check that the page index is valid
66 #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
69 #define m_hwnd (HWND)GetHWND()
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 // This is a work-around for missing defines in gcc-2.95 headers
77 #define TCS_RIGHT 0x0002
81 #define TCS_VERTICAL 0x0080
85 #define TCS_BOTTOM TCS_RIGHT
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 #include <wx/listimpl.cpp>
94 WX_DEFINE_LIST( wxNotebookPageInfoList
) ;
96 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
)
97 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
)
99 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
100 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange
)
102 EVT_SIZE(wxNotebook::OnSize
)
104 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey
)
107 #if wxUSE_EXTENDED_RTTI
108 WX_DEFINE_FLAGS( wxNotebookStyle
)
110 wxBEGIN_FLAGS( wxNotebookStyle
)
111 // new style border flags, we put them first to
112 // use them for streaming out
113 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
114 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
115 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
116 wxFLAGS_MEMBER(wxBORDER_RAISED
)
117 wxFLAGS_MEMBER(wxBORDER_STATIC
)
118 wxFLAGS_MEMBER(wxBORDER_NONE
)
120 // old style border flags
121 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
122 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
123 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
124 wxFLAGS_MEMBER(wxRAISED_BORDER
)
125 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
126 wxFLAGS_MEMBER(wxBORDER
)
128 // standard window styles
129 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
130 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
131 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
132 wxFLAGS_MEMBER(wxWANTS_CHARS
)
133 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
134 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
135 wxFLAGS_MEMBER(wxVSCROLL
)
136 wxFLAGS_MEMBER(wxHSCROLL
)
138 wxFLAGS_MEMBER(wxNB_FIXEDWIDTH
)
139 wxFLAGS_MEMBER(wxNB_LEFT
)
140 wxFLAGS_MEMBER(wxNB_RIGHT
)
141 wxFLAGS_MEMBER(wxNB_BOTTOM
)
143 wxEND_FLAGS( wxNotebookStyle
)
145 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook
, wxControl
,"wx/notebook.h")
146 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo
, wxObject
, "wx/notebook.h" )
148 wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo
* , wxNotebookPageInfoList
) ;
150 template<> void wxCollectionToVariantArray( wxNotebookPageInfoList
const &theList
, wxxVariantArray
&value
)
152 wxListCollectionToVariantArray
<wxNotebookPageInfoList::compatibility_iterator
>( theList
, value
) ;
155 wxBEGIN_PROPERTIES_TABLE(wxNotebook
)
156 wxEVENT_PROPERTY( PageChanging
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, wxNotebookEvent
)
157 wxEVENT_PROPERTY( PageChanged
, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, wxNotebookEvent
)
159 wxPROPERTY_COLLECTION( PageInfos
, wxNotebookPageInfoList
, wxNotebookPageInfo
* , AddPageInfo
, GetPageInfos
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
160 wxPROPERTY_FLAGS( WindowStyle
, wxNotebookStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
161 wxEND_PROPERTIES_TABLE()
163 wxBEGIN_HANDLERS_TABLE(wxNotebook
)
164 wxEND_HANDLERS_TABLE()
166 wxCONSTRUCTOR_5( wxNotebook
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
169 wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo
)
170 wxREADONLY_PROPERTY( Page
, wxNotebookPage
* , GetPage
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
171 wxREADONLY_PROPERTY( Text
, wxString
, GetText
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
172 wxREADONLY_PROPERTY( Selected
, bool , GetSelected
, false, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
173 wxREADONLY_PROPERTY( ImageId
, int , GetImageId
, -1 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
174 wxEND_PROPERTIES_TABLE()
176 wxBEGIN_HANDLERS_TABLE(wxNotebookPageInfo
)
177 wxEND_HANDLERS_TABLE()
179 wxCONSTRUCTOR_4( wxNotebookPageInfo
, wxNotebookPage
* , Page
, wxString
, Text
, bool , Selected
, int , ImageId
)
182 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
, wxControl
)
183 IMPLEMENT_DYNAMIC_CLASS(wxNotebookPageInfo
, wxObject
)
185 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent
, wxNotifyEvent
)
187 // ============================================================================
189 // ============================================================================
191 // ----------------------------------------------------------------------------
192 // wxNotebook construction
193 // ----------------------------------------------------------------------------
195 const wxNotebookPageInfoList
& wxNotebook::GetPageInfos() const
197 wxNotebookPageInfoList
* list
= const_cast< wxNotebookPageInfoList
* >( &m_pageInfos
) ;
198 WX_CLEAR_LIST( wxNotebookPageInfoList
, *list
) ;
199 for( size_t i
= 0 ; i
< GetPageCount() ; ++i
)
201 wxNotebookPageInfo
*info
= new wxNotebookPageInfo() ;
202 info
->Create( const_cast<wxNotebook
*>(this)->GetPage(i
) , GetPageText(i
) , GetSelection() == int(i
) , GetPageImage(i
) ) ;
203 list
->Append( info
) ;
208 // common part of all ctors
209 void wxNotebook::Init()
215 m_hbrBackground
= NULL
;
216 #endif // wxUSE_UXTHEME
219 // default for dynamic class
220 wxNotebook::wxNotebook()
225 // the same arguments as for wxControl
226 wxNotebook::wxNotebook(wxWindow
*parent
,
231 const wxString
& name
)
235 Create(parent
, id
, pos
, size
, style
, name
);
239 bool wxNotebook::Create(wxWindow
*parent
,
244 const wxString
& name
)
246 // comctl32.dll 6.0 doesn't support non-top tabs with visual styles (the
247 // control is simply not rendered correctly), so disable them in this case
248 const int verComCtl32
= wxApp::GetComCtl32Version();
249 if ( verComCtl32
== 600 )
251 // check if we use themes at all -- if we don't, we're still ok
253 if ( wxUxThemeEngine::GetIfActive() )
256 style
&= ~(wxNB_BOTTOM
| wxNB_LEFT
| wxNB_RIGHT
);
260 if ( !CreateControl(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
,
261 wxDefaultValidator
, name
) )
264 if ( !MSWCreateControl(WC_TABCONTROL
, wxEmptyString
, pos
, size
) )
270 WXDWORD
wxNotebook::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
272 WXDWORD tabStyle
= wxControl::MSWGetStyle(style
, exstyle
);
274 tabStyle
|= WS_TABSTOP
| TCS_TABS
;
276 if ( style
& wxNB_MULTILINE
)
277 tabStyle
|= TCS_MULTILINE
;
278 if ( style
& wxNB_FIXEDWIDTH
)
279 tabStyle
|= TCS_FIXEDWIDTH
;
281 if ( style
& wxNB_BOTTOM
)
282 tabStyle
|= TCS_RIGHT
;
283 else if ( style
& wxNB_LEFT
)
284 tabStyle
|= TCS_VERTICAL
;
285 else if ( style
& wxNB_RIGHT
)
286 tabStyle
|= TCS_VERTICAL
| TCS_RIGHT
;
291 // note that we never want to have the default WS_EX_CLIENTEDGE style
292 // as it looks too ugly for the notebooks
299 wxNotebook::~wxNotebook()
302 if ( m_hbrBackground
)
303 ::DeleteObject((HBRUSH
)m_hbrBackground
);
304 #endif // wxUSE_UXTHEME
307 // ----------------------------------------------------------------------------
308 // wxNotebook accessors
309 // ----------------------------------------------------------------------------
311 size_t wxNotebook::GetPageCount() const
314 wxASSERT( (int)m_pages
.Count() == TabCtrl_GetItemCount(m_hwnd
) );
316 return m_pages
.Count();
319 int wxNotebook::GetRowCount() const
321 return TabCtrl_GetRowCount(m_hwnd
);
324 int wxNotebook::SetSelection(size_t nPage
)
326 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxNOT_FOUND
, wxT("notebook page out of range") );
328 if ( int(nPage
) != m_nSelection
)
330 wxNotebookEvent
event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, m_windowId
);
331 event
.SetSelection(nPage
);
332 event
.SetOldSelection(m_nSelection
);
333 event
.SetEventObject(this);
334 if ( !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed() )
336 // program allows the page change
337 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
338 (void)GetEventHandler()->ProcessEvent(event
);
340 TabCtrl_SetCurSel(m_hwnd
, nPage
);
347 bool wxNotebook::SetPageText(size_t nPage
, const wxString
& strText
)
349 wxCHECK_MSG( IS_VALID_PAGE(nPage
), false, wxT("notebook page out of range") );
352 tcItem
.mask
= TCIF_TEXT
;
353 tcItem
.pszText
= (wxChar
*)strText
.c_str();
355 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
358 wxString
wxNotebook::GetPageText(size_t nPage
) const
360 wxCHECK_MSG( IS_VALID_PAGE(nPage
), wxEmptyString
, wxT("notebook page out of range") );
364 tcItem
.mask
= TCIF_TEXT
;
365 tcItem
.pszText
= buf
;
366 tcItem
.cchTextMax
= WXSIZEOF(buf
);
369 if ( TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) )
370 str
= tcItem
.pszText
;
375 int wxNotebook::GetPageImage(size_t nPage
) const
377 wxCHECK_MSG( IS_VALID_PAGE(nPage
), -1, wxT("notebook page out of range") );
380 tcItem
.mask
= TCIF_IMAGE
;
382 return TabCtrl_GetItem(m_hwnd
, nPage
, &tcItem
) ? tcItem
.iImage
: -1;
385 bool wxNotebook::SetPageImage(size_t nPage
, int nImage
)
387 wxCHECK_MSG( IS_VALID_PAGE(nPage
), false, wxT("notebook page out of range") );
390 tcItem
.mask
= TCIF_IMAGE
;
391 tcItem
.iImage
= nImage
;
393 return TabCtrl_SetItem(m_hwnd
, nPage
, &tcItem
) != 0;
396 void wxNotebook::SetImageList(wxImageList
* imageList
)
398 wxNotebookBase::SetImageList(imageList
);
402 TabCtrl_SetImageList(m_hwnd
, (HIMAGELIST
)imageList
->GetHIMAGELIST());
406 // ----------------------------------------------------------------------------
407 // wxNotebook size settings
408 // ----------------------------------------------------------------------------
410 void wxNotebook::SetPageSize(const wxSize
& size
)
412 // transform the page size into the notebook size
419 TabCtrl_AdjustRect(GetHwnd(), true, &rc
);
422 SetSize(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
425 void wxNotebook::SetPadding(const wxSize
& padding
)
427 TabCtrl_SetPadding(GetHwnd(), padding
.x
, padding
.y
);
430 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
432 void wxNotebook::SetTabSize(const wxSize
& sz
)
434 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE
, 0, MAKELPARAM(sz
.x
, sz
.y
));
437 wxSize
wxNotebook::CalcSizeFromPage(const wxSize
& sizePage
) const
439 wxSize sizeTotal
= sizePage
;
441 // We need to make getting tab size part of the wxWidgets API.
442 wxSize
tabSize(0, 0);
443 if (GetPageCount() > 0)
446 TabCtrl_GetItemRect((HWND
) GetHWND(), 0, & rect
);
447 tabSize
.x
= rect
.right
- rect
.left
;
448 tabSize
.y
= rect
.bottom
- rect
.top
;
450 if ( HasFlag(wxNB_LEFT
) || HasFlag(wxNB_RIGHT
) )
452 sizeTotal
.x
+= tabSize
.x
+ 7;
458 sizeTotal
.y
+= tabSize
.y
+ 7;
464 void wxNotebook::AdjustPageSize(wxNotebookPage
*page
)
466 wxCHECK_RET( page
, _T("NULL page in wxNotebook::AdjustPageSize") );
472 // get the page size from the notebook size
473 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
475 // This check is to work around a bug in TabCtrl_AdjustRect which will
476 // cause a crash on win2k, or on XP with themes disabled, if the
477 // wxNB_MULTILINE style is used and the rectangle is very small, (such as
478 // when the notebook is first created.) The value of 20 is just
479 // arbitrarily chosen, if there is a better way to determine this value
480 // then please do so. --RD
481 if (rc
.right
> 20 && rc
.bottom
> 20)
483 TabCtrl_AdjustRect(m_hwnd
, false, &rc
);
484 page
->SetSize(rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
488 // ----------------------------------------------------------------------------
489 // wxNotebook operations
490 // ----------------------------------------------------------------------------
492 // remove one page from the notebook, without deleting
493 wxNotebookPage
*wxNotebook::DoRemovePage(size_t nPage
)
495 wxNotebookPage
*pageRemoved
= wxNotebookBase::DoRemovePage(nPage
);
499 TabCtrl_DeleteItem(m_hwnd
, nPage
);
501 if ( m_pages
.IsEmpty() )
503 // no selection any more, the notebook becamse empty
506 else // notebook still not empty
508 int selNew
= TabCtrl_GetCurSel(m_hwnd
);
511 // No selection change, just refresh the current selection.
512 // Because it could be that the slection index changed
513 // we need to update it.
514 // Note: this does not mean the selection it self changed.
515 m_nSelection
= selNew
;
516 m_pages
[m_nSelection
]->Refresh();
518 else if (int(nPage
) == m_nSelection
)
520 // The selection was deleted.
522 // Determine new selection.
523 if (m_nSelection
== int(GetPageCount()))
524 selNew
= m_nSelection
- 1;
526 selNew
= m_nSelection
;
528 // m_nSelection must be always valid so reset it before calling
531 SetSelection(selNew
);
535 wxFAIL
; // Windows did not behave ok.
543 bool wxNotebook::DeleteAllPages()
545 size_t nPageCount
= GetPageCount();
547 for ( nPage
= 0; nPage
< nPageCount
; nPage
++ )
548 delete m_pages
[nPage
];
552 TabCtrl_DeleteAllItems(m_hwnd
);
556 InvalidateBestSize();
560 // same as AddPage() but does it at given position
561 bool wxNotebook::InsertPage(size_t nPage
,
562 wxNotebookPage
*pPage
,
563 const wxString
& strText
,
567 wxCHECK_MSG( pPage
!= NULL
, false, _T("NULL page in wxNotebook::InsertPage") );
568 wxCHECK_MSG( IS_VALID_PAGE(nPage
) || nPage
== GetPageCount(), false,
569 _T("invalid index in wxNotebook::InsertPage") );
571 wxASSERT_MSG( pPage
->GetParent() == this,
572 _T("notebook pages must have notebook as parent") );
574 // add a new tab to the control
575 // ----------------------------
577 // init all fields to 0
579 wxZeroMemory(tcItem
);
581 // set the image, if any
584 tcItem
.mask
|= TCIF_IMAGE
;
585 tcItem
.iImage
= imageId
;
589 if ( !strText
.IsEmpty() )
591 tcItem
.mask
|= TCIF_TEXT
;
592 tcItem
.pszText
= (wxChar
*)strText
.c_str(); // const_cast
595 // hide the page: unless it is selected, it shouldn't be shown (and if it
596 // is selected it will be shown later)
597 HWND hwnd
= GetWinHwnd(pPage
);
598 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~WS_VISIBLE
);
600 // this updates internal flag too -- otherwise it would get out of sync
601 // with the real state
605 // fit the notebook page to the tab control's display area: this should be
606 // done before adding it to the notebook or TabCtrl_InsertItem() will
607 // change the notebooks size itself!
608 AdjustPageSize(pPage
);
610 // finally do insert it
611 if ( TabCtrl_InsertItem(m_hwnd
, nPage
, &tcItem
) == -1 )
613 wxLogError(wxT("Can't create the notebook page '%s'."), strText
.c_str());
618 // succeeded: save the pointer to the page
619 m_pages
.Insert(pPage
, nPage
);
621 // we may need to adjust the size again if the notebook size changed:
622 // normally this only happens for the first page we add (the tabs which
623 // hadn't been there before are now shown) but for a multiline notebook it
624 // can happen for any page at all as a new row could have been started
625 if ( m_pages
.GetCount() == 1 || HasFlag(wxNB_MULTILINE
) )
627 AdjustPageSize(pPage
);
630 // now deal with the selection
631 // ---------------------------
633 // if the inserted page is before the selected one, we must update the
634 // index of the selected page
635 if ( int(nPage
) <= m_nSelection
)
637 // one extra page added
641 // some page should be selected: either this one or the first one if there
642 // is still no selection
646 else if ( m_nSelection
== -1 )
650 SetSelection(selNew
);
652 InvalidateBestSize();
656 int wxNotebook::HitTest(const wxPoint
& pt
, long *flags
) const
658 TC_HITTESTINFO hitTestInfo
;
659 hitTestInfo
.pt
.x
= pt
.x
;
660 hitTestInfo
.pt
.y
= pt
.y
;
661 int item
= TabCtrl_HitTest(GetHwnd(), &hitTestInfo
);
667 if ((hitTestInfo
.flags
& TCHT_NOWHERE
) == TCHT_NOWHERE
)
668 *flags
|= wxNB_HITTEST_NOWHERE
;
669 if ((hitTestInfo
.flags
& TCHT_ONITEM
) == TCHT_ONITEM
)
670 *flags
|= wxNB_HITTEST_ONITEM
;
671 if ((hitTestInfo
.flags
& TCHT_ONITEMICON
) == TCHT_ONITEMICON
)
672 *flags
|= wxNB_HITTEST_ONICON
;
673 if ((hitTestInfo
.flags
& TCHT_ONITEMLABEL
) == TCHT_ONITEMLABEL
)
674 *flags
|= wxNB_HITTEST_ONLABEL
;
681 // ----------------------------------------------------------------------------
682 // wxNotebook callbacks
683 // ----------------------------------------------------------------------------
685 void wxNotebook::OnSize(wxSizeEvent
& event
)
687 // fit the notebook page to the tab control's display area
689 rc
.left
= rc
.top
= 0;
690 GetSize((int *)&rc
.right
, (int *)&rc
.bottom
);
692 // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it
693 // returns completely false values for multiline tab controls after the tabs
694 // are added but before getting the first WM_SIZE (off by ~50 pixels, see
696 // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863
698 // and the only work around I could find was this ugly hack... without it
699 // simply toggling the "multiline" checkbox in the notebook sample resulted
700 // in a noticeable page displacement
701 if ( HasFlag(wxNB_MULTILINE
) )
703 // avoid an infinite recursion: we get another notification too!
704 static bool s_isInOnSize
= false;
709 SendMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
,
710 MAKELPARAM(rc
.right
, rc
.bottom
));
711 s_isInOnSize
= false;
715 TabCtrl_AdjustRect(m_hwnd
, false, &rc
);
717 int width
= rc
.right
- rc
.left
,
718 height
= rc
.bottom
- rc
.top
;
719 size_t nCount
= m_pages
.Count();
720 for ( size_t nPage
= 0; nPage
< nCount
; nPage
++ ) {
721 wxNotebookPage
*pPage
= m_pages
[nPage
];
722 pPage
->SetSize(rc
.left
, rc
.top
, width
, height
);
727 #endif // wxUSE_UXTHEME
732 void wxNotebook::OnSelChange(wxNotebookEvent
& event
)
734 // is it our tab control?
735 if ( event
.GetEventObject() == this )
737 int sel
= event
.GetOldSelection();
739 m_pages
[sel
]->Show(false);
741 sel
= event
.GetSelection();
744 wxNotebookPage
*pPage
= m_pages
[sel
];
748 // If the newly focused window is not a child of the new page,
749 // SetFocus was not successful and the notebook itself should be
751 wxWindow
*currentFocus
= FindFocus();
752 wxWindow
*startFocus
= currentFocus
;
753 while ( currentFocus
&& currentFocus
!= pPage
&& currentFocus
!= this )
754 currentFocus
= currentFocus
->GetParent();
756 if ( startFocus
== pPage
|| currentFocus
!= pPage
)
760 else // no pages in the notebook, give the focus to itself
768 // we want to give others a chance to process this message as well
772 bool wxNotebook::MSWTranslateMessage(WXMSG
*wxmsg
)
774 const MSG
* const msg
= (MSG
*)wxmsg
;
776 // intercept TAB, CTRL+TAB and CTRL+SHIFT+TAB for processing by wxNotebook.
777 // TAB will be passed to the currently selected page, CTRL+TAB and
778 // CTRL+SHIFT+TAB will be processed by the notebook itself. do not
779 // intercept SHIFT+TAB. This goes to the parent of the notebook which will
781 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_TAB
&&
782 msg
->hwnd
== m_hwnd
&&
783 (wxIsCtrlDown() || !wxIsShiftDown()) )
785 return MSWProcessMessage(wxmsg
);
791 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent
& event
)
793 if ( event
.IsWindowChange() ) {
795 AdvanceSelection(event
.GetDirection());
798 // we get this event in 3 cases
800 // a) one of our pages might have generated it because the user TABbed
801 // out from it in which case we should propagate the event upwards and
802 // our parent will take care of setting the focus to prev/next sibling
806 // b) the parent panel wants to give the focus to us so that we
807 // forward it to our selected page. We can't deal with this in
808 // OnSetFocus() because we don't know which direction the focus came
809 // from in this case and so can't choose between setting the focus to
810 // first or last panel child
814 // c) we ourselves (see MSWTranslateMessage) generated the event
816 wxWindow
* const parent
= GetParent();
818 const bool isFromParent
= event
.GetEventObject() == parent
;
819 const bool isFromSelf
= event
.GetEventObject() == this;
821 if ( isFromParent
|| isFromSelf
)
823 // no, it doesn't come from child, case (b) or (c): forward to a
824 // page but only if direction is backwards (TAB) or from ourselves,
825 if ( m_nSelection
!= -1 &&
826 (!event
.GetDirection() || isFromSelf
) )
828 // so that the page knows that the event comes from it's parent
829 // and is being propagated downwards
830 event
.SetEventObject(this);
832 wxWindow
*page
= m_pages
[m_nSelection
];
833 if ( !page
->GetEventHandler()->ProcessEvent(event
) )
837 //else: page manages focus inside it itself
839 else // otherwise set the focus to the notebook itself
846 // it comes from our child, case (a), pass to the parent, but only
847 // if the direction is forwards. Otherwise set the focus to the
848 // notebook itself. The notebook is always the 'first' control of a
850 if ( !event
.GetDirection() )
856 event
.SetCurrentFocus(this);
857 parent
->GetEventHandler()->ProcessEvent(event
);
865 WXHANDLE
wxNotebook::QueryBgBitmap(wxWindow
*win
)
868 GetWindowRect(GetHwnd(), &rc
);
870 WindowHDC
hDC(GetHwnd());
871 MemoryHDC
hDCMem(hDC
);
872 CompatibleBitmap
hBmp(hDC
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
874 SelectInHDC
selectBmp(hDCMem
, hBmp
);
876 ::SendMessage(GetHwnd(), WM_PRINTCLIENT
,
878 PRF_ERASEBKGND
| PRF_CLIENT
| PRF_NONCLIENT
);
883 ::GetWindowRect(GetHwndOf(win
), &rc2
);
885 COLORREF c
= ::GetPixel(hDCMem
, rc2
.left
- rc
.left
, rc2
.top
- rc
.top
);
889 else // we are asked to create the brush
891 return (WXHANDLE
)::CreatePatternBrush(hBmp
);
895 void wxNotebook::UpdateBgBrush()
897 if ( m_hbrBackground
)
898 ::DeleteObject((HBRUSH
)m_hbrBackground
);
900 if ( !m_hasBgCol
&& wxUxThemeEngine::GetIfActive() )
902 m_hbrBackground
= (WXHBRUSH
)QueryBgBitmap();
906 m_hbrBackground
= NULL
;
910 WXHBRUSH
wxNotebook::MSWGetBgBrushForChild(WXHDC hDC
, wxWindow
*win
)
912 if ( m_hbrBackground
)
914 // before drawing with the background brush, we need to position it
917 ::GetWindowRect(GetHwndOf(win
), &rc
);
919 ::MapWindowPoints(NULL
, GetHwnd(), (POINT
*)&rc
, 1);
921 if ( !::SetBrushOrgEx((HDC
)hDC
, -rc
.left
, -rc
.top
, NULL
) )
923 wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)"));
926 return m_hbrBackground
;
929 return wxNotebookBase::MSWGetBgBrushForChild(hDC
, win
);
932 wxColour
wxNotebook::MSWGetBgColourForChild(wxWindow
*win
)
935 return GetBackgroundColour();
937 if ( !wxUxThemeEngine::GetIfActive() )
940 COLORREF c
= (COLORREF
)QueryBgBitmap(win
);
942 return c
== CLR_INVALID
? wxNullColour
: wxRGBToColour(c
);
945 #endif // wxUSE_UXTHEME
947 // ----------------------------------------------------------------------------
948 // wxNotebook base class virtuals
949 // ----------------------------------------------------------------------------
951 #if wxUSE_CONSTRAINTS
953 // override these 2 functions to do nothing: everything is done in OnSize
955 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse
))
957 // don't set the sizes of the pages - their correct size is not yet known
958 wxControl::SetConstraintSizes(false);
961 bool wxNotebook::DoPhase(int WXUNUSED(nPhase
))
966 #endif // wxUSE_CONSTRAINTS
968 // ----------------------------------------------------------------------------
969 // wxNotebook Windows message handlers
970 // ----------------------------------------------------------------------------
972 bool wxNotebook::MSWOnScroll(int orientation
, WXWORD nSBCode
,
973 WXWORD pos
, WXHWND control
)
975 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
980 return wxNotebookBase::MSWOnScroll(orientation
, nSBCode
, pos
, control
);
983 bool wxNotebook::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
* result
)
985 wxNotebookEvent
event(wxEVT_NULL
, m_windowId
);
987 NMHDR
* hdr
= (NMHDR
*)lParam
;
988 switch ( hdr
->code
) {
990 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
);
993 case TCN_SELCHANGING
:
994 event
.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
);
998 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1001 event
.SetSelection(TabCtrl_GetCurSel(m_hwnd
));
1002 event
.SetOldSelection(m_nSelection
);
1003 event
.SetEventObject(this);
1004 event
.SetInt(idCtrl
);
1006 bool processed
= GetEventHandler()->ProcessEvent(event
);
1007 *result
= !event
.IsAllowed();
1011 #endif // wxUSE_NOTEBOOK