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"
27 #include "ParagraphParameters.h"
36 // I dare you to enable this and help me find all the bugs that then show
41 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
44 #ifndef NO_PEXTRA_REALLY
57 enum MINIPAGE_ALIGNMENT {
61 MINIPAGE_ALIGN_MIDDLE,
92 //META_PROTECTED_SEPARATOR,
108 /// The footnotekinds
119 ALGORITHM, // Bernhard, 970807
121 WIDE_FIG, // CFO-G, 971106
123 WIDE_TAB // CFO-G, 971106
127 typedef char value_type;
129 typedef std::vector<value_type> TextContainer;
131 /* This should be TextContainer::size_type, but we need
132 signed values for now.
134 typedef TextContainer::difference_type size_type;
138 /// this constructor inserts the new paragraph in a list
140 LyXParagraph(LyXParagraph * par);
141 /// the destructor removes the new paragraph from the list
145 Language const * getParLanguage(BufferParams const &) const;
147 bool isRightToLeftPar(BufferParams const &) const;
149 void ChangeLanguage(BufferParams const & bparams,
150 Language const * from, Language const * to);
152 bool isMultiLingual(BufferParams const &);
155 string const String(Buffer const *, bool label);
157 string const String(Buffer const *, size_type beg, size_type end);
160 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
163 void validate(LaTeXFeatures &) const;
173 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
174 std::ostream &, TexRow & texrow,
178 std::ostream & foot, TexRow & foot_texrow,
183 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
184 std::ostream &, TexRow & texrow, bool moving_arg);
187 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
188 std::ostream &, TexRow & texrow
190 ,std::ostream & foot, TexRow & foot_texrow,
195 LyXParagraph * Clone() const;
198 bool HasSameLayout(LyXParagraph const * par) const;
201 void MakeSameLayout(LyXParagraph const * par);
203 /// Is it the first par with same depth and layout?
204 bool IsFirstInSequence() const;
206 /** Check if the current paragraph is the last paragraph in a
208 int GetEndLabel(BufferParams const &) const;
212 void SetInsetOwner(Inset * i);
214 void deleteInsetsLyXText(BufferView *);
216 void resizeInsetsLyXText(BufferView *);
225 size_type size() const;
229 void setContentsFromPar(LyXParagraph * par);
231 void clearContents();
233 ParagraphParameters params;
236 LyXTextClass::LayoutList::size_type layout;
240 \item no footnote, closed footnote,
241 \item open footnote, where footnote
242 \item means footnote-environment
245 footnote_flag footnoteflag;
247 /// footnote, margin, fig, tab
248 footnote_kind footnotekind;
253 array<int, 10> counter_;
256 void setCounter(int i, int v);
258 int getCounter(int i) const;
260 void incCounter(int i);
271 LyXParagraph * next_;
273 LyXParagraph * previous_;
276 InsetBibKey * bibkey; // ale970302
279 void next(LyXParagraph *);
280 /** these function are able to hide closed footnotes
282 LyXParagraph * next();
284 LyXParagraph const * next() const;
287 void previous(LyXParagraph *);
289 LyXParagraph * previous();
291 LyXParagraph const * previous() const;
294 /** these function are able to hide open and closed footnotes
296 LyXParagraph * NextAfterFootnote();
298 LyXParagraph const * NextAfterFootnote() const;
301 LyXParagraph * PreviousBeforeFootnote();
303 LyXParagraph * LastPhysicalPar();
305 LyXParagraph const * LastPhysicalPar() const;
308 LyXParagraph * FirstPhysicalPar();
310 LyXParagraph const * FirstPhysicalPar() const;
311 /// returns the physical paragraph
312 LyXParagraph * ParFromPos(size_type pos);
313 /// returns the position in the physical par
314 int PositionInParFromPos(size_type pos) const;
317 /// for the environments
318 LyXParagraph * DepthHook(int depth);
319 /// for the environments
320 LyXParagraph const * DepthHook(int depth) const;
322 int BeginningOfMainBody() const;
324 string const & GetLabelstring() const;
326 /// the next two functions are for the manual labels
327 string const GetLabelWidthString() const;
329 void SetLabelWidthString(string const & s);
331 LyXTextClass::LayoutList::size_type GetLayout() const;
333 char GetAlign() const;
335 char GetDepth() const;
337 void SetLayout(BufferParams const &,
338 LyXTextClass::LayoutList::size_type new_layout);
340 void SetOnlyLayout(BufferParams const &,
341 LyXTextClass::LayoutList::size_type new_layout);
343 int GetFirstCounter(int i) const;
346 size_type Last() const;
349 void Erase(size_type pos);
350 /** the flag determines wether the layout should be copied
352 void BreakParagraph(BufferParams const &, size_type pos, int flag);
354 void BreakParagraphConservative(BufferParams const &, size_type pos);
355 /** Get unistantiated font setting. Returns the difference
356 between the characters font and the layoutfont.
357 This is what is stored in the fonttable
360 GetFontSettings(BufferParams const &, size_type pos) const;
362 LyXFont const GetFirstFontSettings() const;
364 /** Get fully instantiated font. If pos == -1, use the layout
365 font attached to this paragraph.
366 If pos == -2, use the label font of the layout attached here.
367 In all cases, the font is instantiated, i.e. does not have any
368 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
371 LyXFont const getFont(BufferParams const &, size_type pos) const;
373 value_type GetChar(size_type pos) const;
375 value_type GetUChar(BufferParams const &, size_type pos) const;
376 /// The position must already exist.
377 void SetChar(size_type pos, value_type c);
379 void SetFont(size_type pos, LyXFont const & font);
381 string const GetWord(size_type &) const;
382 /// Returns the height of the highest font in range
383 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
384 size_type endpos) const;
386 void InsertChar(size_type pos, value_type c);
388 void InsertChar(size_type pos, value_type c, LyXFont const &);
390 void InsertInset(size_type pos, Inset * inset);
392 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
394 bool InsertInsetAllowed(Inset * inset);
396 Inset * GetInset(size_type pos);
398 Inset const * GetInset(size_type pos) const;
401 void OpenFootnote(size_type pos);
403 void CloseFootnote(size_type pos);
405 /** important for cut and paste
406 Temporary change from BufferParams to Buffer. Will revert when we
407 get rid of the argument to Inset::Clone(Buffer const &) */
408 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
410 void CutIntoMinibuffer(BufferParams const &, size_type pos);
412 bool InsertFromMinibuffer(size_type pos);
415 bool IsHfill(size_type pos) const;
417 bool IsInset(size_type pos) const;
420 bool IsFloat(size_type pos) const;
423 bool IsNewline(size_type pos) const;
425 bool IsSeparator(size_type pos) const;
427 bool IsLineSeparator(size_type pos) const;
429 bool IsKomma(size_type pos) const;
430 /// Used by the spellchecker
431 bool IsLetter(size_type pos) const;
433 bool IsWord(size_type pos) const;
435 /** This one resets all layout and dtp switches but not the font
436 of the single characters
440 /** paste this paragraph with the next one
441 be carefull, this doesent make any check at all
443 void PasteParagraph(BufferParams const &);
445 /// used to remove the error messages
446 int AutoDeleteInsets();
448 /// returns -1 if inset not found
449 int GetPositionOfInset(Inset * inset) const;
452 /// ok and now some footnote functions
453 void OpenFootnotes();
456 void CloseFootnotes();
458 LyXParagraph * FirstSelfrowPar();
462 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
465 /** A paragraph following a footnote is a "dummy". A paragraph
466 with a footnote in it is stored as three paragraphs:
467 First a paragraph with the text up to the footnote, then
468 one (or more) paragraphs with the footnote, and finally
469 the a paragraph with the text after the footnote. Only the
470 first paragraph keeps information about layoutparameters, */
471 bool IsDummy() const;
473 #ifndef NO_PEXTRA_REALLY
474 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
475 I have to set it on each of it's elements */
477 void SetPExtraType(BufferParams const &, int type,
478 string const & width, string const & widthp);
480 void UnsetPExtraType(BufferParams const &);
483 bool linuxDocConvertChar(char c, string & sgml_string);
492 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
495 friend struct matchIT;
498 /// used by lower_bound and upper_bound
500 int operator()(LyXParagraph::InsetTable const & a,
501 LyXParagraph::InsetTable const & b) const {
502 return a.pos < b.pos;
505 /** A font entry covers a range of positions. Notice that the
506 entries in the list are inserted in random order.
507 I don't think it's worth the effort to implement a more effective
508 datastructure, because the number of different fonts in a paragraph
510 Nevertheless, I decided to store fontlist using a sorted vector:
511 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
512 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
513 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
514 (font_1 covers the chars 0,...,pos_1) (Dekel)
518 FontTable(size_type p, LyXFont const & f)
521 font_ = container.get(f);
524 size_type pos() const { return pos_; }
526 void pos(size_type p) { pos_ = p; }
528 LyXFont const & font() const { return *font_; }
530 void font(LyXFont const & f) { font_ = container.get(f);}
532 /// End position of paragraph this font attribute covers
534 /** Font. Interpretation of the font values:
535 If a value is LyXFont::INHERIT_*, it means that the font
536 attribute is inherited from either the layout of this
537 paragraph or, in the case of nested paragraphs, from the
538 layout in the environment one level up until completely
540 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
541 allowed in these font tables.
543 boost::shared_ptr<LyXFont> font_;
545 static ShareContainer<LyXFont> container;
548 friend struct matchFT;
551 /// used by lower_bound and upper_bound
553 int operator()(LyXParagraph::FontTable const & a,
554 LyXParagraph::FontTable const & b) const {
555 return a.pos() < b.pos();
560 typedef std::vector<FontTable> FontList;
564 typedef std::vector<InsetTable> InsetList;
568 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
569 std::ostream &, TexRow & texrow
571 ,std::ostream & foot, TexRow & foot_texrow,
577 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
578 std::ostream &, TexRow & texrow,
579 std::ostream & foot, TexRow & foot_texrow,
584 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
586 int & column, LyXFont const & font,
587 LyXLayout const & style);
589 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
590 std::ostream &, TexRow & texrow,
592 LyXFont & font, LyXFont & running_font,
593 LyXFont & basefont, bool & open_font,
594 LyXLayout const & style,
596 int & column, value_type const c);
600 static unsigned int paragraph_id;
603 class inset_iterator {
608 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
610 inset_iterator & operator++() {
615 Inset * operator*() { return (*it).inset; }
617 size_type getPos() const {return (*it).pos; }
619 bool operator==(inset_iterator const & iter) const {
620 return it == iter.it;
623 bool operator!=(inset_iterator const & iter) const {
624 return it != iter.it;
628 InsetList::iterator it;
631 inset_iterator inset_iterator_begin();
633 inset_iterator inset_iterator_end();
635 inset_iterator InsetIterator(size_type pos);
640 int LyXParagraph::id() const
647 void LyXParagraph::id(int id_arg)
654 bool LyXParagraph::IsFirstInSequence() const
656 LyXParagraph const * dhook = DepthHook(GetDepth());
657 return (dhook == this
658 || dhook->GetLayout() != GetLayout()
659 || dhook->GetDepth() != GetDepth());
664 Inset * LyXParagraph::InInset()
671 LyXParagraph::size_type LyXParagraph::size() const
678 void LyXParagraph::clearContents()
685 void LyXParagraph::setCounter(int i, int v)
692 int LyXParagraph::getCounter(int i) const
699 void LyXParagraph::incCounter(int i)
706 void LyXParagraph::SetChar(size_type pos, value_type c)
713 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
715 return inset_iterator(insetlist.begin());
720 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
722 return inset_iterator(insetlist.end());