detaching a notebook tab



Hello all,

My app has a collection of objects which can be viewed either individually or in a tabbed viewer based on GtkNotebook. When objects are being viewed in the latter way, the user is supposed to be able to drag an object out of the tabbed viewer, with the effect of giving it its own window.

This works fine with gtk 2.24.28, but I'm getting a segfault with the same code on gtk 3.16.4. This looks like a gtk bug, but maybe I'm doing something wrong and before I file a report I'd be grateful if anyone could take a look at minimal test case below.

The idea is to start the program, switch to the second page in the notebook, and try dragging the tab onto the root window. With gtk3
I get a crash, preceded by the message

Gtk-CRITICAL **: gtk_widget_get_frame_clock: assertion 'GTK_IS_WIDGET (widget)' failed

Here's the minimal code:

#include <gtk/gtk.h>

/* Minimal test case for dragging a tab out of a
   notebook onto the root window

   Allin Cottrell <cottrell wfu edu>, 2015-07-06
*/

static GtkNotebook *detach_tab_callback (GtkNotebook *book,
                                         GtkWidget *page,
                                         gint x, gint y,
                                         gpointer data)
{
    GtkWidget *window;
    gint pgnum;

    g_object_ref(page);
    pgnum = gtk_notebook_page_num(GTK_NOTEBOOK(book), page);
    gtk_notebook_remove_page(GTK_NOTEBOOK(book), pgnum);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_add(GTK_CONTAINER(window), page);
    g_object_unref(page);

    gtk_widget_show_all(window);

    /* return NULL since we're not adding the detached
       tab to another GtkNotebook */

    return NULL;
}

int main (int argc, char **argv)
{
    GtkWidget *window, *notebook, *child;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "destroy",
                     gtk_main_quit, NULL);

    notebook = gtk_notebook_new();
    g_signal_connect(G_OBJECT(notebook), "create-window",
                     G_CALLBACK(detach_tab_callback), NULL);

    child = gtk_label_new("Content of first page");
    gtk_widget_set_size_request(child, -1, 100);
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), child, NULL);

    child = gtk_label_new("Content of second page");
    gtk_widget_set_size_request(child, -1, 100);
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), child, NULL);
    gtk_notebook_set_tab_detachable(GTK_NOTEBOOK(notebook),
                                    child, TRUE);

    gtk_container_add(GTK_CONTAINER(window), notebook);
    gtk_widget_show_all(window);

    gtk_main();

    return 0;
}

--
Allin Cottrell
Department of Economics
Wake Forest University, NC



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]