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