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);
54 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
56 button_.draw(pi, x, y);
60 void InsetCommand::setParams(InsetCommandParams const & p)
62 p_.setCmdName(p.getCmdName());
63 p_.setContents(p.getContents());
64 p_.setOptions(p.getOptions());
69 int InsetCommand::latex(Buffer const &, ostream & os,
70 LatexRunParams const &) const
77 int InsetCommand::ascii(Buffer const &, ostream &, int) const
83 int InsetCommand::linuxdoc(Buffer const &, ostream &) const
89 int InsetCommand::docbook(Buffer const &, ostream &, bool) const
95 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
98 case LFUN_INSET_MODIFY: {
100 InsetCommandMailer::string2params(cmd.argument, p);
101 if (p.getCmdName().empty())
105 cmd.view()->updateInset(this);
109 case LFUN_INSET_DIALOG_UPDATE:
110 InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
113 case LFUN_MOUSE_RELEASE:
114 return localDispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
117 return InsetOld::localDispatch(cmd);
123 InsetCommandMailer::InsetCommandMailer(string const & name,
124 InsetCommand & inset)
125 : name_(name), inset_(inset)
129 string const InsetCommandMailer::inset2string(Buffer const &) const
131 return params2string(name(), inset_.params());
135 void InsetCommandMailer::string2params(string const & in,
136 InsetCommandParams & params)
138 params.setCmdName(string());
139 params.setContents(string());
140 params.setOptions(string());
145 istringstream data(STRCONV(in));
151 string const name = lex.getString();
154 // This is part of the inset proper that is usually swallowed
155 // by Buffer::readInset
158 string const token = lex.getString();
159 if (token != "LatexCommand")
168 string const InsetCommandMailer::params2string(string const & name,
169 InsetCommandParams const & params)
174 data << "\\end_inset\n";
175 return STRCONV(data.str());