Verified Commit 30c6e868 authored by Zander Brown's avatar Zander Brown 🇬🇧
Browse files

lib: drop ObjectChange, DiaObjectChangeLegacy

We've now ported all usage to DiaObjectChange direct
parent 15f23954
Pipeline #220305 passed with stage
in 14 minutes and 29 seconds
......@@ -69,10 +69,10 @@
<xi:include href="xml/connection.xml"/>
<xi:include href="xml/connpoint_line.xml"/>
<xi:include href="xml/dia_svg.xml"/>
<xi:include href="xml/objchange.xml"/>
<xi:include href="xml/dia-change.xml" />
<xi:include href="xml/dia-object-change.xml" />
<xi:include href="xml/dia-object-change-legacy.xml" />
<xi:include href="xml/obj-state-object-change.xml"/>
<xi:include href="xml/dia-object-change-list.xml" />
<xi:include href="xml/object-alias.xml"/>
<xi:include href="xml/create.xml"/>
<xi:include href="xml/diatransform.xml"/>
......
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1999 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* Copyright © 2020 Zander Brown <zbrown@gnome.org>
*/
#include "dia-object-change-legacy.h"
struct _DiaObjectChangeLegacy {
DiaObjectChange parent_instance;
ObjectChange *legacy;
};
DIA_DEFINE_OBJECT_CHANGE (DiaObjectChangeLegacy, dia_object_change_legacy)
static void
dia_object_change_legacy_apply (DiaObjectChange *self, DiaObject *object)
{
DiaObjectChangeLegacy *change = DIA_OBJECT_CHANGE_LEGACY (self);
change->legacy->apply (change->legacy, object);
}
static void
dia_object_change_legacy_revert (DiaObjectChange *self, DiaObject *object)
{
DiaObjectChangeLegacy *change = DIA_OBJECT_CHANGE_LEGACY (self);
change->legacy->revert (change->legacy, object);
}
static void
dia_object_change_legacy_free (DiaObjectChange *self)
{
DiaObjectChangeLegacy *change = DIA_OBJECT_CHANGE_LEGACY (self);
if (change->legacy->free) {
change->legacy->free (change->legacy);
}
g_clear_pointer (&change->legacy, g_free);
}
DiaObjectChange *
dia_object_change_legacy_new (ObjectChange *legacy)
{
DiaObjectChangeLegacy *change = dia_object_change_new (DIA_TYPE_OBJECT_CHANGE_LEGACY);
change->legacy = legacy;
return DIA_OBJECT_CHANGE (change);
}
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1999 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* Copyright © 2020 Zander Brown <zbrown@gnome.org>
*/
#pragma once
#ifndef __GTK_DOC_IGNORE__
typedef struct _ObjectChange ObjectChange;
#endif
#include "dia-object-change.h"
#include "objchange.h"
G_BEGIN_DECLS
#define DIA_TYPE_OBJECT_CHANGE_LEGACY dia_object_change_legacy_get_type ()
G_DECLARE_FINAL_TYPE (DiaObjectChangeLegacy, dia_object_change_legacy, DIA, OBJECT_CHANGE_LEGACY, DiaObjectChange)
DiaObjectChange *dia_object_change_legacy_new (ObjectChange *legacy);
G_END_DECLS
......@@ -27,6 +27,24 @@
#include "object.h"
/**
* SECTION:dia-object-change
*
* Forming the basic of undo support to be implemented in objects
*
* Object implementations need some effort to support undo/redo
*
* Return value of object changing functions and methods of DiaObject
*
* FIXME: #DiaObjectChange functions should not require the changed object
* as an argument. Every change object should keep track of the
* relevant object instead. The second argument in the above typedefs
* is deprecated and should not be relied on.
*
* Replaces ObjectChange
*/
static void
dia_object_change_real_apply (DiaObjectChange *self,
DiaObject *object)
......
......@@ -117,6 +117,16 @@ struct _DiaObjectChange {
};
/**
* DiaObjectChangeClass:
* @apply: do the change
* @revert: undo the effects of @apply
* @free: clear fields (called during destruction)
*
* Since: 0.98
*
* Stability: Stable
*/
struct _DiaObjectChangeClass {
GTypeClass parent;
......
......@@ -18,7 +18,7 @@
#include <config.h>
#include "objchange.h"
#include "dia-state-object-change.h"
/**
......@@ -82,6 +82,19 @@ dia_state_object_change_free (DiaObjectChange *self)
}
/**
* dia_state_object_change_new:
* @obj: the #DiaObject whos state changed
* @old_state: the previous #ObjectState
* @get_state: a #GetStateFunc used to generate the #ObjectState of @obj
* @set_state: a #SetStateFunc used to apply a #ObjectState to @obj
*
* Create a single change from the ObjectState
*
* Since: 0.98
*
* Stability: Stable
*/
DiaObjectChange *
dia_state_object_change_new (DiaObject *obj,
ObjectState *old_state,
......
......@@ -16,15 +16,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*!
* \file objchange.h -- Forming the basic of undo support to be implemented in objects
*/
/*!
* \defgroup ObjChange Support for undo/redo
* \brief Object implementations need some effort to support undo/redo
* \ingroup ObjectParts
*/
#pragma once
#include "diatypes.h"
......@@ -39,68 +30,48 @@ G_DECLARE_FINAL_TYPE (DiaStateObjectChange,
DiaObjectChange)
typedef struct _ObjectChange ObjectChange;
typedef void (*ObjectChangeApplyFunc)(ObjectChange *change, DiaObject *obj);
typedef void (*ObjectChangeRevertFunc)(ObjectChange *change, DiaObject *obj);
typedef void (*ObjectChangeFreeFunc)(ObjectChange *change);
/*!
\brief Return value of object changing functions and methods of DiaObject
FIXME: ObjectChange functions should not require the changed object
as an argument. Every change object should keep track of the
relevant object instead. The second argument in the above typedefs
is deprecated and should not be relied on.
\ingroup ObjChange
/**
* ObjectState:
* @free: (nullable): destroy the #ObjectState content
*
* Since: dawn-of-time
*/
struct _ObjectChange {
/*! If apply == transaction_point_pointer then this is a transaction
point. Otherwise this is applying the change */
ObjectChangeApplyFunc apply;
ObjectChangeRevertFunc revert; /*!< revert back to the state before the changed was applied */
ObjectChangeFreeFunc free; /*!< Remove extra data. Then this object is freed */
};
/******** Helper functions of objects: *************/
struct _ObjectState {
void (*free)(ObjectState *state); /*!< Frees pointers in the state,
not called if NULL */
void (*free) (ObjectState *state);
};
/*!
Gets the internal state from the object.
This is used to snapshot the object state
so that it can be stored for undo/redo.
Need not save state that only depens on
the object and it's handles positions.
The calling function owns the returned reference.
\ingroup ObjChange
*/
/**
* GetStateFunc:
*
* Gets the internal state from the object.
* This is used to snapshot the object state
* so that it can be stored for undo/redo.
*
* Need not save state that only depens on
* the object and it's handles positions.
*
* The calling function owns the returned reference.
*
* Since: dawn-of-time
*/
typedef ObjectState * (*GetStateFunc) (DiaObject* obj);
/*!
Sets the internal state from the object.
This is used to snapshot the object state
so that it can be stored for undo/redo.
The called function owns the reference and is
responsible for freeing it.
\ingroup ObjChange
*/
/**
* SetStateFunc:
*
* Sets the internal state from the object.
* This is used to snapshot the object state
* so that it can be stored for undo/redo.
*
* The called function owns the reference and is
* responsible for freeing it.
*
* Since: dawn-of-time
*/
typedef void (*SetStateFunc) (DiaObject* obj, ObjectState *state);
/*! Create a single change from the ObjectState
* \ingroup ObjChange
*/
DiaObjectChange *dia_state_object_change_new (DiaObject *obj,
ObjectState *old_state,
GetStateFunc get_state,
......
......@@ -34,7 +34,7 @@
#include "dynamic_obj.h"
#include "connectionpoint.h"
#include "diafontselector.h"
#include "objchange.h"
#include "dia-state-object-change.h"
/* This is a file with dummy dependencies so that all
object files will be linked into the app.
......
......@@ -75,8 +75,9 @@ EXPORTS
calculate_arrow_point
change_list_add
change_list_create
dia_object_change_list_get_type
dia_object_change_list_new
dia_object_change_list_add
color_convert
color_equals
......@@ -613,7 +614,7 @@ EXPORTS
message_warning
set_message_func
new_object_state_change
dia_state_object_change_new
object_add_connectionpoint
object_add_handle
......
......@@ -87,14 +87,12 @@ libdia_sources = stdprop_sources + [
'polyshape.h',
'beziershape.c',
'beziershape.h',
'objchange.c',
'objchange.h',
'dia-change.c',
'dia-change.h',
'dia-object-change.c',
'dia-object-change.h',
'dia-object-change-legacy.c',
'dia-object-change-legacy.h',
'dia-state-object-change.c',
'dia-state-object-change.h',
'dia-object-change-list.c',
'dia-object-change-list.h',
'dialogs.c',
......
......@@ -27,7 +27,6 @@
#include "message.h"
#include "parent.h"
#include "dia-layer.h"
#include "dia-object-change-legacy.h"
#include "dummy_dep.h"
......@@ -347,12 +346,17 @@ object_list_move_delta (GList *objects, Point *delta)
}
typedef struct _ObjectChangeExchange {
ObjectChange change;
DiaObject *orig;
DiaObject *subst;
gboolean applied;
} ObjectChangeExchange;
struct _DiaExchangeObjectChange {
DiaObjectChange change;
DiaObject *orig;
DiaObject *subst;
gboolean applied;
};
DIA_DEFINE_OBJECT_CHANGE (DiaExchangeObjectChange,
dia_exchange_object_change)
static Handle *
_find_connectable (DiaObject *obj, int *num)
......@@ -424,10 +428,11 @@ object_copy_style (DiaObject *dest, const DiaObject *src)
prop_list_free (props);
}
static void
_object_exchange (ObjectChange *change, DiaObject *obj)
_object_exchange (DiaObjectChange *self, DiaObject *obj)
{
ObjectChangeExchange *c = (ObjectChangeExchange *)change;
DiaExchangeObjectChange *c = DIA_EXCHANGE_OBJECT_CHANGE (self);
DiaLayer *layer = dia_object_get_parent_layer (obj);
DiagramData *dia = layer ? dia_layer_get_parent_diagram (layer) : NULL;
DiaObject *subst = (obj == c->orig) ? c->subst : c->orig;
......
......@@ -31,7 +31,7 @@
#include "diarenderer.h"
#include "attributes.h"
#include "properties.h"
#include "objchange.h"
#include "dia-state-object-change.h"
#include "pixmaps/attribute.xpm"
......
......@@ -62,7 +62,7 @@
#include "arrows.h"
#include "uml.h"
#include "properties.h"
#include "objchange.h"
#include "dia-state-object-change.h"
#include "pixmaps/association.xpm"
......
......@@ -35,7 +35,7 @@
#include "properties.h"
#include "diamenu.h"
#include "class.h"
#include "objchange.h"
#include "dia-state-object-change.h"
#include "pixmaps/umlclass.xpm"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment