From 528a3f7c69ed20f8959cea08e825bdc05330e2fe Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 30 Apr 2025 22:06:15 -0700 Subject: [PATCH 1/3] Allow pen secondary button drag --- .../Primitives/TreeDataGridRow.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs b/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs index 7f345e48..f248cbd3 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs @@ -152,9 +152,17 @@ protected override void OnPointerMoved(PointerEventArgs e) { base.OnPointerMoved(e); - var delta = e.GetPosition(this) - _mouseDownPosition; + var currentPoint = e.GetCurrentPoint(this); + var delta = currentPoint.Position - _mouseDownPosition; - if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed || + var inputSupportsDrag = currentPoint.Pointer.Type switch + { + PointerType.Mouse => currentPoint.Properties.IsLeftButtonPressed, + PointerType.Pen => currentPoint.Properties.IsRightButtonPressed, + _ => false + }; + + if (!inputSupportsDrag || e.Handled || Math.Abs(delta.X) < DragDistance && Math.Abs(delta.Y) < DragDistance || _mouseDownPosition == s_InvalidPoint) From 32f742b4e75bf3257b9ef90a756189d66cc8dbec Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 30 Apr 2025 22:06:31 -0700 Subject: [PATCH 2/3] Allow pen secondary button selection on press --- .../Selection/TreeDataGridCellSelectionModel.cs | 9 ++++++++- .../Selection/TreeDataGridRowSelectionModel.cs | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs index 19d709ef..9882a02d 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs @@ -140,12 +140,19 @@ void ITreeDataGridSelectionInteraction.OnPointerPressed(TreeDataGrid sender, Poi // Select a cell on pointer pressed if: // // - It's a mouse click, not touch: we don't want to select on touch scroll gesture start + // - It's a pen secondary button press, we don't want to select on primary button scroll gesture start // - The cell isn't already selected: we don't want to deselect an existing multiple selection // if the user is trying to drag multiple cells // // Otherwise select on pointer release. + var inputSupportsSelection = e.Pointer.Type switch + { + PointerType.Mouse => true, + PointerType.Pen => e.GetCurrentPoint(null).Properties.IsRightButtonPressed, + _ => false + }; if (!e.Handled && - e.Pointer.Type == PointerType.Mouse && + inputSupportsSelection && e.Source is Control source && sender.TryGetCell(source, out var cell) && !IsSelected(cell.ColumnIndex, cell.RowIndex)) diff --git a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs index ec112459..095549f4 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs @@ -318,12 +318,19 @@ void ITreeDataGridSelectionInteraction.OnPointerPressed(TreeDataGrid sender, Poi // Select a row on pointer pressed if: // // - It's a mouse click, not touch: we don't want to select on touch scroll gesture start + // - It's a pen secondary button press, we don't want to select on primary button scroll gesture start // - The row isn't already selected: we don't want to deselect an existing multiple selection // if the user is trying to drag multiple rows // // Otherwise select on pointer release. + var inputSupportsSelection = e.Pointer.Type switch + { + PointerType.Mouse => true, + PointerType.Pen => e.GetCurrentPoint(null).Properties.IsRightButtonPressed, + _ => false + }; if (!e.Handled && - e.Pointer.Type == PointerType.Mouse && + inputSupportsSelection && e.Source is Control source && sender.TryGetRow(source, out var row) && _source.Rows.RowIndexToModelIndex(row.RowIndex) is { } modelIndex && From 5118be694ac7dd38480f724c186454f80c863f38 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 30 Apr 2025 22:09:15 -0700 Subject: [PATCH 3/3] Rename field --- .../Primitives/TreeDataGridRow.cs | 4 ++-- .../Selection/TreeDataGridCellSelectionModel.cs | 4 ++-- .../Selection/TreeDataGridRowSelectionModel.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs b/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs index f248cbd3..c9ad891a 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Primitives/TreeDataGridRow.cs @@ -155,14 +155,14 @@ protected override void OnPointerMoved(PointerEventArgs e) var currentPoint = e.GetCurrentPoint(this); var delta = currentPoint.Position - _mouseDownPosition; - var inputSupportsDrag = currentPoint.Pointer.Type switch + var pointerSupportsDrag = currentPoint.Pointer.Type switch { PointerType.Mouse => currentPoint.Properties.IsLeftButtonPressed, PointerType.Pen => currentPoint.Properties.IsRightButtonPressed, _ => false }; - if (!inputSupportsDrag || + if (!pointerSupportsDrag || e.Handled || Math.Abs(delta.X) < DragDistance && Math.Abs(delta.Y) < DragDistance || _mouseDownPosition == s_InvalidPoint) diff --git a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs index 9882a02d..4f887dbd 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridCellSelectionModel.cs @@ -145,14 +145,14 @@ void ITreeDataGridSelectionInteraction.OnPointerPressed(TreeDataGrid sender, Poi // if the user is trying to drag multiple cells // // Otherwise select on pointer release. - var inputSupportsSelection = e.Pointer.Type switch + var pointerSupportSelectionOnPress = e.Pointer.Type switch { PointerType.Mouse => true, PointerType.Pen => e.GetCurrentPoint(null).Properties.IsRightButtonPressed, _ => false }; if (!e.Handled && - inputSupportsSelection && + pointerSupportSelectionOnPress && e.Source is Control source && sender.TryGetCell(source, out var cell) && !IsSelected(cell.ColumnIndex, cell.RowIndex)) diff --git a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs index 095549f4..bd4da5d7 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Selection/TreeDataGridRowSelectionModel.cs @@ -323,14 +323,14 @@ void ITreeDataGridSelectionInteraction.OnPointerPressed(TreeDataGrid sender, Poi // if the user is trying to drag multiple rows // // Otherwise select on pointer release. - var inputSupportsSelection = e.Pointer.Type switch + var pointerSupportSelectionOnPress = e.Pointer.Type switch { PointerType.Mouse => true, PointerType.Pen => e.GetCurrentPoint(null).Properties.IsRightButtonPressed, _ => false }; if (!e.Handled && - inputSupportsSelection && + pointerSupportSelectionOnPress && e.Source is Control source && sender.TryGetRow(source, out var row) && _source.Rows.RowIndexToModelIndex(row.RowIndex) is { } modelIndex &&