diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 12e871aa5c..2ee5ece9f4 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -1827,4 +1827,29 @@ 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]; + + default: + return 'c'; + } +} + + + } // namespace lyx diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index bd3066db0b..709f492b37 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -258,10 +258,11 @@ protected: virtual docstring eocString(col_type col, col_type lastcol) const; /// splits cells and shifts right part to the next cell void splitCell(Cursor & cur); - /// Column aligmment for display of cell \p idx. + /// Column alignment for display of cell \p idx. /// Must not be written to file! virtual char displayColAlign(idx_type idx) const; - + /// The value of a fixed col align for a certain hull type + static char colAlign(HullType type, col_type col); /// row info. /// rowinfo_[nrows()] is a dummy row used only for hlines. diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index a782751b10..9a5864f314 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -349,28 +349,38 @@ bool InsetMathHull::idxLast(Cursor & cur) const } +// FIXME: InsetMathGrid should be changed to let the real column alignment be +// given by a virtual method like displayColAlign, because the values produced +// by defaultColAlign can be invalidated by lfuns such as add-column. I suspect +// that for the moment the values produced by defaultColAlign are not used, +// notably because alignment is not implemented in the LyXHTML output. char InsetMathHull::defaultColAlign(col_type col) { - if (type_ == hullEqnArray) - return "rcl"[col]; - if (type_ == hullMultline) - return 'c'; - if (type_ == hullGather) - return 'c'; - if (type_ >= hullAlign) - return "rl"[col & 1]; - return 'c'; + return colAlign(type_, col); } char InsetMathHull::displayColAlign(idx_type idx) const { - if (type_ == hullMultline) { + switch (type_) { + case hullMultline: { row_type const r = row(idx); if (r == 0) return 'l'; if (r == nrows() - 1) return 'r'; + return 'c'; + } + case hullEqnArray: + case hullGather: + case hullAlign: + case hullAlignAt: + case hullXAlignAt: + case hullXXAlignAt: + case hullFlAlign: + return colAlign(type_, col(idx)); + default: + break; } return InsetMathGrid::displayColAlign(idx); } diff --git a/src/mathed/InsetMathSplit.cpp b/src/mathed/InsetMathSplit.cpp index 2adb84522b..5929e27303 100644 --- a/src/mathed/InsetMathSplit.cpp +++ b/src/mathed/InsetMathSplit.cpp @@ -48,20 +48,45 @@ Inset * InsetMathSplit::clone() const } +// FIXME: InsetMathGrid should be changed to let the real column alignment be +// given by a virtual method like displayColAlign, because the values produced +// by defaultColAlign can be invalidated by lfuns such as add-column. I suspect +// that for the moment the values produced by defaultColAlign are not used, +// notably because alignment is not implemented in the LyXHTML output. char InsetMathSplit::defaultColAlign(col_type col) { - if (name_ == "split") - return 'l'; if (name_ == "gathered") return 'c'; - if (name_ == "aligned" || name_ == "align") - return (col & 1) ? 'l' : 'r'; - if (name_ == "alignedat") - return (col & 1) ? 'l' : 'r'; + if (name_ == "lgathered") + return 'l'; + if (name_ == "rgathered") + return 'r'; + if (name_ == "split" + || name_ == "aligned" + || name_ == "align" + || name_ == "alignedat") + return colAlign(hullAlign, col); return 'l'; } +char InsetMathSplit::displayColAlign(idx_type idx) const +{ + if (name_ == "gathered") + return 'c'; + if (name_ == "lgathered") + return 'l'; + if (name_ == "rgathered") + return 'r'; + if (name_ == "split" + || name_ == "aligned" + || name_ == "align" + || name_ == "alignedat") + return colAlign(hullAlign, col(idx)); + return InsetMathGrid::displayColAlign(idx); +} + + void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const { InsetMathGrid::draw(pi, x, y); @@ -82,6 +107,10 @@ bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd, flag.setEnabled(false); return true; } + if (s == "align-left" || s == "align-center" || s == "align-right") { + flag.setEnabled(false); + return true; + } break; } default: diff --git a/src/mathed/InsetMathSplit.h b/src/mathed/InsetMathSplit.h index b0ff437f3d..1b2aa239e4 100644 --- a/src/mathed/InsetMathSplit.h +++ b/src/mathed/InsetMathSplit.h @@ -43,6 +43,8 @@ public: /// char defaultColAlign(col_type); /// + char displayColAlign(idx_type idx) const; + /// InsetCode lyxCode() const { return MATH_SPLIT_CODE; } private: