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