]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_parinset.C
mathed31.diff
[lyx.git] / src / mathed / math_parinset.C
index 8b23756a8f9d02aee3ac7da941827760267d8ef9..862f4554d043422a35f06192bb8fd51f80146bf1 100644 (file)
@@ -26,7 +26,6 @@ MathedRowSt * MathParInset::getRowSt() const
 MathParInset::MathParInset(short st, string const & nm, short ot)
        : MathedInset(nm, ot, st)
 {
-       array = 0;
        ascent = 8;
        width = 4;
        descent = 0;
@@ -36,46 +35,35 @@ 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()
 {
-       if (array) {
-               MathedIter it(array);
-               it.Clear();
-               delete array;
-       }
 }
 
 
 MathedInset * MathParInset::Clone()
 {
-       return new MathParInset(this);
+       return new MathParInset(*this);
 }
 
 
 void MathParInset::setData(MathedArray * a)
 {
-       array = 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.
-       if (array) {
-               MathedIter it(array);
-               while (it.OK()) {
-                       char c = it.GetChar();
-                       if (c == LM_TC_TAB || c == LM_TC_CR) 
-                               it.Delete();
-                       else
-                               it.Next();
-               }
+       MathedIter it(&array);
+       while (it.OK()) {
+               char c = it.GetChar();
+               if (c == LM_TC_TAB || c == LM_TC_CR) 
+                       it.Delete();
+               else
+                       it.Next();
        }
 }
 
@@ -91,11 +79,9 @@ MathParInset::draw(Painter & pain, int x, int y)
        
        xo_ = x;
        yo_ = y; 
-       if (!array || array->empty()) {
-               if (array) {
-                       MathedXIter data(this);
-                       data.GetPos(x, y);
-               }
+       if (array.empty()) {
+               MathedXIter data(this);
+               data.GetPos(x, y);
                pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
                return;
        }  
@@ -187,8 +173,7 @@ MathParInset::Metrics()
        ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des); 
        width = df_width;
        descent = 0;
-       if (!array) return;
-       if (array->empty()) return;
+       if (array.empty()) return;
        
        ascent = 0;
        MathedXIter data(this);
@@ -284,10 +269,10 @@ MathParInset::Metrics()
 
 void MathParInset::Write(ostream & os, bool fragile)
 {
-       if (!array) return;
+       if (array.empty()) return;
        int brace = 0;
        latexkeys const * l;
-       MathedIter data(array);
+       MathedIter data(&array);
        // hack
        MathedRowSt const * crow = getRowSt();   
        data.Reset();
@@ -398,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
@@ -442,7 +432,7 @@ bool MathParInset::Permit(short f) const
 
 MathedArray * MathParInset::GetData()
 {
-       return array;
+       return &array;
 }