From a145b1fd8de819cddd8e0e024854662c38ae9978 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 10 Nov 2003 11:26:33 +0000 Subject: [PATCH] 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 --- src/BufferView_pimpl.C | 10 ++-- src/insets/inset.h | 2 + src/insets/insetcollapsable.C | 10 ++-- src/insets/insetcollapsable.h | 2 + src/text3.C | 97 ++++++++++------------------------- 5 files changed, 44 insertions(+), 77 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 34df16b03e..53b8cbce76 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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(inset)); } return inset; diff --git a/src/insets/inset.h b/src/insets/inset.h index a00d81402e..c4240756b6 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -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 diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 9194111ad7..cf91680156 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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; } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 66e10b093f..536e440d6f 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -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); /// diff --git a/src/text3.C b/src/text3.C index d2d9acce3f..870c3ff5c6 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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(); - - LyXCursor cur; - setCursorFromCoordinates(cur, x, y_tmp); + ParagraphList::iterator pit = ownerParagraphs().begin(); + ParagraphList::iterator end = ownerParagraphs().end(); - 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(); } -- 2.39.2