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"
20 #include "metricsinfo.h"
26 using std::istringstream;
28 using std::ostringstream;
31 InsetCommand::InsetCommand(InsetCommandParams const & p,
32 string const & mailer_name)
33 : p_(p.getCmdName(), p.getContents(), p.getOptions(), p.getSecOptions()),
34 mailer_name_(mailer_name),
39 InsetCommand::~InsetCommand()
41 if (!mailer_name_.empty())
42 InsetCommandMailer(mailer_name_, *this).hideDialog();
46 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
50 button_.update(getScreenLabel(*mi.base.bv->buffer()),
51 editable() != NOT_EDITABLE);
53 button_.metrics(mi, dim);
58 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
60 setPosCache(pi, x, y);
61 button_.draw(pi, x, y);
65 void InsetCommand::setParams(InsetCommandParams const & p)
72 int InsetCommand::latex(Buffer const &, ostream & os,
73 OutputParams const &) const
80 int InsetCommand::plaintext(Buffer const &, ostream &,
81 OutputParams const &) const
87 int InsetCommand::linuxdoc(Buffer const &, ostream &,
88 OutputParams const &) const
94 int InsetCommand::docbook(Buffer const &, ostream &,
95 OutputParams const &) const
101 void InsetCommand::doDispatch(LCursor & cur, FuncRequest & cmd)
103 switch (cmd.action) {
104 case LFUN_INSET_REFRESH:
108 case LFUN_INSET_MODIFY: {
109 InsetCommandParams p;
110 InsetCommandMailer::string2params(mailer_name_, cmd.argument, p);
111 if (p.getCmdName().empty()) {
120 case LFUN_INSET_DIALOG_UPDATE:
121 InsetCommandMailer(cmd.argument, *this).updateDialog(&cur.bv());
124 case LFUN_INSET_DIALOG_SHOW:
125 case LFUN_MOUSE_RELEASE: {
126 if (!mailer_name_.empty())
127 InsetCommandMailer(mailer_name_, *this).showDialog(&cur.bv());
132 InsetBase::doDispatch(cur, cmd);
139 InsetCommandMailer::InsetCommandMailer(string const & name,
140 InsetCommand & inset)
141 : name_(name), inset_(inset)
145 string const InsetCommandMailer::inset2string(Buffer const &) const
147 return params2string(name(), inset_.params());
151 void InsetCommandMailer::string2params(string const & name,
153 InsetCommandParams & params)
155 params = InsetCommandParams();
159 istringstream data(in);
165 if (!lex || n != name)
166 return print_mailer_error("InsetCommandMailer", in, 1, name);
168 // This is part of the inset proper that is usually swallowed
169 // by LyXText::readInset
172 if (!lex || id != "LatexCommand")
173 return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand");
180 InsetCommandMailer::params2string(string const & name,
181 InsetCommandParams const & params)
186 data << "\\end_inset\n";