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