2005-04-26 10:30:24 +00:00
|
|
|
|
// -*- C++ -*-
|
|
|
|
|
/* \file coordcache.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-08-14 14:04:37 +00:00
|
|
|
|
#ifndef COORDCACHE_H
|
|
|
|
|
#define COORDCACHE_H
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
class InsetBase;
|
|
|
|
|
class LyXText;
|
|
|
|
|
class MathArray;
|
|
|
|
|
class Paragraph;
|
|
|
|
|
|
|
|
|
|
#include "support/types.h"
|
2004-08-14 14:04:37 +00:00
|
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
void lyxbreaker(void const * data, const char * hint, int size);
|
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
|
class Point {
|
|
|
|
|
public:
|
2004-08-14 14:04:37 +00:00
|
|
|
|
Point()
|
|
|
|
|
: x_(0), y_(0)
|
2004-10-05 10:11:42 +00:00
|
|
|
|
{}
|
2004-08-14 14:04:37 +00:00
|
|
|
|
|
2005-07-17 12:28:02 +00:00
|
|
|
|
Point(int x, int y)
|
|
|
|
|
: x_(x), y_(y)
|
2004-08-14 14:04:37 +00:00
|
|
|
|
{
|
2005-07-17 12:28:02 +00:00
|
|
|
|
BOOST_ASSERT(x > -1000000);
|
|
|
|
|
BOOST_ASSERT(x < 1000000);
|
|
|
|
|
BOOST_ASSERT(y > -1000000);
|
|
|
|
|
BOOST_ASSERT(y < 1000000);
|
2004-10-05 10:11:42 +00:00
|
|
|
|
}
|
2004-08-14 14:04:37 +00:00
|
|
|
|
|
|
|
|
|
int x_, y_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <class T> class CoordCacheBase {
|
|
|
|
|
public:
|
|
|
|
|
void clear()
|
|
|
|
|
{
|
|
|
|
|
data_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void add(T const * thing, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
data_[thing] = Point(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int x(T const * thing) const
|
|
|
|
|
{
|
|
|
|
|
check(thing, "x");
|
|
|
|
|
return data_.find(thing)->second.x_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y(T const * thing) const
|
|
|
|
|
{
|
|
|
|
|
check(thing, "y");
|
|
|
|
|
return data_.find(thing)->second.y_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Point xy(T const * thing) const
|
|
|
|
|
{
|
|
|
|
|
check(thing, "xy");
|
|
|
|
|
return data_.find(thing)->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool has(T const * thing) const
|
|
|
|
|
{
|
|
|
|
|
return data_.find(thing) != data_.end();
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-14 21:56:40 +00:00
|
|
|
|
// T * find(int x, int y) const
|
|
|
|
|
// {
|
2004-10-05 10:11:42 +00:00
|
|
|
|
// T *
|
2004-08-14 21:56:40 +00:00
|
|
|
|
// cache_type iter
|
2004-10-05 10:11:42 +00:00
|
|
|
|
// }
|
2004-08-14 21:56:40 +00:00
|
|
|
|
|
2004-08-14 14:04:37 +00:00
|
|
|
|
private:
|
|
|
|
|
friend class CoordCache;
|
|
|
|
|
|
|
|
|
|
void check(T const * thing, char const * hint) const
|
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (!has(thing))
|
2004-08-14 14:04:37 +00:00
|
|
|
|
lyxbreaker(thing, hint, data_.size());
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-14 21:56:40 +00:00
|
|
|
|
typedef std::map<T const *, Point> cache_type;
|
|
|
|
|
cache_type data_;
|
2004-08-14 14:04:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
* updated. (x,y) == (0,0) is the upper left screen corner, x increases
|
|
|
|
|
* to the right, y increases downwords.
|
|
|
|
|
* The cache is built in BufferView::Pimpl::metrics which is called
|
|
|
|
|
* from BufferView::Pimpl::update. The individual points are added
|
|
|
|
|
* while we paint them. See for instance paintPar in RowPainter.C.
|
|
|
|
|
*/
|
2004-08-14 14:04:37 +00:00
|
|
|
|
class CoordCache {
|
|
|
|
|
public:
|
|
|
|
|
void clear();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Point get(LyXText const *, lyx::pit_type);
|
2004-08-14 14:04:37 +00:00
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
/// A map from paragraph index number to screen point
|
|
|
|
|
typedef std::map<lyx::pit_type, Point> InnerParPosCache;
|
|
|
|
|
/// A map from a LyXText to the map of paragraphs to screen points
|
|
|
|
|
typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
|
2005-07-18 12:13:32 +00:00
|
|
|
|
/// A map from a CursorSlice to screen points
|
|
|
|
|
typedef std::map<LyXText const *, InnerParPosCache> SliceCache;
|
2005-01-31 16:29:48 +00:00
|
|
|
|
|
|
|
|
|
/// A map from MathArray to position on the screen
|
2006-07-08 20:40:04 +00:00
|
|
|
|
CoordCacheBase<MathArray> & arrays() { return arrays_; }
|
2005-01-31 16:29:48 +00:00
|
|
|
|
CoordCacheBase<MathArray> const & getArrays() const { return arrays_; }
|
|
|
|
|
/// A map from insets to positions on the screen
|
2006-07-08 20:40:04 +00:00
|
|
|
|
CoordCacheBase<InsetBase> & insets() { return insets_; }
|
2005-01-31 16:29:48 +00:00
|
|
|
|
CoordCacheBase<InsetBase> const & getInsets() const { return insets_; }
|
|
|
|
|
/// A map from (LyXText, paragraph) pair to screen positions
|
2006-07-08 20:40:04 +00:00
|
|
|
|
ParPosCache & parPos() { return pars_; }
|
2005-01-31 16:29:48 +00:00
|
|
|
|
ParPosCache const & getParPos() const { return pars_; }
|
2005-07-18 12:13:32 +00:00
|
|
|
|
///
|
|
|
|
|
SliceCache & slice(bool boundary)
|
|
|
|
|
{
|
|
|
|
|
return boundary ? slices1_ : slices0_;
|
|
|
|
|
}
|
|
|
|
|
SliceCache const & getSlice(bool boundary) const
|
|
|
|
|
{
|
|
|
|
|
return boundary ? slices1_ : slices0_;
|
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
private:
|
2005-07-18 12:13:32 +00:00
|
|
|
|
/// MathArrays
|
2004-08-14 14:04:37 +00:00
|
|
|
|
CoordCacheBase<MathArray> arrays_;
|
2005-07-18 12:13:32 +00:00
|
|
|
|
// All insets
|
2004-08-14 14:04:37 +00:00
|
|
|
|
CoordCacheBase<InsetBase> insets_;
|
2005-07-18 12:13:32 +00:00
|
|
|
|
/// Paragraph grouped by owning text
|
2004-11-30 01:59:49 +00:00
|
|
|
|
ParPosCache pars_;
|
2005-07-18 12:13:32 +00:00
|
|
|
|
/// Used with boundary == 0
|
|
|
|
|
SliceCache slices0_;
|
|
|
|
|
/// Used with boundary == 1
|
|
|
|
|
SliceCache slices1_;
|
2004-08-14 14:04:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|