]>
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 | |
873ff54b SL |
274 | #if wxUSE_AUI |
275 | EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnAuiNotebook) | |
276 | EVT_AUINOTEBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnAuiNotebook) | |
277 | #endif | |
425ec0a5 FM |
278 | |
279 | // Update title in idle time | |
280 | EVT_IDLE(MyFrame::OnIdle) | |
281 | END_EVENT_TABLE() | |
282 | ||
eca15c0d | 283 | MyFrame::MyFrame() |
df1496e3 | 284 | : wxFrame(NULL, wxID_ANY, wxString(wxT("wxWidgets book controls sample"))) |
0b4d4194 | 285 | { |
df1496e3 VZ |
286 | #if wxUSE_HELP |
287 | SetExtraStyle(wxFRAME_EX_CONTEXTHELP); | |
288 | #endif // wxUSE_HELP | |
289 | ||
53d09d55 | 290 | #if wxUSE_NOTEBOOK |
eca15c0d | 291 | m_type = Type_Notebook; |
53d09d55 | 292 | #elif wxUSE_CHOICEBOOK |
eca15c0d | 293 | m_type = Type_Choicebook; |
53d09d55 | 294 | #elif wxUSE_LISTBOOK |
eca15c0d VZ |
295 | m_type = Type_Listbook; |
296 | #elif wxUSE_TREEBOOK | |
297 | m_type = Type_Treebook; | |
fab8784c VZ |
298 | #elif wxUSE_TOOLBOOK |
299 | m_type = Type_Toolbook; | |
873ff54b SL |
300 | #elif wxUSE_AUI |
301 | m_type = Type_Aui; | |
abae3b80 | 302 | #else |
53d09d55 WS |
303 | #error "Don't use Notebook sample without any book enabled in wxWidgets build!" |
304 | #endif | |
305 | ||
9133965e WS |
306 | m_orient = ID_ORIENT_DEFAULT; |
307 | m_chkShowImages = true; | |
8864388c | 308 | m_fixedWidth = false; |
9133965e | 309 | m_multi = false; |
8864388c VZ |
310 | m_noPageTheme = false; |
311 | m_buttonBar = false; | |
312 | m_horzLayout = false; | |
9133965e | 313 | |
d52f6c4e | 314 | SetIcon(wxICON(sample)); |
9133965e | 315 | |
d52f6c4e | 316 | // menu of the sample |
9133965e WS |
317 | wxMenu *menuType = new wxMenu; |
318 | #if wxUSE_NOTEBOOK | |
319 | menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, wxT("&Notebook\tCtrl-1")); | |
320 | #endif | |
321 | #if wxUSE_LISTBOOK | |
322 | menuType->AppendRadioItem(ID_BOOK_LISTBOOK, wxT("&Listbook\tCtrl-2")); | |
323 | #endif | |
324 | #if wxUSE_CHOICEBOOK | |
325 | menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3")); | |
326 | #endif | |
eca15c0d VZ |
327 | #if wxUSE_TREEBOOK |
328 | menuType->AppendRadioItem(ID_BOOK_TREEBOOK, wxT("&Treebook\tCtrl-4")); | |
329 | #endif | |
d709457c JS |
330 | #if wxUSE_TOOLBOOK |
331 | menuType->AppendRadioItem(ID_BOOK_TOOLBOOK, wxT("T&oolbook\tCtrl-5")); | |
332 | #endif | |
873ff54b SL |
333 | #if wxUSE_AUI |
334 | menuType->AppendRadioItem(ID_BOOK_AUINOTEBOOK, wxT("&AuiNotebook\tCtrl-6")); | |
335 | #endif | |
eca15c0d VZ |
336 | |
337 | menuType->Check(ID_BOOK_NOTEBOOK + m_type, true); | |
9133965e WS |
338 | |
339 | wxMenu *menuOrient = new wxMenu; | |
76680db4 VZ |
340 | menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tAlt-0")); |
341 | menuOrient->AppendRadioItem(ID_ORIENT_TOP, wxT("&Top\tAlt-1")); | |
342 | menuOrient->AppendRadioItem(ID_ORIENT_BOTTOM, wxT("&Bottom\tAlt-2")); | |
343 | menuOrient->AppendRadioItem(ID_ORIENT_LEFT, wxT("&Left\tAlt-3")); | |
344 | menuOrient->AppendRadioItem(ID_ORIENT_RIGHT, wxT("&Right\tAlt-4")); | |
eca15c0d | 345 | |
8864388c VZ |
346 | wxMenu *menuStyle = new wxMenu; |
347 | #if wxUSE_NOTEBOOK | |
348 | menuStyle->AppendCheckItem(ID_FIXEDWIDTH, wxT("&Fixed Width (wxNotebook)")); | |
349 | menuStyle->AppendCheckItem(ID_MULTI, wxT("&Multiple lines (wxNotebook)")); | |
350 | menuStyle->AppendCheckItem(ID_NOPAGETHEME, wxT("&No Page Theme (wxNotebook)")); | |
351 | #endif | |
352 | #if wxUSE_TOOLBOOK | |
353 | menuStyle->AppendCheckItem(ID_BUTTONBAR, wxT("&Button Bar (wxToolbook)")); | |
354 | menuStyle->AppendCheckItem(ID_HORZ_LAYOUT, wxT("&Horizontal layout (wxToolbook)")); | |
355 | #endif | |
356 | ||
d0a84b63 VZ |
357 | wxMenu *menuPageOperations = new wxMenu; |
358 | menuPageOperations->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A")); | |
a85dda4a | 359 | menuPageOperations->Append(ID_ADD_PAGE_NO_SELECT, wxT("&Add page (don't select)\tAlt-B")); |
d0a84b63 VZ |
360 | menuPageOperations->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I")); |
361 | menuPageOperations->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D")); | |
362 | menuPageOperations->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L")); | |
363 | menuPageOperations->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N")); | |
eca15c0d | 364 | #if wxUSE_TREEBOOK |
d0a84b63 VZ |
365 | menuPageOperations->AppendSeparator(); |
366 | menuPageOperations->Append(ID_ADD_PAGE_BEFORE, wxT("Insert page &before\tAlt-B")); | |
367 | menuPageOperations->Append(ID_ADD_SUB_PAGE, wxT("Add s&ub page\tAlt-U")); | |
eca15c0d | 368 | #endif |
1d6fcbcc | 369 | menuPageOperations->AppendSeparator(); |
f7aaef4d VZ |
370 | menuPageOperations->Append(ID_CHANGE_SELECTION, wxT("&Change selection to 0\tCtrl-0")); |
371 | menuPageOperations->Append(ID_SET_SELECTION, wxT("&Set selection to 0\tShift-Ctrl-0")); | |
9133965e | 372 | |
d0a84b63 | 373 | wxMenu *menuOperations = new wxMenu; |
df1496e3 VZ |
374 | #if wxUSE_HELP |
375 | menuOperations->Append(ID_CONTEXT_HELP, wxT("&Context help\tCtrl-F1")); | |
376 | #endif // wxUSE_HELP | |
d0a84b63 VZ |
377 | menuOperations->Append(ID_HITTEST, wxT("&Hit test\tCtrl-H")); |
378 | ||
9133965e WS |
379 | wxMenu *menuFile = new wxMenu; |
380 | menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control")); | |
381 | menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control")); | |
c0c99785 | 382 | menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S")); |
8864388c | 383 | menuFile->Append(wxID_ANY, wxT("&Style"), menuStyle, wxT("Style of control")); |
9133965e WS |
384 | menuFile->AppendSeparator(); |
385 | menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application")); | |
386 | menuFile->Check(ID_SHOW_IMAGES, m_chkShowImages); | |
9133965e WS |
387 | |
388 | wxMenuBar *menuBar = new wxMenuBar; | |
389 | menuBar->Append(menuFile, wxT("&File")); | |
d0a84b63 | 390 | menuBar->Append(menuPageOperations, wxT("&Pages")); |
eca15c0d | 391 | menuBar->Append(menuOperations, wxT("&Operations")); |
9133965e WS |
392 | SetMenuBar(menuBar); |
393 | ||
394 | // books creation | |
eca15c0d VZ |
395 | m_panel = NULL; |
396 | m_bookCtrl = NULL; | |
76645ab3 VZ |
397 | |
398 | // create a dummy image list with a few icons | |
eca15c0d | 399 | const wxSize imageSize(32, 32); |
76645ab3 | 400 | |
eca15c0d VZ |
401 | m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); |
402 | m_imageList-> | |
403 | Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); | |
404 | m_imageList-> | |
405 | Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); | |
406 | m_imageList-> | |
407 | Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); | |
408 | m_imageList-> | |
409 | Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); | |
76645ab3 | 410 | |
eca15c0d | 411 | m_panel = new wxPanel(this); |
c1dfe277 | 412 | |
9133965e | 413 | #if USE_LOG |
1cfac5b8 | 414 | m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, |
eca15c0d VZ |
415 | wxDefaultPosition, wxDefaultSize, |
416 | wxTE_MULTILINE | wxTE_READONLY); | |
c1dfe277 JS |
417 | |
418 | m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) ); | |
9133965e | 419 | #endif // USE_LOG |
c1dfe277 | 420 | |
c1dfe277 JS |
421 | // Set sizers |
422 | m_sizerFrame = new wxBoxSizer(wxVERTICAL); | |
423 | ||
9133965e WS |
424 | #if USE_LOG |
425 | m_sizerFrame->Add(m_text, 1, wxEXPAND); | |
426 | #endif // USE_LOG | |
c1dfe277 | 427 | |
eca15c0d | 428 | RecreateBook(); |
c1dfe277 JS |
429 | |
430 | m_panel->SetSizer(m_sizerFrame); | |
119629aa | 431 | m_panel->Layout(); |
c1dfe277 | 432 | |
119629aa VZ |
433 | wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); |
434 | sizer->Add(m_panel, wxSizerFlags(1).Expand()); | |
435 | SetSizerAndFit(sizer); | |
0b4d4194 JS |
436 | } |
437 | ||
c1dfe277 | 438 | MyFrame::~MyFrame() |
0b4d4194 | 439 | { |
9133965e | 440 | #if USE_LOG |
c1dfe277 | 441 | delete wxLog::SetActiveTarget(m_logTargetOld); |
9133965e | 442 | #endif // USE_LOG |
76645ab3 | 443 | |
eca15c0d | 444 | delete m_imageList; |
0b4d4194 JS |
445 | } |
446 | ||
eca15c0d VZ |
447 | // DISPATCH_ON_TYPE() macro is an ugly way to write the "same" code for |
448 | // different wxBookCtrlBase-derived classes without duplicating code and | |
449 | // without using templates, it expands into "before <xxx> after" where "xxx" | |
450 | // part is control class-specific | |
451 | #if wxUSE_NOTEBOOK | |
452 | #define CASE_NOTEBOOK(x) case Type_Notebook: x; break; | |
5a053c22 | 453 | #else |
eca15c0d | 454 | #define CASE_NOTEBOOK(x) |
02161c7c | 455 | #endif |
eca15c0d | 456 | |
02161c7c | 457 | #if wxUSE_LISTBOOK |
eca15c0d VZ |
458 | #define CASE_LISTBOOK(x) case Type_Listbook: x; break; |
459 | #else | |
460 | #define CASE_LISTBOOK(x) | |
136bafcd VZ |
461 | #endif |
462 | ||
463 | #if wxUSE_CHOICEBOOK | |
464 | #define CASE_CHOICEBOOK(x) case Type_Choicebook: x; break; | |
136bafcd VZ |
465 | #else |
466 | #define CASE_CHOICEBOOK(x) | |
02161c7c | 467 | #endif |
eca15c0d VZ |
468 | |
469 | #if wxUSE_TREEBOOK | |
470 | #define CASE_TREEBOOK(x) case Type_Treebook: x; break; | |
471 | #else | |
472 | #define CASE_TREEBOOK(x) | |
02161c7c | 473 | #endif |
c1dfe277 | 474 | |
d709457c JS |
475 | #if wxUSE_TOOLBOOK |
476 | #define CASE_TOOLBOOK(x) case Type_Toolbook: x; break; | |
477 | #else | |
478 | #define CASE_TOOLBOOK(x) | |
479 | #endif | |
480 | ||
873ff54b SL |
481 | #if wxUSE_AUI |
482 | #define CASE_AUINOTEBOOK(x) case Type_AuiNotebook: x; break; | |
483 | #else | |
484 | #define CASE_AUINOTEBOOK(x) | |
485 | #endif | |
486 | ||
487 | #define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, aui, after) \ | |
eca15c0d VZ |
488 | switch ( m_type ) \ |
489 | { \ | |
490 | CASE_NOTEBOOK(before nb after) \ | |
eca15c0d | 491 | CASE_LISTBOOK(before lb after) \ |
136bafcd | 492 | CASE_CHOICEBOOK(before cb after) \ |
eca15c0d | 493 | CASE_TREEBOOK(before tb after) \ |
425ec0a5 | 494 | CASE_TOOLBOOK(before toolb after) \ |
873ff54b | 495 | CASE_AUINOTEBOOK(before aui after) \ |
eca15c0d VZ |
496 | \ |
497 | default: \ | |
9a83f860 | 498 | wxFAIL_MSG( wxT("unknown book control type") ); \ |
eca15c0d VZ |
499 | } |
500 | ||
873ff54b | 501 | int MyFrame::TranslateBookFlag(int nb, int lb, int chb, int tbk, int toolbk, int aui) const |
eca15c0d VZ |
502 | { |
503 | int flag = 0; | |
504 | ||
873ff54b | 505 | DISPATCH_ON_TYPE(flag =, nb, lb, chb, tbk, toolbk, aui, + 0); |
eca15c0d VZ |
506 | |
507 | return flag; | |
9133965e | 508 | } |
c1dfe277 | 509 | |
eca15c0d | 510 | void MyFrame::RecreateBook() |
9133965e | 511 | { |
eca15c0d VZ |
512 | int flags; |
513 | switch ( m_orient ) | |
76645ab3 | 514 | { |
eca15c0d | 515 | case ID_ORIENT_TOP: |
2ddb4d13 | 516 | flags = wxBK_TOP; |
eca15c0d VZ |
517 | break; |
518 | ||
519 | case ID_ORIENT_BOTTOM: | |
2ddb4d13 | 520 | flags = wxBK_BOTTOM; |
eca15c0d VZ |
521 | break; |
522 | ||
523 | case ID_ORIENT_LEFT: | |
2ddb4d13 | 524 | flags = wxBK_LEFT; |
eca15c0d VZ |
525 | break; |
526 | ||
527 | case ID_ORIENT_RIGHT: | |
2ddb4d13 | 528 | flags = wxBK_RIGHT; |
eca15c0d VZ |
529 | break; |
530 | ||
531 | default: | |
2ddb4d13 | 532 | flags = wxBK_DEFAULT; |
76645ab3 | 533 | } |
c1dfe277 | 534 | |
8864388c VZ |
535 | #if wxUSE_NOTEBOOK |
536 | if ( m_fixedWidth && m_type == Type_Notebook ) | |
537 | flags |= wxNB_FIXEDWIDTH; | |
eca15c0d VZ |
538 | if ( m_multi && m_type == Type_Notebook ) |
539 | flags |= wxNB_MULTILINE; | |
8864388c VZ |
540 | if ( m_noPageTheme && m_type == Type_Notebook ) |
541 | flags |= wxNB_NOPAGETHEME; | |
542 | #endif | |
543 | #if wxUSE_TOOLBOOK | |
544 | if ( m_buttonBar && m_type == Type_Toolbook ) | |
545 | flags |= wxTBK_BUTTONBAR; | |
546 | if ( m_horzLayout && m_type == Type_Toolbook ) | |
547 | flags |= wxTBK_HORZ_LAYOUT; | |
548 | #endif | |
eca15c0d VZ |
549 | |
550 | wxBookCtrlBase *oldBook = m_bookCtrl; | |
551 | ||
552 | m_bookCtrl = NULL; | |
553 | ||
554 | DISPATCH_ON_TYPE(m_bookCtrl = new, | |
555 | wxNotebook, | |
eca15c0d | 556 | wxListbook, |
136bafcd | 557 | wxChoicebook, |
eca15c0d | 558 | wxTreebook, |
d709457c | 559 | wxToolbook, |
873ff54b | 560 | wxAuiNotebook, |
eca15c0d VZ |
561 | (m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, flags)); |
562 | ||
563 | if ( !m_bookCtrl ) | |
564 | return; | |
565 | ||
566 | m_bookCtrl->Hide(); | |
567 | ||
bd448041 VZ |
568 | // wxToolbook doesn't work without icons so always use them for it. |
569 | if ( m_chkShowImages || m_type == Type_Toolbook ) | |
c1dfe277 | 570 | { |
eca15c0d | 571 | m_bookCtrl->SetImageList(m_imageList); |
c1dfe277 JS |
572 | } |
573 | ||
eca15c0d VZ |
574 | if ( oldBook ) |
575 | { | |
576 | #if wxUSE_TREEBOOK | |
577 | // we only need the old treebook if we're recreating another treebook | |
578 | wxTreebook *tbkOld = m_type == Type_Treebook | |
579 | ? wxDynamicCast(oldBook, wxTreebook) | |
580 | : NULL; | |
581 | #endif // wxUSE_TREEBOOK | |
582 | ||
583 | const int count = oldBook->GetPageCount(); | |
584 | for ( int n = 0; n < count; n++ ) | |
585 | { | |
586 | const int image = GetIconIndex(m_bookCtrl); | |
587 | const wxString str = oldBook->GetPageText(n); | |
588 | ||
589 | wxWindow *page = CreatePage(m_bookCtrl, str); | |
590 | ||
591 | // treebook complication: need to account for possible parent page | |
592 | #if wxUSE_TREEBOOK | |
593 | if ( tbkOld ) | |
594 | { | |
595 | const int parent = tbkOld->GetPageParent(n); | |
596 | if ( parent != wxNOT_FOUND ) | |
597 | { | |
598 | wxStaticCast(m_bookCtrl, wxTreebook)-> | |
9d5371c6 | 599 | InsertSubPage(parent, page, str, false, image); |
eca15c0d VZ |
600 | |
601 | // skip adding it again below | |
602 | continue; | |
603 | } | |
604 | } | |
605 | #endif // wxUSE_TREEBOOK | |
606 | ||
607 | m_bookCtrl->AddPage(page, str, false, image); | |
608 | } | |
609 | ||
610 | const int sel = oldBook->GetSelection(); | |
611 | if ( sel != wxNOT_FOUND ) | |
612 | m_bookCtrl->SetSelection(sel); | |
613 | ||
614 | ||
615 | m_sizerFrame->Detach(oldBook); | |
616 | delete oldBook; | |
617 | } | |
618 | else // no old book | |
619 | { | |
620 | CreateInitialPages(m_bookCtrl); | |
621 | } | |
622 | ||
623 | m_sizerFrame->Insert(0, m_bookCtrl, wxSizerFlags(5).Expand().Border()); | |
624 | ||
625 | m_sizerFrame->Show(m_bookCtrl); | |
9133965e | 626 | m_sizerFrame->Layout(); |
c1dfe277 JS |
627 | } |
628 | ||
ce00f59b | 629 | void MyFrame::AddFlagStrIfFlagPresent(wxString & flagStr, long flags, long flag, |
425ec0a5 FM |
630 | const wxChar * flagName) const |
631 | { | |
632 | if( (flags & flag) == flag ) | |
633 | { | |
634 | if( !flagStr.empty() ) | |
9a83f860 | 635 | flagStr += wxT(" | "); |
425ec0a5 FM |
636 | flagStr += flagName; |
637 | } | |
638 | } | |
9133965e | 639 | |
425ec0a5 FM |
640 | wxPanel *MyFrame::CreateNewPage() const |
641 | { | |
642 | wxPanel *panel = new wxPanel(m_bookCtrl, wxID_ANY ); | |
9133965e | 643 | |
df1496e3 | 644 | #if wxUSE_HELP |
425ec0a5 | 645 | panel->SetHelpText( wxT( "Panel with \"First\" and \"Second\" buttons" ) ); |
eca15c0d | 646 | #endif |
136bafcd | 647 | |
425ec0a5 FM |
648 | (void) new wxButton(panel, wxID_ANY, wxT("First button"), wxPoint(10, 30)); |
649 | (void) new wxButton(panel, wxID_ANY, wxT("Second button"), wxPoint(150, 30)); | |
650 | ||
651 | return panel; | |
652 | } | |
c1dfe277 | 653 | |
425ec0a5 FM |
654 | |
655 | //----------------------------------------------------------------------------- | |
656 | // MyFrame - event handlers | |
657 | //----------------------------------------------------------------------------- | |
0b4d4194 | 658 | |
df1496e3 VZ |
659 | #if wxUSE_HELP |
660 | ||
661 | void MyFrame::OnContextHelp(wxCommandEvent& WXUNUSED(event)) | |
662 | { | |
663 | // launches local event loop | |
664 | wxContextHelp ch( this ); | |
665 | } | |
666 | ||
667 | #endif // wxUSE_HELP | |
668 | ||
d0a84b63 VZ |
669 | void MyFrame::OnHitTest(wxCommandEvent& WXUNUSED(event)) |
670 | { | |
671 | wxBookCtrlBase * book = GetCurrentBook(); | |
672 | const wxPoint pt = ::wxGetMousePosition(); | |
673 | ||
674 | long flags; | |
675 | int pagePos = book->HitTest( book->ScreenToClient(pt), &flags ); | |
676 | ||
677 | wxString flagsStr; | |
678 | ||
9a83f860 VZ |
679 | AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_NOWHERE, wxT("wxBK_HITTEST_NOWHERE") ); |
680 | AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONICON, wxT("wxBK_HITTEST_ONICON") ); | |
681 | AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONLABEL, wxT("wxBK_HITTEST_ONLABEL") ); | |
682 | AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONPAGE, wxT("wxBK_HITTEST_ONPAGE") ); | |
d0a84b63 VZ |
683 | |
684 | wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"), | |
685 | pt.x, | |
686 | pt.y, | |
687 | pagePos, | |
688 | flagsStr.c_str()); | |
689 | } | |
690 | ||
9133965e | 691 | void MyFrame::OnType(wxCommandEvent& event) |
0b4d4194 | 692 | { |
81d3348a | 693 | m_type = static_cast<BookType>(event.GetId() - ID_BOOK_NOTEBOOK); |
eca15c0d VZ |
694 | |
695 | if ( m_bookCtrl ) | |
696 | m_sizerFrame->Hide(m_bookCtrl); | |
0b4d4194 | 697 | |
eca15c0d VZ |
698 | RecreateBook(); |
699 | } | |
477350ce | 700 | |
eca15c0d | 701 | #if wxUSE_TREEBOOK |
477350ce | 702 | |
eca15c0d VZ |
703 | void MyFrame::OnUpdateTreeMenu(wxUpdateUIEvent& event) |
704 | { | |
705 | event.Enable(m_type == Type_Treebook); | |
477350ce VZ |
706 | } |
707 | ||
eca15c0d VZ |
708 | #endif // wxUSE_TREEBOOK |
709 | ||
9133965e | 710 | void MyFrame::OnOrient(wxCommandEvent& event) |
477350ce | 711 | { |
9133965e | 712 | m_orient = event.GetId(); |
eca15c0d | 713 | RecreateBook(); |
9133965e WS |
714 | m_sizerFrame->Layout(); |
715 | } | |
477350ce | 716 | |
9133965e WS |
717 | void MyFrame::OnShowImages(wxCommandEvent& event) |
718 | { | |
719 | m_chkShowImages = event.IsChecked(); | |
eca15c0d | 720 | RecreateBook(); |
9133965e WS |
721 | m_sizerFrame->Layout(); |
722 | } | |
c1dfe277 | 723 | |
8864388c | 724 | void MyFrame::OnStyle(wxCommandEvent& event) |
9133965e | 725 | { |
8864388c VZ |
726 | bool checked = event.IsChecked(); |
727 | switch (event.GetId()) | |
728 | { | |
729 | case ID_FIXEDWIDTH: m_fixedWidth = checked; break; | |
730 | case ID_MULTI: m_multi = checked; break; | |
731 | case ID_NOPAGETHEME: m_noPageTheme = checked; break; | |
732 | case ID_BUTTONBAR: m_buttonBar = checked; break; | |
733 | case ID_HORZ_LAYOUT: m_horzLayout = checked; break; | |
734 | default: break; // avoid compiler warning | |
735 | } | |
736 | ||
eca15c0d | 737 | RecreateBook(); |
9133965e | 738 | m_sizerFrame->Layout(); |
9133965e | 739 | } |
477350ce | 740 | |
9133965e WS |
741 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) |
742 | { | |
743 | Close(); | |
326f9654 RR |
744 | } |
745 | ||
eca15c0d VZ |
746 | void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event)) |
747 | { | |
61c083e7 | 748 | wxBookCtrlBase *currBook = GetCurrentBook(); |
9133965e WS |
749 | |
750 | if ( currBook ) | |
3957448a | 751 | { |
eca15c0d VZ |
752 | static unsigned s_pageAdded = 0; |
753 | currBook->AddPage(CreateNewPage(), | |
754 | wxString::Format | |
755 | ( | |
756 | ADDED_PAGE_NAME wxT("%u"), | |
757 | ++s_pageAdded | |
758 | ), | |
759 | true, | |
760 | GetIconIndex(currBook)); | |
761 | } | |
762 | } | |
763 | ||
a85dda4a RR |
764 | void MyFrame::OnAddPageNoSelect(wxCommandEvent& WXUNUSED(event)) |
765 | { | |
766 | wxBookCtrlBase *currBook = GetCurrentBook(); | |
767 | ||
768 | if ( currBook ) | |
769 | { | |
770 | static unsigned s_pageAdded = 0; | |
771 | currBook->AddPage(CreateNewPage(), | |
772 | wxString::Format | |
773 | ( | |
774 | ADDED_PAGE_NAME wxT("%u"), | |
775 | ++s_pageAdded | |
776 | ), | |
777 | false, | |
778 | GetIconIndex(currBook)); | |
779 | } | |
780 | } | |
781 | ||
eca15c0d VZ |
782 | #if wxUSE_TREEBOOK |
783 | void MyFrame::OnAddSubPage(wxCommandEvent& WXUNUSED(event)) | |
784 | { | |
785 | wxTreebook *currBook = wxDynamicCast(GetCurrentBook(), wxTreebook); | |
786 | if ( currBook ) | |
787 | { | |
788 | const int selPos = currBook->GetSelection(); | |
789 | if ( selPos == wxNOT_FOUND ) | |
790 | { | |
9a83f860 | 791 | wxLogError(wxT("Select the parent page first!")); |
eca15c0d VZ |
792 | return; |
793 | } | |
794 | ||
795 | static unsigned s_subPageAdded = 0; | |
9d5371c6 VZ |
796 | currBook->InsertSubPage |
797 | ( | |
798 | selPos, | |
799 | CreateNewPage(), | |
800 | wxString::Format | |
801 | ( | |
802 | ADDED_SUB_PAGE_NAME wxT("%u"), | |
803 | ++s_subPageAdded | |
804 | ), | |
805 | true, | |
806 | GetIconIndex(currBook) | |
807 | ); | |
eca15c0d VZ |
808 | } |
809 | } | |
810 | ||
811 | void MyFrame::OnAddPageBefore(wxCommandEvent& WXUNUSED(event)) | |
812 | { | |
813 | wxBookCtrlBase *currBook = GetCurrentBook(); | |
814 | if ( currBook ) | |
815 | { | |
816 | const int selPos = currBook->GetSelection(); | |
817 | if ( selPos == wxNOT_FOUND ) | |
818 | { | |
9a83f860 | 819 | wxLogError(wxT("Select the parent page first!")); |
eca15c0d VZ |
820 | return; |
821 | } | |
822 | ||
823 | static unsigned s_subPageAdded = 0; | |
824 | currBook->InsertPage(selPos, | |
825 | CreateNewPage(), | |
826 | wxString::Format | |
827 | ( | |
828 | ADDED_PAGE_NAME_BEFORE wxT("%u"), | |
829 | ++s_subPageAdded | |
830 | ), | |
831 | true, | |
832 | GetIconIndex(currBook)); | |
3957448a VZ |
833 | } |
834 | } | |
eca15c0d | 835 | #endif // wxUSE_TREEBOOK |
3957448a | 836 | |
9133965e | 837 | void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event)) |
29f538ce | 838 | { |
9133965e WS |
839 | static unsigned s_pageIns = 0; |
840 | ||
61c083e7 | 841 | wxBookCtrlBase *currBook = GetCurrentBook(); |
f6bcfd97 | 842 | |
9133965e | 843 | if ( currBook ) |
f6bcfd97 | 844 | { |
9133965e WS |
845 | wxPanel *panel = CreateUserCreatedPage( currBook ); |
846 | ||
847 | currBook->InsertPage( 0, panel, | |
848 | wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false, | |
849 | GetIconIndex(currBook) ); | |
850 | ||
851 | currBook->SetSelection(0); | |
f6bcfd97 | 852 | } |
29f538ce RR |
853 | } |
854 | ||
9133965e | 855 | void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event)) |
33d0e17c | 856 | { |
61c083e7 | 857 | wxBookCtrlBase *currBook = GetCurrentBook(); |
33d0e17c | 858 | |
9133965e WS |
859 | if ( currBook ) |
860 | { | |
861 | int sel = currBook->GetSelection(); | |
862 | ||
863 | if (sel != wxNOT_FOUND) | |
864 | { | |
865 | currBook->DeletePage(sel); | |
866 | } | |
867 | } | |
0b4d4194 JS |
868 | } |
869 | ||
9133965e | 870 | void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event)) |
0b4d4194 | 871 | { |
61c083e7 | 872 | wxBookCtrlBase *currBook = GetCurrentBook(); |
d22699b5 | 873 | |
9133965e | 874 | if ( currBook ) |
c1dfe277 | 875 | { |
9133965e | 876 | int page = currBook->GetPageCount(); |
c1dfe277 | 877 | |
9133965e WS |
878 | if ( page != 0 ) |
879 | { | |
880 | currBook->DeletePage(page - 1); | |
c1dfe277 | 881 | } |
c1dfe277 | 882 | } |
9133965e | 883 | } |
0b4d4194 | 884 | |
9133965e WS |
885 | void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event)) |
886 | { | |
61c083e7 | 887 | wxBookCtrlBase *currBook = GetCurrentBook(); |
0b4d4194 | 888 | |
9133965e WS |
889 | if ( currBook ) |
890 | { | |
891 | currBook->AdvanceSelection(); | |
892 | } | |
0b4d4194 JS |
893 | } |
894 | ||
f7aaef4d | 895 | void MyFrame::OnChangeSelection(wxCommandEvent& WXUNUSED(event)) |
1d6fcbcc VZ |
896 | { |
897 | wxBookCtrlBase *currBook = GetCurrentBook(); | |
898 | ||
899 | if ( currBook ) | |
1d6fcbcc | 900 | currBook->ChangeSelection(0); |
f7aaef4d VZ |
901 | } |
902 | ||
903 | void MyFrame::OnSetSelection(wxCommandEvent& WXUNUSED(event)) | |
904 | { | |
905 | wxBookCtrlBase *currBook = GetCurrentBook(); | |
906 | ||
907 | if ( currBook ) | |
908 | currBook->SetSelection(0); | |
1d6fcbcc VZ |
909 | } |
910 | ||
c1dfe277 | 911 | void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) ) |
96d37807 | 912 | { |
9133965e WS |
913 | static int s_nPages = wxNOT_FOUND; |
914 | static int s_nSel = wxNOT_FOUND; | |
61c083e7 | 915 | static wxBookCtrlBase *s_currBook = NULL; |
9133965e | 916 | |
61c083e7 | 917 | wxBookCtrlBase *currBook = GetCurrentBook(); |
96d37807 | 918 | |
9133965e WS |
919 | int nPages = currBook ? currBook->GetPageCount() : 0; |
920 | int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND; | |
921 | ||
922 | if ( nPages != s_nPages || nSel != s_nSel || s_currBook != currBook ) | |
96d37807 VZ |
923 | { |
924 | s_nPages = nPages; | |
925 | s_nSel = nSel; | |
9133965e WS |
926 | s_currBook = currBook; |
927 | ||
928 | wxString selection; | |
929 | if ( nSel == wxNOT_FOUND ) | |
930 | selection << wxT("not found"); | |
931 | else | |
932 | selection << nSel; | |
96d37807 VZ |
933 | |
934 | wxString title; | |
9133965e | 935 | title.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages, selection.c_str()); |
96d37807 VZ |
936 | |
937 | SetTitle(title); | |
938 | } | |
939 | } | |
3957448a | 940 | |
eca15c0d VZ |
941 | void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent& event) |
942 | { | |
943 | static const struct EventInfo | |
944 | { | |
945 | wxEventType typeChanged, | |
946 | typeChanging; | |
947 | const wxChar *name; | |
948 | } events[] = | |
949 | { | |
02161c7c | 950 | #if wxUSE_NOTEBOOK |
eca15c0d VZ |
951 | { |
952 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, | |
953 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, | |
9a83f860 | 954 | wxT("wxNotebook") |
eca15c0d VZ |
955 | }, |
956 | #endif // wxUSE_NOTEBOOK | |
02161c7c | 957 | #if wxUSE_LISTBOOK |
eca15c0d VZ |
958 | { |
959 | wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, | |
960 | wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, | |
9a83f860 | 961 | wxT("wxListbook") |
eca15c0d VZ |
962 | }, |
963 | #endif // wxUSE_LISTBOOK | |
136bafcd VZ |
964 | #if wxUSE_CHOICEBOOK |
965 | { | |
966 | wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, | |
967 | wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, | |
9a83f860 | 968 | wxT("wxChoicebook") |
136bafcd VZ |
969 | }, |
970 | #endif // wxUSE_CHOICEBOOK | |
eca15c0d VZ |
971 | #if wxUSE_TREEBOOK |
972 | { | |
973 | wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, | |
974 | wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, | |
9a83f860 | 975 | wxT("wxTreebook") |
eca15c0d VZ |
976 | }, |
977 | #endif // wxUSE_TREEBOOK | |
d709457c JS |
978 | #if wxUSE_TOOLBOOK |
979 | { | |
980 | wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED, | |
981 | wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING, | |
9a83f860 | 982 | wxT("wxToolbook") |
d709457c JS |
983 | }, |
984 | #endif // wxUSE_TOOLBOOK | |
873ff54b SL |
985 | #if wxUSE_AUI |
986 | { | |
987 | wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, | |
988 | wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, | |
989 | wxT("wxAuiNotebook") | |
990 | }, | |
991 | #endif // wxUSE_AUI | |
eca15c0d VZ |
992 | }; |
993 | ||
994 | ||
995 | wxString nameEvent, | |
996 | nameControl, | |
997 | veto; | |
998 | const wxEventType eventType = event.GetEventType(); | |
c7e94140 VZ |
999 | |
1000 | // NB: can't use wxStaticCast here as wxBookCtrlBase is not in | |
1001 | // wxRTTI | |
1002 | const wxBookCtrlBase * const | |
1003 | book = static_cast<wxBookCtrlBase *>(event.GetEventObject()); | |
1004 | ||
eca15c0d VZ |
1005 | for ( size_t n = 0; n < WXSIZEOF(events); n++ ) |
1006 | { | |
1007 | const EventInfo& ei = events[n]; | |
1008 | if ( eventType == ei.typeChanged ) | |
1009 | { | |
1010 | nameEvent = wxT("Changed"); | |
1011 | } | |
1012 | else if ( eventType == ei.typeChanging ) | |
1013 | { | |
1014 | const int idx = event.GetOldSelection(); | |
582ca353 | 1015 | |
eca15c0d VZ |
1016 | if ( idx != wxNOT_FOUND && |
1017 | book && book->GetPageText(idx) == VETO_PAGE_NAME ) | |
1018 | { | |
1019 | if ( wxMessageBox | |
1020 | ( | |
1021 | wxT("Are you sure you want to leave this page?\n") | |
1022 | wxT("(This demonstrates veto-ing)"), | |
1023 | wxT("Notebook sample"), | |
1024 | wxICON_QUESTION | wxYES_NO, | |
1025 | this | |
1026 | ) != wxYES ) | |
1027 | { | |
1028 | event.Veto(); | |
9a83f860 | 1029 | veto = wxT(" (vetoed)"); |
eca15c0d VZ |
1030 | } |
1031 | } | |
1032 | ||
1033 | nameEvent = wxT("Changing"); | |
1034 | } | |
1035 | else // skip end of the loop | |
1036 | { | |
1037 | continue; | |
1038 | } | |
1039 | ||
1040 | nameControl = ei.name; | |
1041 | break; | |
1042 | } | |
1043 | ||
1044 | static int s_num = 0; | |
1045 | ||
c7e94140 | 1046 | wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d, current %d%s"), |
eca15c0d VZ |
1047 | ++s_num, |
1048 | nameControl.c_str(), | |
1049 | nameEvent.c_str(), | |
1050 | eventType, | |
1051 | event.GetSelection(), | |
1052 | event.GetOldSelection(), | |
c7e94140 | 1053 | book->GetSelection(), |
eca15c0d VZ |
1054 | veto.c_str()); |
1055 | ||
1056 | #if USE_LOG | |
1057 | m_text->SetInsertionPointEnd(); | |
02161c7c | 1058 | #endif |
eca15c0d | 1059 | } |