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