2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_hullinset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "math_charinset.h"
|
2005-06-17 14:35:19 +00:00
|
|
|
|
#include "math_colorinset.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "math_data.h"
|
|
|
|
|
#include "math_extern.h"
|
2005-11-22 13:52:25 +00:00
|
|
|
|
#include "math_factory.h"
|
2001-11-08 12:30:26 +00:00
|
|
|
|
#include "math_hullinset.h"
|
2001-12-11 15:04:02 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
|
|
|
|
#include "math_streamstr.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
|
#include "math_support.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2005-07-14 23:36:49 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferparams.h"
|
2004-01-16 12:36:23 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-04-18 07:34:15 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2004-11-26 13:56:22 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2004-04-18 07:34:15 +00:00
|
|
|
|
#include "LColor.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "cursor.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "debug.h"
|
2004-04-18 07:34:15 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2002-08-13 17:43:40 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "gettext.h"
|
2004-04-13 17:38:16 +00:00
|
|
|
|
#include "lyx_main.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "lyxrc.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#include "outputparams.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
|
#include "sgml.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "textpainter.h"
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#include "undo.h"
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
#include "insets/render_preview.h"
|
2005-07-17 16:36:21 +00:00
|
|
|
|
#include "insets/insetlabel.h"
|
2004-04-13 17:38:16 +00:00
|
|
|
|
|
2005-07-17 16:36:21 +00:00
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
#include "frontends/LyXView.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
|
2004-04-19 13:05:36 +00:00
|
|
|
|
#include "graphics/PreviewImage.h"
|
2004-04-13 17:38:16 +00:00
|
|
|
|
#include "graphics/PreviewLoader.h"
|
|
|
|
|
|
2004-10-29 23:08:04 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
|
using lyx::docstring;
|
2004-04-18 07:34:15 +00:00
|
|
|
|
using lyx::cap::grabAndEraseSelection;
|
2004-11-26 13:56:22 +00:00
|
|
|
|
using lyx::support::bformat;
|
2004-10-29 23:08:04 +00:00
|
|
|
|
using lyx::support::subst;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::max;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
using std::ostream;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2004-01-28 16:21:29 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2002-08-14 18:31:53 +00:00
|
|
|
|
using std::pair;
|
2004-01-28 16:21:29 +00:00
|
|
|
|
using std::swap;
|
|
|
|
|
using std::vector;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
int getCols(HullType type)
|
2001-10-18 13:21:21 +00:00
|
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
|
switch (type) {
|
|
|
|
|
case hullEqnArray:
|
|
|
|
|
return 3;
|
|
|
|
|
case hullAlign:
|
|
|
|
|
case hullFlAlign:
|
|
|
|
|
case hullAlignAt:
|
|
|
|
|
case hullXAlignAt:
|
|
|
|
|
case hullXXAlignAt:
|
|
|
|
|
return 2;
|
|
|
|
|
default:
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2001-10-18 13:21:21 +00:00
|
|
|
|
}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
|
|
|
|
|
|
// returns position of first relation operator in the array
|
|
|
|
|
// used for "intelligent splitting"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
size_t firstRelOp(MathArray const & ar)
|
2001-10-18 13:21:21 +00:00
|
|
|
|
{
|
|
|
|
|
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
|
|
|
|
|
if ((*it)->isRelOp())
|
|
|
|
|
return it - ar.begin();
|
|
|
|
|
return ar.size();
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
|
char const * star(bool numbered)
|
|
|
|
|
{
|
|
|
|
|
return numbered ? "" : "*";
|
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
|
} // end anon namespace
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
HullType hullType(std::string const & s)
|
|
|
|
|
{
|
|
|
|
|
if (s == "none") return hullNone;
|
|
|
|
|
if (s == "simple") return hullSimple;
|
|
|
|
|
if (s == "equation") return hullEquation;
|
|
|
|
|
if (s == "eqnarray") return hullEqnArray;
|
|
|
|
|
if (s == "align") return hullAlign;
|
|
|
|
|
if (s == "alignat") return hullAlignAt;
|
|
|
|
|
if (s == "xalignat") return hullXAlignAt;
|
|
|
|
|
if (s == "xxalignat") return hullXXAlignAt;
|
|
|
|
|
if (s == "multline") return hullMultline;
|
|
|
|
|
if (s == "gather") return hullGather;
|
|
|
|
|
if (s == "flalign") return hullFlAlign;
|
|
|
|
|
lyxerr << "unknown hull type '" << s << "'" << endl;
|
|
|
|
|
return HullType(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string hullName(HullType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case hullNone: return "none";
|
|
|
|
|
case hullSimple: return "simple";
|
|
|
|
|
case hullEquation: return "equation";
|
|
|
|
|
case hullEqnArray: return "eqnarray";
|
|
|
|
|
case hullAlign: return "align";
|
|
|
|
|
case hullAlignAt: return "alignat";
|
|
|
|
|
case hullXAlignAt: return "xalignat";
|
|
|
|
|
case hullXXAlignAt: return "xxalignat";
|
|
|
|
|
case hullMultline: return "multline";
|
|
|
|
|
case hullGather: return "gather";
|
|
|
|
|
case hullFlAlign: return "flalign";
|
|
|
|
|
default:
|
|
|
|
|
lyxerr << "unknown hull type '" << type << "'" << endl;
|
|
|
|
|
return "none";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
MathHullInset::MathHullInset()
|
2006-09-03 16:14:51 +00:00
|
|
|
|
: MathGridInset(1, 1), type_(hullNone), nonum_(1), label_(1),
|
2004-04-13 17:38:16 +00:00
|
|
|
|
preview_(new RenderPreview(this))
|
2001-09-04 13:32:06 +00:00
|
|
|
|
{
|
2004-01-26 10:13:15 +00:00
|
|
|
|
//lyxerr << "sizeof MathInset: " << sizeof(MathInset) << endl;
|
|
|
|
|
//lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
|
|
|
|
|
//lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << endl;
|
|
|
|
|
//lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << endl;
|
2005-12-15 16:59:59 +00:00
|
|
|
|
initMath();
|
2001-09-04 13:32:06 +00:00
|
|
|
|
setDefaults();
|
|
|
|
|
}
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
MathHullInset::MathHullInset(HullType type)
|
2004-04-13 17:38:16 +00:00
|
|
|
|
: MathGridInset(getCols(type), 1), type_(type), nonum_(1), label_(1),
|
|
|
|
|
preview_(new RenderPreview(this))
|
2002-02-14 13:25:26 +00:00
|
|
|
|
{
|
2005-12-15 16:59:59 +00:00
|
|
|
|
initMath();
|
2002-02-14 13:25:26 +00:00
|
|
|
|
setDefaults();
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-18 11:02:33 +00:00
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
MathHullInset::MathHullInset(MathHullInset const & other)
|
|
|
|
|
: MathGridInset(other),
|
|
|
|
|
type_(other.type_), nonum_(other.nonum_), label_(other.label_),
|
|
|
|
|
preview_(new RenderPreview(this))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathHullInset::~MathHullInset()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> MathHullInset::doClone() const
|
2001-08-02 09:59:09 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathHullInset(*this));
|
2001-08-02 09:59:09 +00:00
|
|
|
|
}
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
MathHullInset & MathHullInset::operator=(MathHullInset const & other)
|
2004-04-13 17:38:16 +00:00
|
|
|
|
{
|
|
|
|
|
if (this == &other)
|
2004-11-23 23:04:52 +00:00
|
|
|
|
return *this;
|
2004-04-13 17:38:16 +00:00
|
|
|
|
*static_cast<MathGridInset*>(this) = MathGridInset(other);
|
|
|
|
|
type_ = other.type_;
|
|
|
|
|
nonum_ = other.nonum_;
|
|
|
|
|
label_ = other.label_;
|
|
|
|
|
preview_.reset(new RenderPreview(*other.preview_, this));
|
2004-11-23 23:04:52 +00:00
|
|
|
|
|
|
|
|
|
return *this;
|
2004-04-13 17:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-15 00:39:44 +00:00
|
|
|
|
InsetBase * MathHullInset::editXY(LCursor & cur, int x, int y)
|
|
|
|
|
{
|
2005-07-18 00:45:10 +00:00
|
|
|
|
if (use_preview_) {
|
2005-07-15 00:39:44 +00:00
|
|
|
|
edit(cur, true);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
return MathNestInset::editXY(cur, x, y);
|
2005-07-15 00:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-18 11:02:33 +00:00
|
|
|
|
MathInset::mode_type MathHullInset::currentMode() const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullNone)
|
2002-07-18 11:02:33 +00:00
|
|
|
|
return UNDECIDED_MODE;
|
|
|
|
|
// definitely math mode ...
|
|
|
|
|
return MATH_MODE;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathHullInset::idxFirst(LCursor & cur) const
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = 0;
|
|
|
|
|
cur.pos() = 0;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathHullInset::idxLast(LCursor & cur) const
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = nargs() - 1;
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
char MathHullInset::defaultColAlign(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullEqnArray)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
return "rcl"[col];
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ >= hullAlign)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
return "rl"[col & 1];
|
2001-09-04 13:32:06 +00:00
|
|
|
|
return 'c';
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
int MathHullInset::defaultColSpace(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullAlign || type_ == hullAlignAt)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
return 0;
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullXAlignAt)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
return (col & 1) ? 20 : 0;
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullXXAlignAt || type_ == hullFlAlign)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
return (col & 1) ? 40 : 0;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
return 0;
|
2001-09-04 13:32:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-24 15:37:14 +00:00
|
|
|
|
char const * MathHullInset::standardFont() const
|
|
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
|
return type_ == hullNone ? "lyxnochange" : "mathnormal";
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-18 00:45:10 +00:00
|
|
|
|
bool MathHullInset::previewState(BufferView * bv) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2005-07-18 00:45:10 +00:00
|
|
|
|
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
|
2004-04-19 13:05:36 +00:00
|
|
|
|
lyx::graphics::PreviewImage const * pimage =
|
2005-07-18 00:45:10 +00:00
|
|
|
|
preview_->getPreviewImage(*bv->buffer());
|
|
|
|
|
return pimage && pimage->image();
|
2004-04-19 13:05:36 +00:00
|
|
|
|
}
|
2005-07-18 00:45:10 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
|
2005-07-18 00:45:10 +00:00
|
|
|
|
void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
if (previewState(mi.base.bv)) {
|
2004-04-13 17:38:16 +00:00
|
|
|
|
preview_->metrics(mi, dim);
|
|
|
|
|
// insert a one pixel gap in front of the formula
|
|
|
|
|
dim.wid += 1;
|
|
|
|
|
if (display())
|
|
|
|
|
dim.des += 12;
|
|
|
|
|
dim_ = dim;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FontSetChanger dummy1(mi.base, standardFont());
|
|
|
|
|
StyleChanger dummy2(mi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
2002-06-04 09:06:04 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// let the cells adjust themselves
|
2004-01-30 11:41:12 +00:00
|
|
|
|
MathGridInset::metrics(mi, dim);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
if (display()) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.asc += 12;
|
|
|
|
|
dim.des += 12;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2001-03-06 17:44:53 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (numberedType()) {
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FontSetChanger dummy(mi.base, "mathbf");
|
2001-06-25 00:06:33 +00:00
|
|
|
|
int l = 0;
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2002-06-04 09:06:04 +00:00
|
|
|
|
l = max(l, mathed_string_width(mi.base.font, nicelabel(row)));
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
if (l)
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.wid += 30 + l;
|
2001-02-16 09:25:43 +00:00
|
|
|
|
}
|
2001-09-03 11:38:04 +00:00
|
|
|
|
|
|
|
|
|
// make it at least as high as the current font
|
|
|
|
|
int asc = 0;
|
|
|
|
|
int des = 0;
|
2002-06-04 09:06:04 +00:00
|
|
|
|
math_font_max_dim(mi.base.font, asc, des);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim.asc = max(dim.asc, asc);
|
|
|
|
|
dim.des = max(dim.des, des);
|
2002-07-08 06:39:40 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim_ = dim;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathHullInset::draw(PainterInfo & pi, int x, int y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2005-07-18 00:45:10 +00:00
|
|
|
|
use_preview_ = previewState(pi.base.bv);
|
2004-04-13 17:38:16 +00:00
|
|
|
|
|
2005-07-18 00:45:10 +00:00
|
|
|
|
if (use_preview_) {
|
2004-04-13 17:38:16 +00:00
|
|
|
|
// one pixel gap in front
|
|
|
|
|
preview_->draw(pi, x + 1, y);
|
|
|
|
|
setPosCache(pi, x, y);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FontSetChanger dummy1(pi.base, standardFont());
|
|
|
|
|
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
2002-07-08 06:39:40 +00:00
|
|
|
|
MathGridInset::draw(pi, x + 1, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
if (numberedType()) {
|
2001-10-19 17:46:13 +00:00
|
|
|
|
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-10-19 17:46:13 +00:00
|
|
|
|
int const yy = y + rowinfo_[row].offset_;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FontSetChanger dummy(pi.base, "mathrm");
|
2006-08-13 22:54:59 +00:00
|
|
|
|
string const nl = nicelabel(row);
|
|
|
|
|
docstring const dnl(nl.begin(), nl.end());
|
|
|
|
|
pi.draw(xx, yy, dnl);
|
2001-07-20 14:54:13 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2004-04-07 16:54:15 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-02 07:30:49 +00:00
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void MathHullInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-03-18 11:45:53 +00:00
|
|
|
|
{
|
2002-05-02 07:30:49 +00:00
|
|
|
|
if (display()) {
|
2003-05-28 13:22:36 +00:00
|
|
|
|
MathGridInset::metricsT(mi, dim);
|
2002-07-11 15:04:43 +00:00
|
|
|
|
} else {
|
2002-05-02 07:30:49 +00:00
|
|
|
|
ostringstream os;
|
|
|
|
|
WriteStream wi(os, false, true);
|
|
|
|
|
write(wi);
|
2003-05-28 13:22:36 +00:00
|
|
|
|
dim.wid = os.str().size();
|
|
|
|
|
dim.asc = 1;
|
|
|
|
|
dim.des = 0;
|
2002-05-02 07:30:49 +00:00
|
|
|
|
}
|
2002-03-18 11:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 06:57:13 +00:00
|
|
|
|
void MathHullInset::drawT(TextPainter & pain, int x, int y) const
|
2002-03-18 11:45:53 +00:00
|
|
|
|
{
|
2002-05-02 07:30:49 +00:00
|
|
|
|
if (display()) {
|
|
|
|
|
MathGridInset::drawT(pain, x, y);
|
2002-07-11 15:04:43 +00:00
|
|
|
|
} else {
|
2002-05-02 07:30:49 +00:00
|
|
|
|
ostringstream os;
|
|
|
|
|
WriteStream wi(os, false, true);
|
|
|
|
|
write(wi);
|
|
|
|
|
pain.draw(x, y, os.str().c_str());
|
|
|
|
|
}
|
2002-03-18 11:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
string const latex_string(MathHullInset const & inset)
|
|
|
|
|
{
|
|
|
|
|
ostringstream ls;
|
|
|
|
|
WriteStream wi(ls, false, false);
|
|
|
|
|
inset.write(wi);
|
|
|
|
|
return ls.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathHullInset::addPreview(lyx::graphics::PreviewLoader & ploader) const
|
|
|
|
|
{
|
2004-04-20 08:16:22 +00:00
|
|
|
|
if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
|
|
|
|
|
string const snippet = latex_string(*this);
|
|
|
|
|
preview_->addPreview(snippet, ploader);
|
|
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-08-17 21:32:04 +00:00
|
|
|
|
bool MathHullInset::notifyCursorLeaves(LCursor & cur)
|
2004-04-13 17:38:16 +00:00
|
|
|
|
{
|
2004-08-13 19:19:24 +00:00
|
|
|
|
if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
|
|
|
|
|
Buffer const & buffer = cur.buffer();
|
|
|
|
|
string const snippet = latex_string(*this);
|
|
|
|
|
preview_->addPreview(snippet, buffer);
|
|
|
|
|
preview_->startLoading(buffer);
|
|
|
|
|
}
|
2006-08-17 21:32:04 +00:00
|
|
|
|
return false;
|
2004-04-13 17:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
string MathHullInset::label(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2005-06-09 12:17:50 +00:00
|
|
|
|
BOOST_ASSERT(row < nrows());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return label_[row];
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
void MathHullInset::label(row_type row, string const & label)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-08-08 14:22:44 +00:00
|
|
|
|
//lyxerr << "setting label '" << label << "' for row " << row << endl;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
label_[row] = label;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
void MathHullInset::numbered(row_type row, bool num)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-03-21 17:42:56 +00:00
|
|
|
|
nonum_[row] = !num;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
bool MathHullInset::numbered(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
return !nonum_[row];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
bool MathHullInset::ams() const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-03-21 17:42:56 +00:00
|
|
|
|
return
|
2006-09-03 16:14:51 +00:00
|
|
|
|
type_ == hullAlign ||
|
|
|
|
|
type_ == hullFlAlign ||
|
|
|
|
|
type_ == hullMultline ||
|
|
|
|
|
type_ == hullGather ||
|
|
|
|
|
type_ == hullAlignAt ||
|
|
|
|
|
type_ == hullXAlignAt ||
|
|
|
|
|
type_ == hullXXAlignAt;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
bool MathHullInset::display() const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
|
return type_ != hullSimple && type_ != hullNone;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-28 16:21:29 +00:00
|
|
|
|
void MathHullInset::getLabelList(Buffer const &, vector<string> & labels) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (!label_[row].empty() && nonum_[row] != 1)
|
2002-08-02 13:35:05 +00:00
|
|
|
|
labels.push_back(label_[row]);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
bool MathHullInset::numberedType() const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullNone)
|
2002-06-24 15:37:14 +00:00
|
|
|
|
return false;
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullSimple)
|
2002-06-24 15:37:14 +00:00
|
|
|
|
return false;
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullXXAlignAt)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return false;
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (!nonum_[row])
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
void MathHullInset::validate(LaTeXFeatures & features) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2001-11-19 15:34:11 +00:00
|
|
|
|
if (ams())
|
2002-01-10 10:05:45 +00:00
|
|
|
|
features.require("amsmath");
|
2001-11-19 15:34:11 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
// Validation is necessary only if not using AMS math.
|
2001-07-26 06:56:43 +00:00
|
|
|
|
// To be safe, we will always run mathedvalidate.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
//if (features.amsstyle)
|
|
|
|
|
// return;
|
|
|
|
|
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("boldsymbol");
|
2001-07-13 14:54:56 +00:00
|
|
|
|
//features.binom = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-03-06 08:10:50 +00:00
|
|
|
|
MathGridInset::validate(features);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-19 19:06:05 +00:00
|
|
|
|
void MathHullInset::header_write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
bool n = numberedType();
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullNone)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
;
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullSimple) {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
os << '$';
|
|
|
|
|
if (cell(0).empty())
|
|
|
|
|
os << ' ';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullEquation) {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (n)
|
|
|
|
|
os << "\\begin{equation" << star(n) << "}\n";
|
|
|
|
|
else
|
|
|
|
|
os << "\\[\n";
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullEqnArray || type_ == hullAlign || type_ ==
|
|
|
|
|
hullFlAlign
|
|
|
|
|
|| type_ == hullGather || type_ == hullMultline)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
os << "\\begin{" << type_ << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullAlignAt || type_ == hullXAlignAt)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "\\begin{" << type_ << star(n) << '}'
|
|
|
|
|
<< '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
|
2002-08-14 18:31:53 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullXXAlignAt)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "\\begin{" << type_ << '}'
|
|
|
|
|
<< '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
|
2002-08-14 18:31:53 +00:00
|
|
|
|
|
|
|
|
|
else
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "\\begin{unknown" << star(n) << '}';
|
2002-07-03 10:36:44 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
void MathHullInset::footer_write(WriteStream & os) const
|
|
|
|
|
{
|
|
|
|
|
bool n = numberedType();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullNone)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
os << "\n";
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullSimple)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
os << '$';
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullEquation)
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (n)
|
|
|
|
|
os << "\\end{equation" << star(n) << "}\n";
|
|
|
|
|
else
|
|
|
|
|
os << "\\]\n";
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullEqnArray || type_ == hullAlign || type_ ==
|
|
|
|
|
hullFlAlign
|
|
|
|
|
|| type_ == hullAlignAt || type_ == hullXAlignAt
|
|
|
|
|
|| type_ == hullGather || type_ == hullMultline)
|
2003-03-17 16:25:00 +00:00
|
|
|
|
os << "\\end{" << type_ << star(n) << "}\n";
|
2001-09-04 14:56:30 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullXXAlignAt)
|
2002-10-24 10:56:32 +00:00
|
|
|
|
os << "\\end{" << type_ << "}\n";
|
2001-09-04 14:56:30 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "\\end{unknown" << star(n) << '}';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 14:43:37 +00:00
|
|
|
|
bool MathHullInset::rowChangeOK() const
|
|
|
|
|
{
|
|
|
|
|
return
|
2006-09-03 16:14:51 +00:00
|
|
|
|
type_ == hullEqnArray || type_ == hullAlign ||
|
|
|
|
|
type_ == hullFlAlign || type_ == hullAlignAt ||
|
|
|
|
|
type_ == hullXAlignAt || type_ == hullXXAlignAt ||
|
|
|
|
|
type_ == hullGather || type_ == hullMultline;
|
2004-11-23 14:43:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-21 13:47:52 +00:00
|
|
|
|
bool MathHullInset::colChangeOK() const
|
|
|
|
|
{
|
2002-08-29 06:49:27 +00:00
|
|
|
|
return
|
2006-09-03 16:14:51 +00:00
|
|
|
|
type_ == hullAlign || type_ == hullFlAlign ||type_ == hullAlignAt ||
|
|
|
|
|
type_ == hullXAlignAt || type_ == hullXXAlignAt;
|
2002-08-21 13:47:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
void MathHullInset::addRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
|
if (!rowChangeOK())
|
|
|
|
|
return;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
nonum_.insert(nonum_.begin() + row + 1, !numberedType());
|
|
|
|
|
label_.insert(label_.begin() + row + 1, string());
|
|
|
|
|
MathGridInset::addRow(row);
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2003-10-06 09:57:03 +00:00
|
|
|
|
void MathHullInset::swapRow(row_type row)
|
|
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
|
if (nrows() <= 1)
|
2003-10-06 09:57:03 +00:00
|
|
|
|
return;
|
|
|
|
|
if (row + 1 == nrows())
|
|
|
|
|
--row;
|
2004-01-28 16:21:29 +00:00
|
|
|
|
swap(nonum_[row], nonum_[row + 1]);
|
|
|
|
|
swap(label_[row], label_[row + 1]);
|
2003-10-06 09:57:03 +00:00
|
|
|
|
MathGridInset::swapRow(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
void MathHullInset::delRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
|
if (nrows() <= 1 || !rowChangeOK())
|
2002-08-19 10:11:13 +00:00
|
|
|
|
return;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
MathGridInset::delRow(row);
|
2005-10-14 10:50:23 +00:00
|
|
|
|
// The last dummy row has no number info nor a label.
|
|
|
|
|
// Test nrows() + 1 because we have already erased the row.
|
|
|
|
|
if (row == nrows() + 1)
|
|
|
|
|
row--;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
nonum_.erase(nonum_.begin() + row);
|
|
|
|
|
label_.erase(label_.begin() + row);
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2002-08-21 13:47:52 +00:00
|
|
|
|
void MathHullInset::addCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
|
if (!colChangeOK())
|
|
|
|
|
return;
|
|
|
|
|
MathGridInset::addCol(col);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2002-08-21 13:47:52 +00:00
|
|
|
|
void MathHullInset::delCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
|
if (ncols() <= 1 || !colChangeOK())
|
|
|
|
|
return;
|
|
|
|
|
MathGridInset::delCol(col);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
string MathHullInset::nicelabel(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (nonum_[row])
|
|
|
|
|
return string();
|
|
|
|
|
if (label_[row].empty())
|
|
|
|
|
return string("(#)");
|
2002-11-27 10:30:28 +00:00
|
|
|
|
return '(' + label_[row] + ')';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
void MathHullInset::glueall()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
MathArray ar;
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2002-07-30 13:56:02 +00:00
|
|
|
|
ar.append(cell(i));
|
2006-09-03 16:14:51 +00:00
|
|
|
|
*this = MathHullInset(hullSimple);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cell(0) = ar;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
setDefaults();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-01 13:28:45 +00:00
|
|
|
|
|
2004-09-13 18:14:37 +00:00
|
|
|
|
void MathHullInset::splitTo2Cols()
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(ncols() == 1);
|
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
|
idx_type const i = 2 * row;
|
|
|
|
|
pos_type pos = firstRelOp(cell(i));
|
|
|
|
|
cell(i + 1) = MathArray(cell(i).begin() + pos, cell(i).end());
|
|
|
|
|
cell(i).erase(pos, cell(i).size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathHullInset::splitTo3Cols()
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(ncols() < 3);
|
|
|
|
|
if (ncols() < 2)
|
|
|
|
|
splitTo2Cols();
|
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
|
idx_type const i = 3 * row + 1;
|
|
|
|
|
if (cell(i).size()) {
|
|
|
|
|
cell(i + 1) = MathArray(cell(i).begin() + 1, cell(i).end());
|
|
|
|
|
cell(i).erase(1, cell(i).size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathHullInset::changeCols(col_type cols)
|
|
|
|
|
{
|
|
|
|
|
if (ncols() == cols)
|
|
|
|
|
return;
|
|
|
|
|
else if (ncols() < cols) {
|
|
|
|
|
// split columns
|
|
|
|
|
if (cols < 3)
|
|
|
|
|
splitTo2Cols();
|
|
|
|
|
else {
|
|
|
|
|
splitTo3Cols();
|
|
|
|
|
while (ncols() < cols)
|
|
|
|
|
MathGridInset::addCol(ncols() - 1);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// combine columns
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
|
idx_type const i = row * ncols();
|
|
|
|
|
for (col_type col = cols; col < ncols(); ++col) {
|
|
|
|
|
cell(i + cols - 1).append(cell(i + col));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// delete columns
|
|
|
|
|
while (ncols() > cols) {
|
|
|
|
|
MathGridInset::delCol(ncols() - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
HullType MathHullInset::getType() const
|
2001-08-01 13:28:45 +00:00
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
return type_;
|
2001-08-01 13:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
void MathHullInset::setType(HullType type)
|
2001-08-01 13:28:45 +00:00
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
type_ = type;
|
2001-09-04 13:32:06 +00:00
|
|
|
|
setDefaults();
|
2001-08-01 13:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
void MathHullInset::mutate(HullType newtype)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2005-07-15 08:51:34 +00:00
|
|
|
|
//lyxerr << "mutating from '" << type_ << "' to '" << newtype << "'" << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
// we try to move along the chain
|
2004-09-13 18:14:37 +00:00
|
|
|
|
// none <-> simple <-> equation <-> eqnarray -> *align* -> multline, gather -+
|
|
|
|
|
// ^ |
|
|
|
|
|
// +-------------------------------------+
|
|
|
|
|
// we use eqnarray as intermediate type for mutations that are not
|
|
|
|
|
// directly supported because it handles labels and numbering for
|
|
|
|
|
// "down mutation".
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (newtype == type_) {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
// done
|
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (newtype < hullNone) {
|
2004-10-17 20:06:35 +00:00
|
|
|
|
// unknown type
|
2006-09-03 16:14:51 +00:00
|
|
|
|
dump();
|
2004-10-17 20:06:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullNone) {
|
|
|
|
|
setType(hullSimple);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
numbered(0, false);
|
2003-05-02 07:52:15 +00:00
|
|
|
|
mutate(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
}
|
2001-08-07 12:02:21 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullSimple) {
|
|
|
|
|
if (newtype == hullNone) {
|
|
|
|
|
setType(hullNone);
|
2004-09-13 18:14:37 +00:00
|
|
|
|
numbered(0, false);
|
2003-05-02 07:52:15 +00:00
|
|
|
|
} else {
|
2006-09-03 16:14:51 +00:00
|
|
|
|
setType(hullEquation);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
numbered(0, false);
|
2003-05-02 07:52:15 +00:00
|
|
|
|
mutate(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullEquation) {
|
|
|
|
|
if (newtype < type_) {
|
|
|
|
|
setType(hullSimple);
|
2004-09-13 18:14:37 +00:00
|
|
|
|
numbered(0, false);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
mutate(newtype);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
} else if (newtype == hullEqnArray) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
// split it "nicely" on the first relop
|
|
|
|
|
splitTo3Cols();
|
2006-09-03 16:14:51 +00:00
|
|
|
|
setType(hullEqnArray);
|
|
|
|
|
} else if (newtype == hullMultline || newtype == hullGather) {
|
2002-08-08 16:08:11 +00:00
|
|
|
|
setType(newtype);
|
2002-08-14 18:31:53 +00:00
|
|
|
|
} else {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
// split it "nicely"
|
2004-09-13 18:14:37 +00:00
|
|
|
|
splitTo2Cols();
|
2006-09-03 16:14:51 +00:00
|
|
|
|
setType(hullAlign);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
mutate(newtype);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullEqnArray) {
|
|
|
|
|
if (newtype < type_) {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
// set correct (no)numbering
|
|
|
|
|
bool allnonum = true;
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
|
if (!nonum_[row])
|
|
|
|
|
allnonum = false;
|
|
|
|
|
|
|
|
|
|
// set first non-empty label
|
|
|
|
|
string label;
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
|
if (!label_[row].empty()) {
|
|
|
|
|
label = label_[row];
|
2001-06-25 00:06:33 +00:00
|
|
|
|
break;
|
2001-07-09 16:59:57 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
glueall();
|
|
|
|
|
nonum_[0] = allnonum;
|
|
|
|
|
label_[0] = label;
|
|
|
|
|
mutate(newtype);
|
|
|
|
|
} else { // align & Co.
|
2004-09-13 18:14:37 +00:00
|
|
|
|
changeCols(2);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
setType(hullAlign);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
mutate(newtype);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullAlign || type_ == hullAlignAt ||
|
|
|
|
|
type_ == hullXAlignAt || type_ == hullFlAlign) {
|
|
|
|
|
if (newtype < hullAlign) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
changeCols(3);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
setType(hullEqnArray);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
mutate(newtype);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
} else if (newtype == hullGather || newtype == hullMultline) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
changeCols(1);
|
|
|
|
|
setType(newtype);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
} else if (newtype == hullXXAlignAt) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
|
numbered(row, false);
|
|
|
|
|
setType(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
setType(newtype);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-09-04 14:56:30 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullXXAlignAt) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
|
numbered(row, false);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (newtype < hullAlign) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
changeCols(3);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
setType(hullEqnArray);
|
2004-09-13 18:14:37 +00:00
|
|
|
|
mutate(newtype);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
} else if (newtype == hullGather || newtype == hullMultline) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
changeCols(1);
|
|
|
|
|
setType(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
} else {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
setType(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (type_ == hullMultline || type_ == hullGather) {
|
|
|
|
|
if (newtype == hullGather || newtype == hullMultline)
|
2004-09-13 18:14:37 +00:00
|
|
|
|
setType(newtype);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
else if (newtype == hullAlign || newtype == hullFlAlign ||
|
|
|
|
|
newtype == hullAlignAt || newtype == hullXAlignAt) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
splitTo2Cols();
|
|
|
|
|
setType(newtype);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
} else if (newtype == hullXXAlignAt) {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
splitTo2Cols();
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
|
numbered(row, false);
|
2004-08-13 21:21:10 +00:00
|
|
|
|
setType(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
} else {
|
2004-09-13 18:14:37 +00:00
|
|
|
|
splitTo3Cols();
|
2006-09-03 16:14:51 +00:00
|
|
|
|
setType(hullEqnArray);
|
2004-09-13 18:14:37 +00:00
|
|
|
|
mutate(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-09-04 14:56:30 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else {
|
|
|
|
|
lyxerr << "mutation from '" << type_
|
2004-09-13 18:14:37 +00:00
|
|
|
|
<< "' to '" << newtype << "' not implemented" << endl;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
|
|
|
|
|
2005-10-14 10:50:23 +00:00
|
|
|
|
string MathHullInset::eolString(row_type row, bool emptyline, bool fragile) const
|
2001-11-08 12:06:56 +00:00
|
|
|
|
{
|
2002-08-15 17:41:24 +00:00
|
|
|
|
string res;
|
|
|
|
|
if (numberedType()) {
|
2002-10-29 13:22:43 +00:00
|
|
|
|
if (!label_[row].empty() && !nonum_[row])
|
2002-11-27 10:30:28 +00:00
|
|
|
|
res += "\\label{" + label_[row] + '}';
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (nonum_[row] && (type_ != hullMultline))
|
2002-08-15 17:41:24 +00:00
|
|
|
|
res += "\\nonumber ";
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
2005-10-14 10:50:23 +00:00
|
|
|
|
return res + MathGridInset::eolString(row, emptyline, fragile);
|
2002-08-15 17:41:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-08-15 17:41:24 +00:00
|
|
|
|
void MathHullInset::write(WriteStream & os) const
|
|
|
|
|
{
|
|
|
|
|
header_write(os);
|
|
|
|
|
MathGridInset::write(os);
|
2001-12-05 08:04:20 +00:00
|
|
|
|
footer_write(os);
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathHullInset::normalize(NormalStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "[formula " << type_ << ' ';
|
2001-11-09 08:35:57 +00:00
|
|
|
|
MathGridInset::normalize(os);
|
2001-11-08 12:06:56 +00:00
|
|
|
|
os << "] ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 18:02:20 +00:00
|
|
|
|
void MathHullInset::mathmlize(MathMLStream & os) const
|
|
|
|
|
{
|
|
|
|
|
MathGridInset::mathmlize(os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-28 16:21:29 +00:00
|
|
|
|
void MathHullInset::infoize(ostream & os) const
|
2002-05-30 07:09:54 +00:00
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
os << "Type: " << type_;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
2001-12-11 15:04:02 +00:00
|
|
|
|
void MathHullInset::check() const
|
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(nonum_.size() == nrows());
|
|
|
|
|
BOOST_ASSERT(label_.size() == nrows());
|
2001-12-11 15:04:02 +00:00
|
|
|
|
}
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void MathHullInset::doExtern(LCursor & cur, FuncRequest & func)
|
2002-08-14 16:43:16 +00:00
|
|
|
|
{
|
|
|
|
|
string lang;
|
|
|
|
|
string extra;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
istringstream iss(lyx::to_utf8(func.argument()));
|
2002-08-14 16:43:16 +00:00
|
|
|
|
iss >> lang >> extra;
|
|
|
|
|
if (extra.empty())
|
|
|
|
|
extra = "noextra";
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning temporarily disabled
|
2004-01-20 14:25:24 +00:00
|
|
|
|
//if (cur.selection()) {
|
2002-08-14 16:43:16 +00:00
|
|
|
|
// MathArray ar;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
// selGet(cur.ar);
|
2003-08-02 11:30:30 +00:00
|
|
|
|
// lyxerr << "use selection: " << ar << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
// insert(pipeThroughExtern(lang, extra, ar));
|
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
MathArray eq;
|
|
|
|
|
eq.push_back(MathAtom(new MathCharInset('=')));
|
|
|
|
|
|
|
|
|
|
// go to first item in line
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() -= cur.idx() % ncols();
|
|
|
|
|
cur.pos() = 0;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (getType() == hullSimple) {
|
2004-01-15 17:34:44 +00:00
|
|
|
|
size_type pos = cur.cell().find_last(eq);
|
2002-08-14 16:43:16 +00:00
|
|
|
|
MathArray ar;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (cur.inMathed() && cur.selection()) {
|
2004-04-18 07:34:15 +00:00
|
|
|
|
asArray(grabAndEraseSelection(cur), ar);
|
2004-01-15 17:34:44 +00:00
|
|
|
|
} else if (pos == cur.cell().size()) {
|
|
|
|
|
ar = cur.cell();
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use whole cell: " << ar << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
} else {
|
2004-01-15 17:34:44 +00:00
|
|
|
|
ar = MathArray(cur.cell().begin() + pos + 1, cur.cell().end());
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use partial cell form pos: " << pos << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
}
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.cell().append(eq);
|
|
|
|
|
cur.cell().append(pipeThroughExtern(lang, extra, ar));
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-08-14 16:43:16 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (getType() == hullEquation) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use equation inset" << endl;
|
2006-09-03 16:14:51 +00:00
|
|
|
|
mutate(hullEqnArray);
|
2004-01-15 17:34:44 +00:00
|
|
|
|
MathArray & ar = cur.cell();
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use cell: " << ar << endl;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
++cur.idx();
|
|
|
|
|
cur.cell() = eq;
|
|
|
|
|
++cur.idx();
|
|
|
|
|
cur.cell() = pipeThroughExtern(lang, extra, ar);
|
2002-08-14 16:43:16 +00:00
|
|
|
|
// move to end of line
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-08-14 16:43:16 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use eqnarray" << endl;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() += 2 - cur.idx() % ncols();
|
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
MathArray ar = cur.cell();
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use cell: " << ar << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning temporarily disabled
|
|
|
|
|
#endif
|
2004-01-15 17:34:44 +00:00
|
|
|
|
addRow(cur.row());
|
|
|
|
|
++cur.idx();
|
|
|
|
|
++cur.idx();
|
|
|
|
|
cur.cell() = eq;
|
|
|
|
|
++cur.idx();
|
|
|
|
|
cur.cell() = pipeThroughExtern(lang, extra, ar);
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-08-14 16:43:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void MathHullInset::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2002-08-13 17:43:40 +00:00
|
|
|
|
{
|
2005-12-01 10:28:50 +00:00
|
|
|
|
//lyxerr << "action: " << cmd.action << endl;
|
2002-08-13 17:43:40 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
case LFUN_FINISHED_LEFT:
|
|
|
|
|
case LFUN_FINISHED_RIGHT:
|
|
|
|
|
case LFUN_FINISHED_UP:
|
|
|
|
|
case LFUN_FINISHED_DOWN:
|
2005-12-01 10:28:50 +00:00
|
|
|
|
//lyxerr << "action: " << cmd.action << endl;
|
2004-11-24 21:58:42 +00:00
|
|
|
|
MathGridInset::doDispatch(cur, cmd);
|
2004-04-13 17:38:16 +00:00
|
|
|
|
notifyCursorLeaves(cur);
|
2005-07-18 17:12:28 +00:00
|
|
|
|
cur.undispatched();
|
2004-04-13 17:38:16 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BREAK_PARAGRAPH:
|
2004-04-08 15:41:48 +00:00
|
|
|
|
// just swallow this
|
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BREAK_LINE:
|
2004-08-12 20:52:43 +00:00
|
|
|
|
// some magic for the common case
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullSimple || type_ == hullEquation) {
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndoInset(cur);
|
2005-07-14 23:36:49 +00:00
|
|
|
|
bool const align =
|
|
|
|
|
cur.bv().buffer()->params().use_amsmath == BufferParams::AMS_ON;
|
2006-09-03 16:14:51 +00:00
|
|
|
|
mutate(align ? hullAlign : hullEqnArray);
|
2004-04-18 19:41:40 +00:00
|
|
|
|
cur.idx() = 0;
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
2004-11-24 21:58:42 +00:00
|
|
|
|
MathGridInset::doDispatch(cur, cmd);
|
2004-04-06 19:25:39 +00:00
|
|
|
|
break;
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
|
case LFUN_MATH_NUMBER:
|
|
|
|
|
//lyxerr << "toggling all numbers" << endl;
|
|
|
|
|
if (display()) {
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndoInset(cur);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
bool old = numberedType();
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (type_ == hullMultline)
|
2004-02-16 11:58:51 +00:00
|
|
|
|
numbered(nrows() - 1, !old);
|
|
|
|
|
else
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
|
numbered(row, !old);
|
|
|
|
|
cur.message(old ? _("No number") : _("Number"));
|
|
|
|
|
}
|
2004-04-06 19:25:39 +00:00
|
|
|
|
break;
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
|
case LFUN_MATH_NONUMBER:
|
|
|
|
|
if (display()) {
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndoInset(cur);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
bool old = numbered(r);
|
|
|
|
|
cur.message(old ? _("No number") : _("Number"));
|
|
|
|
|
numbered(r, !old);
|
2002-08-14 16:11:55 +00:00
|
|
|
|
}
|
2004-04-06 19:25:39 +00:00
|
|
|
|
break;
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_LABEL_INSERT: {
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndoInset(cur);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
string old_label = label(r);
|
2005-07-17 16:36:21 +00:00
|
|
|
|
string const default_label =
|
|
|
|
|
(lyxrc.label_init_length >= 0) ? "eq:" : "";
|
2006-01-10 12:49:34 +00:00
|
|
|
|
if (old_label.empty())
|
|
|
|
|
old_label = default_label;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
string const contents = cmd.argument().empty() ?
|
|
|
|
|
old_label : lyx::to_utf8(cmd.argument());
|
2005-07-17 16:36:21 +00:00
|
|
|
|
|
|
|
|
|
InsetCommandParams p("label", contents);
|
|
|
|
|
string const data = InsetCommandMailer::params2string("label", p);
|
|
|
|
|
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (cmd.argument().empty())
|
2005-07-17 16:36:21 +00:00
|
|
|
|
cur.bv().owner()->getDialogs().show("label", data, 0);
|
2006-09-01 15:41:38 +00:00
|
|
|
|
else {
|
2005-07-17 16:36:21 +00:00
|
|
|
|
FuncRequest fr(LFUN_INSET_INSERT, data);
|
|
|
|
|
dispatch(cur, fr);
|
2002-08-15 14:33:14 +00:00
|
|
|
|
}
|
2005-07-17 16:36:21 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-08-15 14:33:14 +00:00
|
|
|
|
|
2005-07-17 16:36:21 +00:00
|
|
|
|
case LFUN_INSET_INSERT: {
|
2006-09-01 15:41:38 +00:00
|
|
|
|
//lyxerr << "arg: " << lyx::to_utf8(cmd.argument()) << endl;
|
2005-07-17 16:36:21 +00:00
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
|
if (name == "label") {
|
2005-07-17 23:03:01 +00:00
|
|
|
|
InsetCommandParams p;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), p);
|
2005-07-17 23:03:01 +00:00
|
|
|
|
string str = p.getContents();
|
2005-07-17 16:36:21 +00:00
|
|
|
|
recordUndoInset(cur);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2005-07-17 16:36:21 +00:00
|
|
|
|
str = lyx::support::trim(str);
|
|
|
|
|
if (!str.empty())
|
|
|
|
|
numbered(r, true);
|
2005-07-17 23:03:01 +00:00
|
|
|
|
string old = label(r);
|
|
|
|
|
if (str != old) {
|
|
|
|
|
cur.bv().buffer()->changeRefsIfUnique(old, str);
|
|
|
|
|
label(r, str);
|
|
|
|
|
}
|
2005-11-22 13:52:25 +00:00
|
|
|
|
break;
|
2005-07-17 16:36:21 +00:00
|
|
|
|
}
|
2005-11-22 13:52:25 +00:00
|
|
|
|
MathArray ar;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (createMathInset_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
|
2005-11-22 13:52:25 +00:00
|
|
|
|
recordUndo(cur);
|
|
|
|
|
cur.insert(ar);
|
|
|
|
|
} else
|
|
|
|
|
cur.undispatched();
|
2004-04-06 19:25:39 +00:00
|
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_MATH_EXTERN:
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndoInset(cur);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
doExtern(cur, cmd);
|
2004-04-06 19:25:39 +00:00
|
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MATH_MUTATE: {
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndoInset(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
row_type row = cur.row();
|
|
|
|
|
col_type col = cur.col();
|
2006-09-03 16:14:51 +00:00
|
|
|
|
mutate(hullType(lyx::to_utf8(cmd.argument())));
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.idx() = row * ncols() + col;
|
|
|
|
|
if (cur.idx() > cur.lastidx()) {
|
|
|
|
|
cur.idx() = cur.lastidx();
|
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
if (cur.pos() > cur.lastpos())
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
//cur.dispatched(FINISHED);
|
2004-04-06 19:25:39 +00:00
|
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_MATH_DISPLAY: {
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndoInset(cur);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
mutate(type_ == hullSimple ? hullEquation : hullSimple);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
cur.idx() = 0;
|
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
//cur.dispatched(FINISHED);
|
2004-04-06 19:25:39 +00:00
|
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
2002-08-15 14:33:14 +00:00
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
|
MathGridInset::doDispatch(cur, cmd);
|
2004-04-06 19:25:39 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathHullInset::getStatus(LCursor & cur, FuncRequest const & cmd,
|
2005-07-18 00:09:20 +00:00
|
|
|
|
FuncStatus & status) const
|
2004-04-06 19:25:39 +00:00
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
2005-07-18 17:12:28 +00:00
|
|
|
|
case LFUN_FINISHED_LEFT:
|
|
|
|
|
case LFUN_FINISHED_RIGHT:
|
|
|
|
|
case LFUN_FINISHED_UP:
|
|
|
|
|
case LFUN_FINISHED_DOWN:
|
|
|
|
|
status.enabled(true);
|
|
|
|
|
return true;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BREAK_LINE:
|
2004-04-06 19:25:39 +00:00
|
|
|
|
case LFUN_MATH_NUMBER:
|
|
|
|
|
case LFUN_MATH_NONUMBER:
|
|
|
|
|
case LFUN_MATH_EXTERN:
|
|
|
|
|
case LFUN_MATH_MUTATE:
|
|
|
|
|
case LFUN_MATH_DISPLAY:
|
|
|
|
|
// we handle these
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(true);
|
2004-04-06 19:25:39 +00:00
|
|
|
|
return true;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_LABEL_INSERT:
|
2006-09-03 16:14:51 +00:00
|
|
|
|
status.enabled(type_ != hullSimple);
|
2005-07-15 15:19:07 +00:00
|
|
|
|
return true;
|
2005-11-22 13:52:25 +00:00
|
|
|
|
case LFUN_INSET_INSERT: {
|
|
|
|
|
// Don't test createMathInset_fromDialogStr(), since
|
|
|
|
|
// getStatus is not called with a valid reference and the
|
|
|
|
|
// dialog would not be applyable.
|
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
|
status.enabled(name == "ref" ||
|
2006-09-03 16:14:51 +00:00
|
|
|
|
(name == "label" && type_ != hullSimple));
|
2005-11-22 13:52:25 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2004-08-12 20:43:24 +00:00
|
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2006-09-01 15:41:38 +00:00
|
|
|
|
istringstream is(lyx::to_utf8(cmd.argument()));
|
2004-08-12 20:43:24 +00:00
|
|
|
|
string s;
|
|
|
|
|
is >> s;
|
2004-11-23 14:43:37 +00:00
|
|
|
|
if (!rowChangeOK()
|
|
|
|
|
&& (s == "append-row"
|
2004-10-05 10:11:42 +00:00
|
|
|
|
|| s == "delete-row"
|
2004-11-26 13:56:22 +00:00
|
|
|
|
|| s == "copy-row")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.message(bformat(
|
2004-11-26 13:56:22 +00:00
|
|
|
|
N_("Can't change number of rows in '%1$s'"),
|
2006-09-03 16:14:51 +00:00
|
|
|
|
hullName(type_)));
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
2004-11-26 13:56:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-11-23 14:43:37 +00:00
|
|
|
|
if (!colChangeOK()
|
2004-11-15 15:41:42 +00:00
|
|
|
|
&& (s == "append-column"
|
2004-11-23 14:43:37 +00:00
|
|
|
|
|| s == "delete-column"
|
2004-11-26 13:56:22 +00:00
|
|
|
|
|| s == "copy-column")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.message(bformat(
|
2004-11-26 13:56:22 +00:00
|
|
|
|
N_("Can't change number of columns in '%1$s'"),
|
2006-09-03 16:14:51 +00:00
|
|
|
|
hullName(type_)));
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
2004-11-26 13:56:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if ((type_ == hullSimple
|
|
|
|
|
|| type_ == hullEquation
|
|
|
|
|
|| type_ == hullNone) &&
|
2005-03-24 16:26:15 +00:00
|
|
|
|
(s == "add-hline-above" || s == "add-hline-below")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.message(bformat(
|
2005-03-24 16:26:15 +00:00
|
|
|
|
N_("Can't add horizontal grid lines in '%1$s'"),
|
2006-09-03 16:14:51 +00:00
|
|
|
|
hullName(type_)));
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
2005-03-24 16:26:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2005-04-26 11:12:20 +00:00
|
|
|
|
if (s == "add-vline-left" || s == "add-vline-right") {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.message(bformat(
|
2005-03-24 16:26:15 +00:00
|
|
|
|
N_("Can't add vertical grid lines in '%1$s'"),
|
2006-09-03 16:14:51 +00:00
|
|
|
|
hullName(type_)));
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
2005-03-22 12:34:48 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2005-04-26 11:12:20 +00:00
|
|
|
|
if (s == "valign-top" || s == "valign-middle"
|
2005-04-25 14:10:10 +00:00
|
|
|
|
|| s == "valign-bottom" || s == "align-left"
|
|
|
|
|
|| s == "align-center" || s == "align-right") {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
2005-04-25 14:10:10 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2005-07-18 00:09:20 +00:00
|
|
|
|
return MathGridInset::getStatus(cur, cmd, status);
|
2004-08-12 20:43:24 +00:00
|
|
|
|
}
|
2004-04-06 19:25:39 +00:00
|
|
|
|
default:
|
2005-07-18 00:09:20 +00:00
|
|
|
|
return MathGridInset::getStatus(cur, cmd, status);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
2006-01-28 22:15:47 +00:00
|
|
|
|
|
|
|
|
|
// This cannot really happen, but inserted to shut-up gcc
|
|
|
|
|
return MathGridInset::getStatus(cur, cmd, status);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
2003-04-28 08:44:56 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "math_arrayinset.h"
|
|
|
|
|
#include "math_deliminset.h"
|
|
|
|
|
#include "math_factory.h"
|
|
|
|
|
#include "math_parser.h"
|
|
|
|
|
#include "math_spaceinset.h"
|
|
|
|
|
#include "ref_inset.h"
|
|
|
|
|
|
|
|
|
|
#include "bufferview_funcs.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
|
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
|
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// simply scrap this function if you want
|
|
|
|
|
void MathHullInset::mutateToText()
|
|
|
|
|
{
|
|
|
|
|
#if 0
|
|
|
|
|
// translate to latex
|
|
|
|
|
ostringstream os;
|
|
|
|
|
latex(NULL, os, false, false);
|
|
|
|
|
string str = os.str();
|
|
|
|
|
|
|
|
|
|
// insert this text
|
|
|
|
|
LyXText * lt = view_->getLyXText();
|
|
|
|
|
string::const_iterator cit = str.begin();
|
|
|
|
|
string::const_iterator end = str.end();
|
|
|
|
|
for (; cit != end; ++cit)
|
|
|
|
|
view_->owner()->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
|
|
|
|
|
|
|
|
|
|
// remove ourselves
|
|
|
|
|
//view_->owner()->dispatch(LFUN_ESCAPE);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void MathHullInset::handleFont(LCursor & cur, string const & arg,
|
|
|
|
|
string const & font)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
{
|
|
|
|
|
// this whole function is a hack and won't work for incremental font
|
|
|
|
|
// changes...
|
2004-03-18 12:53:43 +00:00
|
|
|
|
recordUndo(cur);
|
|
|
|
|
if (cur.inset().asMathInset()->name() == font)
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.handleFont(font);
|
|
|
|
|
else {
|
|
|
|
|
cur.handleNest(createMathInset(font));
|
|
|
|
|
cur.insert(arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathHullInset::handleFont2(LCursor & cur, string const & arg)
|
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
recordUndo(cur);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
LyXFont font;
|
|
|
|
|
bool b;
|
|
|
|
|
bv_funcs::string2font(arg, font, b);
|
|
|
|
|
if (font.color() != LColor::inherit) {
|
2005-06-17 14:35:19 +00:00
|
|
|
|
MathAtom at = MathAtom(new MathColorInset(true, font.color()));
|
|
|
|
|
cur.handleNest(at, 0);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-06 19:25:39 +00:00
|
|
|
|
void MathHullInset::edit(LCursor & cur, bool left)
|
|
|
|
|
{
|
|
|
|
|
cur.push(*this);
|
2004-04-13 06:27:29 +00:00
|
|
|
|
left ? idxFirst(cur) : idxLast(cur);
|
2004-04-06 19:25:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
string const MathHullInset::editMessage() const
|
|
|
|
|
{
|
|
|
|
|
return _("Math editor mode");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathHullInset::revealCodes(LCursor & cur) const
|
|
|
|
|
{
|
|
|
|
|
if (!cur.inMathed())
|
|
|
|
|
return;
|
|
|
|
|
ostringstream os;
|
|
|
|
|
cur.info(os);
|
2004-02-03 11:21:08 +00:00
|
|
|
|
cur.message(os.str());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
/*
|
|
|
|
|
// write something to the minibuffer
|
|
|
|
|
// translate to latex
|
|
|
|
|
cur.markInsert(bv);
|
|
|
|
|
ostringstream os;
|
|
|
|
|
write(NULL, os);
|
|
|
|
|
string str = os.str();
|
|
|
|
|
cur.markErase(bv);
|
|
|
|
|
string::size_type pos = 0;
|
|
|
|
|
string res;
|
|
|
|
|
for (string::iterator it = str.begin(); it != str.end(); ++it) {
|
|
|
|
|
if (*it == '\n')
|
|
|
|
|
res += ' ';
|
|
|
|
|
else if (*it == '\0') {
|
|
|
|
|
res += " -X- ";
|
|
|
|
|
pos = it - str.begin();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
res += *it;
|
|
|
|
|
}
|
|
|
|
|
if (pos > 30)
|
|
|
|
|
res = res.substr(pos - 30);
|
|
|
|
|
if (res.size() > 60)
|
|
|
|
|
res = res.substr(0, 60);
|
2004-02-03 11:21:08 +00:00
|
|
|
|
cur.message(res);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBase::Code MathHullInset::lyxCode() const
|
|
|
|
|
{
|
|
|
|
|
return MATH_CODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
#if 0
|
2004-01-26 10:13:15 +00:00
|
|
|
|
bool MathHullInset::searchForward(BufferView * bv, string const & str,
|
|
|
|
|
bool, bool)
|
|
|
|
|
{
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-04-13 06:27:29 +00:00
|
|
|
|
#warning completely broken
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#endif
|
2004-01-26 10:13:15 +00:00
|
|
|
|
static MathHullInset * lastformula = 0;
|
2004-03-31 19:11:56 +00:00
|
|
|
|
static CursorBase current = DocIterator(ibegin(nucleus()));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
static MathArray ar;
|
|
|
|
|
static string laststr;
|
|
|
|
|
|
|
|
|
|
if (lastformula != this || laststr != str) {
|
|
|
|
|
//lyxerr << "reset lastformula to " << this << endl;
|
|
|
|
|
lastformula = this;
|
|
|
|
|
laststr = str;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
current = ibegin(nucleus());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
ar.clear();
|
|
|
|
|
mathed_parse_cell(ar, str);
|
|
|
|
|
} else {
|
|
|
|
|
increment(current);
|
|
|
|
|
}
|
|
|
|
|
//lyxerr << "searching '" << str << "' in " << this << ar << endl;
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
for (DocIterator it = current; it != iend(nucleus()); increment(it)) {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
CursorSlice & top = it.back();
|
|
|
|
|
MathArray const & a = top.asMathInset()->cell(top.idx_);
|
|
|
|
|
if (a.matchpart(ar, top.pos_)) {
|
|
|
|
|
bv->cursor().setSelection(it, ar.size());
|
|
|
|
|
current = it;
|
|
|
|
|
top.pos_ += ar.size();
|
|
|
|
|
bv->update();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//lyxerr << "not found!" << endl;
|
|
|
|
|
lastformula = 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
void MathHullInset::write(Buffer const &, std::ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
WriteStream wi(os, false, false);
|
2004-04-07 18:15:29 +00:00
|
|
|
|
os << "Formula ";
|
2004-01-30 11:41:12 +00:00
|
|
|
|
write(wi);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathHullInset::read(Buffer const &, LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
MathAtom at;
|
|
|
|
|
mathed_parse_normal(at, lex);
|
|
|
|
|
operator=(*at->asHullInset());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathHullInset::plaintext(Buffer const &, ostream & os,
|
|
|
|
|
OutputParams const &) const
|
|
|
|
|
{
|
|
|
|
|
if (0 && display()) {
|
|
|
|
|
Dimension dim;
|
|
|
|
|
TextMetricsInfo mi;
|
|
|
|
|
metricsT(mi, dim);
|
|
|
|
|
TextPainter tpain(dim.width(), dim.height());
|
|
|
|
|
drawT(tpain, 0, dim.ascent());
|
|
|
|
|
tpain.show(os, 3);
|
|
|
|
|
// reset metrics cache to "real" values
|
|
|
|
|
//metrics();
|
|
|
|
|
return tpain.textheight();
|
|
|
|
|
} else {
|
|
|
|
|
WriteStream wi(os, false, true);
|
2004-09-21 09:58:23 +00:00
|
|
|
|
wi << cell(0);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return wi.line();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathHullInset::docbook(Buffer const & buf, ostream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
|
|
|
|
{
|
|
|
|
|
MathMLStream ms(os);
|
2004-08-13 11:00:34 +00:00
|
|
|
|
int res = 0;
|
|
|
|
|
string name;
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (getType() == hullSimple)
|
|
|
|
|
name = "inlineequation";
|
2004-08-13 11:00:34 +00:00
|
|
|
|
else
|
|
|
|
|
name = "informalequation";
|
|
|
|
|
|
2004-09-16 20:37:34 +00:00
|
|
|
|
string bname = name;
|
2004-11-23 23:04:52 +00:00
|
|
|
|
if (!label(0).empty())
|
2004-11-02 11:25:20 +00:00
|
|
|
|
bname += " id=\"" + sgml::cleanID(buf, runparams, label(0)) + "\"";
|
2004-08-13 11:00:34 +00:00
|
|
|
|
ms << MTag(bname.c_str());
|
|
|
|
|
|
2004-10-29 23:08:04 +00:00
|
|
|
|
ostringstream ls;
|
2004-08-13 11:00:34 +00:00
|
|
|
|
if (runparams.flavor == OutputParams::XML) {
|
2004-10-29 23:08:04 +00:00
|
|
|
|
ms << MTag("alt role=\"tex\" ");
|
|
|
|
|
// Workaround for db2latex: db2latex always includes equations with
|
|
|
|
|
// \ensuremath{} or \begin{display}\end{display}
|
|
|
|
|
// so we strip LyX' math environment
|
2004-10-05 15:48:36 +00:00
|
|
|
|
WriteStream wi(ls, false, false);
|
|
|
|
|
MathGridInset::write(wi);
|
2004-10-29 23:08:04 +00:00
|
|
|
|
ms << subst(subst(ls.str(), "&", "&"), "<", "<");
|
|
|
|
|
ms << ETag("alt");
|
|
|
|
|
ms << MTag("math");
|
|
|
|
|
MathGridInset::mathmlize(ms);
|
|
|
|
|
ms << ETag("math");
|
2004-08-13 11:00:34 +00:00
|
|
|
|
} else {
|
2004-11-23 23:04:52 +00:00
|
|
|
|
ms << MTag("alt role=\"tex\"");
|
2004-10-29 23:08:04 +00:00
|
|
|
|
res = latex(buf, ls, runparams);
|
|
|
|
|
ms << subst(subst(ls.str(), "&", "&"), "<", "<");
|
|
|
|
|
ms << ETag("alt");
|
2004-08-13 11:00:34 +00:00
|
|
|
|
}
|
2004-11-23 23:04:52 +00:00
|
|
|
|
|
2004-10-29 23:08:04 +00:00
|
|
|
|
ms << "<graphic fileref=\"eqn/";
|
2004-11-23 23:04:52 +00:00
|
|
|
|
if ( !label(0).empty())
|
2004-11-02 11:25:20 +00:00
|
|
|
|
ms << sgml::cleanID(buf, runparams, label(0));
|
2005-07-18 11:00:15 +00:00
|
|
|
|
else
|
2004-10-29 23:08:04 +00:00
|
|
|
|
ms << sgml::uniqueID("anon");
|
2005-07-18 11:00:15 +00:00
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
if (runparams.flavor == OutputParams::XML)
|
2004-10-29 23:08:04 +00:00
|
|
|
|
ms << "\"/>";
|
2004-11-23 23:04:52 +00:00
|
|
|
|
else
|
2004-10-29 23:08:04 +00:00
|
|
|
|
ms << "\">";
|
2004-11-23 23:04:52 +00:00
|
|
|
|
|
2004-08-13 11:00:34 +00:00
|
|
|
|
ms << ETag(name.c_str());
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return ms.line() + res;
|
|
|
|
|
}
|
2005-11-25 14:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathHullInset::textString(Buffer const & buf, ostream & os,
|
|
|
|
|
OutputParams const & op) const
|
|
|
|
|
{
|
|
|
|
|
return plaintext(buf, os, op);
|
|
|
|
|
}
|