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"
28 void lyxbreaker(void const * data, const char * hint, int size);
34 bool covers(int x, int y) const
37 && x <= pos.x_ + dim.wid
38 && y >= pos.y_ - dim.asc
39 && y <= pos.y_ + dim.des;
42 int squareDistance(int x, int y) const
49 else if (x > pos.x_ + dim.wid)
50 xx = x - pos.x_ - dim.wid;
52 if (y < pos.y_ - dim.asc)
53 yy = pos.y_ - dim.asc - y;
54 else if (y > pos.y_ + dim.des)
55 yy = y - pos.y_ - dim.des;
57 // Optimisation: We avoid to compute the sqrt on purpose.
63 template <class T> class CoordCacheBase {
75 void add(T const * thing, int x, int y)
77 data_[thing].pos = Point(x, y);
80 void add(T const * thing, Dimension const & dim)
83 data_[thing].pos = Point(-10000, -10000);
84 data_[thing].dim = dim;
87 Geometry const & geometry(T const * thing) const
89 check(thing, "geometry");
90 return data_.find(thing)->second;
93 Dimension const & dim(T const * thing) const
95 checkDim(thing, "dim");
96 return data_.find(thing)->second.dim;
99 int x(T const * thing) const
102 return data_.find(thing)->second.pos.x_;
105 int y(T const * thing) const
108 return data_.find(thing)->second.pos.y_;
111 Point xy(T const * thing) const
114 return data_.find(thing)->second.pos;
117 bool has(T const * thing) const
119 typename cache_type::const_iterator it = data_.find(thing);
121 if (it == data_.end())
123 return it->second.pos.x_ != -10000;
126 bool hasDim(T const * thing) const
128 return data_.find(thing) != data_.end();
131 bool covers(T const * thing, int x, int y) const
133 typename cache_type::const_iterator it = data_.find(thing);
134 return it != data_.end() && it->second.covers(x, y);
137 int squareDistance(T const * thing, int x, int y) const
139 typename cache_type::const_iterator it = data_.find(thing);
140 if (it == data_.end())
142 return it->second.squareDistance(x, y);
146 friend class CoordCache;
148 void checkDim(T const * thing, char const * hint) const
151 lyxbreaker(thing, hint, data_.size());
154 void check(T const * thing, char const * hint) const
157 lyxbreaker(thing, hint, data_.size());
160 typedef std::map<T const *, Geometry> cache_type;
165 * A BufferView dependent cache that allows us to come from an inset in
166 * a document to a position point and dimension on the screen.
167 * All points cached in this cache are only valid between subsequent
168 * updates. (x,y) == (0,0) is the upper left screen corner, x increases
169 * to the right, y increases downwords.
170 * The dimension part is built in BufferView::updateMetrics() and the
171 * diverse Inset::metrics() calls.
172 * The individual points are added at drawing time in
173 * BufferView::draw(). The math inset position are cached in
174 * the diverse InsetMathXXX::draw() calls and the in-text inset position
175 * are cached in RowPainter::paintInset().
176 * FIXME: For mathed, it would be nice if the insets did not saves their
177 * position themselves. That should be the duty of the containing math
184 /// A map from MathData to position on the screen
185 typedef CoordCacheBase<MathData> Arrays;
186 Arrays & arrays() { return arrays_; }
187 Arrays const & getArrays() const { return arrays_; }
188 /// A map from insets to positions on the screen
189 typedef CoordCacheBase<Inset> Insets;
190 Insets & insets() { return insets_; }
191 Insets const & getInsets() const { return insets_; }
193 /// Dump the contents of the cache to lyxerr in debugging form