]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_scriptinset.C
oh well
[lyx.git] / src / mathed / math_scriptinset.C
index f05ed54b6d01443480eb1ec4a8f6138d4348cef8..0310eeb7922aff2ca2eb3900fc7c0f46e169d50d 100644 (file)
@@ -10,6 +10,9 @@
 #include "debug.h"
 
 
+using std::max;
+
+
 MathScriptInset::MathScriptInset()
        : MathNestInset(2), limits_(0)
 {
@@ -82,8 +85,8 @@ int MathScriptInset::dy0(MathInset const * nuc) const
        int des = down().ascent();
        if (hasLimits(nuc))
                des += nd + 2;
-       else 
-               des = std::max(des, nd);
+       else
+               des = max(des, nd);
        return des;
 }
 
@@ -96,9 +99,9 @@ int MathScriptInset::dy1(MathInset const * nuc) const
        int asc = up().descent();
        if (hasLimits(nuc))
                asc += na + 2;
-       else 
-               asc = std::max(asc, na);
-       asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, mi_, 'I'));
+       else
+               asc = max(asc, na);
+       asc = max(asc, mathed_char_ascent(font_, 'I'));
        return asc;
 }
 
@@ -106,50 +109,50 @@ int MathScriptInset::dy1(MathInset const * nuc) const
 int MathScriptInset::dx0(MathInset const * nuc) const
 {
        lyx::Assert(hasDown());
-       return hasLimits(nuc) ? (width(nuc) - down().width()) / 2 : nwid(nuc);
+       return hasLimits(nuc) ? (width2(nuc) - down().width()) / 2 : nwid(nuc);
 }
 
 
 int MathScriptInset::dx1(MathInset const * nuc) const
 {
        lyx::Assert(hasUp());
-       return hasLimits(nuc) ? (width(nuc) - up().width()) / 2 : nwid(nuc);
+       return hasLimits(nuc) ? (width2(nuc) - up().width()) / 2 : nwid(nuc);
 }
 
 
 int MathScriptInset::dxx(MathInset const * nuc) const
 {
        //lyx::Assert(nuc());
-       return hasLimits(nuc)  ?  (width(nuc) - nwid(nuc)) / 2  :  0;
+       return hasLimits(nuc)  ?  (width2(nuc) - nwid(nuc)) / 2  :  0;
 }
 
 
-int MathScriptInset::ascent(MathInset const * nuc) const
+int MathScriptInset::ascent2(MathInset const * nuc) const
 {
        return dy1(nuc) + (hasUp() ? up().ascent() : 0);
 }
 
 
-int MathScriptInset::descent(MathInset const * nuc) const
+int MathScriptInset::descent2(MathInset const * nuc) const
 {
        return dy0(nuc) + (hasDown() ? down().descent() : 0);
 }
 
 
-int MathScriptInset::width(MathInset const * nuc) const
+int MathScriptInset::width2(MathInset const * nuc) const
 {
        int wid = 0;
        if (hasLimits(nuc)) {
                wid = nwid(nuc);
                if (hasUp())
-                       wid = std::max(wid, up().width());
+                       wid = max(wid, up().width());
                if (hasDown())
-                       wid = std::max(wid, down().width());
+                       wid = max(wid, down().width());
        } else {
                if (hasUp())
-                       wid = std::max(wid, up().width());
+                       wid = max(wid, up().width());
                if (hasDown())
-                       wid = std::max(wid, down().width());
+                       wid = max(wid, down().width());
                wid += nwid(nuc);
        }
        return wid;
@@ -158,59 +161,78 @@ int MathScriptInset::width(MathInset const * nuc) const
 
 int MathScriptInset::nwid(MathInset const * nuc) const
 {
-       return nuc ?
-               nuc->width() :
-               mathed_char_width(LM_TC_TEX, mi_, '.');
+       return nuc ?  nuc->width() : mathed_char_width(font_, '.');
 }
 
 
 int MathScriptInset::nasc(MathInset const * nuc) const
 {
-       return nuc ? nuc->ascent()
-               : mathed_char_ascent(LM_TC_VAR, mi_, 'I');
+       return nuc ? nuc->ascent() : mathed_char_ascent(font_, 'I');
 }
 
 
 int MathScriptInset::ndes(MathInset const * nuc) const
 {
-       return nuc ? nuc->descent()
-               : mathed_char_descent(LM_TC_VAR, mi_, 'I');
+       return nuc ? nuc->descent() : mathed_char_descent(font_, 'I');
 }
 
 
 void MathScriptInset::metrics(MathMetricsInfo const & mi) const
-{      
+{
        metrics(0, mi);
 }
 
 
 void MathScriptInset::metrics(MathInset const * nuc,
        MathMetricsInfo const & mi) const
-{      
-       MathNestInset::metrics(mi);
+{
+       MathMetricsInfo m = mi;
+       smallerStyleScript(m);
+       MathNestInset::metrics(m);
+       whichFont(font_, LM_TC_VAR, m);
        if (nuc)
                nuc->metrics(mi);
-
-       ascent_  = ascent(nuc);
-       descent_ = descent(nuc);
-       width_   = width(nuc);
+       ascent_  = ascent2(nuc);
+       descent_ = descent2(nuc);
+       width_   = width2(nuc);
 }
 
 
 void MathScriptInset::draw(Painter & pain, int x, int y) const
-{  
+{
        //lyxerr << "unexpected call to MathScriptInset::draw()\n";
        draw(0, pain, x, y);
 }
 
 
+void MathScriptInset::metricsT(TextMetricsInfo const & mi) const
+{
+       metricsT(0, mi);
+}
+
+
+void MathScriptInset::metricsT(MathInset const * nuc,
+       TextMetricsInfo const & mi) const
+{
+       if (hasUp())
+               up().metricsT(mi);
+       if (hasDown())
+               down().metricsT(mi);
+       if (nuc)
+               nuc->metricsT(mi);
+       //ascent_  = ascent2(nuc);
+       //descent_ = descent2(nuc);
+       //width_   = width2(nuc);
+}
+
+
 void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
        int x, int y) const
-{  
+{
        if (nuc)
                nuc->draw(pain, x + dxx(nuc), y);
-       else
-               drawStr(pain, LM_TC_TEX, mi_, x + dxx(nuc), y, ".");
+       else if (editing())
+               drawStr(pain, font_, x + dxx(nuc), y, ".");
 
        if (hasUp())
                up().draw(pain, x + dx1(nuc), y - dy1(nuc));
@@ -219,6 +241,25 @@ void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
                down().draw(pain, x + dx0(nuc), y + dy0(nuc));
 }
 
+void MathScriptInset::drawT(TextPainter & pain, int x, int y) const
+{
+       //lyxerr << "unexpected call to MathScriptInset::draw()\n";
+       drawT(0, pain, x, y);
+}
+
+
+void MathScriptInset::drawT(MathInset const * nuc, TextPainter & pain,
+       int x, int y) const
+{
+       if (nuc)
+               nuc->drawT(pain, x + dxx(nuc), y);
+       if (hasUp())
+               up().drawT(pain, x + dx1(nuc), y - dy1(nuc));
+       if (hasDown())
+               down().drawT(pain, x + dx0(nuc), y + dy0(nuc));
+}
+
+
 
 bool MathScriptInset::hasLimits(MathInset const * nuc) const
 {
@@ -228,12 +269,12 @@ bool MathScriptInset::hasLimits(MathInset const * nuc) const
        if (limits_ == -1)
                return false;
 
-       // we can only display limits if the nucleus wants some 
+       // we can only display limits if the nucleus wants some
        if (!nuc)
                return false;
        if (!nuc->isScriptable())
                return false;
-       
+
        // per default \int has limits beside the \int even in displayed formulas
        if (nuc->asSymbolInset())
                if (nuc->asSymbolInset()->name().find("int") != string::npos)
@@ -247,8 +288,10 @@ bool MathScriptInset::hasLimits(MathInset const * nuc) const
 void MathScriptInset::removeEmptyScripts()
 {
        for (int i = 0; i <= 1; ++i)
-               if (script_[i] && !cell(i).size())
+               if (script_[i] && cell(i).size() == 0) {
+                       cell(i).clear();
                        script_[i] = false;
+               }
 }
 
 
@@ -265,6 +308,12 @@ bool MathScriptInset::has(bool up) const
 }
 
 
+bool MathScriptInset::empty() const
+{
+       return !script_[0] && !script_[1];
+}
+
+
 bool MathScriptInset::hasUp() const
 {
        return script_[1];
@@ -291,48 +340,8 @@ bool MathScriptInset::idxLeft(MathInset::idx_type &,
 }
 
 
-bool MathScriptInset::idxFirstUp(idx_type & idx, pos_type & pos) const
-{
-       if (!hasUp())
-               return false;
-       idx = 1;
-       pos = 0; 
-       return true;
-}
-
-
-bool MathScriptInset::idxFirstDown(idx_type & idx, pos_type & pos) const
-{
-       if (!hasDown())
-               return false;
-       idx = 0;
-       pos = 0; 
-       return true;
-}
-
-
-bool MathScriptInset::idxLastUp(idx_type & idx, pos_type & pos) const
-{
-       if (!hasUp())
-               return false;
-       idx = 1;
-       pos = up().data_.size(); 
-       return true;
-}
-
-
-bool MathScriptInset::idxLastDown(idx_type & idx, pos_type & pos) const
-{
-       if (!hasDown())
-               return false;
-       idx = 0;
-       pos = down().data_.size(); 
-       return true;
-}
-
-
 void MathScriptInset::write(WriteStream & os) const
-{  
+{
        //lyxerr << "unexpected call to MathScriptInset::write()\n";
        write2(0, os);
 }
@@ -350,7 +359,7 @@ void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
                }
        } else
                        if (os.firstitem())
-                               lyxerr << "suppressing {} \n";
+                               lyxerr[Debug::MATHED] << "suppressing {} when writing\n";
                        else
                                os << "{}";
 
@@ -363,7 +372,7 @@ void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
 
 
 void MathScriptInset::normalize(NormalStream & os) const
-{  
+{
        //lyxerr << "unexpected call to MathScriptInset::normalize()\n";
        normalize2(0, os);
 }
@@ -374,11 +383,11 @@ void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
        bool d = hasDown() && down().data_.size();
        bool u = hasUp() && up().data_.size();
 
-       if (u) 
+       if (u)
                os << "[sup ";
        if (d)
                os << "[sub ";
-       
+
        if (nuc)
                os << nuc << ' ';
        else
@@ -386,7 +395,7 @@ void MathScriptInset::normalize2(MathInset const * nuc, NormalStream & os) const
 
        if (d)
                os << down().data_ << ']';
-       if (u) 
+       if (u)
                os << up().data_ << ']';
 }
 
@@ -437,5 +446,3 @@ void MathScriptInset::octavize2(MathInset const * nuc, OctaveStream & os) const
        if (hasUp() && up().data_.size())
                os << "^(" << up().data_ << ')';
 }
-
-