fix 'click on first footnote in UserGuide' crash

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8068 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-11-10 11:26:33 +00:00
parent b719f4b39b
commit a145b1fd8d
5 changed files with 44 additions and 77 deletions

View File

@ -882,13 +882,17 @@ namespace {
{
LyXText * text = bv->text;
InsetOld * inset = 0;
InsetOld * inset_hit = 0;
theTempCursor = LCursor(bv);
while ((inset_hit = text->checkInsetHit(x, y))) {
while (true) {
InsetOld * inset_hit = text->checkInsetHit(x, y);
if (!inset_hit)
break;
inset = inset_hit;
if (!inset_hit->descendable())
break;
text = inset_hit->getText(0);
lyxerr << "Hit inset: " << inset << " at x: " << x
<< " y: " << y << endl;
<< " text: " << text << " y: " << y << endl;
theTempCursor.push(static_cast<UpdatableInset*>(inset));
}
return inset;

View File

@ -167,6 +167,8 @@ public:
virtual std::string const editMessage() const;
///
virtual EDITABLE editable() const;
/// can we go further down on mouse click?
virtual bool descendable() const { return false; }
///
virtual bool isTextInset() const { return false; }
/// return true if the inset should be removed automatically

View File

@ -146,6 +146,9 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
button_dim.y1 = -aa;
button_dim.y2 = -aa + dim_collapsed.height();
top_x = x;
top_baseline = y;
if (!isOpen()) {
draw_collapsed(pi, x, y);
return;
@ -156,9 +159,6 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
if (!owner())
x += scroll();
top_x = x;
top_baseline = y;
if (inlined) {
inset.draw(pi, x, y);
} else {
@ -203,8 +203,10 @@ DispatchResult InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd)
if (collapsed_) {
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
collapsed_ = false;
bv->updateInset(this);
edit(bv, true);
bv->buffer()->markDirty();
bv->updateInset(this);
bv->update();
return result;
}

View File

@ -52,6 +52,8 @@ public:
bool hitButton(FuncRequest const &) const;
///
EDITABLE editable() const;
/// can we go further down on mouse click?
bool descendable() const { return isOpen(); }
///
bool insertInset(BufferView *, InsetOld * inset);
///

View File

@ -239,55 +239,6 @@ namespace {
bv->owner()->view_state_changed();
}
// check if the given co-ordinates are inside an inset at the
// given cursor, if one exists. If so, the inset is returned,
// and the co-ordinates are made relative. Otherwise, 0 is returned.
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;
}
} // anon namespace
@ -307,28 +258,34 @@ string const freefont2string()
InsetOld * LyXText::checkInsetHit(int & x, int & y)
{
int y_tmp = y + bv_owner->top_y();
ParagraphList::iterator pit = ownerParagraphs().begin();
ParagraphList::iterator end = ownerParagraphs().end();
LyXCursor cur;
setCursorFromCoordinates(cur, x, y_tmp);
InsetOld * inset = checkInset(*this, cur, x, y_tmp);
if (inset) {
y = y_tmp;
return inset;
lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
for ( ; pit != end; ++pit) {
InsetList::iterator iit = pit->insetlist.begin();
InsetList::iterator iend = pit->insetlist.end();
for ( ; iit != iend; ++iit) {
InsetOld * inset = iit->inset;
lyxerr << "examining inset " << inset
<< " xy: " << inset->x() << "/" << inset->y()
<< " x: " << inset->x() << "..." << inset->x() + inset->width()
<< " y: " << inset->y() - inset->ascent() << "..."
<< inset->y() + inset->descent()
<< endl;
if (x >= inset->x()
&& x <= inset->x() + inset->width()
&& y >= inset->y() - inset->ascent()
&& y <= inset->y() + inset->descent())
{
lyxerr << "Hit inset: " << inset << endl;
y += bv()->top_y();
return inset;
}
}
}
// look at previous position
if (cur.pos() == 0)
return 0;
// move back one
setCursor(cur, cur.par(), cur.pos() - 1, true);
inset = checkInset(*this, cur, x, y_tmp);
if (inset)
y = y_tmp;
return inset;
lyxerr << "No inset hit. " << endl;
return 0;
}
@ -498,7 +455,7 @@ void LyXText::cursorNext()
nextRow(cpit, crit);
LyXCursor cur;
setCursor(cur, parOffset(cpit), crit->pos(), false);
if (cur.y() < bv_owner->top_y() + bv()->workHeight())
if (cur.y() < bv()->top_y() + bv()->workHeight())
cursorDown(true);
bv()->updateScrollbar();
}