]> git.saurik.com Git - wxWidgets.git/blame - src/msw/notebook.cpp
overview of multilib libraries added
[wxWidgets.git] / src / msw / notebook.cpp
CommitLineData
88310e2e
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/notebook.cpp
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>
6c9a19aa 9// Licence: wxWindows licence
88310e2e
VZ
10///////////////////////////////////////////////////////////////////////////////
11
88310e2e 12#ifdef __GNUG__
a3b46648 13#pragma implementation "notebook.h"
88310e2e
VZ
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
1e6feb95 20 #pragma hdrstop
88310e2e
VZ
21#endif
22
1e6feb95
VZ
23#if wxUSE_NOTEBOOK
24
88310e2e
VZ
25// wxWindows
26#ifndef WX_PRECOMP
3096bd2f 27 #include "wx/string.h"
88310e2e
VZ
28#endif // WX_PRECOMP
29
3096bd2f
VZ
30#include "wx/log.h"
31#include "wx/imaglist.h"
32#include "wx/event.h"
33#include "wx/control.h"
34#include "wx/notebook.h"
04eb05b0 35#include "wx/app.h"
88310e2e 36
3096bd2f 37#include "wx/msw/private.h"
88310e2e
VZ
38
39// Windows standard headers
40#ifndef __WIN95__
2432b92d 41 #error "wxNotebook is only supported Windows 95 and above"
88310e2e
VZ
42#endif //Win95
43
aaab7c01
VZ
44#include <windowsx.h> // for SetWindowFont
45
b39dbf34
JS
46#ifdef __GNUWIN32_OLD__
47 #include "wx/msw/gnuwin32/extra.h"
65fd5cb0 48#endif
57c208c5 49
b39dbf34 50#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
c42404a5 51 #include <commctrl.h>
88310e2e
VZ
52#endif
53
85b43fbf
JS
54#include "wx/msw/winundef.h"
55
56#if wxUSE_UXTHEME
57#include "wx/msw/uxtheme.h"
58
59#include "wx/radiobut.h"
60#include "wx/radiobox.h"
61#include "wx/checkbox.h"
62#include "wx/bmpbuttn.h"
63#include "wx/statline.h"
64#include "wx/statbox.h"
65#include "wx/stattext.h"
66#include "wx/slider.h"
67#include "wx/scrolwin.h"
68#include "wx/panel.h"
69#endif
70
88310e2e
VZ
71// ----------------------------------------------------------------------------
72// macros
73// ----------------------------------------------------------------------------
74
75// check that the page index is valid
76#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount()))
77
78// hide the ugly cast
79#define m_hwnd (HWND)GetHWND()
80
74b31181
VZ
81// ----------------------------------------------------------------------------
82// constants
83// ----------------------------------------------------------------------------
84
85// This is a work-around for missing defines in gcc-2.95 headers
86#ifndef TCS_RIGHT
87 #define TCS_RIGHT 0x0002
88#endif
89
90#ifndef TCS_VERTICAL
91 #define TCS_VERTICAL 0x0080
92#endif
93
94#ifndef TCS_BOTTOM
95 #define TCS_BOTTOM TCS_RIGHT
96#endif
97
88310e2e
VZ
98// ----------------------------------------------------------------------------
99// event table
100// ----------------------------------------------------------------------------
101
2e4df4bf
VZ
102DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
103DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
104
d9317fd4 105BEGIN_EVENT_TABLE(wxNotebook, wxControl)
88310e2e
VZ
106 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
107
9026ad85 108 EVT_SIZE(wxNotebook::OnSize)
42e69d6b 109
88310e2e 110 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
42e69d6b 111
88310e2e 112 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
d9317fd4 113END_EVENT_TABLE()
88310e2e 114
51596bcb
SC
115#if wxUSE_EXTENDED_RTTI
116IMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxControl,"wx/notebook.h")
117
118WX_BEGIN_PROPERTIES_TABLE(wxNotebook)
119WX_END_PROPERTIES_TABLE()
120
121WX_BEGIN_HANDLERS_TABLE(wxNotebook)
122WX_END_HANDLERS_TABLE()
123
124WX_CONSTRUCTOR_4( wxNotebook , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size )
125
126#else
d9317fd4 127IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
51596bcb 128#endif
d9317fd4 129IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
88310e2e
VZ
130
131// ============================================================================
132// implementation
133// ============================================================================
134
135// ----------------------------------------------------------------------------
136// wxNotebook construction
137// ----------------------------------------------------------------------------
138
139// common part of all ctors
140void wxNotebook::Init()
141{
1e6feb95 142 m_imageList = NULL;
88310e2e
VZ
143 m_nSelection = -1;
144}
145
146// default for dynamic class
147wxNotebook::wxNotebook()
148{
149 Init();
150}
151
152// the same arguments as for wxControl
153wxNotebook::wxNotebook(wxWindow *parent,
8b9518ee 154 wxWindowID id,
88310e2e
VZ
155 const wxPoint& pos,
156 const wxSize& size,
8b9518ee 157 long style,
88310e2e
VZ
158 const wxString& name)
159{
160 Init();
161
162 Create(parent, id, pos, size, style, name);
163}
164
165// Create() function
166bool wxNotebook::Create(wxWindow *parent,
8b9518ee 167 wxWindowID id,
88310e2e
VZ
168 const wxPoint& pos,
169 const wxSize& size,
8b9518ee 170 long style,
88310e2e
VZ
171 const wxString& name)
172{
04eb05b0
JS
173 // Does ComCtl32 support non-top tabs?
174 int verComCtl32 = wxApp::GetComCtl32Version();
175 if ( verComCtl32 < 470 || verComCtl32 >= 600 )
176 {
177 if (style & wxNB_BOTTOM)
178 style &= ~wxNB_BOTTOM;
179
180 if (style & wxNB_LEFT)
181 style &= ~wxNB_LEFT;
182
183 if (style & wxNB_RIGHT)
184 style &= ~wxNB_RIGHT;
185 }
186
6dd16e4f
VZ
187 if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL,
188 wxDefaultValidator, name) )
0df3fbd7 189 return FALSE;
88310e2e 190
fda7962d 191 if ( !MSWCreateControl(WC_TABCONTROL, wxEmptyString, pos, size) )
0df3fbd7 192 return FALSE;
907f37b3 193
0df3fbd7
VZ
194 SetBackgroundColour(wxColour(::GetSysColor(COLOR_BTNFACE)));
195
196 return TRUE;
197}
198
199WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const
200{
201 WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle);
202
203 tabStyle |= WS_TABSTOP | TCS_TABS;
204
2b5f62a0 205 if ( style & wxNB_MULTILINE )
0df3fbd7
VZ
206 tabStyle |= TCS_MULTILINE;
207 if ( style & wxNB_FIXEDWIDTH )
208 tabStyle |= TCS_FIXEDWIDTH;
209
210 if ( style & wxNB_BOTTOM )
211 tabStyle |= TCS_RIGHT;
212 else if ( style & wxNB_LEFT )
213 tabStyle |= TCS_VERTICAL;
214 else if ( style & wxNB_RIGHT )
215 tabStyle |= TCS_VERTICAL | TCS_RIGHT;
216
217 // ex style
218 if ( exstyle )
219 {
220 // note that we never want to have the default WS_EX_CLIENTEDGE style
221 // as it looks too ugly for the notebooks
222 *exstyle = 0;
223 }
224
225 return tabStyle;
88310e2e
VZ
226}
227
88310e2e
VZ
228// ----------------------------------------------------------------------------
229// wxNotebook accessors
230// ----------------------------------------------------------------------------
07b8d7ec 231
88310e2e
VZ
232int wxNotebook::GetPageCount() const
233{
234 // consistency check
1e6feb95 235 wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) );
88310e2e 236
1e6feb95 237 return m_pages.Count();
88310e2e
VZ
238}
239
240int wxNotebook::GetRowCount() const
241{
242 return TabCtrl_GetRowCount(m_hwnd);
243}
244
245int wxNotebook::SetSelection(int nPage)
246{
223d09f6 247 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
88310e2e 248
2b5f62a0
VZ
249 if ( nPage != m_nSelection )
250 {
251 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
252 event.SetSelection(nPage);
253 event.SetOldSelection(m_nSelection);
254 event.SetEventObject(this);
255 if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
256 {
257 // program allows the page change
258 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
259 (void)GetEventHandler()->ProcessEvent(event);
260
261 TabCtrl_SetCurSel(m_hwnd, nPage);
262 }
263 }
88310e2e 264
2b5f62a0 265 return m_nSelection;
88310e2e
VZ
266}
267
88310e2e
VZ
268bool wxNotebook::SetPageText(int nPage, const wxString& strText)
269{
223d09f6 270 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
88310e2e
VZ
271
272 TC_ITEM tcItem;
273 tcItem.mask = TCIF_TEXT;
837e5743 274 tcItem.pszText = (wxChar *)strText.c_str();
88310e2e
VZ
275
276 return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
277}
278
279wxString wxNotebook::GetPageText(int nPage) const
280{
fda7962d 281 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxEmptyString, wxT("notebook page out of range") );
88310e2e 282
837e5743 283 wxChar buf[256];
88310e2e
VZ
284 TC_ITEM tcItem;
285 tcItem.mask = TCIF_TEXT;
286 tcItem.pszText = buf;
287 tcItem.cchTextMax = WXSIZEOF(buf);
288
289 wxString str;
290 if ( TabCtrl_GetItem(m_hwnd, nPage, &tcItem) )
291 str = tcItem.pszText;
292
293 return str;
294}
295
296int wxNotebook::GetPageImage(int nPage) const
297{
223d09f6 298 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
88310e2e
VZ
299
300 TC_ITEM tcItem;
301 tcItem.mask = TCIF_IMAGE;
302
303 return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1;
304}
305
306bool wxNotebook::SetPageImage(int nPage, int nImage)
307{
223d09f6 308 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
88310e2e
VZ
309
310 TC_ITEM tcItem;
311 tcItem.mask = TCIF_IMAGE;
312 tcItem.iImage = nImage;
313
314 return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
315}
316
317void wxNotebook::SetImageList(wxImageList* imageList)
907f37b3 318{
07b8d7ec
VZ
319 wxNotebookBase::SetImageList(imageList);
320
321 if ( imageList )
1e6feb95 322 {
07b8d7ec 323 TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST());
1e6feb95 324 }
b656febd
VS
325}
326
d9506e77
VZ
327// ----------------------------------------------------------------------------
328// wxNotebook size settings
329// ----------------------------------------------------------------------------
330
331void wxNotebook::SetPageSize(const wxSize& size)
332{
333 // transform the page size into the notebook size
334 RECT rc;
335 rc.left =
336 rc.top = 0;
337 rc.right = size.x;
338 rc.bottom = size.y;
339
340 TabCtrl_AdjustRect(GetHwnd(), TRUE, &rc);
341
342 // and now set it
343 SetSize(rc.right - rc.left, rc.bottom - rc.top);
344}
345
346void wxNotebook::SetPadding(const wxSize& padding)
347{
348 TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y);
349}
42e69d6b
VZ
350
351// Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
352// style.
353void wxNotebook::SetTabSize(const wxSize& sz)
354{
355 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y));
356}
357
2ce7af35
JS
358wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
359{
360 wxSize sizeTotal = sizePage;
361
362 // We need to make getting tab size part of the wxWindows API.
363 wxSize tabSize(0, 0);
364 if (GetPageCount() > 0)
365 {
366 RECT rect;
367 TabCtrl_GetItemRect((HWND) GetHWND(), 0, & rect);
368 tabSize.x = rect.right - rect.left;
369 tabSize.y = rect.bottom - rect.top;
370 }
371 if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
372 {
373 sizeTotal.x += tabSize.x + 7;
374 sizeTotal.y += 7;
375 }
376 else
377 {
378 sizeTotal.x += 7;
379 sizeTotal.y += tabSize.y + 7;
380 }
381
382 return sizeTotal;
383}
384
2015f2b3
VZ
385void wxNotebook::AdjustPageSize(wxNotebookPage *page)
386{
387 wxCHECK_RET( page, _T("NULL page in wxNotebook::AdjustPageSize") );
388
389 RECT rc;
390 rc.left =
391 rc.top = 0;
392
393 // get the page size from the notebook size
394 GetSize((int *)&rc.right, (int *)&rc.bottom);
395 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
396
397 page->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
398}
399
88310e2e
VZ
400// ----------------------------------------------------------------------------
401// wxNotebook operations
402// ----------------------------------------------------------------------------
403
621793f4 404// remove one page from the notebook, without deleting
1e6feb95 405wxNotebookPage *wxNotebook::DoRemovePage(int nPage)
621793f4 406{
df7145da
VZ
407 wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage);
408 if ( !pageRemoved )
409 return NULL;
621793f4 410
df7145da 411 TabCtrl_DeleteItem(m_hwnd, nPage);
621793f4 412
df7145da
VZ
413 if ( m_pages.IsEmpty() )
414 {
415 // no selection any more, the notebook becamse empty
416 m_nSelection = -1;
417 }
418 else // notebook still not empty
419 {
43a997b6
VZ
420 // change the selected page if it was deleted or became invalid
421 int selNew;
df7145da
VZ
422 if ( m_nSelection == GetPageCount() )
423 {
43a997b6
VZ
424 // last page deleted, make the new last page the new selection
425 selNew = m_nSelection - 1;
df7145da 426 }
43a997b6
VZ
427 else if ( nPage <= m_nSelection )
428 {
429 // we must show another page, even if it has the same index
430 selNew = m_nSelection;
431 }
432 else // nothing changes for the currently selected page
433 {
434 selNew = -1;
df7145da 435
43a997b6
VZ
436 // we still must refresh the current page: this needs to be done
437 // for some unknown reason if the tab control shows the up-down
438 // control (i.e. when there are too many pages) -- otherwise after
439 // deleting a page nothing at all is shown
68d31398
JS
440 if (m_nSelection >= 0)
441 m_pages[m_nSelection]->Refresh();
43a997b6
VZ
442 }
443
444 if ( selNew != -1 )
445 {
446 // m_nSelection must be always valid so reset it before calling
447 // SetSelection()
448 m_nSelection = -1;
449 SetSelection(selNew);
450 }
df7145da 451 }
47f12f58 452
df7145da 453 return pageRemoved;
621793f4
JS
454}
455
88310e2e
VZ
456// remove all pages
457bool wxNotebook::DeleteAllPages()
458{
88310e2e
VZ
459 int nPageCount = GetPageCount();
460 int nPage;
461 for ( nPage = 0; nPage < nPageCount; nPage++ )
1e6feb95 462 delete m_pages[nPage];
88310e2e 463
1e6feb95 464 m_pages.Clear();
88310e2e 465
907f37b3
VZ
466 TabCtrl_DeleteAllItems(m_hwnd);
467
47f12f58
JS
468 m_nSelection = -1;
469
88310e2e
VZ
470 return TRUE;
471}
472
88310e2e
VZ
473// same as AddPage() but does it at given position
474bool wxNotebook::InsertPage(int nPage,
475 wxNotebookPage *pPage,
476 const wxString& strText,
477 bool bSelect,
478 int imageId)
479{
22f3361e
VZ
480 wxCHECK_MSG( pPage != NULL, FALSE, _T("NULL page in wxNotebook::InsertPage") );
481 wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE,
482 _T("invalid index in wxNotebook::InsertPage") );
88310e2e 483
efa14cf2
VZ
484 wxASSERT_MSG( pPage->GetParent() == this,
485 _T("notebook pages must have notebook as parent") );
43427087 486
85b43fbf 487#if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO
c02e5a31
JS
488 static bool g_TestedForTheme = FALSE;
489 static bool g_UseTheme = FALSE;
490 if (!g_TestedForTheme)
491 {
492 int commCtrlVersion = wxTheApp->GetComCtl32Version() ;
493
494 g_UseTheme = (commCtrlVersion >= 600);
495 g_TestedForTheme = TRUE;
496 }
497
85b43fbf
JS
498 // Automatically apply the theme background,
499 // changing the colour of the panel to match the
500 // tab page colour. This won't work well with all
501 // themes but it's a start.
c02e5a31 502 if (g_UseTheme && wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel)))
85b43fbf
JS
503 {
504 ApplyThemeBackground(pPage, GetThemeBackgroundColour());
505 }
506#endif
507
22f3361e
VZ
508 // add a new tab to the control
509 // ----------------------------
58a8ab88 510
22f3361e
VZ
511 // init all fields to 0
512 TC_ITEM tcItem;
513 wxZeroMemory(tcItem);
58a8ab88 514
22f3361e
VZ
515 // set the image, if any
516 if ( imageId != -1 )
517 {
518 tcItem.mask |= TCIF_IMAGE;
519 tcItem.iImage = imageId;
520 }
88310e2e 521
22f3361e
VZ
522 // and the text
523 if ( !strText.IsEmpty() )
524 {
525 tcItem.mask |= TCIF_TEXT;
526 tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
527 }
43427087 528
22f3361e
VZ
529 // fit the notebook page to the tab control's display area: this should be
530 // done before adding it to the notebook or TabCtrl_InsertItem() will
531 // change the notebooks size itself!
2015f2b3 532 AdjustPageSize(pPage);
43427087 533
22f3361e 534 // finally do insert it
2015f2b3
VZ
535 if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 )
536 {
22f3361e 537 wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
88310e2e 538
22f3361e
VZ
539 return FALSE;
540 }
88310e2e 541
22f3361e
VZ
542 // succeeded: save the pointer to the page
543 m_pages.Insert(pPage, nPage);
42e69d6b 544
2015f2b3
VZ
545 // for the first page (only) we need to adjust the size again because the
546 // notebook size changed: the tabs which hadn't been there before are now
547 // shown
548 if ( m_pages.GetCount() == 1 )
549 {
550 AdjustPageSize(pPage);
551 }
552
22f3361e
VZ
553 // hide the page: unless it is selected, it shouldn't be shown (and if it
554 // is selected it will be shown later)
555 HWND hwnd = GetWinHwnd(pPage);
556 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
0398b1d6 557
22f3361e
VZ
558 // this updates internal flag too -- otherwise it would get out of sync
559 // with the real state
560 pPage->Show(FALSE);
43427087 561
96d37807 562
22f3361e
VZ
563 // now deal with the selection
564 // ---------------------------
565
566 // if the inserted page is before the selected one, we must update the
567 // index of the selected page
568 if ( nPage <= m_nSelection )
569 {
570 // one extra page added
571 m_nSelection++;
572 }
573
574 // some page should be selected: either this one or the first one if there
575 // is still no selection
576 int selNew = -1;
577 if ( bSelect )
578 selNew = nPage;
579 else if ( m_nSelection == -1 )
580 selNew = 0;
581
582 if ( selNew != -1 )
583 SetSelection(selNew);
584
585 return TRUE;
88310e2e
VZ
586}
587
e450aa69 588int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
ef094fa0
JS
589{
590 TC_HITTESTINFO hitTestInfo;
591 hitTestInfo.pt.x = pt.x;
592 hitTestInfo.pt.y = pt.y;
e450aa69 593 int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo);
ef094fa0 594
e450aa69
VZ
595 if ( flags )
596 {
597 *flags = 0;
598
599 if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
600 *flags |= wxNB_HITTEST_NOWHERE;
601 if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM)
602 *flags |= wxNB_HITTEST_ONITEM;
603 if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
604 *flags |= wxNB_HITTEST_ONICON;
605 if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
606 *flags |= wxNB_HITTEST_ONLABEL;
607 }
ef094fa0
JS
608
609 return item;
610}
611
e450aa69 612
88310e2e
VZ
613// ----------------------------------------------------------------------------
614// wxNotebook callbacks
615// ----------------------------------------------------------------------------
616
9026ad85 617void wxNotebook::OnSize(wxSizeEvent& event)
88310e2e 618{
b5c3b538
VZ
619 // fit the notebook page to the tab control's display area
620 RECT rc;
621 rc.left = rc.top = 0;
622 GetSize((int *)&rc.right, (int *)&rc.bottom);
623
624 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
4b7f2165
VZ
625
626 int width = rc.right - rc.left,
627 height = rc.bottom - rc.top;
1e6feb95 628 size_t nCount = m_pages.Count();
c86f1403 629 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
1e6feb95 630 wxNotebookPage *pPage = m_pages[nPage];
4b7f2165 631 pPage->SetSize(rc.left, rc.top, width, height);
b5c3b538
VZ
632 }
633
88310e2e
VZ
634 event.Skip();
635}
636
637void wxNotebook::OnSelChange(wxNotebookEvent& event)
638{
639 // is it our tab control?
640 if ( event.GetEventObject() == this )
5d1d2d46 641 {
5d1d2d46
VZ
642 int sel = event.GetOldSelection();
643 if ( sel != -1 )
1e6feb95 644 m_pages[sel]->Show(FALSE);
0398b1d6 645
5d1d2d46
VZ
646 sel = event.GetSelection();
647 if ( sel != -1 )
648 {
1e6feb95 649 wxNotebookPage *pPage = m_pages[sel];
5d1d2d46
VZ
650 pPage->Show(TRUE);
651 pPage->SetFocus();
652 }
0398b1d6 653
5d1d2d46
VZ
654 m_nSelection = sel;
655 }
88310e2e
VZ
656
657 // we want to give others a chance to process this message as well
658 event.Skip();
659}
660
661void wxNotebook::OnSetFocus(wxFocusEvent& event)
662{
d9506e77
VZ
663 // this function is only called when the focus is explicitly set (i.e. from
664 // the program) to the notebook - in this case we don't need the
665 // complicated OnNavigationKey() logic because the programmer knows better
666 // what [s]he wants
88310e2e 667
d9506e77
VZ
668 // set focus to the currently selected page if any
669 if ( m_nSelection != -1 )
1e6feb95 670 m_pages[m_nSelection]->SetFocus();
d9506e77
VZ
671
672 event.Skip();
88310e2e
VZ
673}
674
675void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
676{
d9506e77
VZ
677 if ( event.IsWindowChange() ) {
678 // change pages
679 AdvanceSelection(event.GetDirection());
680 }
681 else {
682 // we get this event in 2 cases
683 //
684 // a) one of our pages might have generated it because the user TABbed
685 // out from it in which case we should propagate the event upwards and
686 // our parent will take care of setting the focus to prev/next sibling
687 //
688 // or
689 //
690 // b) the parent panel wants to give the focus to us so that we
691 // forward it to our selected page. We can't deal with this in
692 // OnSetFocus() because we don't know which direction the focus came
693 // from in this case and so can't choose between setting the focus to
694 // first or last panel child
d9506e77 695 wxWindow *parent = GetParent();
fc10daf3
MB
696 // the cast is here to fic a GCC ICE
697 if ( ((wxWindow*)event.GetEventObject()) == parent )
d9506e77
VZ
698 {
699 // no, it doesn't come from child, case (b): forward to a page
700 if ( m_nSelection != -1 )
701 {
702 // so that the page knows that the event comes from it's parent
703 // and is being propagated downwards
704 event.SetEventObject(this);
705
1e6feb95 706 wxWindow *page = m_pages[m_nSelection];
d9506e77
VZ
707 if ( !page->GetEventHandler()->ProcessEvent(event) )
708 {
709 page->SetFocus();
710 }
711 //else: page manages focus inside it itself
712 }
713 else
714 {
715 // we have no pages - still have to give focus to _something_
716 SetFocus();
717 }
718 }
719 else
720 {
721 // it comes from our child, case (a), pass to the parent
722 if ( parent ) {
723 event.SetCurrentFocus(this);
724 parent->GetEventHandler()->ProcessEvent(event);
725 }
726 }
88310e2e 727 }
88310e2e
VZ
728}
729
730// ----------------------------------------------------------------------------
731// wxNotebook base class virtuals
732// ----------------------------------------------------------------------------
b5c3b538 733
0b481c72
VZ
734#if wxUSE_CONSTRAINTS
735
b5c3b538
VZ
736// override these 2 functions to do nothing: everything is done in OnSize
737
4b7f2165 738void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
b5c3b538
VZ
739{
740 // don't set the sizes of the pages - their correct size is not yet known
741 wxControl::SetConstraintSizes(FALSE);
742}
743
4b7f2165 744bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
b5c3b538
VZ
745{
746 return TRUE;
747}
748
0b481c72
VZ
749#endif // wxUSE_CONSTRAINTS
750
0df3fbd7
VZ
751// ----------------------------------------------------------------------------
752// wxNotebook Windows message handlers
753// ----------------------------------------------------------------------------
754
755bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode,
756 WXWORD pos, WXHWND control)
757{
758 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
759 // up-down control
760 if ( control )
761 return FALSE;
762
763 return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control);
764}
765
a23fd0e1 766bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
88310e2e 767{
93a19f17 768 wxNotebookEvent event(wxEVT_NULL, m_windowId);
88310e2e
VZ
769
770 NMHDR* hdr = (NMHDR *)lParam;
771 switch ( hdr->code ) {
772 case TCN_SELCHANGE:
773 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
774 break;
775
776 case TCN_SELCHANGING:
777 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING);
778 break;
779
fd3f686c 780 default:
a23fd0e1 781 return wxControl::MSWOnNotify(idCtrl, lParam, result);
88310e2e
VZ
782 }
783
93a19f17
VZ
784 event.SetSelection(TabCtrl_GetCurSel(m_hwnd));
785 event.SetOldSelection(m_nSelection);
88310e2e 786 event.SetEventObject(this);
a23fd0e1 787 event.SetInt(idCtrl);
88310e2e 788
fd3f686c
VZ
789 bool processed = GetEventHandler()->ProcessEvent(event);
790 *result = !event.IsAllowed();
791 return processed;
88310e2e
VZ
792}
793
85b43fbf
JS
794// Windows only: attempts to get colour for UX theme page background
795wxColour wxNotebook::GetThemeBackgroundColour()
796{
797#if wxUSE_UXTHEME
798 if (wxUxThemeEngine::Get())
799 {
2142d7ba 800 wxUxThemeHandle hTheme(this, L"TAB");
85b43fbf
JS
801 if (hTheme)
802 {
803 // This is total guesswork.
804 // See PlatformSDK\Include\Tmschema.h for values
805 COLORREF themeColor;
2142d7ba
VZ
806 wxUxThemeEngine::Get()->GetThemeColor
807 (
808 hTheme,
809 10 /* TABP_BODY */,
810 1 /* NORMAL */,
811 3821, /* FILLCOLORHINT */
812 & themeColor
813 );
85b43fbf
JS
814
815 wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor));
816 return colour;
817 }
818 }
2142d7ba
VZ
819#endif // wxUSE_UXTHEME
820
85b43fbf
JS
821 return GetBackgroundColour();
822}
823
824// Windows only: attempts to apply the UX theme page background to this page
825void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& colour)
826{
827#if wxUSE_UXTHEME
828 // Don't set the background for buttons since this will
829 // switch it into ownerdraw mode
830 if (window->IsKindOf(CLASSINFO(wxButton)) && !window->IsKindOf(CLASSINFO(wxBitmapButton)))
831 // This is essential, otherwise you'll see dark grey
832 // corners in the buttons.
833 ((wxButton*)window)->wxControl::SetBackgroundColour(colour);
834 else if (window->IsKindOf(CLASSINFO(wxStaticText)) ||
835 window->IsKindOf(CLASSINFO(wxStaticBox)) ||
836 window->IsKindOf(CLASSINFO(wxStaticLine)) ||
837 window->IsKindOf(CLASSINFO(wxRadioButton)) ||
838 window->IsKindOf(CLASSINFO(wxRadioBox)) ||
839 window->IsKindOf(CLASSINFO(wxCheckBox)) ||
840 window->IsKindOf(CLASSINFO(wxBitmapButton)) ||
841 window->IsKindOf(CLASSINFO(wxSlider)) ||
842 window->IsKindOf(CLASSINFO(wxPanel)) ||
843 (window->IsKindOf(CLASSINFO(wxNotebook)) && (window != this)) ||
844 window->IsKindOf(CLASSINFO(wxScrolledWindow))
845 )
846 {
847 window->SetBackgroundColour(colour);
848 }
849
fc10daf3 850 for ( wxWindowList::compatibility_iterator node = window->GetChildren().GetFirst(); node; node = node->GetNext() )
85b43fbf
JS
851 {
852 wxWindow *child = node->GetData();
853 ApplyThemeBackground(child, colour);
854 }
fc7a2a60
VZ
855#else
856 window;
857 colour;
85b43fbf
JS
858#endif
859}
860
c02e5a31
JS
861long wxNotebook::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
862{
863 static bool g_TestedForTheme = FALSE;
864 static bool g_UseTheme = FALSE;
865 switch ( nMsg )
866 {
867 case WM_ERASEBKGND:
868 {
869 if (!g_TestedForTheme)
870 {
871 int commCtrlVersion = wxTheApp->GetComCtl32Version() ;
872
873 g_UseTheme = (commCtrlVersion >= 600);
874 g_TestedForTheme = TRUE;
875 }
876
877 // If using XP themes, it seems we can get away
878 // with not drawing a background, which reduces flicker.
879 if (g_UseTheme)
880 return TRUE;
881 }
882 }
883
884 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
885}
886
887
1e6feb95 888#endif // wxUSE_NOTEBOOK