2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 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 // After 1.2.0 is released, during 1.3.0cvs, we enable this. And after
38 // a while we verify that reading of 1.2.x files work perfectly we remove
39 // this code completely. (Lgb)
40 //#define NO_PEXTRA_REALLY 1
42 // Define this if you want to try out the new storage container for
43 // paragraphs. std::container instead of obfuscated homegrown
45 // This is non working and far from finished.
48 /// A LyXParagraph holds all text, attributes and insets in a text paragraph
51 #ifndef NO_PEXTRA_REALLY
64 enum MINIPAGE_ALIGNMENT {
68 MINIPAGE_ALIGN_MIDDLE,
83 typedef char value_type;
85 typedef std::vector<value_type> TextContainer;
87 /* This should be TextContainer::size_type, but we need
88 signed values for now.
90 typedef TextContainer::difference_type size_type;
94 /// this constructor inserts the new paragraph in a list
96 LyXParagraph(LyXParagraph * par);
98 LyXParagraph(LyXParagraph const &);
99 /// the destructor removes the new paragraph from the list
103 Language const * getParLanguage(BufferParams const &) const;
105 bool isRightToLeftPar(BufferParams const &) const;
107 void ChangeLanguage(BufferParams const & bparams,
108 Language const * from, Language const * to);
110 bool isMultiLingual(BufferParams const &);
113 string const String(Buffer const *, bool label);
115 string const String(Buffer const *, size_type beg, size_type end);
118 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
121 void validate(LaTeXFeatures &) const;
131 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
132 std::ostream &, TexRow & texrow,
135 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
136 std::ostream &, TexRow & texrow, bool moving_arg);
139 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
140 std::ostream &, TexRow & texrow);
142 bool HasSameLayout(LyXParagraph const * par) const;
145 void MakeSameLayout(LyXParagraph const * par);
147 /// Is it the first par with same depth and layout?
148 bool IsFirstInSequence() const;
150 /** Check if the current paragraph is the last paragraph in a
152 int GetEndLabel(BufferParams const &) const;
156 void SetInsetOwner(Inset * i);
158 void deleteInsetsLyXText(BufferView *);
160 void resizeInsetsLyXText(BufferView *);
170 size_type size() const;
174 void setContentsFromPar(LyXParagraph * par);
176 void clearContents();
178 ParagraphParameters params;
181 LyXTextClass::LayoutList::size_type layout;
184 boost::array<int, 10> counter_;
187 void setCounter(int i, int v);
189 int getCounter(int i) const;
191 void incCounter(int i);
200 LyXParagraph * next_;
202 LyXParagraph * previous_;
205 InsetBibKey * bibkey; // ale970302
208 void next(LyXParagraph *);
209 /** these function are able to hide closed footnotes
211 LyXParagraph * next();
213 LyXParagraph const * next() const;
216 void previous(LyXParagraph *);
218 LyXParagraph * previous();
220 LyXParagraph const * previous() const;
222 /// for the environments
223 LyXParagraph * DepthHook(int depth);
224 /// for the environments
225 LyXParagraph const * DepthHook(int depth) const;
227 int BeginningOfMainBody() const;
229 string const & GetLabelstring() const;
231 /// the next two functions are for the manual labels
232 string const GetLabelWidthString() const;
234 void SetLabelWidthString(string const & s);
237 LyXTextClass::LayoutList::size_type GetLayout() const;
239 char GetAlign() const;
241 char GetDepth() const;
243 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
245 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
247 int GetFirstCounter(int i) const;
249 void Erase(size_type pos);
250 /** the flag determines wether the layout should be copied
252 void BreakParagraph(BufferParams const &, size_type pos, int flag);
254 void BreakParagraphConservative(BufferParams const &, size_type pos);
255 /** Get unistantiated font setting. Returns the difference
256 between the characters font and the layoutfont.
257 This is what is stored in the fonttable
260 GetFontSettings(BufferParams const &, size_type pos) const;
262 LyXFont const GetFirstFontSettings() const;
264 /** Get fully instantiated font. If pos == -1, use the layout
265 font attached to this paragraph.
266 If pos == -2, use the label font of the layout attached here.
267 In all cases, the font is instantiated, i.e. does not have any
268 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
271 LyXFont const getFont(BufferParams const &, size_type pos) const;
273 value_type GetChar(size_type pos) const;
275 value_type GetUChar(BufferParams const &, size_type pos) const;
276 /// The position must already exist.
277 void SetChar(size_type pos, value_type c);
279 void SetFont(size_type pos, LyXFont const & font);
281 string const GetWord(size_type &) const;
282 /// Returns the height of the highest font in range
283 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
284 size_type endpos) const;
286 void InsertChar(size_type pos, value_type c);
288 void InsertChar(size_type pos, value_type c, LyXFont const &);
290 void InsertInset(size_type pos, Inset * inset);
292 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
294 bool InsertInsetAllowed(Inset * inset);
296 Inset * GetInset(size_type pos);
298 Inset const * GetInset(size_type pos) const;
299 /** important for cut and paste
300 Temporary change from BufferParams to Buffer. Will revert when we
301 get rid of the argument to Inset::Clone(Buffer const &) */
302 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
304 void CutIntoMinibuffer(BufferParams const &, size_type pos);
306 bool InsertFromMinibuffer(size_type pos);
309 bool IsHfill(size_type pos) const;
311 bool IsInset(size_type pos) const;
313 bool IsNewline(size_type pos) const;
315 bool IsSeparator(size_type pos) const;
317 bool IsLineSeparator(size_type pos) const;
319 bool IsKomma(size_type pos) const;
320 /// Used by the spellchecker
321 bool IsLetter(size_type pos) const;
323 bool IsWord(size_type pos) const;
325 /** This one resets all layout and dtp switches but not the font
326 of the single characters
330 /** paste this paragraph with the next one
331 be carefull, this doesent make any check at all
333 void PasteParagraph(BufferParams const &);
335 /// used to remove the error messages
336 int AutoDeleteInsets();
338 /// returns -1 if inset not found
339 int GetPositionOfInset(Inset * inset) const;
342 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
344 #ifndef NO_PEXTRA_REALLY
345 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
346 I have to set it on each of it's elements */
348 void SetPExtraType(BufferParams const &, int type,
349 string const & width, string const & widthp);
351 void UnsetPExtraType(BufferParams const &);
354 bool linuxDocConvertChar(char c, string & sgml_string);
363 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
366 friend struct matchIT;
369 /// used by lower_bound and upper_bound
371 int operator()(LyXParagraph::InsetTable const & a,
372 LyXParagraph::InsetTable const & b) const {
373 return a.pos < b.pos;
376 /** A font entry covers a range of positions. Notice that the
377 entries in the list are inserted in random order.
378 I don't think it's worth the effort to implement a more effective
379 datastructure, because the number of different fonts in a paragraph
381 Nevertheless, I decided to store fontlist using a sorted vector:
382 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
383 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
384 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
385 (font_1 covers the chars 0,...,pos_1) (Dekel)
389 FontTable(size_type p, LyXFont const & f)
392 font_ = container.get(f);
395 size_type pos() const { return pos_; }
397 void pos(size_type p) { pos_ = p; }
399 LyXFont const & font() const { return *font_; }
401 void font(LyXFont const & f) { font_ = container.get(f);}
403 /// End position of paragraph this font attribute covers
405 /** Font. Interpretation of the font values:
406 If a value is LyXFont::INHERIT_*, it means that the font
407 attribute is inherited from either the layout of this
408 paragraph or, in the case of nested paragraphs, from the
409 layout in the environment one level up until completely
411 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
412 allowed in these font tables.
414 boost::shared_ptr<LyXFont> font_;
416 static ShareContainer<LyXFont> container;
419 friend struct matchFT;
422 /// used by lower_bound and upper_bound
424 int operator()(LyXParagraph::FontTable const & a,
425 LyXParagraph::FontTable const & b) const {
426 return a.pos() < b.pos();
431 typedef std::vector<FontTable> FontList;
435 typedef std::vector<InsetTable> InsetList;
439 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
440 std::ostream &, TexRow & texrow);
442 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
444 int & column, LyXFont const & font,
445 LyXLayout const & style);
447 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
448 std::ostream &, TexRow & texrow,
450 LyXFont & font, LyXFont & running_font,
451 LyXFont & basefont, bool & open_font,
452 LyXLayout const & style,
454 int & column, value_type const c);
458 static unsigned int paragraph_id;
461 class inset_iterator {
466 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
468 inset_iterator & operator++() {
473 Inset * operator*() { return (*it).inset; }
475 size_type getPos() const {return (*it).pos; }
477 bool operator==(inset_iterator const & iter) const {
478 return it == iter.it;
481 bool operator!=(inset_iterator const & iter) const {
482 return it != iter.it;
486 InsetList::iterator it;
489 inset_iterator inset_iterator_begin();
491 inset_iterator inset_iterator_end();
493 inset_iterator InsetIterator(size_type pos);
498 LyXParagraph::size_type LyXParagraph::size() const
505 LyXParagraph::value_type
506 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
508 lyx::Assert(pos <= size());
509 // This is stronger, and I belive that this is the assertion
510 // that we should really use. (Lgb)
511 //Assert(pos < size());
513 // Then this has no meaning. (Lgb)
514 if (!size() || pos == size()) return '\0';
521 int LyXParagraph::id() const
528 void LyXParagraph::id(int id_arg)
535 LyXTextClass::size_type LyXParagraph::GetLayout() const
542 bool LyXParagraph::IsFirstInSequence() const
544 LyXParagraph const * dhook = DepthHook(GetDepth());
545 return (dhook == this
546 || dhook->GetLayout() != GetLayout()
547 || dhook->GetDepth() != GetDepth());
552 Inset * LyXParagraph::InInset()
559 void LyXParagraph::clearContents()
566 void LyXParagraph::setCounter(int i, int v)
573 int LyXParagraph::getCounter(int i) const
580 void LyXParagraph::incCounter(int i)
587 void LyXParagraph::SetChar(size_type pos, value_type c)
594 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
596 return inset_iterator(insetlist.begin());
601 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
603 return inset_iterator(insetlist.end());