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