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 : p_(p.getCmdName(), p.getContents(), p.getOptions()),
37 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
41 button_.update(getScreenLabel(*mi.base.bv->buffer()),
42 editable() != NOT_EDITABLE);
44 button_.metrics(mi, dim);
49 void InsetCommand::draw(PainterInfo & pi, int x, int y) const
51 button_.draw(pi, x, y);
55 void InsetCommand::setParams(InsetCommandParams const & p)
62 int InsetCommand::latex(Buffer const &, ostream & os,
63 LatexRunParams const &) const
70 int InsetCommand::ascii(Buffer const &, ostream &,
71 LatexRunParams const &) const
77 int InsetCommand::linuxdoc(Buffer const &, ostream &,
78 LatexRunParams const &) const
84 int InsetCommand::docbook(Buffer const &, ostream &,
85 LatexRunParams const &) const
92 InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
95 case LFUN_INSET_MODIFY: {
97 InsetCommandMailer::string2params(cmd.argument, p);
98 if (p.getCmdName().empty())
99 return DispatchResult(UNDISPATCHED);
102 cmd.view()->updateInset(this);
103 return DispatchResult(DISPATCHED);
106 case LFUN_INSET_DIALOG_UPDATE:
107 InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
108 return DispatchResult(DISPATCHED);
110 case LFUN_MOUSE_RELEASE:
111 return dispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
114 return DispatchResult(UNDISPATCHED);
120 InsetCommandMailer::InsetCommandMailer(string const & name,
121 InsetCommand & inset)
122 : name_(name), inset_(inset)
126 string const InsetCommandMailer::inset2string(Buffer const &) const
128 return params2string(name(), inset_.params());
132 void InsetCommandMailer::string2params(string const & in,
133 InsetCommandParams & params)
135 params = InsetCommandParams();
140 istringstream data(in);
146 string const name = lex.getString();
149 // This is part of the inset proper that is usually swallowed
150 // by Buffer::readInset
153 string const token = lex.getString();
154 if (token != "LatexCommand")
163 string const InsetCommandMailer::params2string(string const & name,
164 InsetCommandParams const & params)
169 data << "\\end_inset\n";