]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathMacro.cpp
Revert "Fix a number of signedness warnings"
[lyx.git] / src / mathed / InsetMathMacro.cpp
index 144318130ae52bddf49208f234c6b78e2bd5f37d..57294c075354d889ad4513b406b4fd9ebe22d717 100644 (file)
@@ -64,7 +64,7 @@ public:
                        asArray(def, def_);
        }
        ///
-       void setBuffer(Buffer & buffer)
+       void setBuffer(Buffer & buffer) override
        {
                Inset::setBuffer(buffer);
                def_.setBuffer(buffer);
@@ -74,9 +74,9 @@ public:
        ///
        InsetMathMacro const * owner() { return mathMacro_; }
        ///
-       marker_type marker(BufferView const *) const { return NO_MARKER; }
+       marker_type marker(BufferView const *) const override { return NO_MARKER; }
        ///
-       InsetCode lyxCode() const { return ARGUMENT_PROXY_CODE; }
+       InsetCode lyxCode() const override { return ARGUMENT_PROXY_CODE; }
        /// The math data to use for display
        MathData const & displayCell(BufferView const * bv) const
        {
@@ -86,7 +86,7 @@ public:
                return use_def_arg ? def_ : mathMacro_->cell(idx_);
        }
        ///
-       bool addToMathRow(MathRow & mrow, MetricsInfo & mi) const
+       bool addToMathRow(MathRow & mrow, MetricsInfo & mi) const override
        {
                // macro arguments are in macros
                LATTEST(mathMacro_->nesting() > 0);
@@ -121,17 +121,17 @@ public:
                return has_contents;
        }
        ///
-       void beforeMetrics() const
+       void beforeMetrics() const override
        {
                mathMacro_->macro()->unlock();
        }
        ///
-       void afterMetrics() const
+       void afterMetrics() const override
        {
                mathMacro_->macro()->lock();
        }
        ///
-       void beforeDraw(PainterInfo const & pi) const
+       void beforeDraw(PainterInfo const & pi) const override
        {
                // if the macro is being edited, then the painter is in
                // monochrome mode.
@@ -139,42 +139,42 @@ public:
                        pi.pain.leaveMonochromeMode();
        }
        ///
-       void afterDraw(PainterInfo const & pi) const
+       void afterDraw(PainterInfo const & pi) const override
        {
                if (mathMacro_->editMetrics(pi.base.bv))
                        pi.pain.enterMonochromeMode(Color_mathmacroblend);
        }
        ///
-       void metrics(MetricsInfo &, Dimension &) const {
+       void metrics(MetricsInfo &, Dimension &) const override {
                // This should never be invoked, since InsetArgumentProxy insets are linearized
                LATTEST(false);
        }
        ///
-       void draw(PainterInfo &, int, int) const {
+       void draw(PainterInfo &, int, int) const override {
                // This should never be invoked, since InsetArgumentProxy insets are linearized
                LATTEST(false);
        }
        ///
-       int kerning(BufferView const * bv) const
+       int kerning(BufferView const * bv) const override
        {
                return displayCell(bv).kerning(bv);
        }
        // write(), normalize(), infoize() and infoize2() are not needed since
        // InsetMathMacro uses the definition and not the expanded cells.
        ///
-       void maple(MapleStream & ms) const { ms << mathMacro_->cell(idx_); }
+       void maple(MapleStream & ms) const override { ms << mathMacro_->cell(idx_); }
        ///
-       void maxima(MaximaStream & ms) const { ms << mathMacro_->cell(idx_); }
+       void maxima(MaximaStream & ms) const override { ms << mathMacro_->cell(idx_); }
        ///
-       void mathematica(MathematicaStream & ms) const { ms << mathMacro_->cell(idx_); }
+       void mathematica(MathematicaStream & ms) const override { ms << mathMacro_->cell(idx_); }
        ///
-       void mathmlize(MathStream & ms) const { ms << mathMacro_->cell(idx_); }
+       void mathmlize(MathStream & ms) const override { ms << mathMacro_->cell(idx_); }
        ///
-       void htmlize(HtmlStream & ms) const { ms << mathMacro_->cell(idx_); }
+       void htmlize(HtmlStream & ms) const override { ms << mathMacro_->cell(idx_); }
        ///
-       void octave(OctaveStream & os) const { os << mathMacro_->cell(idx_); }
+       void octave(OctaveStream & os) const override { os << mathMacro_->cell(idx_); }
        ///
-       MathClass mathClass() const
+       MathClass mathClass() const override
        {
                return MC_UNKNOWN;
                // This can be refined once the pointer issues are fixed. I did not
@@ -185,7 +185,7 @@ public:
 
 private:
        ///
-       Inset * clone() const
+       Inset * clone() const override
        {
                return new InsetArgumentProxy(*this);
        }
@@ -205,8 +205,8 @@ public:
                : name_(name), displayMode_(DISPLAY_INIT),
                  expanded_(buf), definition_(buf), attachedArgsNum_(0),
                  optionals_(0), nextFoldMode_(true), macroBackup_(buf),
-                 macro_(0), needsUpdate_(false), isUpdating_(false),
-                 appetite_(9), nesting_(0)
+                 macro_(nullptr), needsUpdate_(false), isUpdating_(false),
+                 appetite_(9), nesting_(0), limits_(AUTO_LIMITS)
        {
        }
        /// Update the pointers to our owner of all expanded macros.
@@ -248,6 +248,8 @@ public:
        size_t appetite_;
        /// Level of nesting in macros (including this one)
        int nesting_;
+       ///
+       Limits limits_;
 };
 
 
@@ -371,6 +373,7 @@ bool InsetMathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
        return has_contents;
 }
 
+
 /// Whether the inset allows \(no)limits
 bool InsetMathMacro::allowsLimitsChange() const
 {
@@ -403,6 +406,18 @@ Limits InsetMathMacro::defaultLimits() const
 }
 
 
+Limits InsetMathMacro::limits() const
+{
+       return d->limits_;
+}
+
+
+void InsetMathMacro::limits(Limits lim)
+{
+       d->limits_ = lim;
+}
+
+
 void InsetMathMacro::beforeMetrics() const
 {
        d->macro_->lock();
@@ -634,7 +649,7 @@ void InsetMathMacro::updateMacro(MacroContext const & mc)
                        d->needsUpdate_ = true;
                }
        } else {
-               d->macro_ = 0;
+               d->macro_ = nullptr;
        }
 }
 
@@ -669,7 +684,7 @@ void InsetMathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc,
        UpdateLocker locker(*this);
 
        // known macro?
-       if (d->macro_ == 0)
+       if (d->macro_ == nullptr)
                return;
 
        // remember nesting level of this macro
@@ -822,7 +837,7 @@ void InsetMathMacro::setDisplayMode(InsetMathMacro::DisplayMode mode, int appeti
 
 InsetMathMacro::DisplayMode InsetMathMacro::computeDisplayMode() const
 {
-       if (d->nextFoldMode_ == true && d->macro_ && !d->macro_->locked())
+       if (d->nextFoldMode_ && d->macro_ && !d->macro_->locked())
                return DISPLAY_NORMAL;
        else
                return DISPLAY_UNFOLDED;
@@ -844,10 +859,10 @@ bool InsetMathMacro::validName() const
 
        // valid characters?
        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] != '*')
+               for (char_type c : n) {
+                       if (!(c >= 'a' && c <= 'z')
+                           && !(c >= 'A' && c <= 'Z')
+                           && c != '*')
                                return false;
                }
        }
@@ -952,7 +967,16 @@ void InsetMathMacro::validate(LaTeXFeatures & features) const
 
        // validate the cells and the definition
        if (displayMode() == DISPLAY_NORMAL) {
-               d->definition_.validate(features);
+               // Don't update requirements if the macro comes from
+               // the symbols file and has not been redefined.
+               MathWordList const & words = mathedWordList();
+               MathWordList::const_iterator it = words.find(name());
+               MacroNameSet macros;
+               buffer().listMacroNames(macros);
+               if (it == words.end() || it->second.inset != "macro"
+                   || macros.find(name()) != macros.end()) {
+                       d->definition_.validate(features);
+               }
                InsetMathNest::validate(features);
        }
 }
@@ -1148,10 +1172,10 @@ void InsetMathMacro::write(WriteStream & os) const
                // contains macros with optionals.
                bool braced = false;
                size_type last = cell(i).size() - 1;
-               if (cell(i).size() && cell(i)[last]->asUnknownInset()) {
+               if (!cell(i).empty() && cell(i)[last]->asUnknownInset()) {
                        latexkeys const * l = in_word_set(cell(i)[last]->name());
                        braced = (l && l->inset == "big");
-               } else if (cell(i).size() && cell(i)[0]->asScriptInset()) {
+               } else if (!cell(i).empty() && cell(i)[0]->asScriptInset()) {
                        braced = cell(i)[0]->asScriptInset()->nuc().empty();
                } else {
                        for (size_type j = 0; j < cell(i).size(); ++j) {