gtk-css-engine r130 - in trunk: . libccd/ccd src themes/gtk-css-test/gtk-2.0
- From: robsta svn gnome org
- To: svn-commits-list gnome org
- Subject: gtk-css-engine r130 - in trunk: . libccd/ccd src themes/gtk-css-test/gtk-2.0
- Date: Fri, 26 Sep 2008 15:08:19 +0000 (UTC)
Author: robsta
Date: Fri Sep 26 15:08:18 2008
New Revision: 130
URL: http://svn.gnome.org/viewvc/gtk-css-engine?rev=130&view=rev
Log:
* TODO: mention css2gtkrc.
* libccd/ccd/ccd-style.c:
* libccd/ccd/ccd-style.h:
* libccd/ccd/exports.sym:
Provide API to query for `border-color'.
* src/Makefile.am:
* src/css2gtkrc.c:
Basic version of `css2gtkrc', a simple standalone gtkrc creation tool.
* src/gce-rc-style.c:
* src/gce-serialize.c:
* src/gce-serialize.h:
Finish and hook-up basic gtkrc creation.
Added:
trunk/src/css2gtkrc.c
trunk/src/gce-serialize.c
- copied, changed from r129, /trunk/src/gce-parser.c
trunk/src/gce-serialize.h
- copied, changed from r129, /trunk/src/gce-parser.h
Removed:
trunk/src/gce-parser.c
trunk/src/gce-parser.h
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/TODO
trunk/libccd/ccd/ccd-style.c
trunk/libccd/ccd/ccd-style.h
trunk/libccd/ccd/exports.sym
trunk/src/Makefile.am
trunk/src/gce-rc-style.c
trunk/themes/gtk-css-test/gtk-2.0/styles.css
Modified: trunk/TODO
==============================================================================
--- trunk/TODO (original)
+++ trunk/TODO Fri Sep 26 15:08:18 2008
@@ -16,6 +16,7 @@
Done:
* Border radius.
* Background image: position, repeat, size.
+* External gtkrc-from-css tool for actually shipping themes.
-- Internals --
* Embed `property' struct in all properties, implement ccd_selector_apply()
Modified: trunk/libccd/ccd/ccd-style.c
==============================================================================
--- trunk/libccd/ccd/ccd-style.c (original)
+++ trunk/libccd/ccd/ccd-style.c Fri Sep 26 15:08:18 2008
@@ -249,22 +249,22 @@
double *green,
double *blue)
{
- g_return_val_if_fail (self, FALSE);
+ g_return_val_if_fail (self, false);
if (NULL == self->color) {
- return FALSE;
+ return false;
}
if (red)
*red = self->color->red;
if (green)
- *red = self->color->green;
+ *green = self->color->green;
if (blue)
- *red = self->color->blue;
+ *blue = self->color->blue;
- return TRUE;
+ return true;
}
bool
@@ -273,22 +273,44 @@
double *green,
double *blue)
{
- g_return_val_if_fail (self, FALSE);
+ g_return_val_if_fail (self, false);
if (NULL == self->bg_color) {
- return FALSE;
+ return false;
}
if (red)
*red = self->bg_color->red;
if (green)
- *red = self->bg_color->green;
+ *green = self->bg_color->green;
if (blue)
- *red = self->bg_color->blue;
+ *blue = self->bg_color->blue;
- return TRUE;
+ return true;
+}
+
+bool
+ccd_style_get_border_color (ccd_style_t const *self,
+ double *red,
+ double *green,
+ double *blue)
+{
+ g_return_val_if_fail (self, false);
+
+ /* FIXME hardcoding "left" for now. */
+
+ if (red)
+ *red = self->left.color.red;
+
+ if (green)
+ *green = self->left.color.green;
+
+ if (blue)
+ *blue = self->left.color.blue;
+
+ return true;
}
#ifdef CCD_DEBUG
Modified: trunk/libccd/ccd/ccd-style.h
==============================================================================
--- trunk/libccd/ccd/ccd-style.h (original)
+++ trunk/libccd/ccd/ccd-style.h Fri Sep 26 15:08:18 2008
@@ -78,6 +78,9 @@
bool ccd_style_get_background_color (ccd_style_t const *self,
double *red, double *green, double *blue);
+bool ccd_style_get_border_color (ccd_style_t const *self,
+ double *red, double *green, double *blue);
+
#ifdef CCD_DEBUG
void ccd_style_dump (ccd_style_t const *self);
#endif
Modified: trunk/libccd/ccd/exports.sym
==============================================================================
--- trunk/libccd/ccd/exports.sym (original)
+++ trunk/libccd/ccd/exports.sym Fri Sep 26 15:08:18 2008
@@ -6,6 +6,7 @@
ccd_style_draw_rectangle
ccd_style_get_color
ccd_style_get_background_color
+ccd_style_get_border_color
ccd_stylesheet_new_from_buffer
ccd_stylesheet_new_from_file
ccd_stylesheet_free
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Fri Sep 26 15:08:18 2008
@@ -1,5 +1,8 @@
-AM_CPPFLAGS = \
+# Need to use per-target flags because of gce-serialize.c, see
+# http://www.gnu.org/software/libtool/manual/automake/Libtool-Issues.html
+
+_cppflags = \
$(GCE_CFLAGS) \
-I$(top_srcdir)/libccd \
-I$(top_builddir)/libccd
@@ -8,6 +11,8 @@
engine_LTLIBRARIES = libcss.la
+libcss_la_CPPFLAGS = $(_cppflags)
+
libcss_la_LDFLAGS = \
-module \
-avoid-version \
@@ -25,14 +30,27 @@
gce-maps.h \
gce-node.c \
gce-node.h \
- gce-parser.c \
- gce-parser.h \
gce-rc-style.c \
gce-rc-style.h \
+ gce-serialize.c \
+ gce-serialize.h \
gce-style.c \
gce-style.h \
gce-theme.c
+noinst_PROGRAMS = css2gtkrc
+
+css2gtkrc_CPPFLAGS = $(_cppflags)
+
+css2gtkrc_SOURCES = \
+ css2gtkrc.c \
+ gce-serialize.c \
+ gce-serialize.h
+
+css2gtkrc_LDADD = \
+ $(GCE_LIBS) \
+ ./../libccd/ccd/libccd-1.la
+
EXTRA_DIST = \
exports.sym
Added: trunk/src/css2gtkrc.c
==============================================================================
--- (empty file)
+++ trunk/src/css2gtkrc.c Fri Sep 26 15:08:18 2008
@@ -0,0 +1,55 @@
+/* The CSS Theme Engine for Gtk+.
+ * Copyright (C) 2008 Robert Staudinger
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <ccd/ccd.h>
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "gce-serialize.h"
+
+int
+main (int argc,
+ char **argv)
+{
+ ccd_stylesheet_t *stylesheet;
+ char *gtkrc;
+
+ if (argc <= 1) {
+ fprintf (stderr, "Need filename.\n");
+ return EXIT_FAILURE;
+ }
+
+ stylesheet = ccd_stylesheet_new_from_file (argv[1]);
+ g_assert (stylesheet);
+
+ gtkrc = gce_serialize (stylesheet);
+ ccd_stylesheet_free (stylesheet), stylesheet = NULL;
+
+ if (NULL == gtkrc) {
+ fprintf (stderr, "Conversion failed.\n");
+ return EXIT_FAILURE;
+ }
+
+ printf (gtkrc);
+ printf ("\n");
+
+ g_free (gtkrc), gtkrc = NULL;
+
+ return EXIT_SUCCESS;
+}
Modified: trunk/src/gce-rc-style.c
==============================================================================
--- trunk/src/gce-rc-style.c (original)
+++ trunk/src/gce-rc-style.c Fri Sep 26 15:08:18 2008
@@ -19,8 +19,8 @@
#include <gtk/gtk.h>
#include <string.h>
-#include "gce-parser.h"
#include "gce-rc-style.h"
+#include "gce-serialize.h"
#include "gce-style.h"
static ccd_stylesheet_t *_stylesheet = NULL;
@@ -59,6 +59,7 @@
static GQuark scope_id = 0;
char *gce_file;
+ char *rc_string;
guint old_scope;
guint token;
@@ -83,10 +84,15 @@
gce_file = gtk_rc_find_pixmap_in_path (gtk_settings_get_default (),
scanner, scanner->value.v_string);
_stylesheet = ccd_stylesheet_new_from_file (gce_file);
+ rc_string = gce_serialize (_stylesheet);
#ifdef DEBUG
ccd_stylesheet_dump (_stylesheet);
+ fprintf (stderr, "%s\n\n", rc_string);
#endif
- gce_parser_setup_gtkrc (_stylesheet);
+ if (rc_string) {
+ gtk_rc_parse_string (rc_string);
+ g_free (rc_string), rc_string = NULL;
+ }
_stylesheet_owner = (gpointer) rc_style;
g_free (gce_file), gce_file = NULL;
Copied: trunk/src/gce-serialize.c (from r129, /trunk/src/gce-parser.c)
==============================================================================
--- /trunk/src/gce-parser.c (original)
+++ trunk/src/gce-serialize.c Fri Sep 26 15:08:18 2008
@@ -17,16 +17,259 @@
* MA 02110-1301, USA.
*/
+#include <string.h>
#include <libcroco/libcroco.h>
-#include "gce-parser.h"
+#include "gce-serialize.h"
+/*
+ * Node implementation for querying the stylesheet.
+ */
+
+typedef struct {
+ ccd_node_t parent;
+ char const *type_name;
+ char const *id;
+ char const *pseudo_class;
+} Node;
+
+static bool
+is_a (Node const *self,
+ char const *type_name)
+{
+ return 0 == g_ascii_strcasecmp (self->type_name, type_name);
+}
+
+static char const *
+get_type (Node const *self)
+{
+ return self->type_name;
+}
+
+static char const *
+get_id (Node const *self)
+{
+ return self->id;
+}
+
+static char const *
+get_pseudo_class (Node const *self)
+{
+ return self->pseudo_class;
+}
+
+static const ccd_node_class_t const _node_class = {
+ .is_a = (ccd_node_is_a_f) is_a,
+ .get_container = NULL,
+ .get_base_style = NULL,
+ .get_id = (ccd_node_get_id_f) get_id,
+ .get_type = (ccd_node_get_type_f) get_type,
+ .get_class = NULL,
+ .get_pseudo_class = (ccd_node_get_pseudo_class_f) get_pseudo_class,
+ .get_attribute = NULL,
+ .release = NULL
+};
+
+/*
+ * Gtkrc creation infrastructure.
+ */
+
+enum { NORMAL = 0, ACTIVE, PRELIGHT, SELECTED, INSENSITIVE, N_STATES };
+enum { RED = 0, GREEN, BLUE, N_COLORS };
+enum {
+ FG_SET = 1 << 0,
+ BG_SET = 1 << 1,
+ BASE_SET = 1 << 2,
+ TEXT_SET = 1 << 3
+};
+enum {
+ NORMAL_SET = 1 << 0,
+ ACTIVE_SET = 1 << 1,
+ PRELIGHT_SET = 1 << 2,
+ SELECTED_SET = 1 << 3,
+ INSENSITIVE_SET = 1 << 4
+};
+
+struct RcBlock {
+ struct RcState {
+ double fg[N_COLORS];
+ double bg[N_COLORS];
+ double base[N_COLORS];
+ double text[N_COLORS];
+ guint flags;
+ } colors[N_STATES];
+ guint flags;
+ char const *type_name;
+};
+
+static gboolean
+accumulate_state (ccd_stylesheet_t const *stylesheet,
+ char const *type_name,
+ char const *state_name,
+ struct RcState *state)
+{
+ ccd_style_t style;
+ Node node;
+ gboolean ret;
+
+ ccd_style_init (&style);
+ node.type_name = type_name;
+ node.id = NULL;
+ node.pseudo_class = state_name;
+
+ ret = ccd_stylesheet_query_apply (stylesheet,
+ (ccd_node_t const *) &node, &style);
+ if (!ret) {
+ return false;
+ }
+
+ ret = ccd_style_get_color (&style, &state->fg[RED], &state->fg[GREEN], &state->fg[BLUE]);
+ if (ret) {
+ state->flags |= FG_SET;
+ }
-gboolean
-gce_parser_setup_gtkrc (ccd_stylesheet_t const *stylesheet)
+ ret = ccd_style_get_background_color (&style, &state->bg[RED], &state->bg[GREEN], &state->bg[BLUE]);
+ if (ret) {
+ state->flags |= BG_SET;
+ /* FIXME: also setting "base" to the background color, let's see how this works out. */
+ state->base[RED] = state->bg[RED];
+ state->base[GREEN] = state->bg[GREEN];
+ state->base[BLUE] = state->bg[BLUE];
+ state->flags |= BASE_SET;
+ }
+
+ return (gboolean) state->flags;
+}
+
+static gboolean
+accumulate (ccd_stylesheet_t const *stylesheet,
+ struct RcBlock *block)
+{
+ 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]);
+ if (ret) {
+ block->flags |= NORMAL_SET;
+ }
+ ret = accumulate_state (stylesheet, block->type_name, "normal", &block->colors[NORMAL]);
+ if (ret) {
+ block->flags |= NORMAL_SET;
+ }
+
+ ret = accumulate_state (stylesheet, block->type_name, "active", &block->colors[ACTIVE]);
+ if (ret) {
+ block->flags |= ACTIVE_SET;
+ }
+
+ ret = accumulate_state (stylesheet, block->type_name, "prelight", &block->colors[PRELIGHT]);
+ if (ret) {
+ block->flags |= PRELIGHT_SET;
+ }
+
+ ret = accumulate_state (stylesheet, block->type_name, "selected", &block->colors[SELECTED]);
+ if (ret) {
+ block->flags |= SELECTED_SET;
+ }
+
+ ret = accumulate_state (stylesheet, block->type_name, "insensitive", &block->colors[INSENSITIVE]);
+ if (ret) {
+ block->flags |= INSENSITIVE_SET;
+ }
+
+ return (gboolean) block->flags;
+}
+
+static void
+serialize_state (struct RcState const *state,
+ char const *state_name,
+ GString *rc_string)
+{
+ if (FG_SET & state->flags) {
+ g_string_append_printf (rc_string, "\tfg[%s] = { %.3f, %.3f, %.3f }\n", state_name,
+ state->fg[RED], state->fg[GREEN], state->fg[BLUE]);
+ }
+
+ if (BG_SET & state->flags) {
+ g_string_append_printf (rc_string, "\tbg[%s] = { %.3f, %.3f, %.3f }\n", state_name,
+ state->bg[RED], state->bg[GREEN], state->bg[BLUE]);
+ }
+
+ if (BASE_SET & state->flags) {
+ g_string_append_printf (rc_string, "\tbase[%s] = { %.3f, %.3f, %.3f }\n", state_name,
+ state->base[RED], state->base[GREEN], state->base[BLUE]);
+ }
+
+ if (TEXT_SET & state->flags) {
+ g_string_append_printf (rc_string, "\ttext[%s] = { %.3f, %.3f, %.3f }\n", state_name,
+ state->text[RED], state->text[GREEN], state->text[BLUE]);
+ }
+}
+
+static gboolean
+serialize (struct RcBlock const *block,
+ GString *rc_string)
+{
+ char *style;
+ char *style_name;
+
+ if (strlen (block->type_name) > 3 &&
+ 0 == strncmp ("Gtk", block->type_name, 3)) {
+ style = g_ascii_strdown (block->type_name + 3, -1);
+ } else if (0 == strcmp ("*", block->type_name)) {
+ style = g_strdup ("default");
+ } else {
+ return FALSE;
+ }
+
+ style_name = g_strdup_printf ("gce-%s", style);
+ g_free (style), style = NULL;
+
+ g_string_append_printf (rc_string, "style \"%s\" {\n", style_name);
+
+ if (NORMAL_SET & block->flags) {
+ serialize_state (&block->colors[NORMAL], "NORMAL", rc_string);
+ }
+
+ if (ACTIVE_SET & block->flags) {
+ serialize_state (&block->colors[ACTIVE], "ACTIVE", rc_string);
+ }
+
+ if (PRELIGHT_SET & block->flags) {
+ serialize_state (&block->colors[PRELIGHT], "PRELIGHT", rc_string);
+ }
+
+ if (SELECTED_SET & block->flags) {
+ serialize_state (&block->colors[SELECTED], "SELECTED", rc_string);
+ }
+
+ if (INSENSITIVE_SET & block->flags) {
+ serialize_state (&block->colors[INSENSITIVE], "INSENSITIVE", rc_string);
+ }
+
+ g_string_append (rc_string, "}\n");
+
+ g_string_append_printf (rc_string, "class \"%s\" style \"%s\"\n\n", block->type_name, style_name);
+ g_free (style_name), style_name = NULL;
+
+ return TRUE;
+}
+
+char *
+gce_serialize (ccd_stylesheet_t const *stylesheet)
{
ccd_stylesheet_iter_t iter;
+ ccd_node_class_t original_node_class;
char const *type_name;
ccd_selector_group_t const *group;
+ struct RcBlock block;
+ GString *rc_string;
+ char *str;
+ gboolean ret;
+
+ ccd_node_fill_class (&original_node_class);
+ ccd_node_set_class (&_node_class);
+
+ rc_string = g_string_new ("");
ccd_stylesheet_iter_init (&iter, stylesheet);
@@ -34,7 +277,24 @@
group = NULL;
while (ccd_stylesheet_iter_next (&iter, &type_name, &group)) {
- printf ("%s\n", type_name);
+ /* Only feed widget styles back into gtk, not primitives. */
+ if (strcmp ("*", type_name) != 0 &&
+ strncmp ("Gtk", type_name, 3) != 0) {
+ continue;
+ }
+
+ memset (&block, 0, sizeof (block));
+ block.type_name = type_name;
+ ret = accumulate (stylesheet, &block);
+ if (ret) {
+ serialize (&block, rc_string);
+ }
}
+
+ ccd_node_set_class (&original_node_class);
+
+ str = rc_string->str;
+ g_string_free (rc_string, FALSE), rc_string = NULL;
+ return str;
}
Copied: trunk/src/gce-serialize.h (from r129, /trunk/src/gce-parser.h)
==============================================================================
--- /trunk/src/gce-parser.h (original)
+++ trunk/src/gce-serialize.h Fri Sep 26 15:08:18 2008
@@ -25,7 +25,7 @@
G_BEGIN_DECLS
-gboolean gce_parser_setup_gtkrc (ccd_stylesheet_t const *stylesheet);
+char * gce_serialize (ccd_stylesheet_t const *stylesheet);
G_END_DECLS
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 Fri Sep 26 15:08:18 2008
@@ -1,4 +1,9 @@
+* {
+ background-color: khaki;
+ color: black;
+}
+
arrow {
background-position: center;
background-repeat: no-repeat;
@@ -117,3 +122,6 @@
background-color: yellow;
}
+GtkButton:normal {
+ background-color: darkkhaki;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]