3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
14 #include "insetcommand.h"
16 #include "BufferView.h"
17 #include "dispatchresult.h"
18 #include "funcrequest.h"
19 #include "FuncStatus.h"
21 #include "metricsinfo.h"
29 using std::istringstream;
31 using std::ostringstream;
34 InsetCommand::InsetCommand(InsetCommandParams const & p,
35 string const & mailer_name)
37 mailer_name_(mailer_name),
38 updateButtonLabel_(true)
42 InsetCommand::~InsetCommand()
44 if (!mailer_name_.empty())
45 InsetCommandMailer(mailer_name_, *this).hideDialog();
49 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
51 if (updateButtonLabel_) {
52 updateButtonLabel_ = false;
53 button_.update(getScreenLabel(*mi.base.bv->buffer()),
54 editable() != NOT_EDITABLE);
56 button_.metrics(mi, dim);
61 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
63 setPosCache(pi, x, y);
64 button_.draw(pi, x, y);
68 void InsetCommand::setParams(InsetCommandParams const & p)
71 updateButtonLabel_ = true;
75 int InsetCommand::latex(Buffer const &, odocstream & os,
76 OutputParams const &) const
83 int InsetCommand::plaintext(Buffer const &, odocstream &,
84 OutputParams const &) const
90 int InsetCommand::docbook(Buffer const &, odocstream &,
91 OutputParams const &) const
97 void InsetCommand::doDispatch(LCursor & cur, FuncRequest & cmd)
100 case LFUN_INSET_REFRESH:
101 updateButtonLabel_ = true;
104 case LFUN_INSET_MODIFY: {
105 InsetCommandParams p(p_.getCmdName());
106 InsetCommandMailer::string2params(mailer_name_, to_utf8(cmd.argument()), p);
107 if (p.getCmdName().empty())
114 case LFUN_INSET_DIALOG_UPDATE: {
115 string const name = to_utf8(cmd.argument());
116 InsetCommandMailer(name, *this).updateDialog(&cur.bv());
120 case LFUN_MOUSE_RELEASE: {
121 if (!mailer_name_.empty())
122 InsetCommandMailer(mailer_name_, *this).showDialog(&cur.bv());
127 InsetBase::doDispatch(cur, cmd);
134 bool InsetCommand::getStatus(LCursor & cur, FuncRequest const & cmd,
135 FuncStatus & status) const
137 switch (cmd.action) {
139 case LFUN_ERT_INSERT:
140 status.enabled(false);
143 case LFUN_INSET_REFRESH:
144 case LFUN_INSET_MODIFY:
145 case LFUN_INSET_DIALOG_UPDATE:
146 status.enabled(true);
149 return InsetBase::getStatus(cur, cmd, status);
154 void InsetCommand::replaceContents(std::string const & from, string const & to)
156 if (getContents() == from)
161 InsetCommandMailer::InsetCommandMailer(string const & name,
162 InsetCommand & inset)
163 : name_(name), inset_(inset)
167 string const InsetCommandMailer::inset2string(Buffer const &) const
169 return params2string(name(), inset_.params());
173 void InsetCommandMailer::string2params(string const & name,
175 InsetCommandParams & params)
181 istringstream data(in);
187 if (!lex || n != name)
188 return print_mailer_error("InsetCommandMailer", in, 1, name);
190 // This is part of the inset proper that is usually swallowed
191 // by LyXText::readInset
194 if (!lex || id != "LatexCommand")
195 return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand");
202 InsetCommandMailer::params2string(string const & name,
203 InsetCommandParams const & params)
208 data << "\\end_inset\n";