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