2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
12 #ifndef LYXPARAGRAPH_H
13 #define LYXPARAGRAPH_H
22 #include "insets/lyxinset.h"
26 #include "support/block.h"
36 // I dare you to enable this and help me find all the bugs that then show
38 //#define NEW_INSETS 1
40 // I dare you to try this one too. It is ortogonal with NEW_INSETS so you
41 // can try both or just one of them.
44 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
59 enum MINIPAGE_ALIGNMENT {
63 MINIPAGE_ALIGN_MIDDLE,
93 //META_PROTECTED_SEPARATOR,
109 /// The footnotekinds
120 ALGORITHM, // Bernhard, 970807
122 WIDE_FIG, // CFO-G, 971106
124 WIDE_TAB // CFO-G, 971106
128 typedef char value_type;
130 typedef std::vector<value_type> TextContainer;
132 typedef int size_type;
136 /// this konstruktor inserts the new paragraph in a list
138 LyXParagraph(LyXParagraph * par);
139 /// the destruktors removes the new paragraph from the list
143 Language const * getParLanguage(BufferParams const &) const;
145 bool isRightToLeftPar(BufferParams const &) const;
147 void ChangeLanguage(BufferParams const & bparams,
148 Language const * from, Language const * to);
150 bool isMultiLingual(BufferParams const &);
153 string String(Buffer const *, bool label);
155 string String(Buffer const *, size_type beg, size_type end);
158 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
161 void validate(LaTeXFeatures &) const;
168 void id(int id_arg) {
176 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
177 std::ostream &, TexRow & texrow,
181 std::ostream & foot, TexRow & foot_texrow,
186 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
187 std::ostream &, TexRow & texrow, bool moving_arg);
190 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
191 std::ostream &, TexRow & texrow
193 ,std::ostream & foot, TexRow & foot_texrow,
198 LyXParagraph * Clone() const;
201 bool HasSameLayout(LyXParagraph const * par) const;
204 void MakeSameLayout(LyXParagraph const * par);
206 /// Is it the first par with same depth and layout?
207 bool IsFirstInSequence() const {
208 LyXParagraph const * dhook = DepthHook(GetDepth());
209 return (dhook == this
210 || dhook->GetLayout() != GetLayout()
211 || dhook->GetDepth() != GetDepth());
214 /** Check if the current paragraph is the last paragraph in a
216 int GetEndLabel(BufferParams const &) const;
218 Inset * InInset() { return inset_owner; }
220 void SetInsetOwner(Inset * i);
222 void deleteInsetsLyXText(BufferView *);
224 void resizeInsetsLyXText(BufferView *);
233 size_type size() const { return text.size(); }
236 text.resize(text.size());
239 void setContentsFromPar(LyXParagraph * par) {
243 void clearContents() {
248 VSpace added_space_top;
251 VSpace added_space_bottom;
257 LyXTextClass::LayoutList::size_type layout;
261 \item no footnote, closed footnote,
262 \item open footnote, where footnote
263 \item means footnote-environment
266 footnote_flag footnoteflag;
268 /// footnote, margin, fig, tab
269 footnote_kind footnotekind;
281 bool pagebreak_bottom;
294 block<int, 10> counter_;
297 void setCounter(int i, int v) { counter_[i] = v; }
299 int getCounter(int i) const { return counter_[i]; }
301 void incCounter(int i) { counter_[i]++; }
303 bool start_of_appendix;
314 /* This is for the paragraph extra stuff */
320 string pextra_widthp;
322 int pextra_alignment;
326 bool pextra_start_minipage;
332 string labelwidthstring;
337 LyXParagraph * previous;
340 /* table stuff -- begin*/
343 /* table stuff -- end*/
346 InsetBibKey * bibkey; // ale970302
348 /** these function are able to hide closed footnotes
350 LyXParagraph * Next();
353 LyXParagraph * Previous();
355 LyXParagraph const * Previous() const;
358 /** these function are able to hide open and closed footnotes
360 LyXParagraph * NextAfterFootnote();
362 LyXParagraph const * NextAfterFootnote() const;
365 LyXParagraph * PreviousBeforeFootnote();
367 LyXParagraph * LastPhysicalPar();
369 LyXParagraph const * LastPhysicalPar() const;
372 LyXParagraph * FirstPhysicalPar();
374 LyXParagraph const * FirstPhysicalPar() const;
375 /// returns the physical paragraph
376 LyXParagraph * ParFromPos(size_type pos);
377 /// returns the position in the physical par
378 int PositionInParFromPos(size_type pos) const;
381 /// for the environments
382 LyXParagraph * DepthHook(int depth);
383 /// for the environments
384 LyXParagraph const * DepthHook(int depth) const;
386 int BeginningOfMainBody() const;
388 string const & GetLabelstring() const;
390 /// the next two functions are for the manual labels
391 string GetLabelWidthString() const;
393 void SetLabelWidthString(string const & s);
395 LyXTextClass::LayoutList::size_type GetLayout() const;
397 char GetAlign() const;
399 char GetDepth() const;
401 void SetLayout(BufferParams const &,
402 LyXTextClass::LayoutList::size_type new_layout);
404 void SetOnlyLayout(BufferParams const &,
405 LyXTextClass::LayoutList::size_type new_layout);
407 int GetFirstCounter(int i) const;
409 size_type Last() const;
411 void Erase(size_type pos);
412 /** the flag determines wether the layout should be copied
414 void BreakParagraph(BufferParams const &, size_type pos, int flag);
416 void BreakParagraphConservative(BufferParams const &, size_type pos);
417 /** Get unistantiated font setting. Returns the difference
418 between the characters font and the layoutfont.
419 This is what is stored in the fonttable
421 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
423 LyXFont GetFirstFontSettings() const;
425 /** Get fully instantiated font. If pos == -1, use the layout
426 font attached to this paragraph.
427 If pos == -2, use the label font of the layout attached here.
428 In all cases, the font is instantiated, i.e. does not have any
429 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
432 LyXFont getFont(BufferParams const &, size_type pos) const;
434 value_type GetChar(size_type pos) const;
435 /// The position must already exist.
436 void SetChar(size_type pos, value_type c) {
441 void SetFont(size_type pos, LyXFont const & font);
443 string GetWord(size_type &) const;
444 /// Returns the height of the highest font in range
445 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
446 size_type endpos) const;
448 void InsertChar(size_type pos, value_type c);
450 void InsertChar(size_type pos, value_type c, LyXFont const &);
452 void InsertInset(size_type pos, Inset * inset);
454 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
456 bool InsertInsetAllowed(Inset * inset);
458 Inset * GetInset(size_type pos);
460 Inset const * GetInset(size_type pos) const;
463 void OpenFootnote(size_type pos);
465 void CloseFootnote(size_type pos);
467 /// important for cut and paste
468 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
470 void CutIntoMinibuffer(BufferParams const &, size_type pos);
472 bool InsertFromMinibuffer(size_type pos);
475 bool IsHfill(size_type pos) const;
477 bool IsInset(size_type pos) const;
480 bool IsFloat(size_type pos) const;
483 bool IsNewline(size_type pos) const;
485 bool IsSeparator(size_type pos) const;
487 bool IsLineSeparator(size_type pos) const;
489 bool IsKomma(size_type pos) const;
490 /// Used by the spellchecker
491 bool IsLetter(size_type pos) const;
493 bool IsWord(size_type pos) const;
495 /** This one resets all layout and dtp switches but not the font
496 of the single characters
500 /** paste this paragraph with the next one
501 be carefull, this doesent make any check at all
503 void PasteParagraph(BufferParams const &);
505 /// used to remove the error messages
506 int AutoDeleteInsets();
508 /// returns -1 if inset not found
509 int GetPositionOfInset(Inset * inset) const;
512 /// ok and now some footnote functions
513 void OpenFootnotes();
516 void CloseFootnotes();
518 LyXParagraph * FirstSelfrowPar();
522 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
525 /** A paragraph following a footnote is a "dummy". A paragraph
526 with a footnote in it is stored as three paragraphs:
527 First a paragraph with the text up to the footnote, then
528 one (or more) paragraphs with the footnote, and finally
529 the a paragraph with the text after the footnote. Only the
530 first paragraph keeps information about layoutparameters, */
531 bool IsDummy() const;
533 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
534 I have to set it on each of it's elements */
536 void SetPExtraType(BufferParams const &,
537 int type, char const * width, char const * widthp);
539 void UnsetPExtraType(BufferParams const &);
541 bool linuxDocConvertChar(char c, string & sgml_string);
544 void DocBookContTableRows(Buffer const *,
545 std::ostream &, string & extra,
546 int & desc_on, size_type i,
547 int current_cell_number, int & column);
549 void SimpleDocBookOneTablePar(Buffer const *,
550 std::ostream &, string & extra,
551 int & desc_on, int depth);
561 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
564 friend struct matchIT;
567 /// used by lower_bound and upper_bound
569 int operator()(LyXParagraph::InsetTable const & a,
570 LyXParagraph::InsetTable const & b) const {
571 return a.pos < b.pos;
574 /** A font entry covers a range of positions. Notice that the
575 entries in the list are inserted in random order.
576 I don't think it's worth the effort to implement a more effective
577 datastructure, because the number of different fonts in a paragraph
579 Nevertheless, I decided to store fontlist using a sorted vector:
580 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
581 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
582 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
583 (font_1 covers the chars 0,...,pos_1) (Dekel)
586 /// End position of paragraph this font attribute covers
588 /** Font. Interpretation of the font values:
589 If a value is LyXFont::INHERIT_*, it means that the font
590 attribute is inherited from either the layout of this
591 paragraph or, in the case of nested paragraphs, from the
592 layout in the environment one level up until completely
594 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
595 allowed in these font tables.
599 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
602 friend struct matchFT;
605 /// used by lower_bound and upper_bound
607 int operator()(LyXParagraph::FontTable const & a,
608 LyXParagraph::FontTable const & b) const {
609 return a.pos < b.pos;
614 typedef std::vector<FontTable> FontList;
618 typedef std::vector<InsetTable> InsetList;
622 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
623 std::ostream &, TexRow & texrow
625 ,std::ostream & foot, TexRow & foot_texrow,
631 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
632 std::ostream &, TexRow & texrow,
633 std::ostream & foot, TexRow & foot_texrow,
639 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
640 std::ostream &, TexRow & texrow);
642 bool TeXContTableRows(Buffer const *, BufferParams const &,
643 std::ostream &, size_type i,
644 int current_cell_number,
645 int & column, TexRow & texrow);
648 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
650 int & column, LyXFont const & font,
651 LyXLayout const & style);
653 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
654 std::ostream &, TexRow & texrow,
656 LyXFont & font, LyXFont & running_font,
657 LyXFont & basefont, bool & open_font,
658 LyXLayout const & style,
660 int & column, value_type const c);
664 static unsigned int paragraph_id;
667 class inset_iterator {
672 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
674 inset_iterator & operator++() {
679 Inset * operator*() { return (*it).inset; }
681 size_type getPos() {return (*it).pos; }
683 bool operator==(inset_iterator const & iter) const {
684 return it == iter.it;
687 bool operator!=(inset_iterator const & iter) const {
688 return it != iter.it;
692 InsetList::iterator it;
695 inset_iterator inset_iterator_begin() {
696 return inset_iterator(insetlist.begin());
699 inset_iterator inset_iterator_end() {
700 return inset_iterator(insetlist.end());
703 inset_iterator InsetIterator(size_type pos);