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;
343 size_type Last() const;
346 void Erase(size_type pos);
347 /** the flag determines wether the layout should be copied
349 void BreakParagraph(BufferParams const &, size_type pos, int flag);
351 void BreakParagraphConservative(BufferParams const &, size_type pos);
352 /** Get unistantiated font setting. Returns the difference
353 between the characters font and the layoutfont.
354 This is what is stored in the fonttable
357 GetFontSettings(BufferParams const &, size_type pos) const;
359 LyXFont const GetFirstFontSettings() const;
361 /** Get fully instantiated font. If pos == -1, use the layout
362 font attached to this paragraph.
363 If pos == -2, use the label font of the layout attached here.
364 In all cases, the font is instantiated, i.e. does not have any
365 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
368 LyXFont const getFont(BufferParams const &, size_type pos) const;
370 value_type GetChar(size_type pos) const;
372 value_type GetUChar(BufferParams const &, size_type pos) const;
373 /// The position must already exist.
374 void SetChar(size_type pos, value_type c);
376 void SetFont(size_type pos, LyXFont const & font);
378 string const GetWord(size_type &) const;
379 /// Returns the height of the highest font in range
380 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
381 size_type endpos) const;
383 void InsertChar(size_type pos, value_type c);
385 void InsertChar(size_type pos, value_type c, LyXFont const &);
387 void InsertInset(size_type pos, Inset * inset);
389 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
391 bool InsertInsetAllowed(Inset * inset);
393 Inset * GetInset(size_type pos);
395 Inset const * GetInset(size_type pos) const;
398 void OpenFootnote(size_type pos);
400 void CloseFootnote(size_type pos);
402 /** important for cut and paste
403 Temporary change from BufferParams to Buffer. Will revert when we
404 get rid of the argument to Inset::Clone(Buffer const &) */
405 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
407 void CutIntoMinibuffer(BufferParams const &, size_type pos);
409 bool InsertFromMinibuffer(size_type pos);
412 bool IsHfill(size_type pos) const;
414 bool IsInset(size_type pos) const;
417 bool IsFloat(size_type pos) const;
420 bool IsNewline(size_type pos) const;
422 bool IsSeparator(size_type pos) const;
424 bool IsLineSeparator(size_type pos) const;
426 bool IsKomma(size_type pos) const;
427 /// Used by the spellchecker
428 bool IsLetter(size_type pos) const;
430 bool IsWord(size_type pos) const;
432 /** This one resets all layout and dtp switches but not the font
433 of the single characters
437 /** paste this paragraph with the next one
438 be carefull, this doesent make any check at all
440 void PasteParagraph(BufferParams const &);
442 /// used to remove the error messages
443 int AutoDeleteInsets();
445 /// returns -1 if inset not found
446 int GetPositionOfInset(Inset * inset) const;
449 /// ok and now some footnote functions
450 void OpenFootnotes();
453 void CloseFootnotes();
455 LyXParagraph * FirstSelfrowPar();
459 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
462 /** A paragraph following a footnote is a "dummy". A paragraph
463 with a footnote in it is stored as three paragraphs:
464 First a paragraph with the text up to the footnote, then
465 one (or more) paragraphs with the footnote, and finally
466 the a paragraph with the text after the footnote. Only the
467 first paragraph keeps information about layoutparameters, */
468 bool IsDummy() const;
470 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
471 I have to set it on each of it's elements */
473 void SetPExtraType(BufferParams const &, int type,
474 string const & width, string const & widthp);
476 void UnsetPExtraType(BufferParams const &);
478 bool linuxDocConvertChar(char c, string & sgml_string);
487 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
490 friend struct matchIT;
493 /// used by lower_bound and upper_bound
495 int operator()(LyXParagraph::InsetTable const & a,
496 LyXParagraph::InsetTable const & b) const {
497 return a.pos < b.pos;
500 /** A font entry covers a range of positions. Notice that the
501 entries in the list are inserted in random order.
502 I don't think it's worth the effort to implement a more effective
503 datastructure, because the number of different fonts in a paragraph
505 Nevertheless, I decided to store fontlist using a sorted vector:
506 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
507 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
508 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
509 (font_1 covers the chars 0,...,pos_1) (Dekel)
513 FontTable(size_type p, LyXFont const & f)
516 font_ = container.get(f);
519 size_type pos() const { return pos_; }
521 void pos(size_type p) { pos_ = p; }
523 LyXFont const & font() const { return *font_; }
525 void font(LyXFont const & f) { font_ = container.get(f);}
527 /// End position of paragraph this font attribute covers
529 /** Font. Interpretation of the font values:
530 If a value is LyXFont::INHERIT_*, it means that the font
531 attribute is inherited from either the layout of this
532 paragraph or, in the case of nested paragraphs, from the
533 layout in the environment one level up until completely
535 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
536 allowed in these font tables.
538 boost::shared_ptr<LyXFont> font_;
540 static ShareContainer<LyXFont> container;
543 friend struct matchFT;
546 /// used by lower_bound and upper_bound
548 int operator()(LyXParagraph::FontTable const & a,
549 LyXParagraph::FontTable const & b) const {
550 return a.pos() < b.pos();
555 typedef std::vector<FontTable> FontList;
559 typedef std::vector<InsetTable> InsetList;
563 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
564 std::ostream &, TexRow & texrow
566 ,std::ostream & foot, TexRow & foot_texrow,
572 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
573 std::ostream &, TexRow & texrow,
574 std::ostream & foot, TexRow & foot_texrow,
579 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
581 int & column, LyXFont const & font,
582 LyXLayout const & style);
584 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
585 std::ostream &, TexRow & texrow,
587 LyXFont & font, LyXFont & running_font,
588 LyXFont & basefont, bool & open_font,
589 LyXLayout const & style,
591 int & column, value_type const c);
595 static unsigned int paragraph_id;
598 class inset_iterator {
603 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
605 inset_iterator & operator++() {
610 Inset * operator*() { return (*it).inset; }
612 size_type getPos() const {return (*it).pos; }
614 bool operator==(inset_iterator const & iter) const {
615 return it == iter.it;
618 bool operator!=(inset_iterator const & iter) const {
619 return it != iter.it;
623 InsetList::iterator it;
626 inset_iterator inset_iterator_begin();
628 inset_iterator inset_iterator_end();
630 inset_iterator InsetIterator(size_type pos);
635 int LyXParagraph::id() const
642 void LyXParagraph::id(int id_arg)
649 bool LyXParagraph::IsFirstInSequence() const
651 LyXParagraph const * dhook = DepthHook(GetDepth());
652 return (dhook == this
653 || dhook->GetLayout() != GetLayout()
654 || dhook->GetDepth() != GetDepth());
659 Inset * LyXParagraph::InInset()
666 LyXParagraph::size_type LyXParagraph::size() const
673 void LyXParagraph::clearContents()
680 void LyXParagraph::setCounter(int i, int v)
687 int LyXParagraph::getCounter(int i) const
694 void LyXParagraph::incCounter(int i)
701 void LyXParagraph::SetChar(size_type pos, value_type c)
708 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
710 return inset_iterator(insetlist.begin());
715 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
717 return inset_iterator(insetlist.end());