[dia/zbrown/object-change: 10/16] aadl: port to DiaObjectChange
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/zbrown/object-change: 10/16] aadl: port to DiaObjectChange
- Date: Sat, 10 Oct 2020 22:05:56 +0000 (UTC)
commit a7abf7aed60d0a25896f9a90ed2ce04bfaf5a704
Author: Zander Brown <zbrown gnome org>
Date: Sat Oct 10 22:16:47 2020 +0100
aadl: port to DiaObjectChange
objects/AADL/aadl.h | 7 +++++
objects/AADL/aadlbox.c | 34 +++++++++++----------
objects/AADL/edit_port_declaration.c | 58 +++++++++++++++++++-----------------
objects/AADL/edit_port_declaration.h | 12 ++++++++
4 files changed, 68 insertions(+), 43 deletions(-)
---
diff --git a/objects/AADL/aadl.h b/objects/AADL/aadl.h
index 526e7190d..7fa0170ef 100644
--- a/objects/AADL/aadl.h
+++ b/objects/AADL/aadl.h
@@ -33,6 +33,13 @@
#include "text.h"
#include "properties.h"
+#define DIA_AADL_TYPE_POINT_OBJECT_CHANGE dia_aadl_point_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaAADLPointObjectChange,
+ dia_aadl_point_object_change,
+ DIA_AADL, POINT_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
#undef min
#define min(a,b) (a<b?a:b)
#undef max
diff --git a/objects/AADL/aadlbox.c b/objects/AADL/aadlbox.c
index 2cb4e9fd5..059687cd4 100644
--- a/objects/AADL/aadlbox.c
+++ b/objects/AADL/aadlbox.c
@@ -35,8 +35,6 @@
#include "aadl.h"
#include "edit_port_declaration.h"
-#include "dia-object-change-legacy.h"
-
#define PORT_HANDLE_AADLBOX (HANDLE_CUSTOM9)
@@ -69,8 +67,9 @@ enum change_type {
TYPE_REMOVE_CONNECTION
};
-struct PointChange {
- ObjectChange obj_change;
+
+struct _DiaAADLPointObjectChange {
+ DiaObjectChange obj_change;
enum change_type type;
int applied;
@@ -80,9 +79,12 @@ struct PointChange {
owning ref when applied for REMOVE_POINT */
ConnectionPoint *connection;
-
};
+
+DIA_DEFINE_OBJECT_CHANGE (DiaAADLPointObjectChange, dia_aadl_point_object_change)
+
+
static void aadlbox_update_data(Aadlbox *aadlbox);
static void aadlbox_add_port(Aadlbox *aadlbox, const Point *p, Aadlport *port);
static void aadlbox_remove_port(Aadlbox *aadlbox, Aadlport *port);
@@ -241,8 +243,10 @@ DiaObject *aadlbox_copy(DiaObject *obj)
static void
-aadlbox_change_free(struct PointChange *change)
+dia_aadl_point_object_change_free (DiaObjectChange *self)
{
+ DiaAADLPointObjectChange *change = DIA_AADL_POINT_OBJECT_CHANGE (self);
+
if ( (change->type==TYPE_ADD_POINT && !change->applied) ||
(change->type==TYPE_REMOVE_POINT && change->applied) ) {
@@ -257,8 +261,10 @@ aadlbox_change_free(struct PointChange *change)
static void
-aadlbox_change_apply (struct PointChange *change, DiaObject *obj)
+dia_aadl_point_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
+ DiaAADLPointObjectChange *change = DIA_AADL_POINT_OBJECT_CHANGE (self);
+
change->applied = 1;
switch (change->type) {
case TYPE_ADD_POINT:
@@ -282,8 +288,10 @@ aadlbox_change_apply (struct PointChange *change, DiaObject *obj)
static void
-aadlbox_change_revert (struct PointChange *change, DiaObject *obj)
+dia_aadl_point_object_change_revert (DiaObjectChange *self, DiaObject *obj)
{
+ DiaAADLPointObjectChange *change = DIA_AADL_POINT_OBJECT_CHANGE (self);
+
switch (change->type) {
case TYPE_ADD_POINT:
aadlbox_remove_port((Aadlbox *)obj, change->port);
@@ -316,13 +324,9 @@ aadlbox_create_change (Aadlbox *aadlbox,
Point *point,
void *data)
{
- struct PointChange *change;
-
- change = g_new0 (struct PointChange, 1);
+ DiaAADLPointObjectChange *change;
- change->obj_change.apply = (ObjectChangeApplyFunc) aadlbox_change_apply;
- change->obj_change.revert = (ObjectChangeRevertFunc) aadlbox_change_revert;
- change->obj_change.free = (ObjectChangeFreeFunc) aadlbox_change_free;
+ change = dia_object_change_new (DIA_AADL_TYPE_POINT_OBJECT_CHANGE);
change->type = type;
change->applied = 1;
@@ -343,7 +347,7 @@ aadlbox_create_change (Aadlbox *aadlbox,
g_return_val_if_reached (NULL);
}
- return dia_object_change_legacy_new ((ObjectChange *) change);
+ return DIA_OBJECT_CHANGE (change);
}
diff --git a/objects/AADL/edit_port_declaration.c b/objects/AADL/edit_port_declaration.c
index e786fe983..045255683 100644
--- a/objects/AADL/edit_port_declaration.c
+++ b/objects/AADL/edit_port_declaration.c
@@ -24,7 +24,6 @@
#include <string.h>
#include "aadl.h"
#include "edit_port_declaration.h"
-#include "dia-object-change-legacy.h"
int aadlbox_point_near_port(Aadlbox *aadlbox, Point *p);
@@ -35,21 +34,27 @@ int aadlbox_point_near_port(Aadlbox *aadlbox, Point *p);
** U N D O / R E D O **
***********************************************/
-struct EditPortDeclarationChange
-{
- ObjectChange obj_change;
+struct _DiaAADLEditPortDeclarationObjectChange {
+ DiaObjectChange obj_change;
int applied;
int port_num;
- gchar *oldvalue;
- gchar *newvalue;
+ char *oldvalue;
+ char *newvalue;
};
-static void edit_port_declaration_apply
- (struct EditPortDeclarationChange *change, DiaObject *obj)
+
+DIA_DEFINE_OBJECT_CHANGE (DiaAADLEditPortDeclarationObjectChange,
+ dia_aadl_edit_port_declaration_object_change)
+
+
+static void
+dia_aadl_edit_port_declaration_object_change_apply (DiaObjectChange *self,
+ DiaObject *obj)
{
+ DiaAADLEditPortDeclarationObjectChange *change = DIA_AADL_EDIT_PORT_DECLARATION_OBJECT_CHANGE (self);
Aadlbox *aadlbox = (Aadlbox *) obj;
int port_num = change->port_num;
@@ -58,23 +63,30 @@ static void edit_port_declaration_apply
}
-static void edit_port_declaration_revert
- (struct EditPortDeclarationChange *change, DiaObject *obj)
+
+static void
+dia_aadl_edit_port_declaration_object_change_revert (DiaObjectChange *self,
+ DiaObject *obj)
{
+ DiaAADLEditPortDeclarationObjectChange *change = DIA_AADL_EDIT_PORT_DECLARATION_OBJECT_CHANGE (self);
Aadlbox *aadlbox = (Aadlbox *) obj;
int port_num = change->port_num;
change->applied = 0;
aadlbox->ports[port_num]->declaration = change->oldvalue;
-
}
-static void edit_port_declaration_free (struct EditPortDeclarationChange *change)
+
+static void
+dia_aadl_edit_port_declaration_object_change_free (DiaObjectChange *self)
{
- if (change->applied)
+ DiaAADLEditPortDeclarationObjectChange *change = DIA_AADL_EDIT_PORT_DECLARATION_OBJECT_CHANGE (self);
+
+ if (change->applied) {
g_clear_pointer (&change->oldvalue, g_free);
- else
+ } else {
g_clear_pointer (&change->newvalue, g_free);
+ }
}
@@ -130,7 +142,7 @@ edit_port_declaration_callback (DiaObject *obj,
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *button;
- struct EditPortDeclarationChange *change;
+ DiaAADLEditPortDeclarationObjectChange *change;
Aadlport *port;
Aadlbox *aadlbox = (Aadlbox *) obj;
int port_num;
@@ -191,24 +203,14 @@ edit_port_declaration_callback (DiaObject *obj,
/* Text has been edited - widgets destroyed */
- change = (struct EditPortDeclarationChange *)
- g_malloc (sizeof(struct EditPortDeclarationChange));
-
- change->obj_change.apply =
- (ObjectChangeApplyFunc) edit_port_declaration_apply;
-
- change->obj_change.revert =
- (ObjectChangeRevertFunc) edit_port_declaration_revert;
-
- change->obj_change.free =
- (ObjectChangeFreeFunc) edit_port_declaration_free;
+ change = dia_object_change_new (DIA_AADL_TYPE_EDIT_PORT_DECLARATION_OBJECT_CHANGE);
change->port_num = port_num;
change->newvalue = text;
change->oldvalue = aadlbox->ports[port_num]->declaration;
- change->obj_change.apply((ObjectChange *)change, obj);
+ dia_object_change_apply (DIA_OBJECT_CHANGE (change), obj);
- return dia_object_change_legacy_new ((ObjectChange *) change);
+ return DIA_OBJECT_CHANGE (change);
}
diff --git a/objects/AADL/edit_port_declaration.h b/objects/AADL/edit_port_declaration.h
index 60ea967b9..268f84c14 100644
--- a/objects/AADL/edit_port_declaration.h
+++ b/objects/AADL/edit_port_declaration.h
@@ -18,7 +18,19 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#pragma once
+
+G_BEGIN_DECLS
+
+#define DIA_AADL_TYPE_EDIT_PORT_DECLARATION_OBJECT_CHANGE
dia_aadl_edit_port_declaration_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaAADLEditPortDeclarationObjectChange,
+ dia_aadl_edit_port_declaration_object_change,
+ DIA_AADL, EDIT_PORT_DECLARATION_OBJECT_CHANGE,
+ DiaObjectChange)
+
DiaObjectChange *edit_port_declaration_callback (DiaObject *obj,
Point *clicked,
gpointer data);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]