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