A bit more re-organization.
[lyx.git] / src / mathed / CommandInset.cpp
blobbe67c3d52e63d0316361b711ff0b11a1d3bbb532
1 /**
2 * \file CommandInset.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author André Pönitz
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "CommandInset.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "DispatchResult.h"
17 #include "FuncRequest.h"
19 #include <sstream>
21 using namespace std;
23 namespace lyx {
26 CommandInset::CommandInset(Buffer * buf, docstring const & name, bool needs_math_mode)
27 : InsetMathNest(buf, 2), name_(name), needs_math_mode_(needs_math_mode),
28 set_label_(false)
30 lock_ = true;
34 Inset * CommandInset::clone() const
36 return new CommandInset(*this);
40 void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
42 if (!set_label_) {
43 set_label_ = true;
44 button_.update(screenLabel(), true);
46 button_.metrics(mi, dim);
47 // Cache the inset dimension.
48 setDimCache(mi, dim);
52 Inset * CommandInset::editXY(Cursor & cur, int /*x*/, int /*y*/)
54 edit(cur, true);
55 return this;
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 MathEnsurer ensurer(os, needs_math_mode_);
69 os << '\\' << name_.c_str();
70 if (cell(1).size())
71 os << '[' << cell(1) << ']';
72 os << '{' << cell(0) << '}';
76 docstring const CommandInset::screenLabel() const
78 return name_;
81 } // namespace lyx