3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 // It seems that MacOSX define the check macro.
17 #include "Dimension.h"
19 #include "support/types.h"
30 void lyxbreaker(void const * data, const char * hint, int size);
36 bool covers(int x, int y) const
39 && x <= pos.x_ + dim.wid
40 && y >= pos.y_ - dim.asc
41 && y <= pos.y_ + dim.des;
44 int squareDistance(int x, int y) const
51 else if (x > pos.x_ + dim.wid)
52 xx = x - pos.x_ - dim.wid;
54 if (y < pos.y_ - dim.asc)
55 yy = pos.y_ - dim.asc - y;
56 else if (y > pos.y_ + dim.des)
57 yy = y - pos.y_ - dim.des;
59 // Optimisation: We avoid to compute the sqrt on purpose.
65 template <class T> class CoordCacheBase {
77 void add(T const * thing, int x, int y)
79 data_[thing].pos = Point(x, y);
82 void add(T const * thing, Dimension const & dim)
85 data_[thing].pos = Point(-10000, -10000);
86 data_[thing].dim = dim;
89 Geometry const & geometry(T const * thing) const
91 check(thing, "geometry");
92 return data_.find(thing)->second;
95 Dimension const & dim(T const * thing) const
97 checkDim(thing, "dim");
98 return data_.find(thing)->second.dim;
101 int x(T const * thing) const
104 return data_.find(thing)->second.pos.x_;
107 int y(T const * thing) const
110 return data_.find(thing)->second.pos.y_;
113 Point xy(T const * thing) const
116 return data_.find(thing)->second.pos;
119 bool has(T const * thing) const
121 typename cache_type::const_iterator it = data_.find(thing);
123 if (it == data_.end())
125 return it->second.pos.x_ != -10000;
128 bool hasDim(T const * thing) const
130 return data_.find(thing) != data_.end();
133 bool covers(T const * thing, int x, int y) const
135 typename cache_type::const_iterator it = data_.find(thing);
136 return it != data_.end() && it->second.covers(x, y);
139 int squareDistance(T const * thing, int x, int y) const
141 typename cache_type::const_iterator it = data_.find(thing);
142 if (it == data_.end())
144 return it->second.squareDistance(x, y);
148 friend class CoordCache;
150 void checkDim(T const * thing, char const * hint) const
153 lyxbreaker(thing, hint, data_.size());
156 void check(T const * thing, char const * hint) const
159 lyxbreaker(thing, hint, data_.size());
162 typedef std::map<T const *, Geometry> cache_type;
167 * A BufferView dependent cache that allows us to come from an inset in
168 * a document to a position point and dimension on the screen.
169 * All points cached in this cache are only valid between subsequent
170 * updates. (x,y) == (0,0) is the upper left screen corner, x increases
171 * to the right, y increases downwords.
172 * The dimension part is built in BufferView::updateMetrics() and the
173 * diverse Inset::metrics() calls.
174 * The individual points are added at drawing time in
175 * BufferView::updateMetrics(). The math inset position are cached in
176 * the diverse InsetMathXXX::draw() calls and the in-text inset position
177 * are cached in RowPainter::paintInset().
178 * FIXME: For mathed, it would be nice if the insets did not saves their
179 * position themselves. That should be the duty of the containing math
186 /// A map from MathData to position on the screen
187 CoordCacheBase<MathData> & arrays() { return arrays_; }
188 CoordCacheBase<MathData> const & getArrays() const { return arrays_; }
189 /// A map from insets to positions on the screen
190 CoordCacheBase<Inset> & insets() { return insets_; }
191 CoordCacheBase<Inset> const & getInsets() const { return insets_; }
193 /// Dump the contents of the cache to lyxerr in debugging form
197 CoordCacheBase<MathData> arrays_;
199 CoordCacheBase<Inset> insets_;