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
10 * \author André Pönitz
11 * \author Jürgen Vigna
13 * Full author contact details are available in file CREDITS.
20 #include "InsetList.h"
21 #include "lyxlayout_ptr_fwd.h"
22 #include "RowList_fwd.h"
24 #include "insets/insetbase.h" // only for InsetBase::Code
26 #include "support/types.h"
42 class ParagraphParameters;
46 /// A Paragraph holds all text, attributes and insets in a text paragraph
51 /// Note that this is 1 right now to avoid
52 /// crashes where getChar() is called wrongly
53 /// (returning 0) - if this was 0, then we'd
54 /// try getInset() and crash. We should fix
59 typedef char value_type;
61 typedef lyx::depth_type depth_type;
63 typedef std::vector<value_type> TextContainer;
68 Paragraph(Paragraph const &);
70 Paragraph & operator=(Paragraph const &);
78 Language const * getParLanguage(BufferParams const &) const;
80 bool isRightToLeftPar(BufferParams const &) const;
82 void changeLanguage(BufferParams const & bparams,
83 Language const * from, Language const * to);
85 bool isMultiLingual(BufferParams const &) const;
88 std::string const asString(Buffer const &,
89 OutputParams const & runparams,
92 std::string const asString(Buffer const &, bool label) const;
94 std::string const Paragraph::asString(Buffer const & buffer,
99 std::string const asString(Buffer const &,
100 OutputParams const & runparams,
106 void write(Buffer const &, std::ostream &, BufferParams const &,
107 depth_type & depth) const;
109 void validate(LaTeXFeatures &) const;
112 int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
115 int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
119 bool simpleTeXOnePar(Buffer const &, BufferParams const &,
120 LyXFont const & outerfont, std::ostream &,
121 TexRow & texrow, OutputParams const &);
124 void simpleLinuxDocOnePar(Buffer const & buf,
126 LyXFont const & outerfont,
127 OutputParams const & runparams,
128 lyx::depth_type depth) const;
131 void simpleDocBookOnePar(Buffer const & buf,
133 LyXFont const & outerfont,
134 OutputParams const & runparams,
135 lyx::depth_type depth,
139 bool hasSameLayout(Paragraph const & par) const;
142 void makeSameLayout(Paragraph const & par);
145 void setInsetOwner(UpdatableInset * inset);
147 UpdatableInset * inInset() const;
149 InsetBase::Code ownerCode() const;
151 bool autoBreakRows() const;
153 bool forceDefaultParagraphs() const;
156 lyx::pos_type size() const { return text_.size(); }
158 bool empty() const { return text_.empty(); }
160 void setContentsFromPar(Paragraph const & par);
162 void clearContents();
165 LyXLayout_ptr const & layout() const;
167 void layout(LyXLayout_ptr const & new_layout);
169 /// This is the item depth, only used by enumerate and itemize
170 signed char itemdepth;
173 InsetBibitem * bibitem() const; // ale970302
175 /// initialise tracking for this par
176 void trackChanges(Change::Type = Change::UNCHANGED);
179 void untrackChanges();
181 /// set entire paragraph to new text for change tracking
184 /// look up change type at given pos
185 Change::Type lookupChange(lyx::pos_type pos) const;
187 /// look up change at given pos
188 Change const lookupChangeFull(lyx::pos_type pos) const;
190 /// is there a change within the given range ?
191 bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
193 /// is there a non-addition in this range ?
194 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
196 /// set change at pos
197 void setChange(lyx::pos_type pos, Change::Type type);
200 void acceptChange(lyx::pos_type start, lyx::pos_type end);
203 void rejectChange(lyx::pos_type start, lyx::pos_type end);
205 /// mark whole par as erased
208 /// Paragraphs can contain "manual labels", for example, Description
209 /// environment. The text for this user-editable label is stored in
210 /// the paragraph alongside the text of the rest of the paragraph
211 /// (the body). This function returns the starting position of the
212 /// body of the text in the paragraph.
213 lyx::pos_type beginOfBody() const;
214 /// recompute this value
215 void setBeginOfBody();
218 std::string const & getLabelstring() const;
220 /// the next two functions are for the manual labels
221 std::string const getLabelWidthString() const;
223 void setLabelWidthString(std::string const & s);
225 char getAlign() const;
226 /// The nesting depth of a paragraph
227 depth_type getDepth() const;
228 /// The maximal possible depth of a paragraph after this one
229 depth_type getMaxDepthAfter() const;
231 void applyLayout(LyXLayout_ptr const & new_layout);
234 void eraseIntern(lyx::pos_type pos);
235 /// erase the char at the given position
236 bool erase(lyx::pos_type pos);
237 /// erase the given range. Returns the number of chars actually erased
238 int erase(lyx::pos_type start, lyx::pos_type end);
240 /** Get uninstantiated font setting. Returns the difference
241 between the characters font and the layoutfont.
242 This is what is stored in the fonttable
245 getFontSettings(BufferParams const &, lyx::pos_type pos) const;
247 LyXFont const getFirstFontSettings() const;
249 /** Get fully instantiated font. If pos == -1, use the layout
250 font attached to this paragraph.
251 If pos == -2, use the label font of the layout attached here.
252 In all cases, the font is instantiated, i.e. does not have any
253 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
256 LyXFont const getFont(BufferParams const &, lyx::pos_type pos,
257 LyXFont const & outerfont) const;
258 LyXFont const getLayoutFont(BufferParams const &,
259 LyXFont const & outerfont) const;
260 LyXFont const getLabelFont(BufferParams const &,
261 LyXFont const & outerfont) const;
263 * The font returned by the above functions is the same in a
264 * span of characters. This method will return the last position
265 * in the paragraph for which that font is the same.
266 * This can be used to avoid unnecessary calls to getFont.
268 lyx::pos_type getEndPosOfFontSpan(lyx::pos_type pos) const;
270 value_type getChar(lyx::pos_type pos) const;
272 value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
273 /// The position must already exist.
274 void setChar(lyx::pos_type pos, value_type c);
275 /// pos <= size() (there is a dummy font change at the end of each par)
276 void setFont(lyx::pos_type pos, LyXFont const & font);
277 /// Returns the height of the highest font in range
278 LyXFont_size highestFontInRange(lyx::pos_type startpos,
279 lyx::pos_type endpos,
280 LyXFont_size def_size) const;
282 void insert(lyx::pos_type pos, std::string const & str,
283 LyXFont const & font);
285 void insertChar(lyx::pos_type pos, value_type c);
287 void insertChar(lyx::pos_type pos, value_type c,
288 LyXFont const &, Change change = Change(Change::INSERTED));
290 bool checkInsertChar(LyXFont &);
292 void insertInset(lyx::pos_type pos, InsetBase * inset);
294 void insertInset(lyx::pos_type pos, InsetBase * inset,
295 LyXFont const &, Change change = Change(Change::INSERTED));
297 bool insetAllowed(InsetOld_code code);
299 InsetBase * getInset(lyx::pos_type pos);
301 InsetBase const * getInset(lyx::pos_type pos) const;
304 bool isHfill(lyx::pos_type pos) const;
305 /// hinted by profiler
306 bool isInset(lyx::pos_type pos) const { return getChar(pos) == META_INSET; }
308 bool isNewline(lyx::pos_type pos) const;
310 bool isSeparator(lyx::pos_type pos) const;
312 bool isLineSeparator(lyx::pos_type pos) const;
314 bool isKomma(lyx::pos_type pos) const;
315 /// Used by the spellchecker
316 bool isLetter(lyx::pos_type pos) const;
318 bool isWord(lyx::pos_type pos) const;
320 /// returns -1 if inset not found
321 int getPositionOfInset(InsetBase const * inset) const;
324 int stripLeadingSpaces();
326 /// return true if we allow multiple spaces
327 bool isFreeSpacing() const;
329 /// return true if we allow this par to stay empty
330 bool allowEmpty() const;
332 unsigned char transformChar(unsigned char c, lyx::pos_type pos) const;
334 ParagraphParameters & params();
336 ParagraphParameters const & params() const;
339 RowList::iterator getRow(lyx::pos_type pos);
341 RowList::const_iterator getRow(lyx::pos_type pos) const;
343 size_t row(lyx::pos_type pos) const;
349 mutable RowList rows;
350 /// last draw y position (baseline of top row)
352 /// total height of paragraph
354 /// total width of paragraph, may differ from workwidth
359 LyXLayout_ptr layout_;
360 /// keeping this here instead of in the pimpl makes LyX >10% faster
361 // for average tasks as buffer loading/switching etc.
364 lyx::pos_type begin_of_body_;
368 friend struct Paragraph::Pimpl;
375 inline bool isInsertedText(Paragraph const & par, lyx::pos_type pos)
377 return par.lookupChange(pos) == Change::INSERTED;
381 inline bool isDeletedText(Paragraph const & par, lyx::pos_type pos)
383 return par.lookupChange(pos) == Change::DELETED;
386 #endif // PARAGRAPH_H