From b3d8f7ccc6de754b535ee262e81c93dc2e5861ac Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 23 Nov 2004 14:43:37 +0000 Subject: [PATCH] fix crash in mathhullinset git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9294 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 9 +++++++ src/mathed/math_hullinset.C | 52 ++++++++++++++++++++++--------------- src/mathed/math_hullinset.h | 4 ++- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 4c6fa00bd1..c640f2015f 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,12 @@ +2004-11-22 Georg Baum + + * 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 * math_inset.h: include math_data.h to satisfy concept checks. diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 52c446dbf0..94674cdb14 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -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); } diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index fad9534409..4d50f5e9a6 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -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; -- 2.39.2