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