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();
137 void writeFile(std::ostream &, BufferParams const &, char, char) const;
139 void validate(LaTeXFeatures &) const;
146 void id(int id_arg) {
154 LyXParagraph * TeXOnePar(std::ostream &, TexRow & texrow,
155 std::ostream & foot, TexRow & foot_texrow,
158 bool SimpleTeXOnePar(std::ostream &, TexRow & texrow);
161 LyXParagraph * TeXEnvironment(std::ostream &, TexRow & texrow,
162 std::ostream & foot, TexRow & foot_texrow,
165 LyXParagraph * Clone() const;
168 bool HasSameLayout(LyXParagraph const * par) const;
171 void MakeSameLayout(LyXParagraph const * par);
173 /// Is it the first par with same depth and layout?
174 bool IsFirstInSequence() const {
175 LyXParagraph const * dhook = DepthHook(GetDepth());
176 return (dhook == this
177 || dhook->GetLayout() != GetLayout()
178 || dhook->GetDepth() != GetDepth());
181 /** Check if the current paragraph is the last paragraph in a
183 int GetEndLabel() const;
185 Inset * InInset() { return inset_owner; }
187 void SetInsetOwner(Inset * i) { inset_owner = i; }
196 size_type size() const { return text.size(); }
199 text.resize(text.size());
201 void setContentsFromPar(LyXParagraph * par) {
204 void clearContents() {
209 VSpace added_space_top;
212 VSpace added_space_bottom;
218 LyXTextClass::LayoutList::size_type layout;
222 \item no footnote, closed footnote,
223 \item open footnote, where footnote
224 \item means footnote-environment
227 footnote_flag footnoteflag;
229 /// footnote, margin, fig, tab
230 footnote_kind footnotekind;
232 //@Man: the LyX- DTP-switches
244 bool pagebreak_bottom;
256 block<int, 10> counter_;
259 void setCounter(int i, int v) { counter_[i] = v; }
260 int getCounter(int i) const { return counter_[i]; }
261 void incCounter(int i) { counter_[i]++; }
263 bool start_of_appendix;
274 /* This is for the paragraph extra stuff */
280 string pextra_widthp;
282 int pextra_alignment;
286 bool pextra_start_minipage;
292 string labelwidthstring;
298 LyXParagraph * previous;
300 /* table stuff -- begin*/
303 /* table stuff -- end*/
306 InsetBibKey * bibkey; // ale970302
308 /** these function are able to hide closed footnotes
310 LyXParagraph * Next();
313 LyXParagraph * Previous();
315 LyXParagraph const * Previous() const;
317 /** these function are able to hide open and closed footnotes
319 LyXParagraph * NextAfterFootnote();
321 LyXParagraph const * NextAfterFootnote() const;
324 LyXParagraph * PreviousBeforeFootnote();
326 LyXParagraph * LastPhysicalPar();
328 LyXParagraph const * LastPhysicalPar() const;
331 LyXParagraph * FirstPhysicalPar();
333 LyXParagraph const * FirstPhysicalPar() const;
335 /// returns the physical paragraph
336 LyXParagraph * ParFromPos(size_type pos);
337 /// returns the position in the physical par
338 int PositionInParFromPos(size_type pos) const;
340 /// for the environments
341 LyXParagraph * DepthHook(int depth);
342 /// for the environments
343 LyXParagraph const * DepthHook(int depth) const;
345 int BeginningOfMainBody() const;
347 string GetLabelstring() const;
349 /// the next two functions are for the manual labels
350 string GetLabelWidthString() const;
352 void SetLabelWidthString(string const & s);
354 LyXTextClass::LayoutList::size_type GetLayout() const;
356 char GetAlign() const;
358 char GetDepth() const;
360 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
362 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
364 int GetFirstCounter(int i) const;
366 size_type Last() const;
368 void Erase(size_type pos);
369 /** the flag determines wether the layout should be copied
371 void BreakParagraph(size_type pos, int flag);
373 void BreakParagraphConservative(size_type pos);
374 /** Get unistantiated font setting. Returns the difference
375 between the characters font and the layoutfont.
376 This is what is stored in the fonttable
378 LyXFont GetFontSettings(size_type pos) const;
380 LyXFont GetFirstFontSettings() const;
382 /** Get fully instantiated font. If pos == -1, use the layout
383 font attached to this paragraph.
384 If pos == -2, use the label font of the layout attached here.
385 In all cases, the font is instantiated, i.e. does not have any
386 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
389 LyXFont getFont(size_type pos) const;
391 char GetChar(size_type pos);
393 char GetChar(size_type pos) const;
394 /// The position must already exist.
395 void SetChar(size_type pos, char c) {
400 void SetFont(size_type pos, LyXFont const & font);
402 string GetWord(size_type &) const;
403 /// Returns the height of the highest font in range
404 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
405 size_type endpos) const;
407 void InsertChar(size_type pos, char c);
409 void InsertInset(size_type pos, Inset * inset);
411 bool InsertInsetAllowed(Inset * inset);
413 Inset * GetInset(size_type pos);
415 Inset const * GetInset(size_type pos) const;
417 Inset * ReturnNextInsetPointer(size_type & pos);
419 void OpenFootnote(size_type pos);
421 void CloseFootnote(size_type pos);
422 /// important for cut and paste
423 void CopyIntoMinibuffer(size_type pos) const;
425 void CutIntoMinibuffer(size_type pos);
427 bool InsertFromMinibuffer(size_type pos);
430 bool IsHfill(size_type pos) const;
432 bool IsInset(size_type pos) const;
434 bool IsFloat(size_type pos) const;
436 bool IsNewline(size_type pos) const;
438 bool IsSeparator(size_type pos) const;
440 bool IsLineSeparator(size_type pos) const;
442 bool IsKomma(size_type pos) const;
443 /// Used by the spellchecker
444 bool IsLetter(size_type pos) const;
446 bool IsWord(size_type pos) const;
448 /** This one resets all layout and dtp switches but not the font
449 of the single characters
453 /** paste this paragraph with the next one
454 be carefull, this doesent make any check at all
456 void PasteParagraph();
458 /// used to remove the error messages
459 int AutoDeleteInsets();
461 /// returns -1 if inset not found
462 int GetPositionOfInset(Inset * inset) const;
464 /// ok and now some footnote functions
465 void OpenFootnotes();
468 void CloseFootnotes();
471 LyXParagraph * FirstSelfrowPar();
474 int ClearParagraph() {
476 if (!IsDummy() && !table){
479 || IsLineSeparator(0))){
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(int type, char const * width, char const * widthp);
500 void UnsetPExtraType();
503 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
506 bool linuxDocConvertChar(char c, string & sgml_string);
508 void DocBookContTableRows(std::ostream &, string & extra,
509 int & desc_on, size_type i,
510 int current_cell_number, int & column);
512 void SimpleDocBookOneTablePar(std::ostream &, string & extra,
513 int & desc_on, int depth);
522 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
526 /// used by lower_bound
528 int operator()(LyXParagraph::InsetTable const & a,
529 LyXParagraph::size_type pos) const {
532 /// used by upper_bound
534 int operator()(LyXParagraph::size_type pos,
535 LyXParagraph::InsetTable const & a) const {
539 /** A font entry covers a range of positions. Notice that the
540 entries in the list are inserted in random order.
541 I don't think it's worth the effort to implement a more effective
542 datastructure, because the number of different fonts in a paragraph
546 /// Start position of paragraph this font attribute covers
548 /// Ending position of paragraph this font attribute covers
550 /** Font. Interpretation of the font values:
551 If a value is LyXFont::INHERIT_*, it means that the font
552 attribute is inherited from either the layout of this
553 paragraph or, in the case of nested paragraphs, from the
554 layout in the environment one level up until completely
556 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
557 allowed in these font tables.
562 typedef std::list<FontTable> FontList;
566 typedef std::vector<InsetTable> InsetList;
570 LyXParagraph * TeXDeeper(std::ostream &, TexRow & texrow,
571 std::ostream & foot, TexRow & foot_texrow,
574 LyXParagraph * TeXFootnote(std::ostream &, TexRow & texrow,
575 std::ostream & foot, TexRow & foot_texrow,
579 bool SimpleTeXOneTablePar(std::ostream &, TexRow & texrow);
581 bool TeXContTableRows(std::ostream &, size_type i,
582 int current_cell_number,
583 int & column, TexRow & texrow);
585 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
587 int & column, LyXFont const & font,
588 LyXLayout const & style);
590 void SimpleTeXSpecialChars(std::ostream &, TexRow & texrow,
591 LyXFont & font, LyXFont & running_font,
592 LyXFont & basefont, bool & open_font,
593 LyXLayout const & style,
595 int & column, char const c);
599 static unsigned int paragraph_id;