Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / samples / widgets / notebook.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
3 // Name: notebook.cpp
4 // Purpose: Part of the widgets sample showing book controls
5 // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
6 // Created: 06.04.01
7 // Copyright: (c) 2001 Vadim Zeitlin, 2006 Wlodzimierz Skiba
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_BOOKCTRL
27
28 // for all others, include the necessary headers
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/log.h"
32
33 #include "wx/button.h"
34 #include "wx/checkbox.h"
35 #include "wx/combobox.h"
36 #include "wx/radiobox.h"
37 #include "wx/statbox.h"
38 #include "wx/textctrl.h"
39
40 #include "wx/dynarray.h"
41 #endif
42
43 #include "wx/sizer.h"
44 #include "wx/bookctrl.h"
45 #include "wx/artprov.h"
46 #include "wx/imaglist.h"
47
48 #include "widgets.h"
49
50 // ----------------------------------------------------------------------------
51 // constants
52 // ----------------------------------------------------------------------------
53
54 // control ids
55 enum
56 {
57 BookPage_Reset = wxID_HIGHEST,
58 BookPage_SelectPage,
59 BookPage_AddPage,
60 BookPage_InsertPage,
61 BookPage_RemovePage,
62 BookPage_DeleteAll,
63 BookPage_InsertText,
64 BookPage_RemoveText,
65 BookPage_SelectText,
66 BookPage_NumPagesText,
67 BookPage_CurSelectText,
68 BookPage_Book
69 };
70
71 // book orientations
72 enum Orient
73 {
74 Orient_Top,
75 Orient_Bottom,
76 Orient_Left,
77 Orient_Right,
78 Orient_Max
79 };
80
81 // ----------------------------------------------------------------------------
82 // BookWidgetsPage
83 // ----------------------------------------------------------------------------
84
85 class BookWidgetsPage : public WidgetsPage
86 {
87 public:
88 BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, const char *const icon[]);
89 virtual ~BookWidgetsPage();
90
91 virtual wxControl *GetWidget() const { return m_book; }
92 virtual void RecreateWidget() { RecreateBook(); }
93
94 // lazy creation of the content
95 virtual void CreateContent();
96
97 protected:
98 // event handlers
99 void OnButtonReset(wxCommandEvent& event);
100 void OnButtonDeleteAll(wxCommandEvent& event);
101 void OnButtonSelectPage(wxCommandEvent& event);
102 void OnButtonAddPage(wxCommandEvent& event);
103 void OnButtonInsertPage(wxCommandEvent& event);
104 void OnButtonRemovePage(wxCommandEvent& event);
105
106 void OnCheckOrRadioBox(wxCommandEvent& event);
107
108 void OnUpdateUINumPagesText(wxUpdateUIEvent& event);
109 void OnUpdateUICurSelectText(wxUpdateUIEvent& event);
110
111 void OnUpdateUISelectButton(wxUpdateUIEvent& event);
112 void OnUpdateUIInsertButton(wxUpdateUIEvent& event);
113 void OnUpdateUIRemoveButton(wxUpdateUIEvent& event);
114
115 void OnUpdateUIResetButton(wxUpdateUIEvent& event);
116
117 // reset book parameters
118 void Reset();
119
120 // (re)create book
121 void RecreateBook();
122 virtual wxBookCtrlBase *CreateBook(long flags) = 0;
123
124 #if USE_ICONS_IN_BOOK
125 // create or destroy the image list
126 void CreateImageList();
127 #endif // USE_ICONS_IN_BOOK
128
129 // create a new page
130 wxWindow *CreateNewPage();
131
132 // get the image index for the new page
133 int GetIconIndex() const;
134
135 // get the numeric value of text ctrl
136 int GetTextValue(wxTextCtrl *text) const;
137
138 // is the value in range?
139 bool IsValidValue(int val) const
140 { return (val >= 0) && (val < (int) m_book->GetPageCount()); }
141
142 // the controls
143 // ------------
144
145 // the check/radio boxes for styles
146 wxCheckBox *m_chkImages;
147 wxRadioBox *m_radioOrient;
148
149 // the text controls containing input for various commands
150 wxTextCtrl *m_textInsert,
151 *m_textRemove,
152 *m_textSelect;
153
154 // the book itself and the sizer it is in
155 wxBookCtrlBase *m_book;
156 wxSizer *m_sizerBook;
157
158 #if USE_ICONS_IN_BOOK
159 // the image list for our book
160 wxImageList *m_imageList;
161 #endif // USE_ICONS_IN_BOOK
162
163 private:
164 DECLARE_EVENT_TABLE()
165 };
166
167 // ----------------------------------------------------------------------------
168 // event tables
169 // ----------------------------------------------------------------------------
170
171 BEGIN_EVENT_TABLE(BookWidgetsPage, WidgetsPage)
172 EVT_BUTTON(BookPage_Reset, BookWidgetsPage::OnButtonReset)
173 EVT_BUTTON(BookPage_SelectPage, BookWidgetsPage::OnButtonSelectPage)
174 EVT_BUTTON(BookPage_AddPage, BookWidgetsPage::OnButtonAddPage)
175 EVT_BUTTON(BookPage_InsertPage, BookWidgetsPage::OnButtonInsertPage)
176 EVT_BUTTON(BookPage_RemovePage, BookWidgetsPage::OnButtonRemovePage)
177 EVT_BUTTON(BookPage_DeleteAll, BookWidgetsPage::OnButtonDeleteAll)
178
179 EVT_UPDATE_UI(BookPage_NumPagesText, BookWidgetsPage::OnUpdateUINumPagesText)
180 EVT_UPDATE_UI(BookPage_CurSelectText, BookWidgetsPage::OnUpdateUICurSelectText)
181
182 EVT_UPDATE_UI(BookPage_SelectPage, BookWidgetsPage::OnUpdateUISelectButton)
183 EVT_UPDATE_UI(BookPage_InsertPage, BookWidgetsPage::OnUpdateUIInsertButton)
184 EVT_UPDATE_UI(BookPage_RemovePage, BookWidgetsPage::OnUpdateUIRemoveButton)
185
186 EVT_CHECKBOX(wxID_ANY, BookWidgetsPage::OnCheckOrRadioBox)
187 EVT_RADIOBOX(wxID_ANY, BookWidgetsPage::OnCheckOrRadioBox)
188 END_EVENT_TABLE()
189
190 // ============================================================================
191 // implementation
192 // ============================================================================
193
194 BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, const char *const icon[])
195 :WidgetsPage(book, imaglist, icon)
196 {
197 // init everything
198 m_chkImages = NULL;
199 #if USE_ICONS_IN_BOOK
200 m_imageList = NULL;
201 #endif // USE_ICONS_IN_BOOK
202
203 m_book = NULL;
204 m_radioOrient = NULL;
205 m_sizerBook = (wxSizer *)NULL;
206 }
207
208 void BookWidgetsPage::CreateContent()
209 {
210 wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
211
212 // left pane
213 wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style"));
214
215 // must be in sync with Orient enum
216 wxArrayString orientations;
217 orientations.Add(wxT("&top"));
218 orientations.Add(wxT("&bottom"));
219 orientations.Add(wxT("&left"));
220 orientations.Add(wxT("&right"));
221
222 wxASSERT_MSG( orientations.GetCount() == Orient_Max,
223 wxT("forgot to update something") );
224
225 m_chkImages = new wxCheckBox(this, wxID_ANY, wxT("Show &images"));
226 m_radioOrient = new wxRadioBox(this, wxID_ANY, wxT("&Tab orientation"),
227 wxDefaultPosition, wxDefaultSize,
228 orientations, 1, wxRA_SPECIFY_COLS);
229
230 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
231
232 sizerLeft->Add(m_chkImages, 0, wxALL, 5);
233 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
234 sizerLeft->Add(m_radioOrient, 0, wxALL, 5);
235
236 wxButton *btn = new wxButton(this, BookPage_Reset, wxT("&Reset"));
237 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
238
239 // middle pane
240 wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, wxT("&Contents"));
241 wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
242
243 wxTextCtrl *text;
244 wxSizer *sizerRow = CreateSizerWithTextAndLabel(wxT("Number of pages: "),
245 BookPage_NumPagesText,
246 &text);
247 text->SetEditable(false);
248 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
249
250 sizerRow = CreateSizerWithTextAndLabel(wxT("Current selection: "),
251 BookPage_CurSelectText,
252 &text);
253 text->SetEditable(false);
254 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
255
256 sizerRow = CreateSizerWithTextAndButton(BookPage_SelectPage,
257 wxT("&Select page"),
258 BookPage_SelectText,
259 &m_textSelect);
260 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
261
262 btn = new wxButton(this, BookPage_AddPage, wxT("&Add page"));
263 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
264
265 sizerRow = CreateSizerWithTextAndButton(BookPage_InsertPage,
266 wxT("&Insert page at"),
267 BookPage_InsertText,
268 &m_textInsert);
269 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
270
271 sizerRow = CreateSizerWithTextAndButton(BookPage_RemovePage,
272 wxT("&Remove page"),
273 BookPage_RemoveText,
274 &m_textRemove);
275 sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
276
277 btn = new wxButton(this, BookPage_DeleteAll, wxT("&Delete All"));
278 sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
279
280 // right pane
281 m_sizerBook = new wxBoxSizer(wxHORIZONTAL);
282
283 // the 3 panes compose the window
284 sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
285 sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
286 sizerTop->Add(m_sizerBook, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
287
288 RecreateBook();
289
290 // final initializations
291 Reset();
292 #if USE_ICONS_IN_BOOK
293 CreateImageList();
294 #endif // USE_ICONS_IN_BOOK
295
296 SetSizer(sizerTop);
297 }
298
299 BookWidgetsPage::~BookWidgetsPage()
300 {
301 #if USE_ICONS_IN_BOOK
302 delete m_imageList;
303 #endif // USE_ICONS_IN_BOOK
304 }
305
306 // ----------------------------------------------------------------------------
307 // operations
308 // ----------------------------------------------------------------------------
309
310 void BookWidgetsPage::Reset()
311 {
312 m_chkImages->SetValue(true);
313 m_radioOrient->SetSelection(Orient_Top);
314 }
315
316 #if USE_ICONS_IN_BOOK
317 void BookWidgetsPage::CreateImageList()
318 {
319 if ( m_chkImages->GetValue() )
320 {
321 if ( !m_imageList )
322 {
323 // create a dummy image list with a few icons
324 m_imageList = new wxImageList(32, 32);
325 wxSize size(32, 32);
326 m_imageList->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, size));
327 m_imageList->Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, size));
328 m_imageList->Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, size));
329 m_imageList->Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, size));
330 }
331
332 if ( m_book )
333 m_book->SetImageList(m_imageList);
334 }
335 else // no images
336 {
337 wxDELETE(m_imageList);
338 }
339
340 // because of the bug in wxMSW we can't use SetImageList(NULL) - although
341 // it would be logical if this removed the image list from book, under
342 // MSW it crashes instead - FIXME
343 }
344 #endif // USE_ICONS_IN_BOOK
345
346 void BookWidgetsPage::RecreateBook()
347 {
348 // do not recreate anything in case page content was not prepared yet
349 if(!m_radioOrient)
350 return;
351
352 int flags = ms_defaultFlags;
353
354 switch ( m_radioOrient->GetSelection() )
355 {
356 default:
357 wxFAIL_MSG( wxT("unknown orientation") );
358 // fall through
359
360 case Orient_Top:
361 flags |= wxBK_TOP;
362 break;
363
364 case Orient_Bottom:
365 flags |= wxBK_BOTTOM;
366 break;
367
368 case Orient_Left:
369 flags |= wxBK_LEFT;
370 break;
371
372 case Orient_Right:
373 flags |= wxBK_RIGHT;
374 break;
375 }
376
377 wxBookCtrlBase *oldBook = m_book;
378
379 m_book = CreateBook(flags);
380
381 #if USE_ICONS_IN_BOOK
382 CreateImageList();
383 #endif // USE_ICONS_IN_BOOK
384
385 if ( oldBook )
386 {
387 const int sel = oldBook->GetSelection();
388
389 const int count = oldBook->GetPageCount();
390
391 // recreate the pages
392 for ( int n = 0; n < count; n++ )
393 {
394 m_book->AddPage(CreateNewPage(),
395 oldBook->GetPageText(n),
396 false,
397 m_chkImages->GetValue() ?
398 GetIconIndex() : -1);
399 }
400
401 m_sizerBook->Detach( oldBook );
402 delete oldBook;
403
404 // restore selection
405 if ( sel != -1 )
406 {
407 m_book->SetSelection(sel);
408 }
409 }
410
411 m_sizerBook->Add(m_book, 1, wxGROW | wxALL, 5);
412 m_sizerBook->SetMinSize(150, 0);
413 m_sizerBook->Layout();
414 }
415
416 // ----------------------------------------------------------------------------
417 // helpers
418 // ----------------------------------------------------------------------------
419
420 int BookWidgetsPage::GetTextValue(wxTextCtrl *text) const
421 {
422 long pos = -1;
423
424 if ( !text || !text->GetValue().ToLong(&pos) )
425 pos = -1;
426
427 return (int)pos;
428 }
429
430 int BookWidgetsPage::GetIconIndex() const
431 {
432 #if USE_ICONS_IN_BOOK
433 if ( m_imageList )
434 {
435 int nImages = m_imageList->GetImageCount();
436 if ( nImages > 0 )
437 {
438 return m_book->GetPageCount() % nImages;
439 }
440 }
441 #endif // USE_ICONS_IN_BOOK
442
443 return -1;
444 }
445
446 wxWindow *BookWidgetsPage::CreateNewPage()
447 {
448 return new wxTextCtrl(m_book, wxID_ANY, wxT("I'm a book page"));
449 }
450
451 // ----------------------------------------------------------------------------
452 // event handlers
453 // ----------------------------------------------------------------------------
454
455 void BookWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
456 {
457 Reset();
458
459 RecreateBook();
460 }
461
462 void BookWidgetsPage::OnButtonDeleteAll(wxCommandEvent& WXUNUSED(event))
463 {
464 m_book->DeleteAllPages();
465 }
466
467 void BookWidgetsPage::OnButtonSelectPage(wxCommandEvent& WXUNUSED(event))
468 {
469 int pos = GetTextValue(m_textSelect);
470 wxCHECK_RET( IsValidValue(pos), wxT("button should be disabled") );
471
472 m_book->SetSelection(pos);
473 }
474
475 void BookWidgetsPage::OnButtonAddPage(wxCommandEvent& WXUNUSED(event))
476 {
477 m_book->AddPage(CreateNewPage(), wxT("Added page"), false,
478 GetIconIndex());
479 }
480
481 void BookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event))
482 {
483 int pos = GetTextValue(m_textInsert);
484 wxCHECK_RET( IsValidValue(pos), wxT("button should be disabled") );
485
486 m_book->InsertPage(pos, CreateNewPage(), wxT("Inserted page"), false,
487 GetIconIndex());
488 }
489
490 void BookWidgetsPage::OnButtonRemovePage(wxCommandEvent& WXUNUSED(event))
491 {
492 int pos = GetTextValue(m_textRemove);
493 wxCHECK_RET( IsValidValue(pos), wxT("button should be disabled") );
494
495 m_book->DeletePage(pos);
496 }
497
498 void BookWidgetsPage::OnUpdateUISelectButton(wxUpdateUIEvent& event)
499 {
500 event.Enable( IsValidValue(GetTextValue(m_textSelect)) );
501 }
502
503 void BookWidgetsPage::OnUpdateUIInsertButton(wxUpdateUIEvent& event)
504 {
505 event.Enable( IsValidValue(GetTextValue(m_textInsert)) );
506 }
507
508 void BookWidgetsPage::OnUpdateUIRemoveButton(wxUpdateUIEvent& event)
509 {
510 event.Enable( IsValidValue(GetTextValue(m_textRemove)) );
511 }
512
513 void BookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
514 {
515 if(m_chkImages && m_radioOrient)
516 event.Enable( !m_chkImages->GetValue() ||
517 m_radioOrient->GetSelection() != wxBK_TOP );
518 }
519
520 void BookWidgetsPage::OnUpdateUINumPagesText(wxUpdateUIEvent& event)
521 {
522 if(m_book)
523 event.SetText( wxString::Format(wxT("%u"), unsigned(m_book->GetPageCount())) );
524 }
525
526 void BookWidgetsPage::OnUpdateUICurSelectText(wxUpdateUIEvent& event)
527 {
528 if(m_book)
529 event.SetText( wxString::Format(wxT("%d"), m_book->GetSelection()) );
530 }
531
532 void BookWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
533 {
534 RecreateBook();
535 }
536
537 #if wxUSE_NOTEBOOK
538
539 #include "icons/notebook.xpm"
540 #include "wx/notebook.h"
541
542 // ----------------------------------------------------------------------------
543 // NotebookWidgetsPage
544 // ----------------------------------------------------------------------------
545
546 class NotebookWidgetsPage : public BookWidgetsPage
547 {
548 public:
549 NotebookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
550 : BookWidgetsPage(book, imaglist, notebook_xpm)
551 {
552 RecreateBook();
553 }
554 virtual ~NotebookWidgetsPage() {}
555
556 protected:
557
558 // event handlers
559 void OnPageChanging(wxNotebookEvent& event);
560 void OnPageChanged(wxNotebookEvent& event);
561
562 // (re)create book
563 virtual wxBookCtrlBase *CreateBook(long flags)
564 {
565 return new wxNotebook(this, BookPage_Book,
566 wxDefaultPosition, wxDefaultSize,
567 flags);
568 }
569
570 private:
571 DECLARE_EVENT_TABLE()
572 DECLARE_WIDGETS_PAGE(NotebookWidgetsPage)
573 };
574
575 // ----------------------------------------------------------------------------
576 // event table
577 // ----------------------------------------------------------------------------
578
579 BEGIN_EVENT_TABLE(NotebookWidgetsPage, BookWidgetsPage)
580 EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY, NotebookWidgetsPage::OnPageChanging)
581 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, NotebookWidgetsPage::OnPageChanged)
582 END_EVENT_TABLE()
583
584 #if defined(__WXUNIVERSAL__)
585 #define FAMILY_CTRLS UNIVERSAL_CTRLS
586 #elif defined(__WXMOTIF__)
587 #define FAMILY_CTRLS GENERIC_CTRLS
588 #else
589 #define FAMILY_CTRLS NATIVE_CTRLS
590 #endif
591
592 IMPLEMENT_WIDGETS_PAGE(NotebookWidgetsPage, wxT("Notebook"),
593 FAMILY_CTRLS | BOOK_CTRLS
594 );
595
596 void NotebookWidgetsPage::OnPageChanging(wxNotebookEvent& event)
597 {
598 wxLogMessage(wxT("Notebook page changing from %d to %d (currently %d)."),
599 event.GetOldSelection(),
600 event.GetSelection(),
601 m_book->GetSelection());
602
603 event.Skip();
604 }
605
606 void NotebookWidgetsPage::OnPageChanged(wxNotebookEvent& event)
607 {
608 wxLogMessage(wxT("Notebook page changed from %d to %d (currently %d)."),
609 event.GetOldSelection(),
610 event.GetSelection(),
611 m_book->GetSelection());
612
613 event.Skip();
614 }
615
616 #endif // wxUSE_NOTEBOOK
617
618 #if wxUSE_LISTBOOK
619
620 #include "icons/listbook.xpm"
621 #include "wx/listbook.h"
622
623 // ----------------------------------------------------------------------------
624 // ListbookWidgetsPage
625 // ----------------------------------------------------------------------------
626
627 class ListbookWidgetsPage : public BookWidgetsPage
628 {
629 public:
630 ListbookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
631 : BookWidgetsPage(book, imaglist, listbook_xpm)
632 {
633 RecreateBook();
634 }
635 virtual ~ListbookWidgetsPage() {}
636
637 protected:
638
639 // event handlers
640 void OnPageChanging(wxListbookEvent& event);
641 void OnPageChanged(wxListbookEvent& event);
642
643 // (re)create book
644 virtual wxBookCtrlBase *CreateBook(long flags)
645 {
646 return new wxListbook(this, BookPage_Book,
647 wxDefaultPosition, wxDefaultSize,
648 flags);
649 }
650
651 private:
652 DECLARE_EVENT_TABLE()
653 DECLARE_WIDGETS_PAGE(ListbookWidgetsPage)
654 };
655
656 // ----------------------------------------------------------------------------
657 // event table
658 // ----------------------------------------------------------------------------
659
660 BEGIN_EVENT_TABLE(ListbookWidgetsPage, BookWidgetsPage)
661 EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY, ListbookWidgetsPage::OnPageChanging)
662 EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY, ListbookWidgetsPage::OnPageChanged)
663 END_EVENT_TABLE()
664
665 IMPLEMENT_WIDGETS_PAGE(ListbookWidgetsPage, wxT("Listbook"),
666 GENERIC_CTRLS | BOOK_CTRLS
667 );
668
669 void ListbookWidgetsPage::OnPageChanging(wxListbookEvent& event)
670 {
671 wxLogMessage(wxT("Listbook page changing from %d to %d (currently %d)."),
672 event.GetOldSelection(),
673 event.GetSelection(),
674 m_book->GetSelection());
675
676 event.Skip();
677 }
678
679 void ListbookWidgetsPage::OnPageChanged(wxListbookEvent& event)
680 {
681 wxLogMessage(wxT("Listbook page changed from %d to %d (currently %d)."),
682 event.GetOldSelection(),
683 event.GetSelection(),
684 m_book->GetSelection());
685
686 event.Skip();
687 }
688
689 #endif // wxUSE_LISTBOOK
690
691 #if wxUSE_CHOICEBOOK
692
693 #include "icons/choicebk.xpm"
694 #include "wx/choicebk.h"
695
696 // ----------------------------------------------------------------------------
697 // ChoicebookWidgetsPage
698 // ----------------------------------------------------------------------------
699
700 class ChoicebookWidgetsPage : public BookWidgetsPage
701 {
702 public:
703 ChoicebookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
704 : BookWidgetsPage(book, imaglist, choicebk_xpm)
705 {
706 RecreateBook();
707 }
708 virtual ~ChoicebookWidgetsPage() {}
709
710 protected:
711
712 // event handlers
713 void OnPageChanging(wxChoicebookEvent& event);
714 void OnPageChanged(wxChoicebookEvent& event);
715
716 // (re)create book
717 virtual wxBookCtrlBase *CreateBook(long flags)
718 {
719 return new wxChoicebook(this, BookPage_Book,
720 wxDefaultPosition, wxDefaultSize,
721 flags);
722 }
723
724 private:
725 DECLARE_EVENT_TABLE()
726 DECLARE_WIDGETS_PAGE(ChoicebookWidgetsPage)
727 };
728
729 // ----------------------------------------------------------------------------
730 // event table
731 // ----------------------------------------------------------------------------
732
733 BEGIN_EVENT_TABLE(ChoicebookWidgetsPage, BookWidgetsPage)
734 EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY, ChoicebookWidgetsPage::OnPageChanging)
735 EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY, ChoicebookWidgetsPage::OnPageChanged)
736 END_EVENT_TABLE()
737
738 IMPLEMENT_WIDGETS_PAGE(ChoicebookWidgetsPage, wxT("Choicebook"),
739 GENERIC_CTRLS | BOOK_CTRLS
740 );
741
742 void ChoicebookWidgetsPage::OnPageChanging(wxChoicebookEvent& event)
743 {
744 wxLogMessage(wxT("Choicebook page changing from %d to %d (currently %d)."),
745 event.GetOldSelection(),
746 event.GetSelection(),
747 m_book->GetSelection());
748
749 event.Skip();
750 }
751
752 void ChoicebookWidgetsPage::OnPageChanged(wxChoicebookEvent& event)
753 {
754 wxLogMessage(wxT("Choicebook page changed from %d to %d (currently %d)."),
755 event.GetOldSelection(),
756 event.GetSelection(),
757 m_book->GetSelection());
758
759 event.Skip();
760 }
761
762 #endif // wxUSE_CHOICEBOOK
763
764 #endif // wxUSE_BOOKCTRL