]> git.lyx.org Git - features.git/commitdiff
fix crash in mathhullinset
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 23 Nov 2004 14:43:37 +0000 (14:43 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 23 Nov 2004 14:43:37 +0000 (14:43 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9294 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h

index 4c6fa00bd1e4e9f373da93ba421c3ba49fe0449a..c640f2015fd3d4ddfdc94083bcf1ee831575a071 100644 (file)
@@ -1,3 +1,12 @@
+2004-11-22  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * math_hullinset.[Ch] (rowChangeOK): new
+       * math_hullinset.C (addRow, delRow): check wether rows can be changed
+       * math_hullinset.C (addCol, delCol): remove lyxerr warning since we
+       should never come here if colChangeOK() is false
+       * math_hullinset.C (delCol): don't delete if this is the only column
+       * math_hullinset.C (getStatus): fix LFUN_TABULAR_FEATURE
+
 2004-11-16  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * math_inset.h: include math_data.h to satisfy concept checks.
index 52c446dbf0fd758e0b270cf44012a99aff7734ff..94674cdb14027dd0fe55cc72389cf193f2887921 100644 (file)
@@ -534,6 +534,16 @@ void MathHullInset::footer_write(WriteStream & os) const
 }
 
 
+bool MathHullInset::rowChangeOK() const
+{
+       return
+               type_ == "eqnarray" || type_ == "align" ||
+               type_ == "flalign" || type_ == "alignat" ||
+               type_ == "xalignat" || type_ == "xxalignat" ||
+               type_ == "gather" || type_ == "multline";
+}
+
+
 bool MathHullInset::colChangeOK() const
 {
        return
@@ -544,6 +554,8 @@ bool MathHullInset::colChangeOK() const
 
 void MathHullInset::addRow(row_type row)
 {
+       if (!rowChangeOK())
+               return;
        nonum_.insert(nonum_.begin() + row + 1, !numberedType());
        label_.insert(label_.begin() + row + 1, string());
        MathGridInset::addRow(row);
@@ -552,7 +564,7 @@ void MathHullInset::addRow(row_type row)
 
 void MathHullInset::swapRow(row_type row)
 {
-       if (nrows() == 1)
+       if (nrows() <= 1)
                return;
        if (row + 1 == nrows())
                --row;
@@ -564,7 +576,7 @@ void MathHullInset::swapRow(row_type row)
 
 void MathHullInset::delRow(row_type row)
 {
-       if (nrows() <= 1)
+       if (nrows() <= 1 || !rowChangeOK())
                return;
        MathGridInset::delRow(row);
        nonum_.erase(nonum_.begin() + row);
@@ -574,19 +586,17 @@ void MathHullInset::delRow(row_type row)
 
 void MathHullInset::addCol(col_type col)
 {
-       if (colChangeOK())
-               MathGridInset::addCol(col);
-       else
-               lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
+       if (!colChangeOK())
+               return;
+       MathGridInset::addCol(col);
 }
 
 
 void MathHullInset::delCol(col_type col)
 {
-       if (colChangeOK())
-               MathGridInset::delCol(col);
-       else
-               lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
+       if (ncols() <= 1 || !colChangeOK())
+               return;
+       MathGridInset::delCol(col);
 }
 
 
@@ -1084,24 +1094,24 @@ bool MathHullInset::getStatus(LCursor & cur, FuncRequest const & cmd,
                // we handle these
                return true;
        case LFUN_TABULAR_FEATURE: {
-               // should be more precise
                istringstream is(cmd.argument);
                string s;
                is >> s;
-               if ((type_ == "simple" || type_ == "equation")
-                   && (s == "append-column"
-                       || s == "delete-column"
-                       || s == "swap-column"
-                       || s == "copy-column"
-                       || s == "delete-column"
-                       || s == "append-row"
+               if (!rowChangeOK()
+                   && (s == "append-row"
                        || s == "delete-row"
-                       || s == "swap-row"
                        || s == "copy-row"))
                        return false;
-               if ((type_ == "eqnarray")
+               if (nrows() <= 1
+                   && (s == "delete-row" || s == "swap-row"))
+                       return false;
+               if (!colChangeOK()
                    && (s == "append-column"
-                       || s == "delete-column"))
+                       || s == "delete-column"
+                       || s == "copy-column"))
+                       return false;
+               if (ncols() <= 1
+                   && (s == "delete-column" || s == "swap-column"))
                        return false;
                return MathGridInset::getStatus(cur, cmd, flag);
        }
index fad9534409ad84e5e6a80be21f27b52ebc2ad7e6..4d50f5e9a60a7fe343115944ddf7c5049d64aea1 100644 (file)
@@ -69,7 +69,7 @@ public:
        void addRow(row_type row);
        /// delete a row
        void delRow(row_type row);
-       ///
+       /// swap two rows
        void swapRow(row_type row);
        /// add a column
        void addCol(col_type col);
@@ -165,6 +165,8 @@ private:
        char const * standardFont() const;
        /// consistency check
        void check() const;
+       /// can this change its number of rows?
+       bool rowChangeOK() const;
        /// can this change its number of cols?
        bool colChangeOK() const;