]> git.saurik.com Git - wxWidgets.git/blob - src/msw/notebook.cpp
Make wxMSW wxSpinCtrl "not enough space" messages more helpful.
[wxWidgets.git] / src / msw / notebook.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_NOTEBOOK
20
21 #include "wx/notebook.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
25 #include "wx/string.h"
26 #include "wx/dc.h"
27 #include "wx/log.h"
28 #include "wx/event.h"
29 #include "wx/app.h"
30 #include "wx/dcclient.h"
31 #include "wx/dcmemory.h"
32 #include "wx/control.h"
33 #include "wx/panel.h"
34 #endif // WX_PRECOMP
35
36 #include "wx/imaglist.h"
37 #include "wx/sysopt.h"
38
39 #include "wx/msw/private.h"
40 #include "wx/msw/dc.h"
41
42 #include <windowsx.h>
43 #include "wx/msw/winundef.h"
44
45 #if wxUSE_UXTHEME
46 #include "wx/msw/uxtheme.h"
47 #endif
48
49 // ----------------------------------------------------------------------------
50 // macros
51 // ----------------------------------------------------------------------------
52
53 // check that the page index is valid
54 #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
55
56 // you can set USE_NOTEBOOK_ANTIFLICKER to 0 for desktop Windows versions too
57 // to disable code whih results in flicker-less notebook redrawing at the
58 // expense of some extra GDI resource consumption
59 #ifdef __WXWINCE__
60 // notebooks are never resized under CE anyhow
61 #define USE_NOTEBOOK_ANTIFLICKER 0
62 #else
63 #define USE_NOTEBOOK_ANTIFLICKER 1
64 #endif
65
66 // ----------------------------------------------------------------------------
67 // constants
68 // ----------------------------------------------------------------------------
69
70 // This is a work-around for missing defines in gcc-2.95 headers
71 #ifndef TCS_RIGHT
72 #define TCS_RIGHT 0x0002
73 #endif
74
75 #ifndef TCS_VERTICAL
76 #define TCS_VERTICAL 0x0080
77 #endif
78
79 #ifndef TCS_BOTTOM
80 #define TCS_BOTTOM TCS_RIGHT
81 #endif
82
83 // ----------------------------------------------------------------------------
84 // global variables
85 // ----------------------------------------------------------------------------
86
87 #if USE_NOTEBOOK_ANTIFLICKER
88
89 // the pointer to standard spin button wnd proc
90 static WXFARPROC gs_wndprocNotebookSpinBtn = (WXFARPROC)NULL;
91
92 // the pointer to standard tab control wnd proc
93 static WXFARPROC gs_wndprocNotebook = (WXFARPROC)NULL;
94
95 LRESULT APIENTRY _EXPORT wxNotebookWndProc(HWND hwnd,
96 UINT message,
97 WPARAM wParam,
98 LPARAM lParam);
99
100 #endif // USE_NOTEBOOK_ANTIFLICKER
101
102 // ----------------------------------------------------------------------------
103 // global functions
104 // ----------------------------------------------------------------------------
105
106 static bool HasTroubleWithNonTopTabs()
107 {
108 const int verComCtl32 = wxApp::GetComCtl32Version();
109
110 // 600 is XP, 616 is Vista -- and both have a problem with tabs not on top
111 // (but don't just test for >= 600 as Microsoft might decide to fix it in
112 // later versions, who knows...)
113 return verComCtl32 >= 600 && verComCtl32 <= 616;
114 }
115
116 // ----------------------------------------------------------------------------
117 // event table
118 // ----------------------------------------------------------------------------
119
120 BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
121 EVT_SIZE(wxNotebook::OnSize)
122 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
123
124 #if USE_NOTEBOOK_ANTIFLICKER
125 EVT_ERASE_BACKGROUND(wxNotebook::OnEraseBackground)
126 EVT_PAINT(wxNotebook::OnPaint)
127 #endif // USE_NOTEBOOK_ANTIFLICKER
128 END_EVENT_TABLE()
129
130 // ============================================================================
131 // implementation
132 // ============================================================================
133
134 // ----------------------------------------------------------------------------
135 // wxNotebook construction
136 // ----------------------------------------------------------------------------
137
138 // common part of all ctors
139 void wxNotebook::Init()
140 {
141 #if wxUSE_UXTHEME
142 m_hbrBackground = NULL;
143 #endif // wxUSE_UXTHEME
144
145 #if USE_NOTEBOOK_ANTIFLICKER
146 m_hasSubclassedUpdown = false;
147 m_doneUpdateHack = false;
148 #endif // USE_NOTEBOOK_ANTIFLICKER
149 }
150
151 // default for dynamic class
152 wxNotebook::wxNotebook()
153 {
154 Init();
155 }
156
157 // the same arguments as for wxControl
158 wxNotebook::wxNotebook(wxWindow *parent,
159 wxWindowID id,
160 const wxPoint& pos,
161 const wxSize& size,
162 long style,
163 const wxString& name)
164 {
165 Init();
166
167 Create(parent, id, pos, size, style, name);
168 }
169
170 // Create() function
171 bool wxNotebook::Create(wxWindow *parent,
172 wxWindowID id,
173 const wxPoint& pos,
174 const wxSize& size,
175 long style,
176 const wxString& name)
177 {
178 if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
179 {
180 #if defined(__POCKETPC__)
181 style |= wxBK_BOTTOM | wxNB_FLAT;
182 #else
183 style |= wxBK_TOP;
184 #endif
185 }
186
187 #ifdef __WXWINCE__
188 // Not sure why, but without this style, there is no border
189 // around the notebook tabs.
190 if (style & wxNB_FLAT)
191 style |= wxBORDER_SUNKEN;
192 #endif
193
194 #if !wxUSE_UXTHEME
195 // ComCtl32 notebook tabs simply don't work unless they're on top if we
196 // have uxtheme, we can work around it later (after control creation), but
197 // if we have been compiled without uxtheme support, we have to clear those
198 // styles
199 if ( HasTroubleWithNonTopTabs() )
200 {
201 style &= ~(wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT);
202 }
203 #endif //wxUSE_UXTHEME
204
205 #if defined(__WINE__) && wxUSE_UNICODE
206 LPCTSTR className = L"SysTabControl32";
207 #else
208 LPCTSTR className = WC_TABCONTROL;
209 #endif
210
211 #if USE_NOTEBOOK_ANTIFLICKER
212 // SysTabCtl32 class has natively CS_HREDRAW and CS_VREDRAW enabled and it
213 // causes horrible flicker when resizing notebook, so get rid of it by
214 // using a class without these styles (but otherwise identical to it)
215 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
216 {
217 static ClassRegistrar s_clsNotebook;
218 if ( !s_clsNotebook.IsInitialized() )
219 {
220 // get a copy of standard class and modify it
221 WNDCLASS wc;
222
223 if ( ::GetClassInfo(NULL, WC_TABCONTROL, &wc) )
224 {
225 gs_wndprocNotebook =
226 reinterpret_cast<WXFARPROC>(wc.lpfnWndProc);
227 wc.lpszClassName = wxT("_wx_SysTabCtl32");
228 wc.style &= ~(CS_HREDRAW | CS_VREDRAW);
229 wc.hInstance = wxGetInstance();
230 wc.lpfnWndProc = wxNotebookWndProc;
231 s_clsNotebook.Register(wc);
232 }
233 else
234 {
235 wxLogLastError(wxT("GetClassInfoEx(SysTabCtl32)"));
236 }
237 }
238
239 // use our custom class if available but fall back to the standard
240 // notebook if we failed to register it
241 if ( s_clsNotebook.IsRegistered() )
242 {
243 // it's ok to use c_str() here as the static s_clsNotebook object
244 // has sufficiently long lifetime
245 className = s_clsNotebook.GetName().c_str();
246 }
247 }
248 #endif // USE_NOTEBOOK_ANTIFLICKER
249
250 if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL,
251 wxDefaultValidator, name) )
252 return false;
253
254 if ( !MSWCreateControl(className, wxEmptyString, pos, size) )
255 return false;
256
257 // Inherit parent attributes and, unlike the default, also inherit the
258 // parent background colour in order to blend in with its background if
259 // it's set to a non-default value.
260 InheritAttributes();
261 if ( parent->InheritsBackgroundColour() && !UseBgCol() )
262 SetBackgroundColour(parent->GetBackgroundColour());
263
264 #if wxUSE_UXTHEME
265 if ( HasFlag(wxNB_NOPAGETHEME) ||
266 wxSystemOptions::IsFalse(wxT("msw.notebook.themed-background")) )
267 {
268 SetBackgroundColour(GetThemeBackgroundColour());
269 }
270 else // use themed background by default
271 {
272 // create backing store
273 UpdateBgBrush();
274 }
275
276 // comctl32.dll 6.0 doesn't support non-top tabs with visual styles (the
277 // control is simply not rendered correctly), so we disable themes
278 // if possible, otherwise we simply clear the styles.
279 if ( HasTroubleWithNonTopTabs() &&
280 (style & (wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT)) )
281 {
282 // check if we use themes at all -- if we don't, we're still okay
283 if ( wxUxThemeEngine::GetIfActive() )
284 {
285 wxUxThemeEngine::GetIfActive()->SetWindowTheme(GetHwnd(), L"", L"");
286
287 // correct the background color for the new non-themed control
288 SetBackgroundColour(GetThemeBackgroundColour());
289 }
290 }
291 #endif // wxUSE_UXTHEME
292
293 // Undocumented hack to get flat notebook style
294 // In fact, we should probably only do this in some
295 // curcumstances, i.e. if we know we will have a border
296 // at the bottom (the tab control doesn't draw it itself)
297 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
298 if (HasFlag(wxNB_FLAT))
299 {
300 SendMessage(GetHwnd(), CCM_SETVERSION, COMCTL32_VERSION, 0);
301 if (!m_hasBgCol)
302 SetBackgroundColour(*wxWHITE);
303 }
304 #endif
305 return true;
306 }
307
308 WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const
309 {
310 WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle);
311
312 tabStyle |= WS_TABSTOP | TCS_TABS;
313
314 if ( style & wxNB_MULTILINE )
315 tabStyle |= TCS_MULTILINE;
316 if ( style & wxNB_FIXEDWIDTH )
317 tabStyle |= TCS_FIXEDWIDTH;
318
319 if ( style & wxBK_BOTTOM )
320 tabStyle |= TCS_RIGHT;
321 else if ( style & wxBK_LEFT )
322 tabStyle |= TCS_VERTICAL;
323 else if ( style & wxBK_RIGHT )
324 tabStyle |= TCS_VERTICAL | TCS_RIGHT;
325
326 return tabStyle;
327 }
328
329 wxNotebook::~wxNotebook()
330 {
331 #if wxUSE_UXTHEME
332 if ( m_hbrBackground )
333 ::DeleteObject((HBRUSH)m_hbrBackground);
334 #endif // wxUSE_UXTHEME
335 }
336
337 // ----------------------------------------------------------------------------
338 // wxNotebook accessors
339 // ----------------------------------------------------------------------------
340
341 size_t wxNotebook::GetPageCount() const
342 {
343 // consistency check
344 wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(GetHwnd()) );
345
346 return m_pages.Count();
347 }
348
349 int wxNotebook::GetRowCount() const
350 {
351 return TabCtrl_GetRowCount(GetHwnd());
352 }
353
354 int wxNotebook::SetSelection(size_t nPage)
355 {
356 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") );
357
358 if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection )
359 {
360 if ( SendPageChangingEvent(nPage) )
361 {
362 // program allows the page change
363 const int selectionOld = m_selection;
364
365 UpdateSelection(nPage);
366
367 TabCtrl_SetCurSel(GetHwnd(), nPage);
368
369 SendPageChangedEvent(selectionOld, nPage);
370 }
371 }
372
373 return m_selection;
374 }
375
376 void wxNotebook::UpdateSelection(int selNew)
377 {
378 if ( m_selection != wxNOT_FOUND )
379 m_pages[m_selection]->Show(false);
380
381 if ( selNew != wxNOT_FOUND )
382 {
383 wxNotebookPage *pPage = m_pages[selNew];
384 pPage->Show(true);
385
386 // In addition to showing the page, we also want to give focus to it to
387 // make it possible to work with it from keyboard easily. However there
388 // are two exceptions: first, don't touch the focus at all if the
389 // notebook itself is not currently shown.
390 if ( ::IsWindowVisible(GetHwnd()) )
391 {
392 // And second, don't give focus away if the tab control itself has
393 // it, as this is how the native property sheets behave: if you
394 // explicitly click on the tab label giving it focus, it will
395 // remain after switching to another page. But if the focus was
396 // inside the notebook page, it switches to the new page.
397 if ( !HasFocus() )
398 pPage->SetFocus();
399 }
400 }
401
402 m_selection = selNew;
403 }
404
405 int wxNotebook::ChangeSelection(size_t nPage)
406 {
407 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") );
408
409 const int selOld = m_selection;
410
411 if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection )
412 {
413 TabCtrl_SetCurSel(GetHwnd(), nPage);
414
415 UpdateSelection(nPage);
416 }
417
418 return selOld;
419 }
420
421 bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
422 {
423 wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") );
424
425 TC_ITEM tcItem;
426 tcItem.mask = TCIF_TEXT;
427 tcItem.pszText = wxMSW_CONV_LPTSTR(strText);
428
429 if ( !HasFlag(wxNB_MULTILINE) )
430 return TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0;
431
432 // multiline - we need to set new page size if a line is added or removed
433 int rows = GetRowCount();
434 bool ret = TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0;
435
436 if ( ret && rows != GetRowCount() )
437 {
438 const wxRect r = GetPageSize();
439 const size_t count = m_pages.Count();
440 for ( size_t page = 0; page < count; page++ )
441 m_pages[page]->SetSize(r);
442 }
443
444 return ret;
445 }
446
447 wxString wxNotebook::GetPageText(size_t nPage) const
448 {
449 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") );
450
451 wxChar buf[256];
452 TC_ITEM tcItem;
453 tcItem.mask = TCIF_TEXT;
454 tcItem.pszText = buf;
455 tcItem.cchTextMax = WXSIZEOF(buf);
456
457 wxString str;
458 if ( TabCtrl_GetItem(GetHwnd(), nPage, &tcItem) )
459 str = tcItem.pszText;
460
461 return str;
462 }
463
464 int wxNotebook::GetPageImage(size_t nPage) const
465 {
466 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") );
467
468 TC_ITEM tcItem;
469 tcItem.mask = TCIF_IMAGE;
470
471 return TabCtrl_GetItem(GetHwnd(), nPage, &tcItem) ? tcItem.iImage
472 : wxNOT_FOUND;
473 }
474
475 bool wxNotebook::SetPageImage(size_t nPage, int nImage)
476 {
477 wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("notebook page out of range") );
478
479 TC_ITEM tcItem;
480 tcItem.mask = TCIF_IMAGE;
481 tcItem.iImage = nImage;
482
483 return TabCtrl_SetItem(GetHwnd(), nPage, &tcItem) != 0;
484 }
485
486 void wxNotebook::SetImageList(wxImageList* imageList)
487 {
488 wxNotebookBase::SetImageList(imageList);
489
490 if ( imageList )
491 {
492 (void) TabCtrl_SetImageList(GetHwnd(), GetHimagelistOf(imageList));
493 }
494 }
495
496 // ----------------------------------------------------------------------------
497 // wxNotebook size settings
498 // ----------------------------------------------------------------------------
499
500 wxRect wxNotebook::GetPageSize() const
501 {
502 wxRect r;
503
504 RECT rc;
505 ::GetClientRect(GetHwnd(), &rc);
506
507 // This check is to work around a bug in TabCtrl_AdjustRect which will
508 // cause a crash on win2k or on XP with themes disabled if either
509 // wxNB_MULTILINE is used or tabs are placed on a side, if the rectangle
510 // is too small.
511 //
512 // The value of 20 is chosen arbitrarily but seems to work
513 if ( rc.right > 20 && rc.bottom > 20 )
514 {
515 TabCtrl_AdjustRect(GetHwnd(), false, &rc);
516
517 wxCopyRECTToRect(rc, r);
518 }
519
520 return r;
521 }
522
523 void wxNotebook::SetPageSize(const wxSize& size)
524 {
525 // transform the page size into the notebook size
526 RECT rc;
527 rc.left =
528 rc.top = 0;
529 rc.right = size.x;
530 rc.bottom = size.y;
531
532 TabCtrl_AdjustRect(GetHwnd(), true, &rc);
533
534 // and now set it
535 SetSize(rc.right - rc.left, rc.bottom - rc.top);
536 }
537
538 void wxNotebook::SetPadding(const wxSize& padding)
539 {
540 TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y);
541 }
542
543 // Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
544 // style.
545 void wxNotebook::SetTabSize(const wxSize& sz)
546 {
547 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y));
548 }
549
550 wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
551 {
552 // we can't use TabCtrl_AdjustRect here because it only works for wxNB_TOP
553 wxSize sizeTotal = sizePage;
554
555 wxSize tabSize;
556 if ( GetPageCount() > 0 )
557 {
558 RECT rect;
559 TabCtrl_GetItemRect(GetHwnd(), 0, &rect);
560 tabSize.x = rect.right - rect.left;
561 tabSize.y = rect.bottom - rect.top;
562 }
563
564 const int rows = GetRowCount();
565
566 // add an extra margin in both directions
567 const int MARGIN = 8;
568 if ( IsVertical() )
569 {
570 sizeTotal.x += MARGIN;
571 sizeTotal.y += tabSize.y * rows + MARGIN;
572 }
573 else // horizontal layout
574 {
575 sizeTotal.x += tabSize.x * rows + MARGIN;
576 sizeTotal.y += MARGIN;
577 }
578
579 return sizeTotal;
580 }
581
582 void wxNotebook::AdjustPageSize(wxNotebookPage *page)
583 {
584 wxCHECK_RET( page, wxT("NULL page in wxNotebook::AdjustPageSize") );
585
586 const wxRect r = GetPageSize();
587 if ( !r.IsEmpty() )
588 {
589 page->SetSize(r);
590 }
591 }
592
593 // ----------------------------------------------------------------------------
594 // wxNotebook operations
595 // ----------------------------------------------------------------------------
596
597 // remove one page from the notebook, without deleting
598 wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
599 {
600 wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage);
601 if ( !pageRemoved )
602 return NULL;
603
604 // hide the removed page to maintain the invariant that only the
605 // selected page is visible and others are hidden:
606 pageRemoved->Show(false);
607
608 TabCtrl_DeleteItem(GetHwnd(), nPage);
609
610 if ( m_pages.IsEmpty() )
611 {
612 // no selection any more, the notebook becamse empty
613 m_selection = wxNOT_FOUND;
614 }
615 else // notebook still not empty
616 {
617 int selNew = TabCtrl_GetCurSel(GetHwnd());
618 if ( selNew != wxNOT_FOUND )
619 {
620 // No selection change, just refresh the current selection.
621 // Because it could be that the slection index changed
622 // we need to update it.
623 // Note: this does not mean the selection it self changed.
624 m_selection = selNew;
625 m_pages[m_selection]->Refresh();
626 }
627 else if (int(nPage) == m_selection)
628 {
629 // The selection was deleted.
630
631 // Determine new selection.
632 if (m_selection == int(GetPageCount()))
633 selNew = m_selection - 1;
634 else
635 selNew = m_selection;
636
637 // m_selection must be always valid so reset it before calling
638 // SetSelection()
639 m_selection = wxNOT_FOUND;
640 SetSelection(selNew);
641 }
642 else
643 {
644 wxFAIL; // Windows did not behave ok.
645 }
646 }
647
648 return pageRemoved;
649 }
650
651 // remove all pages
652 bool wxNotebook::DeleteAllPages()
653 {
654 size_t nPageCount = GetPageCount();
655 size_t nPage;
656 for ( nPage = 0; nPage < nPageCount; nPage++ )
657 delete m_pages[nPage];
658
659 m_pages.Clear();
660
661 TabCtrl_DeleteAllItems(GetHwnd());
662
663 m_selection = wxNOT_FOUND;
664
665 InvalidateBestSize();
666 return true;
667 }
668
669 // same as AddPage() but does it at given position
670 bool wxNotebook::InsertPage(size_t nPage,
671 wxNotebookPage *pPage,
672 const wxString& strText,
673 bool bSelect,
674 int imageId)
675 {
676 wxCHECK_MSG( pPage != NULL, false, wxT("NULL page in wxNotebook::InsertPage") );
677 wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false,
678 wxT("invalid index in wxNotebook::InsertPage") );
679
680 wxASSERT_MSG( pPage->GetParent() == this,
681 wxT("notebook pages must have notebook as parent") );
682
683 // add a new tab to the control
684 // ----------------------------
685
686 // init all fields to 0
687 TC_ITEM tcItem;
688 wxZeroMemory(tcItem);
689
690 // set the image, if any
691 if ( imageId != -1 )
692 {
693 tcItem.mask |= TCIF_IMAGE;
694 tcItem.iImage = imageId;
695 }
696
697 // and the text
698 if ( !strText.empty() )
699 {
700 tcItem.mask |= TCIF_TEXT;
701 tcItem.pszText = wxMSW_CONV_LPTSTR(strText);
702 }
703
704 // hide the page: unless it is selected, it shouldn't be shown (and if it
705 // is selected it will be shown later)
706 HWND hwnd = GetWinHwnd(pPage);
707 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
708
709 // this updates internal flag too -- otherwise it would get out of sync
710 // with the real state
711 pPage->Show(false);
712
713
714 // fit the notebook page to the tab control's display area: this should be
715 // done before adding it to the notebook or TabCtrl_InsertItem() will
716 // change the notebooks size itself!
717 AdjustPageSize(pPage);
718
719 // finally do insert it
720 if ( TabCtrl_InsertItem(GetHwnd(), nPage, &tcItem) == -1 )
721 {
722 wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
723
724 return false;
725 }
726
727 // need to update the bg brush when the first page is added
728 // so the first panel gets the correct themed background
729 if ( m_pages.empty() )
730 {
731 #if wxUSE_UXTHEME
732 UpdateBgBrush();
733 #endif // wxUSE_UXTHEME
734 }
735
736 // succeeded: save the pointer to the page
737 m_pages.Insert(pPage, nPage);
738
739 // we may need to adjust the size again if the notebook size changed:
740 // normally this only happens for the first page we add (the tabs which
741 // hadn't been there before are now shown) but for a multiline notebook it
742 // can happen for any page at all as a new row could have been started
743 if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) )
744 {
745 AdjustPageSize(pPage);
746
747 // Additionally, force the layout of the notebook itself by posting a
748 // size event to it. If we don't do it, notebooks with pages on the
749 // left or the right side may fail to account for the fact that they
750 // are now big enough to fit all all of their pages on one row and
751 // still reserve space for the second row of tabs, see #1792.
752 const wxSize s = GetSize();
753 ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(s.x, s.y));
754 }
755
756 // now deal with the selection
757 // ---------------------------
758
759 // if the inserted page is before the selected one, we must update the
760 // index of the selected page
761 if ( int(nPage) <= m_selection )
762 {
763 // one extra page added
764 m_selection++;
765 }
766
767 DoSetSelectionAfterInsertion(nPage, bSelect);
768
769 InvalidateBestSize();
770
771 return true;
772 }
773
774 int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
775 {
776 TC_HITTESTINFO hitTestInfo;
777 hitTestInfo.pt.x = pt.x;
778 hitTestInfo.pt.y = pt.y;
779 int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo);
780
781 if ( flags )
782 {
783 *flags = 0;
784
785 if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
786 *flags |= wxBK_HITTEST_NOWHERE;
787 if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM)
788 *flags |= wxBK_HITTEST_ONITEM;
789 if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
790 *flags |= wxBK_HITTEST_ONICON;
791 if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
792 *flags |= wxBK_HITTEST_ONLABEL;
793 if ( item == wxNOT_FOUND && GetPageSize().Contains(pt) )
794 *flags |= wxBK_HITTEST_ONPAGE;
795 }
796
797 return item;
798 }
799
800 // ----------------------------------------------------------------------------
801 // flicker-less notebook redraw
802 // ----------------------------------------------------------------------------
803
804 #if USE_NOTEBOOK_ANTIFLICKER
805
806 // wnd proc for the spin button
807 LRESULT APIENTRY _EXPORT wxNotebookSpinBtnWndProc(HWND hwnd,
808 UINT message,
809 WPARAM wParam,
810 LPARAM lParam)
811 {
812 if ( message == WM_ERASEBKGND )
813 return 0;
814
815 return ::CallWindowProc(CASTWNDPROC gs_wndprocNotebookSpinBtn,
816 hwnd, message, wParam, lParam);
817 }
818
819 LRESULT APIENTRY _EXPORT wxNotebookWndProc(HWND hwnd,
820 UINT message,
821 WPARAM wParam,
822 LPARAM lParam)
823 {
824 return ::CallWindowProc(CASTWNDPROC gs_wndprocNotebook,
825 hwnd, message, wParam, lParam);
826 }
827
828 void wxNotebook::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
829 {
830 // do nothing here
831 }
832
833 void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event))
834 {
835 wxPaintDC dc(this);
836 wxMemoryDC memdc;
837 RECT rc;
838 ::GetClientRect(GetHwnd(), &rc);
839 wxBitmap bmp(rc.right, rc.bottom);
840 memdc.SelectObject(bmp);
841
842 const wxLayoutDirection dir = dc.GetLayoutDirection();
843 memdc.SetLayoutDirection(dir);
844
845 const HDC hdc = GetHdcOf(memdc);
846
847 // The drawing logic of the native tab control is absolutely impenetrable
848 // but observation shows that in the current Windows versions (XP and 7),
849 // the tab control always erases its entire background in its window proc
850 // when the tabs are top-aligned but does not do it when the tabs are in
851 // any other position.
852 //
853 // This means that we can't rely on our background colour being used for
854 // the blank area in the tab row because this doesn't work in the default
855 // top-aligned case, hence the hack with ExtFloodFill() below. But it also
856 // means that we still do need to erase the DC to account for the other
857 // cases.
858 //
859 // Moreover, just in case some very old or very new (or even future,
860 // although it seems unlikely that this is ever going to change by now)
861 // version of Windows didn't do it like this, do both things in all cases
862 // instead of optimizing away the one of them which doesn't do anything for
863 // the effectively used tab orientation -- better safe than fast.
864
865 // Notice that we use our own background here, not the background used for
866 // the pages, because the tab row background must blend with the parent and
867 // so the background colour inherited from it (if any) must be used.
868 AutoHBRUSH hbr(wxColourToRGB(GetBackgroundColour()));
869
870 ::FillRect(hdc, &rc, hbr);
871
872 MSWDefWindowProc(WM_PAINT, (WPARAM)hdc, 0);
873
874 // At least for the top-aligned tabs, our background colour was overwritten
875 // and so we now replace the default background with our colour. This is
876 // horribly inefficient, of course, but seems to be the only way to do it.
877 if ( UseBgCol() )
878 {
879 SelectInHDC selectBrush(hdc, hbr);
880
881 // Find the point which must contain the default background colour:
882 // this is a hack, of course, but using this point "close" to the
883 // corner seems to work fine in practice.
884 int x = 0,
885 y = 0;
886
887 switch ( GetWindowStyle() & wxBK_ALIGN_MASK )
888 {
889 case wxBK_TOP:
890 x = rc.right - 2;
891 y = 2;
892 break;
893
894 case wxBK_BOTTOM:
895 x = rc.right - 2;
896 y = rc.bottom - 2;
897 break;
898
899 case wxBK_LEFT:
900 x = 2;
901 y = rc.bottom - 2;
902 break;
903
904 case wxBK_RIGHT:
905 x = 2;
906 y = rc.bottom - 2;
907 break;
908 }
909
910 ::ExtFloodFill(hdc, x, y, ::GetSysColor(COLOR_BTNFACE), FLOODFILLSURFACE);
911 }
912
913 // For some reason in RTL mode, source offset has to be -1, otherwise the
914 // right border (physical) remains unpainted.
915 const wxCoord ofs = dir == wxLayout_RightToLeft ? -1 : 0;
916 dc.Blit(ofs, 0, rc.right, rc.bottom, &memdc, ofs, 0);
917 }
918
919 #endif // USE_NOTEBOOK_ANTIFLICKER
920
921 // ----------------------------------------------------------------------------
922 // wxNotebook callbacks
923 // ----------------------------------------------------------------------------
924
925 void wxNotebook::OnSize(wxSizeEvent& event)
926 {
927 if ( GetPageCount() == 0 )
928 {
929 // Prevents droppings on resize, but does cause some flicker
930 // when there are no pages.
931 Refresh();
932 event.Skip();
933 return;
934 }
935 #ifndef __WXWINCE__
936 else
937 {
938 // Without this, we can sometimes get droppings at the edges
939 // of a notebook, for example a notebook in a splitter window.
940 // This needs to be reconciled with the RefreshRect calls
941 // at the end of this function, which weren't enough to prevent
942 // the droppings.
943
944 wxSize sz = GetClientSize();
945
946 // Refresh right side
947 wxRect rect(sz.x-4, 0, 4, sz.y);
948 RefreshRect(rect);
949
950 // Refresh bottom side
951 rect = wxRect(0, sz.y-4, sz.x, 4);
952 RefreshRect(rect);
953
954 // Refresh left side
955 rect = wxRect(0, 0, 4, sz.y);
956 RefreshRect(rect);
957 }
958 #endif // !__WXWINCE__
959
960 // fit all the notebook pages to the tab control's display area
961
962 RECT rc;
963 rc.left = rc.top = 0;
964 GetSize((int *)&rc.right, (int *)&rc.bottom);
965
966 // save the total size, we'll use it below
967 int widthNbook = rc.right - rc.left,
968 heightNbook = rc.bottom - rc.top;
969
970 // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it
971 // returns completely false values for multiline tab controls after the tabs
972 // are added but before getting the first WM_SIZE (off by ~50 pixels, see
973 //
974 // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863
975 //
976 // and the only work around I could find was this ugly hack... without it
977 // simply toggling the "multiline" checkbox in the notebook sample resulted
978 // in a noticeable page displacement
979 if ( HasFlag(wxNB_MULTILINE) )
980 {
981 // avoid an infinite recursion: we get another notification too!
982 static bool s_isInOnSize = false;
983
984 if ( !s_isInOnSize )
985 {
986 s_isInOnSize = true;
987 SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED,
988 MAKELPARAM(rc.right, rc.bottom));
989 s_isInOnSize = false;
990 }
991
992 // The best size depends on the number of rows of tabs, which can
993 // change when the notepad is resized.
994 InvalidateBestSize();
995 }
996
997 #if wxUSE_UXTHEME
998 // background bitmap size has changed, update the brush using it too
999 UpdateBgBrush();
1000 #endif // wxUSE_UXTHEME
1001
1002 TabCtrl_AdjustRect(GetHwnd(), false, &rc);
1003
1004 int width = rc.right - rc.left,
1005 height = rc.bottom - rc.top;
1006 size_t nCount = m_pages.Count();
1007 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
1008 wxNotebookPage *pPage = m_pages[nPage];
1009 pPage->SetSize(rc.left, rc.top, width, height);
1010 }
1011
1012
1013 // unless we had already repainted everything, we now need to refresh
1014 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
1015 {
1016 // invalidate areas not covered by pages
1017 RefreshRect(wxRect(0, 0, widthNbook, rc.top), false);
1018 RefreshRect(wxRect(0, rc.top, rc.left, height), false);
1019 RefreshRect(wxRect(0, rc.bottom, widthNbook, heightNbook - rc.bottom),
1020 false);
1021 RefreshRect(wxRect(rc.right, rc.top, widthNbook - rc.right, height),
1022 false);
1023 }
1024
1025 #if USE_NOTEBOOK_ANTIFLICKER
1026 // subclass the spin control used by the notebook to scroll pages to
1027 // prevent it from flickering on resize
1028 if ( !m_hasSubclassedUpdown )
1029 {
1030 // iterate over all child windows to find spin button
1031 for ( HWND child = ::GetWindow(GetHwnd(), GW_CHILD);
1032 child;
1033 child = ::GetWindow(child, GW_HWNDNEXT) )
1034 {
1035 wxWindow *childWindow = wxFindWinFromHandle((WXHWND)child);
1036
1037 // see if it exists, if no wxWindow found then assume it's the spin
1038 // btn
1039 if ( !childWindow )
1040 {
1041 // subclass the spin button to override WM_ERASEBKGND
1042 if ( !gs_wndprocNotebookSpinBtn )
1043 gs_wndprocNotebookSpinBtn = (WXFARPROC)wxGetWindowProc(child);
1044
1045 wxSetWindowProc(child, wxNotebookSpinBtnWndProc);
1046 m_hasSubclassedUpdown = true;
1047 break;
1048 }
1049 }
1050 }
1051
1052 // Probably because of the games we play above to avoid flicker sometimes
1053 // the text controls inside notebook pages are not shown correctly (they
1054 // don't have their borders) when the notebook is shown for the first time.
1055 // It's not really clear why does this happen and maybe the bug is in
1056 // wxTextCtrl itself and not here but updating the page when it's about to
1057 // be shown doesn't cost much and works around the problem so do it here
1058 // for now.
1059 if ( !m_doneUpdateHack && IsShownOnScreen() )
1060 {
1061 m_doneUpdateHack = true;
1062 wxWindow* const page = GetCurrentPage();
1063 if ( page )
1064 page->Update();
1065 }
1066 #endif // USE_NOTEBOOK_ANTIFLICKER
1067
1068 event.Skip();
1069 }
1070
1071 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
1072 {
1073 if ( event.IsWindowChange() ) {
1074 // change pages
1075 AdvanceSelection(event.GetDirection());
1076 }
1077 else {
1078 // we get this event in 3 cases
1079 //
1080 // a) one of our pages might have generated it because the user TABbed
1081 // out from it in which case we should propagate the event upwards and
1082 // our parent will take care of setting the focus to prev/next sibling
1083 //
1084 // or
1085 //
1086 // b) the parent panel wants to give the focus to us so that we
1087 // forward it to our selected page. We can't deal with this in
1088 // OnSetFocus() because we don't know which direction the focus came
1089 // from in this case and so can't choose between setting the focus to
1090 // first or last panel child
1091 //
1092 // or
1093 //
1094 // c) we ourselves (see MSWTranslateMessage) generated the event
1095 //
1096 wxWindow * const parent = GetParent();
1097
1098 // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE
1099 const bool isFromParent = event.GetEventObject() == (wxObject*) parent;
1100 const bool isFromSelf = event.GetEventObject() == (wxObject*) this;
1101 const bool isForward = event.GetDirection();
1102
1103 if ( isFromSelf && !isForward )
1104 {
1105 // focus is currently on notebook tab and should leave
1106 // it backwards (Shift-TAB)
1107 event.SetCurrentFocus(this);
1108 parent->HandleWindowEvent(event);
1109 }
1110 else if ( isFromParent || isFromSelf )
1111 {
1112 // no, it doesn't come from child, case (b) or (c): forward to a
1113 // page but only if entering notebook page (i.e. direction is
1114 // backwards (Shift-TAB) comething from out-of-notebook, or
1115 // direction is forward (TAB) from ourselves),
1116 if ( m_selection != wxNOT_FOUND &&
1117 (!event.GetDirection() || isFromSelf) )
1118 {
1119 // so that the page knows that the event comes from it's parent
1120 // and is being propagated downwards
1121 event.SetEventObject(this);
1122
1123 wxWindow *page = m_pages[m_selection];
1124 if ( !page->HandleWindowEvent(event) )
1125 {
1126 page->SetFocus();
1127 }
1128 //else: page manages focus inside it itself
1129 }
1130 else // otherwise set the focus to the notebook itself
1131 {
1132 SetFocus();
1133 }
1134 }
1135 else
1136 {
1137 // it comes from our child, case (a), pass to the parent, but only
1138 // if the direction is forwards. Otherwise set the focus to the
1139 // notebook itself. The notebook is always the 'first' control of a
1140 // page.
1141 if ( !isForward )
1142 {
1143 SetFocus();
1144 }
1145 else if ( parent )
1146 {
1147 event.SetCurrentFocus(this);
1148 parent->HandleWindowEvent(event);
1149 }
1150 }
1151 }
1152 }
1153
1154 #if wxUSE_UXTHEME
1155
1156 bool wxNotebook::DoDrawBackground(WXHDC hDC, wxWindow *child)
1157 {
1158 wxUxThemeHandle theme(child ? child : this, L"TAB");
1159 if ( !theme )
1160 return false;
1161
1162 // get the notebook client rect (we're not interested in drawing tabs
1163 // themselves)
1164 wxRect r = GetPageSize();
1165 if ( r.IsEmpty() )
1166 return false;
1167
1168 RECT rc;
1169 wxCopyRectToRECT(r, rc);
1170
1171 // map rect to the coords of the window we're drawing in
1172 if ( child )
1173 ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2);
1174
1175 // we have the content area (page size), but we need to draw all of the
1176 // background for it to be aligned correctly
1177 wxUxThemeEngine::Get()->GetThemeBackgroundExtent
1178 (
1179 theme,
1180 (HDC) hDC,
1181 9 /* TABP_PANE */,
1182 0,
1183 &rc,
1184 &rc
1185 );
1186 wxUxThemeEngine::Get()->DrawThemeBackground
1187 (
1188 theme,
1189 (HDC) hDC,
1190 9 /* TABP_PANE */,
1191 0,
1192 &rc,
1193 NULL
1194 );
1195
1196 return true;
1197 }
1198
1199 WXHBRUSH wxNotebook::QueryBgBitmap()
1200 {
1201 wxRect r = GetPageSize();
1202 if ( r.IsEmpty() )
1203 return 0;
1204
1205 WindowHDC hDC(GetHwnd());
1206 MemoryHDC hDCMem(hDC);
1207 CompatibleBitmap hBmp(hDC, r.x + r.width, r.y + r.height);
1208
1209 SelectInHDC selectBmp(hDCMem, hBmp);
1210
1211 if ( !DoDrawBackground((WXHDC)(HDC)hDCMem) )
1212 return 0;
1213
1214 return (WXHBRUSH)::CreatePatternBrush(hBmp);
1215 }
1216
1217 void wxNotebook::UpdateBgBrush()
1218 {
1219 if ( m_hbrBackground )
1220 ::DeleteObject((HBRUSH)m_hbrBackground);
1221
1222 if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() )
1223 {
1224 m_hbrBackground = QueryBgBitmap();
1225 }
1226 else // no themes or we've got user-defined solid colour
1227 {
1228 m_hbrBackground = NULL;
1229 }
1230 }
1231
1232 bool wxNotebook::MSWPrintChild(WXHDC hDC, wxWindow *child)
1233 {
1234 // solid background colour overrides themed background drawing
1235 if ( !UseBgCol() && DoDrawBackground(hDC, child) )
1236 return true;
1237
1238 // If we're using a solid colour (for example if we've switched off
1239 // theming for this notebook), paint it
1240 if (UseBgCol())
1241 {
1242 wxRect r = GetPageSize();
1243 if ( r.IsEmpty() )
1244 return false;
1245
1246 RECT rc;
1247 wxCopyRectToRECT(r, rc);
1248
1249 // map rect to the coords of the window we're drawing in
1250 if ( child )
1251 ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2);
1252
1253 wxBrush brush(GetBackgroundColour());
1254 HBRUSH hbr = GetHbrushOf(brush);
1255
1256 ::FillRect((HDC) hDC, &rc, hbr);
1257
1258 return true;
1259 }
1260
1261 return wxNotebookBase::MSWPrintChild(hDC, child);
1262 }
1263
1264 #endif // wxUSE_UXTHEME
1265
1266 // Windows only: attempts to get colour for UX theme page background
1267 wxColour wxNotebook::GetThemeBackgroundColour() const
1268 {
1269 #if wxUSE_UXTHEME
1270 if (wxUxThemeEngine::Get())
1271 {
1272 wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB");
1273 if (hTheme)
1274 {
1275 // This is total guesswork.
1276 // See PlatformSDK\Include\Tmschema.h for values.
1277 // JACS: can also use 9 (TABP_PANE)
1278 COLORREF themeColor;
1279 bool success = (S_OK == wxUxThemeEngine::Get()->GetThemeColor(
1280 hTheme,
1281 10 /* TABP_BODY */,
1282 1 /* NORMAL */,
1283 3821 /* FILLCOLORHINT */,
1284 &themeColor));
1285 if (!success)
1286 return GetBackgroundColour();
1287
1288 /*
1289 [DS] Workaround for WindowBlinds:
1290 Some themes return a near black theme color using FILLCOLORHINT,
1291 this makes notebook pages have an ugly black background and makes
1292 text (usually black) unreadable. Retry again with FILLCOLOR.
1293
1294 This workaround potentially breaks appearance of some themes,
1295 but in practice it already fixes some themes.
1296 */
1297 if (themeColor == 1)
1298 {
1299 wxUxThemeEngine::Get()->GetThemeColor(
1300 hTheme,
1301 10 /* TABP_BODY */,
1302 1 /* NORMAL */,
1303 3802 /* FILLCOLOR */,
1304 &themeColor);
1305 }
1306
1307 wxColour colour = wxRGBToColour(themeColor);
1308
1309 // Under Vista, the tab background colour is reported incorrectly.
1310 // So for the default theme at least, hard-code the colour to something
1311 // that will blend in.
1312
1313 static int s_AeroStatus = -1;
1314 if (s_AeroStatus == -1)
1315 {
1316 WCHAR szwThemeFile[1024];
1317 WCHAR szwThemeColor[256];
1318 if (S_OK == wxUxThemeEngine::Get()->GetCurrentThemeName(szwThemeFile, 1024, szwThemeColor, 256, NULL, 0))
1319 {
1320 wxString themeFile(szwThemeFile), themeColor(szwThemeColor);
1321 if (themeFile.Find(wxT("Aero")) != -1 && themeColor == wxT("NormalColor"))
1322 s_AeroStatus = 1;
1323 else
1324 s_AeroStatus = 0;
1325 }
1326 else
1327 s_AeroStatus = 0;
1328 }
1329
1330 if (s_AeroStatus == 1)
1331 colour = wxColour(255, 255, 255);
1332
1333 return colour;
1334 }
1335 }
1336 #endif // wxUSE_UXTHEME
1337
1338 return GetBackgroundColour();
1339 }
1340
1341 // ----------------------------------------------------------------------------
1342 // wxNotebook base class virtuals
1343 // ----------------------------------------------------------------------------
1344
1345 #if wxUSE_CONSTRAINTS
1346
1347 // override these 2 functions to do nothing: everything is done in OnSize
1348
1349 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
1350 {
1351 // don't set the sizes of the pages - their correct size is not yet known
1352 wxControl::SetConstraintSizes(false);
1353 }
1354
1355 bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
1356 {
1357 return true;
1358 }
1359
1360 #endif // wxUSE_CONSTRAINTS
1361
1362 // ----------------------------------------------------------------------------
1363 // wxNotebook Windows message handlers
1364 // ----------------------------------------------------------------------------
1365
1366 bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode,
1367 WXWORD pos, WXHWND control)
1368 {
1369 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
1370 // up-down control
1371 if ( control )
1372 return false;
1373
1374 return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control);
1375 }
1376
1377 bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
1378 {
1379 wxBookCtrlEvent event(wxEVT_NULL, m_windowId);
1380
1381 NMHDR* hdr = (NMHDR *)lParam;
1382 switch ( hdr->code ) {
1383 case TCN_SELCHANGE:
1384 event.SetEventType(wxEVT_NOTEBOOK_PAGE_CHANGED);
1385 break;
1386
1387 case TCN_SELCHANGING:
1388 event.SetEventType(wxEVT_NOTEBOOK_PAGE_CHANGING);
1389 break;
1390
1391 default:
1392 return wxControl::MSWOnNotify(idCtrl, lParam, result);
1393 }
1394
1395 event.SetSelection(TabCtrl_GetCurSel(GetHwnd()));
1396 event.SetOldSelection(m_selection);
1397 event.SetEventObject(this);
1398 event.SetInt(idCtrl);
1399
1400 // Change the selection before generating the event as its handler should
1401 // already see the new page selected.
1402 if ( hdr->code == TCN_SELCHANGE )
1403 UpdateSelection(event.GetSelection());
1404
1405 bool processed = HandleWindowEvent(event);
1406 *result = !event.IsAllowed();
1407 return processed;
1408 }
1409
1410 #endif // wxUSE_NOTEBOOK