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"
15 #include "BufferView.h"
17 #include "funcrequest.h"
19 #include "metricsinfo.h"
21 #include "frontends/Painter.h"
23 #include "support/lstrings.h"
30 InsetCommand::InsetCommand(InsetCommandParams const & p)
31 : p_(p.getCmdName(), p.getContents(), p.getOptions()),
36 BufferView * InsetCommand::view() const
38 return button_.view();
42 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
46 button_.update(getScreenLabel(mi.base.bv->buffer()),
47 editable() != NOT_EDITABLE);
49 button_.metrics(mi, dim);
53 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
55 button_.draw(pi, x, y);
59 void InsetCommand::setParams(InsetCommandParams const & p)
61 p_.setCmdName(p.getCmdName());
62 p_.setContents(p.getContents());
63 p_.setOptions(p.getOptions());
68 int InsetCommand::latex(Buffer const *, ostream & os,
69 LatexRunParams const &) const
76 int InsetCommand::ascii(Buffer const *, ostream &, int) const
82 int InsetCommand::linuxdoc(Buffer const *, ostream &) const
88 int InsetCommand::docbook(Buffer const *, ostream &, bool) const
94 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
97 case LFUN_INSET_MODIFY: {
99 InsetCommandMailer::string2params(cmd.argument, p);
100 if (p.getCmdName().empty())
104 cmd.view()->updateInset(this);
108 case LFUN_INSET_DIALOG_UPDATE:
109 InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
112 case LFUN_MOUSE_RELEASE:
113 return localDispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
122 InsetCommandMailer::InsetCommandMailer(string const & name,
123 InsetCommand & inset)
124 : name_(name), inset_(inset)
128 string const InsetCommandMailer::inset2string() const
130 return params2string(name(), inset_.params());
134 void InsetCommandMailer::string2params(string const & in,
135 InsetCommandParams & params)
137 params.setCmdName(string());
138 params.setContents(string());
139 params.setOptions(string());
144 istringstream data(STRCONV(in));
150 string const name = lex.getString();
153 // This is part of the inset proper that is usually swallowed
154 // by Buffer::readInset
157 string const token = lex.getString();
158 if (token != "LatexCommand")
167 string const InsetCommandMailer::params2string(string const & name,
168 InsetCommandParams const & params)
173 data << "\\end_inset\n";
174 return STRCONV(data.str());