]>
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 | ||
9133965e | 47 | wxPanel *CreateUserCreatedPage(wxBookCtrl *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 | ||
9133965e | 57 | wxPanel *CreateRadioButtonsPage(wxBookCtrl *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 | |
9133965e | 82 | wxPanel *CreateVetoPage(wxBookCtrl *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 | ||
9133965e | 92 | wxPanel *CreateBigButtonPage(wxBookCtrl *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 | |
9133965e | 106 | wxPanel *CreateInsertPage(wxBookCtrl *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 | ||
9133965e | 117 | int GetIconIndex(wxBookCtrl* 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 | |
9133965e WS |
131 | void CreateInitialPages(wxBookCtrl *parent) |
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 | ||
9133965e | 150 | wxPanel *CreatePage(wxBookCtrl *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 | { |
9133965e WS |
191 | m_type = ID_BOOK_NOTEBOOK; |
192 | m_orient = ID_ORIENT_DEFAULT; | |
193 | m_chkShowImages = true; | |
194 | m_multi = false; | |
195 | ||
196 | // menu of the sample | |
197 | ||
198 | wxMenu *menuType = new wxMenu; | |
199 | #if wxUSE_NOTEBOOK | |
200 | menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, wxT("&Notebook\tCtrl-1")); | |
201 | #endif | |
202 | #if wxUSE_LISTBOOK | |
203 | menuType->AppendRadioItem(ID_BOOK_LISTBOOK, wxT("&Listbook\tCtrl-2")); | |
204 | #endif | |
205 | #if wxUSE_CHOICEBOOK | |
206 | menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3")); | |
207 | #endif | |
208 | ||
209 | wxMenu *menuOrient = new wxMenu; | |
210 | menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tCtrl-4")); | |
211 | menuOrient->AppendRadioItem(ID_ORIENT_TOP, wxT("&Top\tCtrl-5")); | |
212 | menuOrient->AppendRadioItem(ID_ORIENT_BOTTOM, wxT("&Bottom\tCtrl-6")); | |
213 | menuOrient->AppendRadioItem(ID_ORIENT_LEFT, wxT("&Left\tCtrl-7")); | |
214 | menuOrient->AppendRadioItem(ID_ORIENT_RIGHT, wxT("&Right\tCtrl-8")); | |
215 | ||
216 | wxMenu *menuDo = new wxMenu; | |
c0c99785 WS |
217 | menuDo->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A")); |
218 | menuDo->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I")); | |
219 | menuDo->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D")); | |
220 | menuDo->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L")); | |
221 | menuDo->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N")); | |
9133965e WS |
222 | |
223 | wxMenu *menuFile = new wxMenu; | |
224 | menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control")); | |
225 | menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control")); | |
c0c99785 WS |
226 | menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S")); |
227 | menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines\tAlt-M")); | |
9133965e WS |
228 | menuFile->AppendSeparator(); |
229 | menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application")); | |
230 | menuFile->Check(ID_SHOW_IMAGES, m_chkShowImages); | |
231 | menuFile->Check(ID_MULTI, m_multi); | |
232 | ||
233 | wxMenuBar *menuBar = new wxMenuBar; | |
234 | menuBar->Append(menuFile, wxT("&File")); | |
235 | menuBar->Append(menuDo, wxT("&Operations")); | |
236 | SetMenuBar(menuBar); | |
237 | ||
238 | // books creation | |
239 | ||
240 | m_panel = (wxPanel *) NULL; | |
02161c7c | 241 | #if wxUSE_NOTEBOOK |
9133965e | 242 | m_notebook = (wxNotebook *) NULL; |
02161c7c WS |
243 | #endif |
244 | #if wxUSE_CHOICEBOOK | |
9133965e | 245 | m_choicebook = (wxChoicebook *) NULL; |
02161c7c WS |
246 | #endif |
247 | #if wxUSE_LISTBOOK | |
9133965e | 248 | m_listbook = (wxListbook *) NULL; |
02161c7c | 249 | #endif |
76645ab3 VZ |
250 | |
251 | // create a dummy image list with a few icons | |
252 | wxSize imageSize(32, 32); | |
253 | ||
254 | m_imageList | |
255 | = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() ); | |
256 | ||
257 | m_imageList->Add | |
258 | ( | |
259 | wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize) | |
260 | ); | |
261 | ||
262 | m_imageList->Add | |
263 | ( | |
264 | wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize) | |
265 | ); | |
266 | ||
267 | m_imageList->Add | |
268 | ( | |
269 | wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize) | |
270 | ); | |
271 | ||
272 | m_imageList->Add | |
273 | ( | |
274 | wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize) | |
275 | ); | |
c1dfe277 | 276 | |
1cfac5b8 | 277 | m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, |
c02e5a31 | 278 | wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE); |
c1dfe277 | 279 | |
9133965e | 280 | #if USE_LOG |
1cfac5b8 | 281 | m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, |
c1dfe277 JS |
282 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY); |
283 | ||
284 | m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) ); | |
9133965e | 285 | #endif // USE_LOG |
c1dfe277 | 286 | |
c1dfe277 JS |
287 | // Set sizers |
288 | m_sizerFrame = new wxBoxSizer(wxVERTICAL); | |
289 | ||
9133965e WS |
290 | #if USE_LOG |
291 | m_sizerFrame->Add(m_text, 1, wxEXPAND); | |
292 | #endif // USE_LOG | |
c1dfe277 | 293 | |
9133965e | 294 | RecreateBooks(); |
c1dfe277 JS |
295 | |
296 | m_panel->SetSizer(m_sizerFrame); | |
297 | ||
c1dfe277 | 298 | m_sizerFrame->Fit(this); |
ed420f6d | 299 | m_sizerFrame->SetSizeHints(this); |
c1dfe277 JS |
300 | |
301 | Centre(wxBOTH); | |
0b4d4194 JS |
302 | } |
303 | ||
c1dfe277 | 304 | MyFrame::~MyFrame() |
0b4d4194 | 305 | { |
9133965e | 306 | #if USE_LOG |
c1dfe277 | 307 | delete wxLog::SetActiveTarget(m_logTargetOld); |
9133965e | 308 | #endif // USE_LOG |
76645ab3 VZ |
309 | |
310 | if (m_imageList) | |
311 | { | |
312 | delete m_imageList; | |
313 | m_imageList = (wxImageList *) NULL; | |
314 | } | |
0b4d4194 JS |
315 | } |
316 | ||
9133965e | 317 | int MyFrame::SelectFlag(int id, int nb, int lb, int chb) |
0b4d4194 | 318 | { |
9133965e | 319 | switch (id) |
c1dfe277 | 320 | { |
9133965e WS |
321 | case ID_NOTEBOOK: return nb; |
322 | case ID_LISTBOOK: return lb; | |
323 | case ID_CHOICEBOOK: return chb; | |
c1dfe277 | 324 | } |
9133965e WS |
325 | return 0; |
326 | } | |
c1dfe277 | 327 | |
9133965e WS |
328 | #define RECREATE( wxBookType , idBook, oldBook , newBook ) \ |
329 | { \ | |
330 | int flags; \ | |
331 | \ | |
332 | switch ( m_orient ) \ | |
333 | { \ | |
334 | case ID_ORIENT_TOP: \ | |
335 | flags = SelectFlag(idBook, wxNB_TOP, wxLB_TOP, wxCHB_TOP); \ | |
336 | break; \ | |
337 | \ | |
338 | case ID_ORIENT_BOTTOM: \ | |
339 | flags = SelectFlag(idBook, wxNB_BOTTOM, wxLB_BOTTOM, wxCHB_BOTTOM); \ | |
340 | break; \ | |
341 | \ | |
342 | case ID_ORIENT_LEFT: \ | |
343 | flags = SelectFlag(idBook, wxNB_LEFT, wxLB_LEFT, wxCHB_LEFT); \ | |
344 | break; \ | |
345 | \ | |
346 | case ID_ORIENT_RIGHT: \ | |
347 | flags = SelectFlag(idBook, wxNB_RIGHT, wxLB_RIGHT, wxCHB_RIGHT); \ | |
348 | break; \ | |
349 | \ | |
350 | default: \ | |
351 | flags = SelectFlag(idBook, wxNB_DEFAULT, wxLB_DEFAULT, wxCHB_DEFAULT); \ | |
352 | } \ | |
353 | \ | |
354 | if ( m_multi && ( idBook == ID_NOTEBOOK ) ) \ | |
355 | flags |= wxNB_MULTILINE; \ | |
356 | \ | |
357 | wxBookType *oldBook = newBook; \ | |
358 | \ | |
359 | newBook = new wxBookType(m_panel, idBook, \ | |
360 | wxDefaultPosition, wxDefaultSize, \ | |
361 | flags); \ | |
362 | \ | |
363 | if ( m_chkShowImages ) \ | |
364 | { \ | |
365 | newBook->SetImageList(m_imageList); \ | |
366 | } \ | |
367 | \ | |
368 | if (oldBook) \ | |
369 | { \ | |
370 | int sel = oldBook->GetSelection(); \ | |
371 | \ | |
372 | int count = oldBook->GetPageCount(); \ | |
373 | for (int n = 0; n < count; n++) \ | |
374 | { \ | |
375 | wxString str = oldBook->GetPageText(n); \ | |
376 | \ | |
377 | wxWindow *page = CreatePage(newBook, str); \ | |
378 | newBook->AddPage(page, str, false, GetIconIndex(newBook) ); \ | |
379 | } \ | |
380 | \ | |
381 | m_sizerFrame->Detach(oldBook); \ | |
382 | \ | |
383 | delete oldBook; \ | |
384 | \ | |
385 | if (sel != wxNOT_FOUND) \ | |
386 | { \ | |
387 | newBook->SetSelection(sel); \ | |
388 | } \ | |
389 | \ | |
390 | } \ | |
391 | else \ | |
392 | { \ | |
393 | wxPanel *panel = CreateRadioButtonsPage(newBook); \ | |
394 | newBook->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(newBook) ); \ | |
395 | \ | |
396 | panel = CreateVetoPage(newBook); \ | |
397 | newBook->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(newBook) ); \ | |
398 | \ | |
399 | panel = CreateBigButtonPage(newBook); \ | |
400 | newBook->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(newBook) ); \ | |
401 | \ | |
402 | panel = CreateInsertPage(newBook); \ | |
403 | newBook->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(newBook) ); \ | |
404 | \ | |
405 | newBook->SetSelection(1); \ | |
406 | } \ | |
407 | \ | |
408 | m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, 4); \ | |
409 | \ | |
410 | m_sizerFrame->Hide(newBook); \ | |
411 | } | |
9a6c9e31 | 412 | |
9133965e WS |
413 | void MyFrame::RecreateBooks() |
414 | { | |
02161c7c | 415 | #if wxUSE_NOTEBOOK |
9133965e | 416 | RECREATE( wxNotebook , ID_NOTEBOOK , notebook , m_notebook ); |
02161c7c WS |
417 | #endif |
418 | #if wxUSE_LISTBOOK | |
9133965e | 419 | RECREATE( wxListbook , ID_LISTBOOK , listbook , m_listbook ); |
02161c7c WS |
420 | #endif |
421 | #if wxUSE_CHOICEBOOK | |
9133965e | 422 | RECREATE( wxChoicebook , ID_CHOICEBOOK , choicebook , m_choicebook ); |
02161c7c | 423 | #endif |
c1dfe277 | 424 | |
9133965e WS |
425 | ShowCurrentBook(); |
426 | } | |
c1dfe277 | 427 | |
9133965e WS |
428 | wxBookCtrl *MyFrame::GetCurrentBook() |
429 | { | |
430 | switch (m_type) | |
76645ab3 | 431 | { |
02161c7c | 432 | #if wxUSE_NOTEBOOK |
9133965e | 433 | case ID_BOOK_NOTEBOOK: return m_notebook; |
02161c7c WS |
434 | #endif |
435 | #if wxUSE_LISTBOOK | |
9133965e | 436 | case ID_BOOK_LISTBOOK: return m_listbook; |
02161c7c WS |
437 | #endif |
438 | #if wxUSE_CHOICEBOOK | |
9133965e | 439 | case ID_BOOK_CHOICEBOOK: return m_choicebook; |
02161c7c | 440 | #endif |
76645ab3 | 441 | } |
9133965e WS |
442 | return NULL; |
443 | } | |
c1dfe277 | 444 | |
9133965e WS |
445 | void MyFrame::ShowCurrentBook() |
446 | { | |
447 | switch(m_type) | |
c1dfe277 | 448 | { |
02161c7c | 449 | #if wxUSE_NOTEBOOK |
9133965e | 450 | case ID_BOOK_NOTEBOOK: if(m_notebook) m_sizerFrame->Show(m_notebook); break; |
02161c7c WS |
451 | #endif |
452 | #if wxUSE_LISTBOOK | |
9133965e | 453 | case ID_BOOK_LISTBOOK: if(m_listbook) m_sizerFrame->Show(m_listbook); break; |
02161c7c WS |
454 | #endif |
455 | #if wxUSE_CHOICEBOOK | |
9133965e | 456 | case ID_BOOK_CHOICEBOOK: if(m_choicebook) m_sizerFrame->Show(m_choicebook); break; |
02161c7c | 457 | #endif |
c1dfe277 JS |
458 | } |
459 | ||
9133965e | 460 | m_sizerFrame->Layout(); |
c1dfe277 JS |
461 | } |
462 | ||
0b4d4194 | 463 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
9133965e WS |
464 | // File menu |
465 | EVT_MENU_RANGE(ID_BOOK_NOTEBOOK,ID_BOOK_MAX,MyFrame::OnType) | |
466 | EVT_MENU_RANGE(ID_ORIENT_DEFAULT,ID_ORIENT_MAX,MyFrame::OnOrient) | |
467 | EVT_MENU(ID_SHOW_IMAGES, MyFrame::OnShowImages) | |
468 | EVT_MENU(ID_MULTI, MyFrame::OnMulti) | |
469 | EVT_MENU(wxID_EXIT,MyFrame::OnExit) | |
470 | ||
471 | // Operations menu | |
472 | EVT_MENU(ID_ADD_PAGE, MyFrame::OnAddPage) | |
473 | EVT_MENU(ID_INSERT_PAGE, MyFrame::OnInsertPage) | |
474 | EVT_MENU(ID_DELETE_CUR_PAGE, MyFrame::OnDeleteCurPage) | |
475 | EVT_MENU(ID_DELETE_LAST_PAGE, MyFrame::OnDeleteLastPage) | |
476 | EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage) | |
477 | ||
478 | // Book controls | |
02161c7c | 479 | #if wxUSE_NOTEBOOK |
c1dfe277 JS |
480 | EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook) |
481 | EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook) | |
02161c7c WS |
482 | #endif |
483 | #if wxUSE_LISTBOOK | |
9133965e WS |
484 | EVT_LISTBOOK_PAGE_CHANGED(ID_LISTBOOK, MyFrame::OnListbook) |
485 | EVT_LISTBOOK_PAGE_CHANGING(ID_LISTBOOK, MyFrame::OnListbook) | |
02161c7c WS |
486 | #endif |
487 | #if wxUSE_CHOICEBOOK | |
9133965e WS |
488 | EVT_CHOICEBOOK_PAGE_CHANGED(ID_CHOICEBOOK, MyFrame::OnChoicebook) |
489 | EVT_CHOICEBOOK_PAGE_CHANGING(ID_CHOICEBOOK, MyFrame::OnChoicebook) | |
02161c7c | 490 | #endif |
c1dfe277 | 491 | |
9133965e | 492 | // Update title in idle time |
96d37807 | 493 | EVT_IDLE(MyFrame::OnIdle) |
0b4d4194 JS |
494 | END_EVENT_TABLE() |
495 | ||
9133965e | 496 | void MyFrame::OnType(wxCommandEvent& event) |
0b4d4194 | 497 | { |
9133965e | 498 | wxBookCtrl *currBook = GetCurrentBook(); |
0b4d4194 | 499 | |
9133965e | 500 | m_type = event.GetId(); |
477350ce | 501 | |
9133965e WS |
502 | if (currBook) |
503 | m_sizerFrame->Hide(currBook); | |
477350ce | 504 | |
9133965e | 505 | ShowCurrentBook(); |
477350ce VZ |
506 | } |
507 | ||
9133965e | 508 | void MyFrame::OnOrient(wxCommandEvent& event) |
477350ce | 509 | { |
9133965e WS |
510 | m_orient = event.GetId(); |
511 | RecreateBooks(); | |
512 | m_sizerFrame->Layout(); | |
513 | } | |
477350ce | 514 | |
9133965e WS |
515 | void MyFrame::OnShowImages(wxCommandEvent& event) |
516 | { | |
517 | m_chkShowImages = event.IsChecked(); | |
518 | RecreateBooks(); | |
519 | m_sizerFrame->Layout(); | |
520 | } | |
c1dfe277 | 521 | |
9133965e WS |
522 | void MyFrame::OnMulti(wxCommandEvent& event) |
523 | { | |
524 | m_multi = event.IsChecked(); | |
525 | RecreateBooks(); | |
526 | m_sizerFrame->Layout(); | |
527 | wxLogMessage(_T("Multiline setting works only in wxNotebook.")); | |
528 | } | |
477350ce | 529 | |
9133965e WS |
530 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) |
531 | { | |
532 | Close(); | |
326f9654 RR |
533 | } |
534 | ||
9133965e | 535 | void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event)) |
3957448a | 536 | { |
9133965e | 537 | static unsigned s_pageAdded = 0; |
3957448a | 538 | |
9133965e WS |
539 | wxBookCtrl *currBook = GetCurrentBook(); |
540 | ||
541 | if ( currBook ) | |
3957448a | 542 | { |
9133965e WS |
543 | wxPanel *panel = new wxPanel( currBook, wxID_ANY ); |
544 | (void) new wxButton( panel, wxID_ANY, wxT("First button"), | |
545 | wxPoint(10, 10), wxDefaultSize ); | |
546 | (void) new wxButton( panel, wxID_ANY, wxT("Second button"), | |
547 | wxPoint(50, 100), wxDefaultSize ); | |
548 | ||
549 | currBook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"), | |
550 | ++s_pageAdded), true, GetIconIndex(currBook) ); | |
3957448a VZ |
551 | } |
552 | } | |
553 | ||
9133965e | 554 | void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event)) |
29f538ce | 555 | { |
9133965e WS |
556 | static unsigned s_pageIns = 0; |
557 | ||
558 | wxBookCtrl *currBook = GetCurrentBook(); | |
f6bcfd97 | 559 | |
9133965e | 560 | if ( currBook ) |
f6bcfd97 | 561 | { |
9133965e WS |
562 | wxPanel *panel = CreateUserCreatedPage( currBook ); |
563 | ||
564 | currBook->InsertPage( 0, panel, | |
565 | wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false, | |
566 | GetIconIndex(currBook) ); | |
567 | ||
568 | currBook->SetSelection(0); | |
f6bcfd97 | 569 | } |
29f538ce RR |
570 | } |
571 | ||
9133965e | 572 | void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event)) |
33d0e17c | 573 | { |
9133965e | 574 | wxBookCtrl *currBook = GetCurrentBook(); |
33d0e17c | 575 | |
9133965e WS |
576 | if ( currBook ) |
577 | { | |
578 | int sel = currBook->GetSelection(); | |
579 | ||
580 | if (sel != wxNOT_FOUND) | |
581 | { | |
582 | currBook->DeletePage(sel); | |
583 | } | |
584 | } | |
0b4d4194 JS |
585 | } |
586 | ||
9133965e | 587 | void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event)) |
0b4d4194 | 588 | { |
9133965e | 589 | wxBookCtrl *currBook = GetCurrentBook(); |
d22699b5 | 590 | |
9133965e | 591 | if ( currBook ) |
c1dfe277 | 592 | { |
9133965e | 593 | int page = currBook->GetPageCount(); |
c1dfe277 | 594 | |
9133965e WS |
595 | if ( page != 0 ) |
596 | { | |
597 | currBook->DeletePage(page - 1); | |
c1dfe277 | 598 | } |
c1dfe277 | 599 | } |
9133965e | 600 | } |
0b4d4194 | 601 | |
9133965e WS |
602 | void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event)) |
603 | { | |
604 | wxBookCtrl *currBook = GetCurrentBook(); | |
0b4d4194 | 605 | |
9133965e WS |
606 | if ( currBook ) |
607 | { | |
608 | currBook->AdvanceSelection(); | |
609 | } | |
0b4d4194 JS |
610 | } |
611 | ||
c1dfe277 | 612 | void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) |
96d37807 | 613 | { |
9133965e WS |
614 | static int s_nPages = wxNOT_FOUND; |
615 | static int s_nSel = wxNOT_FOUND; | |
616 | static wxBookCtrl *s_currBook = NULL; | |
617 | ||
618 | wxBookCtrl *currBook = GetCurrentBook(); | |
96d37807 | 619 | |
9133965e WS |
620 | int nPages = currBook ? currBook->GetPageCount() : 0; |
621 | int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND; | |
622 | ||
623 | if ( nPages != s_nPages || nSel != s_nSel || s_currBook != currBook ) | |
96d37807 VZ |
624 | { |
625 | s_nPages = nPages; | |
626 | s_nSel = nSel; | |
9133965e WS |
627 | s_currBook = currBook; |
628 | ||
629 | wxString selection; | |
630 | if ( nSel == wxNOT_FOUND ) | |
631 | selection << wxT("not found"); | |
632 | else | |
633 | selection << nSel; | |
96d37807 VZ |
634 | |
635 | wxString title; | |
9133965e | 636 | title.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages, selection.c_str()); |
96d37807 VZ |
637 | |
638 | SetTitle(title); | |
639 | } | |
640 | } | |
3957448a | 641 | |
9133965e WS |
642 | #define BOOKEVENT(OnBook,wxBookEvent,bookStr,wxEVT_PAGE_CHANGED,wxEVT_PAGE_CHANGING,s_num) \ |
643 | void MyFrame::OnBook(wxBookEvent& event) \ | |
644 | { \ | |
645 | wxString str = wxT("Unknown "); \ | |
646 | str << wxT(bookStr); \ | |
647 | str << wxT(" event"); \ | |
648 | \ | |
649 | wxEventType eventType = event.GetEventType(); \ | |
650 | \ | |
651 | if (eventType == wxEVT_PAGE_CHANGED) \ | |
652 | { \ | |
653 | str = wxT("Changed"); \ | |
654 | } \ | |
655 | else if (eventType == wxEVT_PAGE_CHANGING) \ | |
656 | { \ | |
657 | int idx = event.GetOldSelection(); \ | |
658 | wxBookCtrl *book = (wxBookCtrl *)event.GetEventObject(); \ | |
659 | if ( idx != wxNOT_FOUND && book && book->GetPageText(idx) == VETO_PAGE_NAME ) \ | |
660 | { \ | |
661 | if \ | |
662 | ( \ | |
663 | wxMessageBox( \ | |
664 | wxT("Are you sure you want to leave this page?\n") \ | |
665 | wxT("(This demonstrates veto-ing)"), \ | |
666 | wxT("Notebook sample"), \ | |
667 | wxICON_QUESTION | wxYES_NO, this) != wxYES ) \ | |
668 | { \ | |
669 | event.Veto(); \ | |
9133965e WS |
670 | } \ |
671 | \ | |
672 | } \ | |
673 | \ | |
674 | str = wxT("Changing"); \ | |
675 | } \ | |
676 | \ | |
677 | static int s_num = 0; \ | |
678 | \ | |
679 | wxString logMsg; \ | |
680 | logMsg.Printf(wxT("%s event #%d: %s (%d) Sel %d, OldSel %d"), \ | |
681 | wxT(bookStr),s_num++, str.c_str(), eventType, \ | |
682 | event.GetSelection(), event.GetOldSelection()); \ | |
683 | \ | |
684 | wxLogMessage(logMsg.c_str()); \ | |
685 | \ | |
686 | m_text->SetInsertionPointEnd(); \ | |
3957448a VZ |
687 | } |
688 | ||
02161c7c | 689 | #if wxUSE_NOTEBOOK |
9133965e | 690 | BOOKEVENT(OnNotebook,wxNotebookEvent,"wxNotebook",wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,s_numNotebookEvents) |
02161c7c WS |
691 | #endif |
692 | #if wxUSE_CHOICEBOOK | |
9133965e | 693 | BOOKEVENT(OnChoicebook,wxChoicebookEvent,"wxChoicebook",wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,s_numChoicebookEvents) |
02161c7c WS |
694 | #endif |
695 | #if wxUSE_LISTBOOK | |
9133965e | 696 | BOOKEVENT(OnListbook,wxListbookEvent,"wxListbook",wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,s_numListbookEvents) |
02161c7c | 697 | #endif |