]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
isInset patch from John
[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 <vector>
22
23 #include "insets/inset.h" // Just for Inset::Code
24 #include "layout.h"
25
26 class ParagraphParameters;
27 class BufferParams;
28 class TexRow;
29 struct LaTeXFeatures;
30 class InsetBibKey;
31 class BufferView;
32 class Language;
33
34 // After 1.2.0 is released, during 1.3.0cvs, we enable this. And after
35 // a while we verify that reading of 1.2.x files work perfectly we remove
36 // this code completely. (Lgb)
37 //#define NO_PEXTRA_REALLY 1
38
39 // Define this if you want to try out the new storage container for
40 // paragraphs. std::container instead of obfuscated homegrown
41 // linked list. (Lgb)
42 // This is non working and far from finished.
43 // #define NO_NEXT 1
44
45 /// A Paragraph holds all text, attributes and insets in a text paragraph
46 class Paragraph  {
47 public:
48 #ifndef NO_PEXTRA_REALLY
49         ///
50         enum PEXTRA_TYPE {
51                 ///
52                 PEXTRA_NONE,
53                 ///
54                 PEXTRA_INDENT,
55                 ///
56                 PEXTRA_MINIPAGE,
57                 ///
58                 PEXTRA_FLOATFLT
59         };
60         ///
61         enum MINIPAGE_ALIGNMENT {
62                 ///
63                 MINIPAGE_ALIGN_TOP,
64                 ///
65                 MINIPAGE_ALIGN_MIDDLE,
66                 ///
67                 MINIPAGE_ALIGN_BOTTOM
68         };
69 #endif
70         ///
71         enum META_KIND {
72                 ///
73                 META_HFILL = 1,
74                 ///
75                 META_NEWLINE,
76                 ///
77                 META_INSET
78         };
79         ///
80         typedef char value_type;
81         /// The same as ParameterStruct::depth_type 
82         typedef unsigned int depth_type;
83         ///
84         typedef std::vector<value_type> TextContainer;
85         ///
86         /* This should be TextContainer::size_type, but we need
87            signed values for now.
88         */
89         typedef TextContainer::difference_type size_type;
90
91         ///
92         Paragraph();
93         /// this constructor inserts the new paragraph in a list
94         explicit
95         Paragraph(Paragraph * par);
96         ///
97         Paragraph(Paragraph const &, bool same_ids);
98         /// the destructor removes the new paragraph from the list
99         ~Paragraph();
100
101         ///
102         Language const * getParLanguage(BufferParams const &) const;
103         ///
104         bool isRightToLeftPar(BufferParams const &) const;
105         ///
106         void changeLanguage(BufferParams const & bparams,
107                             Language const * from, Language const * to);
108         ///
109         bool isMultiLingual(BufferParams const &);
110         ///
111
112         string const asString(Buffer const *, bool label);
113         ///
114         string const asString(Buffer const *, size_type beg, size_type end,
115                               bool label);
116         
117         ///
118         void writeFile(Buffer const *, std::ostream &, BufferParams const &,
119                        depth_type) const;
120         ///
121         void validate(LaTeXFeatures &) const;
122         
123         ///
124         int id() const;
125         ///
126         void id(int id_arg);
127         ///
128         void read();
129
130         ///
131         Paragraph * TeXOnePar(Buffer const *, BufferParams const &,
132                                  std::ostream &, TexRow & texrow,
133                                  bool moving_arg);
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         size_type size() const;
164         ///
165         void setContentsFromPar(Paragraph * par);
166         ///
167         void clearContents();
168
169         ///
170         LyXTextClass::LayoutList::size_type 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         LyXTextClass::LayoutList::size_type getLayout() const;
222         ///
223         char getAlign() const;
224         ///
225         depth_type getDepth() const;
226         ///
227         void setLayout(LyXTextClass::LayoutList::size_type new_layout);
228         ///
229         void setOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
230         ///
231         int getFirstCounter(int i) const;
232         ///
233         void erase(size_type pos);
234         /** the flag determines wether the layout should be copied
235          */ 
236         void breakParagraph(BufferParams const &, size_type pos, int flag);
237         ///
238         void breakParagraphConservative(BufferParams const &, size_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 &, size_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 &, size_type pos) const;
256         LyXFont const getLayoutFont(BufferParams const &) const;
257         LyXFont const getLabelFont(BufferParams const &) const;
258         ///
259         value_type getChar(size_type pos) const;
260         ///
261         value_type getUChar(BufferParams const &, size_type pos) const;
262         /// The position must already exist.
263         void setChar(size_type pos, value_type c);
264         ///
265         void setFont(size_type pos, LyXFont const & font);
266         /// Returns the height of the highest font in range
267         LyXFont::FONT_SIZE highestFontInRange(size_type startpos,
268                                               size_type endpos,
269                                                                                   LyXFont::FONT_SIZE const def_size) const;
270         ///
271         void insertChar(size_type pos, value_type c);
272         ///
273         void insertChar(size_type pos, value_type c, LyXFont const &);
274         ///
275         bool checkInsertChar(LyXFont &);
276         ///
277         void insertInset(size_type pos, Inset * inset);
278         ///
279         void insertInset(size_type pos, Inset * inset, LyXFont const &);
280         ///
281         bool insetAllowed(Inset::Code code);
282         ///
283         Inset * getInset(size_type pos);
284         ///
285         Inset const * getInset(size_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 &, size_type pos) const;
290         ///
291         void cutIntoMinibuffer(BufferParams const &, size_type pos);
292         ///
293         bool insertFromMinibuffer(size_type pos);
294
295         ///
296         bool isHfill(size_type pos) const;
297         ///
298         bool isInset(size_type pos) const;
299         ///
300         bool isNewline(size_type pos) const;
301         ///
302         bool isSeparator(size_type pos) const;
303         ///
304         bool isLineSeparator(size_type pos) const;
305         ///
306         bool isKomma(size_type pos) const;
307         /// Used by the spellchecker
308         bool isLetter(size_type pos) const;
309         /// 
310         bool isWord(size_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         /// used to remove the error messages
323         int autoDeleteInsets();
324
325         /// returns -1 if inset not found
326         int getPositionOfInset(Inset * inset) const;
327
328         /// some good comment here John?
329         Paragraph * getParFromID(int id) const;
330
331         ///
332         int stripLeadingSpaces(LyXTextClassList::size_type tclass); 
333
334 #ifndef NO_PEXTRA_REALLY
335         /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
336            I have to set it on each of it's elements */
337         ///
338         void setPExtraType(BufferParams const &, int type,
339                            string const & width, string const & widthp);
340         ///
341         void unsetPExtraType(BufferParams const &);
342 #endif
343         ///
344         bool sgmlConvertChar(char c, string & sgml_string);
345
346         ParagraphParameters & params();
347         ParagraphParameters const & params() const;
348 private:
349         
350         ///
351         struct InsetTable {
352                 ///
353                 size_type pos;
354                 ///
355                 Inset * inset;
356                 ///
357                 InsetTable(size_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                 size_type getPos() const {return it->pos; }
381                 ///
382                 bool operator==(inset_iterator const & iter) const {
383                         return it == iter.it;
384                 }
385                 ///
386                 bool operator!=(inset_iterator const & iter) const {
387                         return it != iter.it;
388                 }
389         private:
390                 ///
391                 InsetList::iterator it;
392         };
393         ///
394         friend class inset_iterator;
395         
396         ///
397         inset_iterator inset_iterator_begin();
398         ///
399         inset_iterator inset_iterator_end();
400         ///
401         inset_iterator InsetIterator(size_type pos);
402
403 private:
404         /// if anything uses this we don't want it to.
405         Paragraph(Paragraph const &);
406         ///
407         Paragraph * next_;
408         ///
409         Paragraph * previous_;
410
411         struct Pimpl;
412         ///
413         friend struct Paragraph::Pimpl;
414         ///
415         Pimpl * pimpl_;
416 };
417
418 #endif