2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetcommand.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetcommand.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2003-02-26 15:01:10 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "lyxlex.h"
|
2003-06-12 08:52:36 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2003-02-26 15:01:10 +00:00
|
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetCommand::InsetCommand(InsetCommandParams const & p)
|
2003-06-12 08:52:36 +00:00
|
|
|
|
: p_(p.getCmdName(), p.getContents(), p.getOptions()),
|
|
|
|
|
set_label_(false)
|
2001-07-24 15:07:09 +00:00
|
|
|
|
{}
|
2000-08-04 13:12:30 +00:00
|
|
|
|
|
|
|
|
|
|
2003-06-12 08:52:36 +00:00
|
|
|
|
void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
if (!set_label_) {
|
|
|
|
|
set_label_ = true;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
button_.update(getScreenLabel(*mi.base.bv->buffer()),
|
2003-06-12 08:52:36 +00:00
|
|
|
|
editable() != NOT_EDITABLE);
|
|
|
|
|
}
|
|
|
|
|
button_.metrics(mi, dim);
|
2003-07-18 07:47:07 +00:00
|
|
|
|
dim_ = dim;
|
2003-06-12 08:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCommand::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
button_.draw(pi, x, y);
|
2003-06-03 15:10:14 +00:00
|
|
|
|
}
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
void InsetCommand::setParams(InsetCommandParams const & p)
|
2000-08-04 13:12:30 +00:00
|
|
|
|
{
|
2003-09-18 22:26:46 +00:00
|
|
|
|
p_ = p;
|
2003-06-12 08:52:36 +00:00
|
|
|
|
set_label_ = false;
|
2000-08-04 13:12:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetCommand::latex(Buffer const &, ostream & os,
|
2003-05-23 08:59:47 +00:00
|
|
|
|
LatexRunParams const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << getCommand();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetCommand::ascii(Buffer const &, ostream &, int) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetCommand::linuxdoc(Buffer const &, ostream &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetCommand::docbook(Buffer const &, ostream &, bool) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
|
dispatch_result
|
|
|
|
|
InsetCommand::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
|
2003-02-26 15:01:10 +00:00
|
|
|
|
{
|
2003-03-07 15:58:02 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetCommandParams p;
|
|
|
|
|
InsetCommandMailer::string2params(cmd.argument, p);
|
|
|
|
|
if (p.getCmdName().empty())
|
2003-05-16 07:44:00 +00:00
|
|
|
|
return UNDISPATCHED;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
|
|
|
|
|
setParams(p);
|
2003-08-27 13:51:18 +00:00
|
|
|
|
cmd.view()->updateInset(this);
|
2003-05-16 07:44:00 +00:00
|
|
|
|
return DISPATCHED;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
2003-02-26 19:28:38 +00:00
|
|
|
|
|
2003-05-16 07:44:00 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
InsetCommandMailer(cmd.argument, *this).updateDialog(cmd.view());
|
|
|
|
|
return DISPATCHED;
|
2003-02-26 15:01:10 +00:00
|
|
|
|
|
2003-03-09 09:38:47 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2003-10-17 18:01:15 +00:00
|
|
|
|
return dispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
|
2003-03-09 09:38:47 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
default:
|
2003-10-13 01:53:45 +00:00
|
|
|
|
return UNDISPATCHED;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
2003-02-26 15:01:10 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-11 11:52:05 +00:00
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
InsetCommandMailer::InsetCommandMailer(string const & name,
|
|
|
|
|
InsetCommand & inset)
|
|
|
|
|
: name_(name), inset_(inset)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetCommandMailer::inset2string(Buffer const &) const
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
2003-02-27 13:26:07 +00:00
|
|
|
|
return params2string(name(), inset_.params());
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCommandMailer::string2params(string const & in,
|
|
|
|
|
InsetCommandParams & params)
|
|
|
|
|
{
|
2003-09-19 10:16:33 +00:00
|
|
|
|
params = InsetCommandParams();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
2003-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream data(in);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
|
lex.setStream(data);
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const name = lex.getString();
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-10 03:11:54 +00:00
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
|
// by Buffer::readInset
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
if (token != "LatexCommand")
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
params.read(lex);
|
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-13 16:24:49 +00:00
|
|
|
|
string const InsetCommandMailer::params2string(string const & name,
|
2003-02-27 13:26:07 +00:00
|
|
|
|
InsetCommandParams const & params)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
2003-02-27 13:26:07 +00:00
|
|
|
|
data << name << ' ';
|
2003-02-25 14:51:38 +00:00
|
|
|
|
params.write(data);
|
|
|
|
|
data << "\\end_inset\n";
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return data.str();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|