On Mon, Nov 10, 2003 at 11:31:55AM +0100, Alfredo Braunstein wrote:
> Maybe:
> 
>                 while ((inset_hit = text->checkInsetHit(x, y))) {
> +                       if (!inset_hit->isHiglyEditable())
> +                               break;
>                         inset = inset_hit;
>                         text = inset_hit->getText(0);
>                         lyxerr << "Hit inset: " << inset << " at x: " << x
>                                 << " y: " << y << endl;
>                         theTempCursor.push(static_cast<UpdatableInset*>(inset));
>                 }

Something with that idea attached. It solves the particular problem and
seems to be a proper solutuion. And removes 30 lines...

Note that we now simply iterator over the insetlist and do not need the
row structure anymore.

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...)
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.454
diff -u -p -r1.454 BufferView_pimpl.C
--- BufferView_pimpl.C  10 Nov 2003 09:06:31 -0000      1.454
+++ BufferView_pimpl.C  10 Nov 2003 11:23:08 -0000
@@ -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;
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.171
diff -u -p -r1.171 text3.C
--- text3.C     10 Nov 2003 09:06:37 -0000      1.171
+++ text3.C     10 Nov 2003 11:23:08 -0000
@@ -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();
 }
Index: insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.138
diff -u -p -r1.138 inset.h
--- insets/inset.h      10 Nov 2003 09:55:30 -0000      1.138
+++ insets/inset.h      10 Nov 2003 11:23:08 -0000
@@ -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
Index: insets/insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.199
diff -u -p -r1.199 insetcollapsable.C
--- insets/insetcollapsable.C   10 Nov 2003 09:06:41 -0000      1.199
+++ insets/insetcollapsable.C   10 Nov 2003 11:23:08 -0000
@@ -146,6 +146,9 @@ void InsetCollapsable::draw(PainterInfo 
        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 
        if (!owner())
                x += scroll();
 
-       top_x = x;
-       top_baseline = y;
-
        if (inlined) {
                inset.draw(pi, x, y);
        } else {
@@ -203,8 +203,10 @@ DispatchResult InsetCollapsable::lfunMou
                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;
                }
 
Index: insets/insetcollapsable.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v
retrieving revision 1.144
diff -u -p -r1.144 insetcollapsable.h
--- insets/insetcollapsable.h   10 Nov 2003 09:06:41 -0000      1.144
+++ insets/insetcollapsable.h   10 Nov 2003 11:23:08 -0000
@@ -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);
        ///

Reply via email to