// (c) Copyright Microsoft Corporation. // This source is subject to the Microsoft Public License (Ms-PL). // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. using System; using System.Collections.Generic; namespace Avalonia.Controls { /// /// Defines modes that indicates how DataGrid content is copied to the Clipboard. /// public enum DataGridClipboardCopyMode { /// /// Disable the DataGrid's ability to copy selected items as text. /// None, /// /// Enable the DataGrid's ability to copy selected items as text, but do not include /// the column header content as the first line in the text that gets copied to the Clipboard. /// ExcludeHeader, /// /// Enable the DataGrid's ability to copy selected items as text, and include /// the column header content as the first line in the text that gets copied to the Clipboard. /// IncludeHeader } /// /// This structure encapsulate the cell information necessary when clipboard content is prepared. /// public struct DataGridClipboardCellContent { private DataGridColumn _column; private object _content; private object _item; /// /// Creates a new DataGridClipboardCellValue structure containing information about a DataGrid cell. /// /// DataGrid row item containing the cell. /// DataGridColumn containing the cell. /// DataGrid cell value. public DataGridClipboardCellContent(object item, DataGridColumn column, object content) { this._item = item; this._column = column; this._content = content; } /// /// DataGridColumn containing the cell. /// public DataGridColumn Column { get { return _column; } } /// /// Cell content. /// public object Content { get { return _content; } } /// /// DataGrid row item containing the cell. /// public object Item { get { return _item; } } /// /// Field-by-field comparison to avoid reflection-based ValueType.Equals. /// /// DataGridClipboardCellContent to compare. /// True iff this and data are equal public override bool Equals(object obj) { if(obj is DataGridClipboardCellContent content) { return (((_column == content._column) && (_content == content._content)) && (_item == content._item)); } else { return false; } } /// /// Returns a deterministic hash code. /// /// Hash value. public override int GetHashCode() { return ((_column.GetHashCode() ^ _content.GetHashCode()) ^ _item.GetHashCode()); } /// /// Field-by-field comparison to avoid reflection-based ValueType.Equals. /// /// The first DataGridClipboardCellContent. /// The second DataGridClipboardCellContent. /// True iff clipboardCellContent1 and clipboardCellContent2 are equal. public static bool operator ==(DataGridClipboardCellContent clipboardCellContent1, DataGridClipboardCellContent clipboardCellContent2) { return (((clipboardCellContent1._column == clipboardCellContent2._column) && (clipboardCellContent1._content == clipboardCellContent2._content)) && (clipboardCellContent1._item == clipboardCellContent2._item)); } /// /// Field-by-field comparison to avoid reflection-based ValueType.Equals. /// /// The first DataGridClipboardCellContent. /// The second DataGridClipboardCellContent. /// True iff clipboardCellContent1 and clipboardCellContent2 are NOT equal. public static bool operator !=(DataGridClipboardCellContent clipboardCellContent1, DataGridClipboardCellContent clipboardCellContent2) { if ((clipboardCellContent1._column == clipboardCellContent2._column) && (clipboardCellContent1._content == clipboardCellContent2._content)) { return (clipboardCellContent1._item != clipboardCellContent2._item); } return true; } } /// /// This class encapsulates a selected row's information necessary for the CopyingRowClipboardContent event. /// public class DataGridRowClipboardEventArgs : EventArgs { private List _clipboardRowContent; private bool _isColumnHeadersRow; private object _item; /// /// Creates a DataGridRowClipboardEventArgs object and initializes the properties. /// /// The row's associated data item. /// Whether or not this EventArgs is for the column headers. internal DataGridRowClipboardEventArgs(object item, bool isColumnHeadersRow) { _isColumnHeadersRow = isColumnHeadersRow; _item = item; } /// /// This list should be used to modify, add ot remove a cell content before it gets stored into the clipboard. /// public List ClipboardRowContent { get { if (_clipboardRowContent == null) { _clipboardRowContent = new List(); } return _clipboardRowContent; } } /// /// This property is true when the ClipboardRowContent represents column headers, in which case the Item is null. /// public bool IsColumnHeadersRow { get { return _isColumnHeadersRow; } } /// /// DataGrid row item used for proparing the ClipboardRowContent. /// public object Item { get { return _item; } } } }