/// <summary> /// Auto Translate The Selected Resource via Google Translator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void MenuItemClick(object sender, EventArgs e) { MenuItem menuItem = (MenuItem)sender; ContextMenu contextMenu = (ContextMenu)menuItem.Parent; TextBox tbx = (TextBox)contextMenu.SourceControl; TextBoxTranslation tbt = (TextBoxTranslation)tbx.Tag; tbx.Text = Translator.TranslateText(tbx.Text, string.Format("{0}|{1}", sLangCodeSrc, sLangCodeDest)); RangeRegion region = grid1.Selection.GetSelectionRegion(); PositionCollection poss = region.GetCellsPositions(); foreach (Position t in from t in poss let cell = grid1.GetCell(t) as SourceGrid.Cells.Cell where cell != null select t) { GetCell(grid1, t).View = tbt.srcResourceValue.Equals(tbx.Text, StringComparison.OrdinalIgnoreCase) ? cellLocalResourceRed : cellLocalResource; } // Update Translations List translations.Find(check => check.sPageName.Equals(tbt.pageName) && check.sResourceName.Equals(tbt.resourceName)). sLocalizedValue = tbx.Text; // tlpTranslations.Focus(); }
private void InternalAdd(RangeRegion rangeRegion) { foreach (GridRange range in rangeRegion) { m_ranges.Add(range); } }
private void tsDelete_Click(object sender, EventArgs e) { if (gdStop.Selection.IsEmpty()) { return; } RangeRegion range = gdStop.Selection.GetSelectionRegion(); foreach (var r in range) { for (int i = r.End.Row; i >= r.Start.Row; i--) { if (gdStop[i, 0].Tag == null) { continue; } StopNotifyInfo info = (StopNotifyInfo)gdStop[i, 0].Tag; StopNotifies[info.Server].Remove(info); Util.Monitors[info.Server].RemoveStopNotify(info); for (int col = 0; col < 4; col++) { gdStop[i, col].UnBindToGrid(); } gdStop.Rows.Remove(i); } } tsDelete.Enabled = !gdStop.Selection.IsEmpty(); }
private bool IntersectWithCurrentRangesRecursive(RangeRegion rangeRegionToIntersect) { // check against each range foreach (Range range in m_ranges) { RangeRegion excludedResults = null; Range remove = Range.Empty; bool excluded = false; // loop through our new ranges foreach (Range rangeToIntersect in rangeRegionToIntersect) { // if we intersect with at least one range // get the exclusion range. // mark a flag, that we need to remove our // range, and add an excluded range if (range.IntersectsWith(rangeToIntersect)) { excludedResults = rangeToIntersect.Exclude(range); excluded = true; remove = rangeToIntersect; break; } } if (excluded) { rangeRegionToIntersect.Remove(remove); rangeRegionToIntersect.Add(excludedResults); return(true); } } return(false); }
private void InternalAdd(RangeRegion rangeRegion) { foreach (Range range in rangeRegion) { m_ranges.Add(range); } }
private RangeRegion IntersectWithCurrentRanges(RangeRegion rangeRegionToIntersect) { while (IntersectWithCurrentRangesRecursive(rangeRegionToIntersect)) { } return rangeRegionToIntersect; }
private void gdInfo_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.Delete) { if (gdInfo.Selection.IsEmpty()) { return; } RangeRegion range = gdInfo.Selection.GetSelectionRegion(); foreach (var r in range) { for (int i = r.End.Row; i >= r.Start.Row; i--) { if (gdInfo[i, 0].Tag == null) { continue; } InfoNotifyInfo info = (InfoNotifyInfo)gdInfo[i, 0].Tag; InfoNotifies[info.Server].Remove(info); Util.Monitors[info.Server].RemoveInfoNotify(info); for (int col = 0; col < 3; col++) { gdInfo[i, col].UnBindToGrid(); } gdInfo.Rows.Remove(i); } } } }
private bool IntersectWithCurrentRangesRecursive(RangeRegion rangeRegionToIntersect) { // check against each range foreach (Range range in m_ranges) { RangeRegion excludedResults = null; Range remove = Range.Empty; bool excluded = false; // loop through our new ranges foreach (Range rangeToIntersect in rangeRegionToIntersect) { // if we intersect with at least one range // get the exclusion range. // mark a flag, that we need to remove our // range, and add an excluded range if (range.IntersectsWith(rangeToIntersect)) { excludedResults = rangeToIntersect.Exclude(range); excluded = true; remove = rangeToIntersect; break; } } if (excluded) { rangeRegionToIntersect.Remove(remove); rangeRegionToIntersect.Add(excludedResults); return true; } } return false; }
private RangeRegion IntersectWithCurrentRanges(RangeRegion rangeRegionToIntersect) { while (IntersectWithCurrentRangesRecursive(rangeRegionToIntersect)) { } return(rangeRegionToIntersect); }
protected override void OnResetSelection() { RangeRegion prevRange = GetSelectionRegion(); mList.Clear(); OnSelectionChanged(new RangeRegionChangedEventArgs(null, prevRange)); }
protected override void OnResetSelection() { RangeRegion prevRange = GetSelectionRegion(); mList.Clear(); // AlanP: Sept 2013 Changed OnSelectionChanged to new method InvalidateGridSelection // This results in no SelectionChanged event being fired but we still get the grid invalidated InvalidateGridSelection(new RangeRegionChangedEventArgs(null, prevRange)); }
public RangeMergerByCells AddRange(Range rangeToAdd) { RangeRegion rangeRegionToAdd = IntersectWithCurrentRanges(new RangeRegion(rangeToAdd)); foreach (Range range in rangeRegionToAdd) { m_ranges.Add(range); } JoinAdjanced(); return(this); }
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]); }
private IEnumerable <FixMessage> GetSelectedMessages() { RangeRegion region = this.grid1.Selection.GetSelectionRegion(); for (int i = 1; i < this.grid1.Rows.Count; i++) { if (region.ContainsRow(i)) { LogLine line = (LogLine)this.grid1[i, 0].Tag; yield return(line.FixMessage); } } }
public void GetRowsIndex_Performance() { // this test, sadly, tests nothing // remove it RangeRegion region = new RangeRegion(new Range(0, 0, 10000, 5000)); using (IPerformanceCounter counter = new PerformanceCounter()) { region.GetRowsIndex(); Console.WriteLine(string.Format( "Test executed in {0} ms", counter.GetMilisec())); } }
public override RangeRegion GetSelectionRegion() { RangeRegion region = new RangeRegion(); if (Grid.Columns.Count > 0) { foreach (int row in mList) { region.Add(ValidateRange(new Range(row, 0, row, Grid.Columns.Count - 1))); } } return(region); }
public override RangeRegion GetSelectionRegion() { RangeRegion region = new RangeRegion(); if (Grid.Rows.Count > 0) { foreach (int col in mList) { region.Add(ValidateRange(new Range(Grid.FixedRows, col, Grid.Rows.Count - 1, col))); } } return(region); }
private void OnBoxesRemove(object sender, EventArgs e) { RangeRegion region = gridContent.Selection.GetSelectionRegion(); int[] indexes = region.GetRowsIndex(); // no selection -> exit if (indexes.Length == 0) { return; } Items.RemoveAt(indexes[0] - 1); FillGridContent(); OnCompute(sender, e); }
public override RangeRegion GetSelectionRegion() { RangeRegion region = new RangeRegion(); if (Grid.Columns.Count > 0) { foreach (int row in mList) { region.Add(ValidateRange(new Range(row, 0, row, Grid.Columns.Count - 1))); } } return region; }
public override RangeRegion GetSelectionRegion() { RangeRegion region = new RangeRegion(); if (Grid.Columns.Count == 0) { return(region); } foreach (Range selectedRange in mList.GetSelectedRowRegions(0, Grid.Columns.Count)) { region.Add(ValidateRange(selectedRange)); } return(region); }
public override RangeRegion GetSelectionRegion() { RangeRegion region = new RangeRegion(); if (Grid.Rows.Count > 0) { foreach (int col in mList) { region.Add(ValidateRange(new Range(Grid.FixedRows, col, Grid.Rows.Count - 1, col))); } } return region; }
public override void Draw(RangePaintEventArgs e) { RangeRegion region = mSelection.GetSelectionRegion(); if (region.IsEmpty()) { return; } System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor); CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition); System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(mSelection.ActivePosition); RangeCollection ranges = region.GetRanges(); //Draw each selection range foreach (Range rng in ranges) { System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) { continue; } System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); if (rectToDraw.IntersectsWith(focusRect)) { regionToDraw.Exclude(focusRect); } e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); //Draw the border only if there isn't a editing cell // and is the range that contains the focus or there is a single range if (rng.Contains(mSelection.ActivePosition) || ranges.Count == 1) { if (focusContext == null || focusContext.IsEditing() == false) { mSelection.Border.Draw(e.GraphicsCache, rectToDraw); } } } //Draw Focus System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor); e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect); }
/// <summary> /// 活动剪切 /// </summary> private void ActionCut() { RangeRegion region = gridSource.Selection.GetSelectionRegion(); int[] index = region.GetRowsIndex(); if (index.Length == 0) { return; } clipBoardData = new List <ActionBase>(); foreach (var i in index) { clipBoardData.Add(DataSource[i - 1]); } }
private bool RemoveRangeRecursive(GridRange rangeToRemove) { rangeToRemove = NormalizeRange(rangeToRemove); for (int i = 0; i < m_ranges.Count; i++) { GridRange range = m_ranges[i]; if (range.IntersectsWith(rangeToRemove) == false) { continue; } GridRange intersection = range.Intersect(rangeToRemove); m_ranges.Remove(range); RangeRegion excludedRanges = range.Exclude(intersection); InternalAdd(excludedRanges); return(true); } return(false); }
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)); }
public void GetSelectionRegion_ReturnsContiguousRanges() { // select two ranges: // * from row 1 to 100 // * from row 501 to 600 // // Assert that grid.Selection.GetSelectionRegion() returns // only 2 ranges, not 200 Grid grid = new TestRowSelectionHelper().CreateGridWithRows(30); grid.Selection.SelectRange(new Range(1, 0, 2, 0), true); grid.Selection.SelectRange(new Range(21, 0, 22, 0), true); RangeRegion region = grid.Selection.GetSelectionRegion(); Assert.AreEqual(2, region.Count); Assert.AreEqual(new Range(1, 0, 2, 0), region[0]); Assert.AreEqual(new Range(21, 0, 22, 0), region[1]); }
public void SelectSpannedCells_TwoSpannedCells() { // select at two positions the same cell Grid grid1 = new Grid(); grid1.Redim(6, 6); grid1[0, 0] = new SourceGrid.Cells.Cell(); grid1[0, 0].ColumnSpan = 3; grid1[0, 0].RowSpan = 3; grid1[0, 3] = new SourceGrid.Cells.Cell(); grid1[0, 3].ColumnSpan = 3; grid1[0, 3].RowSpan = 3; grid1.Selection.SelectRange(new Range(0, 0, 0, 3), true); RangeRegion region = grid1.Selection.GetSelectionRegion(); Assert.AreEqual(1, region.Count); Assert.AreEqual(new Range(0, 0, 2, 5), region[0]); }
public void SelectSpannedCells_SingleCell() { // just select a single cell. Should select whole spanned cell Grid grid1 = new Grid(); grid1.Redim(6, 6); grid1[0, 0] = new SourceGrid.Cells.Cell(); grid1[0, 0].ColumnSpan = 3; grid1[0, 0].RowSpan = 3; grid1[0, 3] = new SourceGrid.Cells.Cell(); grid1[0, 3].ColumnSpan = 3; grid1[0, 3].RowSpan = 3; grid1.Selection.SelectCell(new Position(0, 0), true); RangeRegion region = grid1.Selection.GetSelectionRegion(); Assert.AreEqual(1, region.Count); Assert.AreEqual(new Range(0, 0, 2, 2), region[0]); }
/// <summary> /// Compare source and destination values on focus lost and indicate (guess) whether text is translated or not /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void TbxLostFocus(object sender, EventArgs e) { TextBox tbx = (TextBox)sender; TextBoxTranslation tbt = (TextBoxTranslation)tbx.Tag; tbx.ForeColor = tbt.srcResourceValue.Equals(tbx.Text, StringComparison.OrdinalIgnoreCase) ? Color.Red : Color.Black; RangeRegion region = grid1.Selection.GetSelectionRegion(); PositionCollection poss = region.GetCellsPositions(); foreach (Position t in from t in poss let cell = grid1.GetCell(t) as SourceGrid.Cells.Cell where cell != null select t) { GetCell(grid1, t).View = tbt.srcResourceValue.Equals(tbx.Text, StringComparison.OrdinalIgnoreCase) ? cellLocalResourceRed : cellLocalResource; } // Update Translations List translations.Find(check => check.sPageName.Equals(tbt.pageName) && check.sResourceName.Equals(tbt.resourceName)). sLocalizedValue = tbx.Text; //tlpTranslations.Focus(); }
public override void Draw(RangePaintEventArgs e) { RangeRegion region = mSelection.GetSelectionRegion(); if (region.IsEmpty()) { return; } // get visible range for scrollable area // AlanP: June 2014. Changed the call from RangeAtAreaExpanded to RangeAtArea to fix a bug that occurred on Partner/Find screen // The grid on this screen has 3 fixed columns on the left but the highlight was always applied to the cell 'behind' the last fixed column // as well as the rest of the row. This is because of getting the 'expanded' range. // To be honest I don't understand what the expanded range is for. The comment for it is not helpful (to me anyway). // It may be something to do with drawing the focus cell? If we see a problem later we could revies this code //Range visibleScrollabeRange = mSelection.Grid.RangeAtAreaExpanded(CellPositionType.Scrollable); Range visibleScrollableRange = mSelection.Grid.RangeAtArea(CellPositionType.Scrollable); System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor); // In OP we would like to have the rows of fixed columns highlighted as well - this seems non-standard // This code is the same as is used in the standard code below, but for the FixedLeft Range Range visibleFixedLeftRange = mSelection.Grid.RangeAtArea(CellPositionType.FixedLeft); foreach (Range rangeToLoop in region) { Range rng = visibleFixedLeftRange.Intersect(rangeToLoop); System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) { continue; } System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); } // Deal with the focus rectangle... The original grid code does not seem to support the focus being on a fixed column, which seems like a bug // but does not affect OpenPetra CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition); // get focus rectangle // clipped to visible range Range focusClippedRange = visibleScrollableRange.Intersect(new Range(mSelection.ActivePosition, mSelection.ActivePosition)); System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(focusClippedRange.Start); //Draw each selection range foreach (Range rangeToLoop in region) { // intersect given range with visible range // this way we ensure we don't loop through thousands // of rows to calculate rectToDraw Range rng = visibleScrollableRange.Intersect(rangeToLoop); System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) { continue; } System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); if (rectToDraw.IntersectsWith(focusRect)) { regionToDraw.Exclude(focusRect); } e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); //Draw the border only if there isn't a editing cell // and is the range that contains the focus or there is a single range if (rng.Contains(mSelection.ActivePosition) || region.Count == 1) { if (focusContext.IsEditing() == false) { mSelection.Border.Draw(e.GraphicsCache, rectToDraw); } } } //Draw Focus System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor); e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect); }
/// <summary> /// Change the ActivePosition (focus) of the grid. /// </summary> /// <param name="pCellToActivate"></param> /// <param name="pResetSelection">True to deselect the previous selected cells</param> /// <returns></returns> public bool Focus(Position pCellToActivate, bool pResetSelection) { //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells bool deselectOtherCells = false; if (pCellToActivate.IsEmpty() == false && pResetSelection) { deselectOtherCells = true; } pCellToActivate = Grid.PositionToStartPosition(pCellToActivate); //Check to see if the value is changed (note that I use the internal variable to see the actual stored value) if (pCellToActivate != ActivePosition) { //GotFocus Event Arguments Cells.ICellVirtual newCellToFocus = Grid.GetCell(pCellToActivate); CellContext newCellContext = new CellContext(Grid, pCellToActivate, newCellToFocus); ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate); if (newCellToFocus != null) { //Cell Focus Entering Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs); if (gotFocusEventArgs.Cancel) { return(false); } //If the cell can't receive the focus stop the focus operation if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false) { return(false); } } //If the new cell is valid I check if I can move the focus inside the grid if (newCellToFocus != null) { //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false. // This is useful for 2 reason: // -To validate the editor // -To check if I can move the focus on another cell bool canFocus = Grid.Focus(); if (canFocus == false) { return(false); } } RangeRegion oldFocusRegion = null; //If there is a cell with the focus fire the focus leave events if (IsActivePositionValid()) { oldFocusRegion = new RangeRegion(ActivePosition); //LostFocus Event Arguments Cells.ICellVirtual oldCellFocus = Grid.GetCell(ActivePosition); CellContext oldCellContext = new CellContext(Grid, ActivePosition, oldCellFocus); ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate); //Cell Focus Leaving Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs); if (lostFocusEventArgs.Cancel) { return(false); } //Cell Lost Focus OnCellLostFocus(lostFocusEventArgs); if (lostFocusEventArgs.Cancel) { return(false); } } else { //Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells) // NOTE: in this case the focus event are not executed m_ActivePosition = Position.Empty; } //Deselect previous selected cells if (deselectOtherCells) { ResetSelection(false); } bool success; if (newCellToFocus != null) { //Cell Got Focus OnCellGotFocus(gotFocusEventArgs); success = (!gotFocusEventArgs.Cancel); } else { success = true; } //Fire a change event RangeRegion newFocusRegion = new RangeRegion(pCellToActivate); OnSelectionChanged(new RangeRegionChangedEventArgs(newFocusRegion, oldFocusRegion)); return(success); } else { if (pCellToActivate.IsEmpty() == false) { //I check if the grid still has the focus, otherwise I force it if (Grid.ContainsFocus) { return(true); } else { return(Grid.Focus()); } } else { return(true); } } }
// AlanP: Sep 2013 Added an optional parameter to specify that selection_changed events should be suppressed /// <summary> /// Change the ActivePosition (focus) of the grid. /// </summary> /// <param name="pCellToActivate"></param> /// <param name="pResetSelection">True to deselect the previous selected cells</param> /// <param name="suppressChangeEvent">Set to true to suppress Selection_Changed events</param> /// <returns></returns> public bool Focus(Position pCellToActivate, bool pResetSelection, bool suppressChangeEvent = false) { //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells bool deselectOtherCells = false; if (pCellToActivate.IsEmpty() == false && pResetSelection) deselectOtherCells = true; //pCellToActivate = Grid.PositionToStartPosition(pCellToActivate); //Check to see if the value is changed (note that I use the internal variable to see the actual stored value) if (pCellToActivate != ActivePosition) { //GotFocus Event Arguments Cells.ICellVirtual newCellToFocus = Grid.GetCell(pCellToActivate); CellContext newCellContext = new CellContext(Grid, pCellToActivate, newCellToFocus); ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate); if (newCellToFocus != null) { //Cell Focus Entering Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs); if (gotFocusEventArgs.Cancel) return false; //If the cell can't receive the focus stop the focus operation if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false) return false; } //If the new cell is valid I check if I can move the focus inside the grid if (newCellToFocus != null) { //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false. // This is useful for 2 reason: // -To validate the editor // -To check if I can move the focus on another cell bool canFocus = Grid.Focus(false); if (canFocus == false) { // AlanP: Oct 2013 // The grid cannot be focused, which happens when we call SelectRowInGrid before the screen has been 'activated'. // We still want to fire our SelectionChanged event ResetSelection(false, true); SelectCell(pCellToActivate, true); return false; } } RangeRegion oldFocusRegion = null; //If there is a cell with the focus fire the focus leave events if (IsActivePositionValid()) { oldFocusRegion = new RangeRegion(ActivePosition); //LostFocus Event Arguments Cells.ICellVirtual oldCellFocus = Grid.GetCell(ActivePosition); CellContext oldCellContext = new CellContext(Grid, ActivePosition, oldCellFocus); ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate); //Cell Focus Leaving Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs); if (lostFocusEventArgs.Cancel) return false; //Cell Lost Focus OnCellLostFocus(lostFocusEventArgs); if (lostFocusEventArgs.Cancel) return false; } else { //Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells) // NOTE: in this case the focus event are not executed m_ActivePosition = Position.Empty; } //Deselect previous selected cells if (deselectOtherCells) ResetSelection(false); // AlanP: Sep 2013 set our new member variable m_SuppressSelectionChangedEvent = suppressChangeEvent; bool success; if (newCellToFocus != null) { //Cell Got Focus // AlanP: this will fire SelectionChanged OnCellGotFocus(gotFocusEventArgs); success = (!gotFocusEventArgs.Cancel); } else { // AlanP: Sep 2013 Added this because when we are Focussing on an empty grid this is our chance to fire SelectionChanged SelectCell(Position.Empty, true); success = true; } //Fire a change event // AlanP: Sept 2013 Changed OnSelectionChanged to new method InvalidateGridSelection // This results in no SelectionChanged event being fired but we still get the grid invalidated RangeRegion newFocusRegion = new RangeRegion(pCellToActivate); InvalidateGridSelection(new RangeRegionChangedEventArgs(newFocusRegion, oldFocusRegion)); // AlanP: Sep 2013 Reset the new member variable m_SuppressSelectionChangedEvent = false; return success; } else { // The cell to activate is the same as the active position if (pCellToActivate.IsEmpty() == false) { DeselectOldRangeAndSelectActiveCell(); //I check if the grid still has the focus, otherwise I force it if (Grid.ContainsFocus) return true; else return Grid.Focus(); } else { // AlanP Sep 2013 // Even though we are activating an empty position when the position is already empty // we will fire off a selectionChanged event because this is useful on an empty grid when the main screen activates for the first time OnSelectionChanged(new RangeRegionChangedEventArgs(Range.Empty, Range.Empty)); return true; } } }
/// <summary> /// Change the ActivePosition (focus) of the grid. /// </summary> /// <param name="pCellToActivate"></param> /// <param name="pResetSelection">True to deselect the previous selected cells</param> /// <returns></returns> public bool Focus(Position pCellToActivate, bool pResetSelection) { //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells bool deselectOtherCells = false; if (pCellToActivate.IsEmpty() == false && pResetSelection) deselectOtherCells = true; //pCellToActivate = Grid.PositionToStartPosition(pCellToActivate); //Check to see if the value is changed (note that I use the internal variable to see the actual stored value) if (pCellToActivate != ActivePosition) { //GotFocus Event Arguments Cells.ICellVirtual newCellToFocus = Grid.GetCell(pCellToActivate); CellContext newCellContext = new CellContext(Grid, pCellToActivate, newCellToFocus); ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate); if (newCellToFocus != null) { //Cell Focus Entering Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs); if (gotFocusEventArgs.Cancel) return false; //If the cell can't receive the focus stop the focus operation if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false) return false; } //If the new cell is valid I check if I can move the focus inside the grid if (newCellToFocus != null) { //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false. // This is useful for 2 reason: // -To validate the editor // -To check if I can move the focus on another cell bool canFocus = Grid.Focus(false); if (canFocus == false) return false; } RangeRegion oldFocusRegion = null; //If there is a cell with the focus fire the focus leave events if (IsActivePositionValid()) { oldFocusRegion = new RangeRegion(ActivePosition); //LostFocus Event Arguments Cells.ICellVirtual oldCellFocus = Grid.GetCell(ActivePosition); CellContext oldCellContext = new CellContext(Grid, ActivePosition, oldCellFocus); ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate); //Cell Focus Leaving Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs); if (lostFocusEventArgs.Cancel) return false; //Cell Lost Focus OnCellLostFocus(lostFocusEventArgs); if (lostFocusEventArgs.Cancel) return false; } else { //Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells) // NOTE: in this case the focus event are not executed m_ActivePosition = Position.Empty; } //Deselect previous selected cells if (deselectOtherCells) ResetSelection(false); bool success; if (newCellToFocus != null) { //Cell Got Focus OnCellGotFocus(gotFocusEventArgs); success = (!gotFocusEventArgs.Cancel); } else { success = true; } //Fire a change event RangeRegion newFocusRegion = new RangeRegion(pCellToActivate); OnSelectionChanged(new RangeRegionChangedEventArgs(newFocusRegion, oldFocusRegion)); return success; } else { if (pCellToActivate.IsEmpty() == false) { DeselectOldRangeAndSelectActiveCell(); //I check if the grid still has the focus, otherwise I force it if (Grid.ContainsFocus) return true; else return Grid.Focus(); } else return true; } }
public override RangeRegion GetSelectionRegion() { RangeRegion region = new RangeRegion(); if (Grid.Columns.Count == 0) return region; foreach (Range selectedRange in mList.GetSelectedRowRegions(0, Grid.Columns.Count)) { region.Add(ValidateRange(selectedRange)); } return region; }
public override void Draw(RangePaintEventArgs e) { RangeRegion region = mSelection.GetSelectionRegion(); if (region.IsEmpty()) { return; } //[email protected]: To support freezePanes enahancement // get visible range for data area Range dataRange = mSelection.Grid.CompleteRange; System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor); CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition); // get focus rectangle // clipped to visible range Range focusClippedRange = dataRange.Intersect(new Range(mSelection.ActivePosition, mSelection.ActivePosition)); System.Drawing.Rectangle focusRect = e.Grid.PositionToVisibleRectangle(focusClippedRange.Start); //[email protected]: To support smooth scrolling. Otherwise transform will not be applied. focusRect.X -= (int)e.GraphicsCache.Graphics.Transform.OffsetX; focusRect.Y -= (int)e.GraphicsCache.Graphics.Transform.OffsetY; bool isFocusCellVisible = e.Grid.IsCellVisible(focusContext.Position, true); //Draw each selection range foreach (Range rangeToLoop in region) { // intersect given range with visible range // this way we ensure we don't loop through thousands // of rows to calculate rectToDraw Range rng = dataRange.Intersect(rangeToLoop); //[email protected]: To support freezePanes enahancement System.Drawing.Rectangle rectToDraw = e.Grid.RangeToVisibleRectangle(rng); //[email protected]: To support smooth scrolling. Otherwise transform will not be applied. rectToDraw.X -= (int)e.GraphicsCache.Graphics.Transform.OffsetX; rectToDraw.Y -= (int)e.GraphicsCache.Graphics.Transform.OffsetY; if (rectToDraw == System.Drawing.Rectangle.Empty) { continue; } System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); Range cellRange = e.Grid.PositionToCellRange(focusContext.Position); //[email protected]: To support freezePanes enahancement: Only if the cell is visible exclude it. It can be hidden under a fixedrow\column if (rectToDraw.IntersectsWith(focusRect) && (isFocusCellVisible || rng.Contains(cellRange))) { regionToDraw.Exclude(focusRect); } e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); var partType = GetBorderType(e.Grid, rng); //Draw the border only if there isn't a editing cell // and is the range that contains the focus or there is a single range if ((rng.Contains(mSelection.ActivePosition) || region.Count == 1) && partType != BorderPartType.None) { //if (!focusContext.IsEditing()) //[email protected]: the border should be drawn even when editing, mSelection.Border.Draw(e.GraphicsCache, rectToDraw, partType); } } //[email protected]: To support freezePanes enahancement: Only if the cell is visible exclude it. It can be hidden under a fixedrow\column if (isFocusCellVisible) //Draw Focus { System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor); e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect); } }
// AlanP: Sep 2013 Added an optional parameter to specify that selection_changed events should be suppressed /// <summary> /// Change the ActivePosition (focus) of the grid. /// </summary> /// <param name="pCellToActivate"></param> /// <param name="pResetSelection">True to deselect the previous selected cells</param> /// <param name="suppressChangeEvent">Set to true to suppress Selection_Changed events</param> /// <returns></returns> public bool Focus(Position pCellToActivate, bool pResetSelection, bool suppressChangeEvent = false) { //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells bool deselectOtherCells = false; if (pCellToActivate.IsEmpty() == false && pResetSelection) { deselectOtherCells = true; } //pCellToActivate = Grid.PositionToStartPosition(pCellToActivate); //Check to see if the value is changed (note that I use the internal variable to see the actual stored value) if (pCellToActivate != ActivePosition) { //GotFocus Event Arguments Cells.ICellVirtual newCellToFocus = Grid.GetCell(pCellToActivate); CellContext newCellContext = new CellContext(Grid, pCellToActivate, newCellToFocus); ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate); if (newCellToFocus != null) { //Cell Focus Entering Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs); if (gotFocusEventArgs.Cancel) { return(false); } //If the cell can't receive the focus stop the focus operation if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false) { return(false); } } //If the new cell is valid I check if I can move the focus inside the grid if (newCellToFocus != null) { //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false. // This is useful for 2 reason: // -To validate the editor // -To check if I can move the focus on another cell bool canFocus = Grid.Focus(false); if (canFocus == false) { // AlanP: Oct 2013 // The grid cannot be focused, which happens when we call SelectRowInGrid before the screen has been 'activated'. // We still want to fire our SelectionChanged event ResetSelection(false, true); SelectCell(pCellToActivate, true); return(false); } } RangeRegion oldFocusRegion = null; //If there is a cell with the focus fire the focus leave events if (IsActivePositionValid()) { oldFocusRegion = new RangeRegion(ActivePosition); //LostFocus Event Arguments Cells.ICellVirtual oldCellFocus = Grid.GetCell(ActivePosition); CellContext oldCellContext = new CellContext(Grid, ActivePosition, oldCellFocus); ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate); //Cell Focus Leaving Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs); if (lostFocusEventArgs.Cancel) { return(false); } //Cell Lost Focus OnCellLostFocus(lostFocusEventArgs); if (lostFocusEventArgs.Cancel) { return(false); } } else { //Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells) // NOTE: in this case the focus event are not executed m_ActivePosition = Position.Empty; } //Deselect previous selected cells if (deselectOtherCells) { ResetSelection(false); } // AlanP: Sep 2013 set our new member variable m_SuppressSelectionChangedEvent = suppressChangeEvent; bool success; if (newCellToFocus != null) { //Cell Got Focus // AlanP: this will fire SelectionChanged OnCellGotFocus(gotFocusEventArgs); success = (!gotFocusEventArgs.Cancel); } else { // AlanP: Sep 2013 Added this because when we are Focussing on an empty grid this is our chance to fire SelectionChanged SelectCell(Position.Empty, true); success = true; } //Fire a change event // AlanP: Sept 2013 Changed OnSelectionChanged to new method InvalidateGridSelection // This results in no SelectionChanged event being fired but we still get the grid invalidated RangeRegion newFocusRegion = new RangeRegion(pCellToActivate); InvalidateGridSelection(new RangeRegionChangedEventArgs(newFocusRegion, oldFocusRegion)); // AlanP: Sep 2013 Reset the new member variable m_SuppressSelectionChangedEvent = false; return(success); } else { // The cell to activate is the same as the active position if (pCellToActivate.IsEmpty() == false) { DeselectOldRangeAndSelectActiveCell(); //I check if the grid still has the focus, otherwise I force it if (Grid.ContainsFocus) { return(true); } else { return(Grid.Focus()); } } else { // AlanP Sep 2013 // Even though we are activating an empty position when the position is already empty // we will fire off a selectionChanged event because this is useful on an empty grid when the main screen activates for the first time OnSelectionChanged(new RangeRegionChangedEventArgs(Range.Empty, Range.Empty)); return(true); } } }
public override void Draw(RangePaintEventArgs e) { RangeRegion region = mSelection.GetSelectionRegion(); if (region.IsEmpty()) { return; } // get visible range for scrollable area Range visibleScrollabeRange = mSelection.Grid.RangeAtAreaExpanded(CellPositionType.Scrollable); System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor); CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition); // get focus rectangle // clipped to visible range Range focusClippedRange = visibleScrollabeRange.Intersect(new Range(mSelection.ActivePosition, mSelection.ActivePosition)); System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(focusClippedRange.Start); //Draw each selection range foreach (Range rangeToLoop in region) { // intersect given range with visible range // this way we ensure we don't loop through thousands // of rows to calculate rectToDraw Range rng = visibleScrollabeRange.Intersect(rangeToLoop); System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) { continue; } System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw); if (rectToDraw.IntersectsWith(focusRect)) { regionToDraw.Exclude(focusRect); } e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw); //Draw the border only if there isn't a editing cell // and is the range that contains the focus or there is a single range if (rng.Contains(mSelection.ActivePosition) || region.Count == 1) { if (focusContext.IsEditing() == false) { mSelection.Border.Draw(e.GraphicsCache, rectToDraw); } } } //Draw Focus System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor); e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect); }