Пример #1
0
        private static void WindowPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F12)
            {
                var window = (Window)sender;
                var devToolsWindow = default(Window);

                if (s_open.TryGetValue(window, out devToolsWindow))
                {
                    devToolsWindow.Activate();
                }
                else
                {
                    devToolsWindow = new Window
                    {
                        Width = 1024,
                        Height = 512,
                        Content = new DevTools(window),
                        DataTemplates = new DataTemplates
                        {
                            new ViewLocator<ReactiveObject>(),
                        }
                    };

                    devToolsWindow.Closed += DevToolsClosed;
                    s_open.Add((Window)sender, devToolsWindow);
                    devToolsWindow.Show();
                }
            }
        }
Пример #2
0
        private static void WindowPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F12)
            {
                Window window = new Window
                {
                    Width = 1024,
                    Height = 512,
                    Content = new DevTools
                    {
                        Root = (Window)sender,
                    },
                };

                window.Show();
            }
        }
Пример #3
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (!e.Handled)
            {
                if (e.Key == Key.F4 ||
                    (e.Key == Key.Down && ((e.Modifiers & ModifierKeys.Alt) != 0)))
                {
                    IsDropDownOpen = !IsDropDownOpen;
                    e.Handled = true;
                }
                else if (IsDropDownOpen && (e.Key == Key.Escape || e.Key == Key.Enter))
                {
                    IsDropDownOpen = false;
                    e.Handled = true;
                }
            }
        }
Пример #4
0
        /// <inheritdoc/>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (!e.Handled)
            {
                switch (e.Key)
                {
                    case Key.Right:
                        if (Items != null && Items.Cast<object>().Any())
                        {
                            IsExpanded = true;
                        }

                        e.Handled = true;
                        break;

                    case Key.Left:
                        IsExpanded = false;
                        e.Handled = true;
                        break;
                }
            }

            base.OnKeyDown(e);
        }
Пример #5
0
        /// <summary>
        /// Called when a key is pressed within the menu.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            bool menuWasOpen = SelectedMenuItem?.IsSubMenuOpen ?? false;

            base.OnKeyDown(e);

            if (menuWasOpen)
            {
                // If a menu item was open and we navigate to a new one with the arrow keys, open
                // that menu and select the first item.
                var selection = SelectedMenuItem;

                if (selection != null && !selection.IsSubMenuOpen)
                {
                    selection.IsSubMenuOpen = true;
                    selection.SelectedIndex = 0;
                }
            }
        }
Пример #6
0
        private void ProcessRawEvent(RawInputEventArgs e)
        {
            IInputElement element = FocusedElement;

            if (element != null)
            {
                var keyInput = e as RawKeyEventArgs;
                if (keyInput != null)
                {
                    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,
                                Modifiers = 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);
                            break;
                    }
                }
                var text = e as RawTextInputEventArgs;
                if (text != null)
                {
                    element.RaiseEvent(new TextInputEventArgs()
                    {
                        Device = this,
                        Text = text.Text,
                        Source = element,
                        RoutedEvent = InputElement.TextInputEvent
                    });
                }
            }
        }
Пример #7
0
 /// <summary>
 /// Called before the <see cref="KeyDown"/> event occurs.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnKeyDown(KeyEventArgs e)
 {
 }
Пример #8
0
 protected override void OnKeyDown(KeyEventArgs e)
 {
     // Don't handle keypresses.
 }
Пример #9
0
        /// <summary>
        /// Called when a key is pressed in the owner window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.LeftAlt)
            {
                if (this.MainMenu == null || !this.MainMenu.IsOpen)
                {
                    // When Alt is pressed without a main menu, or with a closed main menu, show
                    // access key markers in the window (i.e. "_File").
                    this.owner.ShowAccessKeys = this.showingAccessKeys = true;
                }
                else
                {
                    // If the Alt key is pressed and the main menu is open, close the main menu.
                    this.CloseMenu();
                    this.ignoreAltUp = true;
                }

                // We always handle the Alt key.
                e.Handled = true;
            }
        }
Пример #10
0
        private void ProcessRawEvent(RawKeyEventArgs e)
        {
            IInputElement element = this.FocusedElement;

            if (element != null)
            {
                switch (e.Type)
                {
                    case RawKeyEventType.KeyDown:
                    case RawKeyEventType.KeyUp:
                        var routedEvent = e.Type == RawKeyEventType.KeyDown ?
                            InputElement.KeyDownEvent : InputElement.KeyUpEvent;

                        KeyEventArgs ev = new KeyEventArgs
                        {
                            RoutedEvent = routedEvent,
                            Device = this,
                            Key = e.Key,
                            Text = e.Text,
                            Source = element,
                            OriginalSource = element,
                        };

                        element.RaiseEvent(ev);
                        break;
                }
            }
        }
        /// <summary>
        /// Handles the Tab key being pressed in the window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnKeyDown(object sender, KeyEventArgs e)
        {
            var current = FocusManager.Instance.Current;

            if (e.Key == Key.Tab && current != null)
            {
                if ((KeyboardDevice.Instance.Modifiers & ModifierKeys.Shift) == 0)
                {
                    this.TabNext(current);
                }
                else
                {
                    this.TabPrevious(current);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Handles the Tab key being pressed in the window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnKeyDown(object sender, KeyEventArgs e)
        {
            var current = FocusManager.Instance.Current;

            if (current != null)
            {
                FocusNavigationDirection? direction = null;

                switch (e.Key)
                {
                    case Key.Tab:
                        direction = (e.Modifiers & ModifierKeys.Shift) == 0 ?
                            FocusNavigationDirection.Next : FocusNavigationDirection.Previous;
                        break;
                    case Key.Up:
                        direction = FocusNavigationDirection.Up;
                        break;
                    case Key.Down:
                        direction = FocusNavigationDirection.Down;
                        break;
                    case Key.Left:
                        direction = FocusNavigationDirection.Left;
                        break;
                    case Key.Right:
                        direction = FocusNavigationDirection.Right;
                        break;
                }

                if (direction.HasValue)
                {
                    Move(current, direction.Value);
                    e.Handled = true;
                }
            }
        }
Пример #13
0
 /// <summary>
 /// Create HtmlRenderer key event from Perspex key event.
 /// </summary>
 private static RKeyEvent CreateKeyEevent(KeyEventArgs e)
 {
     var control = (e.Modifiers & InputModifiers.Control) == InputModifiers.Control;
     return new RKeyEvent(control, e.Key == Key.A, e.Key == Key.C);
 }
Пример #14
0
        /// <summary>
        /// Handle key down event for selection and copy.
        /// </summary>
        /// <param name="parent">the control hosting the html to invalidate</param>
        /// <param name="e">the pressed key</param>
        public void HandleKeyDown(Control parent, KeyEventArgs e)
        {
            ArgChecker.AssertArgNotNull(parent, "parent");
            ArgChecker.AssertArgNotNull(e, "e");

            _htmlContainerInt.HandleKeyDown(new ControlAdapter(parent), CreateKeyEevent(e));
        }
Пример #15
0
 /// <inheritdoc/>
 protected override void OnKeyDown(KeyEventArgs e)
 {
     // Ignore key presses.
 }
Пример #16
0
        /// <summary>
        /// Called when a key is pressed in the owner window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnKeyDown(object sender, KeyEventArgs e)
        {
            bool menuIsOpen = this.MainMenu?.IsOpen == true;

            if (e.Key == Key.Escape && menuIsOpen)
            {
                // When the Escape key is pressed with the main menu open, close it.
                this.CloseMenu();
                e.Handled = true;
            }
            else if ((KeyboardDevice.Instance.Modifiers & ModifierKeys.Alt) != 0 || menuIsOpen)
            {
                // If any other key is pressed with the Alt key held down, or the main menu is open,
                // find all controls who have registered that access key.
                var text = e.Text.ToUpper();
                var matches = this.registered
                    .Where(x => x.Item1 == text && x.Item2.IsEffectivelyVisible)
                    .Select(x => x.Item2);

                // If the menu is open, only match controls in the menu's visual tree.
                if (menuIsOpen)
                {
                    matches = matches.Where(x => this.MainMenu.IsVisualAncestorOf(x));
                }

                var match = matches.FirstOrDefault();

                // If there was a match, raise the AccessKeyPressed event on it.
                if (match != null)
                {
                    match.RaiseEvent(new RoutedEventArgs(AccessKeyPressedEvent));
                    e.Handled = true;
                }
            }
        }
Пример #17
0
        private void ProcessRawEvent(RawInputEventArgs e)
        {
            IInputElement element = FocusedElement;

            if (element != null)
            {
                var keyInput = e as RawKeyEventArgs;
                if (keyInput != null)
                {
                    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,
                                Modifiers = keyInput.Modifiers,
                                Source = element,
                            };

                            element.RaiseEvent(ev);
                            break;
                    }
                }
                var text = e as RawTextInputEventArgs;
                if (text != null)
                {
                    element.RaiseEvent(new TextInputEventArgs()
                    {
                        Device = this,
                        Text = text.Text,
                        Source = element,
                        RoutedEvent = InputElement.TextInputEvent
                    });
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Handles the Alt/F10 keys being released in the window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnPreviewKeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.LeftAlt:
                    if (this.ignoreAltUp)
                    {
                        this.ignoreAltUp = false;
                    }
                    else if (this.showingAccessKeys && this.MainMenu != null)
                    {
                        this.MainMenu.Open();
                        e.Handled = true;
                    }

                    break;

                case Key.F10:
                    this.owner.ShowAccessKeys = this.showingAccessKeys = true;
                    this.MainMenu.Open();
                    e.Handled = true;
                    break;
            }
        }
Пример #19
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            string text = this.Text ?? string.Empty;
            int caretIndex = this.CaretIndex;
            bool movement = false;
            bool textEntered = false;
            bool handled = true;
            var modifiers = e.Device.Modifiers;

            switch (e.Key)
            {
                case Key.A:
                    if (modifiers == ModifierKeys.Control)
                    {
                        this.SelectAll();
                    }
                    else
                    {
                        goto default;
                    }

                    break;

                case Key.Left:
                    this.MoveHorizontal(-1, modifiers);
                    movement = true;
                    break;

                case Key.Right:
                    this.MoveHorizontal(1, modifiers);
                    movement = true;
                    break;

                case Key.Up:
                    this.MoveVertical(-1, modifiers);
                    movement = true;
                    break;

                case Key.Down:
                    this.MoveVertical(1, modifiers);
                    movement = true;
                    break;

                case Key.Home:
                    this.MoveHome(modifiers);
                    movement = true;
                    break;

                case Key.End:
                    this.MoveEnd(modifiers);
                    movement = true;
                    break;

                case Key.Back:
                    if (!this.DeleteSelection() && this.CaretIndex > 0)
                    {
                        this.Text = text.Substring(0, caretIndex - 1) + text.Substring(caretIndex);
                        --this.CaretIndex;
                    }

                    break;

                case Key.Delete:
                    if (!this.DeleteSelection() && caretIndex < text.Length)
                    {
                        this.Text = text.Substring(0, caretIndex) + text.Substring(caretIndex + 1);
                    }

                    break;

                case Key.Enter:
                    if (this.AcceptsReturn)
                    {
                        goto default;
                    }

                    break;

                case Key.Tab:
                    if (this.AcceptsTab)
                    {
                        goto default;
                    }
                    else
                    {
                        base.OnKeyDown(e);
                        handled = false;
                    }

                    break;

                default:
                    if (!string.IsNullOrEmpty(e.Text))
                    {
                        this.DeleteSelection();
                        caretIndex = this.CaretIndex;
                        text = this.Text ?? string.Empty;
                        this.Text = text.Substring(0, caretIndex) + e.Text + text.Substring(caretIndex);
                        ++this.CaretIndex;
                        textEntered = true;
                    }

                    break;
            }

            if (movement && ((modifiers & ModifierKeys.Shift) != 0))
            {
                this.SelectionEnd = this.CaretIndex;
            }
            else if (movement || textEntered)
            {
                this.SelectionStart = this.SelectionEnd = this.CaretIndex;
            }

            if (handled)
            {
                e.Handled = true;
            }
        }
Пример #20
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            string text = Text ?? string.Empty;
            int caretIndex = CaretIndex;
            bool movement = false;
            bool handled = true;
            var modifiers = e.Modifiers;

            switch (e.Key)
            {
                case Key.A:
                    if (modifiers == InputModifiers.Control)
                    {
                        SelectAll();
                    }

                    break;
                case Key.C:
                    if (modifiers == InputModifiers.Control)
                    {
                        Copy();
                    }

                    break;
                case Key.V:
                    if (modifiers == InputModifiers.Control)
                    {
                        Paste();
                    }

                    break;
                case Key.Left:
                    MoveHorizontal(-1, modifiers);
                    movement = true;
                    break;

                case Key.Right:
                    MoveHorizontal(1, modifiers);
                    movement = true;
                    break;

                case Key.Up:
                    MoveVertical(-1, modifiers);
                    movement = true;
                    break;

                case Key.Down:
                    MoveVertical(1, modifiers);
                    movement = true;
                    break;

                case Key.Home:
                    MoveHome(modifiers);
                    movement = true;
                    break;

                case Key.End:
                    MoveEnd(modifiers);
                    movement = true;
                    break;

                case Key.Back:
                    if (!DeleteSelection() && CaretIndex > 0)
                    {
                        Text = text.Substring(0, caretIndex - 1) + text.Substring(caretIndex);
                        --CaretIndex;
                    }

                    break;

                case Key.Delete:
                    if (!DeleteSelection() && caretIndex < text.Length)
                    {
                        Text = text.Substring(0, caretIndex) + text.Substring(caretIndex + 1);
                    }

                    break;

                case Key.Enter:
                    if (AcceptsReturn)
                    {
                        HandleTextInput("\r\n");
                    }

                    break;

                case Key.Tab:
                    if (AcceptsTab)
                    {
                        HandleTextInput("\t");
                    }
                    else
                    {
                        base.OnKeyDown(e);
                        handled = false;
                    }

                    break;
            }

            if (movement && ((modifiers & InputModifiers.Shift) != 0))
            {
                SelectionEnd = CaretIndex;
            }
            else if (movement)
            {
                SelectionStart = SelectionEnd = CaretIndex;
            }

            if (handled)
            {
                e.Handled = true;
            }
        }
Пример #21
0
        /// <summary>
        /// Called when a key is pressed within the control.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (!e.Handled)
            {
                switch (e.Key)
                {
                    case Key.Up:
                        this.MoveSelection(FocusNavigationDirection.Up);
                        break;
                    case Key.Down:
                        this.MoveSelection(FocusNavigationDirection.Down);
                        break;
                    case Key.Left:
                        this.MoveSelection(FocusNavigationDirection.Left);
                        break;
                    case Key.Right:
                        this.MoveSelection(FocusNavigationDirection.Right);
                        break;
                    default:
                        return;
                }

                var selected = this.SelectedItem;

                if (selected != null)
                {
                    var container = this.ItemContainerGenerator.GetContainerForItem(selected);

                    if (container != null)
                    {
                        container.BringIntoView();
                        FocusManager.Instance.Focus(container, true);
                    }
                }

                e.Handled = true;
            }
        }
Пример #22
0
 /// <summary>
 /// Called before the <see cref="KeyUp"/> event occurs.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnKeyUp(KeyEventArgs e)
 {
 }
Пример #23
0
        /// <summary>
        /// Handles a key being pressed in the menu.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(e.Text))
            {
                var text = e.Text.ToUpper();
                var focus = this.registered
                    .Where(x => x.Item1 == text && x.Item2.IsEffectivelyVisible)
                    .FirstOrDefault()?.Item2;

                if (focus != null)
                {
                    focus.RaiseEvent(new RoutedEventArgs(AccessKeyHandler.AccessKeyPressedEvent));
                }

                e.Handled = true;
            }
        }