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"
27 #include "direction.h"
36 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
51 enum MINIPAGE_ALIGNMENT {
55 MINIPAGE_ALIGN_MIDDLE,
80 //META_PROTECTED_SEPARATOR,
106 ALGORITHM, // Bernhard, 970807
108 WIDE_FIG, // CFO-G, 971106
110 WIDE_TAB // CFO-G, 971106
114 typedef char value_type;
116 typedef std::vector<value_type> TextContainer;
118 typedef int size_type;
122 /// 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 Language const * getLetterLanguage(size_type pos) const;
133 LyXDirection getParDirection() const;
135 LyXDirection getLetterDirection(size_type pos) const;
138 void writeFile(std::ostream &, BufferParams const &, char, char) const;
140 void validate(LaTeXFeatures &) const;
147 void id(int id_arg) {
155 LyXParagraph * TeXOnePar(std::ostream &, TexRow & texrow,
156 std::ostream & foot, TexRow & foot_texrow,
159 bool SimpleTeXOnePar(std::ostream &, TexRow & texrow);
162 LyXParagraph * TeXEnvironment(std::ostream &, TexRow & texrow,
163 std::ostream & foot, TexRow & foot_texrow,
166 LyXParagraph * Clone() const;
169 bool HasSameLayout(LyXParagraph const * par) const;
172 void MakeSameLayout(LyXParagraph const * par);
174 /// Is it the first par with same depth and layout?
175 bool IsFirstInSequence() const {
176 LyXParagraph const * dhook = DepthHook(GetDepth());
177 return (dhook == this
178 || dhook->GetLayout() != GetLayout()
179 || dhook->GetDepth() != GetDepth());
182 /** Check if the current paragraph is the last paragraph in a
184 int GetEndLabel() const;
191 size_type size() const { return text.size(); }
194 text.resize(text.size());
196 void setContentsFromPar(LyXParagraph * par) {
199 void clearContents() {
204 VSpace added_space_top;
207 VSpace added_space_bottom;
210 LyXTextClass::LayoutList::size_type layout;
214 \item no footnote, closed footnote,
215 \item open footnote, where footnote
216 \item means footnote-environment
219 footnote_flag footnoteflag;
221 /// footnote, margin, fig, tab
222 footnote_kind footnotekind;
224 //@Man: the LyX- DTP-switches
236 bool pagebreak_bottom;
248 block<int, 10> counter_;
251 void setCounter(int i, int v) { counter_[i] = v; }
252 int getCounter(int i) const { return counter_[i]; }
253 void incCounter(int i) { counter_[i]++; }
255 bool start_of_appendix;
266 /* This is for the paragraph extra stuff */
272 string pextra_widthp;
274 int pextra_alignment;
278 bool pextra_start_minipage;
284 string labelwidthstring;
290 LyXParagraph * previous;
292 /* table stuff -- begin*/
295 /* table stuff -- end*/
298 InsetBibKey * bibkey; // ale970302
300 /** these function are able to hide closed footnotes
302 LyXParagraph * Next();
305 LyXParagraph * Previous();
307 LyXParagraph const * Previous() const;
309 /** these function are able to hide open and closed footnotes
311 LyXParagraph * NextAfterFootnote();
313 LyXParagraph const * NextAfterFootnote() const;
316 LyXParagraph * PreviousBeforeFootnote();
318 LyXParagraph * LastPhysicalPar();
320 LyXParagraph const * LastPhysicalPar() const;
323 LyXParagraph * FirstPhysicalPar();
325 LyXParagraph const * FirstPhysicalPar() const;
327 /// returns the physical paragraph
328 LyXParagraph * ParFromPos(size_type pos);
329 /// returns the position in the physical par
330 int PositionInParFromPos(size_type pos) const;
332 /// for the environments
333 LyXParagraph * DepthHook(int depth);
334 /// for the environments
335 LyXParagraph const * DepthHook(int depth) const;
337 int BeginningOfMainBody() const;
339 string GetLabelstring() const;
341 /// the next two functions are for the manual labels
342 string GetLabelWidthString() const;
344 void SetLabelWidthString(string const & s);
346 LyXTextClass::LayoutList::size_type GetLayout() const;
348 char GetAlign() const;
350 char GetDepth() const;
352 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
354 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
356 int GetFirstCounter(int i) const;
358 size_type Last() const;
360 void Erase(size_type pos);
361 /** the flag determines wether the layout should be copied
363 void BreakParagraph(size_type pos, int flag);
365 void BreakParagraphConservative(size_type pos);
366 /** Get unistantiated font setting. Returns the difference
367 between the characters font and the layoutfont.
368 This is what is stored in the fonttable
370 LyXFont GetFontSettings(size_type pos) const;
372 LyXFont GetFirstFontSettings() const;
374 /** Get fully instantiated font. If pos == -1, use the layout
375 font attached to this paragraph.
376 If pos == -2, use the label font of the layout attached here.
377 In all cases, the font is instantiated, i.e. does not have any
378 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
381 LyXFont getFont(size_type pos) const;
383 char GetChar(size_type pos);
385 char GetChar(size_type pos) const;
386 /// The position must already exist.
387 void SetChar(size_type pos, char c) {
392 void SetFont(size_type pos, LyXFont const & font);
394 string GetWord(size_type &) const;
395 /// Returns the height of the highest font in range
396 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
397 size_type endpos) const;
399 void InsertChar(size_type pos, char c);
401 void InsertInset(size_type pos, Inset * inset);
403 Inset * GetInset(size_type pos);
405 Inset const * GetInset(size_type pos) const;
407 Inset * ReturnNextInsetPointer(size_type & pos);
409 void OpenFootnote(size_type pos);
411 void CloseFootnote(size_type pos);
412 /// important for cut and paste
413 void CopyIntoMinibuffer(size_type pos) const;
415 void CutIntoMinibuffer(size_type pos);
417 void InsertFromMinibuffer(size_type pos);
420 bool IsHfill(size_type pos) const;
422 bool IsInset(size_type pos) const;
424 bool IsFloat(size_type pos) const;
426 bool IsNewline(size_type pos) const;
428 bool IsSeparator(size_type pos) const;
430 bool IsLineSeparator(size_type pos) const;
432 bool IsKomma(size_type pos) const;
433 /// Used by the spellchecker
434 bool IsLetter(size_type pos) const;
436 bool IsWord(size_type pos) const;
438 /** This one resets all layout and dtp switches but not the font
439 of the single characters
443 /** paste this paragraph with the next one
444 be carefull, this doesent make any check at all
446 void PasteParagraph();
448 /// used to remove the error messages
449 int AutoDeleteInsets();
451 /// returns -1 if inset not found
452 int GetPositionOfInset(Inset * inset) const;
454 /// ok and now some footnote functions
455 void OpenFootnotes();
458 void CloseFootnotes();
461 LyXParagraph * FirstSelfrowPar();
464 int ClearParagraph() {
466 if (!IsDummy() && !table){
469 || IsLineSeparator(0))){
477 /** A paragraph following a footnote is a "dummy". A paragraph
478 with a footnote in it is stored as three paragraphs:
479 First a paragraph with the text up to the footnote, then
480 one (or more) paragraphs with the footnote, and finally
481 the a paragraph with the text after the footnote. Only the
482 first paragraph keeps information about layoutparameters, */
483 bool IsDummy() const;
485 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
486 I have to set it on each of it's elements */
488 void SetPExtraType(int type, char const * width, char const * widthp);
490 void UnsetPExtraType();
493 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
496 bool linuxDocConvertChar(char c, string & sgml_string);
498 void DocBookContTableRows(std::ostream &, string & extra,
499 int & desc_on, size_type i,
500 int current_cell_number, int & column);
502 void SimpleDocBookOneTablePar(std::ostream &, string & extra,
503 int & desc_on, int depth);
511 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
514 /** A font entry covers a range of positions. Notice that the
515 entries in the list are inserted in random order.
516 I don't think it's worth the effort to implement a more effective
517 datastructure, because the number of different fonts in a paragraph
521 /// Start position of paragraph this font attribute covers
523 /// Ending position of paragraph this font attribute covers
525 /** Font. Interpretation of the font values:
526 If a value is LyXFont::INHERIT_*, it means that the font
527 attribute is inherited from either the layout of this
528 paragraph or, in the case of nested paragraphs, from the
529 layout in the environment one level up until completely
531 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
532 allowed in these font tables.
537 typedef std::list<FontTable> FontList;
541 typedef std::vector<InsetTable> InsetList;
545 LyXParagraph * TeXDeeper(std::ostream &, TexRow & texrow,
546 std::ostream & foot, TexRow & foot_texrow,
549 LyXParagraph * TeXFootnote(std::ostream &, TexRow & texrow,
550 std::ostream & foot, TexRow & foot_texrow,
552 LyXDirection par_direction);
554 bool SimpleTeXOneTablePar(std::ostream &, TexRow & texrow);
556 bool TeXContTableRows(std::ostream &, size_type i,
557 int current_cell_number,
558 int & column, TexRow & texrow);
560 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
562 int & column, LyXFont const & font,
563 LyXLayout const & style);
565 void SimpleTeXSpecialChars(std::ostream &, TexRow & texrow,
566 LyXFont & font, LyXFont & running_font,
567 LyXFont & basefont, bool & open_font,
568 LyXLayout const & style,
570 int & column, char const c);
574 static unsigned int paragraph_id;
577 inline bool operator<(LyXParagraph::InsetTable const & a,
578 LyXParagraph::InsetTable const & b)
580 return a.pos < b.pos;