Ejemplo n.º 1
0
        /// <summary>
        /// Attach events to a visual
        /// </summary>
        /// <param name="obj">Object with which event is attached</param>
        /// <param name="senderElement">sender will be passed to the event-handler</param>
        /// <param name="visual">visual object with which event will be attached</param>
        internal static void AttachEvents2Visual(VisifireElement obj, VisifireElement senderElement, FrameworkElement visual)
        {
            if (visual == null)
            {
                return;
            }

            //if (senderElement != null)
            //    visual.Tag = senderElement;

            if (obj._onMouseEnter != null)
            {
                visual.MouseEnter += delegate(object sender, MouseEventArgs e)
                {
                    if (obj._onMouseEnter != null)
                    {
                        obj._onMouseEnter(senderElement, e);
                    }
                }
            }
            ;

            if (obj._onMouseLeave != null)
            {
                visual.MouseLeave += delegate(object sender, MouseEventArgs e)
                {
                    if (obj._onMouseLeave != null)
                    {
                        obj._onMouseLeave(senderElement, e);
                    }
                }
            }
            ;

            PlotArea plotArea = obj as PlotArea;
            object   eventHandler;

            if (plotArea != null)
            {
                eventHandler = plotArea.GetMouseLeftButtonDownEventHandler();
            }
            else
            {
                eventHandler = obj._onMouseLeftButtonDown;
            }

            if (eventHandler != null)
            {
                visual.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
                {
                    if (plotArea != null)
                    {
                        plotArea.FireMouseLeftButtonDownEvent(e);
                    }
                    else
                    {
                        if (obj._onMouseLeftButtonDown != null)
                        {
                            obj._onMouseLeftButtonDown(senderElement, e);
                        }
                    }
                }
            }
            ;

            if (plotArea != null)
            {
                eventHandler = plotArea.GetMouseLeftButtonUpEventHandler();
            }
            else
            {
                eventHandler = obj._onMouseLeftButtonUp;
            }

            if (eventHandler != null)
            {
                visual.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e)
                {
                    if (obj.GetType().Equals(typeof(PlotArea)))
                    {
                        (obj as PlotArea).FireMouseLeftButtonUpEvent(e);
                    }
                    else
                    {
                        if (obj._onMouseLeftButtonUp != null)
                        {
                            obj._onMouseLeftButtonUp(senderElement, e);
                        }
                    }
                }
            }
            ;

            if (plotArea != null)
            {
                eventHandler = plotArea.GetMouseMoveEventHandler();
            }
            else
            {
                eventHandler = obj._onMouseMove;
            }

            if (eventHandler != null)
            {
                visual.MouseMove += delegate(object sender, MouseEventArgs e)
                {
                    if (obj.GetType().Equals(typeof(PlotArea)))
                    {
                        (obj as PlotArea).FireMouseMoveEvent(e);
                    }
                    else
                    {
                        if (obj._onMouseMove != null)
                        {
                            obj._onMouseMove(senderElement, e);
                        }
                    }
                }
            }
            ;

            #region RightMouseButtonEvents4WPF
#if WPF
            object eventHandler4RightMouseButton;

            if (plotArea != null)
            {
                eventHandler4RightMouseButton = plotArea.GetMouseRightButtonDownEventHandler();
            }
            else
            {
                eventHandler4RightMouseButton = obj._onMouseRightButtonDown;
            }

            if (eventHandler4RightMouseButton != null)
            {
                visual.MouseRightButtonDown += delegate(object sender, MouseButtonEventArgs e)
                {
                    if (plotArea != null)
                    {
                        plotArea.FireMouseRightButtonDownEvent(e);
                    }
                    else
                    {
                        if (obj._onMouseRightButtonDown != null)
                        {
                            obj._onMouseRightButtonDown(senderElement, e);
                        }
                    }
                }
            }
            ;

            if (plotArea != null)
            {
                eventHandler4RightMouseButton = plotArea.GetMouseRightButtonUpEventHandler();
            }
            else
            {
                eventHandler4RightMouseButton = obj._onMouseRightButtonUp;
            }

            if (eventHandler4RightMouseButton != null)
            {
                visual.MouseRightButtonUp += delegate(object sender, MouseButtonEventArgs e)
                {
                    if (plotArea != null)
                    {
                        plotArea.FireMouseRightButtonUpEvent(e);
                    }
                    else
                    {
                        if (obj._onMouseRightButtonUp != null)
                        {
                            obj._onMouseRightButtonUp(senderElement, e);
                        }
                    }
                }
            }
            ;
#endif
            #endregion
        }