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"
22 #include "support/std_sstream.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()),
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
62 button_.draw(pi, x, y);
66 void InsetCommand::setParams(InsetCommandParams const & p)
73 int InsetCommand::latex(Buffer const &, ostream & os,
74 OutputParams const &) const
81 int InsetCommand::plaintext(Buffer const &, ostream &,
82 OutputParams const &) const
88 int InsetCommand::linuxdoc(Buffer const &, ostream &,
89 OutputParams const &) const
95 int InsetCommand::docbook(Buffer const &, ostream &,
96 OutputParams const &) const
103 InsetCommand::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
105 switch (cmd.action) {
106 case LFUN_INSET_MODIFY: {
107 InsetCommandParams p;
108 InsetCommandMailer::string2params(mailer_name_, cmd.argument, p);
109 if (p.getCmdName().empty())
110 return DispatchResult(false);
113 return DispatchResult(true, true);
116 case LFUN_INSET_DIALOG_UPDATE:
117 InsetCommandMailer(cmd.argument, *this).updateDialog(&bv);
118 return DispatchResult(true, true);
120 case LFUN_INSET_DIALOG_SHOW:
121 case LFUN_MOUSE_RELEASE: {
122 if (!mailer_name_.empty())
123 InsetCommandMailer(mailer_name_, *this).showDialog(&bv);
124 return DispatchResult(true);
128 return DispatchResult(false);
134 InsetCommandMailer::InsetCommandMailer(string const & name,
135 InsetCommand & inset)
136 : name_(name), inset_(inset)
140 string const InsetCommandMailer::inset2string(Buffer const &) const
142 return params2string(name(), inset_.params());
146 void InsetCommandMailer::string2params(string const & name,
148 InsetCommandParams & params)
150 params = InsetCommandParams();
154 istringstream data(in);
160 if (!lex || n != name)
161 return print_mailer_error("InsetCommandMailer", in, 1, name);
163 // This is part of the inset proper that is usually swallowed
164 // by LyXText::readInset
167 if (!lex || id != "LatexCommand")
168 return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand");
175 InsetCommandMailer::params2string(string const & name,
176 InsetCommandParams const & params)
181 data << "\\end_inset\n";