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());
218 void setContentsFromPar(LyXParagraph * par) {
222 void clearContents() {
227 VSpace added_space_top;
230 VSpace added_space_bottom;
236 LyXTextClass::LayoutList::size_type layout;
240 \item no footnote, closed footnote,
241 \item open footnote, where footnote
242 \item means footnote-environment
245 footnote_flag footnoteflag;
247 /// footnote, margin, fig, tab
248 footnote_kind footnotekind;
250 //@Man: the LyX- DTP-switches
262 bool pagebreak_bottom;
274 block<int, 10> counter_;
277 void setCounter(int i, int v) { counter_[i] = v; }
278 int getCounter(int i) const { return counter_[i]; }
279 void incCounter(int i) { counter_[i]++; }
281 bool start_of_appendix;
292 /* This is for the paragraph extra stuff */
298 string pextra_widthp;
300 int pextra_alignment;
304 bool pextra_start_minipage;
310 string labelwidthstring;
316 LyXParagraph * previous;
318 /* table stuff -- begin*/
321 /* table stuff -- end*/
324 InsetBibKey * bibkey; // ale970302
326 /** these function are able to hide closed footnotes
328 LyXParagraph * Next();
331 LyXParagraph * Previous();
333 LyXParagraph const * Previous() const;
335 /** these function are able to hide open and closed footnotes
337 LyXParagraph * NextAfterFootnote();
339 LyXParagraph const * NextAfterFootnote() const;
342 LyXParagraph * PreviousBeforeFootnote();
344 LyXParagraph * LastPhysicalPar();
346 LyXParagraph const * LastPhysicalPar() const;
349 LyXParagraph * FirstPhysicalPar();
351 LyXParagraph const * FirstPhysicalPar() const;
353 /// returns the physical paragraph
354 LyXParagraph * ParFromPos(size_type pos);
355 /// returns the position in the physical par
356 int PositionInParFromPos(size_type pos) const;
358 /// for the environments
359 LyXParagraph * DepthHook(int depth);
360 /// for the environments
361 LyXParagraph const * DepthHook(int depth) const;
363 int BeginningOfMainBody() const;
365 string GetLabelstring() const;
367 /// the next two functions are for the manual labels
368 string GetLabelWidthString() const;
370 void SetLabelWidthString(string const & s);
372 LyXTextClass::LayoutList::size_type GetLayout() const;
374 char GetAlign() const;
376 char GetDepth() const;
378 void SetLayout(BufferParams const &,
379 LyXTextClass::LayoutList::size_type new_layout);
381 void SetOnlyLayout(BufferParams const &,
382 LyXTextClass::LayoutList::size_type new_layout);
384 int GetFirstCounter(int i) const;
386 size_type Last() const;
388 void Erase(size_type pos);
389 /** the flag determines wether the layout should be copied
391 void BreakParagraph(BufferParams const &, size_type pos, int flag);
393 void BreakParagraphConservative(BufferParams const &, size_type pos);
394 /** Get unistantiated font setting. Returns the difference
395 between the characters font and the layoutfont.
396 This is what is stored in the fonttable
398 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
400 LyXFont GetFirstFontSettings() const;
402 /** Get fully instantiated font. If pos == -1, use the layout
403 font attached to this paragraph.
404 If pos == -2, use the label font of the layout attached here.
405 In all cases, the font is instantiated, i.e. does not have any
406 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
409 LyXFont getFont(BufferParams const &, size_type pos) const;
411 value_type GetChar(size_type pos);
413 value_type GetChar(size_type pos) const;
414 /// The position must already exist.
415 void SetChar(size_type pos, value_type c) {
420 void SetFont(size_type pos, LyXFont const & font);
422 string GetWord(size_type &) const;
423 /// Returns the height of the highest font in range
424 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
425 size_type endpos) const;
427 void InsertChar(size_type pos, value_type c);
429 void InsertChar(size_type pos, value_type c, LyXFont const &);
431 void InsertInset(size_type pos, Inset * inset);
433 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
435 bool InsertInsetAllowed(Inset * inset);
437 Inset * GetInset(size_type pos);
439 Inset const * GetInset(size_type pos) const;
441 void OpenFootnote(size_type pos);
443 void CloseFootnote(size_type pos);
444 /// important for cut and paste
445 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
447 void CutIntoMinibuffer(BufferParams const &, size_type pos);
449 bool InsertFromMinibuffer(size_type pos);
452 bool IsHfill(size_type pos) const;
454 bool IsInset(size_type pos) const;
456 bool IsFloat(size_type pos) const;
458 bool IsNewline(size_type pos) const;
460 bool IsSeparator(size_type pos) const;
462 bool IsLineSeparator(size_type pos) const;
464 bool IsKomma(size_type pos) const;
465 /// Used by the spellchecker
466 bool IsLetter(size_type pos) const;
468 bool IsWord(size_type pos) const;
470 /** This one resets all layout and dtp switches but not the font
471 of the single characters
475 /** paste this paragraph with the next one
476 be carefull, this doesent make any check at all
478 void PasteParagraph(BufferParams const &);
480 /// used to remove the error messages
481 int AutoDeleteInsets();
483 /// returns -1 if inset not found
484 int GetPositionOfInset(Inset * inset) const;
486 /// ok and now some footnote functions
487 void OpenFootnotes();
490 void CloseFootnotes();
493 LyXParagraph * FirstSelfrowPar();
496 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
498 /** A paragraph following a footnote is a "dummy". A paragraph
499 with a footnote in it is stored as three paragraphs:
500 First a paragraph with the text up to the footnote, then
501 one (or more) paragraphs with the footnote, and finally
502 the a paragraph with the text after the footnote. Only the
503 first paragraph keeps information about layoutparameters, */
504 bool IsDummy() const;
506 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
507 I have to set it on each of it's elements */
509 void SetPExtraType(BufferParams const &,
510 int type, char const * width, char const * widthp);
512 void UnsetPExtraType(BufferParams const &);
514 bool linuxDocConvertChar(char c, string & sgml_string);
516 void DocBookContTableRows(Buffer const *,
517 std::ostream &, string & extra,
518 int & desc_on, size_type i,
519 int current_cell_number, int & column);
521 void SimpleDocBookOneTablePar(Buffer const *,
522 std::ostream &, string & extra,
523 int & desc_on, int depth);
532 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
535 friend struct matchIT;
538 /// used by lower_bound and upper_bound
540 int operator()(LyXParagraph::InsetTable const & a,
541 LyXParagraph::InsetTable const & b) const {
542 return a.pos < b.pos;
545 /** A font entry covers a range of positions. Notice that the
546 entries in the list are inserted in random order.
547 I don't think it's worth the effort to implement a more effective
548 datastructure, because the number of different fonts in a paragraph
550 Nevertheless, I decided to store fontlist using a sorted vector:
551 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
552 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
553 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
554 (font_1 covers the chars 0,...,pos_1) (Dekel)
557 /// End position of paragraph this font attribute covers
559 /** Font. Interpretation of the font values:
560 If a value is LyXFont::INHERIT_*, it means that the font
561 attribute is inherited from either the layout of this
562 paragraph or, in the case of nested paragraphs, from the
563 layout in the environment one level up until completely
565 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
566 allowed in these font tables.
570 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
572 friend struct matchFT;
575 /// used by lower_bound and upper_bound
577 int operator()(LyXParagraph::FontTable const & a,
578 LyXParagraph::FontTable const & b) const {
579 return a.pos < b.pos;
584 typedef std::vector<FontTable> FontList;
588 typedef std::vector<InsetTable> InsetList;
592 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
593 std::ostream &, TexRow & texrow,
594 std::ostream & foot, TexRow & foot_texrow,
597 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
598 std::ostream &, TexRow & texrow,
599 std::ostream & foot, TexRow & foot_texrow,
603 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
604 std::ostream &, TexRow & texrow);
606 bool TeXContTableRows(Buffer const *, BufferParams const &,
607 std::ostream &, size_type i,
608 int current_cell_number,
609 int & column, TexRow & texrow);
611 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
613 int & column, LyXFont const & font,
614 LyXLayout const & style);
616 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
617 std::ostream &, TexRow & texrow,
619 LyXFont & font, LyXFont & running_font,
620 LyXFont & basefont, bool & open_font,
621 LyXLayout const & style,
623 int & column, value_type const c);
627 static unsigned int paragraph_id;
629 class inset_iterator {
632 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
633 inset_iterator & operator++() {
637 Inset * operator*() { return (*it).inset; }
638 size_type getPos() {return (*it).pos; }
639 bool operator==(inset_iterator const & iter) const {
640 return it == iter.it;
642 bool operator!=(inset_iterator const & iter) const {
643 return it != iter.it;
646 InsetList::iterator it;
649 inset_iterator inset_iterator_begin() {
650 return inset_iterator(insetlist.begin());
653 inset_iterator inset_iterator_end() {
654 return inset_iterator(insetlist.end());
657 inset_iterator InsetIterator(size_type pos);