Use initial book from available controls. Select it in menu correctly.
[wxWidgets.git] / samples / notebook / notebook.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/notebook/notebook.cpp
3 // Purpose: a sample demonstrating notebook usage
4 // Author: Julian Smart
5 // Modified by: Dimitri Schoolwerth
6 // Created: 26/10/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998-2002 wxWidgets team
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22
23 #include "wx/imaglist.h"
24 #include "wx/artprov.h"
25 #include "notebook.h"
26
27 IMPLEMENT_APP(MyApp)
28
29 bool MyApp::OnInit()
30 {
31 // Create the main window
32 MyFrame *frame = new MyFrame( wxT("Notebook sample") );
33
34 // Problem with generic wxNotebook implementation whereby it doesn't size
35 // properly unless you set the size again
36 #if defined(__WXMOTIF__)
37 int width, height;
38 frame->GetSize(& width, & height);
39 frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height);
40 #endif
41
42 frame->Show();
43
44 return true;
45 }
46
47 wxPanel *CreateUserCreatedPage(wxBookCtrlBase *parent)
48 {
49 wxPanel *panel = new wxPanel(parent);
50
51 (void) new wxButton( panel, wxID_ANY, wxT("Button"),
52 wxPoint(10, 10), wxDefaultSize );
53
54 return panel;
55 }
56
57 wxPanel *CreateRadioButtonsPage(wxBookCtrlBase *parent)
58 {
59 wxPanel *panel = new wxPanel(parent);
60
61 wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
62 wxT("Sabre-toothed tiger"), wxT("T Rex") };
63
64 wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose one"),
65 wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS);
66
67 wxString computers[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"),
68 wxT("Another") };
69
70 wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY,
71 wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize,
72 4, computers, 0, wxRA_SPECIFY_COLS);
73
74 wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
75 sizerPanel->Add(radiobox1, 2, wxEXPAND);
76 sizerPanel->Add(radiobox2, 1, wxEXPAND);
77 panel->SetSizer(sizerPanel);
78
79 return panel;
80 }
81
82 wxPanel *CreateVetoPage(wxBookCtrlBase *parent)
83 {
84 wxPanel *panel = new wxPanel(parent);
85
86 (void) new wxStaticText( panel, wxID_ANY,
87 wxT("This page intentionally left blank"), wxPoint(10, 10) );
88
89 return panel;
90 }
91
92 wxPanel *CreateBigButtonPage(wxBookCtrlBase *parent)
93 {
94 wxPanel *panel = new wxPanel(parent);
95
96 wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button"));
97
98 wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
99 sizerPanel->Add(buttonBig, 1, wxEXPAND);
100 panel->SetSizer(sizerPanel);
101
102 return panel;
103 }
104
105
106 wxPanel *CreateInsertPage(wxBookCtrlBase *parent)
107 {
108 wxPanel *panel = new wxPanel(parent);
109
110 panel->SetBackgroundColour( wxColour( wxT("MAROON") ) );
111 (void) new wxStaticText( panel, wxID_ANY,
112 wxT("This page has been inserted, not added."), wxPoint(10, 10) );
113
114 return panel;
115 }
116
117 int GetIconIndex(wxBookCtrlBase* bookCtrl)
118 {
119 if (bookCtrl && bookCtrl->GetImageList())
120 {
121 int nImages = bookCtrl->GetImageList()->GetImageCount();
122 if (nImages > 0)
123 {
124 return bookCtrl->GetPageCount() % nImages;
125 }
126 }
127
128 return -1;
129 }
130
131 void CreateInitialPages(wxBookCtrlBase *parent)
132 {
133 // Create and add some panels to the notebook
134
135 wxPanel *panel = CreateRadioButtonsPage(parent);
136 parent->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(parent) );
137
138 panel = CreateVetoPage(parent);
139 parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) );
140
141 panel = CreateBigButtonPage(parent);
142 parent->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(parent) );
143
144 panel = CreateInsertPage(parent);
145 parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) );
146
147 parent->SetSelection(1);
148 }
149
150 wxPanel *CreatePage(wxBookCtrlBase *parent, const wxString&pageName)
151 {
152 if
153 (
154 pageName.Contains(INSERTED_PAGE_NAME)
155 || pageName.Contains(ADDED_PAGE_NAME)
156 )
157 {
158 return CreateUserCreatedPage(parent);
159 }
160
161 if (pageName == I_WAS_INSERTED_PAGE_NAME)
162 {
163 return CreateInsertPage(parent);
164 }
165
166 if (pageName == VETO_PAGE_NAME)
167 {
168 return CreateVetoPage(parent);
169 }
170
171 if (pageName == RADIOBUTTONS_PAGE_NAME)
172 {
173 return CreateRadioButtonsPage(parent);
174 }
175
176
177 if (pageName == MAXIMIZED_BUTTON_PAGE_NAME)
178 {
179 return CreateBigButtonPage(parent);
180 }
181
182 wxFAIL;
183
184 return (wxPanel *) NULL;
185 }
186
187 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
188 long style)
189 : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style)
190 {
191 #if wxUSE_NOTEBOOK
192 m_type = ID_BOOK_NOTEBOOK;
193 #elif wxUSE_CHOICEBOOK
194 m_type = ID_BOOK_CHOICEBOOK;
195 #elif wxUSE_LISTBOOK
196 m_type = ID_BOOK_LISTBOOK;
197 #elif
198 #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
199 #endif
200
201 m_orient = ID_ORIENT_DEFAULT;
202 m_chkShowImages = true;
203 m_multi = false;
204
205 // menu of the sample
206
207 wxMenu *menuType = new wxMenu;
208 #if wxUSE_NOTEBOOK
209 menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, wxT("&Notebook\tCtrl-1"));
210 #endif
211 #if wxUSE_LISTBOOK
212 menuType->AppendRadioItem(ID_BOOK_LISTBOOK, wxT("&Listbook\tCtrl-2"));
213 #endif
214 #if wxUSE_CHOICEBOOK
215 menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3"));
216 #endif
217 menuType->Check(m_type, true);
218
219 wxMenu *menuOrient = new wxMenu;
220 menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tCtrl-4"));
221 menuOrient->AppendRadioItem(ID_ORIENT_TOP, wxT("&Top\tCtrl-5"));
222 menuOrient->AppendRadioItem(ID_ORIENT_BOTTOM, wxT("&Bottom\tCtrl-6"));
223 menuOrient->AppendRadioItem(ID_ORIENT_LEFT, wxT("&Left\tCtrl-7"));
224 menuOrient->AppendRadioItem(ID_ORIENT_RIGHT, wxT("&Right\tCtrl-8"));
225
226 wxMenu *menuDo = new wxMenu;
227 menuDo->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A"));
228 menuDo->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I"));
229 menuDo->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D"));
230 menuDo->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L"));
231 menuDo->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N"));
232
233 wxMenu *menuFile = new wxMenu;
234 menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control"));
235 menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control"));
236 menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S"));
237 menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines\tAlt-M"));
238 menuFile->AppendSeparator();
239 menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application"));
240 menuFile->Check(ID_SHOW_IMAGES, m_chkShowImages);
241 menuFile->Check(ID_MULTI, m_multi);
242
243 wxMenuBar *menuBar = new wxMenuBar;
244 menuBar->Append(menuFile, wxT("&File"));
245 menuBar->Append(menuDo, wxT("&Operations"));
246 SetMenuBar(menuBar);
247
248 // books creation
249
250 m_panel = (wxPanel *) NULL;
251 #if wxUSE_NOTEBOOK
252 m_notebook = (wxNotebook *) NULL;
253 #endif
254 #if wxUSE_CHOICEBOOK
255 m_choicebook = (wxChoicebook *) NULL;
256 #endif
257 #if wxUSE_LISTBOOK
258 m_listbook = (wxListbook *) NULL;
259 #endif
260
261 // create a dummy image list with a few icons
262 wxSize imageSize(32, 32);
263
264 m_imageList
265 = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() );
266
267 m_imageList->Add
268 (
269 wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)
270 );
271
272 m_imageList->Add
273 (
274 wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)
275 );
276
277 m_imageList->Add
278 (
279 wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)
280 );
281
282 m_imageList->Add
283 (
284 wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)
285 );
286
287 m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
288 wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
289
290 #if USE_LOG
291 m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString,
292 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
293
294 m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) );
295 #endif // USE_LOG
296
297 // Set sizers
298 m_sizerFrame = new wxBoxSizer(wxVERTICAL);
299
300 #if USE_LOG
301 m_sizerFrame->Add(m_text, 1, wxEXPAND);
302 #endif // USE_LOG
303
304 RecreateBooks();
305
306 m_panel->SetSizer(m_sizerFrame);
307
308 m_sizerFrame->Fit(this);
309 m_sizerFrame->SetSizeHints(this);
310
311 Centre(wxBOTH);
312 }
313
314 MyFrame::~MyFrame()
315 {
316 #if USE_LOG
317 delete wxLog::SetActiveTarget(m_logTargetOld);
318 #endif // USE_LOG
319
320 if (m_imageList)
321 {
322 delete m_imageList;
323 m_imageList = (wxImageList *) NULL;
324 }
325 }
326
327 int MyFrame::SelectFlag(int id, int nb, int lb, int chb)
328 {
329 switch (id)
330 {
331 case ID_NOTEBOOK: return nb;
332 case ID_LISTBOOK: return lb;
333 case ID_CHOICEBOOK: return chb;
334 }
335 return 0;
336 }
337
338 #define RECREATE( wxBookType , idBook, oldBook , newBook ) \
339 { \
340 int flags; \
341 \
342 switch ( m_orient ) \
343 { \
344 case ID_ORIENT_TOP: \
345 flags = SelectFlag(idBook, wxNB_TOP, wxLB_TOP, wxCHB_TOP); \
346 break; \
347 \
348 case ID_ORIENT_BOTTOM: \
349 flags = SelectFlag(idBook, wxNB_BOTTOM, wxLB_BOTTOM, wxCHB_BOTTOM); \
350 break; \
351 \
352 case ID_ORIENT_LEFT: \
353 flags = SelectFlag(idBook, wxNB_LEFT, wxLB_LEFT, wxCHB_LEFT); \
354 break; \
355 \
356 case ID_ORIENT_RIGHT: \
357 flags = SelectFlag(idBook, wxNB_RIGHT, wxLB_RIGHT, wxCHB_RIGHT); \
358 break; \
359 \
360 default: \
361 flags = SelectFlag(idBook, wxNB_DEFAULT, wxLB_DEFAULT, wxCHB_DEFAULT); \
362 } \
363 \
364 if ( m_multi && ( idBook == ID_NOTEBOOK ) ) \
365 flags |= wxNB_MULTILINE; \
366 \
367 wxBookType *oldBook = newBook; \
368 \
369 newBook = new wxBookType(m_panel, idBook, \
370 wxDefaultPosition, wxDefaultSize, \
371 flags); \
372 \
373 if ( m_chkShowImages ) \
374 { \
375 newBook->SetImageList(m_imageList); \
376 } \
377 \
378 if (oldBook) \
379 { \
380 int sel = oldBook->GetSelection(); \
381 \
382 int count = oldBook->GetPageCount(); \
383 for (int n = 0; n < count; n++) \
384 { \
385 wxString str = oldBook->GetPageText(n); \
386 \
387 wxWindow *page = CreatePage(newBook, str); \
388 newBook->AddPage(page, str, false, GetIconIndex(newBook) ); \
389 } \
390 \
391 m_sizerFrame->Detach(oldBook); \
392 \
393 delete oldBook; \
394 \
395 if (sel != wxNOT_FOUND) \
396 { \
397 newBook->SetSelection(sel); \
398 } \
399 \
400 } \
401 else \
402 { \
403 CreateInitialPages(newBook); \
404 } \
405 \
406 m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, 4); \
407 \
408 m_sizerFrame->Hide(newBook); \
409 }
410
411 void MyFrame::RecreateBooks()
412 {
413 #if wxUSE_NOTEBOOK
414 RECREATE( wxNotebook , ID_NOTEBOOK , notebook , m_notebook );
415 #endif
416 #if wxUSE_LISTBOOK
417 RECREATE( wxListbook , ID_LISTBOOK , listbook , m_listbook );
418 #endif
419 #if wxUSE_CHOICEBOOK
420 RECREATE( wxChoicebook , ID_CHOICEBOOK , choicebook , m_choicebook );
421 #endif
422
423 ShowCurrentBook();
424 }
425
426 wxBookCtrlBase *MyFrame::GetCurrentBook()
427 {
428 switch (m_type)
429 {
430 #if wxUSE_NOTEBOOK
431 case ID_BOOK_NOTEBOOK: return m_notebook;
432 #endif
433 #if wxUSE_LISTBOOK
434 case ID_BOOK_LISTBOOK: return m_listbook;
435 #endif
436 #if wxUSE_CHOICEBOOK
437 case ID_BOOK_CHOICEBOOK: return m_choicebook;
438 #endif
439 }
440 return NULL;
441 }
442
443 void MyFrame::ShowCurrentBook()
444 {
445 switch(m_type)
446 {
447 #if wxUSE_NOTEBOOK
448 case ID_BOOK_NOTEBOOK: if(m_notebook) m_sizerFrame->Show(m_notebook); break;
449 #endif
450 #if wxUSE_LISTBOOK
451 case ID_BOOK_LISTBOOK: if(m_listbook) m_sizerFrame->Show(m_listbook); break;
452 #endif
453 #if wxUSE_CHOICEBOOK
454 case ID_BOOK_CHOICEBOOK: if(m_choicebook) m_sizerFrame->Show(m_choicebook); break;
455 #endif
456 }
457
458 m_sizerFrame->Layout();
459 }
460
461 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
462 // File menu
463 EVT_MENU_RANGE(ID_BOOK_NOTEBOOK,ID_BOOK_MAX,MyFrame::OnType)
464 EVT_MENU_RANGE(ID_ORIENT_DEFAULT,ID_ORIENT_MAX,MyFrame::OnOrient)
465 EVT_MENU(ID_SHOW_IMAGES, MyFrame::OnShowImages)
466 EVT_MENU(ID_MULTI, MyFrame::OnMulti)
467 EVT_MENU(wxID_EXIT,MyFrame::OnExit)
468
469 // Operations menu
470 EVT_MENU(ID_ADD_PAGE, MyFrame::OnAddPage)
471 EVT_MENU(ID_INSERT_PAGE, MyFrame::OnInsertPage)
472 EVT_MENU(ID_DELETE_CUR_PAGE, MyFrame::OnDeleteCurPage)
473 EVT_MENU(ID_DELETE_LAST_PAGE, MyFrame::OnDeleteLastPage)
474 EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
475
476 // Book controls
477 #if wxUSE_NOTEBOOK
478 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook)
479 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook)
480 #endif
481 #if wxUSE_LISTBOOK
482 EVT_LISTBOOK_PAGE_CHANGED(ID_LISTBOOK, MyFrame::OnListbook)
483 EVT_LISTBOOK_PAGE_CHANGING(ID_LISTBOOK, MyFrame::OnListbook)
484 #endif
485 #if wxUSE_CHOICEBOOK
486 EVT_CHOICEBOOK_PAGE_CHANGED(ID_CHOICEBOOK, MyFrame::OnChoicebook)
487 EVT_CHOICEBOOK_PAGE_CHANGING(ID_CHOICEBOOK, MyFrame::OnChoicebook)
488 #endif
489
490 // Update title in idle time
491 EVT_IDLE(MyFrame::OnIdle)
492 END_EVENT_TABLE()
493
494 void MyFrame::OnType(wxCommandEvent& event)
495 {
496 wxBookCtrlBase *currBook = GetCurrentBook();
497
498 m_type = event.GetId();
499
500 if (currBook)
501 m_sizerFrame->Hide(currBook);
502
503 ShowCurrentBook();
504 }
505
506 void MyFrame::OnOrient(wxCommandEvent& event)
507 {
508 m_orient = event.GetId();
509 RecreateBooks();
510 m_sizerFrame->Layout();
511 }
512
513 void MyFrame::OnShowImages(wxCommandEvent& event)
514 {
515 m_chkShowImages = event.IsChecked();
516 RecreateBooks();
517 m_sizerFrame->Layout();
518 }
519
520 void MyFrame::OnMulti(wxCommandEvent& event)
521 {
522 m_multi = event.IsChecked();
523 RecreateBooks();
524 m_sizerFrame->Layout();
525 wxLogMessage(_T("Multiline setting works only in wxNotebook."));
526 }
527
528 void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
529 {
530 Close();
531 }
532
533 void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
534 {
535 static unsigned s_pageAdded = 0;
536
537 wxBookCtrlBase *currBook = GetCurrentBook();
538
539 if ( currBook )
540 {
541 wxPanel *panel = new wxPanel( currBook, wxID_ANY );
542 (void) new wxButton( panel, wxID_ANY, wxT("First button"),
543 wxPoint(10, 10), wxDefaultSize );
544 (void) new wxButton( panel, wxID_ANY, wxT("Second button"),
545 wxPoint(50, 100), wxDefaultSize );
546
547 currBook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"),
548 ++s_pageAdded), true, GetIconIndex(currBook) );
549 }
550 }
551
552 void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
553 {
554 static unsigned s_pageIns = 0;
555
556 wxBookCtrlBase *currBook = GetCurrentBook();
557
558 if ( currBook )
559 {
560 wxPanel *panel = CreateUserCreatedPage( currBook );
561
562 currBook->InsertPage( 0, panel,
563 wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false,
564 GetIconIndex(currBook) );
565
566 currBook->SetSelection(0);
567 }
568 }
569
570 void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
571 {
572 wxBookCtrlBase *currBook = GetCurrentBook();
573
574 if ( currBook )
575 {
576 int sel = currBook->GetSelection();
577
578 if (sel != wxNOT_FOUND)
579 {
580 currBook->DeletePage(sel);
581 }
582 }
583 }
584
585 void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event))
586 {
587 wxBookCtrlBase *currBook = GetCurrentBook();
588
589 if ( currBook )
590 {
591 int page = currBook->GetPageCount();
592
593 if ( page != 0 )
594 {
595 currBook->DeletePage(page - 1);
596 }
597 }
598 }
599
600 void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event))
601 {
602 wxBookCtrlBase *currBook = GetCurrentBook();
603
604 if ( currBook )
605 {
606 currBook->AdvanceSelection();
607 }
608 }
609
610 void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
611 {
612 static int s_nPages = wxNOT_FOUND;
613 static int s_nSel = wxNOT_FOUND;
614 static wxBookCtrlBase *s_currBook = NULL;
615
616 wxBookCtrlBase *currBook = GetCurrentBook();
617
618 int nPages = currBook ? currBook->GetPageCount() : 0;
619 int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND;
620
621 if ( nPages != s_nPages || nSel != s_nSel || s_currBook != currBook )
622 {
623 s_nPages = nPages;
624 s_nSel = nSel;
625 s_currBook = currBook;
626
627 wxString selection;
628 if ( nSel == wxNOT_FOUND )
629 selection << wxT("not found");
630 else
631 selection << nSel;
632
633 wxString title;
634 title.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages, selection.c_str());
635
636 SetTitle(title);
637 }
638 }
639
640 #if USE_LOG
641 #define BOOKEVENT_LOG m_text->SetInsertionPointEnd();
642 #else
643 #define BOOKEVENT_LOG
644 #endif
645
646 #define BOOKEVENT(OnBook,wxBookEvent,bookStr,wxEVT_PAGE_CHANGED,wxEVT_PAGE_CHANGING,s_num) \
647 void MyFrame::OnBook(wxBookEvent& event) \
648 { \
649 wxString str = wxT("Unknown "); \
650 str << wxT(bookStr); \
651 str << wxT(" event"); \
652 \
653 wxEventType eventType = event.GetEventType(); \
654 \
655 if (eventType == wxEVT_PAGE_CHANGED) \
656 { \
657 str = wxT("Changed"); \
658 } \
659 else if (eventType == wxEVT_PAGE_CHANGING) \
660 { \
661 int idx = event.GetOldSelection(); \
662 wxBookCtrlBase *book = (wxBookCtrlBase *)event.GetEventObject(); \
663 if ( idx != wxNOT_FOUND && book && book->GetPageText(idx) == VETO_PAGE_NAME ) \
664 { \
665 if \
666 ( \
667 wxMessageBox( \
668 wxT("Are you sure you want to leave this page?\n") \
669 wxT("(This demonstrates veto-ing)"), \
670 wxT("Notebook sample"), \
671 wxICON_QUESTION | wxYES_NO, this) != wxYES ) \
672 { \
673 event.Veto(); \
674 } \
675 \
676 } \
677 \
678 str = wxT("Changing"); \
679 } \
680 \
681 static int s_num = 0; \
682 \
683 wxString logMsg; \
684 logMsg.Printf(wxT("%s event #%d: %s (%d) Sel %d, OldSel %d"), \
685 wxT(bookStr),s_num++, str.c_str(), eventType, \
686 event.GetSelection(), event.GetOldSelection()); \
687 \
688 wxLogMessage(logMsg.c_str()); \
689 \
690 BOOKEVENT_LOG \
691 }
692
693 #if wxUSE_NOTEBOOK
694 BOOKEVENT(OnNotebook,wxNotebookEvent,"wxNotebook",wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,s_numNotebookEvents)
695 #endif
696 #if wxUSE_CHOICEBOOK
697 BOOKEVENT(OnChoicebook,wxChoicebookEvent,"wxChoicebook",wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,s_numChoicebookEvents)
698 #endif
699 #if wxUSE_LISTBOOK
700 BOOKEVENT(OnListbook,wxListbookEvent,"wxListbook",wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,s_numListbookEvents)
701 #endif