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"
25 #include <boost/array.hpp>
35 // I dare you to enable this and help me find all the bugs that then show
37 //#define NEW_INSETS 1
39 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
54 enum MINIPAGE_ALIGNMENT {
58 MINIPAGE_ALIGN_MIDDLE,
88 //META_PROTECTED_SEPARATOR,
104 /// The footnotekinds
115 ALGORITHM, // Bernhard, 970807
117 WIDE_FIG, // CFO-G, 971106
119 WIDE_TAB // CFO-G, 971106
123 typedef char value_type;
125 typedef std::vector<value_type> TextContainer;
127 /* This should be TextContainer::size_type, but we need
128 signed values for now.
130 typedef TextContainer::difference_type size_type;
134 /// this constructor inserts the new paragraph in a list
136 LyXParagraph(LyXParagraph * par);
137 /// the destructor removes the new paragraph from the list
141 Language const * getParLanguage(BufferParams const &) const;
143 bool isRightToLeftPar(BufferParams const &) const;
145 void ChangeLanguage(BufferParams const & bparams,
146 Language const * from, Language const * to);
148 bool isMultiLingual(BufferParams const &);
151 string const String(Buffer const *, bool label);
153 string const String(Buffer const *, size_type beg, size_type end);
156 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
159 void validate(LaTeXFeatures &) const;
169 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
170 std::ostream &, TexRow & texrow,
174 std::ostream & foot, TexRow & foot_texrow,
179 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
180 std::ostream &, TexRow & texrow, bool moving_arg);
183 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
184 std::ostream &, TexRow & texrow
186 ,std::ostream & foot, TexRow & foot_texrow,
191 LyXParagraph * Clone() const;
194 bool HasSameLayout(LyXParagraph const * par) const;
197 void MakeSameLayout(LyXParagraph const * par);
199 /// Is it the first par with same depth and layout?
200 bool IsFirstInSequence() const;
202 /** Check if the current paragraph is the last paragraph in a
204 int GetEndLabel(BufferParams const &) const;
208 void SetInsetOwner(Inset * i);
210 void deleteInsetsLyXText(BufferView *);
212 void resizeInsetsLyXText(BufferView *);
221 size_type size() const;
225 void setContentsFromPar(LyXParagraph * par);
227 void clearContents();
229 VSpace added_space_top;
232 VSpace added_space_bottom;
238 LyXTextClass::LayoutList::size_type layout;
242 \item no footnote, closed footnote,
243 \item open footnote, where footnote
244 \item means footnote-environment
247 footnote_flag footnoteflag;
249 /// footnote, margin, fig, tab
250 footnote_kind footnotekind;
262 bool pagebreak_bottom;
275 array<int, 10> counter_;
278 void setCounter(int i, int v);
280 int getCounter(int i) const;
282 void incCounter(int i);
284 bool start_of_appendix;
295 /* This is for the paragraph extra stuff */
301 string pextra_widthp;
303 int pextra_alignment;
307 bool pextra_start_minipage;
313 string labelwidthstring;
318 LyXParagraph * previous;
321 InsetBibKey * bibkey; // ale970302
323 /** these function are able to hide closed footnotes
325 LyXParagraph * Next();
328 LyXParagraph * Previous();
330 LyXParagraph const * Previous() const;
333 /** these function are able to hide open and closed footnotes
335 LyXParagraph * NextAfterFootnote();
337 LyXParagraph const * NextAfterFootnote() const;
340 LyXParagraph * PreviousBeforeFootnote();
342 LyXParagraph * LastPhysicalPar();
344 LyXParagraph const * LastPhysicalPar() const;
347 LyXParagraph * FirstPhysicalPar();
349 LyXParagraph const * FirstPhysicalPar() const;
350 /// returns the physical paragraph
351 LyXParagraph * ParFromPos(size_type pos);
352 /// returns the position in the physical par
353 int PositionInParFromPos(size_type pos) const;
356 /// for the environments
357 LyXParagraph * DepthHook(int depth);
358 /// for the environments
359 LyXParagraph const * DepthHook(int depth) const;
361 int BeginningOfMainBody() const;
363 string const & GetLabelstring() const;
365 /// the next two functions are for the manual labels
366 string const GetLabelWidthString() const;
368 void SetLabelWidthString(string const & s);
370 LyXTextClass::LayoutList::size_type GetLayout() const;
372 char GetAlign() const;
374 char GetDepth() const;
376 void SetLayout(BufferParams const &,
377 LyXTextClass::LayoutList::size_type new_layout);
379 void SetOnlyLayout(BufferParams const &,
380 LyXTextClass::LayoutList::size_type new_layout);
382 int GetFirstCounter(int i) const;
384 size_type Last() const;
386 void Erase(size_type pos);
387 /** the flag determines wether the layout should be copied
389 void BreakParagraph(BufferParams const &, size_type pos, int flag);
391 void BreakParagraphConservative(BufferParams const &, size_type pos);
392 /** Get unistantiated font setting. Returns the difference
393 between the characters font and the layoutfont.
394 This is what is stored in the fonttable
397 GetFontSettings(BufferParams const &, size_type pos) const;
399 LyXFont const GetFirstFontSettings() const;
401 /** Get fully instantiated font. If pos == -1, use the layout
402 font attached to this paragraph.
403 If pos == -2, use the label font of the layout attached here.
404 In all cases, the font is instantiated, i.e. does not have any
405 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
408 LyXFont const getFont(BufferParams const &, size_type pos) const;
410 value_type GetChar(size_type pos) const;
412 value_type GetUChar(BufferParams const &, size_type pos) const;
413 /// The position must already exist.
414 void SetChar(size_type pos, value_type c);
416 void SetFont(size_type pos, LyXFont const & font);
418 string const GetWord(size_type &) const;
419 /// Returns the height of the highest font in range
420 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
421 size_type endpos) const;
423 void InsertChar(size_type pos, value_type c);
425 void InsertChar(size_type pos, value_type c, LyXFont const &);
427 void InsertInset(size_type pos, Inset * inset);
429 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
431 bool InsertInsetAllowed(Inset * inset);
433 Inset * GetInset(size_type pos);
435 Inset const * GetInset(size_type pos) const;
438 void OpenFootnote(size_type pos);
440 void CloseFootnote(size_type pos);
442 /** important for cut and paste
443 Temporary change from BufferParams to Buffer. Will revert when we
444 get rid of the argument to Inset::Clone(Buffer const &) */
445 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
447 void CutIntoMinibuffer(BufferParams const &, size_type pos);
449 bool InsertFromMinibuffer(size_type pos);
452 bool IsHfill(size_type pos) const;
454 bool IsInset(size_type pos) const;
457 bool IsFloat(size_type pos) const;
460 bool IsNewline(size_type pos) const;
462 bool IsSeparator(size_type pos) const;
464 bool IsLineSeparator(size_type pos) const;
466 bool IsKomma(size_type pos) const;
467 /// Used by the spellchecker
468 bool IsLetter(size_type pos) const;
470 bool IsWord(size_type pos) const;
472 /** This one resets all layout and dtp switches but not the font
473 of the single characters
477 /** paste this paragraph with the next one
478 be carefull, this doesent make any check at all
480 void PasteParagraph(BufferParams const &);
482 /// used to remove the error messages
483 int AutoDeleteInsets();
485 /// returns -1 if inset not found
486 int GetPositionOfInset(Inset * inset) const;
489 /// ok and now some footnote functions
490 void OpenFootnotes();
493 void CloseFootnotes();
495 LyXParagraph * FirstSelfrowPar();
499 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
502 /** A paragraph following a footnote is a "dummy". A paragraph
503 with a footnote in it is stored as three paragraphs:
504 First a paragraph with the text up to the footnote, then
505 one (or more) paragraphs with the footnote, and finally
506 the a paragraph with the text after the footnote. Only the
507 first paragraph keeps information about layoutparameters, */
508 bool IsDummy() const;
510 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
511 I have to set it on each of it's elements */
513 void SetPExtraType(BufferParams const &, int type,
514 string const & width, string const & widthp);
516 void UnsetPExtraType(BufferParams const &);
518 bool linuxDocConvertChar(char c, string & sgml_string);
527 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
530 friend struct matchIT;
533 /// used by lower_bound and upper_bound
535 int operator()(LyXParagraph::InsetTable const & a,
536 LyXParagraph::InsetTable const & b) const {
537 return a.pos < b.pos;
540 /** A font entry covers a range of positions. Notice that the
541 entries in the list are inserted in random order.
542 I don't think it's worth the effort to implement a more effective
543 datastructure, because the number of different fonts in a paragraph
545 Nevertheless, I decided to store fontlist using a sorted vector:
546 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
547 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
548 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
549 (font_1 covers the chars 0,...,pos_1) (Dekel)
552 /// End position of paragraph this font attribute covers
554 /** Font. Interpretation of the font values:
555 If a value is LyXFont::INHERIT_*, it means that the font
556 attribute is inherited from either the layout of this
557 paragraph or, in the case of nested paragraphs, from the
558 layout in the environment one level up until completely
560 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
561 allowed in these font tables.
565 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
568 friend struct matchFT;
571 /// used by lower_bound and upper_bound
573 int operator()(LyXParagraph::FontTable const & a,
574 LyXParagraph::FontTable const & b) const {
575 return a.pos < b.pos;
580 typedef std::vector<FontTable> FontList;
584 typedef std::vector<InsetTable> InsetList;
588 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
589 std::ostream &, TexRow & texrow
591 ,std::ostream & foot, TexRow & foot_texrow,
597 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
598 std::ostream &, TexRow & texrow,
599 std::ostream & foot, TexRow & foot_texrow,
604 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
606 int & column, LyXFont const & font,
607 LyXLayout const & style);
609 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
610 std::ostream &, TexRow & texrow,
612 LyXFont & font, LyXFont & running_font,
613 LyXFont & basefont, bool & open_font,
614 LyXLayout const & style,
616 int & column, value_type const c);
620 static unsigned int paragraph_id;
623 class inset_iterator {
628 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
630 inset_iterator & operator++() {
635 Inset * operator*() { return (*it).inset; }
637 size_type getPos() const {return (*it).pos; }
639 bool operator==(inset_iterator const & iter) const {
640 return it == iter.it;
643 bool operator!=(inset_iterator const & iter) const {
644 return it != iter.it;
648 InsetList::iterator it;
651 inset_iterator inset_iterator_begin();
653 inset_iterator inset_iterator_end();
655 inset_iterator InsetIterator(size_type pos);
660 int LyXParagraph::id() const
667 void LyXParagraph::id(int id_arg)
674 bool LyXParagraph::IsFirstInSequence() const
676 LyXParagraph const * dhook = DepthHook(GetDepth());
677 return (dhook == this
678 || dhook->GetLayout() != GetLayout()
679 || dhook->GetDepth() != GetDepth());
684 Inset * LyXParagraph::InInset()
691 LyXParagraph::size_type LyXParagraph::size() const
698 void LyXParagraph::clearContents()
705 void LyXParagraph::setCounter(int i, int v)
712 int LyXParagraph::getCounter(int i) const
719 void LyXParagraph::incCounter(int i)
726 void LyXParagraph::SetChar(size_type pos, value_type c)
733 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
735 return inset_iterator(insetlist.begin());
740 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
742 return inset_iterator(insetlist.end());