[1558] | 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 |
|
---|
[1563] | 33 |
|
---|
[1558] | 34 | bool MyApp::OnInit()
|
---|
| 35 | {
|
---|
| 36 | // Create the main window
|
---|
[1563] | 37 | MyFrame *frame = new MyFrame(wxT("Preprocessor Frontend"));
|
---|
[1558] | 38 |
|
---|
| 39 | // Problem with generic wxNotebook implementation whereby it doesn't size
|
---|
| 40 | // properly unless you set the size again
|
---|
[1563] | 41 | //#if defined(__WXMOTIF__)
|
---|
| 42 | // frame->SetSize(wxDefaultCoord, wxDefaultCoord, 1024, 768);
|
---|
[1558] | 43 | int width, height;
|
---|
[1563] | 44 | frame->GetSize(&width, &height);
|
---|
[1558] | 45 | frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height);
|
---|
[1563] | 46 | //#endif
|
---|
[1558] | 47 |
|
---|
| 48 | frame->Show();
|
---|
| 49 |
|
---|
| 50 | return true;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[1563] | 53 |
|
---|
| 54 | wxPanel *MyFrame::CreateUserCreatedPage(wxBookCtrlBase *parent)
|
---|
[1558] | 55 | {
|
---|
| 56 | wxPanel *panel = new wxPanel(parent);
|
---|
| 57 |
|
---|
[1563] | 58 | (void) new wxButton(panel, wxID_ANY, wxT("Button"),
|
---|
| 59 | wxPoint(10, 10), wxDefaultSize);
|
---|
[1558] | 60 |
|
---|
| 61 | return panel;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[1563] | 64 |
|
---|
| 65 | wxPanel *MyFrame::CreatePreprocessorPage(wxBookCtrlBase *parent)
|
---|
[1558] | 66 | {
|
---|
| 67 | wxPanel *panel = new wxPanel(parent);
|
---|
| 68 |
|
---|
[1563] | 69 | wxString preprocessorType[] = {wxT("Rss"), wxT("Gvs"), wxT("None")};
|
---|
[1558] | 70 |
|
---|
[1563] | 71 | wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose preprocessor type"),
|
---|
| 72 | wxDefaultPosition, wxDefaultSize, 3, preprocessorType, 1, wxRA_SPECIFY_ROWS);
|
---|
[1558] | 73 |
|
---|
[1563] | 74 | mDetectEmptyViewSpaceText = new wxTextCtrl(panel, wxID_ANY, "detect emtpy view space",
|
---|
| 75 | wxDefaultPosition, wxDefaultSize);
|
---|
[1558] | 76 |
|
---|
[1563] | 77 | //mDetectEmptyViewSpaceCheckBox = new wxCheckBox(panel, wxID_ANY);
|
---|
[1558] | 78 |
|
---|
| 79 | wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
|
---|
[1563] | 80 | sizerPanel->Add(radiobox1, 1, wxEXPAND);
|
---|
| 81 | sizerPanel->Add(mDetectEmptyViewSpaceText, 1);
|
---|
| 82 | sizerPanel->Add(mDetectEmptyViewSpaceCheckBox, 1);
|
---|
| 83 |
|
---|
[1558] | 84 | panel->SetSizer(sizerPanel);
|
---|
| 85 |
|
---|
| 86 | return panel;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[1563] | 89 |
|
---|
| 90 | wxPanel *MyFrame::CreateViewCellsPage(wxBookCtrlBase *parent)
|
---|
[1558] | 91 | {
|
---|
| 92 | wxPanel *panel = new wxPanel(parent);
|
---|
| 93 |
|
---|
[1563] | 94 | wxString viewSpaceHierarchy[] = {wxT("vspBsp"), wxT("vspOsp"), wxT("bsp")};
|
---|
[1558] | 95 |
|
---|
[1563] | 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 |
|
---|
[1558] | 103 | return panel;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[1563] | 106 |
|
---|
| 107 | /*wxPanel *CreateVetoPage(wxBookCtrlBase *parent)
|
---|
[1558] | 108 | {
|
---|
| 109 | wxPanel *panel = new wxPanel(parent);
|
---|
| 110 |
|
---|
[1563] | 111 | (void) new wxStaticText( panel, wxID_ANY,
|
---|
| 112 | wxT("This page intentionally left blank"), wxPoint(10, 10) );
|
---|
[1558] | 113 |
|
---|
| 114 | return panel;
|
---|
[1563] | 115 | }*/
|
---|
[1558] | 116 |
|
---|
| 117 |
|
---|
[1563] | 118 | /*wxPanel *CreateInsertPage(wxBookCtrlBase *parent)
|
---|
[1558] | 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;
|
---|
[1563] | 127 | }*/
|
---|
[1558] | 128 |
|
---|
[1563] | 129 |
|
---|
[1558] | 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 |
|
---|
[1563] | 144 |
|
---|
| 145 | void MyFrame::CreateInitialPages(wxBookCtrlBase *parent)
|
---|
[1558] | 146 | {
|
---|
| 147 | // Create and add some panels to the notebook
|
---|
[1563] | 148 | wxPanel *panel = CreatePreprocessorPage(parent);
|
---|
| 149 | parent->AddPage(panel, PREPROCESSOR_PAGE_NAME, false, GetIconIndex(parent));
|
---|
[1558] | 150 |
|
---|
[1563] | 151 | panel = CreateViewCellsPage(parent);
|
---|
| 152 | parent->AddPage(panel, VIEWCELLS_PAGE_NAME, false, GetIconIndex(parent));
|
---|
[1558] | 153 |
|
---|
[1563] | 154 | //panel = CreateVetoPage(parent);
|
---|
| 155 | //parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) );
|
---|
[1558] | 156 |
|
---|
[1563] | 157 | //panel = CreateInsertPage(parent);
|
---|
| 158 | //parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) );
|
---|
[1558] | 159 |
|
---|
| 160 | parent->SetSelection(1);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[1563] | 163 |
|
---|
| 164 | wxPanel *MyFrame::CreatePage(wxBookCtrlBase *parent, const wxString&pageName)
|
---|
[1558] | 165 | {
|
---|
[1563] | 166 |
|
---|
| 167 | if (pageName == VIEWCELLS_PAGE_NAME)
|
---|
[1558] | 168 | {
|
---|
[1563] | 169 | return CreateViewCellsPage(parent);
|
---|
[1558] | 170 | }
|
---|
| 171 |
|
---|
[1563] | 172 | if (pageName == PREPROCESSOR_PAGE_NAME)
|
---|
[1558] | 173 | {
|
---|
[1563] | 174 | return CreatePreprocessorPage(parent);
|
---|
[1558] | 175 | }
|
---|
| 176 |
|
---|
| 177 | wxFAIL;
|
---|
| 178 |
|
---|
| 179 | return (wxPanel *) NULL;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[1563] | 182 | MyFrame::MyFrame(const wxString& title,
|
---|
| 183 | const wxPoint& pos,
|
---|
| 184 | const wxSize& size,
|
---|
[1558] | 185 | long style)
|
---|
| 186 | : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style)
|
---|
| 187 | {
|
---|
| 188 | #if wxUSE_NOTEBOOK
|
---|
[1563] | 189 | mType = ID_BOOK_NOTEBOOK;
|
---|
[1558] | 190 | #elif wxUSE_CHOICEBOOK
|
---|
[1563] | 191 | mType = ID_BOOK_CHOICEBOOK;
|
---|
[1558] | 192 | #elif wxUSE_LISTBOOK
|
---|
[1563] | 193 | mType = ID_BOOK_LISTBOOK;
|
---|
[1558] | 194 | #elif
|
---|
| 195 | #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
|
---|
| 196 | #endif
|
---|
| 197 |
|
---|
[1563] | 198 | mOrient = ID_ORIENT_DEFAULT;
|
---|
| 199 | mChkShowImages = true;
|
---|
| 200 | mMulti = false;
|
---|
[1558] | 201 |
|
---|
| 202 | SetIcon(wxICON(sample));
|
---|
| 203 |
|
---|
| 204 | // menu of the sample
|
---|
| 205 | wxMenu *menuType = new wxMenu;
|
---|
| 206 | #if wxUSE_NOTEBOOK
|
---|
[1563] | 207 | menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, wxT("&Notebook\tCtrl-1"));
|
---|
[1558] | 208 | #endif
|
---|
| 209 | #if wxUSE_LISTBOOK
|
---|
[1563] | 210 | menuType->AppendRadioItem(ID_BOOK_LISTBOOK, wxT("&Listbook\tCtrl-2"));
|
---|
[1558] | 211 | #endif
|
---|
| 212 | #if wxUSE_CHOICEBOOK
|
---|
| 213 | menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3"));
|
---|
| 214 | #endif
|
---|
| 215 |
|
---|
[1563] | 216 | menuType->Check(mType, true);
|
---|
| 217 |
|
---|
[1558] | 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"));
|
---|
[1563] | 239 | menuFile->Check(ID_SHOW_IMAGES, mChkShowImages);
|
---|
| 240 | menuFile->Check(ID_MULTI, mMulti);
|
---|
[1558] | 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 |
|
---|
[1563] | 249 | mPanel = (wxPanel *) NULL;
|
---|
[1558] | 250 | #if wxUSE_NOTEBOOK
|
---|
[1563] | 251 | mNotebook = (wxNotebook *) NULL;
|
---|
[1558] | 252 | #endif
|
---|
| 253 | #if wxUSE_CHOICEBOOK
|
---|
[1563] | 254 | mChoicebook = (wxChoicebook *) NULL;
|
---|
[1558] | 255 | #endif
|
---|
| 256 | #if wxUSE_LISTBOOK
|
---|
[1563] | 257 | mListbook = (wxListbook *) NULL;
|
---|
[1558] | 258 | #endif
|
---|
| 259 |
|
---|
| 260 | // create a dummy image list with a few icons
|
---|
| 261 | wxSize imageSize(32, 32);
|
---|
| 262 |
|
---|
[1563] | 263 | mImageList
|
---|
[1558] | 264 | = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() );
|
---|
| 265 |
|
---|
[1563] | 266 | mImageList->Add
|
---|
[1558] | 267 | (
|
---|
| 268 | wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)
|
---|
| 269 | );
|
---|
| 270 |
|
---|
[1563] | 271 | mImageList->Add
|
---|
[1558] | 272 | (
|
---|
| 273 | wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)
|
---|
| 274 | );
|
---|
| 275 |
|
---|
[1563] | 276 | mImageList->Add
|
---|
[1558] | 277 | (
|
---|
| 278 | wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)
|
---|
| 279 | );
|
---|
| 280 |
|
---|
[1563] | 281 | mImageList->Add
|
---|
[1558] | 282 | (
|
---|
| 283 | wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)
|
---|
| 284 | );
|
---|
| 285 |
|
---|
[1563] | 286 | mPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
---|
[1558] | 287 | wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
|
---|
| 288 |
|
---|
| 289 | #if USE_LOG
|
---|
[1563] | 290 | mText = new wxTextCtrl(mPanel, wxID_ANY, wxEmptyString,
|
---|
[1558] | 291 | wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
|
---|
| 292 |
|
---|
[1563] | 293 | mLogTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(mText) );
|
---|
[1558] | 294 | #endif // USE_LOG
|
---|
| 295 |
|
---|
| 296 | // Set sizers
|
---|
[1563] | 297 | mSizerFrame = new wxBoxSizer(wxVERTICAL);
|
---|
[1558] | 298 |
|
---|
| 299 | #if USE_LOG
|
---|
[1563] | 300 | mSizerFrame->Add(mText, 1, wxEXPAND);
|
---|
[1558] | 301 | #endif // USE_LOG
|
---|
| 302 |
|
---|
[1563] | 303 | // create preprocessor front end
|
---|
| 304 | //mPreprocessorFrontEnd = new PreprocessorFrontEnd();
|
---|
[1558] | 305 | RecreateBooks();
|
---|
[1563] | 306 | mPanel->SetSizer(mSizerFrame);
|
---|
[1558] | 307 |
|
---|
[1563] | 308 | mSizerFrame->Fit(this);
|
---|
| 309 | mSizerFrame->SetSizeHints(this);
|
---|
[1558] | 310 |
|
---|
| 311 | Centre(wxBOTH);
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[1563] | 314 |
|
---|
[1558] | 315 | MyFrame::~MyFrame()
|
---|
| 316 | {
|
---|
| 317 | #if USE_LOG
|
---|
[1563] | 318 | delete wxLog::SetActiveTarget(mLogTargetOld);
|
---|
[1558] | 319 | #endif // USE_LOG
|
---|
| 320 |
|
---|
[1563] | 321 | if (mImageList)
|
---|
[1558] | 322 | {
|
---|
[1563] | 323 | delete mImageList;
|
---|
| 324 | mImageList = (wxImageList *) NULL;
|
---|
[1558] | 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 |
|
---|
[1563] | 345 | #define RECREATE(wxBookType , idBook, oldBook, newBook) \
|
---|
[1558] | 346 | { \
|
---|
| 347 | int flags; \
|
---|
| 348 | \
|
---|
[1563] | 349 | switch (mOrient) \
|
---|
[1558] | 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 | } \
|
---|
[1563] | 370 | \
|
---|
| 371 | if (mMulti && (idBook == ID_NOTEBOOK)) \
|
---|
[1558] | 372 | flags |= wxNB_MULTILINE; \
|
---|
| 373 | \
|
---|
| 374 | wxBookType *oldBook = newBook; \
|
---|
| 375 | \
|
---|
[1563] | 376 | newBook = new wxBookType(mPanel, idBook, \
|
---|
[1558] | 377 | wxDefaultPosition, wxDefaultSize, \
|
---|
| 378 | flags); \
|
---|
| 379 | \
|
---|
[1563] | 380 | if (mChkShowImages) \
|
---|
[1558] | 381 | { \
|
---|
[1563] | 382 | newBook->SetImageList(mImageList); \
|
---|
[1558] | 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 | \
|
---|
[1563] | 398 | mSizerFrame->Detach(oldBook); \
|
---|
[1558] | 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 | } \
|
---|
[1563] | 412 | \
|
---|
| 413 | mSizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, MARGIN); \
|
---|
| 414 | mSizerFrame->Hide(newBook); \
|
---|
[1558] | 415 | }
|
---|
| 416 |
|
---|
[1563] | 417 |
|
---|
[1558] | 418 | void MyFrame::RecreateBooks()
|
---|
| 419 | {
|
---|
| 420 | #if wxUSE_NOTEBOOK
|
---|
[1563] | 421 | RECREATE(wxNotebook, ID_NOTEBOOK, notebook, mNotebook);
|
---|
[1558] | 422 | #endif
|
---|
| 423 | #if wxUSE_LISTBOOK
|
---|
[1563] | 424 | // RECREATE(wxListbook, ID_LISTBOOK, listbook, mListbook);
|
---|
[1558] | 425 | #endif
|
---|
| 426 | #if wxUSE_CHOICEBOOK
|
---|
[1563] | 427 | RECREATE(wxChoicebook, ID_CHOICEBOOK, choicebook, mChoicebook);
|
---|
[1558] | 428 | #endif
|
---|
| 429 |
|
---|
| 430 | ShowCurrentBook();
|
---|
| 431 | }
|
---|
| 432 |
|
---|
[1563] | 433 |
|
---|
[1558] | 434 | wxBookCtrlBase *MyFrame::GetCurrentBook()
|
---|
| 435 | {
|
---|
[1563] | 436 | switch (mType)
|
---|
[1558] | 437 | {
|
---|
| 438 | #if wxUSE_NOTEBOOK
|
---|
[1563] | 439 | case ID_BOOK_NOTEBOOK: return mNotebook;
|
---|
[1558] | 440 | #endif
|
---|
| 441 | #if wxUSE_LISTBOOK
|
---|
[1563] | 442 | case ID_BOOK_LISTBOOK: return mListbook;
|
---|
[1558] | 443 | #endif
|
---|
| 444 | #if wxUSE_CHOICEBOOK
|
---|
[1563] | 445 | case ID_BOOK_CHOICEBOOK: return mChoicebook;
|
---|
[1558] | 446 | #endif
|
---|
| 447 | }
|
---|
| 448 | return NULL;
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | void MyFrame::ShowCurrentBook()
|
---|
| 452 | {
|
---|
[1563] | 453 | switch(mType)
|
---|
[1558] | 454 | {
|
---|
| 455 | #if wxUSE_NOTEBOOK
|
---|
[1563] | 456 | case ID_BOOK_NOTEBOOK:
|
---|
| 457 | if (mNotebook)
|
---|
| 458 | {
|
---|
| 459 | mSizerFrame->Show(mNotebook);
|
---|
| 460 | }
|
---|
| 461 |
|
---|
| 462 | break;
|
---|
[1558] | 463 | #endif
|
---|
| 464 | #if wxUSE_LISTBOOK
|
---|
[1563] | 465 | case ID_BOOK_LISTBOOK:
|
---|
| 466 | if (mListbook)
|
---|
| 467 | {
|
---|
| 468 | mSizerFrame->Show(mListbook);
|
---|
| 469 | break;
|
---|
| 470 | }
|
---|
[1558] | 471 | #endif
|
---|
| 472 | #if wxUSE_CHOICEBOOK
|
---|
[1563] | 473 | case ID_BOOK_CHOICEBOOK:
|
---|
| 474 | if (mChoicebook)
|
---|
| 475 | {
|
---|
| 476 | mSizerFrame->Show(mChoicebook);
|
---|
| 477 | break;
|
---|
| 478 | }
|
---|
[1558] | 479 | #endif
|
---|
| 480 | }
|
---|
| 481 |
|
---|
[1563] | 482 | mSizerFrame->Layout();
|
---|
[1558] | 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 |
|
---|
[1563] | 522 | mType = event.GetId();
|
---|
[1558] | 523 |
|
---|
| 524 | if (currBook)
|
---|
[1563] | 525 | mSizerFrame->Hide(currBook);
|
---|
[1558] | 526 |
|
---|
| 527 | ShowCurrentBook();
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | void MyFrame::OnOrient(wxCommandEvent& event)
|
---|
| 531 | {
|
---|
[1563] | 532 | mOrient = event.GetId();
|
---|
[1558] | 533 | RecreateBooks();
|
---|
[1563] | 534 | mSizerFrame->Layout();
|
---|
[1558] | 535 | }
|
---|
| 536 |
|
---|
| 537 | void MyFrame::OnShowImages(wxCommandEvent& event)
|
---|
| 538 | {
|
---|
[1563] | 539 | mChkShowImages = event.IsChecked();
|
---|
[1558] | 540 | RecreateBooks();
|
---|
[1563] | 541 | mSizerFrame->Layout();
|
---|
[1558] | 542 | }
|
---|
| 543 |
|
---|
| 544 | void MyFrame::OnMulti(wxCommandEvent& event)
|
---|
| 545 | {
|
---|
[1563] | 546 | mMulti = event.IsChecked();
|
---|
[1558] | 547 | RecreateBooks();
|
---|
[1563] | 548 | mSizerFrame->Layout();
|
---|
[1558] | 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 |
|
---|
[1563] | 563 | if (currBook)
|
---|
[1558] | 564 | {
|
---|
[1563] | 565 | wxPanel *panel = new wxPanel(currBook, wxID_ANY);
|
---|
| 566 |
|
---|
[1558] | 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 |
|
---|
[1563] | 572 | currBook->AddPage(
|
---|
| 573 | panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"),
|
---|
| 574 | ++ s_pageAdded), true, GetIconIndex(currBook) );
|
---|
[1558] | 575 | }
|
---|
| 576 | }
|
---|
| 577 |
|
---|
[1563] | 578 |
|
---|
[1558] | 579 | void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
|
---|
| 580 | {
|
---|
| 581 | static unsigned s_pageIns = 0;
|
---|
| 582 |
|
---|
| 583 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
| 584 |
|
---|
[1563] | 585 | if (currBook)
|
---|
[1558] | 586 | {
|
---|
[1563] | 587 | wxPanel *panel = CreateUserCreatedPage(currBook);
|
---|
[1558] | 588 |
|
---|
| 589 | currBook->InsertPage( 0, panel,
|
---|
[1563] | 590 | wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++ s_pageIns), false,
|
---|
[1558] | 591 | GetIconIndex(currBook) );
|
---|
| 592 |
|
---|
| 593 | currBook->SetSelection(0);
|
---|
| 594 | }
|
---|
| 595 | }
|
---|
| 596 |
|
---|
[1563] | 597 |
|
---|
[1558] | 598 | void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
|
---|
| 599 | {
|
---|
| 600 | wxBookCtrlBase *currBook = GetCurrentBook();
|
---|
| 601 |
|
---|
[1563] | 602 | if (currBook)
|
---|
[1558] | 603 | {
|
---|
[1563] | 604 | const int sel = currBook->GetSelection();
|
---|
[1558] | 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 | {
|
---|
[1563] | 619 | const int page = currBook->GetPageCount();
|
---|
[1558] | 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 |
|
---|
[1563] | 632 | if (currBook)
|
---|
[1558] | 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;
|
---|
[1563] | 662 | title.Printf(wxT("Preprocessor (%d pages, selection: %s)"), nPages, selection.c_str());
|
---|
[1558] | 663 |
|
---|
| 664 | SetTitle(title);
|
---|
| 665 | }
|
---|
| 666 | }
|
---|
| 667 |
|
---|
| 668 | #if USE_LOG
|
---|
[1563] | 669 | #define BOOKEVENT_LOG mText->SetInsertionPointEnd();
|
---|
[1558] | 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
|
---|