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
21 #include <boost/array.hpp>
23 #include "insets/lyxinset.h"
25 #include "ParagraphParameters.h"
34 // I dare you to enable this and help me find all the bugs that then show
36 //#define NEW_INSETS 1
38 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
53 enum MINIPAGE_ALIGNMENT {
57 MINIPAGE_ALIGN_MIDDLE,
87 //META_PROTECTED_SEPARATOR,
103 /// The footnotekinds
114 ALGORITHM, // Bernhard, 970807
116 WIDE_FIG, // CFO-G, 971106
118 WIDE_TAB // CFO-G, 971106
122 typedef char value_type;
124 typedef std::vector<value_type> TextContainer;
126 /* This should be TextContainer::size_type, but we need
127 signed values for now.
129 typedef TextContainer::difference_type size_type;
133 /// this constructor inserts the new paragraph in a list
135 LyXParagraph(LyXParagraph * par);
136 /// the destructor removes the new paragraph from the list
140 Language const * getParLanguage(BufferParams const &) const;
142 bool isRightToLeftPar(BufferParams const &) const;
144 void ChangeLanguage(BufferParams const & bparams,
145 Language const * from, Language const * to);
147 bool isMultiLingual(BufferParams const &);
150 string const String(Buffer const *, bool label);
152 string const String(Buffer const *, size_type beg, size_type end);
155 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
158 void validate(LaTeXFeatures &) const;
168 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
169 std::ostream &, TexRow & texrow,
173 std::ostream & foot, TexRow & foot_texrow,
178 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
179 std::ostream &, TexRow & texrow, bool moving_arg);
182 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
183 std::ostream &, TexRow & texrow
185 ,std::ostream & foot, TexRow & foot_texrow,
190 LyXParagraph * Clone() const;
193 bool HasSameLayout(LyXParagraph const * par) const;
196 void MakeSameLayout(LyXParagraph const * par);
198 /// Is it the first par with same depth and layout?
199 bool IsFirstInSequence() const;
201 /** Check if the current paragraph is the last paragraph in a
203 int GetEndLabel(BufferParams const &) const;
207 void SetInsetOwner(Inset * i);
209 void deleteInsetsLyXText(BufferView *);
211 void resizeInsetsLyXText(BufferView *);
220 size_type size() const;
224 void setContentsFromPar(LyXParagraph * par);
226 void clearContents();
228 ParagraphParameters params;
231 LyXTextClass::LayoutList::size_type layout;
235 \item no footnote, closed footnote,
236 \item open footnote, where footnote
237 \item means footnote-environment
240 footnote_flag footnoteflag;
242 /// footnote, margin, fig, tab
243 footnote_kind footnotekind;
248 array<int, 10> counter_;
251 void setCounter(int i, int v);
253 int getCounter(int i) const;
255 void incCounter(int i);
266 LyXParagraph * previous;
269 InsetBibKey * bibkey; // ale970302
271 /** these function are able to hide closed footnotes
273 LyXParagraph * Next();
276 LyXParagraph * Previous();
278 LyXParagraph const * Previous() const;
281 /** these function are able to hide open and closed footnotes
283 LyXParagraph * NextAfterFootnote();
285 LyXParagraph const * NextAfterFootnote() const;
288 LyXParagraph * PreviousBeforeFootnote();
290 LyXParagraph * LastPhysicalPar();
292 LyXParagraph const * LastPhysicalPar() const;
295 LyXParagraph * FirstPhysicalPar();
297 LyXParagraph const * FirstPhysicalPar() const;
298 /// returns the physical paragraph
299 LyXParagraph * ParFromPos(size_type pos);
300 /// returns the position in the physical par
301 int PositionInParFromPos(size_type pos) const;
304 /// for the environments
305 LyXParagraph * DepthHook(int depth);
306 /// for the environments
307 LyXParagraph const * DepthHook(int depth) const;
309 int BeginningOfMainBody() const;
311 string const & GetLabelstring() const;
313 /// the next two functions are for the manual labels
314 string const GetLabelWidthString() const;
316 void SetLabelWidthString(string const & s);
318 LyXTextClass::LayoutList::size_type GetLayout() const;
320 char GetAlign() const;
322 char GetDepth() const;
324 void SetLayout(BufferParams const &,
325 LyXTextClass::LayoutList::size_type new_layout);
327 void SetOnlyLayout(BufferParams const &,
328 LyXTextClass::LayoutList::size_type new_layout);
330 int GetFirstCounter(int i) const;
332 size_type Last() const;
334 void Erase(size_type pos);
335 /** the flag determines wether the layout should be copied
337 void BreakParagraph(BufferParams const &, size_type pos, int flag);
339 void BreakParagraphConservative(BufferParams const &, size_type pos);
340 /** Get unistantiated font setting. Returns the difference
341 between the characters font and the layoutfont.
342 This is what is stored in the fonttable
345 GetFontSettings(BufferParams const &, size_type pos) const;
347 LyXFont const GetFirstFontSettings() const;
349 /** Get fully instantiated font. If pos == -1, use the layout
350 font attached to this paragraph.
351 If pos == -2, use the label font of the layout attached here.
352 In all cases, the font is instantiated, i.e. does not have any
353 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
356 LyXFont const getFont(BufferParams const &, size_type pos) const;
358 value_type GetChar(size_type pos) const;
360 value_type GetUChar(BufferParams const &, size_type pos) const;
361 /// The position must already exist.
362 void SetChar(size_type pos, value_type c);
364 void SetFont(size_type pos, LyXFont const & font);
366 string const GetWord(size_type &) const;
367 /// Returns the height of the highest font in range
368 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
369 size_type endpos) const;
371 void InsertChar(size_type pos, value_type c);
373 void InsertChar(size_type pos, value_type c, LyXFont const &);
375 void InsertInset(size_type pos, Inset * inset);
377 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
379 bool InsertInsetAllowed(Inset * inset);
381 Inset * GetInset(size_type pos);
383 Inset const * GetInset(size_type pos) const;
386 void OpenFootnote(size_type pos);
388 void CloseFootnote(size_type pos);
390 /** important for cut and paste
391 Temporary change from BufferParams to Buffer. Will revert when we
392 get rid of the argument to Inset::Clone(Buffer const &) */
393 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
395 void CutIntoMinibuffer(BufferParams const &, size_type pos);
397 bool InsertFromMinibuffer(size_type pos);
400 bool IsHfill(size_type pos) const;
402 bool IsInset(size_type pos) const;
405 bool IsFloat(size_type pos) const;
408 bool IsNewline(size_type pos) const;
410 bool IsSeparator(size_type pos) const;
412 bool IsLineSeparator(size_type pos) const;
414 bool IsKomma(size_type pos) const;
415 /// Used by the spellchecker
416 bool IsLetter(size_type pos) const;
418 bool IsWord(size_type pos) const;
420 /** This one resets all layout and dtp switches but not the font
421 of the single characters
425 /** paste this paragraph with the next one
426 be carefull, this doesent make any check at all
428 void PasteParagraph(BufferParams const &);
430 /// used to remove the error messages
431 int AutoDeleteInsets();
433 /// returns -1 if inset not found
434 int GetPositionOfInset(Inset * inset) const;
437 /// ok and now some footnote functions
438 void OpenFootnotes();
441 void CloseFootnotes();
443 LyXParagraph * FirstSelfrowPar();
447 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
450 /** A paragraph following a footnote is a "dummy". A paragraph
451 with a footnote in it is stored as three paragraphs:
452 First a paragraph with the text up to the footnote, then
453 one (or more) paragraphs with the footnote, and finally
454 the a paragraph with the text after the footnote. Only the
455 first paragraph keeps information about layoutparameters, */
456 bool IsDummy() const;
458 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
459 I have to set it on each of it's elements */
461 void SetPExtraType(BufferParams const &, int type,
462 string const & width, string const & widthp);
464 void UnsetPExtraType(BufferParams const &);
466 bool linuxDocConvertChar(char c, string & sgml_string);
475 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
478 friend struct matchIT;
481 /// used by lower_bound and upper_bound
483 int operator()(LyXParagraph::InsetTable const & a,
484 LyXParagraph::InsetTable const & b) const {
485 return a.pos < b.pos;
488 /** A font entry covers a range of positions. Notice that the
489 entries in the list are inserted in random order.
490 I don't think it's worth the effort to implement a more effective
491 datastructure, because the number of different fonts in a paragraph
493 Nevertheless, I decided to store fontlist using a sorted vector:
494 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
495 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
496 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
497 (font_1 covers the chars 0,...,pos_1) (Dekel)
501 FontTable(size_type p, LyXFont const & f)
504 font_ = container.get(f);
507 size_type pos() const { return pos_; }
509 void pos(size_type p) { pos_ = p; }
511 LyXFont const & font() const { return *font_; }
513 void font(LyXFont const & f) { font_ = container.get(f);}
515 /// End position of paragraph this font attribute covers
517 /** Font. Interpretation of the font values:
518 If a value is LyXFont::INHERIT_*, it means that the font
519 attribute is inherited from either the layout of this
520 paragraph or, in the case of nested paragraphs, from the
521 layout in the environment one level up until completely
523 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
524 allowed in these font tables.
526 boost::shared_ptr<LyXFont> font_;
528 static ShareContainer<LyXFont> container;
531 friend struct matchFT;
534 /// used by lower_bound and upper_bound
536 int operator()(LyXParagraph::FontTable const & a,
537 LyXParagraph::FontTable const & b) const {
538 return a.pos() < b.pos();
543 typedef std::vector<FontTable> FontList;
547 typedef std::vector<InsetTable> InsetList;
551 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
552 std::ostream &, TexRow & texrow
554 ,std::ostream & foot, TexRow & foot_texrow,
560 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
561 std::ostream &, TexRow & texrow,
562 std::ostream & foot, TexRow & foot_texrow,
567 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
569 int & column, LyXFont const & font,
570 LyXLayout const & style);
572 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
573 std::ostream &, TexRow & texrow,
575 LyXFont & font, LyXFont & running_font,
576 LyXFont & basefont, bool & open_font,
577 LyXLayout const & style,
579 int & column, value_type const c);
583 static unsigned int paragraph_id;
586 class inset_iterator {
591 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
593 inset_iterator & operator++() {
598 Inset * operator*() { return (*it).inset; }
600 size_type getPos() const {return (*it).pos; }
602 bool operator==(inset_iterator const & iter) const {
603 return it == iter.it;
606 bool operator!=(inset_iterator const & iter) const {
607 return it != iter.it;
611 InsetList::iterator it;
614 inset_iterator inset_iterator_begin();
616 inset_iterator inset_iterator_end();
618 inset_iterator InsetIterator(size_type pos);
623 int LyXParagraph::id() const
630 void LyXParagraph::id(int id_arg)
637 bool LyXParagraph::IsFirstInSequence() const
639 LyXParagraph const * dhook = DepthHook(GetDepth());
640 return (dhook == this
641 || dhook->GetLayout() != GetLayout()
642 || dhook->GetDepth() != GetDepth());
647 Inset * LyXParagraph::InInset()
654 LyXParagraph::size_type LyXParagraph::size() const
661 void LyXParagraph::clearContents()
668 void LyXParagraph::setCounter(int i, int v)
675 int LyXParagraph::getCounter(int i) const
682 void LyXParagraph::incCounter(int i)
689 void LyXParagraph::SetChar(size_type pos, value_type c)
696 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
698 return inset_iterator(insetlist.begin());
703 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
705 return inset_iterator(insetlist.end());