]> git.lyx.org Git - lyx.git/blob - src/undo.C
Applied Angus patch to compile on DEC C++ and to avoid name clashes
[lyx.git] / src / undo.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #include "undo.h"
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19
20 Undo::Undo(undo_kind kind_arg,
21            int number_before_arg, int number_behind_arg,
22            int cursor_par_arg, int cursor_pos_arg,
23            LyXParagraph * par_arg)
24 {
25         kind = kind_arg;
26         number_of_before_par = number_before_arg;
27         number_of_behind_par = number_behind_arg;
28         number_of_cursor_par = cursor_par_arg;
29         cursor_pos = cursor_pos_arg;
30         par = par_arg;
31 }
32
33
34 #ifndef NEW_INSETS
35 Undo::~Undo()
36 {
37         LyXParagraph * tmppar;
38         while (par) {
39                 tmppar = par;
40                 par = par->next_;
41                 delete tmppar;
42         }
43 }
44 #else
45 Undo::~Undo()
46 {
47         LyXParagraph * tmppar;
48         while (par) {
49                 tmppar = par;
50                 par = par->next();
51                 delete tmppar;
52         }
53 }
54 #endif
55
56
57 UndoStack::UndoStack()
58         : limit(100) {}
59
60
61 Undo * UndoStack::pop()
62 {
63         if (stakk.empty()) return 0;
64         Undo * result = stakk.front();
65         stakk.pop_front();
66         return result;
67 }
68
69
70 Undo * UndoStack::top()
71 {
72         if (stakk.empty()) return 0;
73         return stakk.front();
74 }
75
76
77 UndoStack::~UndoStack()
78 {
79         clear();
80 }
81
82
83 void UndoStack::clear()
84 {
85         while (!stakk.empty()) {
86                 Undo * tmp = stakk.front();
87                 stakk.pop_front();
88                 delete tmp;
89         }
90 }
91
92
93 void UndoStack::SetStackLimit(Stakk::size_type l)
94 {
95         limit = l;
96 }
97
98
99 void UndoStack::push(Undo * undo_arg)
100 {
101         if (!undo_arg) return;
102         
103         stakk.push_front(undo_arg);
104         if (stakk.size() > limit) {
105                 Undo * tmp = stakk.back();
106                 stakk.pop_back();
107                 delete tmp;
108         }
109 }
110
111
112 bool UndoStack::empty() const {
113         return stakk.empty();
114 }