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