2005-04-26 10:30:24 +00:00
|
|
|
|
// -*- C++ -*-
|
2007-04-26 04:41:58 +00:00
|
|
|
|
/* \file CoordCache.h
|
2005-04-26 10:30:24 +00:00
|
|
|
|
* 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
|
|
|
|
|
|
2006-10-14 12:39:18 +00:00
|
|
|
|
// It seems that MacOSX define the check macro.
|
|
|
|
|
#undef check
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "support/types.h"
|
2004-08-14 14:04:37 +00:00
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
2006-10-15 22:32:56 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
class Inset;
|
2007-04-29 23:33:02 +00:00
|
|
|
|
class Text;
|
2007-04-26 16:06:39 +00:00
|
|
|
|
class MathData;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
class Paragraph;
|
|
|
|
|
|
2004-08-14 14:04:37 +00:00
|
|
|
|
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
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
Point(int x, int y);
|
2004-08-14 14:04:37 +00:00
|
|
|
|
|
|
|
|
|
int x_, y_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <class T> class CoordCacheBase {
|
|
|
|
|
public:
|
|
|
|
|
void clear()
|
|
|
|
|
{
|
|
|
|
|
data_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-16 10:36:57 +00:00
|
|
|
|
bool empty() const
|
2006-10-21 09:45:11 +00:00
|
|
|
|
{
|
|
|
|
|
return data_.empty();
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-14 14:04:37 +00:00
|
|
|
|
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_;
|
2006-10-21 10:56:36 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
cache_type const & getData() const { return 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
|
2006-10-20 20:57:21 +00:00
|
|
|
|
* updates. (x,y) == (0,0) is the upper left screen corner, x increases
|
2005-01-31 16:29:48 +00:00
|
|
|
|
* to the right, y increases downwords.
|
2006-10-20 19:40:02 +00:00
|
|
|
|
* The cache is built in BufferView::updateMetrics which is called
|
Move BufferView cached pointer out of LyXText:
* LyXText
- bv(), bv_owner, : deleted.
- These methods now need a (Buffer const &) argument: getFont(), applyOuterFont(), getLayoutFont(), getLabelFont(), setCharFont(), setLayout(), singleWidth(), leftMargin(), rightMargin(), computeRowMetrics(), isMainText(), spacing(), isRTL(), cursorX(), rowBreakPoint(), setRowWidth(), labelFill(), labelEnd().
- These methods now need a (BufferView const &) argument and are propably candidates for future removal when 1.6 is opened for development: redoParagraph(), x2pos(), getRowNearY(), getColumnNearX(), checkInsetHit(), setHeightOfRow().
- recUndo(): now need a LCursor argument.
* CoordCache::get(LyXText const *, pit_type):
- now const.
- use const_iterator instead of iterator.
* FontIterator:
- add (Buffer const &) argument to ctor
- buffer_: new const reference to applicable BufferView.
* InsetBase
- xo(), yo(), covers() and neverIndent() are now const.
* InsetText::setViewCache(): deleted
All other changes are due to the LyXText and InsetBase API changes.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15618 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-30 12:45:33 +00:00
|
|
|
|
* from BufferView::update. The individual points are added
|
2005-01-31 16:29:48 +00:00
|
|
|
|
* while we paint them. See for instance paintPar in RowPainter.C.
|
|
|
|
|
*/
|
2004-08-14 14:04:37 +00:00
|
|
|
|
class CoordCache {
|
|
|
|
|
public:
|
|
|
|
|
void clear();
|
|
|
|
|
|
2005-01-31 16:29:48 +00:00
|
|
|
|
/// A map from paragraph index number to screen point
|
2006-10-21 00:16:43 +00:00
|
|
|
|
typedef std::map<pit_type, Point> InnerParPosCache;
|
2005-07-18 12:13:32 +00:00
|
|
|
|
/// A map from a CursorSlice to screen points
|
2007-04-29 23:33:02 +00:00
|
|
|
|
typedef std::map<Text const *, InnerParPosCache> SliceCache;
|
2005-01-31 16:29:48 +00:00
|
|
|
|
|
2007-04-26 16:06:39 +00:00
|
|
|
|
/// A map from MathData to position on the screen
|
|
|
|
|
CoordCacheBase<MathData> & arrays() { return arrays_; }
|
|
|
|
|
CoordCacheBase<MathData> const & getArrays() const { return arrays_; }
|
2005-01-31 16:29:48 +00:00
|
|
|
|
/// A map from insets to positions on the screen
|
2007-04-29 13:39:47 +00:00
|
|
|
|
CoordCacheBase<Inset> & insets() { return insets_; }
|
|
|
|
|
CoordCacheBase<Inset> const & getInsets() const { return insets_; }
|
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
|
|
|
|
|
2006-10-20 20:57:21 +00:00
|
|
|
|
/// Dump the contents of the cache to lyxerr in debugging form
|
|
|
|
|
void dump() const;
|
2005-01-31 16:29:48 +00:00
|
|
|
|
private:
|
2007-04-26 16:06:39 +00:00
|
|
|
|
/// MathDatas
|
|
|
|
|
CoordCacheBase<MathData> arrays_;
|
2005-07-18 12:13:32 +00:00
|
|
|
|
// All insets
|
2007-04-29 13:39:47 +00:00
|
|
|
|
CoordCacheBase<Inset> insets_;
|
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
|
|
|
|
};
|
|
|
|
|
|
2006-10-15 22:32:56 +00:00
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2004-08-14 14:04:37 +00:00
|
|
|
|
#endif
|