Commit 929f0aab authored by konovalovsergey's avatar konovalovsergey

bugfix

parent 36ababec
...@@ -407,6 +407,7 @@ var editor; ...@@ -407,6 +407,7 @@ var editor;
AscCommonExcel.g_oUndoRedoRow = new AscCommonExcel.UndoRedoRowCol(wbModel, true); AscCommonExcel.g_oUndoRedoRow = new AscCommonExcel.UndoRedoRowCol(wbModel, true);
AscCommonExcel.g_oUndoRedoComment = new AscCommonExcel.UndoRedoComment(wbModel); AscCommonExcel.g_oUndoRedoComment = new AscCommonExcel.UndoRedoComment(wbModel);
AscCommonExcel.g_oUndoRedoAutoFilters = new AscCommonExcel.UndoRedoAutoFilters(wbModel); AscCommonExcel.g_oUndoRedoAutoFilters = new AscCommonExcel.UndoRedoAutoFilters(wbModel);
AscCommonExcel.g_DefNameWorksheet = new AscCommonExcel.Woorksheet(wbModel, -1);
}; };
spreadsheet_api.prototype.asc_DownloadAs = function(typeFile, bIsDownloadEvent) {//передаем число соответствующее своему формату. например c_oAscFileType.XLSX spreadsheet_api.prototype.asc_DownloadAs = function(typeFile, bIsDownloadEvent) {//передаем число соответствующее своему формату. например c_oAscFileType.XLSX
......
...@@ -3584,6 +3584,13 @@ function parserFormula( formula, parent, _ws ) { ...@@ -3584,6 +3584,13 @@ function parserFormula( formula, parent, _ws ) {
this.isDirty = isDirty; this.isDirty = isDirty;
}; };
parserFormula.prototype.notify = function(data) { parserFormula.prototype.notify = function(data) {
var eventData = {notifyData: data, assembleType: AscCommon.c_oNotifyParentAssemble.Normal, isRebuild: false};
if (this.parent && this.parent.onFormulaEvent) {
var checkCanDo = this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.CanDo, eventData);
if(!checkCanDo){
return;
}
}
if (AscCommon.c_oNotifyType.Dirty === data.type) { if (AscCommon.c_oNotifyType.Dirty === data.type) {
if (!this.isDirty) { if (!this.isDirty) {
this.isDirty = true; this.isDirty = true;
...@@ -3600,10 +3607,19 @@ function parserFormula( formula, parent, _ws ) { ...@@ -3600,10 +3607,19 @@ function parserFormula( formula, parent, _ws ) {
if (AscCommon.c_oNotifyType.Shift === data.type || AscCommon.c_oNotifyType.Move === data.type || if (AscCommon.c_oNotifyType.Shift === data.type || AscCommon.c_oNotifyType.Move === data.type ||
AscCommon.c_oNotifyType.Delete === data.type) { AscCommon.c_oNotifyType.Delete === data.type) {
this.shiftCells(data.type, data.sheetId, data.bbox, data.offset); this.shiftCells(data.type, data.sheetId, data.bbox, data.offset);
eventData.assembleType = AscCommon.c_oNotifyParentAssemble.Flag;
} else if (AscCommon.c_oNotifyType.ChangeDefName === data.type) { } else if (AscCommon.c_oNotifyType.ChangeDefName === data.type) {
this.changeDefName(data.from, data.to); if (!data.to) {
this.removeTableName(data.from);
} else if (data.from.Name != data.to.Name) {
this.changeDefName(data.from, data.to);
} else if (data.from.isTable) {
eventData.assembleType = AscCommon.c_oNotifyParentAssemble.Current;
eventData.isRebuild = true;
}
} else if (AscCommon.c_oNotifyType.Rebuild === data.type) { } else if (AscCommon.c_oNotifyType.Rebuild === data.type) {
; eventData.assembleType = AscCommon.c_oNotifyParentAssemble.Assemble;
eventData.isRebuild = true;
} else if (AscCommon.c_oNotifyType.ChangeSheet === data.type) { } else if (AscCommon.c_oNotifyType.ChangeSheet === data.type) {
if (this.is3D) { if (this.is3D) {
var changeData = data.data; var changeData = data.data;
...@@ -3619,7 +3635,7 @@ function parserFormula( formula, parent, _ws ) { ...@@ -3619,7 +3635,7 @@ function parserFormula( formula, parent, _ws ) {
} }
} }
if (this.parent && this.parent.onFormulaEvent) { if (this.parent && this.parent.onFormulaEvent) {
this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.ChangeFormula); this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.ChangeFormula, eventData);
} }
} }
}; };
...@@ -4400,14 +4416,20 @@ parserFormula.prototype.getRef = function() { ...@@ -4400,14 +4416,20 @@ parserFormula.prototype.getRef = function() {
} }
} }
}; };
parserFormula.prototype.shiftCells = function(notifyType, sheetId, bbox, offset) { parserFormula.prototype.removeTableName = function(defName) {
var isHor = 0 != offset.offsetCol; var i, elem, LocalSheetId;
var oShiftGetBBox; for (i = 0; i < this.outStack.length; i++) {
if (AscCommon.c_oNotifyType.Shift == notifyType) { elem = this.outStack[i];
oShiftGetBBox = AscCommonExcel.shiftGetBBox(bbox, isHor); if (elem.type == cElementType.table) {
} else { LocalSheetId = elem.ws ? elem.ws.getIndex() : null;
oShiftGetBBox = bbox; if (elem.tableName == defName.Name && (null == defName.LocalSheetId || LocalSheetId == defName.LocalSheetId )) {
this.outStack[i] = elem.toRef();
}
}
} }
};
parserFormula.prototype.shiftCells = function(notifyType, sheetId, bbox, offset) {
var isHor = offset && 0 != offset.offsetCol;
var elem; var elem;
for (var i = 0; i < this.outStack.length; i++) { for (var i = 0; i < this.outStack.length; i++) {
elem = this.outStack[i]; elem = this.outStack[i];
...@@ -4429,9 +4451,12 @@ parserFormula.prototype.getRef = function() { ...@@ -4429,9 +4451,12 @@ parserFormula.prototype.getRef = function() {
var _cellsBbox = AscCommonExcel.g_oRangeCache.getAscRange(_cells.replace(this.regSpace, "")); var _cellsBbox = AscCommonExcel.g_oRangeCache.getAscRange(_cells.replace(this.regSpace, ""));
var isIntersect; var isIntersect;
if (AscCommon.c_oNotifyType.Shift == notifyType) { if (AscCommon.c_oNotifyType.Shift == notifyType) {
isIntersect = oShiftGetBBox.isIntersectForShift(_cellsBbox, isHor); isIntersect = bbox.isIntersectForShift(_cellsBbox, offset);
} else { } else if (AscCommon.c_oNotifyType.Move == notifyType) {
isIntersect = oShiftGetBBox.containsRange(_cellsBbox); isIntersect = bbox.containsRange(_cellsBbox);
} else if (AscCommon.c_oNotifyType.Delete == notifyType) {
//isIntersect = bbox.isIntersect(_cellsBbox);
isIntersect = bbox.containsRange(_cellsBbox);
} }
if (isIntersect) { if (isIntersect) {
var isNoDelete; var isNoDelete;
...@@ -4439,9 +4464,32 @@ parserFormula.prototype.getRef = function() { ...@@ -4439,9 +4464,32 @@ parserFormula.prototype.getRef = function() {
_cellsBbox = _cellsBbox.clone(); _cellsBbox = _cellsBbox.clone();
isNoDelete = _cellsBbox.forShift(bbox, offset); isNoDelete = _cellsBbox.forShift(bbox, offset);
} else if (AscCommon.c_oNotifyType.Move == notifyType) { } else if (AscCommon.c_oNotifyType.Move == notifyType) {
_cellsBbox = _cellsBbox.clone();
_cellsBbox.setOffset(offset);
isNoDelete = true; isNoDelete = true;
} else if (AscCommon.c_oNotifyType.Delete == notifyType) { } else if (AscCommon.c_oNotifyType.Delete == notifyType) {
isNoDelete = false; isNoDelete = false;
// if (bbox.containsRange(_cellsBbox)) {
// isNoDelete = false;
// } else {
// isNoDelete = true;
// if (!_cellsBbox.containsRange(bbox)) {
// var ltIn = bbox.contains(_cellsBbox.c1, _cellsBbox.r1);
// var rtIn = bbox.contains(_cellsBbox.c2, _cellsBbox.r1);
// var lbIn = bbox.contains(_cellsBbox.c1, _cellsBbox.r2);
// var rbIn = bbox.contains(_cellsBbox.c2, _cellsBbox.r2);
// _cellsBbox = _cellsBbox.clone();
// if (ltIn && rtIn) {
// _cellsBbox.setOffsetFirst({offsetCol: 0, offsetRow: bbox.r2 - _cellsBbox.r1 + 1});
// } else if (rtIn && rbIn) {
// _cellsBbox.setOffsetLast({offsetCol: bbox.c1 - _cellsBbox.c2 - 1, offsetRow: 0});
// } else if (rbIn && lbIn) {
// _cellsBbox.setOffsetLast({offsetCol: 0, offsetRow: bbox.r1 - _cellsBbox.r2 - 1});
// } else if (lbIn && ltIn) {
// _cellsBbox.setOffsetFirst({offsetCol: bbox.c2 - _cellsBbox.c1 + 1, offsetRow: 0});
// }
// }
// }
} }
if (isNoDelete) { if (isNoDelete) {
elem.value = elem._cells = elem.value = elem._cells =
......
...@@ -188,9 +188,7 @@ function getRangeType(oBBox){ ...@@ -188,9 +188,7 @@ function getRangeType(oBBox){
this.isLock = null; this.isLock = null;
this.parsedRef = null; this.parsedRef = null;
if (this.ref) { if (this.ref) {
//все ссылки должны быть 3d поэтому без разницы какой sheet предавать this.setRef(this.ref, true);
this.parsedRef = new parserFormula(this.ref, this, this.wb.getWorksheet(0));
this.wb.dependencyFormulas.addToBuildDependencyDefName(this);
} }
} }
...@@ -198,7 +196,17 @@ function getRangeType(oBBox){ ...@@ -198,7 +196,17 @@ function getRangeType(oBBox){
removeDependencies: function() { removeDependencies: function() {
if (this.parsedRef) { if (this.parsedRef) {
this.parsedRef.removeDependencies(); this.parsedRef.removeDependencies();
this.parsedRef = null;
}
},
setRef: function(ref, opt_noRemoveDependencies) {
if(!opt_noRemoveDependencies){
this.removeDependencies();
} }
this.ref = ref;
//all ref should be 3d, so worksheet can be anyone
this.parsedRef = new parserFormula(ref, this, AscCommonExcel.g_DefNameWorksheet);
this.wb.dependencyFormulas.addToBuildDependencyDefName(this);
}, },
getNodeId: function() { getNodeId: function() {
return getDefNameId(this.sheetId, this.name); return getDefNameId(this.sheetId, this.name);
...@@ -211,19 +219,49 @@ function getRangeType(oBBox){ ...@@ -211,19 +219,49 @@ function getRangeType(oBBox){
} }
return new Asc.asc_CDefName(this.name, this.ref, index, this.isTable, this.hidden, this.isLock); return new Asc.asc_CDefName(this.name, this.ref, index, this.isTable, this.hidden, this.isLock);
}, },
onFormulaEvent: function(type, data) { setAscCDefName: function(newAscName) {
if (AscCommon.c_oNotifyParentType.Change === type) { this.name = newAscName.Name;
this.sheetId = this.wb.getSheetIdByIndex(newAscName.LocalSheetId);
this.hidden = newAscName.Hidden;
this.isTable = newAscName.isTable;
if(this.ref != newAscName.Ref){
this.setRef(newAscName.Ref);
}
},
onFormulaEvent: function(type, eventData) {
if (AscCommon.c_oNotifyParentType.CanDo === type) {
var type = eventData.notifyData.type;
return !(this.isTable &&
(AscCommon.c_oNotifyType.Shift === type || AscCommon.c_oNotifyType.Move === type ||
AscCommon.c_oNotifyType.Delete === type));
} else if (AscCommon.c_oNotifyParentType.Change === type) {
this.wb.dependencyFormulas.addToChangedDefName(this); this.wb.dependencyFormulas.addToChangedDefName(this);
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) { } else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
var oldAscName = this.getAscCDefName(); var oldAscName = this.getAscCDefName();
this.parsedRef.buildDependencies(); var assemb;
this.parsedRef.Formula = this.parsedRef.assemble(); switch (eventData.assembleType) {
this.ref = this.parsedRef.Formula; case AscCommon.c_oNotifyParentAssemble.Normal:
assemb = this.parsedRef.assemble();
break;
case AscCommon.c_oNotifyParentAssemble.Flag:
assemb = this.parsedRef.assemble(true);
break;
case AscCommon.c_oNotifyParentAssemble.Current:
assemb = this.parsedRef.Formula;
break;
}
if (eventData.isRebuild) {
this.setRef(assemb, true);
} else {
this.ref = this.parsedRef.Formula = assemb;
this.parsedRef.buildDependencies();
this.wb.dependencyFormulas.addToChangedDefName(this);
}
var newAscName = this.getAscCDefName(); var newAscName = this.getAscCDefName();
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_DefinedNamesChangeUndo, null, History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_DefinedNamesChangeUndo, null,
null, new UndoRedoData_DefinedNamesChange(oldAscName, newAscName), true); null, new UndoRedoData_DefinedNamesChange(oldAscName, newAscName), true);
this.wb.dependencyFormulas.addToChangedDefName(this);
} }
return true;
} }
}; };
...@@ -373,16 +411,21 @@ function getRangeType(oBBox){ ...@@ -373,16 +411,21 @@ function getRangeType(oBBox){
//обязательно, формула не в зависимостях не сдвинутся //обязательно, формула не в зависимостях не сдвинутся
this.buildDependency(); this.buildDependency();
this._shiftMoveDelete(AscCommon.c_oNotifyType.Delete, sheetId, bbox, null); this._shiftMoveDelete(AscCommon.c_oNotifyType.Delete, sheetId, bbox, null);
this.addToChangedRange(sheetId, bbox);
}, },
shift: function(sheetId, bbox, offset) { shift: function(sheetId, bbox, offset) {
//обязательно, формула не в зависимостях не сдвинутся //обязательно, формула не в зависимостях не сдвинутся
this.buildDependency(); this.buildDependency();
this._shiftMoveDelete(AscCommon.c_oNotifyType.Shift, sheetId, bbox, offset); this._shiftMoveDelete(AscCommon.c_oNotifyType.Shift, sheetId, bbox, offset);
var bHor = 0 != offset.offsetCol;
var bboxShift = AscCommonExcel.shiftGetBBox(bbox, bHor);
this.addToChangedRange(sheetId, bboxShift);
}, },
move: function(sheetId, bboxFrom, offset) { move: function(sheetId, bboxFrom, offset) {
//обязательно, формула не в зависимостях не сдвинутся //обязательно, формула не в зависимостях не сдвинутся
this.buildDependency(); this.buildDependency();
this._shiftMoveDelete(AscCommon.c_oNotifyType.Move, sheetId, bboxFrom, offset); this._shiftMoveDelete(AscCommon.c_oNotifyType.Move, sheetId, bboxFrom, offset);
this.addToChangedRange(sheetId, bboxFrom);
}, },
changeSheet: function(sheetId, data) { changeSheet: function(sheetId, data) {
this.buildDependency(); this.buildDependency();
...@@ -396,7 +439,7 @@ function getRangeType(oBBox){ ...@@ -396,7 +439,7 @@ function getRangeType(oBBox){
} }
} }
for (var vertexIndex in sheetContainer.areaMap) { for (var vertexIndex in sheetContainer.areaMap) {
var areaSheetElem = sheetContainer.cellMap[vertexIndex]; var areaSheetElem = sheetContainer.areaMap[vertexIndex];
for (var listenerId in areaSheetElem.listeners) { for (var listenerId in areaSheetElem.listeners) {
listeners[listenerId] = areaSheetElem.listeners[listenerId]; listeners[listenerId] = areaSheetElem.listeners[listenerId];
} }
...@@ -498,23 +541,9 @@ function getRangeType(oBBox){ ...@@ -498,23 +541,9 @@ function getRangeType(oBBox){
return names.sort(sort); return names.sort(sort);
}, },
addDefNameOpen: function(name, ref, sheetIndex, hidden, isTable) { addDefNameOpen: function(name, ref, sheetIndex, hidden, isTable) {
var nameIndex = getDefNameIndex(name);
var container;
var sheetId = this.wb.getSheetIdByIndex(sheetIndex); var sheetId = this.wb.getSheetIdByIndex(sheetIndex);
if (sheetId) { var res = new DefName(this.wb, name, ref, sheetId, hidden, isTable);
container = this.defNames.sheet[sheetId]; this._addDefName(res);
if (!container) {
container = {};
this.defNames.sheet[sheetId] = container;
}
} else {
container = this.defNames.wb;
}
var res = container[nameIndex];
if (!res) {
res = new DefName(this.wb, name, ref, sheetId, hidden, isTable);
container[nameIndex] = res;
}
return res; return res;
}, },
removeDefName: function(sheetIndex, name) { removeDefName: function(sheetIndex, name) {
...@@ -527,7 +556,6 @@ function getRangeType(oBBox){ ...@@ -527,7 +556,6 @@ function getRangeType(oBBox){
defName.removeDependencies(); defName.removeDependencies();
this.addToChangedDefName(defName); this.addToChangedDefName(defName);
this.calcTree();
} }
}, },
editDefinesNames: function(oldAscName, newAscName) { editDefinesNames: function(oldAscName, newAscName) {
...@@ -543,27 +571,27 @@ function getRangeType(oBBox){ ...@@ -543,27 +571,27 @@ function getRangeType(oBBox){
false); false);
} }
if (res) { if (res && oldAscName) {
History.Create_NewPoint(); History.Create_NewPoint();
this._delDefName(res.name, res.sheetId); if (oldAscName.Name != newAscName.Name) {
res = this.addDefNameOpen(newAscName.Name, newAscName.Ref, newAscName.LocalSheetId, newAscName.Hidden,
newAscName.isTable);
if (oldAscName && oldAscName.Name != newAscName.Name) {
this.buildDependency(); this.buildDependency();
res = this._delDefName(res.name, res.sheetId);
res.setAscCDefName(newAscName);
this._addDefName(res);
var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: oldAscName, to: newAscName}; var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: oldAscName, to: newAscName};
this._broadcastDefName(oldAscName.Name, notifyData); this._broadcastDefName(oldAscName.Name, notifyData);
this.addToChangedDefName(res);
} else {
res.setAscCDefName(newAscName);
} }
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_DefinedNamesChange, null, History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_DefinedNamesChange, null,
null, new UndoRedoData_DefinedNamesChange(oldAscName, newAscName)); null, new UndoRedoData_DefinedNamesChange(oldAscName, newAscName));
this.addToChangedDefName(res);
} }
this.calcTree();
return res; return res;
}, },
checkDefName: function (name, sheetIndex) { checkDefName: function (name, sheetIndex) {
...@@ -617,20 +645,20 @@ function getRangeType(oBBox){ ...@@ -617,20 +645,20 @@ function getRangeType(oBBox){
}, },
saveDefName: function() { saveDefName: function() {
var list = []; var list = [];
this._foreachDefName(function(defName, container) { this._foreachDefName(function(defName) {
if (!defName.isTable && defName.Ref) { if (!defName.isTable && defName.ref) {
list.push(defName.getAscCDefName()); list.push(defName.getAscCDefName());
} }
}); });
return list; return list;
}, },
unlockDefName: function() { unlockDefName: function() {
this._foreachDefName(function(defName, container) { this._foreachDefName(function(defName) {
defName.isLock = null; defName.isLock = null;
}); });
}, },
checkDefNameLock: function() { checkDefNameLock: function() {
return this._foreachDefName(function(defName, container) { return this._foreachDefName(function(defName) {
return defName.isLock; return defName.isLock;
}); });
}, },
...@@ -668,19 +696,21 @@ function getRangeType(oBBox){ ...@@ -668,19 +696,21 @@ function getRangeType(oBBox){
var defNameRef = parserHelp.get3DRef(ws.getName(), refClone.getAbsName()); var defNameRef = parserHelp.get3DRef(ws.getName(), refClone.getAbsName());
this.addDefNameOpen(sName, defNameRef, null, null, true); this.addDefNameOpen(sName, defNameRef, null, null, true);
} else { } else {
defName.Ref = defNameRef; defName.ref = defNameRef;
} }
}, },
changeTableRef: function(tableName, newRef) { changeTableRef: function(tableName, newRef) {
History.TurnOff();
var defName = this.getDefNameByName(tableName, null); var defName = this.getDefNameByName(tableName, null);
if (defName) { if (defName) {
var oldAscName = defName.getAscCDefName(); var oldAscName = defName.getAscCDefName();
var newAscName = defName.getAscCDefName(); var newAscName = defName.getAscCDefName();
newAscName.Ref = newRef; newAscName.Ref = defName.ref.split('!')[0] + '!' + newRef.getAbsName();
History.TurnOff();
this.editDefinesNames(oldAscName, newAscName); this.editDefinesNames(oldAscName, newAscName);
History.TurnOn(); var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: oldAscName, to: newAscName};
this._broadcastDefName(defName.name, notifyData);
} }
History.TurnOn();
}, },
changeTableName: function(tableName, newName) { changeTableName: function(tableName, newName) {
var defName = this.getDefNameByName(tableName, null); var defName = this.getDefNameByName(tableName, null);
...@@ -695,6 +725,9 @@ function getRangeType(oBBox){ ...@@ -695,6 +725,9 @@ function getRangeType(oBBox){
}, },
delTableName: function(tableName) { delTableName: function(tableName) {
this._delDefName(tableName, null); this._delDefName(tableName, null);
//todo make ref
// var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: defName.getAscCDefName(), to: null};
// this._broadcastDefName(tableName, notifyData);
}, },
rebuildTable: function(tableName) { rebuildTable: function(tableName) {
var defName = this.getDefNameByName(tableName, null); var defName = this.getDefNameByName(tableName, null);
...@@ -857,6 +890,25 @@ function getRangeType(oBBox){ ...@@ -857,6 +890,25 @@ function getRangeType(oBBox){
this.calcTree(); this.calcTree();
}, },
//internal //internal
_addDefName: function(defName) {
var nameIndex = getDefNameIndex(defName.name);
var container;
var sheetId = defName.sheetId;
if (sheetId) {
container = this.defNames.sheet[sheetId];
if (!container) {
container = {};
this.defNames.sheet[sheetId] = container;
}
} else {
container = this.defNames.wb;
}
var cur = container[nameIndex];
if (cur) {
cur.removeDependencies();
}
container[nameIndex] = defName;
},
_delDefName: function(name, sheetId) { _delDefName: function(name, sheetId) {
var res = null; var res = null;
var nameIndex = getDefNameIndex(name); var nameIndex = getDefNameIndex(name);
...@@ -996,19 +1048,18 @@ function getRangeType(oBBox){ ...@@ -996,19 +1048,18 @@ function getRangeType(oBBox){
this.tempGetByCells = []; this.tempGetByCells = [];
}, },
_shiftMoveDelete: function(notifyType, sheetId, bbox, offset) { _shiftMoveDelete: function(notifyType, sheetId, bbox, offset) {
var isHor = offset && 0 != offset.offsetCol;
var oShiftGetBBox;
if (AscCommon.c_oNotifyType.Shift == notifyType) {
oShiftGetBBox = AscCommonExcel.shiftGetBBox(bbox, isHor);
} else if (AscCommon.c_oNotifyType.Move == notifyType || AscCommon.c_oNotifyType.Delete == notifyType) {
oShiftGetBBox = bbox;
}
var sheetContainer = this.sheetListeners[sheetId]; var sheetContainer = this.sheetListeners[sheetId];
if (sheetContainer) { if (sheetContainer) {
var listeners = {}; var listeners = {};
var isIntersect;
for (var cellIndex in sheetContainer.cellMap) { for (var cellIndex in sheetContainer.cellMap) {
getFromCellIndex(cellIndex); getFromCellIndex(cellIndex);
if (oShiftGetBBox.contains(g_FCI.col, g_FCI.row)) { if (AscCommon.c_oNotifyType.Shift == notifyType) {
isIntersect = bbox.isIntersectForShiftCell(g_FCI.col, g_FCI.row, offset);
} else {
isIntersect = bbox.contains(g_FCI.col, g_FCI.row);
}
if (isIntersect) {
var cellMapElem = sheetContainer.cellMap[cellIndex]; var cellMapElem = sheetContainer.cellMap[cellIndex];
for (var listenerId in cellMapElem.listeners) { for (var listenerId in cellMapElem.listeners) {
listeners[listenerId] = cellMapElem.listeners[listenerId]; listeners[listenerId] = cellMapElem.listeners[listenerId];
...@@ -1017,11 +1068,13 @@ function getRangeType(oBBox){ ...@@ -1017,11 +1068,13 @@ function getRangeType(oBBox){
} }
for (var areaIndex in sheetContainer.areaMap) { for (var areaIndex in sheetContainer.areaMap) {
var areaMapElem = sheetContainer.areaMap[areaIndex]; var areaMapElem = sheetContainer.areaMap[areaIndex];
var isIntersect;
if (AscCommon.c_oNotifyType.Shift == notifyType) { if (AscCommon.c_oNotifyType.Shift == notifyType) {
isIntersect = oShiftGetBBox.isIntersectForShift(areaMapElem.bbox, isHor) isIntersect = bbox.isIntersectForShift(areaMapElem.bbox, offset);
} else { } else if (AscCommon.c_oNotifyType.Move == notifyType) {
isIntersect = oShiftGetBBox.containsRange(areaMapElem.bbox); isIntersect = bbox.containsRange(areaMapElem.bbox);
} else if (AscCommon.c_oNotifyType.Delete == notifyType) {
//isIntersect = bbox.isIntersect(areaMapElem.bbox);
isIntersect = bbox.containsRange(areaMapElem.bbox);
} }
if (isIntersect) { if (isIntersect) {
for (var listenerId in areaMapElem.listeners) { for (var listenerId in areaMapElem.listeners) {
...@@ -1044,14 +1097,18 @@ function getRangeType(oBBox){ ...@@ -1044,14 +1097,18 @@ function getRangeType(oBBox){
RangeTree.prototype = { RangeTree.prototype = {
add: function(bbox, data) { add: function(bbox, data) {
var top = this.yTree.insertOrGet(new Asc.TreeRBNode(bbox.r1, {count: 0, vals: {}}));
var bottom = this.yTree.insertOrGet(new Asc.TreeRBNode(bbox.r2, {count: 0, vals: {}}));
data.id = this.id++; data.id = this.id++;
var startFlag = bbox.r1 !== bbox.r2 ? 1 : 3;
var dataWrap = {bbox: bbox, data: data, isOutput: false}; var dataWrap = {bbox: bbox, data: data, isOutput: false};
top.storedValue.vals[data.id] = {isStart: true, dataWrap: dataWrap}; var top = this.yTree.insertOrGet(new Asc.TreeRBNode(bbox.r1, {count: 0, vals: {}}));
top.storedValue.vals[data.id] = {startFlag: startFlag, dataWrap: dataWrap};
top.storedValue.count++; top.storedValue.count++;
bottom.storedValue.vals[data.id] = {isStart: false, dataWrap: dataWrap}; if (bbox.r1 != bbox.r2) {
bottom.storedValue.count++; startFlag = 2;
var bottom = this.yTree.insertOrGet(new Asc.TreeRBNode(bbox.r2, {count: 0, vals: {}}));
bottom.storedValue.vals[data.id] = {startFlag: startFlag, dataWrap: dataWrap};
bottom.storedValue.count++;
}
}, },
remove: function(bbox, data) { remove: function(bbox, data) {
var top = this.yTree.getElem(bbox.r1); var top = this.yTree.getElem(bbox.r1);
...@@ -1082,7 +1139,7 @@ function getRangeType(oBBox){ ...@@ -1082,7 +1139,7 @@ function getRangeType(oBBox){
console.time('forin'); console.time('forin');
var cellArr = []; var cellArr = [];
for (var cellIndex in cells) { for (var cellIndex in cells) {
cellArr.push(cellIndex); cellArr.push(cellIndex - 0);
} }
console.timeEnd('forin'); console.timeEnd('forin');
console.time('sort'); console.time('sort');
...@@ -1106,7 +1163,7 @@ function getRangeType(oBBox){ ...@@ -1106,7 +1163,7 @@ function getRangeType(oBBox){
curY = curNodeY.key; curY = curNodeY.key;
for (var id in curNodeY.storedValue.vals) { for (var id in curNodeY.storedValue.vals) {
var elem = curNodeY.storedValue.vals[id]; var elem = curNodeY.storedValue.vals[id];
if (elem.isStart && !elem.dataWrap.isOutput) { if (0 !== (1 & elem.startFlag) && !elem.dataWrap.isOutput) {
curNodes[id] = elem; curNodes[id] = elem;
} }
} }
...@@ -1132,7 +1189,7 @@ function getRangeType(oBBox){ ...@@ -1132,7 +1189,7 @@ function getRangeType(oBBox){
} else { } else {
for (var id in curNodeY.storedValue.vals) { for (var id in curNodeY.storedValue.vals) {
var elem = curNodeY.storedValue.vals[id]; var elem = curNodeY.storedValue.vals[id];
if (!elem.isStart && !elem.dataWrap.isOutput) { if (0 !== (2 & elem.startFlag) && !elem.dataWrap.isOutput) {
delete curNodes[id]; delete curNodes[id];
} }
} }
...@@ -1199,7 +1256,6 @@ function getUniqueKeys(array) { ...@@ -1199,7 +1256,6 @@ function getUniqueKeys(array) {
function Workbook(eventsHandlers, oApi){ function Workbook(eventsHandlers, oApi){
this.oApi = oApi; this.oApi = oApi;
this.handlers = eventsHandlers; this.handlers = eventsHandlers;
this.needRecalc = {nodes: {}, length:0};
this.dependencyFormulas = new DependencyGraph(this); this.dependencyFormulas = new DependencyGraph(this);
this.nActive = 0; this.nActive = 0;
...@@ -1630,9 +1686,12 @@ Workbook.prototype.getDefinesNames = function ( name, sheetId ) { ...@@ -1630,9 +1686,12 @@ Workbook.prototype.getDefinesNames = function ( name, sheetId ) {
}; };
Workbook.prototype.delDefinesNames = function ( defName ) { Workbook.prototype.delDefinesNames = function ( defName ) {
this.dependencyFormulas.removeDefName( defName.LocalSheetId, defName.Name ); this.dependencyFormulas.removeDefName( defName.LocalSheetId, defName.Name );
this.dependencyFormulas.calcTree();
}; };
Workbook.prototype.editDefinesNames = function ( oldName, newName, bUndo ) { Workbook.prototype.editDefinesNames = function ( oldName, newName ) {
return this.dependencyFormulas.editDefinesNames( oldName, newName, bUndo ); var res = this.dependencyFormulas.editDefinesNames( oldName, newName );
this.dependencyFormulas.calcTree();
return res;
}; };
Workbook.prototype.findDefinesNames = function ( ref, sheetId ) { Workbook.prototype.findDefinesNames = function ( ref, sheetId ) {
return this.dependencyFormulas.getDefNameByRef( ref, sheetId ); return this.dependencyFormulas.getDefNameByRef( ref, sheetId );
...@@ -2698,9 +2757,7 @@ Woorksheet.prototype._removeRows=function(start, stop){ ...@@ -2698,9 +2757,7 @@ Woorksheet.prototype._removeRows=function(start, stop){
History.Create_NewPoint(); History.Create_NewPoint();
//start, stop 0 based //start, stop 0 based
var nDif = -(stop - start + 1); var nDif = -(stop - start + 1);
var oActualRange = {r1: start, c1: 0, r2: stop, c2: gc_nMaxCol0};
var oActualRange = new Asc.Range(0, start, gc_nMaxCol0, stop); var oActualRange = new Asc.Range(0, start, gc_nMaxCol0, stop);
this.renameDependencyNodes({offsetRow:nDif,offsetCol:0}, oActualRange);
var i, j, length, nIndex, aIndexes = []; var i, j, length, nIndex, aIndexes = [];
for(i in this.aGCells) for(i in this.aGCells)
{ {
...@@ -2740,7 +2797,8 @@ Woorksheet.prototype._removeRows=function(start, stop){ ...@@ -2740,7 +2797,8 @@ Woorksheet.prototype._removeRows=function(start, stop){
} }
delete this.aGCells[nIndex]; delete this.aGCells[nIndex];
} }
//renameDependencyNodes after move cells because addToChanged has to add new locations
this.renameDependencyNodes({offsetRow:nDif,offsetCol:0}, oActualRange);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_RemoveRows, this.getId(), new Asc.Range(0, start, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, start, stop)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_RemoveRows, this.getId(), new Asc.Range(0, start, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, start, stop));
this.autoFilters.insertRows( "delCell", new Asc.Range(0, start, gc_nMaxCol0, stop), c_oAscDeleteOptions.DeleteRows ); this.autoFilters.insertRows( "delCell", new Asc.Range(0, start, gc_nMaxCol0, stop), c_oAscDeleteOptions.DeleteRows );
...@@ -2757,8 +2815,6 @@ Woorksheet.prototype._insertRowsBefore=function(index, count){ ...@@ -2757,8 +2815,6 @@ Woorksheet.prototype._insertRowsBefore=function(index, count){
this.workbook.dependencyFormulas.lockRecal(); this.workbook.dependencyFormulas.lockRecal();
var oActualRange = {r1: index, c1: 0, r2: index + count - 1, c2: gc_nMaxCol0}; var oActualRange = {r1: index, c1: 0, r2: index + count - 1, c2: gc_nMaxCol0};
History.Create_NewPoint(); History.Create_NewPoint();
this.renameDependencyNodes({offsetRow:count,offsetCol:0},oActualRange);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_AddRows, this.getId(), new Asc.Range(0, index, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, index, index + count - 1));
//index 0 based //index 0 based
var aIndexes = []; var aIndexes = [];
for(var i in this.aGCells) for(var i in this.aGCells)
...@@ -2796,6 +2852,10 @@ Woorksheet.prototype._insertRowsBefore=function(index, count){ ...@@ -2796,6 +2852,10 @@ Woorksheet.prototype._insertRowsBefore=function(index, count){
} }
History.LocalChange = false; History.LocalChange = false;
} }
//renameDependencyNodes after move cells because addToChanged has to add new locations
this.renameDependencyNodes({offsetRow:count,offsetCol:0},oActualRange);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_AddRows, this.getId(), new Asc.Range(0, index, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(true, index, index + count - 1));
this.autoFilters.insertRows( "insCell", new Asc.Range(0, index, gc_nMaxCol0, index + count - 1), c_oAscInsertOptions.InsertColumns ); this.autoFilters.insertRows( "insCell", new Asc.Range(0, index, gc_nMaxCol0, index + count - 1), c_oAscInsertOptions.InsertColumns );
...@@ -2826,7 +2886,6 @@ Woorksheet.prototype._removeCols=function(start, stop){ ...@@ -2826,7 +2886,6 @@ Woorksheet.prototype._removeCols=function(start, stop){
//start, stop 0 based //start, stop 0 based
var nDif = -(stop - start + 1), i, j, length, nIndex; var nDif = -(stop - start + 1), i, j, length, nIndex;
var oActualRange = { r1: 0, c1: start, r2: gc_nMaxRow0, c2: stop }; var oActualRange = { r1: 0, c1: start, r2: gc_nMaxRow0, c2: stop };
this.renameDependencyNodes({ offsetRow: 0, offsetCol: nDif }, oActualRange);
for(i in this.aGCells) for(i in this.aGCells)
{ {
var nRowIndex = i - 0; var nRowIndex = i - 0;
...@@ -2854,7 +2913,6 @@ Woorksheet.prototype._removeCols=function(start, stop){ ...@@ -2854,7 +2913,6 @@ Woorksheet.prototype._removeCols=function(start, stop){
} }
} }
} }
var oDefColPr = new AscCommonExcel.UndoRedoData_ColProp(); var oDefColPr = new AscCommonExcel.UndoRedoData_ColProp();
for(i = start; i <= stop; ++i) for(i = start; i <= stop; ++i)
{ {
...@@ -2874,7 +2932,8 @@ Woorksheet.prototype._removeCols=function(start, stop){ ...@@ -2874,7 +2932,8 @@ Woorksheet.prototype._removeCols=function(start, stop){
if(null != elem) if(null != elem)
elem.moveHor(nDif); elem.moveHor(nDif);
} }
//renameDependencyNodes after move cells because addToChanged has to add new locations
this.renameDependencyNodes({ offsetRow: 0, offsetCol: nDif }, oActualRange);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_RemoveCols, this.getId(), new Asc.Range(start, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, start, stop)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_RemoveCols, this.getId(), new Asc.Range(start, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, start, stop));
...@@ -2891,8 +2950,6 @@ Woorksheet.prototype._insertColsBefore=function(index, count){ ...@@ -2891,8 +2950,6 @@ Woorksheet.prototype._insertColsBefore=function(index, count){
this.workbook.dependencyFormulas.lockRecal(); this.workbook.dependencyFormulas.lockRecal();
var oActualRange = {r1: 0, c1: index, r2: gc_nMaxRow0, c2: index + count - 1}; var oActualRange = {r1: 0, c1: index, r2: gc_nMaxRow0, c2: index + count - 1};
History.Create_NewPoint(); History.Create_NewPoint();
this.renameDependencyNodes({offsetRow:0,offsetCol:count},oActualRange);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_AddCols, this.getId(), new Asc.Range(index, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, index, index + count - 1));
//index 0 based //index 0 based
for(var i in this.aGCells) for(var i in this.aGCells)
{ {
...@@ -2913,7 +2970,11 @@ Woorksheet.prototype._insertColsBefore=function(index, count){ ...@@ -2913,7 +2970,11 @@ Woorksheet.prototype._insertColsBefore=function(index, count){
this._moveCellHor(nRowIndex, nIndex, count, oActualRange); this._moveCellHor(nRowIndex, nIndex, count, oActualRange);
} }
} }
//renameDependencyNodes after move cells because addToChanged has to add new locations
this.renameDependencyNodes({offsetRow:0,offsetCol:count},oActualRange);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_AddCols, this.getId(), new Asc.Range(index, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_FromToRowCol(false, index, index + count - 1));
this.autoFilters.insertColumn( "insCells", new Asc.Range(index, 0, index + count - 1, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns ); this.autoFilters.insertColumn( "insCells", new Asc.Range(index, 0, index + count - 1, gc_nMaxRow0), c_oAscInsertOptions.InsertColumns );
this.workbook.dependencyFormulas.unlockRecal(); this.workbook.dependencyFormulas.unlockRecal();
...@@ -3756,12 +3817,8 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){ ...@@ -3756,12 +3817,8 @@ Woorksheet.prototype._moveRange=function(oBBoxFrom, oBBoxTo, copyRange){
if(!copyRange){ if(!copyRange){
var sBBoxFromName = oBBoxFrom.getName(); var sBBoxFromName = oBBoxFrom.getName();
this.workbook.needRecalc.nodes[getVertexId(this.getId(), sBBoxFromName)] = [this.getId(), sBBoxFromName];
this.workbook.needRecalc.length++;
} }
var sBBoxToName = oBBoxTo.getName(); var sBBoxToName = oBBoxTo.getName();
this.workbook.needRecalc.nodes[getVertexId(this.getId(), sBBoxToName)] = [this.getId(), sBBoxToName];
this.workbook.needRecalc.length++;
this.workbook.sortDependency(); this.workbook.sortDependency();
if(true == this.workbook.bUndoChanges || true == this.workbook.bRedoChanges) if(true == this.workbook.bUndoChanges || true == this.workbook.bRedoChanges)
...@@ -3781,7 +3838,6 @@ Woorksheet.prototype._shiftCellsLeft=function(oBBox){ ...@@ -3781,7 +3838,6 @@ Woorksheet.prototype._shiftCellsLeft=function(oBBox){
var nLeft = oBBox.c1; var nLeft = oBBox.c1;
var nRight = oBBox.c2; var nRight = oBBox.c2;
var dif = nLeft - nRight - 1; var dif = nLeft - nRight - 1;
this.renameDependencyNodes( {offsetRow:0,offsetCol:dif}, oBBox );
for(var i = oBBox.r1; i <= oBBox.r2; i++){ for(var i = oBBox.r1; i <= oBBox.r2; i++){
var row = this.aGCells[i]; var row = this.aGCells[i];
if(row){ if(row){
...@@ -3807,7 +3863,9 @@ Woorksheet.prototype._shiftCellsLeft=function(oBBox){ ...@@ -3807,7 +3863,9 @@ Woorksheet.prototype._shiftCellsLeft=function(oBBox){
} }
} }
} }
//renameDependencyNodes after move cells because addToChanged has to add new locations
this.renameDependencyNodes( {offsetRow:0,offsetCol:dif}, oBBox );
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsLeft, this.getId(), new Asc.Range(nLeft, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsLeft, this.getId(), new Asc.Range(nLeft, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox));
this.autoFilters.insertColumn( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftLeft ); this.autoFilters.insertColumn( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftLeft );
//todo проверить не уменьшились ли границы таблицы //todo проверить не уменьшились ли границы таблицы
...@@ -3816,7 +3874,6 @@ Woorksheet.prototype._shiftCellsUp=function(oBBox){ ...@@ -3816,7 +3874,6 @@ Woorksheet.prototype._shiftCellsUp=function(oBBox){
var nTop = oBBox.r1; var nTop = oBBox.r1;
var nBottom = oBBox.r2; var nBottom = oBBox.r2;
var dif = nTop - nBottom - 1; var dif = nTop - nBottom - 1;
this.renameDependencyNodes({offsetRow:dif,offsetCol:0}, oBBox );
var aIndexes = []; var aIndexes = [];
for(var i in this.aGCells) for(var i in this.aGCells)
{ {
...@@ -3846,7 +3903,9 @@ Woorksheet.prototype._shiftCellsUp=function(oBBox){ ...@@ -3846,7 +3903,9 @@ Woorksheet.prototype._shiftCellsUp=function(oBBox){
} }
} }
} }
//renameDependencyNodes after move cells because addToChanged has to add new locations
this.renameDependencyNodes({offsetRow:dif,offsetCol:0}, oBBox );
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsTop, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsTop, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox));
this.autoFilters.insertRows( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftTop ); this.autoFilters.insertRows( "delCell", oBBox, c_oAscDeleteOptions.DeleteCellsAndShiftTop );
//todo проверить не уменьшились ли границы таблицы //todo проверить не уменьшились ли границы таблицы
...@@ -3855,7 +3914,7 @@ Woorksheet.prototype._shiftCellsRight=function(oBBox, displayNameFormatTable){ ...@@ -3855,7 +3914,7 @@ Woorksheet.prototype._shiftCellsRight=function(oBBox, displayNameFormatTable){
var nLeft = oBBox.c1; var nLeft = oBBox.c1;
var nRight = oBBox.c2; var nRight = oBBox.c2;
var dif = nRight - nLeft + 1; var dif = nRight - nLeft + 1;
this.renameDependencyNodes({offsetRow:0,offsetCol:dif}, oBBox);
for(var i = oBBox.r1; i <= oBBox.r2; i++){ for(var i = oBBox.r1; i <= oBBox.r2; i++){
var row = this.aGCells[i]; var row = this.aGCells[i];
if(row){ if(row){
...@@ -3880,7 +3939,9 @@ Woorksheet.prototype._shiftCellsRight=function(oBBox, displayNameFormatTable){ ...@@ -3880,7 +3939,9 @@ Woorksheet.prototype._shiftCellsRight=function(oBBox, displayNameFormatTable){
} }
} }
} }
//renameDependencyNodes after move cells because addToChanged has to add new locations
this.renameDependencyNodes({offsetRow:0,offsetCol:dif}, oBBox);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsRight, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsRight, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, gc_nMaxCol0, oBBox.r2), new UndoRedoData_BBox(oBBox));
this.autoFilters.insertColumn( "insCells", oBBox, c_oAscInsertOptions.InsertCellsAndShiftRight, displayNameFormatTable ); this.autoFilters.insertColumn( "insCells", oBBox, c_oAscInsertOptions.InsertCellsAndShiftRight, displayNameFormatTable );
}; };
...@@ -3889,7 +3950,6 @@ Woorksheet.prototype._shiftCellsBottom=function(oBBox, displayNameFormatTable){ ...@@ -3889,7 +3950,6 @@ Woorksheet.prototype._shiftCellsBottom=function(oBBox, displayNameFormatTable){
var nBottom = oBBox.r2; var nBottom = oBBox.r2;
var dif = nBottom - nTop + 1; var dif = nBottom - nTop + 1;
var aIndexes = []; var aIndexes = [];
this.renameDependencyNodes({offsetRow:dif,offsetCol:0}, oBBox);
for(var i in this.aGCells){ for(var i in this.aGCells){
var rowInd = i - 0; var rowInd = i - 0;
if(rowInd >= nTop) if(rowInd >= nTop)
...@@ -3911,7 +3971,9 @@ Woorksheet.prototype._shiftCellsBottom=function(oBBox, displayNameFormatTable){ ...@@ -3911,7 +3971,9 @@ Woorksheet.prototype._shiftCellsBottom=function(oBBox, displayNameFormatTable){
} }
} }
} }
//renameDependencyNodes after move cells because addToChanged has to add new locations
this.renameDependencyNodes({offsetRow:dif,offsetCol:0}, oBBox);
History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsBottom, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox)); History.Add(AscCommonExcel.g_oUndoRedoWorksheet, AscCH.historyitem_Worksheet_ShiftCellsBottom, this.getId(), new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, gc_nMaxRow0), new UndoRedoData_BBox(oBBox));
this.autoFilters.insertRows( "insCell", oBBox, c_oAscInsertOptions.InsertCellsAndShiftDown, displayNameFormatTable ); this.autoFilters.insertRows( "insCell", oBBox, c_oAscInsertOptions.InsertCellsAndShiftDown, displayNameFormatTable );
}; };
...@@ -4697,24 +4759,43 @@ Cell.prototype.setValueData = function(Val){ ...@@ -4697,24 +4759,43 @@ Cell.prototype.setValueData = function(Val){
} }
} }
}; };
Cell.prototype.onFormulaEvent = function(type, data) { Cell.prototype.onFormulaEvent = function(type, eventData) {
if (AscCommon.c_oNotifyParentType.Change === type) { if (AscCommon.c_oNotifyParentType.CanDo === type) {
;
} else if (AscCommon.c_oNotifyParentType.Change === type) {
this.ws.workbook.dependencyFormulas.addToChangedCell(this); this.ws.workbook.dependencyFormulas.addToChangedCell(this);
} else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) { } else if (AscCommon.c_oNotifyParentType.ChangeFormula === type) {
var DataOld = this.getValueData(); var DataOld = this.getValueData();
this.formulaParsed.buildDependencies(); var assemb;
this.formulaParsed.Formula = this.formulaParsed.assemble(); switch (eventData.assembleType) {
var DataNew = this.getValueData(); case AscCommon.c_oNotifyParentAssemble.Normal:
if (false == DataOld.isEqual(DataNew)) { assemb = this.formulaParsed.assemble();
History.Add(AscCommonExcel.g_oUndoRedoCell, AscCH.historyitem_Cell_ChangeValueUndo, this.ws.getId(), break;
new Asc.Range(this.nCol, this.nRow, this.nCol, this.nRow), case AscCommon.c_oNotifyParentAssemble.Flag:
new UndoRedoData_CellSimpleData(this.nRow, this.nCol, DataOld, DataNew), true); assemb = this.formulaParsed.assemble(true);
this.oValue.cleanCache(); break;
case AscCommon.c_oNotifyParentAssemble.Current:
assemb = this.formulaParsed.Formula;
break;
}
if (eventData.isRebuild) {
this.setValue('=' + assemb);
} else {
this.formulaParsed.Formula = assemb;
this.formulaParsed.buildDependencies();
this.ws.workbook.dependencyFormulas.addToChangedCell(this); this.ws.workbook.dependencyFormulas.addToChangedCell(this);
var DataNew = this.getValueData();
if (false == DataOld.isEqual(DataNew)) {
History.Add(AscCommonExcel.g_oUndoRedoCell, AscCH.historyitem_Cell_ChangeValueUndo, this.ws.getId(),
new Asc.Range(this.nCol, this.nRow, this.nCol, this.nRow),
new UndoRedoData_CellSimpleData(this.nRow, this.nCol, DataOld, DataNew), true);
this.oValue.cleanCache();
}
} }
} else if (AscCommon.c_oNotifyParentType.EndCalculate === type) { } else if (AscCommon.c_oNotifyParentType.EndCalculate === type) {
this._updateCellValue(); this._updateCellValue();
} }
return true;
}; };
Cell.prototype._calculateRefType = function(cell) { Cell.prototype._calculateRefType = function(cell) {
var val = this.formulaParsed.value; var val = this.formulaParsed.value;
...@@ -7568,9 +7649,11 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){ ...@@ -7568,9 +7649,11 @@ Range.prototype._sortByArray=function(oBBox, aSortData, bUndo){
oCurCell.moveVer(shift); oCurCell.moveVer(shift);
rowTo.c[i] = oCurCell; rowTo.c[i] = oCurCell;
if (oCurCell.formulaParsed) { if (oCurCell.formulaParsed) {
History.TurnOff();
var _p_ = oCurCell.formulaParsed.clone(null, oCurCell, this); var _p_ = oCurCell.formulaParsed.clone(null, oCurCell, this);
var assemb = _p_.changeOffset({offsetCol: 0, offsetRow: shift}).assemble(); var assemb = _p_.changeOffset({offsetCol: 0, offsetRow: shift}).assemble();
oCurCell.setValue("=" + assemb); oCurCell.setValue("=" + assemb);
History.TurnOn();
} }
} }
else else
...@@ -8615,6 +8698,7 @@ DrawingObjectsManager.prototype.rebuildCharts = function(data) ...@@ -8615,6 +8698,7 @@ DrawingObjectsManager.prototype.rebuildCharts = function(data)
window['AscCommonExcel'].oDefaultMetrics = oDefaultMetrics; window['AscCommonExcel'].oDefaultMetrics = oDefaultMetrics;
window['AscCommonExcel'].g_nAllColIndex = g_nAllColIndex; window['AscCommonExcel'].g_nAllColIndex = g_nAllColIndex;
window['AscCommonExcel'].g_nAllRowIndex = g_nAllRowIndex; window['AscCommonExcel'].g_nAllRowIndex = g_nAllRowIndex;
window['AscCommonExcel'].g_DefNameWorksheet;
window['AscCommonExcel'].aStandartNumFormats = aStandartNumFormats; window['AscCommonExcel'].aStandartNumFormats = aStandartNumFormats;
window['AscCommonExcel'].aStandartNumFormatsId = aStandartNumFormatsId; window['AscCommonExcel'].aStandartNumFormatsId = aStandartNumFormatsId;
window['AscCommonExcel'].oFormulaLocaleInfo = oFormulaLocaleInfo; window['AscCommonExcel'].oFormulaLocaleInfo = oFormulaLocaleInfo;
......
...@@ -305,11 +305,38 @@ ...@@ -305,11 +305,38 @@
return bRes; return bRes;
}, },
isIntersectForShift: function(range, isHor) { isIntersectForShift: function(range, offset) {
var isHor = offset && 0 != offset.offsetCol;
var toDelete = offset && (offset.offsetCol < 0 || offset.offsetRow < 0);
if (isHor) { if (isHor) {
return this.r1 <= range.r1 && range.r2 <= this.r2 && this.c1 <= range.c2; if (this.r1 <= range.r1 && range.r2 <= this.r2 && this.c1 <= range.c2) {
return true;
} else if (toDelete && this.c1 <= range.c1 && range.c2 <= this.c2) {
var topIn = this.r1 <= range.r1 && range.r1 <= this.r2;
var bottomIn = this.r1 <= range.r2 && range.r2 <= this.r2;
return topIn || bottomIn;
} else {
return false;
}
} else { } else {
return this.c1 <= range.c1 && range.c2 <= this.c2 && this.r1 <= range.r2; if (this.c1 <= range.c1 && range.c2 <= this.c2 && this.r1 <= range.r2) {
return true;
} else if (toDelete && this.r1 <= range.r1 && range.r2 <= this.r2) {
var leftIn = this.c1 <= range.c1 && range.c1 <= this.c2;
var rightIn = this.c1 <= range.c2 && range.c2 <= this.c2;
return leftIn || rightIn;
} else {
return false;
}
}
},
isIntersectForShiftCell: function(col, row, offset) {
var isHor = offset && 0 != offset.offsetCol;
if (isHor) {
return this.r1 <= row && row <= this.r2 && this.c1 <= col;
} else {
return this.c1 <= col && col <= this.c2 && this.r1 <= row;
} }
}, },
...@@ -328,9 +355,18 @@ ...@@ -328,9 +355,18 @@
} }
} else if (this.c1 <= bbox.c2) { } else if (this.c1 <= bbox.c2) {
if (this.c2 <= bbox.c2) { if (this.c2 <= bbox.c2) {
isNoDelete = false; var topIn = bbox.r1 <= this.r1 && this.r1 <= bbox.r2;
var bottomIn = bbox.r1 <= this.r2 && this.r2 <= bbox.r2;
if (topIn && bottomIn) {
isNoDelete = false;
} else if (topIn) {
this.setOffsetFirst({offsetCol: 0, offsetRow: bbox.r2 - this.r1 + 1});
} else if (bottomIn) {
this.setOffsetLast({offsetCol: 0, offsetRow: bbox.r1 - this.r2 - 1});
}
} else { } else {
this.setOffsetFirst({offsetCol: bbox.c2 - this.c1 + 1, offsetRow: 0}); this.setOffsetFirst({offsetCol: bbox.c1 - this.c1, offsetRow: 0});
this.setOffsetLast(offset);
} }
} else { } else {
this.setOffset(offset); this.setOffset(offset);
...@@ -352,9 +388,18 @@ ...@@ -352,9 +388,18 @@
} }
} else if (this.r1 <= bbox.r2) { } else if (this.r1 <= bbox.r2) {
if (this.r2 <= bbox.r2) { if (this.r2 <= bbox.r2) {
isNoDelete = false; var leftIn = bbox.c1 <= this.c1 && this.c1 <= bbox.c2;
var rightIn = bbox.c1 <= this.c2 && this.c2 <= bbox.c2;
if (leftIn && rightIn) {
isNoDelete = false;
} else if (leftIn) {
this.setOffsetFirst({offsetCol: bbox.c2 - this.c1 + 1, offsetRow: 0});
} else if (rightIn) {
this.setOffsetLast({offsetCol: bbox.c1 - this.c2 - 1, offsetRow: 0});
}
} else { } else {
this.setOffsetFirst({offsetCol: 0, offsetRow: bbox.r2 - this.r1 + 1}); this.setOffsetFirst({offsetCol: 0, offsetRow: bbox.r1 - this.r1});
this.setOffsetLast(offset);
} }
} else { } else {
this.setOffset(offset); this.setOffset(offset);
......
...@@ -823,9 +823,16 @@ var c_oAscPrintDefaultSettings = { ...@@ -823,9 +823,16 @@ var c_oAscPrintDefaultSettings = {
}; };
var c_oNotifyParentType = { var c_oNotifyParentType = {
Change: 0, CanDo: 0,
ChangeFormula: 1, Change: 1,
EndCalculate: 2 ChangeFormula: 2,
EndCalculate: 3
};
var c_oNotifyParentAssemble = {
Normal: 0,
Flag: 1,
Current: 2
}; };
var c_oDashType = { var c_oDashType = {
...@@ -1480,6 +1487,8 @@ window['Asc']['c_oAscMaxCellOrCommentLength'] = window['Asc'].c_oAscMaxCellOrCom ...@@ -1480,6 +1487,8 @@ window['Asc']['c_oAscMaxCellOrCommentLength'] = window['Asc'].c_oAscMaxCellOrCom
window["AscCommon"].c_oZoomType = c_oZoomType; window["AscCommon"].c_oZoomType = c_oZoomType;
window["AscCommon"].c_oNotifyType = c_oNotifyType; window["AscCommon"].c_oNotifyType = c_oNotifyType;
window["AscCommon"].c_oNotifyParentType = c_oNotifyParentType; window["AscCommon"].c_oNotifyParentType = c_oNotifyParentType;
window["AscCommon"].c_oNotifyParentAssemble = c_oNotifyParentAssemble;
window["AscCommon"].c_oAscEncodings = c_oAscEncodings; window["AscCommon"].c_oAscEncodings = c_oAscEncodings;
window["AscCommon"].c_oAscEncodingsMap = c_oAscEncodingsMap; window["AscCommon"].c_oAscEncodingsMap = c_oAscEncodingsMap;
window["AscCommon"].c_oAscCodePageUtf8 = c_oAscCodePageUtf8; window["AscCommon"].c_oAscCodePageUtf8 = c_oAscCodePageUtf8;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment