[dia] [api] more prop_list_add*(). less "prop_*.h" (internals) use
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] [api] more prop_list_add*(). less "prop_*.h" (internals) use
- Date: Sun, 7 Oct 2012 13:03:44 +0000 (UTC)
commit 84e91b8ca25e1ca98b99a4ce2952129d4db4dd61
Author: Hans Breuer <hans breuer org>
Date: Sun Oct 7 00:39:27 2012 +0200
[api] more prop_list_add*(). less "prop_*.h" (internals) use
lib/libdia.def | 3 ++
lib/properties.h | 6 ++++
lib/proplist.c | 18 +++++++++++++
lib/propobject.c | 64 +++++++++++++++++++++++++++++++++++++++++++--
plug-ins/pixbuf/pixbuf.c | 22 +++++-----------
5 files changed, 95 insertions(+), 18 deletions(-)
---
diff --git a/lib/libdia.def b/lib/libdia.def
index 3fe1568..4ae4e93 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -329,6 +329,7 @@ EXPORTS
dia_object_set_meta
dia_object_get_meta
dia_object_set_pixbuf
+ dia_object_set_string
dia_object_get_num_connections
dia_plugin_can_unload
@@ -669,12 +670,14 @@ EXPORTS
prop_desc_list_free_handler_chain
prop_desc_lists_intersection
prop_list_add_list
+ prop_list_add_filename
prop_list_add_fill_colour
prop_list_add_line_colour
prop_list_add_line_style
prop_list_add_line_width
prop_list_add_point
prop_list_add_real
+ prop_list_add_string
prop_list_add_show_background
prop_list_free
prop_list_from_descs
diff --git a/lib/properties.h b/lib/properties.h
index a738ba8..efb163e 100644
--- a/lib/properties.h
+++ b/lib/properties.h
@@ -444,6 +444,10 @@ void prop_list_add_show_background (GPtrArray *plist, gboolean fill);
void prop_list_add_point (GPtrArray *plist, const char *name, const Point *point);
/* quite generic, e.g. elem_width, elem_height, curve_distance */
void prop_list_add_real (GPtrArray *plist, const char *name, real value);
+/* addding a string property */
+void prop_list_add_string (GPtrArray *plist, const char *name, const char *value);
+/* addding a string property */
+void prop_list_add_filename (GPtrArray *plist, const char *name, const char *value);
/* Some predicates: */
gboolean pdtpp_true(const PropDescription *pdesc); /* always true */
@@ -543,6 +547,8 @@ Property *object_prop_by_name(DiaObject *obj, const char *name);
Property *object_prop_by_name_type(DiaObject *obj, const char *name, const char *type);
/* Set the pixbuf property if there is one */
ObjectChange *dia_object_set_pixbuf (DiaObject *object, GdkPixbuf *pixbuf);
+/* Set the string property if there is one */
+ObjectChange *dia_object_set_string (DiaObject *object, const char *name, const char *value);
/* ************************************************************* */
diff --git a/lib/proplist.c b/lib/proplist.c
index 3f9e981..dd71cfd 100644
--- a/lib/proplist.c
+++ b/lib/proplist.c
@@ -280,3 +280,21 @@ prop_list_add_real (GPtrArray *plist, const char *name, real value)
((RealProperty *)prop)->real_data = value;
g_ptr_array_add (plist, prop);
}
+void
+prop_list_add_string (GPtrArray *plist, const char *name, const char *value)
+{
+ Property *prop = make_new_prop (name, PROP_TYPE_STRING, 0);
+
+ g_free (((StringProperty *)prop)->string_data);
+ ((StringProperty *)prop)->string_data = g_strdup (value);
+ g_ptr_array_add (plist, prop);
+}
+void
+prop_list_add_filename (GPtrArray *plist, const char *name, const char *value)
+{
+ Property *prop = make_new_prop (name, PROP_TYPE_FILE, 0);
+
+ g_free (((StringProperty *)prop)->string_data);
+ ((StringProperty *)prop)->string_data = g_strdup (value);
+ g_ptr_array_add (plist, prop);
+}
diff --git a/lib/propobject.c b/lib/propobject.c
index 863e828..b9dceba 100644
--- a/lib/propobject.c
+++ b/lib/propobject.c
@@ -378,7 +378,7 @@ object_prop_by_name_type(DiaObject *obj, const char *name, const char *type)
for (pdesc = object_get_prop_descriptions(obj);
pdesc->name != NULL;
pdesc++) {
- if ((pdesc->quark == name_quark)) {
+ if (name_quark == 0 || (pdesc->quark == name_quark)) {
Property *prop;
static GPtrArray *plist = NULL;
@@ -392,7 +392,7 @@ object_prop_by_name_type(DiaObject *obj, const char *name, const char *type)
g_ptr_array_index(plist,0) = prop;
obj->ops->get_props(obj,plist);
return prop;
- }
+ }
}
return NULL;
}
@@ -403,7 +403,20 @@ object_prop_by_name(DiaObject *obj, const char *name)
return object_prop_by_name_type(obj,name,NULL);
}
-
+/*!
+ * \brief Modification of the objects 'pixbuf' property
+ *
+ * @param object object to modify
+ * @param pixbuf the pixbuf to set
+ * @return an object change or NULL
+ *
+ * If the object does not have a pixbuf property nothing
+ * happens. If there is a pixbuf property and the passed
+ * in pixbuf is identical an empty change is returned.
+ *
+ * \memberof _DiaObject
+ * \ingroup StdProps
+ */
ObjectChange *
dia_object_set_pixbuf (DiaObject *object,
GdkPixbuf *pixbuf)
@@ -416,6 +429,8 @@ dia_object_set_pixbuf (DiaObject *object,
if (!prop)
return NULL;
pp = (PixbufProperty *)prop;
+ if (pp->pixbuf == pixbuf)
+ return change_list_create ();
if (pp->pixbuf)
g_object_unref (pp->pixbuf);
pp->pixbuf = g_object_ref (pixbuf);
@@ -424,3 +439,46 @@ dia_object_set_pixbuf (DiaObject *object,
prop_list_free (props);
return change;
}
+
+/*!
+ * \brief Modify the objects string property
+ * @param object the object to modify
+ * @param name the name of the string property (NULL for any)
+ * @param value the value to set, NULL to delete
+ * @return object change on sucess, NULL if not found
+ *
+ * Usually you should not pass NULL for the name, the facility
+ * was added for convenience of the unit test.
+ *
+ * \memberof _DiaObject
+ * \ingroup StdProps
+ */
+ObjectChange *
+dia_object_set_string (DiaObject *object,
+ const char *name,
+ const char *value)
+{
+ ObjectChange *change;
+ GPtrArray *props = NULL;
+ Property *prop = object_prop_by_name_type (object, name, PROP_TYPE_STRING);
+
+ if (!prop)
+ prop = object_prop_by_name_type (object, name, PROP_TYPE_FILE);
+ if (prop) {
+ StringProperty *pp = (StringProperty *)prop;
+ g_free (pp->string_data);
+ pp->string_data = g_strdup (value);
+ props = prop_list_from_single (prop);
+ } else if ((prop = object_prop_by_name_type (object, name, PROP_TYPE_TEXT)) != NULL) {
+ TextProperty *pp = (TextProperty *)prop;
+ g_free (pp->text_data);
+ pp->text_data = g_strdup (value);
+ props = prop_list_from_single (prop);
+ }
+ if (!props)
+ return NULL;
+
+ change = object_apply_props (object, props);
+ prop_list_free (props);
+ return change;
+}
diff --git a/plug-ins/pixbuf/pixbuf.c b/plug-ins/pixbuf/pixbuf.c
index b810388..b8bd536 100644
--- a/plug-ins/pixbuf/pixbuf.c
+++ b/plug-ins/pixbuf/pixbuf.c
@@ -30,8 +30,7 @@
#include "diagdkrenderer.h"
#include "filter.h"
#include "plug-ins.h"
-#include "prop_text.h"
-#include "prop_geomtypes.h"
+#include "properties.h"
#include "object.h"
static gboolean
@@ -124,19 +123,12 @@ import_data (const gchar *filename, DiagramData *data, DiaContext *ctx, void* us
obj = otype->ops->create(&point, otype->default_user_data, &h1, &h2);
if (obj)
{
- PropDescription prop_descs [] = {
- { "image_file", PROP_TYPE_FILE },
- { "elem_width", PROP_TYPE_REAL },
- { "elem_height", PROP_TYPE_REAL },
- PROP_DESC_END};
- GPtrArray *plist = prop_list_from_descs (prop_descs, pdtpp_true);
- StringProperty *strprop = g_ptr_array_index(plist, 0);
- RealProperty *realprop_w = g_ptr_array_index(plist, 1);
- RealProperty *realprop_h = g_ptr_array_index(plist, 2);
-
- strprop->string_data = g_strdup (filename);
- realprop_w->real_data = width / 20.0;
- realprop_h->real_data = height / 20.0;
+ GPtrArray *plist = g_ptr_array_new ();
+
+ prop_list_add_filename (plist, "image_file", filename);
+ prop_list_add_real (plist, "elem_width", width / 20.0);
+ prop_list_add_real (plist, "elem_height", height / 20.0);
+
obj->ops->set_props(obj, plist);
prop_list_free (plist);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]