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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pö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()
|
2008-11-14 14:28:50 +00:00
|
|
|
: InsetMathNest(2), name_(from_ascii("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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFormulaMacro::write(ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2004-08-16 11:27:51 +00:00
|
|
|
os << "FormulaMacro\n";
|
2009-08-07 05:25:22 +00:00
|
|
|
WriteStream wi(os, false, false, WriteStream::wsDefault);
|
2004-03-27 12:36:38 +00:00
|
|
|
tmpl()->write(wi);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetFormulaMacro::latex(otexstream & os,
|
|
|
|
OutputParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2004-04-06 19:25:39 +00:00
|
|
|
//lyxerr << "InsetFormulaMacro::latex" << endl;
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
WriteStream wi(os.os(), runparams.moving_arg, true,
|
2009-08-07 05:25:22 +00:00
|
|
|
runparams.dryrun ? WriteStream::wsDryrun: WriteStream::wsDefault,
|
|
|
|
runparams.encoding);
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
wi.canBreakLine(os.canBreakLine());
|
2004-03-27 12:36:38 +00:00
|
|
|
tmpl()->write(wi);
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
os.canBreakLine(wi.canBreakLine());
|
2011-02-10 20:02:48 +00:00
|
|
|
os.texrow().newlines(wi.line());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetFormulaMacro::plaintext(odocstringstream & os, OutputParams const & runparams, int max_length) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-02-24 15:06:04 +00:00
|
|
|
odocstringstream oss;
|
2009-08-07 05:25:22 +00:00
|
|
|
WriteStream wi(oss, false, true, WriteStream::wsDefault, runparams.encoding);
|
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
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetFormulaMacro::docbook(ostream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
return plaintext(os, runparams);
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFormulaMacro::read(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
|