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
124 LyXParagraph(LyXParagraph * par);
125 /// the destruktors removes the new paragraph from the list
129 Language const * getParLanguage() const;
131 Language const * getLetterLanguage(size_type pos) const;
134 LyXDirection getParDirection() const;
136 LyXDirection getLetterDirection(size_type pos) const;
139 void writeFile(std::ostream &, BufferParams const &, char, char) const;
141 void validate(LaTeXFeatures &) const;
148 void id(int id_arg) {
156 LyXParagraph * TeXOnePar(std::ostream &, TexRow & texrow,
157 std::ostream & foot, TexRow & foot_texrow,
160 bool SimpleTeXOnePar(std::ostream &, TexRow & texrow);
163 LyXParagraph * TeXEnvironment(std::ostream &, TexRow & texrow,
164 std::ostream & foot, TexRow & foot_texrow,
167 LyXParagraph * Clone() const;
170 bool HasSameLayout(LyXParagraph const * par) const;
173 void MakeSameLayout(LyXParagraph const * par);
175 /// Is it the first par with same depth and layout?
176 bool IsFirstInSequence() const {
177 LyXParagraph const * dhook = DepthHook(GetDepth());
178 return (dhook == this
179 || dhook->GetLayout() != GetLayout()
180 || dhook->GetDepth() != GetDepth());
183 /** Check if the current paragraph is the last paragraph in a
185 int GetEndLabel() const;
187 Inset * InInset() { return inset_owner; }
188 void SetInsetOwner(Inset *i) { inset_owner = i; }
198 size_type size() const { return text.size(); }
201 text.resize(text.size());
203 void setContentsFromPar(LyXParagraph * par) {
206 void clearContents() {
211 VSpace added_space_top;
214 VSpace added_space_bottom;
217 LyXTextClass::LayoutList::size_type layout;
221 \item no footnote, closed footnote,
222 \item open footnote, where footnote
223 \item means footnote-environment
226 footnote_flag footnoteflag;
228 /// footnote, margin, fig, tab
229 footnote_kind footnotekind;
231 //@Man: the LyX- DTP-switches
243 bool pagebreak_bottom;
255 block<int, 10> counter_;
258 void setCounter(int i, int v) { counter_[i] = v; }
259 int getCounter(int i) const { return counter_[i]; }
260 void incCounter(int i) { counter_[i]++; }
262 bool start_of_appendix;
273 /* This is for the paragraph extra stuff */
279 string pextra_widthp;
281 int pextra_alignment;
285 bool pextra_start_minipage;
291 string labelwidthstring;
297 LyXParagraph * previous;
299 /* table stuff -- begin*/
302 /* table stuff -- end*/
305 InsetBibKey * bibkey; // ale970302
307 /** these function are able to hide closed footnotes
309 LyXParagraph * Next();
312 LyXParagraph * Previous();
314 LyXParagraph const * Previous() const;
316 /** these function are able to hide open and closed footnotes
318 LyXParagraph * NextAfterFootnote();
320 LyXParagraph const * NextAfterFootnote() const;
323 LyXParagraph * PreviousBeforeFootnote();
325 LyXParagraph * LastPhysicalPar();
327 LyXParagraph const * LastPhysicalPar() const;
330 LyXParagraph * FirstPhysicalPar();
332 LyXParagraph const * FirstPhysicalPar() const;
334 /// returns the physical paragraph
335 LyXParagraph * ParFromPos(size_type pos);
336 /// returns the position in the physical par
337 int PositionInParFromPos(size_type pos) const;
339 /// for the environments
340 LyXParagraph * DepthHook(int depth);
341 /// for the environments
342 LyXParagraph const * DepthHook(int depth) const;
344 int BeginningOfMainBody() const;
346 string GetLabelstring() const;
348 /// the next two functions are for the manual labels
349 string GetLabelWidthString() const;
351 void SetLabelWidthString(string const & s);
353 LyXTextClass::LayoutList::size_type GetLayout() const;
355 char GetAlign() const;
357 char GetDepth() const;
359 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
361 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
363 int GetFirstCounter(int i) const;
365 size_type Last() const;
367 void Erase(size_type pos);
368 /** the flag determines wether the layout should be copied
370 void BreakParagraph(size_type pos, int flag);
372 void BreakParagraphConservative(size_type pos);
373 /** Get unistantiated font setting. Returns the difference
374 between the characters font and the layoutfont.
375 This is what is stored in the fonttable
377 LyXFont GetFontSettings(size_type pos) const;
379 LyXFont GetFirstFontSettings() const;
381 /** Get fully instantiated font. If pos == -1, use the layout
382 font attached to this paragraph.
383 If pos == -2, use the label font of the layout attached here.
384 In all cases, the font is instantiated, i.e. does not have any
385 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
388 LyXFont getFont(size_type pos) const;
390 char GetChar(size_type pos);
392 char GetChar(size_type pos) const;
393 /// The position must already exist.
394 void SetChar(size_type pos, char c) {
399 void SetFont(size_type pos, LyXFont const & font);
401 string GetWord(size_type &) const;
402 /// Returns the height of the highest font in range
403 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
404 size_type endpos) const;
406 void InsertChar(size_type pos, char c);
408 void InsertInset(size_type pos, Inset * inset);
410 bool InsertInsetAllowed(Inset * inset);
412 Inset * GetInset(size_type pos);
414 Inset const * GetInset(size_type pos) const;
416 Inset * ReturnNextInsetPointer(size_type & pos);
418 void OpenFootnote(size_type pos);
420 void CloseFootnote(size_type pos);
421 /// important for cut and paste
422 void CopyIntoMinibuffer(size_type pos) const;
424 void CutIntoMinibuffer(size_type pos);
426 bool InsertFromMinibuffer(size_type pos);
429 bool IsHfill(size_type pos) const;
431 bool IsInset(size_type pos) const;
433 bool IsFloat(size_type pos) const;
435 bool IsNewline(size_type pos) const;
437 bool IsSeparator(size_type pos) const;
439 bool IsLineSeparator(size_type pos) const;
441 bool IsKomma(size_type pos) const;
442 /// Used by the spellchecker
443 bool IsLetter(size_type pos) const;
445 bool IsWord(size_type pos) const;
447 /** This one resets all layout and dtp switches but not the font
448 of the single characters
452 /** paste this paragraph with the next one
453 be carefull, this doesent make any check at all
455 void PasteParagraph();
457 /// used to remove the error messages
458 int AutoDeleteInsets();
460 /// returns -1 if inset not found
461 int GetPositionOfInset(Inset * inset) const;
463 /// ok and now some footnote functions
464 void OpenFootnotes();
467 void CloseFootnotes();
470 LyXParagraph * FirstSelfrowPar();
473 int ClearParagraph() {
475 if (!IsDummy() && !table){
478 || IsLineSeparator(0))){
486 /** A paragraph following a footnote is a "dummy". A paragraph
487 with a footnote in it is stored as three paragraphs:
488 First a paragraph with the text up to the footnote, then
489 one (or more) paragraphs with the footnote, and finally
490 the a paragraph with the text after the footnote. Only the
491 first paragraph keeps information about layoutparameters, */
492 bool IsDummy() const;
494 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
495 I have to set it on each of it's elements */
497 void SetPExtraType(int type, char const * width, char const * widthp);
499 void UnsetPExtraType();
502 bool RoffContTableRows(std::ostream &, size_type i, int actcell);
505 bool linuxDocConvertChar(char c, string & sgml_string);
507 void DocBookContTableRows(std::ostream &, string & extra,
508 int & desc_on, size_type i,
509 int current_cell_number, int & column);
511 void SimpleDocBookOneTablePar(std::ostream &, string & extra,
512 int & desc_on, int depth);
520 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
523 /** A font entry covers a range of positions. Notice that the
524 entries in the list are inserted in random order.
525 I don't think it's worth the effort to implement a more effective
526 datastructure, because the number of different fonts in a paragraph
530 /// Start position of paragraph this font attribute covers
532 /// Ending position of paragraph this font attribute covers
534 /** Font. Interpretation of the font values:
535 If a value is LyXFont::INHERIT_*, it means that the font
536 attribute is inherited from either the layout of this
537 paragraph or, in the case of nested paragraphs, from the
538 layout in the environment one level up until completely
540 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
541 allowed in these font tables.
546 typedef std::list<FontTable> FontList;
550 typedef std::vector<InsetTable> InsetList;
554 LyXParagraph * TeXDeeper(std::ostream &, TexRow & texrow,
555 std::ostream & foot, TexRow & foot_texrow,
558 LyXParagraph * TeXFootnote(std::ostream &, TexRow & texrow,
559 std::ostream & foot, TexRow & foot_texrow,
561 LyXDirection par_direction);
563 bool SimpleTeXOneTablePar(std::ostream &, TexRow & texrow);
565 bool TeXContTableRows(std::ostream &, size_type i,
566 int current_cell_number,
567 int & column, TexRow & texrow);
569 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
571 int & column, LyXFont const & font,
572 LyXLayout const & style);
574 void SimpleTeXSpecialChars(std::ostream &, TexRow & texrow,
575 LyXFont & font, LyXFont & running_font,
576 LyXFont & basefont, bool & open_font,
577 LyXLayout const & style,
579 int & column, char const c);
583 static unsigned int paragraph_id;
586 inline bool operator<(LyXParagraph::InsetTable const & a,
587 LyXParagraph::InsetTable const & b)
589 return a.pos < b.pos;