]>
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 | ||
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 | ||
1cfac5b8 WS |
95 | (void) new wxButton( panel, wxID_ANY, wxT("Button"), |
96 | wxPoint(10, 10), wxDefaultSize ); | |
76645ab3 VZ |
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 | |
1cfac5b8 | 108 | wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose one"), |
c1dfe277 JS |
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 | |
1cfac5b8 | 114 | wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY, |
c1dfe277 JS |
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 | |
1cfac5b8 | 130 | (void) new wxStaticText( panel, wxID_ANY, |
c1dfe277 | 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 | |
ed420f6d | 140 | wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button")); |
c1dfe277 | 141 | |
76645ab3 | 142 | wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); |
c1dfe277 JS |
143 | sizerPanel->Add(buttonBig, 1, wxEXPAND); |
144 | panel->SetSizer(sizerPanel); | |
145 | ||
76645ab3 VZ |
146 | return panel; |
147 | } | |
148 | ||
c1dfe277 | 149 | |
76645ab3 VZ |
150 | wxPanel *MyNotebook::CreateInsertPage() |
151 | { | |
152 | wxPanel *panel = new wxPanel(this); | |
c1dfe277 | 153 | |
c1dfe277 | 154 | panel->SetBackgroundColour( wxColour( wxT("MAROON") ) ); |
1cfac5b8 | 155 | (void) new wxStaticText( panel, wxID_ANY, |
c1dfe277 | 156 | wxT("This page has been inserted, not added."), wxPoint(10, 10) ); |
c1dfe277 | 157 | |
76645ab3 VZ |
158 | return panel; |
159 | } | |
160 | ||
161 | void MyNotebook::CreateInitialPages() | |
162 | { | |
76645ab3 VZ |
163 | // Create and add some panels to the notebook |
164 | ||
dacaa6f1 | 165 | wxPanel *panel = CreateRadioButtonsPage(); |
1cfac5b8 | 166 | AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex() ); |
76645ab3 VZ |
167 | |
168 | panel = CreateVetoPage(); | |
1cfac5b8 | 169 | AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex() ); |
c1dfe277 | 170 | |
76645ab3 | 171 | panel = CreateBigButtonPage(); |
1cfac5b8 | 172 | AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex() ); |
c1dfe277 | 173 | |
76645ab3 | 174 | panel = CreateInsertPage(); |
1cfac5b8 | 175 | InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex() ); |
76645ab3 VZ |
176 | |
177 | ||
178 | SetSelection(1); | |
c1dfe277 JS |
179 | } |
180 | ||
181 | int MyNotebook::GetIconIndex() const | |
0b4d4194 | 182 | { |
c1dfe277 JS |
183 | if (m_imageList) |
184 | { | |
185 | int nImages = m_imageList->GetImageCount(); | |
186 | if (nImages > 0) | |
187 | { | |
188 | return GetPageCount() % nImages; | |
189 | } | |
190 | } | |
191 | ||
192 | return -1; | |
0b4d4194 JS |
193 | } |
194 | ||
c1dfe277 JS |
195 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, |
196 | long style) | |
1cfac5b8 | 197 | : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style) |
0b4d4194 | 198 | { |
c1dfe277 JS |
199 | m_panel = (wxPanel *) NULL; |
200 | m_notebook = (MyNotebook *) NULL; | |
76645ab3 VZ |
201 | |
202 | // create a dummy image list with a few icons | |
203 | wxSize imageSize(32, 32); | |
204 | ||
205 | m_imageList | |
206 | = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() ); | |
207 | ||
208 | m_imageList->Add | |
209 | ( | |
210 | wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize) | |
211 | ); | |
212 | ||
213 | m_imageList->Add | |
214 | ( | |
215 | wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize) | |
216 | ); | |
217 | ||
218 | m_imageList->Add | |
219 | ( | |
220 | wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize) | |
221 | ); | |
222 | ||
223 | m_imageList->Add | |
224 | ( | |
225 | wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize) | |
226 | ); | |
c1dfe277 | 227 | |
1cfac5b8 | 228 | m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, |
c02e5a31 | 229 | wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE); |
c1dfe277 JS |
230 | |
231 | // Create remaining controls | |
232 | ||
233 | // must be in sync with Orient enum | |
234 | wxString strOrientations[] = | |
235 | { | |
236 | wxT("&Top"), | |
237 | wxT("&Bottom"), | |
238 | wxT("&Left"), | |
239 | wxT("&Right"), | |
240 | }; | |
241 | ||
242 | wxASSERT_MSG( WXSIZEOF(strOrientations) == ORIENT_MAX, | |
76645ab3 | 243 | wxT("Forgot to update something") ); |
c1dfe277 JS |
244 | |
245 | m_radioOrient = new wxRadioBox | |
9a6c9e31 VZ |
246 | ( |
247 | m_panel, ID_RADIO_ORIENT, | |
248 | wxT("&Tab orientation"), | |
249 | wxDefaultPosition, wxDefaultSize, | |
250 | WXSIZEOF(strOrientations), strOrientations, | |
251 | 1, wxRA_SPECIFY_COLS | |
252 | ); | |
c1dfe277 JS |
253 | |
254 | m_chkShowImages = new wxCheckBox( m_panel, ID_CHK_SHOWIMAGES, | |
255 | wxT("&Show images") ); | |
5982852a | 256 | #ifndef TEST_LISTBOOK |
9a6c9e31 VZ |
257 | m_chkMultiLine = new wxCheckBox( m_panel, ID_CHK_MULTILINE, |
258 | wxT("&Multiple lines") ); | |
5982852a | 259 | #endif // !TEST_LISTBOOK |
c1dfe277 JS |
260 | |
261 | m_btnAddPage = new wxButton( m_panel, ID_BTN_ADD_PAGE, wxT("&Add page") ); | |
262 | ||
263 | m_btnInsertPage = new wxButton( m_panel, ID_BTN_INSERT_PAGE, | |
264 | wxT("&Insert page") ); | |
265 | ||
3957448a VZ |
266 | m_btnDeleteCurPage = new wxButton( m_panel, ID_BTN_DELETE_CUR_PAGE, |
267 | wxT("&Delete current page") ); | |
268 | ||
269 | m_btnDeleteLastPage = new wxButton( m_panel, ID_BTN_DELETE_LAST_PAGE, | |
270 | wxT("Delete las&t page") ); | |
c1dfe277 JS |
271 | |
272 | m_btnNextPage = new wxButton( m_panel, ID_BTN_NEXT_PAGE, | |
273 | wxT("&Next page") ); | |
274 | ||
275 | m_btnExit = new wxButton( m_panel, wxID_OK, wxT("&Exit") ); | |
276 | m_btnExit->SetDefault(); | |
277 | ||
f07941fc | 278 | #if wxUSE_LOG |
1cfac5b8 | 279 | m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, |
c1dfe277 JS |
280 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY); |
281 | ||
282 | m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) ); | |
f07941fc | 283 | #endif // wxUSE_LOG |
c1dfe277 | 284 | |
c1dfe277 JS |
285 | // Set sizers |
286 | m_sizerFrame = new wxBoxSizer(wxVERTICAL); | |
287 | ||
288 | m_sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
289 | ||
290 | wxBoxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL); | |
9a6c9e31 VZ |
291 | sizerLeft->Add(m_radioOrient, 0, wxEXPAND); |
292 | sizerLeft->Add(m_chkShowImages, 0, wxEXPAND | wxTOP, 4); | |
5982852a | 293 | #ifndef TEST_LISTBOOK |
9a6c9e31 | 294 | sizerLeft->Add(m_chkMultiLine, 0, wxEXPAND | wxTOP, 4); |
5982852a | 295 | #endif // !TEST_LISTBOOK |
c1dfe277 | 296 | |
9a6c9e31 | 297 | sizerLeft->Add(0, 0, 1); // Spacer |
c1dfe277 | 298 | |
9a6c9e31 VZ |
299 | sizerLeft->Add(m_btnAddPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); |
300 | sizerLeft->Add(m_btnInsertPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); | |
301 | sizerLeft->Add(m_btnDeleteCurPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); | |
302 | sizerLeft->Add(m_btnDeleteLastPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); | |
303 | sizerLeft->Add(m_btnNextPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4); | |
c1dfe277 | 304 | |
9a6c9e31 | 305 | sizerLeft->Add(0, 0, 1); // Spacer |
c1dfe277 | 306 | |
9a6c9e31 | 307 | sizerLeft->Add(m_btnExit, 0, wxEXPAND); |
c1dfe277 JS |
308 | |
309 | m_sizerTop->Add(sizerLeft, 0, wxEXPAND | wxALL, 4); | |
310 | ||
311 | ||
312 | m_sizerFrame->Add(m_sizerTop, 1, wxEXPAND); | |
f07941fc | 313 | #if wxUSE_LOG |
c1dfe277 | 314 | m_sizerFrame->Add(m_text, 0, wxEXPAND); |
f07941fc | 315 | #endif // wxUSE_LOG |
c1dfe277 JS |
316 | |
317 | ReInitNotebook(); | |
53071032 | 318 | m_notebook->CreateInitialPages(); |
c1dfe277 JS |
319 | |
320 | m_panel->SetSizer(m_sizerFrame); | |
321 | ||
c1dfe277 | 322 | m_sizerFrame->Fit(this); |
ed420f6d | 323 | m_sizerFrame->SetSizeHints(this); |
c1dfe277 JS |
324 | |
325 | Centre(wxBOTH); | |
326 | ||
0b4d4194 JS |
327 | } |
328 | ||
c1dfe277 | 329 | MyFrame::~MyFrame() |
0b4d4194 | 330 | { |
f07941fc | 331 | #if wxUSE_LOG |
c1dfe277 | 332 | delete wxLog::SetActiveTarget(m_logTargetOld); |
f07941fc | 333 | #endif // wxUSE_LOG |
76645ab3 VZ |
334 | |
335 | if (m_imageList) | |
336 | { | |
337 | delete m_imageList; | |
338 | m_imageList = (wxImageList *) NULL; | |
339 | } | |
340 | ||
0b4d4194 JS |
341 | } |
342 | ||
c1dfe277 | 343 | void MyFrame::ReInitNotebook() |
0b4d4194 | 344 | { |
c1dfe277 | 345 | int flags; |
0b4d4194 | 346 | |
c1dfe277 JS |
347 | switch ( m_radioOrient->GetSelection() ) |
348 | { | |
349 | default: | |
350 | wxFAIL_MSG( wxT("unknown notebook orientation") ); | |
351 | // fall through | |
0b4d4194 | 352 | |
c1dfe277 JS |
353 | case ORIENT_TOP: |
354 | flags = wxNB_TOP; | |
355 | break; | |
0b4d4194 | 356 | |
c1dfe277 JS |
357 | case ORIENT_BOTTOM: |
358 | flags = wxNB_BOTTOM; | |
359 | break; | |
0b4d4194 | 360 | |
c1dfe277 JS |
361 | case ORIENT_LEFT: |
362 | flags = wxNB_LEFT; | |
363 | break; | |
0b4d4194 | 364 | |
c1dfe277 JS |
365 | case ORIENT_RIGHT: |
366 | flags = wxNB_RIGHT; | |
367 | break; | |
368 | } | |
369 | ||
5982852a | 370 | #ifndef TEST_LISTBOOK |
9a6c9e31 VZ |
371 | if ( m_chkMultiLine->IsChecked() ) |
372 | flags |= wxNB_MULTILINE; | |
5982852a | 373 | #endif // !TEST_LISTBOOK |
9a6c9e31 | 374 | |
c1dfe277 JS |
375 | MyNotebook *notebook = m_notebook; |
376 | ||
c1dfe277 JS |
377 | m_notebook = new MyNotebook(m_panel, ID_NOTEBOOK, |
378 | wxDefaultPosition, wxDefaultSize, | |
9a6c9e31 | 379 | flags); |
c1dfe277 | 380 | |
76645ab3 VZ |
381 | if ( m_chkShowImages->IsChecked() ) |
382 | { | |
383 | m_notebook->SetImageList(m_imageList); | |
384 | } | |
c1dfe277 | 385 | |
76645ab3 | 386 | if (notebook) |
c1dfe277 JS |
387 | { |
388 | int sel = notebook->GetSelection(); | |
389 | ||
390 | int count = notebook->GetPageCount(); | |
76645ab3 | 391 | for (int n = 0; n < count; n++) |
c1dfe277 | 392 | { |
76645ab3 | 393 | wxString str = notebook->GetPageText(n); |
c1dfe277 | 394 | |
4e62c3fd | 395 | wxWindow *page = m_notebook->CreatePage(str); |
1cfac5b8 | 396 | m_notebook->AddPage(page, str, false, m_notebook->GetIconIndex() ); |
c1dfe277 JS |
397 | } |
398 | ||
134155b1 | 399 | m_sizerTop->Detach(notebook); |
37144cf0 | 400 | |
c1dfe277 JS |
401 | delete notebook; |
402 | ||
403 | // restore selection | |
76645ab3 | 404 | if (sel != -1) |
c1dfe277 JS |
405 | { |
406 | m_notebook->SetSelection(sel); | |
407 | } | |
76645ab3 | 408 | |
c1dfe277 JS |
409 | } |
410 | ||
76645ab3 | 411 | |
37144cf0 | 412 | m_sizerTop->Add(m_notebook, 1, wxEXPAND | wxALL, 4); |
c1dfe277 JS |
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 | 447 | |
1cfac5b8 WS |
448 | wxPanel *panel = new wxPanel( m_notebook, wxID_ANY ); |
449 | (void) new wxButton( panel, wxID_ANY, wxT("First button"), | |
450 | wxPoint(10, 10), wxDefaultSize ); | |
451 | (void) new wxButton( panel, wxID_ANY, wxT("Second button"), | |
452 | wxPoint(50, 100), wxDefaultSize ); | |
477350ce | 453 | |
76645ab3 | 454 | m_notebook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"), |
1cfac5b8 | 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, | |
1cfac5b8 | 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 | |
f07941fc | 539 | #if wxUSE_LOG |
c1dfe277 | 540 | m_text->SetInsertionPointEnd(); |
f07941fc | 541 | #endif // wxUSE_LOG |
0b4d4194 | 542 | |
c1dfe277 | 543 | event.Skip(); |
0b4d4194 JS |
544 | } |
545 | ||
c1dfe277 | 546 | void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) |
96d37807 VZ |
547 | { |
548 | static int s_nPages = -1; | |
549 | static int s_nSel = -1; | |
550 | ||
551 | int nPages = m_notebook->GetPageCount(); | |
552 | int nSel = m_notebook->GetSelection(); | |
553 | if ( nPages != s_nPages || nSel != s_nSel ) | |
554 | { | |
555 | s_nPages = nPages; | |
556 | s_nSel = nSel; | |
557 | ||
558 | wxString title; | |
c1dfe277 | 559 | title.Printf(wxT("Notebook (%d pages, selection: %d)"), nPages, nSel); |
96d37807 VZ |
560 | |
561 | SetTitle(title); | |
562 | } | |
563 | } | |
3957448a VZ |
564 | |
565 | void MyFrame::OnUpdateUIBtnDeleteCurPage(wxUpdateUIEvent& event) | |
566 | { | |
567 | event.Enable( m_notebook->GetSelection() != -1 ); | |
568 | } | |
569 | ||
570 | void MyFrame::OnUpdateUIBtnDeleteLastPage(wxUpdateUIEvent& event) | |
571 | { | |
572 | event.Enable( m_notebook->GetPageCount() != 0 ); | |
573 | } |