]> git.lyx.org Git - features.git/commitdiff
fix crash in table selection
authorAlfredo Braunstein <abraunst@lyx.org>
Mon, 21 Mar 2005 18:21:13 +0000 (18:21 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Mon, 21 Mar 2005 18:21:13 +0000 (18:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9735 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/ChangeLog
src/insets/insettabular.C
src/insets/insettabular.h

index c7f03ff94cdfc0c9247c09a2def4e8d7e0f95ad6..8596597a06388df53795e4653b3f1dd9cfab59cb 100644 (file)
@@ -1,3 +1,10 @@
+
+2005-03-21  Alfredo Braunstein  <abraunst@lyx.org>
+
+       * insettabular.[Ch]: rename setPos -> setCursorFromCoordinates and
+       make it *not* descend into insets (fix a crash). Move the part
+       needed from editXY to a new function getNearestCell
+
 2005-02-22  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * insetinclude.C (InsetInclude): when constructing from another
index 1a351fb2b348c7a8b3f3032ee516e76c8459069a..2ab039b1ccc2bef8cd2e30f0ef382a4725138564 100644 (file)
@@ -426,16 +426,6 @@ void InsetTabular::edit(LCursor & cur, bool left)
 }
 
 
-InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const
-{
-       //lyxerr << "InsetTabular::editXY: " << this << endl;
-       cur.selection() = false;
-       cur.push(const_cast<InsetTabular&>(*this));
-       return setPos(cur, x, y);
-       //int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(cur.idx());
-}
-
-
 void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
 {
        lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
@@ -450,7 +440,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
 
                if (cmd.button() == mouse_button::button1) {
                        cur.selection() = false;
-                       setPos(cur, cmd.x, cmd.y);
+                       setCursorFromCoordinates(cur, cmd.x, cmd.y);
                        cur.resetAnchor();
                        bvcur = cur;
                        break;
@@ -474,7 +464,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
                if (cmd.button() == mouse_button::button1) {
                        // only accept motions to places not deeper nested than the real anchor
                        if (bvcur.anchor_.hasPart(cur)) {
-                               setPos(cur, cmd.x, cmd.y);
+                               setCursorFromCoordinates(cur, cmd.x, cmd.y);
                                bvcur.setCursor(cur);
                                bvcur.selection() = true;
                        } else
@@ -1136,9 +1126,30 @@ int dist(InsetOld const & inset, int x, int y)
 } //namespace anon
 
 
-InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
+InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const
 {
-       lyxerr << "# InsetTabular::setPos()  x=" << x << " y=" << y << endl;
+       //lyxerr << "InsetTabular::editXY: " << this << endl;
+       cur.selection() = false;
+       cur.push(const_cast<InsetTabular&>(*this));
+       cur.idx() = getNearestCell(x, y);
+       resetPos(cur);
+       return cell(cur.idx())->text_.editXY(cur, x, y);
+       //int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(cur.idx());
+}
+
+
+void InsetTabular::setCursorFromCoordinates(LCursor & cur, int x, int y) const
+{
+       //lyxerr << "# InsetTabular::setCursorFromCoordinates()\n" << cur << endl;
+       cur.idx() = getNearestCell(x, y);
+       resetPos(cur);
+       return cell(cur.idx())->text_.setCursorFromCoordinates(cur, x, y);
+}
+
+
+InsetTabular::idx_type InsetTabular::getNearestCell(int x, int y) const
+{
+       lyxerr << "# InsetTabular::getNearestCell()  x=" << x << " y=" << y << endl;
        idx_type idx_min = 0;
        int dist_min = std::numeric_limits<int>::max();
        for (idx_type i = 0; i < nargs(); ++i) {
@@ -1150,10 +1161,7 @@ InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
                        }
                }
        }
-       cur.idx() = idx_min;
-       //lyxerr << "# InsetTabular::setPos()\n" << cur << endl;
-       resetPos(cur);
-       return cell(cur.idx())->text_.editXY(cur, x, y);
+       return idx_min;
 }
 
 
index b405518834088976ffe84c4281140c32efbf3eda..f3f8ad25ad948e814db7a81503c20b0acb05948d 100644 (file)
@@ -153,7 +153,7 @@ private:
        void drawCellLines(Painter &, int x, int y, row_type row,
                           idx_type cell) const;
        ///
-       InsetBase * setPos(LCursor & cur, int x, int y) const;
+       void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
 
        ///
        void moveNextCell(LCursor & cur);
@@ -183,6 +183,9 @@ private:
        /// are we operating on several cells?
        bool tablemode(LCursor & cur) const;
 
+       /// return the cell nearest to x, y
+       idx_type getNearestCell(int x, int y) const;
+       
        ///
        Buffer const * buffer_;
        ///