]> git.saurik.com Git - wxWidgets.git/blame - src/msw/notebook.cpp
Replaced /'s with \'s as BCC requires \'s for path names
[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
88310e2e 174
789295bf
VZ
175 if ( !MSWCreate(GetId(), GetParent(), WC_TABCONTROL,
176 this, NULL, pos.x, pos.y, size.x, size.y,
177 tabStyle, NULL, 0) )
178 {
88310e2e
VZ
179 return FALSE;
180 }
181
27529614 182 // Not all compilers recognise SetWindowFont
789295bf
VZ
183 ::SendMessage(GetHwnd(), WM_SETFONT,
184 (WPARAM)::GetStockObject(DEFAULT_GUI_FONT), TRUE);
27529614 185
aaab7c01 186
907f37b3 187 if ( parent != NULL )
88310e2e 188 parent->AddChild(this);
907f37b3 189
88310e2e
VZ
190 SubclassWin(m_hWnd);
191
192 return TRUE;
193}
194
88310e2e
VZ
195// ----------------------------------------------------------------------------
196// wxNotebook accessors
197// ----------------------------------------------------------------------------
07b8d7ec 198
88310e2e
VZ
199int wxNotebook::GetPageCount() const
200{
201 // consistency check
1e6feb95 202 wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(m_hwnd) );
88310e2e 203
1e6feb95 204 return m_pages.Count();
88310e2e
VZ
205}
206
207int wxNotebook::GetRowCount() const
208{
209 return TabCtrl_GetRowCount(m_hwnd);
210}
211
212int wxNotebook::SetSelection(int nPage)
213{
223d09f6 214 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
88310e2e
VZ
215
216 ChangePage(m_nSelection, nPage);
217
218 return TabCtrl_SetCurSel(m_hwnd, nPage);
219}
220
88310e2e
VZ
221bool wxNotebook::SetPageText(int nPage, const wxString& strText)
222{
223d09f6 223 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
88310e2e
VZ
224
225 TC_ITEM tcItem;
226 tcItem.mask = TCIF_TEXT;
837e5743 227 tcItem.pszText = (wxChar *)strText.c_str();
88310e2e
VZ
228
229 return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
230}
231
232wxString wxNotebook::GetPageText(int nPage) const
233{
223d09f6 234 wxCHECK_MSG( IS_VALID_PAGE(nPage), wxT(""), wxT("notebook page out of range") );
88310e2e 235
837e5743 236 wxChar buf[256];
88310e2e
VZ
237 TC_ITEM tcItem;
238 tcItem.mask = TCIF_TEXT;
239 tcItem.pszText = buf;
240 tcItem.cchTextMax = WXSIZEOF(buf);
241
242 wxString str;
243 if ( TabCtrl_GetItem(m_hwnd, nPage, &tcItem) )
244 str = tcItem.pszText;
245
246 return str;
247}
248
249int wxNotebook::GetPageImage(int nPage) const
250{
223d09f6 251 wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, wxT("notebook page out of range") );
88310e2e
VZ
252
253 TC_ITEM tcItem;
254 tcItem.mask = TCIF_IMAGE;
255
256 return TabCtrl_GetItem(m_hwnd, nPage, &tcItem) ? tcItem.iImage : -1;
257}
258
259bool wxNotebook::SetPageImage(int nPage, int nImage)
260{
223d09f6 261 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
88310e2e
VZ
262
263 TC_ITEM tcItem;
264 tcItem.mask = TCIF_IMAGE;
265 tcItem.iImage = nImage;
266
267 return TabCtrl_SetItem(m_hwnd, nPage, &tcItem) != 0;
268}
269
270void wxNotebook::SetImageList(wxImageList* imageList)
907f37b3 271{
07b8d7ec
VZ
272 wxNotebookBase::SetImageList(imageList);
273
274 if ( imageList )
1e6feb95 275 {
07b8d7ec 276 TabCtrl_SetImageList(m_hwnd, (HIMAGELIST)imageList->GetHIMAGELIST());
1e6feb95 277 }
b656febd
VS
278}
279
d9506e77
VZ
280// ----------------------------------------------------------------------------
281// wxNotebook size settings
282// ----------------------------------------------------------------------------
283
284void wxNotebook::SetPageSize(const wxSize& size)
285{
286 // transform the page size into the notebook size
287 RECT rc;
288 rc.left =
289 rc.top = 0;
290 rc.right = size.x;
291 rc.bottom = size.y;
292
293 TabCtrl_AdjustRect(GetHwnd(), TRUE, &rc);
294
295 // and now set it
296 SetSize(rc.right - rc.left, rc.bottom - rc.top);
297}
298
299void wxNotebook::SetPadding(const wxSize& padding)
300{
301 TabCtrl_SetPadding(GetHwnd(), padding.x, padding.y);
302}
42e69d6b
VZ
303
304// Windows-only at present. Also, you must use the wxNB_FIXEDWIDTH
305// style.
306void wxNotebook::SetTabSize(const wxSize& sz)
307{
308 ::SendMessage(GetHwnd(), TCM_SETITEMSIZE, 0, MAKELPARAM(sz.x, sz.y));
309}
310
88310e2e
VZ
311// ----------------------------------------------------------------------------
312// wxNotebook operations
313// ----------------------------------------------------------------------------
314
315// remove one page from the notebook
316bool wxNotebook::DeletePage(int nPage)
317{
223d09f6 318 wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, wxT("notebook page out of range") );
88310e2e 319
96d37807
VZ
320 if ( m_nSelection == nPage ) {
321 // advance selection backwards - the page being deleted shouldn't be left
322 // selected
323 AdvanceSelection(FALSE);
324 }
325
88310e2e
VZ
326 TabCtrl_DeleteItem(m_hwnd, nPage);
327
1e6feb95 328 delete m_pages[nPage];
b54e41c5 329 m_pages.RemoveAt(nPage);
88310e2e 330
1e6feb95 331 if ( m_pages.IsEmpty() ) {
96d37807
VZ
332 // no selection if the notebook became empty
333 m_nSelection = -1;
334 }
9b6b5750
JS
335 else
336 m_nSelection = TabCtrl_GetCurSel(m_hwnd);
337
96d37807 338
88310e2e
VZ
339 return TRUE;
340}
341
621793f4 342// remove one page from the notebook, without deleting
1e6feb95 343wxNotebookPage *wxNotebook::DoRemovePage(int nPage)
621793f4 344{
10199e27
VZ
345 wxNotebookPage *pageRemoved = wxNotebookBase::DoRemovePage(nPage);
346 if ( !pageRemoved )
347 return NULL;
621793f4
JS
348
349 TabCtrl_DeleteItem(m_hwnd, nPage);
350
1e6feb95
VZ
351 if ( m_pages.IsEmpty() )
352 m_nSelection = -1;
353 else
354 m_nSelection = TabCtrl_GetCurSel(m_hwnd);
47f12f58 355
1e6feb95 356 return pageRemoved;
621793f4
JS
357}
358
88310e2e
VZ
359// remove all pages
360bool wxNotebook::DeleteAllPages()
361{
88310e2e
VZ
362 int nPageCount = GetPageCount();
363 int nPage;
364 for ( nPage = 0; nPage < nPageCount; nPage++ )
1e6feb95 365 delete m_pages[nPage];
88310e2e 366
1e6feb95 367 m_pages.Clear();
88310e2e 368
907f37b3
VZ
369 TabCtrl_DeleteAllItems(m_hwnd);
370
47f12f58
JS
371 m_nSelection = -1;
372
88310e2e
VZ
373 return TRUE;
374}
375
376// add a page to the notebook
377bool wxNotebook::AddPage(wxNotebookPage *pPage,
378 const wxString& strText,
379 bool bSelect,
380 int imageId)
381{
382 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
383}
384
385// same as AddPage() but does it at given position
386bool wxNotebook::InsertPage(int nPage,
387 wxNotebookPage *pPage,
388 const wxString& strText,
389 bool bSelect,
390 int imageId)
391{
392 wxASSERT( pPage != NULL );
393 wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
394
43427087
VZ
395 // do add the tab to the control
396
397 // init all fields to 0
88310e2e 398 TC_ITEM tcItem;
43427087 399 memset(&tcItem, 0, sizeof(tcItem));
58a8ab88 400
43427087 401 if ( imageId != -1 )
58a8ab88
JS
402 {
403 tcItem.mask |= TCIF_IMAGE;
404 tcItem.iImage = imageId;
405 }
58a8ab88 406
43427087 407 if ( !strText.IsEmpty() )
58a8ab88 408 {
43427087
VZ
409 tcItem.mask |= TCIF_TEXT;
410 tcItem.pszText = (wxChar *)strText.c_str(); // const_cast
58a8ab88 411 }
88310e2e
VZ
412
413 if ( TabCtrl_InsertItem(m_hwnd, nPage, &tcItem) == -1 ) {
223d09f6 414 wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());
43427087 415
88310e2e
VZ
416 return FALSE;
417 }
418
43427087
VZ
419 // if the inserted page is before the selected one, we must update the
420 // index of the selected page
421 if ( nPage <= m_nSelection )
422 {
423 // one extra page added
424 m_nSelection++;
425 }
426
88310e2e 427 // save the pointer to the page
1e6feb95 428 m_pages.Insert(pPage, nPage);
88310e2e 429
88310e2e 430 // don't show pages by default (we'll need to adjust their size first)
42e69d6b 431 HWND hwnd = GetWinHwnd(pPage);
88310e2e
VZ
432 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);
433
42e69d6b
VZ
434 // this updates internal flag too - otherwise it will get out of sync
435 pPage->Show(FALSE);
436
0398b1d6
RD
437 // fit the notebook page to the tab control's display area
438 RECT rc;
439 rc.left = rc.top = 0;
440 GetSize((int *)&rc.right, (int *)&rc.bottom);
441 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
442 pPage->SetSize(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
0398b1d6 443
43427087
VZ
444 // some page should be selected: either this one or the first one if there is
445 // still no selection
446 int selNew = -1;
447 if ( bSelect )
448 selNew = nPage;
449 else if ( m_nSelection == -1 )
450 selNew = 0;
451
452 if ( selNew != -1 )
453 SetSelection(selNew);
96d37807 454
88310e2e
VZ
455 return TRUE;
456}
457
458// ----------------------------------------------------------------------------
459// wxNotebook callbacks
460// ----------------------------------------------------------------------------
461
9026ad85 462void wxNotebook::OnSize(wxSizeEvent& event)
88310e2e 463{
b5c3b538
VZ
464 // fit the notebook page to the tab control's display area
465 RECT rc;
466 rc.left = rc.top = 0;
467 GetSize((int *)&rc.right, (int *)&rc.bottom);
468
469 TabCtrl_AdjustRect(m_hwnd, FALSE, &rc);
4b7f2165
VZ
470
471 int width = rc.right - rc.left,
472 height = rc.bottom - rc.top;
1e6feb95 473 size_t nCount = m_pages.Count();
c86f1403 474 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
1e6feb95 475 wxNotebookPage *pPage = m_pages[nPage];
4b7f2165 476 pPage->SetSize(rc.left, rc.top, width, height);
b5c3b538
VZ
477 }
478
88310e2e
VZ
479 event.Skip();
480}
481
482void wxNotebook::OnSelChange(wxNotebookEvent& event)
483{
484 // is it our tab control?
485 if ( event.GetEventObject() == this )
5d1d2d46 486 {
5d1d2d46
VZ
487 int sel = event.GetOldSelection();
488 if ( sel != -1 )
1e6feb95 489 m_pages[sel]->Show(FALSE);
0398b1d6 490
5d1d2d46
VZ
491 sel = event.GetSelection();
492 if ( sel != -1 )
493 {
1e6feb95 494 wxNotebookPage *pPage = m_pages[sel];
5d1d2d46
VZ
495 pPage->Show(TRUE);
496 pPage->SetFocus();
497 }
0398b1d6 498
5d1d2d46
VZ
499 m_nSelection = sel;
500 }
88310e2e
VZ
501
502 // we want to give others a chance to process this message as well
503 event.Skip();
504}
505
506void wxNotebook::OnSetFocus(wxFocusEvent& event)
507{
d9506e77
VZ
508 // this function is only called when the focus is explicitly set (i.e. from
509 // the program) to the notebook - in this case we don't need the
510 // complicated OnNavigationKey() logic because the programmer knows better
511 // what [s]he wants
88310e2e 512
d9506e77
VZ
513 // set focus to the currently selected page if any
514 if ( m_nSelection != -1 )
1e6feb95 515 m_pages[m_nSelection]->SetFocus();
d9506e77
VZ
516
517 event.Skip();
88310e2e
VZ
518}
519
520void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
521{
d9506e77
VZ
522 if ( event.IsWindowChange() ) {
523 // change pages
524 AdvanceSelection(event.GetDirection());
525 }
526 else {
527 // we get this event in 2 cases
528 //
529 // a) one of our pages might have generated it because the user TABbed
530 // out from it in which case we should propagate the event upwards and
531 // our parent will take care of setting the focus to prev/next sibling
532 //
533 // or
534 //
535 // b) the parent panel wants to give the focus to us so that we
536 // forward it to our selected page. We can't deal with this in
537 // OnSetFocus() because we don't know which direction the focus came
538 // from in this case and so can't choose between setting the focus to
539 // first or last panel child
540
541 wxWindow *parent = GetParent();
542 if ( event.GetEventObject() == parent )
543 {
544 // no, it doesn't come from child, case (b): forward to a page
545 if ( m_nSelection != -1 )
546 {
547 // so that the page knows that the event comes from it's parent
548 // and is being propagated downwards
549 event.SetEventObject(this);
550
1e6feb95 551 wxWindow *page = m_pages[m_nSelection];
d9506e77
VZ
552 if ( !page->GetEventHandler()->ProcessEvent(event) )
553 {
554 page->SetFocus();
555 }
556 //else: page manages focus inside it itself
557 }
558 else
559 {
560 // we have no pages - still have to give focus to _something_
561 SetFocus();
562 }
563 }
564 else
565 {
566 // it comes from our child, case (a), pass to the parent
567 if ( parent ) {
568 event.SetCurrentFocus(this);
569 parent->GetEventHandler()->ProcessEvent(event);
570 }
571 }
88310e2e 572 }
88310e2e
VZ
573}
574
575// ----------------------------------------------------------------------------
576// wxNotebook base class virtuals
577// ----------------------------------------------------------------------------
b5c3b538
VZ
578
579// override these 2 functions to do nothing: everything is done in OnSize
580
4b7f2165 581void wxNotebook::SetConstraintSizes(bool WXUNUSED(recurse))
b5c3b538
VZ
582{
583 // don't set the sizes of the pages - their correct size is not yet known
584 wxControl::SetConstraintSizes(FALSE);
585}
586
4b7f2165 587bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
b5c3b538
VZ
588{
589 return TRUE;
590}
591
a23fd0e1 592bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
88310e2e 593{
93a19f17 594 wxNotebookEvent event(wxEVT_NULL, m_windowId);
88310e2e
VZ
595
596 NMHDR* hdr = (NMHDR *)lParam;
597 switch ( hdr->code ) {
598 case TCN_SELCHANGE:
599 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
600 break;
601
602 case TCN_SELCHANGING:
603 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING);
604 break;
605
fd3f686c 606 default:
a23fd0e1 607 return wxControl::MSWOnNotify(idCtrl, lParam, result);
88310e2e
VZ
608 }
609
93a19f17
VZ
610 event.SetSelection(TabCtrl_GetCurSel(m_hwnd));
611 event.SetOldSelection(m_nSelection);
88310e2e 612 event.SetEventObject(this);
a23fd0e1 613 event.SetInt(idCtrl);
88310e2e 614
fd3f686c
VZ
615 bool processed = GetEventHandler()->ProcessEvent(event);
616 *result = !event.IsAllowed();
617 return processed;
88310e2e
VZ
618}
619
620// ----------------------------------------------------------------------------
621// wxNotebook helper functions
622// ----------------------------------------------------------------------------
623
43427087
VZ
624// generate the page changing and changed events, hide the currently active
625// panel and show the new one
88310e2e
VZ
626void wxNotebook::ChangePage(int nOldSel, int nSel)
627{
fd3f686c
VZ
628 // MT-FIXME should use a real semaphore
629 static bool s_bInsideChangePage = FALSE;
630
631 // when we call ProcessEvent(), our own OnSelChange() is called which calls
632 // this function - break the infinite loop
633 if ( s_bInsideChangePage )
634 return;
635
aaab7c01
VZ
636 // it's not an error (the message may be generated by the tab control itself)
637 // and it may happen - just do nothing
638 if ( nSel == nOldSel )
639 return;
88310e2e 640
fd3f686c
VZ
641 s_bInsideChangePage = TRUE;
642
643 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
644 event.SetSelection(nSel);
645 event.SetOldSelection(nOldSel);
646 event.SetEventObject(this);
1e6feb95 647 if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() )
fd3f686c
VZ
648 {
649 // program doesn't allow the page change
650 s_bInsideChangePage = FALSE;
651 return;
652 }
653
fd3f686c 654 event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
1e6feb95 655 GetEventHandler()->ProcessEvent(event);
fd3f686c 656
fd3f686c 657 s_bInsideChangePage = FALSE;
88310e2e 658}
1e6feb95
VZ
659
660#endif // wxUSE_NOTEBOOK