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(FuncRequest const & cmd, idx_type &, pos_type &)
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 cmd.view()->update();
114 return DispatchResult(true, true);
117 case LFUN_INSET_DIALOG_UPDATE:
118 InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
119 return DispatchResult(true, true);
121 case LFUN_INSET_DIALOG_SHOW:
122 case LFUN_MOUSE_RELEASE: {
123 if (!mailer_name_.empty())
124 InsetCommandMailer(mailer_name_, *this).
125 showDialog(cmd.view());
126 return DispatchResult(true);
130 return DispatchResult(false);
136 InsetCommandMailer::InsetCommandMailer(string const & name,
137 InsetCommand & inset)
138 : name_(name), inset_(inset)
142 string const InsetCommandMailer::inset2string(Buffer const &) const
144 return params2string(name(), inset_.params());
148 void InsetCommandMailer::string2params(string const & name,
150 InsetCommandParams & params)
152 params = InsetCommandParams();
156 istringstream data(in);
162 if (!lex || n != name)
163 return print_mailer_error("InsetCommandMailer", in, 1, name);
165 // This is part of the inset proper that is usually swallowed
166 // by LyXText::readInset
169 if (!lex || id != "LatexCommand")
170 return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand");
177 InsetCommandMailer::params2string(string const & name,
178 InsetCommandParams const & params)
183 data << "\\end_inset\n";