Beispiel #1
0
        private void ProcessRawEvent(RawPointerEventArgs e)
        {
            Contract.Requires <ArgumentNullException>(e != null);

            var mouse = (MouseDevice)e.Device;

            if (mouse._disposed)
            {
                return;
            }

            Position = e.Root.PointToScreen(e.Position);
            var props        = CreateProperties(e);
            var keyModifiers = KeyModifiersUtils.ConvertToKey(e.InputModifiers);

            switch (e.Type)
            {
            case RawPointerEventType.LeaveWindow:
                LeaveWindow(mouse, e.Timestamp, e.Root, props, keyModifiers);
                break;

            case RawPointerEventType.LeftButtonDown:
            case RawPointerEventType.RightButtonDown:
            case RawPointerEventType.MiddleButtonDown:
                if (ButtonCount(props) > 1)
                {
                    e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
                }
                else
                {
                    e.Handled = MouseDown(mouse, e.Timestamp, e.Root, e.Position,
                                          props, keyModifiers);
                }
                break;

            case RawPointerEventType.LeftButtonUp:
            case RawPointerEventType.RightButtonUp:
            case RawPointerEventType.MiddleButtonUp:
                if (ButtonCount(props) != 0)
                {
                    e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
                }
                else
                {
                    e.Handled = MouseUp(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
                }
                break;

            case RawPointerEventType.Move:
                e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
                break;

            case RawPointerEventType.Wheel:
                e.Handled = MouseWheel(mouse, e.Timestamp, e.Root, e.Position, props, ((RawMouseWheelEventArgs)e).Delta, keyModifiers);
                break;
            }
        }
Beispiel #2
0
        public void ProcessRawEvent(RawInputEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            var element = FocusedElement ?? e.Root;

            if (e is RawKeyEventArgs keyInput)
            {
                switch (keyInput.Type)
                {
                case RawKeyEventType.KeyDown:
                case RawKeyEventType.KeyUp:
                    var routedEvent = keyInput.Type == RawKeyEventType.KeyDown
                            ? InputElement.KeyDownEvent
                            : InputElement.KeyUpEvent;

                    KeyEventArgs ev = new KeyEventArgs
                    {
                        RoutedEvent  = routedEvent,
                        Device       = this,
                        Key          = keyInput.Key,
                        KeyModifiers = KeyModifiersUtils.ConvertToKey(keyInput.Modifiers),
                        Source       = element,
                    };

                    IVisual?currentHandler = element;
                    while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown)
                    {
                        var bindings = (currentHandler as IInputElement)?.KeyBindings;
                        if (bindings != null)
                        {
                            KeyBinding[]? bindingsCopy = null;

                            // Create a copy of the KeyBindings list if there's a binding which matches the event.
                            // If we don't do this the foreach loop will throw an InvalidOperationException when the KeyBindings list is changed.
                            // This can happen when a new view is loaded which adds its own KeyBindings to the handler.
                            foreach (var binding in bindings)
                            {
                                if (binding.Gesture?.Matches(ev) == true)
                                {
                                    bindingsCopy = bindings.ToArray();
                                    break;
                                }
                            }

                            if (bindingsCopy is object)
                            {
                                foreach (var binding in bindingsCopy)
                                {
                                    if (ev.Handled)
                                    {
                                        break;
                                    }
                                    binding.TryHandle(ev);
                                }
                            }
                        }
                        currentHandler = currentHandler.VisualParent;
                    }

                    element.RaiseEvent(ev);
                    e.Handled = ev.Handled;
                    break;
                }
            }

            if (e is RawTextInputEventArgs text)
            {
                var ev = new TextInputEventArgs()
                {
                    Device      = this,
                    Text        = text.Text,
                    Source      = element,
                    RoutedEvent = InputElement.TextInputEvent
                };

                element.RaiseEvent(ev);
                e.Handled = ev.Handled;
            }
        }
Beispiel #3
0
        public void ProcessRawEvent(RawInputEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            var element = FocusedElement ?? e.Root;

            if (e is RawKeyEventArgs keyInput)
            {
                switch (keyInput.Type)
                {
                case RawKeyEventType.KeyDown:
                case RawKeyEventType.KeyUp:
                    var routedEvent = keyInput.Type == RawKeyEventType.KeyDown
                            ? InputElement.KeyDownEvent
                            : InputElement.KeyUpEvent;

                    KeyEventArgs ev = new KeyEventArgs
                    {
                        RoutedEvent  = routedEvent,
                        Device       = this,
                        Key          = keyInput.Key,
                        KeyModifiers = KeyModifiersUtils.ConvertToKey(keyInput.Modifiers),
                        Source       = element,
                    };

                    IVisual currentHandler = element;
                    while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown)
                    {
                        var bindings = (currentHandler as IInputElement)?.KeyBindings;
                        if (bindings != null)
                        {
                            foreach (var binding in bindings)
                            {
                                if (ev.Handled)
                                {
                                    break;
                                }
                                binding.TryHandle(ev);
                            }
                        }
                        currentHandler = currentHandler.VisualParent;
                    }

                    element.RaiseEvent(ev);
                    e.Handled = ev.Handled;
                    break;
                }
            }

            if (e is RawTextInputEventArgs text)
            {
                var ev = new TextInputEventArgs()
                {
                    Device      = this,
                    Text        = text.Text,
                    Source      = element,
                    RoutedEvent = InputElement.TextInputEvent
                };

                element.RaiseEvent(ev);
                e.Handled = ev.Handled;
            }
        }