public void Sort(IDictionary <int, int> movedRows) { if (movedRows.Count != 0) { ChangingContext context = new ChangingContext(); foreach (KeyValuePair <CalcLocalIdentity, CalcExpression> pair in this.Storage) { CalcCellIdentity identity = pair.Key as CalcCellIdentity; if (identity != null) { int num2; int rowIndex = identity.RowIndex; if (movedRows.TryGetValue(rowIndex, out num2)) { if (!context.ChangedFormulas.ContainsKey(identity)) { context.ChangedFormulas[identity] = null; } if (num2 >= 0) { CalcCellIdentity identity2 = new CalcCellIdentity(num2, identity.ColumnIndex); CalcExpression expr = pair.Value; int?maxColCount = null; expr = new ReferenceValidateVisitor(new int?(this.RowCount - 1), maxColCount).Visit(expr, num2, identity.ColumnIndex); context.ChangedFormulas[identity2] = new Tuple <CalcLocalIdentity, CalcExpression>(identity, expr); } } } } FormulaOperatorHelper.UpdataChangings(this._formulaOperatorSource, context); } }
public static bool ExtractIdentity(this CalcLocalIdentity id, out int row, out int column, out int rowCount, out int columnCount) { int num7; int num8; CalcCellIdentity objA = id as CalcCellIdentity; CalcRangeIdentity identity2 = id as CalcRangeIdentity; ConditionalGraph.ConditionalIdentity identity3 = id as ConditionalGraph.ConditionalIdentity; if (!object.ReferenceEquals(objA, null)) { row = objA.RowIndex; column = objA.ColumnIndex; rowCount = columnCount = 1; return(true); } if (!object.ReferenceEquals(identity2, null)) { if (identity2.IsFullRow && identity2.IsFullColumn) { int num2; int num3; columnCount = num2 = -1; rowCount = num3 = num2; row = column = num3; } else if (identity2.IsFullRow) { column = columnCount = -1; row = identity2.RowIndex; rowCount = identity2.RowCount; } else if (identity2.IsFullColumn) { row = rowCount = -1; column = identity2.ColumnIndex; columnCount = identity2.ColumnCount; } else { row = identity2.RowIndex; rowCount = identity2.RowCount; column = identity2.ColumnIndex; columnCount = identity2.ColumnCount; } return(true); } if (!object.ReferenceEquals(identity3, null)) { return(identity3.ActualIdentity.ExtractIdentity(out row, out column, out rowCount, out columnCount)); } columnCount = num7 = -2147483648; rowCount = num8 = num7; row = column = num8; return(false); }
public override object GetValue(int range, int rowOffset, int columnOffset) { int rowIndex = this.row + rowOffset; int columnIndex = this.column + columnOffset; if (((rowIndex > -1) && (rowIndex < this.sheetRowCount)) && ((columnIndex > -1) && (columnIndex < this.sheetColumnCount))) { CalcCellIdentity id = new CalcCellIdentity(rowIndex, columnIndex); return(this.context.GetValue(id)); } return(null); }
static CalcLocalIdentity Offset(CalcLocalIdentity id, int rowOffset, int colOffset) { CalcCellIdentity cellIdentity = id as CalcCellIdentity; CalcRangeIdentity range = id as CalcRangeIdentity; if (cellIdentity != null) { return(new CalcCellIdentity(cellIdentity, rowOffset, colOffset)); } if (range != null) { return(new CalcRangeIdentity(range, rowOffset, colOffset)); } return(id); }
protected override CalcExpression VisitCellExpression(CalcCellExpression expr, int baseRow, int baseColumn) { bool flag = this._maxRowIndex.HasValue && expr.RowRelative; bool flag2 = this._maxColIndex.HasValue && expr.ColumnRelative; if (!flag && !flag2) { return(expr); } CalcCellIdentity identity = this.GetId(expr, baseRow, baseColumn) as CalcCellIdentity; if ((!flag || ((identity.RowIndex >= 0) && (identity.RowIndex <= this._maxRowIndex.Value))) && (!flag2 || ((identity.ColumnIndex >= 0) && (identity.ColumnIndex <= this._maxColIndex.Value)))) { return(expr); } return(new CalcErrorExpression(CalcErrors.Reference)); }
internal static Dictionary <CalcLocalIdentity, CalcExpression> GetAllContainsIds(CalcCalculationManager mgr, CalcLocalIdentity id) { Dictionary <CalcCellIdentity, CalcExpression> dictionary2; Dictionary <CalcRangeIdentity, CalcExpression> dictionary3; Dictionary <CalcLocalIdentity, CalcExpression> dictionary = new Dictionary <CalcLocalIdentity, CalcExpression>(); GetAllContainsIds(mgr, id, out dictionary2, out dictionary3); foreach (KeyValuePair <CalcCellIdentity, CalcExpression> pair in dictionary2) { CalcCellIdentity introduced7 = pair.Key; dictionary[introduced7] = pair.Value; } foreach (KeyValuePair <CalcRangeIdentity, CalcExpression> pair2 in dictionary3) { CalcRangeIdentity introduced8 = pair2.Key; dictionary[introduced8] = pair2.Value; } return(dictionary); }
protected override CalcExpression VisitCellExpression(CalcCellExpression expr, int baseRow, int baseColumn) { int num2; int num4; if (base.OffsetExternalOnly) { return(expr); } if (this._isFullBand && ((this._isRow && expr.RowRelative) || (!this._isRow && expr.ColumnRelative))) { return(expr); } CalcCellIdentity id = expr.GetId(baseRow, baseColumn) as CalcCellIdentity; int oldIndex = this._isRow ? id.RowIndex : id.ColumnIndex; this.GetCellOffset(oldIndex, out num2); int num3 = this._isRow ? baseRow : baseColumn; this.GetCellOffset(num3, out num4); if (num2 == -2147483648) { return(new CalcErrorExpression(CalcErrors.Reference)); } int row = num2 - oldIndex; if ((this._isRow && expr.RowRelative) || (!this._isRow && expr.ColumnRelative)) { row -= num4 - num3; } if (row == 0) { return(base.VisitCellExpression(expr, baseRow, baseColumn)); } if (this._isRow) { return(expr.Offset(row, 0, true, !this.OffsetAbsoluteOnly)); } return(expr.Offset(0, row, true, !this.OffsetAbsoluteOnly)); }
protected override CalcExpression VisitCellExpression(CalcCellExpression expr, int baseRow, int baseColumn) { CalcCellIdentity id = expr.GetId(baseRow, baseColumn) as CalcCellIdentity; if (!this._isCopy || !this._offsetForDependency) { if (this._offsetForDependency) { if ((((id.RowIndex + this._rowOffset) < 0) || ((id.ColumnIndex + this._columnOffset) < 0)) || (((id.RowIndex + this._rowOffset) >= this._rowCount) || ((id.ColumnIndex + this._columnOffset) >= this._columnCount))) { return(new CalcErrorExpression(CalcErrors.Reference)); } if (this.NeedMove(id.RowIndex, id.ColumnIndex, -1, -1)) { expr = expr.Offset(this._rowOffset, this._columnOffset, this._offsetForDependency, true) as CalcCellExpression; } } else if (!this._isCopy) { if (!expr.RowRelative) { this._rowOffset = 0; } if (!expr.ColumnRelative) { this._columnOffset = 0; } if (this.NeedMove(baseRow, baseColumn, -1, -1)) { expr = expr.Offset(-this._rowOffset, -this._columnOffset, false, true) as CalcCellExpression; } } if (this._convertToExternal) { return(new CalcExternalCellExpression(this._extSource, expr.Row, expr.Column, expr.RowRelative, expr.ColumnRelative)); } } return(expr); }
static void GetTargetFormulas(CalcCalculationManager sourceMgr, CalcCalculationManager targetMgr, int sourceRowCount, int sourceColumnCount, int fromRow, int fromColumn, int toRow, int toColumn, int fromRowCount, int fromColumnCount, int toRowCount, int toColumnCount, Dictionary <CalcCellIdentity, CalcExpression> cellFormulas, Dictionary <CalcRangeIdentity, CalcExpression> rangeFormulas, bool offsetSelf, out Dictionary <CalcLocalIdentity, CalcExpression> newExpressions) { MoveVisitor visitor; int rowOffset = toRow - fromRow; int columnOffset = toColumn - fromColumn; CellRange fromRange = new CellRange(fromRow, fromColumn, fromRowCount, fromColumnCount); MoveVisitor visitor2 = new MoveVisitor(fromRange, rowOffset, columnOffset, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, sourceMgr != targetMgr, null, !offsetSelf); newExpressions = new Dictionary <CalcLocalIdentity, CalcExpression>(); if ((cellFormulas != null) && (cellFormulas.Count > 0)) { for (int i = toRow; i < (toRow + toRowCount); i++) { int rowIndex = ((i - toRow) % fromRowCount) + fromRow; for (int j = toColumn; j < (toColumn + toColumnCount); j++) { int columnIndex = ((j - toColumn) % fromColumnCount) + fromColumn; CalcCellIdentity identity = new CalcCellIdentity(rowIndex, columnIndex); CalcCellIdentity id = new CalcCellIdentity(i, j); if (cellFormulas.ContainsKey(identity)) { CalcExpression expr = cellFormulas[identity]; if (!offsetSelf) { visitor = new MoveVisitor(fromRange, rowOffset, columnOffset, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, false, null, true); expr = visitor.FirstVisit(expr, identity.RowIndex, identity.ColumnIndex); } else { expr = visitor2.Visit(expr, identity.RowIndex, identity.ColumnIndex); } newExpressions[id] = expr; } else if (targetMgr.GetExpression(id) != null) { newExpressions[id] = null; } } } } int num7 = (toRow + toRowCount) - 1; int num8 = (toColumn + toColumnCount) - 1; if ((rangeFormulas != null) && (rangeFormulas.Count > 0)) { foreach (KeyValuePair <CalcRangeIdentity, CalcExpression> pair in rangeFormulas) { int baseRow = (pair.Key.RowIndex < 0) ? 0 : pair.Key.RowIndex; int baseColumn = (pair.Key.ColumnIndex < 0) ? 0 : pair.Key.ColumnIndex; if (!pair.Key.IsFullRow || !pair.Key.IsFullColumn) { if (pair.Key.IsFullColumn) { for (int k = toColumn; k <= num8; k += fromColumnCount) { int num12 = (k + pair.Key.ColumnCount) - 1; num12 = (num12 > num8) ? (num8 - k) : num12; CalcRangeIdentity identity3 = new CalcRangeIdentity((k + pair.Key.ColumnIndex) - fromColumn, (num12 - k) + 1, false); CalcExpression expression2 = pair.Value; if (!offsetSelf) { visitor = new MoveVisitor(fromRange, 0, columnOffset, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, sourceMgr != targetMgr, null, true); expression2 = visitor.Visit(expression2, baseRow, baseColumn); } else { expression2 = visitor2.Visit(expression2, baseRow, baseColumn); } newExpressions[identity3] = expression2; } } else if (pair.Key.IsFullRow) { for (int m = toRow; m <= num7; m += fromRowCount) { int num14 = (m + pair.Key.RowCount) - 1; num14 = (num14 > num7) ? (num7 - m) : num14; CalcRangeIdentity identity4 = new CalcRangeIdentity((m + pair.Key.RowIndex) - fromRow, (num14 - m) + 1, true); CalcExpression expression3 = pair.Value; if (!offsetSelf) { visitor = new MoveVisitor(fromRange, rowOffset, 0, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, sourceMgr != targetMgr, null, true); expression3 = visitor.Visit(expression3, baseRow, baseColumn); } else { expression3 = visitor2.Visit(expression3, baseRow, baseColumn); } newExpressions[identity4] = expression3; } } else { for (int n = toRow; n <= num7; n += fromRowCount) { int num16 = (n + pair.Key.RowCount) - 1; num16 = (num16 > num7) ? (num7 - n) : num16; for (int num17 = toColumn; num17 <= num8; num17 += fromColumnCount) { int num18 = (num17 + pair.Key.ColumnCount) - 1; num18 = (num18 > num8) ? (num8 - num17) : num18; CalcRangeIdentity identity5 = new CalcRangeIdentity((n + pair.Key.RowIndex) - fromRow, (num17 + pair.Key.ColumnIndex) - fromColumn, (num16 - n) + 1, (num18 - num17) + 1); CalcExpression expression4 = pair.Value; if (!offsetSelf) { expression4 = new MoveVisitor(fromRange, rowOffset, columnOffset, sourceRowCount, sourceColumnCount, false, sourceMgr.Source, sourceMgr != targetMgr, null, true).Visit(expression4, baseRow, baseColumn); } else { expression4 = visitor2.Visit(expression4, baseRow, baseColumn); } newExpressions[identity5] = expression4; } } } } } } }
public static void Identity2Indexs(CalcIdentity id, out int startRow, out int startColumn, out int lastRow, out int lastColumn) { if (id is CalcCellIdentity) { CalcCellIdentity identity = id as CalcCellIdentity; startRow = identity.RowIndex; startColumn = identity.ColumnIndex; lastRow = identity.RowIndex; lastColumn = identity.ColumnIndex; } else if (id is CalcExternalCellIdentity) { CalcExternalCellIdentity identity2 = id as CalcExternalCellIdentity; startRow = identity2.RowIndex; startColumn = identity2.ColumnIndex; lastRow = identity2.RowIndex; lastColumn = identity2.ColumnIndex; } else if (id is CalcRangeIdentity) { CalcRangeIdentity identity3 = id as CalcRangeIdentity; if (identity3.IsFullRow) { startColumn = -1; lastColumn = -1; } else { startColumn = identity3.ColumnIndex; lastColumn = (identity3.ColumnIndex + identity3.ColumnCount) - 1; } if (identity3.IsFullColumn) { startRow = -1; lastRow = -1; } else { startRow = identity3.RowIndex; lastRow = (identity3.RowIndex + identity3.RowCount) - 1; } } else if (id is CalcExternalRangeIdentity) { CalcExternalRangeIdentity identity4 = id as CalcExternalRangeIdentity; if (identity4.IsFullRow) { startColumn = -1; lastColumn = -1; } else { startColumn = identity4.ColumnIndex; lastColumn = (identity4.ColumnIndex + identity4.ColumnCount) - 1; } if (identity4.IsFullColumn) { startRow = -1; lastRow = -1; } else { startRow = identity4.RowIndex; lastRow = (identity4.RowIndex + identity4.RowCount) - 1; } } else if (id is CalcSheetRangeIdentity) { CalcSheetRangeIdentity identity5 = id as CalcSheetRangeIdentity; if (identity5.IsFullRow) { startColumn = -1; lastColumn = -1; } else { startColumn = identity5.ColumnIndex; lastColumn = (identity5.ColumnIndex + identity5.ColumnCount) - 1; } if (identity5.IsFullColumn) { startRow = -1; lastRow = -1; } else { startRow = identity5.RowIndex; lastRow = (identity5.RowIndex + identity5.RowCount) - 1; } } else { startRow = -1; startColumn = -1; lastRow = -1; lastColumn = -1; } }
static void GetChangingIds(IFormulaOperatorSource mgr, bool row, ChangingContext context, OperatorExpressionVisistor visitor, bool updateDependents) { foreach (CalcLocalIdentity identity in mgr.GetAllLocalIdentities()) { CalcIdentity id = identity; if (identity is ConditionalGraph.ConditionalIdentity) { ConditionalGraph.ConditionalIdentity identity3 = identity as ConditionalGraph.ConditionalIdentity; id = (identity3.OldActualIdentity != null) ? identity3.OldActualIdentity : identity3.ActualIdentity; } CalcNode node = mgr.GetNode(id); if ((node == null) || (node.OwnerNode == null)) { CalcCellIdentity identity4 = id as CalcCellIdentity; CalcRangeIdentity identity5 = id as CalcRangeIdentity; CalcExpression expression = mgr.GetExpression(identity); CalcLocalIdentity identity6 = null; int oldStart = -2147483648; int oldEnd = -2147483648; int newEnd = -2147483648; if (identity4 != null) { oldStart = row ? identity4.RowIndex : identity4.ColumnIndex; } else if (identity5 != null) { if (identity5.IsFullRow && identity5.IsFullColumn) { identity6 = identity; oldStart = 0; } else if ((identity5.IsFullRow && !row) || (identity5.IsFullColumn && row)) { if (node != null) { context.InvalidateFormula(mgr, identity5); } if (((node == null) || (node.Dependents == null)) || ((node.Dependents.Count == 0) || !updateDependents)) { continue; } InvalidateNode(mgr, context, node); } else { oldStart = row ? identity5.RowIndex : identity5.ColumnIndex; oldEnd = row ? ((identity5.RowIndex + identity5.RowCount) - 1) : ((identity5.ColumnIndex + identity5.ColumnCount) - 1); } } if (oldStart != -2147483648) { if (identity6 == null) { int num2; if (identity5 != null) { visitor.GetRangeOffset(oldStart, oldEnd, out num2, out newEnd); if ((num2 == oldStart) && (newEnd == oldEnd)) { continue; } if ((num2 == -2147483648) || (newEnd == -2147483648)) { expression = null; } else if (identity5.IsFullRow && row) { identity6 = new CalcRangeIdentity(num2, (newEnd - num2) + 1, true); } else if (identity5.IsFullColumn && !row) { identity6 = new CalcRangeIdentity(num2, (newEnd - num2) + 1, false); } else if (row) { identity6 = new CalcRangeIdentity(num2, identity5.ColumnIndex, (newEnd - num2) + 1, identity5.ColumnCount); } else { identity6 = new CalcRangeIdentity(identity5.RowIndex, num2, identity5.RowCount, (newEnd - num2) + 1); } } else if (identity4 != null) { visitor.GetCellOffset(oldStart, out num2); if (num2 == oldStart) { continue; } if (num2 == -2147483648) { expression = null; } else if (identity4 != null) { identity6 = row ? new CalcCellIdentity(num2, identity4.ColumnIndex) : new CalcCellIdentity(identity4.RowIndex, num2); } } } context.ChangingIdentities[identity] = identity; if (expression != null) { identity6 = (identity is ConditionalGraph.ConditionalIdentity) ? identity : identity6; context.ChangedFormulas[identity6] = new Tuple <CalcLocalIdentity, CalcExpression>(identity, expression); } } } } }