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