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"
35 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
50 enum MINIPAGE_ALIGNMENT {
54 MINIPAGE_ALIGN_MIDDLE,
79 //META_PROTECTED_SEPARATOR,
105 ALGORITHM, // Bernhard, 970807
107 WIDE_FIG, // CFO-G, 971106
109 WIDE_TAB // CFO-G, 971106
113 typedef char value_type;
115 typedef std::vector<value_type> TextContainer;
117 typedef int size_type;
121 /// this konstruktor inserts the new paragraph in a list
123 LyXParagraph(LyXParagraph * par);
124 /// the destruktors removes the new paragraph from the list
128 Language const * getParLanguage(BufferParams const &) const;
130 bool isRightToLeftPar(BufferParams const &) const;
132 void ChangeLanguage(BufferParams const & bparams,
133 Language const * from, Language const * to);
135 bool isMultiLingual(BufferParams const &);
138 string String(BufferParams const &, bool label);
140 string String(size_type beg, size_type end);
143 void writeFile(std::ostream &, BufferParams const &, char, char) const;
145 void validate(LaTeXFeatures &) const;
152 void id(int id_arg) {
160 LyXParagraph * TeXOnePar(BufferParams const &,
161 std::ostream &, TexRow & texrow,
163 std::ostream & foot, TexRow & foot_texrow,
166 bool SimpleTeXOnePar(BufferParams const &,
167 std::ostream &, TexRow & texrow, bool moving_arg);
170 LyXParagraph * TeXEnvironment(BufferParams const &,
171 std::ostream &, TexRow & texrow,
172 std::ostream & foot, TexRow & foot_texrow,
175 LyXParagraph * Clone() const;
178 bool HasSameLayout(LyXParagraph const * par) const;
181 void MakeSameLayout(LyXParagraph const * par);
183 /// Is it the first par with same depth and layout?
184 bool IsFirstInSequence() const {
185 LyXParagraph const * dhook = DepthHook(GetDepth());
186 return (dhook == this
187 || dhook->GetLayout() != GetLayout()
188 || dhook->GetDepth() != GetDepth());
191 /** Check if the current paragraph is the last paragraph in a
193 int GetEndLabel(BufferParams const &) const;
195 Inset * InInset() { return inset_owner; }
197 void SetInsetOwner(Inset * i) { inset_owner = i; }
206 size_type size() const { return text.size(); }
209 text.resize(text.size());
211 void setContentsFromPar(LyXParagraph * par) {
214 void clearContents() {
219 VSpace added_space_top;
222 VSpace added_space_bottom;
228 LyXTextClass::LayoutList::size_type layout;
232 \item no footnote, closed footnote,
233 \item open footnote, where footnote
234 \item means footnote-environment
237 footnote_flag footnoteflag;
239 /// footnote, margin, fig, tab
240 footnote_kind footnotekind;
242 //@Man: the LyX- DTP-switches
254 bool pagebreak_bottom;
266 block<int, 10> counter_;
269 void setCounter(int i, int v) { counter_[i] = v; }
270 int getCounter(int i) const { return counter_[i]; }
271 void incCounter(int i) { counter_[i]++; }
273 bool start_of_appendix;
284 /* This is for the paragraph extra stuff */
290 string pextra_widthp;
292 int pextra_alignment;
296 bool pextra_start_minipage;
302 string labelwidthstring;
308 LyXParagraph * previous;
310 /* table stuff -- begin*/
313 /* table stuff -- end*/
316 InsetBibKey * bibkey; // ale970302
318 /** these function are able to hide closed footnotes
320 LyXParagraph * Next();
323 LyXParagraph * Previous();
325 LyXParagraph const * Previous() const;
327 /** these function are able to hide open and closed footnotes
329 LyXParagraph * NextAfterFootnote();
331 LyXParagraph const * NextAfterFootnote() const;
334 LyXParagraph * PreviousBeforeFootnote();
336 LyXParagraph * LastPhysicalPar();
338 LyXParagraph const * LastPhysicalPar() const;
341 LyXParagraph * FirstPhysicalPar();
343 LyXParagraph const * FirstPhysicalPar() const;
345 /// returns the physical paragraph
346 LyXParagraph * ParFromPos(size_type pos);
347 /// returns the position in the physical par
348 int PositionInParFromPos(size_type pos) const;
350 /// for the environments
351 LyXParagraph * DepthHook(int depth);
352 /// for the environments
353 LyXParagraph const * DepthHook(int depth) const;
355 int BeginningOfMainBody() const;
357 string GetLabelstring() const;
359 /// the next two functions are for the manual labels
360 string GetLabelWidthString() const;
362 void SetLabelWidthString(string const & s);
364 LyXTextClass::LayoutList::size_type GetLayout() const;
366 char GetAlign() const;
368 char GetDepth() const;
370 void SetLayout(BufferParams const &,
371 LyXTextClass::LayoutList::size_type new_layout);
373 void SetOnlyLayout(BufferParams const &,
374 LyXTextClass::LayoutList::size_type new_layout);
376 int GetFirstCounter(int i) const;
378 size_type Last() const;
380 void Erase(size_type pos);
381 /** the flag determines wether the layout should be copied
383 void BreakParagraph(BufferParams const &, size_type pos, int flag);
385 void BreakParagraphConservative(BufferParams const &, size_type pos);
386 /** Get unistantiated font setting. Returns the difference
387 between the characters font and the layoutfont.
388 This is what is stored in the fonttable
390 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
392 LyXFont GetFirstFontSettings() const;
394 /** Get fully instantiated font. If pos == -1, use the layout
395 font attached to this paragraph.
396 If pos == -2, use the label font of the layout attached here.
397 In all cases, the font is instantiated, i.e. does not have any
398 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
401 LyXFont getFont(BufferParams const &, size_type pos) const;
403 char GetChar(size_type pos);
405 char GetChar(size_type pos) const;
406 /// The position must already exist.
407 void SetChar(size_type pos, char c) {
412 void SetFont(size_type pos, LyXFont const & font);
414 string GetWord(size_type &) const;
415 /// Returns the height of the highest font in range
416 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
417 size_type endpos) const;
419 void InsertChar(size_type pos, char c);
421 void InsertInset(size_type pos, Inset * inset);
423 bool InsertInsetAllowed(Inset * inset);
425 Inset * GetInset(size_type pos);
427 Inset const * GetInset(size_type pos) const;
429 void OpenFootnote(size_type pos);
431 void CloseFootnote(size_type pos);
432 /// important for cut and paste
433 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
435 void CutIntoMinibuffer(BufferParams const &, size_type pos);
437 bool InsertFromMinibuffer(size_type pos);
440 bool IsHfill(size_type pos) const;
442 bool IsInset(size_type pos) const;
444 bool IsFloat(size_type pos) const;
446 bool IsNewline(size_type pos) const;
448 bool IsSeparator(size_type pos) const;
450 bool IsLineSeparator(size_type pos) const;
452 bool IsKomma(size_type pos) const;
453 /// Used by the spellchecker
454 bool IsLetter(size_type pos) const;
456 bool IsWord(size_type pos) const;
458 /** This one resets all layout and dtp switches but not the font
459 of the single characters
463 /** paste this paragraph with the next one
464 be carefull, this doesent make any check at all
466 void PasteParagraph(BufferParams const &);
468 /// used to remove the error messages
469 int AutoDeleteInsets();
471 /// returns -1 if inset not found
472 int GetPositionOfInset(Inset * inset) const;
474 /// ok and now some footnote functions
475 void OpenFootnotes();
478 void CloseFootnotes();
481 LyXParagraph * FirstSelfrowPar();
484 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
486 /** A paragraph following a footnote is a "dummy". A paragraph
487 with a footnote in it is stored as three paragraphs:
488 First a paragraph with the text up to the footnote, then
489 one (or more) paragraphs with the footnote, and finally
490 the a paragraph with the text after the footnote. Only the
491 first paragraph keeps information about layoutparameters, */
492 bool IsDummy() const;
494 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
495 I have to set it on each of it's elements */
497 void SetPExtraType(BufferParams const &,
498 int type, char const * width, char const * widthp);
500 void UnsetPExtraType(BufferParams const &);
503 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
506 bool linuxDocConvertChar(char c, string & sgml_string);
508 void DocBookContTableRows(BufferParams const &,
509 std::ostream &, string & extra,
510 int & desc_on, size_type i,
511 int current_cell_number, int & column);
513 void SimpleDocBookOneTablePar(BufferParams const &,
514 std::ostream &, string & extra,
515 int & desc_on, int depth);
524 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
527 friend struct matchIT;
530 /// used by lower_bound
532 int operator()(LyXParagraph::InsetTable const & a,
533 LyXParagraph::size_type pos) const {
536 /// used by upper_bound
538 int operator()(LyXParagraph::size_type pos,
539 LyXParagraph::InsetTable const & a) const {
543 /** A font entry covers a range of positions. Notice that the
544 entries in the list are inserted in random order.
545 I don't think it's worth the effort to implement a more effective
546 datastructure, because the number of different fonts in a paragraph
550 /// Start position of paragraph this font attribute covers
552 /// Ending position of paragraph this font attribute covers
554 /** Font. Interpretation of the font values:
555 If a value is LyXFont::INHERIT_*, it means that the font
556 attribute is inherited from either the layout of this
557 paragraph or, in the case of nested paragraphs, from the
558 layout in the environment one level up until completely
560 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
561 allowed in these font tables.
566 typedef std::list<FontTable> FontList;
570 typedef std::vector<InsetTable> InsetList;
574 LyXParagraph * TeXDeeper(BufferParams const &,
575 std::ostream &, TexRow & texrow,
576 std::ostream & foot, TexRow & foot_texrow,
579 LyXParagraph * TeXFootnote(BufferParams const &,
580 std::ostream &, TexRow & texrow,
581 std::ostream & foot, TexRow & foot_texrow,
585 bool SimpleTeXOneTablePar(BufferParams const &,
586 std::ostream &, TexRow & texrow);
588 bool TeXContTableRows(BufferParams const &,
589 std::ostream &, size_type i,
590 int current_cell_number,
591 int & column, TexRow & texrow);
593 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
595 int & column, LyXFont const & font,
596 LyXLayout const & style);
598 void SimpleTeXSpecialChars(BufferParams const &,
599 std::ostream &, TexRow & texrow,
601 LyXFont & font, LyXFont & running_font,
602 LyXFont & basefont, bool & open_font,
603 LyXLayout const & style,
605 int & column, char const c);
609 static unsigned int paragraph_id;
611 class inset_iterator {
614 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
615 inset_iterator & operator++() {
619 Inset * operator*() { return (*it).inset; }
620 size_type getPos() {return (*it).pos; }
621 bool operator==(inset_iterator const & iter) const {
622 return it == iter.it;
624 bool operator!=(inset_iterator const & iter) const {
625 return it != iter.it;
628 InsetList::iterator it;
631 inset_iterator inset_iterator_begin() {
632 return inset_iterator(insetlist.begin());
635 inset_iterator inset_iterator_end() {
636 return inset_iterator(insetlist.end());
639 inset_iterator InsetIterator(size_type pos);