]> git.saurik.com Git - wxWidgets.git/blame - src/msw/notebook.cpp
Suppressed some flicker in standard wxToolBar
[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
JS
487#if wxUSE_UXTHEME && wxUSE_UXTHEME_AUTO
488 // Automatically apply the theme background,
489 // changing the colour of the panel to match the
490 // tab page colour. This won't work well with all
491 // themes but it's a start.
492 if (wxUxThemeEngine::Get() && pPage->IsKindOf(CLASSINFO(wxPanel)))
493 {
494 ApplyThemeBackground(pPage, GetThemeBackgroundColour());
495 }
496#endif
497
22f3361e
VZ
498 // add a new tab to the control
499 // ----------------------------
58a8ab88 500
22f3361e
VZ
501 // init all fields to 0
502 TC_ITEM tcItem;
503 wxZeroMemory(tcItem);
58a8ab88 504
22f3361e
VZ
505 // set the image, if any
506 if ( imageId != -1 )
507 {
508 tcItem.mask |= TCIF_IMAGE;
509 tcItem.iImage = imageId;
510 }
88310e2e 511
22f3361e
VZ
512 // and the text
513 if ( !strText.IsEmpty() )
514 {
515 tcItem.mask |= TCIF_TEXT;
516 tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
517 }
43427087 518
22f3361e
VZ
519 // fit the notebook page to the tab control's display area: this should be
520 // done before adding it to the notebook or TabCtrl_InsertItem() will
521 // change the notebooks size itself!
2015f2b3 522 AdjustPageSize(pPage);
43427087 523
22f3361e 524 // finally do insert it
2015f2b3
VZ
525 if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 )
526 {
22f3361e 527 wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
88310e2e 528
22f3361e
VZ
529 return FALSE;
530 }
88310e2e 531
22f3361e
VZ
532 // succeeded: save the pointer to the page
533 m_pages.Insert(pPage, nPage);
42e69d6b 534
2015f2b3
VZ
535 // for the first page (only) we need to adjust the size again because the
536 // notebook size changed: the tabs which hadn't been there before are now
537 // shown
538 if ( m_pages.GetCount() == 1 )
539 {
540 AdjustPageSize(pPage);
541 }
542
22f3361e
VZ
543 // hide the page: unless it is selected, it shouldn't be shown (and if it
544 // is selected it will be shown later)
545 HWND hwnd = GetWinHwnd(pPage);
546 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
0398b1d6 547
22f3361e
VZ
548 // this updates internal flag too -- otherwise it would get out of sync
549 // with the real state
550 pPage->Show(FALSE);
43427087 551
96d37807 552
22f3361e
VZ
553 // now deal with the selection
554 // ---------------------------
555
556 // if the inserted page is before the selected one, we must update the
557 // index of the selected page
558 if ( nPage <= m_nSelection )
559 {
560 // one extra page added
561 m_nSelection++;
562 }
563
564 // some page should be selected: either this one or the first one if there
565 // is still no selection
566 int selNew = -1;
567 if ( bSelect )
568 selNew = nPage;
569 else if ( m_nSelection == -1 )
570 selNew = 0;
571
572 if ( selNew != -1 )
573 SetSelection(selNew);
574
575 return TRUE;
88310e2e
VZ
576}
577
e450aa69 578int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
ef094fa0
JS
579{
580 TC_HITTESTINFO hitTestInfo;
581 hitTestInfo.pt.x = pt.x;
582 hitTestInfo.pt.y = pt.y;
e450aa69 583 int item = TabCtrl_HitTest(GetHwnd(), &hitTestInfo);
ef094fa0 584
e450aa69
VZ
585 if ( flags )
586 {
587 *flags = 0;
588
589 if ((hitTestInfo.flags & TCHT_NOWHERE) == TCHT_NOWHERE)
590 *flags |= wxNB_HITTEST_NOWHERE;
591 if ((hitTestInfo.flags & TCHT_ONITEM) == TCHT_ONITEM)
592 *flags |= wxNB_HITTEST_ONITEM;
593 if ((hitTestInfo.flags & TCHT_ONITEMICON) == TCHT_ONITEMICON)
594 *flags |= wxNB_HITTEST_ONICON;
595 if ((hitTestInfo.flags & TCHT_ONITEMLABEL) == TCHT_ONITEMLABEL)
596 *flags |= wxNB_HITTEST_ONLABEL;
597 }
ef094fa0
JS
598
599 return item;
600}
601
e450aa69 602
88310e2e
VZ
603// ----------------------------------------------------------------------------
604// wxNotebook callbacks
605// ----------------------------------------------------------------------------
606
9026ad85 607void wxNotebook::OnSize(wxSizeEvent& event)
88310e2e 608{
b5c3b538
VZ
609 // fit the notebook page to the tab control's display area
610 RECT rc;
611 rc.left = rc.top = 0;
612 GetSize((int *)&rc.right, (int *)&rc.bottom);
613
614 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
4b7f2165
VZ
615
616 int width = rc.right - rc.left,
617 height = rc.bottom - rc.top;
1e6feb95 618 size_t nCount = m_pages.Count();
c86f1403 619 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
1e6feb95 620 wxNotebookPage *pPage = m_pages[nPage];
4b7f2165 621 pPage->SetSize(rc.left, rc.top, width, height);
b5c3b538
VZ
622 }
623
88310e2e
VZ
624 event.Skip();
625}
626
627void wxNotebook::OnSelChange(wxNotebookEvent& event)
628{
629 // is it our tab control?
630 if ( event.GetEventObject() == this )
5d1d2d46 631 {
5d1d2d46
VZ
632 int sel = event.GetOldSelection();
633 if ( sel != -1 )
1e6feb95 634 m_pages[sel]->Show(FALSE);
0398b1d6 635
5d1d2d46
VZ
636 sel = event.GetSelection();
637 if ( sel != -1 )
638 {
1e6feb95 639 wxNotebookPage *pPage = m_pages[sel];
5d1d2d46
VZ
640 pPage->Show(TRUE);
641 pPage->SetFocus();
642 }
0398b1d6 643
5d1d2d46
VZ
644 m_nSelection = sel;
645 }
88310e2e
VZ
646
647 // we want to give others a chance to process this message as well
648 event.Skip();
649}
650
651void wxNotebook::OnSetFocus(wxFocusEvent& event)
652{
d9506e77
VZ
653 // this function is only called when the focus is explicitly set (i.e. from
654 // the program) to the notebook - in this case we don't need the
655 // complicated OnNavigationKey() logic because the programmer knows better
656 // what [s]he wants
88310e2e 657
d9506e77
VZ
658 // set focus to the currently selected page if any
659 if ( m_nSelection != -1 )
1e6feb95 660 m_pages[m_nSelection]->SetFocus();
d9506e77
VZ
661
662 event.Skip();
88310e2e
VZ
663}
664
665void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
666{
d9506e77
VZ
667 if ( event.IsWindowChange() ) {
668 // change pages
669 AdvanceSelection(event.GetDirection());
670 }
671 else {
672 // we get this event in 2 cases
673 //
674 // a) one of our pages might have generated it because the user TABbed
675 // out from it in which case we should propagate the event upwards and
676 // our parent will take care of setting the focus to prev/next sibling
677 //
678 // or
679 //
680 // b) the parent panel wants to give the focus to us so that we
681 // forward it to our selected page. We can't deal with this in
682 // OnSetFocus() because we don't know which direction the focus came
683 // from in this case and so can't choose between setting the focus to
684 // first or last panel child
d9506e77 685 wxWindow *parent = GetParent();
fc10daf3
MB
686 // the cast is here to fic a GCC ICE
687 if ( ((wxWindow*)event.GetEventObject()) == parent )
d9506e77
VZ
688 {
689 // no, it doesn't come from child, case (b): forward to a page
690 if ( m_nSelection != -1 )
691 {
692 // so that the page knows that the event comes from it's parent
693 // and is being propagated downwards
694 event.SetEventObject(this);
695
1e6feb95 696 wxWindow *page = m_pages[m_nSelection];
d9506e77
VZ
697 if ( !page->GetEventHandler()->ProcessEvent(event) )
698 {
699 page->SetFocus();
700 }
701 //else: page manages focus inside it itself
702 }
703 else
704 {
705 // we have no pages - still have to give focus to _something_
706 SetFocus();
707 }
708 }
709 else
710 {
711 // it comes from our child, case (a), pass to the parent
712 if ( parent ) {
713 event.SetCurrentFocus(this);
714 parent->GetEventHandler()->ProcessEvent(event);
715 }
716 }
88310e2e 717 }
88310e2e
VZ
718}
719
720// ----------------------------------------------------------------------------
721// wxNotebook base class virtuals
722// ----------------------------------------------------------------------------
b5c3b538 723
0b481c72
VZ
724#if wxUSE_CONSTRAINTS
725
b5c3b538
VZ
726// override these 2 functions to do nothing: everything is done in OnSize
727
4b7f2165 728void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
b5c3b538
VZ
729{
730 // don't set the sizes of the pages - their correct size is not yet known
731 wxControl::SetConstraintSizes(FALSE);
732}
733
4b7f2165 734bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
b5c3b538
VZ
735{
736 return TRUE;
737}
738
0b481c72
VZ
739#endif // wxUSE_CONSTRAINTS
740
0df3fbd7
VZ
741// ----------------------------------------------------------------------------
742// wxNotebook Windows message handlers
743// ----------------------------------------------------------------------------
744
745bool wxNotebook::MSWOnScroll(int orientation, WXWORD nSBCode,
746 WXWORD pos, WXHWND control)
747{
748 // don't generate EVT_SCROLLWIN events for the WM_SCROLLs coming from the
749 // up-down control
750 if ( control )
751 return FALSE;
752
753 return wxNotebookBase::MSWOnScroll(orientation, nSBCode, pos, control);
754}
755
a23fd0e1 756bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
88310e2e 757{
93a19f17 758 wxNotebookEvent event(wxEVT_NULL, m_windowId);
88310e2e
VZ
759
760 NMHDR* hdr = (NMHDR *)lParam;
761 switch ( hdr->code ) {
762 case TCN_SELCHANGE:
763 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
764 break;
765
766 case TCN_SELCHANGING:
767 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING);
768 break;
769
fd3f686c 770 default:
a23fd0e1 771 return wxControl::MSWOnNotify(idCtrl, lParam, result);
88310e2e
VZ
772 }
773
93a19f17
VZ
774 event.SetSelection(TabCtrl_GetCurSel(m_hwnd));
775 event.SetOldSelection(m_nSelection);
88310e2e 776 event.SetEventObject(this);
a23fd0e1 777 event.SetInt(idCtrl);
88310e2e 778
fd3f686c
VZ
779 bool processed = GetEventHandler()->ProcessEvent(event);
780 *result = !event.IsAllowed();
781 return processed;
88310e2e
VZ
782}
783
85b43fbf
JS
784// Windows only: attempts to get colour for UX theme page background
785wxColour wxNotebook::GetThemeBackgroundColour()
786{
787#if wxUSE_UXTHEME
788 if (wxUxThemeEngine::Get())
789 {
2142d7ba 790 wxUxThemeHandle hTheme(this, L"TAB");
85b43fbf
JS
791 if (hTheme)
792 {
793 // This is total guesswork.
794 // See PlatformSDK\Include\Tmschema.h for values
795 COLORREF themeColor;
2142d7ba
VZ
796 wxUxThemeEngine::Get()->GetThemeColor
797 (
798 hTheme,
799 10 /* TABP_BODY */,
800 1 /* NORMAL */,
801 3821, /* FILLCOLORHINT */
802 & themeColor
803 );
85b43fbf
JS
804
805 wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor));
806 return colour;
807 }
808 }
2142d7ba
VZ
809#endif // wxUSE_UXTHEME
810
85b43fbf
JS
811 return GetBackgroundColour();
812}
813
814// Windows only: attempts to apply the UX theme page background to this page
815void wxNotebook::ApplyThemeBackground(wxWindow* window, const wxColour& colour)
816{
817#if wxUSE_UXTHEME
818 // Don't set the background for buttons since this will
819 // switch it into ownerdraw mode
820 if (window->IsKindOf(CLASSINFO(wxButton)) && !window->IsKindOf(CLASSINFO(wxBitmapButton)))
821 // This is essential, otherwise you'll see dark grey
822 // corners in the buttons.
823 ((wxButton*)window)->wxControl::SetBackgroundColour(colour);
824 else if (window->IsKindOf(CLASSINFO(wxStaticText)) ||
825 window->IsKindOf(CLASSINFO(wxStaticBox)) ||
826 window->IsKindOf(CLASSINFO(wxStaticLine)) ||
827 window->IsKindOf(CLASSINFO(wxRadioButton)) ||
828 window->IsKindOf(CLASSINFO(wxRadioBox)) ||
829 window->IsKindOf(CLASSINFO(wxCheckBox)) ||
830 window->IsKindOf(CLASSINFO(wxBitmapButton)) ||
831 window->IsKindOf(CLASSINFO(wxSlider)) ||
832 window->IsKindOf(CLASSINFO(wxPanel)) ||
833 (window->IsKindOf(CLASSINFO(wxNotebook)) && (window != this)) ||
834 window->IsKindOf(CLASSINFO(wxScrolledWindow))
835 )
836 {
837 window->SetBackgroundColour(colour);
838 }
839
fc10daf3 840 for ( wxWindowList::compatibility_iterator node = window->GetChildren().GetFirst(); node; node = node->GetNext() )
85b43fbf
JS
841 {
842 wxWindow *child = node->GetData();
843 ApplyThemeBackground(child, colour);
844 }
fc7a2a60
VZ
845#else
846 window;
847 colour;
85b43fbf
JS
848#endif
849}
850
1e6feb95 851#endif // wxUSE_NOTEBOOK