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
23 #include <boost/array.hpp>
25 #include "insets/lyxinset.h"
26 #include "ParagraphParameters.h"
27 #include "support/LAssert.h"
37 // I dare you to enable this and help me find all the bugs that then show
42 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
45 #ifndef NO_PEXTRA_REALLY
58 enum MINIPAGE_ALIGNMENT {
62 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 /* This should be TextContainer::size_type, but we need
133 signed values for now.
135 typedef TextContainer::difference_type size_type;
139 /// this constructor inserts the new paragraph in a list
141 LyXParagraph(LyXParagraph * par);
142 /// the destructor removes the new paragraph from the list
146 Language const * getParLanguage(BufferParams const &) const;
148 bool isRightToLeftPar(BufferParams const &) const;
150 void ChangeLanguage(BufferParams const & bparams,
151 Language const * from, Language const * to);
153 bool isMultiLingual(BufferParams const &);
156 string const String(Buffer const *, bool label);
158 string const String(Buffer const *, size_type beg, size_type end);
161 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
164 void validate(LaTeXFeatures &) const;
174 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
175 std::ostream &, TexRow & texrow,
179 std::ostream & foot, TexRow & foot_texrow,
184 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
185 std::ostream &, TexRow & texrow, bool moving_arg);
188 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
189 std::ostream &, TexRow & texrow
191 ,std::ostream & foot, TexRow & foot_texrow,
196 LyXParagraph * Clone() const;
199 bool HasSameLayout(LyXParagraph const * par) const;
202 void MakeSameLayout(LyXParagraph const * par);
204 /// Is it the first par with same depth and layout?
205 bool IsFirstInSequence() const;
207 /** Check if the current paragraph is the last paragraph in a
209 int GetEndLabel(BufferParams const &) const;
213 void SetInsetOwner(Inset * i);
215 void deleteInsetsLyXText(BufferView *);
217 void resizeInsetsLyXText(BufferView *);
227 size_type size() const;
231 void setContentsFromPar(LyXParagraph * par);
233 void clearContents();
235 ParagraphParameters params;
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;
255 boost::array<int, 10> counter_;
258 void setCounter(int i, int v);
260 int getCounter(int i) const;
262 void incCounter(int i);
273 LyXParagraph * next_;
275 LyXParagraph * previous_;
278 InsetBibKey * bibkey; // ale970302
281 void next(LyXParagraph *);
282 /** these function are able to hide closed footnotes
284 LyXParagraph * next();
286 LyXParagraph const * next() const;
289 void previous(LyXParagraph *);
291 LyXParagraph * previous();
293 LyXParagraph const * previous() const;
296 /** these function are able to hide open and closed footnotes
298 LyXParagraph * NextAfterFootnote();
300 LyXParagraph const * NextAfterFootnote() const;
303 LyXParagraph * PreviousBeforeFootnote();
305 LyXParagraph * LastPhysicalPar();
307 LyXParagraph const * LastPhysicalPar() const;
310 LyXParagraph * FirstPhysicalPar();
312 LyXParagraph const * FirstPhysicalPar() const;
313 /// returns the physical paragraph
314 LyXParagraph * ParFromPos(size_type pos);
315 /// returns the position in the physical par
316 int PositionInParFromPos(size_type pos) const;
319 /// for the environments
320 LyXParagraph * DepthHook(int depth);
321 /// for the environments
322 LyXParagraph const * DepthHook(int depth) const;
324 int BeginningOfMainBody() const;
326 string const & GetLabelstring() const;
328 /// the next two functions are for the manual labels
329 string const GetLabelWidthString() const;
331 void SetLabelWidthString(string const & s);
334 LyXTextClass::LayoutList::size_type GetLayout() const;
336 char GetAlign() const;
338 char GetDepth() const;
341 void SetLayout(BufferParams const &,
342 LyXTextClass::LayoutList::size_type new_layout);
344 void SetOnlyLayout(BufferParams const &,
345 LyXTextClass::LayoutList::size_type new_layout);
347 size_type Last() const;
350 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
352 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
355 int GetFirstCounter(int i) const;
357 void Erase(size_type pos);
358 /** the flag determines wether the layout should be copied
360 void BreakParagraph(BufferParams const &, size_type pos, int flag);
362 void BreakParagraphConservative(BufferParams const &, size_type pos);
363 /** Get unistantiated font setting. Returns the difference
364 between the characters font and the layoutfont.
365 This is what is stored in the fonttable
368 GetFontSettings(BufferParams const &, size_type pos) const;
370 LyXFont const GetFirstFontSettings() const;
372 /** Get fully instantiated font. If pos == -1, use the layout
373 font attached to this paragraph.
374 If pos == -2, use the label font of the layout attached here.
375 In all cases, the font is instantiated, i.e. does not have any
376 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
379 LyXFont const getFont(BufferParams const &, size_type pos) const;
381 value_type GetChar(size_type pos) const;
383 value_type GetUChar(BufferParams const &, size_type pos) const;
384 /// The position must already exist.
385 void SetChar(size_type pos, value_type c);
387 void SetFont(size_type pos, LyXFont const & font);
389 string const GetWord(size_type &) const;
390 /// Returns the height of the highest font in range
391 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
392 size_type endpos) const;
394 void InsertChar(size_type pos, value_type c);
396 void InsertChar(size_type pos, value_type c, LyXFont const &);
398 void InsertInset(size_type pos, Inset * inset);
400 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
402 bool InsertInsetAllowed(Inset * inset);
404 Inset * GetInset(size_type pos);
406 Inset const * GetInset(size_type pos) const;
409 void OpenFootnote(size_type pos);
411 void CloseFootnote(size_type pos);
413 /** important for cut and paste
414 Temporary change from BufferParams to Buffer. Will revert when we
415 get rid of the argument to Inset::Clone(Buffer const &) */
416 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
418 void CutIntoMinibuffer(BufferParams const &, size_type pos);
420 bool InsertFromMinibuffer(size_type pos);
423 bool IsHfill(size_type pos) const;
425 bool IsInset(size_type pos) const;
428 bool IsFloat(size_type pos) const;
431 bool IsNewline(size_type pos) const;
433 bool IsSeparator(size_type pos) const;
435 bool IsLineSeparator(size_type pos) const;
437 bool IsKomma(size_type pos) const;
438 /// Used by the spellchecker
439 bool IsLetter(size_type pos) const;
441 bool IsWord(size_type pos) const;
443 /** This one resets all layout and dtp switches but not the font
444 of the single characters
448 /** paste this paragraph with the next one
449 be carefull, this doesent make any check at all
451 void PasteParagraph(BufferParams const &);
453 /// used to remove the error messages
454 int AutoDeleteInsets();
456 /// returns -1 if inset not found
457 int GetPositionOfInset(Inset * inset) const;
460 /// ok and now some footnote functions
461 void OpenFootnotes();
464 void CloseFootnotes();
466 LyXParagraph * FirstSelfrowPar();
470 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
473 /** A paragraph following a footnote is a "dummy". A paragraph
474 with a footnote in it is stored as three paragraphs:
475 First a paragraph with the text up to the footnote, then
476 one (or more) paragraphs with the footnote, and finally
477 the a paragraph with the text after the footnote. Only the
478 first paragraph keeps information about layoutparameters, */
479 bool IsDummy() const;
481 #ifndef NO_PEXTRA_REALLY
482 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
483 I have to set it on each of it's elements */
485 void SetPExtraType(BufferParams const &, int type,
486 string const & width, string const & widthp);
488 void UnsetPExtraType(BufferParams const &);
491 bool linuxDocConvertChar(char c, string & sgml_string);
500 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
503 friend struct matchIT;
506 /// used by lower_bound and upper_bound
508 int operator()(LyXParagraph::InsetTable const & a,
509 LyXParagraph::InsetTable const & b) const {
510 return a.pos < b.pos;
513 /** A font entry covers a range of positions. Notice that the
514 entries in the list are inserted in random order.
515 I don't think it's worth the effort to implement a more effective
516 datastructure, because the number of different fonts in a paragraph
518 Nevertheless, I decided to store fontlist using a sorted vector:
519 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
520 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
521 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
522 (font_1 covers the chars 0,...,pos_1) (Dekel)
526 FontTable(size_type p, LyXFont const & f)
529 font_ = container.get(f);
532 size_type pos() const { return pos_; }
534 void pos(size_type p) { pos_ = p; }
536 LyXFont const & font() const { return *font_; }
538 void font(LyXFont const & f) { font_ = container.get(f);}
540 /// End position of paragraph this font attribute covers
542 /** Font. Interpretation of the font values:
543 If a value is LyXFont::INHERIT_*, it means that the font
544 attribute is inherited from either the layout of this
545 paragraph or, in the case of nested paragraphs, from the
546 layout in the environment one level up until completely
548 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
549 allowed in these font tables.
551 boost::shared_ptr<LyXFont> font_;
553 static ShareContainer<LyXFont> container;
556 friend struct matchFT;
559 /// used by lower_bound and upper_bound
561 int operator()(LyXParagraph::FontTable const & a,
562 LyXParagraph::FontTable const & b) const {
563 return a.pos() < b.pos();
568 typedef std::vector<FontTable> FontList;
572 typedef std::vector<InsetTable> InsetList;
576 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
577 std::ostream &, TexRow & texrow
579 ,std::ostream & foot, TexRow & foot_texrow,
585 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
586 std::ostream &, TexRow & texrow,
587 std::ostream & foot, TexRow & foot_texrow,
592 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
594 int & column, LyXFont const & font,
595 LyXLayout const & style);
597 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
598 std::ostream &, TexRow & texrow,
600 LyXFont & font, LyXFont & running_font,
601 LyXFont & basefont, bool & open_font,
602 LyXLayout const & style,
604 int & column, value_type const c);
608 static unsigned int paragraph_id;
611 class inset_iterator {
616 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
618 inset_iterator & operator++() {
623 Inset * operator*() { return (*it).inset; }
625 size_type getPos() const {return (*it).pos; }
627 bool operator==(inset_iterator const & iter) const {
628 return it == iter.it;
631 bool operator!=(inset_iterator const & iter) const {
632 return it != iter.it;
636 InsetList::iterator it;
639 inset_iterator inset_iterator_begin();
641 inset_iterator inset_iterator_end();
643 inset_iterator InsetIterator(size_type pos);
649 LyXParagraph::value_type
650 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
652 Assert(pos <= size());
653 // This is stronger, and I belive that this is the assertion
654 // that we should really use. (Lgb)
655 //Assert(pos < size());
657 // Then this has no meaning. (Lgb)
658 if (!size() || pos == size()) return '\0';
665 int LyXParagraph::id() const
672 void LyXParagraph::id(int id_arg)
679 bool LyXParagraph::IsFirstInSequence() const
681 LyXParagraph const * dhook = DepthHook(GetDepth());
682 return (dhook == this
683 || dhook->GetLayout() != GetLayout()
684 || dhook->GetDepth() != GetDepth());
689 Inset * LyXParagraph::InInset()
696 LyXParagraph::size_type LyXParagraph::size() const
703 void LyXParagraph::clearContents()
710 void LyXParagraph::setCounter(int i, int v)
717 int LyXParagraph::getCounter(int i) const
724 void LyXParagraph::incCounter(int i)
731 void LyXParagraph::SetChar(size_type pos, value_type c)
738 LyXTextClass::size_type LyXParagraph::GetLayout() const
741 return FirstPhysicalPar()->layout;
749 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
751 return inset_iterator(insetlist.begin());
756 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
758 return inset_iterator(insetlist.end());