public override int GetHashCode() { int hash = 1; if (CmdCode.Length != 0) { hash ^= CmdCode.GetHashCode(); } if (Identity.Length != 0) { hash ^= Identity.GetHashCode(); } if (OppositeId.Length != 0) { hash ^= OppositeId.GetHashCode(); } if (ServerId != 0) { hash ^= ServerId.GetHashCode(); } if (CellAddr != 0) { hash ^= CellAddr.GetHashCode(); } if (LightNo.Length != 0) { hash ^= LightNo.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
static List <int> getAvailables(CellAddr cellAddr) { List <int> available = values.ToList(); for (int i = 0; i < 9; i++) { if (currentMatrix[i, cellAddr.column] != -1) { available.Remove(currentMatrix[i, cellAddr.column]); } if (currentMatrix[cellAddr.row, i] != -1) { available.Remove(currentMatrix[cellAddr.row, i]); } } int rowStart = (cellAddr.row / 3) * 3; int columnStart = (cellAddr.column / 3) * 3; for (int i = rowStart; i < (rowStart + 3); i++) { for (int j = columnStart; j < (columnStart + 3); j++) { if (currentMatrix[i, j] != -1) { available.Remove(currentMatrix[i, j]); } } } return(available); }
// Paste from the Clipboard. Need to distinguish: // 1. Paste from Corecalc formula Copy: preserve sharing // 2. Paste from Corecalc cell Cut: adjust referring cells and this, if formula // 3. Paste from text (e.g. from Excel), parse to new cell public void Paste() { if (Clipboard.ContainsData(ClipboardCell.COPIED_CELL)) { // Copy Corecalc cell ClipboardCell cc = (ClipboardCell)Clipboard.GetData(ClipboardCell.COPIED_CELL); Console.WriteLine("Pasting copied cell " + Clipboard.GetText()); Cell cell = sheet.workbook[cc.FromSheet][cc.FromCellAddr]; int col, row, cols, rows; GetSelectedColsRows(out col, out row, out cols, out rows); sheet.PasteCell(cell, col, row, cols, rows); RecalculateAndShow(); } else if (Clipboard.ContainsData(ClipboardCell.CUT_CELL)) { // Move Corecalc cell Console.WriteLine("Pasting moved cell not implemented."); } else if (Clipboard.ContainsText()) { // Insert text (from external source) CellAddr ca = new CellAddr(dgv.CurrentCellAddress); String text = Clipboard.GetText(); Console.WriteLine("Pasting text " + text); SetCell(ca.col, ca.row, text); } }
public void Delete() { CellAddr ca = new CellAddr(dgv.CurrentCellAddress); sheet.SetCell(null, ca.col, ca.row); RecalculateAndShow(); }
// Insert cell, which must be Formula, as array formula // in area ((ulCol,ulRow), (lrCol, lrRow)) public void SetArrayFormula(Cell cell, int col, int row, CellAddr ulCa, CellAddr lrCa) { Formula formula = cell as Formula; if (cell == null) { throw new Exception("Invalid array formula"); } else { CachedArrayFormula caf = new CachedArrayFormula(formula, this, col, row, ulCa, lrCa); // Increase support sets of cells referred by formula formula.AddToSupportSets(this, col, row, 1, 1); Interval displayCols = new Interval(ulCa.col, lrCa.col), displayRows = new Interval(ulCa.row, lrCa.row); // The underlying formula supports (only) the ArrayFormula cells in display range formula.ResetSupportSet(); formula.AddSupport(this, col, row, this, displayCols, displayRows); int cols = lrCa.col - ulCa.col + 1, rows = lrCa.row - ulCa.row + 1; for (int c = 0; c < cols; c++) { for (int r = 0; r < rows; r++) { this[ulCa.col + c, ulCa.row + r] = new ArrayFormula(caf, c, r); } } } }
// Evaluate cell ref by evaluating the cell referred to public override Value Eval(Sheet sheet, int col, int row) { CellAddr ca = raref.Addr(col, row); Cell cell = (this.sheet ?? sheet)[ca]; return(cell == null ? null : cell.Eval(sheet, ca.col, ca.row)); }
public ArrayExplicit(CellAddr ulCa, CellAddr lrCa, Value[,] values) { this.ulCa = ulCa; this.lrCa = lrCa; this.values = values; this.cols = lrCa.col - ulCa.col + 1; this.rows = lrCa.row - ulCa.row + 1; }
// Attempt to parse s as cell contents, and set selected cell(s) private void SetCell(int col, int row, String text, DataGridViewCellValidatingEventArgs arg = null) { Cell cell = Cell.Parse(text, sheet.workbook, col, row); ArrayFormula oldArrayFormula = sheet[col, row] as ArrayFormula; gui.SetCyclicError(null); if (cell == null) { if (text.TrimStart(' ').StartsWith("=")) // Ill-formed formula, cancel edit { if (arg != null) { ErrorMessage("Bad formula"); arg.Cancel = true; } return; } else if (!String.IsNullOrWhiteSpace(text)) // Assume a quote expression { cell = Cell.Parse("'" + text, sheet.workbook, col, row); } } DataGridViewSelectedCellCollection dgvscc = dgv.SelectedCells; if (dgvscc.Count > 1 && cell is Formula) // Array formula { int ulCol = col, ulRow = row, lrCol = col, lrRow = row; foreach (DataGridViewCell dgvc in dgvscc) { ulCol = Math.Min(ulCol, dgvc.ColumnIndex); ulRow = Math.Min(ulRow, dgvc.RowIndex); lrCol = Math.Max(lrCol, dgvc.ColumnIndex); lrRow = Math.Max(lrRow, dgvc.RowIndex); } CellAddr ulCa = new CellAddr(ulCol, ulRow), lrCa = new CellAddr(lrCol, lrRow); if (oldArrayFormula != null && arg != null && !(oldArrayFormula.caf.ulCa.Equals(ulCa) && oldArrayFormula.caf.lrCa.Equals(lrCa))) { ErrorMessage("Cannot edit part of array formula"); arg.Cancel = true; return; } sheet.SetArrayFormula(cell, col, row, ulCa, lrCa); } else // One-cell formula, or constant, or null (parse error) { if (oldArrayFormula != null && arg != null) { ErrorMessage("Cannot edit part of array formula"); arg.Cancel = true; return; } sheet.SetCell(cell, col, row); } RecalculateAndShow(); gui.SetCyclicError("Cyclic dependency"); }
private ArrayView(CellAddr ulCa, CellAddr lrCa, Sheet sheet) { this.sheet = sheet; this.ulCa = ulCa; this.lrCa = lrCa; this.cols = lrCa.col - ulCa.col + 1; this.rows = lrCa.row - ulCa.row + 1; }
// Copy sheet's currently active cell to Clipboard, also in text format public void Copy() { CellAddr ca = new CellAddr(dgv.CurrentCellAddress); DataObject data = new DataObject(); data.SetData(DataFormats.Text, sheet[ca].Show(ca.col, ca.row, sheet.workbook.format)); data.SetData(ClipboardCell.COPIED_CELL, new ClipboardCell(sheet.Name, ca)); Clipboard.Clear(); Clipboard.SetDataObject(data, false); }
public override Value View(CellAddr ulCa, CellAddr lrCa) { int cols = Cols, rows = Rows, col0 = ulCa.col, row0 = ulCa.row; Value[,] vals = new Value[cols, rows]; for (int c = 0; c < cols; c++) { for (int r = 0; r < rows; r++) { vals[c, r] = NumberValue.Make(matrix[row0 + r, col0 + c]); } } return new ArrayExplicit(vals); }
private void CellToCellArrow(Graphics g, Pen pen, CellAddr ca1, CellAddr ca2) { if (dgv[ca1.col, ca1.row].Displayed || dgv[ca2.col, ca2.row].Displayed) { // Sadly, dgv.GetCellDisplayRectangle returns Empty outside visible area int x1 = (colOffset[ca1.col] + colOffset[ca1.col + 1]) / 2, y1 = (rowOffset[ca1.row] + rowOffset[ca1.row + 1]) / 2, x2 = (colOffset[ca2.col] + colOffset[ca2.col + 1]) / 2, y2 = (rowOffset[ca2.row] + rowOffset[ca2.row + 1]) / 2; g.DrawLine(pen, x1, y1, x2, y2); } }
bool iterate() { iterateCount++; CellAddr cellAddr = getNextCell(); if (cellAddr == null) { return(true); } List <int> availables = getAvailables(cellAddr); foreach (int available in availables) { currentMatrix[cellAddr.row, cellAddr.column] = available; Debug.Write("\n" + cellAddr.row + "," + cellAddr.column + ":" + available); formMatrixUpdater(this, new MatrixChangedEventArgs() { textBox = formMatrix[cellAddr.row, cellAddr.column], value = available.ToString() }); progressBarUpdater(this, new ProgressChangedEventArgs() { progressBar = progressBar, progress = currentProgress }); if (iterate()) { return(true); } currentMatrix[cellAddr.row, cellAddr.column] = -1; formMatrixUpdater(this, new MatrixChangedEventArgs() { textBox = formMatrix[cellAddr.row, cellAddr.column], value = string.Empty }); progressBarUpdater(this, new ProgressChangedEventArgs() { progressBar = progressBar, progress = currentProgress }); } return(false); }
public override Value View(CellAddr ulCa, CellAddr lrCa) { int cols = Cols, rows = Rows, col0 = ulCa.col, row0 = ulCa.row; Value[,] vals = new Value[cols, rows]; for (int c = 0; c < cols; c++) { for (int r = 0; r < rows; r++) { vals[c, r] = NumberValue.Make(matrix[row0 + r, col0 + c]); } } return(new ArrayExplicit(vals)); }
public ArrayView MakeArrayView(Sheet sheet, int col, int row) { CellAddr ulCa = ul.Addr(col, row), lrCa = lr.Addr(col, row); ArrayView view = ArrayView.Make(ulCa, lrCa, this.sheet ?? sheet); // Forcing the evaluation of all cells in an array view value. // TODO: Doing this repeatedly, as in ManyDependents.xml, is costly for (int c = 0; c < view.Cols; c++) { for (int r = 0; r < view.Rows; r++) { // Value ignore = view[c, r]; } } return(view); }
public override int GetHashCode() { int hash = 1; if (CellAddr != 0) { hash ^= CellAddr.GetHashCode(); } if (Status.Length != 0) { hash ^= Status.GetHashCode(); } if (LightPw != 0) { hash ^= LightPw.GetHashCode(); } if (LightLu != 0) { hash ^= LightLu.GetHashCode(); } if (LightLi != 0) { hash ^= LightLi.GetHashCode(); } if (LightBu != 0) { hash ^= LightBu.GetHashCode(); } if (LightBt != 0) { hash ^= LightBt.GetHashCode(); } if (LightUu != 0) { hash ^= LightUu.GetHashCode(); } if (LightUi != 0) { hash ^= LightUi.GetHashCode(); } hash ^= lightBgus_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (CellAddr != 0) { hash ^= CellAddr.GetHashCode(); } if (LightNo.Length != 0) { hash ^= LightNo.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private bool supportAdded, supportRemoved; // Referred cells' support sets up to date // Invariant: Every cell within the display area sheet[ulCa, lrCa] is an // ArrayFormula whose CachedArrayFormula instance is this one. public CachedArrayFormula(Formula formula, Sheet sheet, int formulaCol, int formulaRow, CellAddr ulCa, CellAddr lrCa) { if (formula == null) { throw new Exception("CachedArrayFormula arguments"); } else { this.formula = formula; this._sheet = sheet; this.formulaCol = formulaCol; this.formulaRow = formulaRow; this.ulCa = ulCa; this.lrCa = lrCa; this.supportAdded = this.supportRemoved = false; } }
// Painting arrows to dependents and precedents of cell ca private void DrawDependents(Graphics g, Pen pen, int depth, CellAddr ca, HashSet <CellAddr> done) { if (depth > 0 && !done.Contains(ca)) { done.Add(ca); Cell cell = sheet[ca]; if (cell != null) { cell.ForEachSupported(delegate(Sheet suppSheet, int suppCol, int suppRow) { CellAddr dependent = new CellAddr(suppCol, suppRow); if (suppSheet == sheet) { CellToCellArrow(g, pen, ca, dependent); DrawDependents(g, pen, depth - 1, dependent, done); } }); } } }
private void DrawPrecedents(Graphics g, Pen pen, int depth, CellAddr ca, HashSet <CellAddr> done) { if (depth > 0 && !done.Contains(ca)) { done.Add(ca); Cell cell = sheet[ca]; if (cell != null) { cell.ForEachReferred(sheet, ca.col, ca.row, delegate(FullCellAddr precedent) { if (precedent.sheet == sheet) { CellToCellArrow(g, pen, precedent.ca, ca); DrawPrecedents(g, pen, depth - 1, precedent.ca, done); } }); } } }
public void ApplyToFcas(Sheet sheet, int col, int row, Action <FullCellAddr> act) { CellAddr ulCa = ul.Addr(col, row), lrCa = lr.Addr(col, row); ArrayView.Make(ulCa, lrCa, this.sheet ?? sheet).Apply(act); }
public Cell this[CellAddr ca] { get { return(this[ca.col, ca.row]); } private set { this[ca.col, ca.row] = value; } }
public SheetTab(WorkbookForm gui, Sheet sheet) : base(sheet.Name) { this.gui = gui; this.sheet = sheet; this.Name = sheet.Name; this.dgv = new DataGridView(); dgv.ShowEditingIcon = false; dgv.Dock = DockStyle.Fill; Dock = DockStyle.Fill; // Display formula in the current cell and computed value in other cells dgv.CellFormatting += delegate(Object sender, DataGridViewCellFormattingEventArgs e) { int col = e.ColumnIndex, row = e.RowIndex; if (col == dgv.CurrentCellAddress.X && row == dgv.CurrentCellAddress.Y) { Object obj = sheet.Show(col, row); if (obj != null) { e.Value = obj; e.FormattingApplied = true; } } else { Object obj = sheet.ShowValue(col, row); if (obj != null) { e.Value = obj; e.FormattingApplied = true; } } }; // Show current cell's address, and show formula in formula box dgv.CellEnter += delegate(Object sender, DataGridViewCellEventArgs arg) { int row = arg.RowIndex, col = arg.ColumnIndex; dgv.TopLeftHeaderCell.Value = new CellAddr(col, row).ToString(); gui.formulaBox.Text = (String)dgv.CurrentCell.FormattedValue; }; // Check that cell's contents is well-formed after edit dgv.CellValidating += delegate(Object sender, DataGridViewCellValidatingEventArgs arg) { if (dgv.IsCurrentCellInEditMode) { // Update only if cell was edited int row = arg.RowIndex, col = arg.ColumnIndex; Object value = arg.FormattedValue; if (value != null) SetCell(col, row, value.ToString(), arg); } }; // Experiment with painting on the data grid view dgv.Paint += delegate(Object sender, PaintEventArgs arg) { base.OnPaint(arg); // Update column and row offset tables for drawing arrows between cells: int offset = dgv.RowHeadersWidth; for (int col = 0; col < sheet.Cols; col++) { colOffset[col] = offset; offset += dgv.Columns[col].Width; } colOffset[sheet.Cols] = offset; offset = dgv.ColumnHeadersHeight; for (int row = 0; row < sheet.Rows; row++) { rowOffset[row] = offset; offset += dgv.Rows[row].Height; } rowOffset[sheet.Rows] = offset; Pen pen = new Pen(Color.Blue, 1); pen.EndCap = SDD2D.LineCap.ArrowAnchor; pen.StartCap = SDD2D.LineCap.RoundAnchor; if (dgv.SelectedCells.Count > 0) { DataGridViewCell dgvc = dgv.SelectedCells[0]; CellAddr ca = new CellAddr(dgvc.ColumnIndex, dgvc.RowIndex); Graphics g = arg.Graphics; g.SmoothingMode = SDD2D.SmoothingMode.AntiAlias; int x = dgv.RowHeadersWidth, y = dgv.ColumnHeadersHeight, w = dgv.DisplayRectangle.Width - x, h = dgv.DisplayRectangle.Height - y; // Clip headers *before* the scroll translation/transform g.Clip = new Region(new Rectangle(x, y, w, h)); g.Transform = new SDD2D.Matrix(1, 0, 0, 1, -dgv.HorizontalScrollingOffset, -dgv.VerticalScrollingOffset); SupportArea.IdempotentForeach = false; // Draw all arrows into a cell DrawDependents(g, pen, gui.dependentsDepth, ca, new HashSet<CellAddr>()); DrawPrecedents(g, pen, gui.precedentsDepth, ca, new HashSet<CellAddr>()); } }; dgv.SelectionChanged += delegate(Object sender, EventArgs arg) { if (gui.dependentsDepth != 0 || gui.precedentsDepth != 0) { gui.dependentsDepth = gui.precedentsDepth = 0; Refresh(); } }; // Strange: to hold sheet, we need an extra row, but not an extra column? dgv.ColumnCount = sheet.Cols; dgv.RowCount = sheet.Rows + 1; // Allocate offset tables to assist drawing arrows between cells colOffset = new int[sheet.Cols + 1]; rowOffset = new int[sheet.Rows + 1]; dgv.AllowUserToAddRows = false; // Put labels on columns and rows, disable (meaningless) row sorting: for (int col = 0; col < dgv.ColumnCount; col++) { dgv.Columns[col].Name = CellAddr.ColumnName(col); dgv.Columns[col].SortMode = DataGridViewColumnSortMode.NotSortable; } for (int row = 0; row < dgv.RowCount; row++) dgv.Rows[row].HeaderCell.Value = (row + 1).ToString(); if (sheet.IsFunctionSheet) { DataGridViewCellStyle cellStyle = new DataGridViewCellStyle(); cellStyle.BackColor = Color.LightPink; dgv.ColumnHeadersDefaultCellStyle = dgv.RowHeadersDefaultCellStyle = cellStyle; } // Somewhat arbitrary extension of the width -- using // Graphics.MeasureString("0000", dgv.Font) would be better dgv.RowHeadersWidth += 20; Controls.Add(dgv); }
// Attempt to parse s as cell contents, and set selected cell(s) private void SetCell(int col, int row, String text, DataGridViewCellValidatingEventArgs arg = null) { Cell cell = Cell.Parse(text, sheet.workbook, col, row); ArrayFormula oldArrayFormula = sheet[col, row] as ArrayFormula; gui.SetCyclicError(null); if (cell == null) { if (text.TrimStart(' ').StartsWith("=")) { // Ill-formed formula, cancel edit if (arg != null) { ErrorMessage("Bad formula"); arg.Cancel = true; } return; } else if (!String.IsNullOrWhiteSpace(text)) // Assume a quote expression cell = Cell.Parse("'" + text, sheet.workbook, col, row); } DataGridViewSelectedCellCollection dgvscc = dgv.SelectedCells; if (dgvscc.Count > 1 && cell is Formula) { // Array formula int ulCol = col, ulRow = row, lrCol = col, lrRow = row; foreach (DataGridViewCell dgvc in dgvscc) { ulCol = Math.Min(ulCol, dgvc.ColumnIndex); ulRow = Math.Min(ulRow, dgvc.RowIndex); lrCol = Math.Max(lrCol, dgvc.ColumnIndex); lrRow = Math.Max(lrRow, dgvc.RowIndex); } CellAddr ulCa = new CellAddr(ulCol, ulRow), lrCa = new CellAddr(lrCol, lrRow); if (oldArrayFormula != null && arg != null && !(oldArrayFormula.caf.ulCa.Equals(ulCa) && oldArrayFormula.caf.lrCa.Equals(lrCa))) { ErrorMessage("Cannot edit part of array formula"); arg.Cancel = true; return; } sheet.SetArrayFormula(cell, col, row, ulCa, lrCa); } else { // One-cell formula, or constant, or null (parse error) if (oldArrayFormula != null && arg != null) { ErrorMessage("Cannot edit part of array formula"); arg.Cancel = true; return; } sheet.SetCell(cell, col, row); } RecalculateAndShow(); gui.SetCyclicError("Cyclic dependency"); }
// Painting arrows to dependents and precedents of cell ca private void DrawDependents(Graphics g, Pen pen, int depth, CellAddr ca, HashSet<CellAddr> done) { if (depth > 0 && !done.Contains(ca)) { done.Add(ca); Cell cell = sheet[ca]; if (cell != null) { cell.ForEachSupported(delegate(Sheet suppSheet, int suppCol, int suppRow) { CellAddr dependent = new CellAddr(suppCol, suppRow); if (suppSheet == sheet) { CellToCellArrow(g, pen, ca, dependent); DrawDependents(g, pen, depth - 1, dependent, done); } }); } } }
public void SetCurrentCell(String text) { CellAddr ca = new CellAddr(dgv.CurrentCellAddress); SetCell(ca.col, ca.row, text); }
public abstract Value View(CellAddr ulCa, CellAddr lrCa);
public SheetTab(WorkbookForm gui, Sheet sheet) : base(sheet.Name) { this.gui = gui; this.sheet = sheet; this.Name = sheet.Name; this.dgv = new DataGridView(); dgv.ShowEditingIcon = false; dgv.Dock = DockStyle.Fill; Dock = DockStyle.Fill; // Display formula in the current cell and computed value in other cells dgv.CellFormatting += delegate(Object sender, DataGridViewCellFormattingEventArgs e) { int col = e.ColumnIndex, row = e.RowIndex; if (col == dgv.CurrentCellAddress.X && row == dgv.CurrentCellAddress.Y) { Object obj = sheet.Show(col, row); if (obj != null) { e.Value = obj; e.FormattingApplied = true; } } else { Object obj = sheet.ShowValue(col, row); if (obj != null) { e.Value = obj; e.FormattingApplied = true; } } }; // Show current cell's address, and show formula in formula box dgv.CellEnter += delegate(Object sender, DataGridViewCellEventArgs arg) { int row = arg.RowIndex, col = arg.ColumnIndex; dgv.TopLeftHeaderCell.Value = new CellAddr(col, row).ToString(); gui.formulaBox.Text = (String)dgv.CurrentCell.FormattedValue; }; // Check that cell's contents is well-formed after edit dgv.CellValidating += delegate(Object sender, DataGridViewCellValidatingEventArgs arg) { if (dgv.IsCurrentCellInEditMode) // Update only if cell was edited { int row = arg.RowIndex, col = arg.ColumnIndex; Object value = arg.FormattedValue; if (value != null) { SetCell(col, row, value.ToString(), arg); } } }; // Experiment with painting on the data grid view dgv.Paint += delegate(Object sender, PaintEventArgs arg) { base.OnPaint(arg); // Update column and row offset tables for drawing arrows between cells: int offset = dgv.RowHeadersWidth; for (int col = 0; col < sheet.Cols; col++) { colOffset[col] = offset; offset += dgv.Columns[col].Width; } colOffset[sheet.Cols] = offset; offset = dgv.ColumnHeadersHeight; for (int row = 0; row < sheet.Rows; row++) { rowOffset[row] = offset; offset += dgv.Rows[row].Height; } rowOffset[sheet.Rows] = offset; Pen pen = new Pen(Color.Blue, 1); pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; pen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; if (dgv.SelectedCells.Count > 0) { DataGridViewCell dgvc = dgv.SelectedCells[0]; CellAddr ca = new CellAddr(dgvc.ColumnIndex, dgvc.RowIndex); Graphics g = arg.Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; int x = dgv.RowHeadersWidth, y = dgv.ColumnHeadersHeight, w = dgv.DisplayRectangle.Width - x, h = dgv.DisplayRectangle.Height - y; // Clip headers *before* the scroll translation/transform g.Clip = new Region(new Rectangle(x, y, w, h)); g.Transform = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, -dgv.HorizontalScrollingOffset, -dgv.VerticalScrollingOffset); SupportArea.IdempotentForeach = false; // Draw all arrows into a cell DrawDependents(g, pen, gui.dependentsDepth, ca, new HashSet <CellAddr>()); DrawPrecedents(g, pen, gui.precedentsDepth, ca, new HashSet <CellAddr>()); } }; dgv.SelectionChanged += delegate(Object sender, EventArgs arg) { if (gui.dependentsDepth != 0 || gui.precedentsDepth != 0) { gui.dependentsDepth = gui.precedentsDepth = 0; Refresh(); } }; // Strange: to hold sheet, we need an extra row, but not an extra column? dgv.ColumnCount = sheet.Cols; dgv.RowCount = sheet.Rows + 1; // Allocate offset tables to assist drawing arrows between cells colOffset = new int[sheet.Cols + 1]; rowOffset = new int[sheet.Rows + 1]; dgv.AllowUserToAddRows = false; // Put labels on columns and rows, disable (meaningless) row sorting: for (int col = 0; col < dgv.ColumnCount; col++) { dgv.Columns[col].Name = CellAddr.ColumnName(col); dgv.Columns[col].SortMode = DataGridViewColumnSortMode.NotSortable; } for (int row = 0; row < dgv.RowCount; row++) { dgv.Rows[row].HeaderCell.Value = (row + 1).ToString(); } if (sheet.IsFunctionSheet) { DataGridViewCellStyle cellStyle = new DataGridViewCellStyle(); cellStyle.BackColor = Color.LightPink; dgv.ColumnHeadersDefaultCellStyle = dgv.RowHeadersDefaultCellStyle = cellStyle; } // Somewhat arbitrary extension of the width -- using // Graphics.MeasureString("0000", dgv.Font) would be better dgv.RowHeadersWidth += 20; Controls.Add(dgv); }
public override Value View(CellAddr ulCa, CellAddr lrCa) { return new ArrayExplicit(ulCa.Offset(this.ulCa), lrCa.Offset(this.ulCa), values); }
// Get cell value from array value public virtual Value this[CellAddr ca] { get { return(this[ca.col, ca.row]); } }
public void SetCellErrorText(CellAddr ca, String message) { dgv[ca.col, ca.row].ErrorText = message; }
public override string ToString() { CellAddr ulCa = new CellAddr(colInt.min, rowInt.min), lrCa = new CellAddr(colInt.max, rowInt.max); return String.Format("{0}!{1}:{2}", sheet.Name, ulCa, lrCa); }
private void DrawPrecedents(Graphics g, Pen pen, int depth, CellAddr ca, HashSet<CellAddr> done) { if (depth > 0 && !done.Contains(ca)) { done.Add(ca); Cell cell = sheet[ca]; if (cell != null) { cell.ForEachReferred(sheet, ca.col, ca.row, delegate(FullCellAddr precedent) { if (precedent.sheet == sheet) { CellToCellArrow(g, pen, precedent.ca, ca); DrawPrecedents(g, pen, depth-1, precedent.ca, done); } }); } } }
public ClipboardCell(String fromSheet, CellAddr fromCellAddr) { this.FromSheet = fromSheet; this.FromCellAddr = fromCellAddr; }
public override Value Slice(CellAddr ulCa, CellAddr lrCa) { return(View(ulCa, lrCa)); }
public abstract Value Slice(CellAddr ulCa, CellAddr lrCa);
private readonly CellAddr ca; // Cell's location within array value public ArrayFormula(CachedArrayFormula caf, CellAddr ca) { this.caf = caf; this.ca = ca; }
public override Value View(CellAddr ulCa, CellAddr lrCa) { return(new ArrayExplicit(ulCa.Offset(this.ulCa), lrCa.Offset(this.ulCa), values)); }
public override Value Slice(CellAddr ulCa, CellAddr lrCa) { return View(ulCa, lrCa); }
// Get cell value from array value public virtual Value this[CellAddr ca] { get { return this[ca.col, ca.row]; } }