]> git.lyx.org Git - lyx.git/blob - src/Changes.h
Remove obsolete (and false) comment.
[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 <vector>
25
26
27 namespace lyx {
28
29 class AuthorList;
30 class Buffer;
31 class DocIterator;
32 class FontInfo;
33 class OutputParams;
34 class otexstream;
35 class PainterInfo;
36 class TocBackend;
37
38
39 class Change {
40 public:
41         /// the type of change
42         enum Type {
43                 UNCHANGED, // no change
44                 INSERTED, // new text
45                 DELETED // deleted text
46         };
47
48         explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = support::current_time())
49                 : type(t), author(a), changetime(ct) {}
50
51         /// is the change similar to the given change such that both can be merged?
52         bool isSimilarTo(Change const & change) const;
53         /// The color of this change on screen
54         Color color() const;
55         ///
56         bool changed() const { return type != UNCHANGED; }
57         ///
58         void setUnchanged() { type = UNCHANGED; }
59         ///
60         bool inserted() const { return type == INSERTED; }
61         ///
62         void setInserted() { type = INSERTED; }
63         ///
64         bool deleted() const { return type == DELETED; }
65         ///
66         void setDeleted() { type = DELETED; }
67         /// Is this change made by the current author ?
68         bool currentAuthor() const { return author == 0; }
69
70         /// Paint under- or strike-through line
71         ///
72         /// Text : underline or strike through
73         /// \param x1 begin
74         /// \param x2 end
75         /// \param y baseline
76         void paintCue(PainterInfo & pi, double const x1, double const y,
77                        double const x2, FontInfo const & font) const;
78         /// Box : line below or diagonal
79         /// \param x1,y1 top-left corner
80         /// \param x2,y2 bottom-right corner
81         void paintCue(PainterInfo & pi, double const x1, double const y1,
82                        double const x2, double const y2) const;
83
84         Type type;
85
86         int author;
87
88         time_t changetime;
89 };
90
91 bool operator==(Change const & l, Change const & r);
92 bool operator!=(Change const & l, Change const & r);
93
94 class BufferParams;
95
96 class Changes {
97 public:
98         /// set the pos to the given change
99         void set(Change const & change, pos_type pos);
100         /// set the range (excluding end) to the given change
101         void set(Change const & change, pos_type start, pos_type end);
102
103         /// erase the entry at pos and adjust all range bounds past it
104         /// (assumes that a character was deleted at pos)
105         void erase(lyx::pos_type pos);
106
107         /// insert a new entry at pos and adjust all range bounds past it
108         /// (assumes that a character was inserted at pos)
109         void insert(Change const & change, lyx::pos_type pos);
110
111         ///
112
113         /// return the change at the given pos
114         Change const & lookup(pos_type pos) const;
115
116         /// return true if there is a change in the given range (excluding end)
117         bool isChanged(pos_type start, pos_type end) const;
118         ///
119         bool isChanged() const;
120
121         /// return true if the whole range is deleted
122         bool isDeleted(pos_type start, pos_type end) const;
123
124         /// output latex to mark a transition between two change types
125         /// returns length of text outputted
126         static int latexMarkChange(otexstream & os, BufferParams const & bparams,
127                                    Change const & oldChange, Change const & change,
128                                    OutputParams const & runparams);
129
130         /// output .lyx file format for transitions between changes
131         static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
132                 int & column, Change const & old, Change const & change);
133
134         ///
135         void checkAuthors(AuthorList const & authorList);
136
137         ///
138         void addToToc(DocIterator const & cdit, Buffer const & buffer,
139                       bool output_active, TocBackend & backend) const;
140
141 private:
142         class Range {
143         public:
144                 Range(pos_type s, pos_type e)
145                         : start(s), end(e) {}
146
147                 // does this range contain r ? (inlined as the result of profiling)
148                 bool contains(Range const & r) const {
149                         return r.start >= start && r.end <= end;
150                 }
151
152                 // does this range contain pos ? (inlined as the result of profiling)
153                 bool contains(pos_type pos) const {
154                         return pos >= start && pos < end;
155                 }
156
157                 // do the ranges intersect ?
158                 bool intersects(Range const & r) const;
159
160                 pos_type start;
161                 pos_type end; // Caution: end is not in the range!
162         };
163
164         friend bool operator==(Range const & r1, Range const & r2);
165         friend bool operator!=(Range const & r1, Range const & r2);
166
167         class ChangeRange {
168         public:
169                 ChangeRange(Change const & c, Range const & r)
170                         : change(c), range(r) {}
171
172                 Change change;
173                 Range range;
174         };
175
176         /// merge equal changes with adjoining ranges
177         void merge();
178
179         typedef std::vector<ChangeRange> ChangeTable;
180
181         /// table of changes, every row a change and range descriptor
182         ChangeTable table_;
183 };
184
185
186 } // namespace lyx
187
188 #endif // CHANGES_H