X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathAMSArray.cpp;h=9a9a3495bc7434392afc1e41aa5e6d2c5519106c;hb=5fdc577badb1cb133d6a0dc7d831bb1f82576adb;hp=3febc45cb1c0a603bc6d79e2aff335640ce8ffa7;hpb=f497296c30e6da2f97b16da8ad1c9e96feffb16b;p=lyx.git diff --git a/src/mathed/InsetMathAMSArray.cpp b/src/mathed/InsetMathAMSArray.cpp index 3febc45cb1..9a9a3495bc 100644 --- a/src/mathed/InsetMathAMSArray.cpp +++ b/src/mathed/InsetMathAMSArray.cpp @@ -3,47 +3,51 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author André Pönitz + * \author André Pönitz * * Full author contact details are available in file CREDITS. */ #include -#include "LaTeXFeatures.h" #include "InsetMathAMSArray.h" + +#include "LaTeXFeatures.h" #include "MathData.h" #include "MathStream.h" -#include "MathStream.h" #include "MathSupport.h" +#include "MetricsInfo.h" -#include "funcrequest.h" +#include "FuncRequest.h" #include "FuncStatus.h" -#include "gettext.h" +#include "support/gettext.h" #include "support/lstrings.h" -#include "support/std_ostream.h" -using std::auto_ptr; +#include +#include -namespace lyx { -using support::bformat; +using namespace std; +using namespace lyx::support; + +namespace lyx { -InsetMathAMSArray::InsetMathAMSArray(docstring const & name, int m, int n) - : InsetMathGrid(m, n), name_(name) +InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name, + int m, int n) + : InsetMathGrid(buf, m, n), name_(name) {} -InsetMathAMSArray::InsetMathAMSArray(docstring const & name) - : InsetMathGrid(1, 1), name_(name) +InsetMathAMSArray::InsetMathAMSArray(Buffer * buf, docstring const & name) + : InsetMathGrid(buf, 1, 1), name_(name) {} -auto_ptr InsetMathAMSArray::doClone() const +Inset * InsetMathAMSArray::clone() const { - return auto_ptr(new InsetMathAMSArray(*this)); + return new InsetMathAMSArray(*this); } @@ -79,53 +83,58 @@ char const * InsetMathAMSArray::name_right() const } -bool InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const +void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const { - ArrayChanger dummy(mi.base); + Changer dummy2 = mi.base.changeEnsureMath(); + Changer dummy = mi.base.changeArray(); InsetMathGrid::metrics(mi, dim); - dim.wid += 14; - bool const changed = dim_ != dim; - dim_ = dim; - return changed; } void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const { - int const yy = y - dim_.ascent(); - // Drawing the deco after an ArrayChanger does not work - mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), from_ascii(name_left())); - mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), from_ascii(name_right())); - ArrayChanger dummy(pi.base); - InsetMathGrid::drawWithMargin(pi, x, y, 6, 8); + Changer dummy2 = pi.base.changeEnsureMath(); + Dimension const dim = dimension(*pi.base.bv); + int const yy = y - dim.ascent(); + // Drawing the deco after changeStyle does not work + mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left())); + mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right())); + Changer dummy = pi.base.changeArray(); + InsetMathGrid::draw(pi, x, y); } -bool InsetMathAMSArray::getStatus(LCursor & cur, FuncRequest const & cmd, +bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { - switch (cmd.action) { + switch (cmd.action()) { case LFUN_TABULAR_FEATURE: { - docstring const & s = cmd.argument(); + string s = cmd.getArg(0); if (s == "add-vline-left" || s == "add-vline-right") { flag.message(bformat( - from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_)); - flag.enabled(false); + from_utf8(N_("Can't add vertical grid lines in '%1$s'")), + name_)); + flag.setEnabled(false); return true; } - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } default: - return InsetMathGrid::getStatus(cur, cmd, flag); + break; } + return InsetMathGrid::getStatus(cur, cmd, flag); } void InsetMathAMSArray::write(WriteStream & os) const { + MathEnsurer ensurer(os); os << "\\begin{" << name_ << '}'; + bool open = os.startOuterRow(); InsetMathGrid::write(os); os << "\\end{" << name_ << '}'; + if (open) + os.startOuterRow(); } @@ -147,7 +156,12 @@ void InsetMathAMSArray::normalize(NormalStream & os) const void InsetMathAMSArray::validate(LaTeXFeatures & features) const { - features.require("amsmath"); + if (name_ == "CD") + // amscd is independent of amsmath although it is part of + // the amsmath bundle + features.require("amscd"); + else + features.require("amsmath"); InsetMathGrid::validate(features); }