2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_nestinset.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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
|
|
|
|
#include "math_nestinset.h"
|
2002-02-11 15:55:13 +00:00
|
|
|
|
#include "math_cursor.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2002-08-15 10:02:53 +00:00
|
|
|
|
#include "math_parser.h"
|
2002-08-22 07:06:02 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "LColor.h"
|
2002-06-14 10:48:27 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
MathNestInset::MathNestInset(idx_type nargs)
|
2003-05-28 13:22:36 +00:00
|
|
|
|
: cells_(nargs), lock_(false)
|
2001-08-08 17:26:30 +00:00
|
|
|
|
{}
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
MathInset::idx_type MathNestInset::nargs() const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
return cells_.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
MathArray & MathNestInset::cell(idx_type i)
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cells_[i];
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
MathArray const & MathNestInset::cell(idx_type i) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cells_[i];
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-15 11:58:35 +00:00
|
|
|
|
void MathNestInset::getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const
|
2002-07-16 18:22:45 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & ar = cell(idx);
|
2002-07-26 13:13:20 +00:00
|
|
|
|
x = ar.xo() + ar.pos2x(pos);
|
|
|
|
|
y = ar.yo();
|
2002-07-16 18:22:45 +00:00
|
|
|
|
// move cursor visually into empty cells ("blue rectangles");
|
2002-07-26 13:13:20 +00:00
|
|
|
|
if (cell(idx).empty())
|
2002-07-16 18:22:45 +00:00
|
|
|
|
x += 2;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-06 11:13:56 +00:00
|
|
|
|
|
2001-09-11 15:46:51 +00:00
|
|
|
|
void MathNestInset::substitute(MathMacro const & m)
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-09-11 15:46:51 +00:00
|
|
|
|
cell(i).substitute(m);
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathNestInset::metrics(MetricsInfo const & mi) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
|
MetricsInfo m = mi;
|
2002-07-10 15:51:28 +00:00
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(i).metrics(m);
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (idx + 1 >= nargs())
|
|
|
|
|
return false;
|
|
|
|
|
++idx;
|
|
|
|
|
pos = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
return idxNext(idx, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (idx == 0)
|
|
|
|
|
return false;
|
|
|
|
|
--idx;
|
|
|
|
|
pos = cell(idx).size();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
return idxPrev(idx, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-22 16:14:26 +00:00
|
|
|
|
bool MathNestInset::idxFirst(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (nargs() == 0)
|
|
|
|
|
return false;
|
2003-08-22 16:14:26 +00:00
|
|
|
|
idx = 0;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-22 16:14:26 +00:00
|
|
|
|
bool MathNestInset::idxLast(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (nargs() == 0)
|
|
|
|
|
return false;
|
2003-08-22 16:14:26 +00:00
|
|
|
|
idx = nargs() - 1;
|
|
|
|
|
pos = cell(idx).size();
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (pos == 0)
|
|
|
|
|
return false;
|
|
|
|
|
pos = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
|
bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
|
pos_type n = cell(idx).size();
|
2001-09-14 14:05:57 +00:00
|
|
|
|
if (pos == n)
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return false;
|
2001-09-14 14:05:57 +00:00
|
|
|
|
pos = n;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathNestInset::dump() const
|
|
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
|
WriteStream os(lyxerr);
|
2001-10-19 11:25:48 +00:00
|
|
|
|
os << "---------------------------------------------\n";
|
|
|
|
|
write(os);
|
|
|
|
|
os << "\n";
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-10-19 11:25:48 +00:00
|
|
|
|
os << cell(i) << "\n";
|
|
|
|
|
os << "---------------------------------------------\n";
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
//void MathNestInset::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
void MathNestInset::draw(PainterInfo &, int, int) const
|
2002-06-14 10:48:27 +00:00
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
|
#if 0
|
2002-06-14 12:24:28 +00:00
|
|
|
|
if (lock_)
|
2002-06-14 10:48:27 +00:00
|
|
|
|
pi.pain.fillRectangle(x, y - ascent(), width(), height(),
|
|
|
|
|
LColor::mathlockbg);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
#endif
|
2002-06-14 10:48:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathNestInset::drawSelection(PainterInfo & pi,
|
2002-07-26 17:23:44 +00:00
|
|
|
|
idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
|
|
|
|
|
{
|
|
|
|
|
if (idx1 == idx2) {
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & c = cell(idx1);
|
2002-07-26 17:23:44 +00:00
|
|
|
|
int x1 = c.xo() + c.pos2x(pos1);
|
|
|
|
|
int y1 = c.yo() - c.ascent();
|
|
|
|
|
int x2 = c.xo() + c.pos2x(pos2);
|
|
|
|
|
int y2 = c.yo() + c.descent();
|
|
|
|
|
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
|
|
|
|
} else {
|
2002-08-02 13:35:05 +00:00
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i) {
|
|
|
|
|
if (idxBetween(i, idx1, idx2)) {
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & c = cell(i);
|
2002-08-02 13:35:05 +00:00
|
|
|
|
int x1 = c.xo();
|
|
|
|
|
int y1 = c.yo() - c.ascent();
|
|
|
|
|
int x2 = c.xo() + c.width();
|
|
|
|
|
int y2 = c.yo() + c.descent();
|
|
|
|
|
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
|
|
|
|
}
|
2002-07-26 17:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
|
void MathNestInset::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-08-03 17:10:22 +00:00
|
|
|
|
cell(i).validate(features);
|
|
|
|
|
}
|
2001-10-24 09:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
2001-11-16 09:55:37 +00:00
|
|
|
|
void MathNestInset::replace(ReplaceData & rep)
|
|
|
|
|
{
|
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
|
|
|
|
cell(i).replace(rep);
|
|
|
|
|
}
|
2002-02-01 17:01:30 +00:00
|
|
|
|
|
|
|
|
|
|
2002-08-08 16:08:11 +00:00
|
|
|
|
bool MathNestInset::contains(MathArray const & ar) const
|
2002-02-01 17:01:30 +00:00
|
|
|
|
{
|
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
|
|
|
|
if (cell(i).contains(ar))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-02-11 15:55:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathNestInset::editing() const
|
|
|
|
|
{
|
|
|
|
|
return mathcursor && mathcursor->isInside(this);
|
|
|
|
|
}
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathNestInset::lock() const
|
|
|
|
|
{
|
|
|
|
|
return lock_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathNestInset::lock(bool l)
|
|
|
|
|
{
|
|
|
|
|
lock_ = l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathNestInset::isActive() const
|
|
|
|
|
{
|
2002-06-14 10:48:27 +00:00
|
|
|
|
return nargs() > 0;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathArray MathNestInset::glue() const
|
|
|
|
|
{
|
|
|
|
|
MathArray ar;
|
|
|
|
|
for (unsigned i = 0; i < nargs(); ++i)
|
2002-07-30 13:56:02 +00:00
|
|
|
|
ar.append(cell(i));
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return ar;
|
|
|
|
|
}
|
2002-06-27 18:12:50 +00:00
|
|
|
|
|
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
void MathNestInset::write(WriteStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << '\\' << name().c_str();
|
|
|
|
|
for (unsigned i = 0; i < nargs(); ++i)
|
|
|
|
|
os << '{' << cell(i) << '}';
|
2002-08-02 14:29:42 +00:00
|
|
|
|
if (nargs() == 0)
|
2002-08-22 10:04:11 +00:00
|
|
|
|
os.pendingSpace(true);
|
|
|
|
|
if (lock_ && !os.latex()) {
|
|
|
|
|
os << "\\lyxlock";
|
|
|
|
|
os.pendingSpace(true);
|
|
|
|
|
}
|
2002-08-01 15:53:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathNestInset::normalize(NormalStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << '[' << name().c_str();
|
|
|
|
|
for (unsigned i = 0; i < nargs(); ++i)
|
|
|
|
|
os << ' ' << cell(i);
|
|
|
|
|
os << ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-10-29 08:23:32 +00:00
|
|
|
|
void MathNestInset::notifyCursorLeaves(idx_type idx)
|
|
|
|
|
{
|
|
|
|
|
cell(idx).notifyCursorLeaves();
|
|
|
|
|
}
|
2002-08-15 10:02:53 +00:00
|
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult
|
|
|
|
|
MathNestInset::priv_dispatch(FuncRequest const & cmd,
|
|
|
|
|
idx_type & idx, pos_type & pos)
|
2002-08-15 10:02:53 +00:00
|
|
|
|
{
|
2002-08-22 07:06:02 +00:00
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
|
|
2002-08-15 10:02:53 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_PASTE: {
|
|
|
|
|
MathArray ar;
|
|
|
|
|
mathed_parse_cell(ar, cmd.argument);
|
|
|
|
|
cell(idx).insert(pos, ar);
|
|
|
|
|
pos += ar.size();
|
2003-11-03 19:52:47 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2002-08-15 10:02:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-22 07:06:02 +00:00
|
|
|
|
case LFUN_PASTESELECTION:
|
|
|
|
|
return
|
2002-10-15 06:21:59 +00:00
|
|
|
|
dispatch(
|
|
|
|
|
FuncRequest(bv, LFUN_PASTE, bv->getClipboard()), idx, pos);
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2002-08-22 07:06:02 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
|
|
|
|
if (cmd.button() == mouse_button::button2)
|
2003-10-23 10:53:41 +00:00
|
|
|
|
return priv_dispatch(FuncRequest(bv, LFUN_PASTESELECTION), idx, pos);
|
2003-11-01 15:45:19 +00:00
|
|
|
|
return DispatchResult(false);
|
2002-08-22 07:06:02 +00:00
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
default:
|
2003-10-17 18:01:15 +00:00
|
|
|
|
return MathInset::priv_dispatch(cmd, idx, pos);
|
2002-08-15 10:02:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-05-28 13:22:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathNestInset::metricsMarkers(int) const
|
|
|
|
|
{
|
|
|
|
|
dim_.wid += 2;
|
|
|
|
|
dim_.asc += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathNestInset::metricsMarkers2(int) const
|
|
|
|
|
{
|
|
|
|
|
dim_.wid += 2;
|
|
|
|
|
dim_.asc += 1;
|
|
|
|
|
dim_.des += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MathNestInset::drawMarkers(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
if (!editing())
|
|
|
|
|
return;
|
|
|
|
|
int t = x + dim_.width() - 1;
|
|
|
|
|
int d = y + dim_.descent();
|
|
|
|
|
pi.pain.line(x, d - 3, x, d, LColor::mathframe);
|
|
|
|
|
pi.pain.line(t, d - 3, t, d, LColor::mathframe);
|
|
|
|
|
pi.pain.line(x, d, x + 3, d, LColor::mathframe);
|
|
|
|
|
pi.pain.line(t - 3, d, t, d, LColor::mathframe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathNestInset::drawMarkers2(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
if (!editing())
|
|
|
|
|
return;
|
|
|
|
|
drawMarkers(pi, x, y);
|
|
|
|
|
int t = x + dim_.width() - 1;
|
|
|
|
|
int a = y - dim_.ascent();
|
|
|
|
|
pi.pain.line(x, a + 3, x, a, LColor::mathframe);
|
|
|
|
|
pi.pain.line(t, a + 3, t, a, LColor::mathframe);
|
|
|
|
|
pi.pain.line(x, a, x + 3, a, LColor::mathframe);
|
|
|
|
|
pi.pain.line(t - 3, a, t, a, LColor::mathframe);
|
|
|
|
|
}
|