1999-09-27 18:44:28 +00:00
|
|
|
/*
|
2001-02-14 19:35:25 +00:00
|
|
|
* File: formula.C
|
|
|
|
* Purpose: Implementation of formula inset
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
* Description: Allows the edition of math paragraphs inside Lyx.
|
|
|
|
*
|
|
|
|
* Copyright: 1996-1998 Alejandro Aguilar Sierra
|
|
|
|
*
|
|
|
|
* Version: 0.4, Lyx project.
|
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
2001-02-15 12:22:01 +00:00
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
|
2001-07-13 09:54:32 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "formula.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "math_cursor.h"
|
|
|
|
#include "math_parser.h"
|
2001-10-18 13:21:21 +00:00
|
|
|
#include "math_charinset.h"
|
2001-11-07 13:15:59 +00:00
|
|
|
#include "math_arrayinset.h"
|
|
|
|
#include "math_deliminset.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
#include "math_hullinset.h"
|
|
|
|
#include "math_support.h"
|
|
|
|
#include "math_mathmlstream.h"
|
|
|
|
#include "textpainter.h"
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "gettext.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
#include "lyxrc.h"
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
#include "support/LOstream.h"
|
2001-10-12 12:02:49 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-06-26 19:04:45 +00:00
|
|
|
#include "support/lyxlib.h"
|
|
|
|
#include "support/systemcall.h"
|
|
|
|
#include "support/filetools.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-06-26 19:04:45 +00:00
|
|
|
#include "frontends/Alert.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/Painter.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-06-26 19:04:45 +00:00
|
|
|
#include "graphics/GraphicsImage.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
#include "graphics/PreviewLoader.h"
|
|
|
|
#include "graphics/PreviewImage.h"
|
|
|
|
#include "graphics/Previews.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-06-26 19:04:45 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <boost/bind.hpp>
|
2002-07-05 21:24:15 +00:00
|
|
|
#include <boost/signals/trackable.hpp>
|
|
|
|
#include <boost/signals/connection.hpp>
|
2002-06-26 19:04:45 +00:00
|
|
|
#include <boost/utility.hpp>
|
2002-06-25 18:21:17 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2001-04-25 15:43:57 +00:00
|
|
|
using std::ifstream;
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::istream;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::pair;
|
|
|
|
using std::endl;
|
2000-05-19 16:46:01 +00:00
|
|
|
using std::vector;
|
2001-11-20 16:05:17 +00:00
|
|
|
using std::getline;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
struct InsetFormula::PreviewImpl : public boost::signals::trackable {
|
|
|
|
///
|
|
|
|
PreviewImpl(InsetFormula & p) : parent_(p), pimage_(0) {}
|
|
|
|
|
|
|
|
///
|
|
|
|
void generatePreview(grfx::PreviewLoader & previewer);
|
|
|
|
|
|
|
|
/** This method is connected to the grfx::PreviewLoader::imageReady
|
|
|
|
* signal.
|
|
|
|
*/
|
|
|
|
void previewReady(grfx::PreviewImage const &);
|
|
|
|
|
|
|
|
/// A helper method.
|
|
|
|
string const latexString() const;
|
|
|
|
|
|
|
|
///
|
|
|
|
bool usePreview() const;
|
|
|
|
|
|
|
|
///
|
|
|
|
InsetFormula & parent_;
|
|
|
|
///
|
|
|
|
mutable grfx::PreviewImage const * pimage_;
|
|
|
|
///
|
|
|
|
boost::signals::connection connection_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
InsetFormula::InsetFormula()
|
2002-07-05 21:24:15 +00:00
|
|
|
: par_(MathAtom(new MathHullInset)),
|
|
|
|
preview_(new PreviewImpl(*this))
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
InsetFormula::InsetFormula(InsetFormula const & other)
|
|
|
|
: par_(other.par_),
|
|
|
|
preview_(new PreviewImpl(*this))
|
2002-06-27 18:12:50 +00:00
|
|
|
{}
|
2001-08-06 17:20:26 +00:00
|
|
|
|
|
|
|
|
2002-07-04 11:00:51 +00:00
|
|
|
InsetFormula::InsetFormula(BufferView * bv)
|
2002-07-05 21:24:15 +00:00
|
|
|
: par_(MathAtom(new MathHullInset)),
|
|
|
|
preview_(new PreviewImpl(*this))
|
2002-07-04 11:00:51 +00:00
|
|
|
{
|
|
|
|
view_ = bv;
|
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-07-04 11:00:51 +00:00
|
|
|
InsetFormula::InsetFormula(string const & data)
|
2002-07-05 21:24:15 +00:00
|
|
|
: par_(MathAtom(new MathHullInset)),
|
|
|
|
preview_(new PreviewImpl(*this))
|
2002-07-04 11:00:51 +00:00
|
|
|
{
|
|
|
|
if (!data.size())
|
|
|
|
return;
|
2002-07-04 17:45:35 +00:00
|
|
|
if (!mathed_parse_normal(par_, data))
|
2002-07-04 11:00:51 +00:00
|
|
|
lyxerr << "cannot interpret '" << data << "' as math\n";
|
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
InsetFormula::~InsetFormula()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Inset * InsetFormula::clone(Buffer const &, bool) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return new InsetFormula(*this);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2002-03-25 12:11:25 +00:00
|
|
|
void InsetFormula::write(Buffer const *, ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-03-25 12:11:25 +00:00
|
|
|
WriteStream wi(os, false, false);
|
2002-07-08 06:39:40 +00:00
|
|
|
os << par_->fileInsetLabel() << " ";
|
2002-03-25 12:11:25 +00:00
|
|
|
par_->write(wi);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2002-03-25 12:11:25 +00:00
|
|
|
int InsetFormula::latex(Buffer const *, ostream & os, bool fragile, bool) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-03-25 12:11:25 +00:00
|
|
|
WriteStream wi(os, fragile, true);
|
2001-10-19 11:25:48 +00:00
|
|
|
par_->write(wi);
|
2001-12-03 16:24:50 +00:00
|
|
|
return wi.line();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
int InsetFormula::ascii(Buffer const *, ostream & os, int) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
2002-05-02 07:30:49 +00:00
|
|
|
#if 0
|
2002-03-19 16:55:58 +00:00
|
|
|
TextMetricsInfo mi;
|
2002-03-21 06:57:13 +00:00
|
|
|
par()->metricsT(mi);
|
2002-03-19 16:55:58 +00:00
|
|
|
TextPainter tpain(par()->width(), par()->height());
|
2002-03-21 06:57:13 +00:00
|
|
|
par()->drawT(tpain, 0, par()->ascent());
|
2002-03-19 16:55:58 +00:00
|
|
|
tpain.show(os);
|
|
|
|
// reset metrics cache to "real" values
|
|
|
|
metrics();
|
|
|
|
return tpain.textheight();
|
|
|
|
#else
|
2002-05-02 07:30:49 +00:00
|
|
|
WriteStream wi(os, false, true);
|
2001-10-19 11:25:48 +00:00
|
|
|
par_->write(wi);
|
2001-12-03 16:24:50 +00:00
|
|
|
return wi.line();
|
2002-03-19 16:55:58 +00:00
|
|
|
#endif
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-24 13:38:52 +00:00
|
|
|
int InsetFormula::linuxdoc(Buffer const * buf, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
return docbook(buf, os, false);
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
int InsetFormula::docbook(Buffer const * buf, ostream & os, bool) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2001-11-07 17:30:26 +00:00
|
|
|
MathMLStream ms(os);
|
2002-06-18 15:44:30 +00:00
|
|
|
ms << MTag("equation");
|
|
|
|
ms << MTag("alt");
|
|
|
|
ms << "<[CDATA[";
|
2001-12-03 16:24:50 +00:00
|
|
|
int res = ascii(buf, ms.os(), 0);
|
2002-06-18 15:44:30 +00:00
|
|
|
ms << "]]>";
|
|
|
|
ms << ETag("alt");
|
|
|
|
ms << MTag("math");
|
|
|
|
ms << par_.nucleus();
|
|
|
|
ms << ETag("math");
|
|
|
|
ms << ETag("equation");
|
2001-12-03 16:24:50 +00:00
|
|
|
return ms.line() + res;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-09-24 13:38:52 +00:00
|
|
|
void InsetFormula::read(Buffer const *, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
mathed_parse_normal(par_, lex);
|
2001-07-26 06:56:43 +00:00
|
|
|
metrics();
|
2002-06-27 18:12:50 +00:00
|
|
|
updatePreview();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
//ostream & operator<<(ostream & os, LyXCursor const & c)
|
2001-11-20 14:48:25 +00:00
|
|
|
//{
|
|
|
|
// os << '[' << c.x() << ' ' << c.y() << ' ' << c.pos() << ']';
|
|
|
|
// return os;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
void InsetFormula::draw(BufferView * bv, LyXFont const & font,
|
2001-06-27 14:10:35 +00:00
|
|
|
int y, float & xx, bool) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-06-26 09:15:23 +00:00
|
|
|
int const x = int(xx);
|
2002-06-26 19:04:45 +00:00
|
|
|
int const w = width(bv, font);
|
|
|
|
int const d = descent(bv, font);
|
|
|
|
int const a = ascent(bv, font);
|
|
|
|
int const h = a + d;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
|
|
MathPainterInfo pi(bv->painter());
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
if (preview_->usePreview()) {
|
|
|
|
pi.pain.image(x + 1, y - a + 1, w - 2, h - 2,
|
|
|
|
*(preview_->pimage_->image()));
|
2002-06-26 19:04:45 +00:00
|
|
|
} else {
|
2002-07-04 11:00:51 +00:00
|
|
|
//pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
|
|
|
|
pi.base.style = LM_ST_TEXT;
|
2002-06-26 19:04:45 +00:00
|
|
|
pi.base.font = font;
|
|
|
|
pi.base.font.setColor(LColor::math);
|
|
|
|
if (lcolor.getX11Name(LColor::mathbg)
|
|
|
|
!= lcolor.getX11Name(LColor::background))
|
|
|
|
pi.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
|
|
|
|
|
|
|
|
if (mathcursor &&
|
|
|
|
const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
|
|
|
|
{
|
|
|
|
mathcursor->drawSelection(pi);
|
2002-07-08 06:39:40 +00:00
|
|
|
//pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
|
2002-06-26 08:59:25 +00:00
|
|
|
}
|
2002-06-26 19:04:45 +00:00
|
|
|
|
2002-07-08 06:39:40 +00:00
|
|
|
par_->draw(pi, x + 1, y);
|
2002-06-25 18:21:17 +00:00
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2002-06-26 09:15:23 +00:00
|
|
|
xx += w;
|
2001-10-24 09:16:06 +00:00
|
|
|
xo_ = x;
|
|
|
|
yo_ = y;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
setCursorVisible(false);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
vector<string> const InsetFormula::getLabelList() const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2002-07-08 06:39:40 +00:00
|
|
|
return par()->getLabelList();
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
UpdatableInset::RESULT
|
2001-06-28 10:25:20 +00:00
|
|
|
InsetFormula::localDispatch(BufferView * bv, kb_action action,
|
2001-06-25 00:06:33 +00:00
|
|
|
string const & arg)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
RESULT result = DISPATCHED;
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
switch (action) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
case LFUN_BREAKLINE:
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-07-06 12:09:32 +00:00
|
|
|
mathcursor->breakLine();
|
2001-07-16 15:53:25 +00:00
|
|
|
mathcursor->normalize();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_MATH_NUMBER:
|
|
|
|
{
|
|
|
|
//lyxerr << "toggling all numbers\n";
|
|
|
|
if (display()) {
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2002-07-08 06:39:40 +00:00
|
|
|
bool old = par()->numberedType();
|
2001-09-26 16:52:34 +00:00
|
|
|
for (MathInset::row_type row = 0; row < par_->nrows(); ++row)
|
2001-12-11 15:04:02 +00:00
|
|
|
hull()->numbered(row, !old);
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->owner()->message(old ? _("No number") : _("Number"));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_MATH_NONUMBER:
|
|
|
|
{
|
|
|
|
//lyxerr << "toggling line number\n";
|
|
|
|
if (display()) {
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-12-11 15:04:02 +00:00
|
|
|
MathCursor::row_type row = mathcursor->hullRow();
|
|
|
|
bool old = hull()->numbered(row);
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->owner()->message(old ? _("No number") : _("Number"));
|
2001-12-11 15:04:02 +00:00
|
|
|
hull()->numbered(row, !old);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_INSERT_LABEL:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
MathCursor::row_type row = mathcursor->hullRow();
|
|
|
|
string old_label = hull()->label(row);
|
2001-06-25 00:06:33 +00:00
|
|
|
string new_label = arg;
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (new_label.empty()) {
|
|
|
|
string const default_label =
|
|
|
|
(lyxrc.label_init_length >= 0) ? "eq:" : "";
|
|
|
|
pair<bool, string> const res = old_label.empty()
|
2001-11-26 10:19:58 +00:00
|
|
|
? Alert::askForText(_("Enter new label to insert:"), default_label)
|
|
|
|
: Alert::askForText(_("Enter label:"), old_label);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!res.first)
|
|
|
|
break;
|
|
|
|
new_label = frontStrip(strip(res.second));
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
//if (new_label == old_label)
|
|
|
|
// break; // Nothing to do
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!new_label.empty()) {
|
|
|
|
lyxerr << "setting label to '" << new_label << "'\n";
|
2001-12-11 15:04:02 +00:00
|
|
|
hull()->numbered(row, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2002-06-21 02:22:13 +00:00
|
|
|
#warning FIXME: please check you really mean repaint() ... is it needed,
|
2002-07-04 17:45:35 +00:00
|
|
|
#warning and if so, should it be update() instead ?
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
|
2002-06-21 02:22:13 +00:00
|
|
|
bv->repaint();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
hull()->label(row, new_label);
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_MATH_MUTATE:
|
2001-07-06 12:09:32 +00:00
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
int x;
|
|
|
|
int y;
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->getPos(x, y);
|
2002-07-04 11:00:51 +00:00
|
|
|
mutate(arg);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->setPos(x, y);
|
2001-07-06 12:09:32 +00:00
|
|
|
mathcursor->normalize();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-10-29 15:45:24 +00:00
|
|
|
case LFUN_MATH_EXTERN:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2002-06-18 15:44:30 +00:00
|
|
|
if (mathcursor)
|
|
|
|
mathcursor->handleExtern(arg);
|
2001-10-29 15:45:24 +00:00
|
|
|
// re-compute inset dimension
|
|
|
|
metrics(bv);
|
|
|
|
updateLocal(bv, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_MATH_DISPLAY:
|
2001-07-12 11:53:45 +00:00
|
|
|
{
|
2001-11-13 15:29:45 +00:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->getPos(x, y);
|
2002-07-03 10:36:44 +00:00
|
|
|
if (hullType() == "simple")
|
2002-07-04 11:00:51 +00:00
|
|
|
mutate("equation");
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
2002-07-04 11:00:51 +00:00
|
|
|
mutate("simple");
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->setPos(x, y);
|
2001-07-12 11:53:45 +00:00
|
|
|
mathcursor->normalize();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-07-12 11:53:45 +00:00
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
case LFUN_PASTESELECTION:
|
|
|
|
{
|
|
|
|
string const clip = bv->getClipboard();
|
2002-03-21 17:42:56 +00:00
|
|
|
if (!clip.empty())
|
2001-10-12 12:02:49 +00:00
|
|
|
mathed_parse_normal(par_, clip);
|
2001-07-26 06:46:50 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
default:
|
2001-06-28 10:25:20 +00:00
|
|
|
result = InsetFormulaBase::localDispatch(bv, action, arg);
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
2002-06-27 18:12:50 +00:00
|
|
|
//updatePreview();
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-10-23 13:48:52 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool InsetFormula::display() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
return hullType() != "simple" && hullType() != "none";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
MathHullInset const * InsetFormula::hull() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
lyx::Assert(par_->asHullInset());
|
|
|
|
return par_->asHullInset();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-08-01 16:48:06 +00:00
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
MathHullInset * InsetFormula::hull()
|
2001-10-12 12:02:49 +00:00
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
lyx::Assert(par_->asHullInset());
|
|
|
|
return par_->asHullInset();
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
Inset::Code InsetFormula::lyxCode() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return Inset::MATH_CODE;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormula::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-03 09:54:48 +00:00
|
|
|
par_->validate(features);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
bool InsetFormula::insetAllowed(Inset::Code code) const
|
|
|
|
{
|
2002-03-21 17:42:56 +00:00
|
|
|
return
|
2001-11-12 08:20:30 +00:00
|
|
|
(code == Inset::LABEL_CODE && display())
|
2002-07-04 17:45:35 +00:00
|
|
|
|| code == Inset::REF_CODE
|
2002-03-21 17:42:56 +00:00
|
|
|
|| code == Inset::ERT_CODE;
|
2001-07-23 09:11:14 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int InsetFormula::ascent(BufferView *, LyXFont const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-07-05 21:24:15 +00:00
|
|
|
return preview_->usePreview() ?
|
|
|
|
1 + preview_->pimage_->ascent() : 1 + par_->ascent();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-16 09:25:43 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int InsetFormula::descent(BufferView *, LyXFont const &) const
|
2001-02-16 09:25:43 +00:00
|
|
|
{
|
2002-07-05 21:24:15 +00:00
|
|
|
return preview_->usePreview() ?
|
|
|
|
1 + preview_->pimage_->descent() : 1 + par_->descent();
|
2001-02-16 09:25:43 +00:00
|
|
|
}
|
2001-03-16 12:08:14 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
int InsetFormula::width(BufferView * bv, LyXFont const & font) const
|
2001-03-16 12:08:14 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
metrics(bv, font);
|
2002-07-05 21:24:15 +00:00
|
|
|
return preview_->usePreview() ?
|
|
|
|
preview_->pimage_->width() : par_->width();
|
2001-03-16 12:08:14 +00:00
|
|
|
}
|
2001-08-01 13:28:45 +00:00
|
|
|
|
|
|
|
|
2002-07-04 11:00:51 +00:00
|
|
|
string InsetFormula::hullType() const
|
2001-08-01 13:28:45 +00:00
|
|
|
{
|
2002-07-08 06:39:40 +00:00
|
|
|
return par()->getType();
|
2001-08-01 13:28:45 +00:00
|
|
|
}
|
2002-06-26 19:04:45 +00:00
|
|
|
|
|
|
|
|
2002-07-08 06:39:40 +00:00
|
|
|
void InsetFormula::mutate(string const & type)
|
2002-07-03 10:36:44 +00:00
|
|
|
{
|
2002-07-08 06:39:40 +00:00
|
|
|
par()->mutate(type);
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-26 19:04:45 +00:00
|
|
|
//
|
|
|
|
// preview stuff
|
|
|
|
//
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
void InsetFormula::generatePreview(grfx::PreviewLoader & ploader) const
|
2002-06-26 19:04:45 +00:00
|
|
|
{
|
2002-07-05 21:24:15 +00:00
|
|
|
// Do nothing if no preview is desired.
|
|
|
|
if (!grfx::Previews::activated())
|
|
|
|
return;
|
|
|
|
|
|
|
|
preview_->generatePreview(ploader);
|
2002-06-26 19:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
void InsetFormula::PreviewImpl::generatePreview(grfx::PreviewLoader & ploader)
|
2002-06-26 19:04:45 +00:00
|
|
|
{
|
2002-07-05 21:24:15 +00:00
|
|
|
// Generate the LaTeX snippet.
|
|
|
|
string const snippet = latexString();
|
|
|
|
|
|
|
|
pimage_ = ploader.preview(snippet);
|
|
|
|
if (pimage_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If this is the first time of calling, connect to the
|
|
|
|
// grfx::PreviewLoader signal that'll inform us when the preview image
|
|
|
|
// is ready for loading.
|
|
|
|
if (!connection_.connected()) {
|
|
|
|
connection_ = ploader.imageReady.connect(
|
|
|
|
boost::bind(&PreviewImpl::previewReady, this, _1));
|
|
|
|
}
|
|
|
|
|
|
|
|
ploader.add(snippet);
|
2002-06-27 13:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
bool InsetFormula::PreviewImpl::usePreview() const
|
2002-06-26 19:04:45 +00:00
|
|
|
{
|
2002-07-05 21:24:15 +00:00
|
|
|
BufferView * view = parent_.view();
|
|
|
|
|
|
|
|
if (!grfx::Previews::activated() ||
|
|
|
|
parent_.par_->asNestInset()->editing() ||
|
|
|
|
!view || !view->buffer())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If the cached grfx::PreviewImage is invalid, update it.
|
|
|
|
string const snippet = latexString();
|
|
|
|
if (!pimage_ || snippet != pimage_->snippet()) {
|
|
|
|
grfx::PreviewLoader & ploader =
|
|
|
|
grfx::Previews::get().loader(view->buffer());
|
|
|
|
pimage_ = ploader.preview(snippet);
|
|
|
|
}
|
2002-06-26 19:04:45 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
if (!pimage_)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return pimage_->image();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetFormula::PreviewImpl::latexString() const
|
|
|
|
{
|
2002-06-26 19:04:45 +00:00
|
|
|
ostringstream ls;
|
|
|
|
WriteStream wi(ls, false, false);
|
2002-07-05 21:24:15 +00:00
|
|
|
parent_.par_->write(wi);
|
|
|
|
return ls.str().c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFormula::PreviewImpl::previewReady(grfx::PreviewImage const & pimage)
|
|
|
|
{
|
|
|
|
// Check snippet against the Inset's current contents
|
|
|
|
if (latexString() != pimage.snippet())
|
2002-06-26 19:04:45 +00:00
|
|
|
return;
|
2002-06-27 18:12:50 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
pimage_ = &pimage;
|
|
|
|
BufferView * view = parent_.view();
|
|
|
|
if (view)
|
|
|
|
view->updateInset(&parent_, false);
|
2002-06-27 13:01:31 +00:00
|
|
|
}
|