[gtk+] gtk-demo: Make CSS a resource



commit 075b259321ce7696716c4a4254c476d31cdd08e1
Author: Benjamin Otte <otte redhat com>
Date:   Sun May 13 21:23:41 2012 +0200

    gtk-demo: Make CSS a resource
    
    Also, improve the CSS to give you that basic feel.

 demos/gtk-demo/Makefile.am             |   27 +++++++------
 demos/gtk-demo/css_basics.c            |   22 ++--------
 demos/gtk-demo/css_basics.css          |   22 ++++++++++
 demos/gtk-demo/demo.gresource.xml      |   12 ++++++
 demos/gtk-demo/reset.css               |   68 ++++++++++++++++++++++++++++++++
 demos/gtk-demo/theming_custom_css.c    |    9 ++--
 demos/gtk-demo/theming_style_classes.c |    5 +--
 7 files changed, 127 insertions(+), 38 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index 71a0f85..7ef52f7 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -76,13 +76,8 @@ BUILT_SOURCES = demos.h demo_resources.c
 EXTRA_DIST += 				\
 	$(IMAGEFILES)			\
 	demo.ui				\
-	demo.gresource.xml	\
-	application.ui			\
-	menus.ui			\
-	theming.ui			\
-	fancy.css			\
-	gtk-logo-24.png			\
-	gtk-logo-48.png			\
+	demo.gresource.xml		\
+	$(RESOURCES)			\
 	org.gtk.Demo.gschema.xml
 
 gsettings_SCHEMAS = \
@@ -110,9 +105,18 @@ gtk3_demo_application_SOURCES = \
 
 gtk3_demo_application_LDADD = $(LDADDS)
 
-demo_resources.c: demo.gresource.xml gtk-logo-24.png gtk-logo-48.png application.ui menus.ui
+demo_resources.c: demo.gresource.xml $(RESOURCES)
 	$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $(srcdir)/demo.gresource.xml
 
+RESOURCES=	application.ui			\
+		menus.ui			\
+		theming.ui			\
+		gtk-logo-24.png			\
+		gtk-logo-48.png			\
+		css_basics.css			\
+		fancy.css			\
+		reset.css
+
 IMAGEFILES=	alphatest.png		\
 		apple-red.png		\
 		background.jpg		\
@@ -131,11 +135,8 @@ IMAGEFILES=	alphatest.png		\
 democode_DATA = \
 	$(demos)		\
 	$(IMAGEFILES)		\
-	demo.ui			\
-	menus.ui		\
-	application.ui		\
-	theming.ui		\
-	fancy.css
+	$(RESOURCES)		\
+	demo.ui
 
 DISTCLEANFILES = demos.h
 
diff --git a/demos/gtk-demo/css_basics.c b/demos/gtk-demo/css_basics.c
index 0cbabbe..3eb5e3b 100644
--- a/demos/gtk-demo/css_basics.c
+++ b/demos/gtk-demo/css_basics.c
@@ -9,20 +9,6 @@
 
 static GtkWidget *window = NULL;
 
-#define DEFAULT_CSS \
-  "/* You can edit the CSS to change the appearance of this Window */\n" \
-  "\n" \
-  "GtkWindow {\n" \
-  "  engine: none;\n" \
-  "  background-image: none;\n" \
-  "  background-color: brown;\n" \
-  "}\n" \
-  "\n" \
-  "GtkTextView {\n" \
-  "  color: green;\n" \
-  "}\n" \
-  "\n"
-
 static void
 show_parsing_error (GtkCssProvider *provider,
                     GtkCssSection  *section,
@@ -83,6 +69,7 @@ do_css_basics (GtkWidget *do_widget)
       GtkWidget *container, *child;
       GtkStyleProvider *provider;
       GtkTextBuffer *text;
+      GBytes *bytes;
       
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
@@ -110,9 +97,10 @@ do_css_basics (GtkWidget *do_widget)
                         "changed",
                         G_CALLBACK (css_text_changed),
                         provider);
-      gtk_text_buffer_set_text (text,
-                                DEFAULT_CSS,
-                                -1);
+
+      bytes = g_resources_lookup_data ("/css_basics/gtk.css", 0, NULL);
+      gtk_text_buffer_set_text (text, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));
+
       g_signal_connect (provider,
                         "parsing-error",
                         G_CALLBACK (show_parsing_error),
diff --git a/demos/gtk-demo/css_basics.css b/demos/gtk-demo/css_basics.css
new file mode 100644
index 0000000..bd6a694
--- /dev/null
+++ b/demos/gtk-demo/css_basics.css
@@ -0,0 +1,22 @@
+/* You can edit the text in this window to change the
+ * appearance of this Window.
+ * Be careful, if you screw it up, nothing might be visible
+ * anymore. :)
+ */
+
+/* This CSS resets all properties to their defaults values
+ *    and overrides all user settings and the theme in use */
+ import url("reset.css");
+
+/* Set a very futuristic style by default */
+* {
+  color: green;
+  font-family: Monospace;
+  border: 1px solid;
+}
+
+/* Make sure selections are visible */
+:selected {
+  background-color: darkGreen;
+  color: black;
+}
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index d4a5aec..67aeff4 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -8,4 +8,16 @@
     <file preprocess="xml-stripblanks">application.ui</file>
     <file preprocess="xml-stripblanks">menus.ui</file>
   </gresource>
+  <gresource prefix="/">
+    <file>reset.css</file>
+  </gresource>
+  <gresource prefix="/css_basics">
+    <file alias="gtk.css">css_basics.css</file>
+  </gresource>
+  <gresource prefix="/theming_custom_css">
+    <file alias="gtk.css">fancy.css</file>
+  </gresource>
+  <gresource prefix="/theming_style_classes">
+    <file preprocess="xml-stripblanks">theming.ui</file>
+  </gresource>
 </gresources>
diff --git a/demos/gtk-demo/reset.css b/demos/gtk-demo/reset.css
new file mode 100644
index 0000000..1c27a8e
--- /dev/null
+++ b/demos/gtk-demo/reset.css
@@ -0,0 +1,68 @@
+/* @import this colorsheet to get the default values for every property.
+ * This is useful when writing special CSS tests that should not be
+ * inluenced by themes - not even the default ones.
+ * Keep in mind that the output will be very ugly and not look like
+ * anything GTK.
+ * Also, when adding new style properties, please add them here.
+ */
+
+* {
+  color: inherit;
+  font-size: inherit;
+  background-color: initial;
+  font-family: inherit;
+  font-style: inherit;
+  font-variant: inherit;
+  font-weight: inherit;
+  text-shadow: inherit;
+  icon-shadow: inherit;
+  box-shadow: initial;
+  margin-top: initial;
+  margin-left: initial;
+  margin-bottom: initial;
+  margin-right: initial;
+  padding-top: initial;
+  padding-left: initial;
+  padding-bottom: initial;
+  padding-right: initial;
+  border-top-style: initial;
+  border-top-width: initial;
+  border-left-style: initial;
+  border-left-width: initial;
+  border-bottom-style: initial;
+  border-bottom-width: initial;
+  border-right-style: initial;
+  border-right-width: initial;
+  border-top-left-radius: initial;
+  border-top-right-radius: initial;
+  border-bottom-right-radius: initial;
+  border-bottom-left-radius: initial;
+  outline-style: initial;
+  outline-width: initial;
+  outline-offset: initial;
+  background-clip: initial;
+  background-origin: initial;
+  background-size: initial;
+  background-position: initial;
+  border-top-color: initial;
+  border-right-color: initial;
+  border-bottom-color: initial;
+  border-left-color: initial;
+  outline-color:  initial;
+  background-repeat: initial;
+  background-image: initial;
+  border-image-source: initial;
+  border-image-repeat: initial;
+  border-image-slice: initial;
+  border-image-width: initial;
+  transition-property: initial;
+  transition-duration: initial;
+  transition-timing-function: initial;
+  transition-delay: initial;
+  engine: initial;
+  gtk-key-bindings: initial;
+
+  -GtkWidget-focus-line-width: 0;
+  -GtkWidget-focus-padding: 0;
+  -GtkNotebook-initial-gap: 0;
+}
diff --git a/demos/gtk-demo/theming_custom_css.c b/demos/gtk-demo/theming_custom_css.c
index 00cb22a..a1b9aea 100644
--- a/demos/gtk-demo/theming_custom_css.c
+++ b/demos/gtk-demo/theming_custom_css.c
@@ -20,7 +20,7 @@ do_theming_custom_css (GtkWidget *do_widget)
   GtkWidget *box;
   GtkWidget *button;
   GtkCssProvider *provider;
-  gchar *filename;
+  GBytes *bytes;
 
   if (!window)
     {
@@ -40,13 +40,14 @@ do_theming_custom_css (GtkWidget *do_widget)
       gtk_widget_set_name (button, "fancy");
 
       provider = gtk_css_provider_new ();
-      filename = demo_find_file ("fancy.css", NULL);
-      gtk_css_provider_load_from_path (provider, filename, NULL);
+      bytes = g_resources_lookup_data ("/theming_custom_css/gtk.css", 0, NULL);
+      gtk_css_provider_load_from_data (provider, g_bytes_get_data (bytes, NULL),
+                                       g_bytes_get_size (bytes), NULL);
       gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (do_widget),
                                                  GTK_STYLE_PROVIDER (provider),
                                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
       g_object_unref (provider);
-      g_free (filename);
+      g_bytes_unref (bytes);
 
       gtk_widget_show_all (box);
     }
diff --git a/demos/gtk-demo/theming_style_classes.c b/demos/gtk-demo/theming_style_classes.c
index 4377e2d..d089ece 100644
--- a/demos/gtk-demo/theming_style_classes.c
+++ b/demos/gtk-demo/theming_style_classes.c
@@ -18,7 +18,6 @@ do_theming_style_classes (GtkWidget *do_widget)
 {
   GtkWidget *grid;
   GtkBuilder *builder;
-  gchar *filename;
   GError *err = NULL;
 
   if (!window)
@@ -32,9 +31,7 @@ do_theming_style_classes (GtkWidget *do_widget)
                         G_CALLBACK (gtk_widget_destroyed), &window);
 
       builder = gtk_builder_new ();
-      filename = demo_find_file ("theming.ui", NULL);
-      gtk_builder_add_from_file (builder, filename, &err);
-      g_free (filename);
+      gtk_builder_add_from_resource (builder, "/theming_style_classes/theming.ui", NULL);
       if (err)
         {
           g_error ("ERROR: %s\n", err->message);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]