]> git.saurik.com Git - wxWidgets.git/blame - samples/notebook/notebook.cpp
Add dll.a to the extensions search for by WX_PATH_FIND_LIBRARIES, for the
[wxWidgets.git] / samples / notebook / notebook.cpp
CommitLineData
0b4d4194 1/////////////////////////////////////////////////////////////////////////////
c1dfe277
JS
2// Name: samples/notebook/notebook.cpp
3// Purpose: a sample demonstrating notebook usage
0b4d4194 4// Author: Julian Smart
c1dfe277 5// Modified by: Dimitri Schoolwerth
0b4d4194
JS
6// Created: 26/10/98
7// RCS-ID: $Id$
be5a51fb 8// Copyright: (c) 1998-2002 wxWidgets team
c1dfe277 9// License: wxWindows license
0b4d4194
JS
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
d22699b5 16 #pragma hdrstop
0b4d4194
JS
17#endif
18
19#ifndef WX_PRECOMP
d22699b5 20 #include "wx/wx.h"
0b4d4194
JS
21#endif
22
c1dfe277
JS
23#include "wx/imaglist.h"
24#include "wx/artprov.h"
b2f757f9 25#include "notebook.h"
0b4d4194 26
d52f6c4e
VZ
27#if !defined(__WXMSW__) && !defined(__WXPM__)
28 #include "../sample.xpm"
29#endif
30
0b4d4194
JS
31IMPLEMENT_APP(MyApp)
32
477350ce 33bool MyApp::OnInit()
0b4d4194 34{
c1dfe277
JS
35 // Create the main window
36 MyFrame *frame = new MyFrame( wxT("Notebook sample") );
37
38 // Problem with generic wxNotebook implementation whereby it doesn't size
39 // properly unless you set the size again
3a5bcc4d 40#if defined(__WXMOTIF__)
c1dfe277
JS
41 int width, height;
42 frame->GetSize(& width, & height);
422d0ff0 43 frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height);
5dcf05ae
JS
44#endif
45
c1dfe277
JS
46 frame->Show();
47
1cfac5b8 48 return true;
0b4d4194
JS
49}
50
61c083e7 51wxPanel *CreateUserCreatedPage(wxBookCtrlBase *parent)
0b4d4194 52{
9133965e 53 wxPanel *panel = new wxPanel(parent);
76645ab3 54
1cfac5b8
WS
55 (void) new wxButton( panel, wxID_ANY, wxT("Button"),
56 wxPoint(10, 10), wxDefaultSize );
76645ab3
VZ
57
58 return panel;
59}
60
61c083e7 61wxPanel *CreateRadioButtonsPage(wxBookCtrlBase *parent)
76645ab3 62{
9133965e 63 wxPanel *panel = new wxPanel(parent);
c1dfe277
JS
64
65 wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
66 wxT("Sabre-toothed tiger"), wxT("T Rex") };
76645ab3 67
1cfac5b8 68 wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose one"),
c1dfe277
JS
69 wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS);
70
71 wxString computers[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"),
72 wxT("Another") };
76645ab3 73
1cfac5b8 74 wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY,
c1dfe277
JS
75 wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize,
76 4, computers, 0, wxRA_SPECIFY_COLS);
0b4d4194 77
76645ab3 78 wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
c1dfe277
JS
79 sizerPanel->Add(radiobox1, 2, wxEXPAND);
80 sizerPanel->Add(radiobox2, 1, wxEXPAND);
81 panel->SetSizer(sizerPanel);
82
76645ab3
VZ
83 return panel;
84}
c1dfe277 85
61c083e7 86wxPanel *CreateVetoPage(wxBookCtrlBase *parent)
76645ab3 87{
9133965e 88 wxPanel *panel = new wxPanel(parent);
c1dfe277 89
1cfac5b8 90 (void) new wxStaticText( panel, wxID_ANY,
c1dfe277 91 wxT("This page intentionally left blank"), wxPoint(10, 10) );
c1dfe277 92
76645ab3
VZ
93 return panel;
94}
95
61c083e7 96wxPanel *CreateBigButtonPage(wxBookCtrlBase *parent)
76645ab3 97{
9133965e 98 wxPanel *panel = new wxPanel(parent);
c1dfe277 99
ed420f6d 100 wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button"));
c1dfe277 101
76645ab3 102 wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
c1dfe277
JS
103 sizerPanel->Add(buttonBig, 1, wxEXPAND);
104 panel->SetSizer(sizerPanel);
105
76645ab3
VZ
106 return panel;
107}
108
c1dfe277 109
61c083e7 110wxPanel *CreateInsertPage(wxBookCtrlBase *parent)
76645ab3 111{
9133965e 112 wxPanel *panel = new wxPanel(parent);
c1dfe277 113
c1dfe277 114 panel->SetBackgroundColour( wxColour( wxT("MAROON") ) );
1cfac5b8 115 (void) new wxStaticText( panel, wxID_ANY,
c1dfe277 116 wxT("This page has been inserted, not added."), wxPoint(10, 10) );
c1dfe277 117
76645ab3
VZ
118 return panel;
119}
120
61c083e7 121int GetIconIndex(wxBookCtrlBase* bookCtrl)
76645ab3 122{
9133965e
WS
123 if (bookCtrl && bookCtrl->GetImageList())
124 {
125 int nImages = bookCtrl->GetImageList()->GetImageCount();
126 if (nImages > 0)
127 {
128 return bookCtrl->GetPageCount() % nImages;
129 }
130 }
76645ab3 131
9133965e
WS
132 return -1;
133}
76645ab3 134
61c083e7 135void CreateInitialPages(wxBookCtrlBase *parent)
9133965e
WS
136{
137 // Create and add some panels to the notebook
138
139 wxPanel *panel = CreateRadioButtonsPage(parent);
140 parent->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(parent) );
c1dfe277 141
9133965e
WS
142 panel = CreateVetoPage(parent);
143 parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) );
c1dfe277 144
9133965e
WS
145 panel = CreateBigButtonPage(parent);
146 parent->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(parent) );
76645ab3 147
9133965e
WS
148 panel = CreateInsertPage(parent);
149 parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) );
76645ab3 150
9133965e 151 parent->SetSelection(1);
c1dfe277
JS
152}
153
61c083e7 154wxPanel *CreatePage(wxBookCtrlBase *parent, const wxString&pageName)
0b4d4194 155{
9133965e
WS
156 if
157 (
158 pageName.Contains(INSERTED_PAGE_NAME)
159 || pageName.Contains(ADDED_PAGE_NAME)
160 )
c1dfe277 161 {
9133965e 162 return CreateUserCreatedPage(parent);
c1dfe277
JS
163 }
164
9133965e
WS
165 if (pageName == I_WAS_INSERTED_PAGE_NAME)
166 {
167 return CreateInsertPage(parent);
168 }
169
170 if (pageName == VETO_PAGE_NAME)
171 {
172 return CreateVetoPage(parent);
173 }
174
175 if (pageName == RADIOBUTTONS_PAGE_NAME)
176 {
177 return CreateRadioButtonsPage(parent);
178 }
179
180
181 if (pageName == MAXIMIZED_BUTTON_PAGE_NAME)
182 {
183 return CreateBigButtonPage(parent);
184 }
185
186 wxFAIL;
187
188 return (wxPanel *) NULL;
0b4d4194
JS
189}
190
c1dfe277
JS
191MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
192 long style)
1cfac5b8 193 : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style)
0b4d4194 194{
53d09d55 195#if wxUSE_NOTEBOOK
9133965e 196 m_type = ID_BOOK_NOTEBOOK;
53d09d55
WS
197#elif wxUSE_CHOICEBOOK
198 m_type = ID_BOOK_CHOICEBOOK;
199#elif wxUSE_LISTBOOK
200 m_type = ID_BOOK_LISTBOOK;
201#elif
202 #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
203#endif
204
9133965e
WS
205 m_orient = ID_ORIENT_DEFAULT;
206 m_chkShowImages = true;
207 m_multi = false;
208
d52f6c4e 209 SetIcon(wxICON(sample));
9133965e 210
d52f6c4e 211 // menu of the sample
9133965e
WS
212 wxMenu *menuType = new wxMenu;
213#if wxUSE_NOTEBOOK
214 menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, wxT("&Notebook\tCtrl-1"));
215#endif
216#if wxUSE_LISTBOOK
217 menuType->AppendRadioItem(ID_BOOK_LISTBOOK, wxT("&Listbook\tCtrl-2"));
218#endif
219#if wxUSE_CHOICEBOOK
220 menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3"));
221#endif
53d09d55 222 menuType->Check(m_type, true);
9133965e
WS
223
224 wxMenu *menuOrient = new wxMenu;
225 menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tCtrl-4"));
226 menuOrient->AppendRadioItem(ID_ORIENT_TOP, wxT("&Top\tCtrl-5"));
227 menuOrient->AppendRadioItem(ID_ORIENT_BOTTOM, wxT("&Bottom\tCtrl-6"));
228 menuOrient->AppendRadioItem(ID_ORIENT_LEFT, wxT("&Left\tCtrl-7"));
229 menuOrient->AppendRadioItem(ID_ORIENT_RIGHT, wxT("&Right\tCtrl-8"));
230
231 wxMenu *menuDo = new wxMenu;
c0c99785
WS
232 menuDo->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A"));
233 menuDo->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I"));
234 menuDo->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D"));
235 menuDo->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L"));
236 menuDo->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N"));
9133965e
WS
237
238 wxMenu *menuFile = new wxMenu;
239 menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control"));
240 menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control"));
c0c99785
WS
241 menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S"));
242 menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines\tAlt-M"));
9133965e
WS
243 menuFile->AppendSeparator();
244 menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application"));
245 menuFile->Check(ID_SHOW_IMAGES, m_chkShowImages);
246 menuFile->Check(ID_MULTI, m_multi);
247
248 wxMenuBar *menuBar = new wxMenuBar;
249 menuBar->Append(menuFile, wxT("&File"));
250 menuBar->Append(menuDo, wxT("&Operations"));
251 SetMenuBar(menuBar);
252
253 // books creation
254
255 m_panel = (wxPanel *) NULL;
02161c7c 256#if wxUSE_NOTEBOOK
9133965e 257 m_notebook = (wxNotebook *) NULL;
02161c7c
WS
258#endif
259#if wxUSE_CHOICEBOOK
9133965e 260 m_choicebook = (wxChoicebook *) NULL;
02161c7c
WS
261#endif
262#if wxUSE_LISTBOOK
9133965e 263 m_listbook = (wxListbook *) NULL;
02161c7c 264#endif
76645ab3
VZ
265
266 // create a dummy image list with a few icons
267 wxSize imageSize(32, 32);
268
269 m_imageList
270 = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() );
271
272 m_imageList->Add
273 (
274 wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)
275 );
276
277 m_imageList->Add
278 (
279 wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)
280 );
281
282 m_imageList->Add
283 (
284 wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)
285 );
286
287 m_imageList->Add
288 (
289 wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)
290 );
c1dfe277 291
1cfac5b8 292 m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
c02e5a31 293 wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
c1dfe277 294
9133965e 295#if USE_LOG
1cfac5b8 296 m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString,
c1dfe277
JS
297 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
298
299 m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) );
9133965e 300#endif // USE_LOG
c1dfe277 301
c1dfe277
JS
302 // Set sizers
303 m_sizerFrame = new wxBoxSizer(wxVERTICAL);
304
9133965e
WS
305#if USE_LOG
306 m_sizerFrame->Add(m_text, 1, wxEXPAND);
307#endif // USE_LOG
c1dfe277 308
9133965e 309 RecreateBooks();
c1dfe277
JS
310
311 m_panel->SetSizer(m_sizerFrame);
312
c1dfe277 313 m_sizerFrame->Fit(this);
ed420f6d 314 m_sizerFrame->SetSizeHints(this);
c1dfe277
JS
315
316 Centre(wxBOTH);
0b4d4194
JS
317}
318
c1dfe277 319MyFrame::~MyFrame()
0b4d4194 320{
9133965e 321#if USE_LOG
c1dfe277 322 delete wxLog::SetActiveTarget(m_logTargetOld);
9133965e 323#endif // USE_LOG
76645ab3
VZ
324
325 if (m_imageList)
326 {
327 delete m_imageList;
328 m_imageList = (wxImageList *) NULL;
329 }
0b4d4194
JS
330}
331
9133965e 332int MyFrame::SelectFlag(int id, int nb, int lb, int chb)
0b4d4194 333{
9133965e 334 switch (id)
c1dfe277 335 {
9133965e
WS
336 case ID_NOTEBOOK: return nb;
337 case ID_LISTBOOK: return lb;
338 case ID_CHOICEBOOK: return chb;
c1dfe277 339 }
9133965e
WS
340 return 0;
341}
c1dfe277 342
5a053c22
WS
343#ifdef __SMARTPHONE__
344 #define MARGIN 0
345#else
346 #define MARGIN 4
347#endif
348
9133965e
WS
349#define RECREATE( wxBookType , idBook, oldBook , newBook ) \
350{ \
351 int flags; \
352 \
353 switch ( m_orient ) \
354 { \
355 case ID_ORIENT_TOP: \
356 flags = SelectFlag(idBook, wxNB_TOP, wxLB_TOP, wxCHB_TOP); \
357 break; \
358 \
359 case ID_ORIENT_BOTTOM: \
360 flags = SelectFlag(idBook, wxNB_BOTTOM, wxLB_BOTTOM, wxCHB_BOTTOM); \
361 break; \
362 \
363 case ID_ORIENT_LEFT: \
364 flags = SelectFlag(idBook, wxNB_LEFT, wxLB_LEFT, wxCHB_LEFT); \
365 break; \
366 \
367 case ID_ORIENT_RIGHT: \
368 flags = SelectFlag(idBook, wxNB_RIGHT, wxLB_RIGHT, wxCHB_RIGHT); \
369 break; \
370 \
371 default: \
372 flags = SelectFlag(idBook, wxNB_DEFAULT, wxLB_DEFAULT, wxCHB_DEFAULT); \
373 } \
374 \
375 if ( m_multi && ( idBook == ID_NOTEBOOK ) ) \
376 flags |= wxNB_MULTILINE; \
377 \
378 wxBookType *oldBook = newBook; \
379 \
380 newBook = new wxBookType(m_panel, idBook, \
381 wxDefaultPosition, wxDefaultSize, \
382 flags); \
383 \
384 if ( m_chkShowImages ) \
385 { \
386 newBook->SetImageList(m_imageList); \
387 } \
388 \
389 if (oldBook) \
390 { \
391 int sel = oldBook->GetSelection(); \
392 \
393 int count = oldBook->GetPageCount(); \
394 for (int n = 0; n < count; n++) \
395 { \
396 wxString str = oldBook->GetPageText(n); \
397 \
398 wxWindow *page = CreatePage(newBook, str); \
399 newBook->AddPage(page, str, false, GetIconIndex(newBook) ); \
400 } \
401 \
402 m_sizerFrame->Detach(oldBook); \
403 \
404 delete oldBook; \
405 \
406 if (sel != wxNOT_FOUND) \
407 { \
408 newBook->SetSelection(sel); \
409 } \
410 \
411 } \
412 else \
413 { \
6e9324fc 414 CreateInitialPages(newBook); \
9133965e
WS
415 } \
416 \
5a053c22 417 m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, MARGIN); \
9133965e
WS
418 \
419 m_sizerFrame->Hide(newBook); \
420}
9a6c9e31 421
9133965e
WS
422void MyFrame::RecreateBooks()
423{
02161c7c 424#if wxUSE_NOTEBOOK
9133965e 425 RECREATE( wxNotebook , ID_NOTEBOOK , notebook , m_notebook );
02161c7c
WS
426#endif
427#if wxUSE_LISTBOOK
9133965e 428 RECREATE( wxListbook , ID_LISTBOOK , listbook , m_listbook );
02161c7c
WS
429#endif
430#if wxUSE_CHOICEBOOK
9133965e 431 RECREATE( wxChoicebook , ID_CHOICEBOOK , choicebook , m_choicebook );
02161c7c 432#endif
c1dfe277 433
9133965e
WS
434 ShowCurrentBook();
435}
c1dfe277 436
61c083e7 437wxBookCtrlBase *MyFrame::GetCurrentBook()
9133965e
WS
438{
439 switch (m_type)
76645ab3 440 {
02161c7c 441#if wxUSE_NOTEBOOK
9133965e 442 case ID_BOOK_NOTEBOOK: return m_notebook;
02161c7c
WS
443#endif
444#if wxUSE_LISTBOOK
9133965e 445 case ID_BOOK_LISTBOOK: return m_listbook;
02161c7c
WS
446#endif
447#if wxUSE_CHOICEBOOK
9133965e 448 case ID_BOOK_CHOICEBOOK: return m_choicebook;
02161c7c 449#endif
76645ab3 450 }
9133965e
WS
451 return NULL;
452}
c1dfe277 453
9133965e
WS
454void MyFrame::ShowCurrentBook()
455{
456 switch(m_type)
c1dfe277 457 {
02161c7c 458#if wxUSE_NOTEBOOK
9133965e 459 case ID_BOOK_NOTEBOOK: if(m_notebook) m_sizerFrame->Show(m_notebook); break;
02161c7c
WS
460#endif
461#if wxUSE_LISTBOOK
9133965e 462 case ID_BOOK_LISTBOOK: if(m_listbook) m_sizerFrame->Show(m_listbook); break;
02161c7c
WS
463#endif
464#if wxUSE_CHOICEBOOK
9133965e 465 case ID_BOOK_CHOICEBOOK: if(m_choicebook) m_sizerFrame->Show(m_choicebook); break;
02161c7c 466#endif
c1dfe277
JS
467 }
468
9133965e 469 m_sizerFrame->Layout();
c1dfe277
JS
470}
471
0b4d4194 472BEGIN_EVENT_TABLE(MyFrame, wxFrame)
9133965e
WS
473 // File menu
474 EVT_MENU_RANGE(ID_BOOK_NOTEBOOK,ID_BOOK_MAX,MyFrame::OnType)
475 EVT_MENU_RANGE(ID_ORIENT_DEFAULT,ID_ORIENT_MAX,MyFrame::OnOrient)
476 EVT_MENU(ID_SHOW_IMAGES, MyFrame::OnShowImages)
477 EVT_MENU(ID_MULTI, MyFrame::OnMulti)
478 EVT_MENU(wxID_EXIT,MyFrame::OnExit)
479
480 // Operations menu
481 EVT_MENU(ID_ADD_PAGE, MyFrame::OnAddPage)
482 EVT_MENU(ID_INSERT_PAGE, MyFrame::OnInsertPage)
483 EVT_MENU(ID_DELETE_CUR_PAGE, MyFrame::OnDeleteCurPage)
484 EVT_MENU(ID_DELETE_LAST_PAGE, MyFrame::OnDeleteLastPage)
485 EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
486
487 // Book controls
02161c7c 488#if wxUSE_NOTEBOOK
c1dfe277
JS
489 EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook)
490 EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook)
02161c7c
WS
491#endif
492#if wxUSE_LISTBOOK
9133965e
WS
493 EVT_LISTBOOK_PAGE_CHANGED(ID_LISTBOOK, MyFrame::OnListbook)
494 EVT_LISTBOOK_PAGE_CHANGING(ID_LISTBOOK, MyFrame::OnListbook)
02161c7c
WS
495#endif
496#if wxUSE_CHOICEBOOK
9133965e
WS
497 EVT_CHOICEBOOK_PAGE_CHANGED(ID_CHOICEBOOK, MyFrame::OnChoicebook)
498 EVT_CHOICEBOOK_PAGE_CHANGING(ID_CHOICEBOOK, MyFrame::OnChoicebook)
02161c7c 499#endif
c1dfe277 500
9133965e 501 // Update title in idle time
96d37807 502 EVT_IDLE(MyFrame::OnIdle)
0b4d4194
JS
503END_EVENT_TABLE()
504
9133965e 505void MyFrame::OnType(wxCommandEvent& event)
0b4d4194 506{
61c083e7 507 wxBookCtrlBase *currBook = GetCurrentBook();
0b4d4194 508
9133965e 509 m_type = event.GetId();
477350ce 510
9133965e
WS
511 if (currBook)
512 m_sizerFrame->Hide(currBook);
477350ce 513
9133965e 514 ShowCurrentBook();
477350ce
VZ
515}
516
9133965e 517void MyFrame::OnOrient(wxCommandEvent& event)
477350ce 518{
9133965e
WS
519 m_orient = event.GetId();
520 RecreateBooks();
521 m_sizerFrame->Layout();
522}
477350ce 523
9133965e
WS
524void MyFrame::OnShowImages(wxCommandEvent& event)
525{
526 m_chkShowImages = event.IsChecked();
527 RecreateBooks();
528 m_sizerFrame->Layout();
529}
c1dfe277 530
9133965e
WS
531void MyFrame::OnMulti(wxCommandEvent& event)
532{
533 m_multi = event.IsChecked();
534 RecreateBooks();
535 m_sizerFrame->Layout();
536 wxLogMessage(_T("Multiline setting works only in wxNotebook."));
537}
477350ce 538
9133965e
WS
539void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
540{
541 Close();
326f9654
RR
542}
543
9133965e 544void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
3957448a 545{
9133965e 546 static unsigned s_pageAdded = 0;
3957448a 547
61c083e7 548 wxBookCtrlBase *currBook = GetCurrentBook();
9133965e
WS
549
550 if ( currBook )
3957448a 551 {
9133965e
WS
552 wxPanel *panel = new wxPanel( currBook, wxID_ANY );
553 (void) new wxButton( panel, wxID_ANY, wxT("First button"),
554 wxPoint(10, 10), wxDefaultSize );
555 (void) new wxButton( panel, wxID_ANY, wxT("Second button"),
556 wxPoint(50, 100), wxDefaultSize );
557
558 currBook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"),
559 ++s_pageAdded), true, GetIconIndex(currBook) );
3957448a
VZ
560 }
561}
562
9133965e 563void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
29f538ce 564{
9133965e
WS
565 static unsigned s_pageIns = 0;
566
61c083e7 567 wxBookCtrlBase *currBook = GetCurrentBook();
f6bcfd97 568
9133965e 569 if ( currBook )
f6bcfd97 570 {
9133965e
WS
571 wxPanel *panel = CreateUserCreatedPage( currBook );
572
573 currBook->InsertPage( 0, panel,
574 wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false,
575 GetIconIndex(currBook) );
576
577 currBook->SetSelection(0);
f6bcfd97 578 }
29f538ce
RR
579}
580
9133965e 581void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
33d0e17c 582{
61c083e7 583 wxBookCtrlBase *currBook = GetCurrentBook();
33d0e17c 584
9133965e
WS
585 if ( currBook )
586 {
587 int sel = currBook->GetSelection();
588
589 if (sel != wxNOT_FOUND)
590 {
591 currBook->DeletePage(sel);
592 }
593 }
0b4d4194
JS
594}
595
9133965e 596void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event))
0b4d4194 597{
61c083e7 598 wxBookCtrlBase *currBook = GetCurrentBook();
d22699b5 599
9133965e 600 if ( currBook )
c1dfe277 601 {
9133965e 602 int page = currBook->GetPageCount();
c1dfe277 603
9133965e
WS
604 if ( page != 0 )
605 {
606 currBook->DeletePage(page - 1);
c1dfe277 607 }
c1dfe277 608 }
9133965e 609}
0b4d4194 610
9133965e
WS
611void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event))
612{
61c083e7 613 wxBookCtrlBase *currBook = GetCurrentBook();
0b4d4194 614
9133965e
WS
615 if ( currBook )
616 {
617 currBook->AdvanceSelection();
618 }
0b4d4194
JS
619}
620
c1dfe277 621void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
96d37807 622{
9133965e
WS
623 static int s_nPages = wxNOT_FOUND;
624 static int s_nSel = wxNOT_FOUND;
61c083e7 625 static wxBookCtrlBase *s_currBook = NULL;
9133965e 626
61c083e7 627 wxBookCtrlBase *currBook = GetCurrentBook();
96d37807 628
9133965e
WS
629 int nPages = currBook ? currBook->GetPageCount() : 0;
630 int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND;
631
632 if ( nPages != s_nPages || nSel != s_nSel || s_currBook != currBook )
96d37807
VZ
633 {
634 s_nPages = nPages;
635 s_nSel = nSel;
9133965e
WS
636 s_currBook = currBook;
637
638 wxString selection;
639 if ( nSel == wxNOT_FOUND )
640 selection << wxT("not found");
641 else
642 selection << nSel;
96d37807
VZ
643
644 wxString title;
9133965e 645 title.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages, selection.c_str());
96d37807
VZ
646
647 SetTitle(title);
648 }
649}
3957448a 650
11d1f159
WS
651#if USE_LOG
652 #define BOOKEVENT_LOG m_text->SetInsertionPointEnd();
653#else
654 #define BOOKEVENT_LOG
655#endif
656
9133965e
WS
657#define BOOKEVENT(OnBook,wxBookEvent,bookStr,wxEVT_PAGE_CHANGED,wxEVT_PAGE_CHANGING,s_num) \
658void MyFrame::OnBook(wxBookEvent& event) \
659{ \
660 wxString str = wxT("Unknown "); \
661 str << wxT(bookStr); \
662 str << wxT(" event"); \
663 \
664 wxEventType eventType = event.GetEventType(); \
665 \
666 if (eventType == wxEVT_PAGE_CHANGED) \
667 { \
668 str = wxT("Changed"); \
669 } \
670 else if (eventType == wxEVT_PAGE_CHANGING) \
671 { \
672 int idx = event.GetOldSelection(); \
61c083e7 673 wxBookCtrlBase *book = (wxBookCtrlBase *)event.GetEventObject(); \
9133965e
WS
674 if ( idx != wxNOT_FOUND && book && book->GetPageText(idx) == VETO_PAGE_NAME ) \
675 { \
676 if \
677 ( \
678 wxMessageBox( \
679 wxT("Are you sure you want to leave this page?\n") \
680 wxT("(This demonstrates veto-ing)"), \
681 wxT("Notebook sample"), \
682 wxICON_QUESTION | wxYES_NO, this) != wxYES ) \
683 { \
684 event.Veto(); \
9133965e
WS
685 } \
686 \
687 } \
688 \
689 str = wxT("Changing"); \
690 } \
691 \
692 static int s_num = 0; \
693 \
694 wxString logMsg; \
695 logMsg.Printf(wxT("%s event #%d: %s (%d) Sel %d, OldSel %d"), \
696 wxT(bookStr),s_num++, str.c_str(), eventType, \
697 event.GetSelection(), event.GetOldSelection()); \
698 \
699 wxLogMessage(logMsg.c_str()); \
700 \
11d1f159 701 BOOKEVENT_LOG \
3957448a
VZ
702}
703
02161c7c 704#if wxUSE_NOTEBOOK
9133965e 705BOOKEVENT(OnNotebook,wxNotebookEvent,"wxNotebook",wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,s_numNotebookEvents)
02161c7c
WS
706#endif
707#if wxUSE_CHOICEBOOK
9133965e 708BOOKEVENT(OnChoicebook,wxChoicebookEvent,"wxChoicebook",wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,s_numChoicebookEvents)
02161c7c
WS
709#endif
710#if wxUSE_LISTBOOK
9133965e 711BOOKEVENT(OnListbook,wxListbookEvent,"wxListbook",wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,s_numListbookEvents)
02161c7c 712#endif