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"
23 #include <boost/optional.hpp>
33 class ParagraphParameters;
37 // Define this if you want to try out the new storage container for
39 // This is non working and far from finished.
40 //#define NO_STD_LIST 1
42 /// A Paragraph holds all text, attributes and insets in a text paragraph
46 // Remove this whan ParagraphList transition is over. (Lgb)
47 friend class ParagraphList;
48 friend class ParagraphList::iterator;
49 friend class ParagraphList::const_iterator;
53 /// Note that this is 1 right now to avoid
54 /// crashes where getChar() is called wrongly
55 /// (returning 0) - if this was 0, then we'd
56 /// try getInset() and crash. We should fix
61 typedef char value_type;
62 /// The same as ParameterStruct::depth_type
63 typedef unsigned int depth_type;
69 Paragraph(Paragraph const &);
71 //void operator=(Paragraph const &);
72 /// the destructor removes the new paragraph from the list
76 Language const * getParLanguage(BufferParams const &) const;
78 bool isRightToLeftPar(BufferParams const &) const;
80 void changeLanguage(BufferParams const & bparams,
81 Language const * from, Language const * to);
83 bool isMultiLingual(BufferParams const &);
86 string const asString(Buffer const *, bool label) const;
88 string const asString(Buffer const *, lyx::pos_type beg, lyx::pos_type end,
92 void write(Buffer const *, std::ostream &, BufferParams const &,
93 depth_type & depth) const;
95 void validate(LaTeXFeatures &) const;
97 /// return the unique ID of this paragraph
99 /// Set the Id of this paragraph.
103 int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
106 int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
110 bool simpleTeXOnePar(Buffer const *, BufferParams const &,
111 LyXFont const & outerfont, std::ostream &,
112 TexRow & texrow, LatexRunParams const &);
115 bool hasSameLayout(Paragraph const & par) const;
118 void makeSameLayout(Paragraph const & par);
121 Inset * inInset() const;
123 void setInsetOwner(Inset * i);
125 void deleteInsetsLyXText(BufferView *);
127 void resizeInsetsLyXText(BufferView *);
130 lyx::pos_type size() const;
134 void setContentsFromPar(Paragraph const & par);
136 void clearContents();
139 LyXLayout_ptr const & layout() const;
141 void layout(LyXLayout_ptr const & new_layout);
150 InsetBibitem * bibitem() const; // ale970302
152 /// initialise tracking for this par
153 void trackChanges(Change::Type = Change::UNCHANGED);
156 void untrackChanges();
158 /// set entire paragraph to new text for change tracking
161 /// look up change type at given pos
162 Change::Type lookupChange(lyx::pos_type pos) const;
164 /// look up change at given pos
165 Change const lookupChangeFull(lyx::pos_type pos) const;
167 /// is there a change within the given range ?
168 bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
170 /// is there a non-addition in this range ?
171 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
173 /// set change at pos
174 void setChange(lyx::pos_type pos, Change::Type type);
177 void acceptChange(lyx::pos_type start, lyx::pos_type end);
180 void rejectChange(lyx::pos_type start, lyx::pos_type end);
182 /// mark whole par as erased
185 /// Paragraphs can contain "manual labels", for example, Description environment.
186 /// The text for this user-editable label is stored in the paragraph alongside
187 /// the text of the rest of the paragraph (the body). This function returns
188 /// the starting position of the body of the text in the paragraph.
189 int beginningOfBody() const;
192 string const & getLabelstring() const;
194 /// the next two functions are for the manual labels
195 string const getLabelWidthString() const;
197 void setLabelWidthString(string const & s);
199 char getAlign() const;
200 /// The nesting depth of a paragraph
201 depth_type getDepth() const;
202 /// The maximal possible depth of a paragraph after this one
203 depth_type getMaxDepthAfter() const;
205 void applyLayout(LyXLayout_ptr const & new_layout);
208 void eraseIntern(lyx::pos_type pos);
209 /// erase the char at the given position
210 bool erase(lyx::pos_type pos);
211 /// erase the given range. Returns the number of chars actually erased
212 int erase(lyx::pos_type start, lyx::pos_type end);
214 /** Get uninstantiated font setting. Returns the difference
215 between the characters font and the layoutfont.
216 This is what is stored in the fonttable
219 getFontSettings(BufferParams const &, lyx::pos_type pos) const;
221 LyXFont const getFirstFontSettings() const;
223 /** Get fully instantiated font. If pos == -1, use the layout
224 font attached to this paragraph.
225 If pos == -2, use the label font of the layout attached here.
226 In all cases, the font is instantiated, i.e. does not have any
227 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
230 LyXFont const getFont(BufferParams const &, lyx::pos_type pos,
231 LyXFont const & outerfont) const;
232 LyXFont const getLayoutFont(BufferParams const &,
233 LyXFont const & outerfont) const;
234 LyXFont const getLabelFont(BufferParams const &,
235 LyXFont const & outerfont) const;
237 value_type getChar(lyx::pos_type pos) const;
239 value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
240 /// The position must already exist.
241 void setChar(lyx::pos_type pos, value_type c);
242 /// pos <= size() (there is a dummy font change at the end of each par)
243 void setFont(lyx::pos_type pos, LyXFont const & font);
244 /// Returns the height of the highest font in range
246 highestFontInRange(lyx::pos_type startpos,
247 lyx::pos_type endpos,
248 LyXFont::FONT_SIZE const 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, Inset * inset);
258 void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const &, Change change = Change(Change::INSERTED));
260 bool insetAllowed(Inset::Code code);
262 Inset * getInset(lyx::pos_type pos);
264 Inset const * getInset(lyx::pos_type pos) const;
265 /** important for cut and paste
266 Temporary change from BufferParams to Buffer. Will revert when we
267 get rid of the argument to Inset::clone(Buffer const &) */
268 void copyIntoMinibuffer(Buffer const &, lyx::pos_type pos) const;
270 void cutIntoMinibuffer(BufferParams const &, lyx::pos_type pos);
272 bool insertFromMinibuffer(lyx::pos_type pos);
275 bool isHfill(lyx::pos_type pos) const;
277 bool isInset(lyx::pos_type pos) const;
279 bool isNewline(lyx::pos_type pos) const;
281 bool isSeparator(lyx::pos_type pos) const;
283 bool isLineSeparator(lyx::pos_type pos) const;
285 bool isKomma(lyx::pos_type pos) const;
286 /// Used by the spellchecker
287 bool isLetter(lyx::pos_type pos) const;
289 bool isWord(lyx::pos_type pos) const;
291 /// returns -1 if inset not found
292 int getPositionOfInset(Inset const * inset) const;
295 int stripLeadingSpaces();
298 bool isFreeSpacing() const;
301 ParagraphParameters & params();
303 ParagraphParameters const & params() const;
307 //Counters & counters();
309 void owningBuffer(Buffer const & b) {
314 LyXLayout_ptr layout_;
316 Paragraph * next_par_;
317 Paragraph * prev_par_;
320 boost::optional<Buffer const *> buffer_;
324 friend struct Paragraph::Pimpl;
331 inline bool isInsertedText(Paragraph const & par, lyx::pos_type pos)
333 return par.lookupChange(pos) == Change::INSERTED;
337 inline bool isDeletedText(Paragraph const & par, lyx::pos_type pos)
339 return par.lookupChange(pos) == Change::DELETED;
343 bool operator==(Paragraph const & lhs, Paragraph const & rhs);
345 #endif // PARAGRAPH_H