From 29f538cea2cfcbb272ca724f8dbf778207530033 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 25 May 1999 10:40:07 +0000 Subject: [PATCH] Fixed a notebook crash and added more tests to sample. 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 | 1 + include/wx/gtk1/notebook.h | 1 + samples/notebook/test.cpp | 14 ++++++++++++-- samples/notebook/test.h | 2 ++ src/gtk/notebook.cpp | 14 +++++++++----- src/gtk/window.cpp | 2 +- src/gtk1/notebook.cpp | 14 +++++++++----- src/gtk1/window.cpp | 2 +- 8 files changed, 36 insertions(+), 14 deletions(-) diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index 13b3f0b009..8e88a74887 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -180,6 +180,7 @@ public: wxImageList* m_imageList; wxList m_pages; + int m_lastSelection; /* hack */ DECLARE_DYNAMIC_CLASS(wxNotebook) DECLARE_EVENT_TABLE() diff --git a/include/wx/gtk1/notebook.h b/include/wx/gtk1/notebook.h index 13b3f0b009..8e88a74887 100644 --- a/include/wx/gtk1/notebook.h +++ b/include/wx/gtk1/notebook.h @@ -180,6 +180,7 @@ public: wxImageList* m_imageList; wxList m_pages; + int m_lastSelection; /* hack */ DECLARE_DYNAMIC_CLASS(wxNotebook) DECLARE_EVENT_TABLE() diff --git a/samples/notebook/test.cpp b/samples/notebook/test.cpp index 4f3b57893f..2a60668983 100644 --- a/samples/notebook/test.cpp +++ b/samples/notebook/test.cpp @@ -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(); diff --git a/samples/notebook/test.h b/samples/notebook/test.h index dc40a24564..f9f482ecf8 100644 --- a/samples/notebook/test.h +++ b/samples/notebook/test.h @@ -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 diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 3de79f8445..6523a5a5cb 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -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; } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index f7059d2e7c..d43e0946b1 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -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; diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 3de79f8445..6523a5a5cb 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -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; } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index f7059d2e7c..d43e0946b1 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -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; -- 2.45.2