From: Vadim Zeitlin Date: Thu, 18 Jun 1998 16:59:18 +0000 (+0000) Subject: changed the notebook control to use AddPage() interface (Julian's version X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4bf58c62d243e1d04aaa4e8b67e72289284b4200 changed the notebook control to use AddPage() interface (Julian's version didn't work at all) andupdated the sample to work with it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@113 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index 4fb9d4b980..eebf0ba9ec 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -68,7 +68,7 @@ class wxNotebook: public wxControl void SetPadding( const wxSize& padding ); bool DeleteAllPages(void); bool DeletePage( const int page ); - bool AddPage( const int page, const wxString& text, wxWindow* win, const int imageId = -1, void* data = NULL ); + bool AddPage(wxWindow* win, const wxString& text, const int imageId = -1, void* data = NULL ); wxWindow *GetPageWindow( const int page ) const; // overriden to do nothing @@ -78,7 +78,6 @@ class wxNotebook: public wxControl wxImageList* m_imageList; wxList m_pages; - GtkWidget *m_frame; DECLARE_EVENT_TABLE() }; diff --git a/include/wx/gtk1/notebook.h b/include/wx/gtk1/notebook.h index 4fb9d4b980..eebf0ba9ec 100644 --- a/include/wx/gtk1/notebook.h +++ b/include/wx/gtk1/notebook.h @@ -68,7 +68,7 @@ class wxNotebook: public wxControl void SetPadding( const wxSize& padding ); bool DeleteAllPages(void); bool DeletePage( const int page ); - bool AddPage( const int page, const wxString& text, wxWindow* win, const int imageId = -1, void* data = NULL ); + bool AddPage(wxWindow* win, const wxString& text, const int imageId = -1, void* data = NULL ); wxWindow *GetPageWindow( const int page ) const; // overriden to do nothing @@ -78,7 +78,6 @@ class wxNotebook: public wxControl wxImageList* m_imageList; wxList m_pages; - GtkWidget *m_frame; DECLARE_EVENT_TABLE() }; diff --git a/samples/controls/minimal.cpp b/samples/controls/minimal.cpp index 1ad0899e58..29e220355b 100644 --- a/samples/controls/minimal.cpp +++ b/samples/controls/minimal.cpp @@ -162,21 +162,21 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : "think?" }; - wxPanel *panel = m_notebook->CreatePage( 0, "wxList" ); - + wxPanel *panel = new wxPanel(m_notebook); m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 9, choices ); (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(100,30) ); (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(300,30), wxSize(100,30) ); (void)new wxButton( panel, ID_LISTBOX_CLEAR, "Clear", wxPoint(180,80), wxSize(100,30) ); (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(300,80), wxSize(100,30) ); + m_notebook->AddPage(panel, "wxList"); - panel = m_notebook->CreatePage( 1, "wxChoice" ); - + panel = new wxPanel(m_notebook); m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 9, choices ); + m_notebook->AddPage(panel, "wxChoice"); - panel = m_notebook->CreatePage( 2, "wxComboBox" ); - + panel = new wxPanel(m_notebook); m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 9, choices ); + m_notebook->AddPage(panel, "wxComboBox"); } void MyPanel::OnSize( wxSizeEvent& WXUNUSED(event) ) diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 54ad8ca5ee..73fa4b76ec 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -16,6 +16,8 @@ #include "wx/panel.h" #include "wx/utils.h" #include "wx/imaglist.h" +#include "wx/intl.h" +#include "wx/log.h" //----------------------------------------------------------------------------- // wxNotebookPage @@ -30,9 +32,10 @@ class wxNotebookPage: public wxObject int m_image; void *m_clientData; GtkNotebookPage *m_page; + GtkLabel *m_label; wxWindow *m_clientPanel; - wxNotebookPage(void) + wxNotebookPage() { m_id = -1; m_text = ""; @@ -56,7 +59,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) wxNotebook::wxNotebook(void) { m_imageList = NULL; - m_frame = NULL; m_pages.DeleteContents( TRUE ); }; @@ -65,7 +67,6 @@ wxNotebook::wxNotebook( wxWindow *parent, const wxWindowID id, const long style, const wxString& name ) { m_imageList = NULL; - m_frame = NULL; m_pages.DeleteContents( TRUE ); Create( parent, id, pos, size, style, name ); }; @@ -144,7 +145,7 @@ int wxNotebook::GetPageImage( const int page ) const if (nb_page) return nb_page->m_image; else - return NULL; + return 0; }; void* wxNotebook::GetPageData( const int page ) const @@ -282,35 +283,36 @@ bool wxNotebook::DeletePage( const int page ) return TRUE; }; -bool wxNotebook::AddPage( const int item, const wxString &text, wxWindow* win, const int imageId, void* data ) +bool wxNotebook::AddPage(wxWindow* win, const wxString& text, const int imageId, void* data) { - wxNotebookPage *page = new wxNotebookPage; + // we've created the notebook page in AddChild(). Now we just have to set + // the caption for the page and set the others parameters. - page->m_text = text; - if (page->m_text.IsNull()) page->m_text = ""; - page->m_id = item; - page->m_image = imageId; - page->m_clientData = data; - - m_frame = gtk_label_new( page->m_text ); - gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, m_frame ); - - gtk_misc_set_alignment( GTK_MISC(m_frame), 0.0, 0.5 ); + // first, find the page + wxNotebookPage *page = NULL; - page->m_clientPanel = win; -// page->m_clientPanel = new wxPanel( this, -1, wxPoint(0,0), wxSize(100,100) ); - - m_frame = NULL; - - page->m_page = (GtkNotebookPage*)( g_list_last( GTK_NOTEBOOK(m_widget)->children )->data ); - - if (!page->m_page) + wxNode *node = m_pages.First(); + while (node) { - wxFatalError( "Notebook page creation error" ); - return FALSE; - } + page = (wxNotebookPage*)node->Data(); + if ( page->m_clientPanel == win ) + break; // found + node = node->Next(); + }; + + if ( page == NULL ) { + wxFAIL_MSG("Can't add a page whose parent is not the notebook!"); - m_pages.Append( page ); + return FALSE; + } + + // then set the attributes + page->m_text = text; + if ( page->m_text.IsEmpty() ) + page->m_text = ""; + page->m_image = imageId; + page->m_clientData = data; + gtk_label_set(page->m_label, page->m_text); return TRUE; }; @@ -325,9 +327,27 @@ wxWindow *wxNotebook::GetPageWindow( const int page ) const void wxNotebook::AddChild( wxWindow *win ) { - if (!m_frame) wxFatalError( "Notebook::Addchild() must not be called directly." ); + wxNotebookPage *page = new wxNotebookPage(); + + page->m_id = GetPageCount(); + page->m_label = (GtkLabel *)gtk_label_new("no caption"); + page->m_clientPanel = win; + gtk_notebook_append_page(GTK_NOTEBOOK(m_widget), win->m_widget, + (GtkWidget *)page->m_label); + gtk_misc_set_alignment(GTK_MISC(page->m_label), 0.0, 0.5); + + page->m_page = (GtkNotebookPage*) + ( + g_list_last(GTK_NOTEBOOK(m_widget)->children)->data + ); -// gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, m_frame ); + if (!page->m_page) + { + wxLogFatalError( "Notebook page creation error" ); + return; + } + + m_pages.Append( page ); }; //----------------------------------------------------------------------------- diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 54ad8ca5ee..73fa4b76ec 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -16,6 +16,8 @@ #include "wx/panel.h" #include "wx/utils.h" #include "wx/imaglist.h" +#include "wx/intl.h" +#include "wx/log.h" //----------------------------------------------------------------------------- // wxNotebookPage @@ -30,9 +32,10 @@ class wxNotebookPage: public wxObject int m_image; void *m_clientData; GtkNotebookPage *m_page; + GtkLabel *m_label; wxWindow *m_clientPanel; - wxNotebookPage(void) + wxNotebookPage() { m_id = -1; m_text = ""; @@ -56,7 +59,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl) wxNotebook::wxNotebook(void) { m_imageList = NULL; - m_frame = NULL; m_pages.DeleteContents( TRUE ); }; @@ -65,7 +67,6 @@ wxNotebook::wxNotebook( wxWindow *parent, const wxWindowID id, const long style, const wxString& name ) { m_imageList = NULL; - m_frame = NULL; m_pages.DeleteContents( TRUE ); Create( parent, id, pos, size, style, name ); }; @@ -144,7 +145,7 @@ int wxNotebook::GetPageImage( const int page ) const if (nb_page) return nb_page->m_image; else - return NULL; + return 0; }; void* wxNotebook::GetPageData( const int page ) const @@ -282,35 +283,36 @@ bool wxNotebook::DeletePage( const int page ) return TRUE; }; -bool wxNotebook::AddPage( const int item, const wxString &text, wxWindow* win, const int imageId, void* data ) +bool wxNotebook::AddPage(wxWindow* win, const wxString& text, const int imageId, void* data) { - wxNotebookPage *page = new wxNotebookPage; + // we've created the notebook page in AddChild(). Now we just have to set + // the caption for the page and set the others parameters. - page->m_text = text; - if (page->m_text.IsNull()) page->m_text = ""; - page->m_id = item; - page->m_image = imageId; - page->m_clientData = data; - - m_frame = gtk_label_new( page->m_text ); - gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, m_frame ); - - gtk_misc_set_alignment( GTK_MISC(m_frame), 0.0, 0.5 ); + // first, find the page + wxNotebookPage *page = NULL; - page->m_clientPanel = win; -// page->m_clientPanel = new wxPanel( this, -1, wxPoint(0,0), wxSize(100,100) ); - - m_frame = NULL; - - page->m_page = (GtkNotebookPage*)( g_list_last( GTK_NOTEBOOK(m_widget)->children )->data ); - - if (!page->m_page) + wxNode *node = m_pages.First(); + while (node) { - wxFatalError( "Notebook page creation error" ); - return FALSE; - } + page = (wxNotebookPage*)node->Data(); + if ( page->m_clientPanel == win ) + break; // found + node = node->Next(); + }; + + if ( page == NULL ) { + wxFAIL_MSG("Can't add a page whose parent is not the notebook!"); - m_pages.Append( page ); + return FALSE; + } + + // then set the attributes + page->m_text = text; + if ( page->m_text.IsEmpty() ) + page->m_text = ""; + page->m_image = imageId; + page->m_clientData = data; + gtk_label_set(page->m_label, page->m_text); return TRUE; }; @@ -325,9 +327,27 @@ wxWindow *wxNotebook::GetPageWindow( const int page ) const void wxNotebook::AddChild( wxWindow *win ) { - if (!m_frame) wxFatalError( "Notebook::Addchild() must not be called directly." ); + wxNotebookPage *page = new wxNotebookPage(); + + page->m_id = GetPageCount(); + page->m_label = (GtkLabel *)gtk_label_new("no caption"); + page->m_clientPanel = win; + gtk_notebook_append_page(GTK_NOTEBOOK(m_widget), win->m_widget, + (GtkWidget *)page->m_label); + gtk_misc_set_alignment(GTK_MISC(page->m_label), 0.0, 0.5); + + page->m_page = (GtkNotebookPage*) + ( + g_list_last(GTK_NOTEBOOK(m_widget)->children)->data + ); -// gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, m_frame ); + if (!page->m_page) + { + wxLogFatalError( "Notebook page creation error" ); + return; + } + + m_pages.Append( page ); }; //-----------------------------------------------------------------------------