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