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