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 "support/types.h"
28 void lyxbreaker(void const * data, const char * hint, int size);
41 template <class T> class CoordCacheBase {
48 void add(T const * thing, int x, int y)
50 data_[thing] = Point(x, y);
53 int x(T const * thing) const
56 return data_.find(thing)->second.x_;
59 int y(T const * thing) const
62 return data_.find(thing)->second.y_;
65 Point xy(T const * thing) const
68 return data_.find(thing)->second;
71 bool has(T const * thing) const
73 return data_.find(thing) != data_.end();
76 // T * find(int x, int y) const
83 friend class CoordCache;
85 void check(T const * thing, char const * hint) const
88 lyxbreaker(thing, hint, data_.size());
91 typedef std::map<T const *, Point> cache_type;
96 * A global cache that allows us to come from a paragraph in a document
97 * to a position point on the screen.
98 * All points cached in this cache are only valid between subsequent
99 * updates. (x,y) == (0,0) is the upper left screen corner, x increases
100 * to the right, y increases downwords.
101 * The cache is built in BufferView::updateMetrics which is called
102 * from BufferView::Pimpl::update. The individual points are added
103 * while we paint them. See for instance paintPar in RowPainter.C.
108 Point get(LyXText const *, pit_type);
110 /// A map from paragraph index number to screen point
111 typedef std::map<pit_type, Point> InnerParPosCache;
112 /// A map from a LyXText to the map of paragraphs to screen points
113 typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
114 /// A map from a CursorSlice to screen points
115 typedef std::map<LyXText const *, InnerParPosCache> SliceCache;
117 /// A map from MathArray to position on the screen
118 CoordCacheBase<MathArray> & arrays() { return arrays_; }
119 CoordCacheBase<MathArray> const & getArrays() const { return arrays_; }
120 /// A map from insets to positions on the screen
121 CoordCacheBase<InsetBase> & insets() { return insets_; }
122 CoordCacheBase<InsetBase> const & getInsets() const { return insets_; }
123 /// A map from (LyXText, paragraph) pair to screen positions
124 ParPosCache & parPos() { return pars_; }
125 ParPosCache const & getParPos() const { return pars_; }
127 SliceCache & slice(bool boundary)
129 return boundary ? slices1_ : slices0_;
131 SliceCache const & getSlice(bool boundary) const
133 return boundary ? slices1_ : slices0_;
136 /// Dump the contents of the cache to lyxerr in debugging form
140 CoordCacheBase<MathArray> arrays_;
142 CoordCacheBase<InsetBase> insets_;
143 /// Paragraph grouped by owning text
145 /// Used with boundary == 0
147 /// Used with boundary == 1