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