]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.cpp
Check path of Qt tools if qtchooser is detected
[lyx.git] / src / mathed / InsetMathGrid.cpp
index 00d9a6f20fbf2b2369a976d01edf49a00ef1b9a6..f2d88a2bdfc21fde7de083f496eb47d71aeed90b 100644 (file)
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
-#include "CutAndPaste.h"
-#include "FuncStatus.h"
 #include "Cursor.h"
+#include "CutAndPaste.h"
 #include "FuncRequest.h"
+#include "FuncStatus.h"
+#include "TexRow.h"
 
 #include "frontends/Clipboard.h"
 #include "frontends/Painter.h"
@@ -34,7 +35,6 @@
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
-
 #include "support/lassert.h"
 
 #include <sstream>
@@ -181,7 +181,7 @@ void InsetMathGrid::setDefaults()
 bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
 {
        if (str == "\\hline") {
-               FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
+               FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
                FuncStatus status;
                if (getStatus(cur, fr, status)) {
                        if (status.enabled()) {
@@ -486,7 +486,7 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
                colinfo_[col].offset_ =
                        colinfo_[col - 1].offset_ +
                        colinfo_[col - 1].width_ +
-                       colinfo_[col - 1].skip_ +
+                       displayColSpace(col - 1) +
                        colsep() +
                        colinfo_[col].lines_ * vlinesep();
        }
@@ -508,7 +508,7 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
                        int const nextoffset =
                                colinfo_[first].offset_ +
                                wid +
-                               colinfo_[last].skip_ +
+                               displayColSpace(last) +
                                colsep() +
                                colinfo_[last+1].lines_ * vlinesep();
                        int const dx = nextoffset - colinfo_[last+1].offset_;
@@ -741,7 +741,7 @@ void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
                colinfo_[col].offset_ =
                        colinfo_[col - 1].offset_ +
                        colinfo_[col - 1].width_ +
-                       colinfo_[col - 1].skip_ +
+                       displayColSpace(col - 1) +
                        1 ; //colsep() +
                        //colinfo_[col].lines_ * vlinesep();
        }
@@ -953,7 +953,7 @@ int InsetMathGrid::cellWidth(idx_type idx) const
                col_type c2 = c1 + ncellcols(idx);
                return colinfo_[c2].offset_
                        - colinfo_[c1].offset_
-                       - colinfo_[c2].skip_
+                       - displayColSpace(c2)
                        - colsep()
                        - colinfo_[c2].lines_ * vlinesep();
        }
@@ -1269,13 +1269,13 @@ void InsetMathGrid::write(WriteStream & os,
                for (col_type col = beg_col; col < end_col;) {
                        int nccols = 1;
                        idx_type const idx = index(row, col);
-                       TexRow::RowEntry entry = os.texrow().mathEntry(id(),idx);
-                       os.texrow().startMath(id(),idx);
+                       RowEntry entry = TexRow::mathEntry(id(),idx);
+                       os.texrow().start(entry);
                        if (col >= lastcol) {
                                ++col;
                                continue;
                        }
-                       os.pushRowEntry(entry);
+                       Changer dummy = os.changeRowEntry(entry);
                        if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
                                size_t s = col + 1;
                                while (s < ncols() &&
@@ -1293,7 +1293,6 @@ void InsetMathGrid::write(WriteStream & os,
                                os << '}';
                        os << eocString(col + nccols - 1, lastcol);
                        col += nccols;
-                       os.popRowEntry();
                }
                eol = eolString(row, os.fragile(), os.latex(), last_eoln);
                os << eol;
@@ -1378,6 +1377,11 @@ char InsetMathGrid::displayColAlign(idx_type idx) const
 }
 
 
+int InsetMathGrid::displayColSpace(col_type col) const
+{
+       return colinfo_[col].skip_;
+}
+
 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
@@ -1411,7 +1415,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_CELL_BACKWARD:
                // See below.
-               cur.setSelection(false);
+               cur.selection(false);
                if (!idxPrev(cur)) {
                        cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
                        cur.undispatched();
@@ -1421,7 +1425,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CELL_FORWARD:
                // Can't handle selection by additional 'shift' as this is
                // hard bound to LFUN_CELL_BACKWARD
-               cur.setSelection(false);
+               cur.selection(false);
                if (!idxNext(cur)) {
                        cmd = FuncRequest(LFUN_FINISHED_FORWARD);
                        cur.undispatched();
@@ -1450,17 +1454,12 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_INSET_MODIFY: {
+       case LFUN_TABULAR_FEATURE: {
                cur.recordUndoInset();
                //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
                istringstream is(to_utf8(cmd.argument()));
                string s;
                is >> s;
-               if (s != "tabular") {
-                       InsetMathNest::doDispatch(cur, cmd);
-                       return;
-               }
-               is >> s;
                if (s == "valign-top")
                        setVerticalAlignment('t');
                else if (s == "valign-middle")
@@ -1581,7 +1580,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                cap::replaceSelection(cur);
                docstring topaste;
                if (cmd.argument().empty() && !theClipboard().isInternal())
-                       topaste = theClipboard().getAsText(Clipboard::PlainTextType);
+                       topaste = theClipboard().getAsText(frontend::Clipboard::PlainTextType);
                else {
                        idocstringstream is(cmd.argument());
                        int n = 0;
@@ -1597,7 +1596,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        }
 
                bool hline_enabled = false;
-               FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
+               FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
                FuncStatus status;
                if (getStatus(cur, fr, status))
                        hline_enabled = status.enabled();
@@ -1727,14 +1726,8 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & status) const
 {
        switch (cmd.action()) {
-       case LFUN_INSET_MODIFY: {
-               istringstream is(to_utf8(cmd.argument()));
-               string s;
-               is >> s;
-               if (s != "tabular") {
-                       // We only now about table actions here.
-                       break;
-               }
+       case LFUN_TABULAR_FEATURE: {
+               string s = cmd.getArg(0);
                if (&cur.inset() != this) {
                        // Table actions requires that the cursor is _inside_ the
                        // table.
@@ -1742,7 +1735,6 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.message(from_utf8(N_("Cursor not in table")));
                        return true;
                }
-               is >> s;
                if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
                        status.setEnabled(false);
                        status.message(from_utf8(N_("Only one row")));
@@ -1797,7 +1789,8 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                } else {
                        status.setEnabled(false);
                        status.message(bformat(
-                               from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
+                           from_utf8(N_("Unknown tabular feature '%1$s'")),
+                           from_utf8(s)));
                }
 
 #if 0
@@ -1838,29 +1831,69 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-// static\r
-char InsetMathGrid::colAlign(HullType type, col_type col)\r
-{\r
-       switch (type) {\r
-       case hullEqnArray:\r
-               return "rcl"[col % 3];\r
-\r
-       case hullMultline:\r
-       case hullGather:\r
-               return 'c';\r
-\r
-       case hullAlign:\r
-       case hullAlignAt:\r
-       case hullXAlignAt:\r
-       case hullXXAlignAt:\r
-       case hullFlAlign:\r
-               return "rl"[col & 1];\r
-\r
-       default:\r
-               return 'c';\r
-       }\r
-}\r
-\r
-\r
-\r
+// static
+char InsetMathGrid::colAlign(HullType type, col_type col)
+{
+       switch (type) {
+       case hullEqnArray:
+               return "rcl"[col % 3];
+
+       case hullMultline:
+       case hullGather:
+               return 'c';
+
+       case hullAlign:
+       case hullAlignAt:
+       case hullXAlignAt:
+       case hullXXAlignAt:
+       case hullFlAlign:
+               return "rl"[col & 1];
+
+       case hullUnknown:
+       case hullNone:
+       case hullSimple:
+       case hullEquation:
+       case hullRegexp:
+               return 'c';
+       }
+       // avoid warning
+       return 'c';
+}
+
+
+//static
+int InsetMathGrid::colSpace(HullType type, col_type col)
+{
+       int alignInterSpace = 0;
+       switch (type) {
+       case hullUnknown:
+       case hullNone:
+       case hullSimple:
+       case hullEquation:
+       case hullMultline:
+       case hullGather:
+       case hullRegexp:
+               return 0;
+
+       case hullEqnArray:
+               return 5;
+
+       case hullAlign:
+               alignInterSpace = 20;
+               break;
+       case hullAlignAt:
+               alignInterSpace = 0;
+               break;
+       case hullXAlignAt:
+               alignInterSpace = 40;
+               break;
+       case hullXXAlignAt:
+       case hullFlAlign:
+               alignInterSpace = 60;
+               break;
+       }
+       return (col % 2) ? alignInterSpace : 0;
+}
+
+
 } // namespace lyx