2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_data.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-12-18 03:16:46 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2003-09-05 16:18:57 +00:00
|
|
|
|
#include "math_data.h"
|
2002-10-29 08:23:32 +00:00
|
|
|
|
#include "math_fontinset.h"
|
2001-09-11 10:58:17 +00:00
|
|
|
|
#include "math_scriptinset.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
#include "math_macro.h"
|
|
|
|
|
#include "math_macrotable.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
|
#include "math_support.h"
|
2001-11-16 09:55:37 +00:00
|
|
|
|
#include "math_replace.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
|
2004-08-14 14:03:42 +00:00
|
|
|
|
#include "coordcache.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "LColor.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "cursor.h"
|
|
|
|
|
#include "debug.h"
|
2004-01-07 18:28:50 +00:00
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2004-01-07 18:28:50 +00:00
|
|
|
|
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
|
|
|
|
using std::abs;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
using std::endl;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::min;
|
2004-01-07 18:28:50 +00:00
|
|
|
|
using std::ostringstream;
|
2004-04-13 06:27:29 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::MathArray()
|
|
|
|
|
{}
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
MathArray::MathArray(const_iterator from, const_iterator to)
|
2004-08-14 14:03:42 +00:00
|
|
|
|
: base_type(from, to)
|
2001-11-09 10:44:24 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
|
MathAtom & MathArray::operator[](pos_type pos)
|
2001-04-27 12:35:55 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(pos < size());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
return base_type::operator[](pos);
|
2001-07-12 07:18:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
|
MathAtom const & MathArray::operator[](pos_type pos) const
|
2001-02-14 17:50:58 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(pos < size());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
return base_type::operator[](pos);
|
2001-10-12 12:02:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::insert(size_type pos, MathAtom const & t)
|
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
base_type::insert(begin() + pos, t);
|
2001-02-14 17:50:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 11:39:38 +00:00
|
|
|
|
|
2001-11-08 12:55:58 +00:00
|
|
|
|
void MathArray::insert(size_type pos, MathArray const & ar)
|
2001-02-14 17:50:58 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(pos <= size());
|
2002-07-30 13:56:02 +00:00
|
|
|
|
base_type::insert(begin() + pos, ar.begin(), ar.end());
|
2001-10-10 13:20:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
|
void MathArray::append(MathArray const & ar)
|
2001-02-12 08:55:14 +00:00
|
|
|
|
{
|
2001-11-08 12:55:58 +00:00
|
|
|
|
insert(size(), ar);
|
2001-02-12 08:55:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
|
void MathArray::erase(size_type pos)
|
2001-02-14 17:50:58 +00:00
|
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
|
if (pos < size())
|
2001-08-07 12:02:21 +00:00
|
|
|
|
erase(pos, pos + 1);
|
2001-02-14 17:50:58 +00:00
|
|
|
|
}
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
2001-11-09 10:44:24 +00:00
|
|
|
|
void MathArray::erase(iterator pos1, iterator pos2)
|
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
base_type::erase(pos1, pos2);
|
2001-11-09 10:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::erase(iterator pos)
|
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
base_type::erase(pos);
|
2001-11-09 10:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-14 14:05:57 +00:00
|
|
|
|
void MathArray::erase(size_type pos1, size_type pos2)
|
2001-02-12 08:55:14 +00:00
|
|
|
|
{
|
2002-07-30 13:56:02 +00:00
|
|
|
|
base_type::erase(begin() + pos1, begin() + pos2);
|
2001-11-09 16:27:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
|
void MathArray::dump2() const
|
2001-02-12 08:55:14 +00:00
|
|
|
|
{
|
2001-11-08 12:06:56 +00:00
|
|
|
|
NormalStream ns(lyxerr);
|
2001-08-09 08:53:16 +00:00
|
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2002-08-08 17:11:30 +00:00
|
|
|
|
ns << *it << ' ';
|
2001-02-12 08:55:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
|
void MathArray::dump() const
|
2001-02-12 08:55:14 +00:00
|
|
|
|
{
|
2001-11-08 12:06:56 +00:00
|
|
|
|
NormalStream ns(lyxerr);
|
2001-08-09 08:53:16 +00:00
|
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
ns << '<' << *it << '>';
|
2001-02-12 08:55:14 +00:00
|
|
|
|
}
|
2001-02-28 17:21:16 +00:00
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
|
void MathArray::validate(LaTeXFeatures & features) const
|
2001-07-13 14:54:56 +00:00
|
|
|
|
{
|
2001-08-09 08:53:16 +00:00
|
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2002-08-08 17:11:30 +00:00
|
|
|
|
(*it)->validate(features);
|
2001-07-13 14:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-26 06:46:50 +00:00
|
|
|
|
|
2001-11-16 09:07:40 +00:00
|
|
|
|
bool MathArray::match(MathArray const & ar) const
|
|
|
|
|
{
|
2002-01-03 09:41:26 +00:00
|
|
|
|
return size() == ar.size() && matchpart(ar, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
|
|
|
|
|
{
|
|
|
|
|
if (size() < ar.size() + pos)
|
2001-11-16 09:07:40 +00:00
|
|
|
|
return false;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
const_iterator it = begin() + pos;
|
2002-01-03 09:41:26 +00:00
|
|
|
|
for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
|
2004-01-07 18:28:50 +00:00
|
|
|
|
if (asString(*it) != asString(*jt))
|
2001-11-16 09:07:40 +00:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2001-11-16 09:55:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::replace(ReplaceData & rep)
|
|
|
|
|
{
|
|
|
|
|
for (size_type i = 0; i < size(); ++i) {
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (find1(rep.from, i)) {
|
2001-11-16 09:55:37 +00:00
|
|
|
|
// match found
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "match found!" << endl;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
erase(i, i + rep.from.size());
|
2001-11-16 09:55:37 +00:00
|
|
|
|
insert(i, rep.to);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-08 16:08:11 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning temporarily disabled
|
|
|
|
|
// for (const_iterator it = begin(); it != end(); ++it)
|
|
|
|
|
// it->nucleus()->replace(rep);
|
|
|
|
|
#endif
|
2001-11-16 09:55:37 +00:00
|
|
|
|
}
|
2002-02-01 17:01:30 +00:00
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
bool MathArray::find1(MathArray const & ar, size_type pos) const
|
2002-02-01 17:01:30 +00:00
|
|
|
|
{
|
2004-01-07 18:28:50 +00:00
|
|
|
|
lyxerr << "finding '" << ar << "' in '" << *this << "'" << endl;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
for (size_type i = 0, n = ar.size(); i < n; ++i)
|
2004-01-07 18:28:50 +00:00
|
|
|
|
if (asString(operator[](pos + i)) != asString(ar[i]))
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::size_type MathArray::find(MathArray const & ar) const
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0, last = size() - ar.size(); i < last; ++i)
|
|
|
|
|
if (find1(ar, i))
|
|
|
|
|
return i;
|
|
|
|
|
return size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::size_type MathArray::find_last(MathArray const & ar) const
|
|
|
|
|
{
|
2002-08-10 15:21:07 +00:00
|
|
|
|
for (int i = size() - ar.size(); i >= 0; --i)
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (find1(ar, i))
|
|
|
|
|
return i;
|
|
|
|
|
return size();
|
|
|
|
|
}
|
2002-02-01 17:01:30 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
|
|
bool MathArray::contains(MathArray const & ar) const
|
|
|
|
|
{
|
|
|
|
|
if (find(ar) != size())
|
|
|
|
|
return true;
|
2002-02-01 17:01:30 +00:00
|
|
|
|
for (const_iterator it = begin(); it != end(); ++it)
|
2002-08-09 10:22:35 +00:00
|
|
|
|
if ((*it)->contains(ar))
|
2002-02-01 17:01:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::touch() const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void MathArray::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
metrics(mi);
|
|
|
|
|
dim = dim_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2004-04-20 08:51:15 +00:00
|
|
|
|
bool isInside(DocIterator const & it, MathArray const & ar,
|
2004-04-13 06:27:29 +00:00
|
|
|
|
lyx::pos_type p1, lyx::pos_type p2)
|
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
for (size_t i = 0; i != it.depth(); ++i) {
|
2004-04-13 06:27:29 +00:00
|
|
|
|
CursorSlice const & sl = it[i];
|
|
|
|
|
if (sl.inset().inMathed() && &sl.cell() == &ar)
|
|
|
|
|
return p1 <= sl.pos() && sl.pos() < p2;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void MathArray::metrics(MetricsInfo & mi) const
|
2002-08-02 14:29:42 +00:00
|
|
|
|
{
|
2002-08-29 06:49:27 +00:00
|
|
|
|
mathed_char_dim(mi.base.font, 'I', dim_);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
if (empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dim_.wid = 0;
|
|
|
|
|
Dimension d;
|
2004-04-13 13:54:58 +00:00
|
|
|
|
//BufferView & bv = *mi.base.bv;
|
|
|
|
|
//Buffer const & buf = *bv.buffer();
|
2004-04-13 06:27:29 +00:00
|
|
|
|
for (size_t i = 0, n = size(); i != n; ++i) {
|
|
|
|
|
MathAtom const & at = operator[](i);
|
2004-04-13 13:54:58 +00:00
|
|
|
|
#if 0
|
2004-04-13 06:27:29 +00:00
|
|
|
|
MathMacro const * mac = at->asMacro();
|
|
|
|
|
if (mac && buf.hasMacro(mac->name())) {
|
|
|
|
|
MacroData const & tmpl = buf.getMacro(mac->name());
|
|
|
|
|
int numargs = tmpl.numargs();
|
|
|
|
|
if (i + numargs > n)
|
|
|
|
|
numargs = n - i - 1;
|
|
|
|
|
lyxerr << "metrics:found macro: " << mac->name()
|
|
|
|
|
<< " numargs: " << numargs << endl;
|
|
|
|
|
if (!isInside(bv.cursor(), *this, i + 1, i + numargs + 1)) {
|
|
|
|
|
MathArray args(begin() + i + 1, begin() + i + numargs + 1);
|
|
|
|
|
MathArray exp;
|
|
|
|
|
tmpl.expand(args, exp);
|
|
|
|
|
mac->setExpansion(exp, args);
|
|
|
|
|
mac->metricsExpanded(mi, d);
|
|
|
|
|
dim_.wid += mac->widthExpanded();
|
|
|
|
|
i += numargs;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2003-05-28 13:22:36 +00:00
|
|
|
|
}
|
2004-04-13 13:54:58 +00:00
|
|
|
|
#endif
|
2004-04-13 06:27:29 +00:00
|
|
|
|
at->metrics(mi, d);
|
|
|
|
|
dim_ += d;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathArray::draw(PainterInfo & pi, int x, int y) const
|
2002-08-02 14:29:42 +00:00
|
|
|
|
{
|
|
|
|
|
//lyxerr << "MathArray::draw: x: " << x << " y: " << y << endl;
|
2004-10-05 10:11:42 +00:00
|
|
|
|
setXY(x, y);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
|
|
|
|
if (empty()) {
|
|
|
|
|
pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
// don't draw outside the workarea
|
|
|
|
|
if (y + descent() <= 0
|
|
|
|
|
|| y - ascent() >= pi.pain.paperHeight()
|
|
|
|
|
|| x + width() <= 0
|
|
|
|
|
|| x >= pi.pain.paperWidth())
|
|
|
|
|
return;
|
|
|
|
|
|
2004-04-13 13:54:58 +00:00
|
|
|
|
//BufferView & bv = *pi.base.bv;
|
2004-04-13 06:27:29 +00:00
|
|
|
|
for (size_t i = 0, n = size(); i != n; ++i) {
|
|
|
|
|
MathAtom const & at = operator[](i);
|
2004-04-13 13:54:58 +00:00
|
|
|
|
#if 0
|
|
|
|
|
Buffer const & buf = *bv.buffer();
|
2004-04-13 06:27:29 +00:00
|
|
|
|
// special macro handling
|
|
|
|
|
MathMacro const * mac = at->asMacro();
|
|
|
|
|
if (mac && buf.hasMacro(mac->name())) {
|
|
|
|
|
MacroData const & tmpl = buf.getMacro(mac->name());
|
|
|
|
|
int numargs = tmpl.numargs();
|
|
|
|
|
if (i + numargs > n)
|
|
|
|
|
numargs = n - i - 1;
|
|
|
|
|
if (!isInside(bv.cursor(), *this, i + 1, i + numargs + 1)) {
|
|
|
|
|
mac->drawExpanded(pi, x, y);
|
|
|
|
|
x += mac->widthExpanded();
|
|
|
|
|
i += numargs;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-13 13:54:58 +00:00
|
|
|
|
#endif
|
2005-09-26 10:34:24 +00:00
|
|
|
|
theCoords.insets().add(at.nucleus(), x, y);
|
2004-04-13 06:27:29 +00:00
|
|
|
|
at->drawSelection(pi, x, y);
|
|
|
|
|
at->draw(pi, x, y);
|
|
|
|
|
x += at->width();
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
void MathArray::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-08-02 14:29:42 +00:00
|
|
|
|
{
|
2003-05-28 13:22:36 +00:00
|
|
|
|
dim.clear();
|
|
|
|
|
Dimension d;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
for (const_iterator it = begin(); it != end(); ++it) {
|
2003-05-28 13:22:36 +00:00
|
|
|
|
(*it)->metricsT(mi, d);
|
|
|
|
|
dim += d;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathArray::drawT(TextPainter & pain, int x, int y) const
|
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
//lyxerr << "x: " << x << " y: " << y << ' ' << pain.workAreaHeight() << endl;
|
2004-08-14 14:03:42 +00:00
|
|
|
|
setXY(x, y);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
|
|
|
|
|
for (const_iterator it = begin(), et = end(); it != et; ++it) {
|
|
|
|
|
(*it)->drawT(pain, x, y);
|
2004-08-13 22:39:39 +00:00
|
|
|
|
//x += (*it)->width_;
|
2004-02-02 17:32:56 +00:00
|
|
|
|
x += 2;
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathArray::pos2x(size_type pos) const
|
|
|
|
|
{
|
2003-04-14 06:17:19 +00:00
|
|
|
|
return pos2x(pos, 0);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-14 06:17:19 +00:00
|
|
|
|
int MathArray::pos2x(size_type pos, int glue) const
|
2002-08-02 14:29:42 +00:00
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
2003-04-14 06:17:19 +00:00
|
|
|
|
size_type target = min(pos, size());
|
|
|
|
|
for (size_type i = 0; i < target; ++i) {
|
2002-08-02 14:29:42 +00:00
|
|
|
|
const_iterator it = begin() + i;
|
2002-08-09 10:22:35 +00:00
|
|
|
|
if ((*it)->getChar() == ' ')
|
2002-08-02 14:29:42 +00:00
|
|
|
|
x += glue;
|
2004-02-03 14:29:00 +00:00
|
|
|
|
//lyxerr << "char: " << (*it)->getChar()
|
|
|
|
|
// << "width: " << (*it)->width() << std::endl;
|
2004-02-02 17:32:56 +00:00
|
|
|
|
x += (*it)->width();
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathArray::size_type MathArray::x2pos(int targetx) const
|
|
|
|
|
{
|
2003-04-14 06:17:19 +00:00
|
|
|
|
return x2pos(targetx, 0);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-14 06:17:19 +00:00
|
|
|
|
MathArray::size_type MathArray::x2pos(int targetx, int glue) const
|
2002-08-02 14:29:42 +00:00
|
|
|
|
{
|
2003-04-14 06:17:19 +00:00
|
|
|
|
const_iterator it = begin();
|
2002-08-02 14:29:42 +00:00
|
|
|
|
int lastx = 0;
|
|
|
|
|
int currx = 0;
|
2006-02-24 14:41:48 +00:00
|
|
|
|
// find first position after targetx
|
2002-08-02 14:29:42 +00:00
|
|
|
|
for (; currx < targetx && it < end(); ++it) {
|
|
|
|
|
lastx = currx;
|
2002-08-09 10:22:35 +00:00
|
|
|
|
if ((*it)->getChar() == ' ')
|
2002-08-02 14:29:42 +00:00
|
|
|
|
currx += glue;
|
2004-02-02 17:32:56 +00:00
|
|
|
|
currx += (*it)->width();
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
2005-04-02 14:19:31 +00:00
|
|
|
|
|
2006-02-24 14:41:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* If we are not at the beginning of the array, go to the left
|
|
|
|
|
* of the inset if one of the following two condition holds:
|
|
|
|
|
* - the current inset is editable (so that the cursor tip is
|
|
|
|
|
* deeper than us): in this case, we want all intermediate
|
|
|
|
|
* cursor slices to be before insets;
|
|
|
|
|
* - the mouse is closer to the left side of the inset than to
|
|
|
|
|
* the right one.
|
|
|
|
|
* See bug 1918 for details.
|
|
|
|
|
**/
|
|
|
|
|
if (it != begin()
|
|
|
|
|
&& ((*boost::prior(it))->asNestInset()
|
|
|
|
|
|| abs(lastx - targetx) < abs(currx - targetx))) {
|
2002-08-02 14:29:42 +00:00
|
|
|
|
--it;
|
2005-09-26 10:34:24 +00:00
|
|
|
|
}
|
2005-04-26 11:12:20 +00:00
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return it - begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathArray::dist(int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
int xx = 0;
|
|
|
|
|
int yy = 0;
|
|
|
|
|
|
2004-08-14 14:03:42 +00:00
|
|
|
|
const int xo_ = xo();
|
|
|
|
|
const int yo_ = yo();
|
|
|
|
|
|
2002-08-02 14:29:42 +00:00
|
|
|
|
if (x < xo_)
|
|
|
|
|
xx = xo_ - x;
|
|
|
|
|
else if (x > xo_ + width())
|
|
|
|
|
xx = x - xo_ - width();
|
|
|
|
|
|
|
|
|
|
if (y < yo_ - ascent())
|
|
|
|
|
yy = yo_ - ascent() - y;
|
|
|
|
|
else if (y > yo_ + descent())
|
|
|
|
|
yy = y - yo_ - descent();
|
|
|
|
|
|
|
|
|
|
return xx + yy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-11 08:26:02 +00:00
|
|
|
|
void MathArray::setXY(int x, int y) const
|
2002-08-02 14:29:42 +00:00
|
|
|
|
{
|
2004-11-07 09:39:34 +00:00
|
|
|
|
//lyxerr << "setting position cache for MathArray " << this << std::endl;
|
2005-01-31 16:29:48 +00:00
|
|
|
|
theCoords.arrays().add(this, x, y);
|
2004-08-14 14:03:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathArray::xo() const
|
|
|
|
|
{
|
2005-01-31 16:29:48 +00:00
|
|
|
|
return theCoords.getArrays().x(this);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
}
|
2004-08-14 14:03:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathArray::yo() const
|
|
|
|
|
{
|
2005-01-31 16:29:48 +00:00
|
|
|
|
return theCoords.getArrays().y(this);
|
2004-08-14 14:03:42 +00:00
|
|
|
|
}
|