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"
40 /// the type of change
42 UNCHANGED, // no change
44 DELETED // deleted text
47 explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = support::current_time())
48 : type(t), author(a), changetime(ct) {}
50 /// is the change similar to the given change such that both can be merged?
51 bool isSimilarTo(Change const & change) const;
52 /// The color of this change on screen
55 bool changed() const { return type != UNCHANGED; }
57 void setUnchanged() { type = UNCHANGED; }
59 bool inserted() const { return type == INSERTED; }
61 void setInserted() { type = INSERTED; }
63 bool deleted() const { return type == DELETED; }
65 void setDeleted() { type = DELETED; }
66 /// Is this change made by the current author ?
67 bool currentAuthor() const { return author == 0; }
69 /// Paint under- or strike-through line
71 /// Text : underline or strike through
75 void paintCue(PainterInfo & pi, double const x1, double const y,
76 double const x2, FontInfo const & font) const;
77 /// Box : line below or diagonal
78 /// \param x1,y1 top-left corner
79 /// \param x2,y2 bottom-right corner
80 void paintCue(PainterInfo & pi, double const x1, double const y1,
81 double const x2, double const y2) const;
90 bool operator==(Change const & l, Change const & r);
91 bool operator!=(Change const & l, Change const & r);
97 Changes() : is_update_required_(false) {}
99 /// set the pos to the given change
100 void set(Change const & change, pos_type pos);
101 /// set the range (excluding end) to the given change
102 void set(Change const & change, pos_type start, pos_type end);
104 /// erase the entry at pos and adjust all range bounds past it
105 /// (assumes that a character was deleted at pos)
106 void erase(lyx::pos_type pos);
108 /// insert a new entry at pos and adjust all range bounds past it
109 /// (assumes that a character was inserted at pos)
110 void insert(Change const & change, lyx::pos_type pos);
114 /// return the change at the given pos
115 Change const & lookup(pos_type pos) const;
117 /// return true if there is a change in the given range (excluding end)
118 bool isChanged(pos_type start, pos_type end) const;
120 bool isChanged() const;
122 /// return true if the whole range is deleted
123 bool isDeleted(pos_type start, pos_type end) const;
125 /// output latex to mark a transition between two change types
126 /// returns length of text outputted
127 static int latexMarkChange(otexstream & os, BufferParams const & bparams,
128 Change const & oldChange, Change const & change,
129 OutputParams const & runparams);
131 /// output .lyx file format for transitions between changes
132 static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
133 int & column, Change const & old, Change const & change);
136 void checkAuthors(AuthorList const & authorList);
139 void addToToc(DocIterator const & cdit, Buffer const & buffer,
140 bool output_active) const;
143 void updateBuffer(Buffer const & buf);
145 bool isUpdateRequired() const { return is_update_required_; }
150 Range(pos_type s, pos_type e)
151 : start(s), end(e) {}
153 // does this range contain r ? (inlined as the result of profiling)
154 bool contains(Range const & r) const {
155 return r.start >= start && r.end <= end;
158 // does this range contain pos ? (inlined as the result of profiling)
159 bool contains(pos_type pos) const {
160 return pos >= start && pos < end;
163 // do the ranges intersect ?
164 bool intersects(Range const & r) const;
167 pos_type end; // Caution: end is not in the range!
170 friend bool operator==(Range const & r1, Range const & r2);
171 friend bool operator!=(Range const & r1, Range const & r2);
175 ChangeRange(Change const & c, Range const & r)
176 : change(c), range(r) {}
182 /// merge equal changes with adjoining ranges
185 typedef std::vector<ChangeRange> ChangeTable;
187 /// table of changes, every row a change and range descriptor
190 /// signals that the buffer's flag tracked_changes_present_ needs to be
192 bool is_update_required_;