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