]> git.saurik.com Git - wxWidgets.git/blob - src/msw/notebook.cpp
warnings (and some errors) fixes for wxUniv DLL build
[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 static bool g_TestedForTheme = FALSE;
489 static bool g_UseTheme = FALSE;
490 if (!g_TestedForTheme)
491 {
492 int commCtrlVersion = wxTheApp->GetComCtl32Version() ;
493
494 g_UseTheme = (commCtrlVersion >= 600);
495 g_TestedForTheme = TRUE;
496 }
497
498 // Automatically apply the theme background,
499 // changing the colour of the panel to match the
500 // tab page colour. This won't work well with all
501 // themes but it's a start.
502 if (g_UseTheme && wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel)))
503 {
504 ApplyThemeBackground(pPage, GetThemeBackgroundColour());
505 }
506 #endif
507
508 // add a new tab to the control
509 // ----------------------------
510
511 // init all fields to 0
512 TC_ITEM tcItem;
513 wxZeroMemory(tcItem);
514
515 // set the image, if any
516 if ( imageId != -1 )
517 {
518 tcItem.mask |= TCIF_IMAGE;
519 tcItem.iImage = imageId;
520 }
521
522 // and the text
523 if ( !strText.IsEmpty() )
524 {
525 tcItem.mask |= TCIF_TEXT;
526 tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
527 }
528
529 // fit the notebook page to the tab control's display area: this should be
530 // done before adding it to the notebook or TabCtrl_InsertItem() will
531 // change the notebooks size itself!
532 AdjustPageSize(pPage);
533
534 // finally do insert it
535 if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 )
536 {
537 wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
538
539 return FALSE;
540 }
541
542 // succeeded: save the pointer to the page
543 m_pages.Insert(pPage, nPage);
544
545 // for the first page (only) we need to adjust the size again because the
546 // notebook size changed: the tabs which hadn't been there before are now
547 // shown
548 if ( m_pages.GetCount() == 1 )
549 {
550 AdjustPageSize(pPage);
551 }
552
553 // hide the page: unless it is selected, it shouldn't be shown (and if it
554 // is selected it will be shown later)
555 HWND hwnd = GetWinHwnd(pPage);
556 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
557
558 // this updates internal flag too -- otherwise it would get out of sync
559 // with the real state
560 pPage->Show(FALSE);
561
562
563 // now deal with the selection
564 // ---------------------------
565
566 // if the inserted page is before the selected one, we must update the
567 // index of the selected page
568 if ( nPage <= m_nSelection )
569 {
570 // one extra page added
571 m_nSelection++;
572 }
573
574 // some page should be selected: either this one or the first one if there
575 // is still no selection
576 int selNew = -1;
577 if ( bSelect )
578 selNew = nPage;
579 else if ( m_nSelection == -1 )
580 selNew = 0;
581
582 if ( selNew != -1 )
583 SetSelection(selNew);
584
585 return TRUE;
586 }
587
588 int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
589 {
590 TC_HITTESTINFO hitTestInfo;
591 hitTestInfo.pt.x = pt.x;
592 hitTestInfo.pt.y = pt.y;
593 int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo);
594
595 if ( flags )
596 {
597 *flags = 0;
598
599 if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
600 *flags |= wxNB_HITTEST_NOWHERE;
601 if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM)
602 *flags |= wxNB_HITTEST_ONITEM;
603 if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
604 *flags |= wxNB_HITTEST_ONICON;
605 if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
606 *flags |= wxNB_HITTEST_ONLABEL;
607 }
608
609 return item;
610 }
611
612
613 // ----------------------------------------------------------------------------
614 // wxNotebook callbacks
615 // ----------------------------------------------------------------------------
616
617 void wxNotebook::OnSize(wxSizeEvent& event)
618 {
619 // fit the notebook page to the tab control's display area
620 RECT rc;
621 rc.left = rc.top = 0;
622 GetSize((int *)&rc.right, (int *)&rc.bottom);
623
624 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
625
626 int width = rc.right - rc.left,
627 height = rc.bottom - rc.top;
628 size_t nCount = m_pages.Count();
629 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
630 wxNotebookPage *pPage = m_pages[nPage];
631 pPage->SetSize(rc.left, rc.top, width, height);
632 }
633
634 event.Skip();
635 }
636
637 void wxNotebook::OnSelChange(wxNotebookEvent& event)
638 {
639 // is it our tab control?
640 if ( event.GetEventObject() == this )
641 {
642 int sel = event.GetOldSelection();
643 if ( sel != -1 )
644 m_pages[sel]->Show(FALSE);
645
646 sel = event.GetSelection();
647 if ( sel != -1 )
648 {
649 wxNotebookPage *pPage = m_pages[sel];
650 pPage->Show(TRUE);
651 pPage->SetFocus();
652 }
653
654 m_nSelection = sel;
655 }
656
657 // we want to give others a chance to process this message as well
658 event.Skip();
659 }
660
661 void wxNotebook::OnSetFocus(wxFocusEvent& event)
662 {
663 // this function is only called when the focus is explicitly set (i.e. from
664 // the program) to the notebook - in this case we don't need the
665 // complicated OnNavigationKey() logic because the programmer knows better
666 // what [s]he wants
667
668 // set focus to the currently selected page if any
669 if ( m_nSelection != -1 )
670 m_pages[m_nSelection]->SetFocus();
671
672 event.Skip();
673 }
674
675 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
676 {
677 if ( event.IsWindowChange() ) {
678 // change pages
679 AdvanceSelection(event.GetDirection());
680 }
681 else {
682 // we get this event in 2 cases
683 //
684 // a) one of our pages might have generated it because the user TABbed
685 // out from it in which case we should propagate the event upwards and
686 // our parent will take care of setting the focus to prev/next sibling
687 //
688 // or
689 //
690 // b) the parent panel wants to give the focus to us so that we
691 // forward it to our selected page. We can't deal with this in
692 // OnSetFocus() because we don't know which direction the focus came
693 // from in this case and so can't choose between setting the focus to
694 // first or last panel child
695 wxWindow *parent = GetParent();
696 // the cast is here to fic a GCC ICE
697 if ( ((wxWindow*)event.GetEventObject()) == parent )
698 {
699 // no, it doesn't come from child, case (b): forward to a page
700 if ( m_nSelection != -1 )
701 {
702 // so that the page knows that the event comes from it's parent
703 // and is being propagated downwards
704 event.SetEventObject(this);
705
706 wxWindow *page = m_pages[m_nSelection];
707 if ( !page->GetEventHandler()->ProcessEvent(event) )
708 {
709 page->SetFocus();
710 }
711 //else: page manages focus inside it itself
712 }
713 else
714 {
715 // we have no pages - still have to give focus to _something_
716 SetFocus();
717 }
718 }
719 else
720 {
721 // it comes from our child, case (a), pass to the parent
722 if ( parent ) {
723 event.SetCurrentFocus(this);
724 parent->GetEventHandler()->ProcessEvent(event);
725 }
726 }
727 }
728 }
729
730 // ----------------------------------------------------------------------------
731 // wxNotebook base class virtuals
732 // ----------------------------------------------------------------------------
733
734 #if wxUSE_CONSTRAINTS
735
736 // override these 2 functions to do nothing: everything is done in OnSize
737
738 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
739 {
740 // don't set the sizes of the pages - their correct size is not yet known
741 wxControl::SetConstraintSizes(FALSE);
742 }
743
744 bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
745 {
746 return TRUE;
747 }
748
749 #endif // wxUSE_CONSTRAINTS
750
751 // ----------------------------------------------------------------------------
752 // wxNotebook Windows message handlers
753 // ----------------------------------------------------------------------------
754
755 bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode,
756 WXWORD pos, WXHWND control)
757 {
758 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
759 // up-down control
760 if ( control )
761 return FALSE;
762
763 return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control);
764 }
765
766 bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
767 {
768 wxNotebookEvent event(wxEVT_NULL, m_windowId);
769
770 NMHDR* hdr = (NMHDR *)lParam;
771 switch ( hdr->code ) {
772 case TCN_SELCHANGE:
773 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
774 break;
775
776 case TCN_SELCHANGING:
777 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING);
778 break;
779
780 default:
781 return wxControl::MSWOnNotify(idCtrl, lParam, result);
782 }
783
784 event.SetSelection(TabCtrl_GetCurSel(m_hwnd));
785 event.SetOldSelection(m_nSelection);
786 event.SetEventObject(this);
787 event.SetInt(idCtrl);
788
789 bool processed = GetEventHandler()->ProcessEvent(event);
790 *result = !event.IsAllowed();
791 return processed;
792 }
793
794 // Windows only: attempts to get colour for UX theme page background
795 wxColour wxNotebook::GetThemeBackgroundColour()
796 {
797 #if wxUSE_UXTHEME
798 if (wxUxThemeEngine::Get())
799 {
800 wxUxThemeHandle hTheme(this, L"TAB");
801 if (hTheme)
802 {
803 // This is total guesswork.
804 // See PlatformSDK\Include\Tmschema.h for values
805 COLORREF themeColor;
806 wxUxThemeEngine::Get()->GetThemeColor
807 (
808 hTheme,
809 10 /* TABP_BODY */,
810 1 /* NORMAL */,
811 3821, /* FILLCOLORHINT */
812 & themeColor
813 );
814
815 wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor));
816 return colour;
817 }
818 }
819 #endif // wxUSE_UXTHEME
820
821 return GetBackgroundColour();
822 }
823
824 // Windows only: attempts to apply the UX theme page background to this page
825 #if wxUSE_UXTHEME
826 void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& colour)
827 #else
828 void wxNotebook::ApplyThemeBackground(wxWindow*, const wxColour&)
829 #endif
830 {
831 #if wxUSE_UXTHEME
832 // Don't set the background for buttons since this will
833 // switch it into ownerdraw mode
834 if (window->IsKindOf(CLASSINFO(wxButton)) && !window->IsKindOf(CLASSINFO(wxBitmapButton)))
835 // This is essential, otherwise you'll see dark grey
836 // corners in the buttons.
837 ((wxButton*)window)->wxControl::SetBackgroundColour(colour);
838 else if (window->IsKindOf(CLASSINFO(wxStaticText)) ||
839 window->IsKindOf(CLASSINFO(wxStaticBox)) ||
840 window->IsKindOf(CLASSINFO(wxStaticLine)) ||
841 window->IsKindOf(CLASSINFO(wxRadioButton)) ||
842 window->IsKindOf(CLASSINFO(wxRadioBox)) ||
843 window->IsKindOf(CLASSINFO(wxCheckBox)) ||
844 window->IsKindOf(CLASSINFO(wxBitmapButton)) ||
845 window->IsKindOf(CLASSINFO(wxSlider)) ||
846 window->IsKindOf(CLASSINFO(wxPanel)) ||
847 (window->IsKindOf(CLASSINFO(wxNotebook)) && (window != this)) ||
848 window->IsKindOf(CLASSINFO(wxScrolledWindow))
849 )
850 {
851 window->SetBackgroundColour(colour);
852 }
853
854 for ( wxWindowList::compatibility_iterator node = window->GetChildren().GetFirst(); node; node = node->GetNext() )
855 {
856 wxWindow *child = node->GetData();
857 ApplyThemeBackground(child, colour);
858 }
859 #endif
860 }
861
862 long wxNotebook::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
863 {
864 static bool g_TestedForTheme = FALSE;
865 static bool g_UseTheme = FALSE;
866 switch ( nMsg )
867 {
868 case WM_ERASEBKGND:
869 {
870 if (!g_TestedForTheme)
871 {
872 int commCtrlVersion = wxTheApp->GetComCtl32Version() ;
873
874 g_UseTheme = (commCtrlVersion >= 600);
875 g_TestedForTheme = TRUE;
876 }
877
878 // If using XP themes, it seems we can get away
879 // with not drawing a background, which reduces flicker.
880 if (g_UseTheme)
881 return TRUE;
882 }
883 }
884
885 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
886 }
887
888
889 #endif // wxUSE_NOTEBOOK