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);
138 string String(size_type beg, size_type end);
141 void writeFile(std::ostream &, BufferParams const &, char, char) const;
143 void validate(LaTeXFeatures &) const;
150 void id(int id_arg) {
158 LyXParagraph * TeXOnePar(std::ostream &, TexRow & texrow,
160 std::ostream & foot, TexRow & foot_texrow,
163 bool SimpleTeXOnePar(std::ostream &, TexRow & texrow, bool moving_arg);
166 LyXParagraph * TeXEnvironment(std::ostream &, TexRow & texrow,
167 std::ostream & foot, TexRow & foot_texrow,
170 LyXParagraph * Clone() const;
173 bool HasSameLayout(LyXParagraph const * par) const;
176 void MakeSameLayout(LyXParagraph const * par);
178 /// Is it the first par with same depth and layout?
179 bool IsFirstInSequence() const {
180 LyXParagraph const * dhook = DepthHook(GetDepth());
181 return (dhook == this
182 || dhook->GetLayout() != GetLayout()
183 || dhook->GetDepth() != GetDepth());
186 /** Check if the current paragraph is the last paragraph in a
188 int GetEndLabel() const;
190 Inset * InInset() { return inset_owner; }
192 void SetInsetOwner(Inset * i) { inset_owner = i; }
201 size_type size() const { return text.size(); }
204 text.resize(text.size());
206 void setContentsFromPar(LyXParagraph * par) {
209 void clearContents() {
214 VSpace added_space_top;
217 VSpace added_space_bottom;
223 LyXTextClass::LayoutList::size_type layout;
227 \item no footnote, closed footnote,
228 \item open footnote, where footnote
229 \item means footnote-environment
232 footnote_flag footnoteflag;
234 /// footnote, margin, fig, tab
235 footnote_kind footnotekind;
237 //@Man: the LyX- DTP-switches
249 bool pagebreak_bottom;
261 block<int, 10> counter_;
264 void setCounter(int i, int v) { counter_[i] = v; }
265 int getCounter(int i) const { return counter_[i]; }
266 void incCounter(int i) { counter_[i]++; }
268 bool start_of_appendix;
279 /* This is for the paragraph extra stuff */
285 string pextra_widthp;
287 int pextra_alignment;
291 bool pextra_start_minipage;
297 string labelwidthstring;
303 LyXParagraph * previous;
305 /* table stuff -- begin*/
308 /* table stuff -- end*/
311 InsetBibKey * bibkey; // ale970302
313 /** these function are able to hide closed footnotes
315 LyXParagraph * Next();
318 LyXParagraph * Previous();
320 LyXParagraph const * Previous() const;
322 /** these function are able to hide open and closed footnotes
324 LyXParagraph * NextAfterFootnote();
326 LyXParagraph const * NextAfterFootnote() const;
329 LyXParagraph * PreviousBeforeFootnote();
331 LyXParagraph * LastPhysicalPar();
333 LyXParagraph const * LastPhysicalPar() const;
336 LyXParagraph * FirstPhysicalPar();
338 LyXParagraph const * FirstPhysicalPar() const;
340 /// returns the physical paragraph
341 LyXParagraph * ParFromPos(size_type pos);
342 /// returns the position in the physical par
343 int PositionInParFromPos(size_type pos) const;
345 /// for the environments
346 LyXParagraph * DepthHook(int depth);
347 /// for the environments
348 LyXParagraph const * DepthHook(int depth) const;
350 int BeginningOfMainBody() const;
352 string GetLabelstring() const;
354 /// the next two functions are for the manual labels
355 string GetLabelWidthString() const;
357 void SetLabelWidthString(string const & s);
359 LyXTextClass::LayoutList::size_type GetLayout() const;
361 char GetAlign() const;
363 char GetDepth() const;
365 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
367 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
369 int GetFirstCounter(int i) const;
371 size_type Last() const;
373 void Erase(size_type pos);
374 /** the flag determines wether the layout should be copied
376 void BreakParagraph(size_type pos, int flag);
378 void BreakParagraphConservative(size_type pos);
379 /** Get unistantiated font setting. Returns the difference
380 between the characters font and the layoutfont.
381 This is what is stored in the fonttable
383 LyXFont GetFontSettings(size_type pos) const;
385 LyXFont GetFirstFontSettings() const;
387 /** Get fully instantiated font. If pos == -1, use the layout
388 font attached to this paragraph.
389 If pos == -2, use the label font of the layout attached here.
390 In all cases, the font is instantiated, i.e. does not have any
391 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
394 LyXFont getFont(size_type pos) const;
396 char GetChar(size_type pos);
398 char GetChar(size_type pos) const;
399 /// The position must already exist.
400 void SetChar(size_type pos, char c) {
405 void SetFont(size_type pos, LyXFont const & font);
407 string GetWord(size_type &) const;
408 /// Returns the height of the highest font in range
409 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
410 size_type endpos) const;
412 void InsertChar(size_type pos, char c);
414 void InsertInset(size_type pos, Inset * inset);
416 bool InsertInsetAllowed(Inset * inset);
418 Inset * GetInset(size_type pos);
420 Inset const * GetInset(size_type pos) const;
422 void OpenFootnote(size_type pos);
424 void CloseFootnote(size_type pos);
425 /// important for cut and paste
426 void CopyIntoMinibuffer(size_type pos) const;
428 void CutIntoMinibuffer(size_type pos);
430 bool InsertFromMinibuffer(size_type pos);
433 bool IsHfill(size_type pos) const;
435 bool IsInset(size_type pos) const;
437 bool IsFloat(size_type pos) const;
439 bool IsNewline(size_type pos) const;
441 bool IsSeparator(size_type pos) const;
443 bool IsLineSeparator(size_type pos) const;
445 bool IsKomma(size_type pos) const;
446 /// Used by the spellchecker
447 bool IsLetter(size_type pos) const;
449 bool IsWord(size_type pos) const;
451 /** This one resets all layout and dtp switches but not the font
452 of the single characters
456 /** paste this paragraph with the next one
457 be carefull, this doesent make any check at all
459 void PasteParagraph();
461 /// used to remove the error messages
462 int AutoDeleteInsets();
464 /// returns -1 if inset not found
465 int GetPositionOfInset(Inset * inset) const;
467 /// ok and now some footnote functions
468 void OpenFootnotes();
471 void CloseFootnotes();
474 LyXParagraph * FirstSelfrowPar();
477 int ClearParagraph() {
479 if (!IsDummy() && !table){
482 || IsLineSeparator(0))){
490 /** A paragraph following a footnote is a "dummy". A paragraph
491 with a footnote in it is stored as three paragraphs:
492 First a paragraph with the text up to the footnote, then
493 one (or more) paragraphs with the footnote, and finally
494 the a paragraph with the text after the footnote. Only the
495 first paragraph keeps information about layoutparameters, */
496 bool IsDummy() const;
498 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
499 I have to set it on each of it's elements */
501 void SetPExtraType(int type, char const * width, char const * widthp);
503 void UnsetPExtraType();
506 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
509 bool linuxDocConvertChar(char c, string & sgml_string);
511 void DocBookContTableRows(std::ostream &, string & extra,
512 int & desc_on, size_type i,
513 int current_cell_number, int & column);
515 void SimpleDocBookOneTablePar(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(std::ostream &, TexRow & texrow,
576 std::ostream & foot, TexRow & foot_texrow,
579 LyXParagraph * TeXFootnote(std::ostream &, TexRow & texrow,
580 std::ostream & foot, TexRow & foot_texrow,
584 bool SimpleTeXOneTablePar(std::ostream &, TexRow & texrow);
586 bool TeXContTableRows(std::ostream &, size_type i,
587 int current_cell_number,
588 int & column, TexRow & texrow);
590 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
592 int & column, LyXFont const & font,
593 LyXLayout const & style);
595 void SimpleTeXSpecialChars(std::ostream &, TexRow & texrow,
597 LyXFont & font, LyXFont & running_font,
598 LyXFont & basefont, bool & open_font,
599 LyXLayout const & style,
601 int & column, char const c);
605 static unsigned int paragraph_id;
607 class inset_iterator {
610 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
611 inset_iterator & operator++() {
615 Inset * operator*() { return (*it).inset; }
616 size_type getPos() {return (*it).pos; }
617 bool operator==(inset_iterator const & iter) const {
618 return it == iter.it;
620 bool operator!=(inset_iterator const & iter) const {
621 return it != iter.it;
624 InsetList::iterator it;
627 inset_iterator inset_iterator_begin() {
628 return inset_iterator(insetlist.begin());
631 inset_iterator inset_iterator_end() {
632 return inset_iterator(insetlist.end());
635 inset_iterator InsetIterator(size_type pos);