4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
12 * Record changes in a paragraph.
20 #include "support/strfwd.h"
21 #include "support/types.h"
22 #include "support/lyxtime.h"
24 #include "texstream.h"
38 /// the type of change
40 UNCHANGED, // no change
42 DELETED // deleted text
45 explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = support::current_time())
46 : type(t), author(a), changetime(ct) {}
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
53 bool changed() const { return type != UNCHANGED; }
55 void setUnchanged() { type = UNCHANGED; }
57 bool inserted() const { return type == INSERTED; }
59 void setInserted() { type = INSERTED; }
61 bool deleted() const { return type == DELETED; }
63 void setDeleted() { type = DELETED; }
64 /// Is this change made by the current author ?
65 bool currentAuthor() const { return author == 0; }
74 bool operator==(Change const & l, Change const & r);
75 bool operator!=(Change const & l, Change const & r);
81 Changes() : is_update_required_(false) {}
83 /// set the pos to the given change
84 void set(Change const & change, pos_type pos);
85 /// set the range (excluding end) to the given change
86 void set(Change const & change, pos_type start, pos_type end);
88 /// erase the entry at pos and adjust all range bounds past it
89 /// (assumes that a character was deleted at pos)
90 void erase(lyx::pos_type pos);
92 /// insert a new entry at pos and adjust all range bounds past it
93 /// (assumes that a character was inserted at pos)
94 void insert(Change const & change, lyx::pos_type pos);
98 /// return the change at the given pos
99 Change const & lookup(pos_type pos) const;
101 /// return true if there is a change in the given range (excluding end)
102 bool isChanged(pos_type start, pos_type end) const;
104 bool isChanged() const;
106 /// return true if the whole range is deleted
107 bool isDeleted(pos_type start, pos_type end) const;
109 /// output latex to mark a transition between two change types
110 /// returns length of text outputted
111 static int latexMarkChange(otexstream & os, BufferParams const & bparams,
112 Change const & oldChange, Change const & change,
113 OutputParams const & runparams);
115 /// output .lyx file format for transitions between changes
116 static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
117 int & column, Change const & old, Change const & change);
120 void checkAuthors(AuthorList const & authorList);
123 void addToToc(DocIterator const & cdit, Buffer const & buffer,
124 bool output_active) const;
127 void updateBuffer(Buffer const & buf);
129 bool isUpdateRequired() const { return is_update_required_; }
134 Range(pos_type s, pos_type e)
135 : start(s), end(e) {}
137 // does this range contain r ? (inlined as the result of profiling)
138 bool contains(Range const & r) const {
139 return r.start >= start && r.end <= end;
142 // does this range contain pos ? (inlined as the result of profiling)
143 bool contains(pos_type pos) const {
144 return pos >= start && pos < end;
147 // do the ranges intersect ?
148 bool intersects(Range const & r) const;
151 pos_type end; // Caution: end is not in the range!
154 friend bool operator==(Range const & r1, Range const & r2);
155 friend bool operator!=(Range const & r1, Range const & r2);
159 ChangeRange(Change const & c, Range const & r)
160 : change(c), range(r) {}
166 /// merge equal changes with adjoining ranges
169 typedef std::vector<ChangeRange> ChangeTable;
171 /// table of changes, every row a change and range descriptor
174 /// signals that the buffer's flag tracked_changes_present_ needs to be
176 bool is_update_required_;