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);
91 /// the destructor removes the new paragraph from the list
95 Language const * getParLanguage(BufferParams const &) const;
97 bool isRightToLeftPar(BufferParams const &) const;
99 void ChangeLanguage(BufferParams const & bparams,
100 Language const * from, Language const * to);
102 bool isMultiLingual(BufferParams const &);
105 string const String(Buffer const *, bool label);
107 string const String(Buffer const *, size_type beg, size_type end);
110 void writeFile(Buffer const *, std::ostream &, BufferParams const &,
113 void validate(LaTeXFeatures &) const;
123 LyXParagraph * TeXOnePar(Buffer const *, BufferParams const &,
124 std::ostream &, TexRow & texrow,
127 bool SimpleTeXOnePar(Buffer const *, BufferParams const &,
128 std::ostream &, TexRow & texrow, bool moving_arg);
131 LyXParagraph * TeXEnvironment(Buffer const *, BufferParams const &,
132 std::ostream &, TexRow & texrow);
134 LyXParagraph * Clone() const;
137 bool HasSameLayout(LyXParagraph const * par) const;
140 void MakeSameLayout(LyXParagraph const * par);
142 /// Is it the first par with same depth and layout?
143 bool IsFirstInSequence() const;
145 /** Check if the current paragraph is the last paragraph in a
147 int GetEndLabel(BufferParams const &) const;
151 void SetInsetOwner(Inset * i);
153 void deleteInsetsLyXText(BufferView *);
155 void resizeInsetsLyXText(BufferView *);
165 size_type size() const;
169 void setContentsFromPar(LyXParagraph * par);
171 void clearContents();
173 ParagraphParameters params;
176 LyXTextClass::LayoutList::size_type layout;
179 boost::array<int, 10> counter_;
182 void setCounter(int i, int v);
184 int getCounter(int i) const;
186 void incCounter(int i);
195 LyXParagraph * next_;
197 LyXParagraph * previous_;
200 InsetBibKey * bibkey; // ale970302
203 void next(LyXParagraph *);
204 /** these function are able to hide closed footnotes
206 LyXParagraph * next();
208 LyXParagraph const * next() const;
211 void previous(LyXParagraph *);
213 LyXParagraph * previous();
215 LyXParagraph const * previous() const;
217 /// for the environments
218 LyXParagraph * DepthHook(int depth);
219 /// for the environments
220 LyXParagraph const * DepthHook(int depth) const;
222 int BeginningOfMainBody() const;
224 string const & GetLabelstring() const;
226 /// the next two functions are for the manual labels
227 string const GetLabelWidthString() const;
229 void SetLabelWidthString(string const & s);
232 LyXTextClass::LayoutList::size_type GetLayout() const;
234 char GetAlign() const;
236 char GetDepth() const;
238 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
240 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
242 int GetFirstCounter(int i) const;
244 void Erase(size_type pos);
245 /** the flag determines wether the layout should be copied
247 void BreakParagraph(BufferParams const &, size_type pos, int flag);
249 void BreakParagraphConservative(BufferParams const &, size_type pos);
250 /** Get unistantiated font setting. Returns the difference
251 between the characters font and the layoutfont.
252 This is what is stored in the fonttable
255 GetFontSettings(BufferParams const &, size_type pos) const;
257 LyXFont const GetFirstFontSettings() const;
259 /** Get fully instantiated font. If pos == -1, use the layout
260 font attached to this paragraph.
261 If pos == -2, use the label font of the layout attached here.
262 In all cases, the font is instantiated, i.e. does not have any
263 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
266 LyXFont const getFont(BufferParams const &, size_type pos) const;
268 value_type GetChar(size_type pos) const;
270 value_type GetUChar(BufferParams const &, size_type pos) const;
271 /// The position must already exist.
272 void SetChar(size_type pos, value_type c);
274 void SetFont(size_type pos, LyXFont const & font);
276 string const GetWord(size_type &) const;
277 /// Returns the height of the highest font in range
278 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
279 size_type endpos) const;
281 void InsertChar(size_type pos, value_type c);
283 void InsertChar(size_type pos, value_type c, LyXFont const &);
285 void InsertInset(size_type pos, Inset * inset);
287 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
289 bool InsertInsetAllowed(Inset * inset);
291 Inset * GetInset(size_type pos);
293 Inset const * GetInset(size_type pos) const;
294 /** important for cut and paste
295 Temporary change from BufferParams to Buffer. Will revert when we
296 get rid of the argument to Inset::Clone(Buffer const &) */
297 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
299 void CutIntoMinibuffer(BufferParams const &, size_type pos);
301 bool InsertFromMinibuffer(size_type pos);
304 bool IsHfill(size_type pos) const;
306 bool IsInset(size_type pos) const;
308 bool IsNewline(size_type pos) const;
310 bool IsSeparator(size_type pos) const;
312 bool IsLineSeparator(size_type pos) const;
314 bool IsKomma(size_type pos) const;
315 /// Used by the spellchecker
316 bool IsLetter(size_type pos) const;
318 bool IsWord(size_type pos) const;
320 /** This one resets all layout and dtp switches but not the font
321 of the single characters
325 /** paste this paragraph with the next one
326 be carefull, this doesent make any check at all
328 void PasteParagraph(BufferParams const &);
330 /// used to remove the error messages
331 int AutoDeleteInsets();
333 /// returns -1 if inset not found
334 int GetPositionOfInset(Inset * inset) const;
337 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
339 #ifndef NO_PEXTRA_REALLY
340 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
341 I have to set it on each of it's elements */
343 void SetPExtraType(BufferParams const &, int type,
344 string const & width, string const & widthp);
346 void UnsetPExtraType(BufferParams const &);
349 bool linuxDocConvertChar(char c, string & sgml_string);
358 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
361 friend struct matchIT;
364 /// used by lower_bound and upper_bound
366 int operator()(LyXParagraph::InsetTable const & a,
367 LyXParagraph::InsetTable const & b) const {
368 return a.pos < b.pos;
371 /** A font entry covers a range of positions. Notice that the
372 entries in the list are inserted in random order.
373 I don't think it's worth the effort to implement a more effective
374 datastructure, because the number of different fonts in a paragraph
376 Nevertheless, I decided to store fontlist using a sorted vector:
377 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
378 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
379 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
380 (font_1 covers the chars 0,...,pos_1) (Dekel)
384 FontTable(size_type p, LyXFont const & f)
387 font_ = container.get(f);
390 size_type pos() const { return pos_; }
392 void pos(size_type p) { pos_ = p; }
394 LyXFont const & font() const { return *font_; }
396 void font(LyXFont const & f) { font_ = container.get(f);}
398 /// End position of paragraph this font attribute covers
400 /** Font. Interpretation of the font values:
401 If a value is LyXFont::INHERIT_*, it means that the font
402 attribute is inherited from either the layout of this
403 paragraph or, in the case of nested paragraphs, from the
404 layout in the environment one level up until completely
406 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
407 allowed in these font tables.
409 boost::shared_ptr<LyXFont> font_;
411 static ShareContainer<LyXFont> container;
414 friend struct matchFT;
417 /// used by lower_bound and upper_bound
419 int operator()(LyXParagraph::FontTable const & a,
420 LyXParagraph::FontTable const & b) const {
421 return a.pos() < b.pos();
426 typedef std::vector<FontTable> FontList;
430 typedef std::vector<InsetTable> InsetList;
434 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
435 std::ostream &, TexRow & texrow);
437 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
439 int & column, LyXFont const & font,
440 LyXLayout const & style);
442 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
443 std::ostream &, TexRow & texrow,
445 LyXFont & font, LyXFont & running_font,
446 LyXFont & basefont, bool & open_font,
447 LyXLayout const & style,
449 int & column, value_type const c);
453 static unsigned int paragraph_id;
456 class inset_iterator {
461 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
463 inset_iterator & operator++() {
468 Inset * operator*() { return (*it).inset; }
470 size_type getPos() const {return (*it).pos; }
472 bool operator==(inset_iterator const & iter) const {
473 return it == iter.it;
476 bool operator!=(inset_iterator const & iter) const {
477 return it != iter.it;
481 InsetList::iterator it;
484 inset_iterator inset_iterator_begin();
486 inset_iterator inset_iterator_end();
488 inset_iterator InsetIterator(size_type pos);
493 LyXParagraph::size_type LyXParagraph::size() const
500 LyXParagraph::value_type
501 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
503 lyx::Assert(pos <= size());
504 // This is stronger, and I belive that this is the assertion
505 // that we should really use. (Lgb)
506 //Assert(pos < size());
508 // Then this has no meaning. (Lgb)
509 if (!size() || pos == size()) return '\0';
516 int LyXParagraph::id() const
523 void LyXParagraph::id(int id_arg)
530 LyXTextClass::size_type LyXParagraph::GetLayout() const
537 bool LyXParagraph::IsFirstInSequence() const
539 LyXParagraph const * dhook = DepthHook(GetDepth());
540 return (dhook == this
541 || dhook->GetLayout() != GetLayout()
542 || dhook->GetDepth() != GetDepth());
547 Inset * LyXParagraph::InInset()
554 void LyXParagraph::clearContents()
561 void LyXParagraph::setCounter(int i, int v)
568 int LyXParagraph::getCounter(int i) const
575 void LyXParagraph::incCounter(int i)
582 void LyXParagraph::SetChar(size_type pos, value_type c)
589 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
591 return inset_iterator(insetlist.begin());
596 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
598 return inset_iterator(insetlist.end());