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