]>
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, char* icon[]); | |
90 | virtual ~BookWidgetsPage(); | |
91 | ||
92 | virtual wxControl *GetWidget() const { return m_book; } | |
93 | virtual void RecreateWidget() { RecreateBook(); } | |
94 | ||
95 | protected: | |
96 | // event handlers | |
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 | ||
115 | // reset book parameters | |
116 | void Reset(); | |
117 | ||
118 | // (re)create book | |
119 | void RecreateBook(); | |
120 | virtual wxBookCtrlBase *CreateBook(long flags) = 0; | |
121 | ||
122 | #if USE_ICONS_IN_BOOK | |
123 | // create or destroy the image list | |
124 | void CreateImageList(); | |
125 | #endif // USE_ICONS_IN_BOOK | |
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 | ||
136 | // is the value in range? | |
137 | bool IsValidValue(int val) const | |
138 | { return (val >= 0) && (val < (int) m_book->GetPageCount()); } | |
139 | ||
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 | ||
152 | // the book itself and the sizer it is in | |
153 | wxBookCtrlBase *m_book; | |
154 | wxSizer *m_sizerBook; | |
155 | ||
156 | #if USE_ICONS_IN_BOOK | |
157 | // the image list for our book | |
158 | wxImageList *m_imageList; | |
159 | #endif // USE_ICONS_IN_BOOK | |
160 | ||
161 | private: | |
162 | DECLARE_EVENT_TABLE() | |
163 | }; | |
164 | ||
165 | // ---------------------------------------------------------------------------- | |
166 | // event tables | |
167 | // ---------------------------------------------------------------------------- | |
168 | ||
169 | BEGIN_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) | |
176 | ||
177 | EVT_UPDATE_UI(BookPage_NumPagesText, BookWidgetsPage::OnUpdateUINumPagesText) | |
178 | EVT_UPDATE_UI(BookPage_CurSelectText, BookWidgetsPage::OnUpdateUICurSelectText) | |
179 | ||
180 | EVT_UPDATE_UI(BookPage_SelectPage, BookWidgetsPage::OnUpdateUISelectButton) | |
181 | EVT_UPDATE_UI(BookPage_InsertPage, BookWidgetsPage::OnUpdateUIInsertButton) | |
182 | EVT_UPDATE_UI(BookPage_RemovePage, BookWidgetsPage::OnUpdateUIRemoveButton) | |
183 | ||
184 | EVT_CHECKBOX(wxID_ANY, BookWidgetsPage::OnCheckOrRadioBox) | |
185 | EVT_RADIOBOX(wxID_ANY, BookWidgetsPage::OnCheckOrRadioBox) | |
186 | END_EVENT_TABLE() | |
187 | ||
188 | // ============================================================================ | |
189 | // implementation | |
190 | // ============================================================================ | |
191 | ||
192 | BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, char* icon[]) | |
193 | :WidgetsPage(book, imaglist, icon) | |
194 | { | |
195 | // init everything | |
196 | m_chkImages = NULL; | |
197 | #if USE_ICONS_IN_BOOK | |
198 | m_imageList = NULL; | |
199 | #endif // USE_ICONS_IN_BOOK | |
200 | ||
201 | m_book = NULL; | |
202 | m_sizerBook = (wxSizer *)NULL; | |
203 | ||
204 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
205 | ||
206 | // left pane | |
207 | wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style")); | |
208 | ||
209 | // must be in sync with Orient enum | |
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, | |
217 | _T("forgot to update something") ); | |
218 | ||
219 | m_chkImages = new wxCheckBox(this, wxID_ANY, _T("Show &images")); | |
220 | m_radioOrient = new wxRadioBox(this, wxID_ANY, _T("&Tab orientation"), | |
221 | wxDefaultPosition, wxDefaultSize, | |
222 | orientations, 1, wxRA_SPECIFY_COLS); | |
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 | ||
230 | wxButton *btn = new wxButton(this, BookPage_Reset, _T("&Reset")); | |
231 | sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); | |
232 | ||
233 | // middle pane | |
234 | wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, _T("&Contents")); | |
235 | wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); | |
236 | ||
237 | wxTextCtrl *text; | |
238 | wxSizer *sizerRow = CreateSizerWithTextAndLabel(_T("Number of pages: "), | |
239 | BookPage_NumPagesText, | |
240 | &text); | |
241 | text->SetEditable(false); | |
242 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
243 | ||
244 | sizerRow = CreateSizerWithTextAndLabel(_T("Current selection: "), | |
245 | BookPage_CurSelectText, | |
246 | &text); | |
247 | text->SetEditable(false); | |
248 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
249 | ||
250 | sizerRow = CreateSizerWithTextAndButton(BookPage_SelectPage, | |
251 | _T("&Select page"), | |
252 | BookPage_SelectText, | |
253 | &m_textSelect); | |
254 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
255 | ||
256 | btn = new wxButton(this, BookPage_AddPage, _T("&Add page")); | |
257 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); | |
258 | ||
259 | sizerRow = CreateSizerWithTextAndButton(BookPage_InsertPage, | |
260 | _T("&Insert page at"), | |
261 | BookPage_InsertText, | |
262 | &m_textInsert); | |
263 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
264 | ||
265 | sizerRow = CreateSizerWithTextAndButton(BookPage_RemovePage, | |
266 | _T("&Remove page"), | |
267 | BookPage_RemoveText, | |
268 | &m_textRemove); | |
269 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
270 | ||
271 | btn = new wxButton(this, BookPage_DeleteAll, _T("&Delete All")); | |
272 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); | |
273 | ||
274 | // right pane | |
275 | m_sizerBook = new wxBoxSizer(wxHORIZONTAL); | |
276 | ||
277 | // the 3 panes compose the window | |
278 | sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); | |
279 | sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10); | |
280 | sizerTop->Add(m_sizerBook, 1, wxGROW | (wxALL & ~wxRIGHT), 10); | |
281 | ||
282 | // final initializations | |
283 | Reset(); | |
284 | #if USE_ICONS_IN_BOOK | |
285 | CreateImageList(); | |
286 | #endif // USE_ICONS_IN_BOOK | |
287 | ||
288 | SetSizer(sizerTop); | |
289 | ||
290 | sizerTop->Fit(this); | |
291 | } | |
292 | ||
293 | BookWidgetsPage::~BookWidgetsPage() | |
294 | { | |
295 | #if USE_ICONS_IN_BOOK | |
296 | delete m_imageList; | |
297 | #endif // USE_ICONS_IN_BOOK | |
298 | } | |
299 | ||
300 | // ---------------------------------------------------------------------------- | |
301 | // operations | |
302 | // ---------------------------------------------------------------------------- | |
303 | ||
304 | void BookWidgetsPage::Reset() | |
305 | { | |
306 | m_chkImages->SetValue(true); | |
307 | m_radioOrient->SetSelection(Orient_Top); | |
308 | } | |
309 | ||
310 | #if USE_ICONS_IN_BOOK | |
311 | void BookWidgetsPage::CreateImageList() | |
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); | |
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)); | |
324 | } | |
325 | ||
326 | if ( m_book ) | |
327 | m_book->SetImageList(m_imageList); | |
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 | |
339 | // it would be logical if this removed the image list from book, under | |
340 | // MSW it crashes instead - FIXME | |
341 | } | |
342 | #endif // USE_ICONS_IN_BOOK | |
343 | ||
344 | void BookWidgetsPage::RecreateBook() | |
345 | { | |
346 | int flags = ms_defaultFlags; | |
347 | switch ( m_radioOrient->GetSelection() ) | |
348 | { | |
349 | default: | |
350 | wxFAIL_MSG( _T("unknown orientation") ); | |
351 | // fall through | |
352 | ||
353 | case Orient_Top: | |
354 | flags |= wxBK_TOP; | |
355 | break; | |
356 | ||
357 | case Orient_Bottom: | |
358 | flags |= wxBK_BOTTOM; | |
359 | break; | |
360 | ||
361 | case Orient_Left: | |
362 | flags |= wxBK_LEFT; | |
363 | break; | |
364 | ||
365 | case Orient_Right: | |
366 | flags |= wxBK_RIGHT; | |
367 | break; | |
368 | } | |
369 | ||
370 | wxBookCtrlBase *oldBook = m_book; | |
371 | ||
372 | m_book = CreateBook(flags); | |
373 | ||
374 | #if USE_ICONS_IN_BOOK | |
375 | CreateImageList(); | |
376 | #endif // USE_ICONS_IN_BOOK | |
377 | ||
378 | if ( oldBook ) | |
379 | { | |
380 | const int sel = oldBook->GetSelection(); | |
381 | ||
382 | const int count = oldBook->GetPageCount(); | |
383 | ||
384 | // recreate the pages | |
385 | for ( int n = 0; n < count; n++ ) | |
386 | { | |
387 | m_book->AddPage(CreateNewPage(), | |
388 | oldBook->GetPageText(n), | |
389 | false, | |
390 | m_chkImages->GetValue() ? | |
391 | GetIconIndex() : -1); | |
392 | } | |
393 | ||
394 | m_sizerBook->Detach( oldBook ); | |
395 | delete oldBook; | |
396 | ||
397 | // restore selection | |
398 | if ( sel != -1 ) | |
399 | { | |
400 | m_book->SetSelection(sel); | |
401 | } | |
402 | } | |
403 | ||
404 | m_sizerBook->Add(m_book, 1, wxGROW | wxALL, 5); | |
405 | m_sizerBook->SetMinSize(150, 0); | |
406 | m_sizerBook->Layout(); | |
407 | } | |
408 | ||
409 | // ---------------------------------------------------------------------------- | |
410 | // helpers | |
411 | // ---------------------------------------------------------------------------- | |
412 | ||
413 | int BookWidgetsPage::GetTextValue(wxTextCtrl *text) const | |
414 | { | |
415 | long pos; | |
416 | if ( !text->GetValue().ToLong(&pos) ) | |
417 | pos = -1; | |
418 | ||
419 | return (int)pos; | |
420 | } | |
421 | ||
422 | int BookWidgetsPage::GetIconIndex() const | |
423 | { | |
424 | #if USE_ICONS_IN_BOOK | |
425 | if ( m_imageList ) | |
426 | { | |
427 | int nImages = m_imageList->GetImageCount(); | |
428 | if ( nImages > 0 ) | |
429 | { | |
430 | return m_book->GetPageCount() % nImages; | |
431 | } | |
432 | } | |
433 | #endif // USE_ICONS_IN_BOOK | |
434 | ||
435 | return -1; | |
436 | } | |
437 | ||
438 | wxWindow *BookWidgetsPage::CreateNewPage() | |
439 | { | |
440 | return new wxTextCtrl(m_book, wxID_ANY, _T("I'm a book page")); | |
441 | } | |
442 | ||
443 | // ---------------------------------------------------------------------------- | |
444 | // event handlers | |
445 | // ---------------------------------------------------------------------------- | |
446 | ||
447 | void BookWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
448 | { | |
449 | Reset(); | |
450 | ||
451 | RecreateBook(); | |
452 | } | |
453 | ||
454 | void BookWidgetsPage::OnButtonDeleteAll(wxCommandEvent& WXUNUSED(event)) | |
455 | { | |
456 | m_book->DeleteAllPages(); | |
457 | } | |
458 | ||
459 | void BookWidgetsPage::OnButtonSelectPage(wxCommandEvent& WXUNUSED(event)) | |
460 | { | |
461 | int pos = GetTextValue(m_textSelect); | |
462 | wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") ); | |
463 | ||
464 | m_book->SetSelection(pos); | |
465 | } | |
466 | ||
467 | void BookWidgetsPage::OnButtonAddPage(wxCommandEvent& WXUNUSED(event)) | |
468 | { | |
469 | m_book->AddPage(CreateNewPage(), _T("Added page"), false, | |
470 | GetIconIndex()); | |
471 | } | |
472 | ||
473 | void BookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event)) | |
474 | { | |
475 | int pos = GetTextValue(m_textInsert); | |
476 | wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") ); | |
477 | ||
478 | m_book->InsertPage(pos, CreateNewPage(), _T("Inserted page"), false, | |
479 | GetIconIndex()); | |
480 | } | |
481 | ||
482 | void BookWidgetsPage::OnButtonRemovePage(wxCommandEvent& WXUNUSED(event)) | |
483 | { | |
484 | int pos = GetTextValue(m_textRemove); | |
485 | wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") ); | |
486 | ||
487 | m_book->DeletePage(pos); | |
488 | } | |
489 | ||
490 | void BookWidgetsPage::OnUpdateUISelectButton(wxUpdateUIEvent& event) | |
491 | { | |
492 | event.Enable( IsValidValue(GetTextValue(m_textSelect)) ); | |
493 | } | |
494 | ||
495 | void BookWidgetsPage::OnUpdateUIInsertButton(wxUpdateUIEvent& event) | |
496 | { | |
497 | event.Enable( IsValidValue(GetTextValue(m_textInsert)) ); | |
498 | } | |
499 | ||
500 | void BookWidgetsPage::OnUpdateUIRemoveButton(wxUpdateUIEvent& event) | |
501 | { | |
502 | event.Enable( IsValidValue(GetTextValue(m_textRemove)) ); | |
503 | } | |
504 | ||
505 | void BookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) | |
506 | { | |
507 | event.Enable( !m_chkImages->GetValue() || | |
508 | m_radioOrient->GetSelection() != wxBK_TOP ); | |
509 | } | |
510 | ||
511 | void BookWidgetsPage::OnUpdateUINumPagesText(wxUpdateUIEvent& event) | |
512 | { | |
513 | event.SetText( wxString::Format(_T("%d"), m_book->GetPageCount()) ); | |
514 | } | |
515 | ||
516 | void BookWidgetsPage::OnUpdateUICurSelectText(wxUpdateUIEvent& event) | |
517 | { | |
518 | event.SetText( wxString::Format(_T("%d"), m_book->GetSelection()) ); | |
519 | } | |
520 | ||
521 | void BookWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) | |
522 | { | |
523 | RecreateBook(); | |
524 | } | |
525 | ||
526 | #if wxUSE_NOTEBOOK | |
527 | ||
528 | #include "icons/notebook.xpm" | |
529 | #include "wx/notebook.h" | |
530 | ||
531 | // ---------------------------------------------------------------------------- | |
532 | // NotebookWidgetsPage | |
533 | // ---------------------------------------------------------------------------- | |
534 | ||
535 | class NotebookWidgetsPage : public BookWidgetsPage | |
536 | { | |
537 | public: | |
538 | NotebookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) | |
539 | : BookWidgetsPage(book, imaglist, notebook_xpm) | |
540 | { | |
541 | RecreateBook(); | |
542 | } | |
543 | virtual ~NotebookWidgetsPage() {} | |
544 | ||
545 | protected: | |
546 | ||
547 | // event handlers | |
548 | void OnPageChanging(wxNotebookEvent& event); | |
549 | void OnPageChanged(wxNotebookEvent& event); | |
550 | ||
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 | ||
560 | private: | |
561 | DECLARE_EVENT_TABLE() | |
562 | DECLARE_WIDGETS_PAGE(NotebookWidgetsPage) | |
563 | }; | |
564 | ||
565 | // ---------------------------------------------------------------------------- | |
566 | // event table | |
567 | // ---------------------------------------------------------------------------- | |
568 | ||
569 | BEGIN_EVENT_TABLE(NotebookWidgetsPage, BookWidgetsPage) | |
570 | EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY, NotebookWidgetsPage::OnPageChanging) | |
571 | EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, NotebookWidgetsPage::OnPageChanged) | |
572 | END_EVENT_TABLE() | |
573 | ||
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 | ||
582 | IMPLEMENT_WIDGETS_PAGE(NotebookWidgetsPage, _T("Notebook"), | |
583 | FAMILY_CTRLS | BOOK_CTRLS | |
584 | ); | |
585 | ||
586 | void 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 | ||
596 | void 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 | ||
606 | #endif // wxUSE_NOTEBOOK | |
607 | ||
608 | #if wxUSE_LISTBOOK | |
609 | ||
610 | #include "icons/listbook.xpm" | |
611 | #include "wx/listbook.h" | |
612 | ||
613 | // ---------------------------------------------------------------------------- | |
614 | // ListbookWidgetsPage | |
615 | // ---------------------------------------------------------------------------- | |
616 | ||
617 | class ListbookWidgetsPage : public BookWidgetsPage | |
618 | { | |
619 | public: | |
620 | ListbookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) | |
621 | : BookWidgetsPage(book, imaglist, listbook_xpm) | |
622 | { | |
623 | RecreateBook(); | |
624 | } | |
625 | virtual ~ListbookWidgetsPage() {} | |
626 | ||
627 | protected: | |
628 | ||
629 | // event handlers | |
630 | void OnPageChanging(wxListbookEvent& event); | |
631 | void OnPageChanged(wxListbookEvent& event); | |
632 | ||
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 | ||
642 | private: | |
643 | DECLARE_EVENT_TABLE() | |
644 | DECLARE_WIDGETS_PAGE(ListbookWidgetsPage) | |
645 | }; | |
646 | ||
647 | // ---------------------------------------------------------------------------- | |
648 | // event table | |
649 | // ---------------------------------------------------------------------------- | |
650 | ||
651 | BEGIN_EVENT_TABLE(ListbookWidgetsPage, BookWidgetsPage) | |
652 | EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY, ListbookWidgetsPage::OnPageChanging) | |
653 | EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY, ListbookWidgetsPage::OnPageChanged) | |
654 | END_EVENT_TABLE() | |
655 | ||
656 | IMPLEMENT_WIDGETS_PAGE(ListbookWidgetsPage, _T("Listbook"), | |
657 | GENERIC_CTRLS | BOOK_CTRLS | |
658 | ); | |
659 | ||
660 | void 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 | ||
670 | void 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 | ||
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 | ||
691 | class ChoicebookWidgetsPage : public BookWidgetsPage | |
692 | { | |
693 | public: | |
694 | ChoicebookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) | |
695 | : BookWidgetsPage(book, imaglist, choicebk_xpm) | |
696 | { | |
697 | RecreateBook(); | |
698 | } | |
699 | virtual ~ChoicebookWidgetsPage() {} | |
700 | ||
701 | protected: | |
702 | ||
703 | // event handlers | |
704 | void OnPageChanging(wxChoicebookEvent& event); | |
705 | void OnPageChanged(wxChoicebookEvent& event); | |
706 | ||
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 | ||
716 | private: | |
717 | DECLARE_EVENT_TABLE() | |
718 | DECLARE_WIDGETS_PAGE(ChoicebookWidgetsPage) | |
719 | }; | |
720 | ||
721 | // ---------------------------------------------------------------------------- | |
722 | // event table | |
723 | // ---------------------------------------------------------------------------- | |
724 | ||
725 | BEGIN_EVENT_TABLE(ChoicebookWidgetsPage, BookWidgetsPage) | |
726 | EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY, ChoicebookWidgetsPage::OnPageChanging) | |
727 | EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY, ChoicebookWidgetsPage::OnPageChanged) | |
728 | END_EVENT_TABLE() | |
729 | ||
730 | IMPLEMENT_WIDGETS_PAGE(ChoicebookWidgetsPage, _T("Choicebook"), | |
731 | GENERIC_CTRLS | BOOK_CTRLS | |
732 | ); | |
733 | ||
734 | void 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 | ||
744 | void 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 | ||
754 | #endif // wxUSE_CHOICEBOOK | |
755 | ||
756 | #endif // wxUSE_BOOKCTRL |