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