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