Easier adjusting of layouts
[dia.git] / lib / objchange.c
blob586fd2f9126d6c246d56fe219c2dbba5c084219d
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 #include <config.h>
21 #include "object.h"
23 /******** ObjectChange for object that just need to get/set state: *****/
25 typedef struct _ObjectStateChange ObjectStateChange;
27 struct _ObjectStateChange {
28 ObjectChange obj_change;
30 GetStateFunc get_state;
31 SetStateFunc set_state;
33 ObjectState *saved_state;
34 DiaObject *obj;
37 static void
38 object_state_change_apply_revert(ObjectStateChange *change, DiaObject *obj)
40 ObjectState *old_state;
42 old_state = change->get_state(change->obj);
44 change->set_state(change->obj, change->saved_state);
46 change->saved_state = old_state;
49 static void
50 object_state_change_free(ObjectStateChange *change)
52 if ((change) && (change->saved_state) && (change->saved_state->free))
53 (*change->saved_state->free)(change->saved_state);
54 g_free(change->saved_state);
57 ObjectChange *new_object_state_change(DiaObject *obj,
58 ObjectState *old_state,
59 GetStateFunc get_state,
60 SetStateFunc set_state )
62 ObjectStateChange *change;
64 change = g_new(ObjectStateChange, 1);
66 change->obj_change.apply =
67 (ObjectChangeApplyFunc) object_state_change_apply_revert;
68 change->obj_change.revert =
69 (ObjectChangeRevertFunc) object_state_change_apply_revert;
70 change->obj_change.free =
71 (ObjectChangeFreeFunc) object_state_change_free;
73 change->get_state = get_state;
74 change->set_state = set_state;
76 change->obj = obj;
77 change->saved_state = old_state;
79 return (ObjectChange *)change;