From fd564be3203400024147469faaa7de0884861566 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 19 Feb 2009 01:36:04 +0000 Subject: Clean up the EMFormat stack. Add some GObject properties to bind to. Add some handy color conversion functions to e-util. svn path=/branches/kill-bonobo/; revision=37290 --- e-util/e-binding.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-binding.h | 13 ++++++++++++- e-util/e-util.c | 24 ++++++++++++++++++++++++ e-util/e-util.h | 1 + 4 files changed, 89 insertions(+), 1 deletion(-) (limited to 'e-util') diff --git a/e-util/e-binding.c b/e-util/e-binding.c index 26e62c6a23..26e23ee792 100644 --- a/e-util/e-binding.c +++ b/e-util/e-binding.c @@ -480,3 +480,55 @@ e_mutual_binding_unbind (EMutualBinding *binding) g_signal_handler_disconnect ( binding->reverse.dst_object, binding->direct.handler); } + +/** + * e_binding_transform_color_to_string: + * @src_value: a #GValue of type #GDK_TYPE_COLOR + * @dst_value: a #GValue of type #G_TYPE_STRING + * @user_data: not used + * + * Transforms a #GdkColor value to a color string specification. + * + * Returns: %TRUE always + **/ +gboolean +e_binding_transform_color_to_string (const GValue *src_value, + GValue *dst_value, + gpointer user_data) +{ + const GdkColor *color; + gchar *string; + + color = g_value_get_boxed (src_value); + string = gdk_color_to_string (color); + g_value_set_string (dst_value, string); + g_free (string); + + return TRUE; +} + +/** + * e_binding_transform_string_to_color: + * @src_value: a #GValue of type #G_TYPE_STRING + * @dst_value: a #GValue of type #GDK_TYPE_COLOR + * @user_data: not used + * + * Transforms a color string specification to a #GdkColor. + * + * Returns: %TRUE if color string specification was valid + **/ +gboolean +e_binding_transform_string_to_color (const GValue *src_value, + GValue *dst_value, + gpointer user_data) +{ + GdkColor color; + const gchar *string; + gboolean success; + + string = g_value_get_string (src_value); + if (gdk_color_parse (string, &color)) + g_value_set_boxed (dst_value, &color); + + return success; +} diff --git a/e-util/e-binding.h b/e-util/e-binding.h index 2cced75920..676093bfad 100644 --- a/e-util/e-binding.h +++ b/e-util/e-binding.h @@ -26,7 +26,7 @@ #ifndef E_BINDING_H #define E_BINDING_H -#include +#include G_BEGIN_DECLS @@ -102,6 +102,17 @@ EMutualBinding *e_mutual_binding_new_with_negation const gchar *property2); void e_mutual_binding_unbind (EMutualBinding *binding); + +/* Useful transformation functions */ +gboolean e_binding_transform_color_to_string + (const GValue *src_value, + GValue *dst_value, + gpointer user_data); +gboolean e_binding_transform_string_to_color + (const GValue *src_value, + GValue *dst_value, + gpointer user_data); + G_END_DECLS #endif /* E_BINDING_H */ diff --git a/e-util/e-util.c b/e-util/e-util.c index a5e6c6b548..c65fcbceaf 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -432,6 +432,30 @@ e_write_file_uri (const gchar *filename, const gchar *data) return res; } +/** + * e_color_to_value: + * color: a #GdkColor + * + * Converts a #GdkColor to a 24-bit RGB color value. + * + * Returns: a 24-bit color value + **/ +guint32 +e_color_to_value (GdkColor *color) +{ + guint16 red; + guint16 green; + guint16 blue; + + g_return_val_if_fail (color != NULL, 0); + + red = color->red >> 8; + green = color->green >> 8; + blue = color->blue >> 8; + + return (guint32) (((red << 16) | (green << 8) | blue) & 0xffffff); +} + static gint epow10 (gint number) { diff --git a/e-util/e-util.h b/e-util/e-util.h index 28d7a50a39..65e492850f 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -64,6 +64,7 @@ gint e_int_compare (gconstpointer x, gconstpointer y); gboolean e_write_file_uri (const gchar *filename, const gchar *data); +guint32 e_color_to_value (GdkColor *color); /* This only makes a filename safe for usage as a filename. * It still may have shell meta-characters in it. */ -- cgit v1.2.3