f54cb0da34de7fe9392da8c6cfccf6e274e056ca
[goodguy/history.git] / cinelerra-5.1 / cinelerra / undostack.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef UNDOSTACK_H
23 #define UNDOSTACK_H
24
25 #include <stdio.h>
26 #include <stdint.h>
27
28 #include "linklist.h"
29 #include "stringfile.inc"
30
31 #define UNDOLEVELS 500
32 #define UNDO_KEY_INTERVAL 100
33
34 // The undo stack is a series of key undo buffers and
35 // incremental undo buffers.  The incremental buffers
36 // store the differences in the most compact way possible:
37 // a series of offsets, sizes and values.  This should allow
38 // a huge number of undo updates.
39
40
41 class UndoStackItem : public ListItem<UndoStackItem>
42 {
43 public:
44         UndoStackItem();
45         ~UndoStackItem();
46
47 // Must be inserted into the list before calling this, so it can get the
48 // previous key buffer.
49         void set_data(char *data);
50         void set_description(char *description);
51         void set_filename(char *filename);
52         const char* get_description();
53         void set_flags(uint64_t flags);
54
55 // Decompress the buffers and return them in a newly allocated string.
56 // The string must be deleted by the user.
57         char* get_data();
58         char* get_filename();
59         int has_data();
60         int get_size();
61         int is_key();
62         uint64_t get_flags();
63
64
65 // Get pointer to incremental data for use in an apply_difference command.
66         char* get_incremental_data();
67         int get_incremental_size();
68
69         void set_creator(void *creator);
70         void* get_creator();
71
72 private:
73 // command description for the menu item
74         char *description;
75
76 // key undo buffer or incremental undo buffer
77         int key;
78
79 // type of modification
80         uint64_t load_flags;
81
82 // data after the modification for redos
83         char *data;
84         int data_size;
85
86 // pointer to the object which set this undo buffer
87         void *creator;
88
89         char *session_filename;
90 };
91
92 class UndoStack : public List<UndoStackItem>
93 {
94 public:
95         UndoStack();
96         ~UndoStack();
97
98 // get current undo/redo stack item
99         UndoStackItem *get_current_undo();
100         UndoStackItem *get_current_redo();
101
102 // Create a new undo entry and put on the stack.
103 // The current pointer points to the new entry.
104 // delete future undos if in the middle
105 // delete undos older than UNDOLEVELS if last
106         UndoStackItem* push();
107
108 // move to the next undo entry for a redo
109         UndoStackItem* pull_next();
110
111         void dump(FILE *fp=stdout);
112
113         UndoStackItem* current;
114 };
115
116 #endif