[dia/zbrown/object-change: 14/16] objects: port to DiaObjectChange
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/zbrown/object-change: 14/16] objects: port to DiaObjectChange
- Date: Sat, 10 Oct 2020 22:05:56 +0000 (UTC)
commit 20a81093f0ea7fde77b60ab7facfffef8280d53b
Author: Zander Brown <zbrown gnome org>
Date: Sat Oct 10 22:28:34 2020 +0100
objects: port to DiaObjectChange
objects/ER/attribute.c | 2 +-
objects/GRAFCET/vergent.c | 40 +++++++++++++++++++++++++-------------
objects/Misc/tree.c | 47 ++++++++++++++++++++++++++++++---------------
objects/network/bus.c | 49 +++++++++++++++++++++++++++++++----------------
4 files changed, 92 insertions(+), 46 deletions(-)
---
diff --git a/objects/ER/attribute.c b/objects/ER/attribute.c
index 917d789cf..d9bfec0b7 100644
--- a/objects/ER/attribute.c
+++ b/objects/ER/attribute.c
@@ -31,7 +31,7 @@
#include "diarenderer.h"
#include "attributes.h"
#include "properties.h"
-#include "dia-object-change-legacy.h"
+#include "objchange.h"
#include "pixmaps/attribute.xpm"
diff --git a/objects/GRAFCET/vergent.c b/objects/GRAFCET/vergent.c
index 2b17eab58..a25f3dc35 100644
--- a/objects/GRAFCET/vergent.c
+++ b/objects/GRAFCET/vergent.c
@@ -34,7 +34,6 @@
#include "properties.h"
#include "geometry.h"
#include "connpoint_line.h"
-#include "dia-object-change-legacy.h"
#include "grafcet.h"
@@ -379,32 +378,50 @@ vergent_update_data (Vergent *vergent)
/* DiaObject menu handling */
-typedef struct {
- ObjectChange obj_change;
+
+#define DIA_GRAFCET_TYPE_VERGENT_OBJECT_CHANGE dia_grafcet_vergent_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaGRAFCETVergentObjectChange,
+ dia_grafcet_vergent_object_change,
+ DIA_GRAFCET, VERGENT_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
+struct _DiaGRAFCETVergentObjectChange {
+ DiaObjectChange obj_change;
DiaObjectChange *north, *south;
-} VergentChange;
+};
+
+
+DIA_DEFINE_OBJECT_CHANGE (DiaGRAFCETVergentObjectChange,
+ dia_grafcet_vergent_object_change)
static void
-vergent_change_apply (VergentChange *change, DiaObject *obj)
+dia_grafcet_vergent_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
+ DiaGRAFCETVergentObjectChange *change = DIA_GRAFCET_VERGENT_OBJECT_CHANGE (self);
+
dia_object_change_apply (change->north, obj);
dia_object_change_apply (change->south, obj);
}
static void
-vergent_change_revert (VergentChange *change, DiaObject *obj)
+dia_grafcet_vergent_object_change_revert (DiaObjectChange *self, DiaObject *obj)
{
+ DiaGRAFCETVergentObjectChange *change = DIA_GRAFCET_VERGENT_OBJECT_CHANGE (self);
+
dia_object_change_revert (change->north,obj);
dia_object_change_revert (change->south,obj);
}
static void
-vergent_change_free (VergentChange *change)
+dia_grafcet_vergent_object_change_free (DiaObjectChange *self)
{
+ DiaGRAFCETVergentObjectChange *change = DIA_GRAFCET_VERGENT_OBJECT_CHANGE (self);
+
g_clear_pointer (&change->north, dia_object_change_unref);
g_clear_pointer (&change->south, dia_object_change_unref);
}
@@ -413,12 +430,9 @@ vergent_change_free (VergentChange *change)
static DiaObjectChange *
vergent_create_change (Vergent *vergent, int add, Point *clicked)
{
- VergentChange *vc;
+ DiaGRAFCETVergentObjectChange *vc;
- vc = g_new0 (VergentChange,1);
- vc->obj_change.apply = (ObjectChangeApplyFunc) vergent_change_apply;
- vc->obj_change.revert = (ObjectChangeRevertFunc) vergent_change_revert;
- vc->obj_change.free = (ObjectChangeFreeFunc) vergent_change_free;
+ vc = dia_object_change_new (DIA_GRAFCET_TYPE_VERGENT_OBJECT_CHANGE);
if (add) {
vc->north = connpointline_add_point (vergent->north,clicked);
@@ -430,7 +444,7 @@ vergent_create_change (Vergent *vergent, int add, Point *clicked)
vergent_update_data (vergent);
- return dia_object_change_legacy_new ((ObjectChange *) vc);
+ return DIA_OBJECT_CHANGE (vc);
}
diff --git a/objects/Misc/tree.c b/objects/Misc/tree.c
index 0269108e6..d09d956f2 100644
--- a/objects/Misc/tree.c
+++ b/objects/Misc/tree.c
@@ -29,7 +29,6 @@
#include "attributes.h"
#include "properties.h"
#include "diamenu.h"
-#include "dia-object-change-legacy.h"
#include "pixmaps/tree.xpm"
@@ -49,13 +48,22 @@ typedef struct _Tree {
Color line_color;
} Tree;
+
+#define DIA_MISC_TYPE_TREE_OBJECT_CHANGE dia_misc_tree_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaMiscTreeObjectChange,
+ dia_misc_tree_object_change,
+ DIA_MISC, TREE_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
enum change_type {
TYPE_ADD_POINT,
TYPE_REMOVE_POINT
};
-struct PointChange {
- ObjectChange obj_change;
+
+struct _DiaMiscTreeObjectChange {
+ DiaObjectChange obj_change;
enum change_type type;
int applied;
@@ -66,6 +74,10 @@ struct PointChange {
ConnectionPoint *connected_to; /* NULL if not connected */
};
+
+DIA_DEFINE_OBJECT_CHANGE (DiaMiscTreeObjectChange, dia_misc_tree_object_change)
+
+
static DiaObjectChange *tree_move_handle (Tree *tree,
Handle *handle,
Point *to,
@@ -705,19 +717,24 @@ tree_load(ObjectNode obj_node, int version,DiaContext *ctx)
return &tree->connection.object;
}
+
static void
-tree_change_free(struct PointChange *change)
+dia_misc_tree_object_change_free (DiaObjectChange *self)
{
- if ( (change->type==TYPE_ADD_POINT && !change->applied) ||
- (change->type==TYPE_REMOVE_POINT && change->applied) ){
+ DiaMiscTreeObjectChange *change = DIA_MISC_TREE_OBJECT_CHANGE (self);
+
+ if ((change->type == TYPE_ADD_POINT && !change->applied) ||
+ (change->type == TYPE_REMOVE_POINT && change->applied) ){
g_clear_pointer (&change->handle, g_free);
}
}
static void
-tree_change_apply (struct PointChange *change, DiaObject *obj)
+dia_misc_tree_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
+ DiaMiscTreeObjectChange *change = DIA_MISC_TREE_OBJECT_CHANGE (self);
+
change->applied = 1;
switch (change->type) {
@@ -736,8 +753,10 @@ tree_change_apply (struct PointChange *change, DiaObject *obj)
static void
-tree_change_revert (struct PointChange *change, DiaObject *obj)
+dia_misc_tree_object_change_revert (DiaObjectChange *self, DiaObject *obj)
{
+ DiaMiscTreeObjectChange *change = DIA_MISC_TREE_OBJECT_CHANGE (self);
+
switch (change->type) {
case TYPE_ADD_POINT:
tree_remove_handle ((Tree *) obj, change->handle);
@@ -751,7 +770,9 @@ tree_change_revert (struct PointChange *change, DiaObject *obj)
default:
g_return_if_reached ();
}
+
tree_update_data ((Tree *) obj);
+
change->applied = 0;
}
@@ -763,13 +784,9 @@ tree_create_change (Tree *tree,
Handle *handle,
ConnectionPoint *connected_to)
{
- struct PointChange *change;
-
- change = g_new0(struct PointChange, 1);
+ DiaMiscTreeObjectChange *change;
- change->obj_change.apply = (ObjectChangeApplyFunc) tree_change_apply;
- change->obj_change.revert = (ObjectChangeRevertFunc) tree_change_revert;
- change->obj_change.free = (ObjectChangeFreeFunc) tree_change_free;
+ change = dia_object_change_new (DIA_MISC_TYPE_TREE_OBJECT_CHANGE);
change->type = type;
change->applied = 1;
@@ -777,5 +794,5 @@ tree_create_change (Tree *tree,
change->handle = handle;
change->connected_to = connected_to;
- return dia_object_change_legacy_new ((ObjectChange *) change);
+ return DIA_OBJECT_CHANGE (change);
}
diff --git a/objects/network/bus.c b/objects/network/bus.c
index 75e745705..6ba087bca 100644
--- a/objects/network/bus.c
+++ b/objects/network/bus.c
@@ -29,7 +29,6 @@
#include "attributes.h"
#include "diamenu.h"
#include "properties.h"
-#include "dia-object-change-legacy.h"
#include "pixmaps/bus.xpm"
@@ -49,13 +48,22 @@ typedef struct _Bus {
Color line_color;
} Bus;
+
+#define DIA_NET_TYPE_BUS_OBJECT_CHANGE dia_net_bus_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaNetBusObjectChange,
+ dia_net_bus_object_change,
+ DIA_NET, BUS_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
enum change_type {
TYPE_ADD_POINT,
TYPE_REMOVE_POINT
};
-struct PointChange {
- ObjectChange obj_change;
+
+struct _DiaNetBusObjectChange {
+ DiaObjectChange obj_change;
enum change_type type;
int applied;
@@ -67,6 +75,9 @@ struct PointChange {
};
+DIA_DEFINE_OBJECT_CHANGE (DiaNetBusObjectChange, dia_net_bus_object_change)
+
+
static DiaObjectChange* bus_move_handle (Bus *bus,
Handle *handle,
Point *to,
@@ -705,19 +716,24 @@ bus_load(ObjectNode obj_node, int version,DiaContext *ctx)
return &bus->connection.object;
}
+
static void
-bus_change_free(struct PointChange *change)
+dia_net_bus_object_change_free (DiaObjectChange *self)
{
- if ( (change->type==TYPE_ADD_POINT && !change->applied) ||
- (change->type==TYPE_REMOVE_POINT && change->applied) ){
+ DiaNetBusObjectChange *change = DIA_NET_BUS_OBJECT_CHANGE (self);
+
+ if ((change->type == TYPE_ADD_POINT && !change->applied) ||
+ (change->type == TYPE_REMOVE_POINT && change->applied) ){
g_clear_pointer (&change->handle, g_free);
}
}
static void
-bus_change_apply (struct PointChange *change, DiaObject *obj)
+dia_net_bus_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
+ DiaNetBusObjectChange *change = DIA_NET_BUS_OBJECT_CHANGE (self);
+
change->applied = 1;
switch (change->type) {
@@ -737,14 +753,16 @@ bus_change_apply (struct PointChange *change, DiaObject *obj)
static void
-bus_change_revert (struct PointChange *change, DiaObject *obj)
+dia_net_bus_object_change_revert (DiaObjectChange *self, DiaObject *obj)
{
+ DiaNetBusObjectChange *change = DIA_NET_BUS_OBJECT_CHANGE (self);
+
switch (change->type) {
case TYPE_ADD_POINT:
- bus_remove_handle ((Bus *)obj, change->handle);
+ bus_remove_handle ((Bus *) obj, change->handle);
break;
case TYPE_REMOVE_POINT:
- bus_add_handle ((Bus *)obj, &change->point, change->handle);
+ bus_add_handle ((Bus *) obj, &change->point, change->handle);
if (change->connected_to) {
object_connect (obj, change->handle, change->connected_to);
}
@@ -754,6 +772,7 @@ bus_change_revert (struct PointChange *change, DiaObject *obj)
}
bus_update_data ((Bus *) obj);
+
change->applied = 0;
}
@@ -765,13 +784,9 @@ bus_create_change (Bus *bus,
Handle *handle,
ConnectionPoint *connected_to)
{
- struct PointChange *change;
-
- change = g_new0(struct PointChange, 1);
+ DiaNetBusObjectChange *change;
- change->obj_change.apply = (ObjectChangeApplyFunc) bus_change_apply;
- change->obj_change.revert = (ObjectChangeRevertFunc) bus_change_revert;
- change->obj_change.free = (ObjectChangeFreeFunc) bus_change_free;
+ change = dia_object_change_new (DIA_NET_TYPE_BUS_OBJECT_CHANGE);
change->type = type;
change->applied = 1;
@@ -779,5 +794,5 @@ bus_create_change (Bus *bus,
change->handle = handle;
change->connected_to = connected_to;
- return dia_object_change_legacy_new ((ObjectChange *) change);
+ return DIA_OBJECT_CHANGE (change);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]