- // 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 = (wxNotebookPage *) NULL;
-
- wxNode *node = m_pages.First();
- while (node)
- {
- page = (wxNotebookPage*)node->Data();
- if ( page->m_client == win )
- break; // found
- node = node->Next();
- }
-
- wxCHECK_MSG(page != NULL, FALSE,
- "Can't add a page whose parent is not the notebook!");
-
- // create the image if any
- if ( imageId != -1 ) {
- wxASSERT( m_imageList != NULL );
-
- wxBitmap *bmp = m_imageList->GetBitmap(imageId);
- GdkPixmap *pixmap = bmp->GetPixmap();
- GtkWidget *pixmapwid = gtk_pixmap_new (pixmap, NULL /* @@@@ */);
-
- gtk_box_pack_start(GTK_BOX(page->m_box), pixmapwid, FALSE, FALSE, 3);
-
- gtk_widget_show(pixmapwid);
- }
-
- // then set the attributes
- page->m_text = text;
- if ( page->m_text.IsEmpty() )
- page->m_text = "";
- page->m_image = imageId;
- page->m_label = (GtkLabel *)gtk_label_new(page->m_text);
- gtk_box_pack_start(GTK_BOX(page->m_box), (GtkWidget *)page->m_label,
- FALSE, FALSE, 3);
-
- // @@@: what does this do? do we still need it?
- // gtk_misc_set_alignment(GTK_MISC(page->m_label), 0.0, 0.5);
-
- gtk_widget_show((GtkWidget *)page->m_label);
-
- if ( bSelect ) {
- SetSelection(GetPageCount());
- }
-
- return TRUE;
+ 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;
+
+ if (m_themeEnabled)
+ win->SetThemeEnabled(true);
+
+ GtkNotebook *notebook = GTK_NOTEBOOK(m_widget);
+
+ wxGtkNotebookPage* pageData = new wxGtkNotebookPage;
+
+ m_pages.Insert(win, position);
+ m_pagesData.Insert(position, pageData);
+
+ // set the label image and text
+ // this must be done before adding the page, as GetPageText
+ // and GetPageImage will otherwise return wrong values in
+ // the page-changed event that results from inserting the
+ // first page.
+ pageData->m_imageIndex = imageId;
+
+ pageData->m_box = gtk_hbox_new(false, 1);
+ gtk_container_set_border_width(GTK_CONTAINER(pageData->m_box), 2);
+
+ pageData->m_image = NULL;
+ if (imageId != -1)
+ {
+ if (m_imageList)
+ {
+ const wxBitmap* bitmap = m_imageList->GetBitmapPtr(imageId);
+ pageData->m_image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf());
+ gtk_box_pack_start(GTK_BOX(pageData->m_box),
+ pageData->m_image, false, false, m_padding);
+ }
+ else
+ wxFAIL_MSG("invalid notebook imagelist");
+ }
+
+ /* set the label text */
+ pageData->m_label = gtk_label_new(wxGTK_CONV(wxStripMenuCodes(text)));
+ gtk_box_pack_end(GTK_BOX(pageData->m_box),
+ pageData->m_label, false, false, m_padding);
+
+ gtk_widget_show_all(pageData->m_box);
+ gtk_notebook_insert_page(notebook, win->m_widget, pageData->m_box, position);
+
+ /* apply current style */
+ GtkRcStyle *style = CreateWidgetStyle();
+ if ( style )
+ {
+ gtk_widget_modify_style(pageData->m_label, style);
+ gtk_rc_style_unref(style);
+ }
+
+ if (select && GetPageCount() > 1)
+ {
+ SetSelection( position );
+ }
+
+ InvalidateBestSize();
+ return true;