And of course I forgot the attachment again...

Andre'

-- 
André Pönitz ........................................ [EMAIL PROTECTED]
Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v
retrieving revision 1.37
diff -u -p -u -r1.37 ChangeLog
--- ChangeLog   2001/02/20 10:49:48     1.37
+++ ChangeLog   2001/02/20 12:32:20
@@ -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: array.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/array.C,v
retrieving revision 1.10
diff -u -p -u -r1.10 array.C
--- array.C     2001/02/19 18:29:09     1.10
+++ array.C     2001/02/20 12:32:20
@@ -75,6 +75,13 @@ MathedArray & MathedArray::operator=(Mat
        return *this;
 }
 
+void MathedArray::clear()
+{
+       last_ = 0;
+       bf_.resize(1);
+       bf_[0] = 0;
+}
+
 void MathedArray::swap(MathedArray & array)
 {
        if (this != &array) {
@@ -152,6 +159,54 @@ void MathedArray::move(int p, int shift)
                last_ += shift;
                bf_[last_] = 0;
        }
+}
+
+
+
+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);
 }
 
 
Index: array.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/array.h,v
retrieving revision 1.17
diff -u -p -u -r1.17 array.h
--- array.h     2001/02/19 14:16:57     1.17
+++ array.h     2001/02/20 12:32:20
@@ -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: formula.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.C,v
retrieving revision 1.85
diff -u -p -u -r1.85 formula.C
--- formula.C   2001/02/17 18:52:52     1.85
+++ formula.C   2001/02/20 12:32:20
@@ -227,7 +227,7 @@ InsetFormula::InsetFormula(MathParInset 
 
        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: math_cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v
retrieving revision 1.35
diff -u -p -u -r1.35 math_cursor.C
--- math_cursor.C       2001/02/17 18:52:52     1.35
+++ math_cursor.C       2001/02/20 12:32:20
@@ -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: math_iter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_iter.C,v
retrieving revision 1.37
diff -u -p -u -r1.37 math_iter.C
--- math_iter.C 2001/02/19 18:29:09     1.37
+++ math_iter.C 2001/02/20 12:32:20
@@ -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: math_iter.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_iter.h,v
retrieving revision 1.26
diff -u -p -u -r1.26 math_iter.h
--- math_iter.h 2001/02/19 18:29:10     1.26
+++ math_iter.h 2001/02/20 12:32:20
@@ -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: math_parinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parinset.C,v
retrieving revision 1.7
diff -u -p -u -r1.7 math_parinset.C
--- math_parinset.C     2001/02/20 10:49:48     1.7
+++ math_parinset.C     2001/02/20 12:32:20
@@ -35,16 +35,6 @@ MathParInset::MathParInset(short st, str
 }
 
 
-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.
@@ -386,6 +382,11 @@ void MathParInset::Write(ostream & os, b
                os << string(brace, '}');
 }
 
+
+void MathParInset::clear()
+{
+       array.clear();
+}
 
 bool MathParInset::Inside(int x, int y) 
 {
Index: math_parinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parinset.h,v
retrieving revision 1.5
diff -u -p -u -r1.5 math_parinset.h
--- math_parinset.h     2001/02/20 10:49:48     1.5
+++ math_parinset.h     2001/02/20 12:32:20
@@ -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: math_xiter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_xiter.C,v
retrieving revision 1.9
diff -u -p -u -r1.9 math_xiter.C
--- math_xiter.C        2001/02/17 18:52:53     1.9
+++ math_xiter.C        2001/02/20 12:32:20
@@ -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,

Reply via email to