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