]> Pileus Git - ~andy/gtk/blob - examples/pixmap/pixmap.c
minor fixes
[~andy/gtk] / examples / pixmap / pixmap.c
1
2 #include <gtk/gtk.h>
3
4
5 /* XPM data of Open-File icon */
6 static const char * xpm_data[] = {
7 "16 16 3 1",
8 "       c None",
9 ".      c #000000000000",
10 "X      c #FFFFFFFFFFFF",
11 "                ",
12 "   ......       ",
13 "   .XXX.X.      ",
14 "   .XXX.XX.     ",
15 "   .XXX.XXX.    ",
16 "   .XXX.....    ",
17 "   .XXXXXXX.    ",
18 "   .XXXXXXX.    ",
19 "   .XXXXXXX.    ",
20 "   .XXXXXXX.    ",
21 "   .XXXXXXX.    ",
22 "   .XXXXXXX.    ",
23 "   .XXXXXXX.    ",
24 "   .........    ",
25 "                ",
26 "                "};
27
28
29 /* when invoked (via signal delete_event), terminates the application.
30  */
31 gint close_application( GtkWidget *widget,
32                         GdkEvent  *event,
33                         gpointer   data )
34 {
35     gtk_main_quit ();
36     return FALSE;
37 }
38
39
40 /* is invoked when the button is clicked.  It just prints a message.
41  */
42 void button_clicked( GtkWidget *widget,
43                      gpointer   data ) {
44     g_print ("button clicked\n");
45 }
46
47 int main( int   argc,
48           char *argv[] )
49 {
50     /* GtkWidget is the storage type for widgets */
51     GtkWidget *window, *pixmapwid, *button;
52     GdkPixmap *pixmap;
53     GdkBitmap *mask;
54     GtkStyle *style;
55     
56     /* create the main window, and attach delete_event signal to terminating
57        the application */
58     gtk_init (&argc, &argv);
59     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
60     g_signal_connect (G_OBJECT (window), "delete_event",
61                       G_CALLBACK (close_application), NULL);
62     gtk_container_set_border_width (GTK_CONTAINER (window), 10);
63     gtk_widget_show (window);
64
65     /* now for the pixmap from gdk */
66     style = gtk_widget_get_style (window);
67     pixmap = gdk_pixmap_create_from_xpm_d (window->window,  &mask,
68                                            &style->bg[GTK_STATE_NORMAL],
69                                            (gchar **)xpm_data);
70
71     /* a pixmap widget to contain the pixmap */
72     pixmapwid = gtk_image_new_from_pixmap (pixmap, mask);
73     gtk_widget_show (pixmapwid);
74
75     /* a button to contain the pixmap widget */
76     button = gtk_button_new ();
77     gtk_container_add (GTK_CONTAINER (button), pixmapwid);
78     gtk_container_add (GTK_CONTAINER (window), button);
79     gtk_widget_show (button);
80
81     g_signal_connect (G_OBJECT (button), "clicked",
82                       G_CALLBACK (button_clicked), NULL);
83
84     /* show the window */
85     gtk_main ();
86           
87     return 0;
88 }