]> git.saurik.com Git - wxWidgets.git/blame - src/msw/notebook.cpp
Use the black pen for the border on Windows now too.
[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>
9// Licence: wxWindows license
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"
88310e2e 35
3096bd2f 36#include "wx/msw/private.h"
88310e2e
VZ
37
38// Windows standard headers
39#ifndef __WIN95__
2432b92d 40 #error "wxNotebook is only supported Windows 95 and above"
88310e2e
VZ
41#endif //Win95
42
aaab7c01
VZ
43#include <windowsx.h> // for SetWindowFont
44
57c208c5 45#ifndef __TWIN32__
c42404a5
VZ
46 #ifdef __GNUWIN32_OLD__
47 #include "wx/msw/gnuwin32/extra.h"
48 #endif
65fd5cb0 49#endif
57c208c5 50
ae090fdb 51#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
c42404a5 52 #include <commctrl.h>
88310e2e
VZ
53#endif
54
55// ----------------------------------------------------------------------------
56// macros
57// ----------------------------------------------------------------------------
58
59// check that the page index is valid
60#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount()))
61
62// hide the ugly cast
63#define m_hwnd (HWND)GetHWND()
64
74b31181
VZ
65// ----------------------------------------------------------------------------
66// constants
67// ----------------------------------------------------------------------------
68
69// This is a work-around for missing defines in gcc-2.95 headers
70#ifndef TCS_RIGHT
71 #define TCS_RIGHT 0x0002
72#endif
73
74#ifndef TCS_VERTICAL
75 #define TCS_VERTICAL 0x0080
76#endif
77
78#ifndef TCS_BOTTOM
79 #define TCS_BOTTOM TCS_RIGHT
80#endif
81
88310e2e
VZ
82// ----------------------------------------------------------------------------
83// event table
84// ----------------------------------------------------------------------------
85
2e4df4bf
VZ
86DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
87DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
88
d9317fd4 89BEGIN_EVENT_TABLE(wxNotebook, wxControl)
88310e2e
VZ
90 EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange)
91
9026ad85 92 EVT_SIZE(wxNotebook::OnSize)
42e69d6b 93
88310e2e 94 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
42e69d6b 95
88310e2e 96 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
d9317fd4 97END_EVENT_TABLE()
88310e2e 98
d9317fd4
VZ
99IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
100IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxNotifyEvent)
88310e2e
VZ
101
102// ============================================================================
103// implementation
104// ============================================================================
105
106// ----------------------------------------------------------------------------
107// wxNotebook construction
108// ----------------------------------------------------------------------------
109
110// common part of all ctors
111void wxNotebook::Init()
112{
1e6feb95 113 m_imageList = NULL;
88310e2e
VZ
114 m_nSelection = -1;
115}
116
117// default for dynamic class
118wxNotebook::wxNotebook()
119{
120 Init();
121}
122
123// the same arguments as for wxControl
124wxNotebook::wxNotebook(wxWindow *parent,
8b9518ee 125 wxWindowID id,
88310e2e
VZ
126 const wxPoint& pos,
127 const wxSize& size,
8b9518ee 128 long style,
88310e2e
VZ
129 const wxString& name)
130{
131 Init();
132
133 Create(parent, id, pos, size, style, name);
134}
135
136// Create() function
137bool wxNotebook::Create(wxWindow *parent,
8b9518ee 138 wxWindowID id,
88310e2e
VZ
139 const wxPoint& pos,
140 const wxSize& size,
8b9518ee 141 long style,
88310e2e
VZ
142 const wxString& name)
143{
144 // base init
8d99be5f
VZ
145 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
146 return FALSE;
88310e2e
VZ
147
148 // colors and font
149 m_backgroundColour = wxColour(GetSysColor(COLOR_BTNFACE));
4b7f2165 150 m_foregroundColour = *wxBLACK;
88310e2e 151
88310e2e 152 // style
fd2daa68 153 m_windowStyle = style | wxTAB_TRAVERSAL;
88310e2e 154
d13c32e9
JS
155 long tabStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | TCS_TABS;
156
b0766406
JS
157 if ( m_windowStyle & wxCLIP_SIBLINGS )
158 tabStyle |= WS_CLIPSIBLINGS;
d13c32e9
JS
159 if (m_windowStyle & wxCLIP_CHILDREN)
160 tabStyle |= WS_CLIPCHILDREN;
88310e2e
VZ
161 if ( m_windowStyle & wxTC_MULTILINE )
162 tabStyle |= TCS_MULTILINE;
163 if ( m_windowStyle & wxBORDER )
b54e41c5 164 tabStyle |= WS_BORDER;
58a8ab88
JS
165 if (m_windowStyle & wxNB_FIXEDWIDTH)
166 tabStyle |= TCS_FIXEDWIDTH ;
7a3ac804
RS
167 if (m_windowStyle & wxNB_BOTTOM)
168 tabStyle |= TCS_RIGHT;
169 if (m_windowStyle & wxNB_LEFT)
170 tabStyle |= TCS_VERTICAL;
171 if (m_windowStyle & wxNB_RIGHT)
172 tabStyle |= TCS_VERTICAL|TCS_RIGHT;
0398b1d6 173
a6910334
VZ
174 // note that we don't want to have the default WS_EX_CLIENTEDGE style for the
175 // notebook, so explicitly specify 0 as last parameter
176 if ( !MSWCreateControl(WC_TABCONTROL, tabStyle, pos, size, _T(""), 0) )
789295bf 177 {
88310e2e
VZ
178 return FALSE;
179 }
180
27529614 181 // Not all compilers recognise SetWindowFont
789295bf
VZ
182 ::SendMessage(GetHwnd(), WM_SETFONT,
183 (WPARAM)::GetStockObject(DEFAULT_GUI_FONT), TRUE);
27529614 184
aaab7c01 185
907f37b3 186 if ( parent != NULL )
88310e2e 187 parent->AddChild(this);
907f37b3 188
88310e2e
VZ
189 return TRUE;
190}
191
88310e2e
VZ
192// ----------------------------------------------------------------------------
193// wxNotebook accessors
194// ----------------------------------------------------------------------------
07b8d7ec 195
88310e2e
VZ
196int wxNotebook::GetPageCount() const
197{
198 // consistency check
1e6feb95 199 wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) );
88310e2e 200
1e6feb95 201 return m_pages.Count();
88310e2e
VZ
202}
203
204int wxNotebook::GetRowCount() const
205{
206 return TabCtrl_GetRowCount(m_hwnd);
207}
208
209int wxNotebook::SetSelection(int nPage)
210{
223d09f6 211 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
88310e2e
VZ
212
213 ChangePage(m_nSelection, nPage);
214
215 return TabCtrl_SetCurSel(m_hwnd, nPage);
216}
217
88310e2e
VZ
218bool wxNotebook::SetPageText(int nPage, const wxString& strText)
219{
223d09f6 220 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
88310e2e
VZ
221
222 TC_ITEM tcItem;
223 tcItem.mask = TCIF_TEXT;
837e5743 224 tcItem.pszText = (wxChar *)strText.c_str();
88310e2e
VZ
225
226 return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
227}
228
229wxString wxNotebook::GetPageText(int nPage) const
230{
223d09f6 231 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") );
88310e2e 232
837e5743 233 wxChar buf[256];
88310e2e
VZ
234 TC_ITEM tcItem;
235 tcItem.mask = TCIF_TEXT;
236 tcItem.pszText = buf;
237 tcItem.cchTextMax = WXSIZEOF(buf);
238
239 wxString str;
240 if ( TabCtrl_GetItem(m_hwnd, nPage, &tcItem) )
241 str = tcItem.pszText;
242
243 return str;
244}
245
246int wxNotebook::GetPageImage(int nPage) const
247{
223d09f6 248 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
88310e2e
VZ
249
250 TC_ITEM tcItem;
251 tcItem.mask = TCIF_IMAGE;
252
253 return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1;
254}
255
256bool wxNotebook::SetPageImage(int nPage, int nImage)
257{
223d09f6 258 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
88310e2e
VZ
259
260 TC_ITEM tcItem;
261 tcItem.mask = TCIF_IMAGE;
262 tcItem.iImage = nImage;
263
264 return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
265}
266
267void wxNotebook::SetImageList(wxImageList* imageList)
907f37b3 268{
07b8d7ec
VZ
269 wxNotebookBase::SetImageList(imageList);
270
271 if ( imageList )
1e6feb95 272 {
07b8d7ec 273 TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST());
1e6feb95 274 }
b656febd
VS
275}
276
d9506e77
VZ
277// ----------------------------------------------------------------------------
278// wxNotebook size settings
279// ----------------------------------------------------------------------------
280
281void wxNotebook::SetPageSize(const wxSize& size)
282{
283 // transform the page size into the notebook size
284 RECT rc;
285 rc.left =
286 rc.top = 0;
287 rc.right = size.x;
288 rc.bottom = size.y;
289
290 TabCtrl_AdjustRect(GetHwnd(), TRUE, &rc);
291
292 // and now set it
293 SetSize(rc.right - rc.left, rc.bottom - rc.top);
294}
295
296void wxNotebook::SetPadding(const wxSize& padding)
297{
298 TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y);
299}
42e69d6b
VZ
300
301// Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
302// style.
303void wxNotebook::SetTabSize(const wxSize& sz)
304{
305 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y));
306}
307
88310e2e
VZ
308// ----------------------------------------------------------------------------
309// wxNotebook operations
310// ----------------------------------------------------------------------------
311
312// remove one page from the notebook
313bool wxNotebook::DeletePage(int nPage)
314{
223d09f6 315 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
88310e2e 316
96d37807
VZ
317 if ( m_nSelection == nPage ) {
318 // advance selection backwards - the page being deleted shouldn't be left
319 // selected
320 AdvanceSelection(FALSE);
321 }
322
88310e2e
VZ
323 TabCtrl_DeleteItem(m_hwnd, nPage);
324
1e6feb95 325 delete m_pages[nPage];
b54e41c5 326 m_pages.RemoveAt(nPage);
88310e2e 327
1e6feb95 328 if ( m_pages.IsEmpty() ) {
96d37807
VZ
329 // no selection if the notebook became empty
330 m_nSelection = -1;
331 }
9b6b5750
JS
332 else
333 m_nSelection = TabCtrl_GetCurSel(m_hwnd);
334
96d37807 335
88310e2e
VZ
336 return TRUE;
337}
338
621793f4 339// remove one page from the notebook, without deleting
1e6feb95 340wxNotebookPage *wxNotebook::DoRemovePage(int nPage)
621793f4 341{
10199e27
VZ
342 wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage);
343 if ( !pageRemoved )
344 return NULL;
621793f4
JS
345
346 TabCtrl_DeleteItem(m_hwnd, nPage);
347
1e6feb95
VZ
348 if ( m_pages.IsEmpty() )
349 m_nSelection = -1;
350 else
351 m_nSelection = TabCtrl_GetCurSel(m_hwnd);
47f12f58 352
1e6feb95 353 return pageRemoved;
621793f4
JS
354}
355
88310e2e
VZ
356// remove all pages
357bool wxNotebook::DeleteAllPages()
358{
88310e2e
VZ
359 int nPageCount = GetPageCount();
360 int nPage;
361 for ( nPage = 0; nPage < nPageCount; nPage++ )
1e6feb95 362 delete m_pages[nPage];
88310e2e 363
1e6feb95 364 m_pages.Clear();
88310e2e 365
907f37b3
VZ
366 TabCtrl_DeleteAllItems(m_hwnd);
367
47f12f58
JS
368 m_nSelection = -1;
369
88310e2e
VZ
370 return TRUE;
371}
372
373// add a page to the notebook
374bool wxNotebook::AddPage(wxNotebookPage *pPage,
375 const wxString& strText,
376 bool bSelect,
377 int imageId)
378{
379 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
380}
381
382// same as AddPage() but does it at given position
383bool wxNotebook::InsertPage(int nPage,
384 wxNotebookPage *pPage,
385 const wxString& strText,
386 bool bSelect,
387 int imageId)
388{
389 wxASSERT( pPage != NULL );
390 wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
391
43427087
VZ
392 // do add the tab to the control
393
394 // init all fields to 0
88310e2e 395 TC_ITEM tcItem;
43427087 396 memset(&tcItem, 0, sizeof(tcItem));
58a8ab88 397
43427087 398 if ( imageId != -1 )
58a8ab88
JS
399 {
400 tcItem.mask |= TCIF_IMAGE;
401 tcItem.iImage = imageId;
402 }
58a8ab88 403
43427087 404 if ( !strText.IsEmpty() )
58a8ab88 405 {
43427087
VZ
406 tcItem.mask |= TCIF_TEXT;
407 tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
58a8ab88 408 }
88310e2e
VZ
409
410 if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) {
223d09f6 411 wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
43427087 412
88310e2e
VZ
413 return FALSE;
414 }
415
43427087
VZ
416 // if the inserted page is before the selected one, we must update the
417 // index of the selected page
418 if ( nPage <= m_nSelection )
419 {
420 // one extra page added
421 m_nSelection++;
422 }
423
88310e2e 424 // save the pointer to the page
1e6feb95 425 m_pages.Insert(pPage, nPage);
88310e2e 426
88310e2e 427 // don't show pages by default (we'll need to adjust their size first)
42e69d6b 428 HWND hwnd = GetWinHwnd(pPage);
88310e2e
VZ
429 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
430
42e69d6b
VZ
431 // this updates internal flag too - otherwise it will get out of sync
432 pPage->Show(FALSE);
433
0398b1d6
RD
434 // fit the notebook page to the tab control's display area
435 RECT rc;
436 rc.left = rc.top = 0;
437 GetSize((int *)&rc.right, (int *)&rc.bottom);
438 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
439 pPage->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
0398b1d6 440
43427087
VZ
441 // some page should be selected: either this one or the first one if there is
442 // still no selection
443 int selNew = -1;
444 if ( bSelect )
445 selNew = nPage;
446 else if ( m_nSelection == -1 )
447 selNew = 0;
448
449 if ( selNew != -1 )
450 SetSelection(selNew);
96d37807 451
88310e2e
VZ
452 return TRUE;
453}
454
455// ----------------------------------------------------------------------------
456// wxNotebook callbacks
457// ----------------------------------------------------------------------------
458
9026ad85 459void wxNotebook::OnSize(wxSizeEvent& event)
88310e2e 460{
b5c3b538
VZ
461 // fit the notebook page to the tab control's display area
462 RECT rc;
463 rc.left = rc.top = 0;
464 GetSize((int *)&rc.right, (int *)&rc.bottom);
465
466 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
4b7f2165
VZ
467
468 int width = rc.right - rc.left,
469 height = rc.bottom - rc.top;
1e6feb95 470 size_t nCount = m_pages.Count();
c86f1403 471 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
1e6feb95 472 wxNotebookPage *pPage = m_pages[nPage];
4b7f2165 473 pPage->SetSize(rc.left, rc.top, width, height);
b5c3b538
VZ
474 }
475
88310e2e
VZ
476 event.Skip();
477}
478
479void wxNotebook::OnSelChange(wxNotebookEvent& event)
480{
481 // is it our tab control?
482 if ( event.GetEventObject() == this )
5d1d2d46 483 {
5d1d2d46
VZ
484 int sel = event.GetOldSelection();
485 if ( sel != -1 )
1e6feb95 486 m_pages[sel]->Show(FALSE);
0398b1d6 487
5d1d2d46
VZ
488 sel = event.GetSelection();
489 if ( sel != -1 )
490 {
1e6feb95 491 wxNotebookPage *pPage = m_pages[sel];
5d1d2d46
VZ
492 pPage->Show(TRUE);
493 pPage->SetFocus();
494 }
0398b1d6 495
5d1d2d46
VZ
496 m_nSelection = sel;
497 }
88310e2e
VZ
498
499 // we want to give others a chance to process this message as well
500 event.Skip();
501}
502
503void wxNotebook::OnSetFocus(wxFocusEvent& event)
504{
d9506e77
VZ
505 // this function is only called when the focus is explicitly set (i.e. from
506 // the program) to the notebook - in this case we don't need the
507 // complicated OnNavigationKey() logic because the programmer knows better
508 // what [s]he wants
88310e2e 509
d9506e77
VZ
510 // set focus to the currently selected page if any
511 if ( m_nSelection != -1 )
1e6feb95 512 m_pages[m_nSelection]->SetFocus();
d9506e77
VZ
513
514 event.Skip();
88310e2e
VZ
515}
516
517void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
518{
d9506e77
VZ
519 if ( event.IsWindowChange() ) {
520 // change pages
521 AdvanceSelection(event.GetDirection());
522 }
523 else {
524 // we get this event in 2 cases
525 //
526 // a) one of our pages might have generated it because the user TABbed
527 // out from it in which case we should propagate the event upwards and
528 // our parent will take care of setting the focus to prev/next sibling
529 //
530 // or
531 //
532 // b) the parent panel wants to give the focus to us so that we
533 // forward it to our selected page. We can't deal with this in
534 // OnSetFocus() because we don't know which direction the focus came
535 // from in this case and so can't choose between setting the focus to
536 // first or last panel child
537
538 wxWindow *parent = GetParent();
539 if ( event.GetEventObject() == parent )
540 {
541 // no, it doesn't come from child, case (b): forward to a page
542 if ( m_nSelection != -1 )
543 {
544 // so that the page knows that the event comes from it's parent
545 // and is being propagated downwards
546 event.SetEventObject(this);
547
1e6feb95 548 wxWindow *page = m_pages[m_nSelection];
d9506e77
VZ
549 if ( !page->GetEventHandler()->ProcessEvent(event) )
550 {
551 page->SetFocus();
552 }
553 //else: page manages focus inside it itself
554 }
555 else
556 {
557 // we have no pages - still have to give focus to _something_
558 SetFocus();
559 }
560 }
561 else
562 {
563 // it comes from our child, case (a), pass to the parent
564 if ( parent ) {
565 event.SetCurrentFocus(this);
566 parent->GetEventHandler()->ProcessEvent(event);
567 }
568 }
88310e2e 569 }
88310e2e
VZ
570}
571
572// ----------------------------------------------------------------------------
573// wxNotebook base class virtuals
574// ----------------------------------------------------------------------------
b5c3b538
VZ
575
576// override these 2 functions to do nothing: everything is done in OnSize
577
4b7f2165 578void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
b5c3b538
VZ
579{
580 // don't set the sizes of the pages - their correct size is not yet known
581 wxControl::SetConstraintSizes(FALSE);
582}
583
4b7f2165 584bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
b5c3b538
VZ
585{
586 return TRUE;
587}
588
a23fd0e1 589bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
88310e2e 590{
93a19f17 591 wxNotebookEvent event(wxEVT_NULL, m_windowId);
88310e2e
VZ
592
593 NMHDR* hdr = (NMHDR *)lParam;
594 switch ( hdr->code ) {
595 case TCN_SELCHANGE:
596 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
597 break;
598
599 case TCN_SELCHANGING:
600 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING);
601 break;
602
fd3f686c 603 default:
a23fd0e1 604 return wxControl::MSWOnNotify(idCtrl, lParam, result);
88310e2e
VZ
605 }
606
93a19f17
VZ
607 event.SetSelection(TabCtrl_GetCurSel(m_hwnd));
608 event.SetOldSelection(m_nSelection);
88310e2e 609 event.SetEventObject(this);
a23fd0e1 610 event.SetInt(idCtrl);
88310e2e 611
fd3f686c
VZ
612 bool processed = GetEventHandler()->ProcessEvent(event);
613 *result = !event.IsAllowed();
614 return processed;
88310e2e
VZ
615}
616
617// ----------------------------------------------------------------------------
618// wxNotebook helper functions
619// ----------------------------------------------------------------------------
620
43427087
VZ
621// generate the page changing and changed events, hide the currently active
622// panel and show the new one
88310e2e
VZ
623void wxNotebook::ChangePage(int nOldSel, int nSel)
624{
fd3f686c
VZ
625 // MT-FIXME should use a real semaphore
626 static bool s_bInsideChangePage = FALSE;
627
628 // when we call ProcessEvent(), our own OnSelChange() is called which calls
629 // this function - break the infinite loop
630 if ( s_bInsideChangePage )
631 return;
632
aaab7c01
VZ
633 // it's not an error (the message may be generated by the tab control itself)
634 // and it may happen - just do nothing
635 if ( nSel == nOldSel )
636 return;
88310e2e 637
fd3f686c
VZ
638 s_bInsideChangePage = TRUE;
639
640 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
641 event.SetSelection(nSel);
642 event.SetOldSelection(nOldSel);
643 event.SetEventObject(this);
1e6feb95 644 if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() )
fd3f686c
VZ
645 {
646 // program doesn't allow the page change
647 s_bInsideChangePage = FALSE;
648 return;
649 }
650
fd3f686c 651 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
1e6feb95 652 GetEventHandler()->ProcessEvent(event);
fd3f686c 653
fd3f686c 654 s_bInsideChangePage = FALSE;
88310e2e 655}
1e6feb95
VZ
656
657#endif // wxUSE_NOTEBOOK