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 <boost/array.hpp>
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 /* This should be TextContainer::size_type, but we need
128 signed values for now.
130 typedef TextContainer::difference_type size_type;
134 /// this constructor inserts the new paragraph in a list
136 LyXParagraph(LyXParagraph * par);
137 /// the destructor removes the new paragraph from the list
141 Language const * getParLanguage(BufferParams const &) const;
143 bool isRightToLeftPar(BufferParams const &) const;
145 void ChangeLanguage(BufferParams const & bparams,
146 Language const * from, Language const * to);
148 bool isMultiLingual(BufferParams const &);
151 string const String(Buffer const *, bool label);
153 string const String(Buffer const *, size_type beg, size_type end);
156 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
159 void validate(LaTeXFeatures &) const;
166 void id(int id_arg) {
174 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
175 std::ostream &, TexRow & texrow,
179 std::ostream & foot, TexRow & foot_texrow,
184 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
185 std::ostream &, TexRow & texrow, bool moving_arg);
188 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
189 std::ostream &, TexRow & texrow
191 ,std::ostream & foot, TexRow & foot_texrow,
196 LyXParagraph * Clone() const;
199 bool HasSameLayout(LyXParagraph const * par) const;
202 void MakeSameLayout(LyXParagraph const * par);
204 /// Is it the first par with same depth and layout?
205 bool IsFirstInSequence() const {
206 LyXParagraph const * dhook = DepthHook(GetDepth());
207 return (dhook == this
208 || dhook->GetLayout() != GetLayout()
209 || dhook->GetDepth() != GetDepth());
212 /** Check if the current paragraph is the last paragraph in a
214 int GetEndLabel(BufferParams const &) const;
216 Inset * InInset() { return inset_owner; }
218 void SetInsetOwner(Inset * i);
220 void deleteInsetsLyXText(BufferView *);
222 void resizeInsetsLyXText(BufferView *);
231 size_type size() const { return text.size(); }
234 text.resize(text.size());
237 void setContentsFromPar(LyXParagraph * par) {
241 void clearContents() {
246 VSpace added_space_top;
249 VSpace added_space_bottom;
255 LyXTextClass::LayoutList::size_type layout;
259 \item no footnote, closed footnote,
260 \item open footnote, where footnote
261 \item means footnote-environment
264 footnote_flag footnoteflag;
266 /// footnote, margin, fig, tab
267 footnote_kind footnotekind;
279 bool pagebreak_bottom;
292 array<int, 10> counter_;
295 void setCounter(int i, int v) { counter_[i] = v; }
297 int getCounter(int i) const { return counter_[i]; }
299 void incCounter(int i) { counter_[i]++; }
301 bool start_of_appendix;
312 /* This is for the paragraph extra stuff */
318 string pextra_widthp;
320 int pextra_alignment;
324 bool pextra_start_minipage;
330 string labelwidthstring;
335 LyXParagraph * previous;
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;
367 /// returns the physical paragraph
368 LyXParagraph * ParFromPos(size_type pos);
369 /// returns the position in the physical par
370 int PositionInParFromPos(size_type pos) const;
373 /// for the environments
374 LyXParagraph * DepthHook(int depth);
375 /// for the environments
376 LyXParagraph const * DepthHook(int depth) const;
378 int BeginningOfMainBody() const;
380 string const & GetLabelstring() const;
382 /// the next two functions are for the manual labels
383 string const GetLabelWidthString() const;
385 void SetLabelWidthString(string const & s);
387 LyXTextClass::LayoutList::size_type GetLayout() const;
389 char GetAlign() const;
391 char GetDepth() const;
393 void SetLayout(BufferParams const &,
394 LyXTextClass::LayoutList::size_type new_layout);
396 void SetOnlyLayout(BufferParams const &,
397 LyXTextClass::LayoutList::size_type new_layout);
399 int GetFirstCounter(int i) const;
401 size_type Last() const;
403 void Erase(size_type pos);
404 /** the flag determines wether the layout should be copied
406 void BreakParagraph(BufferParams const &, size_type pos, int flag);
408 void BreakParagraphConservative(BufferParams const &, size_type pos);
409 /** Get unistantiated font setting. Returns the difference
410 between the characters font and the layoutfont.
411 This is what is stored in the fonttable
414 GetFontSettings(BufferParams const &, size_type pos) const;
416 LyXFont const 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 const getFont(BufferParams const &, size_type pos) const;
427 value_type GetChar(size_type pos) const;
428 /// The position must already exist.
429 void SetChar(size_type pos, value_type c) {
434 void SetFont(size_type pos, LyXFont const & font);
436 string const GetWord(size_type &) const;
437 /// Returns the height of the highest font in range
438 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
439 size_type endpos) const;
441 void InsertChar(size_type pos, value_type c);
443 void InsertChar(size_type pos, value_type c, LyXFont const &);
445 void InsertInset(size_type pos, Inset * inset);
447 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
449 bool InsertInsetAllowed(Inset * inset);
451 Inset * GetInset(size_type pos);
453 Inset const * GetInset(size_type pos) const;
456 void OpenFootnote(size_type pos);
458 void CloseFootnote(size_type pos);
460 /// important for cut and paste
461 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
463 void CutIntoMinibuffer(BufferParams const &, size_type pos);
465 bool InsertFromMinibuffer(size_type pos);
468 bool IsHfill(size_type pos) const;
470 bool IsInset(size_type pos) const;
473 bool IsFloat(size_type pos) const;
476 bool IsNewline(size_type pos) const;
478 bool IsSeparator(size_type pos) const;
480 bool IsLineSeparator(size_type pos) const;
482 bool IsKomma(size_type pos) const;
483 /// Used by the spellchecker
484 bool IsLetter(size_type pos) const;
486 bool IsWord(size_type pos) const;
488 /** This one resets all layout and dtp switches but not the font
489 of the single characters
493 /** paste this paragraph with the next one
494 be carefull, this doesent make any check at all
496 void PasteParagraph(BufferParams const &);
498 /// used to remove the error messages
499 int AutoDeleteInsets();
501 /// returns -1 if inset not found
502 int GetPositionOfInset(Inset * inset) const;
505 /// ok and now some footnote functions
506 void OpenFootnotes();
509 void CloseFootnotes();
511 LyXParagraph * FirstSelfrowPar();
515 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
518 /** A paragraph following a footnote is a "dummy". A paragraph
519 with a footnote in it is stored as three paragraphs:
520 First a paragraph with the text up to the footnote, then
521 one (or more) paragraphs with the footnote, and finally
522 the a paragraph with the text after the footnote. Only the
523 first paragraph keeps information about layoutparameters, */
524 bool IsDummy() const;
526 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
527 I have to set it on each of it's elements */
529 void SetPExtraType(BufferParams const &, int type,
530 string const & width, string const & widthp);
532 void UnsetPExtraType(BufferParams const &);
534 bool linuxDocConvertChar(char c, string & sgml_string);
543 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
546 friend struct matchIT;
549 /// used by lower_bound and upper_bound
551 int operator()(LyXParagraph::InsetTable const & a,
552 LyXParagraph::InsetTable const & b) const {
553 return a.pos < b.pos;
556 /** A font entry covers a range of positions. Notice that the
557 entries in the list are inserted in random order.
558 I don't think it's worth the effort to implement a more effective
559 datastructure, because the number of different fonts in a paragraph
561 Nevertheless, I decided to store fontlist using a sorted vector:
562 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
563 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
564 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
565 (font_1 covers the chars 0,...,pos_1) (Dekel)
568 /// End position of paragraph this font attribute covers
570 /** Font. Interpretation of the font values:
571 If a value is LyXFont::INHERIT_*, it means that the font
572 attribute is inherited from either the layout of this
573 paragraph or, in the case of nested paragraphs, from the
574 layout in the environment one level up until completely
576 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
577 allowed in these font tables.
581 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
584 friend struct matchFT;
587 /// used by lower_bound and upper_bound
589 int operator()(LyXParagraph::FontTable const & a,
590 LyXParagraph::FontTable const & b) const {
591 return a.pos < b.pos;
596 typedef std::vector<FontTable> FontList;
600 typedef std::vector<InsetTable> InsetList;
604 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
605 std::ostream &, TexRow & texrow
607 ,std::ostream & foot, TexRow & foot_texrow,
613 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
614 std::ostream &, TexRow & texrow,
615 std::ostream & foot, TexRow & foot_texrow,
620 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
622 int & column, LyXFont const & font,
623 LyXLayout const & style);
625 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
626 std::ostream &, TexRow & texrow,
628 LyXFont & font, LyXFont & running_font,
629 LyXFont & basefont, bool & open_font,
630 LyXLayout const & style,
632 int & column, value_type const c);
636 static unsigned int paragraph_id;
639 class inset_iterator {
644 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
646 inset_iterator & operator++() {
651 Inset * operator*() { return (*it).inset; }
653 size_type getPos() const {return (*it).pos; }
655 bool operator==(inset_iterator const & iter) const {
656 return it == iter.it;
659 bool operator!=(inset_iterator const & iter) const {
660 return it != iter.it;
664 InsetList::iterator it;
667 inset_iterator inset_iterator_begin() {
668 return inset_iterator(insetlist.begin());
671 inset_iterator inset_iterator_end() {
672 return inset_iterator(insetlist.end());
675 inset_iterator InsetIterator(size_type pos);