Commit 61fbd5ae authored by Alexey.Musinov's avatar Alexey.Musinov

[ios] cell editor, insert formula


git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@67712 954022d7-b5bf-4e40-9824-e11837661b57
parent e946a4d2
......@@ -653,18 +653,21 @@ WorksheetView.prototype.__chartsRanges = function() {
if (asc["editor"].isStartAddShape || this.objectRender.selectedGraphicObjectsExists()) {
if (this.isChartAreaEditMode) {
return this.__drawFormulaRanges(this.arrActiveChartsRanges, 0, 0);
return this.__drawFormulaRanges(this.arrActiveChartsRanges, 0, 0, c_oAscSelectionType.RangeChart);
}
}
return null;
};
WorksheetView.prototype.__drawFormulaRanges = function (arrRanges, offsetX, offsetY) {
WorksheetView.prototype.__drawFormulaRanges = function (arrRanges, offsetX, offsetY, rangetype) {
var ranges = [],i = 0, type = 0, left = 0, right = 0, top = 0, bottom = 0;
var addt, addl, addr, addb, colsCount = this.cols.length - 1, rowsCount = this.rows.length - 1;
var defaultWidth = this.model.getDefaultWidth();
defaultWidth = (typeof defaultWidth === "number" && defaultWidth >= 0) ? defaultWidth : -1;
for (i = 0; i < arrRanges.length; ++i) {
ranges.push(arrRanges[i].type);
ranges.push(undefined !== rangetype ? rangetype : arrRanges[i].type);
ranges.push(arrRanges[i].c1);
ranges.push(arrRanges[i].c2);
ranges.push(arrRanges[i].r1);
......@@ -672,31 +675,108 @@ WorksheetView.prototype.__drawFormulaRanges = function (arrRanges, offsetX, offs
type = arrRanges[i].type;
if (1 == type) { // cells
left = this.cols[arrRanges[i].c1].left - offsetX;
top = this.rows[arrRanges[i].r1].top - offsetY;
right = this.cols[arrRanges[i].c2].left + this.cols[arrRanges[i].c2].width - offsetX;
bottom = this.rows[arrRanges[i].r2].top + this.rows[arrRanges[i].r2].height - offsetY;
addl = Math.max(arrRanges[i].c1 - colsCount,0);
addt = Math.max(arrRanges[i].r1 - rowsCount,0);
addr = Math.max(arrRanges[i].c2 - colsCount,0);
addb = Math.max(arrRanges[i].r2 - rowsCount,0);
if (1 === type) { // cells or chart
if (addl > 0)
left = this.cols[colsCount - 1].left + this.defaultColWidth * addl - offsetX;
else
left = this.cols[arrRanges[i].c1].left - offsetX;
if (addt > 0)
top = this.rows[rowsCount - 1].top + addt * gc_dDefaultRowHeightAttribute - offsetY;
else
top = this.rows[arrRanges[i].r1].top - offsetY;
if (addr > 0)
right = this.cols[colsCount - 1].left + this.defaultColWidth * addr - offsetX;
else
right = this.cols[arrRanges[i].c2].left + this.cols[arrRanges[i].c2].width - offsetX;
if (addb > 0)
bottom = this.rows[rowsCount - 1].top + addb * gc_dDefaultRowHeightAttribute - offsetY;
else
bottom = this.rows[arrRanges[i].r2].top + this.rows[arrRanges[i].r2].height - offsetY;
}
else if (2 == type) { // column range
left = this.cols[arrRanges[i].c1].left - offsetX;
top = this.rows[arrRanges[i].r1].top - offsetY;
right = this.cols[arrRanges[i].c2].left + this.cols[arrRanges[i].c2].width - offsetX;
bottom = 0;
else if (2 === type) { // column range
if (addl > 0)
left = this.cols[colsCount - 1].left + this.defaultColWidth * addl - offsetX;
else
left = this.cols[arrRanges[i].c1].left - offsetX;
if (addt > 0)
top = this.rows[rowsCount - 1].top + addt * gc_dDefaultRowHeightAttribute - offsetY;
else
top = this.rows[arrRanges[i].r1].top - offsetY;
if (addr > 0)
right = this.cols[colsCount - 1].left + this.defaultColWidth * addr - offsetX;
else
right = this.cols[arrRanges[i].c2].left + this.cols[arrRanges[i].c2].width - offsetX;
bottom = 0;
}
else if (3 == type) { // row range
left = this.cols[arrRanges[i].c1].left - offsetX;
top = this.rows[arrRanges[i].r1].top - offsetY;
right = 0;
bottom = this.rows[arrRanges[i].r2].top + this.rows[arrRanges[i].r2].height - offsetY;
else if (3 === type) { // row range
if (addl > 0)
left = this.cols[colsCount - 1].left + this.defaultColWidth * addl - offsetX;
else
left = this.cols[arrRanges[i].c1].left - offsetX;
if (addt > 0)
top = this.rows[rowsCount - 1].top + addt * gc_dDefaultRowHeightAttribute - offsetY;
else
top = this.rows[arrRanges[i].r1].top - offsetY;
right = 0;
if (addb > 0)
bottom = this.rows[rowsCount - 1].top + addb * gc_dDefaultRowHeightAttribute - offsetY;
else
bottom = this.rows[arrRanges[i].r2].top + this.rows[arrRanges[i].r2].height - offsetY;
}
else if (4 == type) { // max
left = this.cols[arrRanges[i].c1].left - offsetX;
top = this.rows[arrRanges[i].r1].top - offsetY;
right = 0;
bottom = 0;
else if (4 === type) { // max
if (addl > 0)
left = this.cols[colsCount - 1].left + this.defaultColWidth * addl - offsetX;
else
left = this.cols[arrRanges[i].c1].left - offsetX;
if (addt > 0)
top = this.rows[rowsCount - 1].top + addt * gc_dDefaultRowHeightAttribute - offsetY;
else
top = this.rows[arrRanges[i].r1].top - offsetY;
right = 0;
bottom = 0;
} else {
if (addl > 0)
left = this.cols[colsCount - 1].left + this.defaultColWidth * addl - offsetX;
else
left = this.cols[arrRanges[i].c1].left - offsetX;
if (addt > 0)
top = this.rows[rowsCount - 1].top + addt * gc_dDefaultRowHeightAttribute - offsetY;
else
top = this.rows[arrRanges[i].r1].top - offsetY;
if (addr > 0)
right = this.cols[colsCount - 1].left + this.defaultColWidth * addr - offsetX;
else
right = this.cols[arrRanges[i].c2].left + this.cols[arrRanges[i].c2].width - offsetX;
if (addb > 0)
bottom = this.rows[rowsCount - 1].top + addb * gc_dDefaultRowHeightAttribute - offsetY;
else
bottom = this.rows[arrRanges[i].r2].top + this.rows[arrRanges[i].r2].height - offsetY;
}
// else if (5 === type) { // range image
// }
// else if (6 === type) { // range chart
// }
ranges.push(left);
ranges.push(top);
ranges.push(right);
......
......@@ -4330,7 +4330,15 @@ function offline_mouse_down(x, y, pin, isViewer, isFormulaEditMode) {
_s.isShapeAction = true;
ws.visibleRange = range;
return {id:graphicsInfo.id};
if (!graphicsInfo.object.graphicObject instanceof CChartSpace) {
ws.isChartAreaEditMode = false;
}
return {
id:graphicsInfo.id//,
//ischart: graphicsInfo.object.graphicObject instanceof CChartSpace
};
}
_s.cellPin = pin;
......@@ -4466,19 +4474,22 @@ function offline_cell_editor_draw(width, height, ratio) {
var wb = _api.wb;
var cellEditor = _api.wb.cellEditor;
cellEditor._draw();
return [wb.cellEditor.left, wb.cellEditor.top, wb.cellEditor.right, wb.cellEditor.bottom,
wb.cellEditor.curLeft, wb.cellEditor.curTop, wb.cellEditor.curHeight];
}
function offline_cell_editor_open(isSelectAll, x, y, width, height, ratio) {
function offline_cell_editor_open(x, y, width, height, ratio, isSelectAll, isFormulaInsertMode) {
_null_object.width = width * ratio;
_null_object.height = height * ratio;
var wb = _api.wb;
wb.cellEditor.isSelectAll = isSelectAll;
wb._onEditCell(x, y, true, undefined, undefined, true, false);
return [wb.cellEditor.left, wb.cellEditor.top, wb.cellEditor.right, wb.cellEditor.bottom,
wb.cellEditor.curLeft, wb.cellEditor.curTop, wb.cellEditor.curHeight];
if (! isFormulaInsertMode) {
wb._onEditCell(x, y, true, undefined, undefined, true, false);
} else {
// wb.cellEditor._draw();
}
}
function offline_cell_editor_key_event(keys, width, height, ratio) {
_null_object.width = width * ratio;
......@@ -4537,7 +4548,8 @@ function offline_cell_editor_mouse_event(events) {
pageX:events[i][1],
pageY:events[i][2],
which: 1,
shiftKey:events[i][3]
shiftKey:events[i][3],
button:0
};
if (events[i][3]) {
......@@ -4567,6 +4579,8 @@ function offline_cell_editor_mouse_event(events) {
left = cellEditor.selectionBegin;
right = cellEditor.selectionEnd;
cellEditor.clickCounter.clickCount = 1;
cellEditor._onMouseDown(event);
if (-1 === _s.textSelection) {
......@@ -4586,7 +4600,11 @@ function offline_cell_editor_mouse_event(events) {
} else if (2 == events[i][0]) {
cellEditor._onMouseMove(event);
} else if (3 == events[i][0]) {
cellEditor._onMouseDblClick(event);
cellEditor.clickCounter.clickCount = 2;
cellEditor._onMouseDown(event);
cellEditor._onMouseUp(event);
cellEditor.clickCounter.clickCount = 0;
_s.textSelection = 0;
}
}
......@@ -4597,13 +4615,16 @@ function offline_cell_editor_mouse_event(events) {
function offline_cell_editor_close(x, y, width, height, ratio) {
var e = {which: 13, shiftKey: false, metaKey: false, ctrlKey: false};
//_api.wb.cellEditor._tryCloseEditor(e);
// TODO: SHOW POPUP
if (_api.wb.cellEditor.close(true)) {
_api.wb.getWorksheet().handlers.trigger('applyCloseEvent', e);
} else {
_api.wb.cellEditor.undoAll();
_api.wb.cellEditor.close();
}
_api.wb._onWSSelectionChanged(/*info*/null);
_api.wb._onWSSelectionChanged(null);
}
function offline_cell_editor_selection() {
return _api.wb.cellEditor._drawSelection();
......@@ -4676,6 +4697,73 @@ function offline_can_enter_cell_range() {
var wb = _api.wb;
return wb.cellEditor.canEnterCellRange();
}
function offline_insertFormula(functionName, autoComplete, isDefName) {
var ws = _api.wb.getWorksheet();
var wb = _api.wb;
var t = ws, cursorPos;
var cellRange = null;
// Если нужно сделать автозаполнение формулы, то ищем ячейки)
if (autoComplete) {
cellRange = ws.autoCompleteFormula(functionName);
}
if (isDefName) {
functionName = "=" + functionName;
} else{
if (cellRange) {
if (cellRange.notEditCell) {
// Мы уже ввели все что нужно, редактор открывать не нужно
return null;
}
// Меняем значение ячейки
functionName = "=" + functionName + "(" + cellRange.text + ")";
} else {
// Меняем значение ячейки
functionName = "=" + functionName + "()";
}
// Вычисляем позицию курсора (он должен быть в функции)
cursorPos = functionName.length - 1;
}
var arn = ws.activeRange.clone(true);
var openEditor = function (res) {
if (res) {
// Выставляем переменные, что мы редактируем
// t.controller.setCellEditMode(true);
ws.setCellEditMode(true);
ws.handlers.trigger("asc_onEditCell", c_oAscCellEditorState.editStart);
if (isDefName)
ws.skipHelpSelector = true;
// Открываем, с выставлением позиции курсора
if (!ws.openCellEditorWithText(wb.cellEditor, functionName, cursorPos, /*isFocus*/false,
/*activeRange*/arn)) {
ws.handlers.trigger("asc_onEditCell", c_oAscCellEditorState.editEnd);
// t.controller.setCellEditMode(false);
// t.controller.setStrictClose(false);
// t.controller.setFormulaEditMode(false);
ws.setCellEditMode(false);
ws.setFormulaEditMode(false);
}
if (isDefName)
ws.skipHelpSelector = false;
return [wb.cellEditor.left, wb.cellEditor.top, wb.cellEditor.right, wb.cellEditor.bottom,
wb.cellEditor.curLeft, wb.cellEditor.curTop, wb.cellEditor.curHeight];
} else {
//t.controller.setCellEditMode(false);
//t.controller.setStrictClose(false);
//t.controller.setFormulaEditMode(false);
ws.setCellEditMode(false);
ws.setFormulaEditMode(false);
}
};
return openEditor(true);
}
function offline_copy() {
......@@ -5558,40 +5646,6 @@ function offline_apply_event(type,params) {
break;
}
case 2410: // ASC_SPREADSHEETS_EVENT_TYPE_GET_FORMULAS
{
_stream = global_memory_stream_menu;
_stream["ClearNoAttack"]();
var info = _api.asc_getFormulasInfo();
if (info) {
_stream["WriteLong"](info.length);
for (var i = 0; i < info.length; ++i) {
_stream["WriteString2"](info[i].asc_getGroupName());
var ascFunctions = info[i].asc_getFormulasArray();
_stream["WriteLong"](ascFunctions.length);
for (var j = 0; j < ascFunctions.length; ++j) {
_stream["WriteString2"](ascFunctions[j].asc_getName());
_stream["WriteString2"](ascFunctions[j].asc_getArguments());
}
}
} else {
_stream["WriteLong"](0);
}
if (undefined !== params) {
var localizeData = JSON.parse(params);
_api.asc_setLocalization(localizeData);
}
_return = _stream;
break;
}
case 2415: // ASC_SPREADSHEETS_EVENT_TYPE_CHANGE_COLOR_SCHEME
{
if (undefined !== params) {
......@@ -5633,6 +5687,48 @@ function offline_apply_event(type,params) {
break;
}
case 4010: // ASC_SPREADSHEETS_EVENT_TYPE_INSERT_FORMULA
{
if (params && params.length && params[0]) {
_return = offline_insertFormula(params[0], params[1] ? true : undefined, params[2] ? true : undefined);
}
break;
}
case 4020: // ASC_SPREADSHEETS_EVENT_TYPE_GET_FORMULAS
{
_stream = global_memory_stream_menu;
_stream["ClearNoAttack"]();
var info = _api.asc_getFormulasInfo();
if (info) {
_stream["WriteLong"](info.length);
for (var i = 0; i < info.length; ++i) {
_stream["WriteString2"](info[i].asc_getGroupName());
var ascFunctions = info[i].asc_getFormulasArray();
_stream["WriteLong"](ascFunctions.length);
for (var j = 0; j < ascFunctions.length; ++j) {
_stream["WriteString2"](ascFunctions[j].asc_getName());
_stream["WriteString2"](ascFunctions[j].asc_getArguments());
}
}
} else {
_stream["WriteLong"](0);
}
if (undefined !== params) {
var localizeData = JSON.parse(params);
_api.asc_setLocalization(localizeData);
}
_return = _stream;
break;
}
default:
break;
}
......
......@@ -1706,7 +1706,9 @@
}
}
if (!window['IS_NATIVE_EDITOR']) {
if (window['IS_NATIVE_EDITOR']) {
doChangeSelection(coord);
} else {
window.clearTimeout(t.selectionTimer);
t.selectionTimer = window.setTimeout(function() {
doChangeSelection(coord);
......@@ -2461,7 +2463,9 @@
CellEditor.prototype._onMouseDown = function(event) {
var pos;
var coord = this._getCoordinates(event);
this.clickCounter.mouseDownEvent(coord.x, coord.y, event.button);
if (!window['IS_NATIVE_EDITOR']) {
this.clickCounter.mouseDownEvent(coord.x, coord.y, event.button);
}
this.setFocus(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