2006-12-03 Dimitris Glezos <dimitris@glezos.com>
[dia.git] / lib / objchange.h
blob5019c170823323f12c14dff2a6d413aa659268d0
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1999 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 /*! \file objchange.h -- Forming the basic of undo support to be implemented in objects */
20 #ifndef OBJCHANGE_H
21 #define OBJCHANGE_H
23 #include "diatypes.h"
25 typedef void (*ObjectChangeApplyFunc)(ObjectChange *change, DiaObject *obj);
26 typedef void (*ObjectChangeRevertFunc)(ObjectChange *change, DiaObject *obj);
27 typedef void (*ObjectChangeFreeFunc)(ObjectChange *change);
29 struct _ObjectChange {
30 /*! If apply == transaction_point_pointer then this is a transaction
31 point. Otherwise this is applying the change */
32 ObjectChangeApplyFunc apply;
33 ObjectChangeRevertFunc revert; /*!< revert back to the state before the changed was applied */
34 ObjectChangeFreeFunc free; /*!< Remove extra data. Then this object is freed */
37 /******** Helper functions of objects: *************/
39 struct _ObjectState {
40 void (*free)(ObjectState *state); /*!< Frees pointers in the state,
41 not called if NULL */
44 /*!
45 Gets the internal state from the object.
46 This is used to snapshot the object state
47 so that it can be stored for undo/redo.
49 Need not save state that only depens on
50 the object and it's handles positions.
52 The calling function owns the returned reference.
54 typedef ObjectState * (*GetStateFunc) (DiaObject* obj);
56 /*!
57 Sets the internal state from the object.
58 This is used to snapshot the object state
59 so that it can be stored for undo/redo.
61 The called function owns the reference and is
62 responsible for freeing it.
64 typedef void (*SetStateFunc) (DiaObject* obj, ObjectState *state);
67 ObjectChange *new_object_state_change(DiaObject *obj,
68 ObjectState *old_state,
69 GetStateFunc get_state,
70 SetStateFunc set_state );
72 #endif /* OBJCHANGE_H */