2001-06-25 00:06:33 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_gridinset.h"
|
2001-12-03 17:52:48 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-12-03 16:24:50 +00:00
|
|
|
#include "math_streamstr.h"
|
2001-10-22 15:37:49 +00:00
|
|
|
#include "lyxfont.h"
|
2002-08-13 17:43:40 +00:00
|
|
|
#include "funcrequest.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/Painter.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::swap;
|
|
|
|
using std::max;
|
|
|
|
using std::min;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
|
2002-08-14 16:11:55 +00:00
|
|
|
void mathed_parse_normal(MathGridInset &, string const & argument);
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
namespace {
|
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
string verboseHLine(int n)
|
|
|
|
{
|
|
|
|
string res;
|
|
|
|
for (int i = 0; i < n; ++i)
|
|
|
|
res += "\\hline";
|
2002-10-11 10:45:28 +00:00
|
|
|
if (n)
|
|
|
|
res += " ";
|
|
|
|
return res;
|
2001-11-28 13:09:40 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::CellInfo::CellInfo()
|
|
|
|
: dummy_(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset::RowInfo::RowInfo()
|
2001-11-30 09:16:16 +00:00
|
|
|
: lines_(0), skip_(0)
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-09-05 12:57:13 +00:00
|
|
|
|
2001-08-10 12:12:03 +00:00
|
|
|
int MathGridInset::RowInfo::skipPixels() const
|
|
|
|
{
|
2002-07-09 08:24:33 +00:00
|
|
|
return crskip_.inBP();
|
2001-08-10 12:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset::ColInfo::ColInfo()
|
2001-11-28 13:09:40 +00:00
|
|
|
: align_('c'), leftline_(false), rightline_(false), lines_(0)
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
MathGridInset::MathGridInset(char v, string const & h)
|
2002-06-18 15:44:30 +00:00
|
|
|
: MathNestInset(guessColumns(h)),
|
|
|
|
rowinfo_(2),
|
|
|
|
colinfo_(guessColumns(h) + 1),
|
|
|
|
cellinfo_(1 * guessColumns(h))
|
2001-11-28 13:09:40 +00:00
|
|
|
{
|
|
|
|
setDefaults();
|
2002-03-21 17:42:56 +00:00
|
|
|
valign(v);
|
2001-11-28 13:09:40 +00:00
|
|
|
halign(h);
|
2002-08-12 09:53:04 +00:00
|
|
|
//lyxerr << "created grid with " << ncols() << " columns\n";
|
2001-11-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
MathGridInset::MathGridInset()
|
|
|
|
: MathNestInset(1),
|
|
|
|
rowinfo_(1 + 1),
|
|
|
|
colinfo_(1 + 1),
|
|
|
|
cellinfo_(1),
|
|
|
|
v_align_('c')
|
|
|
|
{
|
|
|
|
setDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathGridInset::MathGridInset(col_type m, row_type n)
|
2002-06-18 15:44:30 +00:00
|
|
|
: MathNestInset(m * n),
|
|
|
|
rowinfo_(n + 1),
|
|
|
|
colinfo_(m + 1),
|
|
|
|
cellinfo_(m * n),
|
|
|
|
v_align_('c')
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-05 12:57:13 +00:00
|
|
|
setDefaults();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-12 16:45:09 +00:00
|
|
|
MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
|
2002-06-18 15:44:30 +00:00
|
|
|
: MathNestInset(m * n),
|
|
|
|
rowinfo_(n + 1),
|
|
|
|
colinfo_(m + 1),
|
|
|
|
cellinfo_(m * n),
|
|
|
|
v_align_(v)
|
2001-10-12 12:02:49 +00:00
|
|
|
{
|
|
|
|
setDefaults();
|
2002-03-21 17:42:56 +00:00
|
|
|
valign(v);
|
2001-10-12 12:02:49 +00:00
|
|
|
halign(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-15 16:13:11 +00:00
|
|
|
MathInset * MathGridInset::clone() const
|
|
|
|
{
|
|
|
|
return new MathGridInset(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return col + ncols() * row;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-05 12:57:13 +00:00
|
|
|
void MathGridInset::setDefaults()
|
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
if (ncols() <= 0)
|
2001-11-28 13:09:40 +00:00
|
|
|
lyxerr << "positive number of columns expected\n";
|
2002-07-31 17:26:14 +00:00
|
|
|
//if (nrows() <= 0)
|
|
|
|
// lyxerr << "positive number of rows expected\n";
|
2001-09-26 16:52:34 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
2001-09-05 12:57:13 +00:00
|
|
|
colinfo_[col].align_ = defaultColAlign(col);
|
|
|
|
colinfo_[col].skip_ = defaultColSpace(col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathGridInset::halign(string const & hh)
|
|
|
|
{
|
2001-11-28 13:09:40 +00:00
|
|
|
col_type col = 0;
|
|
|
|
for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
|
2002-08-12 09:53:04 +00:00
|
|
|
if (col >= ncols())
|
|
|
|
break;
|
2001-11-28 13:09:40 +00:00
|
|
|
char c = *it;
|
|
|
|
if (c == '|') {
|
|
|
|
colinfo_[col].lines_++;
|
|
|
|
} else if (c == 'c' || c == 'l' || c == 'r') {
|
|
|
|
colinfo_[col].align_ = c;
|
|
|
|
++col;
|
|
|
|
colinfo_[col].lines_ = 0;
|
|
|
|
} else {
|
2002-08-12 09:53:04 +00:00
|
|
|
lyxerr << "unknown column separator: '" << c << "'\n";
|
2001-11-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
/*
|
2001-09-26 16:52:34 +00:00
|
|
|
col_type n = hh.size();
|
2001-06-25 00:06:33 +00:00
|
|
|
if (n > ncols())
|
|
|
|
n = ncols();
|
2001-09-26 16:52:34 +00:00
|
|
|
for (col_type col = 0; col < n; ++col)
|
|
|
|
colinfo_[col].align_ = hh[col];
|
2001-11-28 13:09:40 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
|
|
|
|
{
|
|
|
|
col_type col = 0;
|
|
|
|
for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
|
|
|
|
if (*it == 'c' || *it == 'l' || *it == 'r')
|
|
|
|
++col;
|
2002-08-12 09:53:04 +00:00
|
|
|
// let's have at least one column, even if we did not recognize its
|
|
|
|
// alignment
|
|
|
|
if (col == 0)
|
|
|
|
col = 1;
|
2001-11-28 13:09:40 +00:00
|
|
|
return col;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathGridInset::halign(char h, col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-04 13:32:06 +00:00
|
|
|
colinfo_[col].align_ = h;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
char MathGridInset::halign(col_type col) const
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2001-09-04 13:32:06 +00:00
|
|
|
return colinfo_[col].align_;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
string MathGridInset::halign() const
|
|
|
|
{
|
|
|
|
string res;
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
|
|
|
res += string(colinfo_[col].lines_, '|');
|
|
|
|
res += colinfo_[col].align_;
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-11-28 13:09:40 +00:00
|
|
|
return res + string(colinfo_[ncols()].lines_, '|');
|
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathGridInset::valign(char c)
|
|
|
|
{
|
|
|
|
v_align_ = c;
|
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
char MathGridInset::valign() const
|
|
|
|
{
|
|
|
|
return v_align_;
|
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
MathGridInset::col_type MathGridInset::ncols() const
|
|
|
|
{
|
|
|
|
return colinfo_.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::row_type MathGridInset::nrows() const
|
|
|
|
{
|
|
|
|
return rowinfo_.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::col_type MathGridInset::col(idx_type idx) const
|
|
|
|
{
|
|
|
|
return idx % ncols();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::row_type MathGridInset::row(idx_type idx) const
|
|
|
|
{
|
|
|
|
return idx / ncols();
|
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
|
2001-08-10 11:51:06 +00:00
|
|
|
{
|
2001-11-28 13:09:40 +00:00
|
|
|
rowinfo_[row].crskip_ = crskip;
|
2001-08-10 11:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
LyXLength MathGridInset::vcrskip(row_type row) const
|
2001-08-10 11:51:06 +00:00
|
|
|
{
|
2001-11-28 13:09:40 +00:00
|
|
|
return rowinfo_[row].crskip_;
|
2001-08-10 11:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathGridInset::metrics(MathMetricsInfo & mi) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
// let the cells adjust themselves
|
2001-10-22 15:37:49 +00:00
|
|
|
MathNestInset::metrics(mi);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-11-30 09:16:16 +00:00
|
|
|
// compute absolute sizes of vertical structure
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-06-25 00:06:33 +00:00
|
|
|
int asc = 0;
|
|
|
|
int desc = 0;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
2002-08-02 14:29:42 +00:00
|
|
|
MathArray const & c = cell(index(row, col));
|
2002-02-16 15:59:55 +00:00
|
|
|
asc = max(asc, c.ascent());
|
|
|
|
desc = max(desc, c.descent());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
rowinfo_[row].ascent_ = asc;
|
|
|
|
rowinfo_[row].descent_ = desc;
|
|
|
|
}
|
2002-02-11 08:19:02 +00:00
|
|
|
rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
|
2001-11-28 13:09:40 +00:00
|
|
|
rowinfo_[nrows()].ascent_ = 0;
|
|
|
|
rowinfo_[nrows()].descent_ = 0;
|
2001-11-30 09:16:16 +00:00
|
|
|
|
|
|
|
// compute vertical offsets
|
|
|
|
rowinfo_[0].offset_ = 0;
|
|
|
|
for (row_type row = 1; row <= nrows(); ++row) {
|
2002-03-21 17:42:56 +00:00
|
|
|
rowinfo_[row].offset_ =
|
2001-11-30 09:16:16 +00:00
|
|
|
rowinfo_[row - 1].offset_ +
|
|
|
|
rowinfo_[row - 1].descent_ +
|
|
|
|
rowinfo_[row - 1].skipPixels() +
|
2002-02-11 08:19:02 +00:00
|
|
|
rowsep() +
|
|
|
|
rowinfo_[row].lines_ * hlinesep() +
|
2001-11-30 09:16:16 +00:00
|
|
|
rowinfo_[row].ascent_;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
// adjust vertical offset
|
|
|
|
int h = 0;
|
|
|
|
switch (v_align_) {
|
2001-11-28 13:09:40 +00:00
|
|
|
case 't':
|
|
|
|
h = 0;
|
|
|
|
break;
|
|
|
|
case 'b':
|
2001-11-30 09:16:16 +00:00
|
|
|
h = rowinfo_[nrows() - 1].offset_;
|
2001-11-28 13:09:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
2001-11-30 09:16:16 +00:00
|
|
|
h = rowinfo_[nrows() - 1].offset_ / 2;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-11-30 09:16:16 +00:00
|
|
|
for (row_type row = 0; row <= nrows(); ++row)
|
2001-06-25 00:06:33 +00:00
|
|
|
rowinfo_[row].offset_ -= h;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-11-30 09:16:16 +00:00
|
|
|
|
|
|
|
// compute absolute sizes of horizontal structure
|
2001-09-26 16:52:34 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
2001-11-28 13:09:40 +00:00
|
|
|
int wid = 0;
|
2002-03-21 17:42:56 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2002-08-02 14:29:42 +00:00
|
|
|
wid = max(wid, cell(index(row, col)).width());
|
2001-11-30 09:16:16 +00:00
|
|
|
colinfo_[col].width_ = wid;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-11-28 13:09:40 +00:00
|
|
|
colinfo_[ncols()].width_ = 0;
|
2001-11-30 09:16:16 +00:00
|
|
|
|
|
|
|
// compute horizontal offsets
|
2002-02-11 08:19:02 +00:00
|
|
|
colinfo_[0].offset_ = border();
|
2001-11-30 09:16:16 +00:00
|
|
|
for (col_type col = 1; col <= ncols(); ++col) {
|
|
|
|
colinfo_[col].offset_ =
|
|
|
|
colinfo_[col - 1].offset_ +
|
2002-03-21 17:42:56 +00:00
|
|
|
colinfo_[col - 1].width_ +
|
2001-11-30 09:16:16 +00:00
|
|
|
colinfo_[col - 1].skip_ +
|
2002-03-21 17:42:56 +00:00
|
|
|
colsep() +
|
2002-02-11 08:19:02 +00:00
|
|
|
colinfo_[col].lines_ * vlinesep();
|
2001-11-30 09:16:16 +00:00
|
|
|
}
|
2001-11-28 13:09:40 +00:00
|
|
|
|
|
|
|
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.w = colinfo_[ncols() - 1].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
+ colinfo_[ncols() - 1].width_
|
|
|
|
+ vlinesep() * colinfo_[ncols()].lines_
|
|
|
|
+ border();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.a = - rowinfo_[0].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
+ rowinfo_[0].ascent_
|
|
|
|
+ hlinesep() * rowinfo_[0].lines_
|
|
|
|
+ border();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.d = rowinfo_[nrows() - 1].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
+ rowinfo_[nrows() - 1].descent_
|
|
|
|
+ hlinesep() * rowinfo_[nrows()].lines_
|
|
|
|
+ border();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
/*
|
2001-06-25 00:06:33 +00:00
|
|
|
// Increase ws_[i] for 'R' columns (except the first one)
|
|
|
|
for (int i = 1; i < nc_; ++i)
|
2001-09-04 13:32:06 +00:00
|
|
|
if (align_[i] == 'R')
|
2001-06-25 00:06:33 +00:00
|
|
|
ws_[i] += 10 * df_width;
|
|
|
|
// Increase ws_[i] for 'C' column
|
2001-09-04 13:32:06 +00:00
|
|
|
if (align_[0] == 'C')
|
2001-06-25 00:06:33 +00:00
|
|
|
if (ws_[0] < 7 * workwidth / 8)
|
|
|
|
ws_[0] = 7 * workwidth / 8;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
// Adjust local tabs
|
2002-02-11 08:19:02 +00:00
|
|
|
width = colsep();
|
2002-03-21 17:42:56 +00:00
|
|
|
for (cxrow = row_.begin(); cxrow; ++cxrow) {
|
2001-11-28 13:09:40 +00:00
|
|
|
int rg = COLSEP;
|
2001-06-25 00:06:33 +00:00
|
|
|
int lf = 0;
|
|
|
|
for (int i = 0; i < nc_; ++i) {
|
|
|
|
bool isvoid = false;
|
|
|
|
if (cxrow->getTab(i) <= 0) {
|
|
|
|
cxrow->setTab(i, df_width);
|
|
|
|
isvoid = true;
|
|
|
|
}
|
2001-09-04 13:32:06 +00:00
|
|
|
switch (align_[i]) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case 'l':
|
|
|
|
lf = 0;
|
|
|
|
break;
|
|
|
|
case 'c':
|
2002-03-21 17:42:56 +00:00
|
|
|
lf = (ws_[i] - cxrow->getTab(i))/2;
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
case 'R':
|
|
|
|
lf = ws_[i] - cxrow->getTab(i);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
if (cxrow == row_.begin())
|
|
|
|
lf = 0;
|
|
|
|
else if (cxrow.is_last())
|
|
|
|
lf = ws_[i] - cxrow->getTab(i);
|
|
|
|
else
|
2002-03-21 17:42:56 +00:00
|
|
|
lf = (ws_[i] - cxrow->getTab(i))/2;
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
|
|
|
|
cxrow->setTab(i, lf + rg);
|
2002-02-11 08:19:02 +00:00
|
|
|
rg = ws_[i] - ww + colsep();
|
2001-06-25 00:06:33 +00:00
|
|
|
if (cxrow == row_.begin())
|
2002-02-11 08:19:02 +00:00
|
|
|
width += ws_[i] + colsep();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
cxrow->setBaseline(cxrow->getBaseline() - ascent);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2001-08-08 09:31:36 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
void MathGridInset::draw(MathPainterInfo & pi, int x, int y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
|
2001-11-28 13:09:40 +00:00
|
|
|
|
|
|
|
for (row_type row = 0; row <= nrows(); ++row)
|
|
|
|
for (int i = 0; i < rowinfo_[row].lines_; ++i) {
|
|
|
|
int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
|
2002-02-11 08:19:02 +00:00
|
|
|
- i * hlinesep() - hlinesep()/2 - rowsep()/2;
|
2002-07-11 11:27:24 +00:00
|
|
|
pi.pain.line(x + 1, yy, x + width() - 1, yy);
|
2001-11-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (col_type col = 0; col <= ncols(); ++col)
|
|
|
|
for (int i = 0; i < colinfo_[col].lines_; ++i) {
|
|
|
|
int xx = x + colinfo_[col].offset_
|
2002-02-11 08:19:02 +00:00
|
|
|
- i * vlinesep() - vlinesep()/2 - colsep()/2;
|
2002-07-11 11:27:24 +00:00
|
|
|
pi.pain.line(xx, y - ascent() + 1, xx, y + descent() - 1);
|
2001-11-28 13:09:40 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 06:57:13 +00:00
|
|
|
void MathGridInset::metricsT(TextMetricsInfo const & mi) const
|
2002-03-19 16:55:58 +00:00
|
|
|
{
|
|
|
|
// let the cells adjust themselves
|
|
|
|
//MathNestInset::metrics(mi);
|
2002-03-21 17:42:56 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(i).metricsT(mi);
|
2002-03-19 16:55:58 +00:00
|
|
|
|
|
|
|
// compute absolute sizes of vertical structure
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
int asc = 0;
|
|
|
|
int desc = 0;
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
2002-08-02 14:29:42 +00:00
|
|
|
MathArray const & c = cell(index(row, col));
|
2002-03-19 16:55:58 +00:00
|
|
|
asc = max(asc, c.ascent());
|
|
|
|
desc = max(desc, c.descent());
|
|
|
|
}
|
|
|
|
rowinfo_[row].ascent_ = asc;
|
|
|
|
rowinfo_[row].descent_ = desc;
|
|
|
|
}
|
|
|
|
//rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
|
|
|
|
rowinfo_[nrows()].ascent_ = 0;
|
|
|
|
rowinfo_[nrows()].descent_ = 0;
|
|
|
|
|
|
|
|
// compute vertical offsets
|
|
|
|
rowinfo_[0].offset_ = 0;
|
|
|
|
for (row_type row = 1; row <= nrows(); ++row) {
|
2002-03-21 17:42:56 +00:00
|
|
|
rowinfo_[row].offset_ =
|
2002-03-19 16:55:58 +00:00
|
|
|
rowinfo_[row - 1].offset_ +
|
|
|
|
rowinfo_[row - 1].descent_ +
|
|
|
|
//rowinfo_[row - 1].skipPixels() +
|
|
|
|
1 + //rowsep() +
|
|
|
|
//rowinfo_[row].lines_ * hlinesep() +
|
|
|
|
rowinfo_[row].ascent_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust vertical offset
|
|
|
|
int h = 0;
|
|
|
|
switch (v_align_) {
|
|
|
|
case 't':
|
|
|
|
h = 0;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
h = rowinfo_[nrows() - 1].offset_;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
h = rowinfo_[nrows() - 1].offset_ / 2;
|
|
|
|
}
|
|
|
|
for (row_type row = 0; row <= nrows(); ++row)
|
|
|
|
rowinfo_[row].offset_ -= h;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2002-03-19 16:55:58 +00:00
|
|
|
|
|
|
|
// compute absolute sizes of horizontal structure
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
|
|
|
int wid = 0;
|
2002-03-21 17:42:56 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2002-08-02 14:29:42 +00:00
|
|
|
wid = max(wid, cell(index(row, col)).width());
|
2002-03-19 16:55:58 +00:00
|
|
|
colinfo_[col].width_ = wid;
|
|
|
|
}
|
|
|
|
colinfo_[ncols()].width_ = 0;
|
|
|
|
|
|
|
|
// compute horizontal offsets
|
|
|
|
colinfo_[0].offset_ = border();
|
|
|
|
for (col_type col = 1; col <= ncols(); ++col) {
|
|
|
|
colinfo_[col].offset_ =
|
|
|
|
colinfo_[col - 1].offset_ +
|
2002-03-21 17:42:56 +00:00
|
|
|
colinfo_[col - 1].width_ +
|
2002-03-19 16:55:58 +00:00
|
|
|
colinfo_[col - 1].skip_ +
|
2002-03-21 17:42:56 +00:00
|
|
|
1 ; //colsep() +
|
2002-03-19 16:55:58 +00:00
|
|
|
//colinfo_[col].lines_ * vlinesep();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.w = colinfo_[ncols() - 1].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
+ colinfo_[ncols() - 1].width_
|
|
|
|
//+ vlinesep() * colinfo_[ncols()].lines_
|
|
|
|
+ 2;
|
2002-03-19 16:55:58 +00:00
|
|
|
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.a = -rowinfo_[0].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
+ rowinfo_[0].ascent_
|
|
|
|
//+ hlinesep() * rowinfo_[0].lines_
|
|
|
|
+ 1;
|
2002-03-19 16:55:58 +00:00
|
|
|
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.d = rowinfo_[nrows() - 1].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
+ rowinfo_[nrows() - 1].descent_
|
|
|
|
//+ hlinesep() * rowinfo_[nrows()].lines_
|
|
|
|
+ 1;
|
2002-03-19 16:55:58 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 06:57:13 +00:00
|
|
|
void MathGridInset::drawT(TextPainter & pain, int x, int y) const
|
2002-03-19 16:55:58 +00:00
|
|
|
{
|
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
|
2002-03-19 16:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-24 18:10:01 +00:00
|
|
|
string MathGridInset::eolString(row_type row, bool fragile) const
|
2001-08-10 10:39:56 +00:00
|
|
|
{
|
2001-11-28 13:09:40 +00:00
|
|
|
string eol;
|
2001-08-10 10:39:56 +00:00
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
if (!rowinfo_[row].crskip_.zero())
|
2001-11-28 13:09:40 +00:00
|
|
|
eol += "[" + rowinfo_[row].crskip_.asLatexString() + "]";
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-08-10 10:39:56 +00:00
|
|
|
// make sure an upcoming '[' does not break anything
|
2001-11-28 13:09:40 +00:00
|
|
|
if (row + 1 < nrows()) {
|
|
|
|
MathArray const & c = cell(index(row + 1, 0));
|
|
|
|
if (c.size() && c.front()->getChar() == '[')
|
2002-02-01 14:56:49 +00:00
|
|
|
//eol += "[0pt]";
|
|
|
|
eol += "{}";
|
2001-11-28 13:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// only add \\ if necessary
|
|
|
|
if (eol.empty() && row + 1 == nrows())
|
|
|
|
return string();
|
2001-08-10 10:39:56 +00:00
|
|
|
|
2002-10-24 10:56:32 +00:00
|
|
|
return (fragile ? "\\protect\\\\" : "\\\\") + eol;
|
2001-08-10 10:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-15 18:04:01 +00:00
|
|
|
string MathGridInset::eocString(col_type col, col_type lastcol) const
|
2001-08-10 10:39:56 +00:00
|
|
|
{
|
2002-08-15 18:04:01 +00:00
|
|
|
if (col + 1 == lastcol)
|
2001-11-28 13:09:40 +00:00
|
|
|
return string();
|
2001-08-10 10:39:56 +00:00
|
|
|
return " & ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathGridInset::addRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
|
2002-06-18 15:44:30 +00:00
|
|
|
cells_.insert
|
2002-08-02 14:29:42 +00:00
|
|
|
(cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
|
2002-06-18 15:44:30 +00:00
|
|
|
cellinfo_.insert
|
|
|
|
(cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathGridInset::appendRow()
|
|
|
|
{
|
|
|
|
rowinfo_.push_back(RowInfo());
|
2002-08-02 14:29:42 +00:00
|
|
|
//cells_.insert(cells_.end(), ncols(), MathArray());
|
2002-06-18 15:44:30 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
2001-06-28 13:02:03 +00:00
|
|
|
cells_.push_back(cells_type::value_type());
|
2002-06-18 15:44:30 +00:00
|
|
|
cellinfo_.push_back(CellInfo());
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathGridInset::delRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (nrows() == 1)
|
|
|
|
return;
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
cells_type::iterator it = cells_.begin() + row * ncols();
|
2001-06-25 00:06:33 +00:00
|
|
|
cells_.erase(it, it + ncols());
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
|
|
|
|
cellinfo_.erase(jt, jt + ncols());
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
rowinfo_.erase(rowinfo_.begin() + row);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-21 13:47:52 +00:00
|
|
|
void MathGridInset::copyRow(row_type row)
|
|
|
|
{
|
|
|
|
addRow(row);
|
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
|
|
|
cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathGridInset::swapRow(row_type row)
|
|
|
|
{
|
|
|
|
if (nrows() == 1)
|
|
|
|
return;
|
|
|
|
if (row + 1 == nrows())
|
|
|
|
--row;
|
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
|
|
|
swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathGridInset::addCol(col_type newcol)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
const col_type nc = ncols();
|
|
|
|
const row_type nr = nrows();
|
2001-06-27 15:57:57 +00:00
|
|
|
cells_type new_cells((nc + 1) * nr);
|
2002-06-18 15:44:30 +00:00
|
|
|
vector<CellInfo> new_cellinfo((nc + 1) * nr);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nr; ++row)
|
2002-06-18 15:44:30 +00:00
|
|
|
for (col_type col = 0; col < nc; ++col) {
|
2001-06-25 00:06:33 +00:00
|
|
|
new_cells[row * (nc + 1) + col + (col > newcol)]
|
|
|
|
= cells_[row * nc + col];
|
2002-06-18 15:44:30 +00:00
|
|
|
new_cellinfo[row * (nc + 1) + col + (col > newcol)]
|
|
|
|
= cellinfo_[row * nc + col];
|
|
|
|
}
|
2002-02-16 15:59:55 +00:00
|
|
|
swap(cells_, new_cells);
|
2002-06-18 15:44:30 +00:00
|
|
|
swap(cellinfo_, new_cellinfo);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
ColInfo inf;
|
|
|
|
inf.skip_ = defaultColSpace(newcol);
|
|
|
|
inf.align_ = defaultColAlign(newcol);
|
|
|
|
colinfo_.insert(colinfo_.begin() + newcol, inf);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathGridInset::delCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (ncols() == 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cells_type tmpcells;
|
2002-06-18 15:44:30 +00:00
|
|
|
vector<CellInfo> tmpcellinfo;
|
2002-03-21 17:42:56 +00:00
|
|
|
for (col_type i = 0; i < nargs(); ++i)
|
2002-06-18 15:44:30 +00:00
|
|
|
if (i % ncols() != col) {
|
2001-06-25 00:06:33 +00:00
|
|
|
tmpcells.push_back(cells_[i]);
|
2002-06-18 15:44:30 +00:00
|
|
|
tmpcellinfo.push_back(cellinfo_[i]);
|
|
|
|
}
|
2002-02-16 15:59:55 +00:00
|
|
|
swap(cells_, tmpcells);
|
2002-06-18 15:44:30 +00:00
|
|
|
swap(cellinfo_, tmpcellinfo);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
colinfo_.erase(colinfo_.begin() + col);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-21 13:47:52 +00:00
|
|
|
void MathGridInset::copyCol(col_type col)
|
|
|
|
{
|
|
|
|
addCol(col);
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathGridInset::swapCol(col_type col)
|
|
|
|
{
|
|
|
|
if (ncols() == 1)
|
|
|
|
return;
|
|
|
|
if (col + 1 == ncols())
|
|
|
|
--col;
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
int MathGridInset::cellXOffset(idx_type idx) const
|
2001-08-08 09:31:36 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
col_type c = col(idx);
|
2001-08-08 09:31:36 +00:00
|
|
|
int x = colinfo_[c].offset_;
|
2001-09-04 13:32:06 +00:00
|
|
|
char align = colinfo_[c].align_;
|
2001-08-08 09:31:36 +00:00
|
|
|
if (align == 'r' || align == 'R')
|
2002-08-02 14:29:42 +00:00
|
|
|
x += colinfo_[c].width_ - cell(idx).width();
|
2001-08-08 09:31:36 +00:00
|
|
|
if (align == 'c' || align == 'C')
|
2002-08-02 14:29:42 +00:00
|
|
|
x += (colinfo_[c].width_ - cell(idx).width()) / 2;
|
2001-08-08 09:31:36 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
int MathGridInset::cellYOffset(idx_type idx) const
|
2001-08-08 09:31:36 +00:00
|
|
|
{
|
|
|
|
return rowinfo_[row(idx)].offset_;
|
|
|
|
}
|
|
|
|
|
2001-08-10 11:04:23 +00:00
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
|
|
|
|
int targetx) const
|
2002-03-21 09:48:46 +00:00
|
|
|
{
|
|
|
|
if (up) {
|
|
|
|
if (idx < ncols())
|
|
|
|
return false;
|
|
|
|
idx -= ncols();
|
2002-08-02 14:29:42 +00:00
|
|
|
pos = cell(idx).x2pos(targetx - cell(idx).xo());
|
2002-03-21 09:48:46 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (idx >= ncols() * (nrows() - 1))
|
|
|
|
return false;
|
|
|
|
idx += ncols();
|
2002-08-02 14:29:42 +00:00
|
|
|
pos = cell(idx).x2pos(targetx - cell(idx).xo());
|
2002-03-21 09:48:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
// leave matrix if on the left hand edge
|
|
|
|
if (col(idx) == 0)
|
|
|
|
return false;
|
2001-12-02 17:03:46 +00:00
|
|
|
--idx;
|
2001-06-25 00:06:33 +00:00
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
// leave matrix if on the right hand edge
|
2001-11-27 09:44:32 +00:00
|
|
|
if (col(idx) + 1 == ncols())
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2001-12-02 17:03:46 +00:00
|
|
|
++idx;
|
2001-06-25 00:06:33 +00:00
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
switch (v_align_) {
|
|
|
|
case 't':
|
|
|
|
idx = 0;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
idx = (nrows() - 1) * ncols();
|
|
|
|
break;
|
2002-03-21 17:42:56 +00:00
|
|
|
default:
|
2001-12-13 13:40:08 +00:00
|
|
|
idx = ((nrows() - 1) / 2) * ncols();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
switch (v_align_) {
|
|
|
|
case 't':
|
|
|
|
idx = ncols() - 1;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
idx = nargs() - 1;
|
|
|
|
break;
|
|
|
|
default:
|
2001-12-13 13:40:08 +00:00
|
|
|
idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-23 07:33:03 +00:00
|
|
|
bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
|
|
|
|
{
|
|
|
|
if (pos > 0) {
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (col(idx) > 0) {
|
|
|
|
idx -= idx % ncols();
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (idx > 0) {
|
|
|
|
idx = 0;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
|
|
|
|
{
|
|
|
|
if (pos < cell(idx).size()) {
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (col(idx) < ncols() - 1) {
|
|
|
|
idx = idx - idx % ncols() + ncols() - 1;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (idx < nargs() - 1) {
|
|
|
|
idx = nargs() - 1;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-25 12:11:25 +00:00
|
|
|
bool MathGridInset::idxDelete(idx_type & idx)
|
2001-07-09 16:59:57 +00:00
|
|
|
{
|
2002-04-08 09:37:27 +00:00
|
|
|
// nothing to do if we have just one row
|
|
|
|
if (nrows() == 1)
|
|
|
|
return false;
|
|
|
|
|
2002-03-07 17:48:28 +00:00
|
|
|
// nothing to do if we are in the middle of the last row of the inset
|
|
|
|
if (idx + ncols() > nargs())
|
2002-03-25 12:11:25 +00:00
|
|
|
return false;
|
2001-07-09 16:59:57 +00:00
|
|
|
|
2001-11-27 09:44:32 +00:00
|
|
|
// try to delete entire sequence of ncols() empty cells if possible
|
|
|
|
for (idx_type i = idx; i < idx + ncols(); ++i)
|
|
|
|
if (cell(i).size())
|
2002-03-25 12:11:25 +00:00
|
|
|
return false;
|
2001-11-27 09:44:32 +00:00
|
|
|
|
|
|
|
// move cells if necessary
|
|
|
|
for (idx_type i = index(row(idx), 0); i < idx; ++i)
|
2002-07-30 13:56:02 +00:00
|
|
|
std::swap(cell(i), cell(i + ncols()));
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-11-27 09:44:32 +00:00
|
|
|
delRow(row(idx));
|
|
|
|
|
|
|
|
if (idx >= nargs())
|
|
|
|
idx = nargs() - 1;
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
|
|
// undo effect of Ctrl-Tab (i.e. pull next cell)
|
2002-03-21 17:42:56 +00:00
|
|
|
//if (idx + 1 != nargs())
|
2001-07-09 16:59:57 +00:00
|
|
|
// cell(idx).swap(cell(idx + 1));
|
2002-03-25 12:11:25 +00:00
|
|
|
|
|
|
|
// we handled the event..
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// reimplement old behaviour when pressing Delete in the last position
|
|
|
|
// of a cell
|
|
|
|
void MathGridInset::idxGlue(idx_type idx)
|
|
|
|
{
|
|
|
|
col_type c = col(idx);
|
|
|
|
if (c + 1 == ncols()) {
|
|
|
|
if (row(idx) + 1 != nrows()) {
|
|
|
|
for (col_type cc = 0; cc < ncols(); ++cc)
|
2002-07-30 13:56:02 +00:00
|
|
|
cell(idx).append(cell(idx + cc + 1));
|
2002-03-25 12:11:25 +00:00
|
|
|
delRow(row(idx) + 1);
|
|
|
|
}
|
|
|
|
} else {
|
2002-07-30 13:56:02 +00:00
|
|
|
cell(idx).append(cell(idx + 1));
|
2002-03-25 12:11:25 +00:00
|
|
|
for (col_type cc = c + 2; cc < ncols(); ++cc)
|
|
|
|
cell(idx - c + cc - 1) = cell(idx - c + cc);
|
2002-07-30 13:56:02 +00:00
|
|
|
cell(idx - c + ncols() - 1).clear();
|
2002-03-25 12:11:25 +00:00
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
return rowinfo_[row];
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
return rowinfo_[row];
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-07-16 15:53:25 +00:00
|
|
|
|
|
|
|
|
2002-08-02 13:35:05 +00:00
|
|
|
bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
|
|
|
|
{
|
|
|
|
row_type const ri = row(idx);
|
|
|
|
row_type const r1 = min(row(from), row(to));
|
|
|
|
row_type const r2 = max(row(from), row(to));
|
|
|
|
col_type const ci = col(idx);
|
|
|
|
col_type const c1 = min(col(from), col(to));
|
|
|
|
col_type const c2 = max(col(from), col(to));
|
|
|
|
return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
2001-11-09 18:02:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathGridInset::normalize(NormalStream & os) const
|
|
|
|
{
|
|
|
|
os << "[grid ";
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
os << "[row ";
|
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
|
|
|
os << "[cell " << cell(index(row, col)) << ']';
|
|
|
|
os << ']';
|
|
|
|
}
|
|
|
|
os << ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathGridInset::mathmlize(MathMLStream & os) const
|
|
|
|
{
|
|
|
|
os << MTag("mtable");
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
os << MTag("mtr");
|
2002-03-21 17:42:56 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
2001-11-09 18:02:20 +00:00
|
|
|
os << cell(index(row, col));
|
|
|
|
os << ETag("mtr");
|
|
|
|
}
|
|
|
|
os << ETag("mtable");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathGridInset::write(WriteStream & os) const
|
|
|
|
{
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-12-02 17:03:46 +00:00
|
|
|
os << verboseHLine(rowinfo_[row].lines_);
|
2002-08-15 17:41:24 +00:00
|
|
|
// don't write & and empty cells at end of line
|
2002-08-15 18:04:01 +00:00
|
|
|
col_type lastcol = 0;
|
2002-10-24 10:56:32 +00:00
|
|
|
bool emptyline = true;
|
2002-03-21 17:42:56 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
2002-10-24 10:56:32 +00:00
|
|
|
if (!cell(index(row, col)).empty()) {
|
2002-08-15 18:04:01 +00:00
|
|
|
lastcol = col + 1;
|
2002-10-24 10:56:32 +00:00
|
|
|
emptyline = false;
|
|
|
|
}
|
2002-08-15 18:04:01 +00:00
|
|
|
for (col_type col = 0; col < lastcol; ++col)
|
|
|
|
os << cell(index(row, col)) << eocString(col, lastcol);
|
2002-06-24 18:10:01 +00:00
|
|
|
os << eolString(row, os.fragile());
|
2002-10-24 10:56:32 +00:00
|
|
|
// append newline only if line wasn't completely empty
|
2002-10-28 13:10:12 +00:00
|
|
|
// and this was not the last line in the grid
|
|
|
|
if (!emptyline && row + 1 < nrows())
|
2002-10-24 10:56:32 +00:00
|
|
|
os << "\n";
|
2001-11-09 18:02:20 +00:00
|
|
|
}
|
2001-12-02 17:03:46 +00:00
|
|
|
string const s = verboseHLine(rowinfo_[nrows()].lines_);
|
2002-06-18 15:44:30 +00:00
|
|
|
if (!s.empty() && s != " ") {
|
|
|
|
if (os.fragile())
|
|
|
|
os << "\\protect";
|
2001-12-02 17:03:46 +00:00
|
|
|
os << "\\\\" << s;
|
2002-06-18 15:44:30 +00:00
|
|
|
}
|
2001-11-09 18:02:20 +00:00
|
|
|
}
|
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
|
|
int MathGridInset::colsep() const
|
|
|
|
{
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathGridInset::rowsep() const
|
|
|
|
{
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathGridInset::hlinesep() const
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathGridInset::vlinesep() const
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathGridInset::border() const
|
|
|
|
{
|
2002-04-04 10:25:17 +00:00
|
|
|
return 1;
|
2002-02-11 08:19:02 +00:00
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
|
|
void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
|
|
|
|
{
|
|
|
|
if (idx + 1 == nargs())
|
|
|
|
return;
|
|
|
|
MathArray ar = cell(idx);
|
|
|
|
ar.erase(0, pos);
|
|
|
|
cell(idx).erase(pos, cell(idx).size());
|
|
|
|
++idx;
|
|
|
|
pos = 0;
|
|
|
|
cell(idx).insert(0, ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathInset::result_type MathGridInset::dispatch
|
|
|
|
(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_DELETE_LINE_FORWARD:
|
|
|
|
//autocorrect_ = false;
|
|
|
|
//macroModeClose();
|
|
|
|
//if (selection_) {
|
|
|
|
// selDel();
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
if (nrows() > 1)
|
|
|
|
delRow(row(idx));
|
|
|
|
if (idx >= nargs())
|
|
|
|
idx = nargs() - 1;
|
|
|
|
if (pos > cell(idx).size())
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return DISPATCHED_POP;
|
|
|
|
|
|
|
|
case LFUN_TABINSERT:
|
|
|
|
//bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
splitCell(idx, pos);
|
|
|
|
//updateLocal(bv, true);
|
|
|
|
return DISPATCHED_POP;
|
|
|
|
|
|
|
|
case LFUN_BREAKLINE: {
|
|
|
|
//bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
row_type const r = row(idx);
|
|
|
|
addRow(r);
|
|
|
|
|
|
|
|
// split line
|
|
|
|
for (col_type c = col(idx) + 1; c < ncols(); ++c)
|
|
|
|
std::swap(cell(index(r, c)), cell(index(r + 1, c)));
|
|
|
|
|
|
|
|
// split cell
|
|
|
|
splitCell(idx, pos);
|
|
|
|
std::swap(cell(idx), cell(idx + ncols() - 1));
|
2002-09-26 07:40:16 +00:00
|
|
|
if (idx > 0)
|
|
|
|
--idx;
|
|
|
|
pos = cell(idx).size();
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
|
|
//mathcursor->normalize();
|
|
|
|
//updateLocal(bv, true);
|
|
|
|
return DISPATCHED_POP;
|
|
|
|
}
|
|
|
|
|
2002-08-21 13:47:52 +00:00
|
|
|
case LFUN_TABULAR_FEATURE:
|
|
|
|
//lyxerr << "handling tabular-feature " << cmd.argument << "\n";
|
|
|
|
if (cmd.argument == "valign-top")
|
|
|
|
valign('t');
|
|
|
|
else if (cmd.argument == "valign-center")
|
|
|
|
valign('c');
|
|
|
|
else if (cmd.argument == "valign-bottom")
|
|
|
|
valign('b');
|
|
|
|
else if (cmd.argument == "align-left")
|
|
|
|
halign('l', col(idx));
|
|
|
|
else if (cmd.argument == "align-right")
|
|
|
|
halign('r', col(idx));
|
|
|
|
else if (cmd.argument == "align-center")
|
|
|
|
halign('c', col(idx));
|
|
|
|
else if (cmd.argument == "append-row")
|
|
|
|
addRow(row(idx));
|
|
|
|
else if (cmd.argument == "delete-row") {
|
|
|
|
delRow(row(idx));
|
|
|
|
if (idx > nargs())
|
|
|
|
idx -= ncols();
|
|
|
|
} else if (cmd.argument == "copy-row")
|
|
|
|
copyRow(row(idx));
|
|
|
|
else if (cmd.argument == "swap-row")
|
|
|
|
swapRow(row(idx));
|
|
|
|
else if (cmd.argument == "append-column") {
|
|
|
|
row_type r = row(idx);
|
|
|
|
col_type c = col(idx);
|
|
|
|
addCol(c);
|
|
|
|
idx = index(r, c);
|
|
|
|
} else if (cmd.argument == "delete-column") {
|
|
|
|
row_type r = row(idx);
|
|
|
|
col_type c = col(idx);
|
|
|
|
delCol(col(idx));
|
|
|
|
idx = index(r, c);
|
|
|
|
if (idx > nargs())
|
|
|
|
idx -= ncols();
|
|
|
|
} else if (cmd.argument == "copy-column")
|
|
|
|
copyCol(col(idx));
|
|
|
|
else if (cmd.argument == "swap-column")
|
|
|
|
swapCol(col(idx));
|
|
|
|
else
|
|
|
|
return UNDISPATCHED;
|
2002-08-14 15:13:07 +00:00
|
|
|
return DISPATCHED_POP;
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
|
|
case LFUN_PASTE: {
|
|
|
|
//lyxerr << "pasting '" << cmd.argument << "'\n";
|
|
|
|
MathGridInset grid(1, 1);
|
|
|
|
mathed_parse_normal(grid, cmd.argument);
|
|
|
|
if (grid.nargs() == 1) {
|
|
|
|
// single cell/part of cell
|
|
|
|
cell(idx).insert(pos, grid.cell(0));
|
|
|
|
pos += grid.cell(0).size();
|
|
|
|
} else {
|
|
|
|
// multiple cells
|
|
|
|
col_type const numcols = min(grid.ncols(), ncols() - col(idx));
|
|
|
|
row_type const numrows = min(grid.nrows(), nrows() - row(idx));
|
|
|
|
for (row_type r = 0; r < numrows; ++r) {
|
|
|
|
for (col_type c = 0; c < numcols; ++c) {
|
|
|
|
idx_type i = index(r + row(idx), c + col(idx));
|
|
|
|
cell(i).append(grid.cell(grid.index(r, c)));
|
|
|
|
}
|
|
|
|
// append the left over horizontal cells to the last column
|
|
|
|
idx_type i = index(r + row(idx), ncols() - 1);
|
|
|
|
for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
|
|
|
|
cell(i).append(grid.cell(grid.index(r, c)));
|
|
|
|
}
|
|
|
|
// append the left over vertical cells to the last _cell_
|
|
|
|
idx_type i = nargs() - 1;
|
|
|
|
for (row_type r = numrows; r < grid.nrows(); ++r)
|
|
|
|
for (col_type c = 0; c < grid.ncols(); ++c)
|
|
|
|
cell(i).append(grid.cell(grid.index(r, c)));
|
|
|
|
}
|
|
|
|
return DISPATCHED_POP;
|
|
|
|
}
|
2002-08-14 15:13:07 +00:00
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
default:
|
2002-08-15 10:02:53 +00:00
|
|
|
return MathNestInset::dispatch(cmd, idx, pos);
|
2002-08-13 17:43:40 +00:00
|
|
|
}
|
|
|
|
return UNDISPATCHED;
|
|
|
|
}
|