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 StripLeadingSpaces(LyXTextClassList::size_type tclass);
479 /** A paragraph following a footnote is a "dummy". A paragraph
480 with a footnote in it is stored as three paragraphs:
481 First a paragraph with the text up to the footnote, then
482 one (or more) paragraphs with the footnote, and finally
483 the a paragraph with the text after the footnote. Only the
484 first paragraph keeps information about layoutparameters, */
485 bool IsDummy() const;
487 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
488 I have to set it on each of it's elements */
490 void SetPExtraType(int type, char const * width, char const * widthp);
492 void UnsetPExtraType();
495 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
498 bool linuxDocConvertChar(char c, string & sgml_string);
500 void DocBookContTableRows(std::ostream &, string & extra,
501 int & desc_on, size_type i,
502 int current_cell_number, int & column);
504 void SimpleDocBookOneTablePar(std::ostream &, string & extra,
505 int & desc_on, int depth);
514 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
517 friend struct matchIT;
520 /// used by lower_bound
522 int operator()(LyXParagraph::InsetTable const & a,
523 LyXParagraph::size_type pos) const {
526 /// used by upper_bound
528 int operator()(LyXParagraph::size_type pos,
529 LyXParagraph::InsetTable const & a) const {
533 /** A font entry covers a range of positions. Notice that the
534 entries in the list are inserted in random order.
535 I don't think it's worth the effort to implement a more effective
536 datastructure, because the number of different fonts in a paragraph
540 /// Start position of paragraph this font attribute covers
542 /// Ending position of paragraph this font attribute covers
544 /** Font. Interpretation of the font values:
545 If a value is LyXFont::INHERIT_*, it means that the font
546 attribute is inherited from either the layout of this
547 paragraph or, in the case of nested paragraphs, from the
548 layout in the environment one level up until completely
550 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
551 allowed in these font tables.
556 typedef std::list<FontTable> FontList;
560 typedef std::vector<InsetTable> InsetList;
564 LyXParagraph * TeXDeeper(std::ostream &, TexRow & texrow,
565 std::ostream & foot, TexRow & foot_texrow,
568 LyXParagraph * TeXFootnote(std::ostream &, TexRow & texrow,
569 std::ostream & foot, TexRow & foot_texrow,
573 bool SimpleTeXOneTablePar(std::ostream &, TexRow & texrow);
575 bool TeXContTableRows(std::ostream &, size_type i,
576 int current_cell_number,
577 int & column, TexRow & texrow);
579 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
581 int & column, LyXFont const & font,
582 LyXLayout const & style);
584 void SimpleTeXSpecialChars(std::ostream &, TexRow & texrow,
586 LyXFont & font, LyXFont & running_font,
587 LyXFont & basefont, bool & open_font,
588 LyXLayout const & style,
590 int & column, char const c);
594 static unsigned int paragraph_id;
596 class inset_iterator {
599 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
600 inset_iterator & operator++() {
604 Inset * operator*() { return (*it).inset; }
605 size_type getPos() {return (*it).pos; }
606 bool operator==(inset_iterator const & iter) const {
607 return it == iter.it;
609 bool operator!=(inset_iterator const & iter) const {
610 return it != iter.it;
613 InsetList::iterator it;
616 inset_iterator inset_iterator_begin() {
617 return inset_iterator(insetlist.begin());
620 inset_iterator inset_iterator_end() {
621 return inset_iterator(insetlist.end());
624 inset_iterator InsetIterator(size_type pos);