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