]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.h
Change tracking:
[lyx.git] / src / paragraph_pimpl.h
1 // -*- C++ -*-
2 /**
3  * \file paragraph_pimpl.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef PARAGRAPH_PIMPL_H
16 #define PARAGRAPH_PIMPL_H
17
18 #include "paragraph.h"
19
20 #include "changes.h"
21 #include "lyxfont.h"
22 #include "ParagraphParameters.h"
23
24 #include <boost/scoped_ptr.hpp>
25
26 class LyXLayout;
27
28
29 class Paragraph::Pimpl {
30 public:
31         ///
32         Pimpl(Paragraph * owner);
33         /// "Copy constructor"
34         Pimpl(Pimpl const &, Paragraph * owner);
35         ///
36         void setContentsFromPar(Paragraph const & par);
37
38         //
39         // Change tracking
40         //
41         /// look up change at given pos
42         Change const lookupChange(lyx::pos_type pos) const;
43         /// is there a change within the given range ?
44         bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
45         /// is there a non-addition in this range ?
46         bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
47         /// set change type at given pos
48         void setChangeType(lyx::pos_type pos, Change::Type type);
49         /// set change at given pos
50         void setChange(lyx::pos_type pos, Change change);
51         /// mark as erased
52         void markErased(bool);
53         /// accept change
54         void acceptChange(lyx::pos_type start, lyx::pos_type end);
55         /// reject change
56         void rejectChange(lyx::pos_type start, lyx::pos_type end);
57         /// are we tracking changes ?
58         bool tracking() const { return changes_.get(); }
59
60         ///
61         value_type getChar(lyx::pos_type pos) const;
62         ///
63         void setChar(lyx::pos_type pos, value_type c);
64         ///
65         void insertChar(lyx::pos_type pos, value_type c, Change change);
66         ///
67         void insertInset(lyx::pos_type pos, InsetBase * inset, Change change);
68         /// definite erase
69         void eraseIntern(lyx::pos_type pos);
70         /// erase the given position. Returns true if it was actually erased
71         bool erase(lyx::pos_type pos);
72         /// erase the given range
73         int erase(lyx::pos_type start, lyx::pos_type end);
74         ///
75         InsetBase * inset_owner;
76
77         /** A font entry covers a range of positions. Notice that the
78             entries in the list are inserted in random order.
79             I don't think it's worth the effort to implement a more effective
80             datastructure, because the number of different fonts in a paragraph
81             is limited. (Asger)
82             Nevertheless, I decided to store fontlist using a sorted vector:
83             fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
84             pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
85             and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
86             (font_1 covers the chars 0,...,pos_1) (Dekel)
87         */
88         class FontTable  {
89         public:
90                 ///
91                 FontTable(lyx::pos_type p, LyXFont const & f)
92                         : pos_(p), font_(f)
93                 {}
94                 ///
95                 lyx::pos_type pos() const { return pos_; }
96                 ///
97                 void pos(lyx::pos_type p) { pos_ = p; }
98                 ///
99                 LyXFont const & font() const { return font_; }
100                 ///
101                 void font(LyXFont const & f) { font_ = f;}
102         private:
103                 /// End position of paragraph this font attribute covers
104                 lyx::pos_type pos_;
105                 /** Font. Interpretation of the font values:
106                     If a value is LyXFont::INHERIT_*, it means that the font
107                     attribute is inherited from either the layout of this
108                     paragraph or, in the case of nested paragraphs, from the
109                     layout in the environment one level up until completely
110                     resolved.
111                     The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
112                     allowed in these font tables.
113                 */
114                 LyXFont font_;
115         };
116         ///
117         friend class matchFT;
118         ///
119         class matchFT {
120         public:
121                 /// used by lower_bound and upper_bound
122                 int operator()(FontTable const & a, FontTable const & b) const {
123                         return a.pos() < b.pos();
124                 }
125         };
126
127         ///
128         typedef std::vector<FontTable> FontList;
129         ///
130         FontList fontlist;
131
132         ///
133         void simpleTeXBlanks(std::ostream &, TexRow & texrow,
134                              lyx::pos_type const i,
135                              unsigned int & column,
136                              LyXFont const & font,
137                              LyXLayout const & style);
138         ///
139         void simpleTeXSpecialChars(Buffer const &, BufferParams const &,
140                                    std::ostream &, TexRow & texrow,
141                                    OutputParams const &,
142                                    LyXFont & font, LyXFont & running_font,
143                                    LyXFont & basefont,
144                                    LyXFont const & outerfont,
145                                    bool & open_font,
146                                    Change::Type & running_change,
147                                    LyXLayout const & style,
148                                    lyx::pos_type & i,
149                                    unsigned int & column, value_type const c);
150
151         ///
152         void validate(LaTeXFeatures & features,
153                       LyXLayout const & layout) const;
154
155         ///
156         unsigned int id_;
157         ///
158         static unsigned int paragraph_id;
159         ///
160         ParagraphParameters params;
161
162 private:
163         ///
164         lyx::pos_type size() const { return owner_->size(); }
165         /// match a string against a particular point in the paragraph
166         bool isTextAt(std::string const & str, lyx::pos_type pos) const;
167
168         /// for recording and looking up changes in revision tracking mode
169         boost::scoped_ptr<Changes> changes_;
170
171         /// Who owns us?
172         Paragraph * owner_;
173 };
174
175 #endif