3 * \file paragraph_pimpl.h
4 * Copyright 1995-2002 the LyX Team
5 * Read the file COPYING
8 #ifndef PARAGRAPH_PIMPL_H
9 #define PARAGRAPH_PIMPL_H
11 #include "paragraph.h"
12 #include "ParagraphParameters.h"
16 #include <boost/scoped_ptr.hpp>
20 struct Paragraph::Pimpl {
22 typedef std::vector<value_type> TextContainer;
25 Pimpl(Paragraph * owner);
27 Pimpl(Pimpl const &, Paragraph * owner, bool same_ids = false);
29 lyx::pos_type size() const {
39 void setContentsFromPar(Paragraph const * par);
41 void trackChanges(Change::Type type = Change::UNCHANGED);
43 void untrackChanges();
44 /// set all text as new for change mode
46 /// look up change type at given pos
47 Change::Type lookupChange(lyx::pos_type pos) const;
48 /// look up change at given pos
49 Change const lookupChangeFull(lyx::pos_type pos) const;
50 /// is there a change in the given range ?
51 bool isChanged(lyx::pos_type start, lyx::pos_type end) const;
52 /// is there a non-addition in this range ?
53 bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const;
56 void setChange(lyx::pos_type pos, Change::Type type);
62 void acceptChange(lyx::pos_type start, lyx::pos_type end);
65 void rejectChange(lyx::pos_type start, lyx::pos_type end);
67 /// are we tracking changes ?
68 bool tracking() const {
69 return changes_.get();
73 value_type getChar(lyx::pos_type pos) const;
75 void setChar(lyx::pos_type pos, value_type c);
77 void insertChar(lyx::pos_type pos, value_type c, LyXFont const & font, Change change = Change(Change::INSERTED));
79 void insertInset(lyx::pos_type pos, Inset * inset, LyXFont const & font, Change change = Change(Change::INSERTED));
81 void eraseIntern(lyx::pos_type pos);
82 /// erase the given position
83 void erase(lyx::pos_type pos);
84 /// erase the given range
85 bool erase(lyx::pos_type start, lyx::pos_type end);
87 LyXFont const realizeFont(LyXFont const & font,
88 BufferParams const & bparams) const;
92 /** A font entry covers a range of positions. Notice that the
93 entries in the list are inserted in random order.
94 I don't think it's worth the effort to implement a more effective
95 datastructure, because the number of different fonts in a paragraph
97 Nevertheless, I decided to store fontlist using a sorted vector:
98 fontlist = { {pos_1,font_1} , {pos_2,font_2} , ... } where
99 pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
100 and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
101 (font_1 covers the chars 0,...,pos_1) (Dekel)
105 FontTable(lyx::pos_type p, LyXFont const & f)
108 font_ = container.get(f);
111 lyx::pos_type pos() const { return pos_; }
113 void pos(lyx::pos_type p) { pos_ = p; }
115 LyXFont const & font() const { return *font_; }
117 void font(LyXFont const & f) { font_ = container.get(f);}
119 /// End position of paragraph this font attribute covers
121 /** Font. Interpretation of the font values:
122 If a value is LyXFont::INHERIT_*, it means that the font
123 attribute is inherited from either the layout of this
124 paragraph or, in the case of nested paragraphs, from the
125 layout in the environment one level up until completely
127 The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
128 allowed in these font tables.
130 boost::shared_ptr<LyXFont> font_;
132 static ShareContainer<LyXFont> container;
135 friend struct matchFT;
138 /// used by lower_bound and upper_bound
140 int operator()(FontTable const & a, FontTable const & b) const {
141 return a.pos() < b.pos();
146 typedef std::vector<FontTable> FontList;
151 Paragraph * TeXDeeper(Buffer const *, BufferParams const &,
152 std::ostream &, TexRow & texrow);
154 void simpleTeXBlanks(std::ostream &, TexRow & texrow,
155 lyx::pos_type const i,
156 unsigned int & column,
157 LyXFont const & font,
158 LyXLayout const & style);
160 void simpleTeXSpecialChars(Buffer const *, BufferParams const &,
161 std::ostream &, TexRow & texrow,
163 LyXFont & font, LyXFont & running_font,
164 LyXFont & basefont, bool & open_font,
165 Change::Type & running_change,
166 LyXLayout const & style,
168 unsigned int & column, value_type const c);
171 void validate(LaTeXFeatures & features,
172 LyXLayout const & layout) const;
175 Paragraph * getParFromID(int id) const;
179 static unsigned int paragraph_id;
181 ParagraphParameters params;
184 /// erase at the given position. Returns true if it was actually erased
185 bool erasePos(lyx::pos_type pos);
187 /// match a string against a particular point in the paragraph
188 bool isTextAt(string const & str, lyx::pos_type pos) const;
190 /// for recording and looking up changes in revision tracking mode
191 boost::scoped_ptr<Changes> changes_;