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/inset.h" // Just for InsetOld::Code
26 #include "support/types.h"
28 #include "support/std_string.h"
39 class ParagraphParameters;
43 /// A Paragraph holds all text, attributes and insets in a text paragraph
48 /// Note that this is 1 right now to avoid
49 /// crashes where getChar() is called wrongly
50 /// (returning 0) - if this was 0, then we'd
51 /// try getInset() and crash. We should fix
56 typedef char value_type;
58 typedef lyx::depth_type depth_type;
64 Paragraph(Paragraph const &);
66 void operator=(Paragraph const &);
67 /// the destructor removes the new paragraph from the list
71 Language const * getParLanguage(BufferParams const &) const;
73 bool isRightToLeftPar(BufferParams const &) const;
75 void changeLanguage(BufferParams const & bparams,
76 Language const * from, Language const * to);
78 bool isMultiLingual(BufferParams const &);
81 string const asString(Buffer const &, bool label) const;
83 string const asString(Buffer const &, lyx::pos_type beg, lyx::pos_type end,
87 void write(Buffer const &, std::ostream &, BufferParams const &,
88 depth_type & depth) const;
90 void validate(LaTeXFeatures &) const;
92 /// return the unique ID of this paragraph
94 /// Set the Id of this paragraph.
98 int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
101 int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
105 bool simpleTeXOnePar(Buffer const &, BufferParams const &,
106 LyXFont const & outerfont, std::ostream &,
107 TexRow & texrow, LatexRunParams const &);
110 bool hasSameLayout(Paragraph const & par) const;
113 void makeSameLayout(Paragraph const & par);
116 UpdatableInset * inInset() const;
118 void setInsetOwner(UpdatableInset * inset);
120 void deleteInsetsLyXText(BufferView *);
123 lyx::pos_type size() const;
127 void setContentsFromPar(Paragraph const & par);
129 void clearContents();
132 LyXLayout_ptr const & layout() const;
134 void layout(LyXLayout_ptr const & new_layout);
143 InsetBibitem * bibitem() const; // ale970302
145 /// initialise tracking for this par
146 void trackChanges(Change::Type = Change::UNCHANGED);
149 void untrackChanges();
151 /// set entire paragraph to new text for change tracking
154 /// look up change type at given pos
155 Change::Type lookupChange(lyx::pos_type pos) const;
157 /// look up change at given pos
158 Change const lookupChangeFull(lyx::pos_type pos) const;
160 /// is there a change within the given range ?
161 bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
163 /// is there a non-addition in this range ?
164 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
166 /// set change at pos
167 void setChange(lyx::pos_type pos, Change::Type type);
170 void acceptChange(lyx::pos_type start, lyx::pos_type end);
173 void rejectChange(lyx::pos_type start, lyx::pos_type end);
175 /// mark whole par as erased
178 /// Paragraphs can contain "manual labels", for example, Description
179 /// environment. The text for this user-editable label is stored in
180 /// the paragraph alongside the text of the rest of the paragraph
181 /// (the body). This function returns the starting position of the
182 /// body of the text in the paragraph.
183 int beginningOfBody() const;
186 string const & getLabelstring() const;
188 /// the next two functions are for the manual labels
189 string const getLabelWidthString() const;
191 void setLabelWidthString(string const & s);
193 char getAlign() const;
194 /// The nesting depth of a paragraph
195 depth_type getDepth() const;
196 /// The maximal possible depth of a paragraph after this one
197 depth_type getMaxDepthAfter() const;
199 void applyLayout(LyXLayout_ptr const & new_layout);
202 void eraseIntern(lyx::pos_type pos);
203 /// erase the char at the given position
204 bool erase(lyx::pos_type pos);
205 /// erase the given range. Returns the number of chars actually erased
206 int erase(lyx::pos_type start, lyx::pos_type end);
208 /** Get uninstantiated font setting. Returns the difference
209 between the characters font and the layoutfont.
210 This is what is stored in the fonttable
213 getFontSettings(BufferParams const &, lyx::pos_type pos) const;
215 LyXFont const getFirstFontSettings() const;
217 /** Get fully instantiated font. If pos == -1, use the layout
218 font attached to this paragraph.
219 If pos == -2, use the label font of the layout attached here.
220 In all cases, the font is instantiated, i.e. does not have any
221 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
224 LyXFont const getFont(BufferParams const &, lyx::pos_type pos,
225 LyXFont const & outerfont) const;
226 LyXFont const getLayoutFont(BufferParams const &,
227 LyXFont const & outerfont) const;
228 LyXFont const getLabelFont(BufferParams const &,
229 LyXFont const & outerfont) const;
231 * The font returned by the above functions is the same in a
232 * span of characters. This method will return the last position
233 * in the paragraph for which that font is the same.
234 * This can be used to avoid unnecessary calls to getFont.
236 lyx::pos_type getEndPosOfFontSpan(lyx::pos_type pos) const;
238 value_type getChar(lyx::pos_type pos) const;
240 value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
241 /// The position must already exist.
242 void setChar(lyx::pos_type pos, value_type c);
243 /// pos <= size() (there is a dummy font change at the end of each par)
244 void setFont(lyx::pos_type pos, LyXFont const & font);
245 /// Returns the height of the highest font in range
246 LyXFont_size highestFontInRange(lyx::pos_type startpos,
247 lyx::pos_type endpos,
248 LyXFont_size def_size) const;
250 void insertChar(lyx::pos_type pos, value_type c);
252 void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
254 bool checkInsertChar(LyXFont &);
256 void insertInset(lyx::pos_type pos, InsetOld * inset);
258 void insertInset(lyx::pos_type pos, InsetOld * inset, LyXFont const &, Change change = Change(Change::INSERTED));
260 bool insetAllowed(InsetOld::Code code);
262 InsetOld * getInset(lyx::pos_type pos);
264 InsetOld const * getInset(lyx::pos_type pos) const;
267 bool isHfill(lyx::pos_type pos) const;
269 bool isInset(lyx::pos_type pos) const;
271 bool isNewline(lyx::pos_type pos) const;
273 bool isSeparator(lyx::pos_type pos) const;
275 bool isLineSeparator(lyx::pos_type pos) const;
277 bool isKomma(lyx::pos_type pos) const;
278 /// Used by the spellchecker
279 bool isLetter(lyx::pos_type pos) const;
281 bool isWord(lyx::pos_type pos) const;
283 /// returns -1 if inset not found
284 int getPositionOfInset(InsetOld const * inset) const;
287 int stripLeadingSpaces();
289 /// return true if we allow multiple spaces
290 bool isFreeSpacing() const;
292 /// return true if we allow this par to stay empty
293 bool allowEmpty() const;
296 ParagraphParameters & params();
298 ParagraphParameters const & params() const;
303 mutable RowList rows;
304 /// last draw y position (baseline of top row)
309 LyXLayout_ptr layout_;
313 friend struct Paragraph::Pimpl;
320 inline bool isInsertedText(Paragraph const & par, lyx::pos_type pos)
322 return par.lookupChange(pos) == Change::INSERTED;
326 inline bool isDeletedText(Paragraph const & par, lyx::pos_type pos)
328 return par.lookupChange(pos) == Change::DELETED;
331 #endif // PARAGRAPH_H