]> Pileus Git - ~andy/gtk/blob - demos/gtk-demo/theming_custom_css.c
Remove accidental commit that broke gtk3-demo
[~andy/gtk] / demos / gtk-demo / theming_custom_css.c
1 /* CSS Theming/Custom CSS :: fancy.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 #include "demo-common.h"
14
15 static GtkWidget *window = NULL;
16
17 GtkWidget *
18 do_theming_custom_css (GtkWidget *do_widget)
19 {
20   GtkWidget *box;
21   GtkWidget *button;
22   GtkCssProvider *provider;
23   GBytes *bytes;
24
25   if (!window)
26     {
27       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
28       gtk_window_set_screen (GTK_WINDOW (window),
29                              gtk_widget_get_screen (do_widget));
30       gtk_window_set_title (GTK_WINDOW (window), "Custom CSS");
31       gtk_container_set_border_width (GTK_CONTAINER (window), 18);
32       g_signal_connect (window, "destroy",
33                         G_CALLBACK (gtk_widget_destroyed), &window);
34       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
35       gtk_container_add (GTK_CONTAINER (window), box);
36       button = gtk_button_new_with_label ("Plain");
37       gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
38       button = gtk_button_new_with_label ("Fancy");
39       gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
40       gtk_widget_set_name (button, "fancy");
41
42       provider = gtk_css_provider_new ();
43       bytes = g_resources_lookup_data ("/theming_custom_css/gtk.css", 0, NULL);
44       gtk_css_provider_load_from_data (provider, g_bytes_get_data (bytes, NULL),
45                                        g_bytes_get_size (bytes), NULL);
46       gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (do_widget),
47                                                  GTK_STYLE_PROVIDER (provider),
48                                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
49       g_object_unref (provider);
50       g_bytes_unref (bytes);
51
52       gtk_widget_show_all (box);
53     }
54
55   if (!gtk_widget_get_visible (window))
56     {
57       gtk_widget_show (window);
58     }
59   else
60     {
61       gtk_widget_destroy (window);
62       window = NULL;
63     }
64
65   return window;
66 }