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;
215 LyXTextClass::LayoutList::size_type layout;
219 \item no footnote, closed footnote,
220 \item open footnote, where footnote
221 \item means footnote-environment
224 footnote_flag footnoteflag;
226 /// footnote, margin, fig, tab
227 footnote_kind footnotekind;
229 //@Man: the LyX- DTP-switches
241 bool pagebreak_bottom;
253 block<int, 10> counter_;
256 void setCounter(int i, int v) { counter_[i] = v; }
257 int getCounter(int i) const { return counter_[i]; }
258 void incCounter(int i) { counter_[i]++; }
260 bool start_of_appendix;
271 /* This is for the paragraph extra stuff */
277 string pextra_widthp;
279 int pextra_alignment;
283 bool pextra_start_minipage;
289 string labelwidthstring;
295 LyXParagraph * previous;
297 /* table stuff -- begin*/
300 /* table stuff -- end*/
303 InsetBibKey * bibkey; // ale970302
305 /** these function are able to hide closed footnotes
307 LyXParagraph * Next();
310 LyXParagraph * Previous();
312 LyXParagraph const * Previous() const;
314 /** these function are able to hide open and closed footnotes
316 LyXParagraph * NextAfterFootnote();
318 LyXParagraph const * NextAfterFootnote() const;
321 LyXParagraph * PreviousBeforeFootnote();
323 LyXParagraph * LastPhysicalPar();
325 LyXParagraph const * LastPhysicalPar() const;
328 LyXParagraph * FirstPhysicalPar();
330 LyXParagraph const * FirstPhysicalPar() const;
332 /// returns the physical paragraph
333 LyXParagraph * ParFromPos(size_type pos);
334 /// returns the position in the physical par
335 int PositionInParFromPos(size_type pos) const;
337 /// for the environments
338 LyXParagraph * DepthHook(int depth);
339 /// for the environments
340 LyXParagraph const * DepthHook(int depth) const;
342 int BeginningOfMainBody() const;
344 string GetLabelstring() const;
346 /// the next two functions are for the manual labels
347 string GetLabelWidthString() const;
349 void SetLabelWidthString(string const & s);
351 LyXTextClass::LayoutList::size_type GetLayout() const;
353 char GetAlign() const;
355 char GetDepth() const;
357 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
359 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
361 int GetFirstCounter(int i) const;
363 size_type Last() const;
365 void Erase(size_type pos);
366 /** the flag determines wether the layout should be copied
368 void BreakParagraph(size_type pos, int flag);
370 void BreakParagraphConservative(size_type pos);
371 /** Get unistantiated font setting. Returns the difference
372 between the characters font and the layoutfont.
373 This is what is stored in the fonttable
375 LyXFont GetFontSettings(size_type pos) const;
377 LyXFont GetFirstFontSettings() const;
379 /** Get fully instantiated font. If pos == -1, use the layout
380 font attached to this paragraph.
381 If pos == -2, use the label font of the layout attached here.
382 In all cases, the font is instantiated, i.e. does not have any
383 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
386 LyXFont getFont(size_type pos) const;
388 char GetChar(size_type pos);
390 char GetChar(size_type pos) const;
391 /// The position must already exist.
392 void SetChar(size_type pos, char c) {
397 void SetFont(size_type pos, LyXFont const & font);
399 string GetWord(size_type &) const;
400 /// Returns the height of the highest font in range
401 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
402 size_type endpos) const;
404 void InsertChar(size_type pos, char c);
406 void InsertInset(size_type pos, Inset * inset);
408 bool InsertInsetAllowed(Inset * inset);
410 Inset * GetInset(size_type pos);
412 Inset const * GetInset(size_type pos) const;
414 Inset * ReturnNextInsetPointer(size_type & pos);
416 void OpenFootnote(size_type pos);
418 void CloseFootnote(size_type pos);
419 /// important for cut and paste
420 void CopyIntoMinibuffer(size_type pos) const;
422 void CutIntoMinibuffer(size_type pos);
424 bool InsertFromMinibuffer(size_type pos);
427 bool IsHfill(size_type pos) const;
429 bool IsInset(size_type pos) const;
431 bool IsFloat(size_type pos) const;
433 bool IsNewline(size_type pos) const;
435 bool IsSeparator(size_type pos) const;
437 bool IsLineSeparator(size_type pos) const;
439 bool IsKomma(size_type pos) const;
440 /// Used by the spellchecker
441 bool IsLetter(size_type pos) const;
443 bool IsWord(size_type pos) const;
445 /** This one resets all layout and dtp switches but not the font
446 of the single characters
450 /** paste this paragraph with the next one
451 be carefull, this doesent make any check at all
453 void PasteParagraph();
455 /// used to remove the error messages
456 int AutoDeleteInsets();
458 /// returns -1 if inset not found
459 int GetPositionOfInset(Inset * inset) const;
461 /// ok and now some footnote functions
462 void OpenFootnotes();
465 void CloseFootnotes();
468 LyXParagraph * FirstSelfrowPar();
471 int ClearParagraph() {
473 if (!IsDummy() && !table){
476 || IsLineSeparator(0))){
484 /** A paragraph following a footnote is a "dummy". A paragraph
485 with a footnote in it is stored as three paragraphs:
486 First a paragraph with the text up to the footnote, then
487 one (or more) paragraphs with the footnote, and finally
488 the a paragraph with the text after the footnote. Only the
489 first paragraph keeps information about layoutparameters, */
490 bool IsDummy() const;
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(std::ostream &, size_type i, int actcell);
503 bool linuxDocConvertChar(char c, string & sgml_string);
505 void DocBookContTableRows(std::ostream &, string & extra,
506 int & desc_on, size_type i,
507 int current_cell_number, int & column);
509 void SimpleDocBookOneTablePar(std::ostream &, string & extra,
510 int & desc_on, int depth);
519 InsetTable(size_type p, Inset * i) { pos = p; inset = i;}
523 /// used by lower_bound
525 int operator()(LyXParagraph::InsetTable const & a,
526 LyXParagraph::size_type pos) const {
529 /// used by upper_bound
531 int operator()(LyXParagraph::size_type pos,
532 LyXParagraph::InsetTable const & a) const {
536 /** A font entry covers a range of positions. Notice that the
537 entries in the list are inserted in random order.
538 I don't think it's worth the effort to implement a more effective
539 datastructure, because the number of different fonts in a paragraph
543 /// Start position of paragraph this font attribute covers
545 /// Ending position of paragraph this font attribute covers
547 /** Font. Interpretation of the font values:
548 If a value is LyXFont::INHERIT_*, it means that the font
549 attribute is inherited from either the layout of this
550 paragraph or, in the case of nested paragraphs, from the
551 layout in the environment one level up until completely
553 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
554 allowed in these font tables.
559 typedef std::list<FontTable> FontList;
563 typedef std::vector<InsetTable> InsetList;
567 LyXParagraph * TeXDeeper(std::ostream &, TexRow & texrow,
568 std::ostream & foot, TexRow & foot_texrow,
571 LyXParagraph * TeXFootnote(std::ostream &, TexRow & texrow,
572 std::ostream & foot, TexRow & foot_texrow,
576 bool SimpleTeXOneTablePar(std::ostream &, TexRow & texrow);
578 bool TeXContTableRows(std::ostream &, size_type i,
579 int current_cell_number,
580 int & column, TexRow & texrow);
582 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
584 int & column, LyXFont const & font,
585 LyXLayout const & style);
587 void SimpleTeXSpecialChars(std::ostream &, TexRow & texrow,
588 LyXFont & font, LyXFont & running_font,
589 LyXFont & basefont, bool & open_font,
590 LyXLayout const & style,
592 int & column, char const c);
596 static unsigned int paragraph_id;