]> git.saurik.com Git - wxWidgets.git/commitdiff
Fixed a notebook crash and added more tests to sample.
authorRobert Roebling <robert@roebling.de>
Tue, 25 May 1999 10:40:07 +0000 (10:40 +0000)
committerRobert Roebling <robert@roebling.de>
Tue, 25 May 1999 10:40:07 +0000 (10:40 +0000)
  Corrected size behaviour of default button.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2559 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/notebook.h
include/wx/gtk1/notebook.h
samples/notebook/test.cpp
samples/notebook/test.h
src/gtk/notebook.cpp
src/gtk/window.cpp
src/gtk1/notebook.cpp
src/gtk1/window.cpp

index 13b3f0b00994bbbeb8f0743bf9299061a5ebb9d4..8e88a74887d8e40b1c90f297cb4bacb50395d659 100644 (file)
@@ -180,6 +180,7 @@ public:
 
   wxImageList*    m_imageList;
   wxList          m_pages;
+  int             m_lastSelection;  /* hack */
 
   DECLARE_DYNAMIC_CLASS(wxNotebook)
   DECLARE_EVENT_TABLE()
index 13b3f0b00994bbbeb8f0743bf9299061a5ebb9d4..8e88a74887d8e40b1c90f297cb4bacb50395d659 100644 (file)
@@ -180,6 +180,7 @@ public:
 
   wxImageList*    m_imageList;
   wxList          m_pages;
+  int             m_lastSelection;  /* hack */
 
   DECLARE_DYNAMIC_CLASS(wxNotebook)
   DECLARE_EVENT_TABLE()
index 4f3b57893fec2303253d4c59551f13de6de84a9d..2a60668983390f7a2107fb652d5c9626f3ae0c4d 100644 (file)
@@ -58,7 +58,7 @@ bool MyApp::OnInit(void)
 void MyApp::InitTabView(wxNotebook* notebook, wxWindow* window)
 {
   m_okButton = new wxButton(window, wxID_OK, "Close", wxPoint(-1, -1), wxSize(80, 25));
-  m_cancelButton = new wxButton(window, wxID_CANCEL, "Cancel", wxPoint(-1, -1), wxSize(80, 25));
+  m_cancelButton = new wxButton(window, ID_DELETE_PAGE, "Delete page", wxPoint(-1, -1), wxSize(80, 25));
   m_addPageButton = new wxButton(window, ID_ADD_PAGE, "Add page", wxPoint(-1, -1), wxSize(80, 25));
   m_okButton->SetDefault();
 
@@ -108,6 +108,11 @@ void MyApp::InitTabView(wxNotebook* notebook, wxWindow* window)
   wxPanel *panel4 = new wxPanel(notebook, -1);
   panel4->SetBackgroundColour(wxColour("YELLOW"));
   notebook->AddPage(panel4, "Sheep");
+  
+  wxPanel *panel5 = new wxPanel(notebook, -1);
+  panel5->SetBackgroundColour(wxColour("MAGENTA"));
+  (void)new wxStaticText(panel5, -1, "This page has been inserted, not added", wxPoint(10, 10) );
+  notebook->InsertPage(0, panel5, "Sheep");
 }
 
 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
@@ -154,7 +159,7 @@ void MyDialog::Init(void)
 
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_BUTTON(wxID_OK, MyFrame::OnOK)
-    EVT_BUTTON(wxID_CANCEL, MyFrame::OnOK)
+    EVT_BUTTON(ID_DELETE_PAGE, MyFrame::OnDeletePage)
     EVT_BUTTON(ID_ADD_PAGE, MyFrame::OnAddPage)
     EVT_SIZE(MyFrame::OnSize)
 END_EVENT_TABLE()
@@ -176,6 +181,11 @@ void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
   m_notebook->SetSelection( m_notebook->GetPageCount()-1 );
 }
 
+void MyFrame::OnDeletePage(wxCommandEvent& WXUNUSED(event))
+{
+  m_notebook->DeletePage( m_notebook->GetPageCount()-1 );
+}
+
 void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) )
 {
     this->Destroy();
index dc40a2456497e52a14e1e09e8d386cdad7b64ea5..f9f482ecf8c97554996138b542046bc196d97d8f 100644 (file)
@@ -50,6 +50,7 @@ public:
     void OnOK(wxCommandEvent& event);
     void OnCloseWindow(wxCloseEvent& event);
     void OnAddPage(wxCommandEvent& event);
+    void OnDeletePage(wxCommandEvent& event);
     void OnSize(wxSizeEvent& event);
     void Init(void);
 protected:
@@ -78,4 +79,5 @@ DECLARE_EVENT_TABLE()
 
 #define ID_NOTEBOOK         1000
 #define ID_ADD_PAGE         1200
+#define ID_DELETE_PAGE      1201
 
index 3de79f8445cf7cc55947f9845942f29f9e97d15b..6523a5a5cb56bae9159e646ee8a4246dccff8f44 100644 (file)
@@ -184,6 +184,7 @@ void wxNotebook::Init()
 {
     m_imageList = (wxImageList *) NULL;
     m_pages.DeleteContents( TRUE );
+    m_lastSelection = -1;
 }
 
 wxNotebook::wxNotebook()
@@ -251,11 +252,9 @@ int wxNotebook::GetSelection() const
 
     GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
     
-    GtkNotebookPage *page = GTK_NOTEBOOK_PAGE( notebook->cur_page );
+    if (notebook->cur_page == NULL) return m_lastSelection;
     
-    wxCHECK_MSG( page, -1, "no notebook page selected/current" );
-
-    return g_list_index( pages, (gpointer)page );
+    return g_list_index( pages, (gpointer)(notebook->cur_page) );
 }
 
 int wxNotebook::GetPageCount() const
@@ -462,9 +461,14 @@ bool wxNotebook::DeletePage( int page )
     wxNotebookPage* nb_page = GetNotebookPage(page);
     if (!nb_page) return FALSE;
 
+    /* GTK sets GtkNotebook.cur_page to NULL before sending
+       the switvh page event */
+    m_lastSelection = GetSelection();
+    
     nb_page->m_client->Destroy();
-
     m_pages.DeleteObject( nb_page );
+    
+    m_lastSelection = -1;
 
     return TRUE;
 }
index f7059d2e7c44ad99bf57070d4b1816a0ddd8eb81..d43e0946b19039f4c3a7eda56d4baf154a4248f8 100644 (file)
@@ -1982,7 +1982,7 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
 
         int border = 0;
 
-        if (GTK_WIDGET_HAS_DEFAULT(m_widget))
+        if (GTK_WIDGET_CAN_DEFAULT(m_widget))
        {
            /* the default button has a border around it */
            border = 5;
index 3de79f8445cf7cc55947f9845942f29f9e97d15b..6523a5a5cb56bae9159e646ee8a4246dccff8f44 100644 (file)
@@ -184,6 +184,7 @@ void wxNotebook::Init()
 {
     m_imageList = (wxImageList *) NULL;
     m_pages.DeleteContents( TRUE );
+    m_lastSelection = -1;
 }
 
 wxNotebook::wxNotebook()
@@ -251,11 +252,9 @@ int wxNotebook::GetSelection() const
 
     GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
     
-    GtkNotebookPage *page = GTK_NOTEBOOK_PAGE( notebook->cur_page );
+    if (notebook->cur_page == NULL) return m_lastSelection;
     
-    wxCHECK_MSG( page, -1, "no notebook page selected/current" );
-
-    return g_list_index( pages, (gpointer)page );
+    return g_list_index( pages, (gpointer)(notebook->cur_page) );
 }
 
 int wxNotebook::GetPageCount() const
@@ -462,9 +461,14 @@ bool wxNotebook::DeletePage( int page )
     wxNotebookPage* nb_page = GetNotebookPage(page);
     if (!nb_page) return FALSE;
 
+    /* GTK sets GtkNotebook.cur_page to NULL before sending
+       the switvh page event */
+    m_lastSelection = GetSelection();
+    
     nb_page->m_client->Destroy();
-
     m_pages.DeleteObject( nb_page );
+    
+    m_lastSelection = -1;
 
     return TRUE;
 }
index f7059d2e7c44ad99bf57070d4b1816a0ddd8eb81..d43e0946b19039f4c3a7eda56d4baf154a4248f8 100644 (file)
@@ -1982,7 +1982,7 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
 
         int border = 0;
 
-        if (GTK_WIDGET_HAS_DEFAULT(m_widget))
+        if (GTK_WIDGET_CAN_DEFAULT(m_widget))
        {
            /* the default button has a border around it */
            border = 5;