Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / tools / Edit / UndoRedo.h
blob50fb49c8d76f449d6c625b31ec2f0e8c84c57c6c
1 /**********************************************************
2 ** **
3 ** $VER: UndoRedo.h 1.2 (3.2.2001) **
4 ** Datatypes for journalized buffer **
5 ** **
6 ** © T.Pierron, C.Guilaume. Free software under **
7 ** terms of GNU public license. **
8 ** **
9 **********************************************************/
11 #ifndef UNDOREDO_H
12 #define UNDOREDO_H
14 #ifndef MEMORY_H
15 #include "Memory.h"
16 #endif
18 /* Size of one chunk of undo/redo buf (must be a power of 2) */
19 #define UNDO_CHUNK 32
21 /** Structure holding modifications data (operations) **/
22 typedef struct _RBOps
24 struct _RBOps *prev;
25 UWORD size; /* Nb. of bytes in the array data */
26 UBYTE data[ UNDO_CHUNK ]; /* Buffer for operation data */
27 } *RBOps;
29 /** Rollback segment (text) **/
30 typedef struct _RBSeg
32 struct _RBSeg *prev, *next;
33 ULONG max; /* Max data in data array */
34 UBYTE data[1]; /* Removed characters */
35 } *RBSeg;
37 /** Internal values per Project **/
38 typedef struct _JBuf /* Journalized buffer */
40 LINE *line; /* Last line modified */
41 ULONG nbc; /* Last character modified */
42 RBOps ops; /* Stack of operations */
43 RBSeg rbseg; /* Rollback segment */
44 ULONG size; /* Nb. of bytes in modif buffer */
45 ULONG rbsz; /* Nb. of bytes in rollback segment */
46 UBYTE op; /* Type of last operation */
47 UBYTE rbtype; /* 0:undo 1:redo */
48 APTR prj; /* Link to project struct */
49 } JBUF;
51 typedef JBUF * JBuf; /* Main type pointer */
53 /** Get Project struct **/
54 #define PRJ(jbuf) ((Project)jbuf->prj)
56 /** Operations journalized **/
57 #define ADD_CHAR 1 /* Add chars on a new line */
58 #define REM_CHAR 2 /* Remove chars */
59 #define REM_LINE 3 /* Remove whole content of a line */
60 #define JOIN_LINE 4 /* Line joined */
61 #define GROUP_BY 5 /* Group of operation */
63 #define LAST_TYPE(x) ((STRPTR)(x))[-1]
64 #define IS_COMMIT(x) ((STRPTR)(x))[-2]
65 #define OUT_OF_DATE ((STRPTR)-1)
66 #define NO_MEANING_VAL ((STRPTR)-2)
68 /** Datatypes specific to an operation (must be WORD aligned) **/
69 typedef struct _AddChar
71 LINE *line; /* Line where operation occured */
72 UWORD pos; /* Position in this line */
73 UWORD nbc; /* Nb. of char inserted */
74 #ifdef __AROS__
75 UWORD pad; /* to get multiple-of-4 structure sizeof */
76 #endif
77 UBYTE commit; /* Savepoint */
78 UBYTE type; /* ADD_CHAR */
79 } *AddChar;
81 /** Yes, no meaning changes, except type == REM_CHAR **/
82 typedef struct _AddChar *RemChar;
84 typedef struct _RemLine
86 LINE *line; /* Line removed */
87 LINE *after; /* Insert the line after this one */
88 #ifdef __AROS__
89 UWORD pad; /* to get multiple-of-4 structure sizeof */
90 #endif
91 UBYTE commit; /* Savepoint */
92 UBYTE type; /* REM_LINE */
93 } *RemLine;
95 typedef struct _JoinLine
97 LINE *line; /* First line concerned */
98 LINE *old; /* Old line removed */
99 ULONG pos; /* Joined position */
100 #ifdef __AROS__
101 UWORD pad; /* to get multiple-of-4 structure sizeof */
102 #endif
103 UBYTE commit; /* Savepoint */
104 UBYTE type; /* JOIN_LINE */
105 } *JoinLine;
107 typedef struct _GroupBy /* Gather multiple operations */
109 #ifdef __AROS__
110 UWORD pad; /* to get multiple-of-4 structure sizeof */
111 #endif
112 UBYTE commit; /* Savepoint */
113 UBYTE type; /* GROUP_BY */
114 } *GroupBy;
116 void flush_undo_buf ( JBuf );
117 void rollback ( JBuf );
118 void last_modif ( JBuf, char );
119 #ifdef PROJECT_H
120 void commit_work ( Project );
121 #endif
123 STRPTR pop_last_op ( JBuf, char, char ); /* Update JBuf values */
125 void reg_add_chars ( JBuf, LINE *, ULONG pos, UWORD nb );
126 void reg_rem_chars ( JBuf, LINE *, ULONG s, ULONG e );
127 void reg_join_lines ( JBuf, LINE *, LINE * );
128 void reg_rem_line ( JBuf, LINE * );
129 void reg_group_by ( JBuf );
131 #endif