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