]> git.lyx.org Git - lyx.git/blob - src/paragraph.h
* Throw out DialogBase.h
[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 "lyxlayout_ptr_fwd.h"
17 #include "lyxfont.h" // Just for LyXFont::FONT_SIZE
18 #include "InsetList.h"
19
20 #include "insets/inset.h" // Just for Inset::Code
21
22 #include "support/types.h"
23
24 #include "LString.h"
25
26 class BufferParams;
27 class BufferView;
28 class Counters;
29 class InsetBibKey;
30 class Language;
31 class LaTeXFeatures;
32 class ParagraphParameters;
33 class TexRow;
34
35 // After 1.2.0 is released, during 1.3.0cvs, we enable this. And after
36 // a while we verify that reading of 1.2.x files work perfectly we remove
37 // this code completely. (Lgb)
38 #define NO_PEXTRA_REALLY 1
39
40 // Define this if you want to try out the new storage container for
41 // paragraphs. (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         ///
85         Paragraph();
86         /// this constructor inserts the new paragraph in a list
87         explicit
88         Paragraph(Paragraph * par);
89         ///
90         Paragraph(Paragraph const &, bool same_ids);
91         /// the destructor removes the new paragraph from the list
92         ~Paragraph();
93
94         ///
95         Language const * getParLanguage(BufferParams const &) const;
96         ///
97         bool isRightToLeftPar(BufferParams const &) const;
98         ///
99         void changeLanguage(BufferParams const & bparams,
100                             Language const * from, Language const * to);
101         ///
102         bool isMultiLingual(BufferParams const &);
103
104         ///
105         string const asString(Buffer const *, bool label);
106         ///
107         string const asString(Buffer const *, lyx::pos_type beg, lyx::pos_type end,
108                               bool label);
109
110         ///
111         void writeFile(Buffer const *, std::ostream &, BufferParams const &,
112                        depth_type) const;
113         ///
114         void validate(LaTeXFeatures &) const;
115
116         /// return the unique ID of this paragraph
117         int id() const;
118         ///
119         void read();
120
121         ///
122         Paragraph * TeXOnePar(Buffer const *, BufferParams const &,
123                                  std::ostream &, TexRow & texrow,
124                                  bool moving_arg);
125
126         ///
127         int startTeXParParams(BufferParams const &, std::ostream &, bool) const;
128
129         ///
130         int endTeXParParams(BufferParams const &, std::ostream &, bool) const;
131
132
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() 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         lyx::pos_type size() const;
163         ///
164         bool empty() const;
165         ///
166         void setContentsFromPar(Paragraph * par);
167         ///
168         void clearContents();
169
170         ///
171         LyXLayout_ptr const & layout() const;
172         ///
173         void layout(LyXLayout_ptr const & new_layout);
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         char getAlign() const;
218         /// The nesting depth of a paragraph
219         depth_type getDepth() const;
220         /// The maximal possible depth of a paragraph after this one
221         depth_type getMaxDepthAfter() const;
222         ///
223         void applyLayout(LyXLayout_ptr const & new_layout);
224         ///
225         void erase(lyx::pos_type pos);
226         /** the flag determines wether the layout should be copied
227          */
228         void breakParagraph(BufferParams const &, lyx::pos_type pos, int flag);
229         ///
230         void breakParagraphConservative(BufferParams const &, lyx::pos_type pos);
231         /** Get unistantiated font setting. Returns the difference
232             between the characters font and the layoutfont.
233             This is what is stored in the fonttable
234         */
235         LyXFont const
236         getFontSettings(BufferParams const &, lyx::pos_type pos) const;
237         ///
238         LyXFont const getFirstFontSettings() const;
239
240         /** Get fully instantiated font. If pos == -1, use the layout
241             font attached to this paragraph.
242             If pos == -2, use the label font of the layout attached here.
243             In all cases, the font is instantiated, i.e. does not have any
244             attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
245             LyXFont::TOGGLE.
246         */
247         LyXFont const getFont(BufferParams const &, lyx::pos_type pos) const;
248         LyXFont const getLayoutFont(BufferParams const &) const;
249         LyXFont const getLabelFont(BufferParams const &) const;
250         ///
251         value_type getChar(lyx::pos_type pos) const;
252         ///
253         value_type getUChar(BufferParams const &, lyx::pos_type pos) const;
254         /// The position must already exist.
255         void setChar(lyx::pos_type pos, value_type c);
256         /// pos <= size() (there is a dummy font change at the end of each par)
257         void setFont(lyx::pos_type pos, LyXFont const & font);
258         /// Returns the height of the highest font in range
259         LyXFont::FONT_SIZE
260         highestFontInRange(lyx::pos_type startpos,
261                            lyx::pos_type endpos,
262                            LyXFont::FONT_SIZE const def_size) const;
263         ///
264         void insertChar(lyx::pos_type pos, value_type c);
265         ///
266         void insertChar(lyx::pos_type pos, value_type c, LyXFont const &);
267         ///
268         bool checkInsertChar(LyXFont &);
269         ///
270         void insertInset(lyx::pos_type pos, Inset * inset);
271         ///
272         void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const &);
273         ///
274         bool insetAllowed(Inset::Code code);
275         ///
276         Inset * getInset(lyx::pos_type pos);
277         ///
278         Inset const * getInset(lyx::pos_type pos) const;
279         /** important for cut and paste
280             Temporary change from BufferParams to Buffer. Will revert when we
281             get rid of the argument to Inset::clone(Buffer const &) */
282         void copyIntoMinibuffer(Buffer const &, lyx::pos_type pos) const;
283         ///
284         void cutIntoMinibuffer(BufferParams const &, lyx::pos_type pos);
285         ///
286         bool insertFromMinibuffer(lyx::pos_type pos);
287
288         ///
289         bool isHfill(lyx::pos_type pos) const;
290         ///
291         bool isInset(lyx::pos_type pos) const;
292         ///
293         bool isNewline(lyx::pos_type pos) const;
294         ///
295         bool isSeparator(lyx::pos_type pos) const;
296         ///
297         bool isLineSeparator(lyx::pos_type pos) const;
298         ///
299         bool isKomma(lyx::pos_type pos) const;
300         /// Used by the spellchecker
301         bool isLetter(lyx::pos_type pos) const;
302         ///
303         bool isWord(lyx::pos_type pos) const;
304
305         /** paste this paragraph with the next one
306             be carefull, this doesent make any check at all
307         */
308         void pasteParagraph(BufferParams const &);
309
310         /// returns -1 if inset not found
311         int getPositionOfInset(Inset const * inset) const;
312
313         /// some good comment here John?
314         Paragraph * getParFromID(int id) const;
315
316         ///
317         int stripLeadingSpaces();
318
319 #ifndef NO_PEXTRA_REALLY
320         /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
321            I have to set it on each of it's elements */
322         ///
323         void setPExtraType(BufferParams const &, int type,
324                            string const & width, string const & widthp);
325         ///
326         void unsetPExtraType(BufferParams const &);
327 #endif
328         ///
329         bool isFreeSpacing() const;
330
331         ///
332         ParagraphParameters & params();
333         ///
334         ParagraphParameters const & params() const;
335         ///
336         InsetList insetlist;
337         ///
338         Counters & counters();
339
340 private:
341         ///
342         LyXLayout_ptr layout_;
343         /// if anything uses this we don't want it to.
344         Paragraph(Paragraph const &);
345         ///
346         Paragraph * next_;
347         ///
348         Paragraph * previous_;
349
350         struct Pimpl;
351         ///
352         friend struct Paragraph::Pimpl;
353         ///
354         Pimpl * pimpl_;
355 };
356
357 #endif