]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathMacroTemplate.cpp
Assure correct spacing of colored items in mathed
[lyx.git] / src / mathed / InsetMathMacroTemplate.cpp
index 8435d4819bc7654fb84a70f1033631587e669b99..6c109696a753bc90877bd59c89ced44aa430a680 100644 (file)
@@ -126,7 +126,7 @@ void InsetLabelBox::metrics(MetricsInfo & mi, Dimension & dim) const
        if (parent_.editing(mi.base.bv) && label_.length() > 0) {
                // grey
                FontInfo font = sane_font;
-               font.setSize(FONT_SIZE_TINY);
+               font.setSize(TINY_SIZE);
                font.setColor(Color_mathmacrolabel);
 
                // make space for label and box
@@ -156,7 +156,7 @@ void InsetLabelBox::draw(PainterInfo & pi, int x, int y) const
        if (parent_.editing(pi.base.bv) && label_.length() > 0) {
                // grey
                FontInfo font = sane_font;
-               font.setSize(FONT_SIZE_TINY);
+               font.setSize(TINY_SIZE);
                font.setColor(Color_mathmacrolabel);
 
                // make space for label and box
@@ -250,7 +250,7 @@ void InsetDisplayLabelBox::draw(PainterInfo & pi, int x, int y) const
 class InsetMathWrapper : public InsetMath {
 public:
        ///
-       InsetMathWrapper(MathData const * value) : value_(value) {}
+       explicit InsetMathWrapper(MathData const * value) : value_(value) {}
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
@@ -286,9 +286,9 @@ void InsetMathWrapper::draw(PainterInfo & pi, int x, int y) const
 class InsetColoredCell : public InsetMathNest {
 public:
        ///
-       InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max);
+       InsetColoredCell(Buffer * buf, ColorCode blend);
        ///
-       InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max, MathAtom const & atom);
+       InsetColoredCell(Buffer * buf, ColorCode blend, MathAtom const & atom);
        ///
        void draw(PainterInfo &, int x, int y) const;
        ///
@@ -298,20 +298,18 @@ protected:
        ///
        Inset * clone() const;
        ///
-       ColorCode min_;
-       ///
-       ColorCode max_;
+       ColorCode blend_;
 };
 
 
-InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max)
-       : InsetMathNest(buf, 1), min_(min), max_(max)
+InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode blend)
+       : InsetMathNest(buf, 1), blend_(blend)
 {
 }
 
 
-InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode min, ColorCode max, MathAtom const & atom)
-       : InsetMathNest(buf, 1), min_(min), max_(max)
+InsetColoredCell::InsetColoredCell(Buffer * buf, ColorCode blend, MathAtom const & atom)
+       : InsetMathNest(buf, 1), blend_(blend)
 {
        cell(0).insert(0, atom);
 }
@@ -331,7 +329,7 @@ void InsetColoredCell::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetColoredCell::draw(PainterInfo & pi, int x, int y) const
 {
-       pi.pain.enterMonochromeMode(min_, max_);
+       pi.pain.enterMonochromeMode(blend_);
        cell(0).draw(pi, x, y);
        pi.pain.leaveMonochromeMode();
 }
@@ -497,7 +495,7 @@ void InsetMathMacroTemplate::createLook(int args) const
                        // color it light grey, if it is to be removed when the cursor leaves
                        if (i == argsInLook_) {
                                optData->push_back(MathAtom(
-                                       new InsetColoredCell(buffer_, Color_mathbg, Color_mathmacrooldarg)));
+                                       new InsetColoredCell(buffer_, Color_mathmacrooldarg)));
                                optData = &(*optData)[optData->size() - 1].nucleus()->cell(0);
                        }
 
@@ -513,7 +511,7 @@ void InsetMathMacroTemplate::createLook(int args) const
                arg.push_back(MathAtom(new InsetMathMacroArgument(i + 1)));
                if (i >= argsInLook_) {
                        look_.push_back(MathAtom(new InsetColoredCell(buffer_,
-                               Color_mathbg, Color_mathmacrooldarg,
+                               Color_mathmacrooldarg,
                                MathAtom(new InsetMathBrace(arg)))));
                } else
                        look_.push_back(MathAtom(new InsetMathBrace(arg)));
@@ -522,7 +520,7 @@ void InsetMathMacroTemplate::createLook(int args) const
                MathData arg;
                arg.push_back(MathAtom(new InsetMathMacroArgument(i + 1)));
                look_.push_back(MathAtom(new InsetColoredCell(buffer_,
-                       Color_mathbg, Color_mathmacronewarg,
+                       Color_mathmacronewarg,
                        MathAtom(new InsetMathBrace(arg)))));
        }
 
@@ -545,7 +543,7 @@ void InsetMathMacroTemplate::createLook(int args) const
 void InsetMathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        Changer dummy1 = mi.base.changeFontSet("mathnormal");
-       Changer dummy2 = mi.base.font.changeStyle(LM_ST_TEXT);
+       Changer dummy2 = mi.base.font.changeStyle(TEXT_STYLE);
 
        // valid macro?
        MacroData const * macro = 0;
@@ -576,9 +574,9 @@ void InsetMathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
        if (macro)
                macro->unlock();
 
-       dim.wid += 6;
-       dim.des += 2;
-       dim.asc += 2;
+       dim.wid += leftOffset(mi.base.bv) + rightOffset(mi.base.bv);;
+       dim.des += bottomOffset(mi.base.bv);
+       dim.asc += topOffset(mi.base.bv);
 }
 
 
@@ -587,22 +585,24 @@ void InsetMathMacroTemplate::draw(PainterInfo & pi, int x, int y) const
        // FIXME: Calling Changer on the same object repeatedly is inefficient.
        Changer dummy0 = pi.base.font.changeColor(Color_math);
        Changer dummy1 = pi.base.changeFontSet("mathnormal");
-       Changer dummy2 = pi.base.font.changeStyle(LM_ST_TEXT);
+       Changer dummy2 = pi.base.font.changeStyle(TEXT_STYLE);
 
        Dimension const dim = dimension(*pi.base.bv);
 
        // draw outer frame
-       int const a = y - dim.asc + 1;
-       int const w = dim.wid - 2;
-       int const h = dim.height() - 2;
-       pi.pain.rectangle(x + 1, a, w, h, Color_mathframe);
+       int const hoffset = leftOffset(pi.base.bv) + rightOffset(pi.base.bv);
+       int const voffset = topOffset(pi.base.bv) + bottomOffset(pi.base.bv);
+       int const a = y - dim.asc + topOffset(pi.base.bv) / 2;
+       int const w = dim.wid - (hoffset - hoffset / 2);
+       int const h = dim.height() - (voffset - voffset / 2);
+       pi.pain.rectangle(x + leftOffset(pi.base.bv) / 2, a, w, h, Color_mathframe);
 
        // just to be sure: set some dummy values for coord cache
        for (idx_type i = 0; i < nargs(); ++i)
                cell(i).setXY(*pi.base.bv, x, y);
 
        // draw contents
-       look_.draw(pi, x + 3, y);
+       look_.draw(pi, x + leftOffset(pi.base.bv), y);
 }
 
 
@@ -755,7 +755,7 @@ class OptionalsMacroInstanceFix
 {
 public:
        ///
-       OptionalsMacroInstanceFix(int optionals) : optionals_(optionals) {}
+       explicit OptionalsMacroInstanceFix(int optionals) : optionals_(optionals) {}
        ///
        void operator()(InsetMathMacro * macro)
        {
@@ -1263,7 +1263,7 @@ int InsetMathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition)
 }
 
 
-docstring InsetMathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetMathMacroTemplate::xhtml(XMLStream &, OutputParams const &) const
 {
        return docstring();
 }
@@ -1292,11 +1292,13 @@ bool InsetMathMacroTemplate::validName() const
                return false;*/
 
        // valid characters?
-       for (size_t i = 0; i < n.size(); ++i) {
-               if (!(n[i] >= 'a' && n[i] <= 'z')
-                   && !(n[i] >= 'A' && n[i] <= 'Z')
-                   && n[i] != '*')
-                       return false;
+       if (n.size() > 1) {
+               for (size_t i = 0; i < n.size(); ++i) {
+                       if (!(n[i] >= 'a' && n[i] <= 'z')
+                           && !(n[i] >= 'A' && n[i] <= 'Z')
+                           && n[i] != '*')
+                               return false;
+               }
        }
 
        return true;