]> git.saurik.com Git - wxWidgets.git/blob - src/msw/notebook.cpp
793d0dd8d7355391b1b118a105f30b743d2702f4
[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 #endif // WX_PRECOMP
34
35 #include "wx/imaglist.h"
36 #include "wx/sysopt.h"
37
38 #include "wx/msw/private.h"
39 #include "wx/msw/dc.h"
40
41 #include <windowsx.h>
42 #include "wx/msw/winundef.h"
43
44 #if wxUSE_UXTHEME
45 #include "wx/msw/uxtheme.h"
46 #endif
47
48 // ----------------------------------------------------------------------------
49 // macros
50 // ----------------------------------------------------------------------------
51
52 // check that the page index is valid
53 #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
54
55 // you can set USE_NOTEBOOK_ANTIFLICKER to 0 for desktop Windows versions too
56 // to disable code whih results in flicker-less notebook redrawing at the
57 // expense of some extra GDI resource consumption
58 #ifdef __WXWINCE__
59 // notebooks are never resized under CE anyhow
60 #define USE_NOTEBOOK_ANTIFLICKER 0
61 #else
62 #define USE_NOTEBOOK_ANTIFLICKER 1
63 #endif
64
65 // ----------------------------------------------------------------------------
66 // constants
67 // ----------------------------------------------------------------------------
68
69 // This is a work-around for missing defines in gcc-2.95 headers
70 #ifndef TCS_RIGHT
71 #define TCS_RIGHT 0x0002
72 #endif
73
74 #ifndef TCS_VERTICAL
75 #define TCS_VERTICAL 0x0080
76 #endif
77
78 #ifndef TCS_BOTTOM
79 #define TCS_BOTTOM TCS_RIGHT
80 #endif
81
82 // ----------------------------------------------------------------------------
83 // global variables
84 // ----------------------------------------------------------------------------
85
86 #if USE_NOTEBOOK_ANTIFLICKER
87
88 // the pointer to standard spin button wnd proc
89 static WXFARPROC gs_wndprocNotebookSpinBtn = (WXFARPROC)NULL;
90
91 // the pointer to standard tab control wnd proc
92 static WXFARPROC gs_wndprocNotebook = (WXFARPROC)NULL;
93
94 LRESULT APIENTRY _EXPORT wxNotebookWndProc(HWND hwnd,
95 UINT message,
96 WPARAM wParam,
97 LPARAM lParam);
98
99 #endif // USE_NOTEBOOK_ANTIFLICKER
100
101 // ----------------------------------------------------------------------------
102 // global functions
103 // ----------------------------------------------------------------------------
104
105 static bool HasTroubleWithNonTopTabs()
106 {
107 const int verComCtl32 = wxApp::GetComCtl32Version();
108
109 // 600 is XP, 616 is Vista -- and both have a problem with tabs not on top
110 // (but don't just test for >= 600 as Microsoft might decide to fix it in
111 // later versions, who knows...)
112 return verComCtl32 >= 600 && verComCtl32 <= 616;
113 }
114
115 // ----------------------------------------------------------------------------
116 // event table
117 // ----------------------------------------------------------------------------
118
119 #include "wx/listimpl.cpp"
120
121 WX_DEFINE_LIST( wxNotebookPageInfoList )
122
123 BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
124 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
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 m_nSelection = wxNOT_FOUND;
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_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection )
454 {
455 if ( SendPageChangingEvent(nPage) )
456 {
457 // program allows the page change
458 SendPageChangedEvent(m_nSelection, nPage);
459
460 TabCtrl_SetCurSel(GetHwnd(), nPage);
461 }
462 }
463
464 return m_nSelection;
465 }
466
467 void wxNotebook::UpdateSelection(int selNew)
468 {
469 if ( m_nSelection != wxNOT_FOUND )
470 m_pages[m_nSelection]->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_nSelection = 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_nSelection;
496
497 if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection )
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 TabCtrl_DeleteItem(GetHwnd(), nPage);
691
692 if ( m_pages.IsEmpty() )
693 {
694 // no selection any more, the notebook becamse empty
695 m_nSelection = wxNOT_FOUND;
696 }
697 else // notebook still not empty
698 {
699 int selNew = TabCtrl_GetCurSel(GetHwnd());
700 if ( selNew != wxNOT_FOUND )
701 {
702 // No selection change, just refresh the current selection.
703 // Because it could be that the slection index changed
704 // we need to update it.
705 // Note: this does not mean the selection it self changed.
706 m_nSelection = selNew;
707 m_pages[m_nSelection]->Refresh();
708 }
709 else if (int(nPage) == m_nSelection)
710 {
711 // The selection was deleted.
712
713 // Determine new selection.
714 if (m_nSelection == int(GetPageCount()))
715 selNew = m_nSelection - 1;
716 else
717 selNew = m_nSelection;
718
719 // m_nSelection must be always valid so reset it before calling
720 // SetSelection()
721 m_nSelection = wxNOT_FOUND;
722 SetSelection(selNew);
723 }
724 else
725 {
726 wxFAIL; // Windows did not behave ok.
727 }
728 }
729
730 return pageRemoved;
731 }
732
733 // remove all pages
734 bool wxNotebook::DeleteAllPages()
735 {
736 size_t nPageCount = GetPageCount();
737 size_t nPage;
738 for ( nPage = 0; nPage < nPageCount; nPage++ )
739 delete m_pages[nPage];
740
741 m_pages.Clear();
742
743 TabCtrl_DeleteAllItems(GetHwnd());
744
745 m_nSelection = wxNOT_FOUND;
746
747 InvalidateBestSize();
748 return true;
749 }
750
751 // same as AddPage() but does it at given position
752 bool wxNotebook::InsertPage(size_t nPage,
753 wxNotebookPage *pPage,
754 const wxString& strText,
755 bool bSelect,
756 int imageId)
757 {
758 wxCHECK_MSG( pPage != NULL, false, wxT("NULL page in wxNotebook::InsertPage") );
759 wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false,
760 wxT("invalid index in wxNotebook::InsertPage") );
761
762 wxASSERT_MSG( pPage->GetParent() == this,
763 wxT("notebook pages must have notebook as parent") );
764
765 // add a new tab to the control
766 // ----------------------------
767
768 // init all fields to 0
769 TC_ITEM tcItem;
770 wxZeroMemory(tcItem);
771
772 // set the image, if any
773 if ( imageId != -1 )
774 {
775 tcItem.mask |= TCIF_IMAGE;
776 tcItem.iImage = imageId;
777 }
778
779 // and the text
780 if ( !strText.empty() )
781 {
782 tcItem.mask |= TCIF_TEXT;
783 tcItem.pszText = (wxChar *)strText.wx_str(); // const_cast
784 }
785
786 // hide the page: unless it is selected, it shouldn't be shown (and if it
787 // is selected it will be shown later)
788 HWND hwnd = GetWinHwnd(pPage);
789 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
790
791 // this updates internal flag too -- otherwise it would get out of sync
792 // with the real state
793 pPage->Show(false);
794
795
796 // fit the notebook page to the tab control's display area: this should be
797 // done before adding it to the notebook or TabCtrl_InsertItem() will
798 // change the notebooks size itself!
799 AdjustPageSize(pPage);
800
801 // finally do insert it
802 if ( TabCtrl_InsertItem(GetHwnd(), nPage, &tcItem) == -1 )
803 {
804 wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
805
806 return false;
807 }
808
809 // need to update the bg brush when the first page is added
810 // so the first panel gets the correct themed background
811 if ( m_pages.empty() )
812 {
813 #if wxUSE_UXTHEME
814 UpdateBgBrush();
815 #endif // wxUSE_UXTHEME
816 }
817
818 // succeeded: save the pointer to the page
819 m_pages.Insert(pPage, nPage);
820
821 // also ensure that the notebook background is used for its pages by making
822 // them transparent: this ensures that MSWGetBgBrush() queries the notebook
823 // for the background brush to be used for erasing them
824 if ( wxPanel *panel = wxDynamicCast(pPage, wxPanel) )
825 {
826 panel->MSWSetTransparentBackground();
827 }
828
829 // we may need to adjust the size again if the notebook size changed:
830 // normally this only happens for the first page we add (the tabs which
831 // hadn't been there before are now shown) but for a multiline notebook it
832 // can happen for any page at all as a new row could have been started
833 if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) )
834 {
835 AdjustPageSize(pPage);
836 }
837
838 // now deal with the selection
839 // ---------------------------
840
841 // if the inserted page is before the selected one, we must update the
842 // index of the selected page
843 if ( int(nPage) <= m_nSelection )
844 {
845 // one extra page added
846 m_nSelection++;
847 }
848
849 // some page should be selected: either this one or the first one if there
850 // is still no selection
851 int selNew = wxNOT_FOUND;
852 if ( bSelect )
853 selNew = nPage;
854 else if ( m_nSelection == wxNOT_FOUND )
855 selNew = 0;
856
857 if ( selNew != wxNOT_FOUND )
858 SetSelection(selNew);
859
860 InvalidateBestSize();
861
862 return true;
863 }
864
865 int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
866 {
867 TC_HITTESTINFO hitTestInfo;
868 hitTestInfo.pt.x = pt.x;
869 hitTestInfo.pt.y = pt.y;
870 int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo);
871
872 if ( flags )
873 {
874 *flags = 0;
875
876 if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
877 *flags |= wxBK_HITTEST_NOWHERE;
878 if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM)
879 *flags |= wxBK_HITTEST_ONITEM;
880 if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
881 *flags |= wxBK_HITTEST_ONICON;
882 if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
883 *flags |= wxBK_HITTEST_ONLABEL;
884 if ( item == wxNOT_FOUND && GetPageSize().Contains(pt) )
885 *flags |= wxBK_HITTEST_ONPAGE;
886 }
887
888 return item;
889 }
890
891 // ----------------------------------------------------------------------------
892 // flicker-less notebook redraw
893 // ----------------------------------------------------------------------------
894
895 #if USE_NOTEBOOK_ANTIFLICKER
896
897 // wnd proc for the spin button
898 LRESULT APIENTRY _EXPORT wxNotebookSpinBtnWndProc(HWND hwnd,
899 UINT message,
900 WPARAM wParam,
901 LPARAM lParam)
902 {
903 if ( message == WM_ERASEBKGND )
904 return 0;
905
906 return ::CallWindowProc(CASTWNDPROC gs_wndprocNotebookSpinBtn,
907 hwnd, message, wParam, lParam);
908 }
909
910 LRESULT APIENTRY _EXPORT wxNotebookWndProc(HWND hwnd,
911 UINT message,
912 WPARAM wParam,
913 LPARAM lParam)
914 {
915 return ::CallWindowProc(CASTWNDPROC gs_wndprocNotebook,
916 hwnd, message, wParam, lParam);
917 }
918
919 void wxNotebook::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
920 {
921 // do nothing here
922 }
923
924 void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event))
925 {
926 wxPaintDC dc(this);
927 wxMemoryDC memdc;
928 RECT rc;
929 ::GetClientRect(GetHwnd(), &rc);
930 wxBitmap bmp(rc.right, rc.bottom);
931 memdc.SelectObject(bmp);
932
933 const wxLayoutDirection dir = dc.GetLayoutDirection();
934 memdc.SetLayoutDirection(dir);
935
936 // if there is no special brush just use the solid background colour
937 #if wxUSE_UXTHEME
938 HBRUSH hbr = (HBRUSH)m_hbrBackground;
939 #else
940 HBRUSH hbr = 0;
941 #endif
942 wxBrush brush;
943 if ( !hbr )
944 {
945 brush = wxBrush(GetBackgroundColour());
946 hbr = GetHbrushOf(brush);
947 }
948
949 wxMSWDCImpl *impl = (wxMSWDCImpl*) memdc.GetImpl();
950
951 ::FillRect(GetHdcOf(*impl), &rc, hbr);
952
953 MSWDefWindowProc(WM_PAINT, (WPARAM)(impl->GetHDC()), 0);
954
955 // For some reason in RTL mode, source offset has to be -1, otherwise the
956 // right border (physical) remains unpainted.
957 const wxCoord ofs = dir == wxLayout_RightToLeft ? -1 : 0;
958 dc.Blit(ofs, 0, rc.right, rc.bottom, &memdc, ofs, 0);
959 }
960
961 #endif // USE_NOTEBOOK_ANTIFLICKER
962
963 // ----------------------------------------------------------------------------
964 // wxNotebook callbacks
965 // ----------------------------------------------------------------------------
966
967 void wxNotebook::OnSize(wxSizeEvent& event)
968 {
969 if ( GetPageCount() == 0 )
970 {
971 // Prevents droppings on resize, but does cause some flicker
972 // when there are no pages.
973 Refresh();
974 event.Skip();
975 return;
976 }
977 #ifndef __WXWINCE__
978 else
979 {
980 // Without this, we can sometimes get droppings at the edges
981 // of a notebook, for example a notebook in a splitter window.
982 // This needs to be reconciled with the RefreshRect calls
983 // at the end of this function, which weren't enough to prevent
984 // the droppings.
985
986 wxSize sz = GetClientSize();
987
988 // Refresh right side
989 wxRect rect(sz.x-4, 0, 4, sz.y);
990 RefreshRect(rect);
991
992 // Refresh bottom side
993 rect = wxRect(0, sz.y-4, sz.x, 4);
994 RefreshRect(rect);
995
996 // Refresh left side
997 rect = wxRect(0, 0, 4, sz.y);
998 RefreshRect(rect);
999 }
1000 #endif // !__WXWINCE__
1001
1002 // fit all the notebook pages to the tab control's display area
1003
1004 RECT rc;
1005 rc.left = rc.top = 0;
1006 GetSize((int *)&rc.right, (int *)&rc.bottom);
1007
1008 // save the total size, we'll use it below
1009 int widthNbook = rc.right - rc.left,
1010 heightNbook = rc.bottom - rc.top;
1011
1012 // there seems to be a bug in the implementation of TabCtrl_AdjustRect(): it
1013 // returns completely false values for multiline tab controls after the tabs
1014 // are added but before getting the first WM_SIZE (off by ~50 pixels, see
1015 //
1016 // http://sf.net/tracker/index.php?func=detail&aid=645323&group_id=9863&atid=109863
1017 //
1018 // and the only work around I could find was this ugly hack... without it
1019 // simply toggling the "multiline" checkbox in the notebook sample resulted
1020 // in a noticeable page displacement
1021 if ( HasFlag(wxNB_MULTILINE) )
1022 {
1023 // avoid an infinite recursion: we get another notification too!
1024 static bool s_isInOnSize = false;
1025
1026 if ( !s_isInOnSize )
1027 {
1028 s_isInOnSize = true;
1029 SendMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED,
1030 MAKELPARAM(rc.right, rc.bottom));
1031 s_isInOnSize = false;
1032 }
1033
1034 // The best size depends on the number of rows of tabs, which can
1035 // change when the notepad is resized.
1036 InvalidateBestSize();
1037 }
1038
1039 #if wxUSE_UXTHEME
1040 // background bitmap size has changed, update the brush using it too
1041 UpdateBgBrush();
1042 #endif // wxUSE_UXTHEME
1043
1044 TabCtrl_AdjustRect(GetHwnd(), false, &rc);
1045
1046 int width = rc.right - rc.left,
1047 height = rc.bottom - rc.top;
1048 size_t nCount = m_pages.Count();
1049 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
1050 wxNotebookPage *pPage = m_pages[nPage];
1051 pPage->SetSize(rc.left, rc.top, width, height);
1052 }
1053
1054
1055 // unless we had already repainted everything, we now need to refresh
1056 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
1057 {
1058 // invalidate areas not covered by pages
1059 RefreshRect(wxRect(0, 0, widthNbook, rc.top), false);
1060 RefreshRect(wxRect(0, rc.top, rc.left, height), false);
1061 RefreshRect(wxRect(0, rc.bottom, widthNbook, heightNbook - rc.bottom),
1062 false);
1063 RefreshRect(wxRect(rc.right, rc.top, widthNbook - rc.right, height),
1064 false);
1065 }
1066
1067 #if USE_NOTEBOOK_ANTIFLICKER
1068 // subclass the spin control used by the notebook to scroll pages to
1069 // prevent it from flickering on resize
1070 if ( !m_hasSubclassedUpdown )
1071 {
1072 // iterate over all child windows to find spin button
1073 for ( HWND child = ::GetWindow(GetHwnd(), GW_CHILD);
1074 child;
1075 child = ::GetWindow(child, GW_HWNDNEXT) )
1076 {
1077 wxWindow *childWindow = wxFindWinFromHandle((WXHWND)child);
1078
1079 // see if it exists, if no wxWindow found then assume it's the spin
1080 // btn
1081 if ( !childWindow )
1082 {
1083 // subclass the spin button to override WM_ERASEBKGND
1084 if ( !gs_wndprocNotebookSpinBtn )
1085 gs_wndprocNotebookSpinBtn = (WXFARPROC)wxGetWindowProc(child);
1086
1087 wxSetWindowProc(child, wxNotebookSpinBtnWndProc);
1088 m_hasSubclassedUpdown = true;
1089 break;
1090 }
1091 }
1092 }
1093 #endif // USE_NOTEBOOK_ANTIFLICKER
1094
1095 event.Skip();
1096 }
1097
1098 void wxNotebook::OnSelChange(wxBookCtrlEvent& event)
1099 {
1100 // is it our tab control?
1101 if ( event.GetEventObject() == this )
1102 {
1103 UpdateSelection(event.GetSelection());
1104 }
1105
1106 // we want to give others a chance to process this message as well
1107 event.Skip();
1108 }
1109
1110 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
1111 {
1112 if ( event.IsWindowChange() ) {
1113 // change pages
1114 AdvanceSelection(event.GetDirection());
1115 }
1116 else {
1117 // we get this event in 3 cases
1118 //
1119 // a) one of our pages might have generated it because the user TABbed
1120 // out from it in which case we should propagate the event upwards and
1121 // our parent will take care of setting the focus to prev/next sibling
1122 //
1123 // or
1124 //
1125 // b) the parent panel wants to give the focus to us so that we
1126 // forward it to our selected page. We can't deal with this in
1127 // OnSetFocus() because we don't know which direction the focus came
1128 // from in this case and so can't choose between setting the focus to
1129 // first or last panel child
1130 //
1131 // or
1132 //
1133 // c) we ourselves (see MSWTranslateMessage) generated the event
1134 //
1135 wxWindow * const parent = GetParent();
1136
1137 // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE
1138 const bool isFromParent = event.GetEventObject() == (wxObject*) parent;
1139 const bool isFromSelf = event.GetEventObject() == (wxObject*) this;
1140
1141 if ( isFromParent || isFromSelf )
1142 {
1143 // no, it doesn't come from child, case (b) or (c): forward to a
1144 // page but only if direction is backwards (TAB) or from ourselves,
1145 if ( m_nSelection != wxNOT_FOUND &&
1146 (!event.GetDirection() || isFromSelf) )
1147 {
1148 // so that the page knows that the event comes from it's parent
1149 // and is being propagated downwards
1150 event.SetEventObject(this);
1151
1152 wxWindow *page = m_pages[m_nSelection];
1153 if ( !page->HandleWindowEvent(event) )
1154 {
1155 page->SetFocus();
1156 }
1157 //else: page manages focus inside it itself
1158 }
1159 else // otherwise set the focus to the notebook itself
1160 {
1161 SetFocus();
1162 }
1163 }
1164 else
1165 {
1166 // it comes from our child, case (a), pass to the parent, but only
1167 // if the direction is forwards. Otherwise set the focus to the
1168 // notebook itself. The notebook is always the 'first' control of a
1169 // page.
1170 if ( !event.GetDirection() )
1171 {
1172 SetFocus();
1173 }
1174 else if ( parent )
1175 {
1176 event.SetCurrentFocus(this);
1177 parent->HandleWindowEvent(event);
1178 }
1179 }
1180 }
1181 }
1182
1183 #if wxUSE_UXTHEME
1184
1185 bool wxNotebook::DoDrawBackground(WXHDC hDC, wxWindow *child)
1186 {
1187 wxUxThemeHandle theme(child ? child : this, L"TAB");
1188 if ( !theme )
1189 return false;
1190
1191 // get the notebook client rect (we're not interested in drawing tabs
1192 // themselves)
1193 wxRect r = GetPageSize();
1194 if ( r.IsEmpty() )
1195 return false;
1196
1197 RECT rc;
1198 wxCopyRectToRECT(r, rc);
1199
1200 // map rect to the coords of the window we're drawing in
1201 if ( child )
1202 ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2);
1203
1204 // we have the content area (page size), but we need to draw all of the
1205 // background for it to be aligned correctly
1206 wxUxThemeEngine::Get()->GetThemeBackgroundExtent
1207 (
1208 theme,
1209 (HDC) hDC,
1210 9 /* TABP_PANE */,
1211 0,
1212 &rc,
1213 &rc
1214 );
1215 wxUxThemeEngine::Get()->DrawThemeBackground
1216 (
1217 theme,
1218 (HDC) hDC,
1219 9 /* TABP_PANE */,
1220 0,
1221 &rc,
1222 NULL
1223 );
1224
1225 return true;
1226 }
1227
1228 WXHBRUSH wxNotebook::QueryBgBitmap()
1229 {
1230 wxRect r = GetPageSize();
1231 if ( r.IsEmpty() )
1232 return 0;
1233
1234 WindowHDC hDC(GetHwnd());
1235 MemoryHDC hDCMem(hDC);
1236 CompatibleBitmap hBmp(hDC, r.x + r.width, r.y + r.height);
1237
1238 SelectInHDC selectBmp(hDCMem, hBmp);
1239
1240 if ( !DoDrawBackground((WXHDC)(HDC)hDCMem) )
1241 return 0;
1242
1243 return (WXHBRUSH)::CreatePatternBrush(hBmp);
1244 }
1245
1246 void wxNotebook::UpdateBgBrush()
1247 {
1248 if ( m_hbrBackground )
1249 ::DeleteObject((HBRUSH)m_hbrBackground);
1250
1251 if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() )
1252 {
1253 m_hbrBackground = QueryBgBitmap();
1254 }
1255 else // no themes or we've got user-defined solid colour
1256 {
1257 m_hbrBackground = NULL;
1258 }
1259 }
1260
1261 WXHBRUSH wxNotebook::MSWGetBgBrushForChild(WXHDC hDC, wxWindow *child)
1262 {
1263 if ( m_hbrBackground )
1264 {
1265 // before drawing with the background brush, we need to position it
1266 // correctly
1267 RECT rc;
1268 ::GetWindowRect(GetHwndOf(child), &rc);
1269
1270 ::MapWindowPoints(NULL, GetHwnd(), (POINT *)&rc, 1);
1271
1272 if ( !::SetBrushOrgEx((HDC)hDC, -rc.left, -rc.top, NULL) )
1273 {
1274 wxLogLastError(wxT("SetBrushOrgEx(notebook bg brush)"));
1275 }
1276
1277 return m_hbrBackground;
1278 }
1279
1280 return wxNotebookBase::MSWGetBgBrushForChild(hDC, child);
1281 }
1282
1283 bool wxNotebook::MSWPrintChild(WXHDC hDC, wxWindow *child)
1284 {
1285 // solid background colour overrides themed background drawing
1286 if ( !UseBgCol() && DoDrawBackground(hDC, child) )
1287 return true;
1288
1289 // If we're using a solid colour (for example if we've switched off
1290 // theming for this notebook), paint it
1291 if (UseBgCol())
1292 {
1293 wxRect r = GetPageSize();
1294 if ( r.IsEmpty() )
1295 return false;
1296
1297 RECT rc;
1298 wxCopyRectToRECT(r, rc);
1299
1300 // map rect to the coords of the window we're drawing in
1301 if ( child )
1302 ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2);
1303
1304 wxBrush brush(GetBackgroundColour());
1305 HBRUSH hbr = GetHbrushOf(brush);
1306
1307 ::FillRect((HDC) hDC, &rc, hbr);
1308
1309 return true;
1310 }
1311
1312 return wxNotebookBase::MSWPrintChild(hDC, child);
1313 }
1314
1315 #endif // wxUSE_UXTHEME
1316
1317 // Windows only: attempts to get colour for UX theme page background
1318 wxColour wxNotebook::GetThemeBackgroundColour() const
1319 {
1320 #if wxUSE_UXTHEME
1321 if (wxUxThemeEngine::Get())
1322 {
1323 wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB");
1324 if (hTheme)
1325 {
1326 // This is total guesswork.
1327 // See PlatformSDK\Include\Tmschema.h for values.
1328 // JACS: can also use 9 (TABP_PANE)
1329 COLORREF themeColor;
1330 bool success = (S_OK == wxUxThemeEngine::Get()->GetThemeColor(
1331 hTheme,
1332 10 /* TABP_BODY */,
1333 1 /* NORMAL */,
1334 3821 /* FILLCOLORHINT */,
1335 &themeColor));
1336 if (!success)
1337 return GetBackgroundColour();
1338
1339 /*
1340 [DS] Workaround for WindowBlinds:
1341 Some themes return a near black theme color using FILLCOLORHINT,
1342 this makes notebook pages have an ugly black background and makes
1343 text (usually black) unreadable. Retry again with FILLCOLOR.
1344
1345 This workaround potentially breaks appearance of some themes,
1346 but in practice it already fixes some themes.
1347 */
1348 if (themeColor == 1)
1349 {
1350 wxUxThemeEngine::Get()->GetThemeColor(
1351 hTheme,
1352 10 /* TABP_BODY */,
1353 1 /* NORMAL */,
1354 3802 /* FILLCOLOR */,
1355 &themeColor);
1356 }
1357
1358 wxColour colour = wxRGBToColour(themeColor);
1359
1360 // Under Vista, the tab background colour is reported incorrectly.
1361 // So for the default theme at least, hard-code the colour to something
1362 // that will blend in.
1363
1364 static int s_AeroStatus = -1;
1365 if (s_AeroStatus == -1)
1366 {
1367 WCHAR szwThemeFile[1024];
1368 WCHAR szwThemeColor[256];
1369 if (S_OK == wxUxThemeEngine::Get()->GetCurrentThemeName(szwThemeFile, 1024, szwThemeColor, 256, NULL, 0))
1370 {
1371 wxString themeFile(szwThemeFile), themeColor(szwThemeColor);
1372 if (themeFile.Find(wxT("Aero")) != -1 && themeColor == wxT("NormalColor"))
1373 s_AeroStatus = 1;
1374 else
1375 s_AeroStatus = 0;
1376 }
1377 else
1378 s_AeroStatus = 0;
1379 }
1380
1381 if (s_AeroStatus == 1)
1382 colour = wxColour(255, 255, 255);
1383
1384 return colour;
1385 }
1386 }
1387 #endif // wxUSE_UXTHEME
1388
1389 return GetBackgroundColour();
1390 }
1391
1392 // ----------------------------------------------------------------------------
1393 // wxNotebook base class virtuals
1394 // ----------------------------------------------------------------------------
1395
1396 #if wxUSE_CONSTRAINTS
1397
1398 // override these 2 functions to do nothing: everything is done in OnSize
1399
1400 void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
1401 {
1402 // don't set the sizes of the pages - their correct size is not yet known
1403 wxControl::SetConstraintSizes(false);
1404 }
1405
1406 bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
1407 {
1408 return true;
1409 }
1410
1411 #endif // wxUSE_CONSTRAINTS
1412
1413 // ----------------------------------------------------------------------------
1414 // wxNotebook Windows message handlers
1415 // ----------------------------------------------------------------------------
1416
1417 bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode,
1418 WXWORD pos, WXHWND control)
1419 {
1420 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
1421 // up-down control
1422 if ( control )
1423 return false;
1424
1425 return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control);
1426 }
1427
1428 bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
1429 {
1430 wxBookCtrlEvent event(wxEVT_NULL, m_windowId);
1431
1432 NMHDR* hdr = (NMHDR *)lParam;
1433 switch ( hdr->code ) {
1434 case TCN_SELCHANGE:
1435 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
1436 break;
1437
1438 case TCN_SELCHANGING:
1439 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING);
1440 break;
1441
1442 default:
1443 return wxControl::MSWOnNotify(idCtrl, lParam, result);
1444 }
1445
1446 event.SetSelection(TabCtrl_GetCurSel(GetHwnd()));
1447 event.SetOldSelection(m_nSelection);
1448 event.SetEventObject(this);
1449 event.SetInt(idCtrl);
1450
1451 bool processed = HandleWindowEvent(event);
1452 *result = !event.IsAllowed();
1453 return processed;
1454 }
1455
1456 #endif // wxUSE_NOTEBOOK