]> git.lyx.org Git - features.git/commitdiff
fix nasty bug when inserting labels when cursor was in nested array
authorAndré Pönitz <poenitz@gmx.net>
Tue, 11 Dec 2001 15:04:02 +0000 (15:04 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 11 Dec 2001 15:04:02 +0000 (15:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3189 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formula.C
src/mathed/formula.h
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_gridinset.h
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_inset.h

index 2cd2e7304a46234fb1b606228c3092a9616c3885..37fb7351b3a42c72b86736aa3cb6010deaffdb06 100644 (file)
@@ -364,7 +364,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
 
 vector<string> const InsetFormula::getLabelList() const
 {
-       return mat()->getLabelList();
+       return hull()->getLabelList();
 }
 
 
@@ -388,9 +388,9 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        //lyxerr << "toggling all numbers\n";
                        if (display()) {
                                bv->lockedInsetStoreUndo(Undo::INSERT);
-                               bool old = mat()->numberedType();
+                               bool old = hull()->numberedType();
                                for (MathInset::row_type row = 0; row < par_->nrows(); ++row)
-                                       mat()->numbered(row, !old);
+                                       hull()->numbered(row, !old);
                                bv->owner()->message(old ? _("No number") : _("Number"));
                                updateLocal(bv, true);
                        }
@@ -402,10 +402,10 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        //lyxerr << "toggling line number\n";
                        if (display()) {
                                bv->lockedInsetStoreUndo(Undo::INSERT);
-                               MathCursor::row_type row = mathcursor->row();
-                               bool old = mat()->numbered(row);
+                               MathCursor::row_type row = mathcursor->hullRow();
+                               bool old = hull()->numbered(row);
                                bv->owner()->message(old ? _("No number") : _("Number"));
-                               mat()->numbered(row, !old);
+                               hull()->numbered(row, !old);
                                updateLocal(bv, true);
                        }
                        break;
@@ -415,8 +415,8 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                {
                        bv->lockedInsetStoreUndo(Undo::INSERT);
 
-                       MathCursor::row_type row = mathcursor->row();
-                       string old_label = mat()->label(row);
+                       MathCursor::row_type row = mathcursor->hullRow();
+                       string old_label = hull()->label(row);
                        string new_label = arg;
 
                        if (new_label.empty()) {
@@ -425,8 +425,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                                pair<bool, string> const res = old_label.empty()
                                        ? Alert::askForText(_("Enter new label to insert:"), default_label)
                                        : Alert::askForText(_("Enter label:"), old_label);
-                               
-                               lyxerr << "res: " << res.first << " - '" << res.second << "'\n";
                                if (!res.first)
                                        break;
                                new_label = frontStrip(strip(res.second));
@@ -437,13 +435,13 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
 
                        if (!new_label.empty()) {
                                lyxerr << "setting label to '" << new_label << "'\n";
-                               mat()->numbered(row, true);
+                               hull()->numbered(row, true);
                        }
 
                        if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
                                bv->redraw();
 
-                       mat()->label(row, new_label);
+                       hull()->label(row, new_label);
 
                        updateLocal(bv, true);
                        break;
@@ -455,7 +453,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        int x;
                        int y;
                        mathcursor->getPos(x, y);
-                       mat()->mutate(arg);
+                       hull()->mutate(arg);
                        mathcursor->setPos(x, y);
                        mathcursor->normalize();
                        updateLocal(bv, true);
@@ -477,10 +475,10 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        int x = 0;
                        int y = 0;
                        mathcursor->getPos(x, y);
-                       if (mat()->getType() == LM_OT_SIMPLE)
-                               mat()->mutate(LM_OT_EQUATION);
+                       if (hull()->getType() == LM_OT_SIMPLE)
+                               hull()->mutate(LM_OT_EQUATION);
                        else
-                               mat()->mutate(LM_OT_SIMPLE);
+                               hull()->mutate(LM_OT_SIMPLE);
                        mathcursor->setPos(x, y);
                        mathcursor->normalize();
                        updateLocal(bv, true);
@@ -495,16 +493,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        break;
                }
 
-               case LFUN_MATH_COLUMN_INSERT:
-               {
-                       if (mat()->getType() == LM_OT_ALIGN)
-                               mat()->mutate(LM_OT_ALIGNAT);
-                       mat()->addCol(mat()->ncols());
-                       mathcursor->normalize();
-                       updateLocal(bv, true);
-                       break;
-               }
-
                default:
                        result = InsetFormulaBase::localDispatch(bv, action, arg);
        }
@@ -538,7 +526,7 @@ void InsetFormula::handleExtern(const string & arg)
        MathArray ar;
        if (needEqnArray(extra)) {
                mathcursor->last();
-               mathcursor->readLine(ar);
+               //mathcursor->readLine(ar);
                mathcursor->breakLine();
        } else if (selected) {
                mathcursor->selGet(ar);
@@ -557,18 +545,18 @@ void InsetFormula::handleExtern(const string & arg)
 
 bool InsetFormula::display() const
 {
-       return mat()->getType() != LM_OT_SIMPLE;
+       return hull()->getType() != LM_OT_SIMPLE;
 }
 
 
-MathHullInset const * InsetFormula::mat() const
+MathHullInset const * InsetFormula::hull() const
 {
        lyx::Assert(par_->asHullInset());
        return par_->asHullInset();
 }
 
 
-MathHullInset * InsetFormula::mat()
+MathHullInset * InsetFormula::hull()
 {
        lyx::Assert(par_->asHullInset());
        return par_->asHullInset();
@@ -616,5 +604,5 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
 
 MathInsetTypes InsetFormula::getType() const
 {
-       return mat()->getType();
+       return hull()->getType();
 }
index 471f5f31308a96f036729146799a0d2c072313d7..dd2ec650ca9681c51f167c00d8175b281d59fb5d 100644 (file)
@@ -82,10 +82,10 @@ private:
        bool display() const;
        /// available in AMS only?
        bool ams() const;
-       /// Access
-       MathHullInset * mat();
-       /// Access
-       MathHullInset const * mat() const;
+       /// access to hull
+       MathHullInset * hull();
+       /// access to hull
+       MathHullInset const * hull() const;
        ///
        void handleExtern(string const & arg);
 
index 80cc2f918a331ead28edb2e203fd57d7547da33b..309ed06d167035ecaeee66a5623077978907acda 100644 (file)
@@ -521,8 +521,11 @@ void MathCursor::delLine()
                return;
        }
 
-       if (par()->nrows() > 1)
-               par()->delRow(row());
+       if (par()->nrows() > 1) {
+               // grid are the only things with more than one row...
+               lyx::Assert(par()->asGridInset());
+               par()->asGridInset()->delRow(hullRow());
+       }
 
        if (idx() > par()->nargs())
                idx() = par()->nargs();
@@ -929,15 +932,15 @@ MathCursor::size_type MathCursor::size() const
 }
 
 
-MathCursor::col_type MathCursor::col() const
+MathCursor::col_type MathCursor::hullCol() const
 {
-       return par()->col(idx());
+       return Cursor_[0].par_->nucleus()->asGridInset()->col(Cursor_[0].idx_);
 }
 
 
-MathCursor::row_type MathCursor::row() const
+MathCursor::row_type MathCursor::hullRow() const
 {
-       return par()->row(idx());
+       return Cursor_[0].par_->nucleus()->asGridInset()->row(Cursor_[0].idx_);
 }
 
 
@@ -1052,11 +1055,11 @@ void MathCursor::breakLine()
                idx() = 0;
                pos() = size();
        } else {
-               p->addRow(row());
+               p->addRow(hullRow());
 
                // split line
-               const row_type r = row();
-               for (col_type c = col() + 1; c < p->ncols(); ++c)
+               const row_type r = hullRow();
+               for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
                        p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
 
                // split cell
@@ -1066,12 +1069,12 @@ void MathCursor::breakLine()
 }
 
 
-void MathCursor::readLine(MathArray & ar) const
-{
-       idx_type base = row() * par()->ncols();
-       for (idx_type off = 0; off < par()->ncols(); ++off)
-               ar.push_back(par()->cell(base + off));
-}
+//void MathCursor::readLine(MathArray & ar) const
+//{
+//     idx_type base = row() * par()->ncols();
+//     for (idx_type off = 0; off < par()->ncols(); ++off)
+//             ar.push_back(par()->cell(base + off));
+//}
 
 
 char MathCursor::valign() const
index 93f5d05bcf21bdf120bfe14d0309cc4679e29071..4ba59767445f8ab21b037d8fa69ae14d28364214 100644 (file)
@@ -171,11 +171,9 @@ public:
        ///
        char halign() const;
        ///
-       col_type ncols() const;
+       col_type hullCol() const;
        ///
-       col_type col() const;
-       ///
-       row_type row() const;
+       row_type hullRow() const;
 
        /// make sure cursor position is valid
        void normalize() const;
index 8a6e8a14a8735a7af4f11737a25792489400cbfb..c1dfb8e9077d8b91c98eae2e6ad293033c3a8ddb 100644 (file)
@@ -131,13 +131,13 @@ public:
        void idxDeleteRange(idx_type, idx_type);
                        
        ///
-       void addRow(row_type);
+       virtual void addRow(row_type);
        ///
-       void delRow(row_type);
+       virtual void delRow(row_type);
        ///
-       void addCol(col_type);
+       virtual void addCol(col_type);
        ///
-       void delCol(col_type);
+       virtual void delCol(col_type);
        ///
        virtual void appendRow();
        ///
index 939f64db0ccd37359cde6359b19002805bc0c5a0..fa7bdd36ce8733793495f3e09b704cdc169a3b64 100644 (file)
@@ -5,12 +5,13 @@
 #endif
 
 #include "math_hullinset.h"
+#include "math_mathmlstream.h"
+#include "math_streamstr.h"
 #include "math_support.h"
 #include "debug.h"
 #include "Painter.h"
 #include "LaTeXFeatures.h"
-#include "math_mathmlstream.h"
-#include "math_streamstr.h"
+#include "support/LAssert.h"
 
 #include <vector>
 
@@ -191,6 +192,8 @@ void MathHullInset::draw(Painter & pain, int x, int y) const
 
 string MathHullInset::label(row_type row) const
 {
+       row_type n = nrows();
+       lyx::Assert(row < n);
        return label_[row];
 }
 
@@ -687,3 +690,10 @@ void MathHullInset::mathmlize(MathMLStream & os) const
 }
 
 
+void MathHullInset::check() const
+{
+       lyx::Assert(nonum_.size() == nrows());
+       lyx::Assert(label_.size() == nrows());
+}
+
+
index 43e7d9783c709aea7209aaaf58a6334dde98edee..c2747fb14e232f03add99f3335114d224a15ddff 100644 (file)
@@ -47,9 +47,9 @@ public:
        ///
        void validate(LaTeXFeatures & features) const;
        /// identifies MatrixInsets
-       virtual MathHullInset const * asHullInset() const { return this; }
+       MathHullInset const * asHullInset() const { return this; }
        /// identifies HullInset
-       virtual MathHullInset * asHullInset() { return this; }
+       MathHullInset * asHullInset() { return this; }
 
        ///
        void addRow(row_type);
@@ -94,6 +94,8 @@ private:
        void glueall();
        ///
        string nicelabel(row_type row) const;
+       /// consistency check
+       void check() const;
 
        ///
        MathInsetTypes objtype_;
index 1d56323a7d92620338090dfc50683061ba891837..f80316ecd10ec16c21faee103874d09342317287 100644 (file)
@@ -179,14 +179,6 @@ public:
        virtual int cellXOffset(idx_type) const { return 0; }
        /// any additional y-offset when drawing a cell?
        virtual int cellYOffset(idx_type) const { return 0; }
-       /// add a row after a given one
-       virtual void addRow(row_type) {}
-       /// delete a given row
-       virtual void delRow(row_type) {}
-       /// add a column after a given one
-       virtual void addCol(col_type) {}
-       /// delete a given row
-       virtual void delCol(col_type) {}
 
        /// identifies certain types of insets
        virtual MathArrayInset        * asArrayInset()        { return 0; }