Commit aebbb827 authored by GoshaZotov's avatar GoshaZotov

changes for paste into cell editor

parent aa9b1036
......@@ -45,7 +45,7 @@
*/
var g_fontApplication = AscFonts.g_fontApplication;
var c_oAscBorderStyles = AscCommon.c_oAscBorderStyles;
var c_oAscMaxCellOrCommentLength = AscCommon.c_oAscMaxCellOrCommentLength;
var c_oAscMaxCellOrCommentLength = Asc.c_oAscMaxCellOrCommentLength;
var doc = window.document;
var copyPasteUseBinary = true;
var CopyPasteCorrectString = AscCommon.CopyPasteCorrectString;
......@@ -1242,7 +1242,7 @@
if(node == undefined)
return;
var aResult, binaryResult, pasteFragment = node, t = this, localStorageResult;
var binaryResult, pasteFragment = node, t = this, localStorageResult;
t.alreadyLoadImagesOnServer = false;
//****binary****
......@@ -1493,10 +1493,10 @@
var result = false;
var isChange = false;
var currentCellData = aResult[r][c];
if(currentCellData && currentCellData[0])
var currentCellData = aResult.content[r][c];
if(currentCellData && currentCellData.content)
{
currentCellData = currentCellData[0];
currentCellData = currentCellData.content;
for(var i = 0; i < currentCellData.length; i++)
{
if(currentCellData[i] && currentCellData[i].text && currentCellData[i].text.length > c_oAscMaxCellOrCommentLength)
......@@ -1510,15 +1510,15 @@
for(var j = 0; j < iterCount; j++)
{
splitText = text.substr(c_oAscMaxCellOrCommentLength * j, c_oAscMaxCellOrCommentLength * (j + 1));
if(!aResult[r])
aResult[r] = [];
if(!aResult[r][c])
aResult[r][c] = [];
if(!aResult[r][c][0])
aResult[r][c][0] = [];
if(!aResult.content[r])
aResult.content[r] = [];
if(!aResult.content[r][c])
aResult.content[r][c] = [];
if(!aResult.content[r][c].content)
aResult.content[r][c].content = [];
aResult[r][c][0] = currentCellData;
aResult[r][c][0][0].text = splitText;
aResult.content[r][c].content[0] = currentCellData[0];
aResult.content[r][c].content[0].text = splitText;
if(iterCount !== j + 1)
r++;
......@@ -1574,7 +1574,7 @@
History.StartTransaction();
var api = window["Asc"]["editor"];
var addImagesFromWord = data.addImagesFromWord;
var addImagesFromWord = data.props.addImagesFromWord;
//определяем стартовую позицию, если изображений несколько вставляется
for(var i = 0; i < addImagesFromWord.length; i++)
{
......@@ -1961,19 +1961,8 @@
return;
}
var aResult = [];
aResult[this.activeRange.r1] = [];
var oNewItem = [];
oNewItem[0] = this._getDefaultCell(worksheet);
aResult[this.activeRange.r1][this.activeRange.c1] = oNewItem;
oNewItem[0][0].text = text;
aResult.fontsNew = [];
aResult.rowSpanSpCount = 0;
aResult.cellCount = 1;
aResult._images = undefined;
aResult._aPastedImages = undefined;
var aResult = new excelPasteContent();
aResult = aResult.getDefaultPasteContent(worksheet, this.activeRange.r1, this.activeRange.c1, text);
if(aResult && !(aResult.onlyImages && window["Asc"]["editor"] && window["Asc"]["editor"].isChartEditor))
{
......@@ -1981,28 +1970,6 @@
}
},
_getDefaultCell: function (worksheet)
{
var res = [];
var fn = worksheet.model.workbook.getDefaultFont();
var fs = worksheet.model.workbook.getDefaultSize();
res.push({
format: {
fn: fn,
fs: fs,
b: false,
i: false,
u: Asc.EUnderline.underlineNone,
s: false,
va: 'none'
},
text: ''});
return res;
},
_getTextFromWorksheet: function(worksheet)
{
var res = "";
......@@ -2095,11 +2062,137 @@
};
/** @constructor */
function excelPasteContent()
{
this.content = [];
this.props = {};
return this;
}
excelPasteContent.prototype = {
constructor: excelPasteContent,
getDefaultPasteContent: function(worksheet, row, col, text)
{
var pasteCell = this.getCell(row, col);
pasteCell.setDefaultCell(worksheet);
pasteCell.content[0].text = text;
this.props.fontsNew = [];
this.props.rowSpanSpCount = 0;
this.props.cellCount = 1;
this.props._images = undefined;
this.props._aPastedImages = undefined;
return this;
},
setCellContent: function(row, col, data)
{
if(!this.content[row])
{
this.content[row] = [];
}
if(!this.content[row][col])
{
this.content[row][col] = [];
}
this.content[row][col] = data;
},
getCell: function(row, col)
{
if(!this.content[row])
{
this.content[row] = [];
}
if(!this.content[row][col])
{
this.content[row][col] = new pasteCell();
}
return this.content[row][col];
},
deleteCell: function(row, col)
{
delete this.content[row][col];
}
};
/** @constructor */
function pasteCell()
{
this.content = [];
this.rowSpan = null;
this.colSpan = null;
this.bc = null;
this.borders = null;
this.toolTip = null;
this.hyperLink = null;
return this;
}
pasteCell.prototype = {
constructor: pasteCell,
addContentItem: function(item)
{
this.content.push(item);
},
clone: function()
{
var result = new pasteCell();
for(var item = 0; item < this.content.length; item++)
{
result.content[item] = {text: this.content[item].text, format: this.content[item].format};
};
result.borders = this.borders;
result.rowSpan = this.rowSpan;
result.colSpan = this.colSpan;
result.toolTip = this.toolTip;
result.bc = this.bc;
result.hyperLink = this.hyperLink;
return result;
},
setDefaultCell: function (worksheet)
{
var fn = worksheet.model.workbook.getDefaultFont();
var fs = worksheet.model.workbook.getDefaultSize();
this.content.push({
format: {
fn: fn,
fs: fs,
b: false,
i: false,
u: Asc.EUnderline.underlineNone,
s: false,
va: 'none'
},
text: ''});
}
};
/** @constructor */
function pasteFromBinaryWord(clipboard, ws) {
function pasteFromBinaryWord(clipboard, ws)
{
this.aResult = new excelPasteContent();
this.fontsNew = {};
this.aResult = [];
this.clipboard = clipboard;
this.ws = ws;
this.isUsuallyPutImages = null;
......@@ -2126,18 +2219,18 @@
var coverDocument = documentContentBounds.getBounds(0,0, documentContent);
this._parseChildren(coverDocument, activeRange);
this.aResult.fontsNew = this.fontsNew;
this.aResult.rowSpanSpCount = 0;
this.aResult.cellCount = coverDocument.width;
this.aResult._images = pasteData.images ? pasteData.images : this.aResult._images;
this.aResult._aPastedImages = pasteData.aPastedImages ? pasteData.aPastedImages : this.aResult._aPastedImages;
this.aResult.props.fontsNew = this.fontsNew;
this.aResult.props.rowSpanSpCount = 0;
this.aResult.props.cellCount = coverDocument.width;
this.aResult.props._images = pasteData.images ? pasteData.images : this.aResult.props._images;
this.aResult.props._aPastedImages = pasteData.aPastedImages ? pasteData.aPastedImages : this.aResult.props._aPastedImages;
worksheet.setSelectionInfo('paste', this.aResult, this);
},
_parseChildren: function(children, activeRange)
{
var backgroundColor;
var childrens = children.children;
for(var i = 0; i < childrens.length; i++)
{
......@@ -2145,15 +2238,8 @@
{
for(var row = childrens[i].top; row < childrens[i].top + childrens[i].height; row++)
{
if(!this.aResult[row + activeRange.r1])
this.aResult[row + activeRange.r1] = [];
for(var col = childrens[i].left; col < childrens[i].left + childrens[i].width; col++)
{
if(!this.aResult[row + activeRange.r1][col + activeRange.c1])
this.aResult[row + activeRange.r1][col + activeRange.c1] = [];
if(!this.aResult[row + activeRange.r1][col + activeRange.c1][0])
this.aResult[row + activeRange.r1][col + activeRange.c1][0] = [];
var isCtable = false;
var tempChildren = childrens[i].children[0].children;
var colSpan = null;
......@@ -2173,16 +2259,21 @@
rowSpan = childrens[i].height;
colSpan = childrens[i].width;
}
this.aResult[row + activeRange.r1][col + activeRange.c1][0].rowSpan = rowSpan;
this.aResult[row + activeRange.r1][col + activeRange.c1][0].colSpan = colSpan;
var newCell = this.aResult.getCell(row + activeRange.r1, col + activeRange.c1)
newCell.rowSpan = rowSpan;
newCell.colSpan = colSpan;
//backgroundColor
backgroundColor = this.getBackgroundColorTCell(childrens[i]);
var backgroundColor = this.getBackgroundColorTCell(childrens[i]);
if(backgroundColor)
this.aResult[row + activeRange.r1][col + activeRange.c1][0].bc = backgroundColor;
{
newCell.bc = backgroundColor;
}
this.aResult[row + activeRange.r1][col + activeRange.c1][0].borders = this._getBorders(childrens[i], row, col, this.aResult[row + activeRange.r1][col + activeRange.c1][0].borders);
var borders = this._getBorders(childrens[i], row, col, newCell.borders);
newCell.borders = borders;
}
}
}
......@@ -2200,67 +2291,18 @@
}
},
_getBorders: function(cellTable, top, left, oldBorders)
{
var borders = cellTable.elem.Get_Borders();
var widthCell = cellTable.width;
var heigthCell = cellTable.height;
var defaultStyle = "solid";
var borderStyleName;
var formatBorders = oldBorders ? oldBorders : new AscCommonExcel.Border();
//top border for cell
if(top == cellTable.top && !formatBorders.t.s && borders.Top.Value !== 0/*border_None*/)
{
borderStyleName = this.clipboard._getBorderStyleName(defaultStyle, this.ws.objectRender.convertMetric(borders.Top.Size,3,1));
if (null !== borderStyleName) {
formatBorders.t.setStyle(borderStyleName);
formatBorders.t.c = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + borders.Top.Color.r + "," + borders.Top.Color.g + "," + borders.Top.Color.b + ")"));
}
}
//left border for cell
if(left == cellTable.left && !formatBorders.l.s && borders.Left.Value !== 0/*border_None*/)
{
borderStyleName = this.clipboard._getBorderStyleName(defaultStyle, this.ws.objectRender.convertMetric(borders.Left.Size,3,1));
if (null !== borderStyleName) {
formatBorders.l.setStyle(borderStyleName);
formatBorders.l.c = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + borders.Left.Color.r + "," + borders.Left.Color.g + "," + borders.Left.Color.b + ")"));
}
}
//bottom border for cell
if(top == cellTable.top + heigthCell - 1 && !formatBorders.b.s && borders.Bottom.Value !== 0/*border_None*/)
{
borderStyleName = this.clipboard._getBorderStyleName(defaultStyle, this.ws.objectRender.convertMetric(borders.Bottom.Size,3,1));
if (null !== borderStyleName) {
formatBorders.b.setStyle(borderStyleName);
formatBorders.b.c = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + borders.Bottom.Color.r + "," + borders.Bottom.Color.g + "," + borders.Bottom.Color.b + ")"));
}
}
//right border for cell
if(left == cellTable.left + widthCell - 1 && !formatBorders.r.s && borders.Right.Value !== 0/*border_None*/)
{
borderStyleName = this.clipboard._getBorderStyleName(defaultStyle, this.ws.objectRender.convertMetric(borders.Right.Size,3,1));
if (null !== borderStyleName) {
formatBorders.r.setStyle(borderStyleName);
formatBorders.r.c = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + borders.Right.Color.r + "," + borders.Right.Color.g + "," + borders.Right.Color.b + ")"));
}
}
return formatBorders;
},
_parseParagraph: function(paragraph, activeRange, row, col, rowSpan, colSpan)
{
var content = paragraph.elem.Content;
var row, cTextPr, fontFamily = "Arial";
var text = null;
var oNewItem = [], cloneNewItem;
var oNewItem = new pasteCell(), cloneNewItem;
var paraRunContent;
var aResult = this.aResult;
if(row === undefined)
{
if(aResult.length == 0)
if(aResult.content.length == 0)
{
row = activeRange.r1;
}
......@@ -2268,20 +2310,24 @@
row = aResult.length;
}
if(this.aResult[row + this.maxLengthRowCount] && this.aResult[row + this.maxLengthRowCount][col] && this.aResult[row + this.maxLengthRowCount][col][0] && this.aResult[row + this.maxLengthRowCount][col][0].length === 0 && (this.aResult[row + this.maxLengthRowCount][col][0].borders || this.aResult[row + this.maxLengthRowCount][col][0].rowSpan != null))
var cell = this.aResult.getCell(row + this.maxLengthRowCount, col);
if(cell && cell.length === 0 && (cell.borders || cell.rowSpan != null))
{
if(this.aResult[row + this.maxLengthRowCount][col][0].borders)
oNewItem.borders = this.aResult[row + this.maxLengthRowCount][col][0].borders;
if(this.aResult[row + this.maxLengthRowCount][col][0].rowSpan != null)
if(cell.borders)
{
oNewItem.borders = cell.borders;
}
if(cell.rowSpan != null)
{
oNewItem.rowSpan = this.aResult[row + this.maxLengthRowCount][col][0].rowSpan;
oNewItem.colSpan = this.aResult[row + this.maxLengthRowCount][col][0].colSpan;
oNewItem.rowSpan = cell.rowSpan;
oNewItem.colSpan = cell.colSpan;
}
delete this.aResult[row + this.maxLengthRowCount][col];
this.aResult.deleteCell(row + this.maxLengthRowCount, col)
};
if(!aResult[row])
aResult[row] = [];
//if(!aResult[row])
//aResult[row] = [];
var s = 0;
var c1 = col !== undefined ? col : activeRange.c1;
......@@ -2336,10 +2382,10 @@
fontFamily = formatText.format.fn;
this.fontsNew[fontFamily] = 1;
oNewItem.push(formatText);
oNewItem.content.push(formatText);
if(text !== null)
oNewItem[oNewItem.length - 1].text = text;
oNewItem.content[oNewItem.content.length - 1].text = text;
text = "";
};
......@@ -2348,17 +2394,11 @@
//проходимся по контенту paragraph
for(var n = 0; n < content.length; n++)
{
if(!aResult[row + this.maxLengthRowCount])
aResult[row + this.maxLengthRowCount] = [];
//s - меняется в зависимости от табуляции
if(!aResult[row + this.maxLengthRowCount][s + c1])
aResult[row + this.maxLengthRowCount][s + c1] = [];
this.aResult.getCell(row + this.maxLengthRowCount, s + c1);
if(text == null)
text = "";
switch(content[n].Type)
{
case para_Run://*paraRun*
......@@ -2402,79 +2442,6 @@
},
_getAlignHorisontal: function(paraPr)
{
var result;
var settings = paraPr.ParaPr;
if(!settings)
return;
switch(settings.Jc)
{
case 0:
{
result = "right";
break;
}
case 1:
{
result = "left";
break;
}
case 2:
{
result = "center";
break;
}
case 3:
{
result = null;
break;
}
};
return result;
},
getBackgroundColorTCell: function(elem)
{
var compiledPrCell, color;
var backgroundColor = null;
//TODO внутреннии таблицы без стиля - цвет фона белый
var tableCell = this._getParentByTag(elem, c_oAscBoundsElementType.Cell);
if(tableCell)
{
compiledPrCell = tableCell.elem.Get_CompiledPr();
if(compiledPrCell && compiledPrCell.Shd.Value !== 1/*shd_Nil*/)
{
var color = compiledPrCell.Shd.Color;
backgroundColor = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + color.r + "," + color.g + "," + color.b + ")"));
};
};
return backgroundColor;
},
_getParentByTag: function(elem, tag)
{
var result;
if(!elem)
return null;
if(elem.type == tag)
result = elem;
else if(elem.parent)
result = this._getParentByTag(elem.parent, tag);
else if(!elem.parent)
result = null;
return result;
},
_parseParaRun: function(paraRun, oNewItem, paraPr, s, row, c1, text)
{
var paraRunContent = paraRun.Content;
......@@ -2508,38 +2475,30 @@
case para_Tab://*paraEnd / paraTab*
{
//if(!oNewItem.length)
//{
this.fontsNew[paragraphFontFamily] = 1;
oNewItem.push(formatText);
//}
this.fontsNew[paragraphFontFamily] = 1;
oNewItem.content.push(formatText);
if(text !== null)
oNewItem[oNewItem.length - 1].text = text;
oNewItem.content[oNewItem.content.length - 1].text = text;
cloneNewItem = this._getCloneNewItem(oNewItem);
cloneNewItem = oNewItem.clone();
//переходим в следующую ячейку
if(typeof aResult[row + this.maxLengthRowCount][s + c1] == "object")
aResult[row + this.maxLengthRowCount][s + c1][aResult[row + this.maxLengthRowCount][s + c1].length] = cloneNewItem;
else
{
aResult[row + this.maxLengthRowCount][s + c1] = [];
aResult[row + this.maxLengthRowCount][s + c1][0] = cloneNewItem;
}
var cell = aResult.getCell(row + this.maxLengthRowCount, s + c1);
aResult.setCellContent(row + this.maxLengthRowCount, s + c1, cloneNewItem);
text = "";
oNewItem = [];
oNewItem = new pasteCell();
s++;
break;
};
case para_Drawing:
{
if(!aResult.addImagesFromWord)
aResult.addImagesFromWord = [];
aResult.addImagesFromWord[aResult.addImagesFromWord.length] = {image: paraRunContent[pR], col: s + c1, row: row};
if(!aResult.props.addImagesFromWord)
aResult.props.addImagesFromWord = [];
aResult.props.addImagesFromWord.push({image: paraRunContent[pR], col: s + c1, row: row});
if(null === this.isUsuallyPutImages)
this._addImageToMap(paraRunContent[pR]);
......@@ -2547,18 +2506,13 @@
case para_End:
{
if(typeof aResult[row][s + c1] == "object")
aResult[row][s + c1][aResult[row][s + c1].length] = oNewItem;
else
{
aResult[row][s + c1] = [];
aResult[row][s + c1][0] = oNewItem;
}
var cell = aResult.getCell(row, s + c1);
aResult.setCellContent(row, s + c1, oNewItem);
var checkMaxTextLength = this.clipboard._checkMaxTextLength(this.aResult, row + this.maxLengthRowCount, s + c1);
if(checkMaxTextLength)
{
aResult = checkMaxTextLength.aResult;
aResult.content = checkMaxTextLength.aResult.content;
this.maxLengthRowCount += checkMaxTextLength.r - row;
}
};
......@@ -2569,13 +2523,13 @@
{
this.fontsNew[paragraphFontFamily] = 1;
oNewItem.push(formatText);
oNewItem.content.push(formatText);
if(text !== null)
oNewItem[oNewItem.length - 1].text = text;
oNewItem.content[oNewItem.content.length - 1].text = text;
cloneNewItem = this._getCloneNewItem(oNewItem);
cloneNewItem = oNewItem.clone();
text = "";
};
......@@ -2586,18 +2540,141 @@
_addImageToMap: function(paraDrawing)
{
var aResult = this.aResult;
if(!aResult._aPastedImages)
aResult._aPastedImages = [];
if(!aResult._images)
aResult._images = [];
if(!aResult.props._aPastedImages)
aResult.props._aPastedImages = [];
if(!aResult.props._images)
aResult.props._images = [];
var oGraphicObj = paraDrawing.GraphicObj;
if(!oGraphicObj || (oGraphicObj && !oGraphicObj.blipFill) || (oGraphicObj && oGraphicObj.blipFill && !oGraphicObj.blipFill.RasterImageId))
return;
var sImageUrl = oGraphicObj.blipFill.RasterImageId;
aResult._aPastedImages[aResult._aPastedImages.length] = new AscCommon.CBuilderImages(oGraphicObj.blipFill, sImageUrl, oGraphicObj, oGraphicObj.spPr, null);
aResult._images[aResult._images.length] = sImageUrl;
aResult.props._aPastedImages.push(new AscCommon.CBuilderImages(oGraphicObj.blipFill, sImageUrl, oGraphicObj, oGraphicObj.spPr, null));
aResult.props._images.push(sImageUrl);
},
_getBorders: function(cellTable, top, left, oldBorders)
{
var borders = cellTable.elem.Get_Borders();
var widthCell = cellTable.width;
var heigthCell = cellTable.height;
var defaultStyle = "solid";
var borderStyleName;
var formatBorders = oldBorders ? oldBorders : new AscCommonExcel.Border();
//top border for cell
if(top == cellTable.top && !formatBorders.t.s && borders.Top.Value !== 0/*border_None*/)
{
borderStyleName = this.clipboard._getBorderStyleName(defaultStyle, this.ws.objectRender.convertMetric(borders.Top.Size,3,1));
if (null !== borderStyleName) {
formatBorders.t.setStyle(borderStyleName);
formatBorders.t.c = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + borders.Top.Color.r + "," + borders.Top.Color.g + "," + borders.Top.Color.b + ")"));
}
}
//left border for cell
if(left == cellTable.left && !formatBorders.l.s && borders.Left.Value !== 0/*border_None*/)
{
borderStyleName = this.clipboard._getBorderStyleName(defaultStyle, this.ws.objectRender.convertMetric(borders.Left.Size,3,1));
if (null !== borderStyleName) {
formatBorders.l.setStyle(borderStyleName);
formatBorders.l.c = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + borders.Left.Color.r + "," + borders.Left.Color.g + "," + borders.Left.Color.b + ")"));
}
}
//bottom border for cell
if(top == cellTable.top + heigthCell - 1 && !formatBorders.b.s && borders.Bottom.Value !== 0/*border_None*/)
{
borderStyleName = this.clipboard._getBorderStyleName(defaultStyle, this.ws.objectRender.convertMetric(borders.Bottom.Size,3,1));
if (null !== borderStyleName) {
formatBorders.b.setStyle(borderStyleName);
formatBorders.b.c = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + borders.Bottom.Color.r + "," + borders.Bottom.Color.g + "," + borders.Bottom.Color.b + ")"));
}
}
//right border for cell
if(left == cellTable.left + widthCell - 1 && !formatBorders.r.s && borders.Right.Value !== 0/*border_None*/)
{
borderStyleName = this.clipboard._getBorderStyleName(defaultStyle, this.ws.objectRender.convertMetric(borders.Right.Size,3,1));
if (null !== borderStyleName) {
formatBorders.r.setStyle(borderStyleName);
formatBorders.r.c = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + borders.Right.Color.r + "," + borders.Right.Color.g + "," + borders.Right.Color.b + ")"));
}
}
return formatBorders;
},
_getAlignHorisontal: function(paraPr)
{
var result;
var settings = paraPr.ParaPr;
if(!settings)
return;
switch(settings.Jc)
{
case 0:
{
result = "right";
break;
}
case 1:
{
result = "left";
break;
}
case 2:
{
result = "center";
break;
}
case 3:
{
result = null;
break;
}
};
return result;
},
getBackgroundColorTCell: function(elem)
{
var compiledPrCell, color;
var backgroundColor = null;
//TODO внутреннии таблицы без стиля - цвет фона белый
var tableCell = this._getParentByTag(elem, c_oAscBoundsElementType.Cell);
if(tableCell)
{
compiledPrCell = tableCell.elem.Get_CompiledPr();
if(compiledPrCell && compiledPrCell.Shd.Value !== 1/*shd_Nil*/)
{
var color = compiledPrCell.Shd.Color;
backgroundColor = new AscCommonExcel.RgbColor(this.clipboard._getBinaryColor("rgb(" + color.r + "," + color.g + "," + color.b + ")"));
};
};
return backgroundColor;
},
_getParentByTag: function(elem, tag)
{
var result;
if(!elem)
return null;
if(elem.type == tag)
result = elem;
else if(elem.parent)
result = this._getParentByTag(elem.parent, tag);
else if(!elem.parent)
result = null;
return result;
},
_getAllNumberingText: function(Lvl, numberingText)
......@@ -2647,22 +2724,6 @@
NumTextPr.Merge( TextPr_temp );
NumTextPr.Merge( NumLvl.TextPr );
/*var X_start = X;
if ( align_Right === NumJc )
X_start = X - NumberingItem.WidthNum;
else if ( align_Center === NumJc )
X_start = X - NumberingItem.WidthNum / 2;
NumTextPr.Unifill.check(PDSE.Theme, PDSE.ColorMap);
var RGBA = NumTextPr.Unifill.getRGBAColor();
if ( true === NumTextPr.Color.Auto )
pGraphics.b_color1( AutoColor.r, AutoColor.g, AutoColor.b, 255);
else
pGraphics.b_color1(RGBA.R, RGBA.G, RGBA.B, 255 );*/
// Рисуется только сам символ нумерации
var oNumPr = paragraph.Numbering_Get();
var LvlPr, Lvl;
......@@ -2904,25 +2965,6 @@
};
return formatText;
},
_getCloneNewItem: function(oNewItem)
{
var result = [];
for(var item = 0; item < oNewItem.length; item++)
{
result[item] = {text: oNewItem[item].text, format: oNewItem[item].format};
};
result.borders = oNewItem.borders;
result.rowSpan = oNewItem.rowSpan;
result.colSpan = oNewItem.colSpan;
result.toolTip = result.toolTip;
result.bc = oNewItem.bc;
result.hyperLink = oNewItem.hyperLink;
return result;
}
};
......
......@@ -9164,7 +9164,7 @@
break;
case "paste":
// Вставляем текст из локального буфера или нет
isLocal ? t._pasteFromLocalBuff( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth ) : t._pasteFromGlobalBuff( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth );
isLocal ? t._pasteData(isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth) : t._loadDataBeforePaste(isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth);
bIsUpdate = false;
break;
case "hyperlink":
......@@ -9207,7 +9207,7 @@
t._updateCellsRange( arn, canChangeColWidth );
}
//в случае, если вставляем из глобального буфера, транзакцию закрываем внутри функции _pasteFromGlobalBuff на callbacks от загрузки шрифтов и картинок
//в случае, если вставляем из глобального буфера, транзакцию закрываем внутри функции _loadDataBeforePaste на callbacks от загрузки шрифтов и картинок
if ( prop !== "paste" || (prop === "paste" && isLocal) ) {
History.EndTransaction();
}
......@@ -9218,7 +9218,7 @@
checkRange = t._pasteFromBinary( val, true );
}
else {
checkRange = t._setInfoAfterPaste( val, true );
checkRange = t._pasteFromHTML( val, true );
}
}
if ( "paste" === prop && val.onlyImages === true ) {
......@@ -9229,45 +9229,54 @@
}
};
WorksheetView.prototype._pasteFromLocalBuff = function ( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth ) {
WorksheetView.prototype._pasteData = function ( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth ) {
var t = this;
var callTrigger = false;
if ( isLargeRange ) {
if ( isLargeRange )
{
callTrigger = true;
t.handlers.trigger( "slowOperation", true );
}
t.model.workbook.lockDraw();
var selectData;
if ( isLocal === 'binary' ) {
if ( isLocal === 'binary' )
{
selectData = t._pasteFromBinary( val );
}
else {
selectData = t._setInfoAfterPaste( val );
else
{
selectData = t._pasteFromHTML( val );
}
t.model.autoFilters.renameTableColumn( t.activeRange );
if ( !selectData ) {
if ( !selectData )
{
bIsUpdate = false;
t.model.workbook.unLockDraw();
t.model.workbook.buildRecalc();
if ( callTrigger ) {
if ( callTrigger )
{
t.handlers.trigger( "slowOperation", false );
}
return;
}
this.expandColsOnScroll(false, true);
this.expandRowsOnScroll(false, true);
var arrFormula = selectData[1];
for ( var i = 0; i < arrFormula.length; ++i ) {//!!!
for ( var i = 0; i < arrFormula.length; ++i )
{
var rangeF = arrFormula[i].range;
var valF = arrFormula[i].val;
if ( rangeF.isOneCell() ) {
if ( rangeF.isOneCell() )
{
rangeF.setValue( valF, null, true );
}
else {
else
{
var oBBox = rangeF.getBBox0();
t.model._getCell( oBBox.r1, oBBox.c1 ).setValue( valF, null, true );
}
......@@ -9279,27 +9288,8 @@
var selectionRange = arn.clone( true );
//добавляем автофильтры и форматированные таблицы
if ( isLocal === true && val.lStorage && val.lStorage.autoFilters && val.lStorage.autoFilters.length ) {
var aFilters = val.lStorage.autoFilters;
var range;
for ( var aF = 0; aF < aFilters.length; aF++ ) {
range = t.model.getRange3( aFilters[aF].range.r1 + selectionRange.r1, aFilters[aF].range.c1 + selectionRange.c1, aFilters[aF].range.r2 + selectionRange.r1, aFilters[aF].range.c2 + selectionRange.c1 );
//если область вставки содержит форматированную таблицу, которая пересекается с вставляемой форматированной таблицей
var intersectionRangeWithTableParts = t.model.autoFilters._intersectionRangeWithTableParts( range.bbox );
if ( intersectionRangeWithTableParts )
continue;
if ( aFilters[aF].style ) {
range.cleanFormat();
}
t.model.autoFilters.addAutoFilter( aFilters[aF].style, range.bbox, true, true );
if ( !aFilters[aF].autoFilter ) {
t.model.autoFilters.addAutoFilter( null, range.bbox, true, true );
}
}
}
else if ( isLocal === 'binary' && val.TableParts && val.TableParts.length ) {
if ( isLocal === 'binary' && val.TableParts && val.TableParts.length )
{
var aFilters = val.TableParts;
var range;
var tablePartRange;
......@@ -9345,16 +9335,20 @@
//делаем unmerge ф/т
var arnToRange = t.activeRange;
var intersectionRangeWithTableParts = t.model.autoFilters._intersectionRangeWithTableParts( arnToRange );
if ( intersectionRangeWithTableParts && intersectionRangeWithTableParts.length ) {
if ( intersectionRangeWithTableParts && intersectionRangeWithTableParts.length )
{
var tablePart;
for ( var i = 0; i < intersectionRangeWithTableParts.length; i++ ) {
for ( var i = 0; i < intersectionRangeWithTableParts.length; i++ )
{
tablePart = intersectionRangeWithTableParts[i];
this.model.getRange3( tablePart.Ref.r1, tablePart.Ref.c1, tablePart.Ref.r2, tablePart.Ref.c2 ).unmerge();
}
}
if ( bIsUpdate ) {
if ( callTrigger ) {
if ( bIsUpdate )
{
if ( callTrigger )
{
t.handlers.trigger( "slowOperation", false );
}
t.isChanged = true;
......@@ -9362,7 +9356,8 @@
}
var oSelection = History.GetSelection();
if ( null != oSelection ) {
if ( null != oSelection )
{
oSelection = oSelection.clone();
oSelection.assign( selectionRange.c1, selectionRange.r1, selectionRange.c2, selectionRange.r2 );
History.SetSelection( oSelection );
......@@ -9370,28 +9365,25 @@
}
};
WorksheetView.prototype._pasteFromGlobalBuff = function ( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth ) {
WorksheetView.prototype._loadDataBeforePaste = function ( isLargeRange, isLocal, pasteContent, bIsUpdate, canChangeColWidth ) {
var t = this;
//загрузка шрифтов, в случае удачи на callback вставляем текст
t._loadFonts( val.fontsNew, function () {
t._loadFonts( pasteContent.props.fontsNew, function () {
var api = asc["editor"];
var isEndTransaction = false;
if ( val.addImages && val.addImages.length != 0 && !(window["Asc"]["editor"] && window["Asc"]["editor"].isChartEditor) ) {
if ( val.onlyImages !== true ) {
t._pasteFromLocalBuff( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth );
}
api.wb.clipboard.pasteProcessor._insertImagesFromHTML( t, val );
isEndTransaction = true;
}
else if ( val.addImagesFromWord && val.addImagesFromWord.length != 0 && !(window["Asc"]["editor"] && window["Asc"]["editor"].isChartEditor) ) {
var oObjectsForDownload = AscCommon.GetObjectsForImageDownload( val._aPastedImages );
if ( pasteContent.props.addImagesFromWord && pasteContent.props.addImagesFromWord.length != 0 && !(window["Asc"]["editor"] && window["Asc"]["editor"].isChartEditor) )
{
var oObjectsForDownload = AscCommon.GetObjectsForImageDownload( pasteContent.props._aPastedImages );
//if already load images on server
if ( api.wb.clipboard.pasteProcessor.alreadyLoadImagesOnServer === true ) {
if ( api.wb.clipboard.pasteProcessor.alreadyLoadImagesOnServer === true )
{
var oImageMap = {};
for ( var i = 0, length = oObjectsForDownload.aBuilderImagesByUrl.length; i < length; ++i ) {
for ( var i = 0, length = oObjectsForDownload.aBuilderImagesByUrl.length; i < length; ++i )
{
var url = oObjectsForDownload.aUrls[i];
//get name from array already load on server urls
......@@ -9413,52 +9405,56 @@
}
}
if ( val.onlyImages !== true ) {
t._pasteFromLocalBuff( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth );
if ( pasteContent.props.onlyImages !== true )
{
t._pasteData( isLargeRange, isLocal, pasteContent, bIsUpdate, canChangeColWidth );
}
api.wb.clipboard.pasteProcessor._insertImagesFromBinaryWord( t, val, oImageMap );
api.wb.clipboard.pasteProcessor._insertImagesFromBinaryWord( t, pasteContent, oImageMap );
isEndTransaction = true;
}
else {
else
{
AscCommon.sendImgUrls( api, oObjectsForDownload.aUrls, function ( data ) {
var oImageMap = {};
AscCommon.ResetNewUrls( data, oObjectsForDownload.aUrls, oObjectsForDownload.aBuilderImagesByUrl, oImageMap );
if ( val.onlyImages !== true ) {
t._pasteFromLocalBuff( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth );
if ( pasteContent.props.onlyImages !== true ) {
t._pasteData( isLargeRange, isLocal, pasteContent, bIsUpdate, canChangeColWidth );
}
api.wb.clipboard.pasteProcessor._insertImagesFromBinaryWord( t, val, oImageMap );
api.wb.clipboard.pasteProcessor._insertImagesFromBinaryWord( t, pasteContent, oImageMap );
//закрываем транзакцию, поскольку в setSelectionInfo она не закроется
History.EndTransaction();
}, true );
}
}
else if ( val.onlyImages !== true ) {
t._pasteFromLocalBuff( isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth );
else if ( pasteContent.props.onlyImages !== true )
{
t._pasteData( isLargeRange, isLocal, pasteContent, bIsUpdate, canChangeColWidth );
isEndTransaction = true;
}
//закрываем транзакцию, поскольку в setSelectionInfo она не закроется
if ( isEndTransaction ) {
if ( isEndTransaction )
{
History.EndTransaction();
}
} );
};
WorksheetView.prototype._setInfoAfterPaste = function ( values, isCheckSelection ) {
WorksheetView.prototype._pasteFromHTML = function ( pasteContent, isCheckSelection ) {
var t = this;
var wb = window["Asc"]["editor"].wb;
var arn = wb && wb.clipboard && wb.clipboard.pasteProcessor && wb.clipboard.pasteProcessor.activeRange ? wb.clipboard.pasteProcessor.activeRange : t.activeRange.clone( true );
var arrFormula = [];
var numFor = 0;
var rMax = values.length + values.rowSpanSpCount;
if ( values.rowCount && values.rowCount !== 0 && values.isOneTable ) {
rMax = values.rowCount + arn.r1;
var rMax = pasteContent.content.length + pasteContent.props.rowSpanSpCount;
if ( pasteContent.props.rowCount && pasteContent.props.rowCount !== 0 && pasteContent.props.isOneTable )
{
rMax = pasteContent.props.rowCount + arn.r1;
}
var cMax = values.cellCount + arn.c1;
var cMax = pasteContent.props.cellCount + arn.c1;
var isMultiple = false;
var firstCell = t.model.getRange3( arn.r1, arn.c1, arn.r1, arn.c1 );
......@@ -9468,47 +9464,60 @@
//если вставляем в мерженную ячейку, диапазон которой больше или равен
if ( arn.c2 >= cMax - 1 && arn.r2 >= rMax - 1 && isMergedFirstCell && isMergedFirstCell.c1 === arn.c1 && isMergedFirstCell.c2 === arn.c2 && isMergedFirstCell.r1 === arn.r1 && isMergedFirstCell.r2 === arn.r2 && cMax - arn.c1 === values[arn.r1][arn.c1][0].colSpan && rMax - arn.r1 === values[arn.r1][arn.c1][0].rowSpan ) {
if ( !isCheckSelection ) {
values[arn.r1][arn.c1][0].colSpan = isMergedFirstCell.c2 - isMergedFirstCell.c1 + 1;
values[arn.r1][arn.c1][0].rowSpan = isMergedFirstCell.r2 - isMergedFirstCell.r1 + 1;
if ( arn.c2 >= cMax - 1 && arn.r2 >= rMax - 1 && isMergedFirstCell && isMergedFirstCell.c1 === arn.c1 && isMergedFirstCell.c2 === arn.c2 && isMergedFirstCell.r1 === arn.r1 && isMergedFirstCell.r2 === arn.r2 && cMax - arn.c1 === pasteContent.content[arn.r1][arn.c1].colSpan && rMax - arn.r1 === pasteContent.content[arn.r1][arn.c1].rowSpan )
{
if ( !isCheckSelection )
{
pasteContent.content[arn.r1][arn.c1].colSpan = isMergedFirstCell.c2 - isMergedFirstCell.c1 + 1;
pasteContent.content[arn.r1][arn.c1].rowSpan = isMergedFirstCell.r2 - isMergedFirstCell.r1 + 1;
}
isOneMerge = true;
}
else if ( arn.c2 >= cMax - 1 && arn.r2 >= rMax - 1 && values.isOneTable ) {
else if ( arn.c2 >= cMax - 1 && arn.r2 >= rMax - 1 && pasteContent.props.isOneTable )
{
//если область кратная куску вставки
var widthArea = arn.c2 - arn.c1 + 1;
var heightArea = arn.r2 - arn.r1 + 1;
var widthPasteFr = cMax - arn.c1;
var heightPasteFr = rMax - arn.r1;
//если кратны, то обрабатываем
if ( widthArea % widthPasteFr === 0 && heightArea % heightPasteFr === 0 ) {
if ( widthArea % widthPasteFr === 0 && heightArea % heightPasteFr === 0 )
{
isMultiple = true;
}
else if ( firstCell.hasMerged() !== null )//в противном случае ошибка
{
if ( isCheckSelection ) {
if ( isCheckSelection )
{
return arn;
}
else {
else
{
this.handlers.trigger( "onError", c_oAscError.ID.PastInMergeAreaError, c_oAscError.Level.NoCritical );
return;
}
}
}
else {
else
{
//проверка на наличие части объединённой ячейки в области куда осуществляем вставку
for ( var rFirst = arn.r1; rFirst < rMax; ++rFirst ) {
for ( var cFirst = arn.c1; cFirst < cMax; ++cFirst ) {
for ( var rFirst = arn.r1; rFirst < rMax; ++rFirst )
{
for ( var cFirst = arn.c1; cFirst < cMax; ++cFirst )
{
range = t.model.getRange3( rFirst, cFirst, rFirst, cFirst );
var merged = range.hasMerged();
if ( merged ) {
if ( merged.r1 < arn.r1 || merged.r2 > rMax - 1 || merged.c1 < arn.c1 || merged.c2 > cMax - 1 ) {
if ( merged )
{
if ( merged.r1 < arn.r1 || merged.r2 > rMax - 1 || merged.c1 < arn.c1 || merged.c2 > cMax - 1 )
{
//ошибка в случае если вставка происходит в часть объедененной ячейки
if ( isCheckSelection ) {
if ( isCheckSelection )
{
return arn;
}
else {
else
{
this.handlers.trigger( "onErrorEvent", c_oAscError.ID.PastInMergeAreaError, c_oAscError.Level.NoCritical );
return;
}
......@@ -9517,29 +9526,33 @@
}
}
}
var rMax2 = rMax;
var cMax2 = cMax;
var rMax = values.length;
var rMax = pasteContent.content.length;
var trueArn = t.activeRange;
if ( isCheckSelection ) {
if ( isCheckSelection )
{
var newArr = arn.clone( true );
newArr.r2 = rMax2 - 1;
newArr.c2 = cMax2 - 1;
if ( isMultiple || isOneMerge ) {
if ( isMultiple || isOneMerge )
{
newArr.r2 = trueArn.r2;
newArr.c2 = trueArn.c2;
}
return newArr;
}
//если не возникает конфликт, делаем unmerge
rangeUnMerge.unmerge();
if ( !isOneMerge ) {
if ( !isOneMerge )
{
arn.r2 = (rMax2 - 1 > 0) ? (rMax2 - 1) : 0;
arn.c2 = (cMax2 - 1 > 0) ? (cMax2 - 1) : 0;
}
var mergeArr = [];
var n = 0;
if ( isMultiple )//случай автозаполнения сложных форм
{
......@@ -9549,39 +9562,51 @@
var plRow = (rMax2 - arn.r1);
var plCol = (arn.c2 - arn.c1) + 1;
}
else {
else
{
var maxARow = 1;
var maxACol = 1;
var plRow = 0;
var plCol = 0;
}
if ( isMultiple ) {
if ( values[arn.r1] && values[arn.r1][arn.c1] ) {
var currentObj = values[arn.r1][arn.c1][0];
if ( isMultiple )
{
if ( pasteContent.content[arn.r1] && pasteContent.content[arn.r1][arn.c1] )
{
var currentObj = pasteContent.content[arn.r1][arn.c1].content[0];
var valFormat = '';
if ( currentObj[0] !== undefined ) {
if ( currentObj[0] !== undefined )
{
valFormat = currentObj[0].text;
}
}
}
for ( var autoR = 0; autoR < maxARow; ++autoR ) {
for ( var autoC = 0; autoC < maxACol; ++autoC ) {
for ( var r = arn.r1; r < rMax; ++r ) {
for ( var c = arn.c1; c < values[r].length; ++c ) {
if ( undefined !== values[r][c] ) {
var mergeArr = [];
for ( var autoR = 0; autoR < maxARow; ++autoR )
{
for ( var autoC = 0; autoC < maxACol; ++autoC )
{
for ( var r = arn.r1; r < rMax; ++r )
{
for ( var c = arn.c1; c < pasteContent.content[r].length; ++c )
{
if ( undefined !== pasteContent.content[r][c] ) {
var range = t.model.getRange3( r + autoR * plRow, c + autoC * plCol, r + autoR * plRow, c + autoC * plCol );
var currentObj = values[r][c][0];
if ( currentObj.length === 1 ) {
//if(!isMultiple)
//{
var currentObj = pasteContent.content[r][c].content;
if ( currentObj.length === 1 )
{
var valFormat = currentObj[0].text;
var nameFormat = false;
//}
if ( currentObj[0].cellFrom ) {
if ( currentObj[0].cellFrom )
{
var offset = range.getCells()[0].getOffset2( currentObj[0].cellFrom ), assemb, _p_ = new AscCommonExcel.parserFormula( currentObj[0].text.substring( 1 ), "", range.worksheet );
if ( _p_.parse() ) {
if ( _p_.parse() )
{
assemb = _p_.changeOffset( offset ).assemble();
//range.setValue("="+assemb);
arrFormula[numFor] = {};
......@@ -9590,16 +9615,20 @@
numFor++;
}
}
else {
else
{
range.setValue( valFormat );
}
if ( nameFormat ) {
if ( nameFormat )
{
range.setNumFormat( nameFormat );
}
range.setBold( currentObj[0].format.b );
range.setItalic( currentObj[0].format.i );
range.setStrikeout( currentObj[0].format.s );
if ( !isOneMerge && currentObj[0].format && currentObj[0].format.c != null && currentObj[0].format.c != undefined ) {
if ( !isOneMerge && currentObj[0].format && currentObj[0].format.c != null && currentObj[0].format.c != undefined )
{
range.setFontcolor( currentObj[0].format.c );
}
range.setUnderline( currentObj[0].format.u );
......@@ -9607,54 +9636,68 @@
range.setFontname( currentObj[0].format.fn );
range.setFontsize( currentObj[0].format.fs );
}
else {
else
{
range.setValue2( currentObj );
range.setAlignVertical( currentObj.va );
}
if ( currentObj.length === 1 && currentObj[0].format.fs !== '' && currentObj[0].format.fs !== null && currentObj[0].format.fs !== undefined ) {
if ( currentObj.length === 1 && currentObj[0].format.fs !== '' && currentObj[0].format.fs !== null && currentObj[0].format.fs !== undefined )
{
range.setFontsize( currentObj[0].format.fs );
}
if ( !isOneMerge ) {
if ( !isOneMerge )
{
range.setAlignHorizontal( currentObj.a );
}
var isMerged = false;
for ( var mergeCheck = 0; mergeCheck < mergeArr.length; ++mergeCheck ) {
if ( r + 1 + autoR * plRow <= mergeArr[mergeCheck].r2 && r + 1 + autoR * plRow >= mergeArr[mergeCheck].r1 && c + autoC * plCol + 1 <= mergeArr[mergeCheck].c2 && c + 1 + autoC * plCol >= mergeArr[mergeCheck].c1 ) {
for ( var mergeCheck = 0; mergeCheck < mergeArr.length; ++mergeCheck )
{
if ( r + 1 + autoR * plRow <= mergeArr[mergeCheck].r2 && r + 1 + autoR * plRow >= mergeArr[mergeCheck].r1 && c + autoC * plCol + 1 <= mergeArr[mergeCheck].c2 && c + 1 + autoC * plCol >= mergeArr[mergeCheck].c1 )
{
isMerged = true;
}
}
//обработка для мерженных ячеек
if ( (currentObj.colSpan > 1 || currentObj.rowSpan > 1) && !isMerged ) {
if ( (currentObj.colSpan > 1 || currentObj.rowSpan > 1) && !isMerged )
{
range.setOffsetLast( {offsetCol: currentObj.colSpan - 1, offsetRow: currentObj.rowSpan - 1} );
mergeArr[n] = {
r1: range.first.row, r2: range.last.row, c1: range.first.col, c2: range.last.col
};
n++;
if ( currentObj[0] == undefined ) {
if ( currentObj[0] == undefined )
{
range.setValue( '' );
}
range.merge( c_oAscMergeOptions.Merge );
}
if ( !isOneMerge ) {
if ( !isOneMerge )
{
range.setBorderSrc( currentObj.borders );
}
range.setWrap( currentObj.wrap );
if ( currentObj.bc && currentObj.bc.rgb ) {
if ( currentObj.bc && currentObj.bc.rgb )
{
range.setFill( currentObj.bc );
}
var link = values[r][c][0].hyperLink;
if ( link ) {
var link = pasteContent.content[r][c].hyperLink;
if ( link )
{
var newHyperlink = new AscCommonExcel.Hyperlink();
if ( values[r][c][0].hyperLink.search( '#' ) === 0 ) {
if ( pasteContent.content[r][c].hyperLink.search( '#' ) === 0 )
{
newHyperlink.setLocation( link.replace( '#', '' ) );
}
else {
else
{
newHyperlink.Hyperlink = link;
}
newHyperlink.Ref = range;
newHyperlink.Tooltip = values[r][c][0].toolTip;
newHyperlink.Tooltip = pasteContent.content[r][c].toolTip;
range.setHyperlink( newHyperlink );
}
}
......@@ -9662,7 +9705,9 @@
}
}
}
if ( isMultiple ) {
if ( isMultiple )
{
arn.r2 = trueArn.r2;
arn.c2 = trueArn.c2;
}
......
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