On Mon, Nov 10, 2003 at 11:10:23AM +0100, Alfredo Braunstein wrote:
> Alfredo Braunstein wrote:
>
> > The attached solves it, even if it doesn't seem the right solution.
>
> There is an architectural problem here: the Cursor doesn't know that the
> inset is collapsed and tries to go further down.
> Maybe checkInsetHit still needs to be recursive after all.
Couldn't it simply return 'nonEditable' or whatever suitable (maybe an
additional check returning 0 for collapsed insets) that makes
InsetOld * checkInset(LyXText & text,
LyXCursor const & cur, int & x, int & y)
{
lyx::pos_type const pos = cur.pos();
ParagraphList::iterator par = text.getPar(cur);
if (pos >= par->size() || !par->isInset(pos))
return 0;
InsetOld /*const*/ * inset = par->getInset(pos);
if (!isEditableInset(inset))
return 0;
// get inset dimensions
BOOST_ASSERT(par->getInset(pos));
LyXFont const & font = text.getFont(par, pos);
int const width = inset->width();
int const inset_x = font.isVisibleRightToLeft()
? (cur.x() - width) : cur.x();
Box b(
inset_x + inset->scroll(),
inset_x + width,
cur.y() - inset->ascent(),
cur.y() + inset->descent()
);
if (!b.contains(x, y)) {
lyxerr[Debug::GUI] << "Missed inset at x,y "
<< x << ',' << y
<< " box " << b << endl;
return 0;
}
text.setCursor(cur.par(), pos, true);
x -= b.x1;
// The origin of an inset is on the baseline
y -= text.cursor.y();
return inset;
}
return 0?
Btw: I just noticed that this does set the cursor... maybe it should be
split into a strictly 'informational' part (i.e. answer the question
whether the inset was hit) and the 'inset locking' part (set the cursor
to the place)
Andre'
--
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)