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