]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_gridinset.C
bug + spped fixes + small stuff
[lyx.git] / src / mathed / math_gridinset.C
index 77e3badbc6c3290e55e31d86ecb3aedfa21eed10..9ed68656e3c867d535b3bd29bc56b96eb758a5a4 100644 (file)
 #include "math_data.h"
 #include "math_mathmlstream.h"
 #include "math_streamstr.h"
+#include "BufferView.h"
+#include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
 #include "funcrequest.h"
 #include "LColor.h"
+
 #include "frontends/Painter.h"
+
 #include "support/std_sstream.h"
 
 #include "insets/mailinset.h"
@@ -751,9 +755,8 @@ int MathGridInset::cellYOffset(idx_type idx) const
 }
 
 
-bool MathGridInset::idxUpDown(BufferView & bv, bool up, int targetx) const
+bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
 {
-       CursorSlice & cur = cursorTip(bv);
        if (up) {
                if (cur.idx() < ncols())
                        return false;
@@ -763,15 +766,14 @@ bool MathGridInset::idxUpDown(BufferView & bv, bool up, int targetx) const
                        return false;
                cur.idx() += ncols();
        }
-       cur.pos() = cur.cell().x2pos(targetx - cur.cell().xo());
+       cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
        return true;
 }
 
 
-bool MathGridInset::idxLeft(BufferView & bv) const
+bool MathGridInset::idxLeft(LCursor & cur) const
 {
        // leave matrix if on the left hand edge
-       CursorSlice & cur = cursorTip(bv);
        if (cur.col() == 0)
                return false;
        --cur.idx();
@@ -780,10 +782,9 @@ bool MathGridInset::idxLeft(BufferView & bv) const
 }
 
 
-bool MathGridInset::idxRight(BufferView & bv) const
+bool MathGridInset::idxRight(LCursor & cur) const
 {
        // leave matrix if on the right hand edge
-       CursorSlice & cur = cursorTip(bv);
        if (cur.col() + 1 == ncols())
                return false;
        ++cur.idx();
@@ -792,9 +793,8 @@ bool MathGridInset::idxRight(BufferView & bv) const
 }
 
 
-bool MathGridInset::idxFirst(BufferView & bv) const
+bool MathGridInset::idxFirst(LCursor & cur) const
 {
-       CursorSlice & cur = cursorTip(bv);
        switch (v_align_) {
                case 't':
                        cur.idx() = 0;
@@ -810,9 +810,8 @@ bool MathGridInset::idxFirst(BufferView & bv) const
 }
 
 
-bool MathGridInset::idxLast(BufferView & bv) const
+bool MathGridInset::idxLast(LCursor & cur) const
 {
-       CursorSlice & cur = cursorTip(bv);
        switch (v_align_) {
                case 't':
                        cur.idx() = ncols() - 1;
@@ -828,9 +827,8 @@ bool MathGridInset::idxLast(BufferView & bv) const
 }
 
 
-bool MathGridInset::idxHome(BufferView & bv) const
+bool MathGridInset::idxHome(LCursor & cur) const
 {
-       CursorSlice & cur = cursorTip(bv);
        if (cur.pos() > 0) {
                cur.pos() = 0;
                return true;
@@ -849,9 +847,8 @@ bool MathGridInset::idxHome(BufferView & bv) const
 }
 
 
-bool MathGridInset::idxEnd(BufferView & bv) const
+bool MathGridInset::idxEnd(LCursor & cur) const
 {
-       CursorSlice & cur = cursorTip(bv);
        if (cur.pos() < cur.lastpos()) {
                cur.pos() = cur.lastpos();
                return true;
@@ -887,7 +884,7 @@ bool MathGridInset::idxDelete(idx_type & idx)
 
        // move cells if necessary
        for (idx_type i = index(row(idx), 0); i < idx; ++i)
-               std::swap(cell(i), cell(i + ncols()));
+               swap(cell(i), cell(i + ncols()));
 
        delRow(row(idx));
 
@@ -1033,9 +1030,8 @@ int MathGridInset::border() const
 }
 
 
-void MathGridInset::splitCell(BufferView & bv)
+void MathGridInset::splitCell(LCursor & cur)
 {
-       CursorSlice & cur = cursorTip(bv);
        if (cur.idx() + 1 == nargs())
                return;
        MathArray ar = cur.cell();
@@ -1048,9 +1044,9 @@ void MathGridInset::splitCell(BufferView & bv)
 
 
 DispatchResult
-MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
+MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       CursorSlice & cur = cursorTip(bv);
+       //lyxerr << "*** MathGridInset: request: " << cmd << endl;
        switch (cmd.action) {
 
                case LFUN_MOUSE_RELEASE:
@@ -1058,10 +1054,10 @@ MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        //      GridInsetMailer(*this).showDialog();
                        //      return DispatchResult(true, true);
                        //}
-                       return DispatchResult(false);
+                       return MathNestInset::priv_dispatch(cur, cmd);
 
                case LFUN_INSET_DIALOG_UPDATE:
-                       GridInsetMailer(*this).updateDialog(&bv);
+                       GridInsetMailer(*this).updateDialog(&cur.bv());
                        return DispatchResult(false);
 
                // insert file functions
@@ -1074,29 +1070,29 @@ MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
                        //}
                        if (nrows() > 1)
                                delRow(cur.row());
-                       if (cur.idx() >= nargs())
-                               cur.idx() = nargs() - 1;
+                       if (cur.idx() > cur.lastidx())
+                               cur.idx() = cur.lastidx();
                        if (cur.pos() > cur.lastpos())
                                cur.pos() = cur.lastpos();
                        return DispatchResult(true, FINISHED);
 
                case LFUN_CELL_SPLIT:
-                       //recordUndo(bv, Undo::ATOMIC);
-                       splitCell(bv);
+                       ////recordUndo(cur, Undo::ATOMIC);
+                       splitCell(cur);
                        return DispatchResult(true, FINISHED);
 
                case LFUN_BREAKLINE: {
-                       //recordUndo(bv, Undo::INSERT);
+                       ////recordUndo(cur, Undo::INSERT);
                        row_type const r = cur.row();
                        addRow(r);
 
                        // split line
                        for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
-                               std::swap(cell(index(r, c)), cell(index(r + 1, c)));
+                               swap(cell(index(r, c)), cell(index(r + 1, c)));
 
                        // split cell
-                       splitCell(bv);
-                       std::swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
+                       splitCell(cur);
+                       swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
                        if (cur.idx() > 0)
                                --cur.idx();
                        cur.idx() = cur.lastpos();
@@ -1196,6 +1192,6 @@ cur.row());
                }
 
                default:
-                       return MathNestInset::priv_dispatch(bv, cmd);
+                       return MathNestInset::priv_dispatch(cur, cmd);
        }
 }