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;
338 void SetLayout(BufferParams const &,
339 LyXTextClass::LayoutList::size_type new_layout);
341 void SetOnlyLayout(BufferParams const &,
342 LyXTextClass::LayoutList::size_type new_layout);
344 size_type Last() const;
347 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
349 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
352 int GetFirstCounter(int i) const;
354 void Erase(size_type pos);
355 /** the flag determines wether the layout should be copied
357 void BreakParagraph(BufferParams const &, size_type pos, int flag);
359 void BreakParagraphConservative(BufferParams const &, size_type pos);
360 /** Get unistantiated font setting. Returns the difference
361 between the characters font and the layoutfont.
362 This is what is stored in the fonttable
365 GetFontSettings(BufferParams const &, size_type pos) const;
367 LyXFont const GetFirstFontSettings() const;
369 /** Get fully instantiated font. If pos == -1, use the layout
370 font attached to this paragraph.
371 If pos == -2, use the label font of the layout attached here.
372 In all cases, the font is instantiated, i.e. does not have any
373 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
376 LyXFont const getFont(BufferParams const &, size_type pos) const;
378 value_type GetChar(size_type pos) const;
380 value_type GetUChar(BufferParams const &, size_type pos) const;
381 /// The position must already exist.
382 void SetChar(size_type pos, value_type c);
384 void SetFont(size_type pos, LyXFont const & font);
386 string const GetWord(size_type &) const;
387 /// Returns the height of the highest font in range
388 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
389 size_type endpos) const;
391 void InsertChar(size_type pos, value_type c);
393 void InsertChar(size_type pos, value_type c, LyXFont const &);
395 void InsertInset(size_type pos, Inset * inset);
397 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
399 bool InsertInsetAllowed(Inset * inset);
401 Inset * GetInset(size_type pos);
403 Inset const * GetInset(size_type pos) const;
406 void OpenFootnote(size_type pos);
408 void CloseFootnote(size_type pos);
410 /** important for cut and paste
411 Temporary change from BufferParams to Buffer. Will revert when we
412 get rid of the argument to Inset::Clone(Buffer const &) */
413 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
415 void CutIntoMinibuffer(BufferParams const &, size_type pos);
417 bool InsertFromMinibuffer(size_type pos);
420 bool IsHfill(size_type pos) const;
422 bool IsInset(size_type pos) const;
425 bool IsFloat(size_type pos) const;
428 bool IsNewline(size_type pos) const;
430 bool IsSeparator(size_type pos) const;
432 bool IsLineSeparator(size_type pos) const;
434 bool IsKomma(size_type pos) const;
435 /// Used by the spellchecker
436 bool IsLetter(size_type pos) const;
438 bool IsWord(size_type pos) const;
440 /** This one resets all layout and dtp switches but not the font
441 of the single characters
445 /** paste this paragraph with the next one
446 be carefull, this doesent make any check at all
448 void PasteParagraph(BufferParams const &);
450 /// used to remove the error messages
451 int AutoDeleteInsets();
453 /// returns -1 if inset not found
454 int GetPositionOfInset(Inset * inset) const;
457 /// ok and now some footnote functions
458 void OpenFootnotes();
461 void CloseFootnotes();
463 LyXParagraph * FirstSelfrowPar();
467 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
470 /** A paragraph following a footnote is a "dummy". A paragraph
471 with a footnote in it is stored as three paragraphs:
472 First a paragraph with the text up to the footnote, then
473 one (or more) paragraphs with the footnote, and finally
474 the a paragraph with the text after the footnote. Only the
475 first paragraph keeps information about layoutparameters, */
476 bool IsDummy() const;
478 #ifndef NO_PEXTRA_REALLY
479 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
480 I have to set it on each of it's elements */
482 void SetPExtraType(BufferParams const &, int type,
483 string const & width, string const & widthp);
485 void UnsetPExtraType(BufferParams const &);
488 bool linuxDocConvertChar(char c, string & sgml_string);
497 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
500 friend struct matchIT;
503 /// used by lower_bound and upper_bound
505 int operator()(LyXParagraph::InsetTable const & a,
506 LyXParagraph::InsetTable const & b) const {
507 return a.pos < b.pos;
510 /** A font entry covers a range of positions. Notice that the
511 entries in the list are inserted in random order.
512 I don't think it's worth the effort to implement a more effective
513 datastructure, because the number of different fonts in a paragraph
515 Nevertheless, I decided to store fontlist using a sorted vector:
516 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
517 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
518 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
519 (font_1 covers the chars 0,...,pos_1) (Dekel)
523 FontTable(size_type p, LyXFont const & f)
526 font_ = container.get(f);
529 size_type pos() const { return pos_; }
531 void pos(size_type p) { pos_ = p; }
533 LyXFont const & font() const { return *font_; }
535 void font(LyXFont const & f) { font_ = container.get(f);}
537 /// End position of paragraph this font attribute covers
539 /** Font. Interpretation of the font values:
540 If a value is LyXFont::INHERIT_*, it means that the font
541 attribute is inherited from either the layout of this
542 paragraph or, in the case of nested paragraphs, from the
543 layout in the environment one level up until completely
545 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
546 allowed in these font tables.
548 boost::shared_ptr<LyXFont> font_;
550 static ShareContainer<LyXFont> container;
553 friend struct matchFT;
556 /// used by lower_bound and upper_bound
558 int operator()(LyXParagraph::FontTable const & a,
559 LyXParagraph::FontTable const & b) const {
560 return a.pos() < b.pos();
565 typedef std::vector<FontTable> FontList;
569 typedef std::vector<InsetTable> InsetList;
573 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
574 std::ostream &, TexRow & texrow
576 ,std::ostream & foot, TexRow & foot_texrow,
582 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
583 std::ostream &, TexRow & texrow,
584 std::ostream & foot, TexRow & foot_texrow,
589 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
591 int & column, LyXFont const & font,
592 LyXLayout const & style);
594 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
595 std::ostream &, TexRow & texrow,
597 LyXFont & font, LyXFont & running_font,
598 LyXFont & basefont, bool & open_font,
599 LyXLayout const & style,
601 int & column, value_type const c);
605 static unsigned int paragraph_id;
608 class inset_iterator {
613 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
615 inset_iterator & operator++() {
620 Inset * operator*() { return (*it).inset; }
622 size_type getPos() const {return (*it).pos; }
624 bool operator==(inset_iterator const & iter) const {
625 return it == iter.it;
628 bool operator!=(inset_iterator const & iter) const {
629 return it != iter.it;
633 InsetList::iterator it;
636 inset_iterator inset_iterator_begin();
638 inset_iterator inset_iterator_end();
640 inset_iterator InsetIterator(size_type pos);
645 int LyXParagraph::id() const
652 void LyXParagraph::id(int id_arg)
659 bool LyXParagraph::IsFirstInSequence() const
661 LyXParagraph const * dhook = DepthHook(GetDepth());
662 return (dhook == this
663 || dhook->GetLayout() != GetLayout()
664 || dhook->GetDepth() != GetDepth());
669 Inset * LyXParagraph::InInset()
676 LyXParagraph::size_type LyXParagraph::size() const
683 void LyXParagraph::clearContents()
690 void LyXParagraph::setCounter(int i, int v)
697 int LyXParagraph::getCounter(int i) const
704 void LyXParagraph::incCounter(int i)
711 void LyXParagraph::SetChar(size_type pos, value_type c)
718 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
720 return inset_iterator(insetlist.begin());
725 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
727 return inset_iterator(insetlist.end());