protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); //verifico che l'eventuale edit sia terminato altrimenti esco if (Selection.ActivePosition.IsEmpty() == false) { CellContext focusCell = new CellContext(this, Selection.ActivePosition); if (focusCell.Cell != null && focusCell.IsEditing()) { if (focusCell.EndEdit(false) == false) return; } } //scateno eventi di MouseDown Position position = PositionAtPoint(new Point(e.X, e.Y)); if (position.IsEmpty() == false) { Cells.ICellVirtual cellMouseDown = GetCell(position); if (cellMouseDown != null) { // AlanP: Nov 2013. Added this if/else clause to set the position to the first column unless the click is on an editable cell if (cellMouseDown.Editor != null && cellMouseDown.Editor.EditableMode == EditableMode.Focus) { // The position is ok CellContext newFocusCell = new CellContext(this, position); newFocusCell.StartEdit(); } else if (position.Row >= this.FixedRows) { // AlanP: Jan 2014. Added this test that we are doing full row selection because on some grids we do column selection if (this.SelectionMode == GridSelectionMode.Row) { // always imagine that the click was on the first column // AlanP: March 2014 - the column is now the first VISIBLE column (in the normal sense, not visible in the display window) // AP screens may or may not display a checkbox column in column 0 int column = this.FixedColumns; while (column < this.Columns.Count - 1 && !((ColumnInfoCollection)this.Columns)[column].Visible) { column++; } position = new Position(position.Row, column); } } ChangeMouseDownCell(position, position); //Cell.OnMouseDown CellContext cellContext = new CellContext(this, position, cellMouseDown); Controller.OnMouseDown(cellContext, e); } } else ChangeMouseDownCell(Position.Empty, Position.Empty); }
private void _grid_ZValueChanged(SourceGrid.CellContext cc) { var g = _grid; var p = cc.Position; int row = p.Row; if (row == 0) //role { var cb = cc.Cell.Editor as SourceGrid.Cells.Editors.ComboBox; _role = (ERole)cb.Control.SelectedIndex; _SelectRole(); return; } //AOutput.Write(p.Column, p.Row, cc.IsEditing()); //uncheck if selected default value. The control checks when changed. if (p.Column == 1 && cc.IsEditing()) { bool uncheck = false; switch (cc.Cell.Editor) { case SourceGrid.Cells.Editors.ComboBox cb: if (cb.Control.SelectedIndex <= 0) { uncheck = true; } break; case SourceGrid.Cells.Editors.TextBox tb: if ((cc.Value as string).NE()) { uncheck = true; } break; } if (uncheck) { g.ZCheck(row, false); } } var rk = g.ZGetRowKey(row); //AOutput.Write(p.Column, row, g.ZIsChecked(row)); switch (rk) { case "runMode": _SelectRunMode(); //show/hide ifRunning2 if (_IsRunGreen()) { g.ZSetCellText("ifRunning", 1, "warn"); } break; case "ifRunning": //if runMode green, cannot be ifRunning run[_restart] if (_IsRunGreen()) { g.ZSetCellText("runMode", 1, "blue"); g.ZCheck("runMode", true); } break; } bool _IsRunGreen() => cc.IsEditing() && (_Get("ifRunning")?.Starts("run") ?? false) && _Get("runMode") != "blue"; if (p.Column == 0 && g.ZIsChecked(row)) { switch (rk) { case "icon": case "manifest": g.ZCheck("resFile", false); break; case "resFile": g.ZCheck("icon", false); g.ZCheck("manifest", false); break; } } }
/// <summary> /// Process Delete, Ctrl+C, Ctrl+V, Up, Down, Left, Right, Tab keys /// </summary> /// <param name="e"></param> public virtual void ProcessSpecialGridKey(KeyEventArgs e) { if (e.Handled) return; bool enableArrows,enableTab,enablePageDownUp; enableArrows = enableTab = enablePageDownUp = false; if ( (SpecialKeys & GridSpecialKeys.Arrows) == GridSpecialKeys.Arrows) enableArrows = true; if ( (SpecialKeys & GridSpecialKeys.PageDownUp) == GridSpecialKeys.PageDownUp) enablePageDownUp = true; if ( (SpecialKeys & GridSpecialKeys.Tab) == GridSpecialKeys.Tab) enableTab = true; bool enableEscape = false; if ( (SpecialKeys & GridSpecialKeys.Escape) == GridSpecialKeys.Escape) enableEscape = true; bool enableEnter = false; if ( (SpecialKeys & GridSpecialKeys.Enter) == GridSpecialKeys.Enter) enableEnter = true; #region Processing keys //Escape if (e.KeyCode == Keys.Escape && enableEscape) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { if (focusCellContext.EndEdit(true)) e.Handled = true; } } //Enter if (e.KeyCode == Keys.Enter && enableEnter) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { focusCellContext.EndEdit(false); e.Handled = true; } } //Tab if (e.KeyCode == Keys.Tab && enableTab) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { //se l'editing non riesce considero il tasto processato // altrimenti no, in questo modo il tab ha effetto anche per lo spostamento if (focusCellContext.EndEdit(false) == false) { e.Handled = true; return; } } } #endregion #region Navigate keys: arrows, tab and PgDown/Up if (e.KeyCode == Keys.Down && enableArrows) { Selection.MoveActiveCell(1, 0); e.Handled = true; } else if (e.KeyCode == Keys.Up && enableArrows) { Selection.MoveActiveCell(-1, 0); e.Handled = true; } else if (e.KeyCode == Keys.Right && enableArrows) { Selection.MoveActiveCell(0, 1); e.Handled = true; } else if (e.KeyCode == Keys.Left && enableArrows) { Selection.MoveActiveCell(0, -1); e.Handled = true; } else if (e.KeyCode == Keys.Tab && enableTab) { //If the tab failed I automatically select the next control in the form (SelectNextControl) if (e.Modifiers == Keys.Shift) // backward { if (Selection.MoveActiveCell(0, -1, -1, int.MaxValue) == false) FindForm().SelectNextControl(this, false, true, true, true); e.Handled = true; } else //forward { if (Selection.MoveActiveCell(0, 1, 1, int.MinValue) == false) FindForm().SelectNextControl(this, true, true, true, true); e.Handled = true; } } else if ( (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown) && enablePageDownUp) { Point focusPoint = PositionToRectangle(Selection.ActivePosition).Location; focusPoint.Offset(1, 1); //in modo da entrare nella cella if (e.KeyCode == Keys.PageDown) CustomScrollPageDown(); else if (e.KeyCode == Keys.PageUp) CustomScrollPageUp(); Position newPosition = PositionAtPoint(focusPoint); if (Selection.CanReceiveFocus(newPosition)) Selection.Focus(newPosition, true); e.Handled = true; } #endregion #region Clipboard bool pasteEnabled = (ClipboardMode & ClipboardMode.Paste) == ClipboardMode.Paste; bool copyEnabled = (ClipboardMode & ClipboardMode.Copy) == ClipboardMode.Copy; bool cutEnabled = (ClipboardMode & ClipboardMode.Cut) == ClipboardMode.Cut; bool deleteEnabled = (ClipboardMode & ClipboardMode.Delete) == ClipboardMode.Delete; RangeRegion selRegion = Selection.GetSelectionRegion(); //Paste if (e.Control && e.KeyCode == Keys.V && pasteEnabled && selRegion.IsEmpty() == false) { RangeData rngData = RangeData.ClipboardGetData(); if (rngData != null) { Range rng = selRegion.GetRanges()[0]; Range destinationRange = rngData.FindDestinationRange(this, rng.Start); rngData.WriteData(this, destinationRange); e.Handled = true; Selection.ResetSelection(true); Selection.SelectRange(destinationRange, true); } } //Copy else if (e.Control && e.KeyCode == Keys.C && copyEnabled && selRegion.IsEmpty() == false) { Range rng = selRegion.GetRanges()[0]; RangeData data = new RangeData(); data.LoadData(this, rng, rng.Start, CutMode.None); RangeData.ClipboardSetData(data); e.Handled = true; } //Cut else if (e.Control && e.KeyCode == Keys.X && cutEnabled && selRegion.IsEmpty() == false) { Range rng = selRegion.GetRanges()[0]; RangeData data = new RangeData(); data.LoadData(this, rng, rng.Start, CutMode.CutImmediately); RangeData.ClipboardSetData(data); e.Handled = true; } //Delete else if (e.KeyCode == Keys.Delete && deleteEnabled) { ClearValues(selRegion); e.Handled = true; } #endregion }
/// <summary> /// Draw the specified Cell /// </summary> protected virtual void PaintCell(DevAge.Drawing.GraphicsCache graphics, CellContext cellContext, RectangleF drawRectangle) { if (drawRectangle.Width > 0 && drawRectangle.Height > 0 && (cellContext.Cell.Editor == null || cellContext.Cell.Editor.EnableCellDrawOnEdit || cellContext.IsEditing() == false) ) { cellContext.Cell.View.DrawCell(cellContext, graphics, drawRectangle); } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); //verifico che l'eventuale edit sia terminato altrimenti esco if (Selection.ActivePosition.IsEmpty() == false) { CellContext focusCell = new CellContext(this, Selection.ActivePosition); if (focusCell.Cell != null && focusCell.IsEditing()) { if (focusCell.EndEdit(false) == false) return; } } //scateno eventi di MouseDown Position position = PositionAtPoint(new Point(e.X, e.Y)); if (position.IsEmpty() == false) { Cells.ICellVirtual cellMouseDown = GetCell(position); if (cellMouseDown != null) { ChangeMouseDownCell(position, position); //Cell.OnMouseDown CellContext cellContext = new CellContext(this, position, cellMouseDown); Controller.OnMouseDown(cellContext, e); } } else ChangeMouseDownCell(Position.Empty, Position.Empty); }
/// <summary> /// Process Delete, Ctrl+C, Ctrl+V, Up, Down, Left, Right, Tab keys /// </summary> /// <param name="e"></param> public virtual void ProcessSpecialGridKey(KeyEventArgs e) { if (e.Handled) return; bool enableArrows,enableTab,enablePageDownUp; enableArrows = enableTab = enablePageDownUp = false; if ( (SpecialKeys & GridSpecialKeys.Arrows) == GridSpecialKeys.Arrows) enableArrows = true; if ( (SpecialKeys & GridSpecialKeys.PageDownUp) == GridSpecialKeys.PageDownUp) enablePageDownUp = true; if ( (SpecialKeys & GridSpecialKeys.Tab) == GridSpecialKeys.Tab) enableTab = true; bool enableEscape = false; if ( (SpecialKeys & GridSpecialKeys.Escape) == GridSpecialKeys.Escape) enableEscape = true; bool enableEnter = false; if ( (SpecialKeys & GridSpecialKeys.Enter) == GridSpecialKeys.Enter) enableEnter = true; #region Processing keys //Escape if (e.KeyCode == Keys.Escape && enableEscape) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { if (focusCellContext.EndEdit(true)) e.Handled = true; } } //Enter if (e.KeyCode == Keys.Enter && enableEnter) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { focusCellContext.EndEdit(false); e.Handled = true; } } //Tab if (e.KeyCode == Keys.Tab && enableTab) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { //se l'editing non riesce considero il tasto processato // altrimenti no, in questo modo il tab ha effetto anche per lo spostamento if (focusCellContext.EndEdit(false) == false) { e.Handled = true; return; } } } #endregion #region Navigate keys: arrows, tab and PgDown/Up var shiftPressed = e.Modifiers == Keys.Shift; var resetSelection = shiftPressed == false; if (e.KeyCode == Keys.Down && enableArrows) { Selection.MoveActiveCell(1, 0, resetSelection); e.Handled = true; } else if (e.KeyCode == Keys.Up && enableArrows) { Selection.MoveActiveCell(-1, 0, resetSelection); e.Handled = true; } else if (e.KeyCode == Keys.Right && enableArrows) { Selection.MoveActiveCell(0, 1, resetSelection); e.Handled = true; } else if (e.KeyCode == Keys.Left && enableArrows) { Selection.MoveActiveCell(0, -1, resetSelection); e.Handled = true; } else if (e.KeyCode == Keys.Tab && enableTab) { //If the tab failed I automatically select the next control in the form (SelectNextControl) if (e.Modifiers == Keys.Shift) // backward { if (Selection.MoveActiveCell(0, -1, -1, int.MaxValue) == false) FindForm().SelectNextControl(this, false, true, true, true); e.Handled = true; } else //forward { if (Selection.MoveActiveCell(0, 1, 1, int.MinValue) == false) FindForm().SelectNextControl(this, true, true, true, true); e.Handled = true; } } else if ( (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown) && enablePageDownUp) { //MICK(18): I commented out this part - focusing is done within my CustomScrollPageDown() and CustomScrollPageUp() //Point focusPoint = PositionToRectangle(Selection.ActivePosition).Location; //focusPoint.Offset(1, 1); //in modo da entrare nella cella if (e.KeyCode == Keys.PageDown) CustomScrollPageDown(); else if (e.KeyCode == Keys.PageUp) CustomScrollPageUp(); //MICK(18): I commented out this part - focusing is done within my CustomScrollPageDown() and CustomScrollPageUp() //Position newPosition = PositionAtPoint(focusPoint); //if (Selection.CanReceiveFocus(newPosition)) // Selection.Focus(newPosition, true); e.Handled = true; } if (shiftPressed) { Selection.ResetSelection(true); Selection.SelectRange(new Range(m_firstCellShiftSelected, Selection.ActivePosition), true); } #endregion #region Clipboard RangeRegion selRegion = (ClipboardUseOnlyActivePosition ? new RangeRegion(Selection.ActivePosition) : Selection.GetSelectionRegion()); //Paste if (e.Control && e.KeyCode == Keys.V) { PerformPaste(selRegion); e.Handled = true; } //Copy else if (e.Control && e.KeyCode == Keys.C) { PerformCopy(selRegion); e.Handled = true; } //Cut else if (e.Control && e.KeyCode == Keys.X) { PerformCut(selRegion); e.Handled = true; } //Delete else if (e.KeyCode == Keys.Delete) { PerformDelete(selRegion); e.Handled = true; } #endregion }
/// <summary> /// Draw the selection using the SelectionColor property over the selected cells. Draw a Border around the selection using Border and BorderMode properties. /// </summary> /// <param name="p_Panel"></param> /// <param name="graphics"></param> /// <param name="pRangeToRedraw">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param> public virtual void DrawSelectionMask(GridSubPanel p_Panel, DevAge.Drawing.GraphicsCache graphics, Range pRangeToRedraw) { if (IsEmpty()) { return; } Region oldClip = graphics.Graphics.Clip; SolidBrush brushFillMask = graphics.BrushsCache.GetBrush(BackColor); try { graphics.Graphics.Clip = new Region(graphics.ClipRectangle); Range rangeFocus = Range.Empty; Rectangle rectFocus = Rectangle.Empty; if (m_ActivePosition.IsEmpty() == false && pRangeToRedraw.Contains(m_ActivePosition)) { rectFocus = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(m_ActivePosition)); rangeFocus = Grid.PositionToCellRange(m_ActivePosition); } Cells.ICellVirtual cellFocus = Grid.GetCell(m_ActivePosition); //Draw selection mask and border //Draw each cell separately if ((m_MaskStyle & SelectionMaskStyle.DrawOnlyInitializedCells) == SelectionMaskStyle.DrawOnlyInitializedCells && (MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells) //Draw Over cells enabled? { PositionCollection selectedCells = GetCellsPositions(); for (int i = 0; i < selectedCells.Count; i++) { //if must be redrawed, is is not the cell with the focus and contains a cell if (pRangeToRedraw.Contains(selectedCells[i]) && rangeFocus.Contains(selectedCells[i]) == false && Grid.GetCell(selectedCells[i]) != null) { Rectangle rect = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(selectedCells[i])); graphics.Graphics.FillRectangle(brushFillMask, rect); } } } //draw all the selected ranges (Default) //Draw Over cells enabled? else if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells) { RangeCollection selectedRanges = GetRanges(); for (int i = 0; i < selectedRanges.Count; i++) { Range range = selectedRanges[i]; if (range.IntersectsWith(pRangeToRedraw)) { Rectangle rect = p_Panel.RectangleGridToPanel(Grid.RangeToRectangle(range)); if (range.Contains(m_ActivePosition)) { Region region = new Region(rect); region.Exclude(rectFocus); graphics.Graphics.FillRegion(brushFillMask, region); } else { graphics.Graphics.FillRectangle(brushFillMask, rect); } } } } //Draw focus mask and focus border (only if there is a fucus cell and is not in editng mode) CellContext focusCellContext = new CellContext(Grid, m_ActivePosition, cellFocus); if (cellFocus != null && focusCellContext.IsEditing() == false && pRangeToRedraw.Contains(m_ActivePosition)) { //Draw Over cells enabled? if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells) { if (m_FocusBackColor != Color.Transparent) { Brush focusBrush = graphics.BrushsCache.GetBrush(m_FocusBackColor); graphics.Graphics.FillRectangle(focusBrush, rectFocus); } } } if (focusCellContext.IsEditing() == false) { mRangeHighlight.DrawHighlight(p_Panel, graphics, pRangeToRedraw); } } finally { graphics.Graphics.Clip = oldClip; } }