]> git.lyx.org Git - lyx.git/blob - src/Paragraph.h
* gcc does not like missing characters in keywords
[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 "FontEnums.h"
20 #include "LayoutPtr.h"
21
22 #include "insets/InsetCode.h"
23
24 #include "support/strfwd.h"
25 #include "support/types.h"
26 // FIXME: would be nice to forward declare odocstream instead of
27 // including this:
28 #include "support/docstream.h"
29
30 namespace lyx {
31
32 class AuthorList;
33 class Buffer;
34 class BufferParams;
35 class Change;
36 class Counters;
37 class Inset;
38 class InsetBibitem;
39 class LaTeXFeatures;
40 class Inset_code;
41 class InsetList;
42 class Language;
43 class Font;
44 class Font_size;
45 class MetricsInfo;
46 class OutputParams;
47 class PainterInfo;
48 class ParagraphParameters;
49 class TexRow;
50
51
52 class FontSpan {
53 public:
54         /// Invalid font span containing no character
55         FontSpan() : first(0), last(-1) {}
56         /// Span including first and last
57         FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
58
59 public:
60         /// Range including first and last.
61         pos_type first, last;
62 };
63
64 ///
65 enum TextCase {
66         ///
67         text_lowercase = 0,
68         ///
69         text_capitalization = 1,
70         ///
71         text_uppercase = 2
72 };
73
74
75 /// A Paragraph holds all text, attributes and insets in a text paragraph
76 class Paragraph
77 {
78 public:
79         ///
80         Paragraph();
81         ///
82         Paragraph(Paragraph const &);
83         ///
84         Paragraph & operator=(Paragraph const &);
85         ///
86         ~Paragraph();
87         ///
88         int id() const;
89
90         ///
91         Language const * getParLanguage(BufferParams const &) const;
92         ///
93         bool isRTL(BufferParams const &) const;
94         ///
95         void changeLanguage(BufferParams const & bparams,
96                             Language const * from, Language const * to);
97         ///
98         bool isMultiLingual(BufferParams const &) const;
99
100         ///
101         docstring const asString(Buffer const &, bool label) const;
102         ///
103         docstring const asString(Buffer const & buffer,
104                                    pos_type beg,
105                                    pos_type end,
106                                    bool label) const;
107
108         ///
109         void write(Buffer const &, std::ostream &, BufferParams const &,
110                    depth_type & depth) const;
111         ///
112         void validate(LaTeXFeatures &) const;
113
114         ///
115         bool latex(Buffer const &, BufferParams const &,
116                              Font const & outerfont, odocstream &,
117                              TexRow & texrow, OutputParams const &) const;
118
119         /// Can we drop the standard paragraph wrapper?
120         bool emptyTag() const;
121
122         /// Get the id of the paragraph, usefull for docbook
123         std::string getID(Buffer const & buf,
124                           OutputParams const & runparams) const;
125
126         /// Get the first word of a paragraph, return the position where it left
127         pos_type getFirstWord(Buffer const & buf,
128                                    odocstream & os,
129                                    OutputParams const & runparams) const;
130
131         /// Writes to stream the docbook representation
132         void simpleDocBookOnePar(Buffer const & buf,
133                                  odocstream &,
134                                  OutputParams const & runparams,
135                                  Font const & outerfont,
136                                  pos_type initial = 0) const;
137
138         ///
139         bool hasSameLayout(Paragraph const & par) const;
140
141         ///
142         void makeSameLayout(Paragraph const & par);
143
144         ///
145         void setInsetOwner(Inset * inset);
146         ///
147         Inset * inInset() const;
148         ///
149         InsetCode ownerCode() const;
150         ///
151         bool forceDefaultParagraphs() const;
152
153         ///
154         pos_type size() const;
155         ///
156         bool empty() const;
157
158         ///
159         LayoutPtr const & layout() const;
160         ///
161         void layout(LayoutPtr const & new_layout);
162
163         /// This is the item depth, only used by enumerate and itemize
164         signed char itemdepth;
165
166         /// look up change at given pos
167         Change const & lookupChange(pos_type pos) const;
168
169         /// is there a change within the given range ?
170         bool isChanged(pos_type start, pos_type end) const;
171         /// is there an unchanged char at the given pos ?
172         bool isUnchanged(pos_type pos) const;
173         /// is there an insertion at the given pos ?
174         bool isInserted(pos_type pos) const;
175         /// is there a deletion at the given pos ?
176         bool isDeleted(pos_type pos) const;
177
178         /// will the paragraph be physically merged with the next
179         /// one if the imaginary end-of-par character is logically deleted?
180         bool isMergedOnEndOfParDeletion(bool trackChanges) const;
181
182         /// set change for the entire par
183         void setChange(Change const & change);
184
185         /// set change at given pos
186         void setChange(pos_type pos, Change const & change);
187
188         /// accept changes within the given range
189         void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end);
190
191         /// reject changes within the given range
192         void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end);
193
194         /// Paragraphs can contain "manual labels", for example, Description
195         /// environment. The text for this user-editable label is stored in
196         /// the paragraph alongside the text of the rest of the paragraph
197         /// (the body). This function returns the starting position of the
198         /// body of the text in the paragraph.
199         pos_type beginOfBody() const;
200         /// recompute this value
201         void setBeginOfBody();
202
203         ///
204         docstring const & getLabelstring() const;
205
206         /// the next two functions are for the manual labels
207         docstring const getLabelWidthString() const;
208         /// Set label width string.
209         void setLabelWidthString(docstring const & s);
210         /// translate \p label to the paragraph language if possible.
211         docstring const translateIfPossible(docstring const & label,
212                 BufferParams const & bparams) const;
213         /// Expand the counters for the labelstring of \c layout
214         docstring expandLabel(LayoutPtr const &, BufferParams const &,
215                 bool process_appendix = true) const;
216         /// Actual paragraph alignment used
217         char getAlign() const;
218         /// The nesting depth of a paragraph
219         depth_type getDepth() const;
220         /// The maximal possible depth of a paragraph after this one
221         depth_type getMaxDepthAfter() const;
222         ///
223         void applyLayout(LayoutPtr const & new_layout);
224
225         /// (logically) erase the char at pos; return true if it was actually erased
226         bool eraseChar(pos_type pos, bool trackChanges);
227         /// (logically) erase the given range; return the number of chars actually erased
228         int eraseChars(pos_type start, pos_type end, bool trackChanges);
229
230         ///
231         void resetFonts(Font const & font);
232
233         /** Get uninstantiated font setting. Returns the difference
234             between the characters font and the layoutfont.
235             This is what is stored in the fonttable
236         */
237         Font const
238         getFontSettings(BufferParams const &, pos_type pos) const;
239         ///
240         Font const getFirstFontSettings(BufferParams const &) const;
241
242         /** Get fully instantiated font. If pos == -1, use the layout
243             font attached to this paragraph.
244             If pos == -2, use the label font of the layout attached here.
245             In all cases, the font is instantiated, i.e. does not have any
246             attributes with values FONT_INHERIT, FONT_IGNORE or
247             FONT_TOGGLE.
248         */
249         Font const getFont(BufferParams const &, pos_type pos,
250                               Font const & outerfont) const;
251         Font const getLayoutFont(BufferParams const &,
252                                     Font const & outerfont) const;
253         Font const getLabelFont(BufferParams const &,
254                                    Font const & outerfont) const;
255         /**
256          * The font returned by the above functions is the same in a
257          * span of characters. This method will return the first and
258          * the last positions in the paragraph for which that font is
259          * the same. This can be used to avoid unnecessary calls to getFont.
260          */
261         FontSpan fontSpan(pos_type pos) const;
262         ///
263         char_type getChar(pos_type pos) const;
264         /// Get the char, but mirror all bracket characters if it is right-to-left
265         char_type getUChar(BufferParams const &, pos_type pos) const;
266         /// pos <= size() (there is a dummy font change at the end of each par)
267         void setFont(pos_type pos, Font const & font);
268         /// Returns the height of the highest font in range
269         FontSize highestFontInRange(pos_type startpos,
270                                         pos_type endpos, FontSize def_size) const;
271         ///
272         void insert(pos_type pos, docstring const & str,
273                     Font const & font, Change const & change);
274
275         ///
276         void appendString(docstring const & s, Font const & font,
277                 Change const & change);
278         ///
279         void appendChar(char_type c, Font const & font, Change const & change);
280         ///
281         void insertChar(pos_type pos, char_type c, bool trackChanges);
282         ///
283         void insertChar(pos_type pos, char_type c,
284                         Font const &, bool trackChanges);
285         ///
286         void insertChar(pos_type pos, char_type c,
287                         Font const &, Change const & change);
288         ///
289         void insertInset(pos_type pos, Inset * inset,
290                          Change const & change);
291         ///
292         void insertInset(pos_type pos, Inset * inset,
293                          Font const &, Change const & change);
294         ///
295         bool insetAllowed(InsetCode code);
296         ///
297         Inset * getInset(pos_type pos);
298         ///
299         Inset const * getInset(pos_type pos) const;
300
301         /// Release inset at given position.
302         /// \warning does not honour change tracking!
303         /// Therefore, it should only be used for breaking and merging
304         /// paragraphs
305         Inset * releaseInset(pos_type pos);
306
307         ///
308         InsetList const & insetList() const;
309
310         ///
311         bool isHfill(pos_type pos) const;
312
313         /// hinted by profiler
314         bool isInset(pos_type pos) const;
315         ///
316         bool isNewline(pos_type pos) const;
317         /// return true if the char is a word separator
318         bool isSeparator(pos_type pos) const;
319         ///
320         bool isLineSeparator(pos_type pos) const;
321         /// True if the character/inset at this point can be part of a word.
322         /// Note that digits in particular are considered as letters
323         bool isLetter(pos_type pos) const;
324
325         /// returns true if at least one line break or line separator has been deleted
326         /// at the beginning of the paragraph (either physically or logically)
327         bool stripLeadingSpaces(bool trackChanges);
328
329         /// return true if we allow multiple spaces
330         bool isFreeSpacing() const;
331
332         /// return true if we allow this par to stay empty
333         bool allowEmpty() const;
334         ///
335         char_type transformChar(char_type c, pos_type pos) const;
336         ///
337         ParagraphParameters & params();
338         ///
339         ParagraphParameters const & params() const;
340
341         /// Check if we are in a Biblio environment and insert or
342         /// delete InsetBibitems as necessary.
343         /// \retval int 1, if we had to add an inset, in which case
344         /// the cursor will need to move cursor forward; -pos, if we deleted
345         /// an inset, in which case pos is the position from which the inset
346         /// was deleted, and the cursor will need to be moved back one if it
347         /// was previously past that position. Return 0 otherwise.
348         int checkBiblio(bool track_changes);
349
350         /// For each author, set 'used' to true if there is a change
351         /// by this author in the paragraph.
352         void checkAuthors(AuthorList const & authorList);
353
354         ///
355         void changeCase(BufferParams const & bparams, pos_type pos,
356                 pos_type right, TextCase action);
357
358         /// find \param str string inside Paragraph.
359         /// \return true if the specified string is at the specified position
360         /// \param del specifies whether deleted strings in ct mode will be considered
361         bool find(
362                 docstring const & str, ///< string to search
363                 bool cs, ///<
364                 bool mw, ///<
365                 pos_type pos, ///< start from here.
366                 bool del = true) const;
367
368 private:
369         /// Pimpl away stuff
370         class Private;
371         ///
372         friend class Paragraph::Private;
373         ///
374         Private * d;
375 };
376
377 } // namespace lyx
378
379 #endif // PARAGRAPH_H