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