X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cb43b372fb1567caf7ccfa523aca10c676ceaec4..3dd4e4e05cc46ffc653730715e527af7b18b9caf:/src/gtk/notebook.cpp diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index d9b2bbc090..feb8c042c5 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -2,9 +2,8 @@ // Name: notebook.cpp // Purpose: // Author: Robert Roebling -// Created: 01/02/97 -// Id: -// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem +// Id: $Id$ +// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -37,7 +36,6 @@ public: m_box = (GtkWidget *) NULL; } -//private: int m_id; wxString m_text; int m_image; @@ -88,6 +86,40 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); } +//----------------------------------------------------------------------------- +// InsertChild callback for wxNotebook +//----------------------------------------------------------------------------- + +static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child ) +{ + wxNotebookPage *page = new wxNotebookPage(); + + page->m_id = parent->GetPageCount(); + + page->m_box = gtk_hbox_new (FALSE, 0); + gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); + + GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); + + page->m_client = child; + gtk_notebook_append_page( notebook, child->m_widget, page->m_box ); + + page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); + + page->m_parent = notebook; + + gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); + + if (!page->m_page) + { + wxLogFatalError( "Notebook page creation error" ); + return; + } + + parent->m_pages.Append( page ); +} + //----------------------------------------------------------------------------- // wxNotebook //----------------------------------------------------------------------------- @@ -128,6 +160,7 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name ) { m_needParent = TRUE; + m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; PreCreation( parent, id, pos, size, style, name ); @@ -142,6 +175,10 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, (gpointer)this ); + m_parent->AddChild( this ); + + (m_parent->m_insertCallback)( m_parent, this ); + PostCreation(); Show( TRUE ); @@ -151,6 +188,8 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, int wxNotebook::GetSelection() const { + wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" ); + if (m_pages.Number() == 0) return -1; GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page; @@ -183,6 +222,8 @@ int wxNotebook::GetRowCount() const wxString wxNotebook::GetPageText( int page ) const { + wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" ); + wxNotebookPage* nb_page = GetNotebookPage(page); if (nb_page) return nb_page->m_text; @@ -192,6 +233,8 @@ wxString wxNotebook::GetPageText( int page ) const int wxNotebook::GetPageImage( int page ) const { + wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" ); + wxNotebookPage* nb_page = GetNotebookPage(page); if (nb_page) return nb_page->m_image; @@ -201,6 +244,8 @@ int wxNotebook::GetPageImage( int page ) const wxNotebookPage* wxNotebook::GetNotebookPage(int page) const { + wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" ); + wxNotebookPage *nb_page = (wxNotebookPage *) NULL; wxNode *node = m_pages.First(); @@ -219,6 +264,8 @@ wxNotebookPage* wxNotebook::GetNotebookPage(int page) const int wxNotebook::SetSelection( int page ) { + wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" ); + int selOld = GetSelection(); wxNotebookPage* nb_page = GetNotebookPage(page); @@ -242,6 +289,8 @@ int wxNotebook::SetSelection( int page ) void wxNotebook::AdvanceSelection( bool bForward ) { + wxCHECK_RET( m_widget != NULL, "invalid notebook" ); + int sel = GetSelection(); int max = GetPageCount(); @@ -258,6 +307,8 @@ void wxNotebook::SetImageList( wxImageList* imageList ) bool wxNotebook::SetPageText( int page, const wxString &text ) { + wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" ); + wxNotebookPage* nb_page = GetNotebookPage(page); if (!nb_page) return FALSE; @@ -290,6 +341,8 @@ void wxNotebook::SetPadding( const wxSize &WXUNUSED(padding) ) bool wxNotebook::DeleteAllPages() { + wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" ); + wxNode *page_node = m_pages.First(); while (page_node) { @@ -332,6 +385,8 @@ bool wxNotebook::DeletePage( int page ) bool wxNotebook::AddPage(wxWindow* win, const wxString& text, bool bSelect, int imageId) { + wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" ); + // we've created the notebook page in AddChild(). Now we just have to set // the caption for the page and set the others parameters. @@ -351,10 +406,14 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text, { wxASSERT( m_imageList != NULL ); - wxBitmap *bmp = m_imageList->GetBitmap(imageId); + const wxBitmap *bmp = m_imageList->GetBitmap(imageId); GdkPixmap *pixmap = bmp->GetPixmap(); GdkBitmap *mask = (GdkBitmap*) NULL; - if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap(); + if ( bmp->GetMask() ) + { + mask = bmp->GetMask()->GetBitmap(); + } + GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask ); gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3); @@ -381,6 +440,8 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text, wxWindow *wxNotebook::GetPage( int page ) const { + wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" ); + wxNotebookPage* nb_page = GetNotebookPage(page); if (!nb_page) return (wxWindow *) NULL; @@ -388,37 +449,6 @@ wxWindow *wxNotebook::GetPage( int page ) const return nb_page->m_client; } -void wxNotebook::AddChild( wxWindow *win ) -{ - m_children.Append(win); - - wxNotebookPage *page = new wxNotebookPage(); - - page->m_id = GetPageCount(); - - page->m_box = gtk_hbox_new (FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); - - page->m_client = win; - gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, page->m_box ); - - page->m_page = - (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); - - page->m_parent = GTK_NOTEBOOK(m_widget); - - gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win ); - - if (!page->m_page) - { - wxLogFatalError( "Notebook page creation error" ); - return; - } - - m_pages.Append( page ); -} - // override these 2 functions to do nothing: everything is done in OnSize void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) { @@ -431,6 +461,12 @@ bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) return TRUE; } +void wxNotebook::ApplyWidgetStyle() +{ + SetWidgetStyle(); + gtk_widget_set_style( m_widget, m_widgetStyle ); +} + //----------------------------------------------------------------------------- // wxNotebookEvent //-----------------------------------------------------------------------------