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;
444 /// The position must already exist.
445 void SetChar(size_type pos, value_type c) {
449 text.replace(pos, c);
454 void SetFont(size_type pos, LyXFont const & font);
456 string const GetWord(size_type &) const;
457 /// Returns the height of the highest font in range
458 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
459 size_type endpos) const;
461 void InsertChar(size_type pos, value_type c);
463 void InsertChar(size_type pos, value_type c, LyXFont const &);
465 void InsertInset(size_type pos, Inset * inset);
467 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
469 bool InsertInsetAllowed(Inset * inset);
471 Inset * GetInset(size_type pos);
473 Inset const * GetInset(size_type pos) const;
476 void OpenFootnote(size_type pos);
478 void CloseFootnote(size_type pos);
480 /** important for cut and paste
481 Temporary change from BufferParams to Buffer. Will revert when we
482 get rid of the argument to Inset::Clone(Buffer const &) */
483 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
485 void CutIntoMinibuffer(BufferParams const &, size_type pos);
487 bool InsertFromMinibuffer(size_type pos);
490 bool IsHfill(size_type pos) const;
492 bool IsInset(size_type pos) const;
495 bool IsFloat(size_type pos) const;
498 bool IsNewline(size_type pos) const;
500 bool IsSeparator(size_type pos) const;
502 bool IsLineSeparator(size_type pos) const;
504 bool IsKomma(size_type pos) const;
505 /// Used by the spellchecker
506 bool IsLetter(size_type pos) const;
508 bool IsWord(size_type pos) const;
510 /** This one resets all layout and dtp switches but not the font
511 of the single characters
515 /** paste this paragraph with the next one
516 be carefull, this doesent make any check at all
518 void PasteParagraph(BufferParams const &);
520 /// used to remove the error messages
521 int AutoDeleteInsets();
523 /// returns -1 if inset not found
524 int GetPositionOfInset(Inset * inset) const;
527 /// ok and now some footnote functions
528 void OpenFootnotes();
531 void CloseFootnotes();
533 LyXParagraph * FirstSelfrowPar();
537 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
540 /** A paragraph following a footnote is a "dummy". A paragraph
541 with a footnote in it is stored as three paragraphs:
542 First a paragraph with the text up to the footnote, then
543 one (or more) paragraphs with the footnote, and finally
544 the a paragraph with the text after the footnote. Only the
545 first paragraph keeps information about layoutparameters, */
546 bool IsDummy() const;
548 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
549 I have to set it on each of it's elements */
551 void SetPExtraType(BufferParams const &, int type,
552 string const & width, string const & widthp);
554 void UnsetPExtraType(BufferParams const &);
556 bool linuxDocConvertChar(char c, string & sgml_string);
565 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
568 friend struct matchIT;
571 /// used by lower_bound and upper_bound
573 int operator()(LyXParagraph::InsetTable const & a,
574 LyXParagraph::InsetTable const & b) const {
575 return a.pos < b.pos;
578 /** A font entry covers a range of positions. Notice that the
579 entries in the list are inserted in random order.
580 I don't think it's worth the effort to implement a more effective
581 datastructure, because the number of different fonts in a paragraph
583 Nevertheless, I decided to store fontlist using a sorted vector:
584 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
585 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
586 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
587 (font_1 covers the chars 0,...,pos_1) (Dekel)
590 /// End position of paragraph this font attribute covers
592 /** Font. Interpretation of the font values:
593 If a value is LyXFont::INHERIT_*, it means that the font
594 attribute is inherited from either the layout of this
595 paragraph or, in the case of nested paragraphs, from the
596 layout in the environment one level up until completely
598 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
599 allowed in these font tables.
603 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
606 friend struct matchFT;
609 /// used by lower_bound and upper_bound
611 int operator()(LyXParagraph::FontTable const & a,
612 LyXParagraph::FontTable const & b) const {
613 return a.pos < b.pos;
618 typedef std::vector<FontTable> FontList;
622 typedef std::vector<InsetTable> InsetList;
626 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
627 std::ostream &, TexRow & texrow
629 ,std::ostream & foot, TexRow & foot_texrow,
635 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
636 std::ostream &, TexRow & texrow,
637 std::ostream & foot, TexRow & foot_texrow,
642 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
644 int & column, LyXFont const & font,
645 LyXLayout const & style);
647 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
648 std::ostream &, TexRow & texrow,
650 LyXFont & font, LyXFont & running_font,
651 LyXFont & basefont, bool & open_font,
652 LyXLayout const & style,
654 int & column, value_type const c);
658 static unsigned int paragraph_id;
661 class inset_iterator {
666 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
668 inset_iterator & operator++() {
673 Inset * operator*() { return (*it).inset; }
675 size_type getPos() const {return (*it).pos; }
677 bool operator==(inset_iterator const & iter) const {
678 return it == iter.it;
681 bool operator!=(inset_iterator const & iter) const {
682 return it != iter.it;
686 InsetList::iterator it;
689 inset_iterator inset_iterator_begin() {
690 return inset_iterator(insetlist.begin());
693 inset_iterator inset_iterator_end() {
694 return inset_iterator(insetlist.end());
697 inset_iterator InsetIterator(size_type pos);