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