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(Buffer const *, bool label);
140 string String(Buffer const *, size_type beg, size_type end);
143 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
146 void validate(LaTeXFeatures &) const;
153 void id(int id_arg) {
161 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
162 std::ostream &, TexRow & texrow,
164 std::ostream & foot, TexRow & foot_texrow,
167 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
168 std::ostream &, TexRow & texrow, bool moving_arg);
171 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
172 std::ostream &, TexRow & texrow,
173 std::ostream & foot, TexRow & foot_texrow,
176 LyXParagraph * Clone() const;
179 bool HasSameLayout(LyXParagraph const * par) const;
182 void MakeSameLayout(LyXParagraph const * par);
184 /// Is it the first par with same depth and layout?
185 bool IsFirstInSequence() const {
186 LyXParagraph const * dhook = DepthHook(GetDepth());
187 return (dhook == this
188 || dhook->GetLayout() != GetLayout()
189 || dhook->GetDepth() != GetDepth());
192 /** Check if the current paragraph is the last paragraph in a
194 int GetEndLabel(BufferParams const &) const;
196 Inset * InInset() { return inset_owner; }
198 void SetInsetOwner(Inset * i) { inset_owner = i; }
207 size_type size() const { return text.size(); }
210 text.resize(text.size());
212 void setContentsFromPar(LyXParagraph * par) {
215 void clearContents() {
220 VSpace added_space_top;
223 VSpace added_space_bottom;
229 LyXTextClass::LayoutList::size_type layout;
233 \item no footnote, closed footnote,
234 \item open footnote, where footnote
235 \item means footnote-environment
238 footnote_flag footnoteflag;
240 /// footnote, margin, fig, tab
241 footnote_kind footnotekind;
243 //@Man: the LyX- DTP-switches
255 bool pagebreak_bottom;
267 block<int, 10> counter_;
270 void setCounter(int i, int v) { counter_[i] = v; }
271 int getCounter(int i) const { return counter_[i]; }
272 void incCounter(int i) { counter_[i]++; }
274 bool start_of_appendix;
285 /* This is for the paragraph extra stuff */
291 string pextra_widthp;
293 int pextra_alignment;
297 bool pextra_start_minipage;
303 string labelwidthstring;
309 LyXParagraph * previous;
311 /* table stuff -- begin*/
314 /* table stuff -- end*/
317 InsetBibKey * bibkey; // ale970302
319 /** these function are able to hide closed footnotes
321 LyXParagraph * Next();
324 LyXParagraph * Previous();
326 LyXParagraph const * Previous() const;
328 /** these function are able to hide open and closed footnotes
330 LyXParagraph * NextAfterFootnote();
332 LyXParagraph const * NextAfterFootnote() const;
335 LyXParagraph * PreviousBeforeFootnote();
337 LyXParagraph * LastPhysicalPar();
339 LyXParagraph const * LastPhysicalPar() const;
342 LyXParagraph * FirstPhysicalPar();
344 LyXParagraph const * FirstPhysicalPar() const;
346 /// returns the physical paragraph
347 LyXParagraph * ParFromPos(size_type pos);
348 /// returns the position in the physical par
349 int PositionInParFromPos(size_type pos) const;
351 /// for the environments
352 LyXParagraph * DepthHook(int depth);
353 /// for the environments
354 LyXParagraph const * DepthHook(int depth) const;
356 int BeginningOfMainBody() const;
358 string GetLabelstring() const;
360 /// the next two functions are for the manual labels
361 string GetLabelWidthString() const;
363 void SetLabelWidthString(string const & s);
365 LyXTextClass::LayoutList::size_type GetLayout() const;
367 char GetAlign() const;
369 char GetDepth() const;
371 void SetLayout(BufferParams const &,
372 LyXTextClass::LayoutList::size_type new_layout);
374 void SetOnlyLayout(BufferParams const &,
375 LyXTextClass::LayoutList::size_type new_layout);
377 int GetFirstCounter(int i) const;
379 size_type Last() const;
381 void Erase(size_type pos);
382 /** the flag determines wether the layout should be copied
384 void BreakParagraph(BufferParams const &, size_type pos, int flag);
386 void BreakParagraphConservative(BufferParams const &, size_type pos);
387 /** Get unistantiated font setting. Returns the difference
388 between the characters font and the layoutfont.
389 This is what is stored in the fonttable
391 LyXFont GetFontSettings(BufferParams const &, size_type pos) const;
393 LyXFont GetFirstFontSettings() const;
395 /** Get fully instantiated font. If pos == -1, use the layout
396 font attached to this paragraph.
397 If pos == -2, use the label font of the layout attached here.
398 In all cases, the font is instantiated, i.e. does not have any
399 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
402 LyXFont getFont(BufferParams const &, size_type pos) const;
404 char GetChar(size_type pos);
406 char GetChar(size_type pos) const;
407 /// The position must already exist.
408 void SetChar(size_type pos, char c) {
413 void SetFont(size_type pos, LyXFont const & font);
415 string GetWord(size_type &) const;
416 /// Returns the height of the highest font in range
417 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
418 size_type endpos) const;
420 void InsertChar(size_type pos, char c);
422 void InsertInset(size_type pos, Inset * inset);
424 bool InsertInsetAllowed(Inset * inset);
426 Inset * GetInset(size_type pos);
428 Inset const * GetInset(size_type pos) const;
430 void OpenFootnote(size_type pos);
432 void CloseFootnote(size_type pos);
433 /// important for cut and paste
434 void CopyIntoMinibuffer(BufferParams const &, size_type pos) const;
436 void CutIntoMinibuffer(BufferParams const &, size_type pos);
438 bool InsertFromMinibuffer(size_type pos);
441 bool IsHfill(size_type pos) const;
443 bool IsInset(size_type pos) const;
445 bool IsFloat(size_type pos) const;
447 bool IsNewline(size_type pos) const;
449 bool IsSeparator(size_type pos) const;
451 bool IsLineSeparator(size_type pos) const;
453 bool IsKomma(size_type pos) const;
454 /// Used by the spellchecker
455 bool IsLetter(size_type pos) const;
457 bool IsWord(size_type pos) const;
459 /** This one resets all layout and dtp switches but not the font
460 of the single characters
464 /** paste this paragraph with the next one
465 be carefull, this doesent make any check at all
467 void PasteParagraph(BufferParams const &);
469 /// used to remove the error messages
470 int AutoDeleteInsets();
472 /// returns -1 if inset not found
473 int GetPositionOfInset(Inset * inset) const;
475 /// ok and now some footnote functions
476 void OpenFootnotes();
479 void CloseFootnotes();
482 LyXParagraph * FirstSelfrowPar();
485 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
487 /** A paragraph following a footnote is a "dummy". A paragraph
488 with a footnote in it is stored as three paragraphs:
489 First a paragraph with the text up to the footnote, then
490 one (or more) paragraphs with the footnote, and finally
491 the a paragraph with the text after the footnote. Only the
492 first paragraph keeps information about layoutparameters, */
493 bool IsDummy() const;
495 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
496 I have to set it on each of it's elements */
498 void SetPExtraType(BufferParams const &,
499 int type, char const * width, char const * widthp);
501 void UnsetPExtraType(BufferParams const &);
504 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
507 bool linuxDocConvertChar(char c, string & sgml_string);
509 void DocBookContTableRows(Buffer const *,
510 std::ostream &, string & extra,
511 int & desc_on, size_type i,
512 int current_cell_number, int & column);
514 void SimpleDocBookOneTablePar(Buffer const *,
515 std::ostream &, string & extra,
516 int & desc_on, int depth);
525 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
528 friend struct matchIT;
531 /// used by lower_bound
533 int operator()(LyXParagraph::InsetTable const & a,
534 LyXParagraph::size_type pos) const {
537 /// used by upper_bound
539 int operator()(LyXParagraph::size_type pos,
540 LyXParagraph::InsetTable const & a) const {
544 /** A font entry covers a range of positions. Notice that the
545 entries in the list are inserted in random order.
546 I don't think it's worth the effort to implement a more effective
547 datastructure, because the number of different fonts in a paragraph
551 /// Start position of paragraph this font attribute covers
553 /// Ending position of paragraph this font attribute covers
555 /** Font. Interpretation of the font values:
556 If a value is LyXFont::INHERIT_*, it means that the font
557 attribute is inherited from either the layout of this
558 paragraph or, in the case of nested paragraphs, from the
559 layout in the environment one level up until completely
561 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
562 allowed in these font tables.
567 typedef std::list<FontTable> FontList;
571 typedef std::vector<InsetTable> InsetList;
575 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
576 std::ostream &, TexRow & texrow,
577 std::ostream & foot, TexRow & foot_texrow,
580 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
581 std::ostream &, TexRow & texrow,
582 std::ostream & foot, TexRow & foot_texrow,
586 bool SimpleTeXOneTablePar(Buffer const *, BufferParams const &,
587 std::ostream &, TexRow & texrow);
589 bool TeXContTableRows(Buffer const *, BufferParams const &,
590 std::ostream &, size_type i,
591 int current_cell_number,
592 int & column, TexRow & texrow);
594 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
596 int & column, LyXFont const & font,
597 LyXLayout const & style);
599 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
600 std::ostream &, TexRow & texrow,
602 LyXFont & font, LyXFont & running_font,
603 LyXFont & basefont, bool & open_font,
604 LyXLayout const & style,
606 int & column, char const c);
610 static unsigned int paragraph_id;
612 class inset_iterator {
615 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
616 inset_iterator & operator++() {
620 Inset * operator*() { return (*it).inset; }
621 size_type getPos() {return (*it).pos; }
622 bool operator==(inset_iterator const & iter) const {
623 return it == iter.it;
625 bool operator!=(inset_iterator const & iter) const {
626 return it != iter.it;
629 InsetList::iterator it;
632 inset_iterator inset_iterator_begin() {
633 return inset_iterator(insetlist.begin());
636 inset_iterator inset_iterator_end() {
637 return inset_iterator(insetlist.end());
640 inset_iterator InsetIterator(size_type pos);