Ejemplo n.º 1
0
        private void MouseDown(IMouseDevice device, IVisual visual, Point p)
        {
            IVisual hit = visual.GetVisualAt(p);

            if (hit != null)
            {
                IInteractive source = this.GetSource(hit);

                if (source != null)
                {
                    source.RaiseEvent(new PointerEventArgs
                    {
                        Device         = this,
                        RoutedEvent    = InputElement.PointerPressedEvent,
                        OriginalSource = source,
                        Source         = source,
                    });
                }

                IInputElement focusable = this.GetFocusable(hit);

                if (focusable != null && focusable.Focusable)
                {
                    focusable.Focus();
                }
            }
        }
Ejemplo n.º 2
0
        private void MouseDown(IMouseDevice device, uint timestamp, IInputElement root, Point p)
        {
            var hit = HitTest(root, p);

            if (hit != null)
            {
                IInteractive source = GetSource(hit);

                if (source != null)
                {
                    var settings        = Locator.Current.GetService <IPlatformSettings>();
                    var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds;

                    if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
                    {
                        _clickCount = 0;
                    }

                    ++_clickCount;
                    _lastClickTime = timestamp;
                    _lastClickRect = new Rect(p, new Size())
                                     .Inflate(new Thickness(settings.DoubleClickSize.Width / 2, settings.DoubleClickSize.Height / 2));

                    var e = new PointerPressEventArgs
                    {
                        Device      = this,
                        RoutedEvent = InputElement.PointerPressedEvent,
                        Source      = source,
                        ClickCount  = _clickCount,
                    };

                    source.RaiseEvent(e);
                }
            }
        }
Ejemplo n.º 3
0
        public void Focus(IInputElement control)
        {
            IInteractive current = this.Current as IInteractive;
            IInteractive next    = control as IInteractive;

            if (current != null)
            {
                current.RaiseEvent(new RoutedEventArgs
                {
                    RoutedEvent    = InputElement.LostFocusEvent,
                    Source         = current,
                    OriginalSource = current,
                });
            }

            this.Current = control;

            IKeyboardDevice keyboard = Locator.Current.GetService <IKeyboardDevice>();

            if (keyboard != null)
            {
                keyboard.FocusedElement = control;
            }

            if (next != null)
            {
                next.RaiseEvent(new RoutedEventArgs
                {
                    RoutedEvent    = InputElement.GotFocusEvent,
                    Source         = next,
                    OriginalSource = next,
                });
            }
        }
Ejemplo n.º 4
0
        private static void PointerReleased(RoutedEventArgs ev)
        {
            if (ev.Route == RoutingStrategies.Bubble)
            {
                var e = (PointerReleasedEventArgs)ev;

                if (s_lastPress == e.Source)
                {
                    s_lastPress.RaiseEvent(new RoutedEventArgs(TappedEvent));
                }
            }
        }
Ejemplo n.º 5
0
        private void MouseWheel(IMouseDevice device, IInputRoot root, Point p, Vector delta, InputModifiers inputModifiers)
        {
            var hit = HitTest(root, p);

            if (hit != null)
            {
                IInteractive source = GetSource(hit);

                source?.RaiseEvent(new PointerWheelEventArgs
                {
                    Device         = this,
                    RoutedEvent    = InputElement.PointerWheelChangedEvent,
                    Source         = source,
                    Delta          = delta,
                    InputModifiers = inputModifiers
                });
            }
        }
Ejemplo n.º 6
0
        private void MouseUp(IMouseDevice device, IInputRoot root, Point p, MouseButton button, InputModifiers inputModifiers)
        {
            var hit = HitTest(root, p);

            if (hit != null)
            {
                IInteractive source = GetSource(hit);

                source?.RaiseEvent(new PointerReleasedEventArgs
                {
                    Device         = this,
                    RoutedEvent    = InputElement.PointerReleasedEvent,
                    Source         = source,
                    MouseButton    = button,
                    InputModifiers = inputModifiers
                });
            }
        }
Ejemplo n.º 7
0
        public void Down(IInteractive target, IInteractive source, MouseButton mouseButton = MouseButton.Left,
                         Point position = default, InputModifiers modifiers = default, int clickCount = 1)
        {
            _pressedButtons |= Convert(mouseButton);
            var props = new PointerPointProperties(_pressedButtons);

            if (ButtonCount(props) > 1)
            {
                Move(target, source, position);
            }
            else
            {
                _pressedButton = mouseButton;
                _pointer.Capture((IInputElement)target);
                target.RaiseEvent(new PointerPressedEventArgs(source, _pointer, (IVisual)source, position, Timestamp(), props,
                                                              GetModifiers(modifiers), clickCount));
            }
        }
Ejemplo n.º 8
0
        private bool MouseDown(IMouseDevice device, uint timestamp, IInputElement root, Point p, MouseButton button, InputModifiers inputModifiers)
        {
            Contract.Requires <ArgumentNullException>(device != null);
            Contract.Requires <ArgumentNullException>(root != null);

            var hit = HitTest(root, p);

            if (hit != null)
            {
                IInteractive source = GetSource(hit);

                if (source != null)
                {
                    var settings        = AvaloniaLocator.Current.GetService <IPlatformSettings>();
                    var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds;

                    if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
                    {
                        _clickCount = 0;
                    }

                    ++_clickCount;
                    _lastClickTime = timestamp;
                    _lastClickRect = new Rect(p, new Size())
                                     .Inflate(new Thickness(settings.DoubleClickSize.Width / 2, settings.DoubleClickSize.Height / 2));

                    var e = new PointerPressedEventArgs
                    {
                        Device         = this,
                        RoutedEvent    = InputElement.PointerPressedEvent,
                        Source         = source,
                        ClickCount     = _clickCount,
                        MouseButton    = button,
                        InputModifiers = inputModifiers
                    };

                    source.RaiseEvent(e);
                    return(e.Handled);
                }
            }

            return(false);
        }
Ejemplo n.º 9
0
        private void MouseUp(IMouseDevice device, IInputRoot root, Point p)
        {
            var hit = HitTest(root, p);

            if (hit != null)
            {
                IInteractive source = GetSource(hit);

                if (source != null)
                {
                    source.RaiseEvent(new PointerEventArgs
                    {
                        Device      = this,
                        RoutedEvent = InputElement.PointerReleasedEvent,
                        Source      = source,
                    });
                }
            }
        }
Ejemplo n.º 10
0
        private void MouseUp(IMouseDevice device, IVisual visual, Point p)
        {
            IVisual hit = visual.GetVisualAt(p);

            if (hit != null)
            {
                IInteractive source = this.GetSource(hit);

                if (source != null)
                {
                    source.RaiseEvent(new PointerEventArgs
                    {
                        Device         = this,
                        RoutedEvent    = InputElement.PointerReleasedEvent,
                        OriginalSource = source,
                        Source         = source,
                    });
                }
            }
        }
Ejemplo n.º 11
0
        private void MouseWheel(IMouseDevice device, IInputElement root, Point p, Vector delta)
        {
            var hit = this.HitTest(root, p);

            if (hit != null)
            {
                IInteractive source = this.GetSource(hit);

                if (source != null)
                {
                    source.RaiseEvent(new PointerWheelEventArgs
                    {
                        Device         = this,
                        RoutedEvent    = InputElement.PointerWheelChangedEvent,
                        OriginalSource = source,
                        Source         = source,
                        Delta          = delta,
                    });
                }
            }
        }
Ejemplo n.º 12
0
        public void Down(IInteractive target, IInteractive source, MouseButton mouseButton = MouseButton.Left,
                         Point position = default, InputModifiers modifiers = default, int clickCount = 1)
        {
            _pressedButtons |= Convert(mouseButton);
            var props = new PointerPointProperties((RawInputModifiers)_pressedButtons,
                                                   mouseButton == MouseButton.Left ? PointerUpdateKind.LeftButtonPressed
                : mouseButton == MouseButton.Middle ? PointerUpdateKind.MiddleButtonPressed
                : mouseButton == MouseButton.Right ? PointerUpdateKind.RightButtonPressed : PointerUpdateKind.Other
                                                   );

            if (ButtonCount(props) > 1)
            {
                Move(target, source, position);
            }
            else
            {
                _pressedButton = mouseButton;
                _pointer.Capture((IInputElement)target);
                source.RaiseEvent(new PointerPressedEventArgs(source, _pointer, (IVisual)source, position, Timestamp(), props,
                                                              GetModifiers(modifiers), clickCount));
            }
        }