mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 05:33:33 +00:00
09ec5ba3e7
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7676 a592a061-630c-0410-9148-cb99ea01b6c8
159 lines
3.2 KiB
C
159 lines
3.2 KiB
C
/**
|
|
* \file math_xyarrowinset.C
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author André Pönitz
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "math_xyarrowinset.h"
|
|
#include "math_xymatrixinset.h"
|
|
#include "math_mathmlstream.h"
|
|
#include "math_streamstr.h"
|
|
#include "math_support.h"
|
|
#include "frontends/Painter.h"
|
|
#include "debug.h"
|
|
|
|
|
|
using std::max;
|
|
|
|
|
|
MathXYArrowInset::MathXYArrowInset()
|
|
: MathNestInset(2)
|
|
{}
|
|
|
|
|
|
auto_ptr<InsetBase> MathXYArrowInset::clone() const
|
|
{
|
|
return auto_ptr<InsetBase>(new MathXYArrowInset(*this));
|
|
}
|
|
|
|
|
|
MathXYMatrixInset const * MathXYArrowInset::targetMatrix() const
|
|
{
|
|
return target_;
|
|
}
|
|
|
|
|
|
MathArray const & MathXYArrowInset::targetCell() const
|
|
{
|
|
#if 0
|
|
MathXYMatrixInset const * p = targetMatrix();
|
|
int x = 0;
|
|
int y = 0;
|
|
MathArray const & t = cell(0);
|
|
for (MathArray::const_iterator it = t.begin(); it != t.end(); ++it) {
|
|
switch ((*it)->getChar()) {
|
|
case 'l': --x; break;
|
|
case 'r': ++x; break;
|
|
case 'u': --y; break;
|
|
case 'd': ++y; break;
|
|
}
|
|
}
|
|
//lyxerr << "target: x: " << x << " y: " << y << endl;
|
|
MathInset::idx_type n = mi_.idx + p->ncols() * y + x;
|
|
if (n >= p->nargs()) {
|
|
lyxerr << "source: n: " << mi_.idx << "\n"
|
|
<< "target: n: " << n << " out of range" << endl;
|
|
n = 0;
|
|
}
|
|
return p->cell(n);
|
|
#else
|
|
static MathArray dummy;
|
|
return dummy;
|
|
#endif
|
|
}
|
|
|
|
|
|
MathArray const & MathXYArrowInset::sourceCell() const
|
|
{
|
|
#if 0
|
|
return targetMatrix()->cell(mi_.idx);
|
|
#else
|
|
static MathArray dummy;
|
|
return dummy;
|
|
#endif
|
|
}
|
|
|
|
|
|
void MathXYArrowInset::metrics(MetricsInfo & mi) const
|
|
{
|
|
MathNestInset::metrics(mi);
|
|
mi_ = mi;
|
|
FontSetChanger dummy(mi.base, "textrm");
|
|
#if 0
|
|
target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
|
|
|
|
if (editing()) {
|
|
int w = mathed_string_width(mi.base.font, "target: ");
|
|
width_ = w + max(cell(0).width(), cell(1).width());
|
|
ascent_ = cell(0).ascent();
|
|
descent_ = cell(0).descent() + cell(1).height() + 10;
|
|
} else {
|
|
width_ = 0;
|
|
ascent_ = 0;
|
|
descent_ = 0;
|
|
//mathed_string_dim(font_, "X", ascent_, descent_, width_);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
void MathXYArrowInset::draw(PainterInfo & pi, int x, int y) const
|
|
{
|
|
metrics(mi_);
|
|
FontSetChanger dummy(pi.base, "textrm");
|
|
|
|
if (editing()) {
|
|
|
|
#if 0
|
|
|
|
int lasc;
|
|
int ldes;
|
|
int lwid;
|
|
mathed_string_dim(pi.base.font, "target: ", lasc, ldes, lwid);
|
|
|
|
cell(0).draw(pi, x + lwid, y);
|
|
drawStr(pi, pi.base.font, x + 3, y, "target");
|
|
y += max(cell(0).descent(), ldes) + 5;
|
|
|
|
y += max(cell(1).ascent(), lasc) + 5;
|
|
cell(1).draw(pi, x + lwid, y);
|
|
drawStr(pi, pi.base.font, x + 3, y, "label");
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
drawStr(pi, font_, x, y, "X");
|
|
MathArray const & s = sourceCell();
|
|
MathArray const & t = targetCell();
|
|
pi.pain.line(s.xm(), s.ym(), t.xm(), t.ym(), LColor::math);
|
|
cell(1).draw(pi, (s.xm() + t.xm())/2, (s.ym() + t.ym())/2);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void MathXYArrowInset::write(WriteStream & os) const
|
|
{
|
|
os << "\\ar";
|
|
if (cell(0).size())
|
|
os << '[' << cell(0) << ']';
|
|
if (cell(1).size())
|
|
os << (up_ ? '^' : '_') << '{' << cell(1) << '}';
|
|
os << " ";
|
|
}
|
|
|
|
|
|
void MathXYArrowInset::normalize(NormalStream & os) const
|
|
{
|
|
os << "[xyarrow ";
|
|
MathNestInset::normalize(os);
|
|
os << ']';
|
|
}
|