Esempio n. 1
0
        public void SetFocusedElement(
            IInputElement element, 
            NavigationMethod method,
            InputModifiers modifiers)
        {
            if (element != FocusedElement)
            {
                var interactive = FocusedElement as IInteractive;

                interactive?.RaiseEvent(new RoutedEventArgs
                {
                    RoutedEvent = InputElement.LostFocusEvent,
                });

                FocusedElement = element;
                interactive = element as IInteractive;

                interactive?.RaiseEvent(new GotFocusEventArgs
                {
                    RoutedEvent = InputElement.GotFocusEvent,
                    NavigationMethod = method,
                    InputModifiers = modifiers,
                });
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Focuses a control.
        /// </summary>
        /// <param name="control">The control to focus.</param>
        /// <param name="method">The method by which focus was changed.</param>
        /// <param name="modifiers">Any input modifiers active at the time of focus.</param>
        public void Focus(
            IInputElement control, 
            NavigationMethod method = NavigationMethod.Unspecified,
            InputModifiers modifiers = InputModifiers.None)
        {
            if (control != null)
            {
                var scope = GetFocusScopeAncestors(control)
                    .FirstOrDefault();

                if (scope != null)
                {
                    Scope = scope;
                    SetFocusedElement(scope, control, method, modifiers);
                }
            }
            else if (Current != null)
            {
                // If control is null, set focus to the topmost focus scope.
                foreach (var scope in GetFocusScopeAncestors(Current).Reverse().ToList())
                {
                    IInputElement element;

                    if (_focusScopes.TryGetValue(scope, out element))
                    {
                        Focus(element, method);
                        break;
                    }
                }
            }
        }
 public RawMouseWheelEventArgs(
     IInputDevice device,
     uint timestamp,
     IInputRoot root,
     Point position,
     Vector delta, InputModifiers inputModifiers)
     : base(device, timestamp, root, RawMouseEventType.Wheel, position, inputModifiers)
 {
     Delta = delta;
 }
Esempio n. 4
0
 public RawKeyEventArgs(
     IKeyboardDevice device,
     uint timestamp,
     RawKeyEventType type,
     Key key, InputModifiers modifiers)
     : base(device, timestamp)
 {
     Key = key;
     Type = type;
     Modifiers = modifiers;
 }
Esempio n. 5
0
        public RawMouseEventArgs(
            IInputDevice device,
            uint timestamp,
            IInputRoot root,
            RawMouseEventType type,
            Point position, InputModifiers inputModifiers)
            : base(device, timestamp)
        {
            Contract.Requires<ArgumentNullException>(device != null);
            Contract.Requires<ArgumentNullException>(root != null);

            Root = root;
            Position = position;
            Type = type;
            InputModifiers = inputModifiers;
        }
        /// <summary>
        /// Moves the focus in the specified direction.
        /// </summary>
        /// <param name="element">The current element.</param>
        /// <param name="direction">The direction to move.</param>
        /// <param name="modifiers">Any input modifiers active at the time of focus.</param>
        public void Move(
            IInputElement element, 
            NavigationDirection direction,
            InputModifiers modifiers = InputModifiers.None)
        {
            Contract.Requires<ArgumentNullException>(element != null);

            var next = GetNext(element, direction);

            if (next != null)
            {
                var method = direction == NavigationDirection.Next ||
                             direction == NavigationDirection.Previous ?
                             NavigationMethod.Tab : NavigationMethod.Directional;
                FocusManager.Instance.Focus(next, method, modifiers);
            }
        }
Esempio n. 7
0
        private void MoveVertical(int count, InputModifiers modifiers)
        {
            var formattedText = _presenter.FormattedText;
            var lines = formattedText.GetLines().ToList();
            var caretIndex = CaretIndex;
            var lineIndex = GetLine(caretIndex, lines) + count;

            if (lineIndex >= 0 && lineIndex < lines.Count)
            {
                var line = lines[lineIndex];
                var rect = formattedText.HitTestTextPosition(caretIndex);
                var y = count < 0 ? rect.Y : rect.Bottom;
                var point = new Point(rect.X, y + (count * (line.Height / 2)));
                var hit = formattedText.HitTestPoint(point);
                CaretIndex = hit.TextPosition + (hit.IsTrailing ? 1 : 0);
            }
        }
Esempio n. 8
0
        private void MoveEnd(InputModifiers modifiers)
        {
            var text = TextDocument ?? null;
            var caretIndex = CaretIndex;

            if (caretIndex >= 0)
            {
                if ((modifiers & InputModifiers.Control) != 0)
                {
                    caretIndex = TextDocument.TextLength;
                }
                else
                {
                    var lineOffset = TextDocument.GetLineByOffset(CaretIndex).EndOffset;
                    var whiteSpace = TextUtilities.GetWhitespaceBefore(TextDocument, lineOffset);
                    caretIndex = lineOffset - whiteSpace.Length;
                }

                CaretIndex = caretIndex;
                SetHighestColumn();
            }
        }
Esempio n. 9
0
        private bool MouseUp(IMouseDevice device, IInputRoot 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)
            {
                var source = GetSource(hit);
                var e      = new PointerReleasedEventArgs
                {
                    Device         = this,
                    RoutedEvent    = InputElement.PointerReleasedEvent,
                    Source         = source,
                    MouseButton    = button,
                    InputModifiers = inputModifiers
                };

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

            return(false);
        }
Esempio n. 10
0
 private DragDropEffects Drop(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
 {
     try
     {
         return(RaiseDragEvent(_lastTarget, inputRoot, point, DragDrop.DropEvent, effects, data, modifiers));
     }
     finally
     {
         _lastTarget = null;
     }
 }
Esempio n. 11
0
        private void MoveHorizontal(int count, InputModifiers modifiers)
        {
            var caretIndex = CaretIndex;

            if (caretIndex > TextDocument.TextLength)
            {
                caretIndex = TextDocument.TextLength;
            }

            if (caretIndex >= 0)
            {
                if ((modifiers & InputModifiers.Control) != 0)
                {
                    if (count > 0)
                    {
                        count =
                            TextUtilities.GetNextCaretPosition(TextDocument, caretIndex, TextUtilities.LogicalDirection.Forward,
                                TextUtilities.CaretPositioningMode.WordStartOrSymbol) - caretIndex;
                    }
                    else
                    {
                        count =
                            TextUtilities.GetNextCaretPosition(TextDocument, caretIndex, TextUtilities.LogicalDirection.Backward,
                                TextUtilities.CaretPositioningMode.WordStartOrSymbol) - caretIndex;
                    }

                    if (caretIndex + count <= TextDocument.TextLength && caretIndex + count >= 0)
                    {
                        CaretIndex += count;
                    }
                }
                else
                {
                    if (count > 0)
                    {
                        for (var i = 0; i < Math.Abs(count); i++)
                        {
                            var line = TextDocument.GetLineByOffset(caretIndex);

                            if (caretIndex == line.EndOffset)
                            {
                                if (line.NextLine != null)
                                {
                                    caretIndex = line.NextLine.Offset;
                                }
                            }
                            else
                            {
                                caretIndex = TextUtilities.GetNextCaretPosition(TextDocument, caretIndex, TextUtilities.LogicalDirection.Forward,
                                    TextUtilities.CaretPositioningMode.Normal);
                            }
                        }
                    }
                    else
                    {
                        for (var i = 0; i < Math.Abs(count); i++)
                        {
                            var line = TextDocument.GetLineByOffset(caretIndex);

                            if (caretIndex == line.Offset)
                            {
                                if (line.PreviousLine != null)
                                {
                                    caretIndex = line.PreviousLine.EndOffset;
                                }
                            }
                            else
                            {
                                caretIndex = TextUtilities.GetNextCaretPosition(TextDocument, caretIndex,
                                    TextUtilities.LogicalDirection.Backward, TextUtilities.CaretPositioningMode.Normal);
                            }
                        }
                    }

                    CaretIndex = caretIndex;
                }

                SetHighestColumn();
            }
        }
Esempio n. 12
0
        private bool MouseUp(IMouseDevice device, IInputRoot root, Point p, MouseButton button, InputModifiers inputModifiers)
        {
            var hit = HitTest(root, p);

            if (hit != null)
            {
                var source = GetSource(hit);
                var e = new PointerReleasedEventArgs
                {
                    Device = this,
                    RoutedEvent = InputElement.PointerReleasedEvent,
                    Source = source,
                    MouseButton = button,
                    InputModifiers = inputModifiers
                };

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

            return false;
        }
Esempio n. 13
0
 public PointerPointProperties(InputModifiers modifiers)
 {
     IsLeftButtonPressed   = modifiers.HasFlag(InputModifiers.LeftMouseButton);
     IsMiddleButtonPressed = modifiers.HasFlag(InputModifiers.MiddleMouseButton);
     IsRightButtonPressed  = modifiers.HasFlag(InputModifiers.RightMouseButton);
 }
Esempio n. 14
0
 internal void OnMouseLeftButtonUp_Click(InputModifiers inputModifiers, ref bool handled)
 {
     // completed a click without dragging, so we're sorting
     InvokeProcessSort(inputModifiers);
     handled = true;
 }
Esempio n. 15
0
        //TODO GroupSorting
        internal void ProcessSort(InputModifiers inputModifiers)
        {
            // if we can sort:
            //  - DataConnection.AllowSort is true, and
            //  - AllowUserToSortColumns and CanSort are true, and
            //  - OwningColumn is bound, and
            //  - SortDescriptionsCollection exists, and
            //  - the column's data type is comparable
            // then try to sort
            if (OwningColumn != null &&
                OwningGrid != null &&
                OwningGrid.EditingRow == null &&
                OwningColumn != OwningGrid.ColumnsInternal.FillerColumn &&
                OwningGrid.DataConnection.AllowSort &&
                OwningGrid.CanUserSortColumns &&
                OwningColumn.CanUserSort &&
                OwningGrid.DataConnection.SortDescriptions != null)
            {
                DataGrid owningGrid = OwningGrid;
                bool     desending;
                AvaloniaSortDescription newSort;

                KeyboardHelper.GetMetaKeyState(inputModifiers, out bool ctrl, out bool shift);

                AvaloniaSortDescription sort           = OwningColumn.GetSortDescription();
                ICollectionView         collectionView = owningGrid.DataConnection.CollectionView;
                Debug.Assert(collectionView != null);
                using (collectionView.DeferRefresh())
                {
                    // if shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                    if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0)
                    {
                        /*if (collectionView.CanGroup && collectionView.GroupDescriptions != null)
                         * {
                         *  // Make sure we sort by the GroupDescriptions first
                         *  for (int i = 0; i < collectionView.GroupDescriptions.Count; i++)
                         *  {
                         *      PropertyGroupDescription groupDescription = collectionView.GroupDescriptions[i] as PropertyGroupDescription;
                         *      if (groupDescription != null && collectionView.SortDescriptions.Count <= i || collectionView.SortDescriptions[i].PropertyName != groupDescription.PropertyName)
                         *      {
                         *          collectionView.SortDescriptions.Insert(Math.Min(i, collectionView.SortDescriptions.Count), new SortDescription(groupDescription.PropertyName, ListSortDirection.Ascending));
                         *      }
                         *  }
                         *  while (collectionView.SortDescriptions.Count > collectionView.GroupDescriptions.Count)
                         *  {
                         *      collectionView.SortDescriptions.RemoveAt(collectionView.GroupDescriptions.Count);
                         *  }
                         * }
                         * else if (!shift)
                         * {
                         *  owningGrid.DataConnection.SortDescriptions.Clear();
                         * }*/
                        owningGrid.DataConnection.SortDescriptions.Clear();
                    }

                    if (sort != null)
                    {
                        newSort = sort.SwitchSortDirection();

                        // changing direction should not affect sort order, so we replace this column's
                        // sort description instead of just adding it to the end of the collection
                        int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort);
                        if (oldIndex >= 0)
                        {
                            owningGrid.DataConnection.SortDescriptions.Remove(sort);
                            owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                        }
                        else
                        {
                            owningGrid.DataConnection.SortDescriptions.Add(newSort);
                        }
                    }
                    else
                    {
                        string propertyName = OwningColumn.GetSortPropertyName();
                        // no-opt if we couldn't find a property to sort on
                        if (string.IsNullOrEmpty(propertyName))
                        {
                            return;
                        }

                        newSort = AvaloniaSortDescription.FromPath(propertyName, culture: collectionView.Culture);
                        owningGrid.DataConnection.SortDescriptions.Add(newSort);
                    }
                }

                // We've completed the sort, so send the Invoked event for the column header's automation peer

                /*if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked))
                 * {
                 *  AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(this);
                 *  if (peer != null)
                 *  {
                 *      peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked);
                 *  }
                 * }*/
            }
        }
Esempio n. 16
0
        private void MoveHorizontal(int count, InputModifiers modifiers)
        {
            var caretIndex = CaretIndex;

            if (caretIndex > TextDocument.TextLength)
            {
                caretIndex = TextDocument.TextLength;
            }

            if (caretIndex >= 0)
            {
                if ((modifiers & InputModifiers.Control) != 0)
                {
                    if (count > 0)
                    {
                        count =
                            TextUtilities.GetNextCaretPosition(TextDocument, caretIndex, TextUtilities.LogicalDirection.Forward,
                                                               TextUtilities.CaretPositioningMode.WordStartOrSymbol) - caretIndex;
                    }
                    else
                    {
                        count =
                            TextUtilities.GetNextCaretPosition(TextDocument, caretIndex, TextUtilities.LogicalDirection.Backward,
                                                               TextUtilities.CaretPositioningMode.WordStartOrSymbol) - caretIndex;
                    }

                    if (caretIndex + count <= TextDocument.TextLength && caretIndex + count >= 0)
                    {
                        CaretIndex += count;
                    }
                }
                else
                {
                    if (count > 0)
                    {
                        for (var i = 0; i < Math.Abs(count); i++)
                        {
                            var line = TextDocument.GetLineByOffset(caretIndex);

                            if (caretIndex == line.EndOffset)
                            {
                                if (line.NextLine != null)
                                {
                                    caretIndex = line.NextLine.Offset;
                                }
                            }
                            else
                            {
                                caretIndex = TextUtilities.GetNextCaretPosition(TextDocument, caretIndex, TextUtilities.LogicalDirection.Forward,
                                                                                TextUtilities.CaretPositioningMode.Normal);
                            }
                        }
                    }
                    else
                    {
                        for (var i = 0; i < Math.Abs(count); i++)
                        {
                            var line = TextDocument.GetLineByOffset(caretIndex);

                            if (caretIndex == line.Offset)
                            {
                                if (line.PreviousLine != null)
                                {
                                    caretIndex = line.PreviousLine.EndOffset;
                                }
                            }
                            else
                            {
                                caretIndex = TextUtilities.GetNextCaretPosition(TextDocument, caretIndex,
                                                                                TextUtilities.LogicalDirection.Backward, TextUtilities.CaretPositioningMode.Normal);
                            }
                        }
                    }

                    CaretIndex = caretIndex;
                }

                SetHighestColumn();
            }
        }
Esempio n. 17
0
 public static bool HasModifiers(this KeyEventArgs args, InputModifiers modifier) =>
 (args.Modifiers & modifier) == modifier;
Esempio n. 18
0
 KeyModifiers GetModifiers(InputModifiers modifiers) =>
 (KeyModifiers)((int)modifiers & (int)RawInputModifiers.KeyboardMask);
Esempio n. 19
0
 public RawDragEvent(IDragDropDevice inputDevice, RawDragEventType type,
                     IInputElement inputRoot, Point location, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
     : base(inputDevice, 0)
 {
     Type      = type;
     InputRoot = inputRoot;
     Location  = location;
     Data      = data;
     Effects   = effects;
     Modifiers = modifiers;
 }
Esempio n. 20
0
        private bool MouseWheel(IMouseDevice device, IInputRoot root, Point p, Vector delta, InputModifiers inputModifiers)
        {
            Contract.Requires <ArgumentNullException>(device != null);
            Contract.Requires <ArgumentNullException>(root != null);

            var hit = HitTest(root, p);

            if (hit != null)
            {
                var source = GetSource(hit);
                var e      = new PointerWheelEventArgs
                {
                    Device         = this,
                    RoutedEvent    = InputElement.PointerWheelChangedEvent,
                    Source         = source,
                    Delta          = delta,
                    InputModifiers = inputModifiers
                };

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

            return(false);
        }
Esempio n. 21
0
 private DragDropEffects DragEnter(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
 {
     _lastTarget = GetTarget(inputRoot, point);
     return(RaiseDragEvent(_lastTarget, inputRoot, point, DragDrop.DragEnterEvent, effects, data, modifiers));
 }
Esempio n. 22
0
 InputModifiers GetModifiers(InputModifiers modifiers) => modifiers | _pressedButtons;
Esempio n. 23
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);

                if (source != null)
                {
                    source.RaiseEvent(new PointerReleasedEventArgs
                    {
                        Device         = this,
                        RoutedEvent    = InputElement.PointerReleasedEvent,
                        Source         = source,
                        MouseButton    = button,
                        InputModifiers = inputModifiers
                    });
                }
            }
        }
Esempio n. 24
0
 public void Down(IInteractive target, MouseButton mouseButton = MouseButton.Left, Point position = default,
                  InputModifiers modifiers = default, int clickCount = 1)
 {
     Down(target, target, mouseButton, position, modifiers, clickCount);
 }
Esempio n. 25
0
        private bool MouseWheel(IMouseDevice device, IInputRoot root, Point p, Vector delta, InputModifiers inputModifiers)
        {
            var hit = HitTest(root, p);

            if (hit != null)
            {
                var source = GetSource(hit);
                var e = new PointerWheelEventArgs
                {
                    Device = this,
                    RoutedEvent = InputElement.PointerWheelChangedEvent,
                    Source = source,
                    Delta = delta,
                    InputModifiers = inputModifiers
                };

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

            return false;
        }
Esempio n. 26
0
 private void RaiseKeyEvent(TextBox textBox, Key key, InputModifiers inputModifiers)
 {
     textBox.RaiseEvent(new KeyEventArgs
     {
         RoutedEvent = InputElement.KeyDownEvent,
         Modifiers = inputModifiers,
         Key = key
     });
 }
Esempio n. 27
0
        /// <summary>
        /// Sets the currently focused element in the specified scope.
        /// </summary>
        /// <param name="scope">The focus scope.</param>
        /// <param name="element">The element to focus. May be null.</param>
        /// <param name="method">The method by which focus was changed.</param>
        /// <param name="modifiers">Any input modifiers active at the time of focus.</param>
        /// <remarks>
        /// If the specified scope is the current <see cref="Scope"/> then the keyboard focus
        /// will change.
        /// </remarks>
        public void SetFocusedElement(
            IFocusScope scope,
            IInputElement element,
            NavigationMethod method = NavigationMethod.Unspecified,
            InputModifiers modifiers = InputModifiers.None)
        {
            Contract.Requires<ArgumentNullException>(scope != null);

            _focusScopes[scope] = element;

            if (Scope == scope)
            {
                KeyboardDevice.Instance.SetFocusedElement(element, method, modifiers);
            }
        }
Esempio n. 28
0
 public static void GetMetaKeyState(InputModifiers modifiers, out bool ctrl, out bool shift, out bool alt)
 {
     ctrl  = (modifiers & InputModifiers.Control) == InputModifiers.Control;
     shift = (modifiers & InputModifiers.Shift) == InputModifiers.Shift;
     alt   = (modifiers & InputModifiers.Alt) == InputModifiers.Alt;
 }
Esempio n. 29
0
        private DragDropEffects DragOver(IInputRoot inputRoot, Point point, IDataObject data, DragDropEffects effects, InputModifiers modifiers)
        {
            var target = GetTarget(inputRoot, point);

            if (target == _lastTarget)
            {
                return(RaiseDragEvent(target, inputRoot, point, DragDrop.DragOverEvent, effects, data, modifiers));
            }

            try
            {
                if (_lastTarget != null)
                {
                    _lastTarget.RaiseEvent(new RoutedEventArgs(DragDrop.DragLeaveEvent));
                }
                return(RaiseDragEvent(target, inputRoot, point, DragDrop.DragEnterEvent, effects, data, modifiers));
            }
            finally
            {
                _lastTarget = target;
            }
        }
Esempio n. 30
0
        private void MouseMove(IMouseDevice device, IInputRoot root, Point p, InputModifiers inputModifiers)
        {
            IInputElement source;

            if (Captured == null)
            {
                source = SetPointerOver(this, root, p);
            }
            else
            {
                var elements = Captured.GetSelfAndVisualAncestors().OfType<IInputElement>().ToList();
                SetPointerOver(this, root, elements);
                source = Captured;
            }

            source.RaiseEvent(new PointerEventArgs
            {
                Device = this,
                RoutedEvent = InputElement.PointerMovedEvent,
                Source = source,
                InputModifiers = inputModifiers
            });
        }
Esempio n. 31
0
        private void MoveVertical(int count, InputModifiers modifiers)
        {
            var caretIndex = CaretIndex;

            if (caretIndex >= 0)
            {
                var currentPosition = TextDocument.GetLocation(caretIndex);

                if (currentPosition.Line + count > 0 && currentPosition.Line + count <= TextDocument.LineCount)
                {
                    var line = TextDocument.Lines[currentPosition.Line - 1 + count];

                    var col = line.EndOffset;

                    if (highestUserSelectedColumn <= line.Length)
                    {
                        col = highestUserSelectedColumn;
                    }

                    CaretIndex = TextDocument.GetOffset(currentPosition.Line + count, col);
                }
            }
        }
Esempio n. 32
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);

                if (source != null)
                {
                    source.RaiseEvent(new PointerWheelEventArgs
                    {
                        Device = this,
                        RoutedEvent = InputElement.PointerWheelChangedEvent,
                        Source = source,
                        Delta = delta,
                        InputModifiers = inputModifiers
                    });
                }
            }
        }
Esempio n. 33
0
        private DragDropEffects RaiseEventAndUpdateCursor(RawDragEventType type, IInputElement root, Point pt, InputModifiers modifiers)
        {
            _lastPosition = pt;

            RawDragEvent rawEvent = new RawDragEvent(_dragDrop, type, root, pt, _draggedData, _allowedEffects, modifiers);
            var          tl       = root.GetSelfAndVisualAncestors().OfType <TopLevel>().FirstOrDefault();

            tl.PlatformImpl?.Input(rawEvent);

            var effect = GetPreferredEffect(rawEvent.Effects & _allowedEffects, modifiers);

            UpdateCursor(root, effect);
            return(effect);
        }
        //TODO GroupSorting
        internal void ProcessSort(InputModifiers inputModifiers)
        {
            // if we can sort:
            //  - DataConnection.AllowSort is true, and
            //  - AllowUserToSortColumns and CanSort are true, and
            //  - OwningColumn is bound, and
            //  - SortDescriptionsCollection exists, and
            //  - the column's data type is comparable
            // then try to sort
            if (OwningColumn != null &&
                OwningGrid != null &&
                OwningGrid.EditingRow == null &&
                OwningColumn != OwningGrid.ColumnsInternal.FillerColumn &&
                OwningGrid.DataConnection.AllowSort &&
                OwningGrid.CanUserSortColumns &&
                OwningColumn.CanUserSort &&
                OwningGrid.DataConnection.SortDescriptions != null)
            {
                DataGrid owningGrid = OwningGrid;

                DataGridSortDescription newSort;

                KeyboardHelper.GetMetaKeyState(inputModifiers, out bool ctrl, out bool shift);

                DataGridSortDescription sort           = OwningColumn.GetSortDescription();
                IDataGridCollectionView collectionView = owningGrid.DataConnection.CollectionView;
                Debug.Assert(collectionView != null);
                using (collectionView.DeferRefresh())
                {
                    // if shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                    if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0)
                    {
                        owningGrid.DataConnection.SortDescriptions.Clear();
                    }

                    if (sort != null)
                    {
                        newSort = sort.SwitchSortDirection();

                        // changing direction should not affect sort order, so we replace this column's
                        // sort description instead of just adding it to the end of the collection
                        int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort);
                        if (oldIndex >= 0)
                        {
                            owningGrid.DataConnection.SortDescriptions.Remove(sort);
                            owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                        }
                        else
                        {
                            owningGrid.DataConnection.SortDescriptions.Add(newSort);
                        }
                    }
                    else
                    {
                        string propertyName = OwningColumn.GetSortPropertyName();
                        // no-opt if we couldn't find a property to sort on
                        if (string.IsNullOrEmpty(propertyName))
                        {
                            return;
                        }

                        newSort = DataGridSortDescription.FromPath(propertyName, culture: collectionView.Culture);
                        owningGrid.DataConnection.SortDescriptions.Add(newSort);
                    }
                }
            }
        }
Esempio n. 35
0
 public KeyGesture(Key key, InputModifiers modifiers)
 {
     Key          = key;
     KeyModifiers = (KeyModifiers)(((int)modifiers) & 0xf);
 }
Esempio n. 36
0
 private void SetSelectionForControlDelete(InputModifiers modifiers)
 {
     SelectionStart = CaretIndex;
     MoveHorizontal(1, modifiers);
     SelectionEnd = CaretIndex;
 }
Esempio n. 37
0
        private void MouseDown(IMouseDevice device, uint timestamp, IInputElement root, Point p, MouseButton button, InputModifiers inputModifiers)
        {
            var hit = HitTest(root, p);

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

                if (source != null)
                {
                    var settings = PerspexLocator.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,
                        MouseButton = button,
                        InputModifiers = inputModifiers
                    };

                    source.RaiseEvent(e);
                }
            }
        }
Esempio n. 38
0
 public RawTextInputEventArgs(IKeyboardDevice device, ulong timestamp, string text, InputModifiers modifiers) : base(device, timestamp)
 {
     Text      = text;
     Modifiers = modifiers;
 }
Esempio n. 39
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);

                if (source != null)
                {
                    source.RaiseEvent(new PointerReleasedEventArgs
                    {
                        Device = this,
                        RoutedEvent = InputElement.PointerReleasedEvent,
                        Source = source,
                        MouseButton = button,
                        InputModifiers = inputModifiers
                    });
                }
            }
        }
 private static void AddBinding(RoutedCommand command, InputModifiers modifiers, Key key,
                                EventHandler <ExecutedRoutedEventArgs> handler)
 {
     CommandBindings.Add(new RoutedCommandBinding(command, handler));
     KeyBindings.Add(TextAreaDefaultInputHandler.CreateKeyBinding(command, modifiers, key));
 }
Esempio n. 41
0
        private void MoveHorizontal(int count, InputModifiers modifiers)
        {
            var text = Text ?? string.Empty;
            var caretIndex = CaretIndex;

            if ((modifiers & InputModifiers.Control) != 0)
            {
                if (count > 0)
                {
                    count = StringUtils.NextWord(text, caretIndex, false) - caretIndex;
                }
                else
                {
                    count = StringUtils.PreviousWord(text, caretIndex, false) - caretIndex;
                }
            }

            CaretIndex = caretIndex += count;
        }
Esempio n. 42
0
        private void MouseDown(IMouseDevice device, uint timestamp, IInputElement root, Point p, MouseButton button, InputModifiers inputModifiers)
        {
            var hit = HitTest(root, p);

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

                if (source != null)
                {
                    var settings        = PerspexLocator.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,
                        MouseButton    = button,
                        InputModifiers = inputModifiers
                    };

                    source.RaiseEvent(e);
                }
            }
        }
Esempio n. 43
0
        private void MoveEnd(InputModifiers modifiers)
        {
            var text = Text ?? string.Empty;
            var caretIndex = CaretIndex;

            if ((modifiers & InputModifiers.Control) != 0)
            {
                caretIndex = text.Length;
            }
            else
            {
                var lines = _presenter.FormattedText.GetLines();
                var pos = 0;

                foreach (var line in lines)
                {
                    pos += line.Length;

                    if (pos > caretIndex)
                    {
                        if (pos < text.Length)
                        {
                            --pos;
                        }

                        break;
                    }
                }

                caretIndex = pos;
            }

            CaretIndex = caretIndex;
        }
Esempio n. 44
0
        private DragDropEffects RaiseDragEvent(Interactive target, IInputRoot inputRoot, Point point, RoutedEvent <DragEventArgs> routedEvent, DragDropEffects operation, IDataObject data, InputModifiers modifiers)
        {
            if (target == null)
            {
                return(DragDropEffects.None);
            }

            var p = inputRoot.TranslatePoint(point, target);

            if (!p.HasValue)
            {
                return(DragDropEffects.None);
            }

            var args = new DragEventArgs(routedEvent, data, target, p.Value, modifiers)
            {
                RoutedEvent = routedEvent,
                DragEffects = operation
            };

            target.RaiseEvent(args);
            return(args.DragEffects);
        }