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,
81 //META_PROTECTED_SEPARATOR,
107 ALGORITHM, // Bernhard, 970807
109 WIDE_FIG, // CFO-G, 971106
111 WIDE_TAB // CFO-G, 971106
115 typedef char value_type;
117 typedef std::vector<value_type> TextContainer;
119 typedef int size_type;
123 /// this konstruktor inserts the new paragraph in a list
125 LyXParagraph(LyXParagraph * par);
126 /// the destruktors removes the new paragraph from the list
130 Language const * getParLanguage(BufferParams const &) const;
132 bool isRightToLeftPar(BufferParams const &) const;
134 void ChangeLanguage(BufferParams const & bparams,
135 Language const * from, Language const * to);
137 bool isMultiLingual(BufferParams const &);
140 string String(Buffer const *, bool label);
142 string String(Buffer const *, size_type beg, size_type end);
145 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
148 void validate(LaTeXFeatures &) const;
155 void id(int id_arg) {
163 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
164 std::ostream &, TexRow & texrow,
166 std::ostream & foot, TexRow & foot_texrow,
169 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
170 std::ostream &, TexRow & texrow, bool moving_arg);
173 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
174 std::ostream &, TexRow & texrow,
175 std::ostream & foot, TexRow & foot_texrow,
178 LyXParagraph * Clone() const;
181 bool HasSameLayout(LyXParagraph const * par) const;
184 void MakeSameLayout(LyXParagraph const * par);
186 /// Is it the first par with same depth and layout?
187 bool IsFirstInSequence() const {
188 LyXParagraph const * dhook = DepthHook(GetDepth());
189 return (dhook == this
190 || dhook->GetLayout() != GetLayout()
191 || dhook->GetDepth() != GetDepth());
194 /** Check if the current paragraph is the last paragraph in a
196 int GetEndLabel(BufferParams const &) const;
198 Inset * InInset() { return inset_owner; }
200 void SetInsetOwner(Inset * i);
202 void deleteInsetsLyXText(BufferView *);
203 void resizeInsetsLyXText(BufferView *);
212 size_type size() const { return text.size(); }
215 text.resize(text.size());
217 void setContentsFromPar(LyXParagraph * par) {
220 void clearContents() {
225 VSpace added_space_top;
228 VSpace added_space_bottom;
234 LyXTextClass::LayoutList::size_type layout;
238 \item no footnote, closed footnote,
239 \item open footnote, where footnote
240 \item means footnote-environment
243 footnote_flag footnoteflag;
245 /// footnote, margin, fig, tab
246 footnote_kind footnotekind;
248 //@Man: the LyX- DTP-switches
260 bool pagebreak_bottom;
272 block<int, 10> counter_;
275 void setCounter(int i, int v) { counter_[i] = v; }
276 int getCounter(int i) const { return counter_[i]; }
277 void incCounter(int i) { counter_[i]++; }
279 bool start_of_appendix;
290 /* This is for the paragraph extra stuff */
296 string pextra_widthp;
298 int pextra_alignment;
302 bool pextra_start_minipage;
308 string labelwidthstring;
314 LyXParagraph * previous;
316 /* table stuff -- begin*/
319 /* table stuff -- end*/
322 InsetBibKey * bibkey; // ale970302
324 /** these function are able to hide closed footnotes
326 LyXParagraph * Next();
329 LyXParagraph * Previous();
331 LyXParagraph const * Previous() const;
333 /** these function are able to hide open and closed footnotes
335 LyXParagraph * NextAfterFootnote();
337 LyXParagraph const * NextAfterFootnote() const;
340 LyXParagraph * PreviousBeforeFootnote();
342 LyXParagraph * LastPhysicalPar();
344 LyXParagraph const * LastPhysicalPar() const;
347 LyXParagraph * FirstPhysicalPar();
349 LyXParagraph const * FirstPhysicalPar() const;
351 /// returns the physical paragraph
352 LyXParagraph * ParFromPos(size_type pos);
353 /// returns the position in the physical par
354 int PositionInParFromPos(size_type pos) const;
356 /// for the environments
357 LyXParagraph * DepthHook(int depth);
358 /// for the environments
359 LyXParagraph const * DepthHook(int depth) const;
361 int BeginningOfMainBody() const;
363 string GetLabelstring() const;
365 /// the next two functions are for the manual labels
366 string GetLabelWidthString() const;
368 void SetLabelWidthString(string const & s);
370 LyXTextClass::LayoutList::size_type GetLayout() const;
372 char GetAlign() const;
374 char GetDepth() const;
376 void SetLayout(BufferParams const &,
377 LyXTextClass::LayoutList::size_type new_layout);
379 void SetOnlyLayout(BufferParams const &,
380 LyXTextClass::LayoutList::size_type new_layout);
382 int GetFirstCounter(int i) const;
384 size_type Last() const;
386 void Erase(size_type pos);
387 /** the flag determines wether the layout should be copied
389 void BreakParagraph(BufferParams const &, size_type pos, int flag);
391 void BreakParagraphConservative(BufferParams const &, size_type pos);
392 /** Get unistantiated font setting. Returns the difference
393 between the characters font and the layoutfont.
394 This is what is stored in the fonttable
396 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
398 LyXFont GetFirstFontSettings() const;
400 /** Get fully instantiated font. If pos == -1, use the layout
401 font attached to this paragraph.
402 If pos == -2, use the label font of the layout attached here.
403 In all cases, the font is instantiated, i.e. does not have any
404 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
407 LyXFont getFont(BufferParams const &, size_type pos) const;
409 char GetChar(size_type pos);
411 char GetChar(size_type pos) const;
412 /// The position must already exist.
413 void SetChar(size_type pos, char c) {
418 void SetFont(size_type pos, LyXFont const & font);
420 string GetWord(size_type &) const;
421 /// Returns the height of the highest font in range
422 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
423 size_type endpos) const;
425 void InsertChar(size_type pos, char c);
427 void InsertChar(size_type pos, char c, LyXFont const &);
429 void InsertInset(size_type pos, Inset * inset);
431 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
433 bool InsertInsetAllowed(Inset * inset);
435 Inset * GetInset(size_type pos);
437 Inset const * GetInset(size_type pos) const;
439 void OpenFootnote(size_type pos);
441 void CloseFootnote(size_type pos);
442 /// important for cut and paste
443 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
445 void CutIntoMinibuffer(BufferParams const &, size_type pos);
447 bool InsertFromMinibuffer(size_type pos);
450 bool IsHfill(size_type pos) const;
452 bool IsInset(size_type pos) const;
454 bool IsFloat(size_type pos) const;
456 bool IsNewline(size_type pos) const;
458 bool IsSeparator(size_type pos) const;
460 bool IsLineSeparator(size_type pos) const;
462 bool IsKomma(size_type pos) const;
463 /// Used by the spellchecker
464 bool IsLetter(size_type pos) const;
466 bool IsWord(size_type pos) const;
468 /** This one resets all layout and dtp switches but not the font
469 of the single characters
473 /** paste this paragraph with the next one
474 be carefull, this doesent make any check at all
476 void PasteParagraph(BufferParams const &);
478 /// used to remove the error messages
479 int AutoDeleteInsets();
481 /// returns -1 if inset not found
482 int GetPositionOfInset(Inset * inset) const;
484 /// ok and now some footnote functions
485 void OpenFootnotes();
488 void CloseFootnotes();
491 LyXParagraph * FirstSelfrowPar();
494 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
496 /** A paragraph following a footnote is a "dummy". A paragraph
497 with a footnote in it is stored as three paragraphs:
498 First a paragraph with the text up to the footnote, then
499 one (or more) paragraphs with the footnote, and finally
500 the a paragraph with the text after the footnote. Only the
501 first paragraph keeps information about layoutparameters, */
502 bool IsDummy() const;
504 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
505 I have to set it on each of it's elements */
507 void SetPExtraType(BufferParams const &,
508 int type, char const * width, char const * widthp);
510 void UnsetPExtraType(BufferParams const &);
512 bool linuxDocConvertChar(char c, string & sgml_string);
514 void DocBookContTableRows(Buffer const *,
515 std::ostream &, string & extra,
516 int & desc_on, size_type i,
517 int current_cell_number, int & column);
519 void SimpleDocBookOneTablePar(Buffer const *,
520 std::ostream &, string & extra,
521 int & desc_on, int depth);
530 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
533 friend struct matchIT;
536 /// used by lower_bound
538 int operator()(LyXParagraph::InsetTable const & a,
539 LyXParagraph::size_type pos) const {
542 /// used by upper_bound
544 int operator()(LyXParagraph::size_type pos,
545 LyXParagraph::InsetTable const & a) const {
549 /** A font entry covers a range of positions. Notice that the
550 entries in the list are inserted in random order.
551 I don't think it's worth the effort to implement a more effective
552 datastructure, because the number of different fonts in a paragraph
554 Nevertheless, I decided to store fontlist using a sorted vector:
555 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
556 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
557 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
558 (font_1 covers the chars 0,...,pos_1) (Dekel)
561 /// End position of paragraph this font attribute covers
563 /** Font. Interpretation of the font values:
564 If a value is LyXFont::INHERIT_*, it means that the font
565 attribute is inherited from either the layout of this
566 paragraph or, in the case of nested paragraphs, from the
567 layout in the environment one level up until completely
569 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
570 allowed in these font tables.
574 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
576 friend struct matchFT;
579 /// used by lower_bound
581 int operator()(LyXParagraph::FontTable const & a,
582 LyXParagraph::size_type pos) const {
585 /// used by upper_bound
587 int operator()(LyXParagraph::size_type pos,
588 LyXParagraph::FontTable const & a) const {
594 typedef std::vector<FontTable> FontList;
598 typedef std::vector<InsetTable> InsetList;
602 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
603 std::ostream &, TexRow & texrow,
604 std::ostream & foot, TexRow & foot_texrow,
607 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
608 std::ostream &, TexRow & texrow,
609 std::ostream & foot, TexRow & foot_texrow,
613 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
614 std::ostream &, TexRow & texrow);
616 bool TeXContTableRows(Buffer const *, BufferParams const &,
617 std::ostream &, size_type i,
618 int current_cell_number,
619 int & column, TexRow & texrow);
621 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
623 int & column, LyXFont const & font,
624 LyXLayout const & style);
626 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
627 std::ostream &, TexRow & texrow,
629 LyXFont & font, LyXFont & running_font,
630 LyXFont & basefont, bool & open_font,
631 LyXLayout const & style,
633 int & column, char const c);
637 static unsigned int paragraph_id;
639 class inset_iterator {
642 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
643 inset_iterator & operator++() {
647 Inset * operator*() { return (*it).inset; }
648 size_type getPos() {return (*it).pos; }
649 bool operator==(inset_iterator const & iter) const {
650 return it == iter.it;
652 bool operator!=(inset_iterator const & iter) const {
653 return it != iter.it;
656 InsetList::iterator it;
659 inset_iterator inset_iterator_begin() {
660 return inset_iterator(insetlist.begin());
663 inset_iterator inset_iterator_end() {
664 return inset_iterator(insetlist.end());
667 inset_iterator InsetIterator(size_type pos);