Re: GtkExpander label widgets (using buttons as)



David Caldwell <david <at> porkrind.org> writes:

Tristan Van Berkom <tristan.van.berkom <at> gmail.com> writes:

David Caldwell wrote:

I have a GtkExpander and I set its label widget to an hbox to
which I added a label and 2 buttons. They all display nicely, but
the buttons don't work properly.

Can you reproduce this misbehaviour in a brief code segment and post
it ?

My last snippet was perhaps too snipped. Here is a complete program you should
just be able to compile up and test.

// -*- compile-command: "cc -g -std=gnu99 `pkg-config gtk+-2.0 --cflags --libs`
-o test test.c" -*-

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

void clicked(GtkButton *button, void *which)
{
    printf("%s clicked\n", which);
}

int main(int argc, char **argv)
{
    gtk_init (&argc, &argv); // could technically do autolist_add(main_init,
gtk_init); but it wouldnt buy me anything

    GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    GtkWidget *vbox1 = gtk_vbox_new (FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), vbox1);

    GtkWidget *expander = gtk_expander_new(NULL);
    gtk_expander_set_expanded(GTK_EXPANDER(expander), TRUE);
    gtk_box_pack_start(GTK_BOX(vbox1), expander, FALSE, FALSE, 0);

    GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
    gtk_expander_set_label_widget(GTK_EXPANDER(expander), hbox);

    GtkLabel *label = GTK_LABEL(gtk_label_new("The Label"));
    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), TRUE, TRUE, 0);
    gtk_widget_set_sensitive(GTK_WIDGET(label), TRUE);

    GtkWidget *edit_button = gtk_button_new_with_mnemonic("Edit");
    gtk_box_pack_start(GTK_BOX(hbox), edit_button, FALSE, FALSE, 0);
    gtk_widget_set_sensitive(edit_button, TRUE);
    g_signal_connect(edit_button, "clicked",
                     G_CALLBACK(clicked), 
                     (gpointer)"Edit");

    GtkWidget *delete_button = gtk_button_new_with_mnemonic("Delete");
    gtk_box_pack_start(GTK_BOX(hbox), delete_button, FALSE, FALSE, 0);
    gtk_widget_set_sensitive(delete_button, TRUE);
    g_signal_connect(delete_button, "clicked",
                     G_CALLBACK(clicked), 
                     (gpointer)"Delete");

    GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(expander), vbox);
    // ... put some junk in the vbox

    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}





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