]> git.lyx.org Git - lyx.git/commitdiff
mathed31.diff
authorLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 20 Feb 2001 13:16:07 +0000 (13:16 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 20 Feb 2001 13:16:07 +0000 (13:16 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1566 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/array.C
src/mathed/array.h
src/mathed/formula.C
src/mathed/math_cursor.C
src/mathed/math_iter.C
src/mathed/math_iter.h
src/mathed/math_parinset.C
src/mathed/math_parinset.h
src/mathed/math_xiter.C

index 15509bde45c7b06edb2d713e16a3db8d64413fe6..d25266b1485739f858df459427b2242bad7b123f 100644 (file)
@@ -3,6 +3,8 @@
        * math_parinset.[Ch]: make array a real MathArray, not just a
          pointer to one.
 
+       * move MathIter::Copy(int, int) to MathArray::shrink(pos, pos)
+
        * several files: subsequent changes
 
 
index c520fa99ad7f422fa2fef3ebfd2c0ba299485d63..80568195631219050d9c052c31d141efc7f83fa7 100644 (file)
@@ -75,6 +75,13 @@ MathedArray & MathedArray::operator=(MathedArray const & array)
        return *this;
 }
 
+void MathedArray::clear()
+{
+       last_ = 0;
+       bf_.resize(1);
+       bf_[0] = 0;
+}
+
 void MathedArray::swap(MathedArray & array)
 {
        if (this != &array) {
@@ -155,6 +162,54 @@ void MathedArray::move(int p, int shift)
 }
 
 
+
+void MathedArray::shrink(int pos1, int pos2)
+{
+       if (pos1 == 0 && pos2 >= last())        
+               return;
+
+       short fc = 0;
+       if (pos1 > 0 && bf_[pos1] > ' ') {
+               for (int p = pos1; p >= 0; --p) {
+                       if (MathIsFont(bf_[p])) {
+                               if (p != pos1 - 1)
+                                       fc = bf_[p];
+                               else
+                                       --pos1;
+                               break;
+                       }
+               }
+       }
+
+       if (pos2 > 0 && bf_[pos2] >= ' ' && MathIsFont(bf_[pos2 - 1]))
+               --pos2;
+
+       int dx = pos2 - pos1;
+       MathedArray a;
+       a.resize(dx + 1);
+       strange_copy(&a, (fc) ? 1 : 0, pos1, dx);
+       if (fc) {
+               a[0] = fc;
+               ++dx;
+       }
+       a.last(dx);
+       a[dx] = '\0';
+
+       MathedIter it(&a);
+       it.Reset();
+
+       while (it.OK()) {
+               if (it.IsInset()) {
+                       MathedInset * inset = it.GetInset();
+                       inset = inset->Clone();
+                       a.raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
+               }
+               it.Next();
+       }
+       swap(a);
+}
+
+
 #if 0
 void MathedArray::insert(MathedArray::iterator pos,
                         MathedArray::const_iterator beg,
index 16cba293b9cc1d117e675e8c9b2d2b119a35d68c..1d19613f1f7e4366906ee46d67a96db758f92c24 100644 (file)
@@ -65,6 +65,8 @@ public:
        
        ///
        int empty() const;
+       ///
+       void clear();
    
        ///
        int last() const;
@@ -73,6 +75,8 @@ public:
 
        ///
        void swap(MathedArray &);
+       ///
+       void shrink(int pos1, int pos2);
 
 #if 0
        ///
index acd8c3c2efc879d069492ff2544d217f5b388b14..19e1f78f489c5add63315c7f75f89c6e85be3555 100644 (file)
@@ -227,7 +227,7 @@ InsetFormula::InsetFormula(MathParInset * p)
 
        par = is_multiline(p->GetType()) ?
                new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
-               new MathParInset(p);
+               new MathParInset(*p);
        //   mathcursor = 0;
 
        disp_flag = (par->GetType()>0);
@@ -537,9 +537,6 @@ void InsetFormula::display(bool dspf)
                        par->SetStyle(LM_ST_DISPLAY);
                } else {
                        if (is_multiline(par->GetType())) {
-                               MathParInset * p = new MathParInset(par);
-                               delete par;
-                               par = p;
                                if (mathcursor)
                                        mathcursor->SetPar(par);
                        }
index a8290700b7b996b6646a1a7e9745cece15d048b5..45c58b7f6f23ebc110b7c6cdbd138dfbc13f7d45 100644 (file)
@@ -843,12 +843,10 @@ bool MathedCursor::pullArg()
                        return false;
                
                MathedArray * a = p->GetData();
-               p->setData(0);
+               p->clear();
                Delete();
-               if (a) {
-                       cursor->Merge(a);
-                       cursor->Adjust();
-               }
+               cursor->Merge(a);
+               cursor->Adjust();
 
                return true;
        }
@@ -904,7 +902,8 @@ void MathedCursor::SelCopy()
                int p1 = (cursor->getPos() < selpos) ? cursor->getPos() : selpos;
                int p2 = (cursor->getPos() > selpos) ?
                        cursor->getPos() : selpos;
-               selarray = cursor->Copy(p1, p2);
+               selarray = new MathedArray(*(cursor->GetData()));
+               selarray->shrink(p1, p2);
                cursor->Adjust();
                SelClear();
        }
@@ -919,7 +918,8 @@ void MathedCursor::SelCut()
 
                int p1 = (cursor->getPos() < selpos) ? cursor->getPos() : selpos;
                int p2 = (cursor->getPos() > selpos) ? cursor->getPos() : selpos;
-               selarray = cursor->Copy(p1, p2);
+               selarray = new MathedArray(*(cursor->GetData()));
+               selarray->shrink(p1, p2);
                cursor->Clean(selpos);
                cursor->Adjust();
                SelClear();
index dbbbb70711fdc9d43ab81109bedc51b2bbcc0157..bf8c5b844459b3cfd94618911a4fa1d68b981d51 100644 (file)
@@ -376,84 +376,6 @@ bool MathedIter::Delete()
 }
 
 
-MathedArray * MathedIter::Copy()
-{
-#if 0
-       return Copy(0, 10000);
-#else
-       if (!array) {
-       //      lyxerr << "Math error: Attempting to copy a void array." << endl;
-               return 0;
-       }
-
-       return new MathedArray(*array);
-#endif
-}
-
-
-MathedArray * MathedIter::Copy(int pos1, int pos2)
-{
-       if (!array) {
-       //      lyxerr << "Math error: Attempting to copy a void array." << endl;
-               return 0;
-       }
-
-       if (pos1 > 0 || pos2 <= array->last()) {
-               ipush();
-               MathedArray * t = array;
-               MathedArray * a;
-
-               short fc = 0;
-               if (pos1 > 0 && (*array)[pos1] > ' ') {
-                       for (int p = pos1; p >= 0; --p) {
-                               if (MathIsFont((*array)[p])) {
-                               if (p != pos1 - 1)
-                               fc = (*array)[p];
-                               else
-                               --pos1;
-                               break;
-                               }
-                       }
-               }
-
-               if (pos2 > 0 && (*array)[pos2] >= ' '
-                            && MathIsFont((*array)[pos2 - 1]))
-                       --pos2;
-
-               int dx = pos2 - pos1;
-               a = new MathedArray;
-               a->resize(dx + 1);
-               //       lyxerr << "VA " << pos2 << " " << pos2 << " " << dx << endl;
-               array->strange_copy(a, (fc) ? 1 : 0, pos1, dx);
-               if (fc) {
-                       (*a)[0] = fc;
-                       ++dx;
-               }
-               a->last(dx);
-               (*a)[dx] = '\0';
-
-               array = a;
-               Reset();
-
-               while (OK()) {
-                       if (IsInset()) {
-                               MathedInset * inset = GetInset();
-                               inset = inset->Clone();
-                               array->raw_pointer_insert(inset, pos + 1, sizeof(inset));
-                       }
-                       Next();
-               }
-               array = t;
-               ipop();
-
-               return a;
-       }
-
-       // otherwise: full copy
-       return new MathedArray(*array);
-}
-
-
 void MathedIter::Clear()
 {
        if (!array) {
index c3a27a7c664d2e2240cb5d839bb41c83239babca..22b0a0e9d223ec14cb3a9c9e70cf030c7b061837 100644 (file)
@@ -110,11 +110,7 @@ public:
        void setNumCols(int n) { ncols = n; }
        ///
        MathedArray * GetData() const;
-       /// Copy every object 
-       MathedArray * Copy();
        /// Copy every object from position p1 to p2
-       MathedArray * Copy(int p1, int p2);
-       /// Delete every object from position p1 to p2
        void Clear();
 protected:
        ///
index 2ca3d14a092101296a04a7769d87f2810c1350d0..862f4554d043422a35f06192bb8fd51f80146bf1 100644 (file)
@@ -35,16 +35,6 @@ MathParInset::MathParInset(short st, string const & nm, short ot)
 }
 
 
-MathParInset::MathParInset(MathParInset * p)
-       : MathedInset(p)
-{
-       flag = p->flag;
-       p->setArgumentIdx(0);
-       MathedIter it(p->GetData());
-       setData(it.Copy());
-}
-
-
 MathParInset::~MathParInset()
 {
 }
@@ -52,12 +42,18 @@ MathParInset::~MathParInset()
 
 MathedInset * MathParInset::Clone()
 {
-       return new MathParInset(this);
+       return new MathParInset(*this);
 }
 
 
 void MathParInset::setData(MathedArray * a)
 {
+       if (!a) {
+               lyxerr << "can't set Data from NULL pointer" << endl;
+               array = MathedArray();
+               return;
+       }
+
        array = *a;
        
        // A standard paragraph shouldn't have any tabs nor CRs.
@@ -387,6 +383,11 @@ void MathParInset::Write(ostream & os, bool fragile)
 }
 
 
+void MathParInset::clear()
+{
+       array.clear();
+}
+
 bool MathParInset::Inside(int x, int y) 
 {
   return (x >= xo() && x <= xo() + width
index 5aa640a4cd7b77aa1a8bef8d37e168a063f715e0..ede21651d8be3a7a32fe8c07efd7f2ddeb4df304 100644 (file)
@@ -19,9 +19,6 @@ public:
        MathParInset(short st = LM_ST_TEXT, string const & nm = string(),
                     short ot = LM_OT_MIN);
        ///
-       explicit
-       MathParInset(MathParInset *);
-       ///
        virtual ~MathParInset();
        ///
        virtual MathedInset * Clone();
@@ -79,6 +76,8 @@ public:
        int yo() const {
                return yo_;
        }
+       ///
+       void clear();
 protected:
        /// Paragraph data is stored here
        MathedArray array;
index bcd012efc083710ab4fdae75f84f0146802c8d38..6e449fe0bcfadc983fa51117a6f320d39dae38d9 100644 (file)
@@ -148,8 +148,7 @@ void MathedXIter::Merge(MathedArray * a0)
                return;
        }
        // All insets must be clonned
-       MathedIter it(a0);
-       MathedArray * a = it.Copy();
+       MathedArray * a = new MathedArray(*a0);
 
 #if 0
        array->insert(array->begin() + pos,