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 // I dare you to try this one too. It is ortogonal with NEW_INSETS so you
40 // can try both or just one of them.
43 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
58 enum MINIPAGE_ALIGNMENT {
62 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 typedef int size_type;
135 /// this konstruktor inserts the new paragraph in a list
137 LyXParagraph(LyXParagraph * par);
138 /// the destruktors removes the new paragraph from the list
142 Language const * getParLanguage(BufferParams const &) const;
144 bool isRightToLeftPar(BufferParams const &) const;
146 void ChangeLanguage(BufferParams const & bparams,
147 Language const * from, Language const * to);
149 bool isMultiLingual(BufferParams const &);
152 string const String(Buffer const *, bool label);
154 string const String(Buffer const *, size_type beg, size_type end);
157 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
160 void validate(LaTeXFeatures &) const;
167 void id(int id_arg) {
175 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
176 std::ostream &, TexRow & texrow,
180 std::ostream & foot, TexRow & foot_texrow,
185 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
186 std::ostream &, TexRow & texrow, bool moving_arg);
189 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
190 std::ostream &, TexRow & texrow
192 ,std::ostream & foot, TexRow & foot_texrow,
197 LyXParagraph * Clone() const;
200 bool HasSameLayout(LyXParagraph const * par) const;
203 void MakeSameLayout(LyXParagraph const * par);
205 /// Is it the first par with same depth and layout?
206 bool IsFirstInSequence() const {
207 LyXParagraph const * dhook = DepthHook(GetDepth());
208 return (dhook == this
209 || dhook->GetLayout() != GetLayout()
210 || dhook->GetDepth() != GetDepth());
213 /** Check if the current paragraph is the last paragraph in a
215 int GetEndLabel(BufferParams const &) const;
217 Inset * InInset() { return inset_owner; }
219 void SetInsetOwner(Inset * i);
221 void deleteInsetsLyXText(BufferView *);
223 void resizeInsetsLyXText(BufferView *);
232 size_type size() const { return text.size(); }
235 text.resize(text.size());
238 void setContentsFromPar(LyXParagraph * par) {
242 void clearContents() {
247 VSpace added_space_top;
250 VSpace added_space_bottom;
256 LyXTextClass::LayoutList::size_type layout;
260 \item no footnote, closed footnote,
261 \item open footnote, where footnote
262 \item means footnote-environment
265 footnote_flag footnoteflag;
267 /// footnote, margin, fig, tab
268 footnote_kind footnotekind;
280 bool pagebreak_bottom;
293 block<int, 10> counter_;
296 void setCounter(int i, int v) { counter_[i] = v; }
298 int getCounter(int i) const { return counter_[i]; }
300 void incCounter(int i) { counter_[i]++; }
302 bool start_of_appendix;
313 /* This is for the paragraph extra stuff */
319 string pextra_widthp;
321 int pextra_alignment;
325 bool pextra_start_minipage;
331 string labelwidthstring;
336 LyXParagraph * previous;
339 /* table stuff -- begin*/
342 /* table stuff -- end*/
345 InsetBibKey * bibkey; // ale970302
347 /** these function are able to hide closed footnotes
349 LyXParagraph * Next();
352 LyXParagraph * Previous();
354 LyXParagraph const * Previous() const;
357 /** these function are able to hide open and closed footnotes
359 LyXParagraph * NextAfterFootnote();
361 LyXParagraph const * NextAfterFootnote() const;
364 LyXParagraph * PreviousBeforeFootnote();
366 LyXParagraph * LastPhysicalPar();
368 LyXParagraph const * LastPhysicalPar() const;
371 LyXParagraph * FirstPhysicalPar();
373 LyXParagraph const * FirstPhysicalPar() const;
374 /// returns the physical paragraph
375 LyXParagraph * ParFromPos(size_type pos);
376 /// returns the position in the physical par
377 int PositionInParFromPos(size_type pos) const;
380 /// for the environments
381 LyXParagraph * DepthHook(int depth);
382 /// for the environments
383 LyXParagraph const * DepthHook(int depth) const;
385 int BeginningOfMainBody() const;
387 string const & GetLabelstring() const;
389 /// the next two functions are for the manual labels
390 string const GetLabelWidthString() const;
392 void SetLabelWidthString(string const & s);
394 LyXTextClass::LayoutList::size_type GetLayout() const;
396 char GetAlign() const;
398 char GetDepth() const;
400 void SetLayout(BufferParams const &,
401 LyXTextClass::LayoutList::size_type new_layout);
403 void SetOnlyLayout(BufferParams const &,
404 LyXTextClass::LayoutList::size_type new_layout);
406 int GetFirstCounter(int i) const;
408 size_type Last() const;
410 void Erase(size_type pos);
411 /** the flag determines wether the layout should be copied
413 void BreakParagraph(BufferParams const &, size_type pos, int flag);
415 void BreakParagraphConservative(BufferParams const &, size_type pos);
416 /** Get unistantiated font setting. Returns the difference
417 between the characters font and the layoutfont.
418 This is what is stored in the fonttable
421 GetFontSettings(BufferParams const &, size_type pos) const;
423 LyXFont const GetFirstFontSettings() const;
425 /** Get fully instantiated font. If pos == -1, use the layout
426 font attached to this paragraph.
427 If pos == -2, use the label font of the layout attached here.
428 In all cases, the font is instantiated, i.e. does not have any
429 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
432 LyXFont const getFont(BufferParams const &, size_type pos) const;
434 value_type GetChar(size_type pos) const;
435 /// The position must already exist.
436 void SetChar(size_type pos, value_type c) {
441 void SetFont(size_type pos, LyXFont const & font);
443 string const GetWord(size_type &) const;
444 /// Returns the height of the highest font in range
445 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
446 size_type endpos) const;
448 void InsertChar(size_type pos, value_type c);
450 void InsertChar(size_type pos, value_type c, LyXFont const &);
452 void InsertInset(size_type pos, Inset * inset);
454 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
456 bool InsertInsetAllowed(Inset * inset);
458 Inset * GetInset(size_type pos);
460 Inset const * GetInset(size_type pos) const;
463 void OpenFootnote(size_type pos);
465 void CloseFootnote(size_type pos);
467 /// important for cut and paste
468 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
470 void CutIntoMinibuffer(BufferParams const &, size_type pos);
472 bool InsertFromMinibuffer(size_type pos);
475 bool IsHfill(size_type pos) const;
477 bool IsInset(size_type pos) const;
480 bool IsFloat(size_type pos) const;
483 bool IsNewline(size_type pos) const;
485 bool IsSeparator(size_type pos) const;
487 bool IsLineSeparator(size_type pos) const;
489 bool IsKomma(size_type pos) const;
490 /// Used by the spellchecker
491 bool IsLetter(size_type pos) const;
493 bool IsWord(size_type pos) const;
495 /** This one resets all layout and dtp switches but not the font
496 of the single characters
500 /** paste this paragraph with the next one
501 be carefull, this doesent make any check at all
503 void PasteParagraph(BufferParams const &);
505 /// used to remove the error messages
506 int AutoDeleteInsets();
508 /// returns -1 if inset not found
509 int GetPositionOfInset(Inset * inset) const;
512 /// ok and now some footnote functions
513 void OpenFootnotes();
516 void CloseFootnotes();
518 LyXParagraph * FirstSelfrowPar();
522 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
525 /** A paragraph following a footnote is a "dummy". A paragraph
526 with a footnote in it is stored as three paragraphs:
527 First a paragraph with the text up to the footnote, then
528 one (or more) paragraphs with the footnote, and finally
529 the a paragraph with the text after the footnote. Only the
530 first paragraph keeps information about layoutparameters, */
531 bool IsDummy() const;
533 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
534 I have to set it on each of it's elements */
536 void SetPExtraType(BufferParams const &, int type,
537 string const & width, string const & widthp);
539 void UnsetPExtraType(BufferParams const &);
541 bool linuxDocConvertChar(char c, string & sgml_string);
544 void DocBookContTableRows(Buffer const *,
545 std::ostream &, string & extra,
546 int & desc_on, size_type i,
547 int current_cell_number, int & column);
549 void SimpleDocBookOneTablePar(Buffer const *,
550 std::ostream &, string & extra,
551 int & desc_on, int depth);
561 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
564 friend struct matchIT;
567 /// used by lower_bound and upper_bound
569 int operator()(LyXParagraph::InsetTable const & a,
570 LyXParagraph::InsetTable const & b) const {
571 return a.pos < b.pos;
574 /** A font entry covers a range of positions. Notice that the
575 entries in the list are inserted in random order.
576 I don't think it's worth the effort to implement a more effective
577 datastructure, because the number of different fonts in a paragraph
579 Nevertheless, I decided to store fontlist using a sorted vector:
580 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
581 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
582 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
583 (font_1 covers the chars 0,...,pos_1) (Dekel)
586 /// End position of paragraph this font attribute covers
588 /** Font. Interpretation of the font values:
589 If a value is LyXFont::INHERIT_*, it means that the font
590 attribute is inherited from either the layout of this
591 paragraph or, in the case of nested paragraphs, from the
592 layout in the environment one level up until completely
594 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
595 allowed in these font tables.
599 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
602 friend struct matchFT;
605 /// used by lower_bound and upper_bound
607 int operator()(LyXParagraph::FontTable const & a,
608 LyXParagraph::FontTable const & b) const {
609 return a.pos < b.pos;
614 typedef std::vector<FontTable> FontList;
618 typedef std::vector<InsetTable> InsetList;
622 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
623 std::ostream &, TexRow & texrow
625 ,std::ostream & foot, TexRow & foot_texrow,
631 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
632 std::ostream &, TexRow & texrow,
633 std::ostream & foot, TexRow & foot_texrow,
639 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
640 std::ostream &, TexRow & texrow);
642 bool TeXContTableRows(Buffer const *, BufferParams const &,
643 std::ostream &, size_type i,
644 int current_cell_number,
645 int & column, TexRow & texrow);
648 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
650 int & column, LyXFont const & font,
651 LyXLayout const & style);
653 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
654 std::ostream &, TexRow & texrow,
656 LyXFont & font, LyXFont & running_font,
657 LyXFont & basefont, bool & open_font,
658 LyXLayout const & style,
660 int & column, value_type const c);
664 static unsigned int paragraph_id;
667 class inset_iterator {
672 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
674 inset_iterator & operator++() {
679 Inset * operator*() { return (*it).inset; }
681 size_type getPos() {return (*it).pos; }
683 bool operator==(inset_iterator const & iter) const {
684 return it == iter.it;
687 bool operator!=(inset_iterator const & iter) const {
688 return it != iter.it;
692 InsetList::iterator it;
695 inset_iterator inset_iterator_begin() {
696 return inset_iterator(insetlist.begin());
699 inset_iterator inset_iterator_end() {
700 return inset_iterator(insetlist.end());
703 inset_iterator InsetIterator(size_type pos);