2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetFormulaMacro.cpp
|
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"
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "MacroTable.h"
|
2006-09-17 09:55:13 +00:00
|
|
|
|
#include "MathMacroTemplate.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
|
|
|
|
#include "support/gettext.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "OutputParams.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
|
#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
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace lyx::support;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2007-04-30 10:31:51 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
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
|
2007-04-30 10:31:51 +00:00
|
|
|
|
(docstring const & name, int nargs, docstring 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
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
|
istringstream is(s);
|
2002-07-12 14:24:47 +00:00
|
|
|
|
read(is);
|
2001-08-14 07:46:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetFormulaMacro::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetFormulaMacro::latex(Buffer const &, odocstream & os,
|
2007-05-28 22:27:45 +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
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetFormulaMacro::plaintext(Buffer const &, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2007-02-24 15:06:04 +00:00
|
|
|
|
odocstringstream oss;
|
|
|
|
|
WriteStream wi(oss, false, true);
|
2004-03-27 12:36:38 +00:00
|
|
|
|
tmpl()->write(wi);
|
2007-02-24 15:06:04 +00:00
|
|
|
|
|
|
|
|
|
docstring const str = oss.str();
|
|
|
|
|
os << str;
|
|
|
|
|
return str.size();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetFormulaMacro::docbook(Buffer const & buf, ostream & os,
|
2007-05-28 22:27:45 +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
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetFormulaMacro::read(Buffer const &, Lexer & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-12 14:24:47 +00:00
|
|
|
|
read(lex.getStream());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
void InsetFormulaMacro::read(istream & is)
|
2002-07-12 14:24:47 +00:00
|
|
|
|
{
|
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-10-21 00:16:43 +00:00
|
|
|
|
return 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
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +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-11 17:24:46 +00:00
|
|
|
|
dim.wid += 10 + theFontMetrics(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
|
2007-04-29 18:17:15 +00:00
|
|
|
|
Font font = p.base.font;
|
2007-10-25 12:41:02 +00:00
|
|
|
|
font.setColor(Color_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
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
|
// Color_mathbg used to be "AntiqueWhite" but is "linen" now, too
|
|
|
|
|
pi.pain.fillRectangle(x, a, w, h, Color_mathmacrobg);
|
|
|
|
|
pi.pain.rectangle(x, a, w, h, Color_mathframe);
|
2001-08-03 09:54:48 +00:00
|
|
|
|
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME
|
2004-02-02 17:32:56 +00:00
|
|
|
|
#if 0
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor & cur = p.base.bv->cursor();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
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,
|
2006-10-11 17:24:46 +00:00
|
|
|
|
x + theFontMetrics(p.base.font).width(prefix()) + 5,
|
2006-10-07 16:15:06 +00:00
|
|
|
|
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_);
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|