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
23 #include <boost/array.hpp>
25 #include "insets/lyxinset.h"
27 #include "ParagraphParameters.h"
36 // I dare you to enable this and help me find all the bugs that then show
38 //#define NEW_INSETS 1
40 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
55 enum MINIPAGE_ALIGNMENT {
59 MINIPAGE_ALIGN_MIDDLE,
89 //META_PROTECTED_SEPARATOR,
105 /// The footnotekinds
116 ALGORITHM, // Bernhard, 970807
118 WIDE_FIG, // CFO-G, 971106
120 WIDE_TAB // CFO-G, 971106
124 typedef char value_type;
126 typedef std::vector<value_type> TextContainer;
128 /* This should be TextContainer::size_type, but we need
129 signed values for now.
131 typedef TextContainer::difference_type size_type;
135 /// this constructor inserts the new paragraph in a list
137 LyXParagraph(LyXParagraph * par);
138 /// the destructor removes the new paragraph from the list
142 Language const * getParLanguage(BufferParams const &) const;
144 bool isRightToLeftPar(BufferParams const &) const;
146 void ChangeLanguage(BufferParams const & bparams,
147 Language const * from, Language const * to);
149 bool isMultiLingual(BufferParams const &);
152 string const String(Buffer const *, bool label);
154 string const String(Buffer const *, size_type beg, size_type end);
157 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
160 void validate(LaTeXFeatures &) const;
170 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
171 std::ostream &, TexRow & texrow,
175 std::ostream & foot, TexRow & foot_texrow,
180 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
181 std::ostream &, TexRow & texrow, bool moving_arg);
184 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
185 std::ostream &, TexRow & texrow
187 ,std::ostream & foot, TexRow & foot_texrow,
192 LyXParagraph * Clone() const;
195 bool HasSameLayout(LyXParagraph const * par) const;
198 void MakeSameLayout(LyXParagraph const * par);
200 /// Is it the first par with same depth and layout?
201 bool IsFirstInSequence() const;
203 /** Check if the current paragraph is the last paragraph in a
205 int GetEndLabel(BufferParams const &) const;
209 void SetInsetOwner(Inset * i);
211 void deleteInsetsLyXText(BufferView *);
213 void resizeInsetsLyXText(BufferView *);
222 size_type size() const;
226 void setContentsFromPar(LyXParagraph * par);
228 void clearContents();
230 ParagraphParameters params;
233 LyXTextClass::LayoutList::size_type layout;
237 \item no footnote, closed footnote,
238 \item open footnote, where footnote
239 \item means footnote-environment
242 footnote_flag footnoteflag;
244 /// footnote, margin, fig, tab
245 footnote_kind footnotekind;
250 array<int, 10> counter_;
253 void setCounter(int i, int v);
255 int getCounter(int i) const;
257 void incCounter(int i);
268 LyXParagraph * next_;
270 LyXParagraph * previous_;
273 InsetBibKey * bibkey; // ale970302
276 void next(LyXParagraph *);
277 /** these function are able to hide closed footnotes
279 LyXParagraph * next();
281 LyXParagraph const * next() const;
284 void previous(LyXParagraph *);
286 LyXParagraph * previous();
288 LyXParagraph const * previous() const;
291 /** these function are able to hide open and closed footnotes
293 LyXParagraph * NextAfterFootnote();
295 LyXParagraph const * NextAfterFootnote() const;
298 LyXParagraph * PreviousBeforeFootnote();
300 LyXParagraph * LastPhysicalPar();
302 LyXParagraph const * LastPhysicalPar() const;
305 LyXParagraph * FirstPhysicalPar();
307 LyXParagraph const * FirstPhysicalPar() const;
308 /// returns the physical paragraph
309 LyXParagraph * ParFromPos(size_type pos);
310 /// returns the position in the physical par
311 int PositionInParFromPos(size_type pos) const;
314 /// for the environments
315 LyXParagraph * DepthHook(int depth);
316 /// for the environments
317 LyXParagraph const * DepthHook(int depth) const;
319 int BeginningOfMainBody() const;
321 string const & GetLabelstring() const;
323 /// the next two functions are for the manual labels
324 string const GetLabelWidthString() const;
326 void SetLabelWidthString(string const & s);
328 LyXTextClass::LayoutList::size_type GetLayout() const;
330 char GetAlign() const;
332 char GetDepth() const;
334 void SetLayout(BufferParams const &,
335 LyXTextClass::LayoutList::size_type new_layout);
337 void SetOnlyLayout(BufferParams const &,
338 LyXTextClass::LayoutList::size_type new_layout);
340 int GetFirstCounter(int i) const;
342 size_type Last() const;
344 void Erase(size_type pos);
345 /** the flag determines wether the layout should be copied
347 void BreakParagraph(BufferParams const &, size_type pos, int flag);
349 void BreakParagraphConservative(BufferParams const &, size_type pos);
350 /** Get unistantiated font setting. Returns the difference
351 between the characters font and the layoutfont.
352 This is what is stored in the fonttable
355 GetFontSettings(BufferParams const &, size_type pos) const;
357 LyXFont const GetFirstFontSettings() const;
359 /** Get fully instantiated font. If pos == -1, use the layout
360 font attached to this paragraph.
361 If pos == -2, use the label font of the layout attached here.
362 In all cases, the font is instantiated, i.e. does not have any
363 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
366 LyXFont const getFont(BufferParams const &, size_type pos) const;
368 value_type GetChar(size_type pos) const;
370 value_type GetUChar(BufferParams const &, size_type pos) const;
371 /// The position must already exist.
372 void SetChar(size_type pos, value_type c);
374 void SetFont(size_type pos, LyXFont const & font);
376 string const GetWord(size_type &) const;
377 /// Returns the height of the highest font in range
378 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
379 size_type endpos) const;
381 void InsertChar(size_type pos, value_type c);
383 void InsertChar(size_type pos, value_type c, LyXFont const &);
385 void InsertInset(size_type pos, Inset * inset);
387 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
389 bool InsertInsetAllowed(Inset * inset);
391 Inset * GetInset(size_type pos);
393 Inset const * GetInset(size_type pos) const;
396 void OpenFootnote(size_type pos);
398 void CloseFootnote(size_type pos);
400 /** important for cut and paste
401 Temporary change from BufferParams to Buffer. Will revert when we
402 get rid of the argument to Inset::Clone(Buffer const &) */
403 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
405 void CutIntoMinibuffer(BufferParams const &, size_type pos);
407 bool InsertFromMinibuffer(size_type pos);
410 bool IsHfill(size_type pos) const;
412 bool IsInset(size_type pos) const;
415 bool IsFloat(size_type pos) const;
418 bool IsNewline(size_type pos) const;
420 bool IsSeparator(size_type pos) const;
422 bool IsLineSeparator(size_type pos) const;
424 bool IsKomma(size_type pos) const;
425 /// Used by the spellchecker
426 bool IsLetter(size_type pos) const;
428 bool IsWord(size_type pos) const;
430 /** This one resets all layout and dtp switches but not the font
431 of the single characters
435 /** paste this paragraph with the next one
436 be carefull, this doesent make any check at all
438 void PasteParagraph(BufferParams const &);
440 /// used to remove the error messages
441 int AutoDeleteInsets();
443 /// returns -1 if inset not found
444 int GetPositionOfInset(Inset * inset) const;
447 /// ok and now some footnote functions
448 void OpenFootnotes();
451 void CloseFootnotes();
453 LyXParagraph * FirstSelfrowPar();
457 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
460 /** A paragraph following a footnote is a "dummy". A paragraph
461 with a footnote in it is stored as three paragraphs:
462 First a paragraph with the text up to the footnote, then
463 one (or more) paragraphs with the footnote, and finally
464 the a paragraph with the text after the footnote. Only the
465 first paragraph keeps information about layoutparameters, */
466 bool IsDummy() const;
468 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
469 I have to set it on each of it's elements */
471 void SetPExtraType(BufferParams const &, int type,
472 string const & width, string const & widthp);
474 void UnsetPExtraType(BufferParams const &);
476 bool linuxDocConvertChar(char c, string & sgml_string);
485 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
488 friend struct matchIT;
491 /// used by lower_bound and upper_bound
493 int operator()(LyXParagraph::InsetTable const & a,
494 LyXParagraph::InsetTable const & b) const {
495 return a.pos < b.pos;
498 /** A font entry covers a range of positions. Notice that the
499 entries in the list are inserted in random order.
500 I don't think it's worth the effort to implement a more effective
501 datastructure, because the number of different fonts in a paragraph
503 Nevertheless, I decided to store fontlist using a sorted vector:
504 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
505 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
506 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
507 (font_1 covers the chars 0,...,pos_1) (Dekel)
511 FontTable(size_type p, LyXFont const & f)
514 font_ = container.get(f);
517 size_type pos() const { return pos_; }
519 void pos(size_type p) { pos_ = p; }
521 LyXFont const & font() const { return *font_; }
523 void font(LyXFont const & f) { font_ = container.get(f);}
525 /// End position of paragraph this font attribute covers
527 /** Font. Interpretation of the font values:
528 If a value is LyXFont::INHERIT_*, it means that the font
529 attribute is inherited from either the layout of this
530 paragraph or, in the case of nested paragraphs, from the
531 layout in the environment one level up until completely
533 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
534 allowed in these font tables.
536 boost::shared_ptr<LyXFont> font_;
538 static ShareContainer<LyXFont> container;
541 friend struct matchFT;
544 /// used by lower_bound and upper_bound
546 int operator()(LyXParagraph::FontTable const & a,
547 LyXParagraph::FontTable const & b) const {
548 return a.pos() < b.pos();
553 typedef std::vector<FontTable> FontList;
557 typedef std::vector<InsetTable> InsetList;
561 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
562 std::ostream &, TexRow & texrow
564 ,std::ostream & foot, TexRow & foot_texrow,
570 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
571 std::ostream &, TexRow & texrow,
572 std::ostream & foot, TexRow & foot_texrow,
577 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
579 int & column, LyXFont const & font,
580 LyXLayout const & style);
582 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
583 std::ostream &, TexRow & texrow,
585 LyXFont & font, LyXFont & running_font,
586 LyXFont & basefont, bool & open_font,
587 LyXLayout const & style,
589 int & column, value_type const c);
593 static unsigned int paragraph_id;
596 class inset_iterator {
601 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
603 inset_iterator & operator++() {
608 Inset * operator*() { return (*it).inset; }
610 size_type getPos() const {return (*it).pos; }
612 bool operator==(inset_iterator const & iter) const {
613 return it == iter.it;
616 bool operator!=(inset_iterator const & iter) const {
617 return it != iter.it;
621 InsetList::iterator it;
624 inset_iterator inset_iterator_begin();
626 inset_iterator inset_iterator_end();
628 inset_iterator InsetIterator(size_type pos);
633 int LyXParagraph::id() const
640 void LyXParagraph::id(int id_arg)
647 bool LyXParagraph::IsFirstInSequence() const
649 LyXParagraph const * dhook = DepthHook(GetDepth());
650 return (dhook == this
651 || dhook->GetLayout() != GetLayout()
652 || dhook->GetDepth() != GetDepth());
657 Inset * LyXParagraph::InInset()
664 LyXParagraph::size_type LyXParagraph::size() const
671 void LyXParagraph::clearContents()
678 void LyXParagraph::setCounter(int i, int v)
685 int LyXParagraph::getCounter(int i) const
692 void LyXParagraph::incCounter(int i)
699 void LyXParagraph::SetChar(size_type pos, value_type c)
706 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
708 return inset_iterator(insetlist.begin());
713 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
715 return inset_iterator(insetlist.end());