X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/53b28675492e387711489760dbfe08ba5086ce73..1f0299c17dc878540bf190c290392db241b425ad:/src/gtk1/notebook.cpp?ds=sidebyside diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 7ec169b526..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; - wxPanel *m_clientPanel; + 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 ); }; @@ -131,37 +132,32 @@ int wxNotebook::GetRowCount(void) const wxString wxNotebook::GetPageText( const int page ) const { - wxNotebookPage *nb_page = NULL; - - wxNode *node = m_pages.First(); - while (node) - { - nb_page = (wxNotebookPage*)node->Data(); - if (nb_page->m_id == page) break; - node = node->Next(); - }; - if (!node) return ""; - - return nb_page->m_text; + wxNotebookPage* nb_page = GetNotebookPage(page); + if (nb_page) + return nb_page->m_text; + else + return ""; }; int wxNotebook::GetPageImage( const int page ) const { - wxNotebookPage *nb_page = NULL; - - wxNode *node = m_pages.First(); - while (node) - { - nb_page = (wxNotebookPage*)node->Data(); - if (nb_page->m_id == page) break; - node = node->Next(); - }; - if (!node) return -1; - - return nb_page->m_image; + wxNotebookPage* nb_page = GetNotebookPage(page); + if (nb_page) + return nb_page->m_image; + else + return 0; }; void* wxNotebook::GetPageData( const int page ) const +{ + wxNotebookPage* nb_page = GetNotebookPage(page); + if (nb_page) + return nb_page->m_clientData; + else + return NULL; +}; + +wxNotebookPage* wxNotebook::GetNotebookPage(int page) const { wxNotebookPage *nb_page = NULL; @@ -173,22 +169,13 @@ void* wxNotebook::GetPageData( const int page ) const node = node->Next(); }; if (!node) return NULL; - - return nb_page->m_clientData; + return nb_page; }; int wxNotebook::SetSelection( const int page ) { - wxNotebookPage *nb_page = NULL; - - wxNode *node = m_pages.First(); - while (node) - { - nb_page = (wxNotebookPage*)node->Data(); - if (nb_page->m_id == page) break; - node = node->Next(); - }; - if (!node) return -1; + wxNotebookPage* nb_page = GetNotebookPage(page); + if (!nb_page) return -1; int page_num = 0; GList *child = GTK_NOTEBOOK(m_widget)->children; @@ -213,16 +200,8 @@ void wxNotebook::SetImageList( wxImageList* imageList ) bool wxNotebook::SetPageText( const int page, const wxString &text ) { - wxNotebookPage *nb_page = NULL; - - wxNode *node = m_pages.First(); - while (node) - { - nb_page = (wxNotebookPage*)node->Data(); - if (nb_page->m_id == page) break; - node = node->Next(); - }; - if (!node) return FALSE; + wxNotebookPage* nb_page = GetNotebookPage(page); + if (!nb_page) return FALSE; nb_page->m_text = text; @@ -233,16 +212,9 @@ bool wxNotebook::SetPageText( const int page, const wxString &text ) bool wxNotebook::SetPageImage( const int page, const int image ) { - wxNotebookPage *nb_page = NULL; - - wxNode *node = m_pages.First(); - while (node) - { - nb_page = (wxNotebookPage*)node->Data(); - if (nb_page->m_id == page) break; - node = node->Next(); - }; - if (!node) return FALSE; + wxNotebookPage* nb_page = GetNotebookPage(page); + if (!nb_page) + return FALSE; nb_page->m_image = image; @@ -253,17 +225,9 @@ bool wxNotebook::SetPageImage( const int page, const int image ) bool wxNotebook::SetPageData( const int page, void* data ) { - wxNotebookPage *nb_page = NULL; + wxNotebookPage* nb_page = GetNotebookPage(page); + if (!nb_page) return FALSE; - wxNode *node = m_pages.First(); - while (node) - { - nb_page = (wxNotebookPage*)node->Data(); - if (nb_page->m_id == page) break; - node = node->Next(); - }; - if (!node) return FALSE; - nb_page->m_clientData = data; return TRUE; @@ -295,16 +259,8 @@ bool wxNotebook::DeleteAllPages(void) bool wxNotebook::DeletePage( const int page ) { - wxNotebookPage *nb_page = NULL; - - wxNode *node = m_pages.First(); - while (node) - { - nb_page = (wxNotebookPage*)node->Data(); - if (nb_page->m_id == page) break; - node = node->Next(); - }; - if (!node) return FALSE; + wxNotebookPage* nb_page = GetNotebookPage(page); + if (!nb_page) return FALSE; int page_num = 0; GList *child = GTK_NOTEBOOK(m_widget)->children; @@ -314,61 +270,84 @@ bool wxNotebook::DeletePage( const int page ) page_num++; child = child->next; }; - - if (!child) wxFatalError( "Notebook delete error" );; + + wxASSERT( child ); + + delete nb_page->m_clientPanel; - gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num ); +// Amazingly, this is not necessary +// gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num ); m_pages.DeleteObject( nb_page ); return TRUE; }; -wxPanel *wxNotebook::CreatePage( const int item, const wxString &text, 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. + + // first, find the page + wxNotebookPage *page = NULL; + + wxNode *node = m_pages.First(); + while (node) + { + 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!"); + + return FALSE; + } + // then set the attributes page->m_text = text; - if (page->m_text.IsNull()) page->m_text = ""; - page->m_id = item; + if ( page->m_text.IsEmpty() ) + page->m_text = ""; page->m_image = imageId; page->m_clientData = data; - - m_frame = gtk_label_new( page->m_text ); - gtk_misc_set_alignment( GTK_MISC(m_frame), 0.0, 0.5 ); + gtk_label_set(page->m_label, page->m_text); - page->m_clientPanel = new wxPanel( this, -1, wxPoint(0,0), wxSize(100,100) ); - - m_frame = NULL; - - page->m_page = GTK_NOTEBOOK(m_widget)->cur_page; - - m_pages.Append( page ); - - return page->m_clientPanel; + return TRUE; }; -wxPanel *wxNotebook::GetPanel( const int page ) +wxWindow *wxNotebook::GetPageWindow( const int page ) const { - wxNotebookPage *nb_page = NULL; - - wxNode *node = m_pages.First(); - while (node) - { - nb_page = (wxNotebookPage*)node->Data(); - if (nb_page->m_id == page) break; - node = node->Next(); - }; - if (!node) return NULL; + wxNotebookPage* nb_page = GetNotebookPage(page); + if (!nb_page) return NULL; return nb_page->m_clientPanel; }; 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 ); }; //-----------------------------------------------------------------------------