]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
a2c27bb367ebabfd274cdb48d11a596caabaf738
[lyx.git] / src / paragraph.h
1 // -*- C++ -*-
2 /**
3  * \file paragraph.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  * \author André Pönitz
11  * \author Jürgen Vigna
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #ifndef PARAGRAPH_H
17 #define PARAGRAPH_H
18
19 #include "lyxlayout_ptr_fwd.h"
20 #include "lyxfont.h" // Just for LyXFont::FONT_SIZE
21 #include "InsetList.h"
22
23 #include "insets/inset.h" // Just for InsetOld::Code
24
25 #include "support/types.h"
26 #include "changes.h"
27 #include "RowList_fwd.h"
28
29 #include "support/std_string.h"
30
31 class Buffer;
32 class BufferParams;
33 class BufferView;
34 class Counters;
35 class InsetBibitem;
36 class Language;
37 class LaTeXFeatures;
38 class LatexRunParams;
39 class ParagraphParameters;
40 class TexRow;
41 class UpdatableInset;
42
43 /// A Paragraph holds all text, attributes and insets in a text paragraph
44 class Paragraph  {
45 public:
46         ///
47         enum META_KIND {
48                 /// Note that this is 1 right now to avoid
49                 /// crashes where getChar() is called wrongly
50                 /// (returning 0) - if this was 0, then we'd
51                 /// try getInset() and crash. We should fix
52                 /// all these places.
53                 META_INSET = 1
54         };
55         ///
56         typedef char value_type;
57         /// The same as ParameterStruct::depth_type
58         typedef unsigned int depth_type;
59
60         ///
61         Paragraph();
62
63         ///
64         Paragraph(Paragraph const &);
65         ///
66         void operator=(Paragraph const &);
67         /// the destructor removes the new paragraph from the list
68         ~Paragraph();
69
70         ///
71         Language const * getParLanguage(BufferParams const &) const;
72         ///
73         bool isRightToLeftPar(BufferParams const &) const;
74         ///
75         void changeLanguage(BufferParams const & bparams,
76                             Language const * from, Language const * to);
77         ///
78         bool isMultiLingual(BufferParams const &);
79
80         ///
81         string const asString(Buffer const &, bool label) const;
82         ///
83         string const asString(Buffer const &, lyx::pos_type beg, lyx::pos_type end,
84                               bool label) const;
85
86         ///
87         void write(Buffer const &, std::ostream &, BufferParams const &,
88                        depth_type & depth) const;
89         ///
90         void validate(LaTeXFeatures &) const;
91
92         /// return the unique ID of this paragraph
93         int id() const;
94         /// Set the Id of this paragraph.
95         void id(int);
96
97         ///
98         int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
99
100         ///
101         int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
102
103
104         ///
105         bool simpleTeXOnePar(Buffer const &, BufferParams const &,
106                              LyXFont const & outerfont, std::ostream &,
107                              TexRow & texrow, LatexRunParams const &);
108
109         ///
110         bool hasSameLayout(Paragraph const & par) const;
111
112         ///
113         void makeSameLayout(Paragraph const & par);
114
115         ///
116         UpdatableInset * inInset() const;
117         ///
118         void setInsetOwner(UpdatableInset * inset);
119         ///
120         void deleteInsetsLyXText(BufferView *);
121
122         ///
123         lyx::pos_type size() const;
124         ///
125         bool empty() const;
126         ///
127         void setContentsFromPar(Paragraph const & par);
128         ///
129         void clearContents();
130
131         ///
132         LyXLayout_ptr const & layout() const;
133         ///
134         void layout(LyXLayout_ptr const & new_layout);
135
136         ///
137         char enumdepth;
138
139         ///
140         char itemdepth;
141
142         ///
143         InsetBibitem * bibitem() const;  // ale970302
144
145         /// initialise tracking for this par
146         void trackChanges(Change::Type = Change::UNCHANGED);
147
148         /// stop tracking
149         void untrackChanges();
150
151         /// set entire paragraph to new text for change tracking
152         void cleanChanges();
153
154         /// look up change type at given pos
155         Change::Type lookupChange(lyx::pos_type pos) const;
156
157         /// look up change at given pos
158         Change const lookupChangeFull(lyx::pos_type pos) const;
159
160         /// is there a change within the given range ?
161         bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
162
163         /// is there a non-addition in this range ?
164         bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
165
166         /// set change at pos
167         void setChange(lyx::pos_type pos, Change::Type type);
168
169         /// accept change
170         void acceptChange(lyx::pos_type start, lyx::pos_type end);
171
172         /// reject change
173         void rejectChange(lyx::pos_type start, lyx::pos_type end);
174
175         /// mark whole par as erased
176         void markErased();
177
178         /// Paragraphs can contain "manual labels", for example, Description
179         /// environment. The text for this user-editable label is stored in
180         /// the paragraph alongside the text of the rest of the paragraph
181         /// (the body). This function returns the starting position of the
182         /// body of the text in the paragraph.
183         int beginningOfBody() const;
184
185         ///
186         string const & getLabelstring() const;
187
188         /// the next two functions are for the manual labels
189         string const getLabelWidthString() const;
190         ///
191         void setLabelWidthString(string const & s);
192         ///
193         char getAlign() const;
194         /// The nesting depth of a paragraph
195         depth_type getDepth() const;
196         /// The maximal possible depth of a paragraph after this one
197         depth_type getMaxDepthAfter() const;
198         ///
199         void applyLayout(LyXLayout_ptr const & new_layout);
200
201         /// definite erase
202         void eraseIntern(lyx::pos_type pos);
203         /// erase the char at the given position
204         bool erase(lyx::pos_type pos);
205         /// erase the given range. Returns the number of chars actually erased
206         int erase(lyx::pos_type start, lyx::pos_type end);
207
208         /** Get uninstantiated font setting. Returns the difference
209             between the characters font and the layoutfont.
210             This is what is stored in the fonttable
211         */
212         LyXFont const
213         getFontSettings(BufferParams const &, lyx::pos_type pos) const;
214         ///
215         LyXFont const getFirstFontSettings() const;
216
217         /** Get fully instantiated font. If pos == -1, use the layout
218             font attached to this paragraph.
219             If pos == -2, use the label font of the layout attached here.
220             In all cases, the font is instantiated, i.e. does not have any
221             attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
222             LyXFont::TOGGLE.
223         */
224         LyXFont const getFont(BufferParams const &, lyx::pos_type pos,
225                               LyXFont const & outerfont) const;
226         LyXFont const getLayoutFont(BufferParams const &,
227                                     LyXFont const & outerfont) const;
228         LyXFont const getLabelFont(BufferParams const &,
229                                    LyXFont const & outerfont) const;
230         /**
231          * The font returned by the above functions is the same in a
232          * span of characters. This method will return the last position
233          * in the paragraph for which that font is the same.
234          * This can be used to avoid unnecessary calls to getFont.
235          */
236         lyx::pos_type getEndPosOfFontSpan(lyx::pos_type pos) const;
237         ///
238         value_type getChar(lyx::pos_type pos) const;
239         ///
240         value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
241         /// The position must already exist.
242         void setChar(lyx::pos_type pos, value_type c);
243         /// pos <= size() (there is a dummy font change at the end of each par)
244         void setFont(lyx::pos_type pos, LyXFont const & font);
245         /// Returns the height of the highest font in range
246         LyXFont::FONT_SIZE
247         highestFontInRange(lyx::pos_type startpos,
248                            lyx::pos_type endpos,
249                            LyXFont::FONT_SIZE const def_size) const;
250         ///
251         void insertChar(lyx::pos_type pos, value_type c);
252         ///
253         void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
254         ///
255         bool checkInsertChar(LyXFont &);
256         ///
257         void insertInset(lyx::pos_type pos, InsetOld * inset);
258         ///
259         void insertInset(lyx::pos_type pos, InsetOld * inset, LyXFont const &, Change change = Change(Change::INSERTED));
260         ///
261         bool insetAllowed(InsetOld::Code code);
262         ///
263         InsetOld * getInset(lyx::pos_type pos);
264         ///
265         InsetOld const * getInset(lyx::pos_type pos) const;
266
267         ///
268         bool isHfill(lyx::pos_type pos) const;
269         ///
270         bool isInset(lyx::pos_type pos) const;
271         ///
272         bool isNewline(lyx::pos_type pos) const;
273         ///
274         bool isSeparator(lyx::pos_type pos) const;
275         ///
276         bool isLineSeparator(lyx::pos_type pos) const;
277         ///
278         bool isKomma(lyx::pos_type pos) const;
279         /// Used by the spellchecker
280         bool isLetter(lyx::pos_type pos) const;
281         ///
282         bool isWord(lyx::pos_type pos) const;
283
284         /// returns -1 if inset not found
285         int getPositionOfInset(InsetOld const * inset) const;
286
287         ///
288         int stripLeadingSpaces();
289
290         /// return true if we allow multiple spaces
291         bool isFreeSpacing() const;
292
293         /// return true if we allow this par to stay empty
294         bool allowEmpty() const;
295
296         ///
297         ParagraphParameters & params();
298         ///
299         ParagraphParameters const & params() const;
300         ///
301         InsetList insetlist;
302
303         ///
304         mutable RowList rows;
305         /// last draw y position (baseline of top row)
306         int y;
307
308 private:
309         ///
310         LyXLayout_ptr layout_;
311
312         struct Pimpl;
313         ///
314         friend struct Paragraph::Pimpl;
315         ///
316         Pimpl * pimpl_;
317
318 };
319
320
321 inline bool isInsertedText(Paragraph const & par, lyx::pos_type pos)
322 {
323         return par.lookupChange(pos) == Change::INSERTED;
324 }
325
326
327 inline bool isDeletedText(Paragraph const & par, lyx::pos_type pos)
328 {
329         return par.lookupChange(pos) == Change::DELETED;
330 }
331
332 #endif // PARAGRAPH_H