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"
26 #include "ParagraphParameters.h"
27 #include "support/LAssert.h"
37 // I dare you to enable this and help me find all the bugs that then show
42 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
45 #ifndef NO_PEXTRA_REALLY
58 enum MINIPAGE_ALIGNMENT {
62 MINIPAGE_ALIGN_MIDDLE,
93 //META_PROTECTED_SEPARATOR,
109 /// The footnotekinds
120 ALGORITHM, // Bernhard, 970807
122 WIDE_FIG, // CFO-G, 971106
124 WIDE_TAB // CFO-G, 971106
128 typedef char value_type;
130 typedef std::vector<value_type> TextContainer;
132 /* This should be TextContainer::size_type, but we need
133 signed values for now.
135 typedef TextContainer::difference_type size_type;
139 /// this constructor inserts the new paragraph in a list
141 LyXParagraph(LyXParagraph * par);
142 /// the destructor removes the new paragraph from the list
146 Language const * getParLanguage(BufferParams const &) const;
148 bool isRightToLeftPar(BufferParams const &) const;
150 void ChangeLanguage(BufferParams const & bparams,
151 Language const * from, Language const * to);
153 bool isMultiLingual(BufferParams const &);
156 string const String(Buffer const *, bool label);
158 string const String(Buffer const *, size_type beg, size_type end);
161 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
164 void validate(LaTeXFeatures &) const;
174 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
175 std::ostream &, TexRow & texrow,
179 std::ostream & foot, TexRow & foot_texrow,
184 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
185 std::ostream &, TexRow & texrow, bool moving_arg);
188 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
189 std::ostream &, TexRow & texrow
191 ,std::ostream & foot, TexRow & foot_texrow,
196 LyXParagraph * Clone() const;
199 bool HasSameLayout(LyXParagraph const * par) const;
202 void MakeSameLayout(LyXParagraph const * par);
204 /// Is it the first par with same depth and layout?
205 bool IsFirstInSequence() const;
207 /** Check if the current paragraph is the last paragraph in a
209 int GetEndLabel(BufferParams const &) const;
213 void SetInsetOwner(Inset * i);
215 void deleteInsetsLyXText(BufferView *);
217 void resizeInsetsLyXText(BufferView *);
226 size_type size() const;
230 void setContentsFromPar(LyXParagraph * par);
232 void clearContents();
234 ParagraphParameters params;
237 LyXTextClass::LayoutList::size_type layout;
241 \item no footnote, closed footnote,
242 \item open footnote, where footnote
243 \item means footnote-environment
246 footnote_flag footnoteflag;
248 /// footnote, margin, fig, tab
249 footnote_kind footnotekind;
254 boost::array<int, 10> counter_;
257 void setCounter(int i, int v);
259 int getCounter(int i) const;
261 void incCounter(int i);
272 LyXParagraph * next_;
274 LyXParagraph * previous_;
277 InsetBibKey * bibkey; // ale970302
280 void next(LyXParagraph *);
281 /** these function are able to hide closed footnotes
283 LyXParagraph * next();
285 LyXParagraph const * next() const;
288 void previous(LyXParagraph *);
290 LyXParagraph * previous();
292 LyXParagraph const * previous() const;
295 /** these function are able to hide open and closed footnotes
297 LyXParagraph * NextAfterFootnote();
299 LyXParagraph const * NextAfterFootnote() const;
302 LyXParagraph * PreviousBeforeFootnote();
304 LyXParagraph * LastPhysicalPar();
306 LyXParagraph const * LastPhysicalPar() const;
309 LyXParagraph * FirstPhysicalPar();
311 LyXParagraph const * FirstPhysicalPar() const;
312 /// returns the physical paragraph
313 LyXParagraph * ParFromPos(size_type pos);
314 /// returns the position in the physical par
315 int PositionInParFromPos(size_type pos) const;
318 /// for the environments
319 LyXParagraph * DepthHook(int depth);
320 /// for the environments
321 LyXParagraph const * DepthHook(int depth) const;
323 int BeginningOfMainBody() const;
325 string const & GetLabelstring() const;
327 /// the next two functions are for the manual labels
328 string const GetLabelWidthString() const;
330 void SetLabelWidthString(string const & s);
332 LyXTextClass::LayoutList::size_type GetLayout() const;
334 char GetAlign() const;
336 char GetDepth() const;
339 void SetLayout(BufferParams const &,
340 LyXTextClass::LayoutList::size_type new_layout);
342 void SetOnlyLayout(BufferParams const &,
343 LyXTextClass::LayoutList::size_type new_layout);
345 size_type Last() const;
348 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
350 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
353 int GetFirstCounter(int i) const;
355 void Erase(size_type pos);
356 /** the flag determines wether the layout should be copied
358 void BreakParagraph(BufferParams const &, size_type pos, int flag);
360 void BreakParagraphConservative(BufferParams const &, size_type pos);
361 /** Get unistantiated font setting. Returns the difference
362 between the characters font and the layoutfont.
363 This is what is stored in the fonttable
366 GetFontSettings(BufferParams const &, size_type pos) const;
368 LyXFont const GetFirstFontSettings() const;
370 /** Get fully instantiated font. If pos == -1, use the layout
371 font attached to this paragraph.
372 If pos == -2, use the label font of the layout attached here.
373 In all cases, the font is instantiated, i.e. does not have any
374 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
377 LyXFont const getFont(BufferParams const &, size_type pos) const;
379 value_type GetChar(size_type pos) const;
381 value_type GetUChar(BufferParams const &, size_type pos) const;
382 /// The position must already exist.
383 void SetChar(size_type pos, value_type c);
385 void SetFont(size_type pos, LyXFont const & font);
387 string const GetWord(size_type &) const;
388 /// Returns the height of the highest font in range
389 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
390 size_type endpos) const;
392 void InsertChar(size_type pos, value_type c);
394 void InsertChar(size_type pos, value_type c, LyXFont const &);
396 void InsertInset(size_type pos, Inset * inset);
398 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
400 bool InsertInsetAllowed(Inset * inset);
402 Inset * GetInset(size_type pos);
404 Inset const * GetInset(size_type pos) const;
407 void OpenFootnote(size_type pos);
409 void CloseFootnote(size_type pos);
411 /** important for cut and paste
412 Temporary change from BufferParams to Buffer. Will revert when we
413 get rid of the argument to Inset::Clone(Buffer const &) */
414 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
416 void CutIntoMinibuffer(BufferParams const &, size_type pos);
418 bool InsertFromMinibuffer(size_type pos);
421 bool IsHfill(size_type pos) const;
423 bool IsInset(size_type pos) const;
426 bool IsFloat(size_type pos) const;
429 bool IsNewline(size_type pos) const;
431 bool IsSeparator(size_type pos) const;
433 bool IsLineSeparator(size_type pos) const;
435 bool IsKomma(size_type pos) const;
436 /// Used by the spellchecker
437 bool IsLetter(size_type pos) const;
439 bool IsWord(size_type pos) const;
441 /** This one resets all layout and dtp switches but not the font
442 of the single characters
446 /** paste this paragraph with the next one
447 be carefull, this doesent make any check at all
449 void PasteParagraph(BufferParams const &);
451 /// used to remove the error messages
452 int AutoDeleteInsets();
454 /// returns -1 if inset not found
455 int GetPositionOfInset(Inset * inset) const;
458 /// ok and now some footnote functions
459 void OpenFootnotes();
462 void CloseFootnotes();
464 LyXParagraph * FirstSelfrowPar();
468 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
471 /** A paragraph following a footnote is a "dummy". A paragraph
472 with a footnote in it is stored as three paragraphs:
473 First a paragraph with the text up to the footnote, then
474 one (or more) paragraphs with the footnote, and finally
475 the a paragraph with the text after the footnote. Only the
476 first paragraph keeps information about layoutparameters, */
477 bool IsDummy() const;
479 #ifndef NO_PEXTRA_REALLY
480 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
481 I have to set it on each of it's elements */
483 void SetPExtraType(BufferParams const &, int type,
484 string const & width, string const & widthp);
486 void UnsetPExtraType(BufferParams const &);
489 bool linuxDocConvertChar(char c, string & sgml_string);
498 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
501 friend struct matchIT;
504 /// used by lower_bound and upper_bound
506 int operator()(LyXParagraph::InsetTable const & a,
507 LyXParagraph::InsetTable const & b) const {
508 return a.pos < b.pos;
511 /** A font entry covers a range of positions. Notice that the
512 entries in the list are inserted in random order.
513 I don't think it's worth the effort to implement a more effective
514 datastructure, because the number of different fonts in a paragraph
516 Nevertheless, I decided to store fontlist using a sorted vector:
517 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
518 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
519 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
520 (font_1 covers the chars 0,...,pos_1) (Dekel)
524 FontTable(size_type p, LyXFont const & f)
527 font_ = container.get(f);
530 size_type pos() const { return pos_; }
532 void pos(size_type p) { pos_ = p; }
534 LyXFont const & font() const { return *font_; }
536 void font(LyXFont const & f) { font_ = container.get(f);}
538 /// End position of paragraph this font attribute covers
540 /** Font. Interpretation of the font values:
541 If a value is LyXFont::INHERIT_*, it means that the font
542 attribute is inherited from either the layout of this
543 paragraph or, in the case of nested paragraphs, from the
544 layout in the environment one level up until completely
546 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
547 allowed in these font tables.
549 boost::shared_ptr<LyXFont> font_;
551 static ShareContainer<LyXFont> container;
554 friend struct matchFT;
557 /// used by lower_bound and upper_bound
559 int operator()(LyXParagraph::FontTable const & a,
560 LyXParagraph::FontTable const & b) const {
561 return a.pos() < b.pos();
566 typedef std::vector<FontTable> FontList;
570 typedef std::vector<InsetTable> InsetList;
574 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
575 std::ostream &, TexRow & texrow
577 ,std::ostream & foot, TexRow & foot_texrow,
583 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
584 std::ostream &, TexRow & texrow,
585 std::ostream & foot, TexRow & foot_texrow,
590 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
592 int & column, LyXFont const & font,
593 LyXLayout const & style);
595 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
596 std::ostream &, TexRow & texrow,
598 LyXFont & font, LyXFont & running_font,
599 LyXFont & basefont, bool & open_font,
600 LyXLayout const & style,
602 int & column, value_type const c);
606 static unsigned int paragraph_id;
609 class inset_iterator {
614 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
616 inset_iterator & operator++() {
621 Inset * operator*() { return (*it).inset; }
623 size_type getPos() const {return (*it).pos; }
625 bool operator==(inset_iterator const & iter) const {
626 return it == iter.it;
629 bool operator!=(inset_iterator const & iter) const {
630 return it != iter.it;
634 InsetList::iterator it;
637 inset_iterator inset_iterator_begin();
639 inset_iterator inset_iterator_end();
641 inset_iterator InsetIterator(size_type pos);
647 LyXParagraph::value_type
648 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
650 Assert(pos <= size());
651 // This is stronger, and I belive that this is the assertion
652 // that we should really use. (Lgb)
653 //Assert(pos < size());
655 // Then this has no meaning. (Lgb)
656 if (!size() || pos == size()) return '\0';
663 int LyXParagraph::id() const
670 void LyXParagraph::id(int id_arg)
677 bool LyXParagraph::IsFirstInSequence() const
679 LyXParagraph const * dhook = DepthHook(GetDepth());
680 return (dhook == this
681 || dhook->GetLayout() != GetLayout()
682 || dhook->GetDepth() != GetDepth());
687 Inset * LyXParagraph::InInset()
694 LyXParagraph::size_type LyXParagraph::size() const
701 void LyXParagraph::clearContents()
708 void LyXParagraph::setCounter(int i, int v)
715 int LyXParagraph::getCounter(int i) const
722 void LyXParagraph::incCounter(int i)
729 void LyXParagraph::SetChar(size_type pos, value_type c)
736 LyXTextClass::size_type LyXParagraph::GetLayout() const
739 return FirstPhysicalPar()->layout;
747 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
749 return inset_iterator(insetlist.begin());
754 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
756 return inset_iterator(insetlist.end());