GtkEntry as Notebook tabname problem. Code attached.



Hi All,

First off I'm probably stretching the notebook api a bit. What I'm trying to
do is allow the user the ability to edit the tabname. So I though why not
use a gtkentry as the tabname, especially since its only requires a
gtkwidget! Seemed reasonable to me. Anyway, the problem is the entry does
not grab the cursor; doesn't change the cursor from an arrow to an 'I-bar'
cursor. But wait it gets better, if only one or two of several tabs are
showing the problem persists, as soon as those tabs are scrolled out of view
and new tabs are scrolled into view, the new tabs now accept input in the
entry. When the original tabs are later scrolled back into view, they also
have input control. Now everything is fine??? If all tabs are showing
initially, your out of luck, you can never get input control!

Anyone got any ideas?

--bruce

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

static GtkWidget *create_tabname(gint i)
{
    GtkWidget *hbox;
    GtkWidget *label;
    GtkWidget *entry;
    gchar name[32];

    hbox = gtk_hbox_new(FALSE, 0);
    {
        label = gtk_label_new("    ");
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);

        entry = gtk_entry_new();
        sprintf(name, "Foo #%d", i);
        gtk_entry_set_text(GTK_ENTRY(entry), name);
        gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
    }
    return hbox;
}

static gboolean on_window_delete (GtkWidget *widget, GtkWidget *event,
                                  gpointer data)
{
    gtk_main_quit();

    return FALSE;
}

gint main (gint argc, gchar **argv)
{
    GtkWidget *window, *vbox;
    GtkNotebook *notebook;
    GtkWidget *label;
    GtkWidget *tab_name;
    gint i;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Tab Test");
    gtk_window_set_default_size (GTK_WINDOW (window), 200, 100);
    gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);

    g_signal_connect (G_OBJECT (window), "delete_event",
                      G_CALLBACK (on_window_delete), NULL);

    vbox = gtk_vbox_new (FALSE, 0);

    notebook = GTK_NOTEBOOK (gtk_notebook_new ());
    gtk_notebook_set_tab_pos (notebook, GTK_POS_TOP);
    gtk_notebook_set_scrollable(notebook, TRUE);
    gtk_notebook_popup_enable(notebook);
    gtk_container_set_border_width (GTK_CONTAINER (notebook), 10);

    gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (notebook),
                        TRUE, TRUE, 0);

    gtk_container_add (GTK_CONTAINER (window), vbox);
    gtk_widget_show_all (GTK_WIDGET (window));

    for (i = 0; i < 7; i++)
    {
        label = gtk_label_new("doesn't matter what this is");
        tab_name = create_tabname(i);
        gtk_widget_show_all(tab_name);
        gtk_notebook_append_page (notebook, label, tab_name);
    }

    gtk_widget_show_all (GTK_WIDGET (notebook));

    gtk_main ();

    return 0;
}



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