remove position cache from insets - these were the last data item stored in

each inset, so we are down to the absolute minimum here...


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2929 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-10-24 09:16:06 +00:00
parent 8cd5b4a291
commit cde897f38b
28 changed files with 90 additions and 145 deletions

View File

@ -163,6 +163,8 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
par_->draw(pain, x, y);
xx += par_->width();
xo_ = x;
yo_ = y;
setCursorVisible(false);
}
@ -365,11 +367,17 @@ void InsetFormula::handleExtern(const string & arg)
if (!mathcursor)
return;
bool selected = mathcursor->selection();
MathArray ar;
if (mathcursor->selection())
if (selected) {
mathcursor->selGet(ar);
else
lyxerr << "use selection: " << ar << "\n";
} else {
ar = mathcursor->cursor().cell();
lyxerr << "use whole cell: " << ar << "\n";
}
// parse args
string lang;
@ -392,15 +400,14 @@ void InsetFormula::handleExtern(const string & arg)
string code = os.str().c_str();
// run external sript
string script = "lyx2" + arg + " '" + code + "' " + outfile;
string script = "lyx2" + lang + " '" + code + "' " + outfile;
lyxerr << "calling: " << script << endl;
Systemcalls cmd(Systemcalls::System, script, 0);
// append a '='
//ar.push_back(MathAtom(new MathCharInset('=')));
// append result
MathArray br;
if (selected)
br.push_back(MathAtom(new MathCharInset('=', LM_TC_VAR)));
ifstream is(outfile.c_str());
mathed_parse_cell(br, is);
mathcursor->insert(br);

View File

@ -103,7 +103,7 @@ MathArrayInset * matrixpar(MathInset::idx_type & idx)
InsetFormulaBase::InsetFormulaBase()
: view_(0), font_()
: view_(0), font_(), xo_(0), yo_(0)
{
// This is needed as long the math parser is not re-entrant
MathMacroTable::builtinMacros();
@ -172,9 +172,9 @@ void InsetFormulaBase::insetUnlock(BufferView * bv)
void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
{
mathcursor->getPos(x, y);
x -= par()->xo();
y -= par()->yo();
y -= 3;
x += xo_;
y += yo_ - 3;
//lyxerr << "getCursorPos: " << x << " " << y << "\n";
}
@ -189,14 +189,14 @@ void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
int x;
int y;
mathcursor->getPos(x, y);
//x -= par()->xo();
y -= par()->yo();
y -= 3;
y -= yo_;
int asc = 0;
int des = 0;
MathMetricsInfo mi(bv, font_, LM_ST_TEXT);
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
bv->showLockedInsetCursor(x, y, asc, des);
//lyxerr << "toggleInsetCursor: " << x << " " << y << "\n";
}
toggleCursorVisible();
@ -210,13 +210,12 @@ void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
int x;
int y;
mathcursor->getPos(x, y);
x -= par()->xo();
y -= par()->yo();
int asc = 0;
int des = 0;
MathMetricsInfo mi(bv, font_, LM_ST_TEXT);
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
bv->fitLockedInsetCursor(x, y, asc, des);
//lyxerr << "showInsetCursor: " << x << " " << y << "\n";
}
toggleInsetCursor(bv);
}
@ -255,9 +254,8 @@ void InsetFormulaBase::insetButtonRelease(BufferView * bv,
{
if (mathcursor) {
hideInsetCursor(bv);
x += par()->xo();
y += par()->yo();
mathcursor->setPos(x, y);
mathcursor->setPos(x + xo_, y + yo_);
//lyxerr << "insetButtonRelease: " << x + xo_ << " " << y + yo_ << "\n";
showInsetCursor(bv);
if (sel_flag) {
sel_flag = false;
@ -288,14 +286,12 @@ void InsetFormulaBase::insetMotionNotify(BufferView * bv,
if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
sel_flag = true;
hideInsetCursor(bv);
mathcursor->setPos(sel_x + par()->xo(), sel_y + par()->yo());
mathcursor->setPos(sel_x, sel_y);
mathcursor->selStart();
showInsetCursor(bv);
mathcursor->getPos(sel_x, sel_y);
} else if (sel_flag) {
hideInsetCursor(bv);
x += par()->xo();
y += par()->yo();
mathcursor->setPos(x, y);
showInsetCursor(bv);
mathcursor->getPos(x, y);
@ -429,14 +425,11 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
// break;
case LFUN_SETXY: {
lyxerr << "LFUN_SETXY broken!\n";
int x;
int y;
int x1;
int y1;
int x = 0;
int y = 0;
istringstream is(arg.c_str());
is >> x >> y;
par()->getXY(x1, y1);
mathcursor->setPos(x1 + x, y1 + y);
mathcursor->setPos(x, y);
updateLocal(bv, false);
break;
}
@ -683,6 +676,21 @@ Inset::Code InsetFormulaBase::lyxCode() const
}
int InsetFormulaBase::upperY() const
{
return yo_ - ascent(view_, font_);
}
int InsetFormulaBase::lowerY() const
{
return yo_ + descent(view_, font_);
}
/////////////////////////////////////////////////////////////////////
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
if (bv->available()) {
@ -795,3 +803,4 @@ void mathDispatchGreek(BufferView * bv, string const & arg)
}
}

View File

@ -45,6 +45,10 @@ public:
virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
///
virtual MathInsetTypes getType() const = 0;
/// upper y coordinate
virtual int upperY() const;
/// lower y coordinate
virtual int lowerY() const;
public:
///
@ -93,6 +97,10 @@ public:
virtual void metrics(BufferView * bv = 0, LyXFont const & font = LyXFont()) const;
///
virtual void updateLocal(BufferView * bv, bool mark_dirty);
///
int xo() const { return xo_; }
///
int yo() const { return yo_; }
private:
/// unimplemented
void operator=(const InsetFormulaBase &);
@ -100,6 +108,11 @@ private:
mutable BufferView * view_;
///
mutable LyXFont font_;
protected:
///
mutable int xo_;
///
mutable int yo_;
};
// We don't really mess want around with mathed stuff outside mathed.

View File

@ -115,7 +115,7 @@ void InsetFormulaMacro::read(Buffer const *, LyXLex & lex)
{
string name = mathed_parse_macro(lex);
setInsetName(name);
lyxerr << "metrics disabled";
//lyxerr << "metrics disabled";
metrics();
}
@ -202,7 +202,7 @@ MathInsetTypes InsetFormulaMacro::getType() const
void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
int baseline, float & x, bool /*cleared*/) const
int y, float & x, bool /*cleared*/) const
{
Painter & pain = bv->painter();
LyXFont font(f);
@ -210,24 +210,23 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
// label
font.setColor(LColor::math);
int const y = baseline - ascent(bv, font) + 1;
int const a = y - ascent(bv, font) + 1;
int const w = width(bv, font) - 2;
int const h = ascent(bv, font) + descent(bv, font) - 2;
// LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
pain.fillRectangle(int(x), y , w, h, LColor::mathmacrobg);
pain.rectangle(int(x), y, w, h, LColor::mathframe);
pain.fillRectangle(int(x), a , w, h, LColor::mathmacrobg);
pain.rectangle(int(x), a, w, h, LColor::mathframe);
if (mathcursor && mathcursor->formula() == this)
mathcursor->drawSelection(pain);
pain.text(int(x + 2), baseline, prefix(), font);
pain.text(int(x + 2), y, prefix(), font);
x += width(bv, font);
// formula
float t = par()->width() + 5;
x -= t;
par()->draw(pain, int(x), baseline);
x += t;
xo_ = int(x) - par()->width() - 5;
yo_ = y;
par()->draw(pain, xo_, yo_);
}

View File

@ -42,8 +42,6 @@ void MathBinomInset::metrics(MathMetricsInfo const & st) const
void MathBinomInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);

View File

@ -84,8 +84,6 @@ void MathCharInset::metrics(MathMetricsInfo const & mi) const
void MathCharInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
//lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
drawChar(pain, code_, mi_, x, y, char_);
}

View File

@ -750,7 +750,7 @@ void MathCursor::selClear()
void MathCursor::selGet(MathArray & ar)
{
seldump("selGet");
if (selection_)
if (!selection_)
return;
theSelection.grab(*this);
@ -1179,9 +1179,8 @@ bool MathCursor::goUp()
int y0;
getPos(x0, y0);
std::vector<MathCursorPos> save = Cursor_;
MathAtom const & out = formula()->par();
y0 -= xarray().ascent();
for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
setPos(x0, y);
if (save != Cursor_ && xarray().yo() < y0)
return true;
@ -1212,9 +1211,8 @@ bool MathCursor::goDown()
int y0;
getPos(x0, y0);
std::vector<MathCursorPos> save = Cursor_;
MathAtom const & out = formula()->par();
y0 += xarray().descent();
for (int y = y0 + 4; y < out->yo() + out->descent(); y += 4) {
for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
setPos(x0, y);
if (save != Cursor_ && xarray().yo() > y0)
return true;

View File

@ -84,8 +84,6 @@ void MathDecorationInset::metrics(MathMetricsInfo const & st) const
void MathDecorationInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(x);
xcell(0).draw(pain, x, y);
if (wide())
mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);

View File

@ -76,9 +76,6 @@ void MathDelimInset::metrics(MathMetricsInfo const & mi) const
void MathDelimInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
int const w = dw();
int const b = y - ascent_;
xcell(0).draw(pain, x + w + 2, y);

View File

@ -33,8 +33,6 @@ void MathFracInset::metrics(MathMetricsInfo const & mi) const
void MathFracInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);

View File

@ -58,7 +58,5 @@ void MathFuncInset::metrics(MathMetricsInfo const & mi) const
void MathFuncInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
drawStr(pain, LM_TC_TEX, mi_, x, y, name_);
}

View File

@ -44,7 +44,5 @@ void MathFuncLimInset::metrics(MathMetricsInfo const & mi) const
void MathFuncLimInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
drawStr(pain, LM_TC_TEXTRM, mi_, x, y, sym_->name);
}

View File

@ -257,8 +257,6 @@ void MathGridInset::metrics(MathMetricsInfo const & mi) const
void MathGridInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
for (idx_type idx = 0; idx < nargs(); ++idx)
xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx));
}

View File

@ -25,7 +25,6 @@
MathInset::MathInset()
: xo_(0), yo_(0)
{}
@ -47,30 +46,6 @@ std::ostream & operator<<(std::ostream & os, MathInset const & inset)
}
int MathInset::xo() const
{
return xo_;
}
int MathInset::yo() const
{
return yo_;
}
void MathInset::xo(int x) const
{
xo_ = x;
}
void MathInset::yo(int y) const
{
yo_ = y;
}
MathInset::size_type MathInset::nargs() const
{
return 0;
@ -182,13 +157,6 @@ void MathInset::idxDeleteRange(idx_type, idx_type)
{}
void MathInset::getXY(int & x, int & y) const
{
x = xo();
y = yo();
}
void MathInset::writeNormal(std::ostream & os) const
{
os << "[unknown ";
@ -209,13 +177,8 @@ void MathInset::dump() const
bool MathInset::covers(int x, int y) const
{
//lyxerr << "cover? p: " << this << " x: " << x << " y: " << y
// << " xo_: " << xo_ << " yo_: " << yo_ << endl;
return
x >= xo_ &&
x <= xo_ + width() &&
y >= yo_ - ascent() &&
y <= yo_ + descent();
lyxerr << "MathInset::covers() called directly!\n";
return false;
}

View File

@ -104,7 +104,7 @@ public:
/// the virtual base destructor
virtual ~MathInset();
/// draw the object, sets xo_ and yo_ cached values
/// draw the object
virtual void draw(Painter &, int x, int y) const;
/// write LaTeX and Lyx code
virtual void write(MathWriteInfo & os) const;
@ -171,16 +171,6 @@ public:
///
virtual MathXArray const & xcell(idx_type) const;
///
virtual int xo() const;
///
virtual int yo() const;
///
virtual void xo(int tx) const;
///
virtual void yo(int ty) const;
///
///
virtual col_type ncols() const { return 1; }
///
@ -202,8 +192,6 @@ public:
///
virtual void delCol(col_type) {}
///
virtual void getXY(int & x, int & y) const;
///
virtual bool covers(int x, int y) const;
@ -253,13 +241,6 @@ public:
virtual void validate(LaTeXFeatures & features) const;
///
virtual void handleFont(MathTextCodes) {}
private:
/// the following are used for positioning the cursor with the mouse
/// cached cursor start position in pixels from the document left
mutable int xo_;
/// cached cursor start position in pixels from the document top
mutable int yo_;
};
std::ostream & operator<<(std::ostream &, MathInset const &);

View File

@ -113,9 +113,6 @@ void MathMacro::metrics(MathMetricsInfo const & mi) const
void MathMacro::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
metrics(mi_);
if (defining()) {

View File

@ -67,8 +67,6 @@ void MathMacroTemplate::metrics(MathMetricsInfo const & mi) const
void MathMacroTemplate::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
xcell(0).draw(pain, x + 2, y + 1);
pain.rectangle(x, y - ascent(), width(), height(), LColor::blue);
}

View File

@ -173,9 +173,6 @@ void MathMatrixInset::metrics(MathMetricsInfo const & mi) const
void MathMatrixInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
MathGridInset::draw(pain, x, y);
if (numberedType()) {

View File

@ -57,8 +57,6 @@ void MathNestInset::metrics(MathMetricsInfo const & mi) const
void MathNestInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
for (idx_type i = 0; i < nargs(); ++i)
xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
}
@ -161,3 +159,21 @@ void MathNestInset::validate(LaTeXFeatures & features) const
for (idx_type i = 0; i < nargs(); ++i)
cell(i).validate(features);
}
bool MathNestInset::covers(int x, int y) const
{
if (!nargs())
return false;
int x0 = xcell(0).xo();
int y0 = xcell(0).yo() - xcell(0).ascent();
int x1 = xcell(0).xo() + xcell(0).width();
int y1 = xcell(0).yo() + xcell(0).descent();
for (idx_type i = 1; i < nargs(); ++i) {
x0 = min(x0, xcell(i).xo());
y0 = min(y0, xcell(i).yo() - xcell(i).ascent());
x1 = max(x1, xcell(i).xo() + xcell(i).width());
y1 = max(y1, xcell(i).yo() + xcell(i).descent());
}
return x >= x0 && x <= x1 && y >= y0 && y <= y1;
}

View File

@ -68,6 +68,8 @@ public:
///
void validate(LaTeXFeatures & features) const;
///
bool covers(int x, int y) const;
protected:
///

View File

@ -41,9 +41,6 @@ void MathNotInset::metrics(MathMetricsInfo const & mi) const
void MathNotInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
if (math_font_available(LM_TC_CMSY))
drawChar(pain, LM_TC_CMSY, mi_, x, y, 54);
else

View File

@ -42,8 +42,6 @@ void MathRootInset::metrics(MathMetricsInfo const & mi) const
void MathRootInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
int const w = xcell(0).width();
xcell(0).draw(pain, x, y - 5 - xcell(0).descent()); // the "exponent"
xcell(1).draw(pain, x + w + 8, y); // the "base"

View File

@ -209,9 +209,6 @@ void MathScriptInset::draw(Painter & pain, int x, int y) const
void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
int x, int y) const
{
xo(x);
yo(y);
if (nuc)
nuc->draw(pain, x + dxx(nuc), y);
else

View File

@ -20,8 +20,6 @@ MathInset * MathSizeInset::clone() const
void MathSizeInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
xcell(0).draw(pain, x, y);
}

View File

@ -44,8 +44,6 @@ void MathSpecialCharInset::metrics(MathMetricsInfo const & mi) const
void MathSpecialCharInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
drawChar(pain, LM_TC_CONST, mi_, x, y, char_);
}

View File

@ -30,8 +30,6 @@ void MathSqrtInset::metrics(MathMetricsInfo const & mi) const
void MathSqrtInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
xcell(0).draw(pain, x + 10, y);
int const a = ascent_;
int const d = descent_;

View File

@ -31,8 +31,6 @@ void MathStackrelInset::metrics(MathMetricsInfo const & mi) const
void MathStackrelInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).height() - 4);
xcell(1).draw(pain, m - xcell(1).width() / 2, y);

View File

@ -81,8 +81,6 @@ void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
void MathSymbolInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
MathTextCodes Code = code();
if (sym_->latex_font_id > 0 && math_font_available(Code))
drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);