]> Pileus Git - ~andy/gtk/blob - demos/gtk-demo/theming_custom_css.c
gtk-demo: Remove file lists from demo data
[~andy/gtk] / demos / gtk-demo / theming_custom_css.c
1 /* CSS Theming/Custom CSS
2  *
3  * GTK+ uses CSS for theming. If required, applications can
4  * install their own custom CSS style provider to achieve
5  * special effects.
6  *
7  * Doing this has the downside that your application will no
8  * longer react to the users theme preferences, so this should
9  * be used sparingly.
10  */
11
12 #include <gtk/gtk.h>
13
14 static GtkWidget *window = NULL;
15
16 GtkWidget *
17 do_theming_custom_css (GtkWidget *do_widget)
18 {
19   GtkWidget *box;
20   GtkWidget *button;
21   GtkCssProvider *provider;
22   GBytes *bytes;
23
24   if (!window)
25     {
26       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
27       gtk_window_set_screen (GTK_WINDOW (window),
28                              gtk_widget_get_screen (do_widget));
29       gtk_window_set_title (GTK_WINDOW (window), "Custom CSS");
30       gtk_container_set_border_width (GTK_CONTAINER (window), 18);
31       g_signal_connect (window, "destroy",
32                         G_CALLBACK (gtk_widget_destroyed), &window);
33       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
34       gtk_container_add (GTK_CONTAINER (window), box);
35       button = gtk_button_new_with_label ("Plain");
36       gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
37       button = gtk_button_new_with_label ("Fancy");
38       gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
39       gtk_widget_set_name (button, "fancy");
40
41       provider = gtk_css_provider_new ();
42       bytes = g_resources_lookup_data ("/theming_custom_css/fancy.css", 0, NULL);
43       gtk_css_provider_load_from_data (provider, g_bytes_get_data (bytes, NULL),
44                                        g_bytes_get_size (bytes), NULL);
45       gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (do_widget),
46                                                  GTK_STYLE_PROVIDER (provider),
47                                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
48       g_object_unref (provider);
49       g_bytes_unref (bytes);
50
51       gtk_widget_show_all (box);
52     }
53
54   if (!gtk_widget_get_visible (window))
55     {
56       gtk_widget_show (window);
57     }
58   else
59     {
60       gtk_widget_destroy (window);
61       window = NULL;
62     }
63
64   return window;
65 }