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 Inset::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 *);
115 void resizeInsetsLyXText(BufferView *);
118 lyx::pos_type size() const;
122 void setContentsFromPar(Paragraph const & par);
124 void clearContents();
127 LyXLayout_ptr const & layout() const;
129 void layout(LyXLayout_ptr const & new_layout);
138 InsetBibitem * bibitem() const; // ale970302
140 /// initialise tracking for this par
141 void trackChanges(Change::Type = Change::UNCHANGED);
144 void untrackChanges();
146 /// set entire paragraph to new text for change tracking
149 /// look up change type at given pos
150 Change::Type lookupChange(lyx::pos_type pos) const;
152 /// look up change at given pos
153 Change const lookupChangeFull(lyx::pos_type pos) const;
155 /// is there a change within the given range ?
156 bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
158 /// is there a non-addition in this range ?
159 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
161 /// set change at pos
162 void setChange(lyx::pos_type pos, Change::Type type);
165 void acceptChange(lyx::pos_type start, lyx::pos_type end);
168 void rejectChange(lyx::pos_type start, lyx::pos_type end);
170 /// mark whole par as erased
173 /// Paragraphs can contain "manual labels", for example, Description
174 /// environment. The text for this user-editable label is stored in
175 /// the paragraph alongside the text of the rest of the paragraph
176 /// (the body). This function returns the starting position of the
177 /// body of the text in the paragraph.
178 int beginningOfBody() const;
181 string const & getLabelstring() const;
183 /// the next two functions are for the manual labels
184 string const getLabelWidthString() const;
186 void setLabelWidthString(string const & s);
188 char getAlign() const;
189 /// The nesting depth of a paragraph
190 depth_type getDepth() const;
191 /// The maximal possible depth of a paragraph after this one
192 depth_type getMaxDepthAfter() const;
194 void applyLayout(LyXLayout_ptr const & new_layout);
197 void eraseIntern(lyx::pos_type pos);
198 /// erase the char at the given position
199 bool erase(lyx::pos_type pos);
200 /// erase the given range. Returns the number of chars actually erased
201 int erase(lyx::pos_type start, lyx::pos_type end);
203 /** Get uninstantiated font setting. Returns the difference
204 between the characters font and the layoutfont.
205 This is what is stored in the fonttable
208 getFontSettings(BufferParams const &, lyx::pos_type pos) const;
210 LyXFont const getFirstFontSettings() const;
212 /** Get fully instantiated font. If pos == -1, use the layout
213 font attached to this paragraph.
214 If pos == -2, use the label font of the layout attached here.
215 In all cases, the font is instantiated, i.e. does not have any
216 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
219 LyXFont const getFont(BufferParams const &, lyx::pos_type pos,
220 LyXFont const & outerfont) const;
221 LyXFont const getLayoutFont(BufferParams const &,
222 LyXFont const & outerfont) const;
223 LyXFont const getLabelFont(BufferParams const &,
224 LyXFont const & outerfont) const;
226 value_type getChar(lyx::pos_type pos) const;
228 value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
229 /// The position must already exist.
230 void setChar(lyx::pos_type pos, value_type c);
231 /// pos <= size() (there is a dummy font change at the end of each par)
232 void setFont(lyx::pos_type pos, LyXFont const & font);
233 /// Returns the height of the highest font in range
235 highestFontInRange(lyx::pos_type startpos,
236 lyx::pos_type endpos,
237 LyXFont::FONT_SIZE const def_size) const;
239 void insertChar(lyx::pos_type pos, value_type c);
241 void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
243 bool checkInsertChar(LyXFont &);
245 void insertInset(lyx::pos_type pos, Inset * inset);
247 void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const &, Change change = Change(Change::INSERTED));
249 bool insetAllowed(Inset::Code code);
251 Inset * getInset(lyx::pos_type pos);
253 Inset const * getInset(lyx::pos_type pos) const;
254 /** important for cut and paste
255 Temporary change from BufferParams to Buffer. Will revert when we
256 get rid of the argument to Inset::clone(Buffer const &) */
257 void copyIntoMinibuffer(Buffer const &, lyx::pos_type pos) const;
259 void cutIntoMinibuffer(BufferParams const &, lyx::pos_type pos);
261 bool insertFromMinibuffer(lyx::pos_type pos);
264 bool isHfill(lyx::pos_type pos) const;
266 bool isInset(lyx::pos_type pos) const;
268 bool isNewline(lyx::pos_type pos) const;
270 bool isSeparator(lyx::pos_type pos) const;
272 bool isLineSeparator(lyx::pos_type pos) const;
274 bool isKomma(lyx::pos_type pos) const;
275 /// Used by the spellchecker
276 bool isLetter(lyx::pos_type pos) const;
278 bool isWord(lyx::pos_type pos) const;
280 /// returns -1 if inset not found
281 int getPositionOfInset(Inset const * inset) const;
284 int stripLeadingSpaces();
287 bool isFreeSpacing() 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;
321 bool operator==(Paragraph const & lhs, Paragraph const & rhs);
323 #endif // PARAGRAPH_H