]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.h
prevent crash when inserting minipage in table cell,
[lyx.git] / src / paragraph_pimpl.h
1 // -*- C++ -*-
2 /**
3  * \file paragraph_pimpl.h
4  * Copyright 1995-2003 the LyX Team
5  * Read the file COPYING
6  */
7
8 #ifndef PARAGRAPH_PIMPL_H
9 #define PARAGRAPH_PIMPL_H
10
11 #include "paragraph.h"
12 #include "ParagraphParameters.h"
13 #include "changes.h"
14 #include "counters.h"
15
16 #include <boost/scoped_ptr.hpp>
17
18 class LyXLayout;
19
20 struct Paragraph::Pimpl {
21         ///
22         typedef std::vector<value_type> TextContainer;
23
24         ///
25         Pimpl(Paragraph * owner);
26         /// Copy constructor
27         Pimpl(Pimpl const &, Paragraph * owner);
28         ///
29         lyx::pos_type size() const {
30                 return text.size();
31         }
32         ///
33         bool empty() const {
34                 return text.empty();
35         }
36         ///
37         void clear();
38         ///
39         void setContentsFromPar(Paragraph const & par);
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
55         /// set change at pos
56         void setChange(lyx::pos_type pos, Change::Type type);
57
58         /// mark as erased
59         void markErased();
60
61         /// accept change
62         void acceptChange(lyx::pos_type start, lyx::pos_type end);
63
64         /// reject change
65         void rejectChange(lyx::pos_type start, lyx::pos_type end);
66
67         /// are we tracking changes ?
68         bool tracking() const {
69                 return changes_.get();
70         }
71
72         ///
73         value_type getChar(lyx::pos_type pos) const;
74         ///
75         void setChar(lyx::pos_type pos, value_type c);
76         ///
77         void insertChar(lyx::pos_type pos, value_type c, LyXFont const & font, Change change = Change(Change::INSERTED));
78         ///
79         void insertInset(lyx::pos_type pos, InsetOld * inset, LyXFont const & font, Change change = Change(Change::INSERTED));
80         /// definite erase
81         void eraseIntern(lyx::pos_type pos);
82         /// erase the given position. Returns true if it was actually erased
83         bool erase(lyx::pos_type pos);
84         /// erase the given range
85         int erase(lyx::pos_type start, lyx::pos_type end);
86         ///
87         UpdatableInset * inset_owner;
88
89         /** A font entry covers a range of positions. Notice that the
90             entries in the list are inserted in random order.
91             I don't think it's worth the effort to implement a more effective
92             datastructure, because the number of different fonts in a paragraph
93             is limited. (Asger)
94             Nevertheless, I decided to store fontlist using a sorted vector:
95             fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
96             pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
97             and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
98             (font_1 covers the chars 0,...,pos_1) (Dekel)
99         */
100         struct FontTable  {
101                 ///
102                 FontTable(lyx::pos_type p, LyXFont const & f)
103                         : pos_(p)
104                         {
105                                 font_ = container.get(f);
106                         }
107                 ///
108                 lyx::pos_type pos() const { return pos_; }
109                 ///
110                 void pos(lyx::pos_type p) { pos_ = p; }
111                 ///
112                 LyXFont const & font() const { return *font_; }
113                 ///
114                 void font(LyXFont const & f) { font_ = container.get(f);}
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                 boost::shared_ptr<LyXFont> font_;
128                 ///
129                 static ShareContainer<LyXFont> container;
130         };
131         ///
132         friend struct matchFT;
133         ///
134         struct matchFT {
135                 /// used by lower_bound and upper_bound
136                 inline
137                 int operator()(FontTable const & a, FontTable const & b) const {
138                         return a.pos() < b.pos();
139                 }
140         };
141
142         ///
143         typedef std::vector<FontTable> FontList;
144         ///
145         FontList fontlist;
146
147         ///
148         void simpleTeXBlanks(std::ostream &, TexRow & texrow,
149                              lyx::pos_type const i,
150                              unsigned int & column,
151                              LyXFont const & font,
152                              LyXLayout const & style);
153         ///
154         void simpleTeXSpecialChars(Buffer const *, BufferParams const &,
155                                    std::ostream &, TexRow & texrow,
156                                    LatexRunParams const &,
157                                    LyXFont & font, LyXFont & running_font,
158                                    LyXFont & basefont,
159                                    LyXFont const & outerfont,
160                                    bool & open_font,
161                                    Change::Type & running_change,
162                                    LyXLayout const & style,
163                                    lyx::pos_type & i,
164                                    unsigned int & column, value_type const c);
165
166         ///
167         void validate(LaTeXFeatures & features,
168                       LyXLayout const & layout) const;
169
170         ///
171         unsigned int id_;
172         ///
173         static unsigned int paragraph_id;
174         ///
175         ParagraphParameters params;
176
177 private:
178         /// match a string against a particular point in the paragraph
179         bool isTextAt(string const & str, lyx::pos_type pos) const;
180
181         /// for recording and looking up changes in revision tracking mode
182         boost::scoped_ptr<Changes> changes_;
183
184         /// Who owns us?
185         Paragraph * owner_;
186         ///
187         TextContainer text;
188 };
189
190 #endif