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 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
55 enum MINIPAGE_ALIGNMENT {
59 MINIPAGE_ALIGN_MIDDLE,
89 //META_PROTECTED_SEPARATOR,
105 /// The footnotekinds
116 ALGORITHM, // Bernhard, 970807
118 WIDE_FIG, // CFO-G, 971106
120 WIDE_TAB // CFO-G, 971106
124 typedef char value_type;
126 typedef std::vector<value_type> TextContainer;
128 typedef int size_type;
132 /// this konstruktor inserts the new paragraph in a list
134 LyXParagraph(LyXParagraph * par);
135 /// the destruktors removes the new paragraph from the list
139 Language const * getParLanguage(BufferParams const &) const;
141 bool isRightToLeftPar(BufferParams const &) const;
143 void ChangeLanguage(BufferParams const & bparams,
144 Language const * from, Language const * to);
146 bool isMultiLingual(BufferParams const &);
149 string String(Buffer const *, bool label);
151 string String(Buffer const *, size_type beg, size_type end);
154 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
157 void validate(LaTeXFeatures &) const;
164 void id(int id_arg) {
172 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
173 std::ostream &, TexRow & texrow,
177 std::ostream & foot, TexRow & foot_texrow,
182 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
183 std::ostream &, TexRow & texrow, bool moving_arg);
186 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
187 std::ostream &, TexRow & texrow,
188 std::ostream & foot, TexRow & foot_texrow,
191 LyXParagraph * Clone() const;
194 bool HasSameLayout(LyXParagraph const * par) const;
197 void MakeSameLayout(LyXParagraph const * par);
199 /// Is it the first par with same depth and layout?
200 bool IsFirstInSequence() const {
201 LyXParagraph const * dhook = DepthHook(GetDepth());
202 return (dhook == this
203 || dhook->GetLayout() != GetLayout()
204 || dhook->GetDepth() != GetDepth());
207 /** Check if the current paragraph is the last paragraph in a
209 int GetEndLabel(BufferParams const &) const;
211 Inset * InInset() { return inset_owner; }
213 void SetInsetOwner(Inset * i);
215 void deleteInsetsLyXText(BufferView *);
216 void resizeInsetsLyXText(BufferView *);
225 size_type size() const { return text.size(); }
228 text.resize(text.size());
231 void setContentsFromPar(LyXParagraph * par) {
235 void clearContents() {
240 VSpace added_space_top;
243 VSpace added_space_bottom;
249 LyXTextClass::LayoutList::size_type layout;
253 \item no footnote, closed footnote,
254 \item open footnote, where footnote
255 \item means footnote-environment
258 footnote_flag footnoteflag;
260 /// footnote, margin, fig, tab
261 footnote_kind footnotekind;
263 //@Man: the LyX- DTP-switches
275 bool pagebreak_bottom;
288 block<int, 10> counter_;
291 void setCounter(int i, int v) { counter_[i] = v; }
292 int getCounter(int i) const { return counter_[i]; }
293 void incCounter(int i) { counter_[i]++; }
295 bool start_of_appendix;
306 /* This is for the paragraph extra stuff */
312 string pextra_widthp;
314 int pextra_alignment;
318 bool pextra_start_minipage;
324 string labelwidthstring;
330 LyXParagraph * previous;
332 /* table stuff -- begin*/
335 /* table stuff -- end*/
338 InsetBibKey * bibkey; // ale970302
340 /** these function are able to hide closed footnotes
342 LyXParagraph * Next();
345 LyXParagraph * Previous();
347 LyXParagraph const * Previous() const;
350 /** these function are able to hide open and closed footnotes
352 LyXParagraph * NextAfterFootnote();
354 LyXParagraph const * NextAfterFootnote() const;
357 LyXParagraph * PreviousBeforeFootnote();
359 LyXParagraph * LastPhysicalPar();
361 LyXParagraph const * LastPhysicalPar() const;
364 LyXParagraph * FirstPhysicalPar();
366 LyXParagraph const * FirstPhysicalPar() const;
369 /// returns the physical paragraph
370 LyXParagraph * ParFromPos(size_type pos);
371 /// returns the position in the physical par
372 int PositionInParFromPos(size_type pos) const;
374 /// for the environments
375 LyXParagraph * DepthHook(int depth);
376 /// for the environments
377 LyXParagraph const * DepthHook(int depth) const;
379 int BeginningOfMainBody() const;
381 string const & GetLabelstring() const;
383 /// the next two functions are for the manual labels
384 string GetLabelWidthString() const;
386 void SetLabelWidthString(string const & s);
388 LyXTextClass::LayoutList::size_type GetLayout() const;
390 char GetAlign() const;
392 char GetDepth() const;
394 void SetLayout(BufferParams const &,
395 LyXTextClass::LayoutList::size_type new_layout);
397 void SetOnlyLayout(BufferParams const &,
398 LyXTextClass::LayoutList::size_type new_layout);
400 int GetFirstCounter(int i) const;
402 size_type Last() const;
404 void Erase(size_type pos);
405 /** the flag determines wether the layout should be copied
407 void BreakParagraph(BufferParams const &, size_type pos, int flag);
409 void BreakParagraphConservative(BufferParams const &, size_type pos);
410 /** Get unistantiated font setting. Returns the difference
411 between the characters font and the layoutfont.
412 This is what is stored in the fonttable
414 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
416 LyXFont GetFirstFontSettings() const;
418 /** Get fully instantiated font. If pos == -1, use the layout
419 font attached to this paragraph.
420 If pos == -2, use the label font of the layout attached here.
421 In all cases, the font is instantiated, i.e. does not have any
422 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
425 LyXFont getFont(BufferParams const &, size_type pos) const;
427 value_type GetChar(size_type pos);
429 value_type GetChar(size_type pos) const;
430 /// The position must already exist.
431 void SetChar(size_type pos, value_type c) {
436 void SetFont(size_type pos, LyXFont const & font);
438 string GetWord(size_type &) const;
439 /// Returns the height of the highest font in range
440 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
441 size_type endpos) const;
443 void InsertChar(size_type pos, value_type c);
445 void InsertChar(size_type pos, value_type c, LyXFont const &);
447 void InsertInset(size_type pos, Inset * inset);
449 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
451 bool InsertInsetAllowed(Inset * inset);
453 Inset * GetInset(size_type pos);
455 Inset const * GetInset(size_type pos) const;
458 void OpenFootnote(size_type pos);
460 void CloseFootnote(size_type pos);
462 /// important for cut and paste
463 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
465 void CutIntoMinibuffer(BufferParams const &, size_type pos);
467 bool InsertFromMinibuffer(size_type pos);
470 bool IsHfill(size_type pos) const;
472 bool IsInset(size_type pos) const;
475 bool IsFloat(size_type pos) const;
478 bool IsNewline(size_type pos) const;
480 bool IsSeparator(size_type pos) const;
482 bool IsLineSeparator(size_type pos) const;
484 bool IsKomma(size_type pos) const;
485 /// Used by the spellchecker
486 bool IsLetter(size_type pos) const;
488 bool IsWord(size_type pos) const;
490 /** This one resets all layout and dtp switches but not the font
491 of the single characters
495 /** paste this paragraph with the next one
496 be carefull, this doesent make any check at all
498 void PasteParagraph(BufferParams const &);
500 /// used to remove the error messages
501 int AutoDeleteInsets();
503 /// returns -1 if inset not found
504 int GetPositionOfInset(Inset * inset) const;
507 /// ok and now some footnote functions
508 void OpenFootnotes();
511 void CloseFootnotes();
513 LyXParagraph * FirstSelfrowPar();
517 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
520 /** A paragraph following a footnote is a "dummy". A paragraph
521 with a footnote in it is stored as three paragraphs:
522 First a paragraph with the text up to the footnote, then
523 one (or more) paragraphs with the footnote, and finally
524 the a paragraph with the text after the footnote. Only the
525 first paragraph keeps information about layoutparameters, */
526 bool IsDummy() const;
528 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
529 I have to set it on each of it's elements */
531 void SetPExtraType(BufferParams const &,
532 int type, char const * width, char const * widthp);
534 void UnsetPExtraType(BufferParams const &);
536 bool linuxDocConvertChar(char c, string & sgml_string);
538 void DocBookContTableRows(Buffer const *,
539 std::ostream &, string & extra,
540 int & desc_on, size_type i,
541 int current_cell_number, int & column);
543 void SimpleDocBookOneTablePar(Buffer const *,
544 std::ostream &, string & extra,
545 int & desc_on, int depth);
554 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
557 friend struct matchIT;
560 /// used by lower_bound and upper_bound
562 int operator()(LyXParagraph::InsetTable const & a,
563 LyXParagraph::InsetTable const & b) const {
564 return a.pos < b.pos;
567 /** A font entry covers a range of positions. Notice that the
568 entries in the list are inserted in random order.
569 I don't think it's worth the effort to implement a more effective
570 datastructure, because the number of different fonts in a paragraph
572 Nevertheless, I decided to store fontlist using a sorted vector:
573 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
574 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
575 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
576 (font_1 covers the chars 0,...,pos_1) (Dekel)
579 /// End position of paragraph this font attribute covers
581 /** Font. Interpretation of the font values:
582 If a value is LyXFont::INHERIT_*, it means that the font
583 attribute is inherited from either the layout of this
584 paragraph or, in the case of nested paragraphs, from the
585 layout in the environment one level up until completely
587 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
588 allowed in these font tables.
592 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
594 friend struct matchFT;
597 /// used by lower_bound and upper_bound
599 int operator()(LyXParagraph::FontTable const & a,
600 LyXParagraph::FontTable const & b) const {
601 return a.pos < b.pos;
606 typedef std::vector<FontTable> FontList;
610 typedef std::vector<InsetTable> InsetList;
614 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
615 std::ostream &, TexRow & texrow,
616 std::ostream & foot, TexRow & foot_texrow,
620 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
621 std::ostream &, TexRow & texrow,
622 std::ostream & foot, TexRow & foot_texrow,
627 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
628 std::ostream &, TexRow & texrow);
630 bool TeXContTableRows(Buffer const *, BufferParams const &,
631 std::ostream &, size_type i,
632 int current_cell_number,
633 int & column, TexRow & texrow);
635 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
637 int & column, LyXFont const & font,
638 LyXLayout const & style);
640 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
641 std::ostream &, TexRow & texrow,
643 LyXFont & font, LyXFont & running_font,
644 LyXFont & basefont, bool & open_font,
645 LyXLayout const & style,
647 int & column, value_type const c);
651 static unsigned int paragraph_id;
653 class inset_iterator {
656 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
657 inset_iterator & operator++() {
661 Inset * operator*() { return (*it).inset; }
662 size_type getPos() {return (*it).pos; }
663 bool operator==(inset_iterator const & iter) const {
664 return it == iter.it;
666 bool operator!=(inset_iterator const & iter) const {
667 return it != iter.it;
670 InsetList::iterator it;
673 inset_iterator inset_iterator_begin() {
674 return inset_iterator(insetlist.begin());
677 inset_iterator inset_iterator_end() {
678 return inset_iterator(insetlist.end());
681 inset_iterator InsetIterator(size_type pos);