tufte layout files:
[lyx.git] / src / Paragraph.h
blob0336ffead27a425628b4e7acf32a0c5fd85a36bb
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.
7 * \author Asger Alstrup
8 * \author Lars Gullik Bjønnes
9 * \author John Levon
10 * \author André Pönitz
11 * \author Jürgen Vigna
13 * Full author contact details are available in file CREDITS.
16 #ifndef PARAGRAPH_H
17 #define PARAGRAPH_H
19 #include "FontEnums.h"
20 #include "Layout.h"
22 #include "insets/InsetCode.h"
24 #include "support/strfwd.h"
25 #include "support/types.h"
27 namespace lyx {
29 class AuthorList;
30 class Buffer;
31 class BufferParams;
32 class Change;
33 class Counters;
34 class Cursor;
35 class CursorSlice;
36 class DocIterator;
37 class docstring_list;
38 class DocumentClass;
39 class Inset;
40 class InsetBibitem;
41 class LaTeXFeatures;
42 class Inset_code;
43 class InsetList;
44 class Language;
45 class Font;
46 class Font_size;
47 class MetricsInfo;
48 class OutputParams;
49 class PainterInfo;
50 class ParagraphParameters;
51 class TexRow;
52 class Toc;
53 class WordLangTuple;
55 class FontSpan {
56 public:
57 /// Invalid font span containing no character
58 FontSpan() : first(0), last(-1) {}
59 /// Span including first and last
60 FontSpan(pos_type f, pos_type l) : first(f), last(l) {}
62 public:
63 /// Range including first and last.
64 pos_type first, last;
67 ///
68 enum TextCase {
69 ///
70 text_lowercase = 0,
71 ///
72 text_capitalization = 1,
73 ///
74 text_uppercase = 2
78 ///
79 enum AsStringParameter
81 AS_STR_NONE = 0, ///< No option, only printable characters.
82 AS_STR_LABEL = 1, ///< Prefix with paragraph label.
83 AS_STR_INSETS = 2, ///< Go into insets.
84 AS_STR_NEWLINES = 4 ///< Get also newline characters.
88 /// A Paragraph holds all text, attributes and insets in a text paragraph
89 class Paragraph
91 public:
92 ///
93 Paragraph();
94 ///
95 Paragraph(Paragraph const &);
96 /// Partial copy constructor.
97 /// Copy the Paragraph contents from \p beg to \p end (without end).
98 Paragraph(Paragraph const & par, pos_type beg, pos_type end);
99 ///
100 Paragraph & operator=(Paragraph const &);
102 ~Paragraph();
104 int id() const;
107 void addChangesToToc(DocIterator const & cdit, Buffer const & buf) const;
109 Language const * getParLanguage(BufferParams const &) const;
111 bool isRTL(BufferParams const &) const;
113 void changeLanguage(BufferParams const & bparams,
114 Language const * from, Language const * to);
116 bool isMultiLingual(BufferParams const &) const;
118 /// Convert the paragraph to a string.
119 /// \param AsStringParameter options. This can contain any combination of
120 /// asStringParameter values. Valid examples:
121 /// asString(AS_STR_LABEL)
122 /// asString(AS_STR_LABEL | AS_STR_INSETS)
123 /// asString(AS_STR_INSETS)
124 docstring asString(int options = AS_STR_NONE) const;
126 docstring asString(pos_type beg, pos_type end,
127 int options = AS_STR_NONE) const;
129 /// Extract only the explicitly visible text (without any formatting),
130 /// descending into insets
131 docstring stringify(pos_type beg, pos_type end, int options, OutputParams & runparams) const;
134 void write(std::ostream &, BufferParams const &,
135 depth_type & depth) const;
137 void validate(LaTeXFeatures &) const;
140 bool latex(BufferParams const &, Font const & outerfont, odocstream &,
141 TexRow & texrow, OutputParams const &,
142 int start_pos = 0, int end_pos = -1) const;
144 /// Can we drop the standard paragraph wrapper?
145 bool emptyTag() const;
147 /// Get the id of the paragraph, usefull for docbook
148 std::string getID(Buffer const & buf, OutputParams const & runparams) const;
150 /// Output the first word of a paragraph, return the position where it left.
151 pos_type firstWordDocBook(odocstream & os, OutputParams const & runparams) const;
153 /// Output the first word of a paragraph, return the position where it left.
154 pos_type firstWordLyXHTML(odocstream & os, OutputParams const & runparams) const;
156 /// Writes to stream the docbook representation
157 void simpleDocBookOnePar(Buffer const & buf,
158 odocstream &,
159 OutputParams const & runparams,
160 Font const & outerfont,
161 pos_type initial = 0) const;
162 /// \return any material that has had to be deferred until after the
163 /// paragraph has closed.
164 docstring simpleLyXHTMLOnePar(Buffer const & buf,
165 odocstream &,
166 OutputParams const & runparams,
167 Font const & outerfont,
168 pos_type initial = 0) const;
171 bool hasSameLayout(Paragraph const & par) const;
174 void makeSameLayout(Paragraph const & par);
177 void setInsetOwner(Inset const * inset);
179 Inset const & inInset() const;
181 bool allowParagraphCustomization() const;
183 bool usePlainLayout() const;
185 pos_type size() const;
187 bool empty() const;
190 Layout const & layout() const;
191 /// Do not pass a temporary to this!
192 void setLayout(Layout const & layout);
194 void setPlainOrDefaultLayout(DocumentClass const & tc);
196 void setDefaultLayout(DocumentClass const & tc);
198 void setPlainLayout(DocumentClass const & tc);
200 /// This is the item depth, only used by enumerate and itemize
201 signed char itemdepth;
203 /// look up change at given pos
204 Change const & lookupChange(pos_type pos) const;
206 /// is there a change within the given range ?
207 bool isChanged(pos_type start, pos_type end) const;
208 /// is there an unchanged char at the given pos ?
209 bool isChanged(pos_type pos) const;
210 /// is there an insertion at the given pos ?
211 bool isInserted(pos_type pos) const;
212 /// is there a deletion at the given pos ?
213 bool isDeleted(pos_type pos) const;
214 /// is the whole paragraph deleted ?
215 bool isDeleted(pos_type start, pos_type end) const;
217 /// will the paragraph be physically merged with the next
218 /// one if the imaginary end-of-par character is logically deleted?
219 bool isMergedOnEndOfParDeletion(bool trackChanges) const;
221 /// set change for the entire par
222 void setChange(Change const & change);
224 /// set change at given pos
225 void setChange(pos_type pos, Change const & change);
227 /// accept changes within the given range
228 void acceptChanges(pos_type start, pos_type end);
230 /// reject changes within the given range
231 void rejectChanges(pos_type start, pos_type end);
233 /// Paragraphs can contain "manual labels", for example, Description
234 /// environment. The text for this user-editable label is stored in
235 /// the paragraph alongside the text of the rest of the paragraph
236 /// (the body). This function returns the starting position of the
237 /// body of the text in the paragraph.
238 pos_type beginOfBody() const;
239 /// recompute this value
240 void setBeginOfBody();
243 docstring const & labelString() const;
245 /// the next two functions are for the manual labels
246 docstring const getLabelWidthString() const;
247 /// Set label width string.
248 void setLabelWidthString(docstring const & s);
249 /// Expand the counters for the labelstring of \c layout
250 docstring expandLabel(Layout const &, BufferParams const &,
251 bool process_appendix = true) const;
252 /// Actual paragraph alignment used
253 char getAlign() const;
254 /// The nesting depth of a paragraph
255 depth_type getDepth() const;
256 /// The maximal possible depth of a paragraph after this one
257 depth_type getMaxDepthAfter() const;
259 void applyLayout(Layout const & new_layout);
261 /// (logically) erase the char at pos; return true if it was actually erased
262 bool eraseChar(pos_type pos, bool trackChanges);
263 /// (logically) erase the given range; return the number of chars actually erased
264 int eraseChars(pos_type start, pos_type end, bool trackChanges);
267 void resetFonts(Font const & font);
269 /** Get uninstantiated font setting. Returns the difference
270 between the characters font and the layoutfont.
271 This is what is stored in the fonttable
273 Font const &
274 getFontSettings(BufferParams const &, pos_type pos) const;
276 Font const & getFirstFontSettings(BufferParams const &) const;
278 /** Get fully instantiated font. If pos == -1, use the layout
279 font attached to this paragraph.
280 If pos == -2, use the label font of the layout attached here.
281 In all cases, the font is instantiated, i.e. does not have any
282 attributes with values FONT_INHERIT, FONT_IGNORE or
283 FONT_TOGGLE.
285 Font const getFont(BufferParams const &, pos_type pos,
286 Font const & outerfont) const;
287 Font const getLayoutFont(BufferParams const &,
288 Font const & outerfont) const;
289 Font const getLabelFont(BufferParams const &,
290 Font const & outerfont) const;
292 * The font returned by the above functions is the same in a
293 * span of characters. This method will return the first and
294 * the last positions in the paragraph for which that font is
295 * the same. This can be used to avoid unnecessary calls to getFont.
297 FontSpan fontSpan(pos_type pos) const;
299 char_type getChar(pos_type pos) const;
300 /// Get the char, but mirror all bracket characters if it is right-to-left
301 char_type getUChar(BufferParams const &, pos_type pos) const;
302 /// pos <= size() (there is a dummy font change at the end of each par)
303 void setFont(pos_type pos, Font const & font);
304 /// Returns the height of the highest font in range
305 FontSize highestFontInRange(pos_type startpos,
306 pos_type endpos, FontSize def_size) const;
308 void insert(pos_type pos, docstring const & str,
309 Font const & font, Change const & change);
312 void appendString(docstring const & s, Font const & font,
313 Change const & change);
315 void appendChar(char_type c, Font const & font, Change const & change);
317 void insertChar(pos_type pos, char_type c, bool trackChanges);
319 void insertChar(pos_type pos, char_type c,
320 Font const &, bool trackChanges);
322 void insertChar(pos_type pos, char_type c,
323 Font const &, Change const & change);
324 /// Insert \p inset at position \p pos with \p change traking status.
325 /// \return true if successful.
326 bool insertInset(pos_type pos, Inset * inset,
327 Change const & change);
328 /// Insert \p inset at position \p pos with \p change traking status and
329 /// \p font.
330 /// \return true if successful.
331 bool insertInset(pos_type pos, Inset * inset,
332 Font const & font, Change const & change);
334 Inset * getInset(pos_type pos);
336 Inset const * getInset(pos_type pos) const;
338 /// Release inset at given position.
339 /// \warning does not honour change tracking!
340 /// Therefore, it should only be used for breaking and merging
341 /// paragraphs
342 Inset * releaseInset(pos_type pos);
345 InsetList const & insetList() const;
347 void setBuffer(Buffer &);
350 bool isHfill(pos_type pos) const;
352 /// hinted by profiler
353 bool isInset(pos_type pos) const;
355 bool isNewline(pos_type pos) const;
356 /// return true if the char is a word separator
357 bool isSeparator(pos_type pos) const;
359 bool isLineSeparator(pos_type pos) const;
360 /// True if the character/inset at this point is a word separator.
361 /// Note that digits in particular are not considered as word separator.
362 bool isWordSeparator(pos_type pos) const;
363 /// True if the element at this point is a character that is not a letter.
364 bool isChar(pos_type pos) const;
365 /// True if the element at this point is a space
366 bool isSpace(pos_type pos) const;
368 /// returns true if at least one line break or line separator has been deleted
369 /// at the beginning of the paragraph (either physically or logically)
370 bool stripLeadingSpaces(bool trackChanges);
372 /// return true if we allow multiple spaces
373 bool isFreeSpacing() const;
375 /// return true if we allow this par to stay empty
376 bool allowEmpty() const;
378 char_type transformChar(char_type c, pos_type pos) const;
380 ParagraphParameters & params();
382 ParagraphParameters const & params() const;
384 /// Check if we are in a Biblio environment and insert or
385 /// delete InsetBibitems as necessary.
386 /// \retval int 1, if we had to add an inset, in which case
387 /// the cursor will need to move cursor forward; -pos, if we deleted
388 /// an inset, in which case pos is the position from which the inset
389 /// was deleted, and the cursor will need to be moved back one if it
390 /// was previously past that position. Return 0 otherwise.
391 int checkBiblio(Buffer const & buffer);
393 /// For each author, set 'used' to true if there is a change
394 /// by this author in the paragraph.
395 void checkAuthors(AuthorList const & authorList);
398 void changeCase(BufferParams const & bparams, pos_type pos,
399 pos_type & right, TextCase action);
401 /// find \param str string inside Paragraph.
402 /// \return true if the specified string is at the specified position
403 /// \param del specifies whether deleted strings in ct mode will be considered
404 bool find(
405 docstring const & str, ///< string to search
406 bool cs, ///<
407 bool mw, ///<
408 pos_type pos, ///< start from here.
409 bool del = true) const;
411 void locateWord(pos_type & from, pos_type & to,
412 word_location const loc) const;
414 void updateWords();
416 /// Spellcheck word at position \p from and fill in found misspelled word
417 /// and \p suggestions if \p do_suggestion is true.
418 /// \return true if pointed word is misspelled.
419 bool spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
420 docstring_list & suggestions, bool do_suggestion = true) const;
422 /// Spellcheck word at position \p pos.
423 /// \return true if pointed word is misspelled.
424 bool isMisspelled(pos_type pos) const;
426 private:
428 void deregisterWords();
430 void collectWords();
432 void registerWords();
434 /// Pimpl away stuff
435 class Private;
437 friend class Paragraph::Private;
439 Private * d;
442 } // namespace lyx
444 #endif // PARAGRAPH_H