1 /* Dia -- an diagram creation/manipulation program
2  * Copyright (C) 1999 Alexander Larsson
3  *
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.
8  *
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.
13  *
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.
17  */
18 #ifndef UNDO_H
19 #define UNDO_H
20 
21 
22 typedef struct _UndoStack UndoStack;
23 typedef struct _Change Change;
24 
25 #include "diagram.h"
26 #include "objchange.h"
27 
28 typedef void (*UndoApplyFunc)(Change *change, Diagram *dia);
29 typedef void (*UndoRevertFunc)(Change *change, Diagram *dia);
30 typedef void (*UndoFreeFunc)(Change *change);
31 
32 struct _Change {
33   /* If apply == transaction_point_pointer then this is a transaction
34      point */
35   UndoApplyFunc  apply;
36   UndoRevertFunc revert;
37   UndoFreeFunc   free; /* Remove extra data. Then this object is freed */
38   Change *prev, *next;
39 };
40 
41 struct _UndoStack {
42   Diagram *dia;
43   Change *last_change; /* Points to the object on the top of stack. */
44   Change *current_change; /* Points to the last object currently applied */
45   Change *last_save;   /* Points to current_change at the time of last save. */
46   int depth;
47 };
48 
49 UndoStack *new_undo_stack(Diagram *dia);
50 void undo_destroy(UndoStack *stack);
51 void undo_push_change(UndoStack *stack, Change *change);
52 void undo_set_transactionpoint(UndoStack *stack);
53 void undo_revert_to_last_tp(UndoStack *stack);
54 void undo_apply_to_next_tp(UndoStack *stack);
55 void undo_clear(UndoStack *stack);
56 void undo_mark_save(UndoStack *stack);
57 gboolean undo_is_saved(UndoStack *stack);
58 gboolean undo_available(UndoStack *stack, gboolean undo);
59 Change* undo_remove_to(UndoStack *stack, UndoApplyFunc *type);
60 
61 /* Specific undo functions: */
62 
63 Change *undo_move_objects(Diagram *dia, Point *orig_pos,
64 			  Point *dest_pos, GList *obj_list);
65 Change *undo_move_handle(Diagram *dia,
66 			 Handle *handle, DiaObject *obj,
67 			 Point orig_pos, Point dest_pos);
68 Change *undo_connect(Diagram *dia, DiaObject *obj, Handle *handle,
69 		     ConnectionPoint *connectionpoint);
70 Change *undo_unconnect(Diagram *dia, DiaObject *obj, Handle *handle);
71 Change *undo_delete_objects_children(Diagram *dia, GList *obj_list);
72 Change *undo_delete_objects(Diagram *dia, GList *obj_list); /* Reads current obj list */
73 Change *undo_insert_objects(Diagram *dia, GList *obj_list,
74 			    int applied);
75 Change *undo_reorder_objects(Diagram *dia, GList *changed_list,
76 			     GList *orig_list); /* Reads current obj list */
77 Change *undo_object_change(Diagram *dia, DiaObject *obj,
78 			   ObjectChange *obj_change);
79 Change *undo_group_objects(Diagram *dia, GList *obj_list,
80 			   DiaObject *group, GList *orig_list);
81 Change *undo_ungroup_objects(Diagram *dia, GList *obj_list,
82 			     DiaObject *group, int group_index);
83 Change *undo_parenting(Diagram *dia, DiaObject *parentobj, DiaObject *childobj,
84 		       gboolean parent);
85 Change *undo_move_object_other_layer(Diagram *diagram, GList *selected_list,
86 				     gboolean moving_up);
87 
88 #endif /* UNDO_H */
89 
90