#include "buffer_funcs.h"
#include "bufferlist.h"
#include "bufferparams.h"
+#include "coordcache.h"
#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
// and the scrollbar
updateScrollbar();
}
+
+ // remove old position cache
+ theCoords.clear();
+
+ // The real, big redraw.
screen().redraw(*bv_);
+
bv_->owner()->view_state_changed();
}
bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
{
- //lyxerr << "BufferView::Pimpl::workAreaDispatch: request: "
- // << cmd << std::endl;
+ lyxerr << "BufferView::Pimpl::workAreaDispatch: request: "
+ << cmd0 << std::endl;
// this is only called for mouse related events including
// LFUN_FILE_OPEN generated by drag-and-drop.
FuncRequest cmd = cmd0;
+2004-08-14 André Pönitz <poenitz@gmx.net>
+
+ * coordcache.[Ch]:
+ * Makefile.am: new files to accomodate an 'external' (x,y)-position
+ cache for all insets in (at least partially) visible (top-level)
+ paragraphs.
+
+ * BufferView_pimpl.C: reset external coord cache before every update.
+ This means the coord cache only contains valid entries.
+
2004-08-14 Lars Gullik Bjonnes <larsbj@lyx.org>
bug 1096
converter.h \
counters.C \
counters.h \
+ coordcache.C \
+ coordcache.h \
cursor.C \
cursor.h \
cursor_slice.C \
FL_Coord, FL_Coord,
int key, void * xev)
{
+ if (event != 11)
+ lyxerr[Debug::WORKAREA] << "Workarea event: EVENT: " << event << endl;
+
XEvent * ev = static_cast<XEvent*>(xev);
XWorkArea * area = static_cast<XWorkArea*>(ob->u_vdata);
break;
case FL_DRAG: {
+ lyxerr[Debug::WORKAREA] << "Workarea event: DRAG 0" << endl;
+
if (!ev || !area->scrollbar)
break;
+
+2004-08-14 André Pönitz <poenitz@gmx.net>
+
+ * inset.[Ch]:
+ * insetbase.[Ch]: remove the 'internale' xo, yo position cache
+
2004-08-13 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* insetoptarg.C (latexOptional): if the optional argument contains
#include "lyxtext.h"
#include "LColor.h"
#include "metricsinfo.h"
+#include "coordcache.h"
using std::string;
InsetOld::InsetOld()
- : InsetBase(),
- xo_(0), yo_(0), scx(0),
+ : scx(0),
//background_color_(LColor::inherit)
background_color_(LColor::background)
{}
InsetOld::InsetOld(InsetOld const & in)
- : InsetBase(),
- xo_(0), yo_(0), scx(0), name_(in.name_),
+ : InsetBase(in), scx(0), name_(in.name_),
background_color_(in.background_color_)
{}
void InsetOld::setPosCache(PainterInfo const & pi, int x, int y) const
{
//lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl;
- xo_ = x;
- yo_ = y + pi.base.bv->top_y();
+ theCoords.insets_.add(this, x, y + pi.base.bv->top_y());
}
LColor_color backgroundColor() const;
/// set x/y drawing position cache
void setPosCache(PainterInfo const &, int, int) const;
- ///
- int xo() const { return xo_; }
- ///
- int yo() const { return yo_; }
/// returns the actual scroll-value
virtual int scroll(bool recursive = true) const;
///
bool forceDefaultParagraphs(InsetBase const * inset) const;
protected:
- ///
- mutable int xo_;
- ///
- mutable int yo_;
///
mutable int scx;
///
#include "insetbase.h"
#include "buffer.h"
+#include "coordcache.h"
#include "BufferView.h"
#include "LColor.h"
#include "cursor.h"
}
+int InsetBase::xo() const
+{
+ return theCoords.insets_.x(this);
+}
+
+
+int InsetBase::yo() const
+{
+ return theCoords.insets_.y(this);
+}
+
+
bool InsetBase::covers(int x, int y) const
{
//lyxerr << "InsetBase::covers, x: " << x << " y: " << y
// << " x1: " << xo() << " x2: " << xo() + width()
// << " y1: " << yo() - ascent() << " y2: " << yo() + descent()
// << std::endl;
- return x >= xo()
+ return theCoords.insets_.has(this)
+ && x >= xo()
&& x <= xo() + width()
&& y >= yo() - ascent()
&& y <= yo() + descent();
/// add space for markers
void metricsMarkers2(Dimension & dim, int framesize = 1) const;
/// last drawn position for 'important' insets
- virtual int xo() const { return 0; }
+ int xo() const;
/// last drawn position for 'important' insets
- virtual int yo() const { return 0; }
+ int yo() const;
/// set x/y drawing position cache if available
virtual void setPosCache(PainterInfo const &, int, int) const {}
/// do we cover screen position x/y?
cell = tabular.getNumberOfCells() - 1;
}
cur.selection() = false;
- resetPos(cur);
- cur.bv().fitCursor();
+ // this accesses the position cache before it is initialized
+ //resetPos(cur);
+ //cur.bv().fitCursor();
cur.push(*this);
cur.idx() = cell;
}
cur.selection() = false;
cur.push(const_cast<InsetTabular&>(*this));
return setPos(cur, x, y);
- //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
+ //int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(actcell);
}
for (; c < cell; ++c)
lx += tabular.getWidthOfColumn(c);
- return lx - tabular.getWidthOfColumn(cell) + xo_;
+ return lx - tabular.getWidthOfColumn(cell) + xo();
}
scroll(bv, - tabular.getWidthOfColumn(actcell) - 20);
} else if (cursorx_ - offset < 20) {
scroll(bv, 20 - cursorx_ + offset);
- } else if (scroll() && xo_ > 20 &&
- xo_ + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
+ } else if (scroll() && xo() > 20 &&
+ xo() + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
scroll(bv, old_x - cursorx_);
}
#include "updatableinset.h"
#include "BufferView.h"
+#include "coordcache.h"
#include "cursor.h"
#include "debug.h"
#include "dispatchresult.h"
}
int const workW = bv.workWidth();
+ int xo_ = theCoords.insets_.x(this);
int const tmp_xo_ = xo_ - scx;
if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
void UpdatableInset::scroll(BufferView & bv, int offset) const
{
+ int const xo_ = theCoords.insets_.x(this);
if (offset > 0) {
if (!scx && xo_ >= 20)
return;
}
if (view()->available()) {
- if (view()->fitCursor() || update)
+ // Redraw screen unless explicitly told otherwise.
+ // This also initializes the position cache for all insets
+ // in (at least partially) visible top-level paragraphs.
+ if (update)
+ view()->update();
+
+ // fitCursor() needs valid inset position. The previous call to
+ // update() makes sure we have such even for freshly created
+ // insets.
+ if (view()->fitCursor())
view()->update();
// if we executed a mutating lfun, mark the buffer as dirty
if (getStatus(cmd).enabled()
#include "math_support.h"
#include "math_replace.h"
+#include "coordcache.h"
#include "LColor.h"
#include "BufferView.h"
#include "buffer.h"
MathArray::MathArray()
- : xo_(0), yo_(0)
{}
MathArray::MathArray(const_iterator from, const_iterator to)
- : base_type(from, to), xo_(0), yo_(0)
+ : base_type(from, to)
{}
void MathArray::draw(PainterInfo & pi, int x, int y) const
{
//lyxerr << "MathArray::draw: x: " << x << " y: " << y << endl;
- xo_ = x;
- yo_ = y;
+ setXY(x, y);
if (empty()) {
pi.pain.rectangle(x, y - ascent(), width(), height(), LColor::mathline);
void MathArray::drawT(TextPainter & pain, int x, int y) const
{
//lyxerr << "x: " << x << " y: " << y << ' ' << pain.workAreaHeight() << endl;
- xo_ = x;
- yo_ = y;
+ setXY(x, y);
for (const_iterator it = begin(), et = end(); it != et; ++it) {
(*it)->drawT(pain, x, y);
int xx = 0;
int yy = 0;
+ const int xo_ = xo();
+ const int yo_ = yo();
+
if (x < xo_)
xx = xo_ - x;
else if (x > xo_ + width())
void MathArray::setXY(int x, int y) const
{
- xo_ = x;
- yo_ = y;
+ lyxerr << "setting position cache for MathArray " << this << std::endl;
+ theCoords.arrays_.add(this, x, y);
+}
+
+
+int MathArray::xo() const
+{
+ return theCoords.arrays_.x(this);
}
+
+
+int MathArray::yo() const
+{
+ return theCoords.arrays_.y(this);
+}
+
void touch() const;
/// access to cached x coordinate of last drawing
- int xo() const { return xo_; }
+ int xo() const;
/// access to cached y coordinate of last drawing
- int yo() const { return yo_; }
+ int yo() const;
/// access to cached x coordinate of mid point of last drawing
- int xm() const { return xo_ + dim_.wid / 2; }
+ int xm() const { return xo() + dim_.wid / 2; }
/// access to cached y coordinate of mid point of last drawing
- int ym() const { return yo_ + (dim_.des - dim_.asc) / 2; }
+ int ym() const { return yo() + (dim_.des - dim_.asc) / 2; }
/// write access to coordinate;
void setXY(int x, int y) const;
/// returns x coordinate of given position in the array
/// cached dimensions of cell
mutable Dimension dim_;
- /// cached x coordinate of last drawing
- mutable int xo_;
- /// cached y coordinate of last drawing
- mutable int yo_;
};
///
#include "math_mathmlstream.h"
#include "math_streamstr.h"
+#include "debug.h"
+
#include "support/std_ostream.h"
using std::auto_ptr;
MathDecorationInset::MathDecorationInset(latexkeys const * key)
: MathNestInset(1), key_(key)
-{}
+{
+ lyxerr << " creating deco " << key->name << std::endl;
+}
auto_ptr<InsetBase> MathDecorationInset::clone() const
#include <config.h>
#include "math_diminset.h"
+#include "coordcache.h"
#include "debug.h"
MathDimInset::MathDimInset()
- : xo_(-3), yo_(-3) // some sentinel value for debugging
{}
void MathDimInset::setPosCache(PainterInfo const &, int x, int y) const
{
//lyxerr << "MathDimInset: cache to " << x << " " << y << std::endl;
- xo_ = x;
- yo_ = y;
+ theCoords.insets_.add(this, x, y);
}
///
int width() const;
- ///
- int xo() const { return xo_; }
- ///
- int yo() const { return yo_; }
///
void setPosCache(PainterInfo const & pi, int x, int y) const;
protected:
///
mutable Dimension dim_;
- ///
- mutable int xo_;
- ///
- mutable int yo_;
};
#endif
return MathAtom(new MathKernInset);
if (s == "xrightarrow" || s == "xleftarrow")
return MathAtom(new MathXArrowInset(s));
- if (s == "split" || s == "gathered" || s == "aligned")
+ if (s == "split" || s == "gathered" || s == "aligned" || s == "alignedat")
return MathAtom(new MathSplitInset(s));
if (s == "cases")
return MathAtom(new MathCasesInset);
}
-void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
+void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
{
+ // FIXME: hack to get position cache warm
+ draw(pi, x, y);
+
// this should use the x/y values given, not the cached values
LCursor & cur = pi.base.bv->cursor();
if (!cur.selection())
}
else if (name == "split" || name == "cases" ||
- name == "gathered" || name == "aligned") {
+ name == "gathered" || name == "aligned" ||
+ name == "alignedat") {
cell->push_back(createMathInset(name));
parse2(cell->back(), FLAG_END, mode, false);
}
return 'c';
if (name_ == "aligned")
return (col & 1) ? 'l' : 'r';
+ if (name_ == "alignedat")
+ return (col & 1) ? 'l' : 'r';
return 'l';
}
#include "rowpainter.h"
#include "buffer.h"
+#include "coordcache.h"
#include "cursor.h"
#include "debug.h"
#include "bufferparams.h"
BOOST_ASSERT(inset);
PainterInfo pi(const_cast<BufferView *>(&bv_), pain_);
pi.base.font = getFont(pos);
+ theCoords.insets_.add(inset, int(x_), yo_ + row_.baseline());
inset->drawSelection(pi, int(x_), yo_ + row_.baseline());
inset->draw(pi, int(x_), yo_ + row_.baseline());
x_ += inset->width();
}
+// Manhattan distance to nearest corner
int LyXText::dist(int x, int y) const
{
int xx = 0;
#include "bufferparams.h"
#include "BufferView.h"
#include "cursor.h"
+#include "coordcache.h"
#include "CutAndPaste.h"
#include "debug.h"
#include "dispatchresult.h"
for (; iit != iend; ++iit) {
InsetBase * inset = iit->inset;
#if 1
- lyxerr << "examining inset " << inset
- << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
- << " yo: " << inset->yo() - inset->ascent() << "..."
- << inset->yo() + inset->descent() << endl;
+ lyxerr << "examining inset " << inset << endl;
+ if (theCoords.insets_.has(inset))
+ lyxerr
+ << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
+ << " yo: " << inset->yo() - inset->ascent() << "..."
+ << inset->yo() + inset->descent() << endl;
+ else
+ lyxerr << " inset has no cached position";
#endif
if (inset->covers(x, y)) {
lyxerr << "Hit inset: " << inset << endl;