2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetFormulaMacro.C
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetFormulaMacro.h"
|
|
|
|
|
#include "MathMacroTable.h"
|
2006-09-17 09:55:13 +00:00
|
|
|
|
#include "MathMacroTemplate.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathMLStream.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "cursor.h"
|
2004-03-27 12:36:38 +00:00
|
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "gettext.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
#include "LColor.h"
|
|
|
|
|
#include "lyxlex.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
|
#include "outputparams.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
#include "frontends/FontLoader.h"
|
|
|
|
|
#include "frontends/FontMetrics.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
|
|
|
|
#include <sstream>
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::bformat;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
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-08 00:33:41 +00:00
|
|
|
|
using std::ostream;
|
2004-03-27 12:36:38 +00:00
|
|
|
|
using std::endl;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
InsetFormulaMacro::InsetFormulaMacro()
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathNest(2), name_("unknownA")
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{}
|
2001-08-03 09:54:48 +00:00
|
|
|
|
|
|
|
|
|
|
2003-07-04 15:55:18 +00:00
|
|
|
|
InsetFormulaMacro::InsetFormulaMacro
|
2004-01-26 10:13:15 +00:00
|
|
|
|
(string const & name, int nargs, string const & type)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathNest(2), name_(name)
|
2001-08-03 09:54:48 +00:00
|
|
|
|
{
|
2003-07-04 15:55:18 +00:00
|
|
|
|
MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
InsetFormulaMacro::InsetFormulaMacro(string const & s)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathNest(2), name_("unknownB")
|
2001-08-14 07:46:11 +00:00
|
|
|
|
{
|
2003-09-15 11:00:00 +00:00
|
|
|
|
std::istringstream is(s);
|
2002-07-12 14:24:47 +00:00
|
|
|
|
read(is);
|
2001-08-14 07:46:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetFormulaMacro::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetFormulaMacro(*this));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetFormulaMacro::write(Buffer const &, ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-08-16 11:27:51 +00:00
|
|
|
|
os << "FormulaMacro\n";
|
2002-03-25 12:11:25 +00:00
|
|
|
|
WriteStream wi(os, false, false);
|
2004-03-27 12:36:38 +00:00
|
|
|
|
tmpl()->write(wi);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetFormulaMacro::latex(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-04-06 19:25:39 +00:00
|
|
|
|
//lyxerr << "InsetFormulaMacro::latex" << endl;
|
2003-05-23 09:23:03 +00:00
|
|
|
|
WriteStream wi(os, runparams.moving_arg, true);
|
2004-03-27 12:36:38 +00:00
|
|
|
|
tmpl()->write(wi);
|
2000-09-05 14:15:09 +00:00
|
|
|
|
return 2;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
|
int InsetFormulaMacro::plaintext(Buffer const &, ostream & os,
|
|
|
|
|
OutputParams const &) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-03-25 12:11:25 +00:00
|
|
|
|
WriteStream wi(os, false, true);
|
2004-03-27 12:36:38 +00:00
|
|
|
|
tmpl()->write(wi);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetFormulaMacro::docbook(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2003-11-05 12:06:20 +00:00
|
|
|
|
return plaintext(buf, os, runparams);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetFormulaMacro::read(Buffer const &, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-12 14:24:47 +00:00
|
|
|
|
read(lex.getStream());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFormulaMacro::read(std::istream & is)
|
|
|
|
|
{
|
2003-11-03 17:47:28 +00:00
|
|
|
|
auto_ptr<MathMacroTemplate> p(new MathMacroTemplate(is));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
name_ = p->name();
|
2003-11-03 17:47:28 +00:00
|
|
|
|
MathMacroTable::create(MathAtom(p.release()));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
string InsetFormulaMacro::prefix() const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return lyx::to_utf8(bformat(_(" Macro: %1$s: "), lyx::from_utf8(name_)));
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-06-02 17:58:19 +00:00
|
|
|
|
void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2004-04-06 19:25:39 +00:00
|
|
|
|
//lyxerr << "InsetFormulaMacro: " << this << " -- " << &tmpl() << endl;
|
2004-03-27 12:36:38 +00:00
|
|
|
|
tmpl()->metrics(mi, dim);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
dim.asc += 5;
|
|
|
|
|
dim.des += 5;
|
2006-10-07 16:15:06 +00:00
|
|
|
|
dim.wid += 10
|
|
|
|
|
+ theApp->fontLoader().metrics(mi.base.font).width(prefix());
|
2004-03-27 12:36:38 +00:00
|
|
|
|
dim_ = dim;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
|
2001-08-03 09:54:48 +00:00
|
|
|
|
{
|
|
|
|
|
// label
|
2003-05-30 06:48:24 +00:00
|
|
|
|
LyXFont font = p.base.font;
|
2001-08-03 09:54:48 +00:00
|
|
|
|
font.setColor(LColor::math);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2004-04-07 20:20:15 +00:00
|
|
|
|
PainterInfo pi(p.base.bv, p.pain);
|
2002-08-19 14:39:35 +00:00
|
|
|
|
pi.base.style = LM_ST_TEXT;
|
|
|
|
|
pi.base.font = font;
|
|
|
|
|
|
2003-06-02 17:58:19 +00:00
|
|
|
|
int const a = y - dim_.asc + 1;
|
|
|
|
|
int const w = dim_.wid - 2;
|
|
|
|
|
int const h = dim_.height() - 2;
|
2001-08-03 09:54:48 +00:00
|
|
|
|
|
|
|
|
|
// LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
|
2002-08-19 14:39:35 +00:00
|
|
|
|
pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
|
|
|
|
|
pi.pain.rectangle(x, a, w, h, LColor::mathframe);
|
2001-08-03 09:54:48 +00:00
|
|
|
|
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-02-02 17:32:56 +00:00
|
|
|
|
#warning FIXME
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2004-02-02 17:32:56 +00:00
|
|
|
|
#if 0
|
2004-01-26 10:13:15 +00:00
|
|
|
|
LCursor & cur = p.base.bv->cursor();
|
|
|
|
|
if (cur.isInside(this))
|
|
|
|
|
cur.drawSelection(pi);
|
2004-02-02 17:32:56 +00:00
|
|
|
|
#endif
|
2001-08-03 09:54:48 +00:00
|
|
|
|
|
2002-08-19 14:39:35 +00:00
|
|
|
|
pi.pain.text(x + 2, y, prefix(), font);
|
2001-08-03 09:54:48 +00:00
|
|
|
|
|
2004-03-27 12:36:38 +00:00
|
|
|
|
// body
|
2006-10-07 16:15:06 +00:00
|
|
|
|
tmpl()->draw(pi,
|
|
|
|
|
x + theApp->fontLoader().metrics(p.base.font).width(prefix()) + 5,
|
|
|
|
|
y);
|
2004-03-27 12:36:38 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2001-08-03 09:54:48 +00:00
|
|
|
|
}
|
2004-03-27 12:36:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathAtom & InsetFormulaMacro::tmpl() const
|
|
|
|
|
{
|
|
|
|
|
return MathMacroTable::provide(name_);
|
|
|
|
|
}
|