]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
some more getPar removals
[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 InsetOld::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         ///
116         lyx::pos_type size() const;
117         ///
118         bool empty() const;
119         ///
120         void setContentsFromPar(Paragraph const & par);
121         ///
122         void clearContents();
123
124         ///
125         LyXLayout_ptr const & layout() const;
126         ///
127         void layout(LyXLayout_ptr const & new_layout);
128
129         ///
130         char enumdepth;
131
132         ///
133         char itemdepth;
134
135         ///
136         InsetBibitem * bibitem() const;  // ale970302
137
138         /// initialise tracking for this par
139         void trackChanges(Change::Type = Change::UNCHANGED);
140
141         /// stop tracking
142         void untrackChanges();
143
144         /// set entire paragraph to new text for change tracking
145         void cleanChanges();
146
147         /// look up change type at given pos
148         Change::Type lookupChange(lyx::pos_type pos) const;
149
150         /// look up change at given pos
151         Change const lookupChangeFull(lyx::pos_type pos) const;
152
153         /// is there a change within the given range ?
154         bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
155
156         /// is there a non-addition in this range ?
157         bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
158
159         /// set change at pos
160         void setChange(lyx::pos_type pos, Change::Type type);
161
162         /// accept change
163         void acceptChange(lyx::pos_type start, lyx::pos_type end);
164
165         /// reject change
166         void rejectChange(lyx::pos_type start, lyx::pos_type end);
167
168         /// mark whole par as erased
169         void markErased();
170
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;
177
178         ///
179         string const & getLabelstring() const;
180
181         /// the next two functions are for the manual labels
182         string const getLabelWidthString() const;
183         ///
184         void setLabelWidthString(string const & s);
185         ///
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;
191         ///
192         void applyLayout(LyXLayout_ptr const & new_layout);
193
194         /// definite erase
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);
200
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
204         */
205         LyXFont const
206         getFontSettings(BufferParams const &, lyx::pos_type pos) const;
207         ///
208         LyXFont const getFirstFontSettings() const;
209
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
215             LyXFont::TOGGLE.
216         */
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;
223         /**
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.
228          */
229         lyx::pos_type getEndPosOfFontSpan(lyx::pos_type pos) const;
230         ///
231         value_type getChar(lyx::pos_type pos) const;
232         ///
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
239         LyXFont::FONT_SIZE
240         highestFontInRange(lyx::pos_type startpos,
241                            lyx::pos_type endpos,
242                            LyXFont::FONT_SIZE const def_size) const;
243         ///
244         void insertChar(lyx::pos_type pos, value_type c);
245         ///
246         void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
247         ///
248         bool checkInsertChar(LyXFont &);
249         ///
250         void insertInset(lyx::pos_type pos, InsetOld * inset);
251         ///
252         void insertInset(lyx::pos_type pos, InsetOld * inset, LyXFont const &, Change change = Change(Change::INSERTED));
253         ///
254         bool insetAllowed(InsetOld::Code code);
255         ///
256         InsetOld * getInset(lyx::pos_type pos);
257         ///
258         InsetOld const * getInset(lyx::pos_type pos) const;
259
260         ///
261         bool isHfill(lyx::pos_type pos) const;
262         ///
263         bool isInset(lyx::pos_type pos) const;
264         ///
265         bool isNewline(lyx::pos_type pos) const;
266         ///
267         bool isSeparator(lyx::pos_type pos) const;
268         ///
269         bool isLineSeparator(lyx::pos_type pos) const;
270         ///
271         bool isKomma(lyx::pos_type pos) const;
272         /// Used by the spellchecker
273         bool isLetter(lyx::pos_type pos) const;
274         ///
275         bool isWord(lyx::pos_type pos) const;
276
277         /// returns -1 if inset not found
278         int getPositionOfInset(InsetOld const * inset) const;
279
280         ///
281         int stripLeadingSpaces();
282
283         /// return true if we allow multiple spaces
284         bool isFreeSpacing() const;
285
286         /// return true if we allow this par to stay empty
287         bool allowEmpty() 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 #endif // PARAGRAPH_H