]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
some more changes
[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 "LString.h"
17
18 #include "lyxlayout_ptr_fwd.h"
19 #include "insets/inset.h" // Just for Inset::Code
20 #include "lyxfont.h" // Just for LyXFont::FONT_SIZE
21 #include "support/types.h"
22
23 class ParagraphParameters;
24 class BufferParams;
25 class TexRow;
26 class LaTeXFeatures;
27 class InsetBibKey;
28 class BufferView;
29 class Language;
30
31 // After 1.2.0 is released, during 1.3.0cvs, we enable this. And after
32 // a while we verify that reading of 1.2.x files work perfectly we remove
33 // this code completely. (Lgb)
34 #define NO_PEXTRA_REALLY 1
35
36 // Define this if you want to try out the new storage container for
37 // paragraphs. std::container instead of obfuscated homegrown
38 // linked list. (Lgb)
39 // This is non working and far from finished.
40 // #define NO_NEXT 1
41
42 /// A Paragraph holds all text, attributes and insets in a text paragraph
43 class Paragraph  {
44 public:
45 #ifndef NO_PEXTRA_REALLY
46         ///
47         enum PEXTRA_TYPE {
48                 ///
49                 PEXTRA_NONE,
50                 ///
51                 PEXTRA_INDENT,
52                 ///
53                 PEXTRA_MINIPAGE,
54                 ///
55                 PEXTRA_FLOATFLT
56         };
57         ///
58         enum MINIPAGE_ALIGNMENT {
59                 ///
60                 MINIPAGE_ALIGN_TOP,
61                 ///
62                 MINIPAGE_ALIGN_MIDDLE,
63                 ///
64                 MINIPAGE_ALIGN_BOTTOM
65         };
66 #endif
67         ///
68         enum META_KIND {
69                 ///
70                 META_HFILL = 1,
71                 ///
72                 META_NEWLINE,
73                 ///
74                 META_INSET
75         };
76         ///
77         typedef char value_type;
78         /// The same as ParameterStruct::depth_type
79         typedef unsigned int depth_type;
80
81         ///
82         Paragraph();
83         /// this constructor inserts the new paragraph in a list
84         explicit
85         Paragraph(Paragraph * par);
86         ///
87         Paragraph(Paragraph const &, bool same_ids);
88         /// the destructor removes the new paragraph from the list
89         ~Paragraph();
90
91         ///
92         Language const * getParLanguage(BufferParams const &) const;
93         ///
94         bool isRightToLeftPar(BufferParams const &) const;
95         ///
96         void changeLanguage(BufferParams const & bparams,
97                             Language const * from, Language const * to);
98         ///
99         bool isMultiLingual(BufferParams const &);
100
101         ///
102         string const asString(Buffer const *, bool label);
103         ///
104         string const asString(Buffer const *, lyx::pos_type beg, lyx::pos_type end,
105                               bool label);
106
107         ///
108         void writeFile(Buffer const *, std::ostream &, BufferParams const &,
109                        depth_type) const;
110         ///
111         void validate(LaTeXFeatures &) const;
112
113         ///
114         int id() const;
115         ///
116         void id(int id_arg);
117         ///
118         void read();
119
120         ///
121         Paragraph * TeXOnePar(Buffer const *, BufferParams const &,
122                                  std::ostream &, TexRow & texrow,
123                                  bool moving_arg);
124
125         ///
126         int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
127
128         ///
129         int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
130
131
132         ///
133         bool simpleTeXOnePar(Buffer const *, BufferParams const &,
134                              std::ostream &, TexRow & texrow, bool moving_arg);
135
136         ///
137         Paragraph * TeXEnvironment(Buffer const *, BufferParams const &,
138                                       std::ostream &, TexRow & texrow);
139         ///
140         bool hasSameLayout(Paragraph const * par) const;
141
142         ///
143         void makeSameLayout(Paragraph const * par);
144
145         /// Is it the first par with same depth and layout?
146         bool isFirstInSequence() const;
147
148         /** Check if the current paragraph is the last paragraph in a
149             proof environment */
150         int getEndLabel() const;
151         ///
152         Inset * inInset() const;
153         ///
154         void setInsetOwner(Inset * i);
155         ///
156         void deleteInsetsLyXText(BufferView *);
157         ///
158         void resizeInsetsLyXText(BufferView *);
159
160         ///
161         lyx::pos_type size() const;
162         ///
163         void setContentsFromPar(Paragraph * par);
164         ///
165         void clearContents();
166
167         ///
168         LyXLayout_ptr const & layout() const;
169         ///
170         void layout(LyXLayout_ptr const & new_layout);
171
172         ///
173         void setCounter(int i, int v);
174         ///
175         int getCounter(int i) const;
176         ///
177         void incCounter(int i);
178
179         ///
180         char enumdepth;
181
182         ///
183         char itemdepth;
184
185         ///
186         InsetBibKey * bibkey;  // ale970302
187
188         ///
189         void next(Paragraph *);
190         /** these function are able to hide closed footnotes
191          */
192         Paragraph * next();
193         ///
194         Paragraph const * next() const;
195
196         ///
197         void previous(Paragraph *);
198         ///
199         Paragraph * previous();
200         ///
201         Paragraph const * previous() const;
202
203         /// for the environments
204         Paragraph * depthHook(depth_type depth);
205         /// for the environments
206         Paragraph const * depthHook(depth_type depth) const;
207         ///
208         Paragraph * outerHook();
209         ///
210         Paragraph const * outerHook() const;
211         ///
212         int beginningOfMainBody() const;
213         ///
214         string const & getLabelstring() const;
215
216         /// the next two functions are for the manual labels
217         string const getLabelWidthString() const;
218         ///
219         void setLabelWidthString(string const & s);
220         ///
221         char getAlign() const;
222         /// The nesting depth of a paragraph
223         depth_type getDepth() const;
224         /// The maximal possible depth of a paragraph after this one
225         depth_type getMaxDepthAfter() const;
226         ///
227         void applyLayout(LyXLayout_ptr const & new_layout);
228         ///
229         int getFirstCounter(int i) const;
230         ///
231         void erase(lyx::pos_type pos);
232         /** the flag determines wether the layout should be copied
233          */
234         void breakParagraph(BufferParams const &, lyx::pos_type pos, int flag);
235         ///
236         void breakParagraphConservative(BufferParams const &, lyx::pos_type pos);
237         /** Get unistantiated 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 highestFontInRange(lyx::pos_type startpos,
266                                               lyx::pos_type endpos,
267                                               LyXFont::FONT_SIZE const def_size) const;
268         ///
269         void insertChar(lyx::pos_type pos, value_type c);
270         ///
271         void insertChar(lyx::pos_type pos, value_type c, LyXFont const &);
272         ///
273         bool checkInsertChar(LyXFont &);
274         ///
275         void insertInset(lyx::pos_type pos, Inset * inset);
276         ///
277         void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const &);
278         ///
279         bool insetAllowed(Inset::Code code);
280         ///
281         Inset * getInset(lyx::pos_type pos);
282         ///
283         Inset const * getInset(lyx::pos_type pos) const;
284         /** important for cut and paste
285             Temporary change from BufferParams to Buffer. Will revert when we
286             get rid of the argument to Inset::clone(Buffer const &) */
287         void copyIntoMinibuffer(Buffer const &, lyx::pos_type pos) const;
288         ///
289         void cutIntoMinibuffer(BufferParams const &, lyx::pos_type pos);
290         ///
291         bool insertFromMinibuffer(lyx::pos_type pos);
292
293         ///
294         bool isHfill(lyx::pos_type pos) const;
295         ///
296         bool isInset(lyx::pos_type pos) const;
297         ///
298         bool isNewline(lyx::pos_type pos) const;
299         ///
300         bool isSeparator(lyx::pos_type pos) const;
301         ///
302         bool isLineSeparator(lyx::pos_type pos) const;
303         ///
304         bool isKomma(lyx::pos_type pos) const;
305         /// Used by the spellchecker
306         bool isLetter(lyx::pos_type pos) const;
307         ///
308         bool isWord(lyx::pos_type pos) const;
309
310         /** paste this paragraph with the next one
311             be carefull, this doesent make any check at all
312         */
313         void pasteParagraph(BufferParams const &);
314
315         /// returns -1 if inset not found
316         int getPositionOfInset(Inset const * inset) const;
317
318         /// some good comment here John?
319         Paragraph * getParFromID(int id) const;
320
321         ///
322         int stripLeadingSpaces();
323
324 #ifndef NO_PEXTRA_REALLY
325         /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
326            I have to set it on each of it's elements */
327         ///
328         void setPExtraType(BufferParams const &, int type,
329                            string const & width, string const & widthp);
330         ///
331         void unsetPExtraType(BufferParams const &);
332 #endif
333         ///
334         bool sgmlConvertChar(char c, string & sgml_string);
335         ///
336         bool isFreeSpacing() const;
337
338         ParagraphParameters & params();
339         ParagraphParameters const & params() const;
340 private:
341         ///
342         LyXLayout_ptr layout_;
343 public:
344         /** Both these definitions must be made public to keep Compaq cxx 6.5
345          *  happy.
346          */
347         ///
348         struct InsetTable {
349                 ///
350                 lyx::pos_type pos;
351                 ///
352                 Inset * inset;
353                 ///
354                 InsetTable(lyx::pos_type p, Inset * i) : pos(p), inset(i) {}
355         };
356
357         ///
358         typedef std::vector<InsetTable> InsetList;
359 private:
360         ///
361         InsetList insetlist;
362 public:
363         ///
364         class inset_iterator {
365         public:
366                 ///
367                 inset_iterator() {}
368                 //
369                 inset_iterator(InsetList::iterator const & iter);
370                 ///
371                 inset_iterator & operator++() {
372                         ++it;
373                         return *this;
374                 }
375                 ///
376                 Inset * operator*() { return it->inset; }
377                 ///
378                 Inset * operator->() { return it->inset; }
379
380                 ///
381                 lyx::pos_type getPos() const { return it->pos; }
382                 ///
383                 bool operator==(inset_iterator const & iter) const {
384                         return it == iter.it;
385                 }
386                 ///
387                 bool operator!=(inset_iterator const & iter) const {
388                         return it != iter.it;
389                 }
390         private:
391                 ///
392                 InsetList::iterator it;
393         };
394         ///
395         friend class inset_iterator;
396
397         ///
398         inset_iterator inset_iterator_begin();
399         ///
400         inset_iterator inset_iterator_end();
401         /// returns inset iterator of the first inset at or after pos.
402         inset_iterator InsetIterator(lyx::pos_type pos);
403
404 private:
405         /// if anything uses this we don't want it to.
406         Paragraph(Paragraph const &);
407         ///
408         Paragraph * next_;
409         ///
410         Paragraph * previous_;
411
412         struct Pimpl;
413         ///
414         friend struct Paragraph::Pimpl;
415         ///
416         Pimpl * pimpl_;
417 };
418
419 #endif