/// <summary> /// Convert a range and an array of string into a string. Normally using a tab delimited for columns and a LineFeed for rows. /// </summary> /// <returns></returns> protected static string[,] DataToStringArray(GridVirtual sourceGrid, GridRange range) { int numberOfRows = range.End.Row - range.Start.Row + 1; int numberOfCols = range.End.Column - range.Start.Column + 1; string[,] values = new string[numberOfRows, numberOfCols]; int arrayRow = 0; for (int r = range.Start.Row; r <= range.End.Row; r++, arrayRow++) { int arrayCol = 0; for (int c = range.Start.Column; c <= range.End.Column; c++, arrayCol++) { String val = String.Empty; Position posCell = new Position(r, c); Cells.ICellVirtual cell = sourceGrid.GetCell(posCell); CellContext cellContext = new CellContext(sourceGrid, posCell, cell); if (cell != null && cell.Editor != null && cell.Editor.IsStringConversionSupported()) { values[arrayRow, arrayCol] = cell.Editor.ValueToString(cell.Model.ValueModel.GetValue(cellContext)); } else if (cell != null) { values[arrayRow, arrayCol] = cellContext.DisplayText; } } } return(values); }
public void Swap(int rowIndex1, int rowIndex2) { var wholeGrid = new GridRange(rowIndex1, 0, rowIndex1, int.MaxValue); var wholeGrid2 = new GridRange(rowIndex2, 0, rowIndex2, int.MaxValue); var firstRanes = this.SpannedRangesCollection.GetRanges(wholeGrid); var secondRanges = this.SpannedRangesCollection.GetRanges(wholeGrid2); foreach (var rangineInFirst in firstRanes) { if (rangineInFirst.RowsCount > 1) { throw new SourceGridException("Can not swap rows if they contain spanned ranged which extend more than one row"); } var newRange = new GridRange(rowIndex2, rangineInFirst.Start.Column, rowIndex2, rangineInFirst.End.Column); this.SpannedRangesCollection.Update(rangineInFirst, newRange); } foreach (var rangesInSecond in secondRanges) { if (rangesInSecond.RowsCount > 1) { throw new SourceGridException("Can not swap rows if they contain spanned ranged which extend more than one row"); } var newRange = new GridRange(rowIndex1, rangesInSecond.Start.Column, rowIndex1, rangesInSecond.End.Column); this.SpannedRangesCollection.Update(rangesInSecond, newRange); } }
public StandardHiddenRowCoordinator(RowsBase rows) { this.m_rows = rows; rows.RowVisibilityChanged += delegate(int rowIndex, bool becameVisible) { var range = new GridRange(rowIndex, 0, rowIndex, 1); if (becameVisible) { m_rowMerger.RemoveRange(range); } else { m_rowMerger.AddRange(range); } }; rows.RowVisibilityChanged += delegate(int rowIndex, bool becameVisible) { if (becameVisible == true) { m_totalHiddenRows -= 1; } else { m_totalHiddenRows += 1; } if (m_totalHiddenRows < 0) { throw new SourceGridException("Total hidden rows becamse less than 0. This indicates a bug"); } }; }
private void EnsureNoSpannedCellsExist(int row, int col, Cells.ICell p_cell) { var spanRange = new GridRange(row, col, row + p_cell.RowSpan - 1, col + p_cell.ColumnSpan - 1); var ranges = spannedCellReferences.SpannedRangesCollection.GetRanges( spanRange); if (ranges.Count == 0) { return; } var start = new Position(row, col); foreach (var range in ranges) { if (start.Equals(range.Start) == true) { continue; } Cells.ICell existingSpannedCell = this[range.Start]; if (existingSpannedCell == null) { throw new ArgumentException("internal error. please report this bug to developers"); } throw new OverlappingCellException(string.Format( "Given cell at position ({0}, {1}), " + "intersects with another cell " + "at position ({2}, {3}) '{4}'", row, col, existingSpannedCell.Row.Index, existingSpannedCell.Column.Index, existingSpannedCell.DisplayText)); } }
public void ShrinkOrRemoveSpannedColumns(int startIndex, int count) { const int startRow = 0; const int endRow = 1000; var removeRange = new GridRange(startRow, startIndex, endRow, startIndex + count - 1); foreach (var range in this.SpannedRangesCollection.ToArray()) { var intersection = range.Intersect(removeRange); if (intersection.IsEmpty() == false) { var cell = m_grid[range.Start]; var span = cell.ColumnSpan - count; if (span <= 1 && cell.ColumnSpan <= 1) { cell.ColumnSpan = 1; this.SpannedRangesCollection.Remove(range); } else { cell.ColumnSpan = span; } } } }
public RangePaintEventArgs(GridVirtual grid, DevAge.Drawing.GraphicsCache graphicsCache, GridRange drawingRange) { mGrid = grid; mGraphicsCache = graphicsCache; mDrawingRange = drawingRange; }
/// <summary> /// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range. /// </summary> /// <param name="p_Range1"></param> /// <param name="p_Range2"></param> /// <returns></returns> public static RangeRegion Union(GridRange p_Range1, GridRange p_Range2) { RangeRegion range = new RangeRegion(); range.Add(p_Range1); range.Add(p_Range2); return(range); }
public static GridRange From(Position startPosition, int rowCount, int colCount) { var range = new GridRange(startPosition); range.RowsCount = rowCount; range.ColumnsCount = colCount; return(range); }
public SortRangeRowsEventArgs(GridRange p_Range, int keyColumn, bool p_bAscending, IComparer p_CellComparer) { m_Range = p_Range; mKeyColumn = keyColumn; m_bAscending = p_bAscending; m_CellComparer = p_CellComparer; }
/// <summary> /// Constructor /// </summary> public Grid() { this.SuspendLayout(); this.Name = "Grid"; spannedCellReferences = new SpannedCellRangesController( this, new QuadTreeRangesList(GridRange.From(new Position(0, 0), 4, 4))); this.ResumeLayout(false); }
/// <summary> /// Constructor /// </summary> /// <param name="addedRange"></param> /// <param name="removedRange"></param> public RangeRegionChangedEventArgs(GridRange addedRange, GridRange removedRange) { if (addedRange.IsEmpty() == false) { this.addedRange = new RangeRegion(addedRange); } if (removedRange.IsEmpty() == false) { this.removedRange = new RangeRegion(removedRange); } }
public void Update(GridRange oldRange, GridRange newRange) { var range = base.QueryFirst(oldRange.Start); if (range == null) { throw new RangeNotFoundException(); } Remove(oldRange); Insert(newRange); }
/// <summary> /// Updates range whose start position matches. /// If no matches found, an exception is thrown /// </summary> /// <param name="newRange"></param> public void Update(GridRange newRange) { GridRange?index = this.SpannedRangesCollection.FindRangeWithStart(newRange.Start); if (index == null) { throw new ArgumentException(string.Format( "Could not find a spanned cell range with the same starting point as {0}", newRange.Start)); } this.SpannedRangesCollection.Update(index.Value, newRange); }
private static int GetVisibleColumnCount(GridVirtual sourceGrid, GridRange sourceRange) { int visibleCount = 0; for (int c = sourceRange.Start.Column; c <= sourceRange.End.Column; c++) { if (sourceGrid.Columns.IsColumnVisible(c)) { visibleCount++; } } return(visibleCount); }
public void MoveUpSpannedRanges(int startIndex, int moveCount) { foreach (var range in this.SpannedRangesCollection.ToArray()) { if (range.Start.Row <= startIndex) { continue; } var newRange = new GridRange(range.Start.Row - moveCount, range.Start.Column, range.End.Row - moveCount, range.End.Column); this.SpannedRangesCollection.Update(range, newRange); } }
/// <summary> /// Convert a string buffer into a Range object and an array of string. /// </summary> /// <param name="data"></param> /// <param name="range"></param> /// <param name="values"></param> protected virtual void StringToData(string data, out GridRange range, out object[,] values) { //tolgo uno dei due caratteri di a capo per usare lo split data = data.Replace("\x0D\x0A", "\x0A"); string[] rowsData = data.Split('\x0A', '\x0D'); //Check if the last row is not null (some application put a last \n character at the end of the cells, for example excel) int rows = rowsData.Length; if (rows > 0 && (rowsData[rows - 1] == null || rowsData[rows - 1].Length == 0)) { rows--; } if (rows == 0) { range = GridRange.Empty; values = new string[0, 0]; return; } //Calculate the columns based on the first rows! Note: probably is better to calculate the maximum columns. string[] firstColumnsData = rowsData[0].Split('\t'); int cols = firstColumnsData.Length; range = new GridRange(0, 0, rows - 1, cols - 1); values = new string[rows, cols]; int arrayRow = 0; for (int r = range.Start.Row; r < range.Start.Row + rows; r++, arrayRow++) { string rowData = rowsData[arrayRow]; string[] columnsData = rowData.Split('\t'); int arrayCol = 0; for (int c = range.Start.Column; c <= range.End.Column; c++, arrayCol++) { if (arrayCol < columnsData.Length) { values[arrayRow, arrayCol] = columnsData[arrayCol]; } else { values[arrayRow, arrayCol] = ""; } } } }
/// <summary> /// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range. /// </summary> /// <param name="p_Range1"></param> /// <param name="p_Range2"></param> /// <returns></returns> public static GridRange GetBounds(GridRange p_Range1, GridRange p_Range2) { if (p_Range1.IsEmpty()) { return(p_Range2); } else if (p_Range2.IsEmpty()) { return(p_Range1); } else { return(new GridRange(Position.Min(p_Range1.Start, p_Range2.Start), Position.Max(p_Range1.End, p_Range2.End), false)); } }
/// <summary> /// Load the specified range data into a string array. This method use the cell editor to get the value. /// </summary> /// <param name="sourceGrid"></param> /// <param name="sourceRange"></param> /// <param name="cutMode">Cut mode. Can be used to remove the data from the source when pasting it to the destination or immediately.</param> public static RangeData LoadData(GridVirtual sourceGrid, GridRange sourceRange, CutMode cutMode) { RangeData data = new RangeData(sourceGrid); //mCutMode = cutMode; data.mSourceRange = sourceRange; data.mSourceValues = new object[sourceRange.RowsCount, GetVisibleColumnCount(sourceGrid, sourceRange)]; int arrayRow = 0; for (int r = sourceRange.Start.Row; r <= sourceRange.End.Row; r++, arrayRow++) { int arrayCol = 0; for (int c = sourceRange.Start.Column; c <= sourceRange.End.Column; c++) { if (sourceGrid.Columns.IsColumnVisible(c) == false) { continue; } Position posCell = new Position(r, c); Cells.ICellVirtual cell = sourceGrid.GetCell(posCell); CellContext cellContext = new CellContext(sourceGrid, posCell, cell); /*if (cell != null && cell.Editor != null && cell.Editor.IsStringConversionSupported()) * data.mSourceValues[arrayRow, arrayCol] = cell.Editor.ValueToString( cell.Model.ValueModel.GetValue(cellContext) ); * else if (cell != null) * data.mSourceValues[arrayRow, arrayCol] = cellContext.DisplayText;*/ if (cell != null) { data.mSourceValues[arrayRow, arrayCol] = cellContext.Value; } arrayCol++; } } //Cut Data if (cutMode == CutMode.CutImmediately && sourceGrid != null) { sourceGrid.ClearValues(new RangeRegion(sourceRange)); } data.mClipboardDataObject = new System.Windows.Forms.DataObject(); data.mClipboardDataObject.SetData(RANGEDATA_FORMAT, data); string[,] values = DataToStringArray(sourceGrid, data.mSourceRange); data.mClipboardDataObject.SetData(typeof(string), StringArrayToString(values)); return(data); }
/// <summary> /// Adds or updates given range. /// Updates range only when existing range with given start position is found /// </summary> /// <param name="newRange"></param> public void UpdateOrAdd(GridRange newRange) { if (newRange.Equals(GridRange.Empty)) { throw new ArgumentException("Range can not be empty"); } GridRange?index = this.SpannedRangesCollection.FindRangeWithStart(newRange.Start); if (index == null) { this.SpannedRangesCollection.Add(newRange); } else { this.SpannedRangesCollection.Update(GridRange.FromPosition(newRange.Start), newRange); } }
public RowInfoCollectoinHiddenRowCoordinator(RowInfoCollection rows) : base(rows) { // when rows are removed, check if some of them were hidden // if yes, inform hidden row coordinator that they were removed rows.RowsRemoving += delegate(object sender, IndexRangeEventArgs e) { for (int i = 0; i < e.Count; i++) { var index = i + e.StartIndex; if (rows.IsRowVisible(index) == false) { base.m_totalHiddenRows -= 1; } } var range = new GridRange(e.StartIndex, 0, e.StartIndex + e.Count, 1); base.m_rowMerger.RemoveRange(range); }; }
/// <summary> /// Returns the intersection between the 2 Range. If one of the range is empty then the return is empty. /// </summary> /// <param name="p_Range1"></param> /// <param name="p_Range2"></param> /// <returns></returns> public static GridRange Intersect(GridRange p_Range1, GridRange p_Range2) { if (p_Range1.IsEmpty() || p_Range2.IsEmpty()) { return(GridRange.Empty); } Position startNew = Position.Max(p_Range1.Start, p_Range2.Start); Position endNew = Position.Min(p_Range1.End, p_Range2.End); if (startNew.Column > endNew.Column || startNew.Row > endNew.Row) { return(GridRange.Empty); } else { return(new GridRange(startNew, endNew, false)); } }
public GridRange FindDestinationRange(GridVirtual destinationGrid, Position dropDestination) { if (dropDestination.IsEmpty()) { return(GridRange.Empty); } Position destinationStart = new Position(dropDestination.Row + (mSourceRange.Start.Row - mStartDragPosition.Row), dropDestination.Column + (mSourceRange.Start.Column - mStartDragPosition.Column)); destinationStart = Position.Max(destinationStart, new Position(0, 0)); GridRange destination = mSourceRange; destination.MoveTo(destinationStart); destination = destination.Intersect(destinationGrid.CompleteRange); return(destination); }
/// <summary> /// If the cell is not linked to a grid the result is not accurate (Font can be null). Call InternalGetRequiredSize with RowSpan and ColSpan = 1. /// </summary> /// <param name="maxLayoutArea">SizeF structure that specifies the maximum layout area for the text. If width or height are zero the value is set to a default maximum value.</param> /// <returns></returns> public System.Drawing.Size Measure(System.Drawing.Size maxLayoutArea) { if (Cell == null) { return(System.Drawing.Size.Empty); } if (Grid == null) { throw new SourceGridException("Grid is null"); } System.Drawing.Size requiredSize = Cell.View.Measure(this, maxLayoutArea); GridRange range = Grid.PositionToCellRange(Position); //Approximate the width and Height value if ColSpan or RowSpan are grater than 1 // round to the greater value requiredSize.Width = (int)Math.Ceiling((float)requiredSize.Width / range.ColumnsCount); requiredSize.Height = (int)Math.Ceiling((float)requiredSize.Height / range.RowsCount); return(requiredSize); }
protected override void PaintCell(DevAge.Drawing.GraphicsCache graphics, CellContext cellContext, RectangleF drawRectangle) { GridRange cellRange = PositionToCellRange(cellContext.Position); if (cellRange.ColumnsCount == 1 && cellRange.RowsCount == 1) { base.PaintCell(graphics, cellContext, drawRectangle); } else //Row/Col Span > 1 { // I draw the merged cell only if not already drawn otherwise // drawing the same cell can cause some problem when using // special drawing code (for example semi transparent background) if (mDrawnRange.Contains(cellRange) == false) { Rectangle spanRect = RangeToRectangle(cellRange); base.PaintCell(graphics, cellContext, spanRect); mDrawnRange.Add(cellRange); } } }
/// <summary> /// This method converts a Position to the real range of the cell. This is usefull when RowSpan or ColumnSpan is greater than 1. /// </summary> /// <returns></returns> public override GridRange RangeToCellRange(GridRange range) { int x = range.Start.Column; int x1 = range.End.Column; int y = range.Start.Row; int y1 = range.End.Row; for (int x2 = range.Start.Column; x2 <= range.End.Column; x2++) { for (int y2 = range.Start.Row; y2 <= range.End.Row; y2++) { var p = new Position(y2, x2); GridRange range2 = PositionToCellRange(p); if (range2.IsEmpty()) { range2 = new GridRange(p, p); } if (range2.Start.Column < x) { x = range2.Start.Column; } if (range2.End.Column > x1) { x1 = range2.End.Column; } if (range2.Start.Row < y) { y = range2.Start.Row; } if (range2.End.Row > y1) { y1 = range2.End.Row; } } } return(new GridRange(y, x, y1, x1)); }
public System.Collections.Generic.List <GridRange> GetRanges(GridRange range) { return(base.Query(range)); }
public SelectionChangeEventArgs(SelectionChangeEventType p_Type, GridRange p_Range) { m_Type = p_Type; m_Range = p_Range; }
public RangeCancelEventArgs(GridRange p_GridRange) : base(p_GridRange) { }
public RangeEventArgs(GridRange p_GridRange) { m_GridRange = p_GridRange; }
public void LoadData(GridVirtual sourceGrid, GridRange sourceRange, Position startDragPosition, CutMode cutMode) { LoadData(sourceGrid, sourceRange, Position.Empty, cutMode); }