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>
|
|
|
|
|
|
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"
|
2002-10-29 14:13:02 +00:00
|
|
|
|
#include "math_cursor.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
|
#include "math_support.h"
|
2002-08-14 16:43:16 +00:00
|
|
|
|
#include "math_extern.h"
|
|
|
|
|
#include "math_charinset.h"
|
2002-05-02 07:30:49 +00:00
|
|
|
|
#include "textpainter.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "debug.h"
|
2002-08-13 17:43:40 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "gettext.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "LColor.h"
|
|
|
|
|
#include "lyxrc.h"
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/Alert.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
|
|
|
|
|
#include "support/std_sstream.h"
|
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::trim;
|
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;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::ostringstream;
|
2002-08-14 18:31:53 +00:00
|
|
|
|
using std::pair;
|
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 {
|
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
int getCols(string const & type)
|
2001-10-18 13:21:21 +00:00
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type == "eqnarray")
|
|
|
|
|
return 3;
|
|
|
|
|
if (type == "align")
|
|
|
|
|
return 2;
|
2002-10-14 12:56:21 +00:00
|
|
|
|
if (type == "flalign")
|
|
|
|
|
return 2;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type == "alignat")
|
|
|
|
|
return 2;
|
|
|
|
|
if (type == "xalignat")
|
|
|
|
|
return 2;
|
|
|
|
|
if (type == "xxalignat")
|
|
|
|
|
return 2;
|
2001-10-18 13:21:21 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
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"
|
2002-01-08 13:31:14 +00:00
|
|
|
|
MathArray::size_type 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
|
|
|
|
|
|
|
|
|
int typecode(string const & s)
|
2001-10-18 13:21:21 +00:00
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (s == "none") return 0;
|
|
|
|
|
if (s == "simple") return 1;
|
2003-05-02 07:52:15 +00:00
|
|
|
|
if (s == "equation") return 2;
|
|
|
|
|
if (s == "eqnarray") return 3;
|
|
|
|
|
if (s == "align") return 4;
|
|
|
|
|
if (s == "alignat") return 5;
|
|
|
|
|
if (s == "xalignat") return 6;
|
|
|
|
|
if (s == "xxalignat") return 7;
|
|
|
|
|
if (s == "multline") return 8;
|
|
|
|
|
if (s == "gather") return 9;
|
|
|
|
|
if (s == "flalign") return 10;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "unknown hull type '" << s << "'" << endl;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
return 0;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
bool smaller(string const & s, string const & t)
|
2001-10-18 13:21:21 +00:00
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
return typecode(s) < typecode(t);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2001-10-18 13:21:21 +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
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
MathHullInset::MathHullInset()
|
2002-07-03 10:36:44 +00:00
|
|
|
|
: MathGridInset(1, 1), type_("none"), nonum_(1), label_(1)
|
2001-09-04 13:32:06 +00:00
|
|
|
|
{
|
|
|
|
|
setDefaults();
|
|
|
|
|
}
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
MathHullInset::MathHullInset(string const & type)
|
|
|
|
|
: MathGridInset(getCols(type), 1), type_(type), nonum_(1), label_(1)
|
2002-02-14 13:25:26 +00:00
|
|
|
|
{
|
|
|
|
|
setDefaults();
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-18 11:02:33 +00:00
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> MathHullInset::clone() 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
|
|
|
|
|
2002-07-18 11:02:33 +00:00
|
|
|
|
MathInset::mode_type MathHullInset::currentMode() const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2002-07-18 11:02:33 +00:00
|
|
|
|
if (type_ == "none")
|
|
|
|
|
return UNDECIDED_MODE;
|
|
|
|
|
// definitely math mode ...
|
|
|
|
|
return MATH_MODE;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
bool MathHullInset::idxFirst(idx_type & idx, pos_type & pos) const
|
|
|
|
|
{
|
|
|
|
|
idx = 0;
|
|
|
|
|
pos = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathHullInset::idxLast(idx_type & idx, pos_type & pos) const
|
|
|
|
|
{
|
|
|
|
|
idx = nargs() - 1;
|
|
|
|
|
pos = cell(idx).size();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
char MathHullInset::defaultColAlign(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type_ == "eqnarray")
|
|
|
|
|
return "rcl"[col];
|
|
|
|
|
if (typecode(type_) >= typecode("align"))
|
|
|
|
|
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
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type_ == "align" || type_ == "alignat")
|
|
|
|
|
return 0;
|
|
|
|
|
if (type_ == "xalignat")
|
|
|
|
|
return (col & 1) ? 20 : 0;
|
2002-10-14 12:56:21 +00:00
|
|
|
|
if (type_ == "xxalignat" || type_ == "flalign")
|
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
|
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type_ == "none")
|
2002-06-24 15:37:14 +00:00
|
|
|
|
return "lyxnochange";
|
|
|
|
|
return "mathnormal";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-02-13 13:28:32 +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
|
2002-05-30 07:09:54 +00:00
|
|
|
|
MathGridInset::metrics(mi);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
if (display()) {
|
2003-05-27 13:55:03 +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)
|
2003-05-27 13:55:03 +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);
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.asc = max(dim_.asc, asc);
|
|
|
|
|
dim_.des = max(dim_.des, des);
|
2002-07-08 06:39:40 +00:00
|
|
|
|
|
|
|
|
|
// for markers
|
2002-07-11 11:27:24 +00:00
|
|
|
|
metricsMarkers2();
|
2003-06-02 10:03:27 +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
|
|
|
|
{
|
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");
|
2002-06-24 15:37:14 +00:00
|
|
|
|
drawStr(pi, pi.base.font, xx, yy, nicelabel(row));
|
2001-07-20 14:54:13 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2002-07-08 06:39:40 +00:00
|
|
|
|
|
2002-07-09 13:38:27 +00:00
|
|
|
|
drawMarkers2(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:30:26 +00:00
|
|
|
|
string MathHullInset::label(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2001-12-11 15:04:02 +00:00
|
|
|
|
row_type n = nrows();
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(row < n);
|
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
|
2002-07-03 10:36:44 +00:00
|
|
|
|
type_ == "align" ||
|
2002-10-14 12:56:21 +00:00
|
|
|
|
type_ == "flalign" ||
|
2002-07-03 10:36:44 +00:00
|
|
|
|
type_ == "multline" ||
|
|
|
|
|
type_ == "gather" ||
|
|
|
|
|
type_ == "alignat" ||
|
|
|
|
|
type_ == "xalignat" ||
|
|
|
|
|
type_ == "xxalignat";
|
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
|
|
|
|
{
|
2003-05-02 07:52:15 +00:00
|
|
|
|
return type_ != "simple" && type_ != "none";
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-18 20:18:39 +00:00
|
|
|
|
void MathHullInset::getLabelList(Buffer const &,
|
|
|
|
|
std::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
|
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type_ == "none")
|
2002-06-24 15:37:14 +00:00
|
|
|
|
return false;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type_ == "simple")
|
2002-06-24 15:37:14 +00:00
|
|
|
|
return false;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type_ == "xxalignat")
|
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();
|
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type_ == "none")
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
else if (type_ == "simple") {
|
|
|
|
|
os << '$';
|
|
|
|
|
if (cell(0).empty())
|
|
|
|
|
os << ' ';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else if (type_ == "equation") {
|
|
|
|
|
if (n)
|
|
|
|
|
os << "\\begin{equation" << star(n) << "}\n";
|
|
|
|
|
else
|
|
|
|
|
os << "\\[\n";
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-01-07 09:42:10 +00:00
|
|
|
|
else if (type_ == "eqnarray" || type_ == "align" || type_ == "flalign"
|
|
|
|
|
|| type_ == "gather" || type_ == "multline")
|
2002-07-03 10:36:44 +00:00
|
|
|
|
os << "\\begin{" << type_ << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-08-14 18:31:53 +00:00
|
|
|
|
else if (type_ == "alignat" || type_ == "xalignat")
|
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
|
|
|
|
|
|
|
|
|
else if (type_ == "xxalignat")
|
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
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (type_ == "none")
|
|
|
|
|
os << "\n";
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else if (type_ == "simple")
|
|
|
|
|
os << '$';
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else if (type_ == "equation")
|
|
|
|
|
if (n)
|
|
|
|
|
os << "\\end{equation" << star(n) << "}\n";
|
|
|
|
|
else
|
|
|
|
|
os << "\\]\n";
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
else if (type_ == "eqnarray" || type_ == "align" || type_ == "flalign"
|
2003-01-07 09:42:10 +00:00
|
|
|
|
|| type_ == "alignat" || type_ == "xalignat"
|
|
|
|
|
|| type_ == "gather" || type_ == "multline")
|
2003-03-17 16:25:00 +00:00
|
|
|
|
os << "\\end{" << type_ << star(n) << "}\n";
|
2001-09-04 14:56:30 +00:00
|
|
|
|
|
2003-01-07 09:42:10 +00:00
|
|
|
|
else if (type_ == "xxalignat")
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-21 13:47:52 +00:00
|
|
|
|
bool MathHullInset::colChangeOK() const
|
|
|
|
|
{
|
2002-08-29 06:49:27 +00:00
|
|
|
|
return
|
2002-10-14 12:56:21 +00:00
|
|
|
|
type_ == "align" || type_ == "flalign" ||type_ == "alignat" ||
|
2002-08-29 06:49:27 +00:00
|
|
|
|
type_ == "xalignat" || type_ == "xxalignat";
|
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
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (nrows() == 1)
|
|
|
|
|
return;
|
|
|
|
|
if (row + 1 == nrows())
|
|
|
|
|
--row;
|
|
|
|
|
std::swap(nonum_[row], nonum_[row + 1]);
|
|
|
|
|
std::swap(label_[row], label_[row + 1]);
|
|
|
|
|
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
|
|
|
|
{
|
2002-08-19 10:11:13 +00:00
|
|
|
|
if (nrows() <= 1)
|
|
|
|
|
return;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
MathGridInset::delRow(row);
|
|
|
|
|
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
|
|
|
|
{
|
2002-11-04 02:12:42 +00:00
|
|
|
|
if (colChangeOK())
|
2002-07-03 10:36:44 +00:00
|
|
|
|
MathGridInset::addCol(col);
|
2002-08-21 13:47:52 +00:00
|
|
|
|
else
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
|
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
|
|
|
|
{
|
2002-11-04 02:12:42 +00:00
|
|
|
|
if (colChangeOK())
|
2002-07-03 10:36:44 +00:00
|
|
|
|
MathGridInset::delCol(col);
|
2002-08-21 13:47:52 +00:00
|
|
|
|
else
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
|
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));
|
2002-07-03 10:36:44 +00:00
|
|
|
|
*this = MathHullInset("simple");
|
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
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
string const & 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
void MathHullInset::setType(string const & 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
void MathHullInset::mutate(string const & newtype)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2003-10-23 10:53:41 +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
|
2002-08-14 18:31:53 +00:00
|
|
|
|
// none <-> simple <-> equation <-> eqnarray
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
if (newtype == "dump") {
|
|
|
|
|
dump();
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else if (newtype == type_) {
|
|
|
|
|
// done
|
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
2003-05-02 07:52:15 +00:00
|
|
|
|
else if (type_ == "none") {
|
|
|
|
|
setType("simple");
|
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
|
|
|
|
|
2003-05-02 07:52:15 +00:00
|
|
|
|
else if (type_ == "simple") {
|
|
|
|
|
if (newtype == "none") {
|
|
|
|
|
setType("none");
|
|
|
|
|
} else {
|
|
|
|
|
setType("equation");
|
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
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else if (type_ == "equation") {
|
|
|
|
|
if (smaller(newtype, type_)) {
|
|
|
|
|
setType("simple");
|
|
|
|
|
mutate(newtype);
|
|
|
|
|
} else if (newtype == "eqnarray") {
|
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
|
|
|
|
|
|
// split it "nicely" on the firest relop
|
|
|
|
|
pos_type pos = firstRelOp(cell(0));
|
2002-07-30 13:56:02 +00:00
|
|
|
|
cell(1) = MathArray(cell(0).begin() + pos, cell(0).end());
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell(0).erase(pos, cell(0).size());
|
|
|
|
|
|
|
|
|
|
if (cell(1).size()) {
|
2002-07-30 13:56:02 +00:00
|
|
|
|
cell(2) = MathArray(cell(1).begin() + 1, cell(1).end());
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell(1).erase(1, cell(1).size());
|
|
|
|
|
}
|
|
|
|
|
setType("eqnarray");
|
|
|
|
|
mutate(newtype);
|
2002-08-08 12:45:38 +00:00
|
|
|
|
} else if (newtype == "multline" || newtype == "gather") {
|
2002-08-08 16:08:11 +00:00
|
|
|
|
setType(newtype);
|
2002-08-08 12:45:38 +00:00
|
|
|
|
numbered(0, false);
|
2002-08-14 18:31:53 +00:00
|
|
|
|
} else {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
|
// split it "nicely"
|
|
|
|
|
pos_type pos = firstRelOp(cell(0));
|
|
|
|
|
cell(1) = cell(0);
|
|
|
|
|
cell(0).erase(pos, cell(0).size());
|
|
|
|
|
cell(1).erase(0, pos);
|
|
|
|
|
setType("align");
|
|
|
|
|
mutate(newtype);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else if (type_ == "eqnarray") {
|
|
|
|
|
if (smaller(newtype, type_)) {
|
|
|
|
|
// 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.
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
|
idx_type c = 3 * row + 1;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
cell(c).append(cell(c + 1));
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2002-07-03 10:36:44 +00:00
|
|
|
|
MathGridInset::delCol(2);
|
|
|
|
|
setType("align");
|
|
|
|
|
mutate(newtype);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else if (type_ == "align") {
|
|
|
|
|
if (smaller(newtype, type_)) {
|
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
|
setType("eqnarray");
|
|
|
|
|
mutate(newtype);
|
|
|
|
|
} else {
|
|
|
|
|
setType(newtype);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-09-04 14:56:30 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else if (type_ == "multline") {
|
2002-11-04 02:12:42 +00:00
|
|
|
|
if (newtype == "gather" || newtype == "align" ||
|
2002-10-14 12:56:21 +00:00
|
|
|
|
newtype == "xalignat" || newtype == "xxalignat" || newtype == "flalign")
|
2002-08-21 13:47:52 +00:00
|
|
|
|
setType(newtype);
|
|
|
|
|
else if (newtype == "eqnarray") {
|
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
|
setType("eqnarray");
|
2002-07-03 10:36:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "mutation from '" << type_
|
2002-08-21 13:47:52 +00:00
|
|
|
|
<< "' to '" << newtype << "' not implemented" << endl;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (type_ == "gather") {
|
|
|
|
|
if (newtype == "multline") {
|
|
|
|
|
setType("multline");
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "mutation from '" << type_
|
|
|
|
|
<< "' to '" << newtype << "' not implemented" << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-09-04 14:56:30 +00:00
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else {
|
|
|
|
|
lyxerr << "mutation from '" << type_
|
|
|
|
|
<< "' to '" << newtype << "' not implemented" << endl;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
|
|
|
|
|
2002-08-15 17:41:24 +00:00
|
|
|
|
string MathHullInset::eolString(row_type row, 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] + '}';
|
2003-01-07 09:42:10 +00:00
|
|
|
|
if (nonum_[row] && (type_ != "multline"))
|
2002-08-15 17:41:24 +00:00
|
|
|
|
res += "\\nonumber ";
|
2001-11-08 12:06:56 +00:00
|
|
|
|
}
|
2002-08-15 17:41:24 +00:00
|
|
|
|
return res + MathGridInset::eolString(row, fragile);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
void MathHullInset::infoize(std::ostream & os) const
|
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
|
2002-08-14 16:43:16 +00:00
|
|
|
|
void MathHullInset::doExtern
|
|
|
|
|
(FuncRequest const & func, idx_type & idx, pos_type & pos)
|
|
|
|
|
{
|
|
|
|
|
string lang;
|
|
|
|
|
string extra;
|
|
|
|
|
istringstream iss(func.argument.c_str());
|
|
|
|
|
iss >> lang >> extra;
|
|
|
|
|
if (extra.empty())
|
|
|
|
|
extra = "noextra";
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning temporarily disabled
|
|
|
|
|
//if (selection()) {
|
|
|
|
|
// MathArray ar;
|
|
|
|
|
// selGet(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
|
|
|
|
|
idx -= idx % ncols();
|
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
|
|
if (getType() == "simple") {
|
|
|
|
|
size_type pos = cell(idx).find_last(eq);
|
|
|
|
|
MathArray ar;
|
2002-10-29 14:13:02 +00:00
|
|
|
|
if (mathcursor && mathcursor->selection()) {
|
2003-06-02 10:03:27 +00:00
|
|
|
|
asArray(mathcursor->grabAndEraseSelection(), ar);
|
2002-10-29 14:13:02 +00:00
|
|
|
|
} else if (pos == cell(idx).size()) {
|
2002-08-14 16:43:16 +00:00
|
|
|
|
ar = cell(idx);
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use whole cell: " << ar << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
} else {
|
|
|
|
|
ar = MathArray(cell(idx).begin() + pos + 1, cell(idx).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
|
|
|
|
}
|
|
|
|
|
cell(idx).append(eq);
|
|
|
|
|
cell(idx).append(pipeThroughExtern(lang, extra, ar));
|
|
|
|
|
pos = cell(idx).size();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (getType() == "equation") {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use equation inset" << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
mutate("eqnarray");
|
|
|
|
|
MathArray & ar = cell(idx);
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use cell: " << ar << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
cell(idx + 1) = eq;
|
|
|
|
|
cell(idx + 2) = pipeThroughExtern(lang, extra, ar);
|
|
|
|
|
// move to end of line
|
|
|
|
|
idx += 2;
|
|
|
|
|
pos = cell(idx).size();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "use eqnarray" << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
idx -= idx % ncols();
|
|
|
|
|
idx += 2;
|
|
|
|
|
pos = 0;
|
|
|
|
|
MathArray ar = cell(idx);
|
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
|
|
|
|
|
addRow(row(idx));
|
|
|
|
|
cell(idx + 2) = eq;
|
|
|
|
|
cell(idx + 3) = pipeThroughExtern(lang, extra, ar);
|
|
|
|
|
idx += 3;
|
|
|
|
|
pos = cell(idx).size();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult MathHullInset::priv_dispatch
|
2002-08-13 17:43:40 +00:00
|
|
|
|
(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_BREAKLINE:
|
|
|
|
|
if (type_ == "simple" || type_ == "equation") {
|
|
|
|
|
mutate("eqnarray");
|
|
|
|
|
idx = 1;
|
|
|
|
|
pos = 0;
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(FINISHED);
|
2002-08-14 18:31:53 +00:00
|
|
|
|
}
|
2003-10-17 18:01:15 +00:00
|
|
|
|
return MathGridInset::priv_dispatch(cmd, idx, pos);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MATH_NUMBER:
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "toggling all numbers" << endl;
|
2002-08-13 17:43:40 +00:00
|
|
|
|
if (display()) {
|
2003-07-25 19:18:43 +00:00
|
|
|
|
//recordUndo(bv, Undo::INSERT);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
bool old = numberedType();
|
2003-01-07 09:42:10 +00:00
|
|
|
|
if (type_ == "multline")
|
|
|
|
|
numbered(nrows() - 1, !old);
|
|
|
|
|
else
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
|
numbered(row, !old);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
//bv->owner()->message(old ? _("No number") : _("Number"));
|
|
|
|
|
}
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(DISPATCHED);
|
2002-08-14 18:31:53 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MATH_NONUMBER:
|
2002-08-13 17:43:40 +00:00
|
|
|
|
if (display()) {
|
2003-01-07 09:42:10 +00:00
|
|
|
|
row_type r = (type_ == "multline") ? nrows() - 1 : row(idx);
|
2003-07-25 19:18:43 +00:00
|
|
|
|
//recordUndo(bv, Undo::INSERT);
|
2003-01-07 09:42:10 +00:00
|
|
|
|
bool old = numbered(r);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
//bv->owner()->message(old ? _("No number") : _("Number"));
|
2003-01-07 09:42:10 +00:00
|
|
|
|
numbered(r, !old);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(DISPATCHED);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
2002-08-14 16:11:55 +00:00
|
|
|
|
case LFUN_INSERT_LABEL: {
|
2003-01-07 09:42:10 +00:00
|
|
|
|
row_type r = (type_ == "multline") ? nrows() - 1 : row(idx);
|
2002-08-14 16:11:55 +00:00
|
|
|
|
string old_label = label(r);
|
|
|
|
|
string new_label = cmd.argument;
|
|
|
|
|
|
|
|
|
|
if (new_label.empty()) {
|
|
|
|
|
string const default_label =
|
|
|
|
|
(lyxrc.label_init_length >= 0) ? "eq:" : "";
|
|
|
|
|
pair<bool, string> const res = old_label.empty()
|
|
|
|
|
? Alert::askForText(_("Enter new label to insert:"), default_label)
|
|
|
|
|
: Alert::askForText(_("Enter label:"), old_label);
|
|
|
|
|
if (!res.first)
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(UNDISPATCHED);
|
2002-08-14 16:11:55 +00:00
|
|
|
|
new_label = trim(res.second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if (new_label == old_label)
|
|
|
|
|
// break; // Nothing to do
|
|
|
|
|
|
|
|
|
|
if (!new_label.empty())
|
|
|
|
|
numbered(r, true);
|
|
|
|
|
label(r, new_label);
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(DISPATCHED);
|
2002-08-14 16:11:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-14 16:43:16 +00:00
|
|
|
|
case LFUN_MATH_EXTERN:
|
|
|
|
|
doExtern(cmd, idx, pos);
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(FINISHED);
|
2002-08-14 16:43:16 +00:00
|
|
|
|
|
2002-08-15 14:33:14 +00:00
|
|
|
|
case LFUN_MATH_MUTATE: {
|
2003-10-23 10:53:41 +00:00
|
|
|
|
lyxerr << "Hull: MUTATE: " << cmd.argument << endl;
|
2002-08-15 14:33:14 +00:00
|
|
|
|
row_type r = row(idx);
|
|
|
|
|
col_type c = col(idx);
|
|
|
|
|
mutate(cmd.argument);
|
|
|
|
|
idx = r * ncols() + c;
|
|
|
|
|
if (idx >= nargs())
|
|
|
|
|
idx = nargs() - 1;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
if (pos > cell(idx).size())
|
2002-08-15 14:33:14 +00:00
|
|
|
|
pos = cell(idx).size();
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(FINISHED);
|
2002-08-15 14:33:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_MATH_DISPLAY: {
|
|
|
|
|
mutate(type_ == "simple" ? "equation" : "simple");
|
|
|
|
|
idx = 0;
|
|
|
|
|
pos = cell(idx).size();
|
2003-10-29 19:19:27 +00:00
|
|
|
|
return DispatchResult(FINISHED);
|
2002-08-15 14:33:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
|
default:
|
2003-10-17 18:01:15 +00:00
|
|
|
|
return MathGridInset::priv_dispatch(cmd, idx, pos);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-28 08:44:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string MathHullInset::fileInsetLabel() const
|
|
|
|
|
{
|
|
|
|
|
return "Formula";
|
|
|
|
|
}
|