From: André Pönitz Date: Mon, 9 Jul 2001 16:59:57 +0000 (+0000) Subject: cursor movement in multiline math; remove dead code X-Git-Tag: 1.6.10~21109 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=faa697a2a9ee609d4d6b878d726c968ecce3dd28;p=features.git cursor movement in multiline math; remove dead code git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2212 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 8ce2221ac3..a9b9ed3b62 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,12 @@ +2001-07-04 André Pönitz + + * math_grid.C: in the first cell of a completely empty row + deletes that row, places the cursor in the first of the + new empty cells. + + * math_grid.C: try to split cell nicely when mutating from single-cell + to multi-cell environment + 2001-07-09 Dekel Tsur * math_matrixinset.C (mutate): Use only the first label when @@ -13,7 +22,7 @@ * formulabase.C (mathDispatchInsertMath): remove bogus return statement. -2001-07-04 André Pönitz +2001-07-09 André Pönitz * math_*inset.C: Change order of arguments in MathInset constructor diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 4508d4dd9b..b6d8e4613a 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -176,13 +176,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, updateLocal(bv); break; - - case LFUN_DELETE_LINE_FORWARD: - bv->lockedInsetStoreUndo(Undo::DELETE); - mathcursor->DelLine(); - updateLocal(bv); - break; - case LFUN_MATH_NUMBER: { //lyxerr << "toggling all numbers\n"; diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index e86ff0a55b..491845ce82 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -469,7 +469,6 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, { //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action // << " arg: '" << arg << "' cursor: " << mathcursor << "\n"; - // extern char *dispatch_result; if (!mathcursor) return UNDISPATCHED; @@ -970,8 +969,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, } } - if (mathcursor) - mathcursor->normalize(); + mathcursor->normalize(); if (mathcursor && was_macro != mathcursor->InMacroMode() && action >= 0 diff --git a/src/mathed/math_bigopinset.C b/src/mathed/math_bigopinset.C index b69206490d..588a4cde9f 100644 --- a/src/mathed/math_bigopinset.C +++ b/src/mathed/math_bigopinset.C @@ -143,9 +143,12 @@ bool MathBigopInset::hasLimits() const } -bool MathBigopInset::idxDelete(int idx) +void MathBigopInset::idxDelete(int & idx, bool & popit, bool & deleteit) { - // ignore the return value, we do not want the inset to be deleted - MathScriptInset::idxDelete(idx); - return false; + if (idx == 0) + up(false); + else + down(false); + popit = true; + deleteit = true; } diff --git a/src/mathed/math_bigopinset.h b/src/mathed/math_bigopinset.h index 946fb67ce5..e0409aeb5a 100644 --- a/src/mathed/math_bigopinset.h +++ b/src/mathed/math_bigopinset.h @@ -26,7 +26,7 @@ public: /// void limits(int); /// - bool idxDelete(int idx); + void idxDelete(int & idx, bool & popit, bool & deleteit); private: /// 1: \limits, -1: \nolimits, 0: use default int lims_; diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 6a1fcfe578..c23a395021 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -415,11 +415,13 @@ void MathCursor::Delete() if (cursor_ < array().size()) array().erase(cursor_); - // delete empty cells parts if necessary + // delete empty cells if necessary if (cursor_ == 0 && array().size() == 0) { - bool removeit = par_->idxDelete(idx_); - if (pop() && removeit) - Delete(); + bool popit; + bool removeit; + par_->idxDelete(idx_, popit, removeit); + if (popit && pop() && removeit) + Delete(); } #ifdef WITH_WARNINGS @@ -1176,19 +1178,6 @@ bool MathCursor::prevIsInset() const } -bool MathCursor::IsFont() const -{ - return MathIsFont(nextCode()); -} - - -bool MathCursor::IsScript() const -{ - normalize(); - return MathIsScript(nextCode()); -} - - int MathCursor::xpos() const { normalize(); @@ -1225,24 +1214,27 @@ void MathCursor::splitCell() void MathCursor::breakLine() { MathMatrixInset * p = static_cast(formula()->par()); - if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION) + if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION) { p->mutate(LM_OT_EQNARRAY); - p->addRow(row()); - - // split line - const int r = row(); - for (int c = col() + 1; c < p->ncols(); ++c) { - const int i1 = p->index(r, c); - const int i2 = p->index(r + 1, c); - lyxerr << "swapping cells " << i1 << " and " << i2 << "\n"; - p->cell(i1).swap(p->cell(i2)); - } + p->addRow(row()); + idx_ = p->nrows(); + cursor_ = 0; + } else { + p->addRow(row()); + + // split line + const int r = row(); + for (int c = col() + 1; c < p->ncols(); ++c) { + const int i1 = p->index(r, c); + const int i2 = p->index(r + 1, c); + lyxerr << "swapping cells " << i1 << " and " << i2 << "\n"; + p->cell(i1).swap(p->cell(i2)); + } - // split cell - splitCell(); - MathArray & halfcell = array(); - idx_ += p->ncols() - 1; - halfcell.swap(array()); + // split cell + splitCell(); + p->cell(idx_).swap(p->cell(idx_ + p->ncols() - 1)); + } } char MathCursor::valign() const diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 59e76f6918..92184db894 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -221,10 +221,6 @@ private: /// bool prevIsInset() const; /// - bool IsFont() const; - /// - bool IsScript() const; - /// void merge(MathArray const & arr); /// MathInset * nextInset() const; diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index 5ff51edf87..356ec41193 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -50,23 +50,12 @@ MathStyles smallerStyleFrac(MathStyles st); enum MathTextCodes { /// This must be >= 0 LM_TC_MIN = 0, - /// Open and Close group - LM_TC_OPEN, - /// - LM_TC_CLOSE, /// Math Inset LM_TC_INSET, - /// Super and sub scripts - LM_TC_UP, - /// - LM_TC_DOWN, - /// Editable Math Inset - LM_TC_ACTIVE_INSET, - /// Editable Text Inset - LM_TC_TEXT_INSET, + /// LM_FONT_BEGIN, - /// Internal code for constants 11 + /// Internal code for constants 4 LM_TC_CONST, /// Internal code for variables LM_TC_VAR, @@ -125,8 +114,6 @@ enum MathInsetTypes { /// An array LM_OT_MATRIX, - /// A big operator - LM_OT_BIGOP, /// A LaTeX macro LM_OT_UNDEF, /// diff --git a/src/mathed/math_grid.C b/src/mathed/math_grid.C index 9c3fa1a1a9..d6dad817c7 100644 --- a/src/mathed/math_grid.C +++ b/src/mathed/math_grid.C @@ -365,6 +365,32 @@ bool MathGridInset::idxLast(int & idx, int & pos) const } +void MathGridInset::idxDelete(int & idx, bool & popit, bool & deleteit) +{ + popit = false; + deleteit = false; + + // delete entire row if in first cell of empty row + if (col(idx) == 0 && nrows() > 1) { + bool deleterow = true; + for (int i = idx; i < idx + ncols(); ++i) + if (cell(i).size()) { + deleterow = false; + break; + } + if (deleterow) + delRow(row(idx)); + + if (idx >= nargs()) + idx = nargs() - 1; + return; + } + + // undo effect of Ctrl-Tab (i.e. pull next cell) + //if (idx != nargs() - 1) + // cell(idx).swap(cell(idx + 1)); +} + MathGridInset::RowInfo const & MathGridInset::rowinfo(int i) const { diff --git a/src/mathed/math_grid.h b/src/mathed/math_grid.h index 35a578fb85..b3e14e36f4 100644 --- a/src/mathed/math_grid.h +++ b/src/mathed/math_grid.h @@ -99,6 +99,8 @@ public: bool idxFirst(int &, int &) const; /// bool idxLast(int &, int &) const; + /// + void idxDelete(int &, bool &, bool &); /// void addRow(int); diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 82760011ad..c17c9644f9 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -294,9 +294,10 @@ bool MathInset::idxFirstDown(int &, int &) const return false; } -bool MathInset::idxDelete(int) +void MathInset::idxDelete(int &, bool & popit, bool & deleteit) { - return false; + popit = false; + deleteit = false; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 7b86dc3c2d..f8c6e4c117 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -121,8 +121,9 @@ public: virtual bool idxEnd(int & idx, int & pos) const; /// Delete a cell and move cursor - // a return value true indicates that the whole inset should be deleted - virtual bool idxDelete(int idx); + // the return value indicates whether the cursor should leave the inset + // and/or the whole inset should be deleted + virtual void idxDelete(int & idx, bool & popit, bool & deleteit); /// int nargs() const; diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 10c7e0234e..1ee03e8de4 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -69,6 +69,17 @@ int getCols(short int type) return col; } +// returns position of first relation operator in the array +// used for "intelligent splitting" +int firstRelOp(MathArray const & array) +{ + for (int pos = 0; pos < array.size(); array.next(pos)) + if (!array.isInset(pos) && + MathIsRelOp(array.GetChar(pos), array.GetCode(pos))) + return pos; + return array.size(); +} + } MathMatrixInset::MathMatrixInset(MathInsetTypes t) @@ -456,15 +467,36 @@ void MathMatrixInset::mutate(short newtype) SetType(LM_OT_SIMPLE); break; - case LM_OT_ALIGN: + case LM_OT_ALIGN: { MathGridInset::addCol(1); + + // split it "nicely" + int pos = firstRelOp(cell(0)); + cell(1) = cell(0); + cell(0).erase(pos, cell(0).size()); + cell(1).erase(0, pos); + halign("rl"); SetType(LM_OT_ALIGN); break; + } + case LM_OT_EQNARRAY: default: MathGridInset::addCol(1); MathGridInset::addCol(1); + + // split it "nicely" on the firest relop + int pos1 = firstRelOp(cell(0)); + cell(1) = cell(0); + cell(0).erase(pos1, cell(0).size()); + cell(1).erase(0, pos1); + int pos2 = 0; + cell(1).next(pos2); + cell(2) = cell(1); + cell(1).erase(pos2, cell(1).size()); + cell(2).erase(0, pos2); + halign("rcl"); SetType(LM_OT_EQNARRAY); mutate(newtype); @@ -476,12 +508,15 @@ void MathMatrixInset::mutate(short newtype) switch (newtype) { case LM_OT_SIMPLE: case LM_OT_EQUATION: { + // set correct (no)numbering bool allnonum = true; for (int r = 0; r < nrows(); ++r) { if (!nonum_[r]) allnonum = false; } + nonum_[0] = allnonum; + // set first non-empty label string label; for (int r = 0; r < nrows(); ++r) { if (!label_[r].empty()) { @@ -489,16 +524,15 @@ void MathMatrixInset::mutate(short newtype) break; } } + label_[0] = label; glueall(); mutate(newtype); - label_[0] = label; - nonum_[0] = allnonum; break; } case LM_OT_ALIGN: - default: + default: { for (int row = 0; row < nrows(); ++row) { int c = 3 * row + 1; cell(c).push_back(cell(c + 1)); @@ -508,6 +542,7 @@ void MathMatrixInset::mutate(short newtype) halign("rl"); mutate(newtype); break; + } } break; diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index f80a61262b..be9972a006 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -185,13 +185,12 @@ bool MathScriptInset::idxLastDown(int & idx, int & pos) const } -bool MathScriptInset::idxDelete(int idx) +void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit) { - if (idx == 0) { + if (idx == 0) up(false); - return !down(); - } else { + else down(false); - return !up(); - } + popit = true; + deleteit = !(up() || down()); } diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 6ea6d8d6f4..2fa10b6e01 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -61,7 +61,7 @@ public: /// Identifies ScriptInsets bool isScriptInset() const { return true; } /// - bool idxDelete(int idx); + void idxDelete(int & idx, bool & popit, bool & deleteit); private: /// bool up_; diff --git a/src/mathed/support.C b/src/mathed/support.C index 622e5dc34a..c2b2cde9d0 100644 --- a/src/mathed/support.C +++ b/src/mathed/support.C @@ -6,6 +6,7 @@ #include "lyxfont.h" #include "font.h" #include "math_defs.h" +#include "math_parser.h" #include "Painter.h" #include "matriz.h" #include "symbol_def.h" @@ -468,26 +469,6 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, int code) } -#define USE_EXCEPTIONS 0 -#if USE_EXCEPTIONS -struct deco_not_found {}; - - -math_deco_struct const & search_deco(int code) -{ - math_deco_struct const * res = - lower_bound(math_deco_table, - math_deco_table + math_deco_table_size, - code, math_deco_compare()); - if (res != math_deco_table + math_deco_table_size && - res->code == code) - return *res; - throw deco_not_found(); -} - -#else - - math_deco_struct const * search_deco(int code) { math_deco_struct search_elem = { code, 0, 0 }; @@ -501,18 +482,11 @@ math_deco_struct const * search_deco(int code) return res; return 0; } -#endif bool MathIsInset(short x) { - return LM_TC_INSET <= x && x <= LM_TC_ACTIVE_INSET; -} - - -bool MathIsFont(short x) -{ - return LM_TC_CONST <= x && x <= LM_TC_BSYM; + return LM_TC_INSET == x; } @@ -522,24 +496,6 @@ bool MathIsAlphaFont(short x) } -bool MathIsUp(short x) -{ - return x == LM_TC_UP; -} - - -bool MathIsDown(short x) -{ - return x == LM_TC_DOWN; -} - - -bool MathIsScript(short x) -{ - return x == LM_TC_DOWN || x == LM_TC_UP; -} - - bool MathIsBOPS(short x) { return MathLookupBOP(x) > LMB_NONE; @@ -554,7 +510,7 @@ bool MathIsBinary(short x) bool MathIsSymbol(short x) { - return LM_TC_SYMB <= x && x <= LM_TC_BSYM; + return x == LM_TC_SYMB || x == LM_TC_BOPS || x == LM_TC_BSYM; } @@ -610,3 +566,15 @@ MathStyles smallerStyleFrac(MathStyles st) } return st; } + +bool MathIsRelOp(byte c, MathTextCodes f) +{ + if (f == LM_TC_BOP && (c == '=' || c == '<' || c == '>')) + return true; +#ifndef WITH_WARNINGS +#warning implement me properly +#endif + if (f == LM_TC_SYMB && (c == LM_leq || c == LM_geq)) + return true; + return false; +} diff --git a/src/mathed/support.h b/src/mathed/support.h index 6c2696d21d..51353904f9 100644 --- a/src/mathed/support.h +++ b/src/mathed/support.h @@ -4,6 +4,7 @@ #define MATH_SUPPORT_H #include "lyxfont.h" +#include "math_defs.h" #ifndef byte #define byte unsigned char @@ -39,14 +40,11 @@ int mathed_string_width(short type, int size, string const & s); math_deco_struct const * search_deco(int code); bool MathIsInset(short x); -bool MathIsFont(short x); bool MathIsAlphaFont(short x); -bool MathIsUp(short x); -bool MathIsDown(short x); -bool MathIsScript(short x); bool MathIsBOPS(short x); bool MathIsBinary(short x); bool MathIsSymbol(short x); +bool MathIsRelOp(byte c, MathTextCodes f); void drawStr(Painter & pain, short type, int siz, int x, int y, string const & s);