tufte layout files:
[lyx.git] / src / Changes.h
blobcb5f57b080a360a939cf8ffc030ce4866a097a24
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.
7 * \author John Levon
8 * \author Michael Gerz
10 * Full author contact details are available in file CREDITS.
12 * Record changes in a paragraph.
15 #ifndef CHANGES_H
16 #define CHANGES_H
18 #include "Color.h"
20 #include "support/docstream.h"
21 #include "support/strfwd.h"
22 #include "support/types.h"
23 #include "support/lyxtime.h"
25 #include <vector>
28 namespace lyx {
30 class AuthorList;
31 class Buffer;
32 class DocIterator;
33 class OutputParams;
35 class Change {
36 public:
37 /// the type of change
38 enum Type {
39 UNCHANGED, // no change
40 INSERTED, // new text
41 DELETED // deleted text
44 explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = current_time())
45 : type(t), author(a), changetime(ct) {}
47 /// is the change similar to the given change such that both can be merged?
48 bool isSimilarTo(Change const & change) const;
49 /// The color of this change on screen
50 Color color() const;
51 ///
52 bool changed() const { return type != UNCHANGED; }
53 ///
54 void setUnchanged() { type = UNCHANGED; }
55 ///
56 bool inserted() const { return type == INSERTED; }
57 ///
58 void setInserted() { type = INSERTED; }
59 ///
60 bool deleted() const { return type == DELETED; }
61 ///
62 void setDeleted() { type = DELETED; }
63 /// Is this change made by the current author ?
64 bool currentAuthor() const { return author == 0; }
66 Type type;
68 int author;
70 time_t changetime;
73 bool operator==(Change const & l, Change const & r);
74 bool operator!=(Change const & l, Change const & r);
76 class BufferParams;
78 class Changes {
79 public:
80 /// set the pos to the given change
81 void set(Change const & change, pos_type pos);
82 /// set the range (excluding end) to the given change
83 void set(Change const & change, pos_type start, pos_type end);
85 /// erase the entry at pos and adjust all range bounds past it
86 /// (assumes that a character was deleted at pos)
87 void erase(lyx::pos_type pos);
89 /// insert a new entry at pos and adjust all range bounds past it
90 /// (assumes that a character was inserted at pos)
91 void insert(Change const & change, lyx::pos_type pos);
93 ///
95 /// return the change at the given pos
96 Change const & lookup(pos_type pos) const;
98 /// return true if there is a change in the given range (excluding end)
99 bool isChanged(pos_type start, pos_type end) const;
101 /// return true if the whole range is deleted
102 bool isDeleted(pos_type start, pos_type end) const;
104 /// output latex to mark a transition between two change types
105 /// returns length of text outputted
106 static int latexMarkChange(odocstream & os, BufferParams const & bparams,
107 Change const & oldChange, Change const & change,
108 OutputParams const & runparams);
110 /// output .lyx file format for transitions between changes
111 static void lyxMarkChange(std::ostream & os, BufferParams const & bparams,
112 int & column, Change const & old, Change const & change);
115 void checkAuthors(AuthorList const & authorList);
118 void addToToc(DocIterator const & cdit, Buffer const & buffer) const;
120 private:
121 class Range {
122 public:
123 Range(pos_type s, pos_type e)
124 : start(s), end(e) {}
126 // does this range contain r ? (inlined as the result of profiling)
127 bool contains(Range const & r) const {
128 return r.start >= start && r.end <= end;
131 // does this range contain pos ? (inlined as the result of profiling)
132 bool contains(pos_type pos) const {
133 return pos >= start && pos < end;
136 // do the ranges intersect ?
137 bool intersects(Range const & r) const;
139 pos_type start;
140 pos_type end; // Caution: end is not in the range!
143 friend bool operator==(Range const & r1, Range const & r2);
144 friend bool operator!=(Range const & r1, Range const & r2);
146 class ChangeRange {
147 public:
148 ChangeRange(Change const & c, Range const & r)
149 : change(c), range(r) {}
151 Change change;
152 Range range;
155 /// merge equal changes with adjoining ranges
156 void merge();
158 typedef std::vector<ChangeRange> ChangeTable;
160 /// table of changes, every row a change and range descriptor
161 ChangeTable table_;
165 } // namespace lyx
167 #endif // CHANGES_H