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.
18 #include "support/strfwd.h"
19 #include "support/types.h"
20 #include "support/lyxtime.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 /// set the pos to the given change
98 void set(Change const & change, pos_type pos);
99 /// set the range (excluding end) to the given change
100 void set(Change const & change, pos_type start, pos_type end);
102 /// erase the entry at pos and adjust all range bounds past it
103 /// (assumes that a character was deleted at pos)
104 void erase(pos_type pos);
106 /// insert a new entry at pos and adjust all range bounds past it
107 /// (assumes that a character was inserted at pos)
108 void insert(Change const & change, pos_type pos);
112 /// return the change at the given pos
113 Change const & lookup(pos_type pos) const;
115 /// return true if there is a change in the given range (excluding end)
116 bool isChanged(pos_type start, pos_type end) const;
118 bool isChanged() const;
120 /// return true if the whole range is deleted
121 bool isDeleted(pos_type start, pos_type end) const;
123 /// output latex to mark a transition between two change types
124 /// returns length of text outputted
125 static int latexMarkChange(otexstream & os, BufferParams const & bparams,
126 Change const & oldChange, Change const & change,
127 OutputParams const & runparams);
129 /// output .lyx file format for transitions between changes
130 static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
131 int & column, Change const & old, Change const & change);
134 void checkAuthors(AuthorList const & authorList) const;
137 void addToToc(DocIterator const & cdit, Buffer const & buffer,
138 bool output_active, TocBackend & backend) const;
143 Range(pos_type s, pos_type e)
144 : start(s), end(e) {}
146 // does this range contain r ? (inlined as the result of profiling)
147 bool contains(Range const & r) const {
148 return r.start >= start && r.end <= end;
151 // does this range contain pos ? (inlined as the result of profiling)
152 bool contains(pos_type pos) const {
153 return pos >= start && pos < end;
156 // do the ranges intersect ?
157 bool intersects(Range const & r) const;
160 pos_type end; // Caution: end is not in the range!
163 friend bool operator==(Range const & r1, Range const & r2);
164 friend bool operator!=(Range const & r1, Range const & r2);
168 ChangeRange(Change const & c, Range const & r)
169 : change(c), range(r) {}
175 /// merge equal changes with adjoining ranges
178 typedef std::vector<ChangeRange> ChangeTable;
180 /// table of changes, every row a change and range descriptor