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