]> git.lyx.org Git - features.git/blob - src/lyxparagraph.h
fix lyxalgo.h, dra pagebreak with text on line, change the math_deco_search a bit
[features.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(ostream &, TexRow & texrow,
155                                  ostream & foot, TexRow & foot_texrow,
156                                  int & foot_count);
157         ///
158         bool SimpleTeXOnePar(ostream &, TexRow & texrow);
159
160         ///
161         LyXParagraph * TeXEnvironment(ostream &, TexRow & texrow,
162                                       ostream & foot, TexRow & foot_texrow,
163                                       int & foot_count);
164         ///
165         LyXParagraph * Clone() const;
166         
167         ///
168         bool HasSameLayout(LyXParagraph const * par) const;
169         
170         ///
171         void MakeSameLayout(LyXParagraph const * par);
172
173         /// Is it the first par with same depth and layout?
174         bool IsFirstInSequence() const {
175                 LyXParagraph const * dhook = DepthHook(GetDepth());
176                 return (dhook == this
177                         || dhook->GetLayout() != GetLayout()
178                         || dhook->GetDepth() != GetDepth());
179         }
180
181
182         ///
183         TextContainer text;
184         ///
185         size_type size() const { return text.size(); }
186         /// 
187         VSpace added_space_top;
188         
189         /// 
190         VSpace added_space_bottom;
191         
192         ///
193         LyXTextClass::LayoutList::size_type layout;
194         
195         /**
196           \begin{itemize}
197           \item no footnote, closed footnote, 
198           \item open footnote, where footnote
199           \item means footnote-environment
200           \end{itemize}
201          */
202         footnote_flag footnoteflag;
203
204         /// footnote, margin, fig, tab
205         footnote_kind footnotekind;
206    
207         //@Man: the LyX- DTP-switches
208         //@{
209         ///
210         bool line_top;
211         
212         ///
213         bool line_bottom;
214         
215         ///
216         bool pagebreak_top;
217         
218         ///
219         bool pagebreak_bottom;
220         
221         ///
222         LyXAlignment align;
223         
224         ///
225         char depth;
226         
227         ///
228         bool noindent;
229         
230 private:
231         block<int, 10> counter_;
232 public:
233         ///
234         void setCounter(int i, int v) { counter_[i] = v; }
235         int getCounter(int i) const { return counter_[i]; }
236         void incCounter(int i) { counter_[i]++; }
237         ///
238         bool start_of_appendix;
239
240         ///
241         bool appendix;
242
243         ///
244         char enumdepth;
245         
246         ///
247         char itemdepth;
248
249         /* This is for the paragraph extra stuff */
250         ///
251         int pextra_type;
252         ///
253         string pextra_width;
254         ///
255         string pextra_widthp;
256         ///
257         int pextra_alignment;
258         ///
259         bool pextra_hfill;
260         ///
261         bool pextra_start_minipage;
262         
263         ///
264         string labelstring;
265         
266         ///
267         string labelwidthstring;
268         //@}
269         
270         ///
271         LyXParagraph * next;
272         ///
273         LyXParagraph * previous;
274
275         /* table stuff -- begin*/
276         ///
277         LyXTable * table;
278         /* table stuff -- end*/
279
280         /// 
281         InsetBibKey * bibkey;  // ale970302
282
283         /** these function are able to hide closed footnotes
284          */
285         LyXParagraph * Next();
286         
287         ///
288         LyXParagraph * Previous();
289         ///
290         LyXParagraph const * Previous() const;
291
292         /** these function are able to hide open and closed footnotes
293          */ 
294         LyXParagraph * NextAfterFootnote();
295         ///
296         LyXParagraph const * NextAfterFootnote() const;
297         
298         ///
299         LyXParagraph * PreviousBeforeFootnote();
300         ///
301         LyXParagraph * LastPhysicalPar();
302         
303         ///
304         LyXParagraph * FirstPhysicalPar();
305         ///
306         LyXParagraph const * FirstPhysicalPar() const;
307
308         /// returns the physical paragraph
309         LyXParagraph * ParFromPos(size_type pos);
310         /// returns the position in the physical par
311         int PositionInParFromPos(size_type pos) const;
312
313         /// for the environments
314         LyXParagraph * DepthHook(int depth);
315         /// for the environments
316         LyXParagraph const * DepthHook(int depth) const;
317         ///
318         int BeginningOfMainBody() const;
319         ///
320         string GetLabestring() const;
321         
322         /// the next two functions are for the manual labels
323         string GetLabelWidthString() const;
324         ///
325         void SetLabelWidthString(string const & s);
326         ///
327         LyXTextClass::LayoutList::size_type GetLayout() const;
328         ///
329         char GetAlign() const;
330         ///
331         char GetDepth() const;
332         ///
333         void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
334         ///
335         void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
336         ///
337         int GetFirstCounter(int i) const;
338         ///
339         size_type Last() const;
340         ///
341         void Erase(size_type pos);
342         /** the flag determines wether the layout should be copied
343          */ 
344         void BreakParagraph(size_type pos, int flag);
345         ///
346         void BreakParagraphConservative(size_type pos);
347         /** Get unistantiated font setting. Returns the difference
348           between the characters font and the layoutfont.
349           This is what is stored in the fonttable
350          */
351         LyXFont GetFontSettings(size_type pos) const;
352         /** Get fully instantiated font. If pos == -1, use the layout
353           font attached to this paragraph.
354           If pos == -2, use the label font of the layout attached here.
355           In all cases, the font is instantiated, i.e. does not have any
356           attributes with values LyXFont::INHERIT, LyXFont::IGNORE or 
357           LyXFont::TOGGLE.
358           */
359         LyXFont getFont(size_type pos) const;
360         ///
361         char GetChar(size_type pos);
362         ///
363         char GetChar(size_type pos) const;
364         ///
365         void SetFont(size_type pos, LyXFont const & font);
366         ///
367         string GetWord(size_type &) const;
368         /// Returns the height of the highest font in range
369         LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
370                                               size_type endpos) const;
371         ///
372         void InsertChar(size_type pos, char c);
373         ///
374         void InsertInset(size_type pos, Inset * inset);
375         ///
376         Inset * GetInset(size_type pos);
377         ///
378         Inset const * GetInset(size_type pos) const;
379         ///
380         Inset * ReturnNextInsetPointer(size_type & pos);
381         ///
382         void OpenFootnote(size_type pos);
383         ///
384         void CloseFootnote(size_type pos);
385         /// important for cut and paste
386         void CopyIntoMinibuffer(size_type pos) const;
387         ///
388         void CutIntoMinibuffer(size_type pos);
389         ///
390         void InsertFromMinibuffer(size_type pos);
391
392         ///
393         bool IsHfill(size_type pos) const;
394         ///
395         bool IsInset(size_type pos) const;
396         ///
397         bool IsFloat(size_type pos) const;
398         ///
399         bool IsNewline(size_type pos) const;
400         ///
401         bool IsSeparator(size_type pos) const;
402         ///
403         bool IsLineSeparator(size_type pos) const;
404         ///
405         bool IsKomma(size_type pos) const;
406         /// Used by the spellchecker
407         bool IsLetter(size_type pos) const;
408         /// 
409         bool IsWord(size_type pos) const;
410
411         /** This one resets all layout and dtp switches but not the font
412          of the single characters
413          */ 
414         void Clear();
415
416         /** paste this paragraph with the next one
417           be carefull, this doesent make any check at all
418           */ 
419         void PasteParagraph();
420
421         /// used to remove the error messages
422         int AutoDeleteInsets();
423
424         /// returns -1 if inset not found
425         int GetPositionOfInset(Inset * inset) const;
426         
427         /// ok and now some footnote functions
428         void OpenFootnotes();
429
430         ///
431         void CloseFootnotes();
432    
433         ///
434         LyXParagraph * FirstSelfrowPar();
435
436         ///
437         int ClearParagraph() {
438                 int i = 0;
439                 if (!IsDummy() && !table){
440                         while (Last()
441                                && (IsNewline(0) 
442                                    || IsLineSeparator(0))){
443                                 Erase(0);
444                                 ++i;
445                         }
446                 }
447                 return i;
448         }
449         
450         /** A paragraph following a footnote is a "dummy". A paragraph
451           with a footnote in it is stored as three paragraphs:
452           First a paragraph with the text up to the footnote, then
453           one (or more) paragraphs with the footnote, and finally
454           the a paragraph with the text after the footnote. Only the
455           first paragraph keeps information  about layoutparameters, */
456         bool IsDummy() const {
457                 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
458                         && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
459         }
460
461         /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
462            I have to set it on each of it's elements */
463         ///
464         void SetPExtraType(int type, char const * width, char const * widthp);
465         ///
466         void UnsetPExtraType();
467 #if 0
468         ///
469         bool RoffContTableRows(ostream &, size_type i, int actcell);
470 #endif
471         ///
472         bool linuxDocConvertChar(char c, string & sgml_string);
473         ///
474         void DocBookContTableRows(ostream &, string & extra, int & desc_on,
475                                   size_type i,
476                                   int current_cell_number, int & column);
477         ///
478         void SimpleDocBookOneTablePar(ostream &, string & extra,
479                                       int & desc_on, int depth);
480 private:
481         /** A font entry covers a range of positions. Notice that the
482           entries in the list are inserted in random order.
483           I don't think it's worth the effort to implement a more effective
484           datastructure, because the number of different fonts in a paragraph
485           is limited. (Asger)
486         */
487         struct FontTable  {
488                 /// Start position of paragraph this font attribute covers
489                 size_type pos;
490                 /// Ending position of paragraph this font attribute covers
491                 size_type pos_end;
492                 /** Font. Interpretation of the font values:
493                 If a value is LyXFont::INHERIT_*, it means that the font 
494                 attribute is inherited from either the layout of this
495                 paragraph or, in the case of nested paragraphs, from the 
496                 layout in the environment one level up until completely 
497                 resolved.
498                 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT 
499                 allowed in these font tables.
500                 */
501                 LyXFont font;
502         };
503         ///
504         struct InsetTable {
505                 ///
506                 size_type pos;
507                 ///
508                 Inset * inset;
509         };
510         ///
511         typedef list<FontTable> FontList;
512         ///
513         FontList fontlist;
514         ///
515         typedef list<InsetTable> InsetList;
516         ///
517         InsetList insetlist;
518         ///
519         LyXParagraph * TeXDeeper(ostream &, TexRow & texrow,
520                                  ostream & foot, TexRow & foot_texrow,
521                                  int & foot_count);
522         ///
523         LyXParagraph * TeXFootnote(ostream &, TexRow & texrow,
524                                    ostream & foot, TexRow & foot_texrow,
525                                    int & foot_count,
526                                    LyXDirection par_direction);
527         ///
528         bool SimpleTeXOneTablePar(ostream &, TexRow & texrow);
529         ///
530         bool TeXContTableRows(ostream &, size_type i,
531                               int current_cell_number,
532                               int & column, TexRow & texrow);
533         ///
534         void SimpleTeXBlanks(ostream &, TexRow & texrow,
535                              size_type const i,
536                              int & column, LyXFont const & font,
537                              LyXLayout const & style);
538         ///
539         void SimpleTeXSpecialChars(ostream &, TexRow & texrow,
540                                    LyXFont & font, LyXFont & running_font,
541                                    LyXFont & basefont, bool & open_font,
542                                    LyXLayout const & style,
543                                    size_type & i,
544                                    int & column, char const c);
545         ///
546         unsigned int id_;
547         ///
548         static unsigned int paragraph_id;
549 };
550 #endif