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