2 * \file CommandInset.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "CommandInset.h"
15 #include "MathStream.h"
16 #include "DispatchResult.h"
17 #include "FuncRequest.h"
26 CommandInset::CommandInset(docstring const & name, bool needs_math_mode)
27 : InsetMathNest(2), name_(name), needs_math_mode_(needs_math_mode),
34 Inset * CommandInset::clone() const
36 return new CommandInset(*this);
40 void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
44 button_.update(screenLabel(), true);
46 button_.metrics(mi, dim);
47 // Cache the inset dimension.
52 Inset * CommandInset::editXY(Cursor & cur, int /*x*/, int /*y*/)
59 void CommandInset::draw(PainterInfo & pi, int x, int y) const
61 button_.draw(pi, x, y);
62 setPosCache(pi, x, y);
66 void CommandInset::write(WriteStream & os) const
68 bool brace = os.pendingBrace();
69 os.pendingBrace(false);
70 if (os.latex() && os.textMode() && needs_math_mode_) {
71 os << "\\ensuremath{";
74 os << '\\' << name_.c_str();
76 os << '[' << cell(1) << ']';
77 os << '{' << cell(0) << '}';
78 os.pendingBrace(brace);
82 docstring const CommandInset::screenLabel() const