2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file formulamacro.C
|
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
|
|
#include "formulamacro.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
|
#include "math_macrotable.h"
|
2002-07-12 14:24:47 +00:00
|
|
|
|
#include "math_macrotemplate.h"
|
2001-12-11 17:47:27 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "cursor.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
|
|
|
|
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2003-09-16 09:44:34 +00:00
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
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;
|
|
|
|
|
|
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()
|
2004-01-26 10:13:15 +00:00
|
|
|
|
: MathNestInset(2), name_("unknown")
|
|
|
|
|
{}
|
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)
|
|
|
|
|
: MathNestInset(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)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
: MathNestInset(2), name_("unknown")
|
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
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "FormulaMacro ";
|
2002-03-25 12:11:25 +00:00
|
|
|
|
WriteStream wi(os, false, false);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
MathNestInset::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
|
|
|
|
{
|
2003-05-23 09:23:03 +00:00
|
|
|
|
WriteStream wi(os, runparams.moving_arg, true);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
MathNestInset::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-01-26 10:13:15 +00:00
|
|
|
|
MathNestInset::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::linuxdoc(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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()));
|
2003-06-02 10:03:27 +00:00
|
|
|
|
//metrics();
|
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
|
|
|
|
{
|
2004-01-26 10:13:15 +00:00
|
|
|
|
return bformat(_(" Macro: %1$s: "), 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-01-26 10:13:15 +00:00
|
|
|
|
MathNestInset::metrics(mi);
|
|
|
|
|
dim = cell(0).dim();
|
|
|
|
|
dim += cell(1).dim();
|
|
|
|
|
dim.asc += 5;
|
|
|
|
|
dim.des += 5;
|
|
|
|
|
dim.wid += 10 + font_metrics::width(prefix(), mi.base.font);
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim = dim_;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#warning FIXME
|
|
|
|
|
#if 0
|
2001-10-12 12:02:49 +00:00
|
|
|
|
MathAtom const & InsetFormulaMacro::par() const
|
2001-04-24 16:13:38 +00:00
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return MathMacroTable::provide(getInsetName());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
MathAtom & InsetFormulaMacro::par()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return MathMacroTable::provide(getInsetName());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#endif
|
2001-08-03 09:54:48 +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
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
PainterInfo pi(p.base.bv);
|
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-01-26 10:13:15 +00:00
|
|
|
|
LCursor & cur = p.base.bv->cursor();
|
|
|
|
|
if (cur.isInside(this))
|
|
|
|
|
cur.drawSelection(pi);
|
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
|
|
|
|
|
|
|
|
|
// formula
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#warning FIXME
|
|
|
|
|
#if 0
|
2003-05-30 06:48:24 +00:00
|
|
|
|
par()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);
|
2002-04-03 13:53:46 +00:00
|
|
|
|
xo_ = x;
|
2001-10-24 09:16:06 +00:00
|
|
|
|
yo_ = y;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#endif
|
2001-08-03 09:54:48 +00:00
|
|
|
|
}
|