From bb86894aa2057493f3d840b443e5e67cf712da16 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Mon, 22 Oct 2018 13:47:50 +0800 Subject: [PATCH] Add CellPointerPressed event + Make avalonia reference nightly-invariant --- .../Avalonia.DataGrid.Themes.Default.csproj | 2 +- .../Avalonia.DataGrid.csproj | 2 +- src/Avalonia.DataGrid/DataGrid.cs | 13 +++ src/Avalonia.DataGrid/DataGridCell.cs | 85 +++++++++---------- src/Avalonia.DataGrid/EventArgs.cs | 47 ++++++++++ 5 files changed, 104 insertions(+), 45 deletions(-) diff --git a/src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj b/src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj index b6c808893e..d6e449a854 100644 --- a/src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj +++ b/src/Avalonia.DataGrid.Themes.Default/Avalonia.DataGrid.Themes.Default.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/Avalonia.DataGrid/Avalonia.DataGrid.csproj b/src/Avalonia.DataGrid/Avalonia.DataGrid.csproj index f1f6eb3a09..b0189a4994 100644 --- a/src/Avalonia.DataGrid/Avalonia.DataGrid.csproj +++ b/src/Avalonia.DataGrid/Avalonia.DataGrid.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/Avalonia.DataGrid/DataGrid.cs b/src/Avalonia.DataGrid/DataGrid.cs index 4ac6c6424b..33b4978596 100644 --- a/src/Avalonia.DataGrid/DataGrid.cs +++ b/src/Avalonia.DataGrid/DataGrid.cs @@ -1246,6 +1246,11 @@ namespace Avalonia.Controls /// public event EventHandler CellEditEnding; + /// + /// Occurs when cell is mouse-pressed. + /// + public event EventHandler CellPointerPressed; + /// /// Occurs when the /// property of a column changes. @@ -2222,6 +2227,14 @@ namespace Avalonia.Controls { CellEditEnding?.Invoke(this, e); } + + /// + /// Raises the CellPointerPressed event. + /// + internal virtual void OnCellPointerPressed(DataGridCellPointerPressedEventArgs e) + { + CellPointerPressed?.Invoke(this, e); + } /// /// Raises the CurrentCellChanged event. diff --git a/src/Avalonia.DataGrid/DataGridCell.cs b/src/Avalonia.DataGrid/DataGridCell.cs index bec178d5bf..0bc5818679 100644 --- a/src/Avalonia.DataGrid/DataGridCell.cs +++ b/src/Avalonia.DataGrid/DataGridCell.cs @@ -86,7 +86,7 @@ namespace Avalonia.Controls OwningGrid.CurrentSlot == OwningRow.Slot; } } - + private bool IsEdited { get @@ -95,7 +95,7 @@ namespace Avalonia.Controls OwningGrid.EditingColumnIndex == ColumnIndex; } } - + private bool IsMouseOver { get @@ -127,7 +127,7 @@ namespace Avalonia.Controls UpdatePseudoClasses(); _rightGridLine = e.NameScope.Find(DATAGRIDCELL_elementRightGridLine); - if(_rightGridLine != null && OwningColumn == null) + if (_rightGridLine != null && OwningColumn == null) { // Turn off the right GridLine for filler cells _rightGridLine.IsVisible = false; @@ -160,23 +160,22 @@ namespace Avalonia.Controls //TODO TabStop private void DataGridCell_PointerPressed(PointerPressedEventArgs e) { - if(e.MouseButton != MouseButton.Left) - { - return; - } - // OwningGrid is null for TopLeftHeaderCell and TopRightHeaderCell because they have no OwningRow if (OwningGrid != null) { - if (!e.Handled) - //if (!e.Handled && OwningGrid.IsTabStop) - { - OwningGrid.Focus(); - } - if (OwningRow != null) + OwningGrid.OnCellPointerPressed(new DataGridCellPointerPressedEventArgs(this, OwningRow, OwningColumn, e)); + if (e.MouseButton == MouseButton.Left) { - e.Handled = OwningGrid.UpdateStateOnMouseLeftButtonDown(e, ColumnIndex, OwningRow.Slot, !e.Handled); - OwningGrid.UpdatedStateOnMouseLeftButtonDown = true; + if (!e.Handled) + //if (!e.Handled && OwningGrid.IsTabStop) + { + OwningGrid.Focus(); + } + if (OwningRow != null) + { + e.Handled = OwningGrid.UpdateStateOnMouseLeftButtonDown(e, ColumnIndex, OwningRow.Slot, !e.Handled); + OwningGrid.UpdatedStateOnMouseLeftButtonDown = true; + } } } } @@ -262,7 +261,7 @@ namespace Avalonia.Controls _rightGridLine.Fill = OwningGrid.VerticalGridLinesBrush; } - bool newVisibility = + bool newVisibility = (OwningGrid.GridLinesVisibility == DataGridGridLinesVisibility.Vertical || OwningGrid.GridLinesVisibility == DataGridGridLinesVisibility.All) && (OwningGrid.ColumnsInternal.FillerColumn.IsActive || OwningColumn != lastVisibleColumn); @@ -275,7 +274,7 @@ namespace Avalonia.Controls private void OnOwningColumnSet(DataGridColumn column) { - if(column == null) + if (column == null) { Classes.Clear(); } @@ -303,34 +302,34 @@ namespace Avalonia.Controls [TemplateVisualState(Name = VisualStates.StateValid, GroupName = VisualStates.GroupValidation)] public sealed partial class DataGridCell : ContentControl */ - - //TODO Styles - /// - /// Ensures that the correct Style is applied to this object. - /// - /// Caller's previous associated Style - /*internal void EnsureStyle(Style previousStyle) + + //TODO Styles + /// + /// Ensures that the correct Style is applied to this object. + /// + /// Caller's previous associated Style + /*internal void EnsureStyle(Style previousStyle) + { + if (Style != null + && (OwningColumn == null || Style != OwningColumn.CellStyle) + && (OwningGrid == null || Style != OwningGrid.CellStyle) + && (Style != previousStyle)) { - if (Style != null - && (OwningColumn == null || Style != OwningColumn.CellStyle) - && (OwningGrid == null || Style != OwningGrid.CellStyle) - && (Style != previousStyle)) - { - return; - } + return; + } - Style style = null; - if (OwningColumn != null) - { - style = OwningColumn.CellStyle; - } - if (style == null && OwningGrid != null) - { - style = OwningGrid.CellStyle; - } - SetStyleWithType(style); - } */ + Style style = null; + if (OwningColumn != null) + { + style = OwningColumn.CellStyle; + } + if (style == null && OwningGrid != null) + { + style = OwningGrid.CellStyle; + } + SetStyleWithType(style); + } */ } diff --git a/src/Avalonia.DataGrid/EventArgs.cs b/src/Avalonia.DataGrid/EventArgs.cs index 5136020f4d..c96d9d8dfe 100644 --- a/src/Avalonia.DataGrid/EventArgs.cs +++ b/src/Avalonia.DataGrid/EventArgs.cs @@ -3,6 +3,7 @@ // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. +using Avalonia.Input; using Avalonia.Interactivity; using System; using System.ComponentModel; @@ -171,6 +172,52 @@ namespace Avalonia.Controls #endregion Properties } + + /// + /// Provides information after the cell has been pressed. + /// + public class DataGridCellPointerPressedEventArgs : EventArgs + { + /// + /// Instantiates a new instance of this class. + /// + /// The cell that has been pressed. + /// The row container of the cell that has been pressed. + /// The column of the cell that has been pressed. + /// The pointer action that has been taken. + public DataGridCellPointerPressedEventArgs(DataGridCell cell, + DataGridRow row, + DataGridColumn column, + PointerPressedEventArgs e) + { + Cell = cell; + Row = row; + Column = column; + PointerPressedEventArgs = e; + } + + /// + /// The cell that has been pressed. + /// + public DataGridCell Cell { get; } + + /// + /// The row container of the cell that has been pressed. + /// + public DataGridRow Row { get; } + + /// + /// The column of the cell that has been pressed. + /// + public DataGridColumn Column { get; } + + /// + /// The pointer action that has been taken. + /// + public PointerPressedEventArgs PointerPressedEventArgs { get; } + } + + /// /// Provides information just before a cell exits editing mode. ///