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,
77 typedef char value_type;
79 typedef std::vector<value_type> TextContainer;
81 /* This should be TextContainer::size_type, but we need
82 signed values for now.
84 typedef TextContainer::difference_type size_type;
88 /// this constructor inserts the new paragraph in a list
90 LyXParagraph(LyXParagraph * par);
92 LyXParagraph(LyXParagraph const &);
93 /// the destructor removes the new paragraph from the list
97 Language const * getParLanguage(BufferParams const &) const;
99 bool isRightToLeftPar(BufferParams const &) const;
101 void ChangeLanguage(BufferParams const & bparams,
102 Language const * from, Language const * to);
104 bool isMultiLingual(BufferParams const &);
107 string const String(Buffer const *, bool label);
109 string const String(Buffer const *, size_type beg, size_type end);
112 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
115 void validate(LaTeXFeatures &) const;
125 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
126 std::ostream &, TexRow & texrow,
129 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
130 std::ostream &, TexRow & texrow, bool moving_arg);
133 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
134 std::ostream &, TexRow & texrow);
137 LyXParagraph * Clone() const;
140 bool HasSameLayout(LyXParagraph const * par) const;
143 void MakeSameLayout(LyXParagraph const * par);
145 /// Is it the first par with same depth and layout?
146 bool IsFirstInSequence() const;
148 /** Check if the current paragraph is the last paragraph in a
150 int GetEndLabel(BufferParams const &) const;
154 void SetInsetOwner(Inset * i);
156 void deleteInsetsLyXText(BufferView *);
158 void resizeInsetsLyXText(BufferView *);
168 size_type size() const;
172 void setContentsFromPar(LyXParagraph * par);
174 void clearContents();
176 ParagraphParameters params;
179 LyXTextClass::LayoutList::size_type layout;
182 boost::array<int, 10> counter_;
185 void setCounter(int i, int v);
187 int getCounter(int i) const;
189 void incCounter(int i);
198 LyXParagraph * next_;
200 LyXParagraph * previous_;
203 InsetBibKey * bibkey; // ale970302
206 void next(LyXParagraph *);
207 /** these function are able to hide closed footnotes
209 LyXParagraph * next();
211 LyXParagraph const * next() const;
214 void previous(LyXParagraph *);
216 LyXParagraph * previous();
218 LyXParagraph const * previous() const;
220 /// for the environments
221 LyXParagraph * DepthHook(int depth);
222 /// for the environments
223 LyXParagraph const * DepthHook(int depth) const;
225 int BeginningOfMainBody() const;
227 string const & GetLabelstring() const;
229 /// the next two functions are for the manual labels
230 string const GetLabelWidthString() const;
232 void SetLabelWidthString(string const & s);
235 LyXTextClass::LayoutList::size_type GetLayout() const;
237 char GetAlign() const;
239 char GetDepth() const;
241 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
243 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
245 int GetFirstCounter(int i) const;
247 void Erase(size_type pos);
248 /** the flag determines wether the layout should be copied
250 void BreakParagraph(BufferParams const &, size_type pos, int flag);
252 void BreakParagraphConservative(BufferParams const &, size_type pos);
253 /** Get unistantiated font setting. Returns the difference
254 between the characters font and the layoutfont.
255 This is what is stored in the fonttable
258 GetFontSettings(BufferParams const &, size_type pos) const;
260 LyXFont const GetFirstFontSettings() const;
262 /** Get fully instantiated font. If pos == -1, use the layout
263 font attached to this paragraph.
264 If pos == -2, use the label font of the layout attached here.
265 In all cases, the font is instantiated, i.e. does not have any
266 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
269 LyXFont const getFont(BufferParams const &, size_type pos) const;
271 value_type GetChar(size_type pos) const;
273 value_type GetUChar(BufferParams const &, size_type pos) const;
274 /// The position must already exist.
275 void SetChar(size_type pos, value_type c);
277 void SetFont(size_type pos, LyXFont const & font);
279 string const GetWord(size_type &) const;
280 /// Returns the height of the highest font in range
281 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
282 size_type endpos) const;
284 void InsertChar(size_type pos, value_type c);
286 void InsertChar(size_type pos, value_type c, LyXFont const &);
288 void InsertInset(size_type pos, Inset * inset);
290 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
292 bool InsertInsetAllowed(Inset * inset);
294 Inset * GetInset(size_type pos);
296 Inset const * GetInset(size_type pos) const;
297 /** important for cut and paste
298 Temporary change from BufferParams to Buffer. Will revert when we
299 get rid of the argument to Inset::Clone(Buffer const &) */
300 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
302 void CutIntoMinibuffer(BufferParams const &, size_type pos);
304 bool InsertFromMinibuffer(size_type pos);
307 bool IsHfill(size_type pos) const;
309 bool IsInset(size_type pos) const;
311 bool IsNewline(size_type pos) const;
313 bool IsSeparator(size_type pos) const;
315 bool IsLineSeparator(size_type pos) const;
317 bool IsKomma(size_type pos) const;
318 /// Used by the spellchecker
319 bool IsLetter(size_type pos) const;
321 bool IsWord(size_type pos) const;
323 /** This one resets all layout and dtp switches but not the font
324 of the single characters
328 /** paste this paragraph with the next one
329 be carefull, this doesent make any check at all
331 void PasteParagraph(BufferParams const &);
333 /// used to remove the error messages
334 int AutoDeleteInsets();
336 /// returns -1 if inset not found
337 int GetPositionOfInset(Inset * inset) const;
340 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
342 #ifndef NO_PEXTRA_REALLY
343 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
344 I have to set it on each of it's elements */
346 void SetPExtraType(BufferParams const &, int type,
347 string const & width, string const & widthp);
349 void UnsetPExtraType(BufferParams const &);
352 bool linuxDocConvertChar(char c, string & sgml_string);
361 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
364 friend struct matchIT;
367 /// used by lower_bound and upper_bound
369 int operator()(LyXParagraph::InsetTable const & a,
370 LyXParagraph::InsetTable const & b) const {
371 return a.pos < b.pos;
374 /** A font entry covers a range of positions. Notice that the
375 entries in the list are inserted in random order.
376 I don't think it's worth the effort to implement a more effective
377 datastructure, because the number of different fonts in a paragraph
379 Nevertheless, I decided to store fontlist using a sorted vector:
380 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
381 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
382 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
383 (font_1 covers the chars 0,...,pos_1) (Dekel)
387 FontTable(size_type p, LyXFont const & f)
390 font_ = container.get(f);
393 size_type pos() const { return pos_; }
395 void pos(size_type p) { pos_ = p; }
397 LyXFont const & font() const { return *font_; }
399 void font(LyXFont const & f) { font_ = container.get(f);}
401 /// End position of paragraph this font attribute covers
403 /** Font. Interpretation of the font values:
404 If a value is LyXFont::INHERIT_*, it means that the font
405 attribute is inherited from either the layout of this
406 paragraph or, in the case of nested paragraphs, from the
407 layout in the environment one level up until completely
409 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
410 allowed in these font tables.
412 boost::shared_ptr<LyXFont> font_;
414 static ShareContainer<LyXFont> container;
417 friend struct matchFT;
420 /// used by lower_bound and upper_bound
422 int operator()(LyXParagraph::FontTable const & a,
423 LyXParagraph::FontTable const & b) const {
424 return a.pos() < b.pos();
429 typedef std::vector<FontTable> FontList;
433 typedef std::vector<InsetTable> InsetList;
437 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
438 std::ostream &, TexRow & texrow);
440 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
442 int & column, LyXFont const & font,
443 LyXLayout const & style);
445 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
446 std::ostream &, TexRow & texrow,
448 LyXFont & font, LyXFont & running_font,
449 LyXFont & basefont, bool & open_font,
450 LyXLayout const & style,
452 int & column, value_type const c);
456 static unsigned int paragraph_id;
459 class inset_iterator {
464 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
466 inset_iterator & operator++() {
471 Inset * operator*() { return (*it).inset; }
473 size_type getPos() const {return (*it).pos; }
475 bool operator==(inset_iterator const & iter) const {
476 return it == iter.it;
479 bool operator!=(inset_iterator const & iter) const {
480 return it != iter.it;
484 InsetList::iterator it;
487 inset_iterator inset_iterator_begin();
489 inset_iterator inset_iterator_end();
491 inset_iterator InsetIterator(size_type pos);
496 LyXParagraph::size_type LyXParagraph::size() const
503 LyXParagraph::value_type
504 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
506 lyx::Assert(pos <= size());
507 // This is stronger, and I belive that this is the assertion
508 // that we should really use. (Lgb)
509 //Assert(pos < size());
511 // Then this has no meaning. (Lgb)
512 if (!size() || pos == size()) return '\0';
519 int LyXParagraph::id() const
526 void LyXParagraph::id(int id_arg)
533 LyXTextClass::size_type LyXParagraph::GetLayout() const
540 bool LyXParagraph::IsFirstInSequence() const
542 LyXParagraph const * dhook = DepthHook(GetDepth());
543 return (dhook == this
544 || dhook->GetLayout() != GetLayout()
545 || dhook->GetDepth() != GetDepth());
550 Inset * LyXParagraph::InInset()
557 void LyXParagraph::clearContents()
564 void LyXParagraph::setCounter(int i, int v)
571 int LyXParagraph::getCounter(int i) const
578 void LyXParagraph::incCounter(int i)
585 void LyXParagraph::SetChar(size_type pos, value_type c)
592 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
594 return inset_iterator(insetlist.begin());
599 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
601 return inset_iterator(insetlist.end());