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 "funcrequest.h"
19 #include "metricsinfo.h"
21 #include "support/std_sstream.h"
23 using std::istringstream;
25 using std::ostringstream;
28 InsetCommand::InsetCommand(InsetCommandParams const & p)
29 : p_(p.getCmdName(), p.getContents(), p.getOptions()),
34 BufferView * InsetCommand::view() const
36 return button_.view();
40 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
44 button_.update(getScreenLabel(*mi.base.bv->buffer()),
45 editable() != NOT_EDITABLE);
47 button_.metrics(mi, dim);
52 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
54 button_.draw(pi, x, y);
58 void InsetCommand::setParams(InsetCommandParams const & p)
60 p_.setCmdName(p.getCmdName());
61 p_.setContents(p.getContents());
62 p_.setOptions(p.getOptions());
67 int InsetCommand::latex(Buffer const &, ostream & os,
68 LatexRunParams const &) const
75 int InsetCommand::ascii(Buffer const &, ostream &, int) const
81 int InsetCommand::linuxdoc(Buffer const &, ostream &) const
87 int InsetCommand::docbook(Buffer const &, ostream &, bool) const
93 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
96 case LFUN_INSET_MODIFY: {
98 InsetCommandMailer::string2params(cmd.argument, p);
99 if (p.getCmdName().empty())
103 cmd.view()->updateInset(this);
107 case LFUN_INSET_DIALOG_UPDATE:
108 InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
111 case LFUN_MOUSE_RELEASE:
112 return localDispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
115 return InsetOld::localDispatch(cmd);
121 InsetCommandMailer::InsetCommandMailer(string const & name,
122 InsetCommand & inset)
123 : name_(name), inset_(inset)
127 string const InsetCommandMailer::inset2string(Buffer const &) const
129 return params2string(name(), inset_.params());
133 void InsetCommandMailer::string2params(string const & in,
134 InsetCommandParams & params)
136 params.setCmdName(string());
137 params.setContents(string());
138 params.setOptions(string());
143 istringstream data(in);
149 string const name = lex.getString();
152 // This is part of the inset proper that is usually swallowed
153 // by Buffer::readInset
156 string const token = lex.getString();
157 if (token != "LatexCommand")
166 string const InsetCommandMailer::params2string(string const & name,
167 InsetCommandParams const & params)
172 data << "\\end_inset\n";