]> 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 12e871aa5c1256eb308afd99420ccd65d073b415..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>
@@ -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();
@@ -1576,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;
@@ -1827,4 +1831,69 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
+// 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