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