]> git.lyx.org Git - lyx.git/blob - src/Changes.h
Fix setting Interlingua as GUI language
[lyx.git] / src / Changes.h
1 // -*- C++ -*-
2 /**
3  * \file Changes.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Michael Gerz
9  *
10  * Full author contact details are available in file CREDITS.
11  *
12  * Record changes in a paragraph.
13  */
14
15 #ifndef CHANGES_H
16 #define CHANGES_H
17
18 #include "Color.h"
19
20 #include "support/strfwd.h"
21 #include "support/types.h"
22 #include "support/lyxtime.h"
23
24 #include "texstream.h"
25
26 #include <vector>
27
28
29 namespace lyx {
30
31 class AuthorList;
32 class Buffer;
33 class DocIterator;
34 class OutputParams;
35
36 class Change {
37 public:
38         /// the type of change
39         enum Type {
40                 UNCHANGED, // no change
41                 INSERTED, // new text
42                 DELETED // deleted text
43         };
44
45         explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = support::current_time())
46                 : type(t), author(a), changetime(ct) {}
47
48         /// is the change similar to the given change such that both can be merged?
49         bool isSimilarTo(Change const & change) const;
50         /// The color of this change on screen
51         Color color() const;
52         ///
53         bool changed() const { return type != UNCHANGED; }
54         ///
55         void setUnchanged() { type = UNCHANGED; }
56         ///
57         bool inserted() const { return type == INSERTED; }
58         ///
59         void setInserted() { type = INSERTED; }
60         ///
61         bool deleted() const { return type == DELETED; }
62         ///
63         void setDeleted() { type = DELETED; }
64         /// Is this change made by the current author ?
65         bool currentAuthor() const { return author == 0; }
66
67         Type type;
68
69         int author;
70
71         time_t changetime;
72 };
73
74 bool operator==(Change const & l, Change const & r);
75 bool operator!=(Change const & l, Change const & r);
76
77 class BufferParams;
78
79 class Changes {
80 public:
81         /// set the pos to the given change
82         void set(Change const & change, pos_type pos);
83         /// set the range (excluding end) to the given change
84         void set(Change const & change, pos_type start, pos_type end);
85
86         /// erase the entry at pos and adjust all range bounds past it
87         /// (assumes that a character was deleted at pos)
88         void erase(lyx::pos_type pos);
89
90         /// insert a new entry at pos and adjust all range bounds past it
91         /// (assumes that a character was inserted at pos)
92         void insert(Change const & change, lyx::pos_type pos);
93
94         ///
95
96         /// return the change at the given pos
97         Change const & lookup(pos_type pos) const;
98
99         /// return true if there is a change in the given range (excluding end)
100         bool isChanged(pos_type start, pos_type end) const;
101
102         /// return true if the whole range is deleted
103         bool isDeleted(pos_type start, pos_type end) const;
104
105         /// output latex to mark a transition between two change types
106         /// returns length of text outputted
107         static int latexMarkChange(otexstream & os, BufferParams const & bparams,
108                                    Change const & oldChange, Change const & change,
109                                    OutputParams const & runparams);
110
111         /// output .lyx file format for transitions between changes
112         static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
113                 int & column, Change const & old, Change const & change);
114
115         ///
116         void checkAuthors(AuthorList const & authorList);
117
118         ///
119         void addToToc(DocIterator const & cdit, Buffer const & buffer,
120                 bool output_active) const;
121
122 private:
123         class Range {
124         public:
125                 Range(pos_type s, pos_type e)
126                         : start(s), end(e) {}
127
128                 // does this range contain r ? (inlined as the result of profiling)
129                 bool contains(Range const & r) const {
130                         return r.start >= start && r.end <= end;
131                 }
132
133                 // does this range contain pos ? (inlined as the result of profiling)
134                 bool contains(pos_type pos) const {
135                         return pos >= start && pos < end;
136                 }
137
138                 // do the ranges intersect ?
139                 bool intersects(Range const & r) const;
140
141                 pos_type start;
142                 pos_type end; // Caution: end is not in the range!
143         };
144
145         friend bool operator==(Range const & r1, Range const & r2);
146         friend bool operator!=(Range const & r1, Range const & r2);
147
148         class ChangeRange {
149         public:
150                 ChangeRange(Change const & c, Range const & r)
151                         : change(c), range(r) {}
152
153                 Change change;
154                 Range range;
155         };
156
157         /// merge equal changes with adjoining ranges
158         void merge();
159
160         typedef std::vector<ChangeRange> ChangeTable;
161
162         /// table of changes, every row a change and range descriptor
163         ChangeTable table_;
164 };
165
166
167 } // namespace lyx
168
169 #endif // CHANGES_H