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);
48 bool covers(int x, int y) const
51 && x <= pos.x_ + dim.wid
52 && y >= pos.y_ - dim.asc
53 && y <= pos.y_ + dim.des;
58 template <class T> class CoordCacheBase {
70 void add(T const * thing, int x, int y)
72 data_[thing].pos = Point(x, y);
75 void add(T const * thing, Dimension const & dim)
77 data_[thing].dim = dim;
80 Dimension const & dim(T const * thing) const
83 return data_.find(thing)->second.dim;
86 int x(T const * thing) const
89 return data_.find(thing)->second.pos.x_;
92 int y(T const * thing) const
95 return data_.find(thing)->second.pos.y_;
98 Point xy(T const * thing) const
101 return data_.find(thing)->second.pos;
104 bool has(T const * thing) const
106 return data_.find(thing) != data_.end();
109 bool covers(T const * thing, int x, int y) const
111 cache_type::const_iterator it = data_.find(thing);
112 return it != data_.end() && it->second.covers(x, y);
116 friend class CoordCache;
118 void check(T const * thing, char const * hint) const
121 lyxbreaker(thing, hint, data_.size());
124 typedef std::map<T const *, Geometry> cache_type;
128 cache_type const & getData() const { return data_; }
132 * A BufferView dependent cache that allows us to come from an inset in
133 * a document to a position point and dimension on the screen.
134 * All points cached in this cache are only valid between subsequent
135 * updates. (x,y) == (0,0) is the upper left screen corner, x increases
136 * to the right, y increases downwords.
137 * The dimension part is built in BufferView::updateMetrics() and the
138 * diverse Inset::metrics() calls.
139 * The individual points are added at drawing time in
140 * BufferView::updateMetrics(). The math inset position are cached in
141 * the diverse InsetMathXXX::draw() calls and the in-text inset position
142 * are cached in RowPainter::paintInset().
143 * FIXME: For mathed, it would be nice if the insets did not saves their
144 * position themselves. That should be the duty of the containing math
151 /// A map from MathData to position on the screen
152 CoordCacheBase<MathData> & arrays() { return arrays_; }
153 CoordCacheBase<MathData> const & getArrays() const { return arrays_; }
154 /// A map from insets to positions on the screen
155 CoordCacheBase<Inset> & insets() { return insets_; }
156 CoordCacheBase<Inset> const & getInsets() const { return insets_; }
158 /// Dump the contents of the cache to lyxerr in debugging form
162 CoordCacheBase<MathData> arrays_;
164 CoordCacheBase<Inset> insets_;