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 &) const;
124 void simpleLinuxDocOnePar(Buffer const & buf,
126 LyXFont const & outerfont,
127 OutputParams const & runparams,
128 lyx::depth_type depth) const;
130 /// Get the id of the paragraph, usefull for docbook
131 std::string getDocbookId() const;
134 void simpleDocBookOnePar(Buffer const & buf,
136 LyXFont const & outerfont,
137 OutputParams const & runparams,
138 lyx::depth_type depth) const;
141 bool hasSameLayout(Paragraph const & par) const;
144 void makeSameLayout(Paragraph const & par);
147 void setInsetOwner(UpdatableInset * inset);
149 UpdatableInset * inInset() const;
151 InsetBase::Code ownerCode() const;
153 bool autoBreakRows() const;
155 bool forceDefaultParagraphs() const;
158 lyx::pos_type size() const { return text_.size(); }
160 bool empty() const { return text_.empty(); }
162 void setContentsFromPar(Paragraph const & par);
164 void clearContents();
167 LyXLayout_ptr const & layout() const;
169 void layout(LyXLayout_ptr const & new_layout);
171 /// This is the item depth, only used by enumerate and itemize
172 signed char itemdepth;
175 InsetBibitem * bibitem() const; // ale970302
177 /// initialise tracking for this par
178 void trackChanges(Change::Type = Change::UNCHANGED);
181 void untrackChanges();
183 /// set entire paragraph to new text for change tracking
186 /// look up change type at given pos
187 Change::Type lookupChange(lyx::pos_type pos) const;
189 /// look up change at given pos
190 Change const lookupChangeFull(lyx::pos_type pos) const;
192 /// is there a change within the given range ?
193 bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
195 /// is there a non-addition in this range ?
196 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
198 /// set change at pos
199 void setChange(lyx::pos_type pos, Change::Type type);
202 void acceptChange(lyx::pos_type start, lyx::pos_type end);
205 void rejectChange(lyx::pos_type start, lyx::pos_type end);
207 /// mark whole par as erased
210 /// Paragraphs can contain "manual labels", for example, Description
211 /// environment. The text for this user-editable label is stored in
212 /// the paragraph alongside the text of the rest of the paragraph
213 /// (the body). This function returns the starting position of the
214 /// body of the text in the paragraph.
215 lyx::pos_type beginOfBody() const;
216 /// recompute this value
217 void setBeginOfBody();
220 std::string const & getLabelstring() const;
222 /// the next two functions are for the manual labels
223 std::string const getLabelWidthString() const;
225 void setLabelWidthString(std::string const & s);
227 char getAlign() const;
228 /// The nesting depth of a paragraph
229 depth_type getDepth() const;
230 /// The maximal possible depth of a paragraph after this one
231 depth_type getMaxDepthAfter() const;
233 void applyLayout(LyXLayout_ptr const & new_layout);
236 void eraseIntern(lyx::pos_type pos);
237 /// erase the char at the given position
238 bool erase(lyx::pos_type pos);
239 /// erase the given range. Returns the number of chars actually erased
240 int erase(lyx::pos_type start, lyx::pos_type end);
242 /** Get uninstantiated font setting. Returns the difference
243 between the characters font and the layoutfont.
244 This is what is stored in the fonttable
247 getFontSettings(BufferParams const &, lyx::pos_type pos) const;
249 LyXFont const getFirstFontSettings() const;
251 /** Get fully instantiated font. If pos == -1, use the layout
252 font attached to this paragraph.
253 If pos == -2, use the label font of the layout attached here.
254 In all cases, the font is instantiated, i.e. does not have any
255 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
258 LyXFont const getFont(BufferParams const &, lyx::pos_type pos,
259 LyXFont const & outerfont) const;
260 LyXFont const getLayoutFont(BufferParams const &,
261 LyXFont const & outerfont) const;
262 LyXFont const getLabelFont(BufferParams const &,
263 LyXFont const & outerfont) const;
265 * The font returned by the above functions is the same in a
266 * span of characters. This method will return the last position
267 * in the paragraph for which that font is the same.
268 * This can be used to avoid unnecessary calls to getFont.
270 lyx::pos_type getEndPosOfFontSpan(lyx::pos_type pos) const;
272 value_type getChar(lyx::pos_type pos) const;
274 value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
275 /// The position must already exist.
276 void setChar(lyx::pos_type pos, value_type c);
277 /// pos <= size() (there is a dummy font change at the end of each par)
278 void setFont(lyx::pos_type pos, LyXFont const & font);
279 /// Returns the height of the highest font in range
280 LyXFont_size highestFontInRange(lyx::pos_type startpos,
281 lyx::pos_type endpos,
282 LyXFont_size def_size) const;
284 void insert(lyx::pos_type pos, std::string const & str,
285 LyXFont const & font);
287 void insertChar(lyx::pos_type pos, value_type c);
289 void insertChar(lyx::pos_type pos, value_type c,
290 LyXFont const &, Change change = Change(Change::INSERTED));
292 bool checkInsertChar(LyXFont &);
294 void insertInset(lyx::pos_type pos, InsetBase * inset);
296 void insertInset(lyx::pos_type pos, InsetBase * inset,
297 LyXFont const &, Change change = Change(Change::INSERTED));
299 bool insetAllowed(InsetOld_code code);
301 InsetBase * getInset(lyx::pos_type pos);
303 InsetBase const * getInset(lyx::pos_type pos) const;
306 bool isHfill(lyx::pos_type pos) const;
307 /// hinted by profiler
308 bool isInset(lyx::pos_type pos) const { return getChar(pos) == META_INSET; }
310 bool isNewline(lyx::pos_type pos) const;
312 bool isSeparator(lyx::pos_type pos) const;
314 bool isLineSeparator(lyx::pos_type pos) const;
316 bool isKomma(lyx::pos_type pos) const;
317 /// Used by the spellchecker
318 bool isLetter(lyx::pos_type pos) const;
320 bool isWord(lyx::pos_type pos) const;
322 /// returns -1 if inset not found
323 int getPositionOfInset(InsetBase const * inset) const;
326 int stripLeadingSpaces();
328 /// return true if we allow multiple spaces
329 bool isFreeSpacing() const;
331 /// return true if we allow this par to stay empty
332 bool allowEmpty() const;
334 unsigned char transformChar(unsigned char c, lyx::pos_type pos) const;
336 ParagraphParameters & params();
338 ParagraphParameters const & params() const;
341 RowList::iterator getRow(lyx::pos_type pos);
343 RowList::const_iterator getRow(lyx::pos_type pos) const;
345 size_t row(lyx::pos_type pos) const;
351 mutable RowList rows;
352 /// last draw y position (baseline of top row)
354 /// total height of paragraph
356 /// total width of paragraph, may differ from workwidth
361 LyXLayout_ptr layout_;
362 /// keeping this here instead of in the pimpl makes LyX >10% faster
363 // for average tasks as buffer loading/switching etc.
366 lyx::pos_type begin_of_body_;
370 friend struct Paragraph::Pimpl;
377 inline bool isInsertedText(Paragraph const & par, lyx::pos_type pos)
379 return par.lookupChange(pos) == Change::INSERTED;
383 inline bool isDeletedText(Paragraph const & par, lyx::pos_type pos)
385 return par.lookupChange(pos) == Change::DELETED;
388 #endif // PARAGRAPH_H