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"
38 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
53 enum MINIPAGE_ALIGNMENT {
57 MINIPAGE_ALIGN_MIDDLE,
83 //META_PROTECTED_SEPARATOR,
109 ALGORITHM, // Bernhard, 970807
111 WIDE_FIG, // CFO-G, 971106
113 WIDE_TAB // CFO-G, 971106
117 typedef char value_type;
119 typedef std::vector<value_type> TextContainer;
121 typedef int size_type;
125 /// this konstruktor inserts the new paragraph in a list
127 LyXParagraph(LyXParagraph * par);
128 /// the destruktors removes the new paragraph from the list
132 Language const * getParLanguage(BufferParams const &) const;
134 bool isRightToLeftPar(BufferParams const &) const;
136 void ChangeLanguage(BufferParams const & bparams,
137 Language const * from, Language const * to);
139 bool isMultiLingual(BufferParams const &);
142 string String(Buffer const *, bool label);
144 string String(Buffer const *, size_type beg, size_type end);
147 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
150 void validate(LaTeXFeatures &) const;
157 void id(int id_arg) {
165 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
166 std::ostream &, TexRow & texrow,
168 std::ostream & foot, TexRow & foot_texrow,
171 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
172 std::ostream &, TexRow & texrow, bool moving_arg);
175 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
176 std::ostream &, TexRow & texrow,
177 std::ostream & foot, TexRow & foot_texrow,
180 LyXParagraph * Clone() const;
183 bool HasSameLayout(LyXParagraph const * par) const;
186 void MakeSameLayout(LyXParagraph const * par);
188 /// Is it the first par with same depth and layout?
189 bool IsFirstInSequence() const {
190 LyXParagraph const * dhook = DepthHook(GetDepth());
191 return (dhook == this
192 || dhook->GetLayout() != GetLayout()
193 || dhook->GetDepth() != GetDepth());
196 /** Check if the current paragraph is the last paragraph in a
198 int GetEndLabel(BufferParams const &) const;
200 Inset * InInset() { return inset_owner; }
202 void SetInsetOwner(Inset * i);
204 void deleteInsetsLyXText(BufferView *);
213 size_type size() const { return text.size(); }
216 text.resize(text.size());
218 void setContentsFromPar(LyXParagraph * par) {
221 void clearContents() {
226 VSpace added_space_top;
229 VSpace added_space_bottom;
235 LyXTextClass::LayoutList::size_type layout;
239 \item no footnote, closed footnote,
240 \item open footnote, where footnote
241 \item means footnote-environment
244 footnote_flag footnoteflag;
246 /// footnote, margin, fig, tab
247 footnote_kind footnotekind;
249 //@Man: the LyX- DTP-switches
261 bool pagebreak_bottom;
273 block<int, 10> counter_;
276 void setCounter(int i, int v) { counter_[i] = v; }
277 int getCounter(int i) const { return counter_[i]; }
278 void incCounter(int i) { counter_[i]++; }
280 bool start_of_appendix;
291 /* This is for the paragraph extra stuff */
297 string pextra_widthp;
299 int pextra_alignment;
303 bool pextra_start_minipage;
309 string labelwidthstring;
315 LyXParagraph * previous;
317 /* table stuff -- begin*/
320 /* table stuff -- end*/
323 InsetBibKey * bibkey; // ale970302
325 /** these function are able to hide closed footnotes
327 LyXParagraph * Next();
330 LyXParagraph * Previous();
332 LyXParagraph const * Previous() const;
334 /** these function are able to hide open and closed footnotes
336 LyXParagraph * NextAfterFootnote();
338 LyXParagraph const * NextAfterFootnote() const;
341 LyXParagraph * PreviousBeforeFootnote();
343 LyXParagraph * LastPhysicalPar();
345 LyXParagraph const * LastPhysicalPar() const;
348 LyXParagraph * FirstPhysicalPar();
350 LyXParagraph const * FirstPhysicalPar() const;
352 /// returns the physical paragraph
353 LyXParagraph * ParFromPos(size_type pos);
354 /// returns the position in the physical par
355 int PositionInParFromPos(size_type pos) const;
357 /// for the environments
358 LyXParagraph * DepthHook(int depth);
359 /// for the environments
360 LyXParagraph const * DepthHook(int depth) const;
362 int BeginningOfMainBody() const;
364 string GetLabelstring() const;
366 /// the next two functions are for the manual labels
367 string GetLabelWidthString() const;
369 void SetLabelWidthString(string const & s);
371 LyXTextClass::LayoutList::size_type GetLayout() const;
373 char GetAlign() const;
375 char GetDepth() const;
377 void SetLayout(BufferParams const &,
378 LyXTextClass::LayoutList::size_type new_layout);
380 void SetOnlyLayout(BufferParams const &,
381 LyXTextClass::LayoutList::size_type new_layout);
383 int GetFirstCounter(int i) const;
385 size_type Last() const;
387 void Erase(size_type pos);
388 /** the flag determines wether the layout should be copied
390 void BreakParagraph(BufferParams const &, size_type pos, int flag);
392 void BreakParagraphConservative(BufferParams const &, size_type pos);
393 /** Get unistantiated font setting. Returns the difference
394 between the characters font and the layoutfont.
395 This is what is stored in the fonttable
397 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
399 LyXFont GetFirstFontSettings() const;
401 /** Get fully instantiated font. If pos == -1, use the layout
402 font attached to this paragraph.
403 If pos == -2, use the label font of the layout attached here.
404 In all cases, the font is instantiated, i.e. does not have any
405 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
408 LyXFont getFont(BufferParams const &, size_type pos) const;
410 char GetChar(size_type pos);
412 char GetChar(size_type pos) const;
413 /// The position must already exist.
414 void SetChar(size_type pos, char c) {
419 void SetFont(size_type pos, LyXFont const & font);
421 string GetWord(size_type &) const;
422 /// Returns the height of the highest font in range
423 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
424 size_type endpos) const;
426 void InsertChar(size_type pos, char c);
429 void InsertChar(size_type pos, char c, LyXFont const &);
432 void InsertInset(size_type pos, Inset * inset);
435 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
438 bool InsertInsetAllowed(Inset * inset);
440 Inset * GetInset(size_type pos);
442 Inset const * GetInset(size_type pos) const;
444 void OpenFootnote(size_type pos);
446 void CloseFootnote(size_type pos);
447 /// important for cut and paste
448 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
450 void CutIntoMinibuffer(BufferParams const &, size_type pos);
452 bool InsertFromMinibuffer(size_type pos);
455 bool IsHfill(size_type pos) const;
457 bool IsInset(size_type pos) const;
459 bool IsFloat(size_type pos) const;
461 bool IsNewline(size_type pos) const;
463 bool IsSeparator(size_type pos) const;
465 bool IsLineSeparator(size_type pos) const;
467 bool IsKomma(size_type pos) const;
468 /// Used by the spellchecker
469 bool IsLetter(size_type pos) const;
471 bool IsWord(size_type pos) const;
473 /** This one resets all layout and dtp switches but not the font
474 of the single characters
478 /** paste this paragraph with the next one
479 be carefull, this doesent make any check at all
481 void PasteParagraph(BufferParams const &);
483 /// used to remove the error messages
484 int AutoDeleteInsets();
486 /// returns -1 if inset not found
487 int GetPositionOfInset(Inset * inset) const;
489 /// ok and now some footnote functions
490 void OpenFootnotes();
493 void CloseFootnotes();
496 LyXParagraph * FirstSelfrowPar();
499 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
501 /** A paragraph following a footnote is a "dummy". A paragraph
502 with a footnote in it is stored as three paragraphs:
503 First a paragraph with the text up to the footnote, then
504 one (or more) paragraphs with the footnote, and finally
505 the a paragraph with the text after the footnote. Only the
506 first paragraph keeps information about layoutparameters, */
507 bool IsDummy() const;
509 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
510 I have to set it on each of it's elements */
512 void SetPExtraType(BufferParams const &,
513 int type, char const * width, char const * widthp);
515 void UnsetPExtraType(BufferParams const &);
517 bool linuxDocConvertChar(char c, string & sgml_string);
519 void DocBookContTableRows(Buffer const *,
520 std::ostream &, string & extra,
521 int & desc_on, size_type i,
522 int current_cell_number, int & column);
524 void SimpleDocBookOneTablePar(Buffer const *,
525 std::ostream &, string & extra,
526 int & desc_on, int depth);
535 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
538 friend struct matchIT;
541 /// used by lower_bound
543 int operator()(LyXParagraph::InsetTable const & a,
544 LyXParagraph::size_type pos) const {
547 /// used by upper_bound
549 int operator()(LyXParagraph::size_type pos,
550 LyXParagraph::InsetTable const & a) const {
554 /** A font entry covers a range of positions. Notice that the
555 entries in the list are inserted in random order.
556 I don't think it's worth the effort to implement a more effective
557 datastructure, because the number of different fonts in a paragraph
559 Nevertheless, I decided to store fontlist using a sorted vector:
560 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
561 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
562 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
563 (font_1 covers the chars 0,...,pos_1) (Dekel)
566 /// End position of paragraph this font attribute covers
568 /** Font. Interpretation of the font values:
569 If a value is LyXFont::INHERIT_*, it means that the font
570 attribute is inherited from either the layout of this
571 paragraph or, in the case of nested paragraphs, from the
572 layout in the environment one level up until completely
574 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
575 allowed in these font tables.
579 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
581 friend struct matchFT;
584 /// used by lower_bound
586 int operator()(LyXParagraph::FontTable const & a,
587 LyXParagraph::size_type pos) const {
590 /// used by upper_bound
592 int operator()(LyXParagraph::size_type pos,
593 LyXParagraph::FontTable const & a) const {
599 typedef std::vector<FontTable> FontList;
603 typedef std::vector<InsetTable> InsetList;
607 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
608 std::ostream &, TexRow & texrow,
609 std::ostream & foot, TexRow & foot_texrow,
612 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
613 std::ostream &, TexRow & texrow,
614 std::ostream & foot, TexRow & foot_texrow,
618 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
619 std::ostream &, TexRow & texrow);
621 bool TeXContTableRows(Buffer const *, BufferParams const &,
622 std::ostream &, size_type i,
623 int current_cell_number,
624 int & column, TexRow & texrow);
626 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
628 int & column, LyXFont const & font,
629 LyXLayout const & style);
631 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
632 std::ostream &, TexRow & texrow,
634 LyXFont & font, LyXFont & running_font,
635 LyXFont & basefont, bool & open_font,
636 LyXLayout const & style,
638 int & column, char const c);
642 static unsigned int paragraph_id;
644 class inset_iterator {
647 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
648 inset_iterator & operator++() {
652 Inset * operator*() { return (*it).inset; }
653 size_type getPos() {return (*it).pos; }
654 bool operator==(inset_iterator const & iter) const {
655 return it == iter.it;
657 bool operator!=(inset_iterator const & iter) const {
658 return it != iter.it;
661 InsetList::iterator it;
664 inset_iterator inset_iterator_begin() {
665 return inset_iterator(insetlist.begin());
668 inset_iterator inset_iterator_end() {
669 return inset_iterator(insetlist.end());
672 inset_iterator InsetIterator(size_type pos);