]>
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$ | |
c1dfe277 JS |
8 | // Copyright: (c) 1998-2002 wxWindows team |
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 | |
37d403aa | 36 | #if defined(__WIN16__) || defined(__WXMOTIF__) |
c1dfe277 JS |
37 | int width, height; |
38 | frame->GetSize(& width, & height); | |
39 | frame->SetSize(-1, -1, width, height); | |
5dcf05ae JS |
40 | #endif |
41 | ||
c1dfe277 JS |
42 | frame->Show(); |
43 | ||
44 | return TRUE; | |
0b4d4194 JS |
45 | } |
46 | ||
c1dfe277 JS |
47 | MyNotebook::MyNotebook(wxWindow *parent, wxWindowID id, |
48 | const wxPoint& pos, const wxSize& size, long style) | |
49 | : wxNotebook(parent, id, pos, size, style) | |
0b4d4194 | 50 | { |
c1dfe277 | 51 | // Empty |
0b4d4194 JS |
52 | } |
53 | ||
76645ab3 | 54 | wxPanel *MyNotebook::CreatePage(const wxString&pageName) |
c1dfe277 | 55 | { |
76645ab3 VZ |
56 | if |
57 | ( | |
58 | pageName.Contains(INSERTED_PAGE_NAME) | |
59 | || pageName.Contains(ADDED_PAGE_NAME) | |
60 | ) | |
61 | { | |
62 | return CreateUserCreatedPage(); | |
63 | } | |
d22699b5 | 64 | |
76645ab3 VZ |
65 | if (pageName == I_WAS_INSERTED_PAGE_NAME) |
66 | { | |
67 | return CreateInsertPage(); | |
68 | } | |
c1dfe277 | 69 | |
76645ab3 VZ |
70 | if (pageName == VETO_PAGE_NAME) |
71 | { | |
72 | return CreateVetoPage(); | |
73 | } | |
c1dfe277 | 74 | |
76645ab3 VZ |
75 | if (pageName == RADIOBUTTONS_PAGE_NAME) |
76 | { | |
77 | return CreateRadioButtonsPage(); | |
78 | } | |
c1dfe277 | 79 | |
c1dfe277 | 80 | |
76645ab3 VZ |
81 | if (pageName == MAXIMIZED_BUTTON_PAGE_NAME) |
82 | { | |
83 | return CreateBigButtonPage(); | |
84 | } | |
c1dfe277 | 85 | |
76645ab3 | 86 | wxFAIL; |
c1dfe277 | 87 | |
76645ab3 VZ |
88 | return (wxPanel *) NULL; |
89 | } | |
90 | ||
91 | wxPanel *MyNotebook::CreateUserCreatedPage() | |
92 | { | |
93 | wxPanel *panel = new wxPanel(this); | |
94 | ||
95 | (void) new wxButton( panel, -1, wxT("Button"), | |
96 | wxPoint(10, 10), wxSize(-1, -1) ); | |
97 | ||
98 | return panel; | |
99 | } | |
100 | ||
101 | wxPanel *MyNotebook::CreateRadioButtonsPage() | |
102 | { | |
103 | wxPanel *panel = new wxPanel(this); | |
c1dfe277 JS |
104 | |
105 | wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"), | |
106 | wxT("Sabre-toothed tiger"), wxT("T Rex") }; | |
76645ab3 | 107 | |
c1dfe277 JS |
108 | wxRadioBox *radiobox1 = new wxRadioBox(panel, -1, wxT("Choose one"), |
109 | wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS); | |
110 | ||
111 | wxString computers[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"), | |
112 | wxT("Another") }; | |
76645ab3 | 113 | |
c1dfe277 JS |
114 | wxRadioBox *radiobox2 = new wxRadioBox(panel, -1, |
115 | wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize, | |
116 | 4, computers, 0, wxRA_SPECIFY_COLS); | |
0b4d4194 | 117 | |
76645ab3 | 118 | wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); |
c1dfe277 JS |
119 | sizerPanel->Add(radiobox1, 2, wxEXPAND); |
120 | sizerPanel->Add(radiobox2, 1, wxEXPAND); | |
121 | panel->SetSizer(sizerPanel); | |
122 | ||
76645ab3 VZ |
123 | return panel; |
124 | } | |
c1dfe277 | 125 | |
76645ab3 VZ |
126 | wxPanel *MyNotebook::CreateVetoPage() |
127 | { | |
128 | wxPanel *panel = new wxPanel(this); | |
c1dfe277 | 129 | |
c1dfe277 JS |
130 | (void) new wxStaticText( panel, -1, |
131 | wxT("This page intentionally left blank"), wxPoint(10, 10) ); | |
c1dfe277 | 132 | |
76645ab3 VZ |
133 | return panel; |
134 | } | |
135 | ||
136 | wxPanel *MyNotebook::CreateBigButtonPage() | |
137 | { | |
138 | wxPanel *panel = new wxPanel(this); | |
c1dfe277 | 139 | |
76645ab3 | 140 | wxButton *buttonBig = new wxButton( panel, -1, wxT("Maximized button"), |
c1dfe277 JS |
141 | wxPoint(0, 0), wxSize(480, 360) ); |
142 | ||
76645ab3 | 143 | wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); |
c1dfe277 JS |
144 | sizerPanel->Add(buttonBig, 1, wxEXPAND); |
145 | panel->SetSizer(sizerPanel); | |
146 | ||
76645ab3 VZ |
147 | return panel; |
148 | } | |
149 | ||
c1dfe277 | 150 | |
76645ab3 VZ |
151 | wxPanel *MyNotebook::CreateInsertPage() |
152 | { | |
153 | wxPanel *panel = new wxPanel(this); | |
c1dfe277 | 154 | |
c1dfe277 JS |
155 | panel->SetBackgroundColour( wxColour( wxT("MAROON") ) ); |
156 | (void) new wxStaticText( panel, -1, | |
157 | wxT("This page has been inserted, not added."), wxPoint(10, 10) ); | |
c1dfe277 | 158 | |
76645ab3 VZ |
159 | return panel; |
160 | } | |
161 | ||
162 | void MyNotebook::CreateInitialPages() | |
163 | { | |
76645ab3 VZ |
164 | // Create and add some panels to the notebook |
165 | ||
dacaa6f1 | 166 | wxPanel *panel = CreateRadioButtonsPage(); |
76645ab3 VZ |
167 | AddPage( panel, RADIOBUTTONS_PAGE_NAME, FALSE, GetIconIndex() ); |
168 | ||
169 | panel = CreateVetoPage(); | |
170 | AddPage( panel, VETO_PAGE_NAME, FALSE, GetIconIndex() ); | |
c1dfe277 | 171 | |
76645ab3 VZ |
172 | panel = CreateBigButtonPage(); |
173 | AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, FALSE, GetIconIndex() ); | |
c1dfe277 | 174 | |
76645ab3 VZ |
175 | panel = CreateInsertPage(); |
176 | InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, FALSE, GetIconIndex() ); | |
177 | ||
178 | ||
179 | SetSelection(1); | |
c1dfe277 JS |
180 | } |
181 | ||
182 | int MyNotebook::GetIconIndex() const | |
0b4d4194 | 183 | { |
c1dfe277 JS |
184 | if (m_imageList) |
185 | { | |
186 | int nImages = m_imageList->GetImageCount(); | |
187 | if (nImages > 0) | |
188 | { | |
189 | return GetPageCount() % nImages; | |
190 | } | |
191 | } | |
192 | ||
193 | return -1; | |
0b4d4194 JS |
194 | } |
195 | ||
c1dfe277 JS |
196 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, |
197 | long style) | |
198 | : wxFrame((wxWindow *) NULL, -1, title, pos, size, style) | |
0b4d4194 | 199 | { |
c1dfe277 JS |
200 | m_panel = (wxPanel *) NULL; |
201 | m_notebook = (MyNotebook *) NULL; | |
76645ab3 VZ |
202 | |
203 | // create a dummy image list with a few icons | |
204 | wxSize imageSize(32, 32); | |
205 | ||
206 | m_imageList | |
207 | = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() ); | |
208 | ||
209 | m_imageList->Add | |
210 | ( | |
211 | wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize) | |
212 | ); | |
213 | ||
214 | m_imageList->Add | |
215 | ( | |
216 | wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize) | |
217 | ); | |
218 | ||
219 | m_imageList->Add | |
220 | ( | |
221 | wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize) | |
222 | ); | |
223 | ||
224 | m_imageList->Add | |
225 | ( | |
226 | wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize) | |
227 | ); | |
c1dfe277 JS |
228 | |
229 | m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, | |
c02e5a31 | 230 | wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE); |
c1dfe277 JS |
231 | |
232 | // Create remaining controls | |
233 | ||
234 | // must be in sync with Orient enum | |
235 | wxString strOrientations[] = | |
236 | { | |
237 | wxT("&Top"), | |
238 | wxT("&Bottom"), | |
239 | wxT("&Left"), | |
240 | wxT("&Right"), | |
241 | }; | |
242 | ||
243 | wxASSERT_MSG( WXSIZEOF(strOrientations) == ORIENT_MAX, | |
76645ab3 | 244 | wxT("Forgot to update something") ); |
c1dfe277 JS |
245 | |
246 | m_radioOrient = new wxRadioBox | |
9a6c9e31 VZ |
247 | ( |
248 | m_panel, ID_RADIO_ORIENT, | |
249 | wxT("&Tab orientation"), | |
250 | wxDefaultPosition, wxDefaultSize, | |
251 | WXSIZEOF(strOrientations), strOrientations, | |
252 | 1, wxRA_SPECIFY_COLS | |
253 | ); | |
c1dfe277 JS |
254 | |
255 | m_chkShowImages = new wxCheckBox( m_panel, ID_CHK_SHOWIMAGES, | |
256 | wxT("&Show images") ); | |
5982852a | 257 | #ifndef TEST_LISTBOOK |
9a6c9e31 VZ |
258 | m_chkMultiLine = new wxCheckBox( m_panel, ID_CHK_MULTILINE, |
259 | wxT("&Multiple lines") ); | |
5982852a | 260 | #endif // !TEST_LISTBOOK |
c1dfe277 JS |
261 | |
262 | m_btnAddPage = new wxButton( m_panel, ID_BTN_ADD_PAGE, wxT("&Add page") ); | |
263 | ||
264 | m_btnInsertPage = new wxButton( m_panel, ID_BTN_INSERT_PAGE, | |
265 | wxT("&Insert page") ); | |
266 | ||
3957448a VZ |
267 | m_btnDeleteCurPage = new wxButton( m_panel, ID_BTN_DELETE_CUR_PAGE, |
268 | wxT("&Delete current page") ); | |
269 | ||
270 | m_btnDeleteLastPage = new wxButton( m_panel, ID_BTN_DELETE_LAST_PAGE, | |
271 | wxT("Delete las&t page") ); | |
c1dfe277 JS |
272 | |
273 | m_btnNextPage = new wxButton( m_panel, ID_BTN_NEXT_PAGE, | |
274 | wxT("&Next page") ); | |
275 | ||
276 | m_btnExit = new wxButton( m_panel, wxID_OK, wxT("&Exit") ); | |
277 | m_btnExit->SetDefault(); | |
278 | ||
c1dfe277 JS |
279 | m_text = new wxTextCtrl(m_panel, -1, wxEmptyString, |
280 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY); | |
281 | ||
282 | m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) ); | |
283 | ||
c1dfe277 JS |
284 | // Set sizers |
285 | m_sizerFrame = new wxBoxSizer(wxVERTICAL); | |
286 | ||
287 | m_sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
288 | ||
289 | wxBoxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL); | |
9a6c9e31 VZ |
290 | sizerLeft->Add(m_radioOrient, 0, wxEXPAND); |
291 | sizerLeft->Add(m_chkShowImages, 0, wxEXPAND | wxTOP, 4); | |
5982852a | 292 | #ifndef TEST_LISTBOOK |
9a6c9e31 | 293 | sizerLeft->Add(m_chkMultiLine, 0, wxEXPAND | wxTOP, 4); |
5982852a | 294 | #endif // !TEST_LISTBOOK |
c1dfe277 | 295 | |
9a6c9e31 | 296 | sizerLeft->Add(0, 0, 1); // Spacer |
c1dfe277 | 297 | |
9a6c9e31 VZ |
298 | sizerLeft->Add(m_btnAddPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); |
299 | sizerLeft->Add(m_btnInsertPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); | |
300 | sizerLeft->Add(m_btnDeleteCurPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); | |
301 | sizerLeft->Add(m_btnDeleteLastPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); | |
302 | sizerLeft->Add(m_btnNextPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); | |
c1dfe277 | 303 | |
9a6c9e31 | 304 | sizerLeft->Add(0, 0, 1); // Spacer |
c1dfe277 | 305 | |
9a6c9e31 | 306 | sizerLeft->Add(m_btnExit, 0, wxEXPAND); |
c1dfe277 JS |
307 | |
308 | m_sizerTop->Add(sizerLeft, 0, wxEXPAND | wxALL, 4); | |
309 | ||
310 | ||
311 | m_sizerFrame->Add(m_sizerTop, 1, wxEXPAND); | |
312 | m_sizerFrame->Add(m_text, 0, wxEXPAND); | |
313 | ||
314 | ReInitNotebook(); | |
53071032 | 315 | m_notebook->CreateInitialPages(); |
c1dfe277 JS |
316 | |
317 | m_panel->SetSizer(m_sizerFrame); | |
318 | ||
319 | m_panel->SetAutoLayout(TRUE); | |
320 | ||
321 | m_sizerFrame->Fit(this); | |
322 | ||
323 | Centre(wxBOTH); | |
324 | ||
0b4d4194 JS |
325 | } |
326 | ||
c1dfe277 | 327 | MyFrame::~MyFrame() |
0b4d4194 | 328 | { |
c1dfe277 | 329 | delete wxLog::SetActiveTarget(m_logTargetOld); |
76645ab3 VZ |
330 | |
331 | if (m_imageList) | |
332 | { | |
333 | delete m_imageList; | |
334 | m_imageList = (wxImageList *) NULL; | |
335 | } | |
336 | ||
0b4d4194 JS |
337 | } |
338 | ||
c1dfe277 | 339 | void MyFrame::ReInitNotebook() |
0b4d4194 | 340 | { |
c1dfe277 | 341 | int flags; |
0b4d4194 | 342 | |
c1dfe277 JS |
343 | switch ( m_radioOrient->GetSelection() ) |
344 | { | |
345 | default: | |
346 | wxFAIL_MSG( wxT("unknown notebook orientation") ); | |
347 | // fall through | |
0b4d4194 | 348 | |
c1dfe277 JS |
349 | case ORIENT_TOP: |
350 | flags = wxNB_TOP; | |
351 | break; | |
0b4d4194 | 352 | |
c1dfe277 JS |
353 | case ORIENT_BOTTOM: |
354 | flags = wxNB_BOTTOM; | |
355 | break; | |
0b4d4194 | 356 | |
c1dfe277 JS |
357 | case ORIENT_LEFT: |
358 | flags = wxNB_LEFT; | |
359 | break; | |
0b4d4194 | 360 | |
c1dfe277 JS |
361 | case ORIENT_RIGHT: |
362 | flags = wxNB_RIGHT; | |
363 | break; | |
364 | } | |
365 | ||
5982852a | 366 | #ifndef TEST_LISTBOOK |
9a6c9e31 VZ |
367 | if ( m_chkMultiLine->IsChecked() ) |
368 | flags |= wxNB_MULTILINE; | |
5982852a | 369 | #endif // !TEST_LISTBOOK |
9a6c9e31 | 370 | |
c1dfe277 JS |
371 | MyNotebook *notebook = m_notebook; |
372 | ||
c1dfe277 JS |
373 | m_notebook = new MyNotebook(m_panel, ID_NOTEBOOK, |
374 | wxDefaultPosition, wxDefaultSize, | |
9a6c9e31 | 375 | flags); |
c1dfe277 | 376 | |
76645ab3 VZ |
377 | if ( m_chkShowImages->IsChecked() ) |
378 | { | |
379 | m_notebook->SetImageList(m_imageList); | |
380 | } | |
c1dfe277 | 381 | |
76645ab3 | 382 | if (notebook) |
c1dfe277 JS |
383 | { |
384 | int sel = notebook->GetSelection(); | |
385 | ||
386 | int count = notebook->GetPageCount(); | |
76645ab3 | 387 | for (int n = 0; n < count; n++) |
c1dfe277 | 388 | { |
76645ab3 | 389 | wxString str = notebook->GetPageText(n); |
c1dfe277 | 390 | |
4e62c3fd | 391 | wxWindow *page = m_notebook->CreatePage(str); |
76645ab3 | 392 | m_notebook->AddPage(page, str, FALSE, m_notebook->GetIconIndex() ); |
c1dfe277 JS |
393 | } |
394 | ||
395 | if (m_sizerNotebook) | |
396 | { | |
397 | m_sizerTop->Remove(m_sizerNotebook); | |
398 | } | |
399 | ||
400 | delete notebook; | |
401 | ||
402 | // restore selection | |
76645ab3 | 403 | if (sel != -1) |
c1dfe277 JS |
404 | { |
405 | m_notebook->SetSelection(sel); | |
406 | } | |
76645ab3 | 407 | |
c1dfe277 JS |
408 | } |
409 | ||
76645ab3 | 410 | |
4e62c3fd | 411 | m_sizerNotebook = new wxBookCtrlSizer(m_notebook); |
c1dfe277 JS |
412 | m_sizerTop->Add(m_sizerNotebook, 1, wxEXPAND | wxALL, 4); |
413 | m_sizerTop->Layout(); | |
414 | } | |
415 | ||
0b4d4194 | 416 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
c1dfe277 JS |
417 | EVT_RADIOBOX(ID_RADIO_ORIENT, MyFrame::OnCheckOrRadioBox) |
418 | EVT_CHECKBOX(ID_CHK_SHOWIMAGES, MyFrame::OnCheckOrRadioBox) | |
5982852a | 419 | #ifndef TEST_LISTBOOK |
9a6c9e31 | 420 | EVT_CHECKBOX(ID_CHK_MULTILINE, MyFrame::OnCheckOrRadioBox) |
5982852a | 421 | #endif // !TEST_LISTBOOK |
c1dfe277 JS |
422 | |
423 | EVT_BUTTON(ID_BTN_ADD_PAGE, MyFrame::OnButtonAddPage) | |
424 | EVT_BUTTON(ID_BTN_INSERT_PAGE, MyFrame::OnButtonInsertPage) | |
3957448a VZ |
425 | EVT_BUTTON(ID_BTN_DELETE_CUR_PAGE, MyFrame::OnButtonDeleteCurPage) |
426 | EVT_BUTTON(ID_BTN_DELETE_LAST_PAGE, MyFrame::OnButtonDeleteLastPage) | |
c1dfe277 JS |
427 | EVT_BUTTON(ID_BTN_NEXT_PAGE, MyFrame::OnButtonNextPage) |
428 | EVT_BUTTON(wxID_OK, MyFrame::OnButtonExit) | |
429 | ||
3957448a VZ |
430 | EVT_UPDATE_UI(ID_BTN_DELETE_CUR_PAGE, MyFrame::OnUpdateUIBtnDeleteCurPage) |
431 | EVT_UPDATE_UI(ID_BTN_DELETE_LAST_PAGE, MyFrame::OnUpdateUIBtnDeleteLastPage) | |
432 | ||
c1dfe277 JS |
433 | EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook) |
434 | EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook) | |
435 | ||
96d37807 | 436 | EVT_IDLE(MyFrame::OnIdle) |
0b4d4194 JS |
437 | END_EVENT_TABLE() |
438 | ||
c02e5a31 | 439 | void MyFrame::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) |
0b4d4194 | 440 | { |
9a6c9e31 | 441 | ReInitNotebook(); |
0b4d4194 JS |
442 | } |
443 | ||
c1dfe277 | 444 | void MyFrame::OnButtonAddPage( wxCommandEvent& WXUNUSED(event) ) |
326f9654 | 445 | { |
53071032 | 446 | static unsigned s_pageAdded = 0; |
477350ce VZ |
447 | |
448 | wxPanel *panel = new wxPanel( m_notebook, -1 ); | |
85b43fbf | 449 | (void) new wxButton( panel, -1, wxT("First button"), |
c1dfe277 | 450 | wxPoint(10, 10), wxSize(-1, -1) ); |
2b5f62a0 VZ |
451 | (void) new wxButton( panel, -1, wxT("Second button"), |
452 | wxPoint(50, 100), wxSize(-1, -1) ); | |
477350ce | 453 | |
76645ab3 | 454 | m_notebook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"), |
2b5f62a0 | 455 | ++s_pageAdded), TRUE, m_notebook->GetIconIndex() ); |
477350ce VZ |
456 | } |
457 | ||
c1dfe277 | 458 | void MyFrame::OnButtonInsertPage( wxCommandEvent& WXUNUSED(event) ) |
477350ce | 459 | { |
53071032 | 460 | static unsigned s_pageIns = 0; |
477350ce | 461 | |
76645ab3 | 462 | wxPanel *panel = m_notebook->CreateUserCreatedPage(); |
c1dfe277 JS |
463 | |
464 | m_notebook->InsertPage( 0, panel, | |
76645ab3 | 465 | wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), FALSE, |
c1dfe277 | 466 | m_notebook->GetIconIndex() ); |
477350ce | 467 | |
477350ce | 468 | m_notebook->SetSelection(0); |
326f9654 RR |
469 | } |
470 | ||
3957448a VZ |
471 | void MyFrame::OnButtonDeleteLastPage( wxCommandEvent& WXUNUSED(event) ) |
472 | { | |
473 | int page = m_notebook->GetPageCount(); | |
474 | ||
475 | if ( page != 0 ) | |
476 | { | |
477 | m_notebook->DeletePage(page - 1); | |
478 | } | |
479 | } | |
480 | ||
481 | void MyFrame::OnButtonDeleteCurPage( wxCommandEvent& WXUNUSED(event) ) | |
29f538ce | 482 | { |
c1dfe277 | 483 | int sel = m_notebook->GetSelection(); |
f6bcfd97 | 484 | |
c1dfe277 | 485 | if (sel != -1) |
f6bcfd97 | 486 | { |
c1dfe277 | 487 | m_notebook->DeletePage(sel); |
f6bcfd97 | 488 | } |
29f538ce RR |
489 | } |
490 | ||
c1dfe277 | 491 | void MyFrame::OnButtonNextPage( wxCommandEvent& WXUNUSED(event) ) |
33d0e17c RR |
492 | { |
493 | m_notebook->AdvanceSelection(); | |
494 | } | |
495 | ||
c1dfe277 | 496 | void MyFrame::OnButtonExit( wxCommandEvent& WXUNUSED(event) ) |
0b4d4194 | 497 | { |
c1dfe277 | 498 | Close(); |
0b4d4194 JS |
499 | } |
500 | ||
c1dfe277 | 501 | void MyFrame::OnNotebook(wxNotebookEvent& event) |
0b4d4194 | 502 | { |
c1dfe277 | 503 | wxString str = wxT("Unknown notebook event"); |
d22699b5 | 504 | |
c1dfe277 | 505 | wxEventType eventType = event.GetEventType(); |
0b4d4194 | 506 | |
c1dfe277 JS |
507 | if (eventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) |
508 | { | |
509 | str = wxT("Notebook changed"); | |
510 | } | |
511 | else if (eventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) | |
512 | { | |
513 | int idx = event.GetOldSelection(); | |
514 | if ( idx != -1 && m_notebook->GetPageText(idx) == VETO_PAGE_NAME ) | |
515 | { | |
516 | if | |
517 | ( | |
518 | wxMessageBox( | |
519 | wxT("Are you sure you want to leave this notebook page?\n") | |
520 | wxT("(This demonstrates veto-ing)"), | |
521 | wxT("Notebook sample"), | |
522 | wxICON_QUESTION | wxYES_NO, this) != wxYES ) | |
523 | { | |
524 | event.Veto(); | |
525 | ||
526 | return; | |
527 | } | |
528 | ||
529 | } | |
530 | ||
531 | str = wxT("Notebook changing"); | |
532 | } | |
0b4d4194 | 533 | |
c1dfe277 | 534 | static int s_numNotebookEvents = 0; |
0b4d4194 | 535 | |
c1dfe277 | 536 | wxLogMessage(wxT("Notebook event #%d: %s (%d)"), |
44e1a03f | 537 | s_numNotebookEvents++, str.c_str(), eventType); |
0b4d4194 | 538 | |
c1dfe277 | 539 | m_text->SetInsertionPointEnd(); |
0b4d4194 | 540 | |
c1dfe277 | 541 | event.Skip(); |
0b4d4194 JS |
542 | } |
543 | ||
c1dfe277 | 544 | void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) |
96d37807 VZ |
545 | { |
546 | static int s_nPages = -1; | |
547 | static int s_nSel = -1; | |
548 | ||
549 | int nPages = m_notebook->GetPageCount(); | |
550 | int nSel = m_notebook->GetSelection(); | |
551 | if ( nPages != s_nPages || nSel != s_nSel ) | |
552 | { | |
553 | s_nPages = nPages; | |
554 | s_nSel = nSel; | |
555 | ||
556 | wxString title; | |
c1dfe277 | 557 | title.Printf(wxT("Notebook (%d pages, selection: %d)"), nPages, nSel); |
96d37807 VZ |
558 | |
559 | SetTitle(title); | |
560 | } | |
561 | } | |
3957448a VZ |
562 | |
563 | void MyFrame::OnUpdateUIBtnDeleteCurPage(wxUpdateUIEvent& event) | |
564 | { | |
565 | event.Enable( m_notebook->GetSelection() != -1 ); | |
566 | } | |
567 | ||
568 | void MyFrame::OnUpdateUIBtnDeleteLastPage(wxUpdateUIEvent& event) | |
569 | { | |
570 | event.Enable( m_notebook->GetPageCount() != 0 ); | |
571 | } |