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