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