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 "support/block.h"
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 typedef int size_type;
131 /// this konstruktor inserts the new paragraph in a list
133 LyXParagraph(LyXParagraph * par);
134 /// the destruktors removes the new paragraph from the list
138 Language const * getParLanguage(BufferParams const &) const;
140 bool isRightToLeftPar(BufferParams const &) const;
142 void ChangeLanguage(BufferParams const & bparams,
143 Language const * from, Language const * to);
145 bool isMultiLingual(BufferParams const &);
148 string const String(Buffer const *, bool label);
150 string const String(Buffer const *, size_type beg, size_type end);
153 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
156 void validate(LaTeXFeatures &) const;
163 void id(int id_arg) {
171 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
172 std::ostream &, TexRow & texrow,
176 std::ostream & foot, TexRow & foot_texrow,
181 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
182 std::ostream &, TexRow & texrow, bool moving_arg);
185 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
186 std::ostream &, TexRow & texrow
188 ,std::ostream & foot, TexRow & foot_texrow,
193 LyXParagraph * Clone() const;
196 bool HasSameLayout(LyXParagraph const * par) const;
199 void MakeSameLayout(LyXParagraph const * par);
201 /// Is it the first par with same depth and layout?
202 bool IsFirstInSequence() const {
203 LyXParagraph const * dhook = DepthHook(GetDepth());
204 return (dhook == this
205 || dhook->GetLayout() != GetLayout()
206 || dhook->GetDepth() != GetDepth());
209 /** Check if the current paragraph is the last paragraph in a
211 int GetEndLabel(BufferParams const &) const;
213 Inset * InInset() { return inset_owner; }
215 void SetInsetOwner(Inset * i);
217 void deleteInsetsLyXText(BufferView *);
219 void resizeInsetsLyXText(BufferView *);
228 size_type size() const { return text.size(); }
231 text.resize(text.size());
234 void setContentsFromPar(LyXParagraph * par) {
238 void clearContents() {
243 VSpace added_space_top;
246 VSpace added_space_bottom;
252 LyXTextClass::LayoutList::size_type layout;
256 \item no footnote, closed footnote,
257 \item open footnote, where footnote
258 \item means footnote-environment
261 footnote_flag footnoteflag;
263 /// footnote, margin, fig, tab
264 footnote_kind footnotekind;
276 bool pagebreak_bottom;
289 block<int, 10> counter_;
292 void setCounter(int i, int v) { counter_[i] = v; }
294 int getCounter(int i) const { return counter_[i]; }
296 void incCounter(int i) { counter_[i]++; }
298 bool start_of_appendix;
309 /* This is for the paragraph extra stuff */
315 string pextra_widthp;
317 int pextra_alignment;
321 bool pextra_start_minipage;
327 string labelwidthstring;
332 LyXParagraph * previous;
335 InsetBibKey * bibkey; // ale970302
337 /** these function are able to hide closed footnotes
339 LyXParagraph * Next();
342 LyXParagraph * Previous();
344 LyXParagraph const * Previous() const;
347 /** these function are able to hide open and closed footnotes
349 LyXParagraph * NextAfterFootnote();
351 LyXParagraph const * NextAfterFootnote() const;
354 LyXParagraph * PreviousBeforeFootnote();
356 LyXParagraph * LastPhysicalPar();
358 LyXParagraph const * LastPhysicalPar() const;
361 LyXParagraph * FirstPhysicalPar();
363 LyXParagraph const * FirstPhysicalPar() const;
364 /// returns the physical paragraph
365 LyXParagraph * ParFromPos(size_type pos);
366 /// returns the position in the physical par
367 int PositionInParFromPos(size_type pos) const;
370 /// for the environments
371 LyXParagraph * DepthHook(int depth);
372 /// for the environments
373 LyXParagraph const * DepthHook(int depth) const;
375 int BeginningOfMainBody() const;
377 string const & GetLabelstring() const;
379 /// the next two functions are for the manual labels
380 string const GetLabelWidthString() const;
382 void SetLabelWidthString(string const & s);
384 LyXTextClass::LayoutList::size_type GetLayout() const;
386 char GetAlign() const;
388 char GetDepth() const;
390 void SetLayout(BufferParams const &,
391 LyXTextClass::LayoutList::size_type new_layout);
393 void SetOnlyLayout(BufferParams const &,
394 LyXTextClass::LayoutList::size_type new_layout);
396 int GetFirstCounter(int i) const;
398 size_type Last() const;
400 void Erase(size_type pos);
401 /** the flag determines wether the layout should be copied
403 void BreakParagraph(BufferParams const &, size_type pos, int flag);
405 void BreakParagraphConservative(BufferParams const &, size_type pos);
406 /** Get unistantiated font setting. Returns the difference
407 between the characters font and the layoutfont.
408 This is what is stored in the fonttable
411 GetFontSettings(BufferParams const &, size_type pos) const;
413 LyXFont const GetFirstFontSettings() const;
415 /** Get fully instantiated font. If pos == -1, use the layout
416 font attached to this paragraph.
417 If pos == -2, use the label font of the layout attached here.
418 In all cases, the font is instantiated, i.e. does not have any
419 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
422 LyXFont const getFont(BufferParams const &, size_type pos) const;
424 value_type GetChar(size_type pos) const;
425 /// The position must already exist.
426 void SetChar(size_type pos, value_type c) {
431 void SetFont(size_type pos, LyXFont const & font);
433 string const GetWord(size_type &) const;
434 /// Returns the height of the highest font in range
435 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
436 size_type endpos) const;
438 void InsertChar(size_type pos, value_type c);
440 void InsertChar(size_type pos, value_type c, LyXFont const &);
442 void InsertInset(size_type pos, Inset * inset);
444 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
446 bool InsertInsetAllowed(Inset * inset);
448 Inset * GetInset(size_type pos);
450 Inset const * GetInset(size_type pos) const;
453 void OpenFootnote(size_type pos);
455 void CloseFootnote(size_type pos);
457 /// important for cut and paste
458 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
460 void CutIntoMinibuffer(BufferParams const &, size_type pos);
462 bool InsertFromMinibuffer(size_type pos);
465 bool IsHfill(size_type pos) const;
467 bool IsInset(size_type pos) const;
470 bool IsFloat(size_type pos) const;
473 bool IsNewline(size_type pos) const;
475 bool IsSeparator(size_type pos) const;
477 bool IsLineSeparator(size_type pos) const;
479 bool IsKomma(size_type pos) const;
480 /// Used by the spellchecker
481 bool IsLetter(size_type pos) const;
483 bool IsWord(size_type pos) const;
485 /** This one resets all layout and dtp switches but not the font
486 of the single characters
490 /** paste this paragraph with the next one
491 be carefull, this doesent make any check at all
493 void PasteParagraph(BufferParams const &);
495 /// used to remove the error messages
496 int AutoDeleteInsets();
498 /// returns -1 if inset not found
499 int GetPositionOfInset(Inset * inset) const;
502 /// ok and now some footnote functions
503 void OpenFootnotes();
506 void CloseFootnotes();
508 LyXParagraph * FirstSelfrowPar();
512 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
515 /** A paragraph following a footnote is a "dummy". A paragraph
516 with a footnote in it is stored as three paragraphs:
517 First a paragraph with the text up to the footnote, then
518 one (or more) paragraphs with the footnote, and finally
519 the a paragraph with the text after the footnote. Only the
520 first paragraph keeps information about layoutparameters, */
521 bool IsDummy() const;
523 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
524 I have to set it on each of it's elements */
526 void SetPExtraType(BufferParams const &, int type,
527 string const & width, string const & widthp);
529 void UnsetPExtraType(BufferParams const &);
531 bool linuxDocConvertChar(char c, string & sgml_string);
540 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
543 friend struct matchIT;
546 /// used by lower_bound and upper_bound
548 int operator()(LyXParagraph::InsetTable const & a,
549 LyXParagraph::InsetTable const & b) const {
550 return a.pos < b.pos;
553 /** A font entry covers a range of positions. Notice that the
554 entries in the list are inserted in random order.
555 I don't think it's worth the effort to implement a more effective
556 datastructure, because the number of different fonts in a paragraph
558 Nevertheless, I decided to store fontlist using a sorted vector:
559 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
560 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
561 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
562 (font_1 covers the chars 0,...,pos_1) (Dekel)
565 /// End position of paragraph this font attribute covers
567 /** Font. Interpretation of the font values:
568 If a value is LyXFont::INHERIT_*, it means that the font
569 attribute is inherited from either the layout of this
570 paragraph or, in the case of nested paragraphs, from the
571 layout in the environment one level up until completely
573 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
574 allowed in these font tables.
578 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
581 friend struct matchFT;
584 /// used by lower_bound and upper_bound
586 int operator()(LyXParagraph::FontTable const & a,
587 LyXParagraph::FontTable const & b) const {
588 return a.pos < b.pos;
593 typedef std::vector<FontTable> FontList;
597 typedef std::vector<InsetTable> InsetList;
601 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
602 std::ostream &, TexRow & texrow
604 ,std::ostream & foot, TexRow & foot_texrow,
610 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
611 std::ostream &, TexRow & texrow,
612 std::ostream & foot, TexRow & foot_texrow,
617 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
619 int & column, LyXFont const & font,
620 LyXLayout const & style);
622 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
623 std::ostream &, TexRow & texrow,
625 LyXFont & font, LyXFont & running_font,
626 LyXFont & basefont, bool & open_font,
627 LyXLayout const & style,
629 int & column, value_type const c);
633 static unsigned int paragraph_id;
636 class inset_iterator {
641 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
643 inset_iterator & operator++() {
648 Inset * operator*() { return (*it).inset; }
650 size_type getPos() {return (*it).pos; }
652 bool operator==(inset_iterator const & iter) const {
653 return it == iter.it;
656 bool operator!=(inset_iterator const & iter) const {
657 return it != iter.it;
661 InsetList::iterator it;
664 inset_iterator inset_iterator_begin() {
665 return inset_iterator(insetlist.begin());
668 inset_iterator inset_iterator_end() {
669 return inset_iterator(insetlist.end());
672 inset_iterator InsetIterator(size_type pos);