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