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"
26 #include "support/block.h"
36 // I dare you to enable this and help me find all the bugs that then show
38 //#define NEW_INSETS 1
40 // I dare you to try this one too. It is ortogonal with NEW_INSETS so you
41 // can try both or just one of them.
44 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
59 enum MINIPAGE_ALIGNMENT {
63 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 typedef int size_type;
136 /// this konstruktor inserts the new paragraph in a list
138 LyXParagraph(LyXParagraph * par);
139 /// the destruktors removes the new paragraph from the list
143 Language const * getParLanguage(BufferParams const &) const;
145 bool isRightToLeftPar(BufferParams const &) const;
147 void ChangeLanguage(BufferParams const & bparams,
148 Language const * from, Language const * to);
150 bool isMultiLingual(BufferParams const &);
153 string const String(Buffer const *, bool label);
155 string const String(Buffer const *, size_type beg, size_type end);
158 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
161 void validate(LaTeXFeatures &) const;
168 void id(int id_arg) {
176 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
177 std::ostream &, TexRow & texrow,
181 std::ostream & foot, TexRow & foot_texrow,
186 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
187 std::ostream &, TexRow & texrow, bool moving_arg);
190 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
191 std::ostream &, TexRow & texrow
193 ,std::ostream & foot, TexRow & foot_texrow,
198 LyXParagraph * Clone() const;
201 bool HasSameLayout(LyXParagraph const * par) const;
204 void MakeSameLayout(LyXParagraph const * par);
206 /// Is it the first par with same depth and layout?
207 bool IsFirstInSequence() const {
208 LyXParagraph const * dhook = DepthHook(GetDepth());
209 return (dhook == this
210 || dhook->GetLayout() != GetLayout()
211 || dhook->GetDepth() != GetDepth());
214 /** Check if the current paragraph is the last paragraph in a
216 int GetEndLabel(BufferParams const &) const;
218 Inset * InInset() { return inset_owner; }
220 void SetInsetOwner(Inset * i);
222 void deleteInsetsLyXText(BufferView *);
224 void resizeInsetsLyXText(BufferView *);
233 size_type size() const { return text.size(); }
236 text.resize(text.size());
239 void setContentsFromPar(LyXParagraph * par) {
243 void clearContents() {
248 VSpace added_space_top;
251 VSpace added_space_bottom;
257 LyXTextClass::LayoutList::size_type layout;
261 \item no footnote, closed footnote,
262 \item open footnote, where footnote
263 \item means footnote-environment
266 footnote_flag footnoteflag;
268 /// footnote, margin, fig, tab
269 footnote_kind footnotekind;
281 bool pagebreak_bottom;
294 block<int, 10> counter_;
297 void setCounter(int i, int v) { counter_[i] = v; }
299 int getCounter(int i) const { return counter_[i]; }
301 void incCounter(int i) { counter_[i]++; }
303 bool start_of_appendix;
314 /* This is for the paragraph extra stuff */
320 string pextra_widthp;
322 int pextra_alignment;
326 bool pextra_start_minipage;
332 string labelwidthstring;
337 LyXParagraph * previous;
340 /* table stuff -- begin*/
343 /* table stuff -- end*/
346 InsetBibKey * bibkey; // ale970302
348 /** these function are able to hide closed footnotes
350 LyXParagraph * Next();
353 LyXParagraph * Previous();
355 LyXParagraph const * Previous() const;
358 /** these function are able to hide open and closed footnotes
360 LyXParagraph * NextAfterFootnote();
362 LyXParagraph const * NextAfterFootnote() const;
365 LyXParagraph * PreviousBeforeFootnote();
367 LyXParagraph * LastPhysicalPar();
369 LyXParagraph const * LastPhysicalPar() const;
372 LyXParagraph * FirstPhysicalPar();
374 LyXParagraph const * FirstPhysicalPar() const;
375 /// returns the physical paragraph
376 LyXParagraph * ParFromPos(size_type pos);
377 /// returns the position in the physical par
378 int PositionInParFromPos(size_type pos) const;
381 /// for the environments
382 LyXParagraph * DepthHook(int depth);
383 /// for the environments
384 LyXParagraph const * DepthHook(int depth) const;
386 int BeginningOfMainBody() const;
388 string const & GetLabelstring() const;
390 /// the next two functions are for the manual labels
391 string const GetLabelWidthString() const;
393 void SetLabelWidthString(string const & s);
395 LyXTextClass::LayoutList::size_type GetLayout() const;
397 char GetAlign() const;
399 char GetDepth() const;
401 void SetLayout(BufferParams const &,
402 LyXTextClass::LayoutList::size_type new_layout);
404 void SetOnlyLayout(BufferParams const &,
405 LyXTextClass::LayoutList::size_type new_layout);
407 int GetFirstCounter(int i) const;
409 size_type Last() const;
411 void Erase(size_type pos);
412 /** the flag determines wether the layout should be copied
414 void BreakParagraph(BufferParams const &, size_type pos, int flag);
416 void BreakParagraphConservative(BufferParams const &, size_type pos);
417 /** Get unistantiated font setting. Returns the difference
418 between the characters font and the layoutfont.
419 This is what is stored in the fonttable
422 GetFontSettings(BufferParams const &, size_type pos) const;
424 LyXFont const GetFirstFontSettings() const;
426 /** Get fully instantiated font. If pos == -1, use the layout
427 font attached to this paragraph.
428 If pos == -2, use the label font of the layout attached here.
429 In all cases, the font is instantiated, i.e. does not have any
430 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
433 LyXFont const getFont(BufferParams const &, size_type pos) const;
435 value_type GetChar(size_type pos) const;
436 /// The position must already exist.
437 void SetChar(size_type pos, value_type c) {
442 void SetFont(size_type pos, LyXFont const & font);
444 string const GetWord(size_type &) const;
445 /// Returns the height of the highest font in range
446 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
447 size_type endpos) const;
449 void InsertChar(size_type pos, value_type c);
451 void InsertChar(size_type pos, value_type c, LyXFont const &);
453 void InsertInset(size_type pos, Inset * inset);
455 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
457 bool InsertInsetAllowed(Inset * inset);
459 Inset * GetInset(size_type pos);
461 Inset const * GetInset(size_type pos) const;
464 void OpenFootnote(size_type pos);
466 void CloseFootnote(size_type pos);
468 /// important for cut and paste
469 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
471 void CutIntoMinibuffer(BufferParams const &, size_type pos);
473 bool InsertFromMinibuffer(size_type pos);
476 bool IsHfill(size_type pos) const;
478 bool IsInset(size_type pos) const;
481 bool IsFloat(size_type pos) const;
484 bool IsNewline(size_type pos) const;
486 bool IsSeparator(size_type pos) const;
488 bool IsLineSeparator(size_type pos) const;
490 bool IsKomma(size_type pos) const;
491 /// Used by the spellchecker
492 bool IsLetter(size_type pos) const;
494 bool IsWord(size_type pos) const;
496 /** This one resets all layout and dtp switches but not the font
497 of the single characters
501 /** paste this paragraph with the next one
502 be carefull, this doesent make any check at all
504 void PasteParagraph(BufferParams const &);
506 /// used to remove the error messages
507 int AutoDeleteInsets();
509 /// returns -1 if inset not found
510 int GetPositionOfInset(Inset * inset) const;
513 /// ok and now some footnote functions
514 void OpenFootnotes();
517 void CloseFootnotes();
519 LyXParagraph * FirstSelfrowPar();
523 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
526 /** A paragraph following a footnote is a "dummy". A paragraph
527 with a footnote in it is stored as three paragraphs:
528 First a paragraph with the text up to the footnote, then
529 one (or more) paragraphs with the footnote, and finally
530 the a paragraph with the text after the footnote. Only the
531 first paragraph keeps information about layoutparameters, */
532 bool IsDummy() const;
534 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
535 I have to set it on each of it's elements */
537 void SetPExtraType(BufferParams const &, int type,
538 string const & width, string const & widthp);
540 void UnsetPExtraType(BufferParams const &);
542 bool linuxDocConvertChar(char c, string & sgml_string);
545 void DocBookContTableRows(Buffer const *,
546 std::ostream &, string & extra,
547 int & desc_on, size_type i,
548 int current_cell_number, int & column);
550 void SimpleDocBookOneTablePar(Buffer const *,
551 std::ostream &, string & extra,
552 int & desc_on, int depth);
562 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
565 friend struct matchIT;
568 /// used by lower_bound and upper_bound
570 int operator()(LyXParagraph::InsetTable const & a,
571 LyXParagraph::InsetTable const & b) const {
572 return a.pos < b.pos;
575 /** A font entry covers a range of positions. Notice that the
576 entries in the list are inserted in random order.
577 I don't think it's worth the effort to implement a more effective
578 datastructure, because the number of different fonts in a paragraph
580 Nevertheless, I decided to store fontlist using a sorted vector:
581 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
582 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
583 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
584 (font_1 covers the chars 0,...,pos_1) (Dekel)
587 /// End position of paragraph this font attribute covers
589 /** Font. Interpretation of the font values:
590 If a value is LyXFont::INHERIT_*, it means that the font
591 attribute is inherited from either the layout of this
592 paragraph or, in the case of nested paragraphs, from the
593 layout in the environment one level up until completely
595 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
596 allowed in these font tables.
600 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
603 friend struct matchFT;
606 /// used by lower_bound and upper_bound
608 int operator()(LyXParagraph::FontTable const & a,
609 LyXParagraph::FontTable const & b) const {
610 return a.pos < b.pos;
615 typedef std::vector<FontTable> FontList;
619 typedef std::vector<InsetTable> InsetList;
623 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
624 std::ostream &, TexRow & texrow
626 ,std::ostream & foot, TexRow & foot_texrow,
632 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
633 std::ostream &, TexRow & texrow,
634 std::ostream & foot, TexRow & foot_texrow,
640 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
641 std::ostream &, TexRow & texrow);
643 bool TeXContTableRows(Buffer const *, BufferParams const &,
644 std::ostream &, size_type i,
645 int current_cell_number,
646 int & column, TexRow & texrow);
649 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
651 int & column, LyXFont const & font,
652 LyXLayout const & style);
654 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
655 std::ostream &, TexRow & texrow,
657 LyXFont & font, LyXFont & running_font,
658 LyXFont & basefont, bool & open_font,
659 LyXLayout const & style,
661 int & column, value_type const c);
665 static unsigned int paragraph_id;
668 class inset_iterator {
673 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
675 inset_iterator & operator++() {
680 Inset * operator*() { return (*it).inset; }
682 size_type getPos() {return (*it).pos; }
684 bool operator==(inset_iterator const & iter) const {
685 return it == iter.it;
688 bool operator!=(inset_iterator const & iter) const {
689 return it != iter.it;
693 InsetList::iterator it;
696 inset_iterator inset_iterator_begin() {
697 return inset_iterator(insetlist.begin());
700 inset_iterator inset_iterator_end() {
701 return inset_iterator(insetlist.end());
704 inset_iterator InsetIterator(size_type pos);