+static const char notebook_name[] = "123";
+
+typedef struct {
+ char *name;
+ GtkWidget *widget;
+ GtkWidget *box;
+ gulong delete_handler;
+ gulong destroy_handler;
+} notebook_data_t;
+
+static notebook_data_t nbd[2]; /* we rip at most two notebook pages off */
+
+static GtkNotebook *create_new_notebook_window(GtkNotebook *source,
+ GtkWidget *page,
+ gint x, gint y, gpointer data)
+{
+ GtkWidget *win, *notebook, *vbox;
+ notebook_data_t *nbdp;
+
+ /* pick the right notebook page data and return if both are detached */
+ if (nbd[0].widget == NULL)
+ nbdp = nbd;
+ else if (nbd[1].widget == NULL)
+ nbdp = nbd + 1;
+ else
+ return NULL;
+
+ nbdp->name = strdup(gtk_widget_get_name(page));
+ nbdp->widget = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(win), nbdp->name);
+ gtk_window_move(GTK_WINDOW(win), x, y);
+
+ /* Destroying the dive list will kill the application */
+ nbdp->delete_handler = g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
+ nbdp->destroy_handler = g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
+
+ nbdp->box = vbox = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(win), vbox);
+
+ notebook = gtk_notebook_new();
+ gtk_widget_set_name(notebook, nbdp->name);
+ gtk_notebook_set_group_name(GTK_NOTEBOOK(notebook), notebook_name);
+ gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 6);
+ gtk_widget_set_size_request(notebook, 450, 350);
+
+ gtk_widget_show_all(win);
+ return GTK_NOTEBOOK(notebook);
+}
+
+static void drag_cb(GtkWidget *widget, GdkDragContext *context,
+ gint x, gint y,
+ GtkSelectionData *selection_data,
+ guint info, guint time,
+ gpointer user_data)
+{
+ GtkWidget *source;
+ notebook_data_t *nbdp;
+
+ /*
+ * We don't actually really *use* this yet, but Dirk wants to
+ * do all the tabs as detatched tabs, and we'd need to use
+ * this all to figure out which window we're talking about.
+ */
+ source = gtk_drag_get_source_widget(context);
+ if (nbd[0].name && ! strcmp(nbd[0].name,gtk_widget_get_name(source)))
+ nbdp = nbd;
+ else if (nbd[1].name && ! strcmp(nbd[1].name,gtk_widget_get_name(source)))
+ nbdp = nbd + 1;
+ else
+ /* HU? */
+ return;
+
+ gtk_drag_finish(context, TRUE, TRUE, time);
+
+ /* we no longer need the widget - but getting rid of this is hard;
+ * remove the signal handler, remove the notebook from the box
+ * then destroy the widget (and clear out our data structure) */
+ g_signal_handler_disconnect(nbdp->widget,nbdp->delete_handler);
+ g_signal_handler_disconnect(nbdp->widget,nbdp->destroy_handler);
+ gtk_container_remove(GTK_CONTAINER(nbdp->box), source);
+ gtk_widget_destroy(nbdp->widget);
+ nbdp->widget = NULL;
+ free(nbdp->name);
+ nbdp->name = NULL;
+}
+