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.
22 #include "support/types.h"
24 #include <boost/assert.hpp>
30 void lyxbreaker(void const * data, const char * hint, int size);
41 BOOST_ASSERT(x > -1000000);
42 BOOST_ASSERT(x < 1000000);
43 BOOST_ASSERT(y > -1000000);
44 BOOST_ASSERT(y < 1000000);
50 template <class T> class CoordCacheBase {
57 void add(T const * thing, int x, int y)
59 data_[thing] = Point(x, y);
62 int x(T const * thing) const
65 return data_.find(thing)->second.x_;
68 int y(T const * thing) const
71 return data_.find(thing)->second.y_;
74 Point xy(T const * thing) const
77 return data_.find(thing)->second;
80 bool has(T const * thing) const
82 return data_.find(thing) != data_.end();
85 // T * find(int x, int y) const
92 friend class CoordCache;
94 void check(T const * thing, char const * hint) const
97 lyxbreaker(thing, hint, data_.size());
100 typedef std::map<T const *, Point> cache_type;
105 * A global cache that allows us to come from a paragraph in a document
106 * to a position point on the screen.
107 * All points cached in this cache are only valid between subsequent
108 * updated. (x,y) == (0,0) is the upper left screen corner, x increases
109 * to the right, y increases downwords.
110 * The cache is built in BufferView::Pimpl::metrics which is called
111 * from BufferView::Pimpl::update. The individual points are added
112 * while we paint them. See for instance paintPar in RowPainter.C.
117 Point get(LyXText const *, lyx::pit_type);
119 /// A map from paragraph index number to screen point
120 typedef std::map<lyx::pit_type, Point> InnerParPosCache;
121 /// A map from a LyXText to the map of paragraphs to screen points
122 typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
123 /// A map from a CursorSlice to screen points
124 typedef std::map<LyXText const *, InnerParPosCache> SliceCache;
126 /// A map from MathArray to position on the screen
127 CoordCacheBase<MathArray> & arrays() { return arrays_; }
128 CoordCacheBase<MathArray> const & getArrays() const { return arrays_; }
129 /// A map from insets to positions on the screen
130 CoordCacheBase<InsetBase> & insets() { return insets_; }
131 CoordCacheBase<InsetBase> const & getInsets() const { return insets_; }
132 /// A map from (LyXText, paragraph) pair to screen positions
133 ParPosCache & parPos() { return pars_; }
134 ParPosCache const & getParPos() const { return pars_; }
136 SliceCache & slice(bool boundary)
138 return boundary ? slices1_ : slices0_;
140 SliceCache const & getSlice(bool boundary) const
142 return boundary ? slices1_ : slices0_;
147 CoordCacheBase<MathArray> arrays_;
149 CoordCacheBase<InsetBase> insets_;
150 /// Paragraph grouped by owning text
152 /// Used with boundary == 0
154 /// Used with boundary == 1