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