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
28 #include "insets/lyxinset.h"
31 #include <boost/array.hpp>
41 // I dare you to enable this and help me find all the bugs that then show
43 //#define NEW_INSETS 1
45 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
60 enum MINIPAGE_ALIGNMENT {
64 MINIPAGE_ALIGN_MIDDLE,
94 //META_PROTECTED_SEPARATOR,
110 /// The footnotekinds
121 ALGORITHM, // Bernhard, 970807
123 WIDE_FIG, // CFO-G, 971106
125 WIDE_TAB // CFO-G, 971106
129 typedef char value_type;
132 typedef std::vector<value_type> TextContainer;
134 typedef std::rope<value_type> TextContainer;
137 /* This should be TextContainer::size_type, but we need
138 signed values for now.
140 typedef TextContainer::difference_type size_type;
144 /// this constructor inserts the new paragraph in a list
146 LyXParagraph(LyXParagraph * par);
147 /// the destructor removes the new paragraph from the list
151 Language const * getParLanguage(BufferParams const &) const;
153 bool isRightToLeftPar(BufferParams const &) const;
155 void ChangeLanguage(BufferParams const & bparams,
156 Language const * from, Language const * to);
158 bool isMultiLingual(BufferParams const &);
161 string const String(Buffer const *, bool label);
163 string const String(Buffer const *, size_type beg, size_type end);
166 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
169 void validate(LaTeXFeatures &) const;
176 void id(int id_arg) {
184 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
185 std::ostream &, TexRow & texrow,
189 std::ostream & foot, TexRow & foot_texrow,
194 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
195 std::ostream &, TexRow & texrow, bool moving_arg);
198 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
199 std::ostream &, TexRow & texrow
201 ,std::ostream & foot, TexRow & foot_texrow,
206 LyXParagraph * Clone() const;
209 bool HasSameLayout(LyXParagraph const * par) const;
212 void MakeSameLayout(LyXParagraph const * par);
214 /// Is it the first par with same depth and layout?
215 bool IsFirstInSequence() const {
216 LyXParagraph const * dhook = DepthHook(GetDepth());
217 return (dhook == this
218 || dhook->GetLayout() != GetLayout()
219 || dhook->GetDepth() != GetDepth());
222 /** Check if the current paragraph is the last paragraph in a
224 int GetEndLabel(BufferParams const &) const;
226 Inset * InInset() { return inset_owner; }
228 void SetInsetOwner(Inset * i);
230 void deleteInsetsLyXText(BufferView *);
232 void resizeInsetsLyXText(BufferView *);
241 size_type size() const { return text.size(); }
245 text.resize(text.size());
249 void setContentsFromPar(LyXParagraph * par) {
253 void clearContents() {
257 text.erase(text.mutable_begin(), text.mutable_end());
262 VSpace added_space_top;
265 VSpace added_space_bottom;
271 LyXTextClass::LayoutList::size_type layout;
275 \item no footnote, closed footnote,
276 \item open footnote, where footnote
277 \item means footnote-environment
280 footnote_flag footnoteflag;
282 /// footnote, margin, fig, tab
283 footnote_kind footnotekind;
295 bool pagebreak_bottom;
308 array<int, 10> counter_;
311 void setCounter(int i, int v) { counter_[i] = v; }
313 int getCounter(int i) const { return counter_[i]; }
315 void incCounter(int i) { counter_[i]++; }
317 bool start_of_appendix;
328 /* This is for the paragraph extra stuff */
334 string pextra_widthp;
336 int pextra_alignment;
340 bool pextra_start_minipage;
346 string labelwidthstring;
351 LyXParagraph * previous;
354 InsetBibKey * bibkey; // ale970302
356 /** these function are able to hide closed footnotes
358 LyXParagraph * Next();
361 LyXParagraph * Previous();
363 LyXParagraph const * Previous() const;
366 /** these function are able to hide open and closed footnotes
368 LyXParagraph * NextAfterFootnote();
370 LyXParagraph const * NextAfterFootnote() const;
373 LyXParagraph * PreviousBeforeFootnote();
375 LyXParagraph * LastPhysicalPar();
377 LyXParagraph const * LastPhysicalPar() const;
380 LyXParagraph * FirstPhysicalPar();
382 LyXParagraph const * FirstPhysicalPar() const;
383 /// returns the physical paragraph
384 LyXParagraph * ParFromPos(size_type pos);
385 /// returns the position in the physical par
386 int PositionInParFromPos(size_type pos) const;
389 /// for the environments
390 LyXParagraph * DepthHook(int depth);
391 /// for the environments
392 LyXParagraph const * DepthHook(int depth) const;
394 int BeginningOfMainBody() const;
396 string const & GetLabelstring() const;
398 /// the next two functions are for the manual labels
399 string const GetLabelWidthString() const;
401 void SetLabelWidthString(string const & s);
403 LyXTextClass::LayoutList::size_type GetLayout() const;
405 char GetAlign() const;
407 char GetDepth() const;
409 void SetLayout(BufferParams const &,
410 LyXTextClass::LayoutList::size_type new_layout);
412 void SetOnlyLayout(BufferParams const &,
413 LyXTextClass::LayoutList::size_type new_layout);
415 int GetFirstCounter(int i) const;
417 size_type Last() const;
419 void Erase(size_type pos);
420 /** the flag determines wether the layout should be copied
422 void BreakParagraph(BufferParams const &, size_type pos, int flag);
424 void BreakParagraphConservative(BufferParams const &, size_type pos);
425 /** Get unistantiated font setting. Returns the difference
426 between the characters font and the layoutfont.
427 This is what is stored in the fonttable
430 GetFontSettings(BufferParams const &, size_type pos) const;
432 LyXFont const GetFirstFontSettings() const;
434 /** Get fully instantiated font. If pos == -1, use the layout
435 font attached to this paragraph.
436 If pos == -2, use the label font of the layout attached here.
437 In all cases, the font is instantiated, i.e. does not have any
438 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
441 LyXFont const getFont(BufferParams const &, size_type pos) const;
443 value_type GetChar(size_type pos) const;
445 value_type GetUChar(BufferParams const &, size_type pos) const;
446 /// The position must already exist.
447 void SetChar(size_type pos, value_type c) {
451 text.replace(pos, c);
456 void SetFont(size_type pos, LyXFont const & font);
458 string const GetWord(size_type &) const;
459 /// Returns the height of the highest font in range
460 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
461 size_type endpos) const;
463 void InsertChar(size_type pos, value_type c);
465 void InsertChar(size_type pos, value_type c, LyXFont const &);
467 void InsertInset(size_type pos, Inset * inset);
469 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
471 bool InsertInsetAllowed(Inset * inset);
473 Inset * GetInset(size_type pos);
475 Inset const * GetInset(size_type pos) const;
478 void OpenFootnote(size_type pos);
480 void CloseFootnote(size_type pos);
482 /** important for cut and paste
483 Temporary change from BufferParams to Buffer. Will revert when we
484 get rid of the argument to Inset::Clone(Buffer const &) */
485 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
487 void CutIntoMinibuffer(BufferParams const &, size_type pos);
489 bool InsertFromMinibuffer(size_type pos);
492 bool IsHfill(size_type pos) const;
494 bool IsInset(size_type pos) const;
497 bool IsFloat(size_type pos) const;
500 bool IsNewline(size_type pos) const;
502 bool IsSeparator(size_type pos) const;
504 bool IsLineSeparator(size_type pos) const;
506 bool IsKomma(size_type pos) const;
507 /// Used by the spellchecker
508 bool IsLetter(size_type pos) const;
510 bool IsWord(size_type pos) const;
512 /** This one resets all layout and dtp switches but not the font
513 of the single characters
517 /** paste this paragraph with the next one
518 be carefull, this doesent make any check at all
520 void PasteParagraph(BufferParams const &);
522 /// used to remove the error messages
523 int AutoDeleteInsets();
525 /// returns -1 if inset not found
526 int GetPositionOfInset(Inset * inset) const;
529 /// ok and now some footnote functions
530 void OpenFootnotes();
533 void CloseFootnotes();
535 LyXParagraph * FirstSelfrowPar();
539 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
542 /** A paragraph following a footnote is a "dummy". A paragraph
543 with a footnote in it is stored as three paragraphs:
544 First a paragraph with the text up to the footnote, then
545 one (or more) paragraphs with the footnote, and finally
546 the a paragraph with the text after the footnote. Only the
547 first paragraph keeps information about layoutparameters, */
548 bool IsDummy() const;
550 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
551 I have to set it on each of it's elements */
553 void SetPExtraType(BufferParams const &, int type,
554 string const & width, string const & widthp);
556 void UnsetPExtraType(BufferParams const &);
558 bool linuxDocConvertChar(char c, string & sgml_string);
567 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
570 friend struct matchIT;
573 /// used by lower_bound and upper_bound
575 int operator()(LyXParagraph::InsetTable const & a,
576 LyXParagraph::InsetTable const & b) const {
577 return a.pos < b.pos;
580 /** A font entry covers a range of positions. Notice that the
581 entries in the list are inserted in random order.
582 I don't think it's worth the effort to implement a more effective
583 datastructure, because the number of different fonts in a paragraph
585 Nevertheless, I decided to store fontlist using a sorted vector:
586 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
587 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
588 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
589 (font_1 covers the chars 0,...,pos_1) (Dekel)
592 /// End position of paragraph this font attribute covers
594 /** Font. Interpretation of the font values:
595 If a value is LyXFont::INHERIT_*, it means that the font
596 attribute is inherited from either the layout of this
597 paragraph or, in the case of nested paragraphs, from the
598 layout in the environment one level up until completely
600 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
601 allowed in these font tables.
605 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
608 friend struct matchFT;
611 /// used by lower_bound and upper_bound
613 int operator()(LyXParagraph::FontTable const & a,
614 LyXParagraph::FontTable const & b) const {
615 return a.pos < b.pos;
620 typedef std::vector<FontTable> FontList;
624 typedef std::vector<InsetTable> InsetList;
628 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
629 std::ostream &, TexRow & texrow
631 ,std::ostream & foot, TexRow & foot_texrow,
637 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
638 std::ostream &, TexRow & texrow,
639 std::ostream & foot, TexRow & foot_texrow,
644 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
646 int & column, LyXFont const & font,
647 LyXLayout const & style);
649 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
650 std::ostream &, TexRow & texrow,
652 LyXFont & font, LyXFont & running_font,
653 LyXFont & basefont, bool & open_font,
654 LyXLayout const & style,
656 int & column, value_type const c);
660 static unsigned int paragraph_id;
663 class inset_iterator {
668 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
670 inset_iterator & operator++() {
675 Inset * operator*() { return (*it).inset; }
677 size_type getPos() const {return (*it).pos; }
679 bool operator==(inset_iterator const & iter) const {
680 return it == iter.it;
683 bool operator!=(inset_iterator const & iter) const {
684 return it != iter.it;
688 InsetList::iterator it;
691 inset_iterator inset_iterator_begin() {
692 return inset_iterator(insetlist.begin());
695 inset_iterator inset_iterator_end() {
696 return inset_iterator(insetlist.end());
699 inset_iterator InsetIterator(size_type pos);