4 * Copyright 1995 Matthias Ettrich
5 * Copyright 2002 the LyX Team
6 * Read the file COPYING
12 #include "lyxlayout_ptr_fwd.h"
13 #include "lyxfont.h" // Just for LyXFont::FONT_SIZE
14 #include "InsetList.h"
16 #include "insets/inset.h" // Just for InsetOld::Code
18 #include "support/types.h"
31 class ParagraphParameters;
36 /// A Paragraph holds all text, attributes and insets in a text paragraph
41 /// Note that this is 1 right now to avoid
42 /// crashes where getChar() is called wrongly
43 /// (returning 0) - if this was 0, then we'd
44 /// try getInset() and crash. We should fix
49 typedef char value_type;
50 /// The same as ParameterStruct::depth_type
51 typedef unsigned int depth_type;
57 Paragraph(Paragraph const &);
59 void operator=(Paragraph const &);
60 /// the destructor removes the new paragraph from the list
64 Language const * getParLanguage(BufferParams const &) const;
66 bool isRightToLeftPar(BufferParams const &) const;
68 void changeLanguage(BufferParams const & bparams,
69 Language const * from, Language const * to);
71 bool isMultiLingual(BufferParams const &);
74 string const asString(Buffer const *, bool label) const;
76 string const asString(Buffer const *, lyx::pos_type beg, lyx::pos_type end,
80 void write(Buffer const *, std::ostream &, BufferParams const &,
81 depth_type & depth) const;
83 void validate(LaTeXFeatures &) const;
85 /// return the unique ID of this paragraph
87 /// Set the Id of this paragraph.
91 int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
94 int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
98 bool simpleTeXOnePar(Buffer const *, BufferParams const &,
99 LyXFont const & outerfont, std::ostream &,
100 TexRow & texrow, LatexRunParams const &);
103 bool hasSameLayout(Paragraph const & par) const;
106 void makeSameLayout(Paragraph const & par);
109 UpdatableInset * inInset() const;
111 void setInsetOwner(UpdatableInset * inset);
113 void deleteInsetsLyXText(BufferView *);
116 lyx::pos_type size() const;
120 void setContentsFromPar(Paragraph const & par);
122 void clearContents();
125 LyXLayout_ptr const & layout() const;
127 void layout(LyXLayout_ptr const & new_layout);
136 InsetBibitem * bibitem() const; // ale970302
138 /// initialise tracking for this par
139 void trackChanges(Change::Type = Change::UNCHANGED);
142 void untrackChanges();
144 /// set entire paragraph to new text for change tracking
147 /// look up change type at given pos
148 Change::Type lookupChange(lyx::pos_type pos) const;
150 /// look up change at given pos
151 Change const lookupChangeFull(lyx::pos_type pos) const;
153 /// is there a change within the given range ?
154 bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
156 /// is there a non-addition in this range ?
157 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
159 /// set change at pos
160 void setChange(lyx::pos_type pos, Change::Type type);
163 void acceptChange(lyx::pos_type start, lyx::pos_type end);
166 void rejectChange(lyx::pos_type start, lyx::pos_type end);
168 /// mark whole par as erased
171 /// Paragraphs can contain "manual labels", for example, Description
172 /// environment. The text for this user-editable label is stored in
173 /// the paragraph alongside the text of the rest of the paragraph
174 /// (the body). This function returns the starting position of the
175 /// body of the text in the paragraph.
176 int beginningOfBody() const;
179 string const & getLabelstring() const;
181 /// the next two functions are for the manual labels
182 string const getLabelWidthString() const;
184 void setLabelWidthString(string const & s);
186 char getAlign() const;
187 /// The nesting depth of a paragraph
188 depth_type getDepth() const;
189 /// The maximal possible depth of a paragraph after this one
190 depth_type getMaxDepthAfter() const;
192 void applyLayout(LyXLayout_ptr const & new_layout);
195 void eraseIntern(lyx::pos_type pos);
196 /// erase the char at the given position
197 bool erase(lyx::pos_type pos);
198 /// erase the given range. Returns the number of chars actually erased
199 int erase(lyx::pos_type start, lyx::pos_type end);
201 /** Get uninstantiated font setting. Returns the difference
202 between the characters font and the layoutfont.
203 This is what is stored in the fonttable
206 getFontSettings(BufferParams const &, lyx::pos_type pos) const;
208 LyXFont const getFirstFontSettings() const;
210 /** Get fully instantiated font. If pos == -1, use the layout
211 font attached to this paragraph.
212 If pos == -2, use the label font of the layout attached here.
213 In all cases, the font is instantiated, i.e. does not have any
214 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
217 LyXFont const getFont(BufferParams const &, lyx::pos_type pos,
218 LyXFont const & outerfont) const;
219 LyXFont const getLayoutFont(BufferParams const &,
220 LyXFont const & outerfont) const;
221 LyXFont const getLabelFont(BufferParams const &,
222 LyXFont const & outerfont) const;
224 * The font returned by the above functions is the same in a
225 * span of characters. This method will return the last position
226 * in the paragraph for which that font is the same.
227 * This can be used to avoid unnecessary calls to getFont.
229 lyx::pos_type getEndPosOfFontSpan(lyx::pos_type pos) const;
231 value_type getChar(lyx::pos_type pos) const;
233 value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
234 /// The position must already exist.
235 void setChar(lyx::pos_type pos, value_type c);
236 /// pos <= size() (there is a dummy font change at the end of each par)
237 void setFont(lyx::pos_type pos, LyXFont const & font);
238 /// Returns the height of the highest font in range
240 highestFontInRange(lyx::pos_type startpos,
241 lyx::pos_type endpos,
242 LyXFont::FONT_SIZE const def_size) const;
244 void insertChar(lyx::pos_type pos, value_type c);
246 void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
248 bool checkInsertChar(LyXFont &);
250 void insertInset(lyx::pos_type pos, InsetOld * inset);
252 void insertInset(lyx::pos_type pos, InsetOld * inset, LyXFont const &, Change change = Change(Change::INSERTED));
254 bool insetAllowed(InsetOld::Code code);
256 InsetOld * getInset(lyx::pos_type pos);
258 InsetOld const * getInset(lyx::pos_type pos) const;
261 bool isHfill(lyx::pos_type pos) const;
263 bool isInset(lyx::pos_type pos) const;
265 bool isNewline(lyx::pos_type pos) const;
267 bool isSeparator(lyx::pos_type pos) const;
269 bool isLineSeparator(lyx::pos_type pos) const;
271 bool isKomma(lyx::pos_type pos) const;
272 /// Used by the spellchecker
273 bool isLetter(lyx::pos_type pos) const;
275 bool isWord(lyx::pos_type pos) const;
277 /// returns -1 if inset not found
278 int getPositionOfInset(InsetOld const * inset) const;
281 int stripLeadingSpaces();
283 /// return true if we allow multiple spaces
284 bool isFreeSpacing() const;
286 /// return true if we allow this par to stay empty
287 bool allowEmpty() const;
290 ParagraphParameters & params();
292 ParagraphParameters const & params() const;
298 LyXLayout_ptr layout_;
302 friend struct Paragraph::Pimpl;
309 inline bool isInsertedText(Paragraph const & par, lyx::pos_type pos)
311 return par.lookupChange(pos) == Change::INSERTED;
315 inline bool isDeletedText(Paragraph const & par, lyx::pos_type pos)
317 return par.lookupChange(pos) == Change::DELETED;
320 #endif // PARAGRAPH_H