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