Author: vfr
Date: Sat Mar 19 18:54:21 2011
New Revision: 37968
URL: http://www.lyx.org/trac/changeset/37968
Log:
Fix bug #7261: Assertion when moving up
There are two possibilities to add an Inset to the CoordCache:
- 1), use CoordCache::add(Inset * p, int x, int y),
- 2), use CoordCache::add(Inset * p, Dimension dim).
In the latter case, the x and y are happily initialized as 0.
Also, when one call CoordCache::has(Inset * p), it will happily
return true because the cache knows something about this inset.
In #7261, LyX asked for the (x,y) position of an Inset and
received (0,0) as an answer, although that is not the position
of the Inset.
By adding some defaults for x,y in case of initializing with
dim only will give an extra check whether the cache really
"has" the position object.
In the long run, we might want to split the cache for
dimensions and positions.
Modified:
lyx-devel/trunk/src/CoordCache.h
Modified: lyx-devel/trunk/src/CoordCache.h
==============================================================================
--- lyx-devel/trunk/src/CoordCache.h Sat Mar 19 18:52:00 2011 (r37967)
+++ lyx-devel/trunk/src/CoordCache.h Sat Mar 19 18:54:21 2011 (r37968)
@@ -81,6 +81,8 @@
void add(T const * thing, Dimension const & dim)
{
+ if (!has(thing))
+ data_[thing].pos = Point(-10000, -10000);
data_[thing].dim = dim;
}
@@ -92,7 +94,7 @@
Dimension const & dim(T const * thing) const
{
- check(thing, "dim");
+ checkDim(thing, "dim");
return data_.find(thing)->second.dim;
}
@@ -116,6 +118,15 @@
bool has(T const * thing) const
{
+ typename cache_type::const_iterator it = data_.find(thing);
+
+ if (it == data_.end())
+ return false;
+ return it->second.pos.x_ != -10000;
+ }
+
+ bool hasDim(T const * thing) const
+ {
return data_.find(thing) != data_.end();
}
@@ -136,6 +147,12 @@
private:
friend class CoordCache;
+ void checkDim(T const * thing, char const * hint) const
+ {
+ if (!hasDim(thing))
+ lyxbreaker(thing, hint, data_.size());
+ }
+
void check(T const * thing, char const * hint) const
{
if (!has(thing))