]> git.lyx.org Git - lyx.git/blob - src/undo.h
bd7e6411bad9e7732d0df00677bd066bb128f586
[lyx.git] / src / undo.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-1999 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef UNDO_H
13 #define UNDO_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "lyxparagraph.h"
20
21 #include <list>
22 using std::list;
23
24 ///
25 class Undo {
26 public:
27         /// The undo kinds
28         enum undo_kind {
29                 ///
30                 INSERT,
31                 ///
32                 DELETE,
33                 ///
34                 EDIT,
35                 ///
36                 FINISH
37         };
38         ///
39         undo_kind kind;
40         ///
41         int number_of_before_par;
42         ///
43         int number_of_behind_par;
44         ///
45         int number_of_cursor_par;
46         ///
47         int cursor_pos; // valid if >= 0
48         ///
49         LyXParagraph * par;
50         ///
51         Undo(undo_kind kind_arg,
52              int number_before_arg, int number_behind_arg,
53              int cursor_par_arg, int cursor_pos_arg,
54              LyXParagraph * par_arg)
55         {
56                 kind = kind_arg;
57                 number_of_before_par = number_before_arg;
58                 number_of_behind_par = number_behind_arg;
59                 number_of_cursor_par = cursor_par_arg;
60                 cursor_pos = cursor_pos_arg;
61                 par = par_arg;
62         }
63         ///
64         ~Undo() {
65                 LyXParagraph * tmppar;
66                 while (par) {
67                         tmppar = par;
68                         par = par->next;
69                         delete tmppar;
70                 }
71         }
72 };
73
74
75 /// A limited Stack for the undo informations.
76 class UndoStack{
77 private:
78         ///
79         typedef list<Undo*> Stakk;
80         ///
81         Stakk stakk;
82         /// the maximum number of undo steps stored.
83         Stakk::size_type limit;
84 public:
85         ///
86         UndoStack();
87         ///
88         Undo * pop();
89         ///
90         Undo * top();
91         ///
92         bool empty() const { return stakk.empty(); }
93         ///
94         ~UndoStack();
95         ///
96         void clear();
97         ///
98         void SetStackLimit(Stakk::size_type l);
99         ///
100         void push(Undo * undo_arg);
101 };
102
103 #endif