]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/notebook/notebook.cpp
disabled wxStackWalker and wxCrashReport for Win64
[wxWidgets.git] / samples / notebook / notebook.cpp
index 55faa391e65381173d902dcb5a0ab440c9ac4669..ad083b352e99d7d60dbddbfdefc5dfc04916603a 100644 (file)
 #include "wx/artprov.h"
 #include "notebook.h"
 
+#if !defined(__WXMSW__) && !defined(__WXPM__)
+    #include "../sample.xpm"
+#endif
+
 IMPLEMENT_APP(MyApp)
 
 bool MyApp::OnInit()
@@ -44,7 +48,7 @@ bool MyApp::OnInit()
     return true;
 }
 
-wxPanel *CreateUserCreatedPage(wxBookCtrl *parent)
+wxPanel *CreateUserCreatedPage(wxBookCtrlBase *parent)
 {
     wxPanel *panel = new wxPanel(parent);
 
@@ -54,7 +58,7 @@ wxPanel *CreateUserCreatedPage(wxBookCtrl *parent)
     return panel;
 }
 
-wxPanel *CreateRadioButtonsPage(wxBookCtrl *parent)
+wxPanel *CreateRadioButtonsPage(wxBookCtrlBase *parent)
 {
     wxPanel *panel = new wxPanel(parent);
 
@@ -79,7 +83,7 @@ wxPanel *CreateRadioButtonsPage(wxBookCtrl *parent)
     return panel;
 }
 
-wxPanel *CreateVetoPage(wxBookCtrl *parent)
+wxPanel *CreateVetoPage(wxBookCtrlBase *parent)
 {
     wxPanel *panel = new wxPanel(parent);
 
@@ -89,7 +93,7 @@ wxPanel *CreateVetoPage(wxBookCtrl *parent)
     return panel;
 }
 
-wxPanel *CreateBigButtonPage(wxBookCtrl *parent)
+wxPanel *CreateBigButtonPage(wxBookCtrlBase *parent)
 {
     wxPanel *panel = new wxPanel(parent);
 
@@ -103,7 +107,7 @@ wxPanel *CreateBigButtonPage(wxBookCtrl *parent)
 }
 
 
-wxPanel *CreateInsertPage(wxBookCtrl *parent)
+wxPanel *CreateInsertPage(wxBookCtrlBase *parent)
 {
     wxPanel *panel = new wxPanel(parent);
 
@@ -114,7 +118,7 @@ wxPanel *CreateInsertPage(wxBookCtrl *parent)
     return panel;
 }
 
-int GetIconIndex(wxBookCtrl* bookCtrl)
+int GetIconIndex(wxBookCtrlBase* bookCtrl)
 {
     if (bookCtrl && bookCtrl->GetImageList())
     {
@@ -128,7 +132,7 @@ int GetIconIndex(wxBookCtrl* bookCtrl)
     return -1;
 }
 
-void CreateInitialPages(wxBookCtrl *parent)
+void CreateInitialPages(wxBookCtrlBase *parent)
 {
     // Create and add some panels to the notebook
 
@@ -147,7 +151,7 @@ void CreateInitialPages(wxBookCtrl *parent)
     parent->SetSelection(1);
 }
 
-wxPanel *CreatePage(wxBookCtrl *parent, const wxString&pageName)
+wxPanel *CreatePage(wxBookCtrlBase *parent, const wxString&pageName)
 {
     if
     (
@@ -188,13 +192,23 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
                  long style)
     : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style)
 {
+#if wxUSE_NOTEBOOK
     m_type = ID_BOOK_NOTEBOOK;
+#elif wxUSE_CHOICEBOOK
+    m_type = ID_BOOK_CHOICEBOOK;
+#elif wxUSE_LISTBOOK
+    m_type = ID_BOOK_LISTBOOK;
+#elif
+    #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
+#endif
+
     m_orient = ID_ORIENT_DEFAULT;
     m_chkShowImages = true;
     m_multi = false;
 
-    // menu of the sample
+    SetIcon(wxICON(sample));
 
+    // menu of the sample
     wxMenu *menuType = new wxMenu;
 #if wxUSE_NOTEBOOK
     menuType->AppendRadioItem(ID_BOOK_NOTEBOOK,   wxT("&Notebook\tCtrl-1"));
@@ -205,6 +219,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
 #if wxUSE_CHOICEBOOK
     menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3"));
 #endif
+    menuType->Check(m_type, true);
 
     wxMenu *menuOrient = new wxMenu;
     menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tCtrl-4"));
@@ -214,17 +229,17 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
     menuOrient->AppendRadioItem(ID_ORIENT_RIGHT,   wxT("&Right\tCtrl-8"));
 
     wxMenu *menuDo = new wxMenu;
-    menuDo->Append(ID_ADD_PAGE, wxT("&Add page"));
-    menuDo->Append(ID_INSERT_PAGE, wxT("&Insert page"));
-    menuDo->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page"));
-    menuDo->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page"));
-    menuDo->Append(ID_NEXT_PAGE, wxT("&Next page"));
+    menuDo->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A"));
+    menuDo->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I"));
+    menuDo->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D"));
+    menuDo->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L"));
+    menuDo->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N"));
 
     wxMenu *menuFile = new wxMenu;
     menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control"));
     menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control"));
-    menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images"));
-    menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines"));
+    menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S"));
+    menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines\tAlt-M"));
     menuFile->AppendSeparator();
     menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application"));
     menuFile->Check(ID_SHOW_IMAGES, m_chkShowImages);
@@ -238,9 +253,15 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
     // books creation
 
     m_panel      = (wxPanel *)      NULL;
+#if wxUSE_NOTEBOOK
     m_notebook   = (wxNotebook *)   NULL;
+#endif
+#if wxUSE_CHOICEBOOK
     m_choicebook = (wxChoicebook *) NULL;
+#endif
+#if wxUSE_LISTBOOK
     m_listbook   = (wxListbook *)   NULL;
+#endif
 
     // create a dummy image list with a few icons
     wxSize imageSize(32, 32);
@@ -319,6 +340,12 @@ int MyFrame::SelectFlag(int id, int nb, int lb, int chb)
     return 0;
 }
 
+#ifdef __SMARTPHONE__
+    #define MARGIN 0
+#else
+    #define MARGIN 4
+#endif
+
 #define RECREATE( wxBookType , idBook, oldBook , newBook )                         \
 {                                                                                  \
     int flags;                                                                     \
@@ -384,42 +411,42 @@ int MyFrame::SelectFlag(int id, int nb, int lb, int chb)
     }                                                                              \
     else                                                                           \
     {                                                                              \
-        wxPanel *panel = CreateRadioButtonsPage(newBook);                          \
-        newBook->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(newBook) ); \
-                                                                                   \
-        panel = CreateVetoPage(newBook);                                           \
-        newBook->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(newBook) );   \
-                                                                                   \
-        panel = CreateBigButtonPage(newBook);                                      \
-        newBook->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(newBook) ); \
-                                                                                   \
-        panel = CreateInsertPage(newBook);                                         \
-        newBook->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(newBook) ); \
-                                                                                   \
-        newBook->SetSelection(1);                                                  \
+        CreateInitialPages(newBook);                                               \
     }                                                                              \
                                                                                    \
-    m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, 4);                      \
+    m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, MARGIN);                 \
                                                                                    \
     m_sizerFrame->Hide(newBook);                                                   \
 }
 
 void MyFrame::RecreateBooks()
 {
+#if wxUSE_NOTEBOOK
     RECREATE( wxNotebook   , ID_NOTEBOOK   , notebook   , m_notebook );
+#endif
+#if wxUSE_LISTBOOK
     RECREATE( wxListbook   , ID_LISTBOOK   , listbook   , m_listbook );
+#endif
+#if wxUSE_CHOICEBOOK
     RECREATE( wxChoicebook , ID_CHOICEBOOK , choicebook , m_choicebook );
+#endif
 
     ShowCurrentBook();
 }
 
-wxBookCtrl *MyFrame::GetCurrentBook()
+wxBookCtrlBase *MyFrame::GetCurrentBook()
 {
     switch (m_type)
     {
+#if wxUSE_NOTEBOOK
         case ID_BOOK_NOTEBOOK:   return m_notebook;
+#endif
+#if wxUSE_LISTBOOK
         case ID_BOOK_LISTBOOK:   return m_listbook;
+#endif
+#if wxUSE_CHOICEBOOK
         case ID_BOOK_CHOICEBOOK: return m_choicebook;
+#endif
     }
     return NULL;
 }
@@ -428,9 +455,15 @@ void MyFrame::ShowCurrentBook()
 {
     switch(m_type)
     {
+#if wxUSE_NOTEBOOK
         case ID_BOOK_NOTEBOOK:   if(m_notebook)   m_sizerFrame->Show(m_notebook);   break;
+#endif
+#if wxUSE_LISTBOOK
         case ID_BOOK_LISTBOOK:   if(m_listbook)   m_sizerFrame->Show(m_listbook);   break;
+#endif
+#if wxUSE_CHOICEBOOK
         case ID_BOOK_CHOICEBOOK: if(m_choicebook) m_sizerFrame->Show(m_choicebook); break;
+#endif
     }
 
     m_sizerFrame->Layout();
@@ -452,12 +485,18 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
 
     // Book controls
+#if wxUSE_NOTEBOOK
     EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook)
     EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook)
+#endif
+#if wxUSE_LISTBOOK
     EVT_LISTBOOK_PAGE_CHANGED(ID_LISTBOOK, MyFrame::OnListbook)
     EVT_LISTBOOK_PAGE_CHANGING(ID_LISTBOOK, MyFrame::OnListbook)
+#endif
+#if wxUSE_CHOICEBOOK
     EVT_CHOICEBOOK_PAGE_CHANGED(ID_CHOICEBOOK, MyFrame::OnChoicebook)
     EVT_CHOICEBOOK_PAGE_CHANGING(ID_CHOICEBOOK, MyFrame::OnChoicebook)
+#endif
 
     // Update title in idle time
     EVT_IDLE(MyFrame::OnIdle)
@@ -465,7 +504,7 @@ END_EVENT_TABLE()
 
 void MyFrame::OnType(wxCommandEvent& event)
 {
-    wxBookCtrl *currBook = GetCurrentBook();
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
     m_type = event.GetId();
 
@@ -506,7 +545,7 @@ void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
 {
     static unsigned s_pageAdded = 0;
 
-    wxBookCtrl *currBook = GetCurrentBook();
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
     if ( currBook )
     {
@@ -525,7 +564,7 @@ void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
 {
     static unsigned s_pageIns = 0;
 
-    wxBookCtrl *currBook = GetCurrentBook();
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
     if ( currBook )
     {
@@ -541,7 +580,7 @@ void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
 {
-    wxBookCtrl *currBook = GetCurrentBook();
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
     if ( currBook )
     {
@@ -556,7 +595,7 @@ void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event))
 {
-    wxBookCtrl *currBook = GetCurrentBook();
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
     if ( currBook )
     {
@@ -571,7 +610,7 @@ void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event))
 {
-    wxBookCtrl *currBook = GetCurrentBook();
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
     if ( currBook )
     {
@@ -583,9 +622,9 @@ void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
 {
     static int s_nPages = wxNOT_FOUND;
     static int s_nSel = wxNOT_FOUND;
-    static wxBookCtrl *s_currBook = NULL;
+    static wxBookCtrlBase *s_currBook = NULL;
 
-    wxBookCtrl *currBook = GetCurrentBook();
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
     int nPages = currBook ? currBook->GetPageCount() : 0;
     int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND;
@@ -609,6 +648,12 @@ void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
     }
 }
 
+#if USE_LOG
+    #define BOOKEVENT_LOG m_text->SetInsertionPointEnd();
+#else
+    #define BOOKEVENT_LOG
+#endif
+
 #define BOOKEVENT(OnBook,wxBookEvent,bookStr,wxEVT_PAGE_CHANGED,wxEVT_PAGE_CHANGING,s_num) \
 void MyFrame::OnBook(wxBookEvent& event)                                                   \
 {                                                                                          \
@@ -625,7 +670,7 @@ void MyFrame::OnBook(wxBookEvent& event)
     else if (eventType == wxEVT_PAGE_CHANGING)                                             \
     {                                                                                      \
         int idx = event.GetOldSelection();                                                 \
-        wxBookCtrl *book = (wxBookCtrl *)event.GetEventObject();                           \
+        wxBookCtrlBase *book = (wxBookCtrlBase *)event.GetEventObject();                   \
         if ( idx != wxNOT_FOUND && book && book->GetPageText(idx) == VETO_PAGE_NAME )      \
         {                                                                                  \
             if                                                                             \
@@ -637,8 +682,6 @@ void MyFrame::OnBook(wxBookEvent& event)
                           wxICON_QUESTION | wxYES_NO, this) != wxYES )                     \
             {                                                                              \
                 event.Veto();                                                              \
-                                                                                           \
-                return;                                                                    \
             }                                                                              \
                                                                                            \
         }                                                                                  \
@@ -655,11 +698,15 @@ void MyFrame::OnBook(wxBookEvent& event)
                                                                                            \
     wxLogMessage(logMsg.c_str());                                                          \
                                                                                            \
-    m_text->SetInsertionPointEnd();                                                        \
-                                                                                           \
-    event.Skip();                                                                          \
+    BOOKEVENT_LOG                                                                          \
 }
 
+#if wxUSE_NOTEBOOK
 BOOKEVENT(OnNotebook,wxNotebookEvent,"wxNotebook",wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,s_numNotebookEvents)
+#endif
+#if wxUSE_CHOICEBOOK
 BOOKEVENT(OnChoicebook,wxChoicebookEvent,"wxChoicebook",wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,s_numChoicebookEvents)
+#endif
+#if wxUSE_LISTBOOK
 BOOKEVENT(OnListbook,wxListbookEvent,"wxListbook",wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,s_numListbookEvents)
+#endif