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