[gtk+/gtk-style-context: 368/490] Make testgtk load CSS for custom styling.



commit 026e39cc48f74fb25759e86a7302de027cd662ff
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Nov 13 21:19:41 2010 +0100

    Make testgtk load CSS for custom styling.

 tests/Makefile.am  |    4 +-
 tests/testgtk.c    |   46 +++++++----
 tests/testgtk.css  |   33 ++++++++
 tests/testgtk2.css |    9 ++
 tests/testgtkrc    |  228 ----------------------------------------------------
 tests/testgtkrc2   |   21 -----
 6 files changed, 73 insertions(+), 268 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 83b70a5..a567c3a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -385,8 +385,8 @@ testexpander_SOURCES = testexpander.c
 EXTRA_DIST += 			\
 	prop-editor.h		\
 	testgtk.1 		\
-	testgtkrc 		\
-	testgtkrc2 		\
+	testgtk.css		\
+	testgtk2.css		\
 	3DRings.xpm		\
 	FilesQueue.xpm		\
 	Modeller.xpm		\
diff --git a/tests/testgtk.c b/tests/testgtk.c
index dc50da0..3372656 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -10054,7 +10054,7 @@ create_main_window (void)
   int i;
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-  gtk_widget_set_name (window, "main window");
+  gtk_widget_set_name (window, "main_window");
   gtk_window_move (GTK_WINDOW (window), 50, 20);
   gtk_window_set_default_size (GTK_WINDOW (window), -1, 400);
 
@@ -10257,6 +10257,9 @@ usage (void)
 int
 main (int argc, char *argv[])
 {
+  GtkCssProvider *provider, *memory_provider;
+  GdkDisplay *display;
+  GdkScreen *screen;
   GtkBindingSet *binding_set;
   int i;
   gboolean done_benchmarks = FALSE;
@@ -10265,19 +10268,28 @@ main (int argc, char *argv[])
 
   test_init ();
 
+  g_set_application_name ("GTK+ Test Program");
+
+  gtk_init (&argc, &argv);
+
+  provider = gtk_css_provider_new ();
+
   /* Check to see if we are being run from the correct
    * directory.
    */
-  if (file_exists ("testgtkrc"))
-    gtk_rc_add_default_file ("testgtkrc");
+  if (file_exists ("testgtk.css"))
+    gtk_css_provider_load_from_path (provider, "testgtk.css", NULL);
   else if (file_exists ("tests/testgtkrc"))
-    gtk_rc_add_default_file ("tests/testgtkrc");
+    gtk_css_provider_load_from_path (provider, "tests/testgtk.css", NULL);
   else
-    g_warning ("Couldn't find file \"testgtkrc\".");
+    g_warning ("Couldn't find file \"testgtk.css\".");
 
-  g_set_application_name ("GTK+ Test Program");
+  display = gdk_display_get_default ();
+  screen = gdk_display_get_default_screen (display);
 
-  gtk_init (&argc, &argv);
+  gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+  g_object_unref (provider);
 
   gtk_accelerator_set_default_mod_mask (GDK_SHIFT_MASK |
 					GDK_CONTROL_MASK |
@@ -10337,17 +10349,17 @@ main (int argc, char *argv[])
 				"debug_msg",
 				1,
 				G_TYPE_STRING, "GtkWidgetClass <ctrl><release>9 test");
-  
-  /* We use gtk_rc_parse_string() here so we can make sure it works across theme
-   * changes
-   */
 
-  gtk_rc_parse_string ("style \"testgtk-version-label\" { "
-		       "   fg[NORMAL] = \"#ff0000\"\n"
-		       "   font = \"Sans 18\"\n"
-		       "}\n"
-		       "widget \"*.testgtk-version-label\" style \"testgtk-version-label\"");
-  
+  memory_provider = gtk_css_provider_new ();
+  gtk_css_provider_load_from_data (memory_provider,
+                                   "#testgtk-version-label {\n"
+                                   "  color: #f00;\n"
+                                   "  font: Sans 18;\n"
+                                   "}",
+                                   -1, NULL);
+  gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (memory_provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
+
   create_main_window ();
 
   gtk_main ();
diff --git a/tests/testgtk.css b/tests/testgtk.css
new file mode 100644
index 0000000..9af0257
--- /dev/null
+++ b/tests/testgtk.css
@@ -0,0 +1,33 @@
+/* testgtk2.css sets all the buttons in the main window to blue by default */
+ import url(testgtk2.css);
+
+* {
+    -GtkButton-child-displacement-x: 1;
+    -GtkButton-child-displacement-y: 1;
+
+    -GtkToolbar-space-size: 10;
+    -GtkToolbar-space-style: line;
+    -GtkToolbar-button-relief: none;
+    -GtkButtonBox-child-min-width: 0;
+    -GtkButtonBox-child-min-height: 0;
+    -GtkArrow-arrow-scaling: 1.0;
+    -GtkEntry-invisible-char: 10046;
+
+    font: Sans 12;
+
+    -Gtest-foo: 47;
+    -Gtest-bar: 47;
+}
+
+GtkLabel:selected {
+    background-color: gray;
+}
+
+GtkLabel:prelight {
+    background-color: mix (#a0a0a0, rgb (75%, 200, 0%), 0.9);
+}
+
+/* override testgtk2, introduce the green color in the button list */
+#main_window GtkScrolledWindow GtkButton:prelight {
+    background-color: rgb (0%, 75%, 0);
+}
diff --git a/tests/testgtk2.css b/tests/testgtk2.css
new file mode 100644
index 0000000..a51ec2a
--- /dev/null
+++ b/tests/testgtk2.css
@@ -0,0 +1,9 @@
+/* this file gets included from testgtk.css */
+
+#main_window GtkButton {
+    font: Monospace 10;
+}
+
+#main_window GtkButton:hover {
+    background-color: rgba(0%, 0%, 75%, 0.1);
+}



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