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.
42 //#define NEW_TABULAR 1
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 String(Buffer const *, bool label);
155 string 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,
192 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 {
205 LyXParagraph const * dhook = DepthHook(GetDepth());
206 return (dhook == this
207 || dhook->GetLayout() != GetLayout()
208 || dhook->GetDepth() != GetDepth());
211 /** Check if the current paragraph is the last paragraph in a
213 int GetEndLabel(BufferParams const &) const;
215 Inset * InInset() { return inset_owner; }
217 void SetInsetOwner(Inset * i);
219 void deleteInsetsLyXText(BufferView *);
220 void resizeInsetsLyXText(BufferView *);
229 size_type size() const { return text.size(); }
232 text.resize(text.size());
235 void setContentsFromPar(LyXParagraph * par) {
239 void clearContents() {
244 VSpace added_space_top;
247 VSpace added_space_bottom;
253 LyXTextClass::LayoutList::size_type layout;
257 \item no footnote, closed footnote,
258 \item open footnote, where footnote
259 \item means footnote-environment
262 footnote_flag footnoteflag;
264 /// footnote, margin, fig, tab
265 footnote_kind footnotekind;
267 //@Man: the LyX- DTP-switches
279 bool pagebreak_bottom;
292 block<int, 10> counter_;
295 void setCounter(int i, int v) { counter_[i] = v; }
296 int getCounter(int i) const { return counter_[i]; }
297 void incCounter(int i) { counter_[i]++; }
299 bool start_of_appendix;
310 /* This is for the paragraph extra stuff */
316 string pextra_widthp;
318 int pextra_alignment;
322 bool pextra_start_minipage;
328 string labelwidthstring;
334 LyXParagraph * previous;
337 /* table stuff -- begin*/
340 /* table stuff -- end*/
343 InsetBibKey * bibkey; // ale970302
345 /** these function are able to hide closed footnotes
347 LyXParagraph * Next();
350 LyXParagraph * Previous();
352 LyXParagraph const * Previous() const;
355 /** these function are able to hide open and closed footnotes
357 LyXParagraph * NextAfterFootnote();
359 LyXParagraph const * NextAfterFootnote() const;
362 LyXParagraph * PreviousBeforeFootnote();
364 LyXParagraph * LastPhysicalPar();
366 LyXParagraph const * LastPhysicalPar() const;
369 LyXParagraph * FirstPhysicalPar();
371 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;
379 /// for the environments
380 LyXParagraph * DepthHook(int depth);
381 /// for the environments
382 LyXParagraph const * DepthHook(int depth) const;
384 int BeginningOfMainBody() const;
386 string const & GetLabelstring() const;
388 /// the next two functions are for the manual labels
389 string GetLabelWidthString() const;
391 void SetLabelWidthString(string const & s);
393 LyXTextClass::LayoutList::size_type GetLayout() const;
395 char GetAlign() const;
397 char GetDepth() const;
399 void SetLayout(BufferParams const &,
400 LyXTextClass::LayoutList::size_type new_layout);
402 void SetOnlyLayout(BufferParams const &,
403 LyXTextClass::LayoutList::size_type new_layout);
405 int GetFirstCounter(int i) const;
407 size_type Last() const;
409 void Erase(size_type pos);
410 /** the flag determines wether the layout should be copied
412 void BreakParagraph(BufferParams const &, size_type pos, int flag);
414 void BreakParagraphConservative(BufferParams const &, size_type pos);
415 /** Get unistantiated font setting. Returns the difference
416 between the characters font and the layoutfont.
417 This is what is stored in the fonttable
419 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
421 LyXFont GetFirstFontSettings() const;
423 /** Get fully instantiated font. If pos == -1, use the layout
424 font attached to this paragraph.
425 If pos == -2, use the label font of the layout attached here.
426 In all cases, the font is instantiated, i.e. does not have any
427 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
430 LyXFont getFont(BufferParams const &, size_type pos) const;
432 value_type GetChar(size_type pos);
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 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 &,
537 int type, char const * width, char 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;}
601 friend struct matchFT;
604 /// used by lower_bound and upper_bound
606 int operator()(LyXParagraph::FontTable const & a,
607 LyXParagraph::FontTable const & b) const {
608 return a.pos < b.pos;
613 typedef std::vector<FontTable> FontList;
617 typedef std::vector<InsetTable> InsetList;
621 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
622 std::ostream &, TexRow & texrow,
623 std::ostream & foot, TexRow & foot_texrow,
627 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
628 std::ostream &, TexRow & texrow,
629 std::ostream & foot, TexRow & foot_texrow,
635 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
636 std::ostream &, TexRow & texrow);
638 bool TeXContTableRows(Buffer const *, BufferParams const &,
639 std::ostream &, size_type i,
640 int current_cell_number,
641 int & column, TexRow & texrow);
644 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
646 int & column, LyXFont const & font,
647 LyXLayout const & style);
649 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
650 std::ostream &, TexRow & texrow,
652 LyXFont & font, LyXFont & running_font,
653 LyXFont & basefont, bool & open_font,
654 LyXLayout const & style,
656 int & column, value_type const c);
660 static unsigned int paragraph_id;
662 class inset_iterator {
665 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
666 inset_iterator & operator++() {
670 Inset * operator*() { return (*it).inset; }
671 size_type getPos() {return (*it).pos; }
672 bool operator==(inset_iterator const & iter) const {
673 return it == iter.it;
675 bool operator!=(inset_iterator const & iter) const {
676 return it != iter.it;
679 InsetList::iterator it;
682 inset_iterator inset_iterator_begin() {
683 return inset_iterator(insetlist.begin());
686 inset_iterator inset_iterator_end() {
687 return inset_iterator(insetlist.end());
690 inset_iterator InsetIterator(size_type pos);