[dia/zbrown/object-change: 12/16] fs: port to DiaObjectChange
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/zbrown/object-change: 12/16] fs: port to DiaObjectChange
- Date: Sat, 10 Oct 2020 22:05:56 +0000 (UTC)
commit 60d1ba6a7dcc8fa8f522406eefdb516f5c3f166a
Author: Zander Brown <zbrown gnome org>
Date: Sat Oct 10 22:24:29 2020 +0100
fs: port to DiaObjectChange
objects/FS/flow-ortho.c | 88 ++++++++++++++++++++++++++++++++-----------------
objects/FS/flow.c | 49 +++++++++++++++++----------
objects/FS/function.c | 66 ++++++++++++++++++++++++++-----------
3 files changed, 134 insertions(+), 69 deletions(-)
---
diff --git a/objects/FS/flow-ortho.c b/objects/FS/flow-ortho.c
index e8bf149df..b6a1ae1cd 100644
--- a/objects/FS/flow-ortho.c
+++ b/objects/FS/flow-ortho.c
@@ -38,13 +38,11 @@
#include "orth_conn.h"
#include "element.h"
#include "properties.h"
-#include "dia-object-change-legacy.h"
#include "pixmaps/orthflow.xpm"
typedef struct _Orthflow Orthflow;
-typedef struct _OrthflowChange OrthflowChange;
typedef enum {
ORTHFLOW_ENERGY,
@@ -62,19 +60,32 @@ struct _Orthflow {
Point textpos; /* This is the master position, only overridden in load */
};
+
+#define DIA_FS_TYPE_ORTHFLOW_OBJECT_CHANGE dia_fs_orthflow_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaFSOrthflowObjectChange,
+ dia_fs_orthflow_object_change,
+ DIA_FS, ORTHFLOW_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
enum OrthflowChangeType {
TEXT_EDIT=1,
FLOW_TYPE=2,
BOTH=3
};
-struct _OrthflowChange {
- ObjectChange obj_change ;
- enum OrthflowChangeType change_type ;
- OrthflowType type ;
- char* text ;
+
+struct _DiaFSOrthflowObjectChange {
+ DiaObjectChange obj_change;
+ enum OrthflowChangeType change_type;
+ OrthflowType type;
+ char *text;
};
+
+DIA_DEFINE_OBJECT_CHANGE (DiaFSOrthflowObjectChange, dia_fs_orthflow_object_change)
+
+
Color orthflow_color_energy = { 1.0f, 0.0f, 0.0f, 1.0f };
Color orthflow_color_material = { 0.8f, 0.0f, 0.8f, 1.0f };
Color orthflow_color_signal = { 0.0f, 0.0f, 1.0f, 1.0f };
@@ -211,35 +222,51 @@ orthflow_set_props(Orthflow *orthflow, GPtrArray *props)
}
-
static void
-orthflow_change_apply_revert (ObjectChange* objchg, DiaObject* obj)
+dia_fs_orthflow_object_change_apply_revert (DiaFSOrthflowObjectChange *change,
+ DiaObject *obj)
{
- struct _OrthflowChange* change = (struct _OrthflowChange*) objchg ;
- Orthflow* oflow = (Orthflow*) obj ;
-
- if ( change->change_type == FLOW_TYPE || change->change_type == BOTH ) {
- OrthflowType type = oflow->type ;
- oflow->type = change->type ;
- change->type = type ;
- orthflow_update_data(oflow) ;
+ Orthflow *oflow = (Orthflow *) obj;
+
+ if (change->change_type == FLOW_TYPE || change->change_type == BOTH) {
+ OrthflowType type = oflow->type;
+ oflow->type = change->type;
+ change->type = type;
+ orthflow_update_data (oflow);
}
- if ( change->change_type & TEXT_EDIT || change->change_type == BOTH ) {
- char* tmp = text_get_string_copy( oflow->text ) ;
- text_set_string( oflow->text, change->text ) ;
+ if (change->change_type & TEXT_EDIT || change->change_type == BOTH) {
+ char *tmp = text_get_string_copy (oflow->text);
+ text_set_string (oflow->text, change->text);
g_clear_pointer (&change->text, g_free);
- change->text = tmp ;
+ change->text = tmp;
}
}
+
static void
-orthflow_change_free(ObjectChange* objchg)
+dia_fs_orthflow_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
- struct _OrthflowChange* change = (struct _OrthflowChange*) objchg ;
+ dia_fs_orthflow_object_change_apply_revert (DIA_FS_ORTHFLOW_OBJECT_CHANGE (self),
+ obj);
+}
+
- if (change->change_type & TEXT_EDIT || change->change_type == BOTH ) {
- g_clear_pointer (&change->text, g_free) ;
+static void
+dia_fs_orthflow_object_change_revert (DiaObjectChange *self, DiaObject *obj)
+{
+ dia_fs_orthflow_object_change_apply_revert (DIA_FS_ORTHFLOW_OBJECT_CHANGE (self),
+ obj);
+}
+
+
+static void
+dia_fs_orthflow_object_change_free (DiaObjectChange *objchg)
+{
+ DiaFSOrthflowObjectChange* change = DIA_FS_ORTHFLOW_OBJECT_CHANGE (objchg);
+
+ if (change->change_type & TEXT_EDIT || change->change_type == BOTH) {
+ g_clear_pointer (&change->text, g_free);
}
}
@@ -249,11 +276,10 @@ orthflow_create_change (enum OrthflowChangeType change_type,
OrthflowType type,
Text *text )
{
- struct _OrthflowChange *change;
- change = g_new0 (struct _OrthflowChange, 1);
- change->obj_change.apply = (ObjectChangeApplyFunc) orthflow_change_apply_revert;
- change->obj_change.revert = (ObjectChangeRevertFunc) orthflow_change_apply_revert;
- change->obj_change.free = (ObjectChangeFreeFunc) orthflow_change_free;
+ DiaFSOrthflowObjectChange *change;
+
+ change = dia_object_change_new (DIA_FS_TYPE_ORTHFLOW_OBJECT_CHANGE);
+
change->change_type = change_type;
change->type = type;
@@ -261,7 +287,7 @@ orthflow_create_change (enum OrthflowChangeType change_type,
change->text = text_get_string_copy (text);
}
- return dia_object_change_legacy_new ((ObjectChange *) change);
+ return DIA_OBJECT_CHANGE (change);
}
diff --git a/objects/FS/flow.c b/objects/FS/flow.c
index 9c23b4494..ab239dbbf 100644
--- a/objects/FS/flow.c
+++ b/objects/FS/flow.c
@@ -35,7 +35,6 @@
#include "text.h"
#include "connection.h"
#include "properties.h"
-#include "dia-object-change-legacy.h"
#include "pixmaps/flow.xpm"
@@ -346,6 +345,7 @@ flow_draw (Flow *flow, DiaRenderer *renderer)
case FLOW_ENERGY:
render_color = &flow_color_energy;
dia_renderer_set_linestyle (renderer, LINESTYLE_SOLID, 0.0);
+ break;
default:
g_return_if_reached ();
}
@@ -577,50 +577,63 @@ flow_load(ObjectNode obj_node, int version, DiaContext *ctx)
return &flow->connection.object;
}
-struct TypeChange {
- ObjectChange obj_change;
- int old_type, new_type;
+
+#define DIA_FS_TYPE_FLOW_OBJECT_CHANGE dia_fs_flow_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaFSFlowObjectChange,
+ dia_fs_flow_object_change,
+ DIA_FS, FLOW_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
+struct _DiaFSFlowObjectChange {
+ DiaObjectChange obj_change;
+ int old_type;
+ int new_type;
};
+
+DIA_DEFINE_OBJECT_CHANGE (DiaFSFlowObjectChange, dia_fs_flow_object_change)
+
+
static void
-type_change_free(struct TypeChange *change)
+dia_fs_flow_object_change_free (DiaObjectChange *change)
{
}
+
static void
-type_change_apply(struct TypeChange *change, DiaObject *obj)
+dia_fs_flow_object_change_apply (DiaObjectChange *self, DiaObject *obj)
{
- Flow *flow = (Flow*)obj;
+ DiaFSFlowObjectChange *change = DIA_FS_FLOW_OBJECT_CHANGE (self);
+ Flow *flow = (Flow *) obj;
flow->type = change->new_type;
- flow_update_data(flow);
+ flow_update_data (flow);
}
+
static void
-type_change_revert(struct TypeChange *change, DiaObject *obj)
+dia_fs_flow_object_change_revert (DiaObjectChange *self, DiaObject *obj)
{
- Flow *flow = (Flow*)obj;
+ DiaFSFlowObjectChange *change = DIA_FS_FLOW_OBJECT_CHANGE (self);
+ Flow *flow = (Flow*) obj;
flow->type = change->old_type;
- flow_update_data(flow);
+ flow_update_data (flow);
}
static DiaObjectChange *
type_create_change (Flow *flow, int type)
{
- struct TypeChange *change;
-
- change = g_new0(struct TypeChange, 1);
+ DiaFSFlowObjectChange *change;
- change->obj_change.apply = (ObjectChangeApplyFunc) type_change_apply;
- change->obj_change.revert = (ObjectChangeRevertFunc) type_change_revert;
- change->obj_change.free = (ObjectChangeFreeFunc) type_change_free;
+ change = dia_object_change_new (DIA_FS_TYPE_FLOW_OBJECT_CHANGE);
change->old_type = flow->type;
change->new_type = type;
- return dia_object_change_legacy_new ((ObjectChange *) change);
+ return DIA_OBJECT_CHANGE (change);
}
diff --git a/objects/FS/function.c b/objects/FS/function.c
index 501479136..8bfddefa3 100644
--- a/objects/FS/function.c
+++ b/objects/FS/function.c
@@ -33,7 +33,6 @@
#include "attributes.h"
#include "text.h"
#include "properties.h"
-#include "dia-object-change-legacy.h"
#include "pixmaps/function.xpm"
@@ -60,14 +59,26 @@ enum FuncChangeType {
ALL
};
-struct _FunctionChange {
- ObjectChange obj_change ;
- enum FuncChangeType change_type ;
- int is_wish ;
- int is_user ;
- char* text ;
+
+#define DIA_FS_TYPE_FUNCTION_OBJECT_CHANGE dia_fs_function_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaFSFunctionObjectChange,
+ dia_fs_function_object_change,
+ DIA_FS, FUNCTION_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
+struct _DiaFSFunctionObjectChange {
+ DiaObjectChange obj_change;
+ enum FuncChangeType change_type;
+ int is_wish;
+ int is_user;
+ char *text;
};
+
+DIA_DEFINE_OBJECT_CHANGE (DiaFSFunctionObjectChange, dia_fs_function_object_change)
+
+
#define FUNCTION_FONTHEIGHT 0.8
#define FUNCTION_BORDERWIDTH_SCALE 6.0
#define FUNCTION_MARGIN_SCALE 3.0
@@ -187,13 +198,13 @@ function_set_props(Function *function, GPtrArray *props)
function_update_data(function);
}
+
static void
-function_change_apply_revert( ObjectChange* objchg, DiaObject* obj)
+function_change_apply_revert (DiaFSFunctionObjectChange *change, DiaObject* obj)
{
- int tmp ;
- char* ttxt ;
- FunctionChange* change = (FunctionChange*) objchg ;
- Function* fcn = (Function*) obj ;
+ int tmp;
+ char *ttxt;
+ Function *fcn = (Function *) obj;
if ( change->change_type == WISH_FUNC || change->change_type == ALL ) {
tmp = fcn->is_wish ;
@@ -213,12 +224,27 @@ function_change_apply_revert( ObjectChange* objchg, DiaObject* obj)
}
}
+
+static void
+dia_fs_function_object_change_apply (DiaObjectChange *self, DiaObject *obj)
+{
+ function_change_apply_revert (DIA_FS_FUNCTION_OBJECT_CHANGE (self), obj);
+}
+
+
+static void
+dia_fs_function_object_change_revert (DiaObjectChange *self, DiaObject *obj)
+{
+ function_change_apply_revert (DIA_FS_FUNCTION_OBJECT_CHANGE (self), obj);
+}
+
+
static void
-function_change_free( ObjectChange* objchg )
+dia_fs_function_object_change_free (DiaObjectChange *self)
{
- FunctionChange* change = (FunctionChange*) objchg ;
+ DiaFSFunctionObjectChange *change = DIA_FS_FUNCTION_OBJECT_CHANGE (self);
- if ( change->change_type == TEXT_EDIT ) {
+ if (change->change_type == TEXT_EDIT) {
g_clear_pointer (&change->text, g_free);
}
}
@@ -227,10 +253,10 @@ function_change_free( ObjectChange* objchg )
static DiaObjectChange *
function_create_change (Function *fcn, enum FuncChangeType change_type)
{
- FunctionChange* change = g_new0(FunctionChange,1) ;
- change->obj_change.apply = (ObjectChangeApplyFunc) function_change_apply_revert ;
- change->obj_change.revert = (ObjectChangeRevertFunc) function_change_apply_revert ;
- change->obj_change.free = (ObjectChangeFreeFunc) function_change_free ;
+ DiaFSFunctionObjectChange *change;
+
+ change = dia_object_change_new (DIA_FS_TYPE_FUNCTION_OBJECT_CHANGE);
+
change->change_type = change_type ;
if (change_type == WISH_FUNC || change_type == ALL) {
@@ -245,7 +271,7 @@ function_create_change (Function *fcn, enum FuncChangeType change_type)
change->text = text_get_string_copy (fcn->text);
}
- 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]