4 * Copyright 1995 Matthias Ettrich
5 * Copyright 2002 the LyX Team
6 * Read the file COPYING
16 #include "lyxlayout_ptr_fwd.h"
17 #include "lyxfont.h" // Just for LyXFont::FONT_SIZE
18 #include "InsetList.h"
20 #include "insets/inset.h" // Just for Inset::Code
22 #include "support/types.h"
33 class ParagraphParameters;
36 // Define this if you want to try out the new storage container for
38 // This is non working and far from finished.
41 /// A Paragraph holds all text, attributes and insets in a text paragraph
54 typedef char value_type;
55 /// The same as ParameterStruct::depth_type
56 typedef unsigned int depth_type;
61 /// this constructor inserts the new paragraph in a list
63 Paragraph(Paragraph * par);
66 Paragraph(Paragraph const &, bool same_ids);
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
98 Paragraph * TeXOnePar(Buffer const *, BufferParams const &,
99 std::ostream &, TexRow & texrow,
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 std::ostream &, TexRow & texrow, bool moving_arg);
114 Paragraph * TeXEnvironment(Buffer const *, BufferParams const &,
115 std::ostream &, TexRow & texrow);
117 bool hasSameLayout(Paragraph const * par) const;
120 void makeSameLayout(Paragraph const * par);
122 /// Is it the first par with same depth and layout?
123 bool isFirstInSequence() const;
125 /** Check if the current paragraph is the last paragraph in a
127 int getEndLabel() const;
129 Inset * inInset() const;
131 void setInsetOwner(Inset * i);
133 void deleteInsetsLyXText(BufferView *);
135 void resizeInsetsLyXText(BufferView *);
138 lyx::pos_type size() const;
142 void setContentsFromPar(Paragraph * par);
144 void clearContents();
147 LyXLayout_ptr const & layout() const;
149 void layout(LyXLayout_ptr const & new_layout);
158 InsetBibKey * bibkey; // ale970302
162 void next(Paragraph *);
163 /** these function are able to hide closed footnotes
167 Paragraph const * next() const;
169 /// initialise tracking for this par
170 void trackChanges(Change::Type = Change::UNCHANGED);
173 void untrackChanges();
175 /// set entire paragraph to new text for change tracking
178 /// look up change type at given pos
179 Change::Type lookupChange(lyx::pos_type pos) const;
181 /// look up change at given pos
182 Change const lookupChangeFull(lyx::pos_type pos) const;
184 /// is there a change within the given range ?
185 bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
187 /// is there a non-addition in this range ?
188 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
191 void acceptChange(lyx::pos_type start, lyx::pos_type end);
194 void rejectChange(lyx::pos_type start, lyx::pos_type end);
196 /// mark whole par as erased
200 void previous(Paragraph *);
202 Paragraph * previous();
204 Paragraph const * previous() const;
206 /// for the environments
207 Paragraph * depthHook(depth_type depth);
208 /// for the environments
209 Paragraph const * depthHook(depth_type depth) const;
211 Paragraph * outerHook();
213 Paragraph const * outerHook() const;
215 int beginningOfMainBody() const;
217 string const & getLabelstring() const;
219 /// the next two functions are for the manual labels
220 string const getLabelWidthString() const;
222 void setLabelWidthString(string const & s);
224 char getAlign() const;
225 /// The nesting depth of a paragraph
226 depth_type getDepth() const;
227 /// The maximal possible depth of a paragraph after this one
228 depth_type getMaxDepthAfter() const;
230 void applyLayout(LyXLayout_ptr const & new_layout);
232 /// erase the char at the given position
233 void erase(lyx::pos_type pos);
234 /// erase the given range. Returns true if actually erased.
235 bool erase(lyx::pos_type start, lyx::pos_type end);
237 /** Get uninstantiated font setting. Returns the difference
238 between the characters font and the layoutfont.
239 This is what is stored in the fonttable
242 getFontSettings(BufferParams const &, lyx::pos_type pos) const;
244 LyXFont const getFirstFontSettings() const;
246 /** Get fully instantiated font. If pos == -1, use the layout
247 font attached to this paragraph.
248 If pos == -2, use the label font of the layout attached here.
249 In all cases, the font is instantiated, i.e. does not have any
250 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
253 LyXFont const getFont(BufferParams const &, lyx::pos_type pos) const;
254 LyXFont const getLayoutFont(BufferParams const &) const;
255 LyXFont const getLabelFont(BufferParams const &) const;
257 value_type getChar(lyx::pos_type pos) const;
259 value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
260 /// The position must already exist.
261 void setChar(lyx::pos_type pos, value_type c);
262 /// pos <= size() (there is a dummy font change at the end of each par)
263 void setFont(lyx::pos_type pos, LyXFont const & font);
264 /// Returns the height of the highest font in range
266 highestFontInRange(lyx::pos_type startpos,
267 lyx::pos_type endpos,
268 LyXFont::FONT_SIZE const def_size) const;
270 void insertChar(lyx::pos_type pos, value_type c);
272 void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
274 bool checkInsertChar(LyXFont &);
276 void insertInset(lyx::pos_type pos, Inset * inset);
278 void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const &, Change change = Change(Change::INSERTED));
280 bool insetAllowed(Inset::Code code);
282 Inset * getInset(lyx::pos_type pos);
284 Inset const * getInset(lyx::pos_type pos) const;
285 /** important for cut and paste
286 Temporary change from BufferParams to Buffer. Will revert when we
287 get rid of the argument to Inset::clone(Buffer const &) */
288 void copyIntoMinibuffer(Buffer const &, lyx::pos_type pos) const;
290 void cutIntoMinibuffer(BufferParams const &, lyx::pos_type pos);
292 bool insertFromMinibuffer(lyx::pos_type pos);
295 bool isHfill(lyx::pos_type pos) const;
297 bool isInset(lyx::pos_type pos) const;
299 bool isNewline(lyx::pos_type pos) const;
301 bool isSeparator(lyx::pos_type pos) const;
303 bool isLineSeparator(lyx::pos_type pos) const;
305 bool isKomma(lyx::pos_type pos) const;
306 /// Used by the spellchecker
307 bool isLetter(lyx::pos_type pos) const;
309 bool isWord(lyx::pos_type pos) const;
311 /// returns -1 if inset not found
312 int getPositionOfInset(Inset const * inset) const;
314 /// some good comment here John?
315 Paragraph * getParFromID(int id) const;
318 int stripLeadingSpaces();
321 bool isFreeSpacing() const;
324 ParagraphParameters & params();
326 ParagraphParameters const & params() const;
330 //Counters & counters();
332 friend void breakParagraph(BufferParams const & bparams,
333 Paragraph * par, lyx::pos_type pos, int flag);
337 LyXLayout_ptr layout_;
338 /// if anything uses this we don't want it to.
339 Paragraph(Paragraph const &);
344 Paragraph * previous_;
348 friend struct Paragraph::Pimpl;
354 inline bool isInsertedText(Paragraph const * par, lyx::pos_type pos)
356 return par->lookupChange(pos) == Change::INSERTED;
360 inline bool isDeletedText(Paragraph const * par, lyx::pos_type pos)
362 return par->lookupChange(pos) == Change::DELETED;
365 #endif // PARAGRAPH_H