]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
3d1f8691fd07d8ef48102060e5852fb3f964703a
[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 #ifdef __GNUG__
13 #pragma interface
14 #endif
15
16 #include "lyxlayout_ptr_fwd.h"
17 #include "lyxfont.h" // Just for LyXFont::FONT_SIZE
18 #include "InsetList.h"
19
20 #include "insets/inset.h" // Just for Inset::Code
21
22 #include "support/types.h"
23 #include "changes.h"
24
25 #include "LString.h"
26
27 class BufferParams;
28 class BufferView;
29 class Counters;
30 class InsetBibKey;
31 class Language;
32 class LaTeXFeatures;
33 class ParagraphParameters;
34 class TexRow;
35
36 // Define this if you want to try out the new storage container for
37 // paragraphs. (Lgb)
38 // This is non working and far from finished.
39 // #define NO_NEXT 1
40
41 /// A Paragraph holds all text, attributes and insets in a text paragraph
42 class Paragraph  {
43 public:
44         ///
45         enum META_KIND {
46                 ///
47                 META_HFILL = 1,
48                 ///
49                 META_NEWLINE,
50                 ///
51                 META_INSET
52         };
53         ///
54         typedef char value_type;
55         /// The same as ParameterStruct::depth_type
56         typedef unsigned int depth_type;
57
58         ///
59         Paragraph();
60 #ifndef NO_NEXT
61         /// this constructor inserts the new paragraph in a list
62         explicit
63         Paragraph(Paragraph * par);
64 #endif
65         ///
66         Paragraph(Paragraph const &, bool same_ids);
67         /// the destructor removes the new paragraph from the list
68         ~Paragraph();
69
70         ///
71         Language const * getParLanguage(BufferParams const &) const;
72         ///
73         bool isRightToLeftPar(BufferParams const &) const;
74         ///
75         void changeLanguage(BufferParams const & bparams,
76                             Language const * from, Language const * to);
77         ///
78         bool isMultiLingual(BufferParams const &);
79
80         ///
81         string const asString(Buffer const *, bool label) const;
82         ///
83         string const asString(Buffer const *, lyx::pos_type beg, lyx::pos_type end,
84                               bool label) const;
85
86         ///
87         void write(Buffer const *, std::ostream &, BufferParams const &,
88                        depth_type & depth) const;
89         ///
90         void validate(LaTeXFeatures &) const;
91
92         /// return the unique ID of this paragraph
93         int id() const;
94         ///
95         void read();
96
97         ///
98         Paragraph * TeXOnePar(Buffer const *, BufferParams const &,
99                                  std::ostream &, TexRow & texrow,
100                                  bool moving_arg);
101
102         ///
103         int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
104
105         ///
106         int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
107
108
109         ///
110         bool simpleTeXOnePar(Buffer const *, BufferParams const &,
111                              std::ostream &, TexRow & texrow, bool moving_arg);
112
113         ///
114         Paragraph * TeXEnvironment(Buffer const *, BufferParams const &,
115                                       std::ostream &, TexRow & texrow);
116         ///
117         bool hasSameLayout(Paragraph const * par) const;
118
119         ///
120         void makeSameLayout(Paragraph const * par);
121
122         /// Is it the first par with same depth and layout?
123         bool isFirstInSequence() const;
124
125         /** Check if the current paragraph is the last paragraph in a
126             proof environment */
127         int getEndLabel() const;
128         ///
129         Inset * inInset() const;
130         ///
131         void setInsetOwner(Inset * i);
132         ///
133         void deleteInsetsLyXText(BufferView *);
134         ///
135         void resizeInsetsLyXText(BufferView *);
136
137         ///
138         lyx::pos_type size() const;
139         ///
140         bool empty() const;
141         ///
142         void setContentsFromPar(Paragraph * par);
143         ///
144         void clearContents();
145
146         ///
147         LyXLayout_ptr const & layout() const;
148         ///
149         void layout(LyXLayout_ptr const & new_layout);
150
151         ///
152         char enumdepth;
153
154         ///
155         char itemdepth;
156
157         ///
158         InsetBibKey * bibkey;  // ale970302
159
160 #ifndef NO_NEXT
161         ///
162         void next(Paragraph *);
163         /** these function are able to hide closed footnotes
164          */
165         Paragraph * next();
166         ///
167         Paragraph const * next() const;
168
169         /// initialise tracking for this par
170         void trackChanges(Change::Type = Change::UNCHANGED);
171  
172         /// stop tracking
173         void untrackChanges();
174  
175         /// set entire paragraph to new text for change tracking
176         void cleanChanges();
177  
178         /// look up change type at given pos
179         Change::Type lookupChange(lyx::pos_type pos) const;
180  
181         /// look up change at given pos
182         Change const lookupChangeFull(lyx::pos_type pos) const;
183  
184         /// is there a change within the given range ?
185         bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
186
187         /// is there a non-addition in this range ?
188         bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
189  
190         /// accept change
191         void acceptChange(lyx::pos_type start, lyx::pos_type end);
192
193         /// reject change
194         void rejectChange(lyx::pos_type start, lyx::pos_type end);
195  
196         /// mark whole par as erased
197         void markErased();
198  
199         ///
200         void previous(Paragraph *);
201         ///
202         Paragraph * previous();
203         ///
204         Paragraph const * previous() const;
205 #endif
206         /// for the environments
207         Paragraph * depthHook(depth_type depth);
208         /// for the environments
209         Paragraph const * depthHook(depth_type depth) const;
210         ///
211         Paragraph * outerHook();
212         ///
213         Paragraph const * outerHook() const;
214         ///
215         int beginningOfMainBody() const;
216         ///
217         string const & getLabelstring() const;
218
219         /// the next two functions are for the manual labels
220         string const getLabelWidthString() const;
221         ///
222         void setLabelWidthString(string const & s);
223         ///
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;
229         ///
230         void applyLayout(LyXLayout_ptr const & new_layout);
231  
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);
236  
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
240         */
241         LyXFont const
242         getFontSettings(BufferParams const &, lyx::pos_type pos) const;
243         ///
244         LyXFont const getFirstFontSettings() const;
245
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
251             LyXFont::TOGGLE.
252         */
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;
256         ///
257         value_type getChar(lyx::pos_type pos) const;
258         ///
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
265         LyXFont::FONT_SIZE
266         highestFontInRange(lyx::pos_type startpos,
267                            lyx::pos_type endpos,
268                            LyXFont::FONT_SIZE const def_size) const;
269         ///
270         void insertChar(lyx::pos_type pos, value_type c);
271         ///
272         void insertChar(lyx::pos_type pos, value_type c, LyXFont const &, Change change = Change(Change::INSERTED));
273         ///
274         bool checkInsertChar(LyXFont &);
275         ///
276         void insertInset(lyx::pos_type pos, Inset * inset);
277         ///
278         void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const &, Change change = Change(Change::INSERTED));
279         ///
280         bool insetAllowed(Inset::Code code);
281         ///
282         Inset * getInset(lyx::pos_type pos);
283         ///
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;
289         ///
290         void cutIntoMinibuffer(BufferParams const &, lyx::pos_type pos);
291         ///
292         bool insertFromMinibuffer(lyx::pos_type pos);
293
294         ///
295         bool isHfill(lyx::pos_type pos) const;
296         ///
297         bool isInset(lyx::pos_type pos) const;
298         ///
299         bool isNewline(lyx::pos_type pos) const;
300         ///
301         bool isSeparator(lyx::pos_type pos) const;
302         ///
303         bool isLineSeparator(lyx::pos_type pos) const;
304         ///
305         bool isKomma(lyx::pos_type pos) const;
306         /// Used by the spellchecker
307         bool isLetter(lyx::pos_type pos) const;
308         ///
309         bool isWord(lyx::pos_type pos) const;
310
311         /// returns -1 if inset not found
312         int getPositionOfInset(Inset const * inset) const;
313
314         /// some good comment here John?
315         Paragraph * getParFromID(int id) const;
316
317         ///
318         int stripLeadingSpaces();
319
320         ///
321         bool isFreeSpacing() const;
322
323         ///
324         ParagraphParameters & params();
325         ///
326         ParagraphParameters const & params() const;
327         ///
328         InsetList insetlist;
329         ///
330         //Counters & counters();
331
332         friend void breakParagraph(BufferParams const & bparams,
333                     Paragraph * par, lyx::pos_type pos, int flag);
334  
335 private:
336         ///
337         LyXLayout_ptr layout_;
338         /// if anything uses this we don't want it to.
339         Paragraph(Paragraph const &);
340 #ifndef NO_NEXT
341         ///
342         Paragraph * next_;
343         ///
344         Paragraph * previous_;
345 #endif
346         struct Pimpl;
347         ///
348         friend struct Paragraph::Pimpl;
349         ///
350         Pimpl * pimpl_;
351 };
352
353  
354 inline bool isInsertedText(Paragraph const * par, lyx::pos_type pos)
355 {
356         return par->lookupChange(pos) == Change::INSERTED;
357 }
358  
359  
360 inline bool isDeletedText(Paragraph const * par, lyx::pos_type pos)
361 {
362         return par->lookupChange(pos) == Change::DELETED;
363 }
364  
365 #endif // PARAGRAPH_H