]>
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 |
526954c5 | 9 | // Licence: wxWindows licence |
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" | |
d0a84b63 VZ |
25 | #include "wx/cshelp.h" |
26 | #include "wx/utils.h" | |
b2f757f9 | 27 | #include "notebook.h" |
0b4d4194 | 28 | |
d52f6c4e VZ |
29 | #if !defined(__WXMSW__) && !defined(__WXPM__) |
30 | #include "../sample.xpm" | |
31 | #endif | |
32 | ||
425ec0a5 FM |
33 | //----------------------------------------------------------------------------- |
34 | // MyApp | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
0b4d4194 JS |
37 | IMPLEMENT_APP(MyApp) |
38 | ||
477350ce | 39 | bool MyApp::OnInit() |
0b4d4194 | 40 | { |
45e6e6f8 VZ |
41 | if ( !wxApp::OnInit() ) |
42 | return false; | |
43 | ||
df1496e3 VZ |
44 | #if wxUSE_HELP |
45 | wxHelpProvider::Set( new wxSimpleHelpProvider ); | |
46 | #endif | |
47 | ||
c1dfe277 | 48 | // Create the main window |
eca15c0d | 49 | MyFrame *frame = new MyFrame(); |
425ec0a5 | 50 | SetTopWindow(frame); |
c1dfe277 JS |
51 | |
52 | // Problem with generic wxNotebook implementation whereby it doesn't size | |
53 | // properly unless you set the size again | |
3a5bcc4d | 54 | #if defined(__WXMOTIF__) |
c1dfe277 JS |
55 | int width, height; |
56 | frame->GetSize(& width, & height); | |
422d0ff0 | 57 | frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height); |
5dcf05ae JS |
58 | #endif |
59 | ||
c1dfe277 JS |
60 | frame->Show(); |
61 | ||
1cfac5b8 | 62 | return true; |
0b4d4194 JS |
63 | } |
64 | ||
425ec0a5 FM |
65 | |
66 | //----------------------------------------------------------------------------- | |
67 | // Creation functions | |
68 | //----------------------------------------------------------------------------- | |
69 | ||
61c083e7 | 70 | wxPanel *CreateUserCreatedPage(wxBookCtrlBase *parent) |
0b4d4194 | 71 | { |
9133965e | 72 | wxPanel *panel = new wxPanel(parent); |
76645ab3 | 73 | |
df1496e3 VZ |
74 | #if wxUSE_HELP |
75 | panel->SetHelpText( wxT( "Panel with a Button" ) ); | |
76 | #endif | |
77 | ||
1cfac5b8 | 78 | (void) new wxButton( panel, wxID_ANY, wxT("Button"), |
425ec0a5 | 79 | wxPoint(10, 10), wxDefaultSize ); |
76645ab3 VZ |
80 | |
81 | return panel; | |
82 | } | |
83 | ||
61c083e7 | 84 | wxPanel *CreateRadioButtonsPage(wxBookCtrlBase *parent) |
76645ab3 | 85 | { |
9133965e | 86 | wxPanel *panel = new wxPanel(parent); |
c1dfe277 | 87 | |
df1496e3 VZ |
88 | #if wxUSE_HELP |
89 | panel->SetHelpText( wxT( "Panel with some Radio Buttons" ) ); | |
90 | #endif | |
91 | ||
ce00f59b | 92 | wxString animals[] = |
425ec0a5 | 93 | { wxT("Fox"), wxT("Hare"), wxT("Rabbit"), |
c1dfe277 | 94 | wxT("Sabre-toothed tiger"), wxT("T Rex") }; |
76645ab3 | 95 | |
1cfac5b8 | 96 | wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose one"), |
c1dfe277 JS |
97 | wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS); |
98 | ||
ce00f59b | 99 | wxString computers[] = |
425ec0a5 | 100 | { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"), |
c1dfe277 | 101 | wxT("Another") }; |
76645ab3 | 102 | |
1cfac5b8 | 103 | wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY, |
c1dfe277 JS |
104 | wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize, |
105 | 4, computers, 0, wxRA_SPECIFY_COLS); | |
0b4d4194 | 106 | |
76645ab3 | 107 | wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); |
c1dfe277 JS |
108 | sizerPanel->Add(radiobox1, 2, wxEXPAND); |
109 | sizerPanel->Add(radiobox2, 1, wxEXPAND); | |
110 | panel->SetSizer(sizerPanel); | |
111 | ||
76645ab3 VZ |
112 | return panel; |
113 | } | |
c1dfe277 | 114 | |
61c083e7 | 115 | wxPanel *CreateVetoPage(wxBookCtrlBase *parent) |
76645ab3 | 116 | { |
9133965e | 117 | wxPanel *panel = new wxPanel(parent); |
c1dfe277 | 118 | |
df1496e3 VZ |
119 | #if wxUSE_HELP |
120 | panel->SetHelpText( wxT( "An empty panel" ) ); | |
121 | #endif | |
122 | ||
1cfac5b8 | 123 | (void) new wxStaticText( panel, wxID_ANY, |
ce00f59b | 124 | wxT("This page intentionally left blank"), |
425ec0a5 | 125 | wxPoint(10, 10) ); |
c1dfe277 | 126 | |
76645ab3 VZ |
127 | return panel; |
128 | } | |
129 | ||
61c083e7 | 130 | wxPanel *CreateBigButtonPage(wxBookCtrlBase *parent) |
76645ab3 | 131 | { |
9133965e | 132 | wxPanel *panel = new wxPanel(parent); |
c1dfe277 | 133 | |
df1496e3 VZ |
134 | #if wxUSE_HELP |
135 | panel->SetHelpText( wxT( "Panel with a maximized button" ) ); | |
136 | #endif | |
137 | ||
ed420f6d | 138 | wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button")); |
c1dfe277 | 139 | |
76645ab3 | 140 | wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); |
c1dfe277 JS |
141 | sizerPanel->Add(buttonBig, 1, wxEXPAND); |
142 | panel->SetSizer(sizerPanel); | |
143 | ||
76645ab3 VZ |
144 | return panel; |
145 | } | |
146 | ||
61c083e7 | 147 | wxPanel *CreateInsertPage(wxBookCtrlBase *parent) |
76645ab3 | 148 | { |
9133965e | 149 | wxPanel *panel = new wxPanel(parent); |
c1dfe277 | 150 | |
df1496e3 VZ |
151 | #if wxUSE_HELP |
152 | panel->SetHelpText( wxT( "Maroon panel" ) ); | |
153 | #endif | |
154 | ||
c1dfe277 | 155 | panel->SetBackgroundColour( wxColour( wxT("MAROON") ) ); |
1cfac5b8 | 156 | (void) new wxStaticText( panel, wxID_ANY, |
ce00f59b | 157 | wxT("This page has been inserted, not added."), |
425ec0a5 | 158 | wxPoint(10, 10) ); |
c1dfe277 | 159 | |
76645ab3 VZ |
160 | return panel; |
161 | } | |
162 | ||
61c083e7 | 163 | int GetIconIndex(wxBookCtrlBase* bookCtrl) |
76645ab3 | 164 | { |
9133965e WS |
165 | if (bookCtrl && bookCtrl->GetImageList()) |
166 | { | |
167 | int nImages = bookCtrl->GetImageList()->GetImageCount(); | |
168 | if (nImages > 0) | |
169 | { | |
170 | return bookCtrl->GetPageCount() % nImages; | |
171 | } | |
172 | } | |
76645ab3 | 173 | |
9133965e WS |
174 | return -1; |
175 | } | |
76645ab3 | 176 | |
61c083e7 | 177 | void CreateInitialPages(wxBookCtrlBase *parent) |
9133965e WS |
178 | { |
179 | // Create and add some panels to the notebook | |
180 | ||
181 | wxPanel *panel = CreateRadioButtonsPage(parent); | |
182 | parent->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(parent) ); | |
c1dfe277 | 183 | |
9133965e WS |
184 | panel = CreateVetoPage(parent); |
185 | parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) ); | |
c1dfe277 | 186 | |
9133965e WS |
187 | panel = CreateBigButtonPage(parent); |
188 | parent->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(parent) ); | |
76645ab3 | 189 | |
9133965e WS |
190 | panel = CreateInsertPage(parent); |
191 | parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) ); | |
76645ab3 | 192 | |
9133965e | 193 | parent->SetSelection(1); |
c1dfe277 JS |
194 | } |
195 | ||
61c083e7 | 196 | wxPanel *CreatePage(wxBookCtrlBase *parent, const wxString&pageName) |
0b4d4194 | 197 | { |
eca15c0d VZ |
198 | if ( pageName.Contains(INSERTED_PAGE_NAME) || |
199 | pageName.Contains(ADDED_PAGE_NAME) || | |
200 | pageName.Contains(ADDED_SUB_PAGE_NAME) || | |
201 | pageName.Contains(ADDED_PAGE_NAME_BEFORE) ) | |
9133965e | 202 | return CreateUserCreatedPage(parent); |
c1dfe277 | 203 | |
eca15c0d | 204 | if ( pageName == I_WAS_INSERTED_PAGE_NAME ) |
9133965e | 205 | return CreateInsertPage(parent); |
9133965e | 206 | |
eca15c0d | 207 | if ( pageName == VETO_PAGE_NAME ) |
9133965e | 208 | return CreateVetoPage(parent); |
9133965e | 209 | |
eca15c0d | 210 | if ( pageName == RADIOBUTTONS_PAGE_NAME ) |
9133965e | 211 | return CreateRadioButtonsPage(parent); |
9133965e | 212 | |
eca15c0d | 213 | if ( pageName == MAXIMIZED_BUTTON_PAGE_NAME ) |
9133965e | 214 | return CreateBigButtonPage(parent); |
9133965e | 215 | |
9a83f860 | 216 | wxFAIL_MSG( wxT("unknown page name") ); |
9133965e | 217 | |
eca15c0d | 218 | return NULL; |
0b4d4194 JS |
219 | } |
220 | ||
425ec0a5 FM |
221 | |
222 | //----------------------------------------------------------------------------- | |
223 | // MyFrame | |
224 | //----------------------------------------------------------------------------- | |
225 | ||
226 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
227 | // File menu | |
228 | EVT_MENU_RANGE(ID_BOOK_NOTEBOOK, ID_BOOK_MAX, MyFrame::OnType) | |
229 | EVT_MENU_RANGE(ID_ORIENT_DEFAULT, ID_ORIENT_MAX, MyFrame::OnOrient) | |
230 | EVT_MENU(ID_SHOW_IMAGES, MyFrame::OnShowImages) | |
231 | EVT_MENU(ID_MULTI, MyFrame::OnMulti) | |
232 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) | |
233 | ||
234 | // Operations menu | |
235 | EVT_MENU(ID_ADD_PAGE, MyFrame::OnAddPage) | |
236 | EVT_MENU(ID_ADD_PAGE_NO_SELECT, MyFrame::OnAddPageNoSelect) | |
237 | EVT_MENU(ID_INSERT_PAGE, MyFrame::OnInsertPage) | |
238 | EVT_MENU(ID_DELETE_CUR_PAGE, MyFrame::OnDeleteCurPage) | |
239 | EVT_MENU(ID_DELETE_LAST_PAGE, MyFrame::OnDeleteLastPage) | |
240 | EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage) | |
f7aaef4d VZ |
241 | EVT_MENU(ID_CHANGE_SELECTION, MyFrame::OnChangeSelection) |
242 | EVT_MENU(ID_SET_SELECTION, MyFrame::OnSetSelection) | |
425ec0a5 FM |
243 | |
244 | #if wxUSE_HELP | |
245 | EVT_MENU(ID_CONTEXT_HELP, MyFrame::OnContextHelp) | |
246 | #endif // wxUSE_HELP | |
247 | EVT_MENU(ID_HITTEST, MyFrame::OnHitTest) | |
248 | ||
249 | // Book controls | |
250 | #if wxUSE_NOTEBOOK | |
251 | EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnNotebook) | |
252 | EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnNotebook) | |
253 | #endif | |
254 | #if wxUSE_LISTBOOK | |
255 | EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnListbook) | |
256 | EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnListbook) | |
257 | #endif | |
258 | #if wxUSE_CHOICEBOOK | |
259 | EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnChoicebook) | |
260 | EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnChoicebook) | |
261 | #endif | |
262 | #if wxUSE_TREEBOOK | |
263 | EVT_TREEBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnTreebook) | |
264 | EVT_TREEBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnTreebook) | |
265 | ||
266 | EVT_MENU(ID_ADD_SUB_PAGE, MyFrame::OnAddSubPage) | |
267 | EVT_MENU(ID_ADD_PAGE_BEFORE, MyFrame::OnAddPageBefore) | |
268 | EVT_UPDATE_UI_RANGE(ID_ADD_PAGE_BEFORE, ID_ADD_SUB_PAGE, | |
269 | MyFrame::OnUpdateTreeMenu) | |
270 | #endif | |
271 | #if wxUSE_TOOLBOOK | |
272 | EVT_TOOLBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnToolbook) | |
273 | EVT_TOOLBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnToolbook) | |
274 | #endif | |
275 | ||
276 | // Update title in idle time | |
277 | EVT_IDLE(MyFrame::OnIdle) | |
278 | END_EVENT_TABLE() | |
279 | ||
eca15c0d | 280 | MyFrame::MyFrame() |
df1496e3 | 281 | : wxFrame(NULL, wxID_ANY, wxString(wxT("wxWidgets book controls sample"))) |
0b4d4194 | 282 | { |
df1496e3 VZ |
283 | #if wxUSE_HELP |
284 | SetExtraStyle(wxFRAME_EX_CONTEXTHELP); | |
285 | #endif // wxUSE_HELP | |
286 | ||
53d09d55 | 287 | #if wxUSE_NOTEBOOK |
eca15c0d | 288 | m_type = Type_Notebook; |
53d09d55 | 289 | #elif wxUSE_CHOICEBOOK |
eca15c0d | 290 | m_type = Type_Choicebook; |
53d09d55 | 291 | #elif wxUSE_LISTBOOK |
eca15c0d VZ |
292 | m_type = Type_Listbook; |
293 | #elif wxUSE_TREEBOOK | |
294 | m_type = Type_Treebook; | |
fab8784c VZ |
295 | #elif wxUSE_TOOLBOOK |
296 | m_type = Type_Toolbook; | |
abae3b80 | 297 | #else |
53d09d55 WS |
298 | #error "Don't use Notebook sample without any book enabled in wxWidgets build!" |
299 | #endif | |
300 | ||
9133965e WS |
301 | m_orient = ID_ORIENT_DEFAULT; |
302 | m_chkShowImages = true; | |
303 | m_multi = false; | |
304 | ||
d52f6c4e | 305 | SetIcon(wxICON(sample)); |
9133965e | 306 | |
d52f6c4e | 307 | // menu of the sample |
9133965e WS |
308 | wxMenu *menuType = new wxMenu; |
309 | #if wxUSE_NOTEBOOK | |
310 | menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, wxT("&Notebook\tCtrl-1")); | |
311 | #endif | |
312 | #if wxUSE_LISTBOOK | |
313 | menuType->AppendRadioItem(ID_BOOK_LISTBOOK, wxT("&Listbook\tCtrl-2")); | |
314 | #endif | |
315 | #if wxUSE_CHOICEBOOK | |
316 | menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3")); | |
317 | #endif | |
eca15c0d VZ |
318 | #if wxUSE_TREEBOOK |
319 | menuType->AppendRadioItem(ID_BOOK_TREEBOOK, wxT("&Treebook\tCtrl-4")); | |
320 | #endif | |
d709457c JS |
321 | #if wxUSE_TOOLBOOK |
322 | menuType->AppendRadioItem(ID_BOOK_TOOLBOOK, wxT("T&oolbook\tCtrl-5")); | |
323 | #endif | |
eca15c0d VZ |
324 | |
325 | menuType->Check(ID_BOOK_NOTEBOOK + m_type, true); | |
9133965e WS |
326 | |
327 | wxMenu *menuOrient = new wxMenu; | |
76680db4 VZ |
328 | menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tAlt-0")); |
329 | menuOrient->AppendRadioItem(ID_ORIENT_TOP, wxT("&Top\tAlt-1")); | |
330 | menuOrient->AppendRadioItem(ID_ORIENT_BOTTOM, wxT("&Bottom\tAlt-2")); | |
331 | menuOrient->AppendRadioItem(ID_ORIENT_LEFT, wxT("&Left\tAlt-3")); | |
332 | menuOrient->AppendRadioItem(ID_ORIENT_RIGHT, wxT("&Right\tAlt-4")); | |
eca15c0d | 333 | |
d0a84b63 VZ |
334 | wxMenu *menuPageOperations = new wxMenu; |
335 | menuPageOperations->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A")); | |
a85dda4a | 336 | menuPageOperations->Append(ID_ADD_PAGE_NO_SELECT, wxT("&Add page (don't select)\tAlt-B")); |
d0a84b63 VZ |
337 | menuPageOperations->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I")); |
338 | menuPageOperations->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D")); | |
339 | menuPageOperations->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L")); | |
340 | menuPageOperations->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N")); | |
eca15c0d | 341 | #if wxUSE_TREEBOOK |
d0a84b63 VZ |
342 | menuPageOperations->AppendSeparator(); |
343 | menuPageOperations->Append(ID_ADD_PAGE_BEFORE, wxT("Insert page &before\tAlt-B")); | |
344 | menuPageOperations->Append(ID_ADD_SUB_PAGE, wxT("Add s&ub page\tAlt-U")); | |
eca15c0d | 345 | #endif |
1d6fcbcc | 346 | menuPageOperations->AppendSeparator(); |
f7aaef4d VZ |
347 | menuPageOperations->Append(ID_CHANGE_SELECTION, wxT("&Change selection to 0\tCtrl-0")); |
348 | menuPageOperations->Append(ID_SET_SELECTION, wxT("&Set selection to 0\tShift-Ctrl-0")); | |
9133965e | 349 | |
d0a84b63 | 350 | wxMenu *menuOperations = new wxMenu; |
df1496e3 VZ |
351 | #if wxUSE_HELP |
352 | menuOperations->Append(ID_CONTEXT_HELP, wxT("&Context help\tCtrl-F1")); | |
353 | #endif // wxUSE_HELP | |
d0a84b63 VZ |
354 | menuOperations->Append(ID_HITTEST, wxT("&Hit test\tCtrl-H")); |
355 | ||
9133965e WS |
356 | wxMenu *menuFile = new wxMenu; |
357 | menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control")); | |
358 | menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control")); | |
c0c99785 WS |
359 | menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S")); |
360 | menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines\tAlt-M")); | |
9133965e WS |
361 | menuFile->AppendSeparator(); |
362 | menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application")); | |
363 | menuFile->Check(ID_SHOW_IMAGES, m_chkShowImages); | |
364 | menuFile->Check(ID_MULTI, m_multi); | |
365 | ||
366 | wxMenuBar *menuBar = new wxMenuBar; | |
367 | menuBar->Append(menuFile, wxT("&File")); | |
d0a84b63 | 368 | menuBar->Append(menuPageOperations, wxT("&Pages")); |
eca15c0d | 369 | menuBar->Append(menuOperations, wxT("&Operations")); |
9133965e WS |
370 | SetMenuBar(menuBar); |
371 | ||
372 | // books creation | |
eca15c0d VZ |
373 | m_panel = NULL; |
374 | m_bookCtrl = NULL; | |
76645ab3 VZ |
375 | |
376 | // create a dummy image list with a few icons | |
eca15c0d | 377 | const wxSize imageSize(32, 32); |
76645ab3 | 378 | |
eca15c0d VZ |
379 | m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); |
380 | m_imageList-> | |
381 | Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); | |
382 | m_imageList-> | |
383 | Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); | |
384 | m_imageList-> | |
385 | Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); | |
386 | m_imageList-> | |
387 | Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); | |
76645ab3 | 388 | |
eca15c0d | 389 | m_panel = new wxPanel(this); |
c1dfe277 | 390 | |
9133965e | 391 | #if USE_LOG |
1cfac5b8 | 392 | m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, |
eca15c0d VZ |
393 | wxDefaultPosition, wxDefaultSize, |
394 | wxTE_MULTILINE | wxTE_READONLY); | |
c1dfe277 JS |
395 | |
396 | m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) ); | |
9133965e | 397 | #endif // USE_LOG |
c1dfe277 | 398 | |
c1dfe277 JS |
399 | // Set sizers |
400 | m_sizerFrame = new wxBoxSizer(wxVERTICAL); | |
401 | ||
9133965e WS |
402 | #if USE_LOG |
403 | m_sizerFrame->Add(m_text, 1, wxEXPAND); | |
404 | #endif // USE_LOG | |
c1dfe277 | 405 | |
eca15c0d | 406 | RecreateBook(); |
c1dfe277 JS |
407 | |
408 | m_panel->SetSizer(m_sizerFrame); | |
119629aa | 409 | m_panel->Layout(); |
c1dfe277 | 410 | |
119629aa VZ |
411 | wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); |
412 | sizer->Add(m_panel, wxSizerFlags(1).Expand()); | |
413 | SetSizerAndFit(sizer); | |
0b4d4194 JS |
414 | } |
415 | ||
c1dfe277 | 416 | MyFrame::~MyFrame() |
0b4d4194 | 417 | { |
9133965e | 418 | #if USE_LOG |
c1dfe277 | 419 | delete wxLog::SetActiveTarget(m_logTargetOld); |
9133965e | 420 | #endif // USE_LOG |
76645ab3 | 421 | |
eca15c0d | 422 | delete m_imageList; |
0b4d4194 JS |
423 | } |
424 | ||
eca15c0d VZ |
425 | // DISPATCH_ON_TYPE() macro is an ugly way to write the "same" code for |
426 | // different wxBookCtrlBase-derived classes without duplicating code and | |
427 | // without using templates, it expands into "before <xxx> after" where "xxx" | |
428 | // part is control class-specific | |
429 | #if wxUSE_NOTEBOOK | |
430 | #define CASE_NOTEBOOK(x) case Type_Notebook: x; break; | |
5a053c22 | 431 | #else |
eca15c0d | 432 | #define CASE_NOTEBOOK(x) |
02161c7c | 433 | #endif |
eca15c0d | 434 | |
02161c7c | 435 | #if wxUSE_LISTBOOK |
eca15c0d VZ |
436 | #define CASE_LISTBOOK(x) case Type_Listbook: x; break; |
437 | #else | |
438 | #define CASE_LISTBOOK(x) | |
136bafcd VZ |
439 | #endif |
440 | ||
441 | #if wxUSE_CHOICEBOOK | |
442 | #define CASE_CHOICEBOOK(x) case Type_Choicebook: x; break; | |
136bafcd VZ |
443 | #else |
444 | #define CASE_CHOICEBOOK(x) | |
02161c7c | 445 | #endif |
eca15c0d VZ |
446 | |
447 | #if wxUSE_TREEBOOK | |
448 | #define CASE_TREEBOOK(x) case Type_Treebook: x; break; | |
449 | #else | |
450 | #define CASE_TREEBOOK(x) | |
02161c7c | 451 | #endif |
c1dfe277 | 452 | |
d709457c JS |
453 | #if wxUSE_TOOLBOOK |
454 | #define CASE_TOOLBOOK(x) case Type_Toolbook: x; break; | |
455 | #else | |
456 | #define CASE_TOOLBOOK(x) | |
457 | #endif | |
458 | ||
425ec0a5 | 459 | #define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, after) \ |
eca15c0d VZ |
460 | switch ( m_type ) \ |
461 | { \ | |
462 | CASE_NOTEBOOK(before nb after) \ | |
eca15c0d | 463 | CASE_LISTBOOK(before lb after) \ |
136bafcd | 464 | CASE_CHOICEBOOK(before cb after) \ |
eca15c0d | 465 | CASE_TREEBOOK(before tb after) \ |
425ec0a5 | 466 | CASE_TOOLBOOK(before toolb after) \ |
eca15c0d VZ |
467 | \ |
468 | default: \ | |
9a83f860 | 469 | wxFAIL_MSG( wxT("unknown book control type") ); \ |
eca15c0d VZ |
470 | } |
471 | ||
d709457c | 472 | int MyFrame::TranslateBookFlag(int nb, int lb, int chb, int tbk, int toolbk) const |
eca15c0d VZ |
473 | { |
474 | int flag = 0; | |
475 | ||
d709457c | 476 | DISPATCH_ON_TYPE(flag =, nb, lb, chb, tbk, toolbk, + 0); |
eca15c0d VZ |
477 | |
478 | return flag; | |
9133965e | 479 | } |
c1dfe277 | 480 | |
eca15c0d | 481 | void MyFrame::RecreateBook() |
9133965e | 482 | { |
eca15c0d VZ |
483 | int flags; |
484 | switch ( m_orient ) | |
76645ab3 | 485 | { |
eca15c0d | 486 | case ID_ORIENT_TOP: |
2ddb4d13 | 487 | flags = wxBK_TOP; |
eca15c0d VZ |
488 | break; |
489 | ||
490 | case ID_ORIENT_BOTTOM: | |
2ddb4d13 | 491 | flags = wxBK_BOTTOM; |
eca15c0d VZ |
492 | break; |
493 | ||
494 | case ID_ORIENT_LEFT: | |
2ddb4d13 | 495 | flags = wxBK_LEFT; |
eca15c0d VZ |
496 | break; |
497 | ||
498 | case ID_ORIENT_RIGHT: | |
2ddb4d13 | 499 | flags = wxBK_RIGHT; |
eca15c0d VZ |
500 | break; |
501 | ||
502 | default: | |
2ddb4d13 | 503 | flags = wxBK_DEFAULT; |
76645ab3 | 504 | } |
c1dfe277 | 505 | |
eca15c0d VZ |
506 | if ( m_multi && m_type == Type_Notebook ) |
507 | flags |= wxNB_MULTILINE; | |
eca15c0d VZ |
508 | |
509 | wxBookCtrlBase *oldBook = m_bookCtrl; | |
510 | ||
511 | m_bookCtrl = NULL; | |
512 | ||
513 | DISPATCH_ON_TYPE(m_bookCtrl = new, | |
514 | wxNotebook, | |
eca15c0d | 515 | wxListbook, |
136bafcd | 516 | wxChoicebook, |
eca15c0d | 517 | wxTreebook, |
d709457c | 518 | wxToolbook, |
eca15c0d VZ |
519 | (m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, flags)); |
520 | ||
521 | if ( !m_bookCtrl ) | |
522 | return; | |
523 | ||
524 | m_bookCtrl->Hide(); | |
525 | ||
526 | if ( m_chkShowImages ) | |
c1dfe277 | 527 | { |
eca15c0d | 528 | m_bookCtrl->SetImageList(m_imageList); |
c1dfe277 JS |
529 | } |
530 | ||
eca15c0d VZ |
531 | if ( oldBook ) |
532 | { | |
533 | #if wxUSE_TREEBOOK | |
534 | // we only need the old treebook if we're recreating another treebook | |
535 | wxTreebook *tbkOld = m_type == Type_Treebook | |
536 | ? wxDynamicCast(oldBook, wxTreebook) | |
537 | : NULL; | |
538 | #endif // wxUSE_TREEBOOK | |
539 | ||
540 | const int count = oldBook->GetPageCount(); | |
541 | for ( int n = 0; n < count; n++ ) | |
542 | { | |
543 | const int image = GetIconIndex(m_bookCtrl); | |
544 | const wxString str = oldBook->GetPageText(n); | |
545 | ||
546 | wxWindow *page = CreatePage(m_bookCtrl, str); | |
547 | ||
548 | // treebook complication: need to account for possible parent page | |
549 | #if wxUSE_TREEBOOK | |
550 | if ( tbkOld ) | |
551 | { | |
552 | const int parent = tbkOld->GetPageParent(n); | |
553 | if ( parent != wxNOT_FOUND ) | |
554 | { | |
555 | wxStaticCast(m_bookCtrl, wxTreebook)-> | |
9d5371c6 | 556 | InsertSubPage(parent, page, str, false, image); |
eca15c0d VZ |
557 | |
558 | // skip adding it again below | |
559 | continue; | |
560 | } | |
561 | } | |
562 | #endif // wxUSE_TREEBOOK | |
563 | ||
564 | m_bookCtrl->AddPage(page, str, false, image); | |
565 | } | |
566 | ||
567 | const int sel = oldBook->GetSelection(); | |
568 | if ( sel != wxNOT_FOUND ) | |
569 | m_bookCtrl->SetSelection(sel); | |
570 | ||
571 | ||
572 | m_sizerFrame->Detach(oldBook); | |
573 | delete oldBook; | |
574 | } | |
575 | else // no old book | |
576 | { | |
577 | CreateInitialPages(m_bookCtrl); | |
578 | } | |
579 | ||
580 | m_sizerFrame->Insert(0, m_bookCtrl, wxSizerFlags(5).Expand().Border()); | |
581 | ||
582 | m_sizerFrame->Show(m_bookCtrl); | |
9133965e | 583 | m_sizerFrame->Layout(); |
c1dfe277 JS |
584 | } |
585 | ||
ce00f59b | 586 | void MyFrame::AddFlagStrIfFlagPresent(wxString & flagStr, long flags, long flag, |
425ec0a5 FM |
587 | const wxChar * flagName) const |
588 | { | |
589 | if( (flags & flag) == flag ) | |
590 | { | |
591 | if( !flagStr.empty() ) | |
9a83f860 | 592 | flagStr += wxT(" | "); |
425ec0a5 FM |
593 | flagStr += flagName; |
594 | } | |
595 | } | |
9133965e | 596 | |
425ec0a5 FM |
597 | wxPanel *MyFrame::CreateNewPage() const |
598 | { | |
599 | wxPanel *panel = new wxPanel(m_bookCtrl, wxID_ANY ); | |
9133965e | 600 | |
df1496e3 | 601 | #if wxUSE_HELP |
425ec0a5 | 602 | panel->SetHelpText( wxT( "Panel with \"First\" and \"Second\" buttons" ) ); |
eca15c0d | 603 | #endif |
136bafcd | 604 | |
425ec0a5 FM |
605 | (void) new wxButton(panel, wxID_ANY, wxT("First button"), wxPoint(10, 30)); |
606 | (void) new wxButton(panel, wxID_ANY, wxT("Second button"), wxPoint(150, 30)); | |
607 | ||
608 | return panel; | |
609 | } | |
c1dfe277 | 610 | |
425ec0a5 FM |
611 | |
612 | //----------------------------------------------------------------------------- | |
613 | // MyFrame - event handlers | |
614 | //----------------------------------------------------------------------------- | |
0b4d4194 | 615 | |
df1496e3 VZ |
616 | #if wxUSE_HELP |
617 | ||
618 | void MyFrame::OnContextHelp(wxCommandEvent& WXUNUSED(event)) | |
619 | { | |
620 | // launches local event loop | |
621 | wxContextHelp ch( this ); | |
622 | } | |
623 | ||
624 | #endif // wxUSE_HELP | |
625 | ||
d0a84b63 VZ |
626 | void MyFrame::OnHitTest(wxCommandEvent& WXUNUSED(event)) |
627 | { | |
628 | wxBookCtrlBase * book = GetCurrentBook(); | |
629 | const wxPoint pt = ::wxGetMousePosition(); | |
630 | ||
631 | long flags; | |
632 | int pagePos = book->HitTest( book->ScreenToClient(pt), &flags ); | |
633 | ||
634 | wxString flagsStr; | |
635 | ||
9a83f860 VZ |
636 | AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_NOWHERE, wxT("wxBK_HITTEST_NOWHERE") ); |
637 | AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONICON, wxT("wxBK_HITTEST_ONICON") ); | |
638 | AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONLABEL, wxT("wxBK_HITTEST_ONLABEL") ); | |
639 | AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONPAGE, wxT("wxBK_HITTEST_ONPAGE") ); | |
d0a84b63 VZ |
640 | |
641 | wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"), | |
642 | pt.x, | |
643 | pt.y, | |
644 | pagePos, | |
645 | flagsStr.c_str()); | |
646 | } | |
647 | ||
9133965e | 648 | void MyFrame::OnType(wxCommandEvent& event) |
0b4d4194 | 649 | { |
81d3348a | 650 | m_type = static_cast<BookType>(event.GetId() - ID_BOOK_NOTEBOOK); |
eca15c0d VZ |
651 | |
652 | if ( m_bookCtrl ) | |
653 | m_sizerFrame->Hide(m_bookCtrl); | |
0b4d4194 | 654 | |
eca15c0d VZ |
655 | RecreateBook(); |
656 | } | |
477350ce | 657 | |
eca15c0d | 658 | #if wxUSE_TREEBOOK |
477350ce | 659 | |
eca15c0d VZ |
660 | void MyFrame::OnUpdateTreeMenu(wxUpdateUIEvent& event) |
661 | { | |
662 | event.Enable(m_type == Type_Treebook); | |
477350ce VZ |
663 | } |
664 | ||
eca15c0d VZ |
665 | #endif // wxUSE_TREEBOOK |
666 | ||
9133965e | 667 | void MyFrame::OnOrient(wxCommandEvent& event) |
477350ce | 668 | { |
9133965e | 669 | m_orient = event.GetId(); |
eca15c0d | 670 | RecreateBook(); |
9133965e WS |
671 | m_sizerFrame->Layout(); |
672 | } | |
477350ce | 673 | |
9133965e WS |
674 | void MyFrame::OnShowImages(wxCommandEvent& event) |
675 | { | |
676 | m_chkShowImages = event.IsChecked(); | |
eca15c0d | 677 | RecreateBook(); |
9133965e WS |
678 | m_sizerFrame->Layout(); |
679 | } | |
c1dfe277 | 680 | |
9133965e WS |
681 | void MyFrame::OnMulti(wxCommandEvent& event) |
682 | { | |
683 | m_multi = event.IsChecked(); | |
eca15c0d | 684 | RecreateBook(); |
9133965e | 685 | m_sizerFrame->Layout(); |
9a83f860 | 686 | wxLogMessage(wxT("Multiline setting works only in wxNotebook.")); |
9133965e | 687 | } |
477350ce | 688 | |
9133965e WS |
689 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) |
690 | { | |
691 | Close(); | |
326f9654 RR |
692 | } |
693 | ||
eca15c0d VZ |
694 | void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event)) |
695 | { | |
61c083e7 | 696 | wxBookCtrlBase *currBook = GetCurrentBook(); |
9133965e WS |
697 | |
698 | if ( currBook ) | |
3957448a | 699 | { |
eca15c0d VZ |
700 | static unsigned s_pageAdded = 0; |
701 | currBook->AddPage(CreateNewPage(), | |
702 | wxString::Format | |
703 | ( | |
704 | ADDED_PAGE_NAME wxT("%u"), | |
705 | ++s_pageAdded | |
706 | ), | |
707 | true, | |
708 | GetIconIndex(currBook)); | |
709 | } | |
710 | } | |
711 | ||
a85dda4a RR |
712 | void MyFrame::OnAddPageNoSelect(wxCommandEvent& WXUNUSED(event)) |
713 | { | |
714 | wxBookCtrlBase *currBook = GetCurrentBook(); | |
715 | ||
716 | if ( currBook ) | |
717 | { | |
718 | static unsigned s_pageAdded = 0; | |
719 | currBook->AddPage(CreateNewPage(), | |
720 | wxString::Format | |
721 | ( | |
722 | ADDED_PAGE_NAME wxT("%u"), | |
723 | ++s_pageAdded | |
724 | ), | |
725 | false, | |
726 | GetIconIndex(currBook)); | |
727 | } | |
728 | } | |
729 | ||
eca15c0d VZ |
730 | #if wxUSE_TREEBOOK |
731 | void MyFrame::OnAddSubPage(wxCommandEvent& WXUNUSED(event)) | |
732 | { | |
733 | wxTreebook *currBook = wxDynamicCast(GetCurrentBook(), wxTreebook); | |
734 | if ( currBook ) | |
735 | { | |
736 | const int selPos = currBook->GetSelection(); | |
737 | if ( selPos == wxNOT_FOUND ) | |
738 | { | |
9a83f860 | 739 | wxLogError(wxT("Select the parent page first!")); |
eca15c0d VZ |
740 | return; |
741 | } | |
742 | ||
743 | static unsigned s_subPageAdded = 0; | |
9d5371c6 VZ |
744 | currBook->InsertSubPage |
745 | ( | |
746 | selPos, | |
747 | CreateNewPage(), | |
748 | wxString::Format | |
749 | ( | |
750 | ADDED_SUB_PAGE_NAME wxT("%u"), | |
751 | ++s_subPageAdded | |
752 | ), | |
753 | true, | |
754 | GetIconIndex(currBook) | |
755 | ); | |
eca15c0d VZ |
756 | } |
757 | } | |
758 | ||
759 | void MyFrame::OnAddPageBefore(wxCommandEvent& WXUNUSED(event)) | |
760 | { | |
761 | wxBookCtrlBase *currBook = GetCurrentBook(); | |
762 | if ( currBook ) | |
763 | { | |
764 | const int selPos = currBook->GetSelection(); | |
765 | if ( selPos == wxNOT_FOUND ) | |
766 | { | |
9a83f860 | 767 | wxLogError(wxT("Select the parent page first!")); |
eca15c0d VZ |
768 | return; |
769 | } | |
770 | ||
771 | static unsigned s_subPageAdded = 0; | |
772 | currBook->InsertPage(selPos, | |
773 | CreateNewPage(), | |
774 | wxString::Format | |
775 | ( | |
776 | ADDED_PAGE_NAME_BEFORE wxT("%u"), | |
777 | ++s_subPageAdded | |
778 | ), | |
779 | true, | |
780 | GetIconIndex(currBook)); | |
3957448a VZ |
781 | } |
782 | } | |
eca15c0d | 783 | #endif // wxUSE_TREEBOOK |
3957448a | 784 | |
9133965e | 785 | void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event)) |
29f538ce | 786 | { |
9133965e WS |
787 | static unsigned s_pageIns = 0; |
788 | ||
61c083e7 | 789 | wxBookCtrlBase *currBook = GetCurrentBook(); |
f6bcfd97 | 790 | |
9133965e | 791 | if ( currBook ) |
f6bcfd97 | 792 | { |
9133965e WS |
793 | wxPanel *panel = CreateUserCreatedPage( currBook ); |
794 | ||
795 | currBook->InsertPage( 0, panel, | |
796 | wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false, | |
797 | GetIconIndex(currBook) ); | |
798 | ||
799 | currBook->SetSelection(0); | |
f6bcfd97 | 800 | } |
29f538ce RR |
801 | } |
802 | ||
9133965e | 803 | void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event)) |
33d0e17c | 804 | { |
61c083e7 | 805 | wxBookCtrlBase *currBook = GetCurrentBook(); |
33d0e17c | 806 | |
9133965e WS |
807 | if ( currBook ) |
808 | { | |
809 | int sel = currBook->GetSelection(); | |
810 | ||
811 | if (sel != wxNOT_FOUND) | |
812 | { | |
813 | currBook->DeletePage(sel); | |
814 | } | |
815 | } | |
0b4d4194 JS |
816 | } |
817 | ||
9133965e | 818 | void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event)) |
0b4d4194 | 819 | { |
61c083e7 | 820 | wxBookCtrlBase *currBook = GetCurrentBook(); |
d22699b5 | 821 | |
9133965e | 822 | if ( currBook ) |
c1dfe277 | 823 | { |
9133965e | 824 | int page = currBook->GetPageCount(); |
c1dfe277 | 825 | |
9133965e WS |
826 | if ( page != 0 ) |
827 | { | |
828 | currBook->DeletePage(page - 1); | |
c1dfe277 | 829 | } |
c1dfe277 | 830 | } |
9133965e | 831 | } |
0b4d4194 | 832 | |
9133965e WS |
833 | void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event)) |
834 | { | |
61c083e7 | 835 | wxBookCtrlBase *currBook = GetCurrentBook(); |
0b4d4194 | 836 | |
9133965e WS |
837 | if ( currBook ) |
838 | { | |
839 | currBook->AdvanceSelection(); | |
840 | } | |
0b4d4194 JS |
841 | } |
842 | ||
f7aaef4d | 843 | void MyFrame::OnChangeSelection(wxCommandEvent& WXUNUSED(event)) |
1d6fcbcc VZ |
844 | { |
845 | wxBookCtrlBase *currBook = GetCurrentBook(); | |
846 | ||
847 | if ( currBook ) | |
1d6fcbcc | 848 | currBook->ChangeSelection(0); |
f7aaef4d VZ |
849 | } |
850 | ||
851 | void MyFrame::OnSetSelection(wxCommandEvent& WXUNUSED(event)) | |
852 | { | |
853 | wxBookCtrlBase *currBook = GetCurrentBook(); | |
854 | ||
855 | if ( currBook ) | |
856 | currBook->SetSelection(0); | |
1d6fcbcc VZ |
857 | } |
858 | ||
c1dfe277 | 859 | void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) |
96d37807 | 860 | { |
9133965e WS |
861 | static int s_nPages = wxNOT_FOUND; |
862 | static int s_nSel = wxNOT_FOUND; | |
61c083e7 | 863 | static wxBookCtrlBase *s_currBook = NULL; |
9133965e | 864 | |
61c083e7 | 865 | wxBookCtrlBase *currBook = GetCurrentBook(); |
96d37807 | 866 | |
9133965e WS |
867 | int nPages = currBook ? currBook->GetPageCount() : 0; |
868 | int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND; | |
869 | ||
870 | if ( nPages != s_nPages || nSel != s_nSel || s_currBook != currBook ) | |
96d37807 VZ |
871 | { |
872 | s_nPages = nPages; | |
873 | s_nSel = nSel; | |
9133965e WS |
874 | s_currBook = currBook; |
875 | ||
876 | wxString selection; | |
877 | if ( nSel == wxNOT_FOUND ) | |
878 | selection << wxT("not found"); | |
879 | else | |
880 | selection << nSel; | |
96d37807 VZ |
881 | |
882 | wxString title; | |
9133965e | 883 | title.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages, selection.c_str()); |
96d37807 VZ |
884 | |
885 | SetTitle(title); | |
886 | } | |
887 | } | |
3957448a | 888 | |
eca15c0d VZ |
889 | void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent& event) |
890 | { | |
891 | static const struct EventInfo | |
892 | { | |
893 | wxEventType typeChanged, | |
894 | typeChanging; | |
895 | const wxChar *name; | |
896 | } events[] = | |
897 | { | |
02161c7c | 898 | #if wxUSE_NOTEBOOK |
eca15c0d VZ |
899 | { |
900 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, | |
901 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, | |
9a83f860 | 902 | wxT("wxNotebook") |
eca15c0d VZ |
903 | }, |
904 | #endif // wxUSE_NOTEBOOK | |
02161c7c | 905 | #if wxUSE_LISTBOOK |
eca15c0d VZ |
906 | { |
907 | wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, | |
908 | wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, | |
9a83f860 | 909 | wxT("wxListbook") |
eca15c0d VZ |
910 | }, |
911 | #endif // wxUSE_LISTBOOK | |
136bafcd VZ |
912 | #if wxUSE_CHOICEBOOK |
913 | { | |
914 | wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, | |
915 | wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, | |
9a83f860 | 916 | wxT("wxChoicebook") |
136bafcd VZ |
917 | }, |
918 | #endif // wxUSE_CHOICEBOOK | |
eca15c0d VZ |
919 | #if wxUSE_TREEBOOK |
920 | { | |
921 | wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, | |
922 | wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, | |
9a83f860 | 923 | wxT("wxTreebook") |
eca15c0d VZ |
924 | }, |
925 | #endif // wxUSE_TREEBOOK | |
d709457c JS |
926 | #if wxUSE_TOOLBOOK |
927 | { | |
928 | wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED, | |
929 | wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING, | |
9a83f860 | 930 | wxT("wxToolbook") |
d709457c JS |
931 | }, |
932 | #endif // wxUSE_TOOLBOOK | |
eca15c0d VZ |
933 | }; |
934 | ||
935 | ||
936 | wxString nameEvent, | |
937 | nameControl, | |
938 | veto; | |
939 | const wxEventType eventType = event.GetEventType(); | |
940 | for ( size_t n = 0; n < WXSIZEOF(events); n++ ) | |
941 | { | |
942 | const EventInfo& ei = events[n]; | |
943 | if ( eventType == ei.typeChanged ) | |
944 | { | |
945 | nameEvent = wxT("Changed"); | |
946 | } | |
947 | else if ( eventType == ei.typeChanging ) | |
948 | { | |
949 | const int idx = event.GetOldSelection(); | |
582ca353 VZ |
950 | |
951 | // NB: can't use wxStaticCast here as wxBookCtrlBase is not in | |
952 | // wxRTTI | |
eca15c0d | 953 | const wxBookCtrlBase * const |
81d3348a | 954 | book = static_cast<wxBookCtrlBase *>(event.GetEventObject()); |
eca15c0d VZ |
955 | if ( idx != wxNOT_FOUND && |
956 | book && book->GetPageText(idx) == VETO_PAGE_NAME ) | |
957 | { | |
958 | if ( wxMessageBox | |
959 | ( | |
960 | wxT("Are you sure you want to leave this page?\n") | |
961 | wxT("(This demonstrates veto-ing)"), | |
962 | wxT("Notebook sample"), | |
963 | wxICON_QUESTION | wxYES_NO, | |
964 | this | |
965 | ) != wxYES ) | |
966 | { | |
967 | event.Veto(); | |
9a83f860 | 968 | veto = wxT(" (vetoed)"); |
eca15c0d VZ |
969 | } |
970 | } | |
971 | ||
972 | nameEvent = wxT("Changing"); | |
973 | } | |
974 | else // skip end of the loop | |
975 | { | |
976 | continue; | |
977 | } | |
978 | ||
979 | nameControl = ei.name; | |
980 | break; | |
981 | } | |
982 | ||
983 | static int s_num = 0; | |
984 | ||
985 | wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d%s"), | |
986 | ++s_num, | |
987 | nameControl.c_str(), | |
988 | nameEvent.c_str(), | |
989 | eventType, | |
990 | event.GetSelection(), | |
991 | event.GetOldSelection(), | |
992 | veto.c_str()); | |
993 | ||
994 | #if USE_LOG | |
995 | m_text->SetInsertionPointEnd(); | |
02161c7c | 996 | #endif |
eca15c0d | 997 | } |