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