2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file command_inset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
|
#include "command_inset.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_data.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2002-08-19 10:11:13 +00:00
|
|
|
|
#include "funcrequest.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
2003-03-04 18:54:56 +00:00
|
|
|
|
CommandInset::CommandInset(string const & name)
|
2004-04-18 19:57:58 +00:00
|
|
|
|
: MathNestInset(2), name_(name), set_label_(false)
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
|
|
|
|
lock_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> CommandInset::doClone() const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new CommandInset(*this));
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-12 08:52:36 +00:00
|
|
|
|
void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
if (!set_label_) {
|
|
|
|
|
set_label_ = true;
|
|
|
|
|
button_.update(screenLabel(), true);
|
|
|
|
|
}
|
|
|
|
|
button_.metrics(mi, dim);
|
2004-04-18 19:57:58 +00:00
|
|
|
|
dim_ = dim;
|
2003-06-12 08:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CommandInset::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
button_.draw(pi, x, y);
|
2004-04-07 16:54:15 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2003-06-12 08:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
|
2002-06-24 15:51:35 +00:00
|
|
|
|
void CommandInset::write(WriteStream & os) const
|
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '\\' << name_.c_str();
|
2002-06-24 15:51:35 +00:00
|
|
|
|
if (cell(1).size())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << cell(1) << ']';
|
|
|
|
|
os << '{' << cell(0) << '}';
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-12 08:52:36 +00:00
|
|
|
|
string const CommandInset::screenLabel() const
|
2002-06-24 15:51:35 +00:00
|
|
|
|
{
|
2004-04-18 19:57:58 +00:00
|
|
|
|
return name_;
|
2002-06-24 15:51:35 +00:00
|
|
|
|
}
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const CommandInset::createDialogStr(string const & name) const
|
|
|
|
|
{
|
2004-04-18 19:57:58 +00:00
|
|
|
|
ostringstream os;
|
|
|
|
|
os << name << " LatexCommand ";
|
|
|
|
|
WriteStream ws(os);
|
|
|
|
|
write(ws);
|
|
|
|
|
ws << "\n\\end_inset\n\n";
|
|
|
|
|
return os.str();
|
2003-03-04 16:39:13 +00:00
|
|
|
|
}
|