2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathHull.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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathArray.h"
|
|
|
|
#include "InsetMathChar.h"
|
|
|
|
#include "InsetMathColor.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathDelim.h"
|
|
|
|
#include "MathExtern.h"
|
|
|
|
#include "MathFactory.h"
|
|
|
|
#include "InsetMathHull.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathParser.h"
|
|
|
|
#include "InsetMathSpace.h"
|
|
|
|
#include "MathStream.h"
|
|
|
|
#include "MathSupport.h"
|
|
|
|
#include "InsetMathRef.h"
|
2006-09-16 18:11:38 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2008-03-09 23:43:05 +00:00
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#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 "LaTeXFeatures.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2008-09-02 20:02:08 +00:00
|
|
|
#include "Language.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
|
|
|
#include "OutputParams.h"
|
2008-02-15 08:09:35 +00:00
|
|
|
#include "ParIterator.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
#include "sgml.h"
|
2007-09-29 11:00:18 +00:00
|
|
|
#include "Text.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "TextPainter.h"
|
2008-02-15 08:09:35 +00:00
|
|
|
#include "TocBackend.h"
|
2002-08-14 16:11:55 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/RenderPreview.h"
|
|
|
|
#include "insets/InsetLabel.h"
|
2004-04-13 17:38:16 +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"
|
|
|
|
|
2007-05-12 06:24:46 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-19 21:00:33 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using cap::grabAndEraseSelection;
|
2003-06-30 23:56:22 +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"
|
2007-04-26 16:05:57 +00:00
|
|
|
size_t firstRelOp(MathData const & ar)
|
2001-10-18 13:21:21 +00:00
|
|
|
{
|
2007-04-26 16:05:57 +00:00
|
|
|
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
|
2001-10-18 13:21:21 +00:00
|
|
|
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-10-22 10:15:23 +00:00
|
|
|
HullType hullType(docstring const & s)
|
2006-09-03 16:14:51 +00:00
|
|
|
{
|
|
|
|
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;
|
2006-10-22 10:15:23 +00:00
|
|
|
lyxerr << "unknown hull type '" << to_utf8(s) << "'" << endl;
|
2006-09-03 16:14:51 +00:00
|
|
|
return HullType(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring hullName(HullType type)
|
2006-09-03 16:14:51 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
2006-10-22 10:15:23 +00:00
|
|
|
case hullNone: return from_ascii("none");
|
|
|
|
case hullSimple: return from_ascii("simple");
|
|
|
|
case hullEquation: return from_ascii("equation");
|
|
|
|
case hullEqnArray: return from_ascii("eqnarray");
|
|
|
|
case hullAlign: return from_ascii("align");
|
|
|
|
case hullAlignAt: return from_ascii("alignat");
|
|
|
|
case hullXAlignAt: return from_ascii("xalignat");
|
|
|
|
case hullXXAlignAt: return from_ascii("xxalignat");
|
|
|
|
case hullMultline: return from_ascii("multline");
|
|
|
|
case hullGather: return from_ascii("gather");
|
|
|
|
case hullFlAlign: return from_ascii("flalign");
|
2006-09-03 16:14:51 +00:00
|
|
|
default:
|
|
|
|
lyxerr << "unknown hull type '" << type << "'" << endl;
|
2006-10-22 10:15:23 +00:00
|
|
|
return from_ascii("none");
|
2006-09-03 16:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-04 12:50:06 +00:00
|
|
|
static InsetLabel * dummy_pointer = 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathHull::InsetMathHull()
|
2008-04-10 21:49:34 +00:00
|
|
|
: InsetMathGrid(1, 1), type_(hullNone), nonum_(1, false),
|
|
|
|
label_(1, dummy_pointer), preview_(new RenderPreview(this))
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
//lyxerr << "sizeof InsetMath: " << sizeof(InsetMath) << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
//lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
//lyxerr << "sizeof InsetMathChar: " << sizeof(InsetMathChar) << endl;
|
2007-10-28 18:51:54 +00:00
|
|
|
//lyxerr << "sizeof FontInfo: " << sizeof(FontInfo) << 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-16 18:11:38 +00:00
|
|
|
InsetMathHull::InsetMathHull(HullType type)
|
2008-04-10 21:49:34 +00:00
|
|
|
: InsetMathGrid(getCols(type), 1), type_(type), nonum_(1, false),
|
|
|
|
label_(1, dummy_pointer), 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
|
|
|
|
2008-05-06 14:11:20 +00:00
|
|
|
InsetMathHull::InsetMathHull(InsetMathHull const & other) : InsetMathGrid()
|
2008-03-04 12:22:48 +00:00
|
|
|
{
|
|
|
|
operator=(other);
|
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathHull::~InsetMathHull()
|
2008-03-04 12:22:48 +00:00
|
|
|
{
|
2008-03-06 19:31:14 +00:00
|
|
|
for (size_t i = 0; i < label_.size(); ++i)
|
|
|
|
delete label_[i];
|
2008-03-04 12:22:48 +00:00
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathHull::clone() const
|
2001-08-02 09:59:09 +00:00
|
|
|
{
|
2007-08-30 22:30:31 +00:00
|
|
|
return new InsetMathHull(*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
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathHull & InsetMathHull::operator=(InsetMathHull const & other)
|
2004-04-13 17:38:16 +00:00
|
|
|
{
|
|
|
|
if (this == &other)
|
2004-11-23 23:04:52 +00:00
|
|
|
return *this;
|
2008-03-04 12:22:48 +00:00
|
|
|
InsetMathGrid::operator=(other);
|
2004-04-13 17:38:16 +00:00
|
|
|
type_ = other.type_;
|
|
|
|
nonum_ = other.nonum_;
|
2008-03-06 19:31:14 +00:00
|
|
|
for (size_t i = 0; i < label_.size(); ++i)
|
|
|
|
delete label_[i];
|
2004-04-13 17:38:16 +00:00
|
|
|
label_ = other.label_;
|
2008-03-04 12:22:48 +00:00
|
|
|
for (size_t i = 0; i != label_.size(); ++i) {
|
|
|
|
if (label_[i])
|
|
|
|
label_[i] = new InsetLabel(*label_[i]);
|
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-04 12:22:48 +00:00
|
|
|
void InsetMathHull::setBuffer(Buffer & buffer)
|
|
|
|
{
|
|
|
|
buffer_ = &buffer;
|
2008-03-04 14:18:34 +00:00
|
|
|
for (idx_type i = 0, n = nargs(); i != n; ++i) {
|
|
|
|
MathData & data = cell(i);
|
|
|
|
for (size_t j = 0; j != data.size(); ++j)
|
|
|
|
data[j].nucleus()->setBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
2008-03-04 12:22:48 +00:00
|
|
|
for (size_t i = 0; i != label_.size(); ++i) {
|
|
|
|
if (label_[i])
|
|
|
|
label_[i]->setBuffer(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathHull::updateLabels(ParIterator const & it)
|
2008-02-15 08:09:35 +00:00
|
|
|
{
|
2008-02-28 10:04:15 +00:00
|
|
|
if (!buffer_) {
|
|
|
|
//FIXME: buffer_ should be set at creation for this inset! Problem is
|
|
|
|
// This inset is created at too many places (see Parser::parse1() in
|
|
|
|
// MathParser.cpp).
|
|
|
|
return;
|
|
|
|
}
|
2008-03-04 12:22:48 +00:00
|
|
|
for (size_t i = 0; i != label_.size(); ++i) {
|
|
|
|
if (label_[i])
|
|
|
|
label_[i]->updateLabels(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 10:04:15 +00:00
|
|
|
|
2008-05-13 08:23:44 +00:00
|
|
|
void InsetMathHull::addToToc(DocIterator const & pit)
|
2008-03-04 12:22:48 +00:00
|
|
|
{
|
|
|
|
if (!buffer_) {
|
|
|
|
//FIXME: buffer_ should be set at creation for this inset! Problem is
|
|
|
|
// This inset is created at too many places (see Parser::parse1() in
|
|
|
|
// MathParser.cpp).
|
2008-02-15 08:09:35 +00:00
|
|
|
return;
|
2008-03-04 12:22:48 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
Toc & toc = buffer().tocBackend().toc("equation");
|
2008-03-04 12:22:48 +00:00
|
|
|
|
|
|
|
for (row_type row = 0; row != nrows(); ++row) {
|
|
|
|
if (nonum_[row])
|
|
|
|
continue;
|
|
|
|
if (label_[row])
|
|
|
|
label_[row]->addToToc(pit);
|
|
|
|
toc.push_back(TocItem(pit, 0, nicelabel(row)));
|
|
|
|
}
|
2008-02-15 08:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * InsetMathHull::editXY(Cursor & cur, int x, int y)
|
2005-07-15 00:39:44 +00:00
|
|
|
{
|
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-09-16 18:11:38 +00:00
|
|
|
return InsetMathNest::editXY(cur, x, y);
|
2005-07-15 00:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMath::mode_type InsetMathHull::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetMathHull::idxFirst(Cursor & 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetMathHull::idxLast(Cursor & 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
char InsetMathHull::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];
|
2007-12-24 02:36:41 +00:00
|
|
|
if (type_ == hullGather)
|
|
|
|
return 'c';
|
|
|
|
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
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
int InsetMathHull::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring InsetMathHull::standardFont() const
|
2002-06-24 15:37:14 +00:00
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
return from_ascii(type_ == hullNone ? "lyxnochange" : "mathnormal");
|
2002-06-24 15:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::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) {
|
2006-10-21 00:16:43 +00:00
|
|
|
graphics::PreviewImage const * pimage =
|
2007-08-21 13:03:55 +00:00
|
|
|
preview_->getPreviewImage(bv->buffer());
|
2005-07-18 00:45:10 +00:00
|
|
|
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
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
|
2005-07-18 00:45:10 +00:00
|
|
|
{
|
|
|
|
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())
|
2006-09-08 13:52:41 +00:00
|
|
|
dim.des += displayMargin();
|
2008-10-13 11:25:37 +00:00
|
|
|
// Cache the inset dimension.
|
2007-09-23 22:39:49 +00:00
|
|
|
setDimCache(mi, dim);
|
2007-09-21 20:39:47 +00:00
|
|
|
return;
|
2004-04-13 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
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
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::metrics(mi, dim);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (display()) {
|
2006-09-08 13:52:41 +00:00
|
|
|
dim.asc += displayMargin();
|
|
|
|
dim.des += displayMargin();
|
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()) {
|
2006-10-22 10:15:23 +00:00
|
|
|
FontSetChanger dummy(mi.base, from_ascii("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);
|
2007-09-23 22:39:49 +00:00
|
|
|
// Cache the inset dimension.
|
|
|
|
// FIXME: This will overwrite InsetMathGrid dimension, is that OK?
|
|
|
|
setDimCache(mi, dim);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2008-10-25 10:47:38 +00:00
|
|
|
pi.pain.fillRectangle(x + 1, y - dim.asc + 1, dim.wid - 2,
|
|
|
|
dim.asc + dim.des - 1, pi.backgroundColor(this));
|
|
|
|
}
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
use_preview_ = previewState(pi.base.bv);
|
2007-05-12 06:24:46 +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);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::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_;
|
2006-10-22 10:15:23 +00:00
|
|
|
FontSetChanger dummy(pi.base, from_ascii("mathrm"));
|
2006-10-17 14:46:45 +00:00
|
|
|
docstring const nl = nicelabel(row);
|
|
|
|
pi.draw(xx, yy, nl);
|
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
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::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()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::metricsT(mi, dim);
|
2002-07-11 15:04:43 +00:00
|
|
|
} else {
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream os;
|
2008-05-31 20:54:50 +00:00
|
|
|
WriteStream wi(os, false, true, false);
|
2002-05-02 07:30:49 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::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()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::drawT(pain, x, y);
|
2002-07-11 15:04:43 +00:00
|
|
|
} else {
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream os;
|
2008-05-31 20:54:50 +00:00
|
|
|
WriteStream wi(os, false, true, false);
|
2002-05-02 07:30:49 +00:00
|
|
|
write(wi);
|
|
|
|
pain.draw(x, y, os.str().c_str());
|
|
|
|
}
|
2002-03-18 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-15 00:22:54 +00:00
|
|
|
static docstring latexString(InsetMathHull const & inset)
|
2004-04-13 17:38:16 +00:00
|
|
|
{
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream ls;
|
2008-09-02 20:02:08 +00:00
|
|
|
// This has to be static, because a preview snippet containing math
|
|
|
|
// in text mode (such as $\text{$\phi$}$) gets processed twice. The
|
|
|
|
// first time as a whole, and the second time only the inner math.
|
|
|
|
// In this last case inset.buffer() would be invalid.
|
2008-09-03 19:07:54 +00:00
|
|
|
// FIXME: preview snippets should only be processed once, such that
|
|
|
|
// both static qualifier and isBufferValid() check can be dropped.
|
2008-09-03 08:17:00 +00:00
|
|
|
static Encoding const * encoding = 0;
|
|
|
|
if (inset.isBufferValid())
|
|
|
|
encoding = &(inset.buffer().params().encoding());
|
2008-09-02 20:02:08 +00:00
|
|
|
WriteStream wi(ls, false, true, false, encoding);
|
2004-04-13 17:38:16 +00:00
|
|
|
inset.write(wi);
|
|
|
|
return ls.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-26 15:53:15 +00:00
|
|
|
void InsetMathHull::initUnicodeMath() const
|
|
|
|
{
|
|
|
|
// Trigger classification of the unicode symbols in this inset
|
|
|
|
docstring const dummy = latexString(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
void InsetMathHull::addPreview(graphics::PreviewLoader & ploader) const
|
2004-04-13 17:38:16 +00:00
|
|
|
{
|
2004-04-20 08:16:22 +00:00
|
|
|
if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
|
2008-03-15 00:22:54 +00:00
|
|
|
docstring const snippet = latexString(*this);
|
2004-04-20 08:16:22 +00:00
|
|
|
preview_->addPreview(snippet, ploader);
|
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
bool InsetMathHull::notifyCursorLeaves(Cursor const & /*old*/, Cursor & 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();
|
2008-03-15 00:22:54 +00:00
|
|
|
docstring const snippet = latexString(*this);
|
2004-08-13 19:19:24 +00:00
|
|
|
preview_->addPreview(snippet, buffer);
|
|
|
|
preview_->startLoading(buffer);
|
2007-04-04 16:17:24 +00:00
|
|
|
cur.updateFlags(Update::Force);
|
2004-08-13 19:19:24 +00:00
|
|
|
}
|
2006-08-17 21:32:04 +00:00
|
|
|
return false;
|
2004-04-13 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring InsetMathHull::label(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(row < nrows(), /**/);
|
2008-03-04 12:22:48 +00:00
|
|
|
if (InsetLabel * il = label_[row])
|
|
|
|
return il->screenLabel();
|
|
|
|
return docstring();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathHull::label(row_type row, docstring 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;
|
2008-03-04 12:22:48 +00:00
|
|
|
if (label_[row]) {
|
2008-03-09 23:43:05 +00:00
|
|
|
if (label.empty()) {
|
|
|
|
delete label_[row];
|
|
|
|
label_[row] = dummy_pointer;
|
2008-07-21 08:48:16 +00:00
|
|
|
// We need an update of the Buffer reference cache.
|
|
|
|
// This is achieved by updateLabels().
|
|
|
|
lyx::updateLabels(buffer());
|
2008-03-09 23:43:05 +00:00
|
|
|
} else
|
|
|
|
label_[row]->updateCommand(label);
|
2008-03-04 12:22:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InsetCommandParams p(LABEL_CODE);
|
|
|
|
p["name"] = label;
|
|
|
|
label_[row] = new InsetLabel(p);
|
|
|
|
if (buffer_)
|
|
|
|
label_[row]->setBuffer(buffer());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::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;
|
2008-03-04 12:22:48 +00:00
|
|
|
if (nonum_[row] && label_[row]) {
|
|
|
|
delete label_[row];
|
|
|
|
label_[row] = 0;
|
2008-07-21 08:48:16 +00:00
|
|
|
// We need an update of the Buffer reference cache.
|
|
|
|
// This is achieved by updateLabels().
|
|
|
|
lyx::updateLabels(buffer());
|
2008-03-04 12:22:48 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::numbered(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return !nonum_[row];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-18 14:32:29 +00:00
|
|
|
Inset::DisplayType InsetMathHull::display() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-05-18 14:32:29 +00:00
|
|
|
return (type_ != hullSimple && type_ != hullNone) ? AlignCenter : Inline;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::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-07-13 14:54:56 +00:00
|
|
|
//features.binom = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::validate(features);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::header_write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
bool n = numberedType();
|
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
switch(type_) {
|
|
|
|
case hullNone:
|
|
|
|
break;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullSimple:
|
2002-07-03 10:36:44 +00:00
|
|
|
os << '$';
|
|
|
|
if (cell(0).empty())
|
|
|
|
os << ' ';
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullEquation:
|
2002-07-03 10:36:44 +00:00
|
|
|
if (n)
|
|
|
|
os << "\\begin{equation" << star(n) << "}\n";
|
|
|
|
else
|
|
|
|
os << "\\[\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline:
|
|
|
|
os << "\\begin{" << hullName(type_) << star(n) << "}\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
os << "\\begin{" << hullName(type_) << star(n) << '}'
|
2002-11-27 10:30:28 +00:00
|
|
|
<< '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2002-08-14 18:31:53 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullXXAlignAt:
|
|
|
|
os << "\\begin{" << hullName(type_) << '}'
|
2002-11-27 10:30:28 +00:00
|
|
|
<< '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2002-08-14 18:31:53 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
default:
|
2002-11-27 10:30:28 +00:00
|
|
|
os << "\\begin{unknown" << star(n) << '}';
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::footer_write(WriteStream & os) const
|
2002-07-03 10:36:44 +00:00
|
|
|
{
|
|
|
|
bool n = numberedType();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
switch(type_) {
|
|
|
|
case hullNone:
|
2002-07-03 10:36:44 +00:00
|
|
|
os << "\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullSimple:
|
2002-07-03 10:36:44 +00:00
|
|
|
os << '$';
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullEquation:
|
2002-07-03 10:36:44 +00:00
|
|
|
if (n)
|
|
|
|
os << "\\end{equation" << star(n) << "}\n";
|
|
|
|
else
|
|
|
|
os << "\\]\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline:
|
|
|
|
os << "\\end{" << hullName(type_) << star(n) << "}\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hullXXAlignAt:
|
|
|
|
os << "\\end{" << hullName(type_) << "}\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-11-27 10:30:28 +00:00
|
|
|
os << "\\end{unknown" << star(n) << '}';
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::rowChangeOK() const
|
2004-11-23 14:43:37 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::colChangeOK() const
|
2002-08-21 13:47:52 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::addRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
if (!rowChangeOK())
|
|
|
|
return;
|
2008-03-11 17:54:05 +00:00
|
|
|
|
|
|
|
bool numbered = numberedType();
|
2008-05-06 06:41:08 +00:00
|
|
|
docstring lab;
|
2008-03-11 17:54:05 +00:00
|
|
|
if (type_ == hullMultline) {
|
2008-05-06 06:41:08 +00:00
|
|
|
if (row + 1 == nrows()) {
|
2008-03-11 17:54:05 +00:00
|
|
|
nonum_[row] = true;
|
2008-05-06 06:41:08 +00:00
|
|
|
lab = label(row);
|
|
|
|
} else
|
2008-03-11 17:54:05 +00:00
|
|
|
numbered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nonum_.insert(nonum_.begin() + row + 1, !numbered);
|
2008-03-04 12:50:06 +00:00
|
|
|
label_.insert(label_.begin() + row + 1, dummy_pointer);
|
2008-05-06 06:41:08 +00:00
|
|
|
if (!lab.empty())
|
|
|
|
label(row + 1, lab);
|
2007-11-05 20:54:28 +00:00
|
|
|
InsetMathGrid::addRow(row);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::swapRow(row_type row)
|
2003-10-06 09:57:03 +00:00
|
|
|
{
|
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;
|
2008-03-07 13:05:04 +00:00
|
|
|
// gcc implements the standard std::vector<bool> which is *not* a container:
|
|
|
|
// http://www.gotw.ca/publications/N1185.pdf
|
|
|
|
// As a results, it doesn't like this:
|
2008-03-04 13:15:02 +00:00
|
|
|
// swap(nonum_[row], nonum_[row + 1]);
|
|
|
|
// so we do it manually:
|
|
|
|
bool const b = nonum_[row];
|
2008-03-04 13:16:50 +00:00
|
|
|
nonum_[row] = nonum_[row + 1];
|
2008-03-04 13:15:02 +00:00
|
|
|
nonum_[row + 1] = b;
|
2004-01-28 16:21:29 +00:00
|
|
|
swap(label_[row], label_[row + 1]);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::swapRow(row);
|
2003-10-06 09:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::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;
|
2008-05-06 06:41:08 +00:00
|
|
|
if (row + 1 == nrows() && type_ == hullMultline) {
|
|
|
|
bool const b = nonum_[row - 1];
|
|
|
|
nonum_[row - 1] = nonum_[row];
|
|
|
|
nonum_[row] = b;
|
|
|
|
swap(label_[row - 1], label_[row]);
|
|
|
|
InsetMathGrid::delRow(row);
|
|
|
|
return;
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::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);
|
2008-03-06 19:31:14 +00:00
|
|
|
delete label_[row];
|
2001-06-25 00:06:33 +00:00
|
|
|
label_.erase(label_.begin() + row);
|
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::addCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
if (!colChangeOK())
|
|
|
|
return;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::addCol(col);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::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;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::delCol(col);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-17 14:46:45 +00:00
|
|
|
docstring InsetMathHull::nicelabel(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (nonum_[row])
|
2006-10-17 14:46:45 +00:00
|
|
|
return docstring();
|
2008-03-04 12:22:48 +00:00
|
|
|
if (!label_[row])
|
2006-10-21 00:16:43 +00:00
|
|
|
return from_ascii("(#)");
|
2008-03-15 11:40:04 +00:00
|
|
|
return '(' + label_[row]->screenLabel() + from_ascii(", #)");
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::glueall()
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData 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-16 18:11:38 +00:00
|
|
|
*this = InsetMathHull(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
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::splitTo2Cols()
|
2004-09-13 18:14:37 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(ncols() == 1, /**/);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::addCol(1);
|
2004-09-13 18:14:37 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
idx_type const i = 2 * row;
|
|
|
|
pos_type pos = firstRelOp(cell(i));
|
2007-04-26 16:05:57 +00:00
|
|
|
cell(i + 1) = MathData(cell(i).begin() + pos, cell(i).end());
|
2004-09-13 18:14:37 +00:00
|
|
|
cell(i).erase(pos, cell(i).size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::splitTo3Cols()
|
2004-09-13 18:14:37 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(ncols() < 3, /**/);
|
2004-09-13 18:14:37 +00:00
|
|
|
if (ncols() < 2)
|
|
|
|
splitTo2Cols();
|
2007-10-13 15:48:22 +00:00
|
|
|
InsetMathGrid::addCol(2);
|
2004-09-13 18:14:37 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
idx_type const i = 3 * row + 1;
|
|
|
|
if (cell(i).size()) {
|
2007-04-26 16:05:57 +00:00
|
|
|
cell(i + 1) = MathData(cell(i).begin() + 1, cell(i).end());
|
2004-09-13 18:14:37 +00:00
|
|
|
cell(i).erase(1, cell(i).size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::changeCols(col_type cols)
|
2004-09-13 18:14:37 +00:00
|
|
|
{
|
|
|
|
if (ncols() == cols)
|
|
|
|
return;
|
|
|
|
else if (ncols() < cols) {
|
|
|
|
// split columns
|
|
|
|
if (cols < 3)
|
|
|
|
splitTo2Cols();
|
|
|
|
else {
|
|
|
|
splitTo3Cols();
|
|
|
|
while (ncols() < cols)
|
2007-10-13 15:48:22 +00:00
|
|
|
InsetMathGrid::addCol(ncols());
|
2004-09-13 18:14:37 +00:00
|
|
|
}
|
|
|
|
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) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::delCol(ncols() - 1);
|
2004-09-13 18:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
HullType InsetMathHull::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-16 18:11:38 +00:00
|
|
|
void InsetMathHull::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-16 18:11:38 +00:00
|
|
|
void InsetMathHull::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
|
2008-03-04 12:22:48 +00:00
|
|
|
nonum_[0] = true;
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
if (!nonum_[row]) {
|
|
|
|
nonum_[0] = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-07-03 10:36:44 +00:00
|
|
|
|
|
|
|
// set first non-empty label
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2008-03-04 12:22:48 +00:00
|
|
|
if (label_[row]) {
|
|
|
|
label_[0] = 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();
|
|
|
|
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 {
|
2006-10-22 10:15:23 +00:00
|
|
|
lyxerr << "mutation from '" << to_utf8(hullName(type_))
|
|
|
|
<< "' to '" << to_utf8(hullName(newtype))
|
2006-10-03 07:56:27 +00:00
|
|
|
<< "' not implemented" << endl;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring InsetMathHull::eolString(row_type row, bool emptyline, bool fragile) const
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring res;
|
2002-08-15 17:41:24 +00:00
|
|
|
if (numberedType()) {
|
2008-03-04 12:22:48 +00:00
|
|
|
if (label_[row] && !nonum_[row])
|
2008-11-14 10:05:07 +00:00
|
|
|
res += "\\label{"
|
|
|
|
+ escape(label_[row]->getParam("name"))
|
|
|
|
+ '}';
|
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
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
return res + InsetMathGrid::eolString(row, emptyline, fragile);
|
2002-08-15 17:41:24 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::write(WriteStream & os) const
|
2002-08-15 17:41:24 +00:00
|
|
|
{
|
2008-09-02 20:04:05 +00:00
|
|
|
ModeSpecifier specifier(os, MATH_MODE);
|
2002-08-15 17:41:24 +00:00
|
|
|
header_write(os);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::write(os);
|
2001-12-05 08:04:20 +00:00
|
|
|
footer_write(os);
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::normalize(NormalStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2006-10-03 07:56:27 +00:00
|
|
|
os << "[formula " << hullName(type_) << ' ';
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::normalize(os);
|
2001-11-08 12:06:56 +00:00
|
|
|
os << "] ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathHull::mathmlize(MathStream & os) const
|
2001-11-09 18:02:20 +00:00
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::mathmlize(os);
|
2001-11-09 18:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathHull::infoize(odocstream & os) const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2006-10-03 07:56:27 +00:00
|
|
|
os << "Type: " << hullName(type_);
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 15:37:14 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::check() const
|
2001-12-11 15:04:02 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(nonum_.size() == nrows(), /**/);
|
|
|
|
LASSERT(label_.size() == nrows(), /**/);
|
2001-12-11 15:04:02 +00:00
|
|
|
}
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func)
|
2002-08-14 16:43:16 +00:00
|
|
|
{
|
2006-10-19 16:51:30 +00:00
|
|
|
docstring dlang;
|
|
|
|
docstring extra;
|
2006-10-21 00:16:43 +00:00
|
|
|
idocstringstream iss(func.argument());
|
2006-10-19 16:51:30 +00:00
|
|
|
iss >> dlang >> extra;
|
2002-08-14 16:43:16 +00:00
|
|
|
if (extra.empty())
|
2006-10-21 00:16:43 +00:00
|
|
|
extra = from_ascii("noextra");
|
2007-12-12 19:28:07 +00:00
|
|
|
string const lang = to_ascii(dlang);
|
2002-08-14 16:43:16 +00:00
|
|
|
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: temporarily disabled
|
2004-01-20 14:25:24 +00:00
|
|
|
//if (cur.selection()) {
|
2007-04-26 16:05:57 +00:00
|
|
|
// MathData 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;
|
|
|
|
//}
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData eq;
|
2006-09-16 18:11:38 +00:00
|
|
|
eq.push_back(MathAtom(new InsetMathChar('=')));
|
2002-08-14 16:43:16 +00:00
|
|
|
|
|
|
|
// 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);
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData ar;
|
2004-01-26 10:13:15 +00:00
|
|
|
if (cur.inMathed() && cur.selection()) {
|
2006-10-22 10:15:23 +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 {
|
2007-04-26 16:05:57 +00:00
|
|
|
ar = MathData(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);
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData & 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;
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData ar = cur.cell();
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "use cell: " << ar << endl;
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: temporarily disabled
|
2007-11-05 20:54:28 +00:00
|
|
|
addRow(cur.row());
|
2004-01-15 17:34:44 +00:00
|
|
|
++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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::doDispatch(Cursor & 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) {
|
|
|
|
|
2007-10-22 22:18:52 +00:00
|
|
|
case LFUN_FINISHED_BACKWARD:
|
|
|
|
case LFUN_FINISHED_FORWARD:
|
2008-02-10 19:57:00 +00:00
|
|
|
case LFUN_FINISHED_RIGHT:
|
|
|
|
case LFUN_FINISHED_LEFT:
|
2005-12-01 10:28:50 +00:00
|
|
|
//lyxerr << "action: " << cmd.action << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
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;
|
|
|
|
|
2008-03-26 08:10:01 +00:00
|
|
|
case LFUN_NEWLINE_INSERT:
|
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) {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2005-07-14 23:36:49 +00:00
|
|
|
bool const align =
|
2007-08-21 13:03:55 +00:00
|
|
|
cur.bv().buffer().params().use_amsmath == BufferParams::package_on;
|
2006-09-03 16:14:51 +00:00
|
|
|
mutate(align ? hullAlign : hullEqnArray);
|
2007-10-11 17:12:34 +00:00
|
|
|
cur.idx() = nrows() * ncols() - 1;
|
2004-04-18 19:41:40 +00:00
|
|
|
cur.pos() = cur.lastpos();
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2002-08-14 16:11:55 +00:00
|
|
|
|
2008-01-11 22:45:19 +00:00
|
|
|
case LFUN_MATH_NUMBER_TOGGLE: {
|
2004-02-16 11:58:51 +00:00
|
|
|
//lyxerr << "toggling all numbers" << endl;
|
2008-01-03 17:31:12 +00:00
|
|
|
cur.recordUndoInset();
|
|
|
|
bool old = numberedType();
|
|
|
|
if (type_ == hullMultline)
|
|
|
|
numbered(nrows() - 1, !old);
|
|
|
|
else
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
numbered(row, !old);
|
2008-10-13 11:25:37 +00:00
|
|
|
|
2008-01-03 17:31:12 +00:00
|
|
|
cur.message(old ? _("No number") : _("Number"));
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2008-01-03 17:31:12 +00:00
|
|
|
}
|
2002-08-14 16:11:55 +00:00
|
|
|
|
2008-01-11 22:45:19 +00:00
|
|
|
case LFUN_MATH_NUMBER_LINE_TOGGLE: {
|
2008-01-03 17:31:12 +00:00
|
|
|
cur.recordUndoInset();
|
|
|
|
row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
|
|
|
bool old = numbered(r);
|
|
|
|
cur.message(old ? _("No number") : _("Number"));
|
|
|
|
numbered(r, !old);
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2008-01-03 17:31:12 +00:00
|
|
|
}
|
2002-08-14 16:11:55 +00:00
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_LABEL_INSERT: {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2006-09-03 16:14:51 +00:00
|
|
|
row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring old_label = label(r);
|
2006-10-21 00:16:43 +00:00
|
|
|
docstring const default_label = from_ascii(
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
(lyxrc.label_init_length >= 0) ? "eq:" : "");
|
2006-01-10 12:49:34 +00:00
|
|
|
if (old_label.empty())
|
|
|
|
old_label = default_label;
|
2005-07-17 16:36:21 +00:00
|
|
|
|
2007-10-19 17:22:55 +00:00
|
|
|
InsetCommandParams p(LABEL_CODE);
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
|
2008-03-27 22:26:24 +00:00
|
|
|
string const data = InsetCommand::params2string("label", p);
|
2005-07-17 16:36:21 +00:00
|
|
|
|
2006-09-01 15:41:38 +00:00
|
|
|
if (cmd.argument().empty())
|
2007-11-18 00:39:15 +00:00
|
|
|
cur.bv().showDialog("label", data);
|
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
|
|
|
|
2008-03-09 23:43:05 +00:00
|
|
|
case LFUN_WORD_DELETE_FORWARD:
|
|
|
|
case LFUN_CHAR_DELETE_FORWARD:
|
|
|
|
if (col(cur.idx()) + 1 == ncols()
|
2008-03-10 17:09:02 +00:00
|
|
|
&& cur.pos() == cur.lastpos()) {
|
|
|
|
if (!label(row(cur.idx())).empty()) {
|
|
|
|
cur.recordUndoInset();
|
|
|
|
label(row(cur.idx()), docstring());
|
|
|
|
} else if (numbered(row(cur.idx()))) {
|
|
|
|
cur.recordUndoInset();
|
|
|
|
numbered(row(cur.idx()), false);
|
|
|
|
} else {
|
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
|
|
|
return;
|
|
|
|
}
|
2008-03-09 23:43:05 +00:00
|
|
|
} else {
|
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-17 16:36:21 +00:00
|
|
|
case LFUN_INSET_INSERT: {
|
2006-10-21 00:16:43 +00:00
|
|
|
//lyxerr << "arg: " << to_utf8(cmd.argument()) << endl;
|
2008-03-04 12:43:20 +00:00
|
|
|
// FIXME: this should be cleaned up to use InsetLabel methods directly.
|
2007-12-12 19:28:07 +00:00
|
|
|
string const name = cmd.getArg(0);
|
2005-07-17 16:36:21 +00:00
|
|
|
if (name == "label") {
|
2007-10-19 17:22:55 +00:00
|
|
|
InsetCommandParams p(LABEL_CODE);
|
2008-03-27 22:26:24 +00:00
|
|
|
InsetCommand::string2params(name, to_utf8(cmd.argument()), p);
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring str = p["name"];
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2006-09-03 16:14:51 +00:00
|
|
|
row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2007-12-12 19:57:42 +00:00
|
|
|
str = trim(str);
|
2005-07-17 16:36:21 +00:00
|
|
|
if (!str.empty())
|
|
|
|
numbered(r, true);
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring old = label(r);
|
2005-07-17 23:03:01 +00:00
|
|
|
if (str != old) {
|
2008-03-04 12:43:20 +00:00
|
|
|
if (label_[r])
|
|
|
|
// The label will take care of the reference update.
|
|
|
|
label(r, str);
|
|
|
|
else {
|
|
|
|
label(r, str);
|
|
|
|
// Newly created inset so initialize it.
|
|
|
|
label_[r]->initView();
|
|
|
|
}
|
2005-07-17 23:03:01 +00:00
|
|
|
}
|
2005-11-22 13:52:25 +00:00
|
|
|
break;
|
2005-07-17 16:36:21 +00:00
|
|
|
}
|
2006-09-30 17:17:31 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
|
|
|
return;
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_EXTERN:
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
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: {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2004-02-25 14:39:14 +00:00
|
|
|
row_type row = cur.row();
|
|
|
|
col_type col = cur.col();
|
2006-10-22 10:15:23 +00:00
|
|
|
mutate(hullType(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();
|
2008-10-13 11:25:37 +00:00
|
|
|
|
2008-02-08 16:19:58 +00:00
|
|
|
// FIXME: find some more clever handling of the selection,
|
|
|
|
// i.e. preserve it.
|
|
|
|
cur.clearSelection();
|
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: {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
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:
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetMathHull::getStatus(Cursor & 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) {
|
2007-10-22 22:18:52 +00:00
|
|
|
case LFUN_FINISHED_BACKWARD:
|
|
|
|
case LFUN_FINISHED_FORWARD:
|
2008-02-10 19:57:00 +00:00
|
|
|
case LFUN_FINISHED_RIGHT:
|
|
|
|
case LFUN_FINISHED_LEFT:
|
2007-05-29 20:53:32 +00:00
|
|
|
case LFUN_UP:
|
|
|
|
case LFUN_DOWN:
|
2008-03-26 08:10:01 +00:00
|
|
|
case LFUN_NEWLINE_INSERT:
|
2004-04-06 19:25:39 +00:00
|
|
|
case LFUN_MATH_EXTERN:
|
|
|
|
case LFUN_MATH_MUTATE:
|
|
|
|
case LFUN_MATH_DISPLAY:
|
|
|
|
// we handle these
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2004-04-06 19:25:39 +00:00
|
|
|
return true;
|
2008-01-11 22:45:19 +00:00
|
|
|
case LFUN_MATH_NUMBER_TOGGLE:
|
2008-01-03 17:31:12 +00:00
|
|
|
// FIXME: what is the right test, this or the one of
|
|
|
|
// LABEL_INSERT?
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(display());
|
2008-01-03 17:31:12 +00:00
|
|
|
status.setOnOff(numberedType());
|
|
|
|
return true;
|
2008-01-11 22:45:19 +00:00
|
|
|
case LFUN_MATH_NUMBER_LINE_TOGGLE: {
|
2008-01-03 17:31:12 +00:00
|
|
|
// FIXME: what is the right test, this or the one of
|
|
|
|
// LABEL_INSERT?
|
2008-05-06 06:41:08 +00:00
|
|
|
bool const enable = (type_ == hullMultline) ?
|
|
|
|
(nrows() - 1 == cur.row()) : display();
|
2008-01-03 17:31:12 +00:00
|
|
|
row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(enable);
|
2008-01-03 17:31:12 +00:00
|
|
|
status.setOnOff(numbered(r));
|
|
|
|
return true;
|
|
|
|
}
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_LABEL_INSERT:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(type_ != hullSimple);
|
2005-07-15 15:19:07 +00:00
|
|
|
return true;
|
2006-09-30 17:17:31 +00:00
|
|
|
case LFUN_INSET_INSERT:
|
|
|
|
if (cmd.getArg(0) == "label") {
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(type_ != hullSimple);
|
2006-09-30 17:17:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return InsetMathGrid::getStatus(cur, cmd, status);
|
2004-08-12 20:43:24 +00:00
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2006-10-21 00:16:43 +00:00
|
|
|
istringstream is(to_utf8(cmd.argument()));
|
2007-12-12 19:28:07 +00:00
|
|
|
string s;
|
2004-08-12 20:43:24 +00:00
|
|
|
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(
|
2006-10-21 00:16:43 +00:00
|
|
|
from_utf8(N_("Can't change number of rows in '%1$s'")),
|
2006-10-22 10:15:23 +00:00
|
|
|
hullName(type_)));
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(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(
|
2006-10-21 00:16:43 +00:00
|
|
|
from_utf8(N_("Can't change number of columns in '%1$s'")),
|
2006-10-22 10:15:23 +00:00
|
|
|
hullName(type_)));
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(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(
|
2006-10-21 00:16:43 +00:00
|
|
|
from_utf8(N_("Can't add horizontal grid lines in '%1$s'")),
|
2006-10-22 10:15:23 +00:00
|
|
|
hullName(type_)));
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(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(
|
2006-10-21 00:16:43 +00:00
|
|
|
from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
|
2006-10-22 10:15:23 +00:00
|
|
|
hullName(type_)));
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(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") {
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2005-04-25 14:10:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
return InsetMathGrid::getStatus(cur, cmd, status);
|
2004-08-12 20:43:24 +00:00
|
|
|
}
|
2004-04-06 19:25:39 +00:00
|
|
|
default:
|
2006-09-16 18:11:38 +00:00
|
|
|
return InsetMathGrid::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
|
2006-09-16 18:11:38 +00:00
|
|
|
return InsetMathGrid::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
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// simply scrap this function if you want
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::mutateToText()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
// translate to latex
|
|
|
|
ostringstream os;
|
2008-04-07 20:43:02 +00:00
|
|
|
latex(os, false, false);
|
2004-01-26 10:13:15 +00:00
|
|
|
string str = os.str();
|
|
|
|
|
|
|
|
// insert this text
|
2007-04-29 23:33:02 +00:00
|
|
|
Text * lt = view_->cursor().innerText();
|
2004-01-26 10:13:15 +00:00
|
|
|
string::const_iterator cit = str.begin();
|
|
|
|
string::const_iterator end = str.end();
|
|
|
|
for (; cit != end; ++cit)
|
2006-09-17 10:03:00 +00:00
|
|
|
view_->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
// remove ourselves
|
2006-10-21 00:16:43 +00:00
|
|
|
//dispatch(LFUN_ESCAPE);
|
2004-01-26 10:13:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::handleFont(Cursor & cur, docstring const & arg,
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring const & font)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
// this whole function is a hack and won't work for incremental font
|
|
|
|
// changes...
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndo();
|
2006-09-16 18:11:38 +00:00
|
|
|
if (cur.inset().asInsetMath()->name() == font)
|
2006-10-22 10:15:23 +00:00
|
|
|
cur.handleFont(to_utf8(font));
|
2004-01-26 10:13:15 +00:00
|
|
|
else {
|
2006-09-16 18:11:38 +00:00
|
|
|
cur.handleNest(createInsetMath(font));
|
2004-01-26 10:13:15 +00:00
|
|
|
cur.insert(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::handleFont2(Cursor & cur, docstring const & arg)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndo();
|
2007-04-29 18:17:15 +00:00
|
|
|
Font font;
|
2004-01-26 10:13:15 +00:00
|
|
|
bool b;
|
2007-09-29 11:00:18 +00:00
|
|
|
font.fromString(to_utf8(arg), b);
|
2007-10-28 18:51:54 +00:00
|
|
|
if (font.fontInfo().color() != Color_inherit) {
|
|
|
|
MathAtom at = MathAtom(new InsetMathColor(true, font.fontInfo().color()));
|
2005-06-17 14:35:19 +00:00
|
|
|
cur.handleNest(at, 0);
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-11 08:20:13 +00:00
|
|
|
void InsetMathHull::edit(Cursor & cur, bool front, EntryDirection entry_from)
|
2004-04-06 19:25:39 +00:00
|
|
|
{
|
|
|
|
cur.push(*this);
|
2008-10-13 11:25:37 +00:00
|
|
|
bool enter_front = (entry_from == Inset::ENTRY_DIRECTION_LEFT ||
|
2008-02-11 08:20:13 +00:00
|
|
|
(entry_from == Inset::ENTRY_DIRECTION_IGNORE && front));
|
2008-02-10 19:52:45 +00:00
|
|
|
enter_front ? idxFirst(cur) : idxLast(cur);
|
2007-04-13 11:35:11 +00:00
|
|
|
// The inset formula dimension is not necessarily the same as the
|
2007-04-13 11:49:58 +00:00
|
|
|
// one of the instant preview image, so we have to indicate to the
|
2007-05-28 22:27:45 +00:00
|
|
|
// BufferView that a metrics update is needed.
|
2007-04-13 11:35:11 +00:00
|
|
|
cur.updateFlags(Update::Force);
|
2004-04-06 19:25:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetMathHull::editMessage() const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2006-09-09 18:52:00 +00:00
|
|
|
return _("Math editor mode");
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::revealCodes(Cursor & cur) const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
if (!cur.inMathed())
|
|
|
|
return;
|
2006-10-22 10:15:23 +00:00
|
|
|
odocstringstream os;
|
2004-01-26 10:13:15 +00:00
|
|
|
cur.info(os);
|
2006-10-22 10:15:23 +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;
|
2008-04-07 20:43:02 +00:00
|
|
|
write(os);
|
2004-01-26 10:13:15 +00:00
|
|
|
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
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
InsetCode InsetMathHull::lyxCode() const
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
return MATH_CODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
#if 0
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::searchForward(BufferView * bv, string const & str,
|
2004-01-26 10:13:15 +00:00
|
|
|
bool, bool)
|
|
|
|
{
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: completely broken
|
2006-09-16 18:11:38 +00:00
|
|
|
static InsetMathHull * lastformula = 0;
|
2004-03-31 19:11:56 +00:00
|
|
|
static CursorBase current = DocIterator(ibegin(nucleus()));
|
2007-04-26 16:05:57 +00:00
|
|
|
static MathData ar;
|
2004-01-26 10:13:15 +00:00
|
|
|
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();
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData const & a = top.asInsetMath()->cell(top.idx_);
|
2004-01-26 10:13:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetMathHull::write(ostream & os) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream oss;
|
2008-05-31 20:54:50 +00:00
|
|
|
WriteStream wi(oss, false, false, false);
|
2006-10-19 16:51:30 +00:00
|
|
|
oss << "Formula ";
|
2004-01-30 11:41:12 +00:00
|
|
|
write(wi);
|
2006-10-21 00:16:43 +00:00
|
|
|
os << to_utf8(oss.str());
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetMathHull::read(Lexer & lex)
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
|
|
|
MathAtom at;
|
|
|
|
mathed_parse_normal(at, lex);
|
|
|
|
operator=(*at->asHullInset());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-31 15:19:39 +00:00
|
|
|
bool InsetMathHull::readQuiet(Lexer & lex)
|
2008-10-17 21:40:11 +00:00
|
|
|
{
|
|
|
|
MathAtom at;
|
2008-10-31 15:19:39 +00:00
|
|
|
bool result = mathed_parse_normal(at, lex, Parse::QUIET);
|
2008-10-17 21:40:11 +00:00
|
|
|
operator=(*at->asHullInset());
|
2008-10-31 15:19:39 +00:00
|
|
|
return result;
|
2008-10-17 21:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-20 01:50:54 +00:00
|
|
|
int InsetMathHull::plaintext(odocstream & os, OutputParams const & runparams) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
|
|
|
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 {
|
2007-02-24 15:06:04 +00:00
|
|
|
odocstringstream oss;
|
2008-07-20 01:50:54 +00:00
|
|
|
WriteStream wi(oss, false, true, false, runparams.encoding);
|
2004-09-21 09:58:23 +00:00
|
|
|
wi << cell(0);
|
2007-02-24 15:06:04 +00:00
|
|
|
|
|
|
|
docstring const str = oss.str();
|
|
|
|
os << str;
|
|
|
|
return str.size();
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
MathStream ms(os);
|
2004-08-13 11:00:34 +00:00
|
|
|
int res = 0;
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring name;
|
2006-09-03 16:14:51 +00:00
|
|
|
if (getType() == hullSimple)
|
2006-10-22 10:15:23 +00:00
|
|
|
name = from_ascii("inlineequation");
|
2004-08-13 11:00:34 +00:00
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
name = from_ascii("informalequation");
|
2004-08-13 11:00:34 +00:00
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring bname = name;
|
2004-11-23 23:04:52 +00:00
|
|
|
if (!label(0).empty())
|
2008-02-27 20:43:16 +00:00
|
|
|
bname += " id='" + sgml::cleanID(buffer(), runparams, label(0)) + "'";
|
2007-11-05 23:46:17 +00:00
|
|
|
|
|
|
|
++ms.tab(); ms.cr(); ms.os() << '<' << bname << '>';
|
2004-08-13 11:00:34 +00:00
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream ls;
|
2004-08-13 11:00:34 +00:00
|
|
|
if (runparams.flavor == OutputParams::XML) {
|
2007-11-05 23:46:17 +00:00
|
|
|
ms << MTag("alt role='tex' ");
|
2004-10-29 23:08:04 +00:00
|
|
|
// Workaround for db2latex: db2latex always includes equations with
|
|
|
|
// \ensuremath{} or \begin{display}\end{display}
|
|
|
|
// so we strip LyX' math environment
|
2008-07-20 01:50:54 +00:00
|
|
|
WriteStream wi(ls, false, false, false, runparams.encoding);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::write(wi);
|
2006-10-22 10:15:23 +00:00
|
|
|
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
|
2007-11-05 23:46:17 +00:00
|
|
|
ms << ETag("alt");
|
|
|
|
ms << MTag("math");
|
|
|
|
ms << ETag("alt");
|
|
|
|
ms << MTag("math");
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::mathmlize(ms);
|
2007-11-05 23:46:17 +00:00
|
|
|
ms << ETag("math");
|
2004-08-13 11:00:34 +00:00
|
|
|
} else {
|
2007-11-05 23:46:17 +00:00
|
|
|
ms << MTag("alt role='tex'");
|
2008-02-27 20:43:16 +00:00
|
|
|
res = latex(ls, runparams);
|
2006-10-22 10:15:23 +00:00
|
|
|
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
|
2007-11-05 23:46:17 +00:00
|
|
|
ms << ETag("alt");
|
2004-08-13 11:00:34 +00:00
|
|
|
}
|
2004-11-23 23:04:52 +00:00
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
ms << from_ascii("<graphic fileref=\"eqn/");
|
|
|
|
if (!label(0).empty())
|
2008-02-27 20:43:16 +00:00
|
|
|
ms << sgml::cleanID(buffer(), runparams, label(0));
|
2005-07-18 11:00:15 +00:00
|
|
|
else
|
2006-10-22 11:00:04 +00:00
|
|
|
ms << sgml::uniqueID(from_ascii("anon"));
|
2005-07-18 11:00:15 +00:00
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
if (runparams.flavor == OutputParams::XML)
|
2006-10-22 10:15:23 +00:00
|
|
|
ms << from_ascii("\"/>");
|
2004-11-23 23:04:52 +00:00
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
ms << from_ascii("\">");
|
2004-11-23 23:04:52 +00:00
|
|
|
|
2007-11-05 23:46:17 +00:00
|
|
|
ms.cr(); --ms.tab(); ms.os() << "</" << name << '>';
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
return ms.line() + res;
|
|
|
|
}
|
2005-11-25 14:40:34 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetMathHull::textString(odocstream & os) const
|
2005-11-25 14:40:34 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
plaintext(os, OutputParams(0));
|
2005-11-25 14:40:34 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2008-03-09 15:07:27 +00:00
|
|
|
docstring InsetMathHull::contextMenu(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
return from_ascii("context-math");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|