]> git.lyx.org Git - lyx.git/blob - src/lyxparagraph.h
1c319bddc8126fb5232678da4a9ead813afb34c6
[lyx.git] / src / lyxparagraph.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-2000 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef LYXPARAGRAPH_H
13 #define LYXPARAGRAPH_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <vector>
20 #include <list>
21
22 #include "insets/lyxinset.h"
23 #include "table.h"
24 #include "vspace.h"
25 #include "layout.h"
26 #include "support/block.h"
27 #include "direction.h"
28
29 class BufferParams;
30 class LyXBuffer;
31 class TexRow;
32 struct LaTeXFeatures;
33 class InsetBibKey;
34
35 using std::list;
36
37 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
38 class LyXParagraph  {
39 public:
40         ///
41         enum PEXTRA_TYPE {
42                 ///
43                 PEXTRA_NONE,
44                 ///
45                 PEXTRA_INDENT,
46                 ///
47                 PEXTRA_MINIPAGE,
48                 ///
49                 PEXTRA_FLOATFLT
50         };
51         ///
52         enum MINIPAGE_ALIGNMENT {
53                 ///
54                 MINIPAGE_ALIGN_TOP,
55                 ///
56                 MINIPAGE_ALIGN_MIDDLE,
57                 ///
58                 MINIPAGE_ALIGN_BOTTOM
59         };
60         ///
61         enum META_KIND {
62                 ///
63                 META_FOOTNOTE = 1,
64                 ///
65                 META_MARGIN,
66                 ///
67                 META_FIG,
68                 ///
69                 META_TAB,
70                 ///
71                 META_ALGORITHM,
72                 ///
73                 META_WIDE_FIG,
74                 ///
75                 META_WIDE_TAB,
76                 ///
77                 META_HFILL,
78                 ///
79                 META_NEWLINE,
80                 ///
81                 META_PROTECTED_SEPARATOR,
82                 ///
83                 META_INSET
84         };
85
86         /// The footnoteflag
87         enum footnote_flag {
88                 ///
89                 NO_FOOTNOTE,
90                 ///
91                 OPEN_FOOTNOTE,
92                 ///
93                 CLOSED_FOOTNOTE
94         };
95
96         /// The footnotekinds
97         enum footnote_kind {
98                 ///
99                 FOOTNOTE,
100                 ///
101                 MARGIN,
102                 ///
103                 FIG,
104                 ///
105                 TAB,
106                 ///
107                 ALGORITHM,  // Bernhard, 970807
108                 ///
109                 WIDE_FIG,   // CFO-G, 971106
110                 ///
111                 WIDE_TAB    // CFO-G, 971106
112         };
113         
114         ///
115         typedef char value_type;
116         ///
117         typedef vector<value_type> TextContainer;
118         ///
119         typedef int size_type;
120
121         ///
122         LyXParagraph();
123         /// this konstruktor inserts the new paragraph in a list
124         LyXParagraph(LyXParagraph * par);
125         /// the destruktors removes the new paragraph from the list
126         ~LyXParagraph();
127
128         ///
129         LyXDirection getParDirection() const;
130         ///
131         LyXDirection getLetterDirection(size_type pos) const;
132         
133         ///
134         void writeFile(ostream &, BufferParams const &, char, char) const;
135         ///
136         void validate(LaTeXFeatures &) const;
137         
138         ///
139         int id() const {
140                 return id_;
141         }
142         ///
143         void id(int id_arg) {
144                 id_ = id_arg;
145         }
146
147         ///
148         void read();
149
150         ///
151         void readSimpleWholeFile(istream &);
152
153         ///
154         LyXParagraph * TeXOnePar(string & file, TexRow & texrow,
155                                 string & foot, TexRow & foot_texrow,
156                                 int & foot_count);
157         ///
158         bool SimpleTeXOnePar(string & file, TexRow & texrow);
159
160         ///
161         LyXParagraph * TeXEnvironment(string & file, TexRow & texrow,
162                                      string & foot, TexRow & foot_texrow,
163                                      int & foot_count);
164         
165         ///
166         LyXParagraph * Clone() const;
167         
168         ///
169         bool HasSameLayout(LyXParagraph const * par) const;
170         
171         ///
172         void MakeSameLayout(LyXParagraph const * par);
173
174         /// Is it the first par with same depth and layout?
175         bool IsFirstInSequence() const {
176                 LyXParagraph const * dhook = DepthHook(GetDepth());
177                 return (dhook == this
178                         || dhook->GetLayout() != GetLayout()
179                         || dhook->GetDepth() != GetDepth());
180         }
181
182
183         ///
184         TextContainer text;
185         ///
186         size_type size() const { return text.size(); }
187         /// 
188         VSpace added_space_top;
189         
190         /// 
191         VSpace added_space_bottom;
192         
193         ///
194         LyXTextClass::LayoutList::size_type layout;
195         
196         /**
197           \begin{itemize}
198           \item no footnote, closed footnote, 
199           \item open footnote, where footnote
200           \item means footnote-environment
201           \end{itemize}
202          */
203         footnote_flag footnoteflag;
204
205         /// footnote, margin, fig, tab
206         footnote_kind footnotekind;
207    
208         //@Man: the LyX- DTP-switches
209         //@{
210         ///
211         bool line_top;
212         
213         ///
214         bool line_bottom;
215         
216         ///
217         bool pagebreak_top;
218         
219         ///
220         bool pagebreak_bottom;
221         
222         ///
223         LyXAlignment align;
224         
225         ///
226         char depth;
227         
228         ///
229         bool noindent;
230         
231 private:
232         block<int, 10> counter_;
233 public:
234         ///
235         void setCounter(int i, int v) { counter_[i] = v; }
236         int getCounter(int i) const { return counter_[i]; }
237         void incCounter(int i) { counter_[i]++; }
238         ///
239         bool start_of_appendix;
240
241         ///
242         bool appendix;
243
244         ///
245         char enumdepth;
246         
247         ///
248         char itemdepth;
249
250         /* This is for the paragraph extra stuff */
251         ///
252         int pextra_type;
253         ///
254         string pextra_width;
255         ///
256         string pextra_widthp;
257         ///
258         int pextra_alignment;
259         ///
260         bool pextra_hfill;
261         ///
262         bool pextra_start_minipage;
263         
264         ///
265         string labelstring;
266         
267         ///
268         string labelwidthstring;
269         //@}
270         
271         ///
272         LyXParagraph * next;
273         ///
274         LyXParagraph * previous;
275
276         /* table stuff -- begin*/
277         ///
278         LyXTable * table;
279         /* table stuff -- end*/
280
281         /// 
282         InsetBibKey * bibkey;  // ale970302
283
284         /** these function are able to hide closed footnotes
285          */
286         LyXParagraph * Next();
287         
288         ///
289         LyXParagraph * Previous();
290         ///
291         LyXParagraph const * Previous() const;
292
293         /** these function are able to hide open and closed footnotes
294          */ 
295         LyXParagraph * NextAfterFootnote();
296         ///
297         LyXParagraph const * NextAfterFootnote() const;
298         
299         ///
300         LyXParagraph * PreviousBeforeFootnote();
301         ///
302         LyXParagraph * LastPhysicalPar();
303         
304         ///
305         LyXParagraph * FirstPhysicalPar();
306         ///
307         LyXParagraph const * FirstPhysicalPar() const;
308
309         /// returns the physical paragraph
310         LyXParagraph * ParFromPos(size_type pos);
311         /// returns the position in the physical par
312         int PositionInParFromPos(size_type pos) const;
313
314         /// for the environments
315         LyXParagraph * DepthHook(int depth);
316         /// for the environments
317         LyXParagraph const * DepthHook(int depth) const;
318         ///
319         int BeginningOfMainBody() const;
320         ///
321         string GetLabestring() const;
322         
323         /// the next two functions are for the manual labels
324         string GetLabelWidthString() const;
325         ///
326         void SetLabelWidthString(string const & s);
327         ///
328         LyXTextClass::LayoutList::size_type GetLayout() const;
329         ///
330         char GetAlign() const;
331         ///
332         char GetDepth() const;
333         ///
334         void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
335         ///
336         void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
337         ///
338         int GetFirstCounter(int i) const;
339         ///
340         size_type Last() const;
341         ///
342         void Erase(size_type pos);
343         /** the flag determines wether the layout should be copied
344          */ 
345         void BreakParagraph(size_type pos, int flag);
346         ///
347         void BreakParagraphConservative(size_type pos);
348         /** Get unistantiated font setting. Returns the difference
349           between the characters font and the layoutfont.
350           This is what is stored in the fonttable
351          */
352         LyXFont GetFontSettings(size_type pos) const;
353         /** Get fully instantiated font. If pos == -1, use the layout
354           font attached to this paragraph.
355           If pos == -2, use the label font of the layout attached here.
356           In all cases, the font is instantiated, i.e. does not have any
357           attributes with values LyXFont::INHERIT, LyXFont::IGNORE or 
358           LyXFont::TOGGLE.
359           */
360         LyXFont getFont(size_type pos) const;
361         ///
362         char GetChar(size_type pos);
363         ///
364         char GetChar(size_type pos) const;
365         ///
366         void SetFont(size_type pos, LyXFont const & font);
367         ///
368         string GetWord(size_type &) const;
369         /// Returns the height of the highest font in range
370         LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
371                                               size_type endpos) const;
372         ///
373         void InsertChar(size_type pos, char c);
374         ///
375         void InsertInset(size_type pos, Inset * inset);
376         ///
377         Inset * GetInset(size_type pos);
378         ///
379         Inset const * GetInset(size_type pos) const;
380         ///
381         Inset * ReturnNextInsetPointer(size_type & pos);
382         ///
383         void OpenFootnote(size_type pos);
384         ///
385         void CloseFootnote(size_type pos);
386         /// important for cut and paste
387         void CopyIntoMinibuffer(size_type pos) const;
388         ///
389         void CutIntoMinibuffer(size_type pos);
390         ///
391         void InsertFromMinibuffer(size_type pos);
392
393         ///
394         bool IsHfill(size_type pos) const;
395         ///
396         bool IsInset(size_type pos) const;
397         ///
398         bool IsFloat(size_type pos) const;
399         ///
400         bool IsNewline(size_type pos) const;
401         ///
402         bool IsSeparator(size_type pos) const;
403         ///
404         bool IsLineSeparator(size_type pos) const;
405         ///
406         bool IsKomma(size_type pos) const;
407         /// Used by the spellchecker
408         bool IsLetter(size_type pos) const;
409         /// 
410         bool IsWord(size_type pos) const;
411
412         /** This one resets all layout and dtp switches but not the font
413          of the single characters
414          */ 
415         void Clear();
416
417         /** paste this paragraph with the next one
418           be carefull, this doesent make any check at all
419           */ 
420         void PasteParagraph();
421
422         /// used to remove the error messages
423         int AutoDeleteInsets();
424
425         /// returns -1 if inset not found
426         int GetPositionOfInset(Inset * inset) const;
427         
428         /// ok and now some footnote functions
429         void OpenFootnotes();
430
431         ///
432         void CloseFootnotes();
433    
434         ///
435         LyXParagraph * FirstSelfrowPar();
436
437         ///
438         int ClearParagraph() {
439                 int i = 0;
440                 if (!IsDummy() && !table){
441                         while (Last()
442                                && (IsNewline(0) 
443                                    || IsLineSeparator(0))){
444                                 Erase(0);
445                                 ++i;
446                         }
447                 }
448                 return i;
449         }
450         
451         /** A paragraph following a footnote is a "dummy". A paragraph
452           with a footnote in it is stored as three paragraphs:
453           First a paragraph with the text up to the footnote, then
454           one (or more) paragraphs with the footnote, and finally
455           the a paragraph with the text after the footnote. Only the
456           first paragraph keeps information  about layoutparameters, */
457         bool IsDummy() const {
458                 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
459                         && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
460         }
461
462         /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
463            I have to set it on each of it's elements */
464         ///
465         void SetPExtraType(int type, char const * width, char const * widthp);
466         ///
467         void UnsetPExtraType();
468         ///
469         bool RoffContTableRows(ostream &, size_type i, int actcell);
470         ///
471         void DocBookContTableRows(string & file, string & extra, int & desc_on,
472                                   size_type i,
473                                   int current_cell_number, int & column);
474         ///
475         bool linuxDocConvertChar(char c, string & sgml_string);
476         ///
477         void SimpleDocBookOneTablePar(string & file, string & extra,
478                                       int & desc_on, int depth);
479 private:
480         /** A font entry covers a range of positions. Notice that the
481           entries in the list are inserted in random order.
482           I don't think it's worth the effort to implement a more effective
483           datastructure, because the number of different fonts in a paragraph
484           is limited. (Asger)
485         */
486         struct FontTable  {
487                 /// Start position of paragraph this font attribute covers
488                 size_type pos;
489                 /// Ending position of paragraph this font attribute covers
490                 size_type pos_end;
491                 /** Font. Interpretation of the font values:
492                 If a value is LyXFont::INHERIT_*, it means that the font 
493                 attribute is inherited from either the layout of this
494                 paragraph or, in the case of nested paragraphs, from the 
495                 layout in the environment one level up until completely 
496                 resolved.
497                 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT 
498                 allowed in these font tables.
499                 */
500                 LyXFont font;
501         };
502         ///
503         struct InsetTable {
504                 ///
505                 size_type pos;
506                 ///
507                 Inset * inset;
508         };
509         ///
510         typedef list<FontTable> FontList;
511         ///
512         FontList fontlist;
513         ///
514         typedef list<InsetTable> InsetList;
515         ///
516         InsetList insetlist;
517         ///
518         LyXParagraph * TeXDeeper(string & file, TexRow & texrow,
519                                    string & foot, TexRow & foot_texrow,
520                                    int & foot_count);
521         ///
522         LyXParagraph * TeXFootnote(string & file, TexRow & texrow,
523                                    string & foot, TexRow & foot_texrow,
524                                    int & foot_count,
525                                    LyXDirection par_direction);
526         ///
527         bool SimpleTeXOneTablePar(string & file, TexRow & texrow);
528         ///
529         bool TeXContTableRows(string & file, size_type i,
530                               int current_cell_number,
531                               int & column, TexRow & texrow);
532         ///
533         void SimpleTeXBlanks(string & file, TexRow & texrow,
534                              size_type const i,
535                              int & column, LyXFont const & font,
536                              LyXLayout const & style);
537         ///
538         void SimpleTeXSpecialChars(string & file, TexRow & texrow,
539                                    LyXFont & font, LyXFont & running_font,
540                                    LyXFont & basefont, bool & open_font,
541                                    LyXLayout const & style,
542                                    size_type & i,
543                                    int & column, char const c);
544         ///
545         unsigned int id_;
546         ///
547         static unsigned int paragraph_id;
548 };
549 #endif