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