On Wed, Apr 07, 2004 at 01:38:45PM +0100, Angus Leeming wrote:
> > No, notifyCursorLeaves should be the place. However, I am pretty
> > sure this is almost never called when necessary. So every place
> > modifying the 'real' cursor (there aren't too many of them, the
> > MOUSE lfuns and Cursor/BuffferView::dispatch come to mind) needs to
> > make sure it is called.
> 
> You mean that Cursor::dispatch should read:
> 
> DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
> {
>         ...
>         for ( ; size(); pop()) {
>                 ...
>                 inset().dispatch(*this, cmd);
>                 if (disp_.dispatched()) {
> +                       inset().notifyCursorLeaves();
>                         break;
>                 }
>         }
>         ...
> }

No. notifyCursorLeaves  should be called for all insets in the part of
the slice stack that's out-of-date.

> Assuming that this should really go in MathNestInset::priv_dispatch, 
> should it become:
> 
>         case LFUN_FINISHED_LEFT:
>                 cur.bv().cursor() = cur;
> +               notifyCursorLeaves();
>                 break;
> 
>         case LFUN_FINISHED_RIGHT:
>                 ++cur.pos();
>                 cur.bv().cursor() = cur;
> +               notifyCursorLeaves();
>                 break;
> 
>         case LFUN_FINISHED_UP:
>                 //idxUpDown(cur, true);
>                 cur.bv().cursor() = cur;
> +               notifyCursorLeaves();
>                 break;
> 
>         case LFUN_FINISHED_DOWN:
>                 //idxUpDown(cur, false);
>                 cur.bv().cursor() = cur;
> +               notifyCursorLeaves();
>                 break;
> 
> I think that that handles movement of the cursor out of the math 
> inset using the keyboard.

This would be the long winded solution.

> How would I go about telling an inset that the cursor has left it 
> because the user pressed the mouse somewhere else in the document?  
> Something like:
> 
> void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
> {
>         ...
>         // Single-click on work area
>         case LFUN_MOUSE_PRESS: {
>                 ...
>                 // Set cursor here.
> +               LCursor tmpcur = bv->cursor();
> +               bool const was_in_mathed = tmpcur.inMathed();
>                 bv->cursor() = cur;
> +               if (was_in_mathed && !bv->cursor().inMathed())
> +                       tmpcur.inset().notifyCursorLeaves();
> 
> ???????
> 
> 
> > Of course, some automatic solution would be nice.... Hm, maybe we
> > can save the cursor in update() and check next time we come round
> > whether the cursor is different. This would yield slightly
> > asynchronous behaviour but should be sufficient for the previews and
> > the cleaning up of empty sub/suprscripts for which it is used now.
> 
> You'll have to explain more. I'm totally ignorant, remember.

BufferView::update is called regularly whenever something interesting
happens. If we store a static copy of the cursor there and compare this
copy to the actual cursor in the next round, we can tell out of which
insets the cursor has moved in the meantime. These could be notified.
[One probably has to make sure that the insets still exist, though..]

The other way is to check for the need of a notification whenever the
real cursor is actually modified, i.e. in the LFUN_FINISHED_* handler.
This should be the more tedious, but also the safer way.

> Incidentally, have you considered writing a little paper explaining 
> how this all works?

Incidentally, no, as I have far too many 'little papers' waiting for
completion...

> Would be really useful to the rest of us. 
> (Meaning me...)

Andre'

Reply via email to