From a6fc77c8e9c48436987bd0545c378331822119e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Tue, 20 Feb 2001 13:16:07 +0000 Subject: [PATCH] mathed31.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1566 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 2 + src/mathed/array.C | 55 +++++++++++++++++++++++++++ src/mathed/array.h | 4 ++ src/mathed/formula.C | 5 +-- src/mathed/math_cursor.C | 14 +++---- src/mathed/math_iter.C | 78 -------------------------------------- src/mathed/math_iter.h | 4 -- src/mathed/math_parinset.C | 23 +++++------ src/mathed/math_parinset.h | 5 +-- src/mathed/math_xiter.C | 3 +- 10 files changed, 84 insertions(+), 109 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 15509bde45..d25266b148 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -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 diff --git a/src/mathed/array.C b/src/mathed/array.C index c520fa99ad..8056819563 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -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, diff --git a/src/mathed/array.h b/src/mathed/array.h index 16cba293b9..1d19613f1f 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -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 /// diff --git a/src/mathed/formula.C b/src/mathed/formula.C index acd8c3c2ef..19e1f78f48 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -227,7 +227,7 @@ InsetFormula::InsetFormula(MathParInset * p) par = is_multiline(p->GetType()) ? new MathMatrixInset(static_cast(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); } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index a8290700b7..45c58b7f6f 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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(); diff --git a/src/mathed/math_iter.C b/src/mathed/math_iter.C index dbbbb70711..bf8c5b8444 100644 --- a/src/mathed/math_iter.C +++ b/src/mathed/math_iter.C @@ -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) { diff --git a/src/mathed/math_iter.h b/src/mathed/math_iter.h index c3a27a7c66..22b0a0e9d2 100644 --- a/src/mathed/math_iter.h +++ b/src/mathed/math_iter.h @@ -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: /// diff --git a/src/mathed/math_parinset.C b/src/mathed/math_parinset.C index 2ca3d14a09..862f4554d0 100644 --- a/src/mathed/math_parinset.C +++ b/src/mathed/math_parinset.C @@ -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 diff --git a/src/mathed/math_parinset.h b/src/mathed/math_parinset.h index 5aa640a4cd..ede21651d8 100644 --- a/src/mathed/math_parinset.h +++ b/src/mathed/math_parinset.h @@ -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; diff --git a/src/mathed/math_xiter.C b/src/mathed/math_xiter.C index bcd012efc0..6e449fe0bc 100644 --- a/src/mathed/math_xiter.C +++ b/src/mathed/math_xiter.C @@ -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, -- 2.39.2