]> git.lyx.org Git - features.git/commitdiff
cursor movement in multiline math; remove dead code
authorAndré Pönitz <poenitz@gmx.net>
Mon, 9 Jul 2001 16:59:57 +0000 (16:59 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 9 Jul 2001 16:59:57 +0000 (16:59 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2212 a592a061-630c-0410-9148-cb99ea01b6c8

17 files changed:
src/mathed/ChangeLog
src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/math_bigopinset.C
src/mathed/math_bigopinset.h
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_defs.h
src/mathed/math_grid.C
src/mathed/math_grid.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_matrixinset.C
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h
src/mathed/support.C
src/mathed/support.h

index 8ce2221ac32c8cc3b34be47b61c335408cf835a6..a9b9ed3b6293a93b4417ff8b6fc80e9a1192ce96 100644 (file)
@@ -1,3 +1,12 @@
+2001-07-04 André Pönitz  <poenitz@htwm.de>
+
+       * math_grid.C: <Delete> in the first cell of a completely empty row
+         deletes that row, <C-Return> 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  <dekelts@tau.ac.il>
 
        * 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  <poenitz@htwm.de>
+2001-07-09 André Pönitz  <poenitz@htwm.de>
 
        * math_*inset.C: Change order of arguments in MathInset constructor 
 
index 4508d4dd9b693ddcbe561416c21ddf3254838883..b6d8e4613a0a46e548c52e53efd2b659d714004e 100644 (file)
@@ -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";
index e86ff0a55b56efa29f55c7fea2f68dd05f9210d4..491845ce825ad72e749fe69510070f258db225de 100644 (file)
@@ -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
index b69206490da51ea3645ae00d95acfb3a4ee41164..588a4cde9f724fb8559f2ff51212bbc8486fea9c 100644 (file)
@@ -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;
 }
index 946fb67ce5baa652bea2f839ce6294ebd007502f..e0409aeb5aa0bbdeb8da86851dad7a9bf74225f7 100644 (file)
@@ -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_;
index 6a1fcfe578dd2f91521039a2a83040608ad9cd44..c23a395021d02e15f273cb2f17d2111e61db64e4 100644 (file)
@@ -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<MathMatrixInset *>(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
index 59e76f691808d3c164f4ab1f06ccf3ed1606439c..92184db894b0cb598f7ddb4fc1e5d04fbba23cdc 100644 (file)
@@ -221,10 +221,6 @@ private:
        ///
        bool prevIsInset() const;
        ///
-       bool IsFont() const;
-       ///
-       bool IsScript() const;
-       ///
        void merge(MathArray const & arr);
        ///
        MathInset * nextInset() const;
index 5ff51edf87d2f58ea016ec7788bf6907b1b88823..356ec41193233bd0a5fd3e165aab6c49c94d7376 100644 (file)
@@ -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,
        ///
index 9c3fa1a1a96d2a8bf6beed81507fe4fd36f2d9bf..d6dad817c7f46905eee1614ac0f59c632bad2506 100644 (file)
@@ -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
 {
index 35a578fb85534ac8f5335ef2f845ed21bd733ddc..b3e14e36f42aadaa2424632c662f05e83eef5b9e 100644 (file)
@@ -99,6 +99,8 @@ public:
        bool idxFirst(int &, int &) const;
        ///
        bool idxLast(int &, int &) const;
+       ///
+       void idxDelete(int &, bool &, bool &);
                        
        ///
        void addRow(int);
index 82760011adc9365ab6c70af77d0b46e1e46a7a7e..c17c9644f9a7b71bb6d10a12acfe14597b16dace 100644 (file)
@@ -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;
 }
 
 
index 7b86dc3c2dbc423258a4e7305752a055c89c0e7d..f8c6e4c117ce8ae64c957da2de9eda276a3d4804 100644 (file)
@@ -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;
index 10c7e0234ed27591225a2e52a80d9ee75b64a637..1ee03e8de44f4e4899f0229c58eb942e9ffb2ba4 100644 (file)
@@ -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;
 
index f80a61262bbb331c501001e009df924e394d40bc..be9972a0061ebf3a09931099f7d869939f1c98f0 100644 (file)
@@ -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());
 }
index 6ea6d8d6f472893859d168c15770d2ac31616688..2fa10b6e0140a621339daa32f58124fd26d23b49 100644 (file)
@@ -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_;
index 622e5dc34a97e5dbfccb0f7eeac4417a2ba11e94..c2b2cde9d0954be3170d1fd6c8ec73a158784016 100644 (file)
@@ -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;
+}
index 6c2696d21d6aa8872dfac1bc639138e7d4faa480..51353904f929142be050c804103ded4ccbf009f8 100644 (file)
@@ -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);