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 *);
211 size_type size() const { return text.size(); }
214 text.resize(text.size());
216 void setContentsFromPar(LyXParagraph * par) {
219 void clearContents() {
224 VSpace added_space_top;
227 VSpace added_space_bottom;
233 LyXTextClass::LayoutList::size_type layout;
237 \item no footnote, closed footnote,
238 \item open footnote, where footnote
239 \item means footnote-environment
242 footnote_flag footnoteflag;
244 /// footnote, margin, fig, tab
245 footnote_kind footnotekind;
247 //@Man: the LyX- DTP-switches
259 bool pagebreak_bottom;
271 block<int, 10> counter_;
274 void setCounter(int i, int v) { counter_[i] = v; }
275 int getCounter(int i) const { return counter_[i]; }
276 void incCounter(int i) { counter_[i]++; }
278 bool start_of_appendix;
289 /* This is for the paragraph extra stuff */
295 string pextra_widthp;
297 int pextra_alignment;
301 bool pextra_start_minipage;
307 string labelwidthstring;
313 LyXParagraph * previous;
315 /* table stuff -- begin*/
318 /* table stuff -- end*/
321 InsetBibKey * bibkey; // ale970302
323 /** these function are able to hide closed footnotes
325 LyXParagraph * Next();
328 LyXParagraph * Previous();
330 LyXParagraph const * Previous() const;
332 /** these function are able to hide open and closed footnotes
334 LyXParagraph * NextAfterFootnote();
336 LyXParagraph const * NextAfterFootnote() const;
339 LyXParagraph * PreviousBeforeFootnote();
341 LyXParagraph * LastPhysicalPar();
343 LyXParagraph const * LastPhysicalPar() const;
346 LyXParagraph * FirstPhysicalPar();
348 LyXParagraph const * FirstPhysicalPar() const;
350 /// returns the physical paragraph
351 LyXParagraph * ParFromPos(size_type pos);
352 /// returns the position in the physical par
353 int PositionInParFromPos(size_type pos) const;
355 /// for the environments
356 LyXParagraph * DepthHook(int depth);
357 /// for the environments
358 LyXParagraph const * DepthHook(int depth) const;
360 int BeginningOfMainBody() const;
362 string GetLabelstring() const;
364 /// the next two functions are for the manual labels
365 string GetLabelWidthString() const;
367 void SetLabelWidthString(string const & s);
369 LyXTextClass::LayoutList::size_type GetLayout() const;
371 char GetAlign() const;
373 char GetDepth() const;
375 void SetLayout(BufferParams const &,
376 LyXTextClass::LayoutList::size_type new_layout);
378 void SetOnlyLayout(BufferParams const &,
379 LyXTextClass::LayoutList::size_type new_layout);
381 int GetFirstCounter(int i) const;
383 size_type Last() const;
385 void Erase(size_type pos);
386 /** the flag determines wether the layout should be copied
388 void BreakParagraph(BufferParams const &, size_type pos, int flag);
390 void BreakParagraphConservative(BufferParams const &, size_type pos);
391 /** Get unistantiated font setting. Returns the difference
392 between the characters font and the layoutfont.
393 This is what is stored in the fonttable
395 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
397 LyXFont GetFirstFontSettings() const;
399 /** Get fully instantiated font. If pos == -1, use the layout
400 font attached to this paragraph.
401 If pos == -2, use the label font of the layout attached here.
402 In all cases, the font is instantiated, i.e. does not have any
403 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
406 LyXFont getFont(BufferParams const &, size_type pos) const;
408 char GetChar(size_type pos);
410 char GetChar(size_type pos) const;
411 /// The position must already exist.
412 void SetChar(size_type pos, char c) {
417 void SetFont(size_type pos, LyXFont const & font);
419 string GetWord(size_type &) const;
420 /// Returns the height of the highest font in range
421 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
422 size_type endpos) const;
424 void InsertChar(size_type pos, char c);
426 void InsertChar(size_type pos, char c, LyXFont const &);
428 void InsertInset(size_type pos, Inset * inset);
430 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
432 bool InsertInsetAllowed(Inset * inset);
434 Inset * GetInset(size_type pos);
436 Inset const * GetInset(size_type pos) const;
438 void OpenFootnote(size_type pos);
440 void CloseFootnote(size_type pos);
441 /// important for cut and paste
442 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
444 void CutIntoMinibuffer(BufferParams const &, size_type pos);
446 bool InsertFromMinibuffer(size_type pos);
449 bool IsHfill(size_type pos) const;
451 bool IsInset(size_type pos) const;
453 bool IsFloat(size_type pos) const;
455 bool IsNewline(size_type pos) const;
457 bool IsSeparator(size_type pos) const;
459 bool IsLineSeparator(size_type pos) const;
461 bool IsKomma(size_type pos) const;
462 /// Used by the spellchecker
463 bool IsLetter(size_type pos) const;
465 bool IsWord(size_type pos) const;
467 /** This one resets all layout and dtp switches but not the font
468 of the single characters
472 /** paste this paragraph with the next one
473 be carefull, this doesent make any check at all
475 void PasteParagraph(BufferParams const &);
477 /// used to remove the error messages
478 int AutoDeleteInsets();
480 /// returns -1 if inset not found
481 int GetPositionOfInset(Inset * inset) const;
483 /// ok and now some footnote functions
484 void OpenFootnotes();
487 void CloseFootnotes();
490 LyXParagraph * FirstSelfrowPar();
493 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
495 /** A paragraph following a footnote is a "dummy". A paragraph
496 with a footnote in it is stored as three paragraphs:
497 First a paragraph with the text up to the footnote, then
498 one (or more) paragraphs with the footnote, and finally
499 the a paragraph with the text after the footnote. Only the
500 first paragraph keeps information about layoutparameters, */
501 bool IsDummy() const;
503 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
504 I have to set it on each of it's elements */
506 void SetPExtraType(BufferParams const &,
507 int type, char const * width, char const * widthp);
509 void UnsetPExtraType(BufferParams const &);
511 bool linuxDocConvertChar(char c, string & sgml_string);
513 void DocBookContTableRows(Buffer const *,
514 std::ostream &, string & extra,
515 int & desc_on, size_type i,
516 int current_cell_number, int & column);
518 void SimpleDocBookOneTablePar(Buffer const *,
519 std::ostream &, string & extra,
520 int & desc_on, int depth);
529 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
532 friend struct matchIT;
535 /// used by lower_bound
537 int operator()(LyXParagraph::InsetTable const & a,
538 LyXParagraph::size_type pos) const {
541 /// used by upper_bound
543 int operator()(LyXParagraph::size_type pos,
544 LyXParagraph::InsetTable const & a) const {
548 /** A font entry covers a range of positions. Notice that the
549 entries in the list are inserted in random order.
550 I don't think it's worth the effort to implement a more effective
551 datastructure, because the number of different fonts in a paragraph
553 Nevertheless, I decided to store fontlist using a sorted vector:
554 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
555 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
556 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
557 (font_1 covers the chars 0,...,pos_1) (Dekel)
560 /// End position of paragraph this font attribute covers
562 /** Font. Interpretation of the font values:
563 If a value is LyXFont::INHERIT_*, it means that the font
564 attribute is inherited from either the layout of this
565 paragraph or, in the case of nested paragraphs, from the
566 layout in the environment one level up until completely
568 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
569 allowed in these font tables.
573 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
575 friend struct matchFT;
578 /// used by lower_bound
580 int operator()(LyXParagraph::FontTable const & a,
581 LyXParagraph::size_type pos) const {
584 /// used by upper_bound
586 int operator()(LyXParagraph::size_type pos,
587 LyXParagraph::FontTable const & a) const {
593 typedef std::vector<FontTable> FontList;
597 typedef std::vector<InsetTable> InsetList;
601 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
602 std::ostream &, TexRow & texrow,
603 std::ostream & foot, TexRow & foot_texrow,
606 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
607 std::ostream &, TexRow & texrow,
608 std::ostream & foot, TexRow & foot_texrow,
612 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
613 std::ostream &, TexRow & texrow);
615 bool TeXContTableRows(Buffer const *, BufferParams const &,
616 std::ostream &, size_type i,
617 int current_cell_number,
618 int & column, TexRow & 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, char const c);
636 static unsigned int paragraph_id;
638 class inset_iterator {
641 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
642 inset_iterator & operator++() {
646 Inset * operator*() { return (*it).inset; }
647 size_type getPos() {return (*it).pos; }
648 bool operator==(inset_iterator const & iter) const {
649 return it == iter.it;
651 bool operator!=(inset_iterator const & iter) const {
652 return it != iter.it;
655 InsetList::iterator it;
658 inset_iterator inset_iterator_begin() {
659 return inset_iterator(insetlist.begin());
662 inset_iterator inset_iterator_end() {
663 return inset_iterator(insetlist.end());
666 inset_iterator InsetIterator(size_type pos);