fix crash in mathhullinset

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9294 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2004-11-23 14:43:37 +00:00
parent 6fb13068e3
commit b3d8f7ccc6
3 changed files with 43 additions and 22 deletions

View 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> 2004-11-16 Lars Gullik Bjonnes <larsbj@gullik.net>
* math_inset.h: include math_data.h to satisfy concept checks. * math_inset.h: include math_data.h to satisfy concept checks.

View 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 bool MathHullInset::colChangeOK() const
{ {
return return
@ -544,6 +554,8 @@ bool MathHullInset::colChangeOK() const
void MathHullInset::addRow(row_type row) void MathHullInset::addRow(row_type row)
{ {
if (!rowChangeOK())
return;
nonum_.insert(nonum_.begin() + row + 1, !numberedType()); nonum_.insert(nonum_.begin() + row + 1, !numberedType());
label_.insert(label_.begin() + row + 1, string()); label_.insert(label_.begin() + row + 1, string());
MathGridInset::addRow(row); MathGridInset::addRow(row);
@ -552,7 +564,7 @@ void MathHullInset::addRow(row_type row)
void MathHullInset::swapRow(row_type row) void MathHullInset::swapRow(row_type row)
{ {
if (nrows() == 1) if (nrows() <= 1)
return; return;
if (row + 1 == nrows()) if (row + 1 == nrows())
--row; --row;
@ -564,7 +576,7 @@ void MathHullInset::swapRow(row_type row)
void MathHullInset::delRow(row_type row) void MathHullInset::delRow(row_type row)
{ {
if (nrows() <= 1) if (nrows() <= 1 || !rowChangeOK())
return; return;
MathGridInset::delRow(row); MathGridInset::delRow(row);
nonum_.erase(nonum_.begin() + row); nonum_.erase(nonum_.begin() + row);
@ -574,19 +586,17 @@ void MathHullInset::delRow(row_type row)
void MathHullInset::addCol(col_type col) void MathHullInset::addCol(col_type col)
{ {
if (colChangeOK()) if (!colChangeOK())
MathGridInset::addCol(col); return;
else MathGridInset::addCol(col);
lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
} }
void MathHullInset::delCol(col_type col) void MathHullInset::delCol(col_type col)
{ {
if (colChangeOK()) if (ncols() <= 1 || !colChangeOK())
MathGridInset::delCol(col); return;
else MathGridInset::delCol(col);
lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
} }
@ -1084,24 +1094,24 @@ bool MathHullInset::getStatus(LCursor & cur, FuncRequest const & cmd,
// we handle these // we handle these
return true; return true;
case LFUN_TABULAR_FEATURE: { case LFUN_TABULAR_FEATURE: {
// should be more precise
istringstream is(cmd.argument); istringstream is(cmd.argument);
string s; string s;
is >> s; is >> s;
if ((type_ == "simple" || type_ == "equation") if (!rowChangeOK()
&& (s == "append-column" && (s == "append-row"
|| s == "delete-column"
|| s == "swap-column"
|| s == "copy-column"
|| s == "delete-column"
|| s == "append-row"
|| s == "delete-row" || s == "delete-row"
|| s == "swap-row"
|| s == "copy-row")) || s == "copy-row"))
return false; return false;
if ((type_ == "eqnarray") if (nrows() <= 1
&& (s == "delete-row" || s == "swap-row"))
return false;
if (!colChangeOK()
&& (s == "append-column" && (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 false;
return MathGridInset::getStatus(cur, cmd, flag); return MathGridInset::getStatus(cur, cmd, flag);
} }

View File

@ -69,7 +69,7 @@ public:
void addRow(row_type row); void addRow(row_type row);
/// delete a row /// delete a row
void delRow(row_type row); void delRow(row_type row);
/// /// swap two rows
void swapRow(row_type row); void swapRow(row_type row);
/// add a column /// add a column
void addCol(col_type col); void addCol(col_type col);
@ -165,6 +165,8 @@ private:
char const * standardFont() const; char const * standardFont() const;
/// consistency check /// consistency check
void check() const; void check() const;
/// can this change its number of rows?
bool rowChangeOK() const;
/// can this change its number of cols? /// can this change its number of cols?
bool colChangeOK() const; bool colChangeOK() const;