]> git.lyx.org Git - lyx.git/blob - src/lyxparagraph.h
the fstream/iostream changes and some small other things
[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(ostream &, BufferParams &, char, char);
125         ///
126         void validate(LaTeXFeatures &);
127         
128         ///
129         int id() const {
130                 return id_;
131         }
132         ///
133         void id(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() const;
155         
156         ///
157         bool HasSameLayout(LyXParagraph const * par);
158         
159         ///
160         void MakeSameLayout(LyXParagraph const * par);
161
162         /// Is it the first par with same depth and layout?
163         bool IsFirstInSequence() const {
164                 LyXParagraph const * 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         ///
176         typedef int size_type;
177         ///
178         TextContainer text;
179         ///
180         size_type size() const { return text.size(); }
181         /// 
182         VSpace added_space_top;
183         
184         /// 
185         VSpace added_space_bottom;
186         
187         ///
188         LyXTextClass::LayoutList::size_type layout;
189         
190         /**
191           \begin{itemize}
192           \item no footnote, closed footnote, 
193           \item open footnote, where footnote
194           \item means footnote-environment
195           \end{itemize}
196          */
197         footnote_flag footnoteflag;
198
199         /// footnote, margin, fig, tab
200         footnote_kind footnotekind;
201    
202         //@Man: the LyX- DTP-switches
203         //@{
204         ///
205         bool line_top;
206         
207         ///
208         bool line_bottom;
209         
210         ///
211         bool pagebreak_top;
212         
213         ///
214         bool pagebreak_bottom;
215         
216         ///
217         LyXAlignment align;
218         
219         ///
220         char depth;
221         
222         ///
223         bool noindent;
224         
225 private:
226         block<int, 10> counter_;
227 public:
228         ///
229         void setCounter(int i, int v) { counter_[i] = v; }
230         int getCounter(int i) const { return counter_[i]; }
231         void incCounter(int i) { counter_[i]++; }
232         ///
233         bool start_of_appendix;
234
235         ///
236         bool appendix;
237
238         ///
239         char enumdepth;
240         
241         ///
242         char itemdepth;
243
244         /* This is for the paragraph extra stuff */
245         ///
246         int pextra_type;
247         ///
248         string pextra_width;
249         ///
250         string pextra_widthp;
251         ///
252         int pextra_alignment;
253         ///
254         bool pextra_hfill;
255         ///
256         bool pextra_start_minipage;
257         
258         ///
259         string labelstring;
260         
261         ///
262         string labelwidthstring;
263         //@}
264         
265         ///
266         LyXParagraph * next;
267         ///
268         LyXParagraph * previous;
269
270         /* table stuff -- begin*/
271         ///
272         LyXTable * table;
273         /* table stuff -- end*/
274
275         /// 
276         InsetBibKey * bibkey;  // ale970302
277
278         /** these function are able to hide closed footnotes
279          */
280         LyXParagraph * Next();
281         
282         ///
283         LyXParagraph * Previous();
284         ///
285         LyXParagraph const * Previous() const;
286
287         /** these function are able to hide open and closed footnotes
288          */ 
289         LyXParagraph * NextAfterFootnote();
290         ///
291         LyXParagraph const * NextAfterFootnote() const;
292         
293         ///
294         LyXParagraph * PreviousBeforeFootnote();
295         ///
296         LyXParagraph * LastPhysicalPar();
297         
298         ///
299         LyXParagraph * FirstPhysicalPar();
300         ///
301         LyXParagraph const * FirstPhysicalPar() const;
302
303         /// returns the physical paragraph
304         LyXParagraph * ParFromPos(size_type pos);
305         /// returns the position in the physical par
306         int PositionInParFromPos(size_type pos) const;
307
308         /// for the environments
309         LyXParagraph * DepthHook(int depth);
310         /// for the environments
311         LyXParagraph const * DepthHook(int depth) const;
312         ///
313         int BeginningOfMainBody() const;
314         ///
315         string GetLabestring() const;
316         
317         /// the next two functions are for the manual labels
318         string GetLabelWidthString() const;
319         ///
320         void SetLabelWidthString(string const & s);
321         ///
322         LyXTextClass::LayoutList::size_type GetLayout() const;
323         ///
324         char GetAlign() const;
325         ///
326         char GetDepth() const;
327         ///
328         void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
329         ///
330         void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
331         ///
332         int GetFirstCounter(int i) const;
333         ///
334         size_type Last() const;
335         ///
336         void Erase(size_type pos);
337         /** the flag determines wether the layout should be copied
338          */ 
339         void BreakParagraph(size_type pos, int flag);
340         ///
341         void BreakParagraphConservative(size_type pos);
342         /** Get unistantiated font setting. Returns the difference
343           between the characters font and the layoutfont.
344           This is what is stored in the fonttable
345          */
346         LyXFont GetFontSettings(size_type pos) const;
347         /** Get fully instantiated font. If pos == -1, use the layout
348           font attached to this paragraph.
349           If pos == -2, use the label font of the layout attached here.
350           In all cases, the font is instantiated, i.e. does not have any
351           attributes with values LyXFont::INHERIT, LyXFont::IGNORE or 
352           LyXFont::TOGGLE.
353           */
354         LyXFont getFont(size_type pos) const;
355         ///
356         char GetChar(size_type pos);
357         ///
358         char GetChar(size_type pos) const;
359         ///
360         void SetFont(size_type pos, LyXFont const & font);
361         ///
362         string GetWord(size_type &) const;
363         /// Returns the height of the highest font in range
364         LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
365                                               size_type endpos) const;
366         ///
367         void InsertChar(size_type pos, char c);
368         ///
369         void InsertInset(size_type pos, Inset * inset);
370         ///
371         Inset * GetInset(size_type pos);
372         ///
373         Inset const * GetInset(size_type pos) const;
374         ///
375         Inset * ReturnNextInsetPointer(size_type & pos);
376         ///
377         void OpenFootnote(size_type pos);
378         ///
379         void CloseFootnote(size_type pos);
380         /// important for cut and paste
381         void CopyIntoMinibuffer(size_type pos) const;
382         ///
383         void CutIntoMinibuffer(size_type pos);
384         ///
385         void InsertFromMinibuffer(size_type pos);
386
387         ///
388         bool IsHfill(size_type pos) const;
389         ///
390         bool IsInset(size_type pos) const;
391         ///
392         bool IsFloat(size_type pos) const;
393         ///
394         bool IsNewline(size_type pos) const;
395         ///
396         bool IsSeparator(size_type pos) const;
397         ///
398         bool IsLineSeparator(size_type pos) const;
399         ///
400         bool IsKomma(size_type pos) const;
401         /// Used by the spellchecker
402         bool IsLetter(size_type pos) const;
403         /// 
404         bool IsWord(size_type pos) const;
405
406         /** This one resets all layout and dtp switches but not the font
407          of the single characters
408          */ 
409         void Clear();
410
411         /** paste this paragraph with the next one
412           be carefull, this doesent make any check at all
413           */ 
414         void PasteParagraph();
415
416         /// used to remove the error messages
417         int AutoDeleteInsets();
418
419         /// returns -1 if inset not found
420         int GetPositionOfInset(Inset * inset) const;
421         
422         /// ok and now some footnote functions
423         void OpenFootnotes();
424
425         ///
426         void CloseFootnotes();
427    
428         ///
429         LyXParagraph * FirstSelfrowPar();
430
431         ///
432         int ClearParagraph(){
433                 int i = 0;
434                 if (!IsDummy() && !table){
435                         while (Last()
436                                && (IsNewline(0) 
437                                    || IsLineSeparator(0))){
438                                 Erase(0);
439                                 i++;
440                         }
441                 }
442                 return i;
443         }
444         
445         /** A paragraph following a footnote is a "dummy". A paragraph
446           with a footnote in it is stored as three paragraphs:
447           First a paragraph with the text up to the footnote, then
448           one (or more) paragraphs with the footnote, and finally
449           the a paragraph with the text after the footnote. Only the
450           first paragraph keeps information  about layoutparameters, */
451         bool IsDummy() const{
452                 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
453                         && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
454         }
455
456         /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
457            I have to set it on each of it's elements */
458         ///
459         void SetPExtraType(int type, char const * width, char const * widthp);
460         ///
461         void UnsetPExtraType();
462         ///
463         bool RoffContTableRows(ostream &, size_type i, int actcell);
464         ///
465         void DocBookContTableRows(string & file, string & extra, int & desc_on,
466                                   size_type i,
467                                   int current_cell_number, int & column);
468         ///
469         bool linuxDocConvertChar(char c, string & sgml_string);
470         ///
471         void SimpleDocBookOneTablePar(string & file, string & extra,
472                                       int & desc_on, int depth);
473 private:
474         /** A font entry covers a range of positions. Notice that the
475           entries in the list are inserted in random order.
476           I don't think it's worth the effort to implement a more effective
477           datastructure, because the number of different fonts in a paragraph
478           is limited. (Asger)
479         */
480         struct FontTable  {
481                 /// Start position of paragraph this font attribute covers
482                 size_type pos;
483                 /// Ending position of paragraph this font attribute covers
484                 size_type pos_end;
485                 /** Font. Interpretation of the font values:
486                 If a value is LyXFont::INHERIT_*, it means that the font 
487                 attribute is inherited from either the layout of this
488                 paragraph or, in the case of nested paragraphs, from the 
489                 layout in the environment one level up until completely 
490                 resolved.
491                 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT 
492                 allowed in these font tables.
493                 */
494                 LyXFont font;
495 #ifndef NEW_TABLE
496                 /// Pointer to next font entry
497                 FontTable * next;
498 #endif
499         };
500         ///
501         struct InsetTable {
502                 ///
503                 size_type pos;
504                 ///
505                 Inset * inset;
506 #ifndef NEW_TABLE
507                 ///
508                 InsetTable * next;
509 #endif
510         };
511 #ifdef NEW_TABLE
512         ///
513         typedef list<FontTable> FontList;
514         ///
515         typedef list<InsetTable> InsetList;
516         ///
517         FontList fontlist;
518         ///
519         InsetList insetlist;
520 #else
521         ///
522         FontTable * fonttable;
523         ///
524         InsetTable * insettable;
525 #endif
526         ///
527         LyXParagraph * TeXDeeper(string & file, TexRow & texrow,
528                                    string & foot, TexRow & foot_texrow,
529                                    int & foot_count);
530         ///
531         LyXParagraph * TeXFootnote(string & file, TexRow & texrow,
532                                    string & foot, TexRow & foot_texrow,
533                                    int & foot_count);
534         ///
535         bool SimpleTeXOnePar(string & file, TexRow & texrow);
536         ///
537         bool SimpleTeXOneTablePar(string & file, TexRow & texrow);
538         ///
539         bool TeXContTableRows(string & file, size_type i,
540                               int current_cell_number,
541                               int & column, TexRow & texrow);
542         ///
543         void SimpleTeXBlanks(string & file, TexRow & texrow,
544                              size_type const i,
545                              int & column, LyXFont const & font,
546                              LyXLayout const & style);
547         ///
548         void SimpleTeXSpecialChars(string & file, TexRow & texrow,
549                                    LyXFont & font, LyXFont & running_font,
550                                    LyXFont & basefont, bool & open_font,
551                                    LyXLayout const & style,
552                                    size_type & i,
553                                    int & column, char const c);
554         ///
555         unsigned int id_;
556         ///
557         static unsigned int paragraph_id;
558 };
559 #endif