/// <summary> /// Remove all the cells excluse the specified range /// </summary> /// <param name="pRangeToLeave"></param> public void Clear(Range pRangeToLeave) { RangeRegion region = new RangeRegion(this); region.Remove(pRangeToLeave); Remove(region); }
/// <summary> /// Prende un range che è già stato filtrato con solo le celle presenti nell'attuale range /// </summary> /// <param name="pRange"></param> /// <returns></returns> private bool InternalRemove(RangeRegion pRange) { pRange = Intersect(pRange); if (pRange.IsEmpty()) { return(true); //il range non è presente } pRange.m_bValidated = true; RangeRegionCancelEventArgs e = new RangeRegionCancelEventArgs(pRange); OnRemovingRange(e); //calling this method the range can change if (e.Cancel) { return(false); } if (pRange.m_bValidated == false) { pRange = Intersect(pRange); if (pRange.IsEmpty()) { return(true); //il range non è presente } } m_RangeCollection = Exclude(pRange).m_RangeCollection; OnRemovedRange(e); m_bValidated = false; return(true); }
/// <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(Range p_Range1, Range p_Range2) { RangeRegion range = new RangeRegion(); range.Add(p_Range1); range.Add(p_Range2); return(range); }
public HighlightedRange(GridVirtual grid) { mGrid = grid; Grid.RangePaint += new RangePaintEventHandler(Grid_RangePaint); Region = new RangeRegion(); }
public void GetRowsIndex() { RangeRegion region = new RangeRegion(); region.Add(new Range(0, 0, 0, 0)); region.Add(new Range(2, 2, 2, 2)); int[] indexes = region.GetRowsIndex(); Assert.AreEqual(2, indexes.Length); Assert.AreEqual(0, indexes[0]); Assert.AreEqual(2, indexes[1]); }
/// <summary> /// Indicates if the specified range of cells is selected /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public virtual bool IntersectsWith(Range p_Range) { if (p_Range.IsEmpty() || IsEmpty()) { return(false); } RangeRegion range = Intersect(p_Range); return(!range.IsEmpty()); }
/// <summary> /// Prende un range che è già stato filtrato con solo le celle non presenti nell'attuale range /// </summary> /// <param name="pRange"></param> /// <returns></returns> private bool InternalAdd(RangeRegion pRange) { if (Contains(pRange)) { return(true); } if (pRange.Contains(this)) //change all the contents with the new range { RangeRegion existingRange = new RangeRegion(this); m_RangeCollection.Clear(); m_RangeCollection.AddRange(pRange.m_RangeCollection); pRange = pRange.Exclude(existingRange); } else { pRange = pRange.Exclude(this); if (pRange.IsEmpty()) { return(true); //il range è vuoto } pRange.m_bValidated = true; RangeRegionCancelEventArgs e = new RangeRegionCancelEventArgs(pRange); OnAddingRange(e); //calling this method the range can change if (e.Cancel) { return(false); } if (pRange.m_bValidated == false) { pRange = pRange.Exclude(this); if (pRange.IsEmpty()) { return(true); //il range è vuoto } } for (int rToAdd = 0; rToAdd < pRange.m_RangeCollection.Count; rToAdd++) { Range rangeToAdd = pRange.m_RangeCollection[rToAdd]; m_RangeCollection.Add(rangeToAdd); } } OnAddedRange(new RangeRegionCancelEventArgs(pRange)); m_bValidated = false; return(true); }
/// <summary> /// Constructor /// </summary> /// <param name="addedRange"></param> /// <param name="removedRange"></param> public RangeRegionChangedEventArgs(Range addedRange, Range removedRange) { if (addedRange.IsEmpty() == false) { this.addedRange = new RangeRegion(addedRange); } if (removedRange.IsEmpty() == false) { this.removedRange = new RangeRegion(removedRange); } }
public RangeRegion Intersect(RangeRegion pRange) { RangeRegion ret = new RangeRegion(); for (int rToCheck = 0; rToCheck < pRange.m_RangeCollection.Count; rToCheck++) { Range rangeToCheck = pRange.m_RangeCollection[rToCheck]; RangeRegion intersect = Intersect(rangeToCheck); ret.m_RangeCollection.AddRange(intersect.m_RangeCollection); } return(ret); }
/// <summary> /// Returns the cells of the current range that don't intersect with the specified range /// </summary> /// <param name="pRange"></param> /// <returns></returns> public RangeRegion Exclude(Range pRange) { RangeRegion range = new RangeRegion(); for (int i = 0; i < m_RangeCollection.Count; i++) { RangeRegion excludedSubRange = m_RangeCollection[i].Exclude(pRange); range.m_RangeCollection.AddRange(excludedSubRange.m_RangeCollection); } return(range); }
public RangeRegion Exclude(RangeRegion pRange) { RangeRegion excludedRange = new RangeRegion(this); if (excludedRange.IsEmpty() == false) { for (int rToCheck = 0; rToCheck < pRange.m_RangeCollection.Count; rToCheck++) { excludedRange = excludedRange.Exclude(pRange.m_RangeCollection[rToCheck]); } } return(excludedRange); }
public void SelectionBug() { // Bug report http://www.devage.com/Forum/ViewTopic.aspx?id=8addb0016ae24d97acdef5183bc745c4#msgae7217a8cdc149d383cfdc207f1dc056 // 1. create new RangeRegion with single Range(3, 3, 3, 3); // 2. Add new range witch extends our range by one cell to right // 3. original RangeRegion should fire event Changed, // witch should report that a new region was added // The bug is that the AddedRange reports to be empty RangeRegion region = new RangeRegion( new Range(3, 3, 3, 3)); region.Changed += delegate (object sender, RangeRegionChangedEventArgs e) { Assert.AreEqual(1, e.AddedRange.Count); }; region.Add(new Range(3, 3, 3, 4)); }
/// <summary> /// Indicates if the specified range of cells is selected /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public virtual bool Contains(RangeRegion p_Range) { if (p_Range.IsEmpty() || IsEmpty()) { return(false); } PositionCollection positions = p_Range.GetCellsPositions(); for (int i = 0; i < positions.Count; i++) { if (Contains(positions[i]) == false) { return(false); } } return(true); }
/// <summary> /// Returns a non contiguous range of cells of the intersection between the current range and the specified range. /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public virtual RangeRegion Intersect(Range p_Range) { RangeRegion range = new RangeRegion(); if (p_Range.IsEmpty() == false && IsEmpty() == false) { //Range for (int i = 0; i < m_RangeCollection.Count; i++) { Range intersectRange = p_Range.Intersect(m_RangeCollection[i]); if (intersectRange.IsEmpty() == false) { range.m_RangeCollection.Add(intersectRange); } } } return(range); }
/// <summary> /// Clear all the selected cells with a valid Model. /// </summary> public virtual void ClearValues(RangeRegion region) { PositionCollection positions = region.GetCellsPositions(); foreach (Position pos in positions) { CellContext cellContext = new CellContext(this, pos); if (cellContext.Cell != null) { if (cellContext.Cell.Editor != null) cellContext.Cell.Editor.ClearCell(cellContext); } } }
/// <summary> /// Returns the cells of the current range that don't intersect with the specified range /// </summary> /// <param name="pRange"></param> /// <returns></returns> public RangeRegion Exclude(Range pRange) { RangeRegion range = new RangeRegion(); for (int i = 0; i < m_RangeCollection.Count; i++) { RangeRegion excludedSubRange = m_RangeCollection[i].Exclude(pRange); range.m_RangeCollection.AddRange(excludedSubRange.m_RangeCollection); } return range; }
/// <summary> /// Constructor /// </summary> /// <param name="addedRange"></param> /// <param name="removedRange"></param> public RangeRegionChangedEventArgs(Range addedRange, Range removedRange) { if (addedRange.IsEmpty() == false) this.addedRange = new RangeRegion(addedRange); if (removedRange.IsEmpty() == false) this.removedRange = new RangeRegion(removedRange); }
/// <summary> /// Check if the positions saved are still valid, for example if all the selected cells are still valid positions, if not the selection are removed without calling any other methods. /// </summary> public virtual void CheckPositions() { Range complete = CompleteRange; if (m_MouseCellPosition.IsEmpty() == false && CompleteRange.Contains(m_MouseCellPosition) == false) m_MouseCellPosition = Position.Empty; if (m_MouseDownPosition.IsEmpty() == false && CompleteRange.Contains(m_MouseDownPosition) == false) m_MouseDownPosition = Position.Empty; if (mDragCellPosition.IsEmpty() == false && CompleteRange.Contains(mDragCellPosition) == false) mDragCellPosition = Position.Empty; //If the selection contains some invalid cells reset the selection state. RangeRegion completeRegion = new RangeRegion(complete); if ( (Selection.ActivePosition.IsEmpty() == false && complete.Contains(Selection.ActivePosition) == false) || (Selection.IsEmpty() == false && completeRegion.Contains(Selection.GetSelectionRegion()) == false) ) // AlanP: Sep 2013. This gets called when we delete rows (eg FPreviouslySelectedDetailRow.Delete()) // so we want to suppress selection_changed at this point because we will call SelectRowInGrid next Selection.ResetSelection(false, true); }
public RangeRegion Intersect(RangeRegion pRange) { RangeRegion ret = new RangeRegion(); for (int rToCheck = 0; rToCheck < pRange.m_RangeCollection.Count; rToCheck++) { Range rangeToCheck = pRange.m_RangeCollection[rToCheck]; RangeRegion intersect = Intersect(rangeToCheck); ret.m_RangeCollection.AddRange(intersect.m_RangeCollection); } return ret; }
/// <summary> /// Add the specified ranges of cells /// </summary> /// <param name="pRange"></param> /// <returns></returns> public bool Add(RangeRegion pRange) { return(InternalAdd(pRange)); }
/// <summary> /// Prende un range che è già stato filtrato con solo le celle non presenti nell'attuale range /// </summary> /// <param name="pRange"></param> /// <returns></returns> private bool InternalAdd(RangeRegion pRange) { if (Contains(pRange)) return true; if (pRange.Contains(this)) //change all the contents with the new range { m_RangeCollection.Clear(); m_RangeCollection.AddRange(pRange.m_RangeCollection); pRange = pRange.Exclude(this); } else { pRange = pRange.Exclude(this); if (pRange.IsEmpty()) return true; //il range è vuoto pRange.m_bValidated = true; RangeRegionCancelEventArgs e = new RangeRegionCancelEventArgs(pRange); OnAddingRange(e); //calling this method the range can change if (e.Cancel) return false; if (pRange.m_bValidated == false) { pRange = pRange.Exclude(this); if (pRange.IsEmpty()) return true; //il range è vuoto } for (int rToAdd = 0; rToAdd < pRange.m_RangeCollection.Count; rToAdd++) { Range rangeToAdd = pRange.m_RangeCollection[rToAdd]; m_RangeCollection.Add(rangeToAdd); } } OnAddedRange(new RangeRegionCancelEventArgs(pRange)); m_bValidated = false; return true; }
/// <summary> /// Check if the positions saved are still valid, for example if all the selected cells are still valid positions, if not the selection are removed without calling any other methods. /// </summary> public virtual void CheckPositions() { Range complete = CompleteRange; if (m_MouseCellPosition.IsEmpty() == false && CompleteRange.Contains(m_MouseCellPosition) == false) m_MouseCellPosition = Position.Empty; if (m_MouseDownPosition.IsEmpty() == false && CompleteRange.Contains(m_MouseDownPosition) == false) m_MouseDownPosition = Position.Empty; if (mDragCellPosition.IsEmpty() == false && CompleteRange.Contains(mDragCellPosition) == false) mDragCellPosition = Position.Empty; //If the selection contains some invalid cells reset the selection state. RangeRegion completeRegion = new RangeRegion(complete); if ( (Selection.ActivePosition.IsEmpty() == false && complete.Contains(Selection.ActivePosition) == false) || (Selection.IsEmpty() == false && completeRegion.Contains(Selection.GetSelectionRegion()) == false) ) Selection.ResetSelection(false); }
/// <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(Range p_Range1, Range p_Range2) { RangeRegion range = new RangeRegion(); range.Add(p_Range1); range.Add(p_Range2); return range; }
/// <summary> /// Return all the cells that don't intersect with the specified cells. (Remove the specified cells from the current cells ad returns the remaining cells) /// </summary> /// <param name="range"></param> /// <returns></returns> public RangeRegion Exclude(Range range) { RangeRegion excluded; Range intersection = Intersect(range); if (intersection.IsEmpty()) { excluded = new RangeRegion(this); } else { excluded = new RangeRegion(); //Top Left if (this.Start.Row < intersection.Start.Row && this.Start.Column < intersection.Start.Column) excluded.Add( new Range(this.Start.Row, this.Start.Column, intersection.Start.Row - 1, intersection.Start.Column - 1) ); //Top if (this.Start.Row < intersection.Start.Row) excluded.Add( new Range(this.Start.Row, intersection.Start.Column, intersection.Start.Row - 1, intersection.End.Column) ); //Top Right if (this.Start.Row < intersection.Start.Row && this.End.Column > intersection.End.Column) excluded.Add( new Range(this.Start.Row, intersection.End.Column + 1, intersection.Start.Row -1, this.End.Column) ); //---------- //Left if (this.Start.Column < intersection.Start.Column) excluded.Add( new Range(intersection.Start.Row, this.Start.Column, intersection.End.Row, intersection.Start.Column -1) ); //Right if (this.End.Column > intersection.End.Column) excluded.Add( new Range(intersection.Start.Row, intersection.End.Column + 1, intersection.End.Row, this.End.Column) ); //-------- //Bottom Left if (this.End.Row > intersection.End.Row && this.Start.Column < intersection.Start.Column) excluded.Add( new Range(intersection.End.Row + 1, this.Start.Column, this.End.Row, intersection.Start.Column - 1) ); //Bottom if (this.End.Row > intersection.End.Row) excluded.Add( new Range(intersection.End.Row + 1, intersection.Start.Column, this.End.Row, intersection.End.Column) ); //Bottom Right if (this.End.Row > intersection.End.Row && this.End.Column > intersection.End.Column) excluded.Add( new Range(intersection.End.Row + 1, intersection.End.Column + 1, this.End.Row, this.End.Column) ); } return excluded; }
public RangeRegionEventArgs(RangeRegion p_GridRangeRegion) { m_GridRangeRegion = p_GridRangeRegion; }
public RangeRegionChangingEventArgs(RangeRegion pCurrentRegion, RangeRegion pRangeToExclude, RangeRegion pRangeToInclude ) { mRegionToExclude = pRangeToExclude; mCurrentRegion = pCurrentRegion; mRegionToInclude = pRangeToInclude; }
public RangeRegionCancelEventArgs(RangeRegion p_GridRangeRegion) : base(p_GridRangeRegion) { }
/// <summary> /// Return all the cells that don't intersect with the specified cells. (Remove the specified cells from the current cells ad returns the remaining cells) /// </summary> /// <param name="range"></param> /// <returns></returns> public RangeRegion Exclude(Range range) { RangeRegion excluded; Range intersection = Intersect(range); if (intersection.IsEmpty()) { excluded = new RangeRegion(this); } else { excluded = new RangeRegion(); //Top Left if (this.Start.Row < intersection.Start.Row && this.Start.Column < intersection.Start.Column) { excluded.Add(new Range(this.Start.Row, this.Start.Column, intersection.Start.Row - 1, intersection.Start.Column - 1)); } //Top if (this.Start.Row < intersection.Start.Row) { excluded.Add(new Range(this.Start.Row, intersection.Start.Column, intersection.Start.Row - 1, intersection.End.Column)); } //Top Right if (this.Start.Row < intersection.Start.Row && this.End.Column > intersection.End.Column) { excluded.Add(new Range(this.Start.Row, intersection.End.Column + 1, intersection.Start.Row - 1, this.End.Column)); } //---------- //Left if (this.Start.Column < intersection.Start.Column) { excluded.Add(new Range(intersection.Start.Row, this.Start.Column, intersection.End.Row, intersection.Start.Column - 1)); } //Right if (this.End.Column > intersection.End.Column) { excluded.Add(new Range(intersection.Start.Row, intersection.End.Column + 1, intersection.End.Row, this.End.Column)); } //-------- //Bottom Left if (this.End.Row > intersection.End.Row && this.Start.Column < intersection.Start.Column) { excluded.Add(new Range(intersection.End.Row + 1, this.Start.Column, this.End.Row, intersection.Start.Column - 1)); } //Bottom if (this.End.Row > intersection.End.Row) { excluded.Add(new Range(intersection.End.Row + 1, intersection.Start.Column, this.End.Row, intersection.End.Column)); } //Bottom Right if (this.End.Row > intersection.End.Row && this.End.Column > intersection.End.Column) { excluded.Add(new Range(intersection.End.Row + 1, intersection.End.Column + 1, this.End.Row, this.End.Column)); } } return(excluded); }
/// <summary> /// Remove the specified ranges of cells /// </summary> /// <param name="pRange"></param> /// <returns></returns> public bool Remove(RangeRegion pRange) { return InternalRemove(pRange); }
public RangeRegionChangingEventArgs(RangeRegion pCurrentRegion, RangeRegion pRangeToExclude, RangeRegion pRangeToInclude) { mRegionToExclude = pRangeToExclude; mCurrentRegion = pCurrentRegion; mRegionToInclude = pRangeToInclude; }
/// <summary> /// Constructor /// </summary> /// <param name="addedRange">Use null if the added range is empty</param> /// <param name="removedRange">Use null if the removed range is empty</param> public RangeRegionChangedEventArgs(RangeRegion addedRange, RangeRegion removedRange) { this.addedRange = addedRange; this.removedRange = removedRange; }
/// <summary> /// Prende un range che è già stato filtrato con solo le celle presenti nell'attuale range /// </summary> /// <param name="pRange"></param> /// <returns></returns> private bool InternalRemove(RangeRegion pRange) { pRange = Intersect(pRange); if (pRange.IsEmpty()) return true; //il range non è presente pRange.m_bValidated = true; RangeRegionCancelEventArgs e = new RangeRegionCancelEventArgs(pRange); OnRemovingRange(e); //calling this method the range can change if (e.Cancel) return false; if (pRange.m_bValidated == false) { pRange = Intersect(pRange); if (pRange.IsEmpty()) return true; //il range non è presente } m_RangeCollection = Exclude(pRange).m_RangeCollection; OnRemovedRange(e); m_bValidated = false; return true; }
/// <summary> /// Copy constructor /// </summary> /// <param name="other"></param> public RangeRegion(RangeRegion other) { m_RangeCollection.AddRange(other.m_RangeCollection); }
/// <summary> /// Returns a non contiguous range of cells of the intersection between the current range and the specified range. /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public virtual RangeRegion Intersect(Range p_Range) { RangeRegion range = new RangeRegion(); if (p_Range.IsEmpty() == false && IsEmpty() == false) { //Range for (int i = 0; i < m_RangeCollection.Count; i++) { Range intersectRange = p_Range.Intersect(m_RangeCollection[i]); if (intersectRange.IsEmpty() == false) range.m_RangeCollection.Add(intersectRange); } } return range; }
/// <summary> /// Indicates if the specified range of cells is selected /// </summary> /// <param name="p_Range"></param> /// <returns></returns> public virtual bool Contains(RangeRegion p_Range) { if (p_Range.IsEmpty() || IsEmpty()) return false; PositionCollection positions = p_Range.GetCellsPositions(); for (int i = 0; i < positions.Count; i++) { if ( Contains(positions[i]) == false) return false; } return true; }
/// <summary> /// Checks if delete is enabled, and clears values from /// given destination by invoking ClearValues(selRegion) /// </summary> /// <param name="selRegion"></param> public void PerformDelete(RangeRegion selRegion) { bool deleteEnabled = (ClipboardMode & ClipboardMode.Delete) == ClipboardMode.Delete; if (deleteEnabled == false || selRegion.IsEmpty() == true) return; ClearValues(selRegion); }
/// <summary> /// Remove the specified ranges of cells /// </summary> /// <param name="pRange"></param> /// <returns></returns> public bool Remove(RangeRegion pRange) { return(InternalRemove(pRange)); }
/// <summary> /// Add the specified ranges of cells /// </summary> /// <param name="pRange"></param> /// <returns></returns> public bool Add(RangeRegion pRange) { return InternalAdd(pRange); }
/// <summary> /// Checks if copy mode is enabled and copies data into clipboard /// </summary> /// <param name="selRegion"></param> public void PerformCopy(RangeRegion selRegion) { bool copyEnabled = (ClipboardMode & ClipboardMode.Copy) == ClipboardMode.Copy; if (copyEnabled == false || selRegion.IsEmpty() == true) return; Range rng = selRegion[0]; RangeData data = RangeData.LoadData(this, rng, CutMode.None); RangeData.ClipboardSetData(data); }
public RangeRegion Exclude(RangeRegion pRange) { RangeRegion excludedRange = new RangeRegion(this); if (excludedRange.IsEmpty() == false) { for (int rToCheck = 0; rToCheck < pRange.m_RangeCollection.Count; rToCheck++) { excludedRange = excludedRange.Exclude( pRange.m_RangeCollection[rToCheck] ); } } return excludedRange; }
/// <summary> /// Checks if cut mode is enabled, and copies /// data into clipaborad /// </summary> /// <param name="selRegion"></param> public void PerformCut(RangeRegion selRegion) { bool cutEnabled = (ClipboardMode & ClipboardMode.Cut) == ClipboardMode.Cut; if (cutEnabled == false || selRegion.IsEmpty() == true) return; Range rng = selRegion[0]; RangeData data = RangeData.LoadData(this, rng, CutMode.CutImmediately); RangeData.ClipboardSetData(data); }
/// <summary> /// Checks if paste mode is enabled and writes /// data into grid from clipboard /// </summary> /// <param name="selRegion"></param> public void PerformPaste(RangeRegion selRegion) { bool pasteEnabled = (ClipboardMode & ClipboardMode.Paste) == ClipboardMode.Paste; if (pasteEnabled == false || selRegion.IsEmpty() == true) return; RangeData rngData = RangeData.ClipboardGetData(); if (rngData == null) return; Range rng = selRegion[0]; Range data = rngData.SourceRange; Range destinationRange = new Range( new Position(rng.Start.Row, rng.Start.Column), new Position(rng.Start.Row + (data.End.Row - data.Start.Row), rng.Start.Column + (data.End.Column - data.Start.Column))); rngData.WriteData(this, rng.Start); Selection.ResetSelection(true); Selection.SelectRange(destinationRange, true); }