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