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() const;
130 bool isRightToLeftPar() const;
132 void ChangeLanguage(Language const * from, Language const * to);
134 bool isMultiLingual();
136 string String(bool label);
139 void writeFile(std::ostream &, BufferParams const &, char, char) const;
141 void validate(LaTeXFeatures &) const;
148 void id(int id_arg) {
156 LyXParagraph * TeXOnePar(std::ostream &, TexRow & texrow,
158 std::ostream & foot, TexRow & foot_texrow,
161 bool SimpleTeXOnePar(std::ostream &, TexRow & texrow, bool moving_arg);
164 LyXParagraph * TeXEnvironment(std::ostream &, TexRow & texrow,
165 std::ostream & foot, TexRow & foot_texrow,
168 LyXParagraph * Clone() const;
171 bool HasSameLayout(LyXParagraph const * par) const;
174 void MakeSameLayout(LyXParagraph const * par);
176 /// Is it the first par with same depth and layout?
177 bool IsFirstInSequence() const {
178 LyXParagraph const * dhook = DepthHook(GetDepth());
179 return (dhook == this
180 || dhook->GetLayout() != GetLayout()
181 || dhook->GetDepth() != GetDepth());
184 /** Check if the current paragraph is the last paragraph in a
186 int GetEndLabel() const;
188 Inset * InInset() { return inset_owner; }
190 void SetInsetOwner(Inset * i) { inset_owner = i; }
199 size_type size() const { return text.size(); }
202 text.resize(text.size());
204 void setContentsFromPar(LyXParagraph * par) {
207 void clearContents() {
212 VSpace added_space_top;
215 VSpace added_space_bottom;
221 LyXTextClass::LayoutList::size_type layout;
225 \item no footnote, closed footnote,
226 \item open footnote, where footnote
227 \item means footnote-environment
230 footnote_flag footnoteflag;
232 /// footnote, margin, fig, tab
233 footnote_kind footnotekind;
235 //@Man: the LyX- DTP-switches
247 bool pagebreak_bottom;
259 block<int, 10> counter_;
262 void setCounter(int i, int v) { counter_[i] = v; }
263 int getCounter(int i) const { return counter_[i]; }
264 void incCounter(int i) { counter_[i]++; }
266 bool start_of_appendix;
277 /* This is for the paragraph extra stuff */
283 string pextra_widthp;
285 int pextra_alignment;
289 bool pextra_start_minipage;
295 string labelwidthstring;
301 LyXParagraph * previous;
303 /* table stuff -- begin*/
306 /* table stuff -- end*/
309 InsetBibKey * bibkey; // ale970302
311 /** these function are able to hide closed footnotes
313 LyXParagraph * Next();
316 LyXParagraph * Previous();
318 LyXParagraph const * Previous() const;
320 /** these function are able to hide open and closed footnotes
322 LyXParagraph * NextAfterFootnote();
324 LyXParagraph const * NextAfterFootnote() const;
327 LyXParagraph * PreviousBeforeFootnote();
329 LyXParagraph * LastPhysicalPar();
331 LyXParagraph const * LastPhysicalPar() const;
334 LyXParagraph * FirstPhysicalPar();
336 LyXParagraph const * FirstPhysicalPar() const;
338 /// returns the physical paragraph
339 LyXParagraph * ParFromPos(size_type pos);
340 /// returns the position in the physical par
341 int PositionInParFromPos(size_type pos) const;
343 /// for the environments
344 LyXParagraph * DepthHook(int depth);
345 /// for the environments
346 LyXParagraph const * DepthHook(int depth) const;
348 int BeginningOfMainBody() const;
350 string GetLabelstring() const;
352 /// the next two functions are for the manual labels
353 string GetLabelWidthString() const;
355 void SetLabelWidthString(string const & s);
357 LyXTextClass::LayoutList::size_type GetLayout() const;
359 char GetAlign() const;
361 char GetDepth() const;
363 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
365 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
367 int GetFirstCounter(int i) const;
369 size_type Last() const;
371 void Erase(size_type pos);
372 /** the flag determines wether the layout should be copied
374 void BreakParagraph(size_type pos, int flag);
376 void BreakParagraphConservative(size_type pos);
377 /** Get unistantiated font setting. Returns the difference
378 between the characters font and the layoutfont.
379 This is what is stored in the fonttable
381 LyXFont GetFontSettings(size_type pos) const;
383 LyXFont GetFirstFontSettings() const;
385 /** Get fully instantiated font. If pos == -1, use the layout
386 font attached to this paragraph.
387 If pos == -2, use the label font of the layout attached here.
388 In all cases, the font is instantiated, i.e. does not have any
389 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
392 LyXFont getFont(size_type pos) const;
394 char GetChar(size_type pos);
396 char GetChar(size_type pos) const;
397 /// The position must already exist.
398 void SetChar(size_type pos, char c) {
403 void SetFont(size_type pos, LyXFont const & font);
405 string GetWord(size_type &) const;
406 /// Returns the height of the highest font in range
407 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
408 size_type endpos) const;
410 void InsertChar(size_type pos, char c);
412 void InsertInset(size_type pos, Inset * inset);
414 bool InsertInsetAllowed(Inset * inset);
416 Inset * GetInset(size_type pos);
418 Inset const * GetInset(size_type pos) const;
420 void OpenFootnote(size_type pos);
422 void CloseFootnote(size_type pos);
423 /// important for cut and paste
424 void CopyIntoMinibuffer(size_type pos) const;
426 void CutIntoMinibuffer(size_type pos);
428 bool InsertFromMinibuffer(size_type pos);
431 bool IsHfill(size_type pos) const;
433 bool IsInset(size_type pos) const;
435 bool IsFloat(size_type pos) const;
437 bool IsNewline(size_type pos) const;
439 bool IsSeparator(size_type pos) const;
441 bool IsLineSeparator(size_type pos) const;
443 bool IsKomma(size_type pos) const;
444 /// Used by the spellchecker
445 bool IsLetter(size_type pos) const;
447 bool IsWord(size_type pos) const;
449 /** This one resets all layout and dtp switches but not the font
450 of the single characters
454 /** paste this paragraph with the next one
455 be carefull, this doesent make any check at all
457 void PasteParagraph();
459 /// used to remove the error messages
460 int AutoDeleteInsets();
462 /// returns -1 if inset not found
463 int GetPositionOfInset(Inset * inset) const;
465 /// ok and now some footnote functions
466 void OpenFootnotes();
469 void CloseFootnotes();
472 LyXParagraph * FirstSelfrowPar();
475 int ClearParagraph() {
477 if (!IsDummy() && !table){
480 || IsLineSeparator(0))){
488 /** A paragraph following a footnote is a "dummy". A paragraph
489 with a footnote in it is stored as three paragraphs:
490 First a paragraph with the text up to the footnote, then
491 one (or more) paragraphs with the footnote, and finally
492 the a paragraph with the text after the footnote. Only the
493 first paragraph keeps information about layoutparameters, */
494 bool IsDummy() const;
496 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
497 I have to set it on each of it's elements */
499 void SetPExtraType(int type, char const * width, char const * widthp);
501 void UnsetPExtraType();
504 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
507 bool linuxDocConvertChar(char c, string & sgml_string);
509 void DocBookContTableRows(std::ostream &, string & extra,
510 int & desc_on, size_type i,
511 int current_cell_number, int & column);
513 void SimpleDocBookOneTablePar(std::ostream &, string & extra,
514 int & desc_on, int depth);
523 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
526 friend struct matchIT;
529 /// used by lower_bound
531 int operator()(LyXParagraph::InsetTable const & a,
532 LyXParagraph::size_type pos) const {
535 /// used by upper_bound
537 int operator()(LyXParagraph::size_type pos,
538 LyXParagraph::InsetTable const & a) const {
542 /** A font entry covers a range of positions. Notice that the
543 entries in the list are inserted in random order.
544 I don't think it's worth the effort to implement a more effective
545 datastructure, because the number of different fonts in a paragraph
549 /// Start position of paragraph this font attribute covers
551 /// Ending position of paragraph this font attribute covers
553 /** Font. Interpretation of the font values:
554 If a value is LyXFont::INHERIT_*, it means that the font
555 attribute is inherited from either the layout of this
556 paragraph or, in the case of nested paragraphs, from the
557 layout in the environment one level up until completely
559 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
560 allowed in these font tables.
565 typedef std::list<FontTable> FontList;
569 typedef std::vector<InsetTable> InsetList;
573 LyXParagraph * TeXDeeper(std::ostream &, TexRow & texrow,
574 std::ostream & foot, TexRow & foot_texrow,
577 LyXParagraph * TeXFootnote(std::ostream &, TexRow & texrow,
578 std::ostream & foot, TexRow & foot_texrow,
582 bool SimpleTeXOneTablePar(std::ostream &, TexRow & texrow);
584 bool TeXContTableRows(std::ostream &, size_type i,
585 int current_cell_number,
586 int & column, TexRow & texrow);
588 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
590 int & column, LyXFont const & font,
591 LyXLayout const & style);
593 void SimpleTeXSpecialChars(std::ostream &, TexRow & texrow,
595 LyXFont & font, LyXFont & running_font,
596 LyXFont & basefont, bool & open_font,
597 LyXLayout const & style,
599 int & column, char const c);
603 static unsigned int paragraph_id;
605 class inset_iterator {
608 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
609 inset_iterator & operator++() {
613 Inset * operator*() { return (*it).inset; }
614 size_type getPos() {return (*it).pos; }
615 bool operator==(inset_iterator const & iter) const {
616 return it == iter.it;
618 bool operator!=(inset_iterator const & iter) const {
619 return it != iter.it;
622 InsetList::iterator it;
625 inset_iterator inset_iterator_begin() {
626 return inset_iterator(insetlist.begin());
629 inset_iterator inset_iterator_end() {
630 return inset_iterator(insetlist.end());
633 inset_iterator InsetIterator(size_type pos);