... the other way round.

This removes the math specific  'math-row-insert' (MATH_ROW_INSERT) etc
lfuns and provides support for the outer world's LFUN_TABULAR_FEATURE
instead.

It get not "properly disabled" if not appropriate, but I'll look into that
later.

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)
? wasy.diff
? images/greek.xpm
? lib/scripts/fig2eps
? lib/scripts/fig2tex
? lib/scripts/fig2xpm
? sigc++/Makefile.in
? sigc++/macros/Makefile.in
? src/lyx_main
? src/frontends/qt2/xforms/Makefile.in
? src/insets/insettext.C.try
? src/mathed/tmp.diff
? src/mathed/script.diff
? src/mathed/.math_gridinset.C.swp
? src/mathed/shared_ptr.diff
Index: lib/bind/math.bind
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/bind/math.bind,v
retrieving revision 1.15
diff -u -p -r1.15 math.bind
--- lib/bind/math.bind  15 Aug 2002 13:57:54 -0000      1.15
+++ lib/bind/math.bind  21 Aug 2002 13:08:51 -0000
@@ -63,18 +63,22 @@
 \bind "M-m t e"   "math-mutate eqnarray"
 \bind "M-m t m"   "math-mutate multline"
 
-\bind "M-m c i"   "math-column-insert"
-\bind "M-m c d"   "math-column-delete"
+\bind "M-m c i"   "tabular-feature insert-column"
+\bind "M-m c d"   "tabular-feature delete-column"
+\bind "M-m c c"   "tabular-feature copy-column"
+\bind "M-m c s"   "tabular-feature swap-column"
 
-\bind "M-m w i"   "math-row-insert"
-\bind "M-m w d"   "math-row-delete"
+\bind "M-m w i"   "tabular-feature insert-row"
+\bind "M-m w d"   "tabular-feature delete-row"
+\bind "M-m w c"   "tabular-feature copy-row"
+\bind "M-m w s"   "tabular-feature swap-row"
 
-\bind "M-m a v t"   "math-valign top"
-\bind "M-m a v c"   "math-valign center"
-\bind "M-m a v b"   "math-valign bottom"
-\bind "M-m a h l"   "math-halign left"
-\bind "M-m a h c"   "math-halign center"
-\bind "M-m a h r"   "math-halign right"
+\bind "M-m w t"   "tabular-feature valign-top"
+\bind "M-m w m"   "tabular-feature valign-center"
+\bind "M-m w b"   "tabular-feature valign-bottom"
+\bind "M-m c l"   "tabular-feature align-left"
+\bind "M-m c m"   "tabular-feature align-center"
+\bind "M-m c r"   "tabular-feature align-right"
 
 # Decoration accents
 
Index: lib/ui/default.ui
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ui/default.ui,v
retrieving revision 1.94
diff -u -p -r1.94 default.ui
--- lib/ui/default.ui   8 Aug 2002 13:01:08 -0000       1.94
+++ lib/ui/default.ui   21 Aug 2002 13:08:51 -0000
@@ -129,20 +129,29 @@ Menuset
        Submenu "Change formula type...|t" "edit_math_mutate"
        Separator
        Submenu "Use computer algebra system|t" "edit_math_extern"
+
+       #Item "Line Top|T" "tabular-feature toggle-line-top"
+       #Item "Line Bottom|B" "tabular-feature toggle-line-bottom"
+       #Item "Line Left|L" "tabular-feature toggle-line-left"
+       #Item "Line Right|R" "tabular-feature toggle-line-right"
+       #Separator
+       Item "Align Column Left|e" "tabular-feature align-left"
+       Item "Align Column Center|C" "tabular-feature align-center"
+       Item "Align Column Right|i" "tabular-feature align-right"
        Separator
-       Item "Align Left|f" "math-halign left"
-       Item "Align Center|C" "math-halign center"
-       Item "Align Right|R" "math-halign right"
+       Item "Align Table Top|o" "tabular-feature valign-top"
+       Item "Align Table Center|n" "tabular-feature valign-center"
+       Item "Align Table Bottom|V" "tabular-feature valign-bottom"
        Separator
-       Item "V.Align Top|T" "math-valign top"
-       Item "V.Align Center|e" "math-valign center"
-       Item "V.Align Bottom|B" "math-valign bottom"
+       Item "Add Row|A" "tabular-feature append-row"
+       Item "Delete Row|w" "tabular-feature delete-row"
+       Item "Copy Row" "tabular-feature copy-row"
+       Item "Swap Rows" "tabular-feature swap-row"
        Separator
-       Item "Add Row" "math-row-insert"
-       Item "Delete Row" "math-row-delete"
-       Separator
-       Item "Add Column" "math-column-insert"
-       Item "Delete Column" "math-column-delete"
+       Item "Add Column|u" "tabular-feature append-column"
+       Item "Delete Column|D" "tabular-feature delete-column"
+       Item "Copy Column" "tabular-feature copy-column"
+       Item "Swap Columns" "tabular-feature swap-column"
     End
 
     Menu "edit_math_extern"
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.904
diff -u -p -r1.904 ChangeLog
--- src/ChangeLog       21 Aug 2002 07:30:54 -0000      1.904
+++ src/ChangeLog       21 Aug 2002 13:08:51 -0000
@@ -1,3 +1,11 @@
+
+2002-08-20  André Pönitz <[EMAIL PROTECTED]>
+
+       * commandtags.h: new LFUNs for swapping/copying table row/colums
+
+       * LyXAction.C:
+       * lyxfunc.C: support for new lfuns
+
 2002-08-21  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>
 
        * tabular.C: 
Index: src/LyXAction.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v
retrieving revision 1.132
diff -u -p -r1.132 LyXAction.C
--- src/LyXAction.C     15 Aug 2002 14:33:11 -0000      1.132
+++ src/LyXAction.C     21 Aug 2002 13:08:51 -0000
@@ -296,12 +296,6 @@ void LyXAction::init()
                { LFUN_MATH_NONUMBER, "math-nonumber", "", Noop },
                { LFUN_MATH_NUMBER, "math-number", "", Noop },
                { LFUN_MATH_EXTERN, "math-extern", "", Noop },
-               { LFUN_MATH_VALIGN, "math-valign", "", Noop },
-               { LFUN_MATH_HALIGN, "math-halign", "", Noop },
-               { LFUN_MATH_ROW_INSERT, "math-row-insert", "", Noop },
-               { LFUN_MATH_ROW_DELETE, "math-row-delete", "", Noop },
-               { LFUN_MATH_COLUMN_INSERT, "math-column-insert", "", Noop },
-               { LFUN_MATH_COLUMN_DELETE, "math-column-delete", "", Noop },
                { LFUN_MATH_PANEL, "math-panel", "", Noop },
                { LFUN_MATH_SIZE, "math-size", "", Noop },
                { LFUN_MENU_OPEN_BY_NAME, "menu-open", "", NoBuffer },
Index: src/commandtags.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/commandtags.h,v
retrieving revision 1.98
diff -u -p -r1.98 commandtags.h
--- src/commandtags.h   19 Aug 2002 10:11:10 -0000      1.98
+++ src/commandtags.h   21 Aug 2002 13:08:51 -0000
@@ -142,12 +142,6 @@ enum kb_action {
        LFUN_MATH_MACRO,                // ale970510
        LFUN_MATH_EXTERN,    // 120     // Andre' 20010424
        LFUN_MATH_PANEL,                // Andre' 20010522
-       LFUN_MATH_VALIGN,               // Andre' 20010522
-       LFUN_MATH_HALIGN,               // Andre' 20010522
-       LFUN_MATH_ROW_INSERT,           // Andre' 20010522
-       LFUN_MATH_ROW_DELETE,           // Andre' 20010522
-       LFUN_MATH_COLUMN_INSERT,        // Andre' 20010522
-       LFUN_MATH_COLUMN_DELETE,        // Andre' 20010522
        LFUN_MATH_MUTATE,               // Andre' 20010523
        LFUN_MATH_IMPORT_SELECTION,     // Andre' 20010704
        LFUN_MATH_SPACE,                // Andre' 20010725
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.370
diff -u -p -r1.370 lyxfunc.C
--- src/lyxfunc.C       19 Aug 2002 10:11:10 -0000      1.370
+++ src/lyxfunc.C       21 Aug 2002 13:08:53 -0000
@@ -362,7 +362,47 @@ FuncStatus LyXFunc::getStatus(FuncReques
        }
 
        case LFUN_TABULAR_FEATURE:
-               disable = true;
+               if (mathcursor) {
+#if 0
+                       // FIXME: check temporarily disabled
+                       // valign code
+                       char align = mathcursor->valign();
+                       if (align == '\0') {
+                               disable = true;
+                               break;
+                       }
+                       if (ev.argument.empty()) {
+                               flag.clear();
+                               break;
+                       }
+                       if (!contains("tcb", ev.argument[0])) {
+                               disable = true;
+                               break;
+                       }
+                       flag.setOnOff(ev.argument[0] == align);
+               } else
+                       disable = true;
+
+                       char align = mathcursor->halign();
+                       if (align == '\0') {
+                               disable = true;
+                               break;
+                       }
+                       if (ev.argument.empty()) {
+                               flag.clear();
+                               break;
+                       }
+                       if (!contains("lcr", ev.argument[0])) {
+                               disable = true;
+                               break;
+                       }
+                       flag.setOnOff(ev.argument[0] == align);
+#endif
+
+                       disable = !mathcursor->halign();
+                       break;
+               }
+
                if (tli) {
                        FuncStatus ret;
                        //ret.disabled(true);
@@ -416,45 +456,6 @@ FuncStatus LyXFunc::getStatus(FuncReques
        case LFUN_LATEX_LOG:
                disable = !IsFileReadable(buf->getLogName().second);
                break;
-       case LFUN_MATH_VALIGN:
-               if (mathcursor) {
-                       char align = mathcursor->valign();
-                       if (align == '\0') {
-                               disable = true;
-                               break;
-                       }
-                       if (ev.argument.empty()) {
-                               flag.clear();
-                               break;
-                       }
-                       if (!contains("tcb", ev.argument[0])) {
-                               disable = true;
-                               break;
-                       }
-                       flag.setOnOff(ev.argument[0] == align);
-               } else
-                       disable = true;
-               break;
-
-       case LFUN_MATH_HALIGN:
-               if (mathcursor) {
-                       char align = mathcursor->halign();
-                       if (align == '\0') {
-                               disable = true;
-                               break;
-                       }
-                       if (ev.argument.empty()) {
-                               flag.clear();
-                               break;
-                       }
-                       if (!contains("lcr", ev.argument[0])) {
-                               disable = true;
-                               break;
-                       }
-                       flag.setOnOff(ev.argument[0] == align);
-               } else
-                       disable = true;
-               break;
 
        case LFUN_MATH_MUTATE:
                if (mathcursor)
@@ -472,15 +473,6 @@ FuncStatus LyXFunc::getStatus(FuncReques
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_EXTERN:
                disable = !mathcursor;
-               break;
-
-       // we need to be math mode and a math array for that
-       // Hack: halign produces non-zero result iff we are in a math array
-       case LFUN_MATH_ROW_INSERT:
-       case LFUN_MATH_ROW_DELETE:
-       case LFUN_MATH_COLUMN_INSERT:
-       case LFUN_MATH_COLUMN_DELETE:
-               disable = !mathcursor || !mathcursor->halign();
                break;
 
        default:
Index: src/mathed/formulabase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v
retrieving revision 1.204
diff -u -p -r1.204 formulabase.C
--- src/mathed/formulabase.C    20 Aug 2002 13:00:25 -0000      1.204
+++ src/mathed/formulabase.C    21 Aug 2002 13:08:53 -0000
@@ -415,12 +415,6 @@ Inset::RESULT InsetFormulaBase::localDis
 
        case LFUN_MATH_MUTATE:
        case LFUN_MATH_DISPLAY:
-       case LFUN_MATH_HALIGN:
-       case LFUN_MATH_VALIGN:
-       case LFUN_MATH_ROW_INSERT:
-       case LFUN_MATH_ROW_DELETE:
-       case LFUN_MATH_COLUMN_INSERT:
-       case LFUN_MATH_COLUMN_DELETE:
        case LFUN_MATH_NUMBER:
        case LFUN_MATH_NONUMBER:
        case LFUN_TABINSERT:
@@ -428,6 +422,7 @@ Inset::RESULT InsetFormulaBase::localDis
        case LFUN_DELETE_LINE_FORWARD:
        case LFUN_INSERT_LABEL:
        case LFUN_MATH_EXTERN:
+       case LFUN_TABULAR_FEATURE:
                bv->lockedInsetStoreUndo(Undo::EDIT);
                mathcursor->dispatch(cmd);
                updateLocal(bv, true);
Index: src/mathed/math_gridinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_gridinset.C,v
retrieving revision 1.81
diff -u -p -r1.81 math_gridinset.C
--- src/mathed/math_gridinset.C 15 Aug 2002 18:04:01 -0000      1.81
+++ src/mathed/math_gridinset.C 21 Aug 2002 13:08:53 -0000
@@ -578,6 +578,25 @@ void MathGridInset::delRow(row_type row)
 }
 
 
+void MathGridInset::copyRow(row_type row)
+{
+       addRow(row);
+       for (col_type col = 0; col < ncols(); ++col)
+               cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
+}
+
+
+void MathGridInset::swapRow(row_type row)
+{
+       if (nrows() == 1)
+               return;
+       if (row + 1 == nrows())
+               --row;
+       for (col_type col = 0; col < ncols(); ++col)
+               swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
+}
+
+
 void MathGridInset::addCol(col_type newcol)
 {
        const col_type nc = ncols();
@@ -621,6 +640,25 @@ void MathGridInset::delCol(col_type col)
 }
 
 
+void MathGridInset::copyCol(col_type col)
+{
+       addCol(col);
+       for (row_type row = 0; row < nrows(); ++row)
+               cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
+}
+
+
+void MathGridInset::swapCol(col_type col)
+{
+       if (ncols() == 1)
+               return;
+       if (col + 1 == ncols())
+               --col;
+       for (row_type row = 0; row < nrows(); ++row)
+               swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
+}
+
+
 int MathGridInset::cellXOffset(idx_type idx) const
 {
        col_type c = col(idx);
@@ -968,41 +1006,49 @@ MathInset::result_type MathGridInset::di
                        return DISPATCHED_POP;
                }
 
-               case LFUN_MATH_HALIGN:
-                       halign((cmd.argument + "c")[0], col(idx));
-                       return DISPATCHED_POP;
-
-               case LFUN_MATH_VALIGN:
-                       valign((cmd.argument + "c")[0]);
-                       return DISPATCHED_POP;
-
-               case LFUN_MATH_ROW_INSERT:
-                       addRow(row(idx));
-                       return DISPATCHED_POP;
-
-               case LFUN_MATH_ROW_DELETE:
-                       delRow(row(idx));
-                       if (idx > nargs())
-                               idx -= ncols();
-                       return DISPATCHED_POP;
-
-               case LFUN_MATH_COLUMN_INSERT: {
-                       row_type r = row(idx);
-                       col_type c = col(idx);
-                       addFancyCol(c);
-                       idx = index(r, c);
-                       return DISPATCHED_POP;
-               }
-
-               case LFUN_MATH_COLUMN_DELETE: {
-                       row_type r = row(idx);
-                       col_type c = col(idx);
-                       delFancyCol(col(idx));
-                       idx = index(r, c);
-                       if (idx > nargs())
-                               idx -= ncols();
+               case LFUN_TABULAR_FEATURE:
+                       //lyxerr << "handling tabular-feature " << cmd.argument << 
+"\n";
+                       if (cmd.argument == "valign-top")
+                               valign('t');
+                       else if (cmd.argument == "valign-center")
+                               valign('c');
+                       else if (cmd.argument == "valign-bottom")
+                               valign('b');
+                       else if (cmd.argument == "align-left")
+                               halign('l', col(idx));
+                       else if (cmd.argument == "align-right")
+                               halign('r', col(idx));
+                       else if (cmd.argument == "align-center")
+                               halign('c', col(idx));
+                       else if (cmd.argument == "append-row")
+                               addRow(row(idx));
+                       else if (cmd.argument == "delete-row") {
+                               delRow(row(idx));
+                               if (idx > nargs())
+                                       idx -= ncols();
+                       } else if (cmd.argument == "copy-row")
+                               copyRow(row(idx));
+                       else if (cmd.argument == "swap-row")
+                               swapRow(row(idx));
+                       else if (cmd.argument == "append-column") {
+                               row_type r = row(idx);
+                               col_type c = col(idx);
+                               addCol(c);
+                               idx = index(r, c);
+                       } else if (cmd.argument == "delete-column") {
+                               row_type r = row(idx);
+                               col_type c = col(idx);
+                               delCol(col(idx));
+                               idx = index(r, c);
+                               if (idx > nargs())
+                                       idx -= ncols();
+                       } else if (cmd.argument == "copy-column")
+                               copyCol(col(idx));
+                       else if (cmd.argument == "swap-column")
+                               swapCol(col(idx));
+                       else 
+                               return UNDISPATCHED;
                        return DISPATCHED_POP;
-               }
 
                case LFUN_PASTE: {
                        //lyxerr << "pasting '" << cmd.argument << "'\n";
Index: src/mathed/math_gridinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_gridinset.h,v
retrieving revision 1.53
diff -u -p -r1.53 math_gridinset.h
--- src/mathed/math_gridinset.h 15 Aug 2002 18:04:01 -0000      1.53
+++ src/mathed/math_gridinset.h 21 Aug 2002 13:08:53 -0000
@@ -164,17 +164,17 @@ public:
        ///
        virtual void delRow(row_type r);
        ///
-       virtual void addFancyRow(row_type r) { addRow(r); }
+       virtual void copyRow(row_type r);
        ///
-       virtual void delFancyRow(row_type r) { delRow(r); }
+       virtual void swapRow(row_type r);
        ///
        virtual void addCol(col_type c);
        ///
        virtual void delCol(col_type c);
        ///
-       virtual void addFancyCol(col_type c) { addCol(c); }
+       virtual void copyCol(col_type c);
        ///
-       virtual void delFancyCol(col_type c) { delCol(c); }
+       virtual void swapCol(col_type c);
        ///
        virtual void appendRow();
        ///
Index: src/mathed/math_hullinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hullinset.C,v
retrieving revision 1.56
diff -u -p -r1.56 math_hullinset.C
--- src/mathed/math_hullinset.C 19 Aug 2002 10:11:13 -0000      1.56
+++ src/mathed/math_hullinset.C 21 Aug 2002 13:08:53 -0000
@@ -400,6 +400,12 @@ void MathHullInset::footer_write(WriteSt
 }
 
 
+bool MathHullInset::colChangeOK() const
+{
+       return type_ == "align" || type_ == "alignat" || type_ == "xalignat";
+}
+
+
 void MathHullInset::addRow(row_type row)
 {
        nonum_.insert(nonum_.begin() + row + 1, !numberedType());
@@ -418,26 +424,21 @@ void MathHullInset::delRow(row_type row)
 }
 
 
-void MathHullInset::addFancyCol(col_type col)
+void MathHullInset::addCol(col_type col)
 {
-       if (type_ == "equation")
-               mutate("eqnarray");
-
-       else if (type_ == "eqnarray") {
-               mutate("align");
-               addFancyCol(col);
-       }
-
-       else if (type_ == "align" || type_ == "alignat"
-             || type_ == "xalignat" || type_ == "xxalignat")
+       if (colChangeOK()) 
                MathGridInset::addCol(col);
+       else
+               lyxerr << "Can't change number of columns in '" << type_ << "'\n";
 }
 
 
-void MathHullInset::delFancyCol(col_type col)
+void MathHullInset::delCol(col_type col)
 {
-       if (type_ == "alignat" || type_ == "xalignat" || type_ == "xxalignat")
+       if (colChangeOK()) 
                MathGridInset::delCol(col);
+       else
+               lyxerr << "Can't change number of columns in '" << type_ << "'\n";
 }
 
 
@@ -584,12 +585,16 @@ void MathHullInset::mutate(string const 
        }
 
        else if (type_ == "multline") {
-               if (newtype == "gather") {
-                       setType("gather");
+               if (newtype == "gather" || newtype == "align" ||        
+                          newtype == "xalign" || newtype == "xxalign")
+                       setType(newtype);
+               else if (newtype == "eqnarray") {
+                       MathGridInset::addCol(1);
+                       MathGridInset::addCol(1);
+                       setType("eqnarray");
                } else {
                        lyxerr << "mutation from '" << type_
-                               << "' to '" << newtype << "' not implemented"
-                                                << endl;
+                               << "' to '" << newtype << "' not implemented" << endl;
                }
        }
 
@@ -800,11 +805,6 @@ MathInset::result_type MathHullInset::di
                        label(r, new_label);
                        return DISPATCHED;
                }
-
-               case LFUN_MATH_HALIGN:
-               case LFUN_MATH_VALIGN:
-                       // we explicitly don't want the default behaviour here
-                       return UNDISPATCHED;
 
                case LFUN_MATH_EXTERN:
                        doExtern(cmd, idx, pos);
Index: src/mathed/math_hullinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hullinset.h,v
retrieving revision 1.26
diff -u -p -r1.26 math_hullinset.h
--- src/mathed/math_hullinset.h 15 Aug 2002 17:41:24 -0000      1.26
+++ src/mathed/math_hullinset.h 21 Aug 2002 13:08:53 -0000
@@ -57,14 +57,14 @@ public:
        /// identifies HullInset
        MathHullInset * asHullInset() { return this; }
 
-       ///
-       void addRow(row_type);
-       ///
-       void delRow(row_type);
-       ///
-       void addFancyCol(col_type);
-       ///
-       void delFancyCol(col_type);
+       /// add a row
+       void addRow(row_type row);
+       /// delete a row
+       void delRow(row_type row);
+       /// add a column
+       void addCol(col_type col);
+       /// delete a column
+       void delCol(col_type col);
 
        /// get type
        string const & getType() const;
@@ -112,6 +112,8 @@ private:
        char const * standardFont() const;
        /// consistency check
        void check() const;
+       /// can this change its number of cols?
+       bool colChangeOK() const;
 
        /// "none", "simple", "display", "eqnarray",...
        string type_;

Reply via email to