]> git.saurik.com Git - wxWidgets.git/blob - src/msw/notebook.cpp
preliminary EXTENDED_RTTI
[wxWidgets.git] / src / msw / notebook.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/notebook.cpp
3 // Purpose: implementation of wxNotebook
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 11.06.98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "notebook.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #if wxUSE_NOTEBOOK
24
25 // wxWindows
26 #ifndef WX_PRECOMP
27 #include "wx/string.h"
28 #endif // WX_PRECOMP
29
30 #include "wx/log.h"
31 #include "wx/imaglist.h"
32 #include "wx/event.h"
33 #include "wx/control.h"
34 #include "wx/notebook.h"
35 #include "wx/app.h"
36
37 #include "wx/msw/private.h"
38
39 // Windows standard headers
40 #ifndef __WIN95__
41 #error "wxNotebook is only supported Windows 95 and above"
42 #endif //Win95
43
44 #include <windowsx.h> // for SetWindowFont
45
46 #ifdef __GNUWIN32_OLD__
47 #include "wx/msw/gnuwin32/extra.h"
48 #endif
49
50 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
51 #include <commctrl.h>
52 #endif
53
54 #include "wx/msw/winundef.h"
55
56 #if wxUSE_UXTHEME
57 #include "wx/msw/uxtheme.h"
58
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"
68 #include "wx/panel.h"
69 #endif
70
71 // ----------------------------------------------------------------------------
72 // macros
73 // ----------------------------------------------------------------------------
74
75 // check that the page index is valid
76 #define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount()))
77
78 // hide the ugly cast
79 #define m_hwnd (HWND)GetHWND()
80
81 // ----------------------------------------------------------------------------
82 // constants
83 // ----------------------------------------------------------------------------
84
85 // This is a work-around for missing defines in gcc-2.95 headers
86 #ifndef TCS_RIGHT
87 #define TCS_RIGHT 0x0002
88 #endif
89
90 #ifndef TCS_VERTICAL
91 #define TCS_VERTICAL 0x0080
92 #endif
93
94 #ifndef TCS_BOTTOM
95 #define TCS_BOTTOM TCS_RIGHT
96 #endif
97
98 // ----------------------------------------------------------------------------
99 // event table
100 // ----------------------------------------------------------------------------
101
102 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
103 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
104
105 BEGIN_EVENT_TABLE(wxNotebook, wxControl)
106 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
107
108 EVT_SIZE(wxNotebook::OnSize)
109
110 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
111
112 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
113 END_EVENT_TABLE()
114
115 #if wxUSE_EXTENDED_RTTI
116 IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxControl,"wx/notebook.h")
117
118 WX_BEGIN_PROPERTIES_TABLE(wxNotebook)
119 WX_END_PROPERTIES_TABLE()
120
121 WX_BEGIN_HANDLERS_TABLE(wxNotebook)
122 WX_END_HANDLERS_TABLE()
123
124 WX_CONSTRUCTOR_4( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size )
125
126 #else
127 IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
128 #endif
129 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
130
131 // ============================================================================
132 // implementation
133 // ============================================================================
134
135 // ----------------------------------------------------------------------------
136 // wxNotebook construction
137 // ----------------------------------------------------------------------------
138
139 // common part of all ctors
140 void wxNotebook::Init()
141 {
142 m_imageList = NULL;
143 m_nSelection = -1;
144 }
145
146 // default for dynamic class
147 wxNotebook::wxNotebook()
148 {
149 Init();
150 }
151
152 // the same arguments as for wxControl
153 wxNotebook::wxNotebook(wxWindow *parent,
154 wxWindowID id,
155 const wxPoint& pos,
156 const wxSize& size,
157 long style,
158 const wxString& name)
159 {
160 Init();
161
162 Create(parent, id, pos, size, style, name);
163 }
164
165 // Create() function
166 bool wxNotebook::Create(wxWindow *parent,
167 wxWindowID id,
168 const wxPoint& pos,
169 const wxSize& size,
170 long style,
171 const wxString& name)
172 {
173 // Does ComCtl32 support non-top tabs?
174 int verComCtl32 = wxApp::GetComCtl32Version();
175 if ( verComCtl32 < 470 || verComCtl32 >= 600 )
176 {
177 if (style & wxNB_BOTTOM)
178 style &= ~wxNB_BOTTOM;
179
180 if (style & wxNB_LEFT)
181 style &= ~wxNB_LEFT;
182
183 if (style & wxNB_RIGHT)
184 style &= ~wxNB_RIGHT;
185 }
186
187 if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL,
188 wxDefaultValidator, name) )
189 return FALSE;
190
191 if ( !MSWCreateControl(WC_TABCONTROL, wxEmptyString, pos, size) )
192 return FALSE;
193
194 SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE)));
195
196 return TRUE;
197 }
198
199 WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const
200 {
201 WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle);
202
203 tabStyle |= WS_TABSTOP | TCS_TABS;
204
205 if ( style & wxNB_MULTILINE )
206 tabStyle |= TCS_MULTILINE;
207 if ( style & wxNB_FIXEDWIDTH )
208 tabStyle |= TCS_FIXEDWIDTH;
209
210 if ( style & wxNB_BOTTOM )
211 tabStyle |= TCS_RIGHT;
212 else if ( style & wxNB_LEFT )
213 tabStyle |= TCS_VERTICAL;
214 else if ( style & wxNB_RIGHT )
215 tabStyle |= TCS_VERTICAL | TCS_RIGHT;
216
217 // ex style
218 if ( exstyle )
219 {
220 // note that we never want to have the default WS_EX_CLIENTEDGE style
221 // as it looks too ugly for the notebooks
222 *exstyle = 0;
223 }
224
225 return tabStyle;
226 }
227
228 // ----------------------------------------------------------------------------
229 // wxNotebook accessors
230 // ----------------------------------------------------------------------------
231
232 int wxNotebook::GetPageCount() const
233 {
234 // consistency check
235 wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) );
236
237 return m_pages.Count();
238 }
239
240 int wxNotebook::GetRowCount() const
241 {
242 return TabCtrl_GetRowCount(m_hwnd);
243 }
244
245 int wxNotebook::SetSelection(int nPage)
246 {
247 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
248
249 if ( nPage != m_nSelection )
250 {
251 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
252 event.SetSelection(nPage);
253 event.SetOldSelection(m_nSelection);
254 event.SetEventObject(this);
255 if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
256 {
257 // program allows the page change
258 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
259 (void)GetEventHandler()->ProcessEvent(event);
260
261 TabCtrl_SetCurSel(m_hwnd, nPage);
262 }
263 }
264
265 return m_nSelection;
266 }
267
268 bool wxNotebook::SetPageText(int nPage, const wxString& strText)
269 {
270 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
271
272 TC_ITEM tcItem;
273 tcItem.mask = TCIF_TEXT;
274 tcItem.pszText = (wxChar *)strText.c_str();
275
276 return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
277 }
278
279 wxString wxNotebook::GetPageText(int nPage) const
280 {
281 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") );
282
283 wxChar buf[256];
284 TC_ITEM tcItem;
285 tcItem.mask = TCIF_TEXT;
286 tcItem.pszText = buf;
287 tcItem.cchTextMax = WXSIZEOF(buf);
288
289 wxString str;
290 if ( TabCtrl_GetItem(m_hwnd, nPage, &tcItem) )
291 str = tcItem.pszText;
292
293 return str;
294 }
295
296 int wxNotebook::GetPageImage(int nPage) const
297 {
298 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
299
300 TC_ITEM tcItem;
301 tcItem.mask = TCIF_IMAGE;
302
303 return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1;
304 }
305
306 bool wxNotebook::SetPageImage(int nPage, int nImage)
307 {
308 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
309
310 TC_ITEM tcItem;
311 tcItem.mask = TCIF_IMAGE;
312 tcItem.iImage = nImage;
313
314 return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
315 }
316
317 void wxNotebook::SetImageList(wxImageList* imageList)
318 {
319 wxNotebookBase::SetImageList(imageList);
320
321 if ( imageList )
322 {
323 TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST());
324 }
325 }
326
327 // ----------------------------------------------------------------------------
328 // wxNotebook size settings
329 // ----------------------------------------------------------------------------
330
331 void wxNotebook::SetPageSize(const wxSize& size)
332 {
333 // transform the page size into the notebook size
334 RECT rc;
335 rc.left =
336 rc.top = 0;
337 rc.right = size.x;
338 rc.bottom = size.y;
339
340 TabCtrl_AdjustRect(GetHwnd(), TRUE, &rc);
341
342 // and now set it
343 SetSize(rc.right - rc.left, rc.bottom - rc.top);
344 }
345
346 void wxNotebook::SetPadding(const wxSize& padding)
347 {
348 TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y);
349 }
350
351 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
352 // style.
353 void wxNotebook::SetTabSize(const wxSize& sz)
354 {
355 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y));
356 }
357
358 wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
359 {
360 wxSize sizeTotal = sizePage;
361
362 // We need to make getting tab size part of the wxWindows API.
363 wxSize tabSize(0, 0);
364 if (GetPageCount() > 0)
365 {
366 RECT rect;
367 TabCtrl_GetItemRect((HWND) GetHWND(), 0, & rect);
368 tabSize.x = rect.right - rect.left;
369 tabSize.y = rect.bottom - rect.top;
370 }
371 if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
372 {
373 sizeTotal.x += tabSize.x + 7;
374 sizeTotal.y += 7;
375 }
376 else
377 {
378 sizeTotal.x += 7;
379 sizeTotal.y += tabSize.y + 7;
380 }
381
382 return sizeTotal;
383 }
384
385 void wxNotebook::AdjustPageSize(wxNotebookPage *page)
386 {
387 wxCHECK_RET( page, _T("NULL page in wxNotebook::AdjustPageSize") );
388
389 RECT rc;
390 rc.left =
391 rc.top = 0;
392
393 // get the page size from the notebook size
394 GetSize((int *)&rc.right, (int *)&rc.bottom);
395 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
396
397 page->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
398 }
399
400 // ----------------------------------------------------------------------------
401 // wxNotebook operations
402 // ----------------------------------------------------------------------------
403
404 // remove one page from the notebook, without deleting
405 wxNotebookPage *wxNotebook::DoRemovePage(int nPage)
406 {
407 wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage);
408 if ( !pageRemoved )
409 return NULL;
410
411 TabCtrl_DeleteItem(m_hwnd, nPage);
412
413 if ( m_pages.IsEmpty() )
414 {
415 // no selection any more, the notebook becamse empty
416 m_nSelection = -1;
417 }
418 else // notebook still not empty
419 {
420 // change the selected page if it was deleted or became invalid
421 int selNew;
422 if ( m_nSelection == GetPageCount() )
423 {
424 // last page deleted, make the new last page the new selection
425 selNew = m_nSelection - 1;
426 }
427 else if ( nPage <= m_nSelection )
428 {
429 // we must show another page, even if it has the same index
430 selNew = m_nSelection;
431 }
432 else // nothing changes for the currently selected page
433 {
434 selNew = -1;
435
436 // we still must refresh the current page: this needs to be done
437 // for some unknown reason if the tab control shows the up-down
438 // control (i.e. when there are too many pages) -- otherwise after
439 // deleting a page nothing at all is shown
440 if (m_nSelection >= 0)
441 m_pages[m_nSelection]->Refresh();
442 }
443
444 if ( selNew != -1 )
445 {
446 // m_nSelection must be always valid so reset it before calling
447 // SetSelection()
448 m_nSelection = -1;
449 SetSelection(selNew);
450 }
451 }
452
453 return pageRemoved;
454 }
455
456 // remove all pages
457 bool wxNotebook::DeleteAllPages()
458 {
459 int nPageCount = GetPageCount();
460 int nPage;
461 for ( nPage = 0; nPage < nPageCount; nPage++ )
462 delete m_pages[nPage];
463
464 m_pages.Clear();
465
466 TabCtrl_DeleteAllItems(m_hwnd);
467
468 m_nSelection = -1;
469
470 return TRUE;
471 }
472
473 // same as AddPage() but does it at given position
474 bool wxNotebook::InsertPage(int nPage,
475 wxNotebookPage *pPage,
476 const wxString& strText,
477 bool bSelect,
478 int imageId)
479 {
480 wxCHECK_MSG( pPage != NULL, FALSE, _T("NULL page in wxNotebook::InsertPage") );
481 wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE,
482 _T("invalid index in wxNotebook::InsertPage") );
483
484 wxASSERT_MSG( pPage->GetParent() == this,
485 _T("notebook pages must have notebook as parent") );
486
487 #if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO
488 // Automatically apply the theme background,
489 // changing the colour of the panel to match the
490 // tab page colour. This won't work well with all
491 // themes but it's a start.
492 if (wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel)))
493 {
494 ApplyThemeBackground(pPage, GetThemeBackgroundColour());
495 }
496 #endif
497
498 // add a new tab to the control
499 // ----------------------------
500
501 // init all fields to 0
502 TC_ITEM tcItem;
503 wxZeroMemory(tcItem);
504
505 // set the image, if any
506 if ( imageId != -1 )
507 {
508 tcItem.mask |= TCIF_IMAGE;
509 tcItem.iImage = imageId;
510 }
511
512 // and the text
513 if ( !strText.IsEmpty() )
514 {
515 tcItem.mask |= TCIF_TEXT;
516 tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
517 }
518
519 // fit the notebook page to the tab control's display area: this should be
520 // done before adding it to the notebook or TabCtrl_InsertItem() will
521 // change the notebooks size itself!
522 AdjustPageSize(pPage);
523
524 // finally do insert it
525 if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 )
526 {
527 wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
528
529 return FALSE;
530 }
531
532 // succeeded: save the pointer to the page
533 m_pages.Insert(pPage, nPage);
534
535 // for the first page (only) we need to adjust the size again because the
536 // notebook size changed: the tabs which hadn't been there before are now
537 // shown
538 if ( m_pages.GetCount() == 1 )
539 {
540 AdjustPageSize(pPage);
541 }
542
543 // hide the page: unless it is selected, it shouldn't be shown (and if it
544 // is selected it will be shown later)
545 HWND hwnd = GetWinHwnd(pPage);
546 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
547
548 // this updates internal flag too -- otherwise it would get out of sync
549 // with the real state
550 pPage->Show(FALSE);
551
552
553 // now deal with the selection
554 // ---------------------------
555
556 // if the inserted page is before the selected one, we must update the
557 // index of the selected page
558 if ( nPage <= m_nSelection )
559 {
560 // one extra page added
561 m_nSelection++;
562 }
563
564 // some page should be selected: either this one or the first one if there
565 // is still no selection
566 int selNew = -1;
567 if ( bSelect )
568 selNew = nPage;
569 else if ( m_nSelection == -1 )
570 selNew = 0;
571
572 if ( selNew != -1 )
573 SetSelection(selNew);
574
575 return TRUE;
576 }
577
578 int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
579 {
580 TC_HITTESTINFO hitTestInfo;
581 hitTestInfo.pt.x = pt.x;
582 hitTestInfo.pt.y = pt.y;
583 int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo);
584
585 if ( flags )
586 {
587 *flags = 0;
588
589 if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
590 *flags |= wxNB_HITTEST_NOWHERE;
591 if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM)
592 *flags |= wxNB_HITTEST_ONITEM;
593 if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
594 *flags |= wxNB_HITTEST_ONICON;
595 if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
596 *flags |= wxNB_HITTEST_ONLABEL;
597 }
598
599 return item;
600 }
601
602
603 // ----------------------------------------------------------------------------
604 // wxNotebook callbacks
605 // ----------------------------------------------------------------------------
606
607 void wxNotebook::OnSize(wxSizeEvent& event)
608 {
609 // fit the notebook page to the tab control's display area
610 RECT rc;
611 rc.left = rc.top = 0;
612 GetSize((int *)&rc.right, (int *)&rc.bottom);
613
614 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
615
616 int width = rc.right - rc.left,
617 height = rc.bottom - rc.top;
618 size_t nCount = m_pages.Count();
619 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
620 wxNotebookPage *pPage = m_pages[nPage];
621 pPage->SetSize(rc.left, rc.top, width, height);
622 }
623
624 event.Skip();
625 }
626
627 void wxNotebook::OnSelChange(wxNotebookEvent& event)
628 {
629 // is it our tab control?
630 if ( event.GetEventObject() == this )
631 {
632 int sel = event.GetOldSelection();
633 if ( sel != -1 )
634 m_pages[sel]->Show(FALSE);
635
636 sel = event.GetSelection();
637 if ( sel != -1 )
638 {
639 wxNotebookPage *pPage = m_pages[sel];
640 pPage->Show(TRUE);
641 pPage->SetFocus();
642 }
643
644 m_nSelection = sel;
645 }
646
647 // we want to give others a chance to process this message as well
648 event.Skip();
649 }
650
651 void wxNotebook::OnSetFocus(wxFocusEvent& event)
652 {
653 // this function is only called when the focus is explicitly set (i.e. from
654 // the program) to the notebook - in this case we don't need the
655 // complicated OnNavigationKey() logic because the programmer knows better
656 // what [s]he wants
657
658 // set focus to the currently selected page if any
659 if ( m_nSelection != -1 )
660 m_pages[m_nSelection]->SetFocus();
661
662 event.Skip();
663 }
664
665 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
666 {
667 if ( event.IsWindowChange() ) {
668 // change pages
669 AdvanceSelection(event.GetDirection());
670 }
671 else {
672 // we get this event in 2 cases
673 //
674 // a) one of our pages might have generated it because the user TABbed
675 // out from it in which case we should propagate the event upwards and
676 // our parent will take care of setting the focus to prev/next sibling
677 //
678 // or
679 //
680 // b) the parent panel wants to give the focus to us so that we
681 // forward it to our selected page. We can't deal with this in
682 // OnSetFocus() because we don't know which direction the focus came
683 // from in this case and so can't choose between setting the focus to
684 // first or last panel child
685 wxWindow *parent = GetParent();
686 // the cast is here to fic a GCC ICE
687 if ( ((wxWindow*)event.GetEventObject()) == parent )
688 {
689 // no, it doesn't come from child, case (b): forward to a page
690 if ( m_nSelection != -1 )
691 {
692 // so that the page knows that the event comes from it's parent
693 // and is being propagated downwards
694 event.SetEventObject(this);
695
696 wxWindow *page = m_pages[m_nSelection];
697 if ( !page->GetEventHandler()->ProcessEvent(event) )
698 {
699 page->SetFocus();
700 }
701 //else: page manages focus inside it itself
702 }
703 else
704 {
705 // we have no pages - still have to give focus to _something_
706 SetFocus();
707 }
708 }
709 else
710 {
711 // it comes from our child, case (a), pass to the parent
712 if ( parent ) {
713 event.SetCurrentFocus(this);
714 parent->GetEventHandler()->ProcessEvent(event);
715 }
716 }
717 }
718 }
719
720 // ----------------------------------------------------------------------------
721 // wxNotebook base class virtuals
722 // ----------------------------------------------------------------------------
723
724 #if wxUSE_CONSTRAINTS
725
726 // override these 2 functions to do nothing: everything is done in OnSize
727
728 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
729 {
730 // don't set the sizes of the pages - their correct size is not yet known
731 wxControl::SetConstraintSizes(FALSE);
732 }
733
734 bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
735 {
736 return TRUE;
737 }
738
739 #endif // wxUSE_CONSTRAINTS
740
741 // ----------------------------------------------------------------------------
742 // wxNotebook Windows message handlers
743 // ----------------------------------------------------------------------------
744
745 bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode,
746 WXWORD pos, WXHWND control)
747 {
748 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
749 // up-down control
750 if ( control )
751 return FALSE;
752
753 return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control);
754 }
755
756 bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
757 {
758 wxNotebookEvent event(wxEVT_NULL, m_windowId);
759
760 NMHDR* hdr = (NMHDR *)lParam;
761 switch ( hdr->code ) {
762 case TCN_SELCHANGE:
763 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
764 break;
765
766 case TCN_SELCHANGING:
767 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING);
768 break;
769
770 default:
771 return wxControl::MSWOnNotify(idCtrl, lParam, result);
772 }
773
774 event.SetSelection(TabCtrl_GetCurSel(m_hwnd));
775 event.SetOldSelection(m_nSelection);
776 event.SetEventObject(this);
777 event.SetInt(idCtrl);
778
779 bool processed = GetEventHandler()->ProcessEvent(event);
780 *result = !event.IsAllowed();
781 return processed;
782 }
783
784 // Windows only: attempts to get colour for UX theme page background
785 wxColour wxNotebook::GetThemeBackgroundColour()
786 {
787 #if wxUSE_UXTHEME
788 if (wxUxThemeEngine::Get())
789 {
790 WXHTHEME hTheme = wxUxThemeEngine::Get()->m_pfnOpenThemeData(GetHWND(), L"TAB");
791 if (hTheme)
792 {
793 // This is total guesswork.
794 // See PlatformSDK\Include\Tmschema.h for values
795 COLORREF themeColor;
796 wxUxThemeEngine::Get()->
797 m_pfnGetThemeColor(hTheme,
798 10 /* TABP_BODY */,
799 1 /* NORMAL */,
800 3821, /* FILLCOLORHINT */
801 & themeColor);
802
803 wxUxThemeEngine::Get()->m_pfnCloseThemeData(hTheme);
804
805 wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor));
806 return colour;
807 }
808 }
809 #endif
810 return GetBackgroundColour();
811 }
812
813 // Windows only: attempts to apply the UX theme page background to this page
814 void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& colour)
815 {
816 #if wxUSE_UXTHEME
817 // Don't set the background for buttons since this will
818 // switch it into ownerdraw mode
819 if (window->IsKindOf(CLASSINFO(wxButton)) && !window->IsKindOf(CLASSINFO(wxBitmapButton)))
820 // This is essential, otherwise you'll see dark grey
821 // corners in the buttons.
822 ((wxButton*)window)->wxControl::SetBackgroundColour(colour);
823 else if (window->IsKindOf(CLASSINFO(wxStaticText)) ||
824 window->IsKindOf(CLASSINFO(wxStaticBox)) ||
825 window->IsKindOf(CLASSINFO(wxStaticLine)) ||
826 window->IsKindOf(CLASSINFO(wxRadioButton)) ||
827 window->IsKindOf(CLASSINFO(wxRadioBox)) ||
828 window->IsKindOf(CLASSINFO(wxCheckBox)) ||
829 window->IsKindOf(CLASSINFO(wxBitmapButton)) ||
830 window->IsKindOf(CLASSINFO(wxSlider)) ||
831 window->IsKindOf(CLASSINFO(wxPanel)) ||
832 (window->IsKindOf(CLASSINFO(wxNotebook)) && (window != this)) ||
833 window->IsKindOf(CLASSINFO(wxScrolledWindow))
834 )
835 {
836 window->SetBackgroundColour(colour);
837 }
838
839 for ( wxWindowList::compatibility_iterator node = window->GetChildren().GetFirst(); node; node = node->GetNext() )
840 {
841 wxWindow *child = node->GetData();
842 ApplyThemeBackground(child, colour);
843 }
844 #else
845 window;
846 colour;
847 #endif
848 }
849
850 #endif // wxUSE_NOTEBOOK