gtk-css-engine r193 - in trunk: . src themes/gtk-css-test/gtk-2.0
- From: robsta svn gnome org
- To: svn-commits-list gnome org
- Subject: gtk-css-engine r193 - in trunk: . src themes/gtk-css-test/gtk-2.0
- Date: Wed, 19 Nov 2008 13:10:55 +0000 (UTC)
Author: robsta
Date: Wed Nov 19 13:10:55 2008
New Revision: 193
URL: http://svn.gnome.org/viewvc/gtk-css-engine?rev=193&view=rev
Log:
* src/gce-functions.c:
* src/gce-serialize.c (style_iterator), (accumulate_state),
(accumulate), (serialize), (iter_func):
Support for basic (single-value) gtk style properties.
Modified:
trunk/ChangeLog
trunk/src/gce-functions.c
trunk/src/gce-serialize.c
trunk/themes/gtk-css-test/gtk-2.0/styles.css
Modified: trunk/src/gce-functions.c
==============================================================================
--- trunk/src/gce-functions.c (original)
+++ trunk/src/gce-functions.c Wed Nov 19 13:10:55 2008
@@ -375,15 +375,14 @@
result.blue / 65535.0);
}
-
static ccss_function_t const _functions[] =
{
- { "url", url },
- { "gtk-color", color },
- { "gtk-mix", mix },
- { "gtk-shade", shade },
- { "gtk-lighter", lighter },
- { "gtk-darker", darker },
+ { "url", url },
+ { "gtk-color", color },
+ { "gtk-mix", mix },
+ { "gtk-shade", shade },
+ { "gtk-lighter", lighter },
+ { "gtk-darker", darker },
{ NULL }
};
Modified: trunk/src/gce-serialize.c
==============================================================================
--- trunk/src/gce-serialize.c (original)
+++ trunk/src/gce-serialize.c Wed Nov 19 13:10:55 2008
@@ -17,6 +17,7 @@
* MA 02110-1301, USA.
*/
+#include <math.h>
#include <string.h>
#include <libcroco/libcroco.h>
#include "gce-serialize.h"
@@ -92,13 +93,60 @@
} colors[N_STATES];
guint flags;
char const *type_name;
+ GSList *style_properties;
};
+static void
+style_iterator (ccss_style_t const *style,
+ char const *property_name,
+ GSList **style_properties)
+{
+ double num_val;
+ char *str_val;
+ char *property;
+ gboolean ret;
+
+ if (g_str_has_prefix (property_name, "gtk-")) {
+
+ /* Try to extract numeric property. */
+ ret = ccss_style_get_double (style, property_name, &num_val);
+ if (ret) {
+ if (lrint (num_val) == num_val) {
+ /* Actually an integer. */
+ property = g_strdup_printf ("%s = %ld",
+ property_name + 4,
+ lrint (num_val));
+ } else {
+ property = g_strdup_printf ("%s = %f",
+ property_name + 4,
+ num_val);
+ }
+ *style_properties = g_slist_prepend (*style_properties,
+ property);
+ return;
+ }
+
+ /* Fall back to string property. */
+ str_val = NULL;
+ ret = ccss_style_get_string (style, property_name, &str_val);
+ if (ret) {
+ property = g_strdup_printf ("%s = \"%s\"",
+ property_name + 4,
+ str_val);
+ g_free (str_val), str_val = NULL;
+ *style_properties = g_slist_prepend (*style_properties,
+ property);
+ return;
+ }
+ }
+}
+
static gboolean
accumulate_state (ccss_stylesheet_t const *stylesheet,
char const *type_name,
char const *state_name,
- struct RcState *state)
+ struct RcState *state,
+ GSList **style_properties)
{
ccss_style_t *style;
Node node;
@@ -143,9 +191,17 @@
g_free (color), color = NULL;
}
+ /* Extract style properties, only for default state. */
+ if (style_properties) {
+ ccss_style_foreach (style, (ccss_style_iterator_f) style_iterator,
+ style_properties);
+ }
+
ccss_style_free (style), style = NULL;
- return (gboolean) state->flags;
+ /* Having colors or style properties means there's something to serialise. */
+ return (gboolean) state->flags ||
+ (gboolean) (style_properties && *style_properties);
}
static gboolean
@@ -155,31 +211,37 @@
gboolean ret;
/* Querying for `normal' state without any- and with the `normal' pseudo class. */
- ret = accumulate_state (stylesheet, block->type_name, NULL, &block->colors[NORMAL]);
+ ret = accumulate_state (stylesheet, block->type_name, NULL,
+ &block->colors[NORMAL], &block->style_properties);
if (ret) {
block->flags |= NORMAL_SET;
}
- ret = accumulate_state (stylesheet, block->type_name, "normal", &block->colors[NORMAL]);
+ ret = accumulate_state (stylesheet, block->type_name, "normal",
+ &block->colors[NORMAL], NULL);
if (ret) {
block->flags |= NORMAL_SET;
}
- ret = accumulate_state (stylesheet, block->type_name, "active", &block->colors[ACTIVE]);
+ ret = accumulate_state (stylesheet, block->type_name, "active",
+ &block->colors[ACTIVE], NULL);
if (ret) {
block->flags |= ACTIVE_SET;
}
- ret = accumulate_state (stylesheet, block->type_name, "prelight", &block->colors[PRELIGHT]);
+ ret = accumulate_state (stylesheet, block->type_name, "prelight",
+ &block->colors[PRELIGHT], NULL);
if (ret) {
block->flags |= PRELIGHT_SET;
}
- ret = accumulate_state (stylesheet, block->type_name, "selected", &block->colors[SELECTED]);
+ ret = accumulate_state (stylesheet, block->type_name, "selected",
+ &block->colors[SELECTED], NULL);
if (ret) {
block->flags |= SELECTED_SET;
}
- ret = accumulate_state (stylesheet, block->type_name, "insensitive", &block->colors[INSENSITIVE]);
+ ret = accumulate_state (stylesheet, block->type_name, "insensitive",
+ &block->colors[INSENSITIVE], NULL);
if (ret) {
block->flags |= INSENSITIVE_SET;
}
@@ -213,8 +275,9 @@
serialize (struct RcBlock const *block,
GString *rc_string)
{
- char *style;
- char *style_name;
+ GSList const *iter;
+ char *style;
+ char *style_name;
if (strlen (block->type_name) > 3 &&
0 == strncmp ("Gtk", block->type_name, 3)) {
@@ -250,6 +313,13 @@
serialize_state (&block->colors[INSENSITIVE], "INSENSITIVE", rc_string);
}
+ /* Style properties. */
+ iter = block->style_properties;
+ while (iter) {
+ g_string_append_printf (rc_string, "\t%s\n", (char const *) iter->data);
+ iter = iter->next;
+ }
+
g_string_append (rc_string, "}\n");
g_string_append_printf (rc_string, "class \"%s\" style \"%s\"\n\n", block->type_name, style_name);
@@ -278,6 +348,13 @@
if (ret) {
serialize (&block, rc_string);
}
+
+ /* Free style properties. */
+ while (block.style_properties) {
+ g_free (block.style_properties->data);
+ block.style_properties = g_slist_delete_link (block.style_properties,
+ block.style_properties);
+ }
}
char *
Modified: trunk/themes/gtk-css-test/gtk-2.0/styles.css
==============================================================================
--- trunk/themes/gtk-css-test/gtk-2.0/styles.css (original)
+++ trunk/themes/gtk-css-test/gtk-2.0/styles.css Wed Nov 19 13:10:55 2008
@@ -1,4 +1,11 @@
+/*
+GtkButton {
+ gtk-xthickness: 2;
+ gtk-ythickness: 3;
+}
+*/
+
* {
background-color: gtk-color(bg_color);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]