gtk-css-engine r118 - in trunk: . libccd/ccd



Author: robsta
Date: Mon Sep 22 08:48:12 2008
New Revision: 118
URL: http://svn.gnome.org/viewvc/gtk-css-engine?rev=118&view=rev

Log:
* libccd/ccd/ccd-background.c: rely on correctly initialised styles.
* libccd/ccd/ccd-background.h: consistently put the property spec at
  the beginning of property structs.
* libccd/ccd/ccd-property.c:
* libccd/ccd/ccd-property.h:
Add ccd_property_is_set() to consistently check on properties.
* libccd/ccd/ccd-style.c: initialise style to built-in defaults.


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/libccd/ccd/ccd-background.c
   trunk/libccd/ccd/ccd-background.h
   trunk/libccd/ccd/ccd-property.c
   trunk/libccd/ccd/ccd-property.h
   trunk/libccd/ccd/ccd-style.c

Modified: trunk/libccd/ccd/ccd-background.c
==============================================================================
--- trunk/libccd/ccd/ccd-background.c	(original)
+++ trunk/libccd/ccd/ccd-background.c	Mon Sep 22 08:48:12 2008
@@ -411,9 +411,16 @@
 	double		dx;
 	double		dy;
 
+	g_return_if_fail (bg_attachment);
+	g_return_if_fail (bg_color);
+	g_return_if_fail (bg_image);
+	g_return_if_fail (bg_position);
+	g_return_if_fail (bg_repeat);
+	g_return_if_fail (bg_size);
+
 	cairo_save (cr);
 
-	if (bg_color && bg_color->spec != CCD_PROPERTY_SPEC_UNSET) {
+	if (ccd_property_is_set (bg_color->spec)) {
 
 		cairo_set_source_rgb (cr, bg_color->color.red, 
 					  bg_color->color.green, 
@@ -421,7 +428,7 @@
 		cairo_fill_preserve (cr);
 	}
 
-	if (bg_image && bg_image->spec != CCD_PROPERTY_SPEC_UNSET) {
+	if (ccd_property_is_set (bg_image->spec)) {
 
 		cairo_translate (cr, x, y);
 #if 0

Modified: trunk/libccd/ccd/ccd-background.h
==============================================================================
--- trunk/libccd/ccd/ccd-background.h	(original)
+++ trunk/libccd/ccd/ccd-background.h	Mon Sep 22 08:48:12 2008
@@ -34,43 +34,43 @@
 G_BEGIN_DECLS
 
 typedef struct {
-	enum ccd_background_repeat {
-		CCD_BACKGROUND_REPEAT = 0,
-		CCD_BACKGROUND_REPEAT_X,
-		CCD_BACKGROUND_REPEAT_Y,
-		CCD_BACKGROUND_NO_REPEAT
-	}			repeat;
 	ccd_property_spec_t	spec;
-} ccd_background_repeat_t;
-
-typedef struct {
 	enum ccd_background_attachment {
 		CCD_BACKGROUND_SCROLL,
 		CCD_BACKGROUND_FIXED
 	}			attachment;
-	ccd_property_spec_t	spec;
 } ccd_background_attachment_t;
 
 typedef struct {
-	ccd_color_t		color;
 	ccd_property_spec_t	spec;
+	ccd_color_t		color;
 } ccd_background_color_t;
 
 typedef struct {
-	ccd_image_t		image;
 	ccd_property_spec_t	spec;
+	ccd_image_t		image;
 } ccd_background_image_t;
 
 typedef struct {
+	ccd_property_spec_t	spec;
 	ccd_position_t		hpos;
 	ccd_position_t		vpos;
-	ccd_property_spec_t	spec;
 } ccd_background_position_t;
 
 typedef struct {
+	ccd_property_spec_t	spec;
+	enum ccd_background_repeat {
+		CCD_BACKGROUND_REPEAT = 0,
+		CCD_BACKGROUND_REPEAT_X,
+		CCD_BACKGROUND_REPEAT_Y,
+		CCD_BACKGROUND_NO_REPEAT
+	}			repeat;
+} ccd_background_repeat_t;
+
+typedef struct {
+	ccd_property_spec_t	spec;
 	ccd_position_t		width;
 	ccd_position_t		height;
-	ccd_property_spec_t	spec;
 } ccd_background_size_t;
 
 typedef struct {

Modified: trunk/libccd/ccd/ccd-property.c
==============================================================================
--- trunk/libccd/ccd/ccd-property.c	(original)
+++ trunk/libccd/ccd/ccd-property.c	Mon Sep 22 08:48:12 2008
@@ -43,6 +43,14 @@
 	return CCD_PROPERTY_SPEC_SET;
 }
 
+bool
+ccd_property_is_set (ccd_property_spec_t property)
+{
+	return CCD_PROPERTY_SPEC_SET == property || 
+	       CCD_PROPERTY_SPEC_INHERIT == property;
+}
+
+
 #ifdef CCD_DEBUG
 
 void

Modified: trunk/libccd/ccd/ccd-property.h
==============================================================================
--- trunk/libccd/ccd/ccd-property.h	(original)
+++ trunk/libccd/ccd/ccd-property.h	Mon Sep 22 08:48:12 2008
@@ -21,6 +21,7 @@
 #define CCD_PROPERTY_H
 
 #include <glib.h>
+#include <stdbool.h>
 #include <libcroco/libcroco.h>
 #include <ccd/ccd-features.h>
 
@@ -28,6 +29,8 @@
 
 #define CCD_PROPERTY_DUMP_PREFIX "    "
 
+/* TODO maybe make this flags, include a CCD_PROPERTY_SPEC_RESOLVED
+ * and resolve in ccd_style_init(). */
 typedef enum {
 	CCD_PROPERTY_SPEC_UNSET = 0,
 	CCD_PROPERTY_SPEC_NONE,
@@ -37,6 +40,8 @@
 
 ccd_property_spec_t ccd_property_parse_spec (CRTerm const **value);
 
+bool ccd_property_is_set (ccd_property_spec_t property);
+
 #ifdef CCD_DEBUG
 void ccd_property_spec_dump (ccd_property_spec_t const spec);
 #endif

Modified: trunk/libccd/ccd/ccd-style.c
==============================================================================
--- trunk/libccd/ccd/ccd-style.c	(original)
+++ trunk/libccd/ccd/ccd-style.c	Mon Sep 22 08:48:12 2008
@@ -20,6 +20,96 @@
 #include <string.h>
 #include "ccd-style.h"
 
+static const ccd_background_attachment_t const _bg_attachment = {
+	.spec = CCD_PROPERTY_SPEC_SET,
+	.attachment = CCD_BACKGROUND_SCROLL
+};
+
+static const ccd_background_color_t const _bg_color = {
+	.spec = CCD_PROPERTY_SPEC_SET,
+	.color = { 1., 1., 1. }
+};
+
+static const ccd_background_image_t const _bg_image = {
+	.spec = CCD_PROPERTY_SPEC_NONE
+};
+
+static const ccd_background_position_t const _bg_position = {
+	.spec = CCD_PROPERTY_SPEC_SET,
+	.hpos = { CCD_POSITION_LENGTH, 0 },
+	.vpos = { CCD_POSITION_LENGTH, 0 }
+};
+
+static const ccd_background_repeat_t const _bg_repeat = {
+	.spec = CCD_PROPERTY_SPEC_SET,
+	.repeat = CCD_BACKGROUND_REPEAT
+};
+
+static const ccd_background_size_t const _bg_size = {
+	.spec = CCD_PROPERTY_SPEC_SET,
+	.width = { CCD_POSITION_AUTO, 0 },
+	.height = { CCD_POSITION_AUTO, 0 }
+};
+
+static const ccd_color_t const _color = {
+	0., 0., 0.
+};
+
+static const ccd_style_t const _default_style = {
+	.bg_attachment = &_bg_attachment,
+	.bg_color = &_bg_color,
+	.bg_image = &_bg_image,
+	.bg_position = &_bg_position,
+	.bg_repeat = &_bg_repeat,
+	.bg_size = &_bg_size,
+	.left = {
+		.width = 0,
+		.width_spec = CCD_PROPERTY_SPEC_SET,
+		.style = CCD_BORDER_STYLE_SOLID,
+		.style_spec = CCD_PROPERTY_SPEC_SET,
+		.color = { 0, 0, 0 },
+		.color_spec = CCD_PROPERTY_SPEC_SET },
+	.left_top = {
+		.radius = 0,
+		.spec = CCD_PROPERTY_SPEC_SET
+	},
+	.top = {
+		.width = 0,
+		.width_spec = CCD_PROPERTY_SPEC_SET,
+		.style = CCD_BORDER_STYLE_SOLID,
+		.style_spec = CCD_PROPERTY_SPEC_SET,
+		.color = { 0, 0, 0 },
+		.color_spec = CCD_PROPERTY_SPEC_SET },
+	.top_right = {
+		.radius = 0,
+		.spec = CCD_PROPERTY_SPEC_SET
+	},
+	.right = {
+		.width = 0,
+		.width_spec = CCD_PROPERTY_SPEC_SET,
+		.style = CCD_BORDER_STYLE_SOLID,
+		.style_spec = CCD_PROPERTY_SPEC_SET,
+		.color = { 0, 0, 0 },
+		.color_spec = CCD_PROPERTY_SPEC_SET },
+	.right_bottom = {
+		.radius = 0,
+		.spec = CCD_PROPERTY_SPEC_SET
+	},
+	.bottom = {
+		.width = 0,
+		.width_spec = CCD_PROPERTY_SPEC_SET,
+		.style = CCD_BORDER_STYLE_SOLID,
+		.style_spec = CCD_PROPERTY_SPEC_SET,
+		.color = { 0, 0, 0 },
+		.color_spec = CCD_PROPERTY_SPEC_SET },
+	.bottom_left = {
+		.radius = 0,
+		.spec = CCD_PROPERTY_SPEC_SET
+	},
+	.color = &_color,
+	.color_spec = CCD_PROPERTY_SPEC_SET
+};
+
 /**
  * ccd_style_init:
  * @self:	a ccd_style_t.
@@ -29,7 +119,7 @@
 void
 ccd_style_init (ccd_style_t *self)
 {
-	memset (self, 0, sizeof (*self));
+	memcpy (self, &_default_style, sizeof (*self));
 }
 
 /**



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