]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/CommandInset.cpp
fix off-by-two drawing error
[lyx.git] / src / mathed / CommandInset.cpp
index 67b56f506e688f2b707242250ccdb0cfbc145dd3..bd1a1b2dd78878f57d89359507bfe5e1dc36bfc3 100644 (file)
 
 #include <sstream>
 
+using namespace std;
 
 namespace lyx {
 
-using std::string;
 
-CommandInset::CommandInset(docstring const & name)
-       : InsetMathNest(2), name_(name), set_label_(false)
+CommandInset::CommandInset(docstring const & name, bool needs_math_mode)
+       : InsetMathNest(2), name_(name), needs_math_mode_(needs_math_mode),
+         set_label_(false)
 {
        lock_ = true;
 }
@@ -36,17 +37,15 @@ Inset * CommandInset::clone() const
 }
 
 
-bool CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
+void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        if (!set_label_) {
                set_label_ = true;
                button_.update(screenLabel(), true);
        }
        button_.metrics(mi, dim);
-       if (dim_ == dim)
-               return false;
-       dim_ = dim;
-       return true;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
@@ -66,6 +65,7 @@ void CommandInset::draw(PainterInfo & pi, int x, int y) const
 
 void CommandInset::write(WriteStream & os) const
 {
+       MathEnsurer ensurer(os, needs_math_mode_);
        os << '\\' << name_.c_str();
        if (cell(1).size())
                os << '[' << cell(1) << ']';