1 | /////////////////////////////////////////////////////////////////////////////
|
---|
2 | // Name: samples/notebook/notebook.cpp
|
---|
3 | // Purpose: a sample demonstrating notebook usage
|
---|
4 | // Author: Julian Smart
|
---|
5 | // Modified by: Dimitri Schoolwerth
|
---|
6 | // Created: 26/10/98
|
---|
7 | // RCS-ID: $Id: notebook.cpp,v 1.38 2005/06/17 14:36:23 VZ Exp $
|
---|
8 | // Copyright: (c) 1998-2002 wxWidgets team
|
---|
9 | // License: wxWindows license
|
---|
10 | /////////////////////////////////////////////////////////////////////////////
|
---|
11 |
|
---|
12 | // For compilers that support precompilation, includes "wx.h".
|
---|
13 | #include "wx/wxprec.h"
|
---|
14 |
|
---|
15 | #ifdef __BORLANDC__
|
---|
16 | #pragma hdrstop
|
---|
17 | #endif
|
---|
18 |
|
---|
19 | #ifndef WX_PRECOMP
|
---|
20 | #include "wx/wx.h"
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | #include "wx/imaglist.h"
|
---|
24 | #include "wx/artprov.h"
|
---|
25 | #include "preprocessorFrontEnd.h"
|
---|
26 |
|
---|
27 | #if !defined(__WXMSW__) && !defined(__WXPM__)
|
---|
28 | #include "../sample.xpm"
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | IMPLEMENT_APP(MyApp)
|
---|
32 |
|
---|
33 |
|
---|
34 | bool MyApp::OnInit()
|
---|
35 | {
|
---|
36 | // Create the main window
|
---|
37 | MyFrame *frame = new MyFrame(wxT("Preprocessor Frontend"));
|
---|
38 |
|
---|
39 | // Problem with generic wxNotebook implementation whereby it doesn't size
|
---|
40 | // properly unless you set the size again
|
---|
41 | //#if defined(__WXMOTIF__)
|
---|
42 | // frame->SetSize(wxDefaultCoord, wxDefaultCoord, 1024, 768);
|
---|
43 | int width, height;
|
---|
44 | frame->GetSize(&width, &height);
|
---|
45 | frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height);
|
---|
46 | //#endif
|
---|
47 |
|
---|
48 | frame->Show();
|
---|
49 |
|
---|
50 | return true;
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | wxPanel *MyFrame::CreateUserCreatedPage(wxBookCtrlBase *parent)
|
---|
55 | {
|
---|
56 | wxPanel *panel = new wxPanel(parent);
|
---|
57 |
|
---|
58 | (void) new wxButton(panel, wxID_ANY, wxT("Button"),
|
---|
59 | wxPoint(10, 10), wxDefaultSize);
|
---|
60 |
|
---|
61 | return panel;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | wxPanel *MyFrame::CreatePreprocessorPage(wxBookCtrlBase *parent)
|
---|
66 | {
|
---|
67 | wxPanel *panel = new wxPanel(parent);
|
---|
68 |
|
---|
69 | wxString preprocessorType[] = {wxT("Rss"), wxT("Gvs"), wxT("None")};
|
---|
70 |
|
---|
71 | wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose preprocessor type"),
|
---|
72 | wxDefaultPosition, wxDefaultSize, 3, preprocessorType, 1, wxRA_SPECIFY_ROWS);
|
---|
73 |
|
---|
74 | mDetectEmptyViewSpaceText = new wxTextCtrl(panel, wxID_ANY, "detect emtpy view space",
|
---|
75 | wxDefaultPosition, wxDefaultSize);
|
---|
76 |
|
---|
77 | //mDetectEmptyViewSpaceCheckBox = new wxCheckBox(panel, wxID_ANY);
|
---|
78 |
|
---|
79 | wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
|
---|
80 | sizerPanel->Add(radiobox1, 1, wxEXPAND);
|
---|
81 | sizerPanel->Add(mDetectEmptyViewSpaceText, 1);
|
---|
82 | sizerPanel->Add(mDetectEmptyViewSpaceCheckBox, 1);
|
---|
83 |
|
---|
84 | panel->SetSizer(sizerPanel);
|
---|
85 |
|
---|
86 | return panel;
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | wxPanel *MyFrame::CreateViewCellsPage(wxBookCtrlBase *parent)
|
---|
91 | {
|
---|
92 | wxPanel *panel = new wxPanel(parent);
|
---|
93 |
|
---|
94 | wxString viewSpaceHierarchy[] = {wxT("vspBsp"), wxT("vspOsp"), wxT("bsp")};
|
---|
95 |
|
---|
96 | wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose view space hierarchy type"),
|
---|
97 | wxDefaultPosition, wxDefaultSize, 3, viewSpaceHierarchy, 1, wxRA_SPECIFY_ROWS);
|
---|
98 |
|
---|
99 | wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
|
---|
100 | sizerPanel->Add(radiobox1, 1, wxEXPAND);
|
---|
101 | panel->SetSizer(sizerPanel);
|
---|
102 |
|
---|
103 | return panel;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | /*wxPanel *CreateVetoPage(wxBookCtrlBase *parent)
|
---|
108 | {
|
---|
109 | wxPanel *panel = new wxPanel(parent);
|
---|
110 |
|
---|
111 | (void) new wxStaticText( panel, wxID_ANY,
|
---|
112 | wxT("This page intentionally left blank"), wxPoint(10, 10) );
|
---|
113 |
|
---|
114 | return panel;
|
---|
115 | }*/
|
---|
116 |
|
---|
117 |
|
---|
118 | /*wxPanel *CreateInsertPage(wxBookCtrlBase *parent)
|
---|
119 | {
|
---|
120 | wxPanel *panel = new wxPanel(parent);
|
---|
121 |
|
---|
122 | panel->SetBackgroundColour( wxColour( wxT("MAROON") ) );
|
---|
123 | (void) new wxStaticText( panel, wxID_ANY,
|
---|
124 | wxT("This page has been inserted, not added."), wxPoint(10, 10) );
|
---|
125 |
|
---|
126 | return panel;
|
---|
127 | }*/
|
---|
128 |
|
---|
129 |
|
---|
130 | int GetIconIndex(wxBookCtrlBase* bookCtrl)
|
---|
131 | {
|
---|
132 | if (bookCtrl && bookCtrl->GetImageList())
|
---|
133 | {
|
---|
134 | int nImages = bookCtrl->GetImageList()->GetImageCount();
|
---|
135 | if (nImages > 0)
|
---|
136 | {
|
---|
137 | return bookCtrl->GetPageCount() % nImages;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | return -1;
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | void MyFrame::CreateInitialPages(wxBookCtrlBase *parent)
|
---|
146 | {
|
---|
147 | // Create and add some panels to the notebook
|
---|
148 | wxPanel *panel = CreatePreprocessorPage(parent);
|
---|
149 | parent->AddPage(panel, PREPROCESSOR_PAGE_NAME, false, GetIconIndex(parent));
|
---|
150 |
|
---|
151 | panel = CreateViewCellsPage(parent);
|
---|
152 | parent->AddPage(panel, VIEWCELLS_PAGE_NAME, false, GetIconIndex(parent));
|
---|
153 |
|
---|
154 | //panel = CreateVetoPage(parent);
|
---|
155 | //parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) );
|
---|
156 |
|
---|
157 | //panel = CreateInsertPage(parent);
|
---|
158 | //parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) );
|
---|
159 |
|
---|
160 | parent->SetSelection(1);
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | wxPanel *MyFrame::CreatePage(wxBookCtrlBase *parent, const wxString&pageName)
|
---|
165 | {
|
---|
166 |
|
---|
167 | if (pageName == VIEWCELLS_PAGE_NAME)
|
---|
168 | {
|
---|
169 | return CreateViewCellsPage(parent);
|
---|
170 | }
|
---|
171 |
|
---|
172 | if (pageName == PREPROCESSOR_PAGE_NAME)
|
---|
173 | {
|
---|
174 | return CreatePreprocessorPage(parent);
|
---|
175 | }
|
---|
176 |
|
---|
177 | wxFAIL;
|
---|
178 |
|
---|
179 | return (wxPanel *) NULL;
|
---|
180 | }
|
---|
181 |
|
---|
182 | MyFrame::MyFrame(const wxString& title,
|
---|
183 | const wxPoint& pos,
|
---|
184 | const wxSize& size,
|
---|
185 | long style)
|
---|
186 | : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style)
|
---|
187 | {
|
---|
188 | #if wxUSE_NOTEBOOK
|
---|
189 | mType = ID_BOOK_NOTEBOOK;
|
---|
190 | #elif wxUSE_CHOICEBOOK
|
---|
191 | mType = ID_BOOK_CHOICEBOOK;
|
---|
192 | #elif wxUSE_LISTBOOK
|
---|
193 | mType = ID_BOOK_LISTBOOK;
|
---|
194 | #elif
|
---|
195 | #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
|
---|
196 | #endif
|
---|
197 |
|
---|
198 | mOrient = ID_ORIENT_DEFAULT;
|
---|
199 | mChkShowImages = true;
|
---|
200 | mMulti = false;
|
---|
201 |
|
---|
202 | SetIcon(wxICON(sample));
|
---|
203 |
|
---|
204 | // menu of the sample
|
---|
205 | wxMenu *menuType = new wxMenu;
|
---|
206 | #if wxUSE_NOTEBOOK
|
---|
207 | menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, wxT("&Notebook\tCtrl-1"));
|
---|
208 | #endif
|
---|
209 | #if wxUSE_LISTBOOK
|
---|
210 | menuType->AppendRadioItem(ID_BOOK_LISTBOOK, wxT("&Listbook\tCtrl-2"));
|
---|
211 | #endif
|
---|
212 | #if wxUSE_CHOICEBOOK
|
---|
213 | menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3"));
|
---|
214 | #endif
|
---|
215 |
|
---|
216 | menuType->Check(mType, true);
|
---|
217 |
|
---|
218 | wxMenu *menuOrient = new wxMenu;
|
---|
219 | menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tCtrl-4"));
|
---|
220 | menuOrient->AppendRadioItem(ID_ORIENT_TOP, wxT("&Top\tCtrl-5"));
|
---|
221 | menuOrient->AppendRadioItem(ID_ORIENT_BOTTOM, wxT("&Bottom\tCtrl-6"));
|
---|
222 | menuOrient->AppendRadioItem(ID_ORIENT_LEFT, wxT("&Left\tCtrl-7"));
|
---|
223 | menuOrient->AppendRadioItem(ID_ORIENT_RIGHT, wxT("&Right\tCtrl-8"));
|
---|
224 |
|
---|
225 | wxMenu *menuDo = new wxMenu;
|
---|
226 | menuDo->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A"));
|
---|
227 | menuDo->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I"));
|
---|
228 | menuDo->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D"));
|
---|
229 | menuDo->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L"));
|
---|
230 | menuDo->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N"));
|
---|
231 |
|
---|
232 | wxMenu *menuFile = new wxMenu;
|
---|
233 | menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control"));
|
---|
234 | menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control"));
|
---|
235 | menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S"));
|
---|
236 | menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines\tAlt-M"));
|
---|
237 | menuFile->AppendSeparator();
|
---|
238 | menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application"));
|
---|
239 | menuFile->Check(ID_SHOW_IMAGES, mChkShowImages);
|
---|
240 | menuFile->Check(ID_MULTI, mMulti);
|
---|
241 |
|
---|
242 | wxMenuBar *menuBar = new wxMenuBar;
|
---|
243 | menuBar->Append(menuFile, wxT("&File"));
|
---|
244 | menuBar->Append(menuDo, wxT("&Operations"));
|
---|
245 | SetMenuBar(menuBar);
|
---|
246 |
|
---|
247 | // books creation
|
---|
248 |
|
---|
249 | mPanel = (wxPanel *) NULL;
|
---|
250 | #if wxUSE_NOTEBOOK
|
---|
251 | mNotebook = (wxNotebook *) NULL;
|
---|
252 | #endif
|
---|
253 | #if wxUSE_CHOICEBOOK
|
---|
254 | mChoicebook = (wxChoicebook *) NULL;
|
---|
255 | #endif
|
---|
256 | #if wxUSE_LISTBOOK
|
---|
257 | mListbook = (wxListbook *) NULL;
|
---|
258 | #endif
|
---|
259 |
|
---|
260 | // create a dummy image list with a few icons
|
---|
261 | wxSize imageSize(32, 32);
|
---|
262 |
|
---|
263 | mImageList
|
---|
264 | = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() );
|
---|
265 |
|
---|
266 | mImageList->Add
|
---|
267 | (
|
---|
268 | wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)
|
---|
269 | );
|
---|
270 |
|
---|
271 | mImageList->Add
|
---|
272 | (
|
---|
273 | wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)
|
---|
274 | );
|
---|
275 |
|
---|
276 | mImageList->Add
|
---|
277 | (
|
---|
278 | wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)
|
---|
279 | );
|
---|
280 |
|
---|
281 | mImageList->Add
|
---|
282 | (
|
---|
283 | wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)
|
---|
284 | );
|
---|
285 |
|
---|
286 | mPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
---|
287 | wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
|
---|
288 |
|
---|
289 | #if USE_LOG
|
---|
290 | mText = new wxTextCtrl(mPanel, wxID_ANY, wxEmptyString,
|
---|
291 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
|
---|
292 |
|
---|
293 | mLogTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(mText) );
|
---|
294 | #endif // USE_LOG
|
---|
295 |
|
---|
296 | // Set sizers
|
---|
297 | mSizerFrame = new wxBoxSizer(wxVERTICAL);
|
---|
298 |
|
---|
299 | #if USE_LOG
|
---|
300 | mSizerFrame->Add(mText, 1, wxEXPAND);
|
---|
301 | #endif // USE_LOG
|
---|
302 |
|
---|
303 | // create preprocessor front end
|
---|
304 | //mPreprocessorFrontEnd = new PreprocessorFrontEnd();
|
---|
305 | RecreateBooks();
|
---|
306 | mPanel->SetSizer(mSizerFrame);
|
---|
307 |
|
---|
308 | mSizerFrame->Fit(this);
|
---|
309 | mSizerFrame->SetSizeHints(this);
|
---|
310 |
|
---|
311 | Centre(wxBOTH);
|
---|
312 | }
|
---|
313 |
|
---|
314 |
|
---|
315 | MyFrame::~MyFrame()
|
---|
316 | {
|
---|
317 | #if USE_LOG
|
---|
318 | delete wxLog::SetActiveTarget(mLogTargetOld);
|
---|
319 | #endif // USE_LOG
|
---|
320 |
|
---|
321 | if (mImageList)
|
---|
322 | {
|
---|
323 | delete mImageList;
|
---|
324 | mImageList = (wxImageList *) NULL;
|
---|
325 | }
|
---|
326 | }
|
---|
327 |
|
---|
328 | int MyFrame::SelectFlag(int id, int nb, int lb, int chb)
|
---|
329 | {
|
---|
330 | switch (id)
|
---|
331 | {
|
---|
332 | case ID_NOTEBOOK: return nb;
|
---|
333 | case ID_LISTBOOK: return lb;
|
---|
334 | case ID_CHOICEBOOK: return chb;
|
---|
335 | }
|
---|
336 | return 0;
|
---|
337 | }
|
---|
338 |
|
---|
339 | #ifdef __SMARTPHONE__
|
---|
340 | #define MARGIN 0
|
---|
341 | #else
|
---|
342 | #define MARGIN 4
|
---|
343 | #endif
|
---|
344 |
|
---|
345 | #define RECREATE(wxBookType , idBook, oldBook, newBook) \
|
---|
346 | { \
|
---|
347 | int flags; \
|
---|
348 | \
|
---|
349 | switch (mOrient) \
|
---|
350 | { \
|
---|
351 | case ID_ORIENT_TOP: \
|
---|
352 | flags = SelectFlag(idBook, wxNB_TOP, wxLB_TOP, wxCHB_TOP); \
|
---|
353 | break; \
|
---|
354 | \
|
---|
355 | case ID_ORIENT_BOTTOM: \
|
---|
356 | flags = SelectFlag(idBook, wxNB_BOTTOM, wxLB_BOTTOM, wxCHB_BOTTOM); \
|
---|
357 | break; \
|
---|
358 | \
|
---|
359 | case ID_ORIENT_LEFT: \
|
---|
360 | flags = SelectFlag(idBook, wxNB_LEFT, wxLB_LEFT, wxCHB_LEFT); \
|
---|
361 | break; \
|
---|
362 | \
|
---|
363 | case ID_ORIENT_RIGHT: \
|
---|
364 | flags = SelectFlag(idBook, wxNB_RIGHT, wxLB_RIGHT, wxCHB_RIGHT); \
|
---|
365 | break; \
|
---|
366 | \
|
---|
367 | default: \
|
---|
368 | flags = SelectFlag(idBook, wxNB_DEFAULT, wxLB_DEFAULT, wxCHB_DEFAULT); \
|
---|
369 | } \
|
---|
370 | \
|
---|
371 | if (mMulti && (idBook == ID_NOTEBOOK)) \
|
---|
372 | flags |= wxNB_MULTILINE; \
|
---|
373 | \
|
---|
374 | wxBookType *oldBook = newBook; \
|
---|
375 | \
|
---|
376 | newBook = new wxBookType(mPanel, idBook, \
|
---|
377 | wxDefaultPosition, wxDefaultSize, \
|
---|
378 | flags); \
|
---|
379 | \
|
---|
380 | if (mChkShowImages) \
|
---|
381 | { \
|
---|
382 | newBook->SetImageList(mImageList); \
|
---|
383 | } \
|
---|
384 | \
|
---|
385 | if (oldBook) \
|
---|
386 | { \
|
---|
387 | int sel = oldBook->GetSelection(); \
|
---|
388 | \
|
---|
389 | int count = oldBook->GetPageCount(); \
|
---|
390 | for (int n = 0; n < count; n++) \
|
---|
391 | { \
|
---|
392 | wxString str = oldBook->GetPageText(n); \
|
---|
393 | \
|
---|
394 | wxWindow *page = CreatePage(newBook, str); \
|
---|
395 | newBook->AddPage(page, str, false, GetIconIndex(newBook) ); \
|
---|
396 | } \
|
---|
397 | \
|
---|
398 | mSizerFrame->Detach(oldBook); \
|
---|
399 | \
|
---|
400 | delete oldBook; \
|
---|
401 | \
|
---|
402 | if (sel != wxNOT_FOUND) \
|
---|
403 | { \
|
---|
404 | newBook->SetSelection(sel); \
|
---|
405 | } \
|
---|
406 | \
|
---|
407 | } \
|
---|
408 | else \
|
---|
409 | { \
|
---|
410 | CreateInitialPages(newBook); \
|
---|
411 | } \
|
---|
412 | \
|
---|
413 | mSizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, MARGIN); \
|
---|
414 | mSizerFrame->Hide(newBook); \
|
---|
415 | }
|
---|
416 |
|
---|
417 |
|
---|
418 | void MyFrame::RecreateBooks()
|
---|
419 | {
|
---|
420 | #if wxUSE_NOTEBOOK
|
---|
421 | RECREATE(wxNotebook, ID_NOTEBOOK, notebook, mNotebook);
|
---|
422 | #endif
|
---|
423 | #if wxUSE_LISTBOOK
|
---|
424 | // RECREATE(wxListbook, ID_LISTBOOK, listbook, mListbook);
|
---|
425 | #endif
|
---|
426 | #if wxUSE_CHOICEBOOK
|
---|
427 | RECREATE(wxChoicebook, ID_CHOICEBOOK, choicebook, mChoicebook);
|
---|
428 | #endif
|
---|
429 |
|
---|
430 | ShowCurrentBook();
|
---|
431 | }
|
---|
432 |
|
---|
433 |
|
---|
434 | wxBookCtrlBase *MyFrame::GetCurrentBook()
|
---|
435 | {
|
---|
436 | switch (mType)
|
---|
437 | {
|
---|
438 | #if wxUSE_NOTEBOOK
|
---|
439 | case ID_BOOK_NOTEBOOK: return mNotebook;
|
---|
440 | #endif
|
---|
441 | #if wxUSE_LISTBOOK
|
---|
442 | case ID_BOOK_LISTBOOK: return mListbook;
|
---|
443 | #endif
|
---|
444 | #if wxUSE_CHOICEBOOK
|
---|
445 | case ID_BOOK_CHOICEBOOK: return mChoicebook;
|
---|
446 | #endif
|
---|
447 | }
|
---|
448 | return NULL;
|
---|
449 | }
|
---|
450 |
|
---|
451 | void MyFrame::ShowCurrentBook()
|
---|
452 | {
|
---|
453 | switch(mType)
|
---|
454 | {
|
---|
455 | #if wxUSE_NOTEBOOK
|
---|
456 | case ID_BOOK_NOTEBOOK:
|
---|
457 | if (mNotebook)
|
---|
458 | {
|
---|
459 | mSizerFrame->Show(mNotebook);
|
---|
460 | }
|
---|
461 |
|
---|
462 | break;
|
---|
463 | #endif
|
---|
464 | #if wxUSE_LISTBOOK
|
---|
465 | case ID_BOOK_LISTBOOK:
|
---|
466 | if (mListbook)
|
---|
467 | {
|
---|
468 | mSizerFrame->Show(mListbook);
|
---|
469 | break;
|
---|
470 | }
|
---|
471 | #endif
|
---|
472 | #if wxUSE_CHOICEBOOK
|
---|
473 | case ID_BOOK_CHOICEBOOK:
|
---|
474 | if (mChoicebook)
|
---|
475 | {
|
---|
476 | mSizerFrame->Show(mChoicebook);
|
---|
477 | break;
|
---|
478 | }
|
---|
479 | #endif
|
---|
480 | }
|
---|
481 |
|
---|
482 | mSizerFrame->Layout();
|
---|
483 | }
|
---|
484 |
|
---|
485 | BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
---|
486 | // File menu
|
---|
487 | EVT_MENU_RANGE(ID_BOOK_NOTEBOOK,ID_BOOK_MAX,MyFrame::OnType)
|
---|
488 | EVT_MENU_RANGE(ID_ORIENT_DEFAULT,ID_ORIENT_MAX,MyFrame::OnOrient)
|
---|
489 | EVT_MENU(ID_SHOW_IMAGES, MyFrame::OnShowImages)
|
---|
490 | EVT_MENU(ID_MULTI, MyFrame::OnMulti)
|
---|
491 | EVT_MENU(wxID_EXIT,MyFrame::OnExit)
|
---|
492 |
|
---|
493 | // Operations menu
|
---|
494 | EVT_MENU(ID_ADD_PAGE, MyFrame::OnAddPage)
|
---|
495 | EVT_MENU(ID_INSERT_PAGE, MyFrame::OnInsertPage)
|
---|
496 | EVT_MENU(ID_DELETE_CUR_PAGE, MyFrame::OnDeleteCurPage)
|
---|
497 | EVT_MENU(ID_DELETE_LAST_PAGE, MyFrame::OnDeleteLastPage)
|
---|
498 | EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
|
---|
499 |
|
---|
500 | // Book controls
|
---|
501 | #if wxUSE_NOTEBOOK
|
---|
502 | EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook)
|
---|
503 | EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook)
|
---|
504 | #endif
|
---|
505 | #if wxUSE_LISTBOOK
|
---|
506 | EVT_LISTBOOK_PAGE_CHANGED(ID_LISTBOOK, MyFrame::OnListbook)
|
---|
507 | EVT_LISTBOOK_PAGE_CHANGING(ID_LISTBOOK, MyFrame::OnListbook)
|
---|
508 | #endif
|
---|
509 | #if wxUSE_CHOICEBOOK
|
---|
510 | EVT_CHOICEBOOK_PAGE_CHANGED(ID_CHOICEBOOK, MyFrame::OnChoicebook)
|
---|
511 | EVT_CHOICEBOOK_PAGE_CHANGING(ID_CHOICEBOOK, MyFrame::OnChoicebook)
|
---|
512 | #endif
|
---|
513 |
|
---|
514 | // Update title in idle time
|
---|
515 | EVT_IDLE(MyFrame::OnIdle)
|
---|
516 | END_EVENT_TABLE()
|
---|
517 |
|
---|
518 | void MyFrame::OnType(wxCommandEvent& event)
|
---|
519 | {
|
---|
520 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
521 |
|
---|
522 | mType = event.GetId();
|
---|
523 |
|
---|
524 | if (currBook)
|
---|
525 | mSizerFrame->Hide(currBook);
|
---|
526 |
|
---|
527 | ShowCurrentBook();
|
---|
528 | }
|
---|
529 |
|
---|
530 | void MyFrame::OnOrient(wxCommandEvent& event)
|
---|
531 | {
|
---|
532 | mOrient = event.GetId();
|
---|
533 | RecreateBooks();
|
---|
534 | mSizerFrame->Layout();
|
---|
535 | }
|
---|
536 |
|
---|
537 | void MyFrame::OnShowImages(wxCommandEvent& event)
|
---|
538 | {
|
---|
539 | mChkShowImages = event.IsChecked();
|
---|
540 | RecreateBooks();
|
---|
541 | mSizerFrame->Layout();
|
---|
542 | }
|
---|
543 |
|
---|
544 | void MyFrame::OnMulti(wxCommandEvent& event)
|
---|
545 | {
|
---|
546 | mMulti = event.IsChecked();
|
---|
547 | RecreateBooks();
|
---|
548 | mSizerFrame->Layout();
|
---|
549 | wxLogMessage(_T("Multiline setting works only in wxNotebook."));
|
---|
550 | }
|
---|
551 |
|
---|
552 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
---|
553 | {
|
---|
554 | Close();
|
---|
555 | }
|
---|
556 |
|
---|
557 | void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
|
---|
558 | {
|
---|
559 | static unsigned s_pageAdded = 0;
|
---|
560 |
|
---|
561 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
562 |
|
---|
563 | if (currBook)
|
---|
564 | {
|
---|
565 | wxPanel *panel = new wxPanel(currBook, wxID_ANY);
|
---|
566 |
|
---|
567 | (void) new wxButton( panel, wxID_ANY, wxT("First button"),
|
---|
568 | wxPoint(10, 10), wxDefaultSize );
|
---|
569 | (void) new wxButton( panel, wxID_ANY, wxT("Second button"),
|
---|
570 | wxPoint(50, 100), wxDefaultSize );
|
---|
571 |
|
---|
572 | currBook->AddPage(
|
---|
573 | panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"),
|
---|
574 | ++ s_pageAdded), true, GetIconIndex(currBook) );
|
---|
575 | }
|
---|
576 | }
|
---|
577 |
|
---|
578 |
|
---|
579 | void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
|
---|
580 | {
|
---|
581 | static unsigned s_pageIns = 0;
|
---|
582 |
|
---|
583 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
584 |
|
---|
585 | if (currBook)
|
---|
586 | {
|
---|
587 | wxPanel *panel = CreateUserCreatedPage(currBook);
|
---|
588 |
|
---|
589 | currBook->InsertPage( 0, panel,
|
---|
590 | wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++ s_pageIns), false,
|
---|
591 | GetIconIndex(currBook) );
|
---|
592 |
|
---|
593 | currBook->SetSelection(0);
|
---|
594 | }
|
---|
595 | }
|
---|
596 |
|
---|
597 |
|
---|
598 | void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
|
---|
599 | {
|
---|
600 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
601 |
|
---|
602 | if (currBook)
|
---|
603 | {
|
---|
604 | const int sel = currBook->GetSelection();
|
---|
605 |
|
---|
606 | if (sel != wxNOT_FOUND)
|
---|
607 | {
|
---|
608 | currBook->DeletePage(sel);
|
---|
609 | }
|
---|
610 | }
|
---|
611 | }
|
---|
612 |
|
---|
613 | void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event))
|
---|
614 | {
|
---|
615 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
616 |
|
---|
617 | if ( currBook )
|
---|
618 | {
|
---|
619 | const int page = currBook->GetPageCount();
|
---|
620 |
|
---|
621 | if ( page != 0 )
|
---|
622 | {
|
---|
623 | currBook->DeletePage(page - 1);
|
---|
624 | }
|
---|
625 | }
|
---|
626 | }
|
---|
627 |
|
---|
628 | void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event))
|
---|
629 | {
|
---|
630 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
631 |
|
---|
632 | if (currBook)
|
---|
633 | {
|
---|
634 | currBook->AdvanceSelection();
|
---|
635 | }
|
---|
636 | }
|
---|
637 |
|
---|
638 | void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
|
---|
639 | {
|
---|
640 | static int s_nPages = wxNOT_FOUND;
|
---|
641 | static int s_nSel = wxNOT_FOUND;
|
---|
642 | static wxBookCtrlBase *s_currBook = NULL;
|
---|
643 |
|
---|
644 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
645 |
|
---|
646 | int nPages = currBook ? currBook->GetPageCount() : 0;
|
---|
647 | int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND;
|
---|
648 |
|
---|
649 | if ( nPages != s_nPages || nSel != s_nSel || s_currBook != currBook )
|
---|
650 | {
|
---|
651 | s_nPages = nPages;
|
---|
652 | s_nSel = nSel;
|
---|
653 | s_currBook = currBook;
|
---|
654 |
|
---|
655 | wxString selection;
|
---|
656 | if ( nSel == wxNOT_FOUND )
|
---|
657 | selection << wxT("not found");
|
---|
658 | else
|
---|
659 | selection << nSel;
|
---|
660 |
|
---|
661 | wxString title;
|
---|
662 | title.Printf(wxT("Preprocessor (%d pages, selection: %s)"), nPages, selection.c_str());
|
---|
663 |
|
---|
664 | SetTitle(title);
|
---|
665 | }
|
---|
666 | }
|
---|
667 |
|
---|
668 | #if USE_LOG
|
---|
669 | #define BOOKEVENT_LOG mText->SetInsertionPointEnd();
|
---|
670 | #else
|
---|
671 | #define BOOKEVENT_LOG
|
---|
672 | #endif
|
---|
673 |
|
---|
674 | #define BOOKEVENT(OnBook,wxBookEvent,bookStr,wxEVT_PAGE_CHANGED,wxEVT_PAGE_CHANGING,s_num) \
|
---|
675 | void MyFrame::OnBook(wxBookEvent& event) \
|
---|
676 | { \
|
---|
677 | wxString str = wxT("Unknown "); \
|
---|
678 | str << wxT(bookStr); \
|
---|
679 | str << wxT(" event"); \
|
---|
680 | \
|
---|
681 | wxEventType eventType = event.GetEventType(); \
|
---|
682 | \
|
---|
683 | if (eventType == wxEVT_PAGE_CHANGED) \
|
---|
684 | { \
|
---|
685 | str = wxT("Changed"); \
|
---|
686 | } \
|
---|
687 | else if (eventType == wxEVT_PAGE_CHANGING) \
|
---|
688 | { \
|
---|
689 | int idx = event.GetOldSelection(); \
|
---|
690 | wxBookCtrlBase *book = (wxBookCtrlBase *)event.GetEventObject(); \
|
---|
691 | if ( idx != wxNOT_FOUND && book && book->GetPageText(idx) == VETO_PAGE_NAME ) \
|
---|
692 | { \
|
---|
693 | if \
|
---|
694 | ( \
|
---|
695 | wxMessageBox( \
|
---|
696 | wxT("Are you sure you want to leave this page?\n") \
|
---|
697 | wxT("(This demonstrates veto-ing)"), \
|
---|
698 | wxT("Notebook sample"), \
|
---|
699 | wxICON_QUESTION | wxYES_NO, this) != wxYES ) \
|
---|
700 | { \
|
---|
701 | event.Veto(); \
|
---|
702 | } \
|
---|
703 | \
|
---|
704 | } \
|
---|
705 | \
|
---|
706 | str = wxT("Changing"); \
|
---|
707 | } \
|
---|
708 | \
|
---|
709 | static int s_num = 0; \
|
---|
710 | \
|
---|
711 | wxString logMsg; \
|
---|
712 | logMsg.Printf(wxT("%s event #%d: %s (%d) Sel %d, OldSel %d"), \
|
---|
713 | wxT(bookStr),s_num++, str.c_str(), eventType, \
|
---|
714 | event.GetSelection(), event.GetOldSelection()); \
|
---|
715 | \
|
---|
716 | wxLogMessage(logMsg.c_str()); \
|
---|
717 | \
|
---|
718 | BOOKEVENT_LOG \
|
---|
719 | }
|
---|
720 |
|
---|
721 | #if wxUSE_NOTEBOOK
|
---|
722 | BOOKEVENT(OnNotebook,wxNotebookEvent,"wxNotebook",wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,s_numNotebookEvents)
|
---|
723 | #endif
|
---|
724 | #if wxUSE_CHOICEBOOK
|
---|
725 | BOOKEVENT(OnChoicebook,wxChoicebookEvent,"wxChoicebook",wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,s_numChoicebookEvents)
|
---|
726 | #endif
|
---|
727 | #if wxUSE_LISTBOOK
|
---|
728 | BOOKEVENT(OnListbook,wxListbookEvent,"wxListbook",wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,s_numListbookEvents)
|
---|
729 | #endif
|
---|