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