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