aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@src.gnome.org>2009-02-19 09:36:04 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2009-02-19 09:36:04 +0800
commitfd564be3203400024147469faaa7de0884861566 (patch)
tree80e69ff89307a7393193520e0f2fe51cdc21540e /e-util
parent7ed5f59771262651ee8b0d29a123e43a6ac0b6c6 (diff)
downloadgsoc2013-evolution-fd564be3203400024147469faaa7de0884861566.tar
gsoc2013-evolution-fd564be3203400024147469faaa7de0884861566.tar.gz
gsoc2013-evolution-fd564be3203400024147469faaa7de0884861566.tar.bz2
gsoc2013-evolution-fd564be3203400024147469faaa7de0884861566.tar.lz
gsoc2013-evolution-fd564be3203400024147469faaa7de0884861566.tar.xz
gsoc2013-evolution-fd564be3203400024147469faaa7de0884861566.tar.zst
gsoc2013-evolution-fd564be3203400024147469faaa7de0884861566.zip
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
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-binding.c52
-rw-r--r--e-util/e-binding.h13
-rw-r--r--e-util/e-util.c24
-rw-r--r--e-util/e-util.h1
4 files changed, 89 insertions, 1 deletions
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 <glib-object.h>
+#include <gdk/gdk.h>
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. */