]> git.lyx.org Git - lyx.git/blob - src/Changes.h
Remove black box around GuiWorkarea? which is visible with Qt4.5.
[lyx.git] / src / Changes.h
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.
6  *
7  * \author John Levon
8  * \author Michael Gerz
9  *
10  * Full author contact details are available in file CREDITS.
11  *
12  * Record changes in a paragraph.
13  */
14
15 #ifndef CHANGES_H
16 #define CHANGES_H
17
18 #include "Color.h"
19
20 #include "support/strfwd.h"
21 #include "support/types.h"
22 #include "support/lyxtime.h"
23
24 #include <vector>
25
26
27 namespace lyx {
28
29 class AuthorList;
30 class Buffer;
31 class DocIterator;
32
33 class Change {
34 public:
35         /// the type of change
36         enum Type {
37                 UNCHANGED, // no change
38                 INSERTED, // new text
39                 DELETED // deleted text
40         };
41
42         explicit Change(Type t = UNCHANGED, int a = 0, time_t ct = current_time())
43                 : type(t), author(a), changetime(ct) {}
44
45         /// is the change similar to the given change such that both can be merged?
46         bool isSimilarTo(Change const & change) const;
47         /// The color of this change on screen
48         Color color() const;
49         ///
50         bool changed() const { return type != UNCHANGED; }
51         ///
52         void setUnchanged() { type = UNCHANGED; }
53         ///
54         bool inserted() const { return type == INSERTED; }
55         ///
56         void setInserted() { type = INSERTED; }
57         ///
58         bool deleted() const { return type == DELETED; }
59         ///
60         void setDeleted() { type = DELETED; }
61
62         Type type;
63
64         int author;
65
66         time_t changetime;
67 };
68
69 bool operator==(Change const & l, Change const & r);
70 bool operator!=(Change const & l, Change const & r);
71
72 class BufferParams;
73
74 class Changes {
75 public:
76         /// set the pos to the given change
77         void set(Change const & change, pos_type pos);
78         /// set the range (excluding end) to the given change
79         void set(Change const & change, pos_type start, pos_type end);
80
81         /// erase the entry at pos and adjust all range bounds past it
82         /// (assumes that a character was deleted at pos)
83         void erase(lyx::pos_type pos);
84
85         /// insert a new entry at pos and adjust all range bounds past it
86         /// (assumes that a character was inserted at pos)
87         void insert(Change const & change, lyx::pos_type pos);
88
89         ///
90
91         /// return the change at the given pos
92         Change const & lookup(pos_type pos) const;
93
94         /// return true if there is a change in the given range (excluding end)
95         bool isChanged(pos_type start, pos_type end) const;
96
97         /// return true if the whole range is deleted
98         bool isFullyDeleted(pos_type const start, pos_type const end) const;            
99
100         /// output latex to mark a transition between two change types
101         /// returns length of text outputted
102         static int latexMarkChange(odocstream & os, BufferParams const & bparams,
103                                    Change const & oldChange, Change const & change);
104
105         /// output .lyx file format for transitions between changes
106         static void lyxMarkChange(std::ostream & os, int & column,
107                 Change const & old, Change const & change);
108
109         ///
110         void checkAuthors(AuthorList const & authorList);
111
112         ///
113         void addToToc(DocIterator const & cdit, Buffer const & buffer) const;
114
115 private:
116         class Range {
117         public:
118                 Range(pos_type s, pos_type e)
119                         : start(s), end(e) {}
120
121                 // does this range contain r ? (inlined as the result of profiling)
122                 bool contains(Range const & r) const {
123                         return r.start >= start && r.end <= end;
124                 }
125
126                 // does this range contain pos ? (inlined as the result of profiling)
127                 bool contains(pos_type pos) const {
128                         return pos >= start && pos < end;
129                 }
130
131                 // do the ranges intersect ?
132                 bool intersects(Range const & r) const;
133
134                 pos_type start;
135                 pos_type end; // Caution: end is not in the range!
136         };
137
138         friend bool operator==(Range const & r1, Range const & r2);
139         friend bool operator!=(Range const & r1, Range const & r2);
140
141         class ChangeRange {
142         public:
143                 ChangeRange(Change const & c, Range const & r)
144                         : change(c), range(r) {}
145
146                 Change change;
147                 Range range;
148         };
149
150         /// merge equal changes with adjoining ranges
151         void merge();
152
153         typedef std::vector<ChangeRange> ChangeTable;
154
155         /// table of changes, every row a change and range descriptor
156         ChangeTable table_;
157 };
158
159
160 } // namespace lyx
161
162 #endif // CHANGES_H