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);
136 bool HasSameLayout(LyXParagraph const * par) const;
139 void MakeSameLayout(LyXParagraph const * par);
141 /// Is it the first par with same depth and layout?
142 bool IsFirstInSequence() const;
144 /** Check if the current paragraph is the last paragraph in a
146 int GetEndLabel(BufferParams const &) const;
150 void SetInsetOwner(Inset * i);
152 void deleteInsetsLyXText(BufferView *);
154 void resizeInsetsLyXText(BufferView *);
164 size_type size() const;
168 void setContentsFromPar(LyXParagraph * par);
170 void clearContents();
172 ParagraphParameters params;
175 LyXTextClass::LayoutList::size_type layout;
178 boost::array<int, 10> counter_;
181 void setCounter(int i, int v);
183 int getCounter(int i) const;
185 void incCounter(int i);
194 LyXParagraph * next_;
196 LyXParagraph * previous_;
199 InsetBibKey * bibkey; // ale970302
202 void next(LyXParagraph *);
203 /** these function are able to hide closed footnotes
205 LyXParagraph * next();
207 LyXParagraph const * next() const;
210 void previous(LyXParagraph *);
212 LyXParagraph * previous();
214 LyXParagraph const * previous() const;
216 /// for the environments
217 LyXParagraph * DepthHook(int depth);
218 /// for the environments
219 LyXParagraph const * DepthHook(int depth) const;
221 int BeginningOfMainBody() const;
223 string const & GetLabelstring() const;
225 /// the next two functions are for the manual labels
226 string const GetLabelWidthString() const;
228 void SetLabelWidthString(string const & s);
231 LyXTextClass::LayoutList::size_type GetLayout() const;
233 char GetAlign() const;
235 char GetDepth() const;
237 void SetLayout(LyXTextClass::LayoutList::size_type new_layout);
239 void SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout);
241 int GetFirstCounter(int i) const;
243 void Erase(size_type pos);
244 /** the flag determines wether the layout should be copied
246 void BreakParagraph(BufferParams const &, size_type pos, int flag);
248 void BreakParagraphConservative(BufferParams const &, size_type pos);
249 /** Get unistantiated font setting. Returns the difference
250 between the characters font and the layoutfont.
251 This is what is stored in the fonttable
254 GetFontSettings(BufferParams const &, size_type pos) const;
256 LyXFont const GetFirstFontSettings() const;
258 /** Get fully instantiated font. If pos == -1, use the layout
259 font attached to this paragraph.
260 If pos == -2, use the label font of the layout attached here.
261 In all cases, the font is instantiated, i.e. does not have any
262 attributes with values LyXFont::INHERIT, LyXFont::IGNORE or
265 LyXFont const getFont(BufferParams const &, size_type pos) const;
267 value_type GetChar(size_type pos) const;
269 value_type GetUChar(BufferParams const &, size_type pos) const;
270 /// The position must already exist.
271 void SetChar(size_type pos, value_type c);
273 void SetFont(size_type pos, LyXFont const & font);
275 string const GetWord(size_type &) const;
276 /// Returns the height of the highest font in range
277 LyXFont::FONT_SIZE HighestFontInRange(size_type startpos,
278 size_type endpos) const;
280 void InsertChar(size_type pos, value_type c);
282 void InsertChar(size_type pos, value_type c, LyXFont const &);
284 void InsertInset(size_type pos, Inset * inset);
286 void InsertInset(size_type pos, Inset * inset, LyXFont const &);
288 bool InsertInsetAllowed(Inset * inset);
290 Inset * GetInset(size_type pos);
292 Inset const * GetInset(size_type pos) const;
293 /** important for cut and paste
294 Temporary change from BufferParams to Buffer. Will revert when we
295 get rid of the argument to Inset::Clone(Buffer const &) */
296 void CopyIntoMinibuffer(Buffer const &, size_type pos) const;
298 void CutIntoMinibuffer(BufferParams const &, size_type pos);
300 bool InsertFromMinibuffer(size_type pos);
303 bool IsHfill(size_type pos) const;
305 bool IsInset(size_type pos) const;
307 bool IsNewline(size_type pos) const;
309 bool IsSeparator(size_type pos) const;
311 bool IsLineSeparator(size_type pos) const;
313 bool IsKomma(size_type pos) const;
314 /// Used by the spellchecker
315 bool IsLetter(size_type pos) const;
317 bool IsWord(size_type pos) const;
319 /** This one resets all layout and dtp switches but not the font
320 of the single characters
324 /** paste this paragraph with the next one
325 be carefull, this doesent make any check at all
327 void PasteParagraph(BufferParams const &);
329 /// used to remove the error messages
330 int AutoDeleteInsets();
332 /// returns -1 if inset not found
333 int GetPositionOfInset(Inset * inset) const;
336 int StripLeadingSpaces(LyXTextClassList::size_type tclass);
338 #ifndef NO_PEXTRA_REALLY
339 /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE
340 I have to set it on each of it's elements */
342 void SetPExtraType(BufferParams const &, int type,
343 string const & width, string const & widthp);
345 void UnsetPExtraType(BufferParams const &);
348 bool linuxDocConvertChar(char c, string & sgml_string);
357 InsetTable(size_type p, Inset * i) : pos(p), inset(i) {}
360 friend struct matchIT;
363 /// used by lower_bound and upper_bound
365 int operator()(LyXParagraph::InsetTable const & a,
366 LyXParagraph::InsetTable const & b) const {
367 return a.pos < b.pos;
370 /** A font entry covers a range of positions. Notice that the
371 entries in the list are inserted in random order.
372 I don't think it's worth the effort to implement a more effective
373 datastructure, because the number of different fonts in a paragraph
375 Nevertheless, I decided to store fontlist using a sorted vector:
376 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
377 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
378 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
379 (font_1 covers the chars 0,...,pos_1) (Dekel)
383 FontTable(size_type p, LyXFont const & f)
386 font_ = container.get(f);
389 size_type pos() const { return pos_; }
391 void pos(size_type p) { pos_ = p; }
393 LyXFont const & font() const { return *font_; }
395 void font(LyXFont const & f) { font_ = container.get(f);}
397 /// End position of paragraph this font attribute covers
399 /** Font. Interpretation of the font values:
400 If a value is LyXFont::INHERIT_*, it means that the font
401 attribute is inherited from either the layout of this
402 paragraph or, in the case of nested paragraphs, from the
403 layout in the environment one level up until completely
405 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
406 allowed in these font tables.
408 boost::shared_ptr<LyXFont> font_;
410 static ShareContainer<LyXFont> container;
413 friend struct matchFT;
416 /// used by lower_bound and upper_bound
418 int operator()(LyXParagraph::FontTable const & a,
419 LyXParagraph::FontTable const & b) const {
420 return a.pos() < b.pos();
425 typedef std::vector<FontTable> FontList;
429 typedef std::vector<InsetTable> InsetList;
433 LyXParagraph * TeXDeeper(Buffer const *, BufferParams const &,
434 std::ostream &, TexRow & texrow);
436 void SimpleTeXBlanks(std::ostream &, TexRow & texrow,
438 int & column, LyXFont const & font,
439 LyXLayout const & style);
441 void SimpleTeXSpecialChars(Buffer const *, BufferParams const &,
442 std::ostream &, TexRow & texrow,
444 LyXFont & font, LyXFont & running_font,
445 LyXFont & basefont, bool & open_font,
446 LyXLayout const & style,
448 int & column, value_type const c);
452 static unsigned int paragraph_id;
455 class inset_iterator {
460 inset_iterator(InsetList::iterator const & iter) : it(iter) {};
462 inset_iterator & operator++() {
467 Inset * operator*() { return (*it).inset; }
469 size_type getPos() const {return (*it).pos; }
471 bool operator==(inset_iterator const & iter) const {
472 return it == iter.it;
475 bool operator!=(inset_iterator const & iter) const {
476 return it != iter.it;
480 InsetList::iterator it;
483 inset_iterator inset_iterator_begin();
485 inset_iterator inset_iterator_end();
487 inset_iterator InsetIterator(size_type pos);
492 LyXParagraph::size_type LyXParagraph::size() const
499 LyXParagraph::value_type
500 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
502 lyx::Assert(pos <= size());
503 // This is stronger, and I belive that this is the assertion
504 // that we should really use. (Lgb)
505 //Assert(pos < size());
507 // Then this has no meaning. (Lgb)
508 if (!size() || pos == size()) return '\0';
515 int LyXParagraph::id() const
522 void LyXParagraph::id(int id_arg)
529 LyXTextClass::size_type LyXParagraph::GetLayout() const
536 bool LyXParagraph::IsFirstInSequence() const
538 LyXParagraph const * dhook = DepthHook(GetDepth());
539 return (dhook == this
540 || dhook->GetLayout() != GetLayout()
541 || dhook->GetDepth() != GetDepth());
546 Inset * LyXParagraph::InInset()
553 void LyXParagraph::clearContents()
560 void LyXParagraph::setCounter(int i, int v)
567 int LyXParagraph::getCounter(int i) const
574 void LyXParagraph::incCounter(int i)
581 void LyXParagraph::SetChar(size_type pos, value_type c)
588 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_begin()
590 return inset_iterator(insetlist.begin());
595 LyXParagraph::inset_iterator LyXParagraph::inset_iterator_end()
597 return inset_iterator(insetlist.end());