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