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