2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_gridinset.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.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-08-02 11:30:30 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-07-17 07:38:41 +00:00
|
|
|
|
#include "math_gridinset.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_data.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"
|
2004-04-05 16:31:52 +00:00
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-04-18 07:34:15 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2004-04-05 16:31:52 +00:00
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
|
#include "LColor.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "debug.h"
|
2002-08-13 17:43:40 +00:00
|
|
|
|
#include "funcrequest.h"
|
2005-02-14 14:25:18 +00:00
|
|
|
|
#include "gettext.h"
|
2004-04-18 19:41:40 +00:00
|
|
|
|
#include "undo.h"
|
2004-01-16 12:36:23 +00:00
|
|
|
|
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2004-01-16 12:36:23 +00:00
|
|
|
|
|
2003-03-10 16:23:34 +00:00
|
|
|
|
#include "insets/mailinset.h"
|
|
|
|
|
|
2005-02-14 14:25:18 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2005-02-14 14:25:18 +00:00
|
|
|
|
using lyx::support::bformat;
|
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::endl;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::max;
|
|
|
|
|
using std::min;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::swap;
|
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
using std::istream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::ostringstream;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::vector;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-10 16:23:34 +00:00
|
|
|
|
class GridInsetMailer : public MailInset {
|
|
|
|
|
public:
|
|
|
|
|
GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
|
|
|
|
|
///
|
|
|
|
|
virtual string const & name() const
|
|
|
|
|
{
|
2003-06-28 01:23:11 +00:00
|
|
|
|
static string const theName = "tabular";
|
2003-03-10 16:23:34 +00:00
|
|
|
|
return theName;
|
|
|
|
|
}
|
|
|
|
|
///
|
2003-07-23 09:54:21 +00:00
|
|
|
|
virtual string const inset2string(Buffer const &) const
|
2003-03-10 16:23:34 +00:00
|
|
|
|
{
|
2003-03-11 09:25:47 +00:00
|
|
|
|
ostringstream data;
|
|
|
|
|
//data << name() << " active_cell " << inset.getActCell() << '\n';
|
|
|
|
|
data << name() << " active_cell " << 0 << '\n';
|
|
|
|
|
WriteStream ws(data);
|
|
|
|
|
inset_.write(ws);
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return data.str();
|
2003-03-10 16:23:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
InsetBase & inset() const { return inset_; }
|
2003-06-28 01:23:11 +00:00
|
|
|
|
MathGridInset & inset_;
|
2003-03-10 16:23:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
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)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
res += ' ';
|
2002-10-11 10:45:28 +00:00
|
|
|
|
return res;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
|
|
|
|
|
int extractInt(istream & is)
|
|
|
|
|
{
|
|
|
|
|
int num = 1;
|
|
|
|
|
is >> num;
|
|
|
|
|
return (num == 0) ? 1 : num;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
|
2003-05-02 07:52:15 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::CellInfo::CellInfo()
|
|
|
|
|
: dummy_(false)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::RowInfo::RowInfo()
|
|
|
|
|
: lines_(0), skip_(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-02 07:52:15 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::ColInfo::ColInfo()
|
2005-02-14 14:25:18 +00:00
|
|
|
|
: align_('c'), lines_(0)
|
2003-05-02 07:52:15 +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)
|
2003-05-02 07:52:15 +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);
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "created grid with " << ncols() << " columns" << endl;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
MathGridInset::MathGridInset()
|
2003-05-02 07:52:15 +00:00
|
|
|
|
: MathNestInset(1),
|
|
|
|
|
rowinfo_(1 + 1),
|
|
|
|
|
colinfo_(1 + 1),
|
|
|
|
|
cellinfo_(1),
|
|
|
|
|
v_align_('c')
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{
|
|
|
|
|
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),
|
2003-05-02 07:52:15 +00:00
|
|
|
|
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),
|
2003-05-02 07:52:15 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-10 22:56:24 +00:00
|
|
|
|
MathGridInset::~MathGridInset()
|
|
|
|
|
{
|
|
|
|
|
GridInsetMailer mailer(*this);
|
|
|
|
|
mailer.hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> MathGridInset::doClone() const
|
2001-12-15 16:13:11 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathGridInset(*this));
|
2001-12-15 16:13:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "positive number of columns expected" << endl;
|
2002-07-31 17:26:14 +00:00
|
|
|
|
//if (nrows() <= 0)
|
2003-08-02 11:30:30 +00:00
|
|
|
|
// lyxerr << "positive number of rows expected" << endl;
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
2003-05-02 07:52:15 +00:00
|
|
|
|
colinfo_[col].align_ = defaultColAlign(col);
|
|
|
|
|
colinfo_[col].skip_ = defaultColSpace(col);
|
2001-09-05 12:57:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2003-05-02 07:52:15 +00:00
|
|
|
|
char c = *it;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
if (c == '|') {
|
|
|
|
|
colinfo_[col].lines_++;
|
2005-02-14 14:25:18 +00:00
|
|
|
|
} else if (col >= ncols()) {
|
|
|
|
|
// Only '|' is allowed in the last dummy column
|
|
|
|
|
break;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
} else if (c == 'c' || c == 'l' || c == 'r') {
|
2003-05-02 07:52:15 +00:00
|
|
|
|
colinfo_[col].align_ = c;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
++col;
|
|
|
|
|
colinfo_[col].lines_ = 0;
|
|
|
|
|
} else {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "unknown column separator: '" << c << "'" << endl;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2003-05-02 07:52:15 +00:00
|
|
|
|
/*
|
2001-09-26 16:52:34 +00:00
|
|
|
|
col_type n = hh.size();
|
2003-05-02 07:52:15 +00:00
|
|
|
|
if (n > ncols())
|
|
|
|
|
n = ncols();
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (col_type col = 0; col < n; ++col)
|
2003-05-02 07:52:15 +00:00
|
|
|
|
colinfo_[col].align_ = hh[col];
|
|
|
|
|
*/
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-02 07:52:15 +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;
|
|
|
|
|
// let's have at least one column, even if we did not recognize its
|
|
|
|
|
// alignment
|
|
|
|
|
if (col == 0)
|
|
|
|
|
col = 1;
|
|
|
|
|
return col;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2003-05-02 07:52:15 +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
|
|
|
|
{
|
2003-05-02 07:52:15 +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_, '|');
|
2003-05-02 07:52:15 +00:00
|
|
|
|
res += colinfo_[col].align_;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2003-05-02 07:52:15 +00:00
|
|
|
|
return res + string(colinfo_[ncols()].lines_, '|');
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2003-05-02 07:52:15 +00:00
|
|
|
|
return colinfo_.size() - 1;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathGridInset::row_type MathGridInset::nrows() const
|
|
|
|
|
{
|
2003-05-02 07:52:15 +00:00
|
|
|
|
return rowinfo_.size() - 1;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathGridInset::metrics(MetricsInfo & 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_;
|
2003-05-02 07:52:15 +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;
|
2003-05-02 07:52:15 +00:00
|
|
|
|
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
|
|
|
|
}
|
2003-05-02 07:52:15 +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
|
|
|
|
}
|
2003-05-02 07:52:15 +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();
|
2003-05-02 07:52:15 +00:00
|
|
|
|
for (col_type col = 1; col <= ncols(); ++col) {
|
2001-11-30 09:16:16 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid = colinfo_[ncols() - 1].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ colinfo_[ncols() - 1].width_
|
2003-05-28 13:22:36 +00:00
|
|
|
|
+ vlinesep() * colinfo_[ncols()].lines_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ border();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.asc = - rowinfo_[0].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ rowinfo_[0].ascent_
|
2003-05-28 13:22:36 +00:00
|
|
|
|
+ hlinesep() * rowinfo_[0].lines_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ border();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.des = rowinfo_[nrows() - 1].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ rowinfo_[nrows() - 1].descent_
|
2003-05-28 13:22:36 +00:00
|
|
|
|
+ hlinesep() * rowinfo_[nrows()].lines_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ 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);
|
|
|
|
|
}
|
|
|
|
|
*/
|
2004-04-06 19:25:39 +00:00
|
|
|
|
metricsMarkers2(dim_);
|
2003-06-02 10:03:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
metrics(mi);
|
|
|
|
|
dim = dim_;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-08 09:31:36 +00:00
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathGridInset::draw(PainterInfo & pi, int x, int y) const
|
2005-04-04 07:13:37 +00:00
|
|
|
|
{
|
|
|
|
|
drawWithMargin(pi, x, y, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-26 11:12:20 +00:00
|
|
|
|
void MathGridInset::drawWithMargin(PainterInfo & pi, int x, int y,
|
2005-04-04 07:13:37 +00:00
|
|
|
|
int lmargin, int rmargin) 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)
|
2005-04-26 11:12:20 +00:00
|
|
|
|
cell(idx).draw(pi, x + lmargin + cellXOffset(idx),
|
2005-04-04 07:13:37 +00:00
|
|
|
|
y + cellYOffset(idx));
|
2001-11-28 13:09:40 +00:00
|
|
|
|
|
2003-05-02 07:52:15 +00:00
|
|
|
|
for (row_type row = 0; row <= nrows(); ++row)
|
2005-02-14 14:25:18 +00:00
|
|
|
|
for (unsigned int i = 0; i < rowinfo_[row].lines_; ++i) {
|
2001-11-28 13:09:40 +00:00
|
|
|
|
int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
|
2002-02-11 08:19:02 +00:00
|
|
|
|
- i * hlinesep() - hlinesep()/2 - rowsep()/2;
|
2005-04-04 07:13:37 +00:00
|
|
|
|
pi.pain.line(x + lmargin + 1, yy,
|
|
|
|
|
x + dim_.width() - rmargin - 1, yy,
|
2003-09-15 10:08:01 +00:00
|
|
|
|
LColor::foreground);
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-02 07:52:15 +00:00
|
|
|
|
for (col_type col = 0; col <= ncols(); ++col)
|
2005-02-14 14:25:18 +00:00
|
|
|
|
for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
|
2005-04-04 07:13:37 +00:00
|
|
|
|
int xx = x + lmargin + colinfo_[col].offset_
|
2002-02-11 08:19:02 +00:00
|
|
|
|
- i * vlinesep() - vlinesep()/2 - colsep()/2;
|
2003-09-15 10:08:01 +00:00
|
|
|
|
pi.pain.line(xx, y - dim_.ascent() + 1,
|
|
|
|
|
xx, y + dim_.descent() - 1,
|
|
|
|
|
LColor::foreground);
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
2004-04-06 19:25:39 +00:00
|
|
|
|
drawMarkers2(pi, x, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) 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)
|
2003-05-28 13:22:36 +00:00
|
|
|
|
cell(i).metricsT(mi, dim);
|
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_;
|
2003-05-02 07:52:15 +00:00
|
|
|
|
rowinfo_[nrows()].ascent_ = 0;
|
|
|
|
|
rowinfo_[nrows()].descent_ = 0;
|
2002-03-19 16:55:58 +00:00
|
|
|
|
|
|
|
|
|
// compute vertical offsets
|
|
|
|
|
rowinfo_[0].offset_ = 0;
|
2003-05-02 07:52:15 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2003-05-02 07:52:15 +00:00
|
|
|
|
for (row_type row = 0; row <= nrows(); ++row)
|
2002-03-19 16:55:58 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2003-05-02 07:52:15 +00:00
|
|
|
|
colinfo_[ncols()].width_ = 0;
|
2002-03-19 16:55:58 +00:00
|
|
|
|
|
|
|
|
|
// compute horizontal offsets
|
|
|
|
|
colinfo_[0].offset_ = border();
|
2003-05-02 07:52:15 +00:00
|
|
|
|
for (col_type col = 1; col <= ncols(); ++col) {
|
2002-03-19 16:55:58 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
dim.wid = 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
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
dim.asc = -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
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
dim.des = 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())
|
2002-11-27 10:30:28 +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;
|
2003-05-02 07:52:15 +00:00
|
|
|
|
inf.skip_ = defaultColSpace(newcol);
|
|
|
|
|
inf.align_ = defaultColAlign(newcol);
|
2001-09-04 13:32:06 +00:00
|
|
|
|
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_;
|
2003-05-02 07:52:15 +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
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
|
2002-03-21 09:48:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (up) {
|
2005-07-16 17:55:49 +00:00
|
|
|
|
if (cur.row() == 0)
|
2002-03-21 09:48:46 +00:00
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() -= ncols();
|
2002-03-21 09:48:46 +00:00
|
|
|
|
} else {
|
2005-07-16 17:55:49 +00:00
|
|
|
|
if (cur.row() + 1 >= nrows())
|
2002-03-21 09:48:46 +00:00
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() += ncols();
|
2002-03-21 09:48:46 +00:00
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
|
2004-01-15 17:34:44 +00:00
|
|
|
|
return true;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathGridInset::idxLeft(LCursor & cur) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
// leave matrix if on the left hand edge
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (cur.col() == 0)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
--cur.idx();
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathGridInset::idxRight(LCursor & cur) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
// leave matrix if on the right hand edge
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (cur.col() + 1 == ncols())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
++cur.idx();
|
|
|
|
|
cur.pos() = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathGridInset::idxFirst(LCursor & cur) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
switch (v_align_) {
|
|
|
|
|
case 't':
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'b':
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = (nrows() - 1) * ncols();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
break;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
default:
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = ((nrows() - 1) / 2) * ncols();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.pos() = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
bool MathGridInset::idxLast(LCursor & cur) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
switch (v_align_) {
|
|
|
|
|
case 't':
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = ncols() - 1;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'b':
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = nargs() - 1;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)
|
2004-01-28 16:21:29 +00:00
|
|
|
|
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
|
|
|
|
}
|
2003-05-02 07:52:15 +00:00
|
|
|
|
string const s = verboseHLine(rowinfo_[nrows()].lines_);
|
|
|
|
|
if (!s.empty() && s != " ") {
|
|
|
|
|
if (os.fragile())
|
|
|
|
|
os << "\\protect";
|
|
|
|
|
os << "\\\\" << s;
|
|
|
|
|
}
|
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
|
|
|
|
|
2004-01-16 12:36:23 +00:00
|
|
|
|
void MathGridInset::splitCell(LCursor & cur)
|
2002-08-13 17:43:40 +00:00
|
|
|
|
{
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (cur.idx() == cur.lastidx())
|
2002-08-13 17:43:40 +00:00
|
|
|
|
return;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
MathArray ar = cur.cell();
|
|
|
|
|
ar.erase(0, cur.pos());
|
|
|
|
|
cur.cell().erase(cur.pos(), cur.lastpos());
|
|
|
|
|
++cur.idx();
|
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
cur.cell().insert(0, ar);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void MathGridInset::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2002-08-13 17:43:40 +00:00
|
|
|
|
{
|
2004-02-06 16:14:06 +00:00
|
|
|
|
//lyxerr << "*** MathGridInset: request: " << cmd << endl;
|
2002-08-13 17:43:40 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
//if (cmd.button() == mouse_button::button3) {
|
|
|
|
|
// GridInsetMailer(*this).showDialog();
|
|
|
|
|
// return DispatchResult(true, true);
|
|
|
|
|
//}
|
2004-11-24 21:58:42 +00:00
|
|
|
|
MathNestInset::doDispatch(cur, cmd);
|
2004-04-08 15:41:48 +00:00
|
|
|
|
break;
|
2003-03-10 16:23:34 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
GridInsetMailer(*this).updateDialog(&cur.bv());
|
2004-04-08 15:41:48 +00:00
|
|
|
|
break;
|
2003-03-10 16:23:34 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
// insert file functions
|
|
|
|
|
case LFUN_DELETE_LINE_FORWARD:
|
2005-07-10 09:30:07 +00:00
|
|
|
|
// FIXME: We use recordUndoInset when a change reflects more
|
|
|
|
|
// than one cell, because recordUndo does not work for
|
|
|
|
|
// multiple cells. Unfortunately this puts the cursor in front
|
|
|
|
|
// of the inset after undo. This is (especilally for large
|
|
|
|
|
// grids) annoying.
|
2005-07-08 09:12:34 +00:00
|
|
|
|
recordUndoInset(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
//autocorrect_ = false;
|
|
|
|
|
//macroModeClose();
|
|
|
|
|
//if (selection_) {
|
|
|
|
|
// selDel();
|
2004-04-08 15:41:48 +00:00
|
|
|
|
// break;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
//}
|
|
|
|
|
if (nrows() > 1)
|
|
|
|
|
delRow(cur.row());
|
|
|
|
|
if (cur.idx() > cur.lastidx())
|
|
|
|
|
cur.idx() = cur.lastidx();
|
|
|
|
|
if (cur.pos() > cur.lastpos())
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2004-04-08 15:41:48 +00:00
|
|
|
|
break;
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
case LFUN_CELL_SPLIT:
|
2004-04-20 08:51:15 +00:00
|
|
|
|
recordUndo(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
splitCell(cur);
|
2004-04-08 15:41:48 +00:00
|
|
|
|
break;
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
2005-07-18 00:09:20 +00:00
|
|
|
|
case LFUN_CELL_BACKWARD:
|
|
|
|
|
// See below.
|
|
|
|
|
cur.selection() = false;
|
|
|
|
|
if (!idxPrev(cur)) {
|
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_LEFT);
|
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_CELL_FORWARD:
|
|
|
|
|
// Can't handle selection by additional 'shift' as this is
|
|
|
|
|
// hard bound to LFUN_CELL_BACKWARD
|
|
|
|
|
cur.selection() = false;
|
|
|
|
|
if (!idxNext(cur)) {
|
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
|
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
case LFUN_BREAKLINE: {
|
2005-07-08 09:12:34 +00:00
|
|
|
|
recordUndoInset(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
row_type const r = cur.row();
|
|
|
|
|
addRow(r);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
// split line
|
|
|
|
|
for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
|
|
|
|
|
swap(cell(index(r, c)), cell(index(r + 1, c)));
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
// split cell
|
|
|
|
|
splitCell(cur);
|
|
|
|
|
swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
|
|
|
|
|
if (cur.idx() > 0)
|
|
|
|
|
--cur.idx();
|
2004-04-18 19:41:40 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
//mathcursor->normalize();
|
2004-04-18 19:41:40 +00:00
|
|
|
|
//cmd = FuncRequest(LFUN_FINISHED_LEFT);
|
2004-04-08 15:41:48 +00:00
|
|
|
|
break;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
}
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2005-07-08 09:12:34 +00:00
|
|
|
|
recordUndoInset(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
//lyxerr << "handling tabular-feature " << cmd.argument << endl;
|
|
|
|
|
istringstream is(cmd.argument);
|
|
|
|
|
string s;
|
|
|
|
|
is >> s;
|
|
|
|
|
if (s == "valign-top")
|
|
|
|
|
valign('t');
|
|
|
|
|
else if (s == "valign-middle")
|
|
|
|
|
valign('c');
|
|
|
|
|
else if (s == "valign-bottom")
|
|
|
|
|
valign('b');
|
|
|
|
|
else if (s == "align-left")
|
2005-02-14 14:25:18 +00:00
|
|
|
|
halign('l', cur.col());
|
2004-02-25 14:39:14 +00:00
|
|
|
|
else if (s == "align-right")
|
2005-02-14 14:25:18 +00:00
|
|
|
|
halign('r', cur.col());
|
2004-02-25 14:39:14 +00:00
|
|
|
|
else if (s == "align-center")
|
2005-02-14 14:25:18 +00:00
|
|
|
|
halign('c', cur.col());
|
2004-02-25 14:39:14 +00:00
|
|
|
|
else if (s == "append-row")
|
|
|
|
|
for (int i = 0, n = extractInt(is); i < n; ++i)
|
|
|
|
|
addRow(cur.row());
|
|
|
|
|
else if (s == "delete-row")
|
|
|
|
|
for (int i = 0, n = extractInt(is); i < n; ++i) {
|
|
|
|
|
delRow(cur.row());
|
|
|
|
|
if (cur.idx() > nargs())
|
|
|
|
|
cur.idx() -= ncols();
|
|
|
|
|
}
|
2005-06-30 18:02:39 +00:00
|
|
|
|
else if (s == "copy-row") {
|
|
|
|
|
// Here (as later) we save the cursor col/row
|
|
|
|
|
// in order to restore it after operation.
|
2005-07-06 07:28:16 +00:00
|
|
|
|
row_type const r = cur.row();
|
|
|
|
|
col_type const c = cur.col();
|
2004-02-25 14:39:14 +00:00
|
|
|
|
for (int i = 0, n = extractInt(is); i < n; ++i)
|
|
|
|
|
copyRow(cur.row());
|
2005-07-06 07:28:16 +00:00
|
|
|
|
cur.idx() = index(r, c);
|
|
|
|
|
}
|
2005-06-30 18:02:39 +00:00
|
|
|
|
else if (s == "swap-row") {
|
2004-02-25 14:39:14 +00:00
|
|
|
|
swapRow(cur.row());
|
2005-06-30 18:02:39 +00:00
|
|
|
|
// Trick to suppress same-idx-means-different-cell
|
|
|
|
|
// assertion crash:
|
|
|
|
|
cur.pos() = 0;
|
2005-07-06 07:28:16 +00:00
|
|
|
|
}
|
2005-02-09 18:56:01 +00:00
|
|
|
|
else if (s == "add-hline-above")
|
|
|
|
|
rowinfo_[cur.row()].lines_++;
|
2005-02-14 14:25:18 +00:00
|
|
|
|
else if (s == "add-hline-below")
|
|
|
|
|
rowinfo_[cur.row()+1].lines_++;
|
2005-02-09 18:56:01 +00:00
|
|
|
|
else if (s == "delete-hline-above")
|
2005-02-14 14:25:18 +00:00
|
|
|
|
rowinfo_[cur.row()].lines_--;
|
|
|
|
|
else if (s == "delete-hline-below")
|
|
|
|
|
rowinfo_[cur.row()+1].lines_--;
|
2005-07-06 07:28:16 +00:00
|
|
|
|
else if (s == "append-column") {
|
|
|
|
|
row_type const r = cur.row();
|
|
|
|
|
col_type const c = cur.col();
|
|
|
|
|
for (int i = 0, n = extractInt(is); i < n; ++i)
|
2005-06-30 18:02:39 +00:00
|
|
|
|
addCol(cur.col());
|
2005-07-06 07:28:16 +00:00
|
|
|
|
cur.idx() = index(r, c);
|
|
|
|
|
}
|
|
|
|
|
else if (s == "delete-column") {
|
|
|
|
|
row_type const r = cur.row();
|
|
|
|
|
col_type const c = cur.col();
|
|
|
|
|
for (int i = 0, n = extractInt(is); i < n; ++i)
|
2004-02-25 14:39:14 +00:00
|
|
|
|
delCol(col(cur.idx()));
|
2005-07-06 07:28:16 +00:00
|
|
|
|
cur.idx() = index(r, min(c, cur.ncols() - 1));
|
|
|
|
|
}
|
2005-06-30 18:02:39 +00:00
|
|
|
|
else if (s == "copy-column") {
|
2005-07-06 07:28:16 +00:00
|
|
|
|
row_type const r = cur.row();
|
|
|
|
|
col_type const c = cur.col();
|
2005-02-14 14:25:18 +00:00
|
|
|
|
copyCol(cur.col());
|
2005-07-06 07:28:16 +00:00
|
|
|
|
cur.idx() = index(r, c);
|
|
|
|
|
}
|
2005-06-30 18:02:39 +00:00
|
|
|
|
else if (s == "swap-column") {
|
2005-02-14 14:25:18 +00:00
|
|
|
|
swapCol(cur.col());
|
2005-06-30 18:02:39 +00:00
|
|
|
|
cur.pos() = 0; // trick, see above
|
2005-07-06 07:28:16 +00:00
|
|
|
|
}
|
2005-02-09 18:56:01 +00:00
|
|
|
|
else if (s == "add-vline-left")
|
2005-04-26 11:12:20 +00:00
|
|
|
|
colinfo_[cur.col()].lines_++;
|
2005-02-14 14:25:18 +00:00
|
|
|
|
else if (s == "add-vline-right")
|
2005-04-26 11:12:20 +00:00
|
|
|
|
colinfo_[cur.col()+1].lines_++;
|
2005-02-09 18:56:01 +00:00
|
|
|
|
else if (s == "delete-vline-left")
|
2005-02-14 14:25:18 +00:00
|
|
|
|
colinfo_[cur.col()].lines_--;
|
|
|
|
|
else if (s == "delete-vline-right")
|
|
|
|
|
colinfo_[cur.col()+1].lines_--;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
else {
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.undispatched();
|
2004-04-08 15:41:48 +00:00
|
|
|
|
break;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
}
|
2004-02-25 14:39:14 +00:00
|
|
|
|
lyxerr << "returning FINISHED_LEFT" << endl;
|
2004-04-08 15:41:48 +00:00
|
|
|
|
break;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
}
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
case LFUN_PASTE: {
|
2004-04-18 07:34:15 +00:00
|
|
|
|
lyxerr << "MathGridInset: PASTE: " << cmd << std::endl;
|
|
|
|
|
istringstream is(cmd.argument);
|
|
|
|
|
int n = 0;
|
|
|
|
|
is >> n;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
MathGridInset grid(1, 1);
|
2004-04-18 07:34:15 +00:00
|
|
|
|
mathed_parse_normal(grid, lyx::cap::getSelection(cur.buffer(), n));
|
2004-02-25 14:39:14 +00:00
|
|
|
|
if (grid.nargs() == 1) {
|
|
|
|
|
// single cell/part of cell
|
2005-07-08 09:12:34 +00:00
|
|
|
|
recordUndo(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.cell().insert(cur.pos(), grid.cell(0));
|
|
|
|
|
cur.pos() += grid.cell(0).size();
|
|
|
|
|
} else {
|
|
|
|
|
// multiple cells
|
2005-07-08 09:12:34 +00:00
|
|
|
|
recordUndoInset(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
col_type const numcols =
|
|
|
|
|
min(grid.ncols(), ncols() - col(cur.idx()));
|
|
|
|
|
row_type const numrows =
|
|
|
|
|
min(grid.nrows(), nrows() - cur.row());
|
|
|
|
|
for (row_type r = 0; r < numrows; ++r) {
|
|
|
|
|
for (col_type c = 0; c < numcols; ++c) {
|
|
|
|
|
idx_type i = index(r + cur.row(), c + col(cur.idx()));
|
|
|
|
|
cell(i).insert(0, grid.cell(grid.index(r, c)));
|
2002-08-14 16:11:55 +00:00
|
|
|
|
}
|
2004-02-25 14:39:14 +00:00
|
|
|
|
// append the left over horizontal cells to the last column
|
|
|
|
|
idx_type i = index(r + cur.row(), ncols() - 1);
|
|
|
|
|
for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
|
|
|
|
|
cell(i).append(grid.cell(grid.index(r, c)));
|
2002-08-14 16:11:55 +00:00
|
|
|
|
}
|
2004-02-25 14:39:14 +00:00
|
|
|
|
// 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)));
|
2002-08-14 16:11:55 +00:00
|
|
|
|
}
|
2004-04-08 15:41:48 +00:00
|
|
|
|
break;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
}
|
2002-08-14 15:13:07 +00:00
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
case LFUN_HOMESEL:
|
|
|
|
|
case LFUN_HOME:
|
|
|
|
|
case LFUN_WORDLEFTSEL:
|
|
|
|
|
case LFUN_WORDLEFT:
|
|
|
|
|
cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
|
|
|
|
|
cur.macroModeClose();
|
2004-04-18 07:34:15 +00:00
|
|
|
|
if (cur.pos() != 0) {
|
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
} else if (cur.idx() % cur.ncols() != 0) {
|
|
|
|
|
cur.idx() -= cur.idx() % cur.ncols();
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.pos() = 0;
|
2004-04-18 07:34:15 +00:00
|
|
|
|
} else if (cur.idx() != 0) {
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.idx() = 0;
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
} else {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_LEFT);
|
2005-04-10 09:07:28 +00:00
|
|
|
|
cur.undispatched();
|
2004-04-18 07:34:15 +00:00
|
|
|
|
}
|
2004-02-25 14:39:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_WORDRIGHTSEL:
|
|
|
|
|
case LFUN_WORDRIGHT:
|
|
|
|
|
case LFUN_ENDSEL:
|
|
|
|
|
case LFUN_END:
|
|
|
|
|
cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
|
|
|
|
|
cur.macroModeClose();
|
|
|
|
|
cur.clearTargetX();
|
2004-04-18 07:34:15 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos()) {
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
2004-04-18 07:34:15 +00:00
|
|
|
|
} else if ((cur.idx() + 1) % cur.ncols() != 0) {
|
|
|
|
|
cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
|
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
} else if (cur.idx() != cur.lastidx()) {
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.idx() = cur.lastidx();
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
} else {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
|
2005-04-10 09:07:28 +00:00
|
|
|
|
cur.undispatched();
|
2004-04-18 07:34:15 +00:00
|
|
|
|
}
|
2004-02-25 14:39:14 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
|
MathNestInset::doDispatch(cur, cmd);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-05 16:31:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathGridInset::getStatus(LCursor & cur, FuncRequest const & cmd,
|
2005-07-18 00:09:20 +00:00
|
|
|
|
FuncStatus & status) const
|
2004-04-05 16:31:52 +00:00
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
2005-02-14 14:25:18 +00:00
|
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2005-04-03 12:07:49 +00:00
|
|
|
|
string const s = cmd.argument;
|
2005-02-14 14:25:18 +00:00
|
|
|
|
if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
|
|
|
|
status.message(N_("Only one row"));
|
2005-02-14 14:25:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (ncols() <= 1 &&
|
|
|
|
|
(s == "delete-column" || s == "swap-column")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
|
|
|
|
status.message(N_("Only one column"));
|
2005-02-14 14:25:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if ((rowinfo_[cur.row()].lines_ == 0 &&
|
|
|
|
|
s == "delete-hline-above") ||
|
|
|
|
|
(rowinfo_[cur.row() + 1].lines_ == 0 &&
|
|
|
|
|
s == "delete-hline-below")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
|
|
|
|
status.message(N_("No hline to delete"));
|
2005-02-14 14:25:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((colinfo_[cur.col()].lines_ == 0 &&
|
|
|
|
|
s == "delete-vline-left") ||
|
|
|
|
|
(colinfo_[cur.col() + 1].lines_ == 0 &&
|
|
|
|
|
s == "delete-vline-right")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
|
|
|
|
status.message(N_("No vline to delete"));
|
2005-02-14 14:25:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (s == "valign-top" || s == "valign-middle" ||
|
|
|
|
|
s == "valign-bottom" || s == "align-left" ||
|
|
|
|
|
s == "align-right" || s == "align-center" ||
|
|
|
|
|
s == "append-row" || s == "delete-row" ||
|
|
|
|
|
s == "copy-row" || s == "swap-row" ||
|
|
|
|
|
s == "add-hline-above" || s == "add-hline-below" ||
|
|
|
|
|
s == "delete-hline-above" || s == "delete-hline-below" ||
|
|
|
|
|
s == "append-column" || s == "delete-column" ||
|
|
|
|
|
s == "copy-column" || s == "swap-column" ||
|
|
|
|
|
s == "add-vline-left" || s == "add-vline-right" ||
|
|
|
|
|
s == "delete-vline-left" || s == "delete-vline-right")
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(true);
|
2005-02-14 14:25:18 +00:00
|
|
|
|
else {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(false);
|
|
|
|
|
status.message(bformat(
|
2005-02-14 14:25:18 +00:00
|
|
|
|
N_("Unknown tabular feature '%1$s'"), s));
|
|
|
|
|
}
|
2005-04-25 14:10:10 +00:00
|
|
|
|
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.setOnOff(s == "align-left" && halign(cur.col()) == 'l'
|
2005-04-25 14:10:10 +00:00
|
|
|
|
|| s == "align-right" && halign(cur.col()) == 'r'
|
|
|
|
|
|| s == "align-center" && halign(cur.col()) == 'c'
|
|
|
|
|
|| s == "valign-top" && valign() == 't'
|
|
|
|
|
|| s == "valign-bottom" && valign() == 'b'
|
|
|
|
|
|| s == "valign-middle" && valign() == 'm');
|
|
|
|
|
|
2004-04-05 16:31:52 +00:00
|
|
|
|
#if 0
|
2005-02-14 14:25:18 +00:00
|
|
|
|
// FIXME: What did this code do?
|
2005-07-08 09:12:34 +00:00
|
|
|
|
// Please check whether it is still needed!
|
2004-04-05 16:31:52 +00:00
|
|
|
|
// should be more precise
|
|
|
|
|
if (v_align_ == '\0') {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enable(true);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (cmd.argument.empty()) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enable(false);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-02-14 14:25:18 +00:00
|
|
|
|
if (!lyx::support::contains("tcb", cmd.argument[0])) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enable(false);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.setOnOff(cmd.argument[0] == v_align_);
|
|
|
|
|
status.enabled(true);
|
2005-02-14 14:25:18 +00:00
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2005-07-18 00:09:20 +00:00
|
|
|
|
|
2005-04-07 09:06:08 +00:00
|
|
|
|
case LFUN_CELL_SPLIT:
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enabled(true);
|
2005-04-07 09:06:08 +00:00
|
|
|
|
return true;
|
2005-07-18 00:09:20 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_CELL_BACKWARD:
|
|
|
|
|
case LFUN_CELL_FORWARD:
|
|
|
|
|
status.enabled(true);
|
|
|
|
|
return true;
|
|
|
|
|
|
2004-04-05 16:31:52 +00:00
|
|
|
|
default:
|
2005-07-18 00:09:20 +00:00
|
|
|
|
return MathNestInset::getStatus(cur, cmd, status);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|