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.

and removal of dead code.

Andre'

-- 
André Pönitz ............................................. [EMAIL PROTECTED]
? todo
? formula.h.1
? .support.h.swp
? math_sqrtinset.h.ok
? extern.diff
? test.log
? test.aux
? formula.C.1
? .array.C.swp
? math_root.h.ok
? math_fracinset.h.my
? math_fracinset.C.my
? math_root.C.ok
? math_sqrtinset.C.ok
Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v
retrieving revision 1.97
diff -u -p -r1.97 ChangeLog
--- ChangeLog   2001/07/09 10:32:44     1.97
+++ ChangeLog   2001/07/09 14:31:17
@@ -1,3 +1,9 @@
+2001-07-04 André Pönitz  <[EMAIL PROTECTED]>
+
+       * 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.
+
 2001-07-09  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
        * formulabase.C (mathDispatchInsertMath): remove bogus return
Index: formula.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.C,v
retrieving revision 1.111
diff -u -p -r1.111 formula.C
--- formula.C   2001/07/06 15:57:54     1.111
+++ formula.C   2001/07/09 14:31:17
@@ -176,13 +176,6 @@ InsetFormula::localDispatch(BufferView *
                        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: formulabase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v
retrieving revision 1.12
diff -u -p -r1.12 formulabase.C
--- formulabase.C       2001/07/09 10:32:44     1.12
+++ formulabase.C       2001/07/09 14:31:17
@@ -469,7 +469,6 @@ InsetFormulaBase::localDispatch(BufferVi
 {
        //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
        //      << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
-       //   extern char *dispatch_result;
 
        if (!mathcursor) 
                return UNDISPATCHED;
@@ -970,8 +969,7 @@ InsetFormulaBase::localDispatch(BufferVi
                }
        }
 
-       if (mathcursor)
-               mathcursor->normalize();
+       mathcursor->normalize();
 
        if (mathcursor && was_macro != mathcursor->InMacroMode()
                                && action >= 0
Index: math_bigopinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_bigopinset.C,v
retrieving revision 1.12
diff -u -p -r1.12 math_bigopinset.C
--- math_bigopinset.C   2001/07/09 10:19:49     1.12
+++ math_bigopinset.C   2001/07/09 14:31:17
@@ -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: math_bigopinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_bigopinset.h,v
retrieving revision 1.8
diff -u -p -r1.8 math_bigopinset.h
--- math_bigopinset.h   2001/06/28 10:25:20     1.8
+++ math_bigopinset.h   2001/07/09 14:31:17
@@ -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: math_cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v
retrieving revision 1.55
diff -u -p -r1.55 math_cursor.C
--- math_cursor.C       2001/07/09 10:19:49     1.55
+++ math_cursor.C       2001/07/09 14:31:17
@@ -415,11 +415,12 @@ 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, removeit;
+               par_->idxDelete(idx_, popit, removeit);
+               if (popit && pop() && removeit)
+                       Delete();
        }
 
 #ifdef WITH_WARNINGS
@@ -1176,19 +1177,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();
@@ -1243,6 +1231,7 @@ void MathCursor::breakLine()
        MathArray & halfcell = array();
        idx_ += p->ncols() - 1;
        halfcell.swap(array());
+       idx_ -= p->ncols() - 1;
 }
 
 char MathCursor::valign() const
Index: math_cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v
retrieving revision 1.23
diff -u -p -r1.23 math_cursor.h
--- math_cursor.h       2001/07/06 12:09:31     1.23
+++ math_cursor.h       2001/07/09 14:31:17
@@ -221,10 +221,6 @@ private:
        ///
        bool prevIsInset() const;
        ///
-       bool IsFont() const;
-       ///
-       bool IsScript() const;
-       ///
        void merge(MathArray const & arr);
        ///
        MathInset * nextInset() const;
Index: math_defs.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_defs.h,v
retrieving revision 1.50
diff -u -p -r1.50 math_defs.h
--- math_defs.h 2001/07/09 10:19:49     1.50
+++ math_defs.h 2001/07/09 14:31:17
@@ -50,23 +50,12 @@ MathStyles smallerStyleFrac(MathStyles s
 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: math_grid.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_grid.C,v
retrieving revision 1.5
diff -u -p -r1.5 math_grid.C
--- math_grid.C 2001/07/09 10:19:49     1.5
+++ math_grid.C 2001/07/09 14:31:17
@@ -365,6 +365,32 @@ bool MathGridInset::idxLast(int & idx, i
 }
 
 
+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: math_grid.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_grid.h,v
retrieving revision 1.4
diff -u -p -r1.4 math_grid.h
--- math_grid.h 2001/07/06 12:09:31     1.4
+++ math_grid.h 2001/07/09 14:31:17
@@ -99,6 +99,8 @@ public: 
        bool idxFirst(int &, int &) const;
        ///
        bool idxLast(int &, int &) const;
+       ///
+       void idxDelete(int &, bool &, bool &);
                        
        ///
        void addRow(int);
Index: math_inset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.C,v
retrieving revision 1.31
diff -u -p -r1.31 math_inset.C
--- math_inset.C        2001/07/09 10:19:49     1.31
+++ math_inset.C        2001/07/09 14:31:17
@@ -294,9 +294,10 @@ bool MathInset::idxFirstDown(int &, int 
        return false;
 }
 
-bool MathInset::idxDelete(int)
+void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
 {
-       return false;
+       popit    = false;
+       deleteit = false;
 }
 
 
Index: math_inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.h,v
retrieving revision 1.33
diff -u -p -r1.33 math_inset.h
--- math_inset.h        2001/07/09 10:19:50     1.33
+++ math_inset.h        2001/07/09 14:31:17
@@ -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: math_matrixinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_matrixinset.C,v
retrieving revision 1.23
diff -u -p -r1.23 math_matrixinset.C
--- math_matrixinset.C  2001/07/09 10:19:50     1.23
+++ math_matrixinset.C  2001/07/09 14:31:18
@@ -69,8 +69,19 @@ 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)
        : MathGridInset(getCols(t), 1, "formula", t), nonum_(1), label_(1)
 {}
@@ -456,15 +467,34 @@ void MathMatrixInset::mutate(short newty
                                        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;
+                               }
 
                                default:
                                        MathGridInset::addCol(1);
                                        MathGridInset::addCol(1);
+
+                                       // split it "nicely"
+                                       int pos1 = firstRelOp(cell(0)); 
+                                       cell(1) = cell(0);
+                                       cell(0).erase(pos1, cell(0).size());
+                                       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);
Index: math_scriptinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_scriptinset.C,v
retrieving revision 1.6
diff -u -p -r1.6 math_scriptinset.C
--- math_scriptinset.C  2001/07/09 10:19:50     1.6
+++ math_scriptinset.C  2001/07/09 14:31:18
@@ -185,13 +185,12 @@ bool MathScriptInset::idxLastDown(int & 
 }
 
 
-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: math_scriptinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_scriptinset.h,v
retrieving revision 1.3
diff -u -p -r1.3 math_scriptinset.h
--- math_scriptinset.h  2001/06/28 10:25:20     1.3
+++ math_scriptinset.h  2001/07/09 14:31:18
@@ -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: support.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/support.C,v
retrieving revision 1.9
diff -u -p -r1.9 support.C
--- support.C   2001/07/06 12:09:32     1.9
+++ support.C   2001/07/09 14:31:18
@@ -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, in
 }
 
 
-#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,45 +482,20 @@ math_deco_struct const * search_deco(int
                return res;
        return 0;
 }
-#endif
 
 
 bool MathIsInset(short x)
 {
-       return LM_TC_INSET <= x && x <= LM_TC_ACTIVE_INSET;
+       return LM_TC_INSET == x;
 }
 
 
-bool MathIsFont(short x)
-{
-       return LM_TC_CONST <= x && x <= LM_TC_BSYM;
-}
-
-
 bool MathIsAlphaFont(short x)
 {
        return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
 }
 
 
-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;
 }
      
 
@@ -609,4 +565,16 @@ MathStyles smallerStyleFrac(MathStyles s
                default:            st = LM_ST_SCRIPTSCRIPT;
        }
        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: support.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/support.h,v
retrieving revision 1.6
diff -u -p -r1.6 support.h
--- support.h   2001/06/25 00:06:32     1.6
+++ support.h   2001/07/09 14:31:18
@@ -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 
 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);

Reply via email to