Ejemplo n.º 1
0
    public void TestConstructor()
    {
        increment = 0;
        IEventTarget eventTarget = (IEventTarget)doc.DocumentElement;

        // Add first event listener
        eventTarget.AddEventListener("mousemove", new EventListener(OnMouseMove), false);
        eventTarget.DispatchEvent(new Event("uievent", "mousemove", true, false));
        Assert.AreEqual(1, increment);

        // Add second event listener
        // "If multiple identical EventListeners are registered on the same EventTarget with the same
        //  parameters the duplicate instances are discarded. They do not cause the EventListener to
        //  be called twice and since they are discarded they do not need to be removed with the removeEventListener method."
        eventTarget.AddEventListener("mousemove", new EventListener(OnMouseMove), false);
        eventTarget.DispatchEvent(new Event("uievent", "mousemove", true, false));
        Assert.AreEqual(2, increment);

        // Remove first event listener
        eventTarget.RemoveEventListener("mousemove", new EventListener(OnMouseMove), false);
        eventTarget.DispatchEvent(new Event("uievent", "mousemove", true, false));
        Assert.AreEqual(2, increment);

        // Remove second event listener
        // "Calling removeEventListener with arguments which do not identify any currently registered EventListener on the EventTarget has no effect."
        eventTarget.RemoveEventListener("mousemove", new EventListener(OnMouseMove), false);
        eventTarget.DispatchEvent(new Event("uievent", "mousemove", true, false));
        Assert.AreEqual(2, increment);
    }
        /// <summary>
        /// Processes mouse events.
        /// </summary>
        /// <param name="type">
        /// A string describing the type of mouse event that occured.
        /// </param>
        /// <param name="e">
        /// The <see cref="MouseEventArgs">MouseEventArgs</see> that contains
        /// the event data.
        /// </param>
        public void OnMouseEvent(string type, MouseEventArgs e)
        {
            if (idMapRaster != null)
            {
                try
                {
                    Color      pixel     = idMapRaster.GetPixel(e.X, e.Y);
                    SvgElement grElement = GetElementFromColor(pixel);
                    if (grElement != null)
                    {
                        IEventTarget target;
                        if (grElement.ElementInstance != null)
                        {
                            target = grElement.ElementInstance as IEventTarget;
                        }
                        else
                        {
                            target = grElement as IEventTarget;
                        }

                        if (target != null)
                        {
                            switch (type)
                            {
                            case "mousemove":
                            {
                                if (currentTarget == target)
                                {
                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.MouseMove, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             e.X, e.Y, e.X, e.Y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                else
                                {
                                    if (currentTarget != null)
                                    {
                                        currentTarget.DispatchEvent(new MouseEvent(
                                                                        EventType.MouseOut, true, false,
                                                                        null, // todo: put view here
                                                                        0,    // todo: put detail here
                                                                        e.X, e.Y, e.X, e.Y,
                                                                        false, false, false, false,
                                                                        0, null, false));
                                    }

                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.MouseOver, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             e.X, e.Y, e.X, e.Y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                break;
                            }

                            case "mousedown":
                                target.DispatchEvent(new MouseEvent(
                                                         EventType.MouseDown, true, false,
                                                         null, // todo: put view here
                                                         0,    // todo: put detail here
                                                         e.X, e.Y, e.X, e.Y,
                                                         false, false, false, false,
                                                         0, null, false));
                                currentDownTarget = target;
                                currentDownX      = e.X;
                                currentDownY      = e.Y;
                                break;

                            case "mouseup":
                                target.DispatchEvent(new MouseEvent(
                                                         EventType.MouseUp, true, false,
                                                         null, // todo: put view here
                                                         0,    // todo: put detail here
                                                         e.X, e.Y, e.X, e.Y,
                                                         false, false, false, false,
                                                         0, null, false));
                                if (/*currentDownTarget == target &&*/ Math.Abs(currentDownX - e.X) < 5 && Math.Abs(currentDownY - e.Y) < 5)
                                {
                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.Click, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             e.X, e.Y, e.X, e.Y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                currentDownTarget = null;
                                currentDownX      = 0;
                                currentDownY      = 0;
                                break;
                            }
                            currentTarget = target;
                        }
                        else
                        {
                            // jr patch
                            if (currentTarget != null && type == "mousemove")
                            {
                                currentTarget.DispatchEvent(new MouseEvent(
                                                                EventType.MouseOut, true, false,
                                                                null, // todo: put view here
                                                                0,    // todo: put detail here
                                                                e.X, e.Y, e.X, e.Y,
                                                                false, false, false, false,
                                                                0, null, false));
                            }
                            currentTarget = null;
                        }
                    }
                    else
                    {
                        // jr patch
                        if (currentTarget != null && type == "mousemove")
                        {
                            currentTarget.DispatchEvent(new MouseEvent(
                                                            EventType.MouseOut, true, false,
                                                            null, // todo: put view here
                                                            0,    // todo: put detail here
                                                            e.X, e.Y, e.X, e.Y,
                                                            false, false, false, false,
                                                            0, null, false));
                        }
                        currentTarget = null;
                    }
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 3
0
        private void ProcessMouseEvents(string type, MouseEventArgs e)
        {
            //Color pixel = _idMapRaster.GetPixel(e.X, e.Y);
            //SvgElement svgElement = GetElementFromColor(pixel);

            SvgElement svgElement    = null;
            var        hitTestResult = _hitTestHelper.HitTest(e.X, e.Y);

            if (hitTestResult != null)
            {
                svgElement = hitTestResult.Element;
            }

            if (type == "mouseup")
            {
                type = type.Trim();
            }

            if (svgElement == null)
            {
                // jr patch
                if (_currentTarget != null && type == "mousemove")
                {
                    _currentTarget.DispatchEvent(new MouseEvent(EventType.MouseOut, true, false,
                                                                null, // todo: put view here
                                                                0,    // todo: put detail here
                                                                e.X, e.Y, e.X, e.Y,
                                                                false, false, false, false,
                                                                0, null, false));
                }
                _currentTarget = null;
                return;
            }

            IEventTarget target;

            if (svgElement.ElementInstance != null)
            {
                target = svgElement.ElementInstance as IEventTarget;
            }
            else
            {
                target = svgElement as IEventTarget;
            }

            if (target == null)
            {
                // jr patch
                if (_currentTarget != null && type == "mousemove")
                {
                    _currentTarget.DispatchEvent(new MouseEvent(EventType.MouseOut, true, false,
                                                                null, // todo: put view here
                                                                0,    // todo: put detail here
                                                                e.X, e.Y, e.X, e.Y,
                                                                false, false, false, false,
                                                                0, null, false));
                }
                _currentTarget = null;
                return;
            }

            switch (type)
            {
            case "mousemove":
            {
                if (_currentTarget == target)
                {
                    target.DispatchEvent(new MouseEvent(EventType.MouseMove, true, false,
                                                        null, // todo: put view here
                                                        0,    // todo: put detail here
                                                        e.X, e.Y, e.X, e.Y,
                                                        false, false, false, false,
                                                        0, null, false));
                }
                else
                {
                    if (_currentTarget != null)
                    {
                        _currentTarget.DispatchEvent(new MouseEvent(EventType.MouseOut, true, false,
                                                                    null, // todo: put view here
                                                                    0,    // todo: put detail here
                                                                    e.X, e.Y, e.X, e.Y,
                                                                    false, false, false, false,
                                                                    0, null, false));
                    }

                    target.DispatchEvent(new MouseEvent(EventType.MouseOver, true, false,
                                                        null, // todo: put view here
                                                        0,    // todo: put detail here
                                                        e.X, e.Y, e.X, e.Y,
                                                        false, false, false, false,
                                                        0, null, false));
                }
                break;
            }

            case "mousedown":
                target.DispatchEvent(new MouseEvent(EventType.MouseDown, true, false,
                                                    null, // todo: put view here
                                                    0,    // todo: put detail here
                                                    e.X, e.Y, e.X, e.Y,
                                                    false, false, false, false,
                                                    0, null, false));
                _currentDownTarget = target;
                _currentDownX      = e.X;
                _currentDownY      = e.Y;
                break;

            case "mouseup":
                target.DispatchEvent(new MouseEvent(EventType.MouseUp, true, false,
                                                    null, // todo: put view here
                                                    0,    // todo: put detail here
                                                    e.X, e.Y, e.X, e.Y,
                                                    false, false, false, false,
                                                    0, null, false));
                if (Math.Abs(_currentDownX - e.X) < 5 && Math.Abs(_currentDownY - e.Y) < 5)
                {
                    target.DispatchEvent(new MouseEvent(EventType.Click, true, false,
                                                        null, // todo: put view here
                                                        0,    // todo: put detail here
                                                        e.X, e.Y, e.X, e.Y,
                                                        false, false, false, false,
                                                        0, null, false));
                }
                _currentDownTarget = null;
                _currentDownX      = 0;
                _currentDownY      = 0;
                break;
            }
            _currentTarget = target;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes mouse events.
        /// </summary>
        /// <param name="type">
        /// A string describing the type of mouse event that occured.
        /// </param>
        /// <param name="e">
        /// The <see cref="MouseEventArgs">MouseEventArgs</see> that contains
        /// the event data.
        /// </param>
        public void OnMouseEvent(string type, int x, int y)
        {
            if (idMapRaster != null)
            {
                try
                {
                    Color        pixel  = idMapRaster.GetPixel(x, y);
                    GraphicsNode grNode = _getGraphicsNodeFromColor(pixel);

                    if (grNode != null)
                    {
                        SvgElement   grElement = (SvgElement)grNode.Element;
                        IEventTarget target;
                        if (grElement.ElementInstance != null)
                        {
                            target = grElement.ElementInstance as IEventTarget;
                        }
                        else
                        {
                            target = grElement as IEventTarget;
                        }

                        if (target != null)
                        {
                            switch (type)
                            {
                            case "mousemove":
                            {
                                if (currentTarget == target)
                                {
                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.MouseMove, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             x, y, x, y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                else
                                {
                                    if (currentTarget != null)
                                    {
                                        currentTarget.DispatchEvent(new MouseEvent(
                                                                        EventType.MouseOut, true, false,
                                                                        null, // todo: put view here
                                                                        0,    // todo: put detail here
                                                                        x, y, x, y,
                                                                        false, false, false, false,
                                                                        0, null, false));
                                    }

                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.MouseOver, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             x, y, x, y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                break;
                            }

                            case "mousedown":
                                target.DispatchEvent(new MouseEvent(
                                                         EventType.MouseDown, true, false,
                                                         null, // todo: put view here
                                                         0,    // todo: put detail here
                                                         x, y, x, y,
                                                         false, false, false, false,
                                                         0, null, false));
                                currentDownTarget = target;
                                currentDownX      = x;
                                currentDownY      = y;
                                break;

                            case "mouseup":
                                target.DispatchEvent(new MouseEvent(
                                                         EventType.MouseUp, true, false,
                                                         null, // todo: put view here
                                                         0,    // todo: put detail here
                                                         x, y, x, y,
                                                         false, false, false, false,
                                                         0, null, false));
                                if (/*currentDownTarget == target &&*/ Math.Abs(currentDownX - x) < 5 && Math.Abs(currentDownY - y) < 5)
                                {
                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.Click, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             x, y, x, y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                currentDownTarget = null;
                                currentDownX      = 0;
                                currentDownY      = 0;
                                break;
                            }
                            currentTarget = target;
                        }
                        else
                        {
                            // jr patch
                            if (currentTarget != null && type == "mousemove")
                            {
                                currentTarget.DispatchEvent(new MouseEvent(
                                                                EventType.MouseOut, true, false,
                                                                null, // todo: put view here
                                                                0,    // todo: put detail here
                                                                x, y, x, y,
                                                                false, false, false, false,
                                                                0, null, false));
                            }
                            currentTarget = null;
                        }
                    }
                    else
                    {
                        // jr patch
                        if (currentTarget != null && type == "mousemove")
                        {
                            currentTarget.DispatchEvent(new MouseEvent(
                                                            EventType.MouseOut, true, false,
                                                            null, // todo: put view here
                                                            0,    // todo: put detail here
                                                            x, y, x, y,
                                                            false, false, false, false,
                                                            0, null, false));
                        }
                        currentTarget = null;
                    }
                }
                catch
                {
                }
            }
        }