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;
275 block<int, 10> counter_;
278 void setCounter(int i, int v) { counter_[i] = v; }
279 int getCounter(int i) const { return counter_[i]; }
280 void incCounter(int i) { counter_[i]++; }
282 bool start_of_appendix;
293 /* This is for the paragraph extra stuff */
299 string pextra_widthp;
301 int pextra_alignment;
305 bool pextra_start_minipage;
311 string labelwidthstring;
317 LyXParagraph * previous;
319 /* table stuff -- begin*/
322 /* table stuff -- end*/
325 InsetBibKey * bibkey; // ale970302
327 /** these function are able to hide closed footnotes
329 LyXParagraph * Next();
332 LyXParagraph * Previous();
334 LyXParagraph const * Previous() const;
336 /** these function are able to hide open and closed footnotes
338 LyXParagraph * NextAfterFootnote();
340 LyXParagraph const * NextAfterFootnote() const;
343 LyXParagraph * PreviousBeforeFootnote();
345 LyXParagraph * LastPhysicalPar();
347 LyXParagraph const * LastPhysicalPar() const;
350 LyXParagraph * FirstPhysicalPar();
352 LyXParagraph const * FirstPhysicalPar() const;
354 /// returns the physical paragraph
355 LyXParagraph * ParFromPos(size_type pos);
356 /// returns the position in the physical par
357 int PositionInParFromPos(size_type pos) const;
359 /// for the environments
360 LyXParagraph * DepthHook(int depth);
361 /// for the environments
362 LyXParagraph const * DepthHook(int depth) const;
364 int BeginningOfMainBody() const;
366 string GetLabelstring() const;
368 /// the next two functions are for the manual labels
369 string GetLabelWidthString() const;
371 void SetLabelWidthString(string const & s);
373 LyXTextClass::LayoutList::size_type GetLayout() const;
375 char GetAlign() const;
377 char GetDepth() const;
379 void SetLayout(BufferParams const &,
380 LyXTextClass::LayoutList::size_type new_layout);
382 void SetOnlyLayout(BufferParams const &,
383 LyXTextClass::LayoutList::size_type new_layout);
385 int GetFirstCounter(int i) const;
387 size_type Last() const;
389 void Erase(size_type pos);
390 /** the flag determines wether the layout should be copied
392 void BreakParagraph(BufferParams const &, size_type pos, int flag);
394 void BreakParagraphConservative(BufferParams const &, size_type pos);
395 /** Get unistantiated font setting. Returns the difference
396 between the characters font and the layoutfont.
397 This is what is stored in the fonttable
399 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
401 LyXFont GetFirstFontSettings() const;
403 /** Get fully instantiated font. If pos == -1, use the layout
404 font attached to this paragraph.
405 If pos == -2, use the label font of the layout attached here.
406 In all cases, the font is instantiated, i.e. does not have any
407 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
410 LyXFont getFont(BufferParams const &, size_type pos) const;
412 value_type GetChar(size_type pos);
414 value_type GetChar(size_type pos) const;
415 /// The position must already exist.
416 void SetChar(size_type pos, value_type c) {
421 void SetFont(size_type pos, LyXFont const & font);
423 string GetWord(size_type &) const;
424 /// Returns the height of the highest font in range
425 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
426 size_type endpos) const;
428 void InsertChar(size_type pos, value_type c);
430 void InsertChar(size_type pos, value_type c, LyXFont const &);
432 void InsertInset(size_type pos, Inset * inset);
434 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
436 bool InsertInsetAllowed(Inset * inset);
438 Inset * GetInset(size_type pos);
440 Inset const * GetInset(size_type pos) const;
442 void OpenFootnote(size_type pos);
444 void CloseFootnote(size_type pos);
445 /// important for cut and paste
446 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
448 void CutIntoMinibuffer(BufferParams const &, size_type pos);
450 bool InsertFromMinibuffer(size_type pos);
453 bool IsHfill(size_type pos) const;
455 bool IsInset(size_type pos) const;
457 bool IsFloat(size_type pos) const;
459 bool IsNewline(size_type pos) const;
461 bool IsSeparator(size_type pos) const;
463 bool IsLineSeparator(size_type pos) const;
465 bool IsKomma(size_type pos) const;
466 /// Used by the spellchecker
467 bool IsLetter(size_type pos) const;
469 bool IsWord(size_type pos) const;
471 /** This one resets all layout and dtp switches but not the font
472 of the single characters
476 /** paste this paragraph with the next one
477 be carefull, this doesent make any check at all
479 void PasteParagraph(BufferParams const &);
481 /// used to remove the error messages
482 int AutoDeleteInsets();
484 /// returns -1 if inset not found
485 int GetPositionOfInset(Inset * inset) const;
487 /// ok and now some footnote functions
488 void OpenFootnotes();
491 void CloseFootnotes();
494 LyXParagraph * FirstSelfrowPar();
497 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
499 /** A paragraph following a footnote is a "dummy". A paragraph
500 with a footnote in it is stored as three paragraphs:
501 First a paragraph with the text up to the footnote, then
502 one (or more) paragraphs with the footnote, and finally
503 the a paragraph with the text after the footnote. Only the
504 first paragraph keeps information about layoutparameters, */
505 bool IsDummy() const;
507 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
508 I have to set it on each of it's elements */
510 void SetPExtraType(BufferParams const &,
511 int type, char const * width, char const * widthp);
513 void UnsetPExtraType(BufferParams const &);
515 bool linuxDocConvertChar(char c, string & sgml_string);
517 void DocBookContTableRows(Buffer const *,
518 std::ostream &, string & extra,
519 int & desc_on, size_type i,
520 int current_cell_number, int & column);
522 void SimpleDocBookOneTablePar(Buffer const *,
523 std::ostream &, string & extra,
524 int & desc_on, int depth);
533 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
536 friend struct matchIT;
539 /// used by lower_bound and upper_bound
541 int operator()(LyXParagraph::InsetTable const & a,
542 LyXParagraph::InsetTable const & b) const {
543 return a.pos < b.pos;
546 /** A font entry covers a range of positions. Notice that the
547 entries in the list are inserted in random order.
548 I don't think it's worth the effort to implement a more effective
549 datastructure, because the number of different fonts in a paragraph
551 Nevertheless, I decided to store fontlist using a sorted vector:
552 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
553 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
554 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
555 (font_1 covers the chars 0,...,pos_1) (Dekel)
558 /// End position of paragraph this font attribute covers
560 /** Font. Interpretation of the font values:
561 If a value is LyXFont::INHERIT_*, it means that the font
562 attribute is inherited from either the layout of this
563 paragraph or, in the case of nested paragraphs, from the
564 layout in the environment one level up until completely
566 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
567 allowed in these font tables.
571 FontTable(size_type p, LyXFont const & f) {pos = p; font = f;}
573 friend struct matchFT;
576 /// used by lower_bound and upper_bound
578 int operator()(LyXParagraph::FontTable const & a,
579 LyXParagraph::FontTable const & b) const {
580 return a.pos < b.pos;
585 typedef std::vector<FontTable> FontList;
589 typedef std::vector<InsetTable> InsetList;
593 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
594 std::ostream &, TexRow & texrow,
595 std::ostream & foot, TexRow & foot_texrow,
598 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
599 std::ostream &, TexRow & texrow,
600 std::ostream & foot, TexRow & foot_texrow,
604 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
605 std::ostream &, TexRow & texrow);
607 bool TeXContTableRows(Buffer const *, BufferParams const &,
608 std::ostream &, size_type i,
609 int current_cell_number,
610 int & column, TexRow & texrow);
612 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
614 int & column, LyXFont const & font,
615 LyXLayout const & style);
617 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
618 std::ostream &, TexRow & texrow,
620 LyXFont & font, LyXFont & running_font,
621 LyXFont & basefont, bool & open_font,
622 LyXLayout const & style,
624 int & column, value_type const c);
628 static unsigned int paragraph_id;
630 class inset_iterator {
633 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
634 inset_iterator & operator++() {
638 Inset * operator*() { return (*it).inset; }
639 size_type getPos() {return (*it).pos; }
640 bool operator==(inset_iterator const & iter) const {
641 return it == iter.it;
643 bool operator!=(inset_iterator const & iter) const {
644 return it != iter.it;
647 InsetList::iterator it;
650 inset_iterator inset_iterator_begin() {
651 return inset_iterator(insetlist.begin());
654 inset_iterator inset_iterator_end() {
655 return inset_iterator(insetlist.end());
658 inset_iterator InsetIterator(size_type pos);