1 /* This file extracted from the GTK tutorial. */
7 /* create a new hbox with an image and a label packed into it
8 * and return the box.. */
10 GtkWidget *xpm_label_box (GtkWidget *parent, gchar *xpm_filename, gchar *label_text)
19 /* create box for xpm and label */
20 box1 = gtk_hbox_new (FALSE, 0);
21 gtk_container_border_width (GTK_CONTAINER (box1), 2);
23 /* get style of button.. I assume it's to get the background color.
24 * if someone knows the real reason, please enlighten me. */
25 style = gtk_widget_get_style(parent);
27 /* now on to the xpm stuff.. load xpm */
28 pixmap = gdk_pixmap_create_from_xpm (parent->window, &mask,
29 &style->bg[GTK_STATE_NORMAL],
31 pixmapwid = gtk_pixmap_new (pixmap, mask);
33 /* create label for button */
34 label = gtk_label_new (label_text);
36 /* pack the pixmap and label into the box */
37 gtk_box_pack_start (GTK_BOX (box1),
38 pixmapwid, FALSE, FALSE, 3);
40 gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 3);
42 gtk_widget_show(pixmapwid);
43 gtk_widget_show(label);
48 /* our usual callback function */
49 void callback (GtkWidget *widget, gpointer data)
51 g_print ("Hello again - %s was pressed\n", (char *) data);
55 int main (int argc, char *argv[])
57 /* GtkWidget is the storage type for widgets */
62 gtk_init (&argc, &argv);
64 /* create a new window */
65 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
67 gtk_window_set_title (GTK_WINDOW (window), "Pixmap'd Buttons!");
69 /* It's a good idea to do this for all windows. */
70 gtk_signal_connect (GTK_OBJECT (window), "destroy",
71 GTK_SIGNAL_FUNC (gtk_exit), NULL);
73 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
74 GTK_SIGNAL_FUNC (gtk_exit), NULL);
77 /* sets the border width of the window. */
78 gtk_container_border_width (GTK_CONTAINER (window), 10);
79 gtk_widget_realize(window);
81 /* create a new button */
82 button = gtk_button_new ();
84 /* You should be getting used to seeing most of these functions by now */
85 gtk_signal_connect (GTK_OBJECT (button), "clicked",
86 GTK_SIGNAL_FUNC (callback), (gpointer) "cool button");
88 /* this calls our box creating function */
89 box1 = xpm_label_box(window, "info.xpm", "cool button");
91 /* pack and show all our widgets */
92 gtk_widget_show(box1);
94 gtk_container_add (GTK_CONTAINER (button), box1);
96 gtk_widget_show(button);
98 gtk_container_add (GTK_CONTAINER (window), button);
100 gtk_widget_show (window);
102 /* rest in gtk_main and wait for the fun to begin! */