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