]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathMacroTemplate.cpp
Revert "Fix a number of signedness warnings"
[lyx.git] / src / mathed / InsetMathMacroTemplate.cpp
index 17fc2d04a2148464193becee154fe3d36be3eab6..1152936ee2e784f64b0ae7c49d654792bc3b78ba 100644 (file)
@@ -22,7 +22,6 @@
 #include "MathStream.h"
 #include "MathParser.h"
 #include "MathSupport.h"
-#include "InsetMathMacroArgument.h"
 
 #include "Buffer.h"
 #include "BufferView.h"
@@ -67,15 +66,15 @@ public:
        InsetLabelBox(Buffer * buf, docstring label, InsetMathMacroTemplate const & parent,
                      bool frame = false);
        ///
-       void metrics(MetricsInfo & mi, Dimension & dim) const;
+       void metrics(MetricsInfo & mi, Dimension & dim) const override;
        ///
-       void draw(PainterInfo &, int x, int y) const;
+       void draw(PainterInfo &, int x, int y) const override;
 
 protected:
        ///
        InsetMathMacroTemplate const & parent_;
        ///
-       Inset * clone() const;
+       Inset * clone() const override;
        ///
        docstring const label_;
        ///
@@ -126,7 +125,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 +155,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
@@ -190,15 +189,15 @@ public:
                        InsetMathMacroTemplate const & parent);
 
        ///
-       marker_type marker(BufferView const *) const;
+       marker_type marker(BufferView const *) const override;
        ///
-       void metrics(MetricsInfo & mi, Dimension & dim) const;
+       void metrics(MetricsInfo & mi, Dimension & dim) const override;
        ///
-       void draw(PainterInfo &, int x, int y) const;
+       void draw(PainterInfo &, int x, int y) const override;
 
 protected:
        ///
-       Inset * clone() const;
+       Inset * clone() const override;
 };
 
 
@@ -231,25 +230,17 @@ void InsetDisplayLabelBox::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        InsetLabelBox::metrics(mi, dim);
        if (!parent_.editing(mi.base.bv)
-           && parent_.cell(parent_.displayIdx()).empty()) {
-               dim.wid = 0;
-               dim.asc = 0;
-               dim.des = 0;
-       }
+           && parent_.cell(parent_.displayIdx()).empty())
+               dim.clear();
 }
 
 
 void InsetDisplayLabelBox::draw(PainterInfo & pi, int x, int y) const
 {
        if (parent_.editing(pi.base.bv)
-           || !parent_.cell(parent_.displayIdx()).empty()) {
-               InsetLabelBox::draw(pi, x, y);
-       } else {
-               bool enabled = pi.pain.isDrawingEnabled();
-               pi.pain.setDrawingEnabled(false);
-               InsetLabelBox::draw(pi, x, y);
-               pi.pain.setDrawingEnabled(enabled);
-       }
+           || !parent_.cell(parent_.displayIdx()).empty()
+               || pi.pain.isNull())
+           InsetLabelBox::draw(pi, x, y);
 }
 
 
@@ -258,15 +249,15 @@ 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;
+       void metrics(MetricsInfo & mi, Dimension & dim) const override;
        ///
-       void draw(PainterInfo &, int x, int y) const;
+       void draw(PainterInfo &, int x, int y) const override;
 
 private:
        ///
-       Inset * clone() const;
+       Inset * clone() const override;
        ///
        MathData const * value_;
 };
@@ -294,32 +285,30 @@ 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;
+       void draw(PainterInfo &, int x, int y) const override;
        ///
-       void metrics(MetricsInfo & mi, Dimension & dim) const;
+       void metrics(MetricsInfo & mi, Dimension & dim) const override;
 
 protected:
        ///
-       Inset * clone() const;
-       ///
-       ColorCode min_;
+       Inset * clone() const override;
        ///
-       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);
 }
@@ -339,7 +328,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();
 }
@@ -352,15 +341,15 @@ public:
        ///
        InsetNameWrapper(MathData const * value, InsetMathMacroTemplate const & parent);
        ///
-       void metrics(MetricsInfo & mi, Dimension & dim) const;
+       void metrics(MetricsInfo & mi, Dimension & dim) const override;
        ///
-       void draw(PainterInfo &, int x, int y) const;
+       void draw(PainterInfo &, int x, int y) const override;
 
 private:
        ///
        InsetMathMacroTemplate const & parent_;
        ///
-       Inset * clone() const;
+       Inset * clone() const override;
 };
 
 
@@ -505,7 +494,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);
                        }
 
@@ -521,7 +510,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)));
@@ -530,7 +519,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)))));
        }
 
@@ -553,7 +542,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;
@@ -584,9 +573,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);
 }
 
 
@@ -595,22 +584,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);
 }
 
 
@@ -763,7 +754,7 @@ class OptionalsMacroInstanceFix
 {
 public:
        ///
-       OptionalsMacroInstanceFix(int optionals) : optionals_(optionals) {}
+       explicit OptionalsMacroInstanceFix(int optionals) : optionals_(optionals) {}
        ///
        void operator()(InsetMathMacro * macro)
        {
@@ -1096,7 +1087,7 @@ void InsetMathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
 
 
 bool InsetMathMacroTemplate::getStatus(Cursor & cur, FuncRequest const & cmd,
-       FuncStatus & flag) const
+       FuncStatus & status) const
 {
        bool ret = true;
        string const arg = to_utf8(cmd.argument());
@@ -1107,12 +1098,12 @@ bool InsetMathMacroTemplate::getStatus(Cursor & cur, FuncRequest const & cmd,
                                num = convert<int>(arg);
                        bool on = (num >= optionals_
                                   && numargs_ < 9 && num <= numargs_ + 1);
-                       flag.setEnabled(on);
+                       status.setEnabled(on);
                        break;
                }
 
                case LFUN_MATH_MACRO_APPEND_GREEDY_PARAM:
-                       flag.setEnabled(numargs_ < 9);
+                       status.setEnabled(numargs_ < 9);
                        break;
 
                case LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM:
@@ -1120,40 +1111,40 @@ bool InsetMathMacroTemplate::getStatus(Cursor & cur, FuncRequest const & cmd,
                        int num = numargs_;
                        if (!arg.empty())
                                num = convert<int>(arg);
-                       flag.setEnabled(num >= 1 && num <= numargs_);
+                       status.setEnabled(num >= 1 && num <= numargs_);
                        break;
                }
 
                case LFUN_MATH_MACRO_MAKE_OPTIONAL:
-                       flag.setEnabled(numargs_ > 0
+                       status.setEnabled(numargs_ > 0
                                     && optionals_ < numargs_
                                     && type_ != MacroTypeDef);
                        break;
 
                case LFUN_MATH_MACRO_MAKE_NONOPTIONAL:
-                       flag.setEnabled(optionals_ > 0
+                       status.setEnabled(optionals_ > 0
                                     && type_ != MacroTypeDef);
                        break;
 
                case LFUN_MATH_MACRO_ADD_OPTIONAL_PARAM:
-                       flag.setEnabled(numargs_ < 9);
+                       status.setEnabled(numargs_ < 9);
                        break;
 
                case LFUN_MATH_MACRO_REMOVE_OPTIONAL_PARAM:
-                       flag.setEnabled(optionals_ > 0);
+                       status.setEnabled(optionals_ > 0);
                        break;
 
                case LFUN_MATH_MACRO_ADD_GREEDY_OPTIONAL_PARAM:
-                       flag.setEnabled(numargs_ == 0
+                       status.setEnabled(numargs_ == 0
                                     && type_ != MacroTypeDef);
                        break;
 
                case LFUN_IN_MATHMACROTEMPLATE:
-                       flag.setEnabled(true);
+                       status.setEnabled(true);
                        break;
 
                default:
-                       ret = InsetMathNest::getStatus(cur, cmd, flag);
+                       ret = InsetMathNest::getStatus(cur, cmd, status);
                        break;
        }
        return ret;
@@ -1225,7 +1216,7 @@ int InsetMathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition)
                        //   \global\def\long\foo#1#2{#1,#2}
                        // We use the \long prefix as this is the equivalent to \newcommand.
                        // We cannot use \newcommand directly because \global does not work with it.
-                       os << "\\global\\long\\def\\" << name();
+                       os << "\n\\global\\long\\def\\" << name();
                        docstring param = from_ascii("#0");
                        for (int i = 1; i <= numargs_; ++i) {
                                param[1] = '0' + i;
@@ -1257,7 +1248,7 @@ int InsetMathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition)
 
        if (os.latex()) {
                // writing .tex. done.
-               os << "\n";
+               os << "%\n";
                ++num_lines;
        } else {
                // writing .lyx, write special .tex export only if necessary
@@ -1271,7 +1262,7 @@ int InsetMathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition)
 }
 
 
-docstring InsetMathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetMathMacroTemplate::xhtml(XMLStream &, OutputParams const &) const
 {
        return docstring();
 }
@@ -1300,11 +1291,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 (char_type c : n) {
+                       if (!(c >= 'a' && c <= 'z')
+                           && !(c >= 'A' && c <= 'Z')
+                           && c != '*')
+                               return false;
+               }
        }
 
        return true;