]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_parinset.C
cleanup indent
[lyx.git] / src / mathed / math_parinset.C
index 13e62ade7e92dcc9fbdea7dd45859892c153c01c..ae43ae750f15dc9641ea2f0641e91bcca957c7d3 100644 (file)
@@ -1,5 +1,9 @@
 #include <config.h>
 
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
 #include "math_parinset.h"
 #include "math_iter.h"
 #include "array.h"
@@ -26,7 +30,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 +39,24 @@ 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)
+void MathParInset::setData(MathedArray const & a)
 {
        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();
        }
 }
 
@@ -90,83 +71,85 @@ MathParInset::draw(Painter & pain, int x, int y)
        bool limits = false;
        
        xo_ = x;
-       yo_ = y; 
-       if (!array || array->empty()) {
-               if (array) {
-                       MathedXIter data(this);
-                       data.GetPos(x, y);
-               }
-               pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
-               return;
-       }  
+       yo_ = y;
        MathedXIter data(this);
+       if (array.empty()) {
+               //MathedXIter data(this);
+               data.GetPos(x, y);
+               pain.rectangle(x, y - df_asc, df_width, df_asc,
+                              LColor::mathline);
+               return;
+       }
+       //MathedXIter data(this);
        data.GoBegin();
        while (data.OK()) {
                data.GetPos(x, y);
-               byte cx = data.GetChar();
+               byte const cx = data.GetChar();
                if (cx >= ' ') {
-                       string s = data.GetString();
-                       drawStr(pain, data.FCode(), size(), x, y, s);
+                       string const s = data.GetString();
+                       drawStr(pain, data.fcode(), size(), x, y, s);
                        mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
                        limits = false;
-               }
-               else {
-                       if (cx == 0)
-                               break;
-                       if (MathIsInset(cx)) {
-                               int yy = y;
-                               MathedInset * p = data.GetInset();
-                               if (cx == LM_TC_UP) {
-                                       if (limits) {
-                                               x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;  
-                                               yy -= (asc + p->Descent()+4);
-                                       }       
-                                       else
-                                               yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
-                               }
-                               else if (cx == LM_TC_DOWN) {
-                                       if (limits) {
-                                               x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
-                                               yy += des + p->Ascent() + 2;
-                                       } else
-                                               yy += des + p->Ascent()/2;
-                               }
-                               else {
-                                       asc = p->Ascent();
-                                       des = p->Descent();
-                               }
-                               p->draw(pain, x, yy);
-                               if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
-                                       limits = p->GetLimits();
-                                       if (limits)
-                                               xp = p->Width();
-                               }
-                               data.Next();
+               } else if (cx == 0) {
+                       break;
+               } else if (MathIsInset(cx)) {
+                       int yy = y;
+                       MathedInset * p = data.GetInset();
+                       if (cx == LM_TC_UP) {
+                               if (limits) {
+                                       x -= (xp > p->Width()) ?
+                                               p->Width() + (xp - p->Width()) / 2 : xp;  
+                                       yy -= (asc + p->Descent() + 4);
+                               } else
+                                       yy -= (p->Descent() > asc) ?
+                                               p->Descent() + 4 : asc;
+                       } else if (cx == LM_TC_DOWN) {
+                               if (limits) {
+                                       x -= (xp > p->Width()) ?
+                                               p->Width() + (xp - p->Width()) / 2 : xp;
+                                       yy += des + p->Ascent() + 2;
+                               } else
+                                       yy += des + p->Ascent() / 2;
+                       } else {
+                               asc = p->Ascent();
+                               des = p->Descent();
                        }
-                       else if (cx == LM_TC_TAB) {
-                               if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
-                                       pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
-                               }
-                               data.Next();
-                               limits = false;
+                       p->draw(pain, x, yy);
+                       if (cx != LM_TC_UP && cx != LM_TC_DOWN) {
+                               limits = p->GetLimits();
+                               if (limits)
+                                       xp = p->Width();
                        }
-                       else if (cx == LM_TC_CR) {
-                               if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
-                                       pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
-                               }
-                               data.Next();
-                               limits = false;
+                       data.Next();
+               } else if (cx == LM_TC_TAB) {
+                       if (cxp == cx
+                           || cxp == LM_TC_CR || data.IsFirst()) {
+                               pain.rectangle(x, y - df_asc,
+                                              df_width, df_asc,
+                                              LColor::mathline);
                        }
-                       else {   
-                               lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
-                               break;
+                       data.Next();
+                       limits = false;
+               } else if (cx == LM_TC_CR) {
+                       if (cxp == LM_TC_TAB
+                           || cxp == LM_TC_CR || data.IsFirst()) {
+                               pain.rectangle(x, y - df_asc,
+                                              df_width, df_asc,
+                                              LColor::mathline);
                        }
+                       data.Next();
+                       limits = false;
+               } else {         
+                       lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
+                       break;
                }
+       
                cxp = cx;
        }
        if (cxp == LM_TC_TAB || cxp == LM_TC_CR) { 
                data.GetPos(x, y);
-               pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
+               pain.rectangle(x, y - df_asc, df_width, df_asc,
+                              LColor::mathline);
        }
 }
 
@@ -187,8 +170,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);
@@ -196,73 +178,72 @@ MathParInset::Metrics()
        while (data.OK()) {
                cx = data.GetChar();      
                if (cx >= ' ') {
-                       string s = data.GetString();
-                       mathed_string_height(data.FCode(),
+                       string const s = data.GetString();
+                       mathed_string_height(data.fcode(),
                                             size(), s, asc, des);
                        if (asc > ascent) ascent = asc;
                        if (des > descent) descent = des;
                        limits = false;
                        mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
-               } else
-                       if (MathIsInset(cx)) {
-                               MathedInset * p = data.GetInset();
-                               p->SetStyle(size());   
-                               p->Metrics();
-                               if (cx == LM_TC_UP) {
-                                       asc += (limits) ? p->Height() + 4: p->Ascent() + 
-                                               ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
-                               } else
-                                       if (cx == LM_TC_DOWN) {
-                                               des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2);
-                                       } else {
-                                               asc = p->Ascent();
-                                               des = p->Descent();
-                                       }
-                               if (asc > ascent) ascent = asc;
-                               if (des > descent) descent = des;
-                               if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
-                                       limits = p->GetLimits();
-                               data.Next();
-                       } else 
-                               if (cx == LM_TC_TAB) {
-                                       int x, y;
-                                       data.GetIncPos(x, y);
-                                       if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
-                                               if (ascent<df_asc) ascent = df_asc;
-                                               tb = x;
-                                       }
-                                       data.setTab(x-tb, tab);
+               } else if (MathIsInset(cx)) {
+                       MathedInset * p = data.GetInset();
+                       p->SetStyle(size());   
+                       p->Metrics();
+                       if (cx == LM_TC_UP) {
+                               asc += (limits) ? p->Height() + 4: p->Ascent() + 
+                                       ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
+                       } else if (cx == LM_TC_DOWN) {
+                               des += (limits ? p->Height() + 4 : p->Height() - p->Ascent() / 2);
+                       } else {
+                               asc = p->Ascent();
+                               des = p->Descent();
+                       }
+                       if (asc > ascent) ascent = asc;
+                       if (des > descent) descent = des;
+                       if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
+                               limits = p->GetLimits();
+                       data.Next();
+               } else  if (cx == LM_TC_TAB) {
+                       int x;
+                       int y;
+                       data.GetIncPos(x, y);
+                       if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
+                               if (ascent < df_asc) ascent = df_asc;
+                               tb = x;
+                       }
+                       data.setTab(x - tb, tab);
+                       tb = x;
+                       ++tab;
+                       limits = false;                   
+                       data.Next();
+               } else if (cx == LM_TC_CR) {
+                       if (tb > 0) {
+                               int x;
+                               int y;
+                               data.GetIncPos(x, y);
+                               if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
+                                       if (ascent < df_asc) ascent = df_asc;
                                        tb = x;
-                                       ++tab;
-                                       limits = false;                   
-                                       data.Next();
-                               } else
-                                       if (cx == LM_TC_CR) {
-                                               if (tb > 0) {
-                                                       int x, y;
-                                                       data.GetIncPos(x, y);
-                                                       if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
-                                                               if (ascent<df_asc) ascent = df_asc;
-                                                               tb = x;
-                                                       } 
-                                                       data.setTab(x - tb, tab);
-                                               } else //if (GetColumns() == 1) 
-                                                       {
-                                                               int x, y;
-                                                               data.GetIncPos(x, y);
-                                                               data.setTab(x, tab);
-                                                               if (ascent<df_asc) ascent = df_asc;
-                                                       } 
-                                               tb = tab = 0;
-                                               data.subMetrics(ascent, descent);
-                                               ascent = df_asc;   
-                                               descent = 0;
-                                               data.Next();
-                                       } else {
-                                               lyxerr << "Mathed Error: Unrecognized code[" << cx
-                                                      << "]" << endl;
-                                               break;
-                                       }       
+                               } 
+                               data.setTab(x - tb, tab);
+                       } else //if (GetColumns() == 1) 
+                               {
+                                       int x;
+                                       int y;
+                                       data.GetIncPos(x, y);
+                                       data.setTab(x, tab);
+                                       if (ascent < df_asc) ascent = df_asc;
+                               } 
+                       tb = tab = 0;
+                       data.subMetrics(ascent, descent);
+                       ascent = df_asc;
+                       descent = 0;
+                       data.Next();
+               } else {
+                       lyxerr << "Mathed Error: Unrecognized code[" << cx
+                              << "]" << endl;
+                       break;
+               }       
                cxp = cx;
        }
        data.GetIncPos(width, ls);
@@ -284,10 +265,10 @@ MathParInset::Metrics()
 
 void MathParInset::Write(ostream & os, bool fragile)
 {
-       if (!array) return;
+       if (array.empty()) return;
        int brace = 0;
-       latexkeys * l;
-       MathedIter data(array);
+       latexkeys const * l;
+       MathedIter data(&array);
        // hack
        MathedRowSt const * crow = getRowSt();   
        data.Reset();
@@ -303,39 +284,39 @@ void MathParInset::Write(ostream & os, bool fragile)
                if (cx >= ' ') {
                        string str = data.GetString();
                        
-                       if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) {
-                               os << '\\' << math_font_name[data.FCode()-LM_TC_RM] << '{';
+                       if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
+                               os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
                        }
                        for (string::const_iterator s = str.begin();
                             s != str.end(); ++s) {
                                byte c = *s;
-                               if (MathIsSymbol(data.FCode())) {
-                                       l = lm_get_key_by_id(c, (data.FCode() == LM_TC_BSYM) ?
+                               if (MathIsSymbol(data.fcode())) {
+                                       l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
                                                             LM_TK_BIGSYM : LM_TK_SYM);
                                        if (l) {
                                                os << '\\' << l->name << ' ';
                                        } else {
 #warning this does not compile on gcc 2.97
                                                //lyxerr << "Illegal symbol code[" << c
-                                               //   << " " << str.end() - s << " " << data.FCode() << "]";
+                                               //   << " " << str.end() - s << " " << data.fcode() << "]";
                                        }
                                } else {
                                        // Is there a standard logical XOR?
-                                       if ((data.FCode() == LM_TC_TEX && c != '{' && c != '}') ||
-                                           (data.FCode() == LM_TC_SPECIAL))
+                                       if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
+                                           (data.fcode() == LM_TC_SPECIAL))
                                                os << '\\';
                                        else {
                                                if (c == '{') ++brace;
                                                if (c == '}') --brace;
                                        }
-                                       if (c == '}' && data.FCode() == LM_TC_TEX && brace < 0) 
+                                       if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0) 
                                                lyxerr <<"Math warning: Unexpected closing brace."
                                                       << endl;
                                        else           
                                                os << char(c);
                                }
                        }
-                       if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
+                       if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
                                os << '}';
                } else     
                        if (MathIsInset(cx)) {
@@ -398,6 +379,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
@@ -440,7 +426,13 @@ bool MathParInset::Permit(short f) const
 }
 
 
-MathedArray * MathParInset::GetData()
+MathedArray & MathParInset::GetData()
+{
+       return array;
+}
+
+
+MathedArray const & MathParInset::GetData() const
 {
        return array;
 }