Commit f3ee9918 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Добавил проверку комментариев при merge.

Добавил merge комментариев при merge ячеек.
Баг http://bugzserver/show_bug.cgi?id=24314

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56499 954022d7-b5bf-4e40-9824-e11837661b57
parent 5032b8bc
...@@ -492,1302 +492,1329 @@ CompositeCommentData.prototype = { ...@@ -492,1302 +492,1329 @@ CompositeCommentData.prototype = {
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
/** @constructor */ /** @constructor */
function CCellCommentator(currentSheet) { function CCellCommentator(currentSheet) {
this.worksheet = currentSheet;
var _this = this; this.overlayCtx = currentSheet.overlayCtx;
var asc = window["Asc"]; this.drawingCtx = currentSheet.drawingCtx;
var asc_applyFunction = asc.applyFunction;
var asc_CCollaborativeRange = asc.asc_CCollaborativeRange;
var isViewerMode = function() { return _this.worksheet.handlers.trigger("getViewerMode"); };
_this.worksheet = currentSheet;
_this.overlayCtx = currentSheet.overlayCtx;
_this.drawingCtx = currentSheet.drawingCtx;
// Drawing settings // Drawing settings
_this.bShow = true; this.bShow = true;
_this.commentIconColor = new CColor(255, 144, 0); this.commentIconColor = new CColor(255, 144, 0);
_this.commentFillColor = new CColor(255, 255, 0); this.commentFillColor = new CColor(255, 255, 0);
_this.commentBorderWidth = 1; // px this.commentPadding = 4; // px
_this.commentPadding = 4; // px this.minAreaWidth = 160; // px
_this.minAreaWidth = 160; // px this.minAreaHeight = 80; // px
_this.minAreaHeight = 80; // px
this.aComments = [];
_this.aComments = []; this.aCommentCoords = [];
_this.aCommentCoords = []; this.lastSelectedId = null;
_this.lastSelectedId = null; this.bSaveHistory = true;
_this.bSaveHistory = true; }
//-----------------------------------------------------------------------------------
// Public methods
//-----------------------------------------------------------------------------------
_this.isLockedComment = function(oComment, lockByDefault, callbackFunc) {
var _this = this;
var lockInfo;
var model = _this.worksheet.model; //-----------------------------------------------------------------------------------
var sheetId = model.getId(); // Public methods
//-----------------------------------------------------------------------------------
var objectGuid = oComment.asc_getId(); CCellCommentator.prototype.isViewerMode = function () {
if (objectGuid) { return this.worksheet.handlers.trigger("getViewerMode");
};
if (false === _this.worksheet.collaborativeEditing.isCoAuthoringExcellEnable()) { CCellCommentator.prototype.isLockedComment = function(oComment, lockByDefault, callbackFunc) {
// Запрещено совместное редактирование var lockInfo;
asc_applyFunction(callbackFunc, true);
return;
}
if ( lockByDefault ) var model = this.worksheet.model;
_this.worksheet.collaborativeEditing.onStartCheckLock(); var sheetId = model.getId();
// Комментарий к документу блокируем как Range
if ( !oComment.asc_getDocumentFlag() ) {
var c = oComment.asc_getCol();
var r = oComment.asc_getRow();
var c1, r1, c2, r2;
var mergedRange = model.getMergedByCell(r, c);
if (mergedRange) {
c1 = mergedRange.c1;
r1 = mergedRange.r1;
c2 = mergedRange.c2;
r2 = mergedRange.r2;
} else {
c1 = c2 = c;
r1 = r2 = r;
}
lockInfo = _this.worksheet.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Range, /*subType*/null, sheetId, new asc_CCollaborativeRange(c1, r1, c2, r2)); var objectGuid = oComment.asc_getId();
} else if (objectGuid) {
lockInfo = _this.worksheet.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Object, /*subType*/null, sheetId, objectGuid);
if (false === _this.worksheet.collaborativeEditing.getCollaborativeEditing()) { if (false === this.worksheet.collaborativeEditing.isCoAuthoringExcellEnable()) {
// Пользователь редактирует один: не ждем ответа, а сразу продолжаем редактирование // Запрещено совместное редактирование
asc_applyFunction(callbackFunc, true); Asc.applyFunction(callbackFunc, true);
callbackFunc = undefined; return;
} }
if (false !== _this.worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeMine, /*bCheckOnlyLockAll*/false)) {
// Редактируем сами
asc_applyFunction(callbackFunc, true);
return;
}
else if (false !== _this.worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeOther, /*bCheckOnlyLockAll*/false)) {
// Уже ячейку кто-то редактирует
asc_applyFunction(callbackFunc, false);
return;
}
// Блокируем if ( lockByDefault )
if ( lockByDefault ) { this.worksheet.collaborativeEditing.onStartCheckLock();
_this.worksheet.collaborativeEditing.addCheckLock(lockInfo);
_this.worksheet.collaborativeEditing.onEndCheckLock(callbackFunc); // Комментарий к документу блокируем как Range
if ( !oComment.asc_getDocumentFlag() ) {
var c = oComment.asc_getCol();
var r = oComment.asc_getRow();
var c1, r1, c2, r2;
var mergedRange = model.getMergedByCell(r, c);
if (mergedRange) {
c1 = mergedRange.c1;
r1 = mergedRange.r1;
c2 = mergedRange.c2;
r2 = mergedRange.r2;
} else {
c1 = c2 = c;
r1 = r2 = r;
} }
else
asc_applyFunction(callbackFunc, true); lockInfo = this.worksheet.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Range, /*subType*/null, sheetId, new Asc.asc_CCollaborativeRange(c1, r1, c2, r2));
} else
lockInfo = this.worksheet.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Object, /*subType*/null, sheetId, objectGuid);
if (false === this.worksheet.collaborativeEditing.getCollaborativeEditing()) {
// Пользователь редактирует один: не ждем ответа, а сразу продолжаем редактирование
Asc.applyFunction(callbackFunc, true);
callbackFunc = undefined;
} }
}; if (false !== this.worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeMine, /*bCheckOnlyLockAll*/false)) {
// Редактируем сами
_this.callLockComments = function(range) { Asc.applyFunction(callbackFunc, true);
return;
if ( range ) {
for (var i = 0; i < _this.aComments.length; i++) {
var comment = _this.aComments[i];
if ( (comment.nCol >= range.c1) && (comment.nCol <= range.c2) && (comment.nRow >= range.r1) && (comment.nRow <= range.r2) )
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
}
} }
}; else if (false !== this.worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeOther, /*bCheckOnlyLockAll*/false)) {
// Уже ячейку кто-то редактирует
_this.unlockComments = function() { Asc.applyFunction(callbackFunc, false);
for (var i = 0; i < _this.aComments.length; i++) { return;
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", _this.aComments[i].asc_getId());
} }
};
// Блокируем
_this.tryUnlockComment = function(id) { if ( lockByDefault ) {
for (var i = 0; i < _this.aComments.length; i++) { this.worksheet.collaborativeEditing.addCheckLock(lockInfo);
if ( _this.aComments[i].asc_getId() == id ) { this.worksheet.collaborativeEditing.onEndCheckLock(callbackFunc);
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", id);
break;
}
} }
}; else
Asc.applyFunction(callbackFunc, true);
}
};
CCellCommentator.prototype.callLockComments = function(range) {
if ( range ) {
for (var i = 0; i < this.aComments.length; i++) {
var comment = this.aComments[i];
if ( (comment.nCol >= range.c1) && (comment.nCol <= range.c2) && (comment.nRow >= range.r1) && (comment.nRow <= range.r2) )
this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
}
}
};
_this.moveRangeComments = function(rangeFrom, rangeTo) { CCellCommentator.prototype.unlockComments = function() {
if ( rangeFrom && rangeTo ) { for (var i = 0; i < this.aComments.length; i++) {
var colOffset = rangeTo.c1 - rangeFrom.c1; this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", this.aComments[i].asc_getId());
var rowOffset = rangeTo.r1 - rangeFrom.r1; }
};
_this.worksheet.model.workbook.handlers.trigger("asc_onHideComment");
for (var i = 0; i < _this.aComments.length; i++) {
var comment = _this.aComments[i];
if ( (comment.nCol >= rangeFrom.c1) && (comment.nCol <= rangeFrom.c2) && (comment.nRow >= rangeFrom.r1) && (comment.nRow <= rangeFrom.r2) ) {
var commentBefore = new asc_CCommentData(comment);
comment.nCol += colOffset;
comment.nRow += rowOffset;
var cellAddress = new CellAddress(comment.nRow, comment.nCol, 0);
comment.sQuoteText = cellAddress.getID() + " : " + _this.worksheet.model.getCell(cellAddress).getValueWithFormat();
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", comment.asc_getId(), comment);
var commentAfter = new asc_CCommentData(comment);
var compositeComment = new CompositeCommentData();
compositeComment.commentBefore = commentBefore;
compositeComment.commentAfter = commentAfter;
History.Create_NewPoint(); CCellCommentator.prototype.tryUnlockComment = function(id) {
History.Add(g_oUndoRedoComment, historyitem_Comment_Change, _this.worksheet.model.getId(), null, compositeComment); for (var i = 0; i < this.aComments.length; i++) {
} if ( this.aComments[i].asc_getId() == id ) {
} this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", id);
break;
} }
}; }
};
_this.deleteCommentsRange = function(range) {
if ( range ) { CCellCommentator.prototype.moveRangeComments = function(rangeFrom, rangeTo) {
var aCommentId = [], i; if ( rangeFrom && rangeTo ) {
for (i = 0; i < _this.aComments.length; ++i) { var colOffset = rangeTo.c1 - rangeFrom.c1;
var comment = _this.aComments[i]; var rowOffset = rangeTo.r1 - rangeFrom.r1;
if ( (comment.nCol >= range.c1) && (comment.nCol <= range.c2) && (comment.nRow >= range.r1) && (comment.nRow <= range.r2) ) {
aCommentId.push(comment.asc_getId()); this.worksheet.model.workbook.handlers.trigger("asc_onHideComment");
}
} for (var i = 0; i < this.aComments.length; i++) {
History.StartTransaction(); var comment = this.aComments[i];
for (i = 0; i < aCommentId.length; i++) {
_this.asc_removeComment(aCommentId[i]); if ( (comment.nCol >= rangeFrom.c1) && (comment.nCol <= rangeFrom.c2) && (comment.nRow >= rangeFrom.r1) && (comment.nRow <= rangeFrom.r2) ) {
var commentBefore = new asc_CCommentData(comment);
comment.nCol += colOffset;
comment.nRow += rowOffset;
var cellAddress = new CellAddress(comment.nRow, comment.nCol, 0);
comment.sQuoteText = cellAddress.getID() + " : " + this.worksheet.model.getCell(cellAddress).getValueWithFormat();
this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", comment.asc_getId(), comment);
var commentAfter = new asc_CCommentData(comment);
var compositeComment = new CompositeCommentData();
compositeComment.commentBefore = commentBefore;
compositeComment.commentAfter = commentAfter;
History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Change, this.worksheet.model.getId(), null, compositeComment);
} }
History.EndTransaction();
} }
}; }
};
_this.prepareComments = function(arrComments) { CCellCommentator.prototype.deleteCommentsRange = function(range) {
var commentList = []; if ( range ) {
for (var i = 0; i < arrComments.length; ++i) { var aCommentId = [], i;
var comment = {"Id": arrComments[i].asc_getId(), "Comment": arrComments[i]}; for (i = 0; i < this.aComments.length; ++i) {
_this.addCommentSerialize(comment["Comment"]); var comment = this.aComments[i];
commentList.push(comment); if ( (comment.nCol >= range.c1) && (comment.nCol <= range.c2) && (comment.nRow >= range.r1) && (comment.nRow <= range.r2) ) {
aCommentId.push(comment.asc_getId());
}
} }
return commentList; History.StartTransaction();
}; for (i = 0; i < aCommentId.length; i++) {
this.asc_removeComment(aCommentId[i]);
_this.addCommentSerialize = function(oComment) { }
History.EndTransaction();
}
};
var _this = this; CCellCommentator.prototype.prepareComments = function(arrComments) {
var commentList = [];
for (var i = 0; i < arrComments.length; ++i) {
var comment = {"Id": arrComments[i].asc_getId(), "Comment": arrComments[i]};
this.addCommentSerialize(comment["Comment"]);
commentList.push(comment);
}
return commentList;
};
if (oComment) { CCellCommentator.prototype.addCommentSerialize = function(oComment) {
if ( !oComment.bDocument && (oComment.nCol != null) && (oComment.nRow != null) ) { if (oComment) {
var cellAddress = new CellAddress(oComment.nRow, oComment.nCol, 0); if ( !oComment.bDocument && (oComment.nCol != null) && (oComment.nRow != null) ) {
oComment.sQuoteText = cellAddress.getID() + " : " + _this.worksheet.model.getCell(cellAddress).getValueWithFormat(); var cellAddress = new CellAddress(oComment.nRow, oComment.nCol, 0);
} oComment.sQuoteText = cellAddress.getID() + " : " + this.worksheet.model.getCell(cellAddress).getValueWithFormat();
_this.aComments.push(oComment);
} }
}; this.aComments.push(oComment);
}
};
_this.getCommentsXY = function(x, y) { CCellCommentator.prototype.getCommentsXY = function(x, y) {
var findCol = this.worksheet._findColUnderCursor(this.pxToPt(x), true);
var findRow = this.worksheet._findRowUnderCursor(this.pxToPt(y), true);
var _this = this; return (findCol && findRow) ? this.asc_getComments(findCol.col, findRow.row) : [];
};
var findCol = _this.worksheet._findColUnderCursor(_this.pxToPt(x), true); CCellCommentator.prototype.drawCommentCells = function() {
var findRow = _this.worksheet._findRowUnderCursor(_this.pxToPt(y), true);
return (findCol && findRow) ? _this.asc_getComments(findCol.col, findRow.row) : []; if ( this.isViewerMode() || !this.bShow )
}; return;
_this.drawCommentCells = function() { var drawCells = []; // Associative array
function getCellId(col, row) { return (col + "_" + row); }
if ( isViewerMode() || !_this.bShow )
return;
var drawCells = []; // Associative array for (var n = 0; n < this.worksheet.drawingArea.frozenPlaces.length; n++) {
function getCellId(col, row) { return (col + "_" + row); } var frozenPlace = this.worksheet.drawingArea.frozenPlaces[n];
var fv = frozenPlace.getFirstVisible();
for (var n = 0; n < _this.worksheet.drawingArea.frozenPlaces.length; n++) { var lvr = this.worksheet.getLastVisibleRow();
var frozenPlace = _this.worksheet.drawingArea.frozenPlaces[n]; var lvc = this.worksheet.getLastVisibleCol();
var fv = frozenPlace.getFirstVisible();
var lvr = _this.worksheet.getLastVisibleRow(); for (var i = 0; i < this.aComments.length; i++) {
var lvc = _this.worksheet.getLastVisibleCol(); // Get cell metrics
var commentCell = this.aComments[i];
for (var i = 0; i < _this.aComments.length; i++) { if (commentCell.asc_getDocumentFlag() || commentCell.asc_getHiddenFlag() || commentCell.asc_getSolved())
// Get cell metrics continue;
var commentCell = _this.aComments[i];
if (commentCell.asc_getDocumentFlag() || commentCell.asc_getHiddenFlag() || commentCell.asc_getSolved()) var mergedRange = this.worksheet.model.getMergedByCell(commentCell.nRow, commentCell.nCol);
continue; var drawCol = mergedRange ? mergedRange.c2 : commentCell.nCol;
var drawRow = mergedRange ? mergedRange.r1 : commentCell.nRow;
var mergedRange = _this.worksheet.model.getMergedByCell(commentCell.nRow, commentCell.nCol); if (drawCol < fv.col || drawRow < fv.row || drawCol > lvc || drawRow > lvr)
var drawCol = mergedRange ? mergedRange.c2 : commentCell.nCol; continue;
var drawRow = mergedRange ? mergedRange.r1 : commentCell.nRow;
if (drawCol < fv.col || drawRow < fv.row || drawCol > lvc || drawRow > lvr) if ( !frozenPlace.isCellInside({ col: drawCol, row: drawRow }) )
continue; continue;
if ( !frozenPlace.isCellInside({ col: drawCol, row: drawRow }) ) var cellId = getCellId(commentCell.nCol, commentCell.nRow);
continue; if (drawCells[cellId])
continue;
var cellId = getCellId(commentCell.nCol, commentCell.nRow);
if (drawCells[cellId]) var metrics = this.getCellMetrics(drawCol, drawRow);
continue; if ( !metrics.result || (metrics.width <= 0) || (metrics.height <= 0) )
continue;
var metrics = _this.getCellMetrics(drawCol, drawRow);
if ( !metrics.result || (metrics.width <= 0) || (metrics.height <= 0) )
continue;
_this.drawingCtx.beginPath();
_this.drawingCtx.setFillStyle(_this.commentIconColor);
_this.drawingCtx.moveTo(metrics.left + metrics.width - _this.pxToPt(7), metrics.top);
_this.drawingCtx.lineTo(metrics.left + metrics.width - _this.pxToPt(1), metrics.top);
_this.drawingCtx.lineTo(metrics.left + metrics.width - _this.pxToPt(1), metrics.top + _this.pxToPt(6));
_this.drawingCtx.closePath();
_this.drawingCtx.fill();
drawCells[cellId] = cellId;
}
}
//if (_this.lastSelectedId)
// _this.asc_selectComment(_this.lastSelectedId, false);
};
_this.getTextMetrics = function(text, units) { this.drawingCtx.beginPath();
this.drawingCtx.setFillStyle(this.commentIconColor);
var _this = this; this.drawingCtx.moveTo(metrics.left + metrics.width - this.pxToPt(7), metrics.top);
var metrics = { width: 0, height: 0 }; this.drawingCtx.lineTo(metrics.left + metrics.width - this.pxToPt(1), metrics.top);
this.drawingCtx.lineTo(metrics.left + metrics.width - this.pxToPt(1), metrics.top + this.pxToPt(6));
this.drawingCtx.closePath();
this.drawingCtx.fill();
if (text && text.length && ((typeof (text) == 'string') || (typeof (text) == 'number'))) { drawCells[cellId] = cellId;
var textOptions = _this.overlayCtx.measureText(text, units);
metrics.width = textOptions.width;
metrics.height = textOptions.lineHeight;
} }
return metrics; }
}; //if (this.lastSelectedId)
// this.asc_selectComment(this.lastSelectedId, false);
};
_this.getCellMetrics = function(col, row) { CCellCommentator.prototype.getTextMetrics = function(text, units) {
var metrics = { width: 0, height: 0 };
var metrics = { top: 0, left: 0, width: 0, height: 0, result: false }; // px if (text && text.length && ((typeof (text) == 'string') || (typeof (text) == 'number'))) {
var textOptions = this.overlayCtx.measureText(text, units);
metrics.width = textOptions.width;
metrics.height = textOptions.lineHeight;
}
return metrics;
};
for (var n = 0; n < _this.worksheet.drawingArea.frozenPlaces.length; n++) { CCellCommentator.prototype.getCellMetrics = function(col, row) {
var frozenPlace = _this.worksheet.drawingArea.frozenPlaces[n]; var metrics = { top: 0, left: 0, width: 0, height: 0, result: false }; // px
if ( !frozenPlace.isCellInside({ col: col, row: row }) )
continue;
var fv = frozenPlace.getFirstVisible();
var mergedRange = _this.worksheet.model.getMergedByCell(row, col);
if (mergedRange && (fv.col < mergedRange.c2) && (fv.row < mergedRange.r2)) { for (var n = 0; n < this.worksheet.drawingArea.frozenPlaces.length; n++) {
var frozenPlace = this.worksheet.drawingArea.frozenPlaces[n];
if ( !frozenPlace.isCellInside({ col: col, row: row }) )
continue;
var startCol = (mergedRange.c1 > fv.col) ? mergedRange.c1 : fv.col; var fv = frozenPlace.getFirstVisible();
var startRow = (mergedRange.r1 > fv.row) ? mergedRange.r1 : fv.row; var mergedRange = this.worksheet.model.getMergedByCell(row, col);
metrics.top = _this.worksheet.getCellTop(startRow, 1) /*- _this.worksheet.getCellTop(fv.row, 1) + _this.worksheet.getCellTop(0, 1)*/ + _this.pxToPt(frozenPlace.getVerticalScroll()) - _this.worksheet.getCellTop(0, 1); if (mergedRange && (fv.col < mergedRange.c2) && (fv.row < mergedRange.r2)) {
metrics.left = _this.worksheet.getCellLeft(startCol, 1) /*- _this.worksheet.getCellLeft(fv.col, 1) + _this.worksheet.getCellLeft(0, 1)*/ + _this.pxToPt(frozenPlace.getHorizontalScroll()) - _this.worksheet.getCellLeft(0, 1);
var i; var startCol = (mergedRange.c1 > fv.col) ? mergedRange.c1 : fv.col;
for (i = startCol; i <= mergedRange.c2; i++) { var startRow = (mergedRange.r1 > fv.row) ? mergedRange.r1 : fv.row;
metrics.width += _this.worksheet.getColumnWidth(i, 1)
} metrics.top = this.worksheet.getCellTop(startRow, 1) /*- this.worksheet.getCellTop(fv.row, 1) + this.worksheet.getCellTop(0, 1)*/ + this.pxToPt(frozenPlace.getVerticalScroll()) - this.worksheet.getCellTop(0, 1);
for (i = startRow; i <= mergedRange.r2; i++) { metrics.left = this.worksheet.getCellLeft(startCol, 1) /*- this.worksheet.getCellLeft(fv.col, 1) + this.worksheet.getCellLeft(0, 1)*/ + this.pxToPt(frozenPlace.getHorizontalScroll()) - this.worksheet.getCellLeft(0, 1);
metrics.height += _this.worksheet.getRowHeight(i, 1)
}
metrics.result = true;
}
else if ((fv.row <= row) && (fv.col <= col)) {
metrics.top = _this.worksheet.getCellTop(row, 1) /*- _this.worksheet.getCellTop(fv.row, 1) + _this.worksheet.getCellTop(0, 1)*/ + _this.pxToPt(frozenPlace.getVerticalScroll()) - _this.worksheet.getCellTop(0, 1); var i;
metrics.left = _this.worksheet.getCellLeft(col, 1) /*- _this.worksheet.getCellLeft(fv.col, 1) + _this.worksheet.getCellLeft(0, 1)*/ + _this.pxToPt(frozenPlace.getHorizontalScroll()) - _this.worksheet.getCellLeft(0, 1); for (i = startCol; i <= mergedRange.c2; i++) {
metrics.width = _this.worksheet.getColumnWidth(col, 1); metrics.width += this.worksheet.getColumnWidth(i, 1)
metrics.height = _this.worksheet.getRowHeight(row, 1);
metrics.result = true;
} }
for (i = startRow; i <= mergedRange.r2; i++) {
metrics.height += this.worksheet.getRowHeight(i, 1)
}
metrics.result = true;
} }
else if ((fv.row <= row) && (fv.col <= col)) {
return metrics; metrics.top = this.worksheet.getCellTop(row, 1) /*- this.worksheet.getCellTop(fv.row, 1) + this.worksheet.getCellTop(0, 1)*/ + this.pxToPt(frozenPlace.getVerticalScroll()) - this.worksheet.getCellTop(0, 1);
}; metrics.left = this.worksheet.getCellLeft(col, 1) /*- this.worksheet.getCellLeft(fv.col, 1) + this.worksheet.getCellLeft(0, 1)*/ + this.pxToPt(frozenPlace.getHorizontalScroll()) - this.worksheet.getCellLeft(0, 1);
metrics.width = this.worksheet.getColumnWidth(col, 1);
_this.updateCommentPosition = function() { metrics.height = this.worksheet.getRowHeight(row, 1);
var _this = this; metrics.result = true;
}
}
if (_this.lastSelectedId) { return metrics;
var comment = _this.asc_findComment(_this.lastSelectedId); };
if (comment) {
var commentList = _this.asc_getComments(comment.asc_getCol(), comment.asc_getRow()); CCellCommentator.prototype.updateCommentPosition = function() {
if (commentList.length) { if (this.lastSelectedId) {
var comment = this.asc_findComment(this.lastSelectedId);
if (comment) {
_this.drawCommentCells(); var commentList = this.asc_getComments(comment.asc_getCol(), comment.asc_getRow());
var coords = _this.getCommentsCoords(commentList); if (commentList.length) {
var indexes = []; this.drawCommentCells();
for (var i = 0; i < commentList.length; i++) { var coords = this.getCommentsCoords(commentList);
indexes.push(commentList[i].asc_getId());
}
var metrics = _this.getCellMetrics(comment.asc_getCol(), comment.asc_getRow());
_this.worksheet.model.workbook.handlers.trigger( "asc_onUpdateCommentPosition", indexes, var indexes = [];
(metrics.result ? coords.asc_getLeftPX() : -1), for (var i = 0; i < commentList.length; i++) {
(metrics.result ? coords.asc_getTopPX() : -1), indexes.push(commentList[i].asc_getId());
(metrics.result ? coords.asc_getReverseLeftPX() : -1) );
} }
var metrics = this.getCellMetrics(comment.asc_getCol(), comment.asc_getRow());
this.worksheet.model.workbook.handlers.trigger( "asc_onUpdateCommentPosition", indexes,
(metrics.result ? coords.asc_getLeftPX() : -1),
(metrics.result ? coords.asc_getTopPX() : -1),
(metrics.result ? coords.asc_getReverseLeftPX() : -1) );
} }
} }
}
};
CCellCommentator.prototype.updateCommentsDependencies = function(bInsert, operType, updateRange) {
var t = this;
var UpdatePair = function(comment, bChange) {
this.comment = comment;
this.bChange = bChange;
}; };
var aChangedComments = []; // Array of UpdatePair
_this.updateCommentsDependencies = function(bInsert, operType, updateRange) {
function updateCommentsList(aComments) {
var UpdatePair = function(comment, bChange) { if ( aComments.length ) {
this.comment = comment;
this.bChange = bChange; t.bSaveHistory = false;
}; var changeArray = [];
var aChangedComments = []; // Array of UpdatePair var removeArray = [];
function updateCommentsList(aComments) { for (var i = 0; i < aComments.length; i++) {
if ( aComments.length ) { if ( aComments[i].bChange ) {
t.asc_changeComment(aComments[i].comment.asc_getId(), aComments[i].comment, /*bChangeCoords*/true, /*bNoEvent*/true);
_this.bSaveHistory = false; changeArray.push({"Id": aComments[i].comment.asc_getId(), "Comment": aComments[i].comment});
var changeArray = []; }
var removeArray = []; else {
t.asc_removeComment(aComments[i].comment.asc_getId(), /*bNoEvent*/true);
for (var i = 0; i < aComments.length; i++) { removeArray.push(aComments[i].comment.asc_getId());
if ( aComments[i].bChange ) {
_this.asc_changeComment(aComments[i].comment.asc_getId(), aComments[i].comment, /*bChangeCoords*/true, /*bNoEvent*/true);
changeArray.push({"Id": aComments[i].comment.asc_getId(), "Comment": aComments[i].comment});
}
else {
_this.asc_removeComment(aComments[i].comment.asc_getId(), /*bNoEvent*/true);
removeArray.push(aComments[i].comment.asc_getId());
}
} }
if ( changeArray.length )
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeComments", changeArray);
if ( removeArray.length )
_this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComments", removeArray);
_this.bSaveHistory = true;
_this.drawCommentCells();
} }
}
if ( changeArray.length )
var i, comment; t.worksheet.model.workbook.handlers.trigger("asc_onChangeComments", changeArray);
if ( bInsert ) { if ( removeArray.length )
switch (operType) { t.worksheet.model.workbook.handlers.trigger("asc_onRemoveComments", removeArray);
case c_oAscInsertOptions.InsertCellsAndShiftDown: { t.bSaveHistory = true;
for (i = 0; i < _this.aComments.length; i++) { t.drawCommentCells();
comment = new asc_CCommentData(_this.aComments[i]); }
if ( (comment.nRow >= updateRange.r1) && (comment.nCol >= updateRange.c1) && (comment.nCol <= updateRange.c2) ) { }
comment.nRow += updateRange.r2 - updateRange.r1 + 1;
aChangedComments.push( new UpdatePair(comment, true) ); var i, comment;
} if ( bInsert ) {
switch (operType) {
case c_oAscInsertOptions.InsertCellsAndShiftDown: {
for (i = 0; i < this.aComments.length; i++) {
comment = new asc_CCommentData(this.aComments[i]);
if ( (comment.nRow >= updateRange.r1) && (comment.nCol >= updateRange.c1) && (comment.nCol <= updateRange.c2) ) {
comment.nRow += updateRange.r2 - updateRange.r1 + 1;
aChangedComments.push( new UpdatePair(comment, true) );
} }
updateCommentsList(aChangedComments);
} }
updateCommentsList(aChangedComments);
}
break; break;
case c_oAscInsertOptions.InsertCellsAndShiftRight: { case c_oAscInsertOptions.InsertCellsAndShiftRight: {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
comment = new asc_CCommentData(_this.aComments[i]); comment = new asc_CCommentData(this.aComments[i]);
if ( (comment.nCol >= updateRange.c1) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) { if ( (comment.nCol >= updateRange.c1) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) {
comment.nCol += updateRange.c2 - updateRange.c1 + 1; comment.nCol += updateRange.c2 - updateRange.c1 + 1;
aChangedComments.push( new UpdatePair(comment, true) ); aChangedComments.push( new UpdatePair(comment, true) );
}
} }
updateCommentsList(aChangedComments);
} }
updateCommentsList(aChangedComments);
}
break; break;
case c_oAscInsertOptions.InsertColumns: { case c_oAscInsertOptions.InsertColumns: {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
comment = new asc_CCommentData(_this.aComments[i]); comment = new asc_CCommentData(this.aComments[i]);
if (comment.nCol >= updateRange.c1) { if (comment.nCol >= updateRange.c1) {
comment.nCol += updateRange.c2 - updateRange.c1 + 1; comment.nCol += updateRange.c2 - updateRange.c1 + 1;
aChangedComments.push( new UpdatePair(comment, true) ); aChangedComments.push( new UpdatePair(comment, true) );
}
} }
updateCommentsList(aChangedComments);
} }
updateCommentsList(aChangedComments);
}
break; break;
case c_oAscInsertOptions.InsertRows: { case c_oAscInsertOptions.InsertRows: {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
comment = new asc_CCommentData(_this.aComments[i]); comment = new asc_CCommentData(this.aComments[i]);
if (comment.nRow >= updateRange.r1) { if (comment.nRow >= updateRange.r1) {
comment.nRow += updateRange.r2 - updateRange.r1 + 1; comment.nRow += updateRange.r2 - updateRange.r1 + 1;
aChangedComments.push( new UpdatePair(comment, true) ); aChangedComments.push( new UpdatePair(comment, true) );
}
} }
updateCommentsList(aChangedComments);
} }
break; updateCommentsList(aChangedComments);
} }
break;
} }
else { }
switch (operType) { else {
switch (operType) {
case "deleteAllComments": {
for (i = 0; i < _this.aComments.length; i++) { case "deleteAllComments": {
comment = new asc_CCommentData(_this.aComments[i]); for (i = 0; i < this.aComments.length; i++) {
if ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) { comment = new asc_CCommentData(this.aComments[i]);
aChangedComments.push( new UpdatePair(comment, false) ); if ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) {
} aChangedComments.push( new UpdatePair(comment, false) );
} }
updateCommentsList(aChangedComments);
} }
updateCommentsList(aChangedComments);
}
break; break;
case c_oAscDeleteOptions.DeleteCellsAndShiftTop: { case c_oAscDeleteOptions.DeleteCellsAndShiftTop: {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
comment = new asc_CCommentData(_this.aComments[i]); comment = new asc_CCommentData(this.aComments[i]);
if ( (comment.nRow > updateRange.r1) && (comment.nCol >= updateRange.c1) && (comment.nCol <= updateRange.c2) ) { if ( (comment.nRow > updateRange.r1) && (comment.nCol >= updateRange.c1) && (comment.nCol <= updateRange.c2) ) {
comment.nRow -= updateRange.r2 - updateRange.r1 + 1; comment.nRow -= updateRange.r2 - updateRange.r1 + 1;
aChangedComments.push( new UpdatePair(comment, true) ); aChangedComments.push( new UpdatePair(comment, true) );
} }
else if ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) { else if ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) {
aChangedComments.push( new UpdatePair(comment, false) ); aChangedComments.push( new UpdatePair(comment, false) );
}
} }
updateCommentsList(aChangedComments);
} }
updateCommentsList(aChangedComments);
}
break; break;
case c_oAscDeleteOptions.DeleteCellsAndShiftLeft: { case c_oAscDeleteOptions.DeleteCellsAndShiftLeft: {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
comment = new asc_CCommentData(_this.aComments[i]); comment = new asc_CCommentData(this.aComments[i]);
if ( (comment.nCol > updateRange.c2) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) { if ( (comment.nCol > updateRange.c2) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) {
comment.nCol -= updateRange.c2 - updateRange.c1 + 1; comment.nCol -= updateRange.c2 - updateRange.c1 + 1;
aChangedComments.push( new UpdatePair(comment, true) ); aChangedComments.push( new UpdatePair(comment, true) );
} }
else if ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) { else if ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) {
aChangedComments.push( new UpdatePair(comment, false) ); aChangedComments.push( new UpdatePair(comment, false) );
}
} }
updateCommentsList(aChangedComments);
} }
updateCommentsList(aChangedComments);
}
break; break;
case c_oAscDeleteOptions.DeleteColumns: { case c_oAscDeleteOptions.DeleteColumns: {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
comment = new asc_CCommentData(_this.aComments[i]); comment = new asc_CCommentData(this.aComments[i]);
if (comment.nCol > updateRange.c2) { if (comment.nCol > updateRange.c2) {
comment.nCol -= updateRange.c2 - updateRange.c1 + 1; comment.nCol -= updateRange.c2 - updateRange.c1 + 1;
aChangedComments.push( new UpdatePair(comment, true) ); aChangedComments.push( new UpdatePair(comment, true) );
} }
else if ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) ) { else if ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) ) {
aChangedComments.push( new UpdatePair(comment, false) ); aChangedComments.push( new UpdatePair(comment, false) );
}
} }
updateCommentsList(aChangedComments);
} }
updateCommentsList(aChangedComments);
}
break; break;
case c_oAscDeleteOptions.DeleteRows: { case c_oAscDeleteOptions.DeleteRows: {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
comment = new asc_CCommentData(_this.aComments[i]); comment = new asc_CCommentData(this.aComments[i]);
if (comment.nRow > updateRange.r2) { if (comment.nRow > updateRange.r2) {
comment.nRow -= updateRange.r2 - updateRange.r1 + 1; comment.nRow -= updateRange.r2 - updateRange.r1 + 1;
aChangedComments.push( new UpdatePair(comment, true) ); aChangedComments.push( new UpdatePair(comment, true) );
} }
else if ( (updateRange.r1 <= comment.nRow) && (updateRange.r2 >= comment.nRow) ) { else if ( (updateRange.r1 <= comment.nRow) && (updateRange.r2 >= comment.nRow) ) {
aChangedComments.push( new UpdatePair(comment, false) ); aChangedComments.push( new UpdatePair(comment, false) );
}
} }
updateCommentsList(aChangedComments);
} }
updateCommentsList(aChangedComments);
}
break; break;
}
}
};
CCellCommentator.prototype.showHideComments = function(bHide, bColumn, start, stop) {
var t = this;
var aChangedComments = [];
function updateCommentsList(aComments) {
if ( aComments.length ) {
History.StartTransaction();
for (var i = 0; i < aComments.length; i++) {
this.asc_changeComment(aComments[i].asc_getId(), aComments[i]);
} }
} History.EndTransaction();
}; t.drawCommentCells();
}
}
_this.showHideComments = function(bHide, bColumn, start, stop) {
for (var i = 0; i < this.aComments.length; i++) {
var aChangedComments = []; var comment = new asc_CCommentData(this.aComments[i]);
function updateCommentsList(aComments) { if ( bColumn ) {
if ( (comment.nCol >= start) && (comment.nCol <= stop) ) {
comment.asc_putHiddenFlag(bHide);
aChangedComments.push(comment);
}
}
else {
if ( (comment.nRow >= start) && (comment.nRow <= stop) ) {
comment.asc_putHiddenFlag(bHide);
aChangedComments.push(comment);
}
}
}
updateCommentsList(aChangedComments);
};
CCellCommentator.prototype.sortComments = function(activeRange, changes) {
var t = this;
if (changes && activeRange) {
var updateCommentsList = function(aComments) {
if ( aComments.length ) { if ( aComments.length ) {
History.StartTransaction(); History.StartTransaction();
for (var i = 0; i < aComments.length; i++) { for (var i = 0; i < aComments.length; i++) {
_this.asc_changeComment(aComments[i].asc_getId(), aComments[i]); this.asc_changeComment(aComments[i].asc_getId(), aComments[i], true);
} }
History.EndTransaction(); History.EndTransaction();
_this.drawCommentCells(); t.drawCommentCells();
}
}
for (var i = 0; i < _this.aComments.length; i++) {
var comment = new asc_CCommentData(_this.aComments[i]);
if ( bColumn ) {
if ( (comment.nCol >= start) && (comment.nCol <= stop) ) {
comment.asc_putHiddenFlag(bHide);
aChangedComments.push(comment);
}
} }
else { };
if ( (comment.nRow >= start) && (comment.nRow <= stop) ) {
comment.asc_putHiddenFlag(bHide); var aChangedComments = [];
aChangedComments.push(comment); for (var i = 0; i < changes.places.length; i++) {
}
var list = this.asc_getComments(activeRange.c1, changes.places[i].from);
for (var j = 0; j < list.length; j++) {
var comment = new asc_CCommentData(list[j]);
comment.nRow = changes.places[i].to;
aChangedComments.push(comment);
} }
} }
updateCommentsList(aChangedComments); updateCommentsList(aChangedComments);
}; }
};
_this.sortComments = function(activeRange, changes) {
CCellCommentator.prototype.resetLastSelectedId = function() {
if (changes && activeRange) { this.cleanLastSelection();
this.lastSelectedId = null;
var updateCommentsList = function(aComments) { };
if ( aComments.length ) {
History.StartTransaction(); CCellCommentator.prototype.cleanLastSelection = function() {
if ( this.lastSelectedId ) {
for (var i = 0; i < aComments.length; i++) { var lastComment = this.asc_findComment(this.lastSelectedId);
_this.asc_changeComment(aComments[i].asc_getId(), aComments[i], true); if ( lastComment ) {
} var lastMetrics = this.getCellMetrics(lastComment.nCol, lastComment.nRow);
if ( lastMetrics.result ) {
History.EndTransaction(); var extraOffset = this.pxToPt(1);
_this.drawCommentCells(); this.overlayCtx.clearRect(lastMetrics.left, lastMetrics.top, lastMetrics.width - extraOffset, lastMetrics.height - extraOffset);
}
};
var aChangedComments = [];
for (var i = 0; i < changes.places.length; i++) {
var list = _this.asc_getComments(activeRange.c1, changes.places[i].from);
for (var j = 0; j < list.length; j++) {
var comment = new asc_CCommentData(list[j]);
comment.nRow = changes.places[i].to;
aChangedComments.push(comment);
}
}
updateCommentsList(aChangedComments);
}
};
_this.resetLastSelectedId = function() {
_this.cleanLastSelection();
_this.lastSelectedId = null;
};
_this.cleanLastSelection = function() {
if ( _this.lastSelectedId ) {
var lastComment = _this.asc_findComment(_this.lastSelectedId);
if ( lastComment ) {
var lastMetrics = _this.getCellMetrics(lastComment.nCol, lastComment.nRow);
if ( lastMetrics.result ) {
var extraOffset = _this.pxToPt(1);
_this.overlayCtx.clearRect(lastMetrics.left, lastMetrics.top, lastMetrics.width - extraOffset, lastMetrics.height - extraOffset);
}
} }
} }
}; }
};
_this.calcCommentsCoords = function(bSave) { CCellCommentator.prototype.calcCommentsCoords = function(bSave) {
_this.aCommentCoords = []; this.aCommentCoords = [];
for (var i = 0; i < _this.aComments.length; i++) { for (var i = 0; i < this.aComments.length; i++) {
var commentCell = _this.aComments[i]; var commentCell = this.aComments[i];
if (commentCell.asc_getDocumentFlag() || !_this.commentCoordsExist(commentCell.asc_getCol(), commentCell.asc_getRow())) { if (commentCell.asc_getDocumentFlag() || !this.commentCoordsExist(commentCell.asc_getCol(), commentCell.asc_getRow())) {
var commentList = _this.asc_getComments(commentCell.asc_getCol(), commentCell.asc_getRow()); var commentList = this.asc_getComments(commentCell.asc_getCol(), commentCell.asc_getRow());
// Calculate coords for document comments // Calculate coords for document comments
if (bSave && (commentCell.asc_getCol() == 0) && (commentCell.asc_getRow() == 0)) { if (bSave && (commentCell.asc_getCol() == 0) && (commentCell.asc_getRow() == 0)) {
var documentComments = _this.asc_getDocumentComments(); var documentComments = this.asc_getDocumentComments();
for (var j = 0; j < documentComments.length; j++) { for (var j = 0; j < documentComments.length; j++) {
commentList.push(documentComments[j]); commentList.push(documentComments[j]);
}
} }
if (commentList.length)
_this.aCommentCoords.push(_this.getCommentsCoords(commentList));
} }
if (commentList.length)
this.aCommentCoords.push(this.getCommentsCoords(commentList));
} }
}; }
};
_this.getCommentsCoords = function(comments) { CCellCommentator.prototype.getCommentsCoords = function(comments) {
// bWithScroll - учитывать вертикальный и горизонтальный скроллы // bWithScroll - учитывать вертикальный и горизонтальный скроллы
var _this = this; var t = this;
var coords = new asc_CCommentCoords(); var coords = new asc_CCommentCoords();
function calcCommentArea(comment, coords) { function calcCommentArea(comment, coords) {
/* User name /* User name
* Time * Time
* Text * Text
*/ */
var originalFont = _this.overlayCtx.getFont(); var originalFont = t.overlayCtx.getFont();
var outputFont = originalFont.clone(); var outputFont = originalFont.clone();
// Set to bold // Set to bold
outputFont.Bold = true; outputFont.Bold = true;
outputFont.FontSize = 9; outputFont.FontSize = 9;
_this.overlayCtx.setFont(outputFont); t.overlayCtx.setFont(outputFont);
// Title // Title
var txtMetrics = _this.getTextMetrics(comment.sUserName, 1); var txtMetrics = t.getTextMetrics(comment.sUserName, 1);
coords.dHeightPX += _this.ptToPx(txtMetrics.height); coords.dHeightPX += t.ptToPx(txtMetrics.height);
var userWidth = _this.ptToPx(txtMetrics.width); var userWidth = t.ptToPx(txtMetrics.width);
if (coords.dWidthPX < userWidth) if (coords.dWidthPX < userWidth)
coords.dWidthPX = userWidth; coords.dWidthPX = userWidth;
txtMetrics = _this.getTextMetrics(comment.sTime, 1); txtMetrics = t.getTextMetrics(comment.sTime, 1);
coords.dHeightPX += _this.ptToPx(txtMetrics.height); coords.dHeightPX += t.ptToPx(txtMetrics.height);
var timeWidth = _this.ptToPx(txtMetrics.width); var timeWidth = t.ptToPx(txtMetrics.width);
if (coords.dWidthPX < timeWidth) if (coords.dWidthPX < timeWidth)
coords.dWidthPX = timeWidth; coords.dWidthPX = timeWidth;
// Set to normal // Set to normal
outputFont.Bold = false; outputFont.Bold = false;
outputFont.FontSize = 9; outputFont.FontSize = 9;
_this.overlayCtx.setFont(outputFont); t.overlayCtx.setFont(outputFont);
// Comment text // Comment text
var commentSpl = comment.sText.split('\n'), i; var commentSpl = comment.sText.split('\n'), i;
for (i = 0; i < commentSpl.length; i++) { for (i = 0; i < commentSpl.length; i++) {
txtMetrics = _this.getTextMetrics(commentSpl[i], 1);
coords.dHeightPX += _this.ptToPx(txtMetrics.height);
var lineWidth = _this.ptToPx(txtMetrics.width);
if (coords.dWidthPX < lineWidth)
coords.dWidthPX = lineWidth;
}
for (i = 0; i < comment.aReplies.length; i++) { txtMetrics = t.getTextMetrics(commentSpl[i], 1);
calcCommentArea(comment.aReplies[i], coords); coords.dHeightPX += t.ptToPx(txtMetrics.height);
} var lineWidth = t.ptToPx(txtMetrics.width);
if (coords.dWidthPX < lineWidth)
coords.dWidthPX = lineWidth;
}
// Min values for (i = 0; i < comment.aReplies.length; i++) {
if (coords.dWidthPX < _this.minAreaWidth) calcCommentArea(comment.aReplies[i], coords);
coords.dWidthPX = _this.minAreaWidth; }
if (coords.dHeightPX < _this.minAreaHeight) // Min values
coords.dHeightPX = _this.minAreaHeight; if (coords.dWidthPX < t.minAreaWidth)
coords.dWidthPX = t.minAreaWidth;
// Calc other coords if (coords.dHeightPX < t.minAreaHeight)
coords.dWidthMM = _this.pxToMm(coords.dWidthPX); coords.dHeightPX = t.minAreaHeight;
coords.dHeightMM = _this.pxToMm(coords.dHeightPX);
var headerRowOffPx = _this.worksheet.getCellTop(0, 0); // Calc other coords
var headerColOffPx = _this.worksheet.getCellLeft(0, 0); coords.dWidthMM = t.pxToMm(coords.dWidthPX);
coords.dHeightMM = t.pxToMm(coords.dHeightPX);
coords.nCol = comment.nCol; var headerRowOffPx = t.worksheet.getCellTop(0, 0);
coords.nRow = comment.nRow; var headerColOffPx = t.worksheet.getCellLeft(0, 0);
var mergedRange = _this.worksheet.model.getMergedByCell(comment.nRow, comment.nCol); coords.nCol = comment.nCol;
coords.nRow = comment.nRow;
coords.nLeft = (mergedRange ? mergedRange.c2 : comment.nCol) + 1; var mergedRange = t.worksheet.model.getMergedByCell(comment.nRow, comment.nCol);
if ( !_this.worksheet.cols[coords.nLeft] ) {
_this.worksheet.expandColsOnScroll(true);
_this.worksheet.handlers.trigger("reinitializeScrollX");
}
coords.nTop = mergedRange ? mergedRange.r1 : comment.nRow;
coords.nLeftOffset = 0;
coords.nTopOffset = 0;
var fvr = _this.worksheet.getFirstVisibleRow(true);
var fvc = _this.worksheet.getFirstVisibleCol(true);
var frozenOffset = _this.getFrozenOffset();
if ( _this.worksheet.topLeftFrozenCell ) {
if ( comment.nCol >= _this.worksheet.getFirstVisibleCol(false) )
frozenOffset.offsetX = 0;
if ( comment.nRow >= _this.worksheet.getFirstVisibleRow(false) )
frozenOffset.offsetY = 0;
}
// Tooltip coords coords.nLeft = (mergedRange ? mergedRange.c2 : comment.nCol) + 1;
coords.dReverseLeftPX = _this.worksheet.getCellLeft(comment.nCol, 0) - _this.worksheet.getCellLeft(fvc, 0) + headerColOffPx + _this.ptToPx(frozenOffset.offsetX); if ( !t.worksheet.cols[coords.nLeft] ) {
coords.dLeftPX = _this.worksheet.getCellLeft(coords.nLeft, 0) - _this.worksheet.getCellLeft(fvc, 0) + headerColOffPx + _this.ptToPx(frozenOffset.offsetX); t.worksheet.expandColsOnScroll(true);
coords.dTopPX = _this.worksheet.getCellTop(coords.nTop, 0) - _this.worksheet.getCellTop(fvr, 0) + headerRowOffPx + _this.ptToPx(frozenOffset.offsetY); t.worksheet.handlers.trigger("reinitializeScrollX");
}
// Correction for merged cell coords.nTop = mergedRange ? mergedRange.r1 : comment.nRow;
var fvrPx = _this.worksheet.getCellTop(0, 0); coords.nLeftOffset = 0;
if (coords.dTopPX < fvrPx) coords.nTopOffset = 0;
coords.dTopPX = fvrPx;
coords.dLeftMM = _this.worksheet.getCellLeft(coords.nLeft, 3) - _this.worksheet.getCellLeft(fvc, 3); var fvr = t.worksheet.getFirstVisibleRow(true);
coords.dTopMM = _this.worksheet.getCellTop(coords.nTop, 3) - _this.worksheet.getCellTop(fvr, 3); var fvc = t.worksheet.getFirstVisibleCol(true);
var findCol = _this.worksheet._findColUnderCursor(_this.worksheet.getCellLeft(coords.nLeft, 1) + _this.pxToPt(coords.dWidthPX + headerColOffPx) - _this.worksheet.getCellLeft(fvc, 1), true); var frozenOffset = t.getFrozenOffset();
var findRow = _this.worksheet._findRowUnderCursor(_this.worksheet.getCellTop(coords.nTop, 1) + _this.pxToPt(coords.dHeightPX + headerRowOffPx) - _this.worksheet.getCellTop(fvr, 1), true); if ( t.worksheet.topLeftFrozenCell ) {
if ( comment.nCol >= t.worksheet.getFirstVisibleCol(false) )
frozenOffset.offsetX = 0;
if ( comment.nRow >= t.worksheet.getFirstVisibleRow(false) )
frozenOffset.offsetY = 0;
}
coords.nRight = findCol ? findCol.col : 0; // Tooltip coords
coords.nBottom = findRow ? findRow.row : 0; coords.dReverseLeftPX = t.worksheet.getCellLeft(comment.nCol, 0) - t.worksheet.getCellLeft(fvc, 0) + headerColOffPx + t.ptToPx(frozenOffset.offsetX);
coords.dLeftPX = t.worksheet.getCellLeft(coords.nLeft, 0) - t.worksheet.getCellLeft(fvc, 0) + headerColOffPx + t.ptToPx(frozenOffset.offsetX);
coords.dTopPX = t.worksheet.getCellTop(coords.nTop, 0) - t.worksheet.getCellTop(fvr, 0) + headerRowOffPx + t.ptToPx(frozenOffset.offsetY);
coords.nRightOffset = _this.worksheet.getCellLeft(coords.nLeft, 0) + coords.nLeftOffset + coords.dWidthPX + headerColOffPx - _this.worksheet.getCellLeft(coords.nRight, 0); // Correction for merged cell
coords.nBottomOffset = _this.worksheet.getCellTop(coords.nTop, 0) + coords.nTopOffset + coords.dHeightPX + headerRowOffPx - _this.worksheet.getCellTop(coords.nBottom, 0); var fvrPx = t.worksheet.getCellTop(0, 0);
if (coords.dTopPX < fvrPx)
coords.dTopPX = fvrPx;
// Return original font coords.dLeftMM = t.worksheet.getCellLeft(coords.nLeft, 3) - t.worksheet.getCellLeft(fvc, 3);
_this.overlayCtx.setFont(originalFont); coords.dTopMM = t.worksheet.getCellTop(coords.nTop, 3) - t.worksheet.getCellTop(fvr, 3);
}
for (var i = 0; i < comments.length; i++) { var findCol = t.worksheet._findColUnderCursor(t.worksheet.getCellLeft(coords.nLeft, 1) + t.pxToPt(coords.dWidthPX + headerColOffPx) - t.worksheet.getCellLeft(fvc, 1), true);
calcCommentArea(comments[i], coords); var findRow = t.worksheet._findRowUnderCursor(t.worksheet.getCellTop(coords.nTop, 1) + t.pxToPt(coords.dHeightPX + headerRowOffPx) - t.worksheet.getCellTop(fvr, 1), true);
}
if (comments.length) { coords.nRight = findCol ? findCol.col : 0;
coords.dWidthPX += _this.commentPadding * 2; coords.nBottom = findRow ? findRow.row : 0;
coords.dWidthMM = _this.pxToMm(coords.dWidthPX);
coords.dHeightPX += _this.commentPadding * 2; coords.nRightOffset = t.worksheet.getCellLeft(coords.nLeft, 0) + coords.nLeftOffset + coords.dWidthPX + headerColOffPx - t.worksheet.getCellLeft(coords.nRight, 0);
coords.dHeightMM = _this.pxToMm(coords.dHeightPX); coords.nBottomOffset = t.worksheet.getCellTop(coords.nTop, 0) + coords.nTopOffset + coords.dHeightPX + headerRowOffPx - t.worksheet.getCellTop(coords.nBottom, 0);
}
return coords; // Return original font
}; t.overlayCtx.setFont(originalFont);
}
_this.commentCoordsExist = function(col, row) { for (var i = 0; i < comments.length; i++) {
calcCommentArea(comments[i], coords);
}
var result = false; if (comments.length) {
for (var i = 0; i < _this.aCommentCoords.length; i++) { coords.dWidthPX += this.commentPadding * 2;
if ((col == _this.aCommentCoords[i].nCol) && (row == _this.aCommentCoords[i].nRow)) coords.dWidthMM = this.pxToMm(coords.dWidthPX);
return true;
}
return result;
};
_this.prepareCommentsToSave = function() { coords.dHeightPX += this.commentPadding * 2;
coords.dHeightMM = this.pxToMm(coords.dHeightPX);
}
/* Calculate the coords of comments for: return coords;
* first visible col = 0 };
* first visible row = 0
* + document comments -> A1
*/
_this.calcCommentsCoords(true); CCellCommentator.prototype.commentCoordsExist = function(col, row) {
};
_this.cleanSelectedComment = function() { var result = false;
if ( _this.lastSelectedId ) { for (var i = 0; i < this.aCommentCoords.length; i++) {
var comment = _this.asc_findComment(_this.lastSelectedId); if ((col == this.aCommentCoords[i].nCol) && (row == this.aCommentCoords[i].nRow))
if ( comment && !comment.asc_getDocumentFlag() && !comment.asc_getSolved() ) { return true;
var metrics = _this.getCellMetrics(comment.asc_getCol(), comment.asc_getRow()); }
if (metrics.result) return result;
_this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width, metrics.height); };
}
}
};
_this.getFrozenOffset = function() {
var offsetX = 0, offsetY = 0, cFrozen = 0, rFrozen = 0, diffWidth = 0, diffHeight = 0;
if ( _this.worksheet.topLeftFrozenCell ) {
cFrozen = _this.worksheet.topLeftFrozenCell.getCol0();
rFrozen = _this.worksheet.topLeftFrozenCell.getRow0();
diffWidth = _this.worksheet.cols[cFrozen].left - _this.worksheet.cols[0].left;
diffHeight = _this.worksheet.rows[rFrozen].top - _this.worksheet.rows[0].top;
offsetX = _this.worksheet.cols[_this.worksheet.visibleRange.c1].left - _this.worksheet.cellsLeft - diffWidth;
offsetY = _this.worksheet.rows[_this.worksheet.visibleRange.r1].top - _this.worksheet.cellsTop - diffHeight;
}
return { offsetX: offsetX, offsetY: offsetY };
};
//-----------------------------------------------------------------------------------
// Misc methods
//-----------------------------------------------------------------------------------
_this.pxToPt = function(val) { CCellCommentator.prototype.prepareCommentsToSave = function() {
return val * _this.ascCvtRatio(0, 1);
};
_this.ptToPx = function(val) { /* Calculate the coords of comments for:
return val * _this.ascCvtRatio(1, 0); * first visible col = 0
}; * first visible row = 0
* + document comments -> A1
*/
_this.mmToPx = function(val) { this.calcCommentsCoords(true);
return val * _this.ascCvtRatio(3, 0); };
};
_this.pxToMm = function(val) { CCellCommentator.prototype.cleanSelectedComment = function() {
return val * _this.ascCvtRatio(0, 3); if ( this.lastSelectedId ) {
}; var comment = this.asc_findComment(this.lastSelectedId);
if ( comment && !comment.asc_getDocumentFlag() && !comment.asc_getSolved() ) {
var metrics = this.getCellMetrics(comment.asc_getCol(), comment.asc_getRow());
if (metrics.result)
this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width, metrics.height);
}
}
};
_this.ascCvtRatio = function(fromUnits, toUnits) { CCellCommentator.prototype.getFrozenOffset = function() {
return Asc.getCvtRatio(fromUnits, toUnits, _this.overlayCtx.getPPIX());
var offsetX = 0, offsetY = 0, cFrozen = 0, rFrozen = 0, diffWidth = 0, diffHeight = 0;
if ( this.worksheet.topLeftFrozenCell ) {
cFrozen = this.worksheet.topLeftFrozenCell.getCol0();
rFrozen = this.worksheet.topLeftFrozenCell.getRow0();
diffWidth = this.worksheet.cols[cFrozen].left - this.worksheet.cols[0].left;
diffHeight = this.worksheet.rows[rFrozen].top - this.worksheet.rows[0].top;
offsetX = this.worksheet.cols[this.worksheet.visibleRange.c1].left - this.worksheet.cellsLeft - diffWidth;
offsetY = this.worksheet.rows[this.worksheet.visibleRange.r1].top - this.worksheet.cellsTop - diffHeight;
} }
} return { offsetX: offsetX, offsetY: offsetY };
};
// Prototype //-----------------------------------------------------------------------------------
CCellCommentator.prototype = { // Misc methods
//-----------------------------------------------------------------------------------
// Show/Hide CCellCommentator.prototype.pxToPt = function(val) {
return val * this.ascCvtRatio(0, 1);
};
asc_showComments: function() { CCellCommentator.prototype.ptToPx = function(val) {
var _this = this; return val * this.ascCvtRatio(1, 0);
if ( !_this.bShow ) { };
_this.bShow = true;
_this.drawCommentCells();
}
},
asc_hideComments: function() { CCellCommentator.prototype.mmToPx = function(val) {
var _this = this; return val * this.ascCvtRatio(3, 0);
_this.bShow = false; };
_this.drawCommentCells();
_this.worksheet.model.workbook.handlers.trigger("asc_onHideComment");
},
// Main CCellCommentator.prototype.pxToMm = function(val) {
return val * this.ascCvtRatio(0, 3);
};
asc_showComment: function(id, bNew) { CCellCommentator.prototype.ascCvtRatio = function(fromUnits, toUnits) {
return Asc.getCvtRatio(fromUnits, toUnits, this.overlayCtx.getPPIX());
};
var _this = this; // Show/Hide
var comment = _this.asc_findComment(id); CCellCommentator.prototype.asc_showComments = function() {
if ( !this.bShow ) {
this.bShow = true;
this.drawCommentCells();
}
};
if (comment) { CCellCommentator.prototype.asc_hideComments = function() {
this.bShow = false;
var callbackFunc = function(result) { this.drawCommentCells();
this.worksheet.model.workbook.handlers.trigger("asc_onHideComment");
if ( !result ) };
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
else
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
var commentList = _this.asc_getComments(comment.asc_getCol(), comment.asc_getRow());
var coords = _this.getCommentsCoords(commentList);
var indexes = []; // Main
for (var i = 0; i < commentList.length; i++) {
indexes.push(commentList[i].asc_getId());
}
// Second click - hide comment CCellCommentator.prototype.asc_showComment = function(id, bNew) {
if (indexes.length) {
if ( _this.lastSelectedId != id )
_this.worksheet.model.workbook.handlers.trigger("asc_onHideComment");
_this.worksheet.model.workbook.handlers.trigger("asc_onShowComment", indexes, coords.asc_getLeftPX(), coords.asc_getTopPX(), coords.asc_getReverseLeftPX(), bNew);
_this.drawCommentCells();
}
_this.lastSelectedId = id;
};
_this.isLockedComment(comment, false, callbackFunc);
}
else
_this.lastSelectedId = null;
},
asc_selectComment: function(id, bMove) { var t = this;
var comment = this.asc_findComment(id);
var _this = this;
var comment = _this.asc_findComment(id); if (comment) {
// Чистим предыдущий селект var callbackFunc = function(result) {
_this.cleanLastSelection();
_this.lastSelectedId = null; if ( !result )
t.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
if (comment && !comment.asc_getDocumentFlag() && !comment.asc_getSolved()) { else
t.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
_this.lastSelectedId = id;
var commentList = t.asc_getComments(comment.asc_getCol(), comment.asc_getRow());
var col = comment.asc_getCol(); var coords = t.getCommentsCoords(commentList);
var row = comment.asc_getRow();
var fvc = _this.worksheet.getFirstVisibleCol(true); var indexes = [];
var fvr = _this.worksheet.getFirstVisibleRow(true); for (var i = 0; i < commentList.length; i++) {
var lvc = _this.worksheet.getLastVisibleCol(); indexes.push(commentList[i].asc_getId());
var lvr = _this.worksheet.getLastVisibleRow();
var offset;
if ( bMove ) {
if ( (row < fvr) || (row > lvr) ) {
offset = row - fvr - Math.round(( lvr - fvr ) / 2);
_this.worksheet.scrollVertical(offset);
_this.worksheet.handlers.trigger("reinitializeScrollY");
}
if ( (col < fvc) || (col > lvc) ) {
offset = col - fvc - Math.round(( lvc - fvc ) / 2);
_this.worksheet.scrollHorizontal(offset);
_this.worksheet.handlers.trigger("reinitializeScrollX");
}
} }
var metrics = _this.getCellMetrics(col, row); // Second click - hide comment
if (metrics.result) { if (indexes.length) {
var extraOffset = _this.pxToPt(1); if ( t.lastSelectedId != id )
_this.overlayCtx.ctx.globalAlpha = 0.2; t.worksheet.model.workbook.handlers.trigger("asc_onHideComment");
_this.overlayCtx.beginPath();
_this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset); t.worksheet.model.workbook.handlers.trigger("asc_onShowComment", indexes, coords.asc_getLeftPX(), coords.asc_getTopPX(), coords.asc_getReverseLeftPX(), bNew);
_this.overlayCtx.setFillStyle(_this.commentFillColor); t.drawCommentCells();
_this.overlayCtx.fillRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset);
_this.overlayCtx.ctx.globalAlpha = 1;
} }
} t.lastSelectedId = id;
}, };
t.isLockedComment(comment, false, callbackFunc);
}
else
t.lastSelectedId = null;
};
CCellCommentator.prototype.asc_selectComment = function(id, bMove) {
var comment = this.asc_findComment(id);
asc_findComment: function(id) { // Чистим предыдущий селект
this.cleanLastSelection();
this.lastSelectedId = null;
var _this = this; if (comment && !comment.asc_getDocumentFlag() && !comment.asc_getSolved()) {
function checkCommentId(id, commentObject) { this.lastSelectedId = id;
if (commentObject.asc_getId() == id) var col = comment.asc_getCol();
return commentObject; var row = comment.asc_getRow();
var fvc = this.worksheet.getFirstVisibleCol(true);
var fvr = this.worksheet.getFirstVisibleRow(true);
var lvc = this.worksheet.getLastVisibleCol();
var lvr = this.worksheet.getLastVisibleRow();
for (var i = 0; i < commentObject.aReplies.length; i++) { var offset;
var comment = checkCommentId(id, commentObject.aReplies[i]); if ( bMove ) {
if (comment) if ( (row < fvr) || (row > lvr) ) {
return comment; offset = row - fvr - Math.round(( lvr - fvr ) / 2);
this.worksheet.scrollVertical(offset);
this.worksheet.handlers.trigger("reinitializeScrollY");
}
if ( (col < fvc) || (col > lvc) ) {
offset = col - fvc - Math.round(( lvc - fvc ) / 2);
this.worksheet.scrollHorizontal(offset);
this.worksheet.handlers.trigger("reinitializeScrollX");
} }
return null;
} }
for (var i = 0; i < _this.aComments.length; i++) { var metrics = this.getCellMetrics(col, row);
var commentCell = _this.aComments[i]; if (metrics.result) {
var obj = checkCommentId(id, commentCell); var extraOffset = this.pxToPt(1);
if (obj) this.overlayCtx.ctx.globalAlpha = 0.2;
return obj; this.overlayCtx.beginPath();
this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset);
this.overlayCtx.setFillStyle(this.commentFillColor);
this.overlayCtx.fillRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset);
this.overlayCtx.ctx.globalAlpha = 1;
}
}
};
CCellCommentator.prototype.asc_findComment = function(id) {
function checkCommentId(id, commentObject) {
if (commentObject.asc_getId() == id)
return commentObject;
for (var i = 0; i < commentObject.aReplies.length; i++) {
var comment = checkCommentId(id, commentObject.aReplies[i]);
if (comment)
return comment;
} }
return null; return null;
}, }
asc_addComment: function(comment, bIsNotUpdate) { for (var i = 0; i < this.aComments.length; i++) {
var commentCell = this.aComments[i];
var obj = checkCommentId(id, commentCell);
if (obj)
return obj;
}
return null;
};
var _this = this; CCellCommentator.prototype.asc_addComment = function(comment, bIsNotUpdate) {
var oComment = comment;
var bChange = false;
oComment.wsId = _this.worksheet.model.getId();
oComment.setId();
if (!oComment.bDocument) { var t = this;
if (!bIsNotUpdate) { var oComment = comment;
oComment.asc_putCol(_this.worksheet.getSelectedColumnIndex()); var bChange = false;
oComment.asc_putRow(_this.worksheet.getSelectedRowIndex()); oComment.wsId = this.worksheet.model.getId();
} oComment.setId();
var existComments = _this.asc_getComments(oComment.nCol, oComment.nRow); if (!oComment.bDocument) {
if ( existComments.length ) { if (!bIsNotUpdate) {
oComment = existComments[0]; oComment.asc_putCol(this.worksheet.getSelectedColumnIndex());
bChange = true; oComment.asc_putRow(this.worksheet.getSelectedRowIndex());
}
else {
if ((oComment.nCol != null) && (oComment.nRow != null)) {
var cellAddress = new CellAddress(oComment.nRow, oComment.nCol, 0);
oComment.sQuoteText = cellAddress.getID() + " : " + _this.worksheet.model.getCell(cellAddress).getValueWithFormat();
}
}
} }
function callbackFunc(result) {
if ( !result ) {
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", oComment.asc_getId(), oComment.asc_getUserId());
}
else {
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", oComment.asc_getId());
// Add new comment
if ( !bChange ) {
History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Add, _this.worksheet.model.getId(), null, new asc_CCommentData(oComment));
_this.aComments.push(oComment);
if (!bIsNotUpdate) var existComments = this.asc_getComments(oComment.nCol, oComment.nRow);
_this.drawCommentCells(); if ( existComments.length ) {
} oComment = existComments[0];
_this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", oComment.asc_getId(), oComment); bChange = true;
}
else {
if ((oComment.nCol != null) && (oComment.nRow != null)) {
var cellAddress = new CellAddress(oComment.nRow, oComment.nCol, 0);
oComment.sQuoteText = cellAddress.getID() + " : " + this.worksheet.model.getCell(cellAddress).getValueWithFormat();
} }
} }
}
if (bIsNotUpdate) function callbackFunc(result) {
callbackFunc(true); if ( !result ) {
else t.worksheet.model.workbook.handlers.trigger("asc_onLockComment", oComment.asc_getId(), oComment.asc_getUserId());
_this.isLockedComment(oComment, true, callbackFunc); }
}, else {
t._addComment(oComment, bChange, bIsNotUpdate);
}
}
asc_changeComment: function(id, oComment, bChangeCoords, bNoEvent) { if (bIsNotUpdate)
callbackFunc(true);
else
this.isLockedComment(oComment, true, callbackFunc);
};
var _this = this; CCellCommentator.prototype.asc_changeComment = function(id, oComment, bChangeCoords, bNoEvent) {
var comment = _this.asc_findComment(id);
if (null === comment)
return;
function callbackFunc(result) {
if ( !result ) {
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
} else {
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
var commentBefore = new asc_CCommentData(comment);
if (comment) {
if ( bChangeCoords ) {
comment.asc_putCol(oComment.asc_getCol());
comment.asc_putRow(oComment.asc_getRow());
}
comment.asc_putText(oComment.asc_getText());
comment.asc_putQuoteText(oComment.asc_getQuoteText());
comment.asc_putUserId(oComment.asc_getUserId());
comment.asc_putUserName(oComment.asc_getUserName());
comment.asc_putTime(oComment.asc_getTime());
comment.asc_putSolved(oComment.asc_getSolved());
comment.asc_putHiddenFlag(oComment.asc_getHiddenFlag());
comment.aReplies = [];
if ( !comment.bDocument && (comment.nCol != null) && (comment.nRow != null) ) {
var cellAddress = new CellAddress(comment.nRow, comment.nCol, 0);
comment.sQuoteText = cellAddress.getID() + " : " + _this.worksheet.model.getCell(cellAddress).getValueWithFormat();
}
var count = oComment.asc_getRepliesCount(); var t = this;
for (var i = 0; i < count; i++) { var comment = this.asc_findComment(id);
comment.asc_addReply(oComment.asc_getReply(i)); if (null === comment)
} return;
if ( !bNoEvent )
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", comment.asc_getId(), comment);
}
if ( _this.bSaveHistory ) { function callbackFunc(result) {
var commentAfter = new asc_CCommentData(comment); if ( !result ) {
t.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
} else {
t.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
var compositeComment = new CompositeCommentData(); var commentBefore = new asc_CCommentData(comment);
compositeComment.commentBefore = commentBefore; if (comment) {
compositeComment.commentAfter = commentAfter; if ( bChangeCoords ) {
comment.asc_putCol(oComment.asc_getCol());
comment.asc_putRow(oComment.asc_getRow());
}
comment.asc_putText(oComment.asc_getText());
comment.asc_putQuoteText(oComment.asc_getQuoteText());
comment.asc_putUserId(oComment.asc_getUserId());
comment.asc_putUserName(oComment.asc_getUserName());
comment.asc_putTime(oComment.asc_getTime());
comment.asc_putSolved(oComment.asc_getSolved());
comment.asc_putHiddenFlag(oComment.asc_getHiddenFlag());
comment.aReplies = [];
if ( !comment.bDocument && (comment.nCol != null) && (comment.nRow != null) ) {
var cellAddress = new CellAddress(comment.nRow, comment.nCol, 0);
comment.sQuoteText = cellAddress.getID() + " : " + t.worksheet.model.getCell(cellAddress).getValueWithFormat();
}
History.Create_NewPoint(); var count = oComment.asc_getRepliesCount();
History.Add(g_oUndoRedoComment, historyitem_Comment_Change, _this.worksheet.model.getId(), null, compositeComment); for (var i = 0; i < count; i++) {
comment.asc_addReply(oComment.asc_getReply(i));
} }
if ( !bNoEvent )
_this.drawCommentCells(); t.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", comment.asc_getId(), comment);
} }
}
_this.isLockedComment(comment, true, callbackFunc); if ( t.bSaveHistory ) {
}, var commentAfter = new asc_CCommentData(comment);
asc_removeComment: function(id, bNoEvent) { var compositeComment = new CompositeCommentData();
compositeComment.commentBefore = commentBefore;
compositeComment.commentAfter = commentAfter;
var _this = this; History.Create_NewPoint();
var comment = _this.asc_findComment(id); History.Add(g_oUndoRedoComment, historyitem_Comment_Change, t.worksheet.model.getId(), null, compositeComment);
if (null === comment)
return;
function callbackFunc(result) {
if ( !result ) {
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
} else {
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
if (comment) {
var i;
if (comment.oParent) {
for (i = 0; i < comment.oParent.aReplies.length; i++) {
if (comment.asc_getId() == comment.oParent.aReplies[i].asc_getId()) {
if ( _this.bSaveHistory ) {
History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Remove, _this.worksheet.model.getId(), null, new asc_CCommentData(comment.oParent.aReplies[i]));
}
comment.oParent.aReplies.splice(i, 1);
break;
}
}
} else {
for (i = 0; i < _this.aComments.length; i++) {
if (comment.asc_getId() == _this.aComments[i].asc_getId()) {
if ( _this.bSaveHistory ) {
History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Remove, _this.worksheet.model.getId(), null, new asc_CCommentData(_this.aComments[i]));
}
_this.aComments.splice(i, 1);
break;
}
}
_this.worksheet.draw();
}
_this.drawCommentCells();
if ( !bNoEvent )
_this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", id);
}
} }
t.drawCommentCells();
} }
}
_this.isLockedComment(comment, true, callbackFunc); this.isLockedComment(comment, true, callbackFunc);
}, };
CCellCommentator.prototype.asc_removeComment = function(id, bNoEvent) {
var t = this;
var comment = this.asc_findComment(id);
if (null === comment)
return;
// Extra functions function callbackFunc(result) {
if ( !result ) {
t.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
} else {
t.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
}
asc_getComments: function(col, row) { t._removeComment(comment, bNoEvent, true);
}
// Array of root items this.isLockedComment(comment, true, callbackFunc);
var comments = []; };
var _this = this;
var _col = col, _row = row, mergedRange = null;
var length = _this.aComments.length;
if (!this.bShow) // Extra functions
return comments;
if (0 < length) { CCellCommentator.prototype.asc_getComments = function(col, row) {
if (null == _col || null == _row) {
var selectedCell = _this.worksheet.getSelectedRange();
var oFirst = selectedCell.getFirst();
_col = oFirst.col - 1;
_row = oFirst.row - 1;
} else
mergedRange = _this.worksheet.model.getMergedByCell(row, col);
for (var i = 0; i < length; i++) { // Array of root items
var commentCell = _this.aComments[i]; var comments = [];
var _col = col, _row = row, mergedRange = null;
var length = this.aComments.length;
if ( !commentCell.asc_getDocumentFlag() /*&& !commentCell.asc_getSolved()*/ && !commentCell.asc_getHiddenFlag() && (commentCell.nLevel == 0) ) { if (!this.bShow)
if ( !mergedRange ) { return comments;
if ( (_col == commentCell.nCol) && (_row == commentCell.nRow) )
comments.push(commentCell); if (0 < length) {
} if (null == _col || null == _row) {
else { var selectedCell = this.worksheet.getSelectedRange();
if ( (commentCell.nCol >= mergedRange.c1) && (commentCell.nRow >= mergedRange.r1) && (commentCell.nCol <= mergedRange.c2) && (commentCell.nRow <= mergedRange.r2) ) var oFirst = selectedCell.getFirst();
comments.push(commentCell); _col = oFirst.col - 1;
} _row = oFirst.row - 1;
} else
mergedRange = this.worksheet.model.getMergedByCell(row, col);
for (var i = 0; i < length; i++) {
var commentCell = this.aComments[i];
if ( !commentCell.asc_getDocumentFlag() /*&& !commentCell.asc_getSolved()*/ && !commentCell.asc_getHiddenFlag() && (commentCell.nLevel == 0) ) {
if ( !mergedRange ) {
if ( (_col == commentCell.nCol) && (_row == commentCell.nRow) )
comments.push(commentCell);
}
else {
if ( (commentCell.nCol >= mergedRange.c1) && (commentCell.nRow >= mergedRange.r1) && (commentCell.nCol <= mergedRange.c2) && (commentCell.nRow <= mergedRange.r2) )
comments.push(commentCell);
} }
} }
} }
return comments; }
}, return comments;
};
asc_getDocumentComments: function() { CCellCommentator.prototype.asc_getDocumentComments = function() {
// Array of root items // Array of root items
var comments = []; var comments = [];
for (var i = 0; i < this.aComments.length; i++) { for (var i = 0; i < this.aComments.length; i++) {
var commentCell = this.aComments[i]; var commentCell = this.aComments[i];
if ((commentCell.nLevel == 0) && commentCell.asc_getDocumentFlag()) if ((commentCell.nLevel == 0) && commentCell.asc_getDocumentFlag())
comments.push(commentCell); comments.push(commentCell);
} }
return comments; return comments;
}, };
// Undo/Redo CCellCommentator.prototype._addComment = function (oComment, bChange, bIsNotUpdate) {
this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", oComment.asc_getId());
Undo: function(type, data) { // Add new comment
if (!bChange) {
History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Add, this.worksheet.model.getId(), null, new asc_CCommentData(oComment));
var _this = this, i, parentComment; this.aComments.push(oComment);
switch (type) {
case historyitem_Comment_Add: if (!bIsNotUpdate)
if (data.oParent) { this.drawCommentCells();
parentComment = _this.asc_findComment(data.oParent.asc_getId()); }
for (i = 0; i < parentComment.aReplies.length; i++) { this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", oComment.asc_getId(), oComment);
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) { };
parentComment.aReplies.splice(i, 1);
break; CCellCommentator.prototype._removeComment = function (comment, bNoEvent, isDraw) {
} if (!comment)
} return;
} else {
for (i = 0; i < _this.aComments.length; i++) {
if (_this.aComments[i].asc_getId() == data.asc_getId()) {
_this.aComments.splice(i, 1);
_this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", data.asc_getId());
break;
}
}
}
break;
case historyitem_Comment_Remove: var i, id = comment.asc_getId();
if (data.oParent) { if (comment.oParent) {
parentComment = _this.asc_findComment(data.oParent.asc_getId()); for (i = 0; i < comment.oParent.aReplies.length; ++i) {
parentComment.aReplies.push(data); if (comment.asc_getId() == comment.oParent.aReplies[i].asc_getId()) {
} else {
_this.aComments.push(data); if (this.bSaveHistory) {
_this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", data.asc_getId(), data); History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Remove, this.worksheet.model.getId(), null, new asc_CCommentData(comment.oParent.aReplies[i]));
} }
comment.oParent.aReplies.splice(i, 1);
break; break;
}
}
} else {
for (i = 0; i < this.aComments.length; i++) {
if (comment.asc_getId() == this.aComments[i].asc_getId()) {
case historyitem_Comment_Change: if (this.bSaveHistory) {
if (data.commentAfter.oParent) { History.Create_NewPoint();
parentComment = _this.asc_findComment(data.commentAfter.oParent.asc_getId()); History.Add(g_oUndoRedoComment, historyitem_Comment_Remove, this.worksheet.model.getId(), null, new asc_CCommentData(this.aComments[i]));
for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1);
parentComment.aReplies.push(data.commentBefore);
break;
}
}
} else {
for (i = 0; i < _this.aComments.length; i++) {
if (_this.aComments[i].asc_getId() == data.commentAfter.asc_getId()) {
_this.aComments.splice(i, 1);
_this.aComments.push(data.commentBefore);
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", data.commentBefore.asc_getId(), data.commentBefore);
break;
}
}
} }
this.aComments.splice(i, 1);
break; break;
}
} }
}, if (isDraw)
this.worksheet.draw();
}
Redo: function(type, data) { if (isDraw)
this.drawCommentCells();
if (!bNoEvent)
this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", id);
};
var _this = this, parentComment, i; CCellCommentator.prototype.isMissComments = function (range) {
switch (type) { var oComment, bMiss = false;
for (var i = 0, length = this.aComments.length; i < length; ++i) {
oComment = this.aComments[i];
if (!oComment.bHidden && range.contains(oComment.nCol, oComment.nRow)) {
if (bMiss)
return true;
bMiss = true;
}
}
case historyitem_Comment_Add: return false;
if (data.oParent) { };
parentComment = _this.asc_findComment(data.oParent.asc_getId());
parentComment.aReplies.push(data);
} else {
_this.aComments.push(data);
_this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", data.asc_getId(), data);
}
break;
case historyitem_Comment_Remove: CCellCommentator.prototype.mergeComments = function (range) {
if (data.oParent) { var i, length, deleteComments = [], oComment, r1 = range.r1, c1 = range.c1, mergeComment = null;
parentComment = _this.asc_findComment(data.oParent.asc_getId()); for (i = 0, length = this.aComments.length; i < length; ++i) {
for (i = 0; i < parentComment.aReplies.length; i++) { oComment = this.aComments[i];
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) { if (range.contains(oComment.nCol, oComment.nRow)) {
parentComment.aReplies.splice(i, 1); if (null === mergeComment)
break; mergeComment = oComment;
} else if (oComment.nRow <= mergeComment.nRow && oComment.nCol < mergeComment.nCol) {
deleteComments.push(mergeComment);
mergeComment = oComment;
} else
deleteComments.push(oComment);
}
}
if (mergeComment && (mergeComment.nCol !== c1 || mergeComment.nRow !== r1)) {
this._removeComment(mergeComment, false, false);
// add Comment
mergeComment.nCol = c1;
mergeComment.nRow = r1;
var cellAddress = new CellAddress(mergeComment.nRow, mergeComment.nCol, 0);
mergeComment.sQuoteText = cellAddress.getID() + " : " + this.worksheet.model.getCell(cellAddress).getValueWithFormat();
this._addComment(mergeComment, false, true);
}
for (i = 0, length = deleteComments.length; i < length; ++i) {
this._removeComment(deleteComments[i], false, false);
}
};
// Undo/Redo
CCellCommentator.prototype.Undo = function(type, data) {
var i, parentComment;
switch (type) {
case historyitem_Comment_Add:
if (data.oParent) {
parentComment = this.asc_findComment(data.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1);
break;
} }
} else { }
for (i = 0; i < _this.aComments.length; i++) { } else {
if (_this.aComments[i].asc_getId() == data.asc_getId()) { for (i = 0; i < this.aComments.length; i++) {
_this.aComments.splice(i, 1); if (this.aComments[i].asc_getId() == data.asc_getId()) {
_this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", data.asc_getId()); this.aComments.splice(i, 1);
break; this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", data.asc_getId());
} break;
} }
} }
break; }
break;
case historyitem_Comment_Change: case historyitem_Comment_Remove:
if (data.commentBefore.oParent) { if (data.oParent) {
parentComment = _this.asc_findComment(data.commentBefore.oParent.asc_getId()); parentComment = this.asc_findComment(data.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) { parentComment.aReplies.push(data);
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) { } else {
parentComment.aReplies.splice(i, 1); this.aComments.push(data);
parentComment.aReplies.push(data.commentAfter); this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", data.asc_getId(), data);
break; }
} break;
case historyitem_Comment_Change:
if (data.commentAfter.oParent) {
parentComment = this.asc_findComment(data.commentAfter.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1);
parentComment.aReplies.push(data.commentBefore);
break;
} }
} else { }
for (i = 0; i < _this.aComments.length; i++) { } else {
if (_this.aComments[i].asc_getId() == data.commentBefore.asc_getId()) { for (i = 0; i < this.aComments.length; i++) {
_this.aComments.splice(i, 1); if (this.aComments[i].asc_getId() == data.commentAfter.asc_getId()) {
_this.aComments.push(data.commentAfter); this.aComments.splice(i, 1);
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", data.commentAfter.asc_getId(), data.commentAfter); this.aComments.push(data.commentBefore);
break; this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", data.commentBefore.asc_getId(), data.commentBefore);
} break;
} }
} }
break; }
} break;
} }
}; };
CCellCommentator.prototype.Redo = function(type, data) {
var parentComment, i;
switch (type) {
case historyitem_Comment_Add:
if (data.oParent) {
parentComment = this.asc_findComment(data.oParent.asc_getId());
parentComment.aReplies.push(data);
} else {
this.aComments.push(data);
this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", data.asc_getId(), data);
}
break;
case historyitem_Comment_Remove:
if (data.oParent) {
parentComment = this.asc_findComment(data.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1);
break;
}
}
} else {
for (i = 0; i < this.aComments.length; i++) {
if (this.aComments[i].asc_getId() == data.asc_getId()) {
this.aComments.splice(i, 1);
this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", data.asc_getId());
break;
}
}
}
break;
case historyitem_Comment_Change:
if (data.commentBefore.oParent) {
parentComment = this.asc_findComment(data.commentBefore.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1);
parentComment.aReplies.push(data.commentAfter);
break;
}
}
} else {
for (i = 0; i < this.aComments.length; i++) {
if (this.aComments[i].asc_getId() == data.commentBefore.asc_getId()) {
this.aComments.splice(i, 1);
this.aComments.push(data.commentAfter);
this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", data.commentAfter.asc_getId(), data.commentAfter);
break;
}
}
}
break;
}
};
\ No newline at end of file
...@@ -735,7 +735,7 @@ Vertex.prototype = { ...@@ -735,7 +735,7 @@ Vertex.prototype = {
slave.setFormula(cell.formulaParsed.assemble(), true, false); slave.setFormula(cell.formulaParsed.assemble(), true, false);
} }
} }
this.bbox = bboxTo this.bbox = bboxTo;
this.cellId = sNewName; this.cellId = sNewName;
this.nodeId = getVertexId(this.sheetId, this.cellId); this.nodeId = getVertexId(this.sheetId, this.cellId);
this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ]; this.wb.needRecalc.nodes[this.nodeId] = [this.sheetId, this.cellId ];
...@@ -1250,7 +1250,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){ ...@@ -1250,7 +1250,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
wTN: oWsTo.getName(), wTN: oWsTo.getName(),
wTI: indexTo, wTI: indexTo,
wTId: oWsTo.getId() wTId: oWsTo.getId()
} };
//переводим обратно в индекс sheet перед которым надо вставить //переводим обратно в индекс sheet перед которым надо вставить
if(tempW.wFI < tempW.wTI) if(tempW.wFI < tempW.wTI)
tempW.wTI++; tempW.wTI++;
...@@ -1280,7 +1280,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){ ...@@ -1280,7 +1280,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
} }
History.TurnOn(); History.TurnOn();
var movedSheet = this.aWorksheets.splice(indexFrom, 1); var movedSheet = this.aWorksheets.splice(indexFrom, 1);
this.aWorksheets.splice(indexTo, 0, movedSheet[0]) this.aWorksheets.splice(indexTo, 0, movedSheet[0]);
this._updateWorksheetIndexes(); this._updateWorksheetIndexes();
this._insertWorksheetFormula(tempW.wTI); this._insertWorksheetFormula(tempW.wTI);
...@@ -3040,7 +3040,7 @@ Woorksheet.prototype._prepareMoveRangeGetCleanRanges=function(oBBoxFrom, oBBoxTo ...@@ -3040,7 +3040,7 @@ Woorksheet.prototype._prepareMoveRangeGetCleanRanges=function(oBBoxFrom, oBBoxTo
{ {
if(r1 <= r2 && c1 <= c2) if(r1 <= r2 && c1 <= c2)
aRangesToCheck.push(oThis.getRange3(r1, c1, r2, c2)); aRangesToCheck.push(oThis.getRange3(r1, c1, r2, c2));
} };
if(intersection.r1 == oBBoxTo.r1 && intersection.c1 == oBBoxTo.c1) if(intersection.r1 == oBBoxTo.r1 && intersection.c1 == oBBoxTo.c1)
{ {
fAddToRangesToCheck(aRangesToCheck, oBBoxTo.r1, intersection.c2 + 1, intersection.r2, oBBoxTo.c2); fAddToRangesToCheck(aRangesToCheck, oBBoxTo.r1, intersection.c2 + 1, intersection.r2, oBBoxTo.c2);
...@@ -4329,7 +4329,7 @@ Range.prototype.createFromBBox=function(worksheet, bbox){ ...@@ -4329,7 +4329,7 @@ Range.prototype.createFromBBox=function(worksheet, bbox){
var oRes = new Range(worksheet, bbox.r1, bbox.c1, bbox.r2, bbox.c2); var oRes = new Range(worksheet, bbox.r1, bbox.c1, bbox.r2, bbox.c2);
oRes.bbox = bbox.clone(); oRes.bbox = bbox.clone();
return oRes; return oRes;
} };
Range.prototype.clone=function(oNewWs){ Range.prototype.clone=function(oNewWs){
if(!oNewWs) if(!oNewWs)
oNewWs = this.worksheet; oNewWs = this.worksheet;
...@@ -4697,9 +4697,7 @@ Range.prototype.getCells=function(){ ...@@ -4697,9 +4697,7 @@ Range.prototype.getCells=function(){
}; };
Range.prototype.setValue=function(val,callback){ Range.prototype.setValue=function(val,callback){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
History.StartTransaction(); History.StartTransaction();
var oThis = this;
this._foreach(function(cell){ this._foreach(function(cell){
cell.setValue(val,callback); cell.setValue(val,callback);
// if(cell.isEmpty()) // if(cell.isEmpty())
...@@ -4709,11 +4707,8 @@ Range.prototype.setValue=function(val,callback){ ...@@ -4709,11 +4707,8 @@ Range.prototype.setValue=function(val,callback){
}; };
Range.prototype.setValue2=function(array){ Range.prototype.setValue2=function(array){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
History.StartTransaction(); History.StartTransaction();
var wb = this.worksheet.workbook, ws = this.worksheet, ar =[];
//[{"text":"qwe","format":{"b":true, "i":false, "u":Asc.EUnderline.underlineNone, "s":false, "fn":"Arial", "fs": 12, "c": 0xff00ff, "va": "subscript" }},{}...] //[{"text":"qwe","format":{"b":true, "i":false, "u":Asc.EUnderline.underlineNone, "s":false, "fn":"Arial", "fs": 12, "c": 0xff00ff, "va": "subscript" }},{}...]
var oThis = this;
/* /*
Устанавливаем значение в Range ячеек. В отличае от setValue, сюда мы попадаем только в случае ввода значения отличного от формулы. Таким образом, если в ячейке была формула, то для нее в графе очищается список ячеек от которых зависела. После чего выставляем флаг о необходимости пересчета. Устанавливаем значение в Range ячеек. В отличае от setValue, сюда мы попадаем только в случае ввода значения отличного от формулы. Таким образом, если в ячейке была формула, то для нее в графе очищается список ячеек от которых зависела. После чего выставляем флаг о необходимости пересчета.
*/ */
...@@ -4726,7 +4721,6 @@ Range.prototype.setValue2=function(array){ ...@@ -4726,7 +4721,6 @@ Range.prototype.setValue2=function(array){
}; };
Range.prototype.setCellStyle=function(val){ Range.prototype.setCellStyle=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4770,7 +4764,6 @@ Range.prototype.setTableStyle=function(val){ ...@@ -4770,7 +4764,6 @@ Range.prototype.setTableStyle=function(val){
}; };
Range.prototype.setNumFormat=function(val){ Range.prototype.setNumFormat=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4793,9 +4786,7 @@ Range.prototype.setNumFormat=function(val){ ...@@ -4793,9 +4786,7 @@ Range.prototype.setNumFormat=function(val){
}; };
Range.prototype.shiftNumFormat=function(nShift, aDigitsCount){ Range.prototype.shiftNumFormat=function(nShift, aDigitsCount){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
var bRes = false; var bRes = false;
var oThis = this;
this._setPropertyNoEmpty(null, null, function(cell, nRow0, nCol0, nRowStart, nColStart){ this._setPropertyNoEmpty(null, null, function(cell, nRow0, nCol0, nRowStart, nColStart){
bRes |= cell.shiftNumFormat(nShift, aDigitsCount[nCol0 - nColStart] || 8); bRes |= cell.shiftNumFormat(nShift, aDigitsCount[nCol0 - nColStart] || 8);
}); });
...@@ -4825,7 +4816,6 @@ Range.prototype.setFont=function(val){ ...@@ -4825,7 +4816,6 @@ Range.prototype.setFont=function(val){
}; };
Range.prototype.setFontname=function(val){ Range.prototype.setFontname=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4848,7 +4838,6 @@ Range.prototype.setFontname=function(val){ ...@@ -4848,7 +4838,6 @@ Range.prototype.setFontname=function(val){
}; };
Range.prototype.setFontsize=function(val){ Range.prototype.setFontsize=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4871,7 +4860,6 @@ Range.prototype.setFontsize=function(val){ ...@@ -4871,7 +4860,6 @@ Range.prototype.setFontsize=function(val){
}; };
Range.prototype.setFontcolor=function(val){ Range.prototype.setFontcolor=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4894,7 +4882,6 @@ Range.prototype.setFontcolor=function(val){ ...@@ -4894,7 +4882,6 @@ Range.prototype.setFontcolor=function(val){
}; };
Range.prototype.setBold=function(val){ Range.prototype.setBold=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4917,7 +4904,6 @@ Range.prototype.setBold=function(val){ ...@@ -4917,7 +4904,6 @@ Range.prototype.setBold=function(val){
}; };
Range.prototype.setItalic=function(val){ Range.prototype.setItalic=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4962,7 +4948,6 @@ Range.prototype.setUnderline=function(val){ ...@@ -4962,7 +4948,6 @@ Range.prototype.setUnderline=function(val){
}; };
Range.prototype.setStrikeout=function(val){ Range.prototype.setStrikeout=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -4985,7 +4970,6 @@ Range.prototype.setStrikeout=function(val){ ...@@ -4985,7 +4970,6 @@ Range.prototype.setStrikeout=function(val){
}; };
Range.prototype.setFontAlign=function(val){ Range.prototype.setFontAlign=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -5054,7 +5038,6 @@ Range.prototype.setAlignHorizontal=function(val){ ...@@ -5054,7 +5038,6 @@ Range.prototype.setAlignHorizontal=function(val){
}; };
Range.prototype.setFill=function(val){ Range.prototype.setFill=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -5077,7 +5060,6 @@ Range.prototype.setFill=function(val){ ...@@ -5077,7 +5060,6 @@ Range.prototype.setFill=function(val){
}; };
Range.prototype.setBorderSrc=function(border){ Range.prototype.setBorderSrc=function(border){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
History.StartTransaction(); History.StartTransaction();
if (null == border) if (null == border)
border = new Border(); border = new Border();
...@@ -5269,7 +5251,6 @@ Range.prototype.setBorder=function(border){ ...@@ -5269,7 +5251,6 @@ Range.prototype.setBorder=function(border){
}; };
Range.prototype.setShrinkToFit=function(val){ Range.prototype.setShrinkToFit=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -5292,7 +5273,6 @@ Range.prototype.setShrinkToFit=function(val){ ...@@ -5292,7 +5273,6 @@ Range.prototype.setShrinkToFit=function(val){
}; };
Range.prototype.setWrap=function(val){ Range.prototype.setWrap=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -5315,7 +5295,6 @@ Range.prototype.setWrap=function(val){ ...@@ -5315,7 +5295,6 @@ Range.prototype.setWrap=function(val){
}; };
Range.prototype.setAngle=function(val){ Range.prototype.setAngle=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -5338,7 +5317,6 @@ Range.prototype.setAngle=function(val){ ...@@ -5338,7 +5317,6 @@ Range.prototype.setAngle=function(val){
}; };
Range.prototype.setVerticalText=function(val){ Range.prototype.setVerticalText=function(val){
History.Create_NewPoint(); History.Create_NewPoint();
var oBBox = this.bbox;
this.createCellOnRowColCross(); this.createCellOnRowColCross();
var fSetProperty = this._setProperty; var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType(); var nRangeType = this._getRangeType();
...@@ -7596,7 +7574,7 @@ Range.prototype._promoteFromTo=function(from, to, bIsPromote, oCanPromote, bCtrl ...@@ -7596,7 +7574,7 @@ Range.prototype._promoteFromTo=function(from, to, bIsPromote, oCanPromote, bCtrl
History.EndTransaction(); History.EndTransaction();
buildRecalc(this.worksheet.workbook); buildRecalc(this.worksheet.workbook);
unLockDraw(this.worksheet.workbook); unLockDraw(this.worksheet.workbook);
} };
Range.prototype.createCellOnRowColCross=function(){ Range.prototype.createCellOnRowColCross=function(){
var oThis = this; var oThis = this;
var bbox = this.bbox; var bbox = this.bbox;
......
...@@ -1830,8 +1830,7 @@ ...@@ -1830,8 +1830,7 @@
WorkbookView.prototype._initCommentsToSave = function () { WorkbookView.prototype._initCommentsToSave = function () {
var isFirst = true; var isFirst = true;
for (var wsKey in this.wsViews) for (var wsKey in this.wsViews) if (this.wsViews.hasOwnProperty(wsKey)) {
{
var wsView = this.wsViews[wsKey]; var wsView = this.wsViews[wsKey];
var wsModel = wsView.model; var wsModel = wsView.model;
wsView.cellCommentator.prepareCommentsToSave(); wsView.cellCommentator.prepareCommentsToSave();
......
...@@ -6266,6 +6266,9 @@ ...@@ -6266,6 +6266,9 @@
var notEmpty = false; var notEmpty = false;
var r, c; var r, c;
if (this.cellCommentator.isMissComments(arn))
return true;
switch (options) { switch (options) {
case c_oAscMergeOptions.Merge: case c_oAscMergeOptions.Merge:
case c_oAscMergeOptions.MergeCenter: case c_oAscMergeOptions.MergeCenter:
...@@ -7869,13 +7872,21 @@ ...@@ -7869,13 +7872,21 @@
case "merge": case "merge":
if (isLargeRange) { callTrigger = true; t.handlers.trigger("slowOperation", true); } if (isLargeRange) { callTrigger = true; t.handlers.trigger("slowOperation", true); }
switch (val) { switch (val) {
case c_oAscMergeOptions.Unmerge: range.unmerge(); break; case c_oAscMergeOptions.MergeCenter:
case c_oAscMergeOptions.MergeCenter: range.merge(val); break; case c_oAscMergeOptions.Merge:
range.merge(val);
t.cellCommentator.mergeComments(range.getBBox0());
break;
case c_oAscMergeOptions.Unmerge:
range.unmerge();
break;
case c_oAscMergeOptions.MergeAcross: case c_oAscMergeOptions.MergeAcross:
for (res = arn.r1; res <= arn.r2; ++res) for (res = arn.r1; res <= arn.r2; ++res) {
t.model.getRange3(res, arn.c1, res, arn.c2).merge(val); t.model.getRange3(res, arn.c1, res, arn.c2).merge(val);
cell = new asc_Range(arn.c1, res, arn.c2, res);
t.cellCommentator.mergeComments(cell);
}
break; break;
case c_oAscMergeOptions.Merge: range.merge(val); break;
} }
break; break;
......
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