예제 #1
0
        void IEventPortal.PortalMouseMove(UIMouseEventArgs e)
        {
            HitChain hitPointChain = GetFreeHitChain();

#if DEBUG
            _dbugHitChainPhase = dbugHitChainPhase.MouseMove;
#endif
            HitTestCoreWithPrevChainHint(hitPointChain, _previousChain, e.X, e.Y);
            _previousChain.ClearAll();
            SetEventOrigin(e, hitPointChain);
            //-------------------------------------------------------
            ForEachOnlyEventPortalBubbleUp(e, hitPointChain, (portal) =>
            {
                portal.PortalMouseMove(e);
                return(true);
            });
            //-------------------------------------------------------
            if (!e.CancelBubbling)
            {
                bool foundSomeHit = false;
                ForEachEventListenerBubbleUp(e, hitPointChain, (listener) =>
                {
                    foundSomeHit           = true;
                    bool isFirstMouseEnter = false;
                    if (e.CurrentMouseActive != null &&
                        e.CurrentMouseActive != listener)
                    {
                        e.CurrentMouseActive.ListenMouseLeave(e);
                        isFirstMouseEnter = true;
                    }

                    if (!e.IsCanceled)
                    {
                        e.CurrentMouseActive = listener;
                        e.IsFirstMouseEnter  = isFirstMouseEnter;
                        e.CurrentMouseActive.ListenMouseMove(e);
                        e.IsFirstMouseEnter = false;
                    }

                    return(true);//stop
                });
                if (!foundSomeHit && e.CurrentMouseActive != null)
                {
                    e.CurrentMouseActive.ListenMouseLeave(e);
                    if (!e.IsCanceled)
                    {
                        e.CurrentMouseActive = null;
                    }
                }
            }
            SwapHitChain(hitPointChain);
            e.StopPropagation();
        }
        void IEventPortal.PortalMouseUp(UIMouseUpEventArgs e)
        {
#if DEBUG
            if (this.dbugRootGraphics != null && this.dbugRootGraphics.dbugEnableGraphicInvalidateTrace)
            {
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("================");
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("MOUSEUP");
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("================");
            }
#endif

            HitChain hitPointChain = GetFreeHitChain();
#if DEBUG
            _dbugHitChainPhase = dbugHitChainPhase.MouseUp;
#endif

            _mousePressMonitor.Reset();
            HitTestCoreWithPrevChainHint(hitPointChain, _previousChain, e.X, e.Y);

            if (hitPointChain.Count > 0)
            {
                SetEventOrigin(e, hitPointChain);
                //---------------------------------------------------------------
                ForEachOnlyEventPortalBubbleUp(e, hitPointChain, (e1, portal) =>
                {
                    //please ensure=> no local var/pararmeter capture inside lambda
                    portal.PortalMouseUp(e1);
                    return(true);
                });
                //---------------------------------------------------------------
                if (!e.CancelBubbling)
                {
                    ForEachEventListenerBubbleUp(e, hitPointChain, (e1, listener) =>
                    {
                        //please ensure=> no local var/pararmeter capture inside lambda
                        if (listener.BypassAllMouseEvents)
                        {
                            return(false);
                        }
                        listener.ListenMouseUp(e1);

                        //return true to stop this loop (no further bubble up)
                        //return false to bubble this to upper control
                        //click or double click
                        if (e1.CurrentContextElement == _currentMouseDown)
                        {
                            if (e.IsAlsoDoubleClick)
                            {
                                listener.ListenMouseDoubleClick(e);
                            }
                            else
                            {
                                listener.ListenMouseClick(e);
                            }
                        }

                        return(e1.CancelBubbling || !listener.BypassAllMouseEvents);
                    });
                }
            }
            SwapHitChain(hitPointChain);
            e.StopPropagation();
        }
        void IEventPortal.PortalMouseMove(UIMouseMoveEventArgs e)
        {
            HitChain hitPointChain = GetFreeHitChain();

#if DEBUG
            _dbugHitChainPhase = dbugHitChainPhase.MouseMove;
#endif
            HitTestCoreWithPrevChainHint(hitPointChain, _previousChain, e.X, e.Y);
            _previousChain.Reset();
            SetEventOrigin(e, hitPointChain);
            //-------------------------------------------------------
            ForEachOnlyEventPortalBubbleUp(e, hitPointChain, (e1, portal) =>
            {
                //please ensure=> no local var/pararmeter capture inside lambda
                portal.PortalMouseMove(e1);
                return(true);
            });
            //-------------------------------------------------------
            if (!e.CancelBubbling)
            {
                _mouseMoveFoundSomeHit         = false;
                _mouseMoveFoundLastMouseActive = false;
                ForEachEventListenerBubbleUp(e, hitPointChain, (e1, listener) =>
                {
                    //please ensure=> no local var/pararmeter capture inside lambda
                    _mouseMoveFoundSomeHit = true;

#if DEBUG
                    if (_dbugEnableDebugMark && e.Ctrl && e1.X <= 10 && e1.Y <= 10)
                    {
                        //show dbug info
                        listener.dbugDevWriteInfo();
                    }
#endif



                    bool _bubble = true; //temp fix
                    if (_latestMouseActive != listener && !_mouseMoveFoundLastMouseActive)
                    {
                        //----------
                        e1.CancelBubbling = _bubble; //temp fix
                        listener.ListenMouseEnter(e1);
                        _bubble = e1.CancelBubbling;
                        //----------

                        if (_latestMouseActive != null)
                        {
                            _mouseLeaveEventArgs.SetCurrentContextElement(_latestMouseActive);
                            UIMouseLeaveEventArgs.SetDiff(_mouseLeaveEventArgs, e1.XDiff, e1.YDiff);
                            _latestMouseActive.ListenMouseLeave(_mouseLeaveEventArgs);
                        }

                        _latestMouseActive = listener;
                    }


                    if (!e1.IsCanceled)
                    {
                        //TODO: review here
                        e1.CancelBubbling = _bubble; //temp fix
                        listener.ListenMouseMove(e1);

                        if (!_mouseMoveFoundLastMouseActive)
                        {
                            _latestMouseActive = e1.CurrentContextElement;
                        }
                    }

                    if (!e1.CancelBubbling)
                    {
                        _mouseMoveFoundLastMouseActive = true;
                    }
                    return(e1.CancelBubbling);
                });

                if (!_mouseMoveFoundSomeHit)
                {
                    if (_latestMouseActive != null)
                    {
                        _mouseLeaveEventArgs.IsDragging = e.IsDragging;
                        UIMouseLeaveEventArgs.SetDiff(_mouseLeaveEventArgs, e.XDiff, e.YDiff);
                        _mouseLeaveEventArgs.SetCurrentContextElement(_latestMouseActive);

                        _latestMouseActive.ListenMouseLeave(_mouseLeaveEventArgs);
                        _latestMouseActive = null;
                    }
                }
            }
            SwapHitChain(hitPointChain);
            e.StopPropagation();
        }
        void IEventPortal.PortalMouseDown(UIMouseDownEventArgs e)
        {
#if DEBUG
            if (this.dbugRootGraphics != null && this.dbugRootGraphics.dbugEnableGraphicInvalidateTrace)
            {
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("================");
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("MOUSEDOWN");
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("================");
            }
            dbugMsgChainVersion = 1;
            int local_msgVersion = 1;
#endif
            HitChain hitPointChain = GetFreeHitChain();
#if DEBUG
            _dbugHitChainPhase = dbugHitChainPhase.MouseDown;
#endif
            HitTestCoreWithPrevChainHint(hitPointChain, _previousChain, e.X, e.Y);

            if (hitPointChain.Count > 0)
            {
                //------------------------------
                //1. origin object
                SetEventOrigin(e, hitPointChain);
                //------------------------------

                _currentMouseDown = null;
                //portal
                ForEachOnlyEventPortalBubbleUp(e, hitPointChain, (e1, portal) =>
                {
                    //please ensure=> no local var/pararmeter capture inside lambda
                    portal.PortalMouseDown(e1);
                    //*****
                    _currentMouseDown = e1.CurrentContextElement;
                    return(true);
                });
                //------------------------------
                //use events
                if (!e.CancelBubbling)
                {
                    _currentMouseDown = null; //clear
                    e.SetCurrentContextElement(null);

                    ForEachEventListenerBubbleUp(e, hitPointChain, (e1, listener) =>
                    {
                        //please ensure=> no local var/pararmeter capture inside lambda
                        if (listener.BypassAllMouseEvents)
                        {
                            return(false);
                        }
                        _currentMouseDown = listener;

                        listener.ListenMouseDown(e1);

                        //-------------------------------------------------------
                        //auto begin monitor mouse press
                        _mousePressMonitor.AddMousePressInformation(e1);
                        _mousePressMonitor.SetMonitoredElement(listener);
                        //-------------------------------------------------------
                        bool cancelMouseBubbling = e1.CancelBubbling;
                        if (_prevMouseDownElement != null &&
                            _prevMouseDownElement != listener)
                        {
                            _prevMouseDownElement.ListenLostMouseFocus(_mouseLostFocusArgs);
                            _prevMouseDownElement = null;//clear
                        }
                        //-------------------------------------------------------
                        //retrun true to stop this loop (no further bubble up)
                        //return false to bubble this to upper control
                        return(e1.CancelBubbling || !listener.BypassAllMouseEvents);
                    });

                    if (_currentMouseDown == null)
                    {
                        _mousePressMonitor.Reset();
                    }
                }

                if (_prevMouseDownElement != _currentMouseDown &&
                    _prevMouseDownElement != null)
                {
                    //TODO: review here, auto or manual
                    _prevMouseDownElement.ListenLostMouseFocus(_mouseLostFocusArgs);
                    _prevMouseDownElement = null;
                }
            }
            //---------------------------------------------------------------

#if DEBUG
            RootGraphic dbug_visualroot = this.dbugRootGraphics;
            if (dbug_visualroot != null && dbug_visualroot.dbug_RecordHitChain)
            {
                dbug_visualroot.dbug_rootHitChainMsg.Clear();
                HitInfo hitInfo;
                for (int tt = hitPointChain.Count - 1; tt >= 0; --tt)
                {
                    hitInfo = hitPointChain.GetHitInfo(tt);
                    RenderElement ve = hitInfo.HitElemAsRenderElement;
                    if (ve != null)
                    {
                        ve.dbug_WriteOwnerLayerInfo(dbug_visualroot, tt);
                        ve.dbug_WriteOwnerLineInfo(dbug_visualroot, tt);
                        string hit_info = new string('.', tt) + " [" + tt + "] "
                                          + "(" + hitInfo.point.X + "," + hitInfo.point.Y + ") "
                                          + ve.dbug_FullElementDescription();
                        dbug_visualroot.dbug_rootHitChainMsg.AddLast(new dbugLayoutMsg(ve, hit_info));
                    }
                }
            }
#endif

            SwapHitChain(hitPointChain);

            e.StopPropagation(); //TODO: review this again
#if DEBUG
            if (local_msgVersion != dbugMsgChainVersion)
            {
                return;
            }
            dbug_visualroot.dbugHitTracker.Write("stop-mousedown");
            dbug_visualroot.dbugHitTracker.Play = false;
#endif
        }
예제 #5
0
        void IEventPortal.PortalMouseUp(UIMouseEventArgs e)
        {
#if DEBUG
            if (this.dbugRootGraphics.dbugEnableGraphicInvalidateTrace)
            {
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("================");
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("MOUSEUP");
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("================");
            }
#endif

            HitChain hitPointChain = GetFreeHitChain();
#if DEBUG
            _dbugHitChainPhase = dbugHitChainPhase.MouseUp;
#endif
            HitTestCoreWithPrevChainHint(hitPointChain, _previousChain, e.X, e.Y);

            if (hitPointChain.Count > 0)
            {
                SetEventOrigin(e, hitPointChain);
                //---------------------------------------------------------------
                ForEachOnlyEventPortalBubbleUp(e, hitPointChain, (portal) =>
                {
                    portal.PortalMouseUp(e);
                    return(true);
                });
                //---------------------------------------------------------------
                if (!e.CancelBubbling)
                {
                    ForEachEventListenerBubbleUp(e, hitPointChain, (listener) =>
                    {
                        if (listener.BypassAllMouseEvents)
                        {
                            return(false);
                        }
                        listener.ListenMouseUp(e);
                        //retrun true to stop this loop (no further bubble up)
                        //return false to bubble this to upper control
                        return(e.CancelBubbling || !listener.BypassAllMouseEvents);
                    });
                }
                //---------------------------------------------------------------
                if (e.IsAlsoDoubleClick)
                {
                    ForEachEventListenerBubbleUp(e, hitPointChain, listener =>
                    {
                        listener.ListenMouseDoubleClick(e);
                        //-------------------------------------------------------
                        //retrun true to stop this loop (no further bubble up)
                        //return false to bubble this to upper control
                        return(e.CancelBubbling || !listener.BypassAllMouseEvents);
                    });
                }
                if (!e.CancelBubbling)
                {
                    if (e.IsAlsoDoubleClick)
                    {
                        //ForEachEventListenerBubbleUp(e, hitPointChain, listener =>
                        //{
                        //    listener.ListenMouseDoubleClick(e);
                        //    //-------------------------------------------------------
                        //    //retrun true to stop this loop (no further bubble up)
                        //    //return false to bubble this to upper control
                        //    return e.CancelBubbling || !listener.BypassAllMouseEvents;
                        //});
                    }
                    else
                    {
                        ForEachEventListenerBubbleUp(e, hitPointChain, listener =>
                        {
                            listener.ListenMouseClick(e);

                            //retrun true to stop this loop (no further bubble up)
                            //return false to bubble this to upper control
                            return(e.CancelBubbling || !listener.BypassAllMouseEvents);
                        });
                    }
                }
            }
            SwapHitChain(hitPointChain);
            e.StopPropagation();
        }
예제 #6
0
        void IEventPortal.PortalMouseDown(UIMouseEventArgs e)
        {
#if DEBUG
            if (this.dbugRootGraphics.dbugEnableGraphicInvalidateTrace)
            {
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("================");
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("MOUSEDOWN");
                this.dbugRootGraphics.dbugGraphicInvalidateTracer.WriteInfo("================");
            }
            dbugMsgChainVersion = 1;
            int local_msgVersion = 1;
#endif
            HitChain hitPointChain = GetFreeHitChain();
#if DEBUG
            _dbugHitChainPhase = dbugHitChainPhase.MouseDown;
#endif
            HitTestCoreWithPrevChainHint(hitPointChain, _previousChain, e.X, e.Y);
            if (hitPointChain.Count > 0)
            {
                //------------------------------
                //1. origin object
                SetEventOrigin(e, hitPointChain);
                //------------------------------
                var prevMouseDownElement          = e.PreviousMouseDown;
                IUIEventListener currentMouseDown = null;
                //portal
                ForEachOnlyEventPortalBubbleUp(e, hitPointChain, (portal) =>
                {
                    portal.PortalMouseDown(e);
                    //*****
                    currentMouseDown = e.CurrentContextElement;
                    return(true);
                });
                //------------------------------
                //use events
                if (!e.CancelBubbling)
                {
                    e.CurrentContextElement = currentMouseDown = null; //clear
                    ForEachEventListenerBubbleUp(e, hitPointChain, listener =>
                    {
                        if (listener.BypassAllMouseEvents)
                        {
                            return(false);
                        }


                        currentMouseDown = listener;
                        listener.ListenMouseDown(e);
                        //-------------------------------------------------------
                        bool cancelMouseBubbling = e.CancelBubbling;
                        if (prevMouseDownElement != null &&
                            prevMouseDownElement != listener)
                        {
                            prevMouseDownElement.ListenLostMouseFocus(e);
                            prevMouseDownElement = null;//clear
                        }
                        //-------------------------------------------------------
                        //retrun true to stop this loop (no further bubble up)
                        //return false to bubble this to upper control
                        return(e.CancelBubbling || !listener.BypassAllMouseEvents);
                    });
                }

                if (prevMouseDownElement != currentMouseDown &&
                    prevMouseDownElement != null)
                {
                    prevMouseDownElement.ListenLostMouseFocus(e);
                    prevMouseDownElement = null;
                }
            }
            //---------------------------------------------------------------

#if DEBUG
            RootGraphic visualroot = this.dbugRootGraphics;
            if (visualroot.dbug_RecordHitChain)
            {
                visualroot.dbug_rootHitChainMsg.Clear();
                HitInfo hitInfo;
                for (int tt = hitPointChain.Count - 1; tt >= 0; --tt)
                {
                    hitInfo = hitPointChain.GetHitInfo(tt);
                    RenderElement ve = hitInfo.HitElemAsRenderElement;
                    if (ve != null)
                    {
                        ve.dbug_WriteOwnerLayerInfo(visualroot, tt);
                        ve.dbug_WriteOwnerLineInfo(visualroot, tt);
                        string hit_info = new string('.', tt) + " [" + tt + "] "
                                          + "(" + hitInfo.point.X + "," + hitInfo.point.Y + ") "
                                          + ve.dbug_FullElementDescription();
                        visualroot.dbug_rootHitChainMsg.AddLast(new dbugLayoutMsg(ve, hit_info));
                    }
                }
            }
#endif

            SwapHitChain(hitPointChain);

            e.StopPropagation();
#if DEBUG
            if (local_msgVersion != dbugMsgChainVersion)
            {
                return;
            }
            visualroot.dbugHitTracker.Write("stop-mousedown");
            visualroot.dbugHitTracker.Play = false;
#endif
        }