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