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