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 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
51 enum MINIPAGE_ALIGNMENT {
55 MINIPAGE_ALIGN_MIDDLE,
80 //META_PROTECTED_SEPARATOR,
106 ALGORITHM, // Bernhard, 970807
108 WIDE_FIG, // CFO-G, 971106
110 WIDE_TAB // CFO-G, 971106
114 typedef char value_type;
116 typedef std::vector<value_type> TextContainer;
118 typedef int size_type;
122 /// this konstruktor inserts the new paragraph in a list
124 LyXParagraph(LyXParagraph * par);
125 /// the destruktors removes the new paragraph from the list
129 Language const * getParLanguage(BufferParams const &) const;
131 bool isRightToLeftPar(BufferParams const &) const;
133 void ChangeLanguage(BufferParams const & bparams,
134 Language const * from, Language const * to);
136 bool isMultiLingual(BufferParams const &);
139 string String(Buffer const *, bool label);
141 string String(Buffer const *, size_type beg, size_type end);
144 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
147 void validate(LaTeXFeatures &) const;
154 void id(int id_arg) {
162 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
163 std::ostream &, TexRow & texrow,
165 std::ostream & foot, TexRow & foot_texrow,
168 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
169 std::ostream &, TexRow & texrow, bool moving_arg);
172 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
173 std::ostream &, TexRow & texrow,
174 std::ostream & foot, TexRow & foot_texrow,
177 LyXParagraph * Clone() const;
180 bool HasSameLayout(LyXParagraph const * par) const;
183 void MakeSameLayout(LyXParagraph const * par);
185 /// Is it the first par with same depth and layout?
186 bool IsFirstInSequence() const {
187 LyXParagraph const * dhook = DepthHook(GetDepth());
188 return (dhook == this
189 || dhook->GetLayout() != GetLayout()
190 || dhook->GetDepth() != GetDepth());
193 /** Check if the current paragraph is the last paragraph in a
195 int GetEndLabel(BufferParams const &) const;
197 Inset * InInset() { return inset_owner; }
199 void SetInsetOwner(Inset * i);
201 void deleteInsetsLyXText(BufferView *);
210 size_type size() const { return text.size(); }
213 text.resize(text.size());
215 void setContentsFromPar(LyXParagraph * par) {
218 void clearContents() {
223 VSpace added_space_top;
226 VSpace added_space_bottom;
232 LyXTextClass::LayoutList::size_type layout;
236 \item no footnote, closed footnote,
237 \item open footnote, where footnote
238 \item means footnote-environment
241 footnote_flag footnoteflag;
243 /// footnote, margin, fig, tab
244 footnote_kind footnotekind;
246 //@Man: the LyX- DTP-switches
258 bool pagebreak_bottom;
270 block<int, 10> counter_;
273 void setCounter(int i, int v) { counter_[i] = v; }
274 int getCounter(int i) const { return counter_[i]; }
275 void incCounter(int i) { counter_[i]++; }
277 bool start_of_appendix;
288 /* This is for the paragraph extra stuff */
294 string pextra_widthp;
296 int pextra_alignment;
300 bool pextra_start_minipage;
306 string labelwidthstring;
312 LyXParagraph * previous;
314 /* table stuff -- begin*/
317 /* table stuff -- end*/
320 InsetBibKey * bibkey; // ale970302
322 /** these function are able to hide closed footnotes
324 LyXParagraph * Next();
327 LyXParagraph * Previous();
329 LyXParagraph const * Previous() const;
331 /** these function are able to hide open and closed footnotes
333 LyXParagraph * NextAfterFootnote();
335 LyXParagraph const * NextAfterFootnote() const;
338 LyXParagraph * PreviousBeforeFootnote();
340 LyXParagraph * LastPhysicalPar();
342 LyXParagraph const * LastPhysicalPar() const;
345 LyXParagraph * FirstPhysicalPar();
347 LyXParagraph const * FirstPhysicalPar() const;
349 /// returns the physical paragraph
350 LyXParagraph * ParFromPos(size_type pos);
351 /// returns the position in the physical par
352 int PositionInParFromPos(size_type pos) const;
354 /// for the environments
355 LyXParagraph * DepthHook(int depth);
356 /// for the environments
357 LyXParagraph const * DepthHook(int depth) const;
359 int BeginningOfMainBody() const;
361 string GetLabelstring() const;
363 /// the next two functions are for the manual labels
364 string GetLabelWidthString() const;
366 void SetLabelWidthString(string const & s);
368 LyXTextClass::LayoutList::size_type GetLayout() const;
370 char GetAlign() const;
372 char GetDepth() const;
374 void SetLayout(BufferParams const &,
375 LyXTextClass::LayoutList::size_type new_layout);
377 void SetOnlyLayout(BufferParams const &,
378 LyXTextClass::LayoutList::size_type new_layout);
380 int GetFirstCounter(int i) const;
382 size_type Last() const;
384 void Erase(size_type pos);
385 /** the flag determines wether the layout should be copied
387 void BreakParagraph(BufferParams const &, size_type pos, int flag);
389 void BreakParagraphConservative(BufferParams const &, size_type pos);
390 /** Get unistantiated font setting. Returns the difference
391 between the characters font and the layoutfont.
392 This is what is stored in the fonttable
394 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
396 LyXFont GetFirstFontSettings() const;
398 /** Get fully instantiated font. If pos == -1, use the layout
399 font attached to this paragraph.
400 If pos == -2, use the label font of the layout attached here.
401 In all cases, the font is instantiated, i.e. does not have any
402 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
405 LyXFont getFont(BufferParams const &, size_type pos) const;
407 char GetChar(size_type pos);
409 char GetChar(size_type pos) const;
410 /// The position must already exist.
411 void SetChar(size_type pos, char c) {
416 void SetFont(size_type pos, LyXFont const & font);
418 string GetWord(size_type &) const;
419 /// Returns the height of the highest font in range
420 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
421 size_type endpos) const;
423 void InsertChar(size_type pos, char c);
425 void InsertInset(size_type pos, Inset * inset);
427 bool InsertInsetAllowed(Inset * inset);
429 Inset * GetInset(size_type pos);
431 Inset const * GetInset(size_type pos) const;
433 void OpenFootnote(size_type pos);
435 void CloseFootnote(size_type pos);
436 /// important for cut and paste
437 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
439 void CutIntoMinibuffer(BufferParams const &, size_type pos);
441 bool InsertFromMinibuffer(size_type pos);
444 bool IsHfill(size_type pos) const;
446 bool IsInset(size_type pos) const;
448 bool IsFloat(size_type pos) const;
450 bool IsNewline(size_type pos) const;
452 bool IsSeparator(size_type pos) const;
454 bool IsLineSeparator(size_type pos) const;
456 bool IsKomma(size_type pos) const;
457 /// Used by the spellchecker
458 bool IsLetter(size_type pos) const;
460 bool IsWord(size_type pos) const;
462 /** This one resets all layout and dtp switches but not the font
463 of the single characters
467 /** paste this paragraph with the next one
468 be carefull, this doesent make any check at all
470 void PasteParagraph(BufferParams const &);
472 /// used to remove the error messages
473 int AutoDeleteInsets();
475 /// returns -1 if inset not found
476 int GetPositionOfInset(Inset * inset) const;
478 /// ok and now some footnote functions
479 void OpenFootnotes();
482 void CloseFootnotes();
485 LyXParagraph * FirstSelfrowPar();
488 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
490 /** A paragraph following a footnote is a "dummy". A paragraph
491 with a footnote in it is stored as three paragraphs:
492 First a paragraph with the text up to the footnote, then
493 one (or more) paragraphs with the footnote, and finally
494 the a paragraph with the text after the footnote. Only the
495 first paragraph keeps information about layoutparameters, */
496 bool IsDummy() const;
498 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
499 I have to set it on each of it's elements */
501 void SetPExtraType(BufferParams const &,
502 int type, char const * width, char const * widthp);
504 void UnsetPExtraType(BufferParams const &);
507 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
510 bool linuxDocConvertChar(char c, string & sgml_string);
512 void DocBookContTableRows(Buffer const *,
513 std::ostream &, string & extra,
514 int & desc_on, size_type i,
515 int current_cell_number, int & column);
517 void SimpleDocBookOneTablePar(Buffer const *,
518 std::ostream &, string & extra,
519 int & desc_on, int depth);
528 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
531 friend struct matchIT;
534 /// used by lower_bound
536 int operator()(LyXParagraph::InsetTable const & a,
537 LyXParagraph::size_type pos) const {
540 /// used by upper_bound
542 int operator()(LyXParagraph::size_type pos,
543 LyXParagraph::InsetTable const & a) const {
547 /** A font entry covers a range of positions. Notice that the
548 entries in the list are inserted in random order.
549 I don't think it's worth the effort to implement a more effective
550 datastructure, because the number of different fonts in a paragraph
552 Nevertheless, I decided to store fontlist using a sorted vector:
553 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
554 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
555 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
556 (font_1 covers the chars 0,...,pos_1) (Dekel)
559 /// End position of paragraph this font attribute covers
561 /** Font. Interpretation of the font values:
562 If a value is LyXFont::INHERIT_*, it means that the font
563 attribute is inherited from either the layout of this
564 paragraph or, in the case of nested paragraphs, from the
565 layout in the environment one level up until completely
567 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
568 allowed in these font tables.
572 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
574 friend struct matchFT;
577 /// used by lower_bound
579 int operator()(LyXParagraph::FontTable const & a,
580 LyXParagraph::size_type pos) const {
583 /// used by upper_bound
585 int operator()(LyXParagraph::size_type pos,
586 LyXParagraph::FontTable const & a) const {
592 typedef std::vector<FontTable> FontList;
596 typedef std::vector<InsetTable> InsetList;
600 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
601 std::ostream &, TexRow & texrow,
602 std::ostream & foot, TexRow & foot_texrow,
605 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
606 std::ostream &, TexRow & texrow,
607 std::ostream & foot, TexRow & foot_texrow,
611 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
612 std::ostream &, TexRow & texrow);
614 bool TeXContTableRows(Buffer const *, BufferParams const &,
615 std::ostream &, size_type i,
616 int current_cell_number,
617 int & column, TexRow & texrow);
619 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
621 int & column, LyXFont const & font,
622 LyXLayout const & style);
624 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
625 std::ostream &, TexRow & texrow,
627 LyXFont & font, LyXFont & running_font,
628 LyXFont & basefont, bool & open_font,
629 LyXLayout const & style,
631 int & column, char const c);
635 static unsigned int paragraph_id;
637 class inset_iterator {
640 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
641 inset_iterator & operator++() {
645 Inset * operator*() { return (*it).inset; }
646 size_type getPos() {return (*it).pos; }
647 bool operator==(inset_iterator const & iter) const {
648 return it == iter.it;
650 bool operator!=(inset_iterator const & iter) const {
651 return it != iter.it;
654 InsetList::iterator it;
657 inset_iterator inset_iterator_begin() {
658 return inset_iterator(insetlist.begin());
661 inset_iterator inset_iterator_end() {
662 return inset_iterator(insetlist.end());
665 inset_iterator InsetIterator(size_type pos);