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 bool const empty() const
53 void add(T const * thing, int x, int y)
55 data_[thing] = Point(x, y);
58 int x(T const * thing) const
61 return data_.find(thing)->second.x_;
64 int y(T const * thing) const
67 return data_.find(thing)->second.y_;
70 Point xy(T const * thing) const
73 return data_.find(thing)->second;
76 bool has(T const * thing) const
78 return data_.find(thing) != data_.end();
81 // T * find(int x, int y) const
88 friend class CoordCache;
90 void check(T const * thing, char const * hint) const
93 lyxbreaker(thing, hint, data_.size());
96 typedef std::map<T const *, Point> cache_type;
100 cache_type const & getData() const { return data_; }
104 * A global cache that allows us to come from a paragraph in a document
105 * to a position point on the screen.
106 * All points cached in this cache are only valid between subsequent
107 * updates. (x,y) == (0,0) is the upper left screen corner, x increases
108 * to the right, y increases downwords.
109 * The cache is built in BufferView::updateMetrics which is called
110 * from BufferView::update. The individual points are added
111 * while we paint them. See for instance paintPar in RowPainter.C.
116 Point get(LyXText const *, pit_type) const;
118 /// A map from paragraph index number to screen point
119 typedef std::map<pit_type, Point> InnerParPosCache;
120 /// A map from a LyXText to the map of paragraphs to screen points
121 typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
122 /// A map from a CursorSlice to screen points
123 typedef std::map<LyXText const *, InnerParPosCache> SliceCache;
125 /// A map from MathArray to position on the screen
126 CoordCacheBase<MathArray> & arrays() { return arrays_; }
127 CoordCacheBase<MathArray> const & getArrays() const { return arrays_; }
128 /// A map from insets to positions on the screen
129 CoordCacheBase<InsetBase> & insets() { return insets_; }
130 CoordCacheBase<InsetBase> const & getInsets() const { return insets_; }
131 /// A map from (LyXText, paragraph) pair to screen positions
132 ParPosCache & parPos() { return pars_; }
133 ParPosCache const & getParPos() const { return pars_; }
135 SliceCache & slice(bool boundary)
137 return boundary ? slices1_ : slices0_;
139 SliceCache const & getSlice(bool boundary) const
141 return boundary ? slices1_ : slices0_;
144 /// Dump the contents of the cache to lyxerr in debugging form
148 CoordCacheBase<MathArray> arrays_;
150 CoordCacheBase<InsetBase> insets_;
151 /// Paragraph grouped by owning text
153 /// Used with boundary == 0
155 /// Used with boundary == 1