[dia] [restructuring] introduce DiaObjectType::prop_descs to reduce code
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] [restructuring] introduce DiaObjectType::prop_descs to reduce code
- Date: Wed, 3 Oct 2012 20:02:10 +0000 (UTC)
commit 13048335f81e0ff38ad77e329995b4ebcd7bddf2
Author: Hans Breuer <hans breuer org>
Date: Sat Sep 29 23:00:57 2012 +0200
[restructuring] introduce DiaObjectType::prop_descs to reduce code
Most of DiaObject::describe_props() and DiaObject::get_props() can
be implemented by the base class this way. So just put
object_describe_props() and object_get_props() into the vtable.
ATM get_props implementations calling e.g.
text_get_attributes(textobj->text,&textobj->attrs);
need to stay, but pure delegates to
object_get_props_from_offsets()
can vanish.
lib/libdia.def | 2 ++
lib/object.h | 9 +++++----
lib/properties.h | 22 ++++++++++++++++++++--
lib/propobject.c | 21 +++++++++++++++++++++
4 files changed, 48 insertions(+), 6 deletions(-)
---
diff --git a/lib/libdia.def b/lib/libdia.def
index 5ec813d..62aaa92 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -517,10 +517,12 @@ EXPORTS
object_copy_props
object_copy_using_properties
object_create_props_dialog
+ object_describe_props
object_destroy
object_find_attribute
object_flags_set
object_get_prop_descriptions
+ object_get_props
object_get_props_from_offsets
object_get_type
object_get_displayname
diff --git a/lib/object.h b/lib/object.h
index 7782ea4..5ab0ab2 100644
--- a/lib/object.h
+++ b/lib/object.h
@@ -538,15 +538,16 @@ struct _DiaObjectType {
char *name; /*!< The type name should follow a pattern of '\<module\> - \<class\>' like "UML - Class" */
int version; /*!< DiaObjects must be backward compatible, i.e. support possibly older versions formats */
- char **pixmap; /*! Also put a pixmap in the sheet_object.
+ char **pixmap; /*!< Also put a pixmap in the sheet_object.
This one is used if not in sheet but in toolbar.
Stored in xpm format */
ObjectTypeOps *ops; /* pointer to the vtable */
- char *pixmap_file; /*! fallback if pixmap is NULL */
- void *default_user_data; /*! use this if no user data is specified in
- the .sheet file */
+ char *pixmap_file; /*!< fallback if pixmap is NULL */
+ void *default_user_data; /*!< use this if no user data is specified in the .sheet file */
+ const PropDescription *prop_descs; /*!< property descriptions */
+ const PropOffset *prop_offsets; /*!< DiaObject struct offsets */
};
/* base property stuff ... */
diff --git a/lib/properties.h b/lib/properties.h
index 8fe6fdc..a738ba8 100644
--- a/lib/properties.h
+++ b/lib/properties.h
@@ -509,14 +509,32 @@ gboolean object_set_props_from_offsets(DiaObject *obj, PropOffset *offsets,
ObjectChange *object_apply_props(DiaObject *obj, GPtrArray *props);
ObjectChange *object_toggle_prop (DiaObject *obj, const char *pname, gboolean val);
-/* standard properties dialogs that can be used for objects that
+/*!
+ * \brief Creation of object specific property dialog
+ * \memberof DiaObject
+ * standard properties dialogs that can be used for objects that
* implement describe_props, get_props and set_props.
* If is_default is set, this is a default dialog, not an object dialog.
*/
WIDGET *object_create_props_dialog (DiaObject *obj, gboolean is_default);
WIDGET *object_list_create_props_dialog(GList *obj, gboolean is_default);
ObjectChange *object_apply_props_from_dialog (DiaObject *obj, WIDGET *dialog);
-
+/*!
+ * \brief Descibe objects properties
+ * \memberof DiaObject
+ * Default implementaiton to describe an objects properties, relies on
+ * DiaObjectType::prop_descs being initialized to the list of property
+ * descriptions.
+ */
+const PropDescription *object_describe_props (DiaObject *obj);
+/*!
+ * \brief Descibe objects properties
+ * \memberof DiaObject
+ * Default implementaiton to get an objects properties, relies on
+ * DiaObjectType::prop_offsets being initialized to the list of property
+ * offsets.
+ */
+void object_get_props(DiaObject *obj, GPtrArray *props);
/* create a property from the object's property descriptors. To be freed with
prop->ops->free(prop); or put it into a single property list. NULL if object
has nothing matching. Property's value is initialised by the object.
diff --git a/lib/propobject.c b/lib/propobject.c
index f9b1f0f..863e828 100644
--- a/lib/propobject.c
+++ b/lib/propobject.c
@@ -79,6 +79,27 @@ object_list_get_prop_descriptions(GList *objects, PropMergeOption option)
return pdesc;
}
+const PropDescription *
+object_describe_props (DiaObject *obj)
+{
+ const PropDescription *props = obj->type->prop_descs;
+
+ g_return_val_if_fail (props != NULL, NULL);
+
+ if (props[0].quark == 0)
+ prop_desc_list_calculate_quarks((PropDescription *)props);
+ return props;
+}
+
+void
+object_get_props(DiaObject *obj, GPtrArray *props)
+{
+ const PropOffset *offsets = obj->type->prop_offsets;
+
+ g_return_if_fail (offsets != NULL);
+
+ object_get_props_from_offsets(obj, (PropOffset *)offsets, props);
+}
/* ------------------------------------------------------ */
/* Change management */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]