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