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 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
483 void CutIntoMinibuffer(BufferParams const &, size_type pos);
485 bool InsertFromMinibuffer(size_type pos);
488 bool IsHfill(size_type pos) const;
490 bool IsInset(size_type pos) const;
493 bool IsFloat(size_type pos) const;
496 bool IsNewline(size_type pos) const;
498 bool IsSeparator(size_type pos) const;
500 bool IsLineSeparator(size_type pos) const;
502 bool IsKomma(size_type pos) const;
503 /// Used by the spellchecker
504 bool IsLetter(size_type pos) const;
506 bool IsWord(size_type pos) const;
508 /** This one resets all layout and dtp switches but not the font
509 of the single characters
513 /** paste this paragraph with the next one
514 be carefull, this doesent make any check at all
516 void PasteParagraph(BufferParams const &);
518 /// used to remove the error messages
519 int AutoDeleteInsets();
521 /// returns -1 if inset not found
522 int GetPositionOfInset(Inset * inset) const;
525 /// ok and now some footnote functions
526 void OpenFootnotes();
529 void CloseFootnotes();
531 LyXParagraph * FirstSelfrowPar();
535 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
538 /** A paragraph following a footnote is a "dummy". A paragraph
539 with a footnote in it is stored as three paragraphs:
540 First a paragraph with the text up to the footnote, then
541 one (or more) paragraphs with the footnote, and finally
542 the a paragraph with the text after the footnote. Only the
543 first paragraph keeps information about layoutparameters, */
544 bool IsDummy() const;
546 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
547 I have to set it on each of it's elements */
549 void SetPExtraType(BufferParams const &, int type,
550 string const & width, string const & widthp);
552 void UnsetPExtraType(BufferParams const &);
554 bool linuxDocConvertChar(char c, string & sgml_string);
563 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
566 friend struct matchIT;
569 /// used by lower_bound and upper_bound
571 int operator()(LyXParagraph::InsetTable const & a,
572 LyXParagraph::InsetTable const & b) const {
573 return a.pos < b.pos;
576 /** A font entry covers a range of positions. Notice that the
577 entries in the list are inserted in random order.
578 I don't think it's worth the effort to implement a more effective
579 datastructure, because the number of different fonts in a paragraph
581 Nevertheless, I decided to store fontlist using a sorted vector:
582 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
583 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
584 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
585 (font_1 covers the chars 0,...,pos_1) (Dekel)
588 /// End position of paragraph this font attribute covers
590 /** Font. Interpretation of the font values:
591 If a value is LyXFont::INHERIT_*, it means that the font
592 attribute is inherited from either the layout of this
593 paragraph or, in the case of nested paragraphs, from the
594 layout in the environment one level up until completely
596 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
597 allowed in these font tables.
601 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
604 friend struct matchFT;
607 /// used by lower_bound and upper_bound
609 int operator()(LyXParagraph::FontTable const & a,
610 LyXParagraph::FontTable const & b) const {
611 return a.pos < b.pos;
616 typedef std::vector<FontTable> FontList;
620 typedef std::vector<InsetTable> InsetList;
624 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
625 std::ostream &, TexRow & texrow
627 ,std::ostream & foot, TexRow & foot_texrow,
633 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
634 std::ostream &, TexRow & texrow,
635 std::ostream & foot, TexRow & foot_texrow,
640 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
642 int & column, LyXFont const & font,
643 LyXLayout const & style);
645 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
646 std::ostream &, TexRow & texrow,
648 LyXFont & font, LyXFont & running_font,
649 LyXFont & basefont, bool & open_font,
650 LyXLayout const & style,
652 int & column, value_type const c);
656 static unsigned int paragraph_id;
659 class inset_iterator {
664 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
666 inset_iterator & operator++() {
671 Inset * operator*() { return (*it).inset; }
673 size_type getPos() const {return (*it).pos; }
675 bool operator==(inset_iterator const & iter) const {
676 return it == iter.it;
679 bool operator!=(inset_iterator const & iter) const {
680 return it != iter.it;
684 InsetList::iterator it;
687 inset_iterator inset_iterator_begin() {
688 return inset_iterator(insetlist.begin());
691 inset_iterator inset_iterator_end() {
692 return inset_iterator(insetlist.end());
695 inset_iterator InsetIterator(size_type pos);