Put mathed on a diet: transfer dimension cache from inset to BufferView.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20457 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-09-23 22:39:49 +00:00
parent d0cd79a7ed
commit 137158532b
62 changed files with 281 additions and 196 deletions

View File

@ -43,8 +43,6 @@ void CoordCache::clear()
{
arrays_.clear();
insets_.clear();
slices0_.clear();
slices1_.clear();
}
@ -53,7 +51,7 @@ void CoordCache::dump() const
lyxerr << "InsetCache contains:" << std::endl;
for (CoordCacheBase<Inset>::cache_type::const_iterator it = getInsets().getData().begin(); it != getInsets().getData().end(); ++it) {
Inset const * inset = it->first;
Point const p = it->second;
Point const p = it->second.pos;
lyxerr << "Inset " << inset << "(" << to_utf8(inset->name())
<< ") has point " << p.x_ << "," << p.y_ << std::endl;
}

View File

@ -14,6 +14,8 @@
// It seems that MacOSX define the check macro.
#undef check
#include "Dimension.h"
#include "support/types.h"
#include <map>
@ -38,6 +40,13 @@ public:
int x_, y_;
};
struct Geometry {
Point pos;
Dimension dim;
};
template <class T> class CoordCacheBase {
public:
void clear()
@ -52,25 +61,36 @@ public:
void add(T const * thing, int x, int y)
{
data_[thing] = Point(x, y);
data_[thing].pos = Point(x, y);
}
void add(T const * thing, Dimension const & dim)
{
data_[thing].dim = dim;
}
Dimension const & dim(T const * thing) const
{
//check(thing, "dim");
return data_.find(thing)->second.dim;
}
int x(T const * thing) const
{
check(thing, "x");
return data_.find(thing)->second.x_;
return data_.find(thing)->second.pos.x_;
}
int y(T const * thing) const
{
check(thing, "y");
return data_.find(thing)->second.y_;
return data_.find(thing)->second.pos.y_;
}
Point xy(T const * thing) const
{
check(thing, "xy");
return data_.find(thing)->second;
return data_.find(thing)->second.pos;
}
bool has(T const * thing) const
@ -93,7 +113,7 @@ private:
lyxbreaker(thing, hint, data_.size());
}
typedef std::map<T const *, Point> cache_type;
typedef std::map<T const *, Geometry> cache_type;
cache_type data_;
public:
@ -114,26 +134,12 @@ class CoordCache {
public:
void clear();
/// A map from paragraph index number to screen point
typedef std::map<pit_type, Point> InnerParPosCache;
/// A map from a CursorSlice to screen points
typedef std::map<Text const *, InnerParPosCache> SliceCache;
/// A map from MathData to position on the screen
CoordCacheBase<MathData> & arrays() { return arrays_; }
CoordCacheBase<MathData> const & getArrays() const { return arrays_; }
/// A map from insets to positions on the screen
CoordCacheBase<Inset> & insets() { return insets_; }
CoordCacheBase<Inset> const & getInsets() const { return insets_; }
///
SliceCache & slice(bool boundary)
{
return boundary ? slices1_ : slices0_;
}
SliceCache const & getSlice(bool boundary) const
{
return boundary ? slices1_ : slices0_;
}
/// Dump the contents of the cache to lyxerr in debugging form
void dump() const;
@ -142,10 +148,6 @@ private:
CoordCacheBase<MathData> arrays_;
// All insets
CoordCacheBase<Inset> insets_;
/// Used with boundary == 0
SliceCache slices0_;
/// Used with boundary == 1
SliceCache slices1_;
};
} // namespace lyx

View File

@ -97,9 +97,9 @@ namespace {
int xo;
int yo;
Inset const * inset = &it.inset();
std::map<Inset const *, Point> const & data =
std::map<Inset const *, Geometry> const & data =
c.bv().coordCache().getInsets().getData();
std::map<Inset const *, Point>::const_iterator I = data.find(inset);
std::map<Inset const *, Geometry>::const_iterator I = data.find(inset);
// FIXME: in the case where the inset is not in the cache, this
// means that no part of it is visible on screen. In this case
@ -110,7 +110,7 @@ namespace {
return it;
}
Point o = I->second;
Point o = I->second.pos;
inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
// Convert to absolute
xo += o.x_;

View File

@ -36,7 +36,6 @@
#include "frontends/Painter.h"
#include "support/convert.h"
#include "support/ExceptionMessage.h"
#include <boost/current_function.hpp>
@ -123,11 +122,9 @@ Inset::Inset()
{}
Dimension const Inset::dimension(BufferView const &) const
Dimension const Inset::dimension(BufferView const & bv) const
{
docstring const id = convert<docstring>(int(lyxCode())) + " " + name();
throw support::ExceptionMessage(support::ErrorException,
_("Inset::dimension(): unimplemented method"), id);
return bv.coordCache().getInsets().dim(this);
}
@ -378,6 +375,13 @@ void Inset::setPosCache(PainterInfo const & pi, int x, int y) const
}
void Inset::setDimCache(MetricsInfo const & mi, Dimension const & dim) const
{
mi.base.bv->coordCache().insets().add(this, dim);
}
/////////////////////////////////////////
bool isEditableInset(Inset const * inset)

View File

@ -147,6 +147,8 @@ public:
int yo(BufferView const & bv) const;
/// set x/y drawing position cache if available
virtual void setPosCache(PainterInfo const &, int, int) const;
///
void setDimCache(MetricsInfo const &, Dimension const &) const;
/// do we cover screen position x/y?
virtual bool covers(BufferView const & bv, int x, int y) const;
/// get the screen positions of the cursor (see note in Cursor.cpp)

View File

@ -60,6 +60,8 @@ void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = fm.width(ds);
if (kind_ == HYPHENATION && dim.wid > 5)
dim.wid -= 2; // to make it look shorter
setDimCache(mi, dim);
}

View File

@ -43,7 +43,8 @@ void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
button_.update(screenLabel(), true);
}
button_.metrics(mi, dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -83,16 +83,24 @@ void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
ArrayChanger dummy(mi.base);
InsetMathGrid::metrics(mi, dim);
dim.wid += 14;
dim_ = dim;
}
Dimension const InsetMathAMSArray::dimension(BufferView const & bv) const
{
Dimension dim = InsetMathGrid::dimension(bv);
dim.wid += 14;
return dim;
}
void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
{
int const yy = y - dim_.ascent();
Dimension const dim = dimension(*pi.base.bv);
int const yy = y - dim.ascent();
// Drawing the deco after an ArrayChanger does not work
mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), from_ascii(name_left()));
mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), from_ascii(name_right()));
mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
ArrayChanger dummy(pi.base);
InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
}

View File

@ -27,6 +27,8 @@ public:
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const;
///
void draw(PainterInfo & pain, int x, int y) const;
///
InsetMathAMSArray * asAMSArrayInset() { return this; }

View File

@ -83,7 +83,14 @@ void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
ArrayChanger dummy(mi.base);
InsetMathGrid::metrics(mi, dim);
dim.wid += 6;
dim_ = dim;
}
Dimension const InsetMathArray::dimension(BufferView const & bv) const
{
Dimension dim = InsetMathGrid::dimension(bv);
dim.wid += 6;
return dim;
}

View File

@ -33,6 +33,8 @@ public:
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
InsetMathArray * asArrayInset() { return this; }

View File

@ -29,8 +29,6 @@ public:
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const { return dim_; };
///
void draw(PainterInfo & pi, int x, int y) const;
///
void write(WriteStream & os) const;

View File

@ -29,9 +29,9 @@ Inset * InsetMathBinom::clone() const
}
int InsetMathBinom::dw() const
int InsetMathBinom::dw(int height) const
{
int w = dim_.height() / 5;
int w = height / 5;
if (w > 15)
w = 15;
if (w < 6)
@ -47,21 +47,23 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
cell(1).metrics(mi);
dim.asc = cell(0).height() + 4 + 5;
dim.des = cell(1).height() + 4 - 5;
dim.wid = std::max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
dim.wid = std::max(cell(0).width(), cell(1).width()) + 2 * dw(dim.height()) + 4;
metricsMarkers2(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
{
int m = x + dim_.width() / 2;
Dimension const dim = dimension(*pi.base.bv);
int m = x + dim.width() / 2;
ScriptChanger dummy(pi.base);
cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 3 - 5);
mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), from_ascii("("));
mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
dw(), dim_.height(), from_ascii(")"));
mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("("));
mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(),
dw(dim.height()), dim.height(), from_ascii(")"));
drawMarkers2(pi, x, y);
}

View File

@ -39,7 +39,7 @@ public:
private:
virtual Inset * clone() const;
///
int dw() const;
int dw(int height) const;
///
bool choose_;
};

View File

@ -36,7 +36,8 @@ void InsetMathBoldSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
cell(0).metrics(mi, dim);
metricsMarkers(dim);
++dim.wid; // for 'double stroke'
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -51,7 +52,9 @@ void InsetMathBoldSymbol::draw(PainterInfo & pi, int x, int y) const
void InsetMathBoldSymbol::metricsT(TextMetricsInfo const & mi, Dimension & /*dim*/) const
{
cell(0).metricsT(mi, dim_);
// FIXME: BROKEN!
Dimension dim;
cell(0).metricsT(mi, dim);
}

View File

@ -49,7 +49,8 @@ void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, "textnormal");
cell(0).metrics(mi, dim);
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -37,14 +37,16 @@ void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
{
pi.pain.rectangle(x + 1, y - dim_.ascent() + 1,
dim_.width() - 2, dim_.height() - 2, Color::foreground);
Dimension const dim = dimension(*pi.base.bv);
pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
dim.width() - 2, dim.height() - 2, Color::foreground);
cell(0).draw(pi, x + 3, y);
setPosCache(pi, x, y);
}

View File

@ -49,7 +49,8 @@ void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des = std::max(cell(0).descent(), t.des);
dim.wid = cell(0).width() + 2 * t.wid;
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -45,15 +45,23 @@ Inset * InsetMathCases::clone() const
void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetMathGrid::metrics(mi);
dim_.wid += 8;
dim = dim_;
InsetMathGrid::metrics(mi, dim);
dim.wid += 8;
}
Dimension const InsetMathCases::dimension(BufferView const & bv) const
{
Dimension dim = InsetMathGrid::dimension(bv);
dim.wid += 8;
return dim;
}
void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
{
mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 6, dim_.height(), from_ascii("{"));
Dimension const dim = dimension(*pi.base.bv);
mathed_draw_deco(pi, x + 1, y - dim.ascent(), 6, dim.height(), from_ascii("{"));
InsetMathGrid::drawWithMargin(pi, x, y, 8, 0);
setPosCache(pi, x, y);
}

View File

@ -27,6 +27,8 @@ public:
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);

View File

@ -86,8 +86,7 @@ void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
lyxerr << "InsetMathChar::metrics: " << dim << endl;
#endif
// Cache the inset dimension.
// FIXME: put the resulting dim in BufferView.
dim_ = dim;
setDimCache(mi, dim);
}

View File

@ -26,8 +26,6 @@ public:
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const { return dim_; }
///
void draw(PainterInfo & pi, int x, int y) const;
///
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;

View File

@ -42,7 +42,8 @@ void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -42,7 +42,8 @@ void InsetMathComment::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -38,16 +38,18 @@ void InsetMathDFrac::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = std::max(cell(0).width(), cell(1).width()) + 2;
dim.asc = cell(0).height() + 2 + 5;
dim.des = cell(1).height() + 2 - 5;
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathDFrac::draw(PainterInfo & pi, int x, int y) const
{
int m = x + dim_.wid / 2;
Dimension const dim = dimension(*pi.base.bv);
int m = x + dim.wid / 2;
cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5);
pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, Color::math);
pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, Color::math);
setPosCache(pi, x, y);
}

View File

@ -117,7 +117,8 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
}
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -83,17 +83,19 @@ void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = cell(0).width() + 2 * dw_ + 8;
dim.asc = max(a0, d0) + h0;
dim.des = max(a0, d0) - h0;
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
{
int const b = y - dim_.asc;
Dimension const dim = dimension(*pi.base.bv);
int const b = y - dim.asc;
cell(0).draw(pi, x + dw_ + 4, y);
mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
b, dw_, dim_.height(), right_);
mathed_draw_deco(pi, x + 4, b, dw_, dim.height(), left_);
mathed_draw_deco(pi, x + dim.width() - dw_ - 4,
b, dw_, dim.height(), right_);
setPosCache(pi, x, y);
}

View File

@ -47,19 +47,21 @@ void InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const
}
else if (key_->name == "ddots")
dh_ = dim.asc;
dim = dim_;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathDots::draw(PainterInfo & pain, int x, int y) const
{
mathed_draw_deco(pain, x + 2, y - dh_, dim_.width() - 2, dim_.ascent(),
Dimension const dim = dimension(*pain.base.bv);
mathed_draw_deco(pain, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
key_->name);
if (key_->name == "vdots" || key_->name == "ddots")
++x;
if (key_->name != "vdots")
--y;
mathed_draw_deco(pain, x + 2, y - dh_, dim_.width() - 2, dim_.ascent(),
mathed_draw_deco(pain, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
key_->name);
setPosCache(pain, x, y);
}

View File

@ -27,8 +27,6 @@ public:
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const { return dim_; };
///
void draw(PainterInfo & pi, int x, int y) const;
///
docstring name() const;
@ -39,8 +37,6 @@ protected:
latexkeys const * key_;
private:
virtual Inset * clone() const;
///
mutable Dimension dim_;
};
} // namespace lyx

View File

@ -34,7 +34,8 @@ void InsetMathEnv::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -43,7 +43,8 @@ Inset * InsetMathExFunc::clone() const
void InsetMathExFunc::metrics(MetricsInfo & mi, Dimension & dim) const
{
mathed_string_dim(mi.base.font, name_, dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -43,14 +43,16 @@ void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, "textnormal");
cell(0).metrics(mi, dim);
metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
{
pi.pain.rectangle(x + 1, y - dim_.ascent() + 1,
dim_.width() - 2, dim_.height() - 2, Color::foreground);
Dimension const dim = dimension(*pi.base.bv);
pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
dim.width() - 2, dim.height() - 2, Color::foreground);
FontSetChanger dummy(pi.base, "textnormal");
cell(0).draw(pi, x + 3, y);
setPosCache(pi, x, y);

View File

@ -46,7 +46,8 @@ void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, key_->name);
cell(0).metrics(mi, dim);
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -61,7 +62,9 @@ void InsetMathFont::draw(PainterInfo & pi, int x, int y) const
void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
{
cell(0).metricsT(mi, dim_);
// FIXME: BROKEN!
Dimension dim;
cell(0).metricsT(mi, dim);
}

View File

@ -38,7 +38,8 @@ void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, key_->name.c_str());
cell(0).metrics(mi, dim);
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -128,14 +128,16 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
}
}
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
{
setPosCache(pi, x, y);
int m = x + dim_.wid / 2;
Dimension const dim = dimension(*pi.base.bv);
int m = x + dim.wid / 2;
if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
if (nargs() == 1) {
ShapeChanger dummy2(pi.base.font, Font::UP_SHAPE);
@ -181,13 +183,13 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
if (nargs() == 3)
xx += cell(2).width() + 5;
pi.pain.line(xx + cell(0).width(),
y + dim_.des - 2,
y + dim.des - 2,
xx + cell(0).width() + 5,
y - dim_.asc + 2, Color::math);
y - dim.asc + 2, Color::math);
}
if (kind_ == FRAC || kind_ == OVER)
pi.pain.line(x + 1, y - 5,
x + dim_.wid - 2, y - 5, Color::math);
x + dim.wid - 2, y - 5, Color::math);
drawMarkers(pi, x, y);
}
@ -199,18 +201,19 @@ void InsetMathFrac::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
dim.wid = std::max(cell(0).width(), cell(1).width());
dim.asc = cell(0).height() + 1;
dim.des = cell(1).height();
//dim = dim_;
}
void InsetMathFrac::drawT(TextPainter & pain, int x, int y) const
{
int m = x + dim_.width() / 2;
// FIXME: BROKEN!
Dimension dim;
int m = x + dim.width() / 2;
cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
// ASCII art: ignore niceties
if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC || kind_ == UNITFRAC)
pain.horizontalLine(x, y, dim_.width());
pain.horizontalLine(x, y, dim.width());
}

View File

@ -40,15 +40,17 @@ void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
dim += cell(1).dim();
dim += cell(2).dim();
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
{
FontSetChanger dummy(pi.base, "textnormal");
pi.pain.rectangle(x + 1, y - dim_.ascent() + 1,
dim_.width() - 2, dim_.height() - 2, Color::foreground);
Dimension const dim = dimension(*pi.base.bv);
pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
dim.width() - 2, dim.height() - 2, Color::foreground);
x += 5;
drawStrBlack(pi, x, y, from_ascii("["));

View File

@ -365,7 +365,7 @@ Length InsetMathGrid::vcrskip(row_type row) const
}
void InsetMathGrid::metrics(MetricsInfo & mi) const
void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
{
// let the cells adjust themselves
InsetMathNest::metrics(mi);
@ -435,17 +435,17 @@ void InsetMathGrid::metrics(MetricsInfo & mi) const
}
dim_.wid = colinfo_[ncols() - 1].offset_
dim.wid = colinfo_[ncols() - 1].offset_
+ colinfo_[ncols() - 1].width_
+ vlinesep() * colinfo_[ncols()].lines_
+ border();
dim_.asc = - rowinfo_[0].offset_
dim.asc = - rowinfo_[0].offset_
+ rowinfo_[0].ascent_
+ hlinesep() * rowinfo_[0].lines_
+ border();
dim_.des = rowinfo_[nrows() - 1].offset_
dim.des = rowinfo_[nrows() - 1].offset_
+ rowinfo_[nrows() - 1].descent_
+ hlinesep() * rowinfo_[nrows()].lines_
+ border();
@ -501,14 +501,9 @@ void InsetMathGrid::metrics(MetricsInfo & mi) const
cxrow->setBaseline(cxrow->getBaseline() - ascent);
}
*/
metricsMarkers2(dim_);
}
void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
{
metrics(mi);
dim = dim_;
metricsMarkers2(dim);
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -517,9 +512,12 @@ void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
drawWithMargin(pi, x, y, 0, 0);
}
void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
int lmargin, int rmargin) const
{
Dimension const dim = dimension(*pi.base.bv);
for (idx_type idx = 0; idx < nargs(); ++idx)
cell(idx).draw(pi, x + lmargin + cellXOffset(idx),
y + cellYOffset(idx));
@ -529,7 +527,7 @@ void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
- i * hlinesep() - hlinesep()/2 - rowsep()/2;
pi.pain.line(x + lmargin + 1, yy,
x + dim_.width() - rmargin - 1, yy,
x + dim.width() - rmargin - 1, yy,
Color::foreground);
}
@ -537,8 +535,8 @@ void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
int xx = x + lmargin + colinfo_[col].offset_
- i * vlinesep() - vlinesep()/2 - colsep()/2;
pi.pain.line(xx, y - dim_.ascent() + 1,
xx, y + dim_.descent() - 1,
pi.pain.line(xx, y - dim.ascent() + 1,
xx, y + dim.descent() - 1,
Color::foreground);
}
drawMarkers2(pi, x, y);

View File

@ -100,8 +100,6 @@ public:
///
InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign);
///
void metrics(MetricsInfo & mi) const;
///
void metrics(MetricsInfo & mi, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;

View File

@ -290,7 +290,8 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid += 1;
if (display())
dim.des += displayMargin();
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
return;
}
@ -321,19 +322,22 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
math_font_max_dim(mi.base.font, asc, des);
dim.asc = max(dim.asc, asc);
dim.des = max(dim.des, des);
dim_ = dim;
// Cache the inset dimension.
// FIXME: This will overwrite InsetMathGrid dimension, is that OK?
setDimCache(mi, dim);
}
void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
{
use_preview_ = previewState(pi.base.bv);
Dimension const dim = dimension(*pi.base.bv);
// background of mathed under focus is not painted because
// selection at the top level of nested inset is difficult to handle.
if (!editing(pi.base.bv))
pi.pain.fillRectangle(x + 1, y - dim_.asc + 1, dim_.wid - 2,
dim_.asc + dim_.des - 1, Color::mathbg);
pi.pain.fillRectangle(x + 1, y - dim.asc + 1, dim.wid - 2,
dim.asc + dim.des - 1, Color::mathbg);
if (use_preview_) {
// one pixel gap in front

View File

@ -35,7 +35,8 @@ void InsetMathLefteqn::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des += 2;
dim.wid = 4;
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -41,7 +41,8 @@ void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
dim += cell(2).dim();
dim.wid += 4 * w_ + 4;
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -33,8 +33,6 @@ public:
/// the size is usually some sort of convex hull of the cells
/// hides inset::metrics() intentionally!
void metrics(MetricsInfo const & mi) const;
///
Dimension const dimension(BufferView const &) const { return dim_; };
/// draw background if locked
void draw(PainterInfo & pi, int x, int y) const;
/// draw selection background
@ -161,8 +159,6 @@ protected:
bool lock_;
///
bool mouse_hover_;
/// Cached dimensions of the inset.
mutable Dimension dim_;
};

View File

@ -35,13 +35,15 @@ void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = cell(1).ascent() + cell(0).height() + 4;
dim.des = cell(1).descent();
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathOverset::draw(PainterInfo & pi, int x, int y) const
{
int m = x + dim_.wid / 2;
Dimension const dim = dimension(*pi.base.bv);
int m = x + dim.wid / 2;
int yo = y - cell(1).ascent() - cell(0).descent() - 1;
cell(1).draw(pi, m - cell(1).width() / 2, y);
FracChanger dummy(pi.base);

View File

@ -27,8 +27,7 @@ InsetMathPar::InsetMathPar(MathData const & ar)
void InsetMathPar::metrics(MetricsInfo & mi, Dimension & dim) const
{
FontSetChanger dummy1(mi.base, "textnormal");
InsetMathGrid::metrics(mi);
dim = dim_;
InsetMathGrid::metrics(mi, dim);
}

View File

@ -39,7 +39,8 @@ void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -52,6 +53,7 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
pi.base.font.setColor(Color::special);
cell(0).draw(pi, x + 1, y);
pi.base.font.setColor(origcol);
Dimension const dim = dimension(*pi.base.bv);
if (kind_ == phantom || kind_ == vphantom) {
// y1---------
@ -66,13 +68,13 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
// / | \.
// x1 x2 x3
int const x2 = x + dim_.wid / 2;
int const x2 = x + dim.wid / 2;
int const x1 = x2 - arrow_size;
int const x3 = x2 + arrow_size;
int const y1 = y - dim_.asc;
int const y1 = y - dim.asc;
int const y2 = y1 + arrow_size;
int const y4 = y + dim_.des;
int const y4 = y + dim.des;
int const y3 = y4 - arrow_size;
// top arrow
@ -98,10 +100,10 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
int const x1 = x;
int const x2 = x + arrow_size;
int const x4 = x + dim_.wid;
int const x4 = x + dim.wid;
int const x3 = x4 - arrow_size;
int const y2 = y + (dim_.des - dim_.asc) / 2;
int const y2 = y + (dim.des - dim.asc) / 2;
int const y1 = y2 - arrow_size;
int const y3 = y2 + arrow_size;

View File

@ -42,7 +42,8 @@ void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des = max(cell(0).descent() - 5, cell(1).descent()) + 2;
dim.wid = cell(0).width() + cell(1).width() + 10;
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -53,11 +54,12 @@ void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
cell(0).draw(pi, x, y - 5 - cell(0).descent());
// the "base"
cell(1).draw(pi, x + w + 8, y);
int const a = dim_.ascent();
int const d = dim_.descent();
Dimension const dim = dimension(*pi.base.bv);
int const a = dim.ascent();
int const d = dim.descent();
int xp[4];
int yp[4];
pi.pain.line(x + dim_.width(), y - a + 1,
pi.pain.line(x + dim.width(), y - a + 1,
x + w + 4, y - a + 1, Color::math);
xp[0] = x + w + 4; yp[0] = y - a + 1;
xp[1] = x + w; yp[1] = y + d;

View File

@ -240,23 +240,26 @@ int InsetMathScript::dy1() const
}
int InsetMathScript::dx0() const
int InsetMathScript::dx0(BufferView const & bv) const
{
BOOST_ASSERT(hasDown());
return hasLimits() ? (dim_.wid - down().width()) / 2 : nwid();
Dimension const dim = dimension(bv);
return hasLimits() ? (dim.wid - down().width()) / 2 : nwid();
}
int InsetMathScript::dx1() const
int InsetMathScript::dx1(BufferView const & bv) const
{
BOOST_ASSERT(hasUp());
return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid() + nker();
Dimension const dim = dimension(bv);
return hasLimits() ? (dim.wid - up().width()) / 2 : nwid() + nker();
}
int InsetMathScript::dxx() const
int InsetMathScript::dxx(BufferView const & bv) const
{
return hasLimits() ? (dim_.wid - nwid()) / 2 : 0;
Dimension const dim = dimension(bv);
return hasLimits() ? (dim.wid - nwid()) / 2 : 0;
}
@ -323,24 +326,25 @@ void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
} else
dim.des = nd;
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathScript::draw(PainterInfo & pi, int x, int y) const
{
if (nuc().size())
nuc().draw(pi, x + dxx(), y);
nuc().draw(pi, x + dxx(*pi.base.bv), y);
else {
nuc().setXY(*pi.base.bv, x + dxx(), y);
nuc().setXY(*pi.base.bv, x + dxx(*pi.base.bv), y);
if (editing(pi.base.bv))
pi.draw(x + dxx(), y, char_type('.'));
pi.draw(x + dxx(*pi.base.bv), y, char_type('.'));
}
ScriptChanger dummy(pi.base);
if (hasUp())
up().draw(pi, x + dx1(), y - dy1());
up().draw(pi, x + dx1(*pi.base.bv), y - dy1());
if (hasDown())
down().draw(pi, x + dx0(), y + dy0());
down().draw(pi, x + dx0(*pi.base.bv), y + dy0());
drawMarkers(pi, x, y);
}
@ -358,11 +362,11 @@ void InsetMathScript::metricsT(TextMetricsInfo const & mi, Dimension & dim) cons
void InsetMathScript::drawT(TextPainter & pain, int x, int y) const
{
if (nuc().size())
nuc().drawT(pain, x + dxx(), y);
nuc().drawT(pain, x + 1, y);
if (hasUp())
up().drawT(pain, x + dx1(), y - dy1());
up().drawT(pain, x + 1, y - dy1());
if (hasDown())
down().drawT(pain, x + dx0(), y + dy0());
down().drawT(pain, x + 1, y + dy0());
}

View File

@ -107,7 +107,7 @@ protected:
private:
virtual Inset * clone() const;
/// returns x offset for main part
int dxx() const;
int dxx(BufferView const & bv) const;
/// returns width of nucleus if any
int nwid() const;
/// returns y offset for either superscript or subscript
@ -117,9 +117,9 @@ private:
/// returns y offset for subscript
int dy1() const;
/// returns x offset for superscript
int dx0() const;
int dx0(BufferView const & bv) const;
/// returns x offset for subscript
int dx1() const;
int dx1(BufferView const & bv) const;
/// returns ascent of nucleus if any
int nasc() const;
/// returns descent of nucleus if any

View File

@ -37,7 +37,8 @@ void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
StyleChanger dummy(mi.base, style_);
cell(0).metrics(mi, dim);
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}

View File

@ -38,19 +38,21 @@ void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
dim.des += 2;
dim.wid += 12;
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
{
cell(0).draw(pi, x + 10, y);
int const a = dim_.ascent();
int const d = dim_.descent();
Dimension const dim = dimension(*pi.base.bv);
int const a = dim.ascent();
int const d = dim.descent();
int xp[3];
int yp[3];
pi.pain.line(x + dim_.width(), y - a + 1,
x + 8, y - a + 1, Color::math);
pi.pain.line(x + dim.width(), y - a + 1,
x + 8, y - a + 1, Color::math);
xp[0] = x + 8; yp[0] = y - a + 1;
xp[1] = x + 5; yp[1] = y + d - 1;
xp[2] = x; yp[2] = y + (d - a)/2;

View File

@ -36,13 +36,15 @@ void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = cell(1).ascent() + cell(0).height() + 4;
dim.des = cell(1).descent();
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathStackrel::draw(PainterInfo & pi, int x, int y) const
{
int m = x + dim_.width() / 2;
Dimension const dim = dimension(*pi.base.bv);
int m = x + dim.width() / 2;
int yo = y - cell(1).ascent() - cell(0).descent() - 1;
cell(1).draw(pi, m - cell(1).width() / 2, y);
FracChanger dummy(pi.base);

View File

@ -48,7 +48,6 @@ void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
} else {
InsetMathGrid::metrics(mi, dim);
}
dim_ = dim;
}

View File

@ -84,8 +84,7 @@ void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
scriptable_ = true;
// Cache the inset dimension.
// FIXME: put the resulting dim in BufferView.
dim_ = dim;
setDimCache(mi, dim);
}

View File

@ -35,8 +35,6 @@ public:
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const { return dim_; }
///
void draw(PainterInfo &, int x, int y) const;
///
int kerning() const { return kerning_; }
@ -83,8 +81,6 @@ private:
mutable int kerning_;
///
mutable bool scriptable_;
/// FIXME: move this out to BufferView
mutable Dimension dim_;
};
} // namespace lyx

View File

@ -42,17 +42,19 @@ void InsetMathTFrac::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = std::max(cell(0).width(), cell(1).width()) + 2;
dim.asc = cell(0).height() + 2 + 5;
dim.des = cell(1).height() + 2 - 5;
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathTFrac::draw(PainterInfo & pi, int x, int y) const
{
StyleChanger dummy(pi.base, LM_ST_SCRIPT);
int m = x + dim_.wid / 2;
Dimension const dim = dimension(*pi.base.bv);
int m = x + dim.wid / 2;
cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5);
pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, Color::math);
pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, Color::math);
setPosCache(pi, x, y);
}

View File

@ -51,7 +51,14 @@ void InsetMathTabular::metrics(MetricsInfo & mi, Dimension & dim) const
FontSetChanger dummy(mi.base, "textnormal");
InsetMathGrid::metrics(mi, dim);
dim.wid += 6;
dim_ = dim;
}
Dimension const InsetMathTabular::dimension(BufferView const & bv) const
{
Dimension dim = InsetMathGrid::dimension(bv);
dim.wid += 6;
return dim;
}

View File

@ -31,6 +31,8 @@ public:
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
InsetMathTabular * asTabularInset() { return this; }

View File

@ -35,13 +35,15 @@ void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = cell(1).ascent();
dim.des = cell(1).descent() + cell(0).height() + 4;
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
void InsetMathUnderset::draw(PainterInfo & pi, int x, int y) const
{
int m = x + dim_.wid / 2;
Dimension const dim = dimension(*pi.base.bv);
int m = x + dim.wid / 2;
int yo = y + cell(1).descent() + cell(0).ascent() + 1;
cell(1).draw(pi, m - cell(1).width() / 2, y);
FracChanger dummy(pi.base);

View File

@ -42,7 +42,8 @@ void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
dim.asc = cell(0).height() + 10;
dim.des = cell(1).height();
metricsMarkers(dim);
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -51,7 +52,8 @@ void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
ScriptChanger dummy(pi.base);
cell(0).draw(pi, x + 5, y - 10);
cell(1).draw(pi, x + 5, y + cell(1).height());
mathed_draw_deco(pi, x + 1, y - 7, dim_.wid - 2, 5, name_);
Dimension const dim = dimension(*pi.base.bv);
mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
drawMarkers(pi, x, y);
}

View File

@ -48,7 +48,6 @@ void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const
if (mi.base.style == LM_ST_DISPLAY)
mi.base.style = LM_ST_TEXT;
InsetMathGrid::metrics(mi, dim);
dim_ = dim;
}

View File

@ -142,7 +142,8 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
editing_ = false;
}
}
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -164,7 +165,8 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
} else if (editing_) {
Font font = pi.base.font;
augmentFont(font, from_ascii("lyxtex"));
int h = y - dim_.ascent() + 2 + tmpl_.ascent();
Dimension const dim = dimension(*pi.base.bv);
int h = y - dim.ascent() + 2 + tmpl_.ascent();
pi.pain.text(x + 3, h, name(), font);
int const w = mathed_string_width(font, name());
tmpl_.draw(pi, x + w + 12, h);

View File

@ -126,7 +126,8 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
if (lockMacro)
MacroTable::globalMacros().get(name_).unlock();
dim_ = dim;
// Cache the inset dimension.
setDimCache(mi, dim);
}
@ -138,6 +139,8 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
setPosCache(p, x, y);
Dimension const dim = dimension(*p.base.bv);
// label
Font font = p.base.font;
font.setColor(Color::math);
@ -146,9 +149,9 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
pi.base.style = LM_ST_TEXT;
pi.base.font = font;
int const a = y - dim_.asc + 1;
int const w = dim_.wid - 2;
int const h = dim_.height() - 2;
int const a = y - dim.asc + 1;
int const w = dim.wid - 2;
int const h = dim.height() - 2;
// Color::mathbg used to be "AntiqueWhite" but is "linen" now, too
// the next line would overwrite the selection!
@ -169,11 +172,11 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
int const w0 = cell(0).width();
int const w1 = cell(1).width();
cell(0).draw(pi, x + 2, y + 1);
pi.pain.rectangle(x, y - dim_.ascent() + 3,
w0 + 4, dim_.height() - 6, Color::mathline);
pi.pain.rectangle(x, y - dim.ascent() + 3,
w0 + 4, dim.height() - 6, Color::mathline);
cell(1).draw(pi, x + 8 + w0, y + 1);
pi.pain.rectangle(x + w0 + 6, y - dim_.ascent() + 3,
w1 + 4, dim_.height() - 6, Color::mathline);
pi.pain.rectangle(x + w0 + 6, y - dim.ascent() + 3,
w1 + 4, dim.height() - 6, Color::mathline);
if (lockMacro)
MacroTable::globalMacros().get(name_).unlock();