[dia/zbrown/object-change: 5/16] group/element: port to DiaObjectChange
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/zbrown/object-change: 5/16] group/element: port to DiaObjectChange
- Date: Sat, 10 Oct 2020 22:05:56 +0000 (UTC)
commit 0e8b8ec3fd2a9befa4c790e4d6f1619b2d4358e9
Author: Zander Brown <zbrown gnome org>
Date: Tue Oct 6 23:12:37 2020 +0100
group/element: port to DiaObjectChange
lib/element.c | 46 +++++++++++++------
lib/element.h | 43 +++++++++++-------
lib/group.c | 141 +++++++++++++++++++++++++++++-----------------------------
lib/group.h | 10 +++--
4 files changed, 137 insertions(+), 103 deletions(-)
---
diff --git a/lib/element.c b/lib/element.c
index cf62628f7..e64bad590 100644
--- a/lib/element.c
+++ b/lib/element.c
@@ -569,21 +569,29 @@ element_load (Element *elem, ObjectNode obj_node, DiaContext *ctx)
}
-typedef struct _ElementChange {
- ObjectChange object_change;
+struct _DiaElementObjectChange {
+ DiaObjectChange object_change;
Element *element;
Point corner;
- real width;
- real height;
-} ElementChange;
+ double width;
+ double height;
+};
+
+
+DIA_DEFINE_OBJECT_CHANGE (DiaElementObjectChange, dia_element_object_change)
+
+
+static void
+dia_element_object_change_free (DiaObjectChange *self)
+{
+
+}
static void
-_element_change_swap (ObjectChange *self,
- DiaObject *obj)
+_element_change_swap (DiaElementObjectChange *ec, DiaObject *obj)
{
- ElementChange *ec = (ElementChange *) self;
Element *elem = ec->element;
Point tmppt;
real tmp;
@@ -596,24 +604,34 @@ _element_change_swap (ObjectChange *self,
}
+static void
+dia_element_object_change_revert (DiaObjectChange *self, DiaObject *obj)
+{
+ _element_change_swap (DIA_ELEMENT_OBJECT_CHANGE (self), obj);
+}
+
+
+static void
+dia_element_object_change_apply (DiaObjectChange *self, DiaObject *obj)
+{
+ _element_change_swap (DIA_ELEMENT_OBJECT_CHANGE (self), obj);
+}
+
+
DiaObjectChange *
element_change_new (const Point *corner,
double width,
double height,
Element *elem)
{
- ElementChange *ec = g_new0 (ElementChange, 1);
-
- ec->object_change.apply = _element_change_swap;
- ec->object_change.revert = _element_change_swap;
- ec->object_change.free = NULL;
+ DiaElementObjectChange *ec = dia_object_change_new (DIA_TYPE_ELEMENT_OBJECT_CHANGE);
ec->element = elem;
ec->corner = elem->corner;
ec->width = elem->width;
ec->height = elem->height;
- return dia_object_change_legacy_new ((ObjectChange *) ec);
+ return DIA_OBJECT_CHANGE (ec);
}
diff --git a/lib/element.h b/lib/element.h
index 801a95c6f..6f619f46b 100644
--- a/lib/element.h
+++ b/lib/element.h
@@ -17,8 +17,7 @@
*/
/* ** \file element.h -- Definition of a diagram - usual rectangular - object with eight handles */
-#ifndef ELEMENT_H
-#define ELEMENT_H
+#pragma once
#include "diatypes.h"
#include "object.h"
@@ -27,26 +26,40 @@
#include "boundingbox.h"
#include "properties.h" /* win32: PropNumData */
-/*!
- * \brief Beside OrthCon one of the most use object classes
+G_BEGIN_DECLS
+
+#define DIA_TYPE_ELEMENT_OBJECT_CHANGE dia_element_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaElementObjectChange, dia_element_object_change, DIA, ELEMENT_OBJECT_CHANGE,
DiaObjectChange)
+
+
+/**
+ * Element:
+ * @resize_handles: not only for resizing but may also be used for connections
+ * @corner: upper-left corner of the #Element
+ * @width: width of the object (with 0 line width)
+ * @height: height of the object (with 0 line width)
+ * @extra_spacing: extra data used for bounding box calculation, filled from
+ * line width
*
- * This is a subclass of DiaObject used to help implementing objects
- * of a type with 8 handles.
+ * Beside #OrthConn one of the most use object classes
*
- * \extends _DiaObject
+ * This is a subclass of #DiaObject used to help implementing objects
+ * of a type with 8 handles.
*/
struct _Element {
- DiaObject object; /* inheritance */
+ /* < private > */
+ DiaObject object;
- Handle resize_handles[8]; /*!< not only for resizing but may also be used for connections */
+ /* < public > */
+ Handle resize_handles[8];
- Point corner; /*!< upper-left corner of the Element */
- real width; /*!< width of the object (with 0 line width) */
- real height; /*!< height of the object (with 0 line width) */
- /*! extra data used for bounding box calculation */
- ElementBBExtras extra_spacing; /*!< filled from line width */
+ Point corner;
+ double width;
+ double height;
+ ElementBBExtras extra_spacing;
};
+
/*! \protected Update internal state after property change */
void element_update_handles(Element *elem);
void element_update_connections_rectangle(Element *elem,
@@ -118,4 +131,4 @@ extern PropNumData width_range;
{ "elem_width", PROP_TYPE_REAL, offsetof(Element, width) }, \
{ "elem_height", PROP_TYPE_REAL, offsetof(Element, height) }
-#endif /* ELEMENT_H */
+G_END_DECLS
diff --git a/lib/group.c b/lib/group.c
index 4badab1b9..de5dd9e14 100644
--- a/lib/group.c
+++ b/lib/group.c
@@ -44,21 +44,9 @@ struct _Group {
DiaMatrix *matrix;
};
-typedef struct _GroupPropChange GroupPropChange;
-struct _GroupPropChange {
- ObjectChange obj_change;
- Group *group;
- GList *changes_per_object;
-};
-
static DiaObjectChange *group_apply_properties_list (Group *group,
GPtrArray *props);
-static void group_prop_change_apply (GroupPropChange *change,
- DiaObject *obj);
-static void group_prop_change_revert (GroupPropChange *change,
- DiaObject *obj);
-static void group_prop_change_free (GroupPropChange *change);
static double group_distance_from (Group *group,
Point *point);
static void group_select (Group *group);
@@ -803,69 +791,29 @@ group_set_props(Group *group, GPtrArray *props)
}
-DiaObjectChange *
-group_apply_properties_list (Group *group, GPtrArray *props)
-{
- GList *tmp = NULL;
- GList *clist = NULL;
- DiaObjectChange *objchange;
- GroupPropChange *change = NULL;
- GPtrArray *props_list, *props_self;
- guint i;
-
- change = g_new0(GroupPropChange, 1);
-
-
- change->obj_change.apply =
- (ObjectChangeApplyFunc) group_prop_change_apply;
- change->obj_change.revert =
- (ObjectChangeRevertFunc) group_prop_change_revert;
- change->obj_change.free =
- (ObjectChangeFreeFunc) group_prop_change_free;
-
- change->group = group;
-
- /* Need to split the passed in properties to self props
- * and the ones really passed to the list of owned objects.
- */
- props_self = g_ptr_array_new();
- props_list = g_ptr_array_new();
- for (i=0; i < props->len; ++i) {
- Property *p = g_ptr_array_index(props,i);
-
- if (p->experience & PXP_NOTSET)
- continue;
- else if ((p->descr->flags & PROP_FLAG_SELF_ONLY) != 0)
- g_ptr_array_add(props_self, p);
- else
- g_ptr_array_add(props_list, p);
- }
-
- for (tmp = group->objects; tmp != NULL; tmp = g_list_next (tmp)) {
- DiaObject *obj = (DiaObject*) tmp->data;
- objchange = NULL;
+struct _DiaGroupObjectChange {
+ DiaObjectChange obj_change;
+ Group *group;
+ GList *changes_per_object;
+};
- objchange = dia_object_apply_properties (obj, props_list);
- clist = g_list_append (clist, objchange);
- }
- /* finally ourself */
- objchange = object_apply_props (&group->object, props_self);
- clist = g_list_append (clist, objchange);
- g_ptr_array_free(props_list, TRUE);
- g_ptr_array_free(props_self, TRUE);
+DIA_DEFINE_OBJECT_CHANGE (DiaGroupObjectChange, dia_group_object_change)
- group_update_data (group);
- change->changes_per_object = clist;
+static void
+dia_group_object_change_free (DiaObjectChange *self)
+{
+ DiaGroupObjectChange *change = DIA_GROUP_OBJECT_CHANGE (self);
- return dia_object_change_legacy_new ((ObjectChange *) change);
+ g_list_free_full (change->changes_per_object, dia_object_change_unref);
}
static void
-group_prop_change_apply (GroupPropChange *change, DiaObject *obj)
+dia_group_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
+ DiaGroupObjectChange *change = DIA_GROUP_OBJECT_CHANGE (self);
GList *tmp;
for (tmp = change->changes_per_object; tmp != NULL;
@@ -886,12 +834,13 @@ group_prop_change_apply (GroupPropChange *change, DiaObject *obj)
static void
-group_prop_change_revert (GroupPropChange *change, DiaObject *obj)
+dia_group_object_change_revert (DiaObjectChange *self, DiaObject *obj)
{
+ DiaGroupObjectChange *change = DIA_GROUP_OBJECT_CHANGE (self);
GList *tmp;
for (tmp = change->changes_per_object; tmp != NULL;
- tmp = g_list_next(tmp)) {
+ tmp = g_list_next (tmp)) {
DiaObjectChange *obj_change = DIA_OBJECT_CHANGE (tmp->data);
/*
@@ -907,10 +856,62 @@ group_prop_change_revert (GroupPropChange *change, DiaObject *obj)
}
-static void
-group_prop_change_free (GroupPropChange *change)
+static DiaObjectChange *
+dia_group_object_change_new (Group *group, GList *changes_per_object)
{
- g_list_free_full (change->changes_per_object, dia_object_change_unref);
+ DiaGroupObjectChange *self = dia_object_change_new (DIA_TYPE_GROUP_OBJECT_CHANGE);
+
+ self->group = group;
+ self->changes_per_object = changes_per_object;
+
+ return DIA_OBJECT_CHANGE (self);
+}
+
+
+DiaObjectChange *
+group_apply_properties_list (Group *group, GPtrArray *props)
+{
+ GList *tmp = NULL;
+ GList *clist = NULL;
+ DiaObjectChange *objchange;
+ GPtrArray *props_list, *props_self;
+ guint i;
+
+ /* Need to split the passed in properties to self props
+ * and the ones really passed to the list of owned objects.
+ */
+ props_self = g_ptr_array_new ();
+ props_list = g_ptr_array_new ();
+ for (i=0; i < props->len; ++i) {
+ Property *p = g_ptr_array_index (props,i);
+
+ if (p->experience & PXP_NOTSET) {
+ continue;
+ } else if ((p->descr->flags & PROP_FLAG_SELF_ONLY) != 0) {
+ g_ptr_array_add (props_self, p);
+ } else {
+ g_ptr_array_add (props_list, p);
+ }
+ }
+
+ for (tmp = group->objects; tmp != NULL; tmp = g_list_next (tmp)) {
+ DiaObject *obj = (DiaObject*) tmp->data;
+ objchange = NULL;
+
+ objchange = dia_object_apply_properties (obj, props_list);
+ clist = g_list_append (clist, objchange);
+ }
+
+ /* finally ourself */
+ objchange = object_apply_props (&group->object, props_self);
+ clist = g_list_append (clist, objchange);
+
+ g_ptr_array_free (props_list, TRUE);
+ g_ptr_array_free (props_self, TRUE);
+
+ group_update_data (group);
+
+ return dia_group_object_change_new (group, clist);
}
diff --git a/lib/group.h b/lib/group.h
index 35c433495..51cc96a0e 100644
--- a/lib/group.h
+++ b/lib/group.h
@@ -15,14 +15,18 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef GROUP_H
-#define GROUP_H
+
+#pragma once
#include "diavar.h"
#include "object.h"
G_BEGIN_DECLS
+#define DIA_TYPE_GROUP_OBJECT_CHANGE dia_group_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaGroupObjectChange, dia_group_object_change, DIA, GROUP_OBJECT_CHANGE,
DiaObjectChange)
+
+
#define DIA_GROUP(object) ((Group *) object)
extern DIAVAR DiaObjectType group_type;
@@ -40,5 +44,3 @@ const DiaMatrix *group_get_transform (Group *group);
#define IS_GROUP(obj) ((obj)->type == &group_type)
G_END_DECLS
-
-#endif /* GROUP_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]