]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
Make lyx2lyx output the new external inset format.
[lyx.git] / src / paragraph.h
1 // -*- C++ -*-
2 /**
3  *  \file paragraph.h
4  *  Copyright 1995 Matthias Ettrich
5  *  Copyright 2002 the LyX Team
6  *  Read the file COPYING
7  */
8
9 #ifndef PARAGRAPH_H
10 #define PARAGRAPH_H
11
12 #include "lyxlayout_ptr_fwd.h"
13 #include "lyxfont.h" // Just for LyXFont::FONT_SIZE
14 #include "InsetList.h"
15
16 #include "insets/inset.h" // Just for Inset::Code
17
18 #include "support/types.h"
19 #include "changes.h"
20
21 #include "LString.h"
22
23 class Buffer;
24 class BufferParams;
25 class BufferView;
26 class Counters;
27 class InsetBibitem;
28 class Language;
29 class LaTeXFeatures;
30 class LatexRunParams;
31 class ParagraphParameters;
32 class TexRow;
33 class ParagraphList;
34 class UpdatableInset;
35
36 /// A Paragraph holds all text, attributes and insets in a text paragraph
37 class Paragraph  {
38 public:
39         ///
40         enum META_KIND {
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
45                 /// all these places.
46                 META_INSET = 1
47         };
48         ///
49         typedef char value_type;
50         /// The same as ParameterStruct::depth_type
51         typedef unsigned int depth_type;
52
53         ///
54         Paragraph();
55
56         ///
57         Paragraph(Paragraph const &);
58         ///
59         void operator=(Paragraph const &);
60         /// the destructor removes the new paragraph from the list
61         ~Paragraph();
62
63         ///
64         Language const * getParLanguage(BufferParams const &) const;
65         ///
66         bool isRightToLeftPar(BufferParams const &) const;
67         ///
68         void changeLanguage(BufferParams const & bparams,
69                             Language const * from, Language const * to);
70         ///
71         bool isMultiLingual(BufferParams const &);
72
73         ///
74         string const asString(Buffer const *, bool label) const;
75         ///
76         string const asString(Buffer const *, lyx::pos_type beg, lyx::pos_type end,
77                               bool label) const;
78
79         ///
80         void write(Buffer const *, std::ostream &, BufferParams const &,
81                        depth_type & depth) const;
82         ///
83         void validate(LaTeXFeatures &) const;
84
85         /// return the unique ID of this paragraph
86         int id() const;
87         /// Set the Id of this paragraph.
88         void id(int);
89
90         ///
91         int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
92
93         ///
94         int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
95
96
97         ///
98         bool simpleTeXOnePar(Buffer const *, BufferParams const &,
99                              LyXFont const & outerfont, std::ostream &,
100                              TexRow & texrow, LatexRunParams const &);
101
102         ///
103         bool hasSameLayout(Paragraph const & par) const;
104
105         ///
106         void makeSameLayout(Paragraph const & par);
107
108         ///
109         UpdatableInset * inInset() const;
110         ///
111         void setInsetOwner(UpdatableInset * inset);
112         ///
113         void deleteInsetsLyXText(BufferView *);
114         ///
115         void resizeInsetsLyXText(BufferView *);
116
117         ///
118         lyx::pos_type size() const;
119         ///
120         bool empty() const;
121         ///
122         void setContentsFromPar(Paragraph const & par);
123         ///
124         void clearContents();
125
126         ///
127         LyXLayout_ptr const & layout() const;
128         ///
129         void layout(LyXLayout_ptr const & new_layout);
130
131         ///
132         char enumdepth;
133
134         ///
135         char itemdepth;
136
137         ///
138         InsetBibitem * bibitem() const;  // ale970302
139
140         /// initialise tracking for this par
141         void trackChanges(Change::Type = Change::UNCHANGED);
142
143         /// stop tracking
144         void untrackChanges();
145
146         /// set entire paragraph to new text for change tracking
147         void cleanChanges();
148
149         /// look up change type at given pos
150         Change::Type lookupChange(lyx::pos_type pos) const;
151
152         /// look up change at given pos
153         Change const lookupChangeFull(lyx::pos_type pos) const;
154
155         /// is there a change within the given range ?
156         bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
157
158         /// is there a non-addition in this range ?
159         bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
160
161         /// set change at pos
162         void setChange(lyx::pos_type pos, Change::Type type);
163
164         /// accept change
165         void acceptChange(lyx::pos_type start, lyx::pos_type end);
166
167         /// reject change
168         void rejectChange(lyx::pos_type start, lyx::pos_type end);
169
170         /// mark whole par as erased
171         void markErased();
172
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;
179
180         ///
181         string const & getLabelstring() const;
182
183         /// the next two functions are for the manual labels
184         string const getLabelWidthString() const;
185         ///
186         void setLabelWidthString(string const & s);
187         ///
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;
193         ///
194         void applyLayout(LyXLayout_ptr const & new_layout);
195
196         /// definite erase
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);
202
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
206         */
207         LyXFont const
208         getFontSettings(BufferParams const &, lyx::pos_type pos) const;
209         ///
210         LyXFont const getFirstFontSettings() const;
211
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
217             LyXFont::TOGGLE.
218         */
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;
225         ///
226         value_type getChar(lyx::pos_type pos) const;
227         ///
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
234         LyXFont::FONT_SIZE
235         highestFontInRange(lyx::pos_type startpos,
236                            lyx::pos_type endpos,
237                            LyXFont::FONT_SIZE const def_size) const;
238         ///
239         void insertChar(lyx::pos_type pos, value_type c);
240         ///
241         void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
242         ///
243         bool checkInsertChar(LyXFont &);
244         ///
245         void insertInset(lyx::pos_type pos, Inset * inset);
246         ///
247         void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const &, Change change = Change(Change::INSERTED));
248         ///
249         bool insetAllowed(Inset::Code code);
250         ///
251         Inset * getInset(lyx::pos_type pos);
252         ///
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;
258         ///
259         void cutIntoMinibuffer(BufferParams const &, lyx::pos_type pos);
260         ///
261         bool insertFromMinibuffer(lyx::pos_type pos);
262
263         ///
264         bool isHfill(lyx::pos_type pos) const;
265         ///
266         bool isInset(lyx::pos_type pos) const;
267         ///
268         bool isNewline(lyx::pos_type pos) const;
269         ///
270         bool isSeparator(lyx::pos_type pos) const;
271         ///
272         bool isLineSeparator(lyx::pos_type pos) const;
273         ///
274         bool isKomma(lyx::pos_type pos) const;
275         /// Used by the spellchecker
276         bool isLetter(lyx::pos_type pos) const;
277         ///
278         bool isWord(lyx::pos_type pos) const;
279
280         /// returns -1 if inset not found
281         int getPositionOfInset(Inset const * inset) const;
282
283         ///
284         int stripLeadingSpaces();
285
286         ///
287         bool isFreeSpacing() const;
288
289         ///
290         ParagraphParameters & params();
291         ///
292         ParagraphParameters const & params() const;
293         ///
294         InsetList insetlist;
295
296 private:
297         ///
298         LyXLayout_ptr layout_;
299
300         struct Pimpl;
301         ///
302         friend struct Paragraph::Pimpl;
303         ///
304         Pimpl * pimpl_;
305
306 };
307
308
309 inline bool isInsertedText(Paragraph const & par, lyx::pos_type pos)
310 {
311         return par.lookupChange(pos) == Change::INSERTED;
312 }
313
314
315 inline bool isDeletedText(Paragraph const & par, lyx::pos_type pos)
316 {
317         return par.lookupChange(pos) == Change::DELETED;
318 }
319
320
321 bool operator==(Paragraph const & lhs, Paragraph const & rhs);
322
323 #endif // PARAGRAPH_H