]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_scriptinset.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[lyx.git] / src / mathed / math_scriptinset.C
index 2de23d00eeb90d6b3d72bd30dce5d4acce5fb193..5c5aa5c7e3c79acc4379e31763da7e77b5df7bcb 100644 (file)
@@ -3,10 +3,11 @@
 #endif
 
 #include "math_scriptinset.h"
-#include "debug.h"
 #include "math_support.h"
+#include "math_symbolinset.h"
 #include "math_mathmlstream.h"
 #include "support/LAssert.h"
+#include "debug.h"
 
 
 MathScriptInset::MathScriptInset()
@@ -105,37 +106,37 @@ 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)) {
@@ -189,10 +190,9 @@ void MathScriptInset::metrics(MathInset const * nuc,
        MathNestInset::metrics(mi);
        if (nuc)
                nuc->metrics(mi);
-
-       ascent_  = ascent(nuc);
-       descent_ = descent(nuc);
-       width_   = width(nuc);
+       ascent_  = ascent2(nuc);
+       descent_ = descent2(nuc);
+       width_   = width2(nuc);
 }
 
 
@@ -221,7 +221,25 @@ void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
 
 bool MathScriptInset::hasLimits(MathInset const * nuc) const
 {
-       return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());
+       // obviuos cases
+       if (limits_ == 1)
+               return true;
+       if (limits_ == -1)
+               return false;
+
+       // 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)
+                       return false;
+
+       // assume "real" limits for everything else
+       return true;
 }
 
 
@@ -272,46 +290,6 @@ 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";
@@ -330,7 +308,7 @@ void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
                                os << "\\limits ";
                }
        } else
-                       if (os.firstitem)
+                       if (os.firstitem())
                                lyxerr << "suppressing {} \n";
                        else
                                os << "{}";