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