]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.cpp
Change the interface to a paragraph's layout. We still store a LayoutPtr, but now...
[lyx.git] / src / mathed / InsetMathGrid.cpp
index 0da03a9df0f5e5fce66d8ba9022ce34e0062fd01..11f08ad9914d7a9987896dc892d78c6969625121 100644 (file)
 #include <config.h>
 
 #include "InsetMathGrid.h"
+
 #include "MathData.h"
 #include "MathParser.h"
 #include "MathStream.h"
+#include "MetricsInfo.h"
 
 #include "BufferView.h"
 #include "CutAndPaste.h"
 #include "FuncStatus.h"
 #include "Cursor.h"
-#include "debug.h"
 #include "FuncRequest.h"
-#include "gettext.h"
 
 #include "frontends/Clipboard.h"
 #include "frontends/Painter.h"
 
+#include "support/debug.h"
+#include "support/docstream.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 
 #include <sstream>
 
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::bformat;
-
-using std::endl;
-using std::max;
-using std::min;
-using std::swap;
-
-using std::string;
-using std::istream;
-using std::istringstream;
-using std::vector;
-
-
 namespace {
 
 docstring verboseHLine(int n)
@@ -83,7 +75,7 @@ InsetMathGrid::CellInfo::CellInfo()
 
 
 InsetMathGrid::RowInfo::RowInfo()
-       : lines_(0), skip_(0), allow_pagebreak_(true)
+       : lines_(0), skip_(0), allow_newpage_(true)
 {}
 
 
@@ -221,13 +213,11 @@ void InsetMathGrid::halign(docstring const & hh)
                        }
                        --it;
                        if (newcolumn) {
-                               colinfo_[col].lines_ = std::count(
+                               colinfo_[col].lines_ = count(
                                        colinfo_[col].special_.begin(),
                                        colinfo_[col].special_.end(), '|');
-                               LYXERR(Debug::MATHED)
-                                       << "special column separator: `"
-                                       << to_utf8(colinfo_[col].special_)
-                                       << '\'' << endl;
+                               LYXERR(Debug::MATHED, "special column separator: `"
+                                       << to_utf8(colinfo_[col].special_) << '\'');
                                ++col;
                                colinfo_[col].lines_ = 0;
                                colinfo_[col].special_.clear();
@@ -240,13 +230,11 @@ void InsetMathGrid::halign(docstring const & hh)
                        colinfo_[col].align_ = static_cast<char>(c);
                        if (!colinfo_[col].special_.empty()) {
                                colinfo_[col].special_ += c;
-                               colinfo_[col].lines_ = std::count(
+                               colinfo_[col].lines_ = count(
                                                colinfo_[col].special_.begin(),
                                                colinfo_[col].special_.end(), '|');
-                               LYXERR(Debug::MATHED)
-                                       << "special column separator: `"
-                                       << to_utf8(colinfo_[col].special_)
-                                       << '\'' << endl;
+                               LYXERR(Debug::MATHED, "special column separator: `"
+                                       << to_utf8(colinfo_[col].special_) << '\'');
                        }
                        ++col;
                        colinfo_[col].lines_ = 0;
@@ -509,7 +497,7 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
 {
-       drawWithMargin(pi, x, y, 0, 0);
+       drawWithMargin(pi, x, y, 1, 1);
 }
 
 
@@ -637,7 +625,7 @@ void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
 }
 
 
-void InsetMathGrid::drawT(TextPainter & pain, int x, int y) const
+void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
 {
 //     for (idx_type idx = 0; idx < nargs(); ++idx)
 //             cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
@@ -650,7 +638,7 @@ docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) c
 
        if (!rowinfo_[row].crskip_.zero())
                eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
-       else if(!rowinfo_[row].allow_pagebreak_)
+       else if(!rowinfo_[row].allow_newpage_)
                eol += '*';
 
        // make sure an upcoming '[' does not break anything
@@ -825,14 +813,14 @@ bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
                        return false;
                cur.idx() += ncols();
        }
-       cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo(cur.bv()));
+       cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
        return true;
 }
 
 
-bool InsetMathGrid::idxLeft(Cursor & cur) const
+bool InsetMathGrid::idxBackward(Cursor & cur) const
 {
-       // leave matrix if on the left hand edge
+       // leave matrix if at the front edge
        if (cur.col() == 0)
                return false;
        --cur.idx();
@@ -841,9 +829,9 @@ bool InsetMathGrid::idxLeft(Cursor & cur) const
 }
 
 
-bool InsetMathGrid::idxRight(Cursor & cur) const
+bool InsetMathGrid::idxForward(Cursor & cur) const
 {
-       // leave matrix if on the right hand edge
+       // leave matrix if at the back edge
        if (cur.col() + 1 == ncols())
                return false;
        ++cur.idx();
@@ -1118,7 +1106,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                break;
 
-       case LFUN_BREAK_LINE: {
+       case LFUN_NEW_LINE: {
                cur.recordUndoInset();
                row_type const r = cur.row();
                addRow(r);
@@ -1161,6 +1149,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        for (int i = 0, n = extractInt(is); i < n; ++i)
                                addRow(cur.row());
                else if (s == "delete-row") {
+                       cur.clearSelection(); // bug 4323
                        for (int i = 0, n = extractInt(is); i < n; ++i) {
                                delRow(cur.row());
                                if (cur.idx() >= nargs())
@@ -1195,10 +1184,11 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        row_type const r = cur.row();
                        col_type const c = cur.col();
                        for (int i = 0, n = extractInt(is); i < n; ++i)
-                               addCol(cur.col());
+                               addCol(cur.col() + 1);
                        cur.idx() = index(r, c);
                }
                else if (s == "delete-column") {
+                       cur.clearSelection(); // bug 4323
                        row_type const r = cur.row();
                        col_type const c = cur.col();
                        for (int i = 0, n = extractInt(is); i < n; ++i)
@@ -1263,7 +1253,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        idocstringstream is(cmd.argument());
                        int n = 0;
                        is >> n;
-                       topaste = cap::getSelection(cur.buffer(), n);
+                       topaste = cap::selection(n);
                }
                InsetMathGrid grid(1, 1);
                if (!topaste.empty())
@@ -1428,7 +1418,7 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.enable(false);
                        break;
                }
-               if (!support::contains("tcb", cmd.argument()[0])) {
+               if (!contains("tcb", cmd.argument()[0])) {
                        status.enable(false);
                        break;
                }