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 * previous;
271 InsetBibKey * bibkey; // ale970302
273 /** these function are able to hide closed footnotes
275 LyXParagraph * Next();
278 LyXParagraph * Previous();
280 LyXParagraph const * Previous() const;
283 /** these function are able to hide open and closed footnotes
285 LyXParagraph * NextAfterFootnote();
287 LyXParagraph const * NextAfterFootnote() const;
290 LyXParagraph * PreviousBeforeFootnote();
292 LyXParagraph * LastPhysicalPar();
294 LyXParagraph const * LastPhysicalPar() const;
297 LyXParagraph * FirstPhysicalPar();
299 LyXParagraph const * FirstPhysicalPar() const;
300 /// returns the physical paragraph
301 LyXParagraph * ParFromPos(size_type pos);
302 /// returns the position in the physical par
303 int PositionInParFromPos(size_type pos) const;
306 /// for the environments
307 LyXParagraph * DepthHook(int depth);
308 /// for the environments
309 LyXParagraph const * DepthHook(int depth) const;
311 int BeginningOfMainBody() const;
313 string const & GetLabelstring() const;
315 /// the next two functions are for the manual labels
316 string const GetLabelWidthString() const;
318 void SetLabelWidthString(string const & s);
320 LyXTextClass::LayoutList::size_type GetLayout() const;
322 char GetAlign() const;
324 char GetDepth() const;
326 void SetLayout(BufferParams const &,
327 LyXTextClass::LayoutList::size_type new_layout);
329 void SetOnlyLayout(BufferParams const &,
330 LyXTextClass::LayoutList::size_type new_layout);
332 int GetFirstCounter(int i) const;
334 size_type Last() const;
336 void Erase(size_type pos);
337 /** the flag determines wether the layout should be copied
339 void BreakParagraph(BufferParams const &, size_type pos, int flag);
341 void BreakParagraphConservative(BufferParams const &, size_type pos);
342 /** Get unistantiated font setting. Returns the difference
343 between the characters font and the layoutfont.
344 This is what is stored in the fonttable
347 GetFontSettings(BufferParams const &, size_type pos) const;
349 LyXFont const GetFirstFontSettings() const;
351 /** Get fully instantiated font. If pos == -1, use the layout
352 font attached to this paragraph.
353 If pos == -2, use the label font of the layout attached here.
354 In all cases, the font is instantiated, i.e. does not have any
355 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
358 LyXFont const getFont(BufferParams const &, size_type pos) const;
360 value_type GetChar(size_type pos) const;
362 value_type GetUChar(BufferParams const &, size_type pos) const;
363 /// The position must already exist.
364 void SetChar(size_type pos, value_type c);
366 void SetFont(size_type pos, LyXFont const & font);
368 string const GetWord(size_type &) const;
369 /// Returns the height of the highest font in range
370 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
371 size_type endpos) const;
373 void InsertChar(size_type pos, value_type c);
375 void InsertChar(size_type pos, value_type c, LyXFont const &);
377 void InsertInset(size_type pos, Inset * inset);
379 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
381 bool InsertInsetAllowed(Inset * inset);
383 Inset * GetInset(size_type pos);
385 Inset const * GetInset(size_type pos) const;
388 void OpenFootnote(size_type pos);
390 void CloseFootnote(size_type pos);
392 /** important for cut and paste
393 Temporary change from BufferParams to Buffer. Will revert when we
394 get rid of the argument to Inset::Clone(Buffer const &) */
395 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
397 void CutIntoMinibuffer(BufferParams const &, size_type pos);
399 bool InsertFromMinibuffer(size_type pos);
402 bool IsHfill(size_type pos) const;
404 bool IsInset(size_type pos) const;
407 bool IsFloat(size_type pos) const;
410 bool IsNewline(size_type pos) const;
412 bool IsSeparator(size_type pos) const;
414 bool IsLineSeparator(size_type pos) const;
416 bool IsKomma(size_type pos) const;
417 /// Used by the spellchecker
418 bool IsLetter(size_type pos) const;
420 bool IsWord(size_type pos) const;
422 /** This one resets all layout and dtp switches but not the font
423 of the single characters
427 /** paste this paragraph with the next one
428 be carefull, this doesent make any check at all
430 void PasteParagraph(BufferParams const &);
432 /// used to remove the error messages
433 int AutoDeleteInsets();
435 /// returns -1 if inset not found
436 int GetPositionOfInset(Inset * inset) const;
439 /// ok and now some footnote functions
440 void OpenFootnotes();
443 void CloseFootnotes();
445 LyXParagraph * FirstSelfrowPar();
449 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
452 /** A paragraph following a footnote is a "dummy". A paragraph
453 with a footnote in it is stored as three paragraphs:
454 First a paragraph with the text up to the footnote, then
455 one (or more) paragraphs with the footnote, and finally
456 the a paragraph with the text after the footnote. Only the
457 first paragraph keeps information about layoutparameters, */
458 bool IsDummy() const;
460 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
461 I have to set it on each of it's elements */
463 void SetPExtraType(BufferParams const &, int type,
464 string const & width, string const & widthp);
466 void UnsetPExtraType(BufferParams const &);
468 bool linuxDocConvertChar(char c, string & sgml_string);
477 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
480 friend struct matchIT;
483 /// used by lower_bound and upper_bound
485 int operator()(LyXParagraph::InsetTable const & a,
486 LyXParagraph::InsetTable const & b) const {
487 return a.pos < b.pos;
490 /** A font entry covers a range of positions. Notice that the
491 entries in the list are inserted in random order.
492 I don't think it's worth the effort to implement a more effective
493 datastructure, because the number of different fonts in a paragraph
495 Nevertheless, I decided to store fontlist using a sorted vector:
496 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
497 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
498 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
499 (font_1 covers the chars 0,...,pos_1) (Dekel)
503 FontTable(size_type p, LyXFont const & f)
506 font_ = container.get(f);
509 size_type pos() const { return pos_; }
511 void pos(size_type p) { pos_ = p; }
513 LyXFont const & font() const { return *font_; }
515 void font(LyXFont const & f) { font_ = container.get(f);}
517 /// End position of paragraph this font attribute covers
519 /** Font. Interpretation of the font values:
520 If a value is LyXFont::INHERIT_*, it means that the font
521 attribute is inherited from either the layout of this
522 paragraph or, in the case of nested paragraphs, from the
523 layout in the environment one level up until completely
525 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
526 allowed in these font tables.
528 boost::shared_ptr<LyXFont> font_;
530 static ShareContainer<LyXFont> container;
533 friend struct matchFT;
536 /// used by lower_bound and upper_bound
538 int operator()(LyXParagraph::FontTable const & a,
539 LyXParagraph::FontTable const & b) const {
540 return a.pos() < b.pos();
545 typedef std::vector<FontTable> FontList;
549 typedef std::vector<InsetTable> InsetList;
553 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
554 std::ostream &, TexRow & texrow
556 ,std::ostream & foot, TexRow & foot_texrow,
562 LyXParagraph * TeXFootnote(Buffer const *, BufferParams const &,
563 std::ostream &, TexRow & texrow,
564 std::ostream & foot, TexRow & foot_texrow,
569 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
571 int & column, LyXFont const & font,
572 LyXLayout const & style);
574 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
575 std::ostream &, TexRow & texrow,
577 LyXFont & font, LyXFont & running_font,
578 LyXFont & basefont, bool & open_font,
579 LyXLayout const & style,
581 int & column, value_type const c);
585 static unsigned int paragraph_id;
588 class inset_iterator {
593 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
595 inset_iterator & operator++() {
600 Inset * operator*() { return (*it).inset; }
602 size_type getPos() const {return (*it).pos; }
604 bool operator==(inset_iterator const & iter) const {
605 return it == iter.it;
608 bool operator!=(inset_iterator const & iter) const {
609 return it != iter.it;
613 InsetList::iterator it;
616 inset_iterator inset_iterator_begin();
618 inset_iterator inset_iterator_end();
620 inset_iterator InsetIterator(size_type pos);
625 int LyXParagraph::id() const
632 void LyXParagraph::id(int id_arg)
639 bool LyXParagraph::IsFirstInSequence() const
641 LyXParagraph const * dhook = DepthHook(GetDepth());
642 return (dhook == this
643 || dhook->GetLayout() != GetLayout()
644 || dhook->GetDepth() != GetDepth());
649 Inset * LyXParagraph::InInset()
656 LyXParagraph::size_type LyXParagraph::size() const
663 void LyXParagraph::clearContents()
670 void LyXParagraph::setCounter(int i, int v)
677 int LyXParagraph::getCounter(int i) const
684 void LyXParagraph::incCounter(int i)
691 void LyXParagraph::SetChar(size_type pos, value_type c)
698 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
700 return inset_iterator(insetlist.begin());
705 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
707 return inset_iterator(insetlist.end());