GtkNotebook "change-current-page" signal problems



Hello list,

I must be missing something obvious, but can someone please explain why 
the (complete) program below doesn't print a message saying the notebook 
page has changed when I switch between the two pages?

The program is listed below, thanks in advance for your comments.

/* To compile, for example:
 *   $ gcc -Wall -g change_page_cb.c -o change_page_cb `pkg-config --cflags gtk+-2.0` `pkg-config --libs 
gtk+-2.0`
 *
 */

#include <gtk/gtk.h>

static gboolean
delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    return FALSE;
}

static void destroy(GtkWidget *widget, gpointer data) 
{ gtk_main_quit(); }

/* Example signal handler for page changes */
static void
change_current_page_cb(GtkNotebook *nb, gint arg1, gpointer data)
{
    g_message("Current notebook page was changed\n");
}

int
main(int argc, char *argv[])
{
    GtkWidget *window, *notebook, *button1, *button2, *tab_label1, 
    *tab_label2;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);

    notebook = gtk_notebook_new();
    g_signal_connect(G_OBJECT(notebook), "change-current-page",
            G_CALLBACK(change_current_page_cb), NULL);

    /* Append a test page to the notebook */
    button1 = gtk_button_new_with_label("Press me");
    gtk_widget_show(button1);
    tab_label1 = gtk_label_new("button 1");
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), button1, 
        tab_label1);

    /* Append another test page to the notebook */
    button2 = gtk_button_new_with_label("Press me");
    gtk_widget_show(button2);
    tab_label2 = gtk_label_new("button 1");
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), button2, 
        tab_label2);

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

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

    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), 
        NULL);

    gtk_widget_show(window);

    gtk_main();
    return 0;
}

-- 
Rob van der Leek                  | rob(at)ricardis(dot)tudelft(dot)nl
Ricardishof 73-A                  | http://www.ricardis.tudelft.nl/~rob 
2614 JE Delft, The Netherlands     
+31 (0)6 155 244 60                



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