]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.h
Continue to improve GtkLengthEntry
[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         /// mark as erased
58         void markErased(bool);
59         /// accept change
60         void acceptChange(lyx::pos_type start, lyx::pos_type end);
61         /// reject change
62         void rejectChange(lyx::pos_type start, lyx::pos_type end);
63         /// are we tracking changes ?
64         bool tracking() const { return changes_.get(); }
65
66         ///
67         value_type getChar(lyx::pos_type pos) const;
68         ///
69         void setChar(lyx::pos_type pos, value_type c);
70         ///
71         void insertChar(lyx::pos_type pos, value_type c, Change change);
72         ///
73         void insertInset(lyx::pos_type pos, InsetBase * inset, Change change);
74         /// definite erase
75         void eraseIntern(lyx::pos_type pos);
76         /// erase the given position. Returns true if it was actually erased
77         bool erase(lyx::pos_type pos);
78         /// erase the given range
79         int erase(lyx::pos_type start, lyx::pos_type end);
80         ///
81         InsetBase * inset_owner;
82
83         /** A font entry covers a range of positions. Notice that the
84             entries in the list are inserted in random order.
85             I don't think it's worth the effort to implement a more effective
86             datastructure, because the number of different fonts in a paragraph
87             is limited. (Asger)
88             Nevertheless, I decided to store fontlist using a sorted vector:
89             fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
90             pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
91             and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
92             (font_1 covers the chars 0,...,pos_1) (Dekel)
93         */
94         class FontTable  {
95         public:
96                 ///
97                 FontTable(lyx::pos_type p, LyXFont const & f)
98                         : pos_(p), font_(f)
99                 {
100 #if 0
101                         font_ = container.get(f);
102 #endif
103                 }
104                 ///
105                 lyx::pos_type pos() const { return pos_; }
106                 ///
107                 void pos(lyx::pos_type p) { pos_ = p; }
108                 ///
109                 LyXFont const & font() const { return font_; }
110 #if 0
111                 ///
112                 void font(LyXFont const & f) { font_ = container.get(f);}
113 #else
114                 ///
115                 void font(LyXFont const & f) { font_ = f;}
116 #endif
117         private:
118                 /// End position of paragraph this font attribute covers
119                 lyx::pos_type pos_;
120                 /** Font. Interpretation of the font values:
121                     If a value is LyXFont::INHERIT_*, it means that the font
122                     attribute is inherited from either the layout of this
123                     paragraph or, in the case of nested paragraphs, from the
124                     layout in the environment one level up until completely
125                     resolved.
126                     The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
127                     allowed in these font tables.
128                 */
129 #if 0
130                 boost::shared_ptr<LyXFont> font_;
131                 ///
132                 static ShareContainer<LyXFont> container;
133 #else
134                 LyXFont font_;
135 #endif
136         };
137         ///
138         friend class matchFT;
139         ///
140         class matchFT {
141         public:
142                 /// used by lower_bound and upper_bound
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                                    OutputParams 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         ///
185         lyx::pos_type size() const { return owner_->size(); }
186         /// match a string against a particular point in the paragraph
187         bool isTextAt(std::string const & str, lyx::pos_type pos) const;
188
189         /// for recording and looking up changes in revision tracking mode
190         boost::scoped_ptr<Changes> changes_;
191
192         /// Who owns us?
193         Paragraph * owner_;
194 };
195
196 #endif