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>
28 void lyxbreaker(void const * data, const char * hint, int size);
39 BOOST_ASSERT(x > -1000000);
40 BOOST_ASSERT(x < 1000000);
41 BOOST_ASSERT(y > -1000000);
42 BOOST_ASSERT(y < 1000000);
48 template <class T> class CoordCacheBase {
55 void add(T const * thing, int x, int y)
57 data_[thing] = Point(x, y);
60 int x(T const * thing) const
63 return data_.find(thing)->second.x_;
66 int y(T const * thing) const
69 return data_.find(thing)->second.y_;
72 Point xy(T const * thing) const
75 return data_.find(thing)->second;
78 bool has(T const * thing) const
80 return data_.find(thing) != data_.end();
83 // T * find(int x, int y) const
90 friend class CoordCache;
92 void check(T const * thing, char const * hint) const
95 lyxbreaker(thing, hint, data_.size());
98 typedef std::map<T const *, Point> cache_type;
103 * A global cache that allows us to come from a paragraph in a document
104 * to a position point on the screen.
105 * All points cached in this cache are only valid between subsequent
106 * updated. (x,y) == (0,0) is the upper left screen corner, x increases
107 * to the right, y increases downwords.
108 * The cache is built in BufferView::Pimpl::metrics which is called
109 * from BufferView::Pimpl::update. The individual points are added
110 * while we paint them. See for instance paintPar in RowPainter.C.
115 Point get(LyXText const *, lyx::pit_type);
117 /// A map from paragraph index number to screen point
118 typedef std::map<lyx::pit_type, Point> InnerParPosCache;
119 /// A map from a LyXText to the map of paragraphs to screen points
120 typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
121 /// A map from a CursorSlice to screen points
122 typedef std::map<LyXText const *, InnerParPosCache> SliceCache;
124 /// A map from MathArray to position on the screen
125 CoordCacheBase<MathArray> & arrays() { return arrays_; }
126 CoordCacheBase<MathArray> const & getArrays() const { return arrays_; }
127 /// A map from insets to positions on the screen
128 CoordCacheBase<InsetBase> & insets() { return insets_; }
129 CoordCacheBase<InsetBase> const & getInsets() const { return insets_; }
130 /// A map from (LyXText, paragraph) pair to screen positions
131 ParPosCache & parPos() { return pars_; }
132 ParPosCache const & getParPos() const { return pars_; }
134 SliceCache & slice(bool boundary)
136 return boundary ? slices1_ : slices0_;
138 SliceCache const & getSlice(bool boundary) const
140 return boundary ? slices1_ : slices0_;
145 CoordCacheBase<MathArray> arrays_;
147 CoordCacheBase<InsetBase> insets_;
148 /// Paragraph grouped by owning text
150 /// Used with boundary == 0
152 /// Used with boundary == 1