]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
This should clean up the language stuff a bit and a small new check for
[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"
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 = false);
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         
116         ///
117         void writeFile(Buffer const *, std::ostream &, BufferParams const &,
118                        depth_type) const;
119         ///
120         void validate(LaTeXFeatures &) const;
121         
122         ///
123         int id() const;
124         ///
125         void id(int id_arg);
126         ///
127         void read();
128
129         ///
130         Paragraph * TeXOnePar(Buffer const *, BufferParams const &,
131                                  std::ostream &, TexRow & texrow,
132                                  bool moving_arg);
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(BufferParams const &) 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         size_type size() const;
163         ///
164         void setContentsFromPar(Paragraph * par);
165         ///
166         void clearContents();
167
168         ///
169         LyXTextClass::LayoutList::size_type layout;
170
171         ///
172         void setCounter(int i, int v);
173         ///
174         int getCounter(int i) const;
175         ///
176         void incCounter(int i);
177
178         ///
179         char enumdepth;
180         
181         ///
182         char itemdepth;
183
184         /// 
185         InsetBibKey * bibkey;  // ale970302
186
187         ///
188         void next(Paragraph *);
189         /** these function are able to hide closed footnotes
190          */
191         Paragraph * next();
192         ///
193         Paragraph const * next() const;
194
195         ///
196         void previous(Paragraph *);
197         ///
198         Paragraph * previous();
199         ///
200         Paragraph const * previous() const;
201
202         /// for the environments
203         Paragraph * depthHook(depth_type depth);
204         /// for the environments
205         Paragraph const * depthHook(depth_type depth) const;
206         /// 
207         Paragraph * outerHook();
208         /// 
209         Paragraph const * outerHook() const;
210         ///
211         int beginningOfMainBody() const;
212         ///
213         string const & getLabelstring() const;
214         
215         /// the next two functions are for the manual labels
216         string const getLabelWidthString() const;
217         ///
218         void setLabelWidthString(string const & s);
219         ///
220         LyXTextClass::LayoutList::size_type getLayout() const;
221         ///
222         char getAlign() const;
223         ///
224         depth_type getDepth() const;
225         ///
226         void setLayout(LyXTextClass::LayoutList::size_type new_layout);
227         ///
228         void setOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
229         ///
230         int getFirstCounter(int i) const;
231         ///
232         void erase(size_type pos);
233         /** the flag determines wether the layout should be copied
234          */ 
235         void breakParagraph(BufferParams const &, size_type pos, int flag);
236         ///
237         void breakParagraphConservative(BufferParams const &, size_type pos);
238         /** Get unistantiated font setting. Returns the difference
239             between the characters font and the layoutfont.
240             This is what is stored in the fonttable
241         */
242         LyXFont const
243         getFontSettings(BufferParams const &, size_type pos) const;
244         ///
245         LyXFont const getFirstFontSettings() const;
246
247         /** Get fully instantiated font. If pos == -1, use the layout
248             font attached to this paragraph.
249             If pos == -2, use the label font of the layout attached here.
250             In all cases, the font is instantiated, i.e. does not have any
251             attributes with values LyXFont::INHERIT, LyXFont::IGNORE or 
252             LyXFont::TOGGLE.
253         */
254         LyXFont const getFont(BufferParams const &, size_type pos) const;
255         ///
256         value_type getChar(size_type pos) const;
257         ///
258         value_type getUChar(BufferParams const &, size_type pos) const;
259         /// The position must already exist.
260         void setChar(size_type pos, value_type c);
261         ///
262         void setFont(size_type pos, LyXFont const & font);
263         /// Returns the height of the highest font in range
264         LyXFont::FONT_SIZE highestFontInRange(size_type startpos,
265                                               size_type endpos) const;
266         ///
267         void insertChar(size_type pos, value_type c);
268         ///
269         void insertChar(size_type pos, value_type c, LyXFont const &);
270         ///
271         bool checkInsertChar(LyXFont &);
272         ///
273         void insertInset(size_type pos, Inset * inset);
274         ///
275         void insertInset(size_type pos, Inset * inset, LyXFont const &);
276         ///
277         bool insetAllowed(Inset::Code code);
278         ///
279         Inset * getInset(size_type pos);
280         ///
281         Inset const * getInset(size_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 &, size_type pos) const;
286         ///
287         void cutIntoMinibuffer(BufferParams const &, size_type pos);
288         ///
289         bool insertFromMinibuffer(size_type pos);
290
291         ///
292         bool isHfill(size_type pos) const;
293         ///
294         bool isInset(size_type pos) const;
295         ///
296         bool isNewline(size_type pos) const;
297         ///
298         bool isSeparator(size_type pos) const;
299         ///
300         bool isLineSeparator(size_type pos) const;
301         ///
302         bool isKomma(size_type pos) const;
303         /// Used by the spellchecker
304         bool isLetter(size_type pos) const;
305         /// 
306         bool isWord(size_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 linuxDocConvertChar(char c, string & sgml_string);
341
342         ParagraphParameters & params();
343         ParagraphParameters const & params() const;
344 private:
345         
346         ///
347         struct InsetTable {
348                 ///
349                 size_type pos;
350                 ///
351                 Inset * inset;
352                 ///
353                 InsetTable(size_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                 size_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(size_type pos);
398
399 private:
400         ///
401         Paragraph * next_;
402         ///
403         Paragraph * previous_;
404
405         struct Pimpl;
406         ///
407         friend struct Paragraph::Pimpl;
408         ///
409         Pimpl * pimpl_;
410 };
411
412 #endif