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"
26 InsetCommand::InsetCommand(InsetCommandParams const & p)
27 : p_(p.getCmdName(), p.getContents(), p.getOptions()),
32 BufferView * InsetCommand::view() const
34 return button_.view();
38 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
42 button_.update(getScreenLabel(*mi.base.bv->buffer()),
43 editable() != NOT_EDITABLE);
45 button_.metrics(mi, dim);
50 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
52 button_.draw(pi, x, y);
56 void InsetCommand::setParams(InsetCommandParams const & p)
58 p_.setCmdName(p.getCmdName());
59 p_.setContents(p.getContents());
60 p_.setOptions(p.getOptions());
65 int InsetCommand::latex(Buffer const &, ostream & os,
66 LatexRunParams const &) const
73 int InsetCommand::ascii(Buffer const &, ostream &, int) const
79 int InsetCommand::linuxdoc(Buffer const &, ostream &) const
85 int InsetCommand::docbook(Buffer const &, ostream &, bool) const
91 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
94 case LFUN_INSET_MODIFY: {
96 InsetCommandMailer::string2params(cmd.argument, p);
97 if (p.getCmdName().empty())
101 cmd.view()->updateInset(this);
105 case LFUN_INSET_DIALOG_UPDATE:
106 InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
109 case LFUN_MOUSE_RELEASE:
110 return localDispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
113 return InsetOld::localDispatch(cmd);
119 InsetCommandMailer::InsetCommandMailer(string const & name,
120 InsetCommand & inset)
121 : name_(name), inset_(inset)
125 string const InsetCommandMailer::inset2string(Buffer const &) const
127 return params2string(name(), inset_.params());
131 void InsetCommandMailer::string2params(string const & in,
132 InsetCommandParams & params)
134 params.setCmdName(string());
135 params.setContents(string());
136 params.setOptions(string());
141 istringstream data(STRCONV(in));
147 string const name = lex.getString();
150 // This is part of the inset proper that is usually swallowed
151 // by Buffer::readInset
154 string const token = lex.getString();
155 if (token != "LatexCommand")
164 string const InsetCommandMailer::params2string(string const & name,
165 InsetCommandParams const & params)
170 data << "\\end_inset\n";
171 return STRCONV(data.str());