Commit 5809d883 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Добавил функцию getCellMetrics для получения информации о ячейке с учетом закрепленных областей

Переделал работу с отрисовкой комментариев для закрепленных областей (и обычного случая в частности)

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@60483 954022d7-b5bf-4e40-9824-e11837661b57
parent 93c9f233
...@@ -582,7 +582,7 @@ CCellCommentator.prototype.drawCommentCells = function() { ...@@ -582,7 +582,7 @@ CCellCommentator.prototype.drawCommentCells = function() {
return; return;
this.drawingCtx.setFillStyle(this.commentIconColor); this.drawingCtx.setFillStyle(this.commentIconColor);
var commentCell, mergedRange, nCol, nRow, vr, nColSize, nRowSize, x, y; var commentCell, mergedRange, nCol, nRow, x, y, metrics;
for (var i = 0; i < this.aComments.length; ++i) { for (var i = 0; i < this.aComments.length; ++i) {
commentCell = this.aComments[i]; commentCell = this.aComments[i];
if (commentCell.asc_getDocumentFlag() || commentCell.asc_getHiddenFlag() || commentCell.asc_getSolved()) if (commentCell.asc_getDocumentFlag() || commentCell.asc_getHiddenFlag() || commentCell.asc_getSolved())
...@@ -592,18 +592,14 @@ CCellCommentator.prototype.drawCommentCells = function() { ...@@ -592,18 +592,14 @@ CCellCommentator.prototype.drawCommentCells = function() {
nCol = mergedRange ? mergedRange.c2 : commentCell.nCol; nCol = mergedRange ? mergedRange.c2 : commentCell.nCol;
nRow = mergedRange ? mergedRange.r1 : commentCell.nRow; nRow = mergedRange ? mergedRange.r1 : commentCell.nRow;
if (vr = this.worksheet.getCellVisibleRange(nCol, nRow)) { if (metrics = this.worksheet.getCellMetrics(nCol, nRow)) {
nColSize = this.worksheet.getColSize(nCol); x = metrics.left + metrics.width;
nRowSize = this.worksheet.getRowSize(nRow); y = metrics.top;
if (nColSize && nRowSize) { this.drawingCtx.beginPath();
x = nColSize.left + nColSize.width - vr.offsetX; this.drawingCtx.moveTo(x - this.pxToPt(7), y);
y = nRowSize.top - vr.offsetY; this.drawingCtx.lineTo(x - this.pxToPt(1), y);
this.drawingCtx.beginPath(); this.drawingCtx.lineTo(x - this.pxToPt(1), y + this.pxToPt(6));
this.drawingCtx.moveTo(x - this.pxToPt(7), y); this.drawingCtx.fill();
this.drawingCtx.lineTo(x - this.pxToPt(1), y);
this.drawingCtx.lineTo(x - this.pxToPt(1), y + this.pxToPt(6));
this.drawingCtx.fill();
}
} }
} }
}; };
...@@ -619,47 +615,6 @@ CCellCommentator.prototype.getTextMetrics = function(text, units) { ...@@ -619,47 +615,6 @@ CCellCommentator.prototype.getTextMetrics = function(text, units) {
return metrics; return metrics;
}; };
CCellCommentator.prototype.getCellMetrics = function(col, row) {
var metrics = { top: 0, left: 0, width: 0, height: 0, result: false }; // px
for (var n = 0; n < this.worksheet.drawingArea.frozenPlaces.length; n++) {
var frozenPlace = this.worksheet.drawingArea.frozenPlaces[n];
if ( !frozenPlace.isCellInside({ col: col, row: row }) )
continue;
var fv = frozenPlace.getFirstVisible();
var mergedRange = this.worksheet.model.getMergedByCell(row, col);
if (mergedRange && (fv.col < mergedRange.c2) && (fv.row < mergedRange.r2)) {
var startCol = (mergedRange.c1 > fv.col) ? mergedRange.c1 : fv.col;
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.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;
for (i = startCol; i <= mergedRange.c2; i++) {
metrics.width += this.worksheet.getColumnWidth(i, 1)
}
for (i = startRow; i <= mergedRange.r2; i++) {
metrics.height += this.worksheet.getRowHeight(i, 1)
}
metrics.result = true;
}
else if ((fv.row <= row) && (fv.col <= col)) {
metrics.top = this.worksheet.getCellTop(row, 1) /*- this.worksheet.getCellTop(fv.row, 1) + this.worksheet.getCellTop(0, 1)*/ + this.pxToPt(frozenPlace.getVerticalScroll()) - this.worksheet.getCellTop(0, 1);
metrics.left = this.worksheet.getCellLeft(col, 1) /*- this.worksheet.getCellLeft(fv.col, 1) + this.worksheet.getCellLeft(0, 1)*/ + this.pxToPt(frozenPlace.getHorizontalScroll()) - this.worksheet.getCellLeft(0, 1);
metrics.width = this.worksheet.getColumnWidth(col, 1);
metrics.height = this.worksheet.getRowHeight(row, 1);
metrics.result = true;
}
}
return metrics;
};
CCellCommentator.prototype.updateCommentPosition = function() { CCellCommentator.prototype.updateCommentPosition = function() {
if (this.lastSelectedId) { if (this.lastSelectedId) {
var comment = this.asc_findComment(this.lastSelectedId); var comment = this.asc_findComment(this.lastSelectedId);
...@@ -675,12 +630,12 @@ CCellCommentator.prototype.updateCommentPosition = function() { ...@@ -675,12 +630,12 @@ CCellCommentator.prototype.updateCommentPosition = function() {
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 isVisible = (null !== this.worksheet.getCellVisibleRange(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), (isVisible ? coords.asc_getLeftPX() : -1),
(metrics.result ? coords.asc_getTopPX() : -1), (isVisible ? coords.asc_getTopPX() : -1),
(metrics.result ? coords.asc_getReverseLeftPX() : -1) ); (isVisible ? coords.asc_getReverseLeftPX() : -1) );
} }
} }
} }
...@@ -858,14 +813,12 @@ CCellCommentator.prototype.resetLastSelectedId = function() { ...@@ -858,14 +813,12 @@ CCellCommentator.prototype.resetLastSelectedId = function() {
}; };
CCellCommentator.prototype.cleanLastSelection = function() { CCellCommentator.prototype.cleanLastSelection = function() {
if ( this.lastSelectedId ) { var metrics;
if (this.lastSelectedId) {
var lastComment = this.asc_findComment(this.lastSelectedId); var lastComment = this.asc_findComment(this.lastSelectedId);
if ( lastComment ) { if (lastComment && (metrics = this.worksheet.getCellMetrics(lastComment.nCol, lastComment.nRow))) {
var lastMetrics = this.getCellMetrics(lastComment.nCol, lastComment.nRow); var extraOffset = this.pxToPt(1);
if ( lastMetrics.result ) { this.overlayCtx.clearRect(metrics.left, metrics.top, metrics.width - extraOffset, metrics.height - extraOffset);
var extraOffset = this.pxToPt(1);
this.overlayCtx.clearRect(lastMetrics.left, lastMetrics.top, lastMetrics.width - extraOffset, lastMetrics.height - extraOffset);
}
} }
} }
}; };
...@@ -1059,13 +1012,12 @@ CCellCommentator.prototype.prepareCommentsToSave = function() { ...@@ -1059,13 +1012,12 @@ CCellCommentator.prototype.prepareCommentsToSave = function() {
}; };
CCellCommentator.prototype.cleanSelectedComment = function() { CCellCommentator.prototype.cleanSelectedComment = function() {
var metrics;
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()); (metrics = this.worksheet.getCellMetrics(comment.asc_getCol(), comment.asc_getRow())))
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);
}
} }
}; };
...@@ -1133,6 +1085,7 @@ CCellCommentator.prototype.asc_showComment = function(id, bNew) { ...@@ -1133,6 +1085,7 @@ CCellCommentator.prototype.asc_showComment = function(id, bNew) {
CCellCommentator.prototype.asc_selectComment = function(id, bMove) { CCellCommentator.prototype.asc_selectComment = function(id, bMove) {
var comment = this.asc_findComment(id); var comment = this.asc_findComment(id);
var metrics;
// Чистим предыдущий селект // Чистим предыдущий селект
this.cleanLastSelection(); this.cleanLastSelection();
...@@ -1163,8 +1116,7 @@ CCellCommentator.prototype.asc_selectComment = function(id, bMove) { ...@@ -1163,8 +1116,7 @@ CCellCommentator.prototype.asc_selectComment = function(id, bMove) {
} }
} }
var metrics = this.getCellMetrics(col, row); if (metrics = this.worksheet.getCellMetrics(col, row)) {
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();
......
...@@ -375,6 +375,20 @@ ...@@ -375,6 +375,20 @@
return vr.contains(col, row) ? new asc_VR(vr, offsetX, offsetY) : null; return vr.contains(col, row) ? new asc_VR(vr, offsetX, offsetY) : null;
}; };
WorksheetView.prototype.getCellMetrics = function (col, row) {
var vr, nColSize, nRowSize;
if (vr = this.getCellVisibleRange(col, row)) {
nColSize = this.getColSize(col);
nRowSize = this.getRowSize(row);
if (nColSize && nRowSize)
return {
left: nColSize.left - vr.offsetX, top: nRowSize.top - vr.offsetY,
width: nColSize.width, height: nRowSize.height
};
}
return null;
};
WorksheetView.prototype.getColSize = function (col) { WorksheetView.prototype.getColSize = function (col) {
return (col >= 0 && col < this.cols.length) ? this.cols[col] : null; return (col >= 0 && col < this.cols.length) ? this.cols[col] : null;
}; };
......
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