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