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,54 +492,49 @@ CompositeCommentData.prototype = { ...@@ -492,54 +492,49 @@ CompositeCommentData.prototype = {
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
/** @constructor */ /** @constructor */
function CCellCommentator(currentSheet) { function CCellCommentator(currentSheet) {
this.worksheet = currentSheet;
this.overlayCtx = currentSheet.overlayCtx;
this.drawingCtx = currentSheet.drawingCtx;
var _this = this; // Drawing settings
var asc = window["Asc"]; this.bShow = true;
var asc_applyFunction = asc.applyFunction; this.commentIconColor = new CColor(255, 144, 0);
var asc_CCollaborativeRange = asc.asc_CCollaborativeRange; this.commentFillColor = new CColor(255, 255, 0);
var isViewerMode = function() { return _this.worksheet.handlers.trigger("getViewerMode"); }; this.commentPadding = 4; // px
this.minAreaWidth = 160; // px
this.minAreaHeight = 80; // px
this.aComments = [];
this.aCommentCoords = [];
this.lastSelectedId = null;
this.bSaveHistory = true;
}
_this.worksheet = currentSheet; //-----------------------------------------------------------------------------------
_this.overlayCtx = currentSheet.overlayCtx; // Public methods
_this.drawingCtx = currentSheet.drawingCtx; //-----------------------------------------------------------------------------------
// Drawing settings CCellCommentator.prototype.isViewerMode = function () {
_this.bShow = true; return this.worksheet.handlers.trigger("getViewerMode");
_this.commentIconColor = new CColor(255, 144, 0); };
_this.commentFillColor = new CColor(255, 255, 0);
_this.commentBorderWidth = 1; // px CCellCommentator.prototype.isLockedComment = function(oComment, lockByDefault, callbackFunc) {
_this.commentPadding = 4; // px
_this.minAreaWidth = 160; // px
_this.minAreaHeight = 80; // px
_this.aComments = [];
_this.aCommentCoords = [];
_this.lastSelectedId = null;
_this.bSaveHistory = true;
//-----------------------------------------------------------------------------------
// Public methods
//-----------------------------------------------------------------------------------
_this.isLockedComment = function(oComment, lockByDefault, callbackFunc) {
var _this = this;
var lockInfo; var lockInfo;
var model = _this.worksheet.model; var model = this.worksheet.model;
var sheetId = model.getId(); var sheetId = model.getId();
var objectGuid = oComment.asc_getId(); var objectGuid = oComment.asc_getId();
if (objectGuid) { if (objectGuid) {
if (false === _this.worksheet.collaborativeEditing.isCoAuthoringExcellEnable()) { if (false === this.worksheet.collaborativeEditing.isCoAuthoringExcellEnable()) {
// Запрещено совместное редактирование // Запрещено совместное редактирование
asc_applyFunction(callbackFunc, true); Asc.applyFunction(callbackFunc, true);
return; return;
} }
if ( lockByDefault ) if ( lockByDefault )
_this.worksheet.collaborativeEditing.onStartCheckLock(); this.worksheet.collaborativeEditing.onStartCheckLock();
// Комментарий к документу блокируем как Range // Комментарий к документу блокируем как Range
if ( !oComment.asc_getDocumentFlag() ) { if ( !oComment.asc_getDocumentFlag() ) {
...@@ -557,71 +552,69 @@ function CCellCommentator(currentSheet) { ...@@ -557,71 +552,69 @@ function CCellCommentator(currentSheet) {
r1 = r2 = r; r1 = r2 = r;
} }
lockInfo = _this.worksheet.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Range, /*subType*/null, sheetId, new asc_CCollaborativeRange(c1, r1, c2, r2)); lockInfo = this.worksheet.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Range, /*subType*/null, sheetId, new Asc.asc_CCollaborativeRange(c1, r1, c2, r2));
} else } else
lockInfo = _this.worksheet.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Object, /*subType*/null, sheetId, objectGuid); lockInfo = this.worksheet.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Object, /*subType*/null, sheetId, objectGuid);
if (false === _this.worksheet.collaborativeEditing.getCollaborativeEditing()) { if (false === this.worksheet.collaborativeEditing.getCollaborativeEditing()) {
// Пользователь редактирует один: не ждем ответа, а сразу продолжаем редактирование // Пользователь редактирует один: не ждем ответа, а сразу продолжаем редактирование
asc_applyFunction(callbackFunc, true); Asc.applyFunction(callbackFunc, true);
callbackFunc = undefined; callbackFunc = undefined;
} }
if (false !== _this.worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeMine, /*bCheckOnlyLockAll*/false)) { if (false !== this.worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeMine, /*bCheckOnlyLockAll*/false)) {
// Редактируем сами // Редактируем сами
asc_applyFunction(callbackFunc, true); Asc.applyFunction(callbackFunc, true);
return; return;
} }
else if (false !== _this.worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeOther, /*bCheckOnlyLockAll*/false)) { else if (false !== this.worksheet.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeOther, /*bCheckOnlyLockAll*/false)) {
// Уже ячейку кто-то редактирует // Уже ячейку кто-то редактирует
asc_applyFunction(callbackFunc, false); Asc.applyFunction(callbackFunc, false);
return; return;
} }
// Блокируем // Блокируем
if ( lockByDefault ) { if ( lockByDefault ) {
_this.worksheet.collaborativeEditing.addCheckLock(lockInfo); this.worksheet.collaborativeEditing.addCheckLock(lockInfo);
_this.worksheet.collaborativeEditing.onEndCheckLock(callbackFunc); this.worksheet.collaborativeEditing.onEndCheckLock(callbackFunc);
} }
else else
asc_applyFunction(callbackFunc, true); Asc.applyFunction(callbackFunc, true);
} }
}; };
CCellCommentator.prototype.callLockComments = function(range) {
_this.callLockComments = function(range) {
if ( range ) { if ( range ) {
for (var i = 0; i < _this.aComments.length; i++) { for (var i = 0; i < this.aComments.length; i++) {
var comment = _this.aComments[i]; var comment = this.aComments[i];
if ( (comment.nCol >= range.c1) && (comment.nCol <= range.c2) && (comment.nRow >= range.r1) && (comment.nRow <= range.r2) ) 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.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
} }
} }
}; };
_this.unlockComments = function() { CCellCommentator.prototype.unlockComments = function() {
for (var i = 0; i < _this.aComments.length; i++) { for (var i = 0; i < this.aComments.length; i++) {
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", _this.aComments[i].asc_getId()); this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", this.aComments[i].asc_getId());
} }
}; };
_this.tryUnlockComment = function(id) { CCellCommentator.prototype.tryUnlockComment = function(id) {
for (var i = 0; i < _this.aComments.length; i++) { for (var i = 0; i < this.aComments.length; i++) {
if ( _this.aComments[i].asc_getId() == id ) { if ( this.aComments[i].asc_getId() == id ) {
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", id); this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", id);
break; break;
} }
} }
}; };
_this.moveRangeComments = function(rangeFrom, rangeTo) { CCellCommentator.prototype.moveRangeComments = function(rangeFrom, rangeTo) {
if ( rangeFrom && rangeTo ) { if ( rangeFrom && rangeTo ) {
var colOffset = rangeTo.c1 - rangeFrom.c1; var colOffset = rangeTo.c1 - rangeFrom.c1;
var rowOffset = rangeTo.r1 - rangeFrom.r1; var rowOffset = rangeTo.r1 - rangeFrom.r1;
_this.worksheet.model.workbook.handlers.trigger("asc_onHideComment"); this.worksheet.model.workbook.handlers.trigger("asc_onHideComment");
for (var i = 0; i < _this.aComments.length; i++) { for (var i = 0; i < this.aComments.length; i++) {
var comment = _this.aComments[i]; var comment = this.aComments[i];
if ( (comment.nCol >= rangeFrom.c1) && (comment.nCol <= rangeFrom.c2) && (comment.nRow >= rangeFrom.r1) && (comment.nRow <= rangeFrom.r2) ) { if ( (comment.nCol >= rangeFrom.c1) && (comment.nCol <= rangeFrom.c2) && (comment.nRow >= rangeFrom.r1) && (comment.nRow <= rangeFrom.r2) ) {
...@@ -630,8 +623,8 @@ function CCellCommentator(currentSheet) { ...@@ -630,8 +623,8 @@ function CCellCommentator(currentSheet) {
comment.nCol += colOffset; comment.nCol += colOffset;
comment.nRow += rowOffset; comment.nRow += rowOffset;
var cellAddress = new CellAddress(comment.nRow, comment.nCol, 0); var cellAddress = new CellAddress(comment.nRow, comment.nCol, 0);
comment.sQuoteText = cellAddress.getID() + " : " + _this.worksheet.model.getCell(cellAddress).getValueWithFormat(); comment.sQuoteText = cellAddress.getID() + " : " + this.worksheet.model.getCell(cellAddress).getValueWithFormat();
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", comment.asc_getId(), comment); this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", comment.asc_getId(), comment);
var commentAfter = new asc_CCommentData(comment); var commentAfter = new asc_CCommentData(comment);
...@@ -640,83 +633,77 @@ function CCellCommentator(currentSheet) { ...@@ -640,83 +633,77 @@ function CCellCommentator(currentSheet) {
compositeComment.commentAfter = commentAfter; compositeComment.commentAfter = commentAfter;
History.Create_NewPoint(); History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Change, _this.worksheet.model.getId(), null, compositeComment); History.Add(g_oUndoRedoComment, historyitem_Comment_Change, this.worksheet.model.getId(), null, compositeComment);
} }
} }
} }
}; };
_this.deleteCommentsRange = function(range) { CCellCommentator.prototype.deleteCommentsRange = function(range) {
if ( range ) { if ( range ) {
var aCommentId = [], i; var aCommentId = [], i;
for (i = 0; i < _this.aComments.length; ++i) { for (i = 0; i < this.aComments.length; ++i) {
var comment = _this.aComments[i]; var comment = this.aComments[i];
if ( (comment.nCol >= range.c1) && (comment.nCol <= range.c2) && (comment.nRow >= range.r1) && (comment.nRow <= range.r2) ) { if ( (comment.nCol >= range.c1) && (comment.nCol <= range.c2) && (comment.nRow >= range.r1) && (comment.nRow <= range.r2) ) {
aCommentId.push(comment.asc_getId()); aCommentId.push(comment.asc_getId());
} }
} }
History.StartTransaction(); History.StartTransaction();
for (i = 0; i < aCommentId.length; i++) { for (i = 0; i < aCommentId.length; i++) {
_this.asc_removeComment(aCommentId[i]); this.asc_removeComment(aCommentId[i]);
} }
History.EndTransaction(); History.EndTransaction();
} }
}; };
_this.prepareComments = function(arrComments) { CCellCommentator.prototype.prepareComments = function(arrComments) {
var commentList = []; var commentList = [];
for (var i = 0; i < arrComments.length; ++i) { for (var i = 0; i < arrComments.length; ++i) {
var comment = {"Id": arrComments[i].asc_getId(), "Comment": arrComments[i]}; var comment = {"Id": arrComments[i].asc_getId(), "Comment": arrComments[i]};
_this.addCommentSerialize(comment["Comment"]); this.addCommentSerialize(comment["Comment"]);
commentList.push(comment); commentList.push(comment);
} }
return commentList; return commentList;
}; };
_this.addCommentSerialize = function(oComment) {
var _this = this;
CCellCommentator.prototype.addCommentSerialize = function(oComment) {
if (oComment) { if (oComment) {
if ( !oComment.bDocument && (oComment.nCol != null) && (oComment.nRow != null) ) { if ( !oComment.bDocument && (oComment.nCol != null) && (oComment.nRow != null) ) {
var cellAddress = new CellAddress(oComment.nRow, oComment.nCol, 0); var cellAddress = new CellAddress(oComment.nRow, oComment.nCol, 0);
oComment.sQuoteText = cellAddress.getID() + " : " + _this.worksheet.model.getCell(cellAddress).getValueWithFormat(); oComment.sQuoteText = cellAddress.getID() + " : " + this.worksheet.model.getCell(cellAddress).getValueWithFormat();
} }
_this.aComments.push(oComment); this.aComments.push(oComment);
} }
}; };
_this.getCommentsXY = function(x, y) {
var _this = this;
var findCol = _this.worksheet._findColUnderCursor(_this.pxToPt(x), true); CCellCommentator.prototype.getCommentsXY = function(x, y) {
var findRow = _this.worksheet._findRowUnderCursor(_this.pxToPt(y), true); var findCol = this.worksheet._findColUnderCursor(this.pxToPt(x), true);
var findRow = this.worksheet._findRowUnderCursor(this.pxToPt(y), true);
return (findCol && findRow) ? _this.asc_getComments(findCol.col, findRow.row) : []; return (findCol && findRow) ? this.asc_getComments(findCol.col, findRow.row) : [];
}; };
_this.drawCommentCells = function() { CCellCommentator.prototype.drawCommentCells = function() {
if ( isViewerMode() || !_this.bShow ) if ( this.isViewerMode() || !this.bShow )
return; return;
var drawCells = []; // Associative array var drawCells = []; // Associative array
function getCellId(col, row) { return (col + "_" + row); } function getCellId(col, row) { return (col + "_" + row); }
for (var n = 0; n < _this.worksheet.drawingArea.frozenPlaces.length; n++) { for (var n = 0; n < this.worksheet.drawingArea.frozenPlaces.length; n++) {
var frozenPlace = _this.worksheet.drawingArea.frozenPlaces[n]; var frozenPlace = this.worksheet.drawingArea.frozenPlaces[n];
var fv = frozenPlace.getFirstVisible(); var fv = frozenPlace.getFirstVisible();
var lvr = _this.worksheet.getLastVisibleRow(); var lvr = this.worksheet.getLastVisibleRow();
var lvc = _this.worksheet.getLastVisibleCol(); var lvc = this.worksheet.getLastVisibleCol();
for (var i = 0; i < _this.aComments.length; i++) { for (var i = 0; i < this.aComments.length; i++) {
// Get cell metrics // Get cell metrics
var commentCell = _this.aComments[i]; var commentCell = this.aComments[i];
if (commentCell.asc_getDocumentFlag() || commentCell.asc_getHiddenFlag() || commentCell.asc_getSolved()) if (commentCell.asc_getDocumentFlag() || commentCell.asc_getHiddenFlag() || commentCell.asc_getSolved())
continue; continue;
var mergedRange = _this.worksheet.model.getMergedByCell(commentCell.nRow, commentCell.nCol); var mergedRange = this.worksheet.model.getMergedByCell(commentCell.nRow, commentCell.nCol);
var drawCol = mergedRange ? mergedRange.c2 : commentCell.nCol; var drawCol = mergedRange ? mergedRange.c2 : commentCell.nCol;
var drawRow = mergedRange ? mergedRange.r1 : commentCell.nRow; var drawRow = mergedRange ? mergedRange.r1 : commentCell.nRow;
if (drawCol < fv.col || drawRow < fv.row || drawCol > lvc || drawRow > lvr) if (drawCol < fv.col || drawRow < fv.row || drawCol > lvc || drawRow > lvr)
...@@ -729,111 +716,106 @@ function CCellCommentator(currentSheet) { ...@@ -729,111 +716,106 @@ function CCellCommentator(currentSheet) {
if (drawCells[cellId]) if (drawCells[cellId])
continue; continue;
var metrics = _this.getCellMetrics(drawCol, drawRow); var metrics = this.getCellMetrics(drawCol, drawRow);
if ( !metrics.result || (metrics.width <= 0) || (metrics.height <= 0) ) if ( !metrics.result || (metrics.width <= 0) || (metrics.height <= 0) )
continue; continue;
_this.drawingCtx.beginPath(); this.drawingCtx.beginPath();
_this.drawingCtx.setFillStyle(_this.commentIconColor); this.drawingCtx.setFillStyle(this.commentIconColor);
_this.drawingCtx.moveTo(metrics.left + metrics.width - _this.pxToPt(7), metrics.top); 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.drawingCtx.lineTo(metrics.left + metrics.width - _this.pxToPt(1), metrics.top + _this.pxToPt(6)); this.drawingCtx.lineTo(metrics.left + metrics.width - this.pxToPt(1), metrics.top + this.pxToPt(6));
_this.drawingCtx.closePath(); this.drawingCtx.closePath();
_this.drawingCtx.fill(); this.drawingCtx.fill();
drawCells[cellId] = cellId; drawCells[cellId] = cellId;
} }
} }
//if (_this.lastSelectedId) //if (this.lastSelectedId)
// _this.asc_selectComment(_this.lastSelectedId, false); // this.asc_selectComment(this.lastSelectedId, false);
}; };
_this.getTextMetrics = function(text, units) {
var _this = this; CCellCommentator.prototype.getTextMetrics = function(text, units) {
var metrics = { width: 0, height: 0 }; var metrics = { width: 0, height: 0 };
if (text && text.length && ((typeof (text) == 'string') || (typeof (text) == 'number'))) { if (text && text.length && ((typeof (text) == 'string') || (typeof (text) == 'number'))) {
var textOptions = _this.overlayCtx.measureText(text, units); var textOptions = this.overlayCtx.measureText(text, units);
metrics.width = textOptions.width; metrics.width = textOptions.width;
metrics.height = textOptions.lineHeight; metrics.height = textOptions.lineHeight;
} }
return metrics; return metrics;
}; };
_this.getCellMetrics = function(col, row) {
CCellCommentator.prototype.getCellMetrics = function(col, row) {
var metrics = { top: 0, left: 0, width: 0, height: 0, result: false }; // px var metrics = { top: 0, left: 0, width: 0, height: 0, result: false }; // px
for (var n = 0; n < _this.worksheet.drawingArea.frozenPlaces.length; n++) { for (var n = 0; n < this.worksheet.drawingArea.frozenPlaces.length; n++) {
var frozenPlace = _this.worksheet.drawingArea.frozenPlaces[n]; var frozenPlace = this.worksheet.drawingArea.frozenPlaces[n];
if ( !frozenPlace.isCellInside({ col: col, row: row }) ) if ( !frozenPlace.isCellInside({ col: col, row: row }) )
continue; continue;
var fv = frozenPlace.getFirstVisible(); var fv = frozenPlace.getFirstVisible();
var mergedRange = _this.worksheet.model.getMergedByCell(row, col); var mergedRange = this.worksheet.model.getMergedByCell(row, col);
if (mergedRange && (fv.col < mergedRange.c2) && (fv.row < mergedRange.r2)) { if (mergedRange && (fv.col < mergedRange.c2) && (fv.row < mergedRange.r2)) {
var startCol = (mergedRange.c1 > fv.col) ? mergedRange.c1 : fv.col; var startCol = (mergedRange.c1 > fv.col) ? mergedRange.c1 : fv.col;
var startRow = (mergedRange.r1 > fv.row) ? mergedRange.r1 : fv.row; var startRow = (mergedRange.r1 > fv.row) ? mergedRange.r1 : fv.row;
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); 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);
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.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 i;
for (i = startCol; i <= mergedRange.c2; i++) { for (i = startCol; i <= mergedRange.c2; i++) {
metrics.width += _this.worksheet.getColumnWidth(i, 1) metrics.width += this.worksheet.getColumnWidth(i, 1)
} }
for (i = startRow; i <= mergedRange.r2; i++) { for (i = startRow; i <= mergedRange.r2; i++) {
metrics.height += _this.worksheet.getRowHeight(i, 1) metrics.height += this.worksheet.getRowHeight(i, 1)
} }
metrics.result = true; metrics.result = true;
} }
else if ((fv.row <= row) && (fv.col <= col)) { 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); 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.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); metrics.width = this.worksheet.getColumnWidth(col, 1);
metrics.height = _this.worksheet.getRowHeight(row, 1); metrics.height = this.worksheet.getRowHeight(row, 1);
metrics.result = true; metrics.result = true;
} }
} }
return metrics; return metrics;
}; };
_this.updateCommentPosition = function() {
var _this = this;
if (_this.lastSelectedId) { CCellCommentator.prototype.updateCommentPosition = function() {
var comment = _this.asc_findComment(_this.lastSelectedId); if (this.lastSelectedId) {
var comment = this.asc_findComment(this.lastSelectedId);
if (comment) { if (comment) {
var commentList = _this.asc_getComments(comment.asc_getCol(), comment.asc_getRow()); var commentList = this.asc_getComments(comment.asc_getCol(), comment.asc_getRow());
if (commentList.length) { if (commentList.length) {
_this.drawCommentCells(); this.drawCommentCells();
var coords = _this.getCommentsCoords(commentList); var coords = this.getCommentsCoords(commentList);
var indexes = []; var indexes = [];
for (var i = 0; i < commentList.length; i++) { for (var i = 0; i < commentList.length; i++) {
indexes.push(commentList[i].asc_getId()); indexes.push(commentList[i].asc_getId());
} }
var metrics = _this.getCellMetrics(comment.asc_getCol(), comment.asc_getRow()); var metrics = this.getCellMetrics(comment.asc_getCol(), comment.asc_getRow());
_this.worksheet.model.workbook.handlers.trigger( "asc_onUpdateCommentPosition", indexes, this.worksheet.model.workbook.handlers.trigger( "asc_onUpdateCommentPosition", indexes,
(metrics.result ? coords.asc_getLeftPX() : -1), (metrics.result ? coords.asc_getLeftPX() : -1),
(metrics.result ? coords.asc_getTopPX() : -1), (metrics.result ? coords.asc_getTopPX() : -1),
(metrics.result ? coords.asc_getReverseLeftPX() : -1) ); (metrics.result ? coords.asc_getReverseLeftPX() : -1) );
} }
} }
} }
}; };
_this.updateCommentsDependencies = function(bInsert, operType, updateRange) {
CCellCommentator.prototype.updateCommentsDependencies = function(bInsert, operType, updateRange) {
var t = this;
var UpdatePair = function(comment, bChange) { var UpdatePair = function(comment, bChange) {
this.comment = comment; this.comment = comment;
this.bChange = bChange; this.bChange = bChange;
...@@ -843,28 +825,28 @@ function CCellCommentator(currentSheet) { ...@@ -843,28 +825,28 @@ function CCellCommentator(currentSheet) {
function updateCommentsList(aComments) { function updateCommentsList(aComments) {
if ( aComments.length ) { if ( aComments.length ) {
_this.bSaveHistory = false; t.bSaveHistory = false;
var changeArray = []; var changeArray = [];
var removeArray = []; var removeArray = [];
for (var i = 0; i < aComments.length; i++) { for (var i = 0; i < aComments.length; i++) {
if ( aComments[i].bChange ) { if ( aComments[i].bChange ) {
_this.asc_changeComment(aComments[i].comment.asc_getId(), aComments[i].comment, /*bChangeCoords*/true, /*bNoEvent*/true); t.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}); changeArray.push({"Id": aComments[i].comment.asc_getId(), "Comment": aComments[i].comment});
} }
else { else {
_this.asc_removeComment(aComments[i].comment.asc_getId(), /*bNoEvent*/true); t.asc_removeComment(aComments[i].comment.asc_getId(), /*bNoEvent*/true);
removeArray.push(aComments[i].comment.asc_getId()); removeArray.push(aComments[i].comment.asc_getId());
} }
} }
if ( changeArray.length ) if ( changeArray.length )
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeComments", changeArray); t.worksheet.model.workbook.handlers.trigger("asc_onChangeComments", changeArray);
if ( removeArray.length ) if ( removeArray.length )
_this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComments", removeArray); t.worksheet.model.workbook.handlers.trigger("asc_onRemoveComments", removeArray);
_this.bSaveHistory = true; t.bSaveHistory = true;
_this.drawCommentCells(); t.drawCommentCells();
} }
} }
...@@ -873,8 +855,8 @@ function CCellCommentator(currentSheet) { ...@@ -873,8 +855,8 @@ function CCellCommentator(currentSheet) {
switch (operType) { switch (operType) {
case c_oAscInsertOptions.InsertCellsAndShiftDown: { case c_oAscInsertOptions.InsertCellsAndShiftDown: {
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) );
...@@ -885,8 +867,8 @@ function CCellCommentator(currentSheet) { ...@@ -885,8 +867,8 @@ function CCellCommentator(currentSheet) {
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) );
...@@ -897,8 +879,8 @@ function CCellCommentator(currentSheet) { ...@@ -897,8 +879,8 @@ function CCellCommentator(currentSheet) {
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) );
...@@ -909,8 +891,8 @@ function CCellCommentator(currentSheet) { ...@@ -909,8 +891,8 @@ function CCellCommentator(currentSheet) {
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) );
...@@ -925,8 +907,8 @@ function CCellCommentator(currentSheet) { ...@@ -925,8 +907,8 @@ function CCellCommentator(currentSheet) {
switch (operType) { switch (operType) {
case "deleteAllComments": { case "deleteAllComments": {
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 ( (updateRange.c1 <= comment.nCol) && (updateRange.c2 >= comment.nCol) && (comment.nRow >= updateRange.r1) && (comment.nRow <= updateRange.r2) ) { 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) );
} }
...@@ -936,8 +918,8 @@ function CCellCommentator(currentSheet) { ...@@ -936,8 +918,8 @@ function CCellCommentator(currentSheet) {
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) );
...@@ -951,8 +933,8 @@ function CCellCommentator(currentSheet) { ...@@ -951,8 +933,8 @@ function CCellCommentator(currentSheet) {
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) );
...@@ -966,8 +948,8 @@ function CCellCommentator(currentSheet) { ...@@ -966,8 +948,8 @@ function CCellCommentator(currentSheet) {
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) );
...@@ -981,8 +963,8 @@ function CCellCommentator(currentSheet) { ...@@ -981,8 +963,8 @@ function CCellCommentator(currentSheet) {
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) );
...@@ -996,10 +978,11 @@ function CCellCommentator(currentSheet) { ...@@ -996,10 +978,11 @@ function CCellCommentator(currentSheet) {
break; break;
} }
} }
}; };
_this.showHideComments = function(bHide, bColumn, start, stop) { CCellCommentator.prototype.showHideComments = function(bHide, bColumn, start, stop) {
var t = this;
var aChangedComments = []; var aChangedComments = [];
function updateCommentsList(aComments) { function updateCommentsList(aComments) {
...@@ -1007,16 +990,16 @@ function CCellCommentator(currentSheet) { ...@@ -1007,16 +990,16 @@ function CCellCommentator(currentSheet) {
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]);
} }
History.EndTransaction(); History.EndTransaction();
_this.drawCommentCells(); t.drawCommentCells();
} }
} }
for (var i = 0; i < _this.aComments.length; i++) { for (var i = 0; i < this.aComments.length; i++) {
var comment = new asc_CCommentData(_this.aComments[i]); var comment = new asc_CCommentData(this.aComments[i]);
if ( bColumn ) { if ( bColumn ) {
if ( (comment.nCol >= start) && (comment.nCol <= stop) ) { if ( (comment.nCol >= start) && (comment.nCol <= stop) ) {
...@@ -1032,9 +1015,10 @@ function CCellCommentator(currentSheet) { ...@@ -1032,9 +1015,10 @@ function CCellCommentator(currentSheet) {
} }
} }
updateCommentsList(aChangedComments); updateCommentsList(aChangedComments);
}; };
_this.sortComments = function(activeRange, changes) { CCellCommentator.prototype.sortComments = function(activeRange, changes) {
var t = this;
if (changes && activeRange) { if (changes && activeRange) {
...@@ -1043,18 +1027,18 @@ function CCellCommentator(currentSheet) { ...@@ -1043,18 +1027,18 @@ function CCellCommentator(currentSheet) {
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], true); this.asc_changeComment(aComments[i].asc_getId(), aComments[i], true);
} }
History.EndTransaction(); History.EndTransaction();
_this.drawCommentCells(); t.drawCommentCells();
} }
}; };
var aChangedComments = []; var aChangedComments = [];
for (var i = 0; i < changes.places.length; i++) { for (var i = 0; i < changes.places.length; i++) {
var list = _this.asc_getComments(activeRange.c1, changes.places[i].from); var list = this.asc_getComments(activeRange.c1, changes.places[i].from);
for (var j = 0; j < list.length; j++) { for (var j = 0; j < list.length; j++) {
var comment = new asc_CCommentData(list[j]); var comment = new asc_CCommentData(list[j]);
comment.nRow = changes.places[i].to; comment.nRow = changes.places[i].to;
...@@ -1063,56 +1047,56 @@ function CCellCommentator(currentSheet) { ...@@ -1063,56 +1047,56 @@ function CCellCommentator(currentSheet) {
} }
updateCommentsList(aChangedComments); updateCommentsList(aChangedComments);
} }
}; };
_this.resetLastSelectedId = function() { CCellCommentator.prototype.resetLastSelectedId = function() {
_this.cleanLastSelection(); this.cleanLastSelection();
_this.lastSelectedId = null; this.lastSelectedId = null;
}; };
_this.cleanLastSelection = function() { CCellCommentator.prototype.cleanLastSelection = function() {
if ( _this.lastSelectedId ) { if ( this.lastSelectedId ) {
var lastComment = _this.asc_findComment(_this.lastSelectedId); var lastComment = this.asc_findComment(this.lastSelectedId);
if ( lastComment ) { if ( lastComment ) {
var lastMetrics = _this.getCellMetrics(lastComment.nCol, lastComment.nRow); var lastMetrics = this.getCellMetrics(lastComment.nCol, lastComment.nRow);
if ( lastMetrics.result ) { if ( lastMetrics.result ) {
var extraOffset = _this.pxToPt(1); var extraOffset = this.pxToPt(1);
_this.overlayCtx.clearRect(lastMetrics.left, lastMetrics.top, lastMetrics.width - extraOffset, lastMetrics.height - extraOffset); 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) if (commentList.length)
_this.aCommentCoords.push(_this.getCommentsCoords(commentList)); 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) {
...@@ -1122,25 +1106,25 @@ function CCellCommentator(currentSheet) { ...@@ -1122,25 +1106,25 @@ function CCellCommentator(currentSheet) {
* 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;
...@@ -1148,15 +1132,15 @@ function CCellCommentator(currentSheet) { ...@@ -1148,15 +1132,15 @@ function CCellCommentator(currentSheet) {
// 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); txtMetrics = t.getTextMetrics(commentSpl[i], 1);
coords.dHeightPX += _this.ptToPx(txtMetrics.height); coords.dHeightPX += t.ptToPx(txtMetrics.height);
var lineWidth = _this.ptToPx(txtMetrics.width); var lineWidth = t.ptToPx(txtMetrics.width);
if (coords.dWidthPX < lineWidth) if (coords.dWidthPX < lineWidth)
coords.dWidthPX = lineWidth; coords.dWidthPX = lineWidth;
} }
...@@ -1166,69 +1150,69 @@ function CCellCommentator(currentSheet) { ...@@ -1166,69 +1150,69 @@ function CCellCommentator(currentSheet) {
} }
// Min values // Min values
if (coords.dWidthPX < _this.minAreaWidth) if (coords.dWidthPX < t.minAreaWidth)
coords.dWidthPX = _this.minAreaWidth; coords.dWidthPX = t.minAreaWidth;
if (coords.dHeightPX < _this.minAreaHeight) if (coords.dHeightPX < t.minAreaHeight)
coords.dHeightPX = _this.minAreaHeight; coords.dHeightPX = t.minAreaHeight;
// Calc other coords // Calc other coords
coords.dWidthMM = _this.pxToMm(coords.dWidthPX); coords.dWidthMM = t.pxToMm(coords.dWidthPX);
coords.dHeightMM = _this.pxToMm(coords.dHeightPX); coords.dHeightMM = t.pxToMm(coords.dHeightPX);
var headerRowOffPx = _this.worksheet.getCellTop(0, 0); var headerRowOffPx = t.worksheet.getCellTop(0, 0);
var headerColOffPx = _this.worksheet.getCellLeft(0, 0); var headerColOffPx = t.worksheet.getCellLeft(0, 0);
coords.nCol = comment.nCol; coords.nCol = comment.nCol;
coords.nRow = comment.nRow; coords.nRow = comment.nRow;
var mergedRange = _this.worksheet.model.getMergedByCell(comment.nRow, comment.nCol); var mergedRange = t.worksheet.model.getMergedByCell(comment.nRow, comment.nCol);
coords.nLeft = (mergedRange ? mergedRange.c2 : comment.nCol) + 1; coords.nLeft = (mergedRange ? mergedRange.c2 : comment.nCol) + 1;
if ( !_this.worksheet.cols[coords.nLeft] ) { if ( !t.worksheet.cols[coords.nLeft] ) {
_this.worksheet.expandColsOnScroll(true); t.worksheet.expandColsOnScroll(true);
_this.worksheet.handlers.trigger("reinitializeScrollX"); t.worksheet.handlers.trigger("reinitializeScrollX");
} }
coords.nTop = mergedRange ? mergedRange.r1 : comment.nRow; coords.nTop = mergedRange ? mergedRange.r1 : comment.nRow;
coords.nLeftOffset = 0; coords.nLeftOffset = 0;
coords.nTopOffset = 0; coords.nTopOffset = 0;
var fvr = _this.worksheet.getFirstVisibleRow(true); var fvr = t.worksheet.getFirstVisibleRow(true);
var fvc = _this.worksheet.getFirstVisibleCol(true); var fvc = t.worksheet.getFirstVisibleCol(true);
var frozenOffset = _this.getFrozenOffset(); var frozenOffset = t.getFrozenOffset();
if ( _this.worksheet.topLeftFrozenCell ) { if ( t.worksheet.topLeftFrozenCell ) {
if ( comment.nCol >= _this.worksheet.getFirstVisibleCol(false) ) if ( comment.nCol >= t.worksheet.getFirstVisibleCol(false) )
frozenOffset.offsetX = 0; frozenOffset.offsetX = 0;
if ( comment.nRow >= _this.worksheet.getFirstVisibleRow(false) ) if ( comment.nRow >= t.worksheet.getFirstVisibleRow(false) )
frozenOffset.offsetY = 0; frozenOffset.offsetY = 0;
} }
// Tooltip coords // Tooltip coords
coords.dReverseLeftPX = _this.worksheet.getCellLeft(comment.nCol, 0) - _this.worksheet.getCellLeft(fvc, 0) + headerColOffPx + _this.ptToPx(frozenOffset.offsetX); coords.dReverseLeftPX = t.worksheet.getCellLeft(comment.nCol, 0) - t.worksheet.getCellLeft(fvc, 0) + headerColOffPx + t.ptToPx(frozenOffset.offsetX);
coords.dLeftPX = _this.worksheet.getCellLeft(coords.nLeft, 0) - _this.worksheet.getCellLeft(fvc, 0) + headerColOffPx + _this.ptToPx(frozenOffset.offsetX); coords.dLeftPX = t.worksheet.getCellLeft(coords.nLeft, 0) - t.worksheet.getCellLeft(fvc, 0) + headerColOffPx + t.ptToPx(frozenOffset.offsetX);
coords.dTopPX = _this.worksheet.getCellTop(coords.nTop, 0) - _this.worksheet.getCellTop(fvr, 0) + headerRowOffPx + _this.ptToPx(frozenOffset.offsetY); coords.dTopPX = t.worksheet.getCellTop(coords.nTop, 0) - t.worksheet.getCellTop(fvr, 0) + headerRowOffPx + t.ptToPx(frozenOffset.offsetY);
// Correction for merged cell // Correction for merged cell
var fvrPx = _this.worksheet.getCellTop(0, 0); var fvrPx = t.worksheet.getCellTop(0, 0);
if (coords.dTopPX < fvrPx) if (coords.dTopPX < fvrPx)
coords.dTopPX = fvrPx; coords.dTopPX = fvrPx;
coords.dLeftMM = _this.worksheet.getCellLeft(coords.nLeft, 3) - _this.worksheet.getCellLeft(fvc, 3); coords.dLeftMM = t.worksheet.getCellLeft(coords.nLeft, 3) - t.worksheet.getCellLeft(fvc, 3);
coords.dTopMM = _this.worksheet.getCellTop(coords.nTop, 3) - _this.worksheet.getCellTop(fvr, 3); coords.dTopMM = t.worksheet.getCellTop(coords.nTop, 3) - t.worksheet.getCellTop(fvr, 3);
var findCol = _this.worksheet._findColUnderCursor(_this.worksheet.getCellLeft(coords.nLeft, 1) + _this.pxToPt(coords.dWidthPX + headerColOffPx) - _this.worksheet.getCellLeft(fvc, 1), true); var findCol = t.worksheet._findColUnderCursor(t.worksheet.getCellLeft(coords.nLeft, 1) + t.pxToPt(coords.dWidthPX + headerColOffPx) - t.worksheet.getCellLeft(fvc, 1), true);
var findRow = _this.worksheet._findRowUnderCursor(_this.worksheet.getCellTop(coords.nTop, 1) + _this.pxToPt(coords.dHeightPX + headerRowOffPx) - _this.worksheet.getCellTop(fvr, 1), true); var findRow = t.worksheet._findRowUnderCursor(t.worksheet.getCellTop(coords.nTop, 1) + t.pxToPt(coords.dHeightPX + headerRowOffPx) - t.worksheet.getCellTop(fvr, 1), true);
coords.nRight = findCol ? findCol.col : 0; coords.nRight = findCol ? findCol.col : 0;
coords.nBottom = findRow ? findRow.row : 0; coords.nBottom = findRow ? findRow.row : 0;
coords.nRightOffset = _this.worksheet.getCellLeft(coords.nLeft, 0) + coords.nLeftOffset + coords.dWidthPX + headerColOffPx - _this.worksheet.getCellLeft(coords.nRight, 0); coords.nRightOffset = t.worksheet.getCellLeft(coords.nLeft, 0) + coords.nLeftOffset + coords.dWidthPX + headerColOffPx - t.worksheet.getCellLeft(coords.nRight, 0);
coords.nBottomOffset = _this.worksheet.getCellTop(coords.nTop, 0) + coords.nTopOffset + coords.dHeightPX + headerRowOffPx - _this.worksheet.getCellTop(coords.nBottom, 0); coords.nBottomOffset = t.worksheet.getCellTop(coords.nTop, 0) + coords.nTopOffset + coords.dHeightPX + headerRowOffPx - t.worksheet.getCellTop(coords.nBottom, 0);
// Return original font // Return original font
_this.overlayCtx.setFont(originalFont); t.overlayCtx.setFont(originalFont);
} }
for (var i = 0; i < comments.length; i++) { for (var i = 0; i < comments.length; i++) {
...@@ -1236,27 +1220,27 @@ function CCellCommentator(currentSheet) { ...@@ -1236,27 +1220,27 @@ function CCellCommentator(currentSheet) {
} }
if (comments.length) { if (comments.length) {
coords.dWidthPX += _this.commentPadding * 2; coords.dWidthPX += this.commentPadding * 2;
coords.dWidthMM = _this.pxToMm(coords.dWidthPX); coords.dWidthMM = this.pxToMm(coords.dWidthPX);
coords.dHeightPX += _this.commentPadding * 2; coords.dHeightPX += this.commentPadding * 2;
coords.dHeightMM = _this.pxToMm(coords.dHeightPX); coords.dHeightMM = this.pxToMm(coords.dHeightPX);
} }
return coords; return coords;
}; };
_this.commentCoordsExist = function(col, row) { CCellCommentator.prototype.commentCoordsExist = function(col, row) {
var result = false; var result = false;
for (var i = 0; i < _this.aCommentCoords.length; i++) { for (var i = 0; i < this.aCommentCoords.length; i++) {
if ((col == _this.aCommentCoords[i].nCol) && (row == _this.aCommentCoords[i].nRow)) if ((col == this.aCommentCoords[i].nCol) && (row == this.aCommentCoords[i].nRow))
return true; return true;
} }
return result; return result;
}; };
_this.prepareCommentsToSave = function() { CCellCommentator.prototype.prepareCommentsToSave = function() {
/* Calculate the coords of comments for: /* Calculate the coords of comments for:
* first visible col = 0 * first visible col = 0
...@@ -1264,98 +1248,91 @@ function CCellCommentator(currentSheet) { ...@@ -1264,98 +1248,91 @@ function CCellCommentator(currentSheet) {
* + document comments -> A1 * + document comments -> A1
*/ */
_this.calcCommentsCoords(true); this.calcCommentsCoords(true);
}; };
_this.cleanSelectedComment = function() { CCellCommentator.prototype.cleanSelectedComment = function() {
if ( _this.lastSelectedId ) { if ( this.lastSelectedId ) {
var comment = _this.asc_findComment(_this.lastSelectedId); var comment = this.asc_findComment(this.lastSelectedId);
if ( comment && !comment.asc_getDocumentFlag() && !comment.asc_getSolved() ) { if ( comment && !comment.asc_getDocumentFlag() && !comment.asc_getSolved() ) {
var metrics = _this.getCellMetrics(comment.asc_getCol(), comment.asc_getRow()); var metrics = this.getCellMetrics(comment.asc_getCol(), comment.asc_getRow());
if (metrics.result) if (metrics.result)
_this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width, metrics.height); this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width, metrics.height);
} }
} }
}; };
_this.getFrozenOffset = function() { CCellCommentator.prototype.getFrozenOffset = function() {
var offsetX = 0, offsetY = 0, cFrozen = 0, rFrozen = 0, diffWidth = 0, diffHeight = 0; var offsetX = 0, offsetY = 0, cFrozen = 0, rFrozen = 0, diffWidth = 0, diffHeight = 0;
if ( _this.worksheet.topLeftFrozenCell ) { if ( this.worksheet.topLeftFrozenCell ) {
cFrozen = _this.worksheet.topLeftFrozenCell.getCol0(); cFrozen = this.worksheet.topLeftFrozenCell.getCol0();
rFrozen = _this.worksheet.topLeftFrozenCell.getRow0(); rFrozen = this.worksheet.topLeftFrozenCell.getRow0();
diffWidth = _this.worksheet.cols[cFrozen].left - _this.worksheet.cols[0].left; diffWidth = this.worksheet.cols[cFrozen].left - this.worksheet.cols[0].left;
diffHeight = _this.worksheet.rows[rFrozen].top - _this.worksheet.rows[0].top; diffHeight = this.worksheet.rows[rFrozen].top - this.worksheet.rows[0].top;
offsetX = _this.worksheet.cols[_this.worksheet.visibleRange.c1].left - _this.worksheet.cellsLeft - diffWidth; 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; offsetY = this.worksheet.rows[this.worksheet.visibleRange.r1].top - this.worksheet.cellsTop - diffHeight;
} }
return { offsetX: offsetX, offsetY: offsetY }; return { offsetX: offsetX, offsetY: offsetY };
}; };
//-----------------------------------------------------------------------------------
// Misc methods
//-----------------------------------------------------------------------------------
_this.pxToPt = function(val) {
return val * _this.ascCvtRatio(0, 1);
};
_this.ptToPx = function(val) { //-----------------------------------------------------------------------------------
return val * _this.ascCvtRatio(1, 0); // Misc methods
}; //-----------------------------------------------------------------------------------
_this.mmToPx = function(val) { CCellCommentator.prototype.pxToPt = function(val) {
return val * _this.ascCvtRatio(3, 0); return val * this.ascCvtRatio(0, 1);
}; };
_this.pxToMm = function(val) { CCellCommentator.prototype.ptToPx = function(val) {
return val * _this.ascCvtRatio(0, 3); return val * this.ascCvtRatio(1, 0);
}; };
_this.ascCvtRatio = function(fromUnits, toUnits) { CCellCommentator.prototype.mmToPx = function(val) {
return Asc.getCvtRatio(fromUnits, toUnits, _this.overlayCtx.getPPIX()); return val * this.ascCvtRatio(3, 0);
} };
}
// Prototype CCellCommentator.prototype.pxToMm = function(val) {
CCellCommentator.prototype = { return val * this.ascCvtRatio(0, 3);
};
// Show/Hide CCellCommentator.prototype.ascCvtRatio = function(fromUnits, toUnits) {
return Asc.getCvtRatio(fromUnits, toUnits, this.overlayCtx.getPPIX());
};
asc_showComments: function() { // Show/Hide
var _this = this; CCellCommentator.prototype.asc_showComments = function() {
if ( !_this.bShow ) { if ( !this.bShow ) {
_this.bShow = true; this.bShow = true;
_this.drawCommentCells(); this.drawCommentCells();
} }
}, };
asc_hideComments: function() { CCellCommentator.prototype.asc_hideComments = function() {
var _this = this; this.bShow = false;
_this.bShow = false; this.drawCommentCells();
_this.drawCommentCells(); this.worksheet.model.workbook.handlers.trigger("asc_onHideComment");
_this.worksheet.model.workbook.handlers.trigger("asc_onHideComment"); };
},
// Main // Main
asc_showComment: function(id, bNew) { CCellCommentator.prototype.asc_showComment = function(id, bNew) {
var _this = this; var t = this;
var comment = _this.asc_findComment(id); var comment = this.asc_findComment(id);
if (comment) { if (comment) {
var callbackFunc = function(result) { var callbackFunc = function(result) {
if ( !result ) if ( !result )
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId()); t.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
else else
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId()); t.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
var commentList = _this.asc_getComments(comment.asc_getCol(), comment.asc_getRow()); var commentList = t.asc_getComments(comment.asc_getCol(), comment.asc_getRow());
var coords = _this.getCommentsCoords(commentList); var coords = t.getCommentsCoords(commentList);
var indexes = []; var indexes = [];
for (var i = 0; i < commentList.length; i++) { for (var i = 0; i < commentList.length; i++) {
...@@ -1364,72 +1341,67 @@ CCellCommentator.prototype = { ...@@ -1364,72 +1341,67 @@ CCellCommentator.prototype = {
// Second click - hide comment // Second click - hide comment
if (indexes.length) { if (indexes.length) {
if ( _this.lastSelectedId != id ) if ( t.lastSelectedId != id )
_this.worksheet.model.workbook.handlers.trigger("asc_onHideComment"); t.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); t.worksheet.model.workbook.handlers.trigger("asc_onShowComment", indexes, coords.asc_getLeftPX(), coords.asc_getTopPX(), coords.asc_getReverseLeftPX(), bNew);
_this.drawCommentCells(); t.drawCommentCells();
} }
_this.lastSelectedId = id; t.lastSelectedId = id;
}; };
_this.isLockedComment(comment, false, callbackFunc); t.isLockedComment(comment, false, callbackFunc);
} }
else else
_this.lastSelectedId = null; t.lastSelectedId = null;
}, };
asc_selectComment: function(id, bMove) {
var _this = this; CCellCommentator.prototype.asc_selectComment = function(id, bMove) {
var comment = _this.asc_findComment(id); var comment = this.asc_findComment(id);
// Чистим предыдущий селект // Чистим предыдущий селект
_this.cleanLastSelection(); this.cleanLastSelection();
_this.lastSelectedId = null; this.lastSelectedId = null;
if (comment && !comment.asc_getDocumentFlag() && !comment.asc_getSolved()) { if (comment && !comment.asc_getDocumentFlag() && !comment.asc_getSolved()) {
_this.lastSelectedId = id; this.lastSelectedId = id;
var col = comment.asc_getCol(); var col = comment.asc_getCol();
var row = comment.asc_getRow(); var row = comment.asc_getRow();
var fvc = _this.worksheet.getFirstVisibleCol(true); var fvc = this.worksheet.getFirstVisibleCol(true);
var fvr = _this.worksheet.getFirstVisibleRow(true); var fvr = this.worksheet.getFirstVisibleRow(true);
var lvc = _this.worksheet.getLastVisibleCol(); var lvc = this.worksheet.getLastVisibleCol();
var lvr = _this.worksheet.getLastVisibleRow(); var lvr = this.worksheet.getLastVisibleRow();
var offset; var offset;
if ( bMove ) { if ( bMove ) {
if ( (row < fvr) || (row > lvr) ) { if ( (row < fvr) || (row > lvr) ) {
offset = row - fvr - Math.round(( lvr - fvr ) / 2); offset = row - fvr - Math.round(( lvr - fvr ) / 2);
_this.worksheet.scrollVertical(offset); this.worksheet.scrollVertical(offset);
_this.worksheet.handlers.trigger("reinitializeScrollY"); this.worksheet.handlers.trigger("reinitializeScrollY");
} }
if ( (col < fvc) || (col > lvc) ) { if ( (col < fvc) || (col > lvc) ) {
offset = col - fvc - Math.round(( lvc - fvc ) / 2); offset = col - fvc - Math.round(( lvc - fvc ) / 2);
_this.worksheet.scrollHorizontal(offset); this.worksheet.scrollHorizontal(offset);
_this.worksheet.handlers.trigger("reinitializeScrollX"); this.worksheet.handlers.trigger("reinitializeScrollX");
} }
} }
var metrics = _this.getCellMetrics(col, row); var metrics = this.getCellMetrics(col, row);
if (metrics.result) { if (metrics.result) {
var extraOffset = _this.pxToPt(1); var extraOffset = this.pxToPt(1);
_this.overlayCtx.ctx.globalAlpha = 0.2; this.overlayCtx.ctx.globalAlpha = 0.2;
_this.overlayCtx.beginPath(); this.overlayCtx.beginPath();
_this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset); this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset);
_this.overlayCtx.setFillStyle(_this.commentFillColor); this.overlayCtx.setFillStyle(this.commentFillColor);
_this.overlayCtx.fillRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset); this.overlayCtx.fillRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset);
_this.overlayCtx.ctx.globalAlpha = 1; this.overlayCtx.ctx.globalAlpha = 1;
} }
} }
}, };
asc_findComment: function(id) {
var _this = this;
CCellCommentator.prototype.asc_findComment = function(id) {
function checkCommentId(id, commentObject) { function checkCommentId(id, commentObject) {
if (commentObject.asc_getId() == id) if (commentObject.asc_getId() == id)
...@@ -1443,30 +1415,30 @@ CCellCommentator.prototype = { ...@@ -1443,30 +1415,30 @@ CCellCommentator.prototype = {
return null; return null;
} }
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];
var obj = checkCommentId(id, commentCell); var obj = checkCommentId(id, commentCell);
if (obj) if (obj)
return obj; return obj;
} }
return null; return null;
}, };
asc_addComment: function(comment, bIsNotUpdate) { CCellCommentator.prototype.asc_addComment = function(comment, bIsNotUpdate) {
var _this = this; var t = this;
var oComment = comment; var oComment = comment;
var bChange = false; var bChange = false;
oComment.wsId = _this.worksheet.model.getId(); oComment.wsId = this.worksheet.model.getId();
oComment.setId(); oComment.setId();
if (!oComment.bDocument) { if (!oComment.bDocument) {
if (!bIsNotUpdate) { if (!bIsNotUpdate) {
oComment.asc_putCol(_this.worksheet.getSelectedColumnIndex()); oComment.asc_putCol(this.worksheet.getSelectedColumnIndex());
oComment.asc_putRow(_this.worksheet.getSelectedRowIndex()); oComment.asc_putRow(this.worksheet.getSelectedRowIndex());
} }
var existComments = _this.asc_getComments(oComment.nCol, oComment.nRow); var existComments = this.asc_getComments(oComment.nCol, oComment.nRow);
if ( existComments.length ) { if ( existComments.length ) {
oComment = existComments[0]; oComment = existComments[0];
bChange = true; bChange = true;
...@@ -1474,50 +1446,38 @@ CCellCommentator.prototype = { ...@@ -1474,50 +1446,38 @@ CCellCommentator.prototype = {
else { else {
if ((oComment.nCol != null) && (oComment.nRow != null)) { if ((oComment.nCol != null) && (oComment.nRow != null)) {
var cellAddress = new CellAddress(oComment.nRow, oComment.nCol, 0); var cellAddress = new CellAddress(oComment.nRow, oComment.nCol, 0);
oComment.sQuoteText = cellAddress.getID() + " : " + _this.worksheet.model.getCell(cellAddress).getValueWithFormat(); oComment.sQuoteText = cellAddress.getID() + " : " + this.worksheet.model.getCell(cellAddress).getValueWithFormat();
} }
} }
} }
function callbackFunc(result) { function callbackFunc(result) {
if ( !result ) { if ( !result ) {
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", oComment.asc_getId(), oComment.asc_getUserId()); t.worksheet.model.workbook.handlers.trigger("asc_onLockComment", oComment.asc_getId(), oComment.asc_getUserId());
} }
else { else {
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", oComment.asc_getId()); t._addComment(oComment, bChange, bIsNotUpdate);
// 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)
_this.drawCommentCells();
}
_this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", oComment.asc_getId(), oComment);
} }
} }
if (bIsNotUpdate) if (bIsNotUpdate)
callbackFunc(true); callbackFunc(true);
else else
_this.isLockedComment(oComment, true, callbackFunc); this.isLockedComment(oComment, true, callbackFunc);
}, };
asc_changeComment: function(id, oComment, bChangeCoords, bNoEvent) { CCellCommentator.prototype.asc_changeComment = function(id, oComment, bChangeCoords, bNoEvent) {
var _this = this; var t = this;
var comment = _this.asc_findComment(id); var comment = this.asc_findComment(id);
if (null === comment) if (null === comment)
return; return;
function callbackFunc(result) { function callbackFunc(result) {
if ( !result ) { if ( !result ) {
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId()); t.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId());
} else { } else {
_this.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId()); t.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
var commentBefore = new asc_CCommentData(comment); var commentBefore = new asc_CCommentData(comment);
if (comment) { if (comment) {
...@@ -1536,7 +1496,7 @@ CCellCommentator.prototype = { ...@@ -1536,7 +1496,7 @@ CCellCommentator.prototype = {
if ( !comment.bDocument && (comment.nCol != null) && (comment.nRow != null) ) { if ( !comment.bDocument && (comment.nCol != null) && (comment.nRow != null) ) {
var cellAddress = new CellAddress(comment.nRow, comment.nCol, 0); var cellAddress = new CellAddress(comment.nRow, comment.nCol, 0);
comment.sQuoteText = cellAddress.getID() + " : " + _this.worksheet.model.getCell(cellAddress).getValueWithFormat(); comment.sQuoteText = cellAddress.getID() + " : " + t.worksheet.model.getCell(cellAddress).getValueWithFormat();
} }
var count = oComment.asc_getRepliesCount(); var count = oComment.asc_getRepliesCount();
...@@ -1544,10 +1504,10 @@ CCellCommentator.prototype = { ...@@ -1544,10 +1504,10 @@ CCellCommentator.prototype = {
comment.asc_addReply(oComment.asc_getReply(i)); comment.asc_addReply(oComment.asc_getReply(i));
} }
if ( !bNoEvent ) if ( !bNoEvent )
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", comment.asc_getId(), comment); t.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", comment.asc_getId(), comment);
} }
if ( _this.bSaveHistory ) { if ( t.bSaveHistory ) {
var commentAfter = new asc_CCommentData(comment); var commentAfter = new asc_CCommentData(comment);
var compositeComment = new CompositeCommentData(); var compositeComment = new CompositeCommentData();
...@@ -1555,93 +1515,59 @@ CCellCommentator.prototype = { ...@@ -1555,93 +1515,59 @@ CCellCommentator.prototype = {
compositeComment.commentAfter = commentAfter; compositeComment.commentAfter = commentAfter;
History.Create_NewPoint(); History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Change, _this.worksheet.model.getId(), null, compositeComment); History.Add(g_oUndoRedoComment, historyitem_Comment_Change, t.worksheet.model.getId(), null, compositeComment);
} }
_this.drawCommentCells(); t.drawCommentCells();
} }
} }
_this.isLockedComment(comment, true, callbackFunc); this.isLockedComment(comment, true, callbackFunc);
}, };
asc_removeComment: function(id, bNoEvent) { CCellCommentator.prototype.asc_removeComment = function(id, bNoEvent) {
var _this = this; var t = this;
var comment = _this.asc_findComment(id); var comment = this.asc_findComment(id);
if (null === comment) if (null === comment)
return; return;
function callbackFunc(result) { function callbackFunc(result) {
if ( !result ) { if ( !result ) {
_this.worksheet.model.workbook.handlers.trigger("asc_onLockComment", comment.asc_getId(), comment.asc_getUserId()); t.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 { } else {
for (i = 0; i < _this.aComments.length; i++) { t.worksheet.model.workbook.handlers.trigger("asc_onUnLockComment", comment.asc_getId());
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); t._removeComment(comment, bNoEvent, true);
break;
}
}
_this.worksheet.draw();
}
_this.drawCommentCells();
if ( !bNoEvent )
_this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", id);
}
}
} }
_this.isLockedComment(comment, true, callbackFunc); this.isLockedComment(comment, true, callbackFunc);
}, };
// Extra functions // Extra functions
asc_getComments: function(col, row) { CCellCommentator.prototype.asc_getComments = function(col, row) {
// Array of root items // Array of root items
var comments = []; var comments = [];
var _this = this;
var _col = col, _row = row, mergedRange = null; var _col = col, _row = row, mergedRange = null;
var length = _this.aComments.length; var length = this.aComments.length;
if (!this.bShow) if (!this.bShow)
return comments; return comments;
if (0 < length) { if (0 < length) {
if (null == _col || null == _row) { if (null == _col || null == _row) {
var selectedCell = _this.worksheet.getSelectedRange(); var selectedCell = this.worksheet.getSelectedRange();
var oFirst = selectedCell.getFirst(); var oFirst = selectedCell.getFirst();
_col = oFirst.col - 1; _col = oFirst.col - 1;
_row = oFirst.row - 1; _row = oFirst.row - 1;
} else } else
mergedRange = _this.worksheet.model.getMergedByCell(row, col); mergedRange = this.worksheet.model.getMergedByCell(row, col);
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
var commentCell = _this.aComments[i]; var commentCell = this.aComments[i];
if ( !commentCell.asc_getDocumentFlag() /*&& !commentCell.asc_getSolved()*/ && !commentCell.asc_getHiddenFlag() && (commentCell.nLevel == 0) ) { if ( !commentCell.asc_getDocumentFlag() /*&& !commentCell.asc_getSolved()*/ && !commentCell.asc_getHiddenFlag() && (commentCell.nLevel == 0) ) {
if ( !mergedRange ) { if ( !mergedRange ) {
...@@ -1656,9 +1582,9 @@ CCellCommentator.prototype = { ...@@ -1656,9 +1582,9 @@ CCellCommentator.prototype = {
} }
} }
return comments; return comments;
}, };
asc_getDocumentComments: function() { CCellCommentator.prototype.asc_getDocumentComments = function() {
// Array of root items // Array of root items
var comments = []; var comments = [];
...@@ -1669,18 +1595,120 @@ CCellCommentator.prototype = { ...@@ -1669,18 +1595,120 @@ CCellCommentator.prototype = {
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());
// Add new comment
if (!bChange) {
History.Create_NewPoint();
History.Add(g_oUndoRedoComment, historyitem_Comment_Add, this.worksheet.model.getId(), null, new asc_CCommentData(oComment));
Undo: function(type, data) { this.aComments.push(oComment);
var _this = this, i, parentComment; if (!bIsNotUpdate)
this.drawCommentCells();
}
this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", oComment.asc_getId(), oComment);
};
CCellCommentator.prototype._removeComment = function (comment, bNoEvent, isDraw) {
if (!comment)
return;
var i, id = comment.asc_getId();
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;
}
}
if (isDraw)
this.worksheet.draw();
}
if (isDraw)
this.drawCommentCells();
if (!bNoEvent)
this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", id);
};
CCellCommentator.prototype.isMissComments = function (range) {
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;
}
}
return false;
};
CCellCommentator.prototype.mergeComments = function (range) {
var i, length, deleteComments = [], oComment, r1 = range.r1, c1 = range.c1, mergeComment = null;
for (i = 0, length = this.aComments.length; i < length; ++i) {
oComment = this.aComments[i];
if (range.contains(oComment.nCol, oComment.nRow)) {
if (null === mergeComment)
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) { switch (type) {
case historyitem_Comment_Add: case historyitem_Comment_Add:
if (data.oParent) { if (data.oParent) {
parentComment = _this.asc_findComment(data.oParent.asc_getId()); parentComment = this.asc_findComment(data.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) { for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) { if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1); parentComment.aReplies.splice(i, 1);
...@@ -1688,10 +1716,10 @@ CCellCommentator.prototype = { ...@@ -1688,10 +1716,10 @@ CCellCommentator.prototype = {
} }
} }
} else { } else {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
if (_this.aComments[i].asc_getId() == data.asc_getId()) { if (this.aComments[i].asc_getId() == data.asc_getId()) {
_this.aComments.splice(i, 1); this.aComments.splice(i, 1);
_this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", data.asc_getId()); this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", data.asc_getId());
break; break;
} }
} }
...@@ -1700,17 +1728,17 @@ CCellCommentator.prototype = { ...@@ -1700,17 +1728,17 @@ CCellCommentator.prototype = {
case historyitem_Comment_Remove: case historyitem_Comment_Remove:
if (data.oParent) { if (data.oParent) {
parentComment = _this.asc_findComment(data.oParent.asc_getId()); parentComment = this.asc_findComment(data.oParent.asc_getId());
parentComment.aReplies.push(data); parentComment.aReplies.push(data);
} else { } else {
_this.aComments.push(data); this.aComments.push(data);
_this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", data.asc_getId(), data); this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", data.asc_getId(), data);
} }
break; break;
case historyitem_Comment_Change: case historyitem_Comment_Change:
if (data.commentAfter.oParent) { if (data.commentAfter.oParent) {
parentComment = _this.asc_findComment(data.commentAfter.oParent.asc_getId()); parentComment = this.asc_findComment(data.commentAfter.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) { for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) { if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1); parentComment.aReplies.splice(i, 1);
...@@ -1719,37 +1747,37 @@ CCellCommentator.prototype = { ...@@ -1719,37 +1747,37 @@ CCellCommentator.prototype = {
} }
} }
} else { } else {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
if (_this.aComments[i].asc_getId() == data.commentAfter.asc_getId()) { if (this.aComments[i].asc_getId() == data.commentAfter.asc_getId()) {
_this.aComments.splice(i, 1); this.aComments.splice(i, 1);
_this.aComments.push(data.commentBefore); this.aComments.push(data.commentBefore);
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", data.commentBefore.asc_getId(), data.commentBefore); this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", data.commentBefore.asc_getId(), data.commentBefore);
break; break;
} }
} }
} }
break; break;
} }
}, };
Redo: function(type, data) { CCellCommentator.prototype.Redo = function(type, data) {
var _this = this, parentComment, i; var parentComment, i;
switch (type) { switch (type) {
case historyitem_Comment_Add: case historyitem_Comment_Add:
if (data.oParent) { if (data.oParent) {
parentComment = _this.asc_findComment(data.oParent.asc_getId()); parentComment = this.asc_findComment(data.oParent.asc_getId());
parentComment.aReplies.push(data); parentComment.aReplies.push(data);
} else { } else {
_this.aComments.push(data); this.aComments.push(data);
_this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", data.asc_getId(), data); this.worksheet.model.workbook.handlers.trigger("asc_onAddComment", data.asc_getId(), data);
} }
break; break;
case historyitem_Comment_Remove: case historyitem_Comment_Remove:
if (data.oParent) { if (data.oParent) {
parentComment = _this.asc_findComment(data.oParent.asc_getId()); parentComment = this.asc_findComment(data.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) { for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) { if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1); parentComment.aReplies.splice(i, 1);
...@@ -1757,10 +1785,10 @@ CCellCommentator.prototype = { ...@@ -1757,10 +1785,10 @@ CCellCommentator.prototype = {
} }
} }
} else { } else {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
if (_this.aComments[i].asc_getId() == data.asc_getId()) { if (this.aComments[i].asc_getId() == data.asc_getId()) {
_this.aComments.splice(i, 1); this.aComments.splice(i, 1);
_this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", data.asc_getId()); this.worksheet.model.workbook.handlers.trigger("asc_onRemoveComment", data.asc_getId());
break; break;
} }
} }
...@@ -1769,7 +1797,7 @@ CCellCommentator.prototype = { ...@@ -1769,7 +1797,7 @@ CCellCommentator.prototype = {
case historyitem_Comment_Change: case historyitem_Comment_Change:
if (data.commentBefore.oParent) { if (data.commentBefore.oParent) {
parentComment = _this.asc_findComment(data.commentBefore.oParent.asc_getId()); parentComment = this.asc_findComment(data.commentBefore.oParent.asc_getId());
for (i = 0; i < parentComment.aReplies.length; i++) { for (i = 0; i < parentComment.aReplies.length; i++) {
if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) { if (parentComment.aReplies[i].asc_getId() == data.asc_getId()) {
parentComment.aReplies.splice(i, 1); parentComment.aReplies.splice(i, 1);
...@@ -1778,16 +1806,15 @@ CCellCommentator.prototype = { ...@@ -1778,16 +1806,15 @@ CCellCommentator.prototype = {
} }
} }
} else { } else {
for (i = 0; i < _this.aComments.length; i++) { for (i = 0; i < this.aComments.length; i++) {
if (_this.aComments[i].asc_getId() == data.commentBefore.asc_getId()) { if (this.aComments[i].asc_getId() == data.commentBefore.asc_getId()) {
_this.aComments.splice(i, 1); this.aComments.splice(i, 1);
_this.aComments.push(data.commentAfter); this.aComments.push(data.commentAfter);
_this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", data.commentAfter.asc_getId(), data.commentAfter); this.worksheet.model.workbook.handlers.trigger("asc_onChangeCommentData", data.commentAfter.asc_getId(), data.commentAfter);
break; break;
} }
} }
} }
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