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"
41 /// the type of change
43 UNCHANGED, // no change
45 DELETED // deleted text
48 explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = support::current_time())
49 : type(t), author(a), changetime(ct) {}
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
56 bool changed() const { return type != UNCHANGED; }
58 void setUnchanged() { type = UNCHANGED; }
60 bool inserted() const { return type == INSERTED; }
62 void setInserted() { type = INSERTED; }
64 bool deleted() const { return type == DELETED; }
66 void setDeleted() { type = DELETED; }
67 /// Is this change made by the current author ?
68 bool currentAuthor() const { return author == 0; }
70 /// Paint under- or strike-through line
72 /// Text : underline or strike through
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;
91 bool operator==(Change const & l, Change const & r);
92 bool operator!=(Change const & l, Change const & r);
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);
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);
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);
113 /// return the change at the given pos
114 Change const & lookup(pos_type pos) const;
116 /// return true if there is a change in the given range (excluding end)
117 bool isChanged(pos_type start, pos_type end) const;
119 bool isChanged() const;
121 /// return true if the whole range is deleted
122 bool isDeleted(pos_type start, pos_type end) const;
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);
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);
135 void checkAuthors(AuthorList const & authorList) const;
138 void addToToc(DocIterator const & cdit, Buffer const & buffer,
139 bool output_active, TocBackend & backend) const;
144 Range(pos_type s, pos_type e)
145 : start(s), end(e) {}
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;
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;
157 // do the ranges intersect ?
158 bool intersects(Range const & r) const;
161 pos_type end; // Caution: end is not in the range!
164 friend bool operator==(Range const & r1, Range const & r2);
165 friend bool operator!=(Range const & r1, Range const & r2);
169 ChangeRange(Change const & c, Range const & r)
170 : change(c), range(r) {}
176 /// merge equal changes with adjoining ranges
179 typedef std::vector<ChangeRange> ChangeTable;
181 /// table of changes, every row a change and range descriptor