X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fcoordcache.h;h=dba9b89fd4d283a2a27c7c31e9ecf2dac1a4c379;hb=52eb91c94fb70d58dceef430659c8781de2eccda;hp=639563036db078a6b1fe53d264886927e28a371c;hpb=b4b6c8b0785e89735c5a565019b1c62be63387fa;p=lyx.git diff --git a/src/coordcache.h b/src/coordcache.h index 639563036d..dba9b89fd4 100644 --- a/src/coordcache.h +++ b/src/coordcache.h @@ -1,33 +1,43 @@ +// -*- C++ -*- +/* \file coordcache.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + #ifndef COORDCACHE_H #define COORDCACHE_H -#include "mathed/math_data.h" -#include "insets/insetbase.h" -#include "lyxtext.h" +// It seems that MacOSX define the check macro. +#undef check -#include +#include "support/types.h" #include +namespace lyx { + +class InsetBase; +class LyXText; +class MathArray; +class Paragraph; + void lyxbreaker(void const * data, const char * hint, int size); -struct Point { +class Point { +public: Point() : x_(0), y_(0) - {} + {} - Point(int x, int y) : x_(x), y_(y) - { - BOOST_ASSERT(x > -3000); - BOOST_ASSERT(x < 4000); - BOOST_ASSERT(y > -3000); - BOOST_ASSERT(y < 4000); - } + Point(int x, int y); int x_, y_; }; - template class CoordCacheBase { public: void clear() @@ -35,6 +45,11 @@ public: data_.clear(); } + bool const empty() const + { + return data_.empty(); + } + void add(T const * thing, int x, int y) { data_[thing] = Point(x, y); @@ -65,34 +80,82 @@ public: // T * find(int x, int y) const // { -// T * +// T * // cache_type iter -// } +// } private: friend class CoordCache; void check(T const * thing, char const * hint) const { - if (!has(thing)) { + if (!has(thing)) lyxbreaker(thing, hint, data_.size()); - BOOST_ASSERT(false); - } } typedef std::map cache_type; cache_type data_; -}; +public: + cache_type const & getData() const { return data_; } +}; +/** + * A global cache that allows us to come from a paragraph in a document + * to a position point on the screen. + * All points cached in this cache are only valid between subsequent + * updates. (x,y) == (0,0) is the upper left screen corner, x increases + * to the right, y increases downwords. + * The cache is built in BufferView::updateMetrics which is called + * from BufferView::update. The individual points are added + * while we paint them. See for instance paintPar in RowPainter.C. + */ class CoordCache { public: void clear(); + Point get(LyXText const *, pit_type) const; + + /// A map from paragraph index number to screen point + typedef std::map InnerParPosCache; + /// A map from a LyXText to the map of paragraphs to screen points + typedef std::map ParPosCache; + /// A map from a CursorSlice to screen points + typedef std::map SliceCache; + + /// A map from MathArray to position on the screen + CoordCacheBase & arrays() { return arrays_; } + CoordCacheBase const & getArrays() const { return arrays_; } + /// A map from insets to positions on the screen + CoordCacheBase & insets() { return insets_; } + CoordCacheBase const & getInsets() const { return insets_; } + /// A map from (LyXText, paragraph) pair to screen positions + ParPosCache & parPos() { return pars_; } + ParPosCache const & getParPos() const { return pars_; } + /// + SliceCache & slice(bool boundary) + { + return boundary ? slices1_ : slices0_; + } + SliceCache const & getSlice(bool boundary) const + { + return boundary ? slices1_ : slices0_; + } + /// Dump the contents of the cache to lyxerr in debugging form + void dump() const; +private: + /// MathArrays CoordCacheBase arrays_; + // All insets CoordCacheBase insets_; + /// Paragraph grouped by owning text + ParPosCache pars_; + /// Used with boundary == 0 + SliceCache slices0_; + /// Used with boundary == 1 + SliceCache slices1_; }; -extern CoordCache theCoords; +} // namespace lyx #endif