#include #include /* Create a new hbox with an image and a label packed into it * and return the box. */ static GtkWidget *xpm_label_box( gchar *xpm_filename, gchar *label_text ) { GtkWidget *box; GtkWidget *label; GtkWidget *image; /* Create box for image and label */ box = gtk_vbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (box), 2); /* Now on to the image stuff */ image = gtk_image_new_from_file (xpm_filename); /* Create a label for the button */ label = gtk_label_new (label_text); GtkWidget * label2 = gtk_label_new (label_text); GtkWidget * image2 = gtk_image_new_from_stock (GTK_STOCK_PRINT, 32); /* Pack the image and label into the box */ gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 3); gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 3); gtk_box_pack_start (GTK_BOX (box), label2, FALSE, FALSE, 3); gtk_box_pack_start (GTK_BOX (box), image2, FALSE, FALSE, 3); gtk_widget_show (image); gtk_widget_show (image2); gtk_widget_show (label); gtk_widget_show (label2); gtk_widget_hide (label); gtk_widget_hide (label2); return box; } // GtkWidget *global_box; GSList * tmp_list; /* Our usual callback function */ static void callback( GtkWidget *widget, gpointer data ) { g_print ("Hello again - %s was pressed\n", (char *) data); // global_image ++; GtkWidget *global_box = gtk_bin_get_child(GTK_BIN (widget)); if (tmp_list != NULL) { char * id = tmp_list->data; GtkWidget * image = gtk_image_new_from_stock (id, 32); gtk_widget_show (image); gtk_box_pack_start (GTK_BOX (global_box), image, FALSE, FALSE, 3); tmp_list = g_slist_next (tmp_list); } } int main( int argc, char *argv[] ) { /* GtkWidget is the storage type for widgets */ GtkWidget *window; GtkWidget *button; GtkWidget *box; gtk_init (&argc, &argv); /* Create a new window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Pixmap'd Buttons!"); /* It's a good idea to do this for all windows. */ g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); /* Sets the border width of the window. */ gtk_container_set_border_width (GTK_CONTAINER (window), 10); GtkWidget * b = gtk_hbox_new(FALSE, 10); /* Create a new button */ button = gtk_button_new (); GtkWidget * button2 = gtk_button_new (); /* Connect the "clicked" signal of the button to our callback */ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (callback), (gpointer) "cool button"); g_signal_connect (G_OBJECT (button2), "clicked", G_CALLBACK (callback), (gpointer) "another button"); /* This calls our box creating function */ box = xpm_label_box ("info.xpm", "cool button"); // global_box = box; tmp_list = gtk_stock_list_ids (); /* Pack and show all our widgets */ gtk_widget_show (box); gtk_container_add (GTK_CONTAINER (button), box); box = xpm_label_box ("info.xpm", "ANOTHER button"); gtk_widget_show (box); gtk_container_add (GTK_CONTAINER (button2), box); gtk_widget_show (button); gtk_widget_show (button2); gtk_widget_show (b); gtk_container_add (GTK_CONTAINER (b), button); gtk_container_add (GTK_CONTAINER (b), button2); gtk_container_add (GTK_CONTAINER (window), b); gtk_widget_show (window); /* Rest in gtk_main and wait for the fun to begin! */ gtk_main (); return 0; }