commit 0b733507da7571759d8eb32ebbdd80f264690a89
Author: Guillaume Munch <[email protected]>
Date:   Sun Dec 13 03:32:32 2015 +0000

    Display the correct horizontal alignment in AMS environments
    
    A longstanding problem... (related: #1861)
    
    The columns in AMS math environments have a fixed alignment (colAlign() in
    InsetMathGrid.cpp). We set this alignment for display (Georg's
    displayColAlign()) in InsetMathHull and InsetMathSplit. This is done 
according
    to tests and documentation for the various environments.
    
    There is also some mechanical code factoring via colAlign().
    
    Finally, I disable setting the horizontal alignment in InsetMathSplit, 
which has
    no impact on the LaTeX output, and has no longer any impact on the screen. 
(As
    for vertical alignment I discovered that it was in fact customisable for
    \aligned & friends! I hope that the more faithful interface will let other
    users discover that too.)

diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 536f4bd..00d9a6f 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -1838,4 +1838,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 bd3066d..6199b7d 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 097a344..cce029f 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -349,28 +349,34 @@ bool InsetMathHull::idxLast(Cursor & cur) const
 }
 
 
+//FIXME: This has probably no effect and can be removed.
 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);
 }
@@ -1241,6 +1247,27 @@ void InsetMathHull::setType(HullType type)
 }
 
 
+bool InsetMathHull::isMutable(HullType type)
+{
+       switch (type) {
+       case hullNone:
+       case hullSimple:
+       case hullEquation:
+       case hullEqnArray:
+       case hullAlign:
+       case hullFlAlign:
+       case hullAlignAt:
+       case hullXAlignAt:
+       case hullXXAlignAt:
+       case hullMultline:
+       case hullGather:
+               return true;
+       default:
+               return false;
+       }
+}
+
+
 void InsetMathHull::mutate(HullType newtype)
 {
        //lyxerr << "mutating from '" << type_ << "' to '" << newtype << "'" << 
endl;
diff --git a/src/mathed/InsetMathSplit.cpp b/src/mathed/InsetMathSplit.cpp
index 5c425fb..f85e664 100644
--- a/src/mathed/InsetMathSplit.cpp
+++ b/src/mathed/InsetMathSplit.cpp
@@ -48,20 +48,41 @@ Inset * InsetMathSplit::clone() const
 }
 
 
+//FIXME: This has probably no effect and can be removed.
 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);
@@ -86,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 b0ff437..6136b6f 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:

Reply via email to