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"
40 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
55 enum MINIPAGE_ALIGNMENT {
59 MINIPAGE_ALIGN_MIDDLE,
84 //META_PROTECTED_SEPARATOR,
110 ALGORITHM, // Bernhard, 970807
112 WIDE_FIG, // CFO-G, 971106
114 WIDE_TAB // CFO-G, 971106
118 typedef char value_type;
120 typedef vector<value_type> TextContainer;
122 typedef int size_type;
126 /// this konstruktor inserts the new paragraph in a list
127 LyXParagraph(LyXParagraph * par);
128 /// the destruktors removes the new paragraph from the list
132 Language const * getParLanguage() const;
134 Language const * getLetterLanguage(size_type pos) const;
137 LyXDirection getParDirection() const;
139 LyXDirection getLetterDirection(size_type pos) const;
142 void writeFile(ostream &, BufferParams const &, char, char) const;
144 void validate(LaTeXFeatures &) const;
151 void id(int id_arg) {
159 LyXParagraph * TeXOnePar(ostream &, TexRow & texrow,
160 ostream & foot, TexRow & foot_texrow,
163 bool SimpleTeXOnePar(ostream &, TexRow & texrow);
166 LyXParagraph * TeXEnvironment(ostream &, TexRow & texrow,
167 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;
195 size_type size() const { return text.size(); }
198 text.resize(text.size());
200 void setContentsFromPar(LyXParagraph * par) {
203 void clearContents() {
208 VSpace added_space_top;
211 VSpace added_space_bottom;
214 LyXTextClass::LayoutList::size_type layout;
218 \item no footnote, closed footnote,
219 \item open footnote, where footnote
220 \item means footnote-environment
223 footnote_flag footnoteflag;
225 /// footnote, margin, fig, tab
226 footnote_kind footnotekind;
228 //@Man: the LyX- DTP-switches
240 bool pagebreak_bottom;
252 block<int, 10> counter_;
255 void setCounter(int i, int v) { counter_[i] = v; }
256 int getCounter(int i) const { return counter_[i]; }
257 void incCounter(int i) { counter_[i]++; }
259 bool start_of_appendix;
270 /* This is for the paragraph extra stuff */
276 string pextra_widthp;
278 int pextra_alignment;
282 bool pextra_start_minipage;
288 string labelwidthstring;
294 LyXParagraph * previous;
296 /* table stuff -- begin*/
299 /* table stuff -- end*/
302 InsetBibKey * bibkey; // ale970302
304 /** these function are able to hide closed footnotes
306 LyXParagraph * Next();
309 LyXParagraph * Previous();
311 LyXParagraph const * Previous() const;
313 /** these function are able to hide open and closed footnotes
315 LyXParagraph * NextAfterFootnote();
317 LyXParagraph const * NextAfterFootnote() const;
320 LyXParagraph * PreviousBeforeFootnote();
322 LyXParagraph * LastPhysicalPar();
324 LyXParagraph const * LastPhysicalPar() const;
327 LyXParagraph * FirstPhysicalPar();
329 LyXParagraph const * FirstPhysicalPar() const;
331 /// returns the physical paragraph
332 LyXParagraph * ParFromPos(size_type pos);
333 /// returns the position in the physical par
334 int PositionInParFromPos(size_type pos) const;
336 /// for the environments
337 LyXParagraph * DepthHook(int depth);
338 /// for the environments
339 LyXParagraph const * DepthHook(int depth) const;
341 int BeginningOfMainBody() const;
343 string GetLabestring() const;
345 /// the next two functions are for the manual labels
346 string GetLabelWidthString() const;
348 void SetLabelWidthString(string const & s);
350 LyXTextClass::LayoutList::size_type GetLayout() const;
352 char GetAlign() const;
354 char GetDepth() const;
356 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
358 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
360 int GetFirstCounter(int i) const;
362 size_type Last() const;
364 void Erase(size_type pos);
365 /** the flag determines wether the layout should be copied
367 void BreakParagraph(size_type pos, int flag);
369 void BreakParagraphConservative(size_type pos);
370 /** Get unistantiated font setting. Returns the difference
371 between the characters font and the layoutfont.
372 This is what is stored in the fonttable
374 LyXFont GetFontSettings(size_type pos) const;
376 LyXFont GetFirstFontSettings() const;
378 /** Get fully instantiated font. If pos == -1, use the layout
379 font attached to this paragraph.
380 If pos == -2, use the label font of the layout attached here.
381 In all cases, the font is instantiated, i.e. does not have any
382 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
385 LyXFont getFont(size_type pos) const;
387 char GetChar(size_type pos);
389 char GetChar(size_type pos) const;
390 /// The position must already exist.
391 void SetChar(size_type pos, char c) {
396 void SetFont(size_type pos, LyXFont const & font);
398 string GetWord(size_type &) const;
399 /// Returns the height of the highest font in range
400 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
401 size_type endpos) const;
403 void InsertChar(size_type pos, char c);
405 void InsertInset(size_type pos, Inset * inset);
407 Inset * GetInset(size_type pos);
409 Inset const * GetInset(size_type pos) const;
411 Inset * ReturnNextInsetPointer(size_type & pos);
413 void OpenFootnote(size_type pos);
415 void CloseFootnote(size_type pos);
416 /// important for cut and paste
417 void CopyIntoMinibuffer(size_type pos) const;
419 void CutIntoMinibuffer(size_type pos);
421 void InsertFromMinibuffer(size_type pos);
424 bool IsHfill(size_type pos) const;
426 bool IsInset(size_type pos) const;
428 bool IsFloat(size_type pos) const;
430 bool IsNewline(size_type pos) const;
432 bool IsSeparator(size_type pos) const;
434 bool IsLineSeparator(size_type pos) const;
436 bool IsKomma(size_type pos) const;
437 /// Used by the spellchecker
438 bool IsLetter(size_type pos) const;
440 bool IsWord(size_type pos) const;
442 /** This one resets all layout and dtp switches but not the font
443 of the single characters
447 /** paste this paragraph with the next one
448 be carefull, this doesent make any check at all
450 void PasteParagraph();
452 /// used to remove the error messages
453 int AutoDeleteInsets();
455 /// returns -1 if inset not found
456 int GetPositionOfInset(Inset * inset) const;
458 /// ok and now some footnote functions
459 void OpenFootnotes();
462 void CloseFootnotes();
465 LyXParagraph * FirstSelfrowPar();
468 int ClearParagraph() {
470 if (!IsDummy() && !table){
473 || IsLineSeparator(0))){
481 /** A paragraph following a footnote is a "dummy". A paragraph
482 with a footnote in it is stored as three paragraphs:
483 First a paragraph with the text up to the footnote, then
484 one (or more) paragraphs with the footnote, and finally
485 the a paragraph with the text after the footnote. Only the
486 first paragraph keeps information about layoutparameters, */
487 bool IsDummy() const {
488 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
489 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
492 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
493 I have to set it on each of it's elements */
495 void SetPExtraType(int type, char const * width, char const * widthp);
497 void UnsetPExtraType();
500 bool RoffContTableRows(ostream &, size_type i, int actcell);
503 bool linuxDocConvertChar(char c, string & sgml_string);
505 void DocBookContTableRows(ostream &, string & extra,
506 int & desc_on, size_type i,
507 int current_cell_number, int & column);
509 void SimpleDocBookOneTablePar(ostream &, string & extra,
510 int & desc_on, int depth);
512 /** A font entry covers a range of positions. Notice that the
513 entries in the list are inserted in random order.
514 I don't think it's worth the effort to implement a more effective
515 datastructure, because the number of different fonts in a paragraph
519 /// Start position of paragraph this font attribute covers
521 /// Ending position of paragraph this font attribute covers
523 /** Font. Interpretation of the font values:
524 If a value is LyXFont::INHERIT_*, it means that the font
525 attribute is inherited from either the layout of this
526 paragraph or, in the case of nested paragraphs, from the
527 layout in the environment one level up until completely
529 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
530 allowed in these font tables.
541 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
544 typedef list<FontTable> FontList;
548 typedef vector<InsetTable> InsetList;
552 LyXParagraph * TeXDeeper(ostream &, TexRow & texrow,
553 ostream & foot, TexRow & foot_texrow,
556 LyXParagraph * TeXFootnote(ostream &, TexRow & texrow,
557 ostream & foot, TexRow & foot_texrow,
559 LyXDirection par_direction);
561 bool SimpleTeXOneTablePar(ostream &, TexRow & texrow);
563 bool TeXContTableRows(ostream &, size_type i,
564 int current_cell_number,
565 int & column, TexRow & texrow);
567 void SimpleTeXBlanks(ostream &, TexRow & texrow,
569 int & column, LyXFont const & font,
570 LyXLayout const & style);
572 void SimpleTeXSpecialChars(ostream &, TexRow & texrow,
573 LyXFont & font, LyXFont & running_font,
574 LyXFont & basefont, bool & open_font,
575 LyXLayout const & style,
577 int & column, char const c);
581 static unsigned int paragraph_id;
584 inline bool operator<(LyXParagraph::InsetTable const & a,
585 LyXParagraph::InsetTable const & b)
587 return a.pos < b.pos;