1 /* CSS Theming/Custom CSS :: fancy.css
3 * GTK+ uses CSS for theming. If required, applications can
4 * install their own custom CSS style provider to achieve
7 * Doing this has the downside that your application will no
8 * longer react to the users theme preferences, so this should
13 #include "demo-common.h"
15 static GtkWidget *window = NULL;
18 do_theming_custom_css (GtkWidget *do_widget)
22 GtkCssProvider *provider;
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");
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);
52 gtk_widget_show_all (box);
55 if (!gtk_widget_get_visible (window))
57 gtk_widget_show (window);
61 gtk_widget_destroy (window);