]> git.lyx.org Git - features.git/commitdiff
mathed51.diff
authorLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 9 Mar 2001 08:45:10 +0000 (08:45 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 9 Mar 2001 08:45:10 +0000 (08:45 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1721 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/math_cursor.C
src/mathed/math_rowst.h
src/mathed/math_xiter.C

index bf4db3ce13e5cd0ae70dae3e0b8aae35765d6e54..c1f3ee159368eaed521843add93d50db371b14b0 100644 (file)
@@ -1,3 +1,11 @@
+2001-03-09  André Pönitz  <poenitz@htwm.de>
+       * math_cursor.C: use std::vector<> in MathStackXIter
+               change selstk from a pointer to the "real thing"
+
+       * math_rowst.h: new MathedRowContainer::erase method
+
+       * math_xiter.C: use MathedRowContainer::erase
+
 2001-03-08  André Pönitz  <poenitz@htwm.de>
        * math_rowst.h: give MathedRowContainer an 'insert' method. 
 
index 06dce679711702c065dce782682758b4f0b3d849..81aba8a6a2e0eaaa37a2ed4fea1329298b56d096 100644 (file)
@@ -66,18 +66,11 @@ bool IsMacro(short tok, int id)
 static int const MAX_STACK_ITEMS = 32;
 
 struct MathStackXIter {
-       int i, imax;
-       MathedXIter * item;
+       std::vector<MathedXIter> item;
+       int i;
 
-       MathStackXIter(int n = MAX_STACK_ITEMS): imax(n) {
-               item = new MathedXIter[imax];
-               i = 0;
-       }
-
-       MathStackXIter(MathStackXIter & stk);
-
-       ~MathStackXIter() {
-               delete[] item;
+       MathStackXIter(int n = MAX_STACK_ITEMS)
+               : item(n), i(0) {
        }
 
        MathedXIter * push() {
@@ -85,8 +78,7 @@ struct MathStackXIter {
        }
 
        MathedXIter * pop() {
-               --i;
-               return &item[i - 1];
+               return &item[--i];
        }
 
        MathedXIter * Item(int idx) {
@@ -107,21 +99,9 @@ struct MathStackXIter {
 
        int Level() { return i; }
 
-} mathstk, *selstk = 0;
+} mathstk, selstk;
 
 
-MathStackXIter::MathStackXIter(MathStackXIter & stk)
-{
-       imax = stk.imax;
-       item = new MathedXIter[imax];
-       i = stk.i;
-       for (int k = 0; k < i; ++k) {
-               item[k].SetData(stk.item[k].getPar());
-               item[k].GoBegin();
-               item[k].goPosAbs(stk.item[k].getPos());
-       }
-}
-
 
 /***----------------  Mathed Cursor  ---------------------------***/
 
@@ -351,7 +331,8 @@ void MathedCursor::SetPos(int x, int y)
                if (!cursor->Next() && !Pop())
                        break;
        }
-       if (x-xp < cursor->GetX()-x) cursor->ipop();
+       if (x - xp < cursor->GetX() - x)
+               cursor->ipop();
        cursor->Adjust();
 }
 
@@ -962,8 +943,8 @@ void MathedCursor::SelStart()
        lyxerr[Debug::MATHED] << "Starting sel " << endl;
        if (!anchor) {
                selpos = cursor->getPos();
-               selstk = new MathStackXIter(mathstk);
-               anchor = selstk->Item(-1);
+               selstk = mathstk;
+               anchor = selstk.Item(-1);
                anchor->SetData(cursor->getPar());
                anchor->GoBegin();
                anchor->goPosAbs(selpos);
@@ -976,8 +957,6 @@ void MathedCursor::SelClear()
 {
        lyxerr[Debug::MATHED] << "Clearing sel " << endl;
        selection = false;
-       delete selstk;
-       selstk = 0;
        anchor = 0;
 }
 
@@ -986,21 +965,21 @@ void MathedCursor::SelClear()
 // Anchor position must be at the same level that stack.
 void MathedCursor::SelBalance()
 {
-       int d = mathstk.Level() - selstk->Level();
+       int d = mathstk.Level() - selstk.Level();
 
        // If unbalanced, balance them
        while (d != 0) {
                if (d < 0) {
-                       // lyxerr << "b[" << mathstk.Level() << " " << selstk->Level
+                       // lyxerr << "b[" << mathstk.Level() << " " << selstk.Level
                        //  << " " << anchor->GetX() << " " << cursor->GetX() << "]";
-                       anchor = selstk->pop();
+                       anchor = selstk.pop();
                        if (anchor->GetX() >= cursor->GetX())
                        anchor->Next();
                } else {
-                       // lyxerr <<"a[" << mathstk.Level() << " " << selstk->Level() <<"]";
+                       // lyxerr <<"a[" << mathstk.Level() << " " << selstk.Level() <<"]";
                        Pop();
                }
-               d = mathstk.Level() - selstk->Level();
+               d = mathstk.Level() - selstk.Level();
        }
 
        // Once balanced the levels, check that they are at the same paragraph
index ea6c16d0377c9042c2a7cb339f3ed051ed27a4d9..3b1c7f24baa25bb8f0e876fd7032ad76c4a57f23 100644 (file)
@@ -174,6 +174,16 @@ struct MathedRowContainer {
                }
        }
 
+       void erase(iterator & it) {
+               Assert(it.st_);
+               MathedRowSt * r = it.st_->next_;
+    if (r) {
+      it.st_->next_ = r->next_;
+      delete r;
+    }
+       }
+
+
        ///
        MathedRowSt * data_;
 
index d2204c111370d59d62dbf50f7ca23a30de1d7a76..d242a58081f12a51a40f730225b10d7f068997fb 100644 (file)
@@ -123,16 +123,8 @@ void MathedXIter::Clean(int pos2)
                                delete inset;
                        continue;
                } 
-               if (IsCR()) {
-                       if (crow_) {
-                               MathedRowContainer::iterator r = crow_;
-                               ++r;
-                               if (r) {
-                                       crow_.st_->next_ = r.st_->next_;
-                                       delete r.st_;
-                               }          
-                       }
-               }
+               if (IsCR() && crow_)
+                       container().erase(crow_);
                Next();
        }    
        ipop();
@@ -216,14 +208,16 @@ string const MathedXIter::GetString() const
 bool MathedXIter::Next()
 {  
 //    lyxerr << "Ne[" << pos << "]";
-       if (!OK()) return false;
+       if (!OK())
+               return false;
        int w = 0;
 //   lyxerr << "xt ";
        if (IsInset()) {
                MathedInset * px = GetInset();
                w = px->Width();
                if (px->GetType() == LM_OT_SCRIPT) {
-                       if (w > sw_) sw_ = w;
+                       if (w > sw_)
+                               sw_ = w;
                        w = 0;
                } else
                        sx_ = (px->GetLimits()) ? w : 0;
@@ -240,7 +234,7 @@ bool MathedXIter::Next()
                        } else
                                if (c == LM_TC_CR && p_) {
                                        x_ = 0;
-                                       if (crow_ && crow_.st_->next_) {
+                                       if (crow_ && !crow_.is_last()) {
                                                ++crow_;
                                                y_ = crow_->getBaseline();
                                                w = crow_->getTab(0);
@@ -291,7 +285,8 @@ void MathedXIter::Adjust()
 {
        int posx = pos;
        GoBegin();
-       while (posx > pos && OK()) Next();  
+       while (posx > pos && OK())
+               Next();  
 }
 
 
@@ -408,16 +403,12 @@ void MathedXIter::delRow()
                        line_empty = false;
                }
        } while (Next());
+
        int const p1 = getPos();
        ipop();
        
        if (line_empty) {
-               
-               MathedRowContainer::iterator r( crow_.st_->next_ );
-               if (r) {
-                       crow_.st_->next_ = r.st_->next_;
-                       delete r.st_;
-               }
+               container().erase(crow_);       
                join(p1);
                Delete();
        } else
@@ -551,7 +542,8 @@ void MathedXIter::IMetrics(int pos2, int & width, int & ascent, int & descent)
                                        << cx << ']' << endl;
                                break;
                        }
-               if (pos < pos2)  Next();
+               if (pos < pos2)
+                       Next();
        }
        width = x_ - x1;
 }