Commit 4e7848c7 authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix bugs #22959, #23026

при scroll-е пересчитываем область ячейки

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@67019 954022d7-b5bf-4e40-9824-e11837661b57
parent f43b1cb2
......@@ -82,6 +82,7 @@
this.input = input;
this.handlers = new asc_HL(handlers);
this.options = {};
this.sides = undefined;
//---declaration---
this.canvasOuter = undefined;
......@@ -223,11 +224,6 @@
/**
* @param {Object} options
* cellX - cell x coord (pt)
* cellY - cell y coord (pt)
* leftSide - array
* rightSide - array
* bottomSide - array
* fragments - text fragments
* flags - text flags (wrapText, textAlign)
* font
......@@ -440,23 +436,44 @@
t._moveCursor(kEndOfText);
};
CellEditor.prototype.move = function (dx, dy, l, t, r, b) {
var opt = this.options;
CellEditor.prototype.move = function (l, t, r, b) {
this.sides = this.options.getSides();
this.left = this.sides.cellX;
this.top = this.sides.cellY;
this.right = this.sides.r[0];
this.bottom = this.sides.b[0];
// Обновляем флаги, т.к. мы уже могли выставить wrap
this.textFlags.wrapText = this.options.flags.wrapText;
if (this.textFlags.wrapText) {
this.textFlags.wrapOnlyNL = true;
this.textFlags.wrapText = false;
}
// ToDo вынести в отдельную функцию
var canExpW = true, canExpH = true, tm, expW, expH, fragments = this._getRenderFragments();
if (0 < fragments.length) {
tm = this.textRender.measureString(fragments, this.textFlags, this._getContentWidth());
expW = tm.width > this._getContentWidth();
expH = tm.height > this._getContentHeight();
this.left += dx;
this.right += dx;
this.top += dy;
this.bottom += dy;
while (expW && canExpW || expH && canExpH) {
if (expW) { canExpW = this._expandWidth(); }
if (expH) { canExpH = this._expandHeight(); }
opt.leftSide.forEach(function (e,i,a) {a[i] = e + dx;});
opt.rightSide.forEach(function (e,i,a) {a[i] = e + dx;});
opt.bottomSide.forEach(function (e,i,a) {a[i] = e + dy;});
if (!canExpW) {
this.textFlags.wrapText = true;
tm = this.textRender.measureString(fragments, this.textFlags, this._getContentWidth());
} else {
tm = this.textRender.measure(this._getContentWidth());
}
expW = tm.width > this._getContentWidth();
expH = tm.height > this._getContentHeight();
}
}
if (this.left < l || this.top < t || this.left > r || this.top > b) {
// hide
this._hideCanvas();
} else {
// ToDo выставлять опции (т.к. при scroll редактор должен пересчитываться и уменьшаться размеры)
this._adjustCanvas();
this._showCanvas();
this._renderText();
......@@ -640,7 +657,7 @@
var ctx = this.drawingCtx;
var u = ctx.getUnits();
this.textFlags = opt.flags;
this.textFlags = opt.flags.clone();
if (this.textFlags.textAlign.toLowerCase() === "justify" || this.isFormula()) {
this.textFlags.textAlign = "left";
}
......@@ -661,14 +678,12 @@
this.kx = asc_getcvt(u, 0/*px*/, ctx.getPPIX());
this.ky = asc_getcvt(u, 0/*px*/, ctx.getPPIY());
opt.leftSide.sort(fSortDescending);
opt.rightSide.sort(fSortAscending);
opt.bottomSide.sort(fSortAscending);
this.sides = opt.getSides();
this.left = opt.cellX;
this.top = opt.cellY;
this.right = opt.rightSide[0];
this.bottom = opt.bottomSide[0];
this.left = this.sides.cellX;
this.top = this.sides.cellY;
this.right = this.sides.r[0];
this.bottom = this.sides.b[0];
this.cursorPos = opt.cursorPos !== undefined ? opt.cursorPos : 0;
this.topLineIndex = 0;
......@@ -1026,15 +1041,15 @@
};
CellEditor.prototype._expandWidth = function () {
var t = this, opt = t.options, l = false, r = false;
var t = this, l = false, r = false, leftSide = this.sides.l, rightSide = this.sides.r;
function expandLeftSide() {
var i = asc_search(opt.leftSide, function (v) {return v < t.left;});
var i = asc_search(leftSide, function (v) {return v < t.left;});
if (i >= 0) {
t.left = opt.leftSide[i];
t.left = leftSide[i];
return true;
}
var val = opt.leftSide[opt.leftSide.length - 1];
var val = leftSide[leftSide.length - 1];
if (Math.abs(t.left - val) > 0.000001) { // left !== leftSide[len-1]
t.left = val;
}
......@@ -1042,12 +1057,12 @@
}
function expandRightSide() {
var i = asc_search(opt.rightSide, function (v) {return v > t.right;});
var i = asc_search(rightSide, function (v) {return v > t.right;});
if (i >= 0) {
t.right = opt.rightSide[i];
t.right = rightSide[i];
return true;
}
var val = opt.rightSide[opt.rightSide.length - 1];
var val = rightSide[rightSide.length - 1];
if (Math.abs(t.right - val) > 0.000001) { // right !== rightSide[len-1]
t.right = val;
}
......@@ -1064,12 +1079,12 @@
};
CellEditor.prototype._expandHeight = function () {
var t = this, opt = t.options, i = asc_search(opt.bottomSide, function (v) {return v > t.bottom;});
var t = this, bottomSide = this.sides.b, i = asc_search(bottomSide, function (v) {return v > t.bottom;});
if (i >= 0) {
t.bottom = opt.bottomSide[i];
t.bottom = bottomSide[i];
return true;
}
var val = opt.bottomSide[opt.bottomSide.length - 1];
var val = bottomSide[bottomSide.length - 1];
if (Math.abs(t.bottom - val) > 0.000001) { // bottom !== bottomSide[len-1]
t.bottom = val;
}
......
......@@ -5266,8 +5266,7 @@
ctxH - (this.rows[oldEnd].top - this.rows[oldStart].top + this.cellsTop + diffHeight) : 0;
if (this.isCellEditMode && editor && this.activeRange.r1 >= rFrozen) {
editor.move(0, -dy, this.cellsLeft + (this.activeRange.c1 >= cFrozen ? diffWidth : 0),
this.cellsTop + diffHeight, ctxW, ctxH);
editor.move(this.cellsLeft + (this.activeRange.c1 >= cFrozen ? diffWidth : 0), this.cellsTop + diffHeight, ctxW, ctxH);
}
var widthChanged = Math.max(calcDecades(vr.r2 + 1), 3) !== oldDec;
......@@ -5456,8 +5455,7 @@
ctxW - (this.cols[oldEnd].left - this.cols[oldStart].left + this.cellsLeft + diffWidth) : 0;
if (this.isCellEditMode && editor && this.activeRange.c1 >= cFrozen) {
editor.move(-dx, 0, this.cellsLeft + diffWidth,
this.cellsTop + (this.activeRange.r1 >= rFrozen ? diffHeight : 0), ctxW, ctxH);
editor.move(this.cellsLeft + diffWidth, this.cellsTop + (this.activeRange.r1 >= rFrozen ? diffHeight : 0), ctxW, ctxH);
}
// Перемещаем область
......@@ -10365,70 +10363,50 @@
return true;
};
WorksheetView.prototype.openCellEditor = function (editor, x, y, isCoord, fragments, cursorPos,
isFocus, isClearCell, isHideCursor, isQuickInput, activeRange) {
var t = this, vr, tc = this.cols, tr = this.rows, col, row, c, fl, mc, bg, isMerged;
var offsetX = 0, offsetY = 0;
WorksheetView.prototype.openCellEditor = function(editor, x, y, isCoord, fragments, cursorPos, isFocus, isClearCell, isHideCursor, isQuickInput, activeRange) {
var t = this, tc = this.cols, tr = this.rows, col, row, c, fl, mc, bg, isMerged;
var ar = this.activeRange;
if (activeRange)
if (activeRange) {
this.activeRange = activeRange.clone();
}
if (this.objectRender.checkCursorDrawingObject(x, y))
if (this.objectRender.checkCursorDrawingObject(x, y)) {
return false;
function getLeftSide(col) {
var i, res = [], offs = t.cols[vr.c1].left - t.cols[0].left - offsetX;
for (i = col; i >= vr.c1; --i) {
if (t.width_1px < t.cols[i].width)
res.push(t.cols[i].left - offs);
}
return res;
}
function getRightSide(col) {
var i, w, res = [], offs = t.cols[vr.c1].left - t.cols[0].left - offsetX;
// Для замерженных ячеек, можем уйти за границу
if (isMerged && col > vr.c2)
col = vr.c2;
for (i = col; i <= vr.c2; ++i) {
w = t.cols[i].width;
if (t.width_1px < w)
res.push(t.cols[i].left + w - offs);
function getVisibleRangeObject() {
var vr = t.visibleRange.clone(), offsetX = 0, offsetY = 0;
if (t.topLeftFrozenCell) {
var cFrozen = t.topLeftFrozenCell.getCol0();
var rFrozen = t.topLeftFrozenCell.getRow0();
if (0 < cFrozen) {
if (col >= cFrozen) {
offsetX = tc[cFrozen].left - tc[0].left;
} else {
vr.c1 = 0;
vr.c2 = cFrozen - 1;
}
w = t.drawingCtx.getWidth();
if (res[res.length - 1] > w) {
res[res.length - 1] = w;
}
return res;
if (0 < rFrozen) {
if (row >= rFrozen) {
offsetY = tr[rFrozen].top - tr[0].top;
} else {
vr.r1 = 0;
vr.r2 = rFrozen - 1;
}
function getBottomSide(row) {
var i, h, res = [], offs = t.rows[vr.r1].top - t.rows[0].top - offsetY;
// Для замерженных ячеек, можем уйти за границу
if (isMerged && row > vr.r2)
row = vr.r2;
for (i = row; i <= vr.r2; ++i) {
h = t.rows[i].height;
if (t.height_1px < h)
res.push(t.rows[i].top + h - offs);
}
h = t.drawingCtx.getHeight();
if (res[res.length - 1] > h) {
res[res.length - 1] = h;
}
return res;
return {vr: vr, offsetX: offsetX, offsetY: offsetY};
}
if (isCoord) {
x *= asc_getcvt( 0/*px*/, 1/*pt*/, this._getPPIX() );
y *= asc_getcvt( 0/*px*/, 1/*pt*/, this._getPPIY() );
x *= asc_getcvt(0/*px*/, 1/*pt*/, this._getPPIX());
y *= asc_getcvt(0/*px*/, 1/*pt*/, this._getPPIY());
col = this._findColUnderCursor(x, true);
row = this._findRowUnderCursor(y, true);
if (!col || !row) {return false;}
if (!col || !row) {
return false;
}
col = col.col;
row = row.row;
} else {
......@@ -10438,14 +10416,18 @@
// Возможно стоит заменить на ячейку из кеша
c = this._getVisibleCell(col, row);
if (!c) {throw "Can not get cell data (col=" + col + ", row=" + row + ")";}
if (!c) {
throw "Can not get cell data (col=" + col + ", row=" + row + ")";
}
fl = this._getCellFlags(c);
isMerged = fl.isMerged();
if (isMerged) {
mc = fl.merged;
c = this._getVisibleCell(mc.c1, mc.r1);
if (!c) {throw "Can not get merged cell data (col=" + mc.c1 + ", row=" + mc.r1 + ")";}
if (!c) {
throw "Can not get merged cell data (col=" + mc.c1 + ", row=" + mc.r1 + ")";
}
fl = this._getCellFlags(c);
}
......@@ -10454,28 +10436,6 @@
this.handlers.trigger("onScroll", this._calcActiveCellOffset());
this.isCellEditMode = true;
vr = this.visibleRange.clone();
if (this.topLeftFrozenCell) {
var cFrozen = this.topLeftFrozenCell.getCol0();
var rFrozen = this.topLeftFrozenCell.getRow0();
if (0 < cFrozen) {
if (col >= cFrozen)
offsetX = tc[cFrozen].left - tc[0].left;
else {
vr.c1 = 0;
vr.c2 = cFrozen - 1;
}
}
if (0 < rFrozen) {
if (row >= rFrozen)
offsetY = tr[rFrozen].top - tr[0].top;
else {
vr.r1 = 0;
vr.r2 = rFrozen - 1;
}
}
}
bg = c.getFill();
this.isFormulaEditMode = false;
// Очищаем массив ячеек для текущей формулы
......@@ -10496,11 +10456,6 @@
var arrAutoCompleteLC = asc.arrayToLowerCase(arrAutoComplete);
editor.open({
cellX: this.cellsLeft + tc[!isMerged ? col : mc.c1].left - tc[vr.c1].left + offsetX,
cellY: this.cellsTop + tr[!isMerged ? row : mc.r1].top - tr[vr.r1].top + offsetY,
leftSide: getLeftSide(!isMerged ? col : mc.c1),
rightSide: getRightSide(!isMerged ? col : mc.c2),
bottomSide: getBottomSide(!isMerged ? row : mc.r2),
fragments: fragments,
flags: fl,
font: new asc.FontProperties(c.getFontname(), c.getFontsize()),
......@@ -10515,10 +10470,57 @@
isAddPersentFormat: isQuickInput && c_oAscNumFormatType.Percent === c.getNumFormat().getType(),
autoComplete: arrAutoComplete,
autoCompleteLC: arrAutoCompleteLC,
saveValueCallback: function (val, flags, skipNLCheck) {
saveValueCallback: function(val, flags, skipNLCheck) {
var oCellEdit = isMerged ? new asc_Range(mc.c1, mc.r1, mc.c1, mc.r1) : new asc_Range(col, row, col, row);
return t._saveCellValueAfterEdit(oCellEdit, c, val, flags,
skipNLCheck, /*isNotHistory*/false, /*lockDraw*/false);
return t._saveCellValueAfterEdit(oCellEdit, c, val, flags, skipNLCheck, /*isNotHistory*/false, /*lockDraw*/false);
},
getSides: function() {
var _col = !isMerged ? col : mc.c1;
var _row = !isMerged ? row : mc.r2;
var vro = getVisibleRangeObject();
var i, w, h, arrLeftS = [], arrRightS = [], arrBottomS = [];
var offsX = tc[vro.vr.c1].left - tc[0].left - vro.offsetX;
var offsY = tr[vro.vr.r1].top - tr[0].top - vro.offsetY;
var cellX = tc[_col].left - offsX, cellY = tr[!isMerged ? row : mc.r1].top - offsY;
for (i = _col; i >= vro.vr.c1; --i) {
if (t.width_1px < tc[i].width) {
arrLeftS.push(tc[i].left - offsX);
}
}
arrLeftS.sort(fSortDescending);
// Для замерженных ячеек, можем уйти за границу
if (isMerged && _col > vro.vr.c2) {
_col = vro.vr.c2;
}
for (i = _col; i <= vro.vr.c2; ++i) {
w = tc[i].width;
if (t.width_1px < w) {
arrRightS.push(tc[i].left + w - offsX);
}
}
w = t.drawingCtx.getWidth();
if (arrRightS[arrRightS.length - 1] > w) {
arrRightS[arrRightS.length - 1] = w;
}
arrRightS.sort(fSortAscending);
// Для замерженных ячеек, можем уйти за границу
if (isMerged && _row > vro.vr.r2) {
_row = vro.vr.r2;
}
for (i = _row; i <= vro.vr.r2; ++i) {
h = tr[i].height;
if (t.height_1px < h) {
arrBottomS.push(tr[i].top + h - offsY);
}
}
h = t.drawingCtx.getHeight();
if (arrBottomS[arrBottomS.length - 1] > h) {
arrBottomS[arrBottomS.length - 1] = h;
}
arrBottomS.sort(fSortAscending);
return {l: arrLeftS, r: arrRightS, b: arrBottomS, cellX: cellX, cellY: cellY};
}
});
return true;
......
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