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