+ wxASSERT_MSG( GetPageCount() == 0, _T("all pages must have been deleted") );
+
+ InvalidateBestSize();
+ return wxNotebookBase::DeleteAllPages();
+}
+
+wxNotebookPage *wxNotebook::DoRemovePage( size_t page )
+{
+ if ( m_selection != -1 && (size_t)m_selection >= page )
+ {
+ // the index will become invalid after the page is deleted
+ m_selection = -1;
+ }
+
+ wxNotebookPage *client = wxNotebookBase::DoRemovePage(page);
+ if ( !client )
+ return NULL;
+
+ gtk_widget_ref( client->m_widget );
+ gtk_widget_unrealize( client->m_widget );
+ gtk_widget_unparent( client->m_widget );
+
+ // gtk_notebook_remove_page() sends "switch_page" signal with some strange
+ // new page index (when deleting selected page 0, new page is 1 although,
+ // clearly, the selection should stay 0), so suppress this
+ gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
+ GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
+
+ gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page );
+
+ gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
+ GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer)this );
+
+ wxGtkNotebookPage* p = GetNotebookPage(page);
+ m_pagesData.DeleteObject(p);
+ delete p;
+
+ return client;
+}
+
+bool wxNotebook::InsertPage( size_t position,
+ wxNotebookPage* win,
+ const wxString& text,
+ bool select,
+ int imageId )
+{
+ wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid notebook") );
+
+ wxCHECK_MSG( win->GetParent() == this, FALSE,
+ wxT("Can't add a page whose parent is not the notebook!") );
+
+ wxCHECK_MSG( position <= GetPageCount(), FALSE,
+ _T("invalid page index in wxNotebookPage::InsertPage()") );
+
+ // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
+ // why this has to be done. NOTE: using gtk_widget_unparent here does not
+ // work as it seems to undo too much and will cause errors in the
+ // gtk_notebook_insert_page below, so instead just clear the parent by
+ // hand here.
+ win->m_widget->parent = NULL;
+
+ // don't receive switch page during addition
+ gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
+ GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), (gpointer) this );
+
+ if (m_themeEnabled)
+ win->SetThemeEnabled(TRUE);
+
+ GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
+
+ wxGtkNotebookPage *nb_page = new wxGtkNotebookPage();
+
+ if ( position == GetPageCount() )
+ m_pagesData.Append( nb_page );
+ else
+ m_pagesData.Insert( m_pagesData.Item( position ), nb_page );
+
+ m_pages.Insert(win, position);
+
+ nb_page->m_box = gtk_hbox_new( FALSE, 1 );
+ gtk_container_border_width( GTK_CONTAINER(nb_page->m_box), 2 );
+
+ gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate",
+ GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win );
+
+#ifndef __VMS
+ // On VMS position is unsigned and thus always positive
+ if (position < 0)
+ gtk_notebook_append_page( notebook, win->m_widget, nb_page->m_box );
+ else
+#endif
+ gtk_notebook_insert_page( notebook, win->m_widget, nb_page->m_box, position );
+
+ nb_page->m_page = (GtkNotebookPage*) g_list_last(notebook->children)->data;
+
+ /* set the label image */
+ nb_page->m_image = imageId;
+
+ if (imageId != -1)
+ {
+ wxASSERT( m_imageList != NULL );
+
+ const wxBitmap *bmp = m_imageList->GetBitmap(imageId);
+ GdkPixmap *pixmap = bmp->GetPixmap();
+ GdkBitmap *mask = (GdkBitmap*) NULL;
+ if ( bmp->GetMask() )
+ {
+ mask = bmp->GetMask()->GetBitmap();
+ }
+
+ GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, mask );
+
+ gtk_box_pack_start(GTK_BOX(nb_page->m_box), pixmapwid, FALSE, FALSE, m_padding);
+
+ gtk_widget_show(pixmapwid);
+ }
+
+ /* set the label text */
+
+ nb_page->m_text = text;
+ if (nb_page->m_text.IsEmpty()) nb_page->m_text = wxT("");
+
+ nb_page->m_label = GTK_LABEL( gtk_label_new(wxGTK_CONV(nb_page->m_text)) );
+ gtk_box_pack_end( GTK_BOX(nb_page->m_box), GTK_WIDGET(nb_page->m_label), FALSE, FALSE, m_padding );
+
+ /* apply current style */
+ GtkRcStyle *style = CreateWidgetStyle();
+ if ( style )
+ {
+ gtk_widget_modify_style(GTK_WIDGET(nb_page->m_label), style);
+ gtk_rc_style_unref(style);
+ }