* notifyCursorEnters called on insets when the cursor entered

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27465 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-11-15 17:11:01 +00:00
parent 7f53badf44
commit 481aff5aff
5 changed files with 35 additions and 19 deletions

View File

@ -627,7 +627,14 @@ void BufferView::setCursorFromScrollbar()
Cursor cur(*this);
cur.reset(buffer_.inset());
tm.setCursorFromCoordinates(cur, 0, newy);
// update the bufferview cursor and notify insets
// FIXME: Care about the d->cursor_ flags to redraw if needed
Cursor old = d->cursor_;
mouseSetCursor(cur);
bool badcursor = notifyCursorLeavesOrEnters(old, d->cursor_);
if (badcursor)
d->cursor_.fixIfBroken();
}
@ -1635,7 +1642,7 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
// Notify left insets
if (cur != old) {
old.fixIfBroken();
bool badcursor = notifyCursorLeaves(old, cur);
bool badcursor = notifyCursorLeavesOrEnters(old, cur);
if (badcursor)
cursor().fixIfBroken();
}
@ -1854,14 +1861,9 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
cap::saveSelection(cursor());
// Has the cursor just left the inset?
bool badcursor = false;
bool leftinset = (&d->cursor_.inset() != &cur.inset());
if (leftinset) {
if (leftinset)
d->cursor_.fixIfBroken();
badcursor = notifyCursorLeaves(d->cursor_, cur);
if (badcursor)
cur.fixIfBroken();
}
// FIXME: shift-mouse selection doesn't work well across insets.
bool do_selection = select && &d->cursor_.anchor().inset() == &cur.inset();
@ -1871,7 +1873,7 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
// FIXME: (2) if we had a working InsetText::notifyCursorLeaves,
// the leftinset bool would not be necessary (badcursor instead).
bool update = leftinset;
if (!do_selection && !badcursor && d->cursor_.inTexted())
if (!do_selection && d->cursor_.inTexted())
update |= checkDepm(cur, d->cursor_);
d->cursor_.setCursor(cur);

View File

@ -2026,7 +2026,7 @@ bool Cursor::fixIfBroken()
}
bool notifyCursorLeaves(Cursor const & old, Cursor & cur)
bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur)
{
// find inset in common
size_type i;
@ -2041,15 +2041,21 @@ bool notifyCursorLeaves(Cursor const & old, Cursor & cur)
&& cur.inTexted() && old.inTexted()
&& cur.pit() != old.pit()) {
old.paragraph().updateWords(old.top());
return false;
}
// notify everything on top of the common part in old cursor,
// but stop if the inset claims the cursor to be invalid now
for (; i < old.depth(); ++i) {
for (size_type j = i; j < old.depth(); ++j) {
Cursor insetPos = old;
insetPos.cutOff(i);
if (old[i].inset().notifyCursorLeaves(insetPos, cur))
insetPos.cutOff(j);
if (old[j].inset().notifyCursorLeaves(insetPos, cur))
return true;
}
// notify everything on top of the common part in new cursor,
// but stop if the inset claims the cursor to be invalid now
for (; i < cur.depth(); ++i) {
if (cur[i].inset().notifyCursorEnters(cur))
return true;
}

View File

@ -430,11 +430,12 @@ public:
/**
* Notifies all insets which appear in old, but not in cur. Make
* Sure that the cursor old is valid, i.e. all inset pointers
* Notifies all insets which appear in old, but not in cur. And then
* notify all insets which appear in cur, but not in old.
* Make sure that the cursor old is valid, i.e. all inset pointers
* point to valid insets! Use Cursor::fixIfBroken if necessary.
*/
bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur);
} // namespace lyx

View File

@ -1628,7 +1628,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// notify insets we just left
if (view()->cursor() != old) {
old.fixIfBroken();
bool badcursor = notifyCursorLeaves(old, view()->cursor());
bool badcursor = notifyCursorLeavesOrEnters(old, view()->cursor());
if (badcursor)
view()->cursor().fixIfBroken();
}

View File

@ -261,10 +261,17 @@ public:
/// Returns true if cursor is now invalid, e.g. if former
/// insets in higher cursor slices of \c old do not exist
/// anymore.
/// \c old is the old cursor, i.e. there is a slice pointing to this.
/// \c old is the old cursor, the last slice points to this.
/// \c cur is the new cursor. Use the update flags to cause a redraw.
virtual bool notifyCursorLeaves(Cursor const & /*old*/, Cursor & /*cur*/)
{ return false; }
/// Is called when the cursor enters this inset.
/// Returns true if cursor is now invalid, e.g. if former
/// insets in higher cursor slices of \c old do not exist
/// anymore.
/// \c cur is the new cursor, some slice points to this. Use the update flags to cause a redraw.
virtual bool notifyCursorEnters(Cursor & /*cur*/)
{ return false; }
/// is called when the mouse enter or leave this inset
/// return true if this inset needs repaint
virtual bool setMouseHover(bool) { return false; }