[dia/zbrown/object-change: 8/16] uml: port to DiaObjectChange
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/zbrown/object-change: 8/16] uml: port to DiaObjectChange
- Date: Sat, 10 Oct 2020 22:05:56 +0000 (UTC)
commit e99e9d870157b9001951452476f2864fc77d62ac
Author: Zander Brown <zbrown gnome org>
Date: Sat Oct 10 22:12:13 2020 +0100
uml: port to DiaObjectChange
objects/UML/association.c | 8 +++--
objects/UML/class.c | 16 ++++++----
objects/UML/class_dialog.c | 73 +++++++++++++++++++++++-----------------------
objects/UML/class_dialog.h | 14 +++++++++
objects/UML/lifeline.c | 42 +++++++++++++++++---------
5 files changed, 94 insertions(+), 59 deletions(-)
---
diff --git a/objects/UML/association.c b/objects/UML/association.c
index c15c84277..d7dd258ae 100644
--- a/objects/UML/association.c
+++ b/objects/UML/association.c
@@ -61,8 +61,8 @@
#include "attributes.h"
#include "arrows.h"
#include "uml.h"
-#include "dia-object-change-legacy.h"
#include "properties.h"
+#include "objchange.h"
#include "pixmaps/association.xpm"
@@ -101,6 +101,7 @@ typedef struct _AssociationEnd {
AggregateType aggregate; /* Note: Can only be != NONE on ONE side! */
} AssociationEnd;
+
struct _AssociationState {
ObjectState obj_state;
@@ -190,8 +191,8 @@ static ObjectTypeOps association_type_ops =
(SaveFunc) object_save_using_properties
};
-DiaObjectType association_type =
-{
+
+DiaObjectType association_type = {
"UML - Association", /* name */
/* Version 0 had no autorouting and so shouldn't have it set by default. */
/* Version 1 was saving both ends separately without using StdProps */
@@ -202,6 +203,7 @@ DiaObjectType association_type =
0 /* default_user_data */
};
+
static ObjectOps association_ops = {
(DestroyFunc) association_destroy,
(DrawFunc) association_draw,
diff --git a/objects/UML/class.c b/objects/UML/class.c
index b945770b1..62295fd9f 100644
--- a/objects/UML/class.c
+++ b/objects/UML/class.c
@@ -34,8 +34,8 @@
#include "attributes.h"
#include "properties.h"
#include "diamenu.h"
-#include "dia-object-change-legacy.h"
#include "class.h"
+#include "objchange.h"
#include "pixmaps/umlclass.xpm"
@@ -378,10 +378,13 @@ umlclass_object_menu(DiaObject *obj, Point *p)
return ¨class_menu;
}
+
typedef struct _CommentState {
ObjectState state;
gboolean visible_comments;
} CommentState;
+
+
static ObjectState*
_comment_get_state (DiaObject *obj)
{
@@ -405,15 +408,16 @@ _comment_set_state (DiaObject *obj, ObjectState *state)
static DiaObjectChange *
umlclass_show_comments_callback (DiaObject *obj, Point *pos, gpointer data)
{
- ObjectState *old_state = _comment_get_state(obj);
- DiaObjectChange *change = new_object_state_change (obj,
- old_state,
- _comment_get_state,
- _comment_set_state );
+ ObjectState *old_state = _comment_get_state (obj);
+ DiaObjectChange *change = dia_state_object_change_new (obj,
+ old_state,
+ _comment_get_state,
+ _comment_set_state);
((UMLClass *) obj)->visible_comments = !((UMLClass *) obj)->visible_comments;
umlclass_calculate_data ((UMLClass *) obj);
umlclass_update_data ((UMLClass *) obj);
+
return change;
}
diff --git a/objects/UML/class_dialog.c b/objects/UML/class_dialog.c
index e31703f4f..22ec2e3e6 100644
--- a/objects/UML/class_dialog.c
+++ b/objects/UML/class_dialog.c
@@ -41,7 +41,6 @@
#include "class.h"
#include "diaoptionmenu.h"
#include "diafontselector.h"
-#include "dia-object-change-legacy.h"
#include "class_dialog.h"
@@ -110,10 +109,8 @@ struct _UMLClassState {
};
-typedef struct _UMLClassChange UMLClassChange;
-
-struct _UMLClassChange {
- ObjectChange obj_change;
+struct _DiaUMLClassObjectChange {
+ DiaObjectChange obj_change;
UMLClass *obj;
@@ -126,6 +123,11 @@ struct _UMLClassChange {
UMLClassState *saved_state;
};
+
+DIA_DEFINE_OBJECT_CHANGE (DiaUMLClassObjectChange,
+ dia_uml_class_object_change)
+
+
static UMLClassState *umlclass_get_state (UMLClass *umlclass);
static DiaObjectChange *new_umlclass_change (UMLClass *obj,
UMLClassState *saved_state,
@@ -970,79 +972,85 @@ umlclass_set_state(UMLClass *umlclass, UMLClassState *state)
umlclass_update_data(umlclass);
}
+
static void
-umlclass_change_apply(UMLClassChange *change, DiaObject *obj)
+dia_uml_class_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
+ DiaUMLClassObjectChange *change = DIA_UML_CLASS_OBJECT_CHANGE (self);
UMLClassState *old_state;
GList *list;
- old_state = umlclass_get_state(change->obj);
+ old_state = umlclass_get_state (change->obj);
- umlclass_set_state(change->obj, change->saved_state);
+ umlclass_set_state (change->obj, change->saved_state);
list = change->disconnected;
while (list) {
- Disconnect *dis = (Disconnect *)list->data;
+ Disconnect *dis = (Disconnect *) list->data;
- object_unconnect(dis->other_object, dis->other_handle);
+ object_unconnect (dis->other_object, dis->other_handle);
- list = g_list_next(list);
+ list = g_list_next (list);
}
change->saved_state = old_state;
change->applied = 1;
}
+
static void
-umlclass_change_revert(UMLClassChange *change, DiaObject *obj)
+dia_uml_class_object_change_revert (DiaObjectChange *self, DiaObject *obj)
{
+ DiaUMLClassObjectChange *change = DIA_UML_CLASS_OBJECT_CHANGE (self);
UMLClassState *old_state;
GList *list;
- old_state = umlclass_get_state(change->obj);
+ old_state = umlclass_get_state (change->obj);
- umlclass_set_state(change->obj, change->saved_state);
+ umlclass_set_state (change->obj, change->saved_state);
list = change->disconnected;
while (list) {
- Disconnect *dis = (Disconnect *)list->data;
+ Disconnect *dis = (Disconnect *) list->data;
- object_connect(dis->other_object, dis->other_handle, dis->cp);
+ object_connect (dis->other_object, dis->other_handle, dis->cp);
- list = g_list_next(list);
+ list = g_list_next (list);
}
change->saved_state = old_state;
change->applied = 0;
}
+
static void
-umlclass_change_free(UMLClassChange *change)
+dia_uml_class_object_change_free (DiaObjectChange *self)
{
+ DiaUMLClassObjectChange *change = DIA_UML_CLASS_OBJECT_CHANGE (self);
GList *list, *free_list;
- umlclass_free_state(change->saved_state);
+ umlclass_free_state (change->saved_state);
g_clear_pointer (&change->saved_state, g_free);
/* Doesn't this mean only one of add, delete can be done in each apply? */
- if (change->applied)
+ if (change->applied) {
free_list = change->deleted_cp;
- else
+ } else {
free_list = change->added_cp;
+ }
list = free_list;
while (list != NULL) {
ConnectionPoint *connection = (ConnectionPoint *) list->data;
- g_assert(connection->connected == NULL); /* Paranoid */
- object_remove_connections_to(connection); /* Shouldn't be needed */
+ g_return_if_fail (connection->connected == NULL); /* Paranoid */
+ object_remove_connections_to (connection); /* Shouldn't be needed */
g_clear_pointer (&connection, g_free);
- list = g_list_next(list);
+ list = g_list_next (list);
}
- g_list_free(free_list);
-
+ g_list_free (free_list);
}
@@ -1053,16 +1061,9 @@ new_umlclass_change (UMLClass *obj,
GList *deleted,
GList *disconnected)
{
- UMLClassChange *change;
-
- change = g_new0(UMLClassChange, 1);
+ DiaUMLClassObjectChange *change;
- change->obj_change.apply =
- (ObjectChangeApplyFunc) umlclass_change_apply;
- change->obj_change.revert =
- (ObjectChangeRevertFunc) umlclass_change_revert;
- change->obj_change.free =
- (ObjectChangeFreeFunc) umlclass_change_free;
+ change = dia_object_change_new (DIA_UML_TYPE_CLASS_OBJECT_CHANGE);
change->obj = obj;
change->saved_state = saved_state;
@@ -1072,7 +1073,7 @@ new_umlclass_change (UMLClass *obj,
change->deleted_cp = deleted;
change->disconnected = disconnected;
- return dia_object_change_legacy_new ((ObjectChange *) change);
+ return DIA_OBJECT_CHANGE (change);
}
diff --git a/objects/UML/class_dialog.h b/objects/UML/class_dialog.h
index 4ecc2888b..c162b841f 100644
--- a/objects/UML/class_dialog.h
+++ b/objects/UML/class_dialog.h
@@ -1,4 +1,16 @@
+#pragma once
+
#include "widgets.h"
+
+G_BEGIN_DECLS
+
+#define DIA_UML_TYPE_CLASS_OBJECT_CHANGE dia_uml_class_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaUMLClassObjectChange,
+ dia_uml_class_object_change,
+ DIA_UML, CLASS_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
/**
* \brief Very special user interface for UMLClass parametrization
*
@@ -105,3 +117,5 @@ void _templates_read_from_dialog(UMLClass *umlclass, UMLClassDialog *prop_dialog
void _attributes_create_page(GtkNotebook *notebook, UMLClass *umlclass);
void _operations_create_page(GtkNotebook *notebook, UMLClass *umlclass);
void _templates_create_page(GtkNotebook *notebook, UMLClass *umlclass);
+
+G_END_DECLS
diff --git a/objects/UML/lifeline.c b/objects/UML/lifeline.c
index 37db57e6c..174933c33 100644
--- a/objects/UML/lifeline.c
+++ b/objects/UML/lifeline.c
@@ -31,7 +31,6 @@
#include "properties.h"
#include "connpoint_line.h"
#include "attributes.h"
-#include "dia-object-change-legacy.h"
#include "pixmaps/lifeline.xpm"
@@ -437,19 +436,32 @@ lifeline_draw (Lifeline *lifeline, DiaRenderer *renderer)
}
+#define DIA_UML_TYPE_LIFELINE_OBJECT_CHANGE dia_uml_lifeline_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaUMLLifelineObjectChange,
+ dia_uml_lifeline_object_change,
+ DIA_UML, LIFELINE_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
/* DiaObject menu handling */
-typedef struct {
- ObjectChange obj_change;
+struct _DiaUMLLifelineObjectChange {
+ DiaObjectChange obj_change;
DiaObjectChange *east, *west;
double cp_distance_change;
LifelineChangeType type;
-} LifelineChange;
+};
+
+
+DIA_DEFINE_OBJECT_CHANGE (DiaUMLLifelineObjectChange,
+ dia_uml_lifeline_object_change)
static void
-lifeline_change_apply (LifelineChange *change, DiaObject *obj)
+dia_uml_lifeline_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
+ DiaUMLLifelineObjectChange *change = DIA_UML_LIFELINE_OBJECT_CHANGE (self);
+
if (change->type == LIFELINE_CHANGE_ADD || change->type == LIFELINE_CHANGE_DEL) {
dia_object_change_apply (change->west,obj);
dia_object_change_apply (change->east,obj);
@@ -460,20 +472,24 @@ lifeline_change_apply (LifelineChange *change, DiaObject *obj)
static void
-lifeline_change_revert (LifelineChange *change, DiaObject *obj)
+dia_uml_lifeline_object_change_revert (DiaObjectChange *self, DiaObject *obj)
{
+ DiaUMLLifelineObjectChange *change = DIA_UML_LIFELINE_OBJECT_CHANGE (self);
+
if (change->type == LIFELINE_CHANGE_ADD || change->type == LIFELINE_CHANGE_DEL) {
dia_object_change_revert (change->west,obj);
dia_object_change_revert (change->east,obj);
} else {
- ((Lifeline*)obj)->cp_distance -= change->cp_distance_change;
+ ((Lifeline*) obj)->cp_distance -= change->cp_distance_change;
}
}
static void
-lifeline_change_free (LifelineChange *change)
+dia_uml_lifeline_object_change_free (DiaObjectChange *self)
{
+ DiaUMLLifelineObjectChange *change = DIA_UML_LIFELINE_OBJECT_CHANGE (self);
+
if (change->type == LIFELINE_CHANGE_ADD ||
change->type == LIFELINE_CHANGE_DEL) {
g_clear_pointer (&change->east, dia_object_change_unref);
@@ -487,12 +503,10 @@ lifeline_create_change (Lifeline *lifeline,
LifelineChangeType changetype,
Point *clicked)
{
- LifelineChange *vc;
+ DiaUMLLifelineObjectChange *vc;
+
+ vc = dia_object_change_new (DIA_UML_TYPE_LIFELINE_OBJECT_CHANGE);
- vc = g_new0 (LifelineChange, 1);
- vc->obj_change.apply = (ObjectChangeApplyFunc)lifeline_change_apply;
- vc->obj_change.revert = (ObjectChangeRevertFunc)lifeline_change_revert;
- vc->obj_change.free = (ObjectChangeFreeFunc)lifeline_change_free;
vc->type = changetype;
switch (vc->type) {
@@ -532,7 +546,7 @@ lifeline_create_change (Lifeline *lifeline,
lifeline_update_data (lifeline);
- return dia_object_change_legacy_new ((ObjectChange *) vc);
+ return DIA_OBJECT_CHANGE (vc);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]