2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathGrid.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \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>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathGrid.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
#include "MathData.h"
|
2006-12-19 14:24:25 +00:00
|
|
|
|
#include "MathParser.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathStream.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
#include "MetricsInfo.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"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/gettext.h"
|
2004-01-16 12:36:23 +00:00
|
|
|
|
|
2007-01-04 12:05:24 +00:00
|
|
|
|
#include "frontends/Clipboard.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2004-01-16 12:36:23 +00:00
|
|
|
|
|
2005-02-14 14:25:18 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
#include "support/docstream.h"
|
2005-02-14 14:25:18 +00:00
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::bformat;
|
2005-02-14 14:25:18 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring verboseHLine(int n)
|
2001-11-28 13:09:40 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring res;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
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
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::CellInfo::CellInfo()
|
2003-05-02 07:52:15 +00:00
|
|
|
|
: dummy_(false)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::RowInfo::RowInfo()
|
2007-11-23 02:10:00 +00:00
|
|
|
|
: lines_(0), skip_(0), allow_newpage_(true)
|
2003-05-02 07:52:15 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
int InsetMathGrid::RowInfo::skipPixels() const
|
2001-08-10 12:12:03 +00:00
|
|
|
|
{
|
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
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::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
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMathGrid::InsetMathGrid(char v, docstring const & h)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathNest(guessColumns(h)),
|
2003-05-02 07:52:15 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::InsetMathGrid()
|
|
|
|
|
: InsetMathNest(1),
|
2003-05-02 07:52:15 +00:00
|
|
|
|
rowinfo_(1 + 1),
|
|
|
|
|
colinfo_(1 + 1),
|
|
|
|
|
cellinfo_(1),
|
|
|
|
|
v_align_('c')
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{
|
|
|
|
|
setDefaults();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::InsetMathGrid(col_type m, row_type n)
|
|
|
|
|
: InsetMathNest(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, docstring const & h)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathNest(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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetMathGrid::clone() const
|
2001-12-15 16:13:11 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetMathGrid(*this);
|
2001-12-15 16:13:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMath::idx_type InsetMathGrid::index(row_type row, col_type col) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
return col + ncols() * row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::setDefaults()
|
2001-09-05 12:57:13 +00:00
|
|
|
|
{
|
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);
|
2007-08-20 17:30:45 +00:00
|
|
|
|
colinfo_[col].special_.clear();
|
2001-09-05 12:57:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathGrid::halign(docstring const & hh)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2001-11-28 13:09:40 +00:00
|
|
|
|
col_type col = 0;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
|
|
|
|
|
char_type c = *it;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
if (c == '|') {
|
|
|
|
|
colinfo_[col].lines_++;
|
2007-08-20 17:30:45 +00:00
|
|
|
|
} else if ((c == 'p' || c == 'm' || c == 'b'||
|
|
|
|
|
c == '!' || c == '@' || c == '>' || c == '<') &&
|
|
|
|
|
it + 1 != hh.end() && *(it + 1) == '{') {
|
|
|
|
|
// @{decl.} and p{width} are standard LaTeX, the
|
|
|
|
|
// others are extensions by array.sty
|
|
|
|
|
bool const newcolumn = c == 'p' || c == 'm' || c == 'b';
|
|
|
|
|
if (newcolumn) {
|
|
|
|
|
// this declares a new column
|
|
|
|
|
if (col >= ncols())
|
|
|
|
|
// Only intercolumn stuff is allowed
|
|
|
|
|
// in the last dummy column
|
|
|
|
|
break;
|
|
|
|
|
colinfo_[col].align_ = 'l';
|
|
|
|
|
} else {
|
|
|
|
|
// this is intercolumn stuff
|
|
|
|
|
if (colinfo_[col].special_.empty())
|
|
|
|
|
// Overtake possible lines
|
|
|
|
|
colinfo_[col].special_ = docstring(colinfo_[col].lines_, '|');
|
|
|
|
|
}
|
|
|
|
|
int brace_open = 0;
|
|
|
|
|
int brace_close = 0;
|
|
|
|
|
while (it != hh.end()) {
|
|
|
|
|
c = *it;
|
|
|
|
|
colinfo_[col].special_ += c;
|
|
|
|
|
if (c == '{')
|
|
|
|
|
++brace_open;
|
|
|
|
|
else if (c == '}')
|
|
|
|
|
++brace_close;
|
|
|
|
|
++it;
|
|
|
|
|
if (brace_open > 0 && brace_open == brace_close)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
--it;
|
|
|
|
|
if (newcolumn) {
|
2007-12-12 19:28:07 +00:00
|
|
|
|
colinfo_[col].lines_ = count(
|
2007-08-20 17:30:45 +00:00
|
|
|
|
colinfo_[col].special_.begin(),
|
|
|
|
|
colinfo_[col].special_.end(), '|');
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "special column separator: `"
|
|
|
|
|
<< to_utf8(colinfo_[col].special_) << '\'');
|
2007-08-20 17:30:45 +00:00
|
|
|
|
++col;
|
|
|
|
|
colinfo_[col].lines_ = 0;
|
|
|
|
|
colinfo_[col].special_.clear();
|
|
|
|
|
}
|
2005-02-14 14:25:18 +00:00
|
|
|
|
} else if (col >= ncols()) {
|
2007-08-20 17:30:45 +00:00
|
|
|
|
// Only intercolumn stuff is allowed in the last
|
|
|
|
|
// dummy column
|
2005-02-14 14:25:18 +00:00
|
|
|
|
break;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
} else if (c == 'c' || c == 'l' || c == 'r') {
|
2007-08-20 17:30:45 +00:00
|
|
|
|
colinfo_[col].align_ = static_cast<char>(c);
|
|
|
|
|
if (!colinfo_[col].special_.empty()) {
|
|
|
|
|
colinfo_[col].special_ += c;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
colinfo_[col].lines_ = count(
|
2007-08-20 17:30:45 +00:00
|
|
|
|
colinfo_[col].special_.begin(),
|
|
|
|
|
colinfo_[col].special_.end(), '|');
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "special column separator: `"
|
|
|
|
|
<< to_utf8(colinfo_[col].special_) << '\'');
|
2007-08-20 17:30:45 +00:00
|
|
|
|
}
|
2001-11-28 13:09:40 +00:00
|
|
|
|
++col;
|
|
|
|
|
colinfo_[col].lines_ = 0;
|
2007-08-20 17:30:45 +00:00
|
|
|
|
colinfo_[col].special_.clear();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const
|
2003-05-02 07:52:15 +00:00
|
|
|
|
{
|
|
|
|
|
col_type col = 0;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
|
2007-08-20 17:30:45 +00:00
|
|
|
|
if (*it == 'c' || *it == 'l' || *it == 'r'||
|
|
|
|
|
*it == 'p' || *it == 'm' || *it == 'b')
|
2003-05-02 07:52:15 +00:00
|
|
|
|
++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
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::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;
|
2007-08-20 17:30:45 +00:00
|
|
|
|
if (!colinfo_[col].special_.empty()) {
|
|
|
|
|
char_type & c = colinfo_[col].special_[colinfo_[col].special_.size() - 1];
|
|
|
|
|
if (c == 'l' || c == 'c' || c == 'r')
|
|
|
|
|
c = h;
|
|
|
|
|
}
|
|
|
|
|
// FIXME: Change alignment of p, m and b columns, too
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
char InsetMathGrid::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
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring InsetMathGrid::halign() const
|
2001-11-28 13:09:40 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring res;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
2007-08-20 17:30:45 +00:00
|
|
|
|
if (colinfo_[col].special_.empty()) {
|
|
|
|
|
res += docstring(colinfo_[col].lines_, '|');
|
|
|
|
|
res += colinfo_[col].align_;
|
|
|
|
|
} else
|
|
|
|
|
res += colinfo_[col].special_;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2007-08-20 17:30:45 +00:00
|
|
|
|
if (colinfo_[ncols()].special_.empty())
|
|
|
|
|
return res + docstring(colinfo_[ncols()].lines_, '|');
|
|
|
|
|
return res + colinfo_[ncols()].special_;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::valign(char c)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
v_align_ = c;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
char InsetMathGrid::valign() const
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
|
|
|
|
return v_align_;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::col_type InsetMathGrid::ncols() const
|
2001-11-28 13:09:40 +00:00
|
|
|
|
{
|
2003-05-02 07:52:15 +00:00
|
|
|
|
return colinfo_.size() - 1;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::row_type InsetMathGrid::nrows() const
|
2001-11-28 13:09:40 +00:00
|
|
|
|
{
|
2003-05-02 07:52:15 +00:00
|
|
|
|
return rowinfo_.size() - 1;
|
2001-11-28 13:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::col_type InsetMathGrid::col(idx_type idx) const
|
2001-11-28 13:09:40 +00:00
|
|
|
|
{
|
|
|
|
|
return idx % ncols();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::row_type InsetMathGrid::row(idx_type idx) const
|
2001-11-28 13:09:40 +00:00
|
|
|
|
{
|
|
|
|
|
return idx / ncols();
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 11:51:06 +00:00
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
void InsetMathGrid::vcrskip(Length 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length InsetMathGrid::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
|
void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
// let the cells adjust themselves
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::metrics(mi);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
BufferView & bv = *mi.base.bv;
|
|
|
|
|
|
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) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Dimension const & dimc = cell(index(row, col)).dimension(bv);
|
|
|
|
|
asc = max(asc, dimc.asc);
|
|
|
|
|
desc = max(desc, dimc.des);
|
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)
|
2007-09-24 13:52:04 +00:00
|
|
|
|
wid = max(wid, cell(index(row, col)).dimension(bv).wid);
|
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
|
|
|
|
|
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
|
dim.wid = colinfo_[ncols() - 1].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ colinfo_[ncols() - 1].width_
|
2006-04-05 23:56:29 +00:00
|
|
|
|
+ vlinesep() * colinfo_[ncols()].lines_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ border();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
|
dim.asc = - rowinfo_[0].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ rowinfo_[0].ascent_
|
2006-04-05 23:56:29 +00:00
|
|
|
|
+ hlinesep() * rowinfo_[0].lines_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ border();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
|
dim.des = rowinfo_[nrows() - 1].offset_
|
2002-03-21 17:42:56 +00:00
|
|
|
|
+ rowinfo_[nrows() - 1].descent_
|
2006-04-05 23:56:29 +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);
|
|
|
|
|
}
|
|
|
|
|
*/
|
2007-09-23 22:39:49 +00:00
|
|
|
|
metricsMarkers2(dim);
|
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-08 09:31:36 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
|
2005-04-04 07:13:37 +00:00
|
|
|
|
{
|
|
|
|
|
drawWithMargin(pi, x, y, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-23 22:39:49 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::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
|
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
BufferView const & bv = *pi.base.bv;
|
2007-09-23 22:39:49 +00:00
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(idx).draw(pi, x + lmargin + cellXOffset(bv, 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,
|
2007-09-23 22:39:49 +00:00
|
|
|
|
x + dim.width() - rmargin - 1, yy,
|
2007-10-25 12:41:02 +00:00
|
|
|
|
Color_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;
|
2007-09-23 22:39:49 +00:00
|
|
|
|
pi.pain.line(xx, y - dim.ascent() + 1,
|
|
|
|
|
xx, y + dim.descent() - 1,
|
2007-10-25 12:41:02 +00:00
|
|
|
|
Color_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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-03-19 16:55:58 +00:00
|
|
|
|
{
|
|
|
|
|
// let the cells adjust themselves
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//InsetMathNest::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) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
//MathData const & c = cell(index(row, col));
|
|
|
|
|
// FIXME: BROKEN!
|
|
|
|
|
Dimension dimc;
|
|
|
|
|
asc = max(asc, dimc.ascent());
|
|
|
|
|
desc = max(desc, dimc.descent());
|
2002-03-19 16:55:58 +00:00
|
|
|
|
}
|
|
|
|
|
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;
|
2007-09-24 13:52:04 +00:00
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
|
// FIXME: BROKEN!
|
|
|
|
|
//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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::drawT(TextPainter & pain, int x, int y) const
|
2002-03-19 16:55:58 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
// for (idx_type idx = 0; idx < nargs(); ++idx)
|
|
|
|
|
// cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
|
2002-03-19 16:55:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const
|
2001-08-10 10:39:56 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring eol;
|
2001-08-10 10:39:56 +00:00
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
|
if (!rowinfo_[row].crskip_.zero())
|
2006-10-22 10:15:23 +00:00
|
|
|
|
eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
|
2007-11-23 02:10:00 +00:00
|
|
|
|
else if(!rowinfo_[row].allow_newpage_)
|
2007-03-19 16:08:17 +00:00
|
|
|
|
eol += '*';
|
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()) {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & c = cell(index(row + 1, 0));
|
2001-11-28 13:09:40 +00:00
|
|
|
|
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
|
2005-10-14 10:50:23 +00:00
|
|
|
|
if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !emptyline))
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return docstring();
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring InsetMathGrid::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)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return docstring();
|
|
|
|
|
return from_ascii(" & ");
|
2001-08-10 10:39:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 20:54:28 +00:00
|
|
|
|
void InsetMathGrid::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
|
2007-04-26 16:05:57 +00:00
|
|
|
|
(cells_.begin() + (row + 1) * ncols(), ncols(), MathData());
|
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
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::appendRow()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
rowinfo_.push_back(RowInfo());
|
2007-04-26 16:05:57 +00:00
|
|
|
|
//cells_.insert(cells_.end(), ncols(), MathData());
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::copyRow(row_type row)
|
2002-08-21 13:47:52 +00:00
|
|
|
|
{
|
2007-11-05 20:54:28 +00:00
|
|
|
|
addRow(row);
|
2002-08-21 13:47:52 +00:00
|
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
|
|
|
|
cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::swapRow(row_type row)
|
2002-08-21 13:47:52 +00:00
|
|
|
|
{
|
|
|
|
|
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]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::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) {
|
2007-10-13 15:48:22 +00:00
|
|
|
|
new_cells[row * (nc + 1) + col + (col >= newcol)]
|
2001-06-25 00:06:33 +00:00
|
|
|
|
= cells_[row * nc + col];
|
2007-10-13 15:48:22 +00:00
|
|
|
|
new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
|
2002-06-18 15:44:30 +00:00
|
|
|
|
= 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::copyCol(col_type col)
|
2002-08-21 13:47:52 +00:00
|
|
|
|
{
|
|
|
|
|
addCol(col);
|
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
|
cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::swapCol(col_type col)
|
2002-08-21 13:47:52 +00:00
|
|
|
|
{
|
|
|
|
|
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]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int InsetMathGrid::cellXOffset(BufferView const & bv, 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_;
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Dimension const & celldim = cell(idx).dimension(bv);
|
2001-08-08 09:31:36 +00:00
|
|
|
|
if (align == 'r' || align == 'R')
|
2007-09-24 13:52:04 +00:00
|
|
|
|
x += colinfo_[c].width_ - celldim.wid;
|
2001-08-08 09:31:36 +00:00
|
|
|
|
if (align == 'c' || align == 'C')
|
2007-09-24 13:52:04 +00:00
|
|
|
|
x += (colinfo_[c].width_ - celldim.wid) / 2;
|
2001-08-08 09:31:36 +00:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
int InsetMathGrid::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
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathGrid::idxUpDown(Cursor & 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
|
|
|
|
}
|
2006-10-13 16:44:44 +00:00
|
|
|
|
cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo(cur.bv()));
|
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
|
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
|
bool InsetMathGrid::idxBackward(Cursor & cur) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2007-11-05 19:44:03 +00:00
|
|
|
|
// leave matrix if at the front 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
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
|
bool InsetMathGrid::idxForward(Cursor & cur) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2007-11-05 19:44:03 +00:00
|
|
|
|
// leave matrix if at the back 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathGrid::idxFirst(Cursor & 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathGrid::idxLast(Cursor & 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathGrid::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
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::idxGlue(idx_type idx)
|
2002-03-25 12:11:25 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::RowInfo const & InsetMathGrid::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::RowInfo & InsetMathGrid::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
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
|
2002-08-02 13:35:05 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::normalize(NormalStream & os) const
|
2001-11-09 18:02:20 +00:00
|
|
|
|
{
|
|
|
|
|
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 << ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathGrid::mathmlize(MathStream & os) const
|
2001-11-09 18:02:20 +00:00
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathGrid::write(WriteStream & os) const
|
2001-11-09 18:02:20 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring eol;
|
2001-11-09 18:02:20 +00:00
|
|
|
|
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);
|
2005-10-14 10:50:23 +00:00
|
|
|
|
eol = eolString(row, emptyline, os.fragile());
|
|
|
|
|
os << eol;
|
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
|
|
|
|
}
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
|
2005-10-14 10:50:23 +00:00
|
|
|
|
if (!s.empty()) {
|
|
|
|
|
if (eol.empty()) {
|
|
|
|
|
if (os.fragile())
|
|
|
|
|
os << "\\protect";
|
|
|
|
|
os << "\\\\";
|
|
|
|
|
}
|
|
|
|
|
os << s;
|
2003-05-02 07:52:15 +00:00
|
|
|
|
}
|
2001-11-09 18:02:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
int InsetMathGrid::colsep() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
|
|
|
|
return 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
int InsetMathGrid::rowsep() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
|
|
|
|
return 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
int InsetMathGrid::hlinesep() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
int InsetMathGrid::vlinesep() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
int InsetMathGrid::border() const
|
2002-02-11 08:19:02 +00:00
|
|
|
|
{
|
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
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathGrid::splitCell(Cursor & 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;
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar = cur.cell();
|
2004-01-15 17:34:44 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2002-08-13 17:43:40 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
|
2002-08-13 17:43:40 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
// insert file functions
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_LINE_DELETE:
|
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.
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset();
|
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:
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
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)) {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
|
2005-07-18 00:09:20 +00:00
|
|
|
|
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)) {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-25 18:34:37 +00:00
|
|
|
|
case LFUN_NEW_LINE: {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset();
|
2004-02-25 14:39:14 +00:00
|
|
|
|
row_type const r = cur.row();
|
2007-11-05 20:54:28 +00:00
|
|
|
|
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();
|
2007-10-22 22:18:52 +00:00
|
|
|
|
//cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
|
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: {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
//lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
|
|
|
|
|
istringstream is(to_utf8(cmd.argument()));
|
2004-02-25 14:39:14 +00:00
|
|
|
|
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)
|
2007-11-05 20:54:28 +00:00
|
|
|
|
addRow(cur.row());
|
2006-03-22 08:46:54 +00:00
|
|
|
|
else if (s == "delete-row") {
|
2007-11-05 10:46:39 +00:00
|
|
|
|
cur.clearSelection(); // bug 4323
|
2004-02-25 14:39:14 +00:00
|
|
|
|
for (int i = 0, n = extractInt(is); i < n; ++i) {
|
|
|
|
|
delRow(cur.row());
|
2006-06-23 14:20:49 +00:00
|
|
|
|
if (cur.idx() >= nargs())
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.idx() -= ncols();
|
|
|
|
|
}
|
2006-03-22 08:46:54 +00:00
|
|
|
|
cur.pos() = 0; // trick, see below
|
|
|
|
|
}
|
2005-06-30 18:02:39 +00:00
|
|
|
|
else if (s == "copy-row") {
|
2006-04-05 23:56:29 +00:00
|
|
|
|
// 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());
|
2006-04-05 23:56:29 +00:00
|
|
|
|
// Trick to suppress same-idx-means-different-cell
|
2005-06-30 18:02:39 +00:00
|
|
|
|
// assertion crash:
|
2006-04-05 23:56:29 +00:00
|
|
|
|
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)
|
2007-11-05 09:51:37 +00:00
|
|
|
|
addCol(cur.col() + 1);
|
2005-07-06 07:28:16 +00:00
|
|
|
|
cur.idx() = index(r, c);
|
|
|
|
|
}
|
|
|
|
|
else if (s == "delete-column") {
|
2007-11-05 10:46:39 +00:00
|
|
|
|
cur.clearSelection(); // bug 4323
|
2005-07-06 07:28:16 +00:00
|
|
|
|
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));
|
2006-03-22 08:46:54 +00:00
|
|
|
|
cur.pos() = 0; // trick, see above
|
2005-07-06 07:28:16 +00:00
|
|
|
|
}
|
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
|
|
|
|
}
|
2007-08-20 17:30:45 +00:00
|
|
|
|
else if (s == "add-vline-left") {
|
2005-04-26 11:12:20 +00:00
|
|
|
|
colinfo_[cur.col()].lines_++;
|
2007-08-20 17:30:45 +00:00
|
|
|
|
if (!colinfo_[cur.col()].special_.empty())
|
|
|
|
|
colinfo_[cur.col()].special_ += '|';
|
|
|
|
|
}
|
|
|
|
|
else if (s == "add-vline-right") {
|
2005-04-26 11:12:20 +00:00
|
|
|
|
colinfo_[cur.col()+1].lines_++;
|
2007-08-20 17:30:45 +00:00
|
|
|
|
if (!colinfo_[cur.col()+1].special_.empty())
|
|
|
|
|
colinfo_[cur.col()+1].special_.insert(0, 1, '|');
|
|
|
|
|
}
|
|
|
|
|
else if (s == "delete-vline-left") {
|
2005-02-14 14:25:18 +00:00
|
|
|
|
colinfo_[cur.col()].lines_--;
|
2007-08-20 17:30:45 +00:00
|
|
|
|
docstring & special = colinfo_[cur.col()].special_;
|
|
|
|
|
if (!special.empty()) {
|
|
|
|
|
docstring::size_type i = special.rfind('|');
|
|
|
|
|
BOOST_ASSERT(i != docstring::npos);
|
|
|
|
|
special.erase(i, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (s == "delete-vline-right") {
|
2005-02-14 14:25:18 +00:00
|
|
|
|
colinfo_[cur.col()+1].lines_--;
|
2007-08-20 17:30:45 +00:00
|
|
|
|
docstring & special = colinfo_[cur.col()+1].special_;
|
|
|
|
|
if (!special.empty()) {
|
|
|
|
|
docstring::size_type i = special.find('|');
|
|
|
|
|
BOOST_ASSERT(i != docstring::npos);
|
|
|
|
|
special.erase(i, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
}
|
2007-10-22 22:18:52 +00:00
|
|
|
|
// perhaps this should be FINISHED_BACKWARD -- just for clarity?
|
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: {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
cur.message(_("Paste"));
|
2006-10-21 00:16:43 +00:00
|
|
|
|
cap::replaceSelection(cur);
|
2007-01-04 12:05:24 +00:00
|
|
|
|
docstring topaste;
|
|
|
|
|
if (cmd.argument().empty() && !theClipboard().isInternal())
|
2007-01-13 18:29:50 +00:00
|
|
|
|
topaste = theClipboard().getAsText();
|
2007-01-04 12:05:24 +00:00
|
|
|
|
else {
|
|
|
|
|
idocstringstream is(cmd.argument());
|
|
|
|
|
int n = 0;
|
|
|
|
|
is >> n;
|
|
|
|
|
topaste = cap::getSelection(cur.buffer(), n);
|
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid grid(1, 1);
|
2007-01-04 12:05:24 +00:00
|
|
|
|
if (!topaste.empty())
|
|
|
|
|
mathed_parse_normal(grid, topaste);
|
|
|
|
|
|
2004-02-25 14:39:14 +00:00
|
|
|
|
if (grid.nargs() == 1) {
|
|
|
|
|
// single cell/part of cell
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
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
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset();
|
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);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
|
2004-02-25 14:39:14 +00:00
|
|
|
|
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
|
|
|
|
}
|
2005-10-12 18:44:53 +00:00
|
|
|
|
cur.clearSelection(); // bug 393
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.finishUndo();
|
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
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_LINE_BEGIN_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_LINE_BEGIN:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_WORD_BACKWARD_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_WORD_BACKWARD:
|
2007-10-28 20:35:57 +00:00
|
|
|
|
case LFUN_WORD_LEFT_SELECT:
|
|
|
|
|
case LFUN_WORD_LEFT:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT ||
|
2007-10-28 20:35:57 +00:00
|
|
|
|
cmd.action == LFUN_WORD_LEFT_SELECT ||
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cmd.action == LFUN_LINE_BEGIN_SELECT);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
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 {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
|
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;
|
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_WORD_FORWARD_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_WORD_FORWARD:
|
2007-10-28 20:35:57 +00:00
|
|
|
|
case LFUN_WORD_RIGHT_SELECT:
|
|
|
|
|
case LFUN_WORD_RIGHT:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_LINE_END_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_LINE_END:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT ||
|
2007-10-28 20:35:57 +00:00
|
|
|
|
cmd.action == LFUN_WORD_RIGHT_SELECT ||
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cmd.action == LFUN_LINE_END_SELECT);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
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 {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
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:
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::doDispatch(cur, cmd);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-05 16:31:52 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathGrid::getStatus(Cursor & 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: {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
string const s = to_utf8(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);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
status.message(from_utf8(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);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
status.message(from_utf8(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);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
status.message(from_utf8(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);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
status.message(from_utf8(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(
|
2006-10-21 00:16:43 +00:00
|
|
|
|
from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
|
2005-02-14 14:25:18 +00:00
|
|
|
|
}
|
2005-04-25 14:10:10 +00:00
|
|
|
|
|
2007-09-16 10:36:57 +00:00
|
|
|
|
status.setOnOff((s == "align-left" && halign(cur.col()) == 'l')
|
|
|
|
|
|| (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'));
|
2005-04-25 14:10:10 +00:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (cmd.argument().empty()) {
|
2005-07-18 00:09:20 +00:00
|
|
|
|
status.enable(false);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
if (!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;
|
|
|
|
|
}
|
2006-09-01 15:41:38 +00:00
|
|
|
|
status.setOnOff(cmd.argument()[0] == v_align_);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
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:
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return InsetMathNest::getStatus(cur, cmd, status);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|