Commit a0fcce52 authored by Igor.Zotov's avatar Igor.Zotov Committed by Alexander.Trofimov

paste html в excel через PasteProcessor

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@62717 954022d7-b5bf-4e40-9824-e11837661b57
parent 1f7dfe70
...@@ -6213,7 +6213,8 @@ PasteProcessor.prototype = ...@@ -6213,7 +6213,8 @@ PasteProcessor.prototype =
{ {
var oThis = this; var oThis = this;
var table = row.Table; var table = row.Table;
if(null != spacing && spacing >= tableSpacingMinValue) var oTableSpacingMinValue = ("undefined" != typeof tableSpacingMinValue) ? tableSpacingMinValue : 0.02;
if(null != spacing && spacing >= oTableSpacingMinValue)
row.Set_CellSpacing(spacing); row.Set_CellSpacing(spacing);
if(node.style.height) if(node.style.height)
{ {
...@@ -6560,8 +6561,8 @@ PasteProcessor.prototype = ...@@ -6560,8 +6561,8 @@ PasteProcessor.prototype =
} }
} }
var sSrc = node.getAttribute("src"); var sSrc = node.getAttribute("src");
if(isNaN(nWidth) || isNaN(nHeight) || !(typeof nWidth === "number") || !(typeof nHeight === "number") if((!window["Asc"] || (window["Asc"] && window["Asc"]["editor"] === undefined)) && (isNaN(nWidth) || isNaN(nHeight) || !(typeof nWidth === "number") || !(typeof nHeight === "number")//первое условие - мы не в редакторе таблиц, тогда выполняем
|| nWidth === 0 || nHeight === 0) || nWidth === 0 || nHeight === 0))
{ {
var img_prop = new asc_CImgProperty(); var img_prop = new asc_CImgProperty();
img_prop.asc_putImageUrl(sSrc); img_prop.asc_putImageUrl(sSrc);
...@@ -7757,3 +7758,58 @@ function Editor_CopyPaste_Create(api) ...@@ -7757,3 +7758,58 @@ function Editor_CopyPaste_Create(api)
document.body.appendChild( ElemToSelect ); document.body.appendChild( ElemToSelect );
} }
function CreateImageFromBinary(bin, nW, nH)
{
var w, h;
if (nW === undefined || nH === undefined)
{
var _image = editor.ImageLoader.map_image_index[bin];
if (_image != undefined && _image.Image != null && _image.Status == ImageLoadStatus.Complete)
{
var _w = Math.max(1, Page_Width - (X_Left_Margin + X_Right_Margin));
var _h = Math.max(1, Page_Height - (Y_Top_Margin + Y_Bottom_Margin));
var bIsCorrect = false;
if (_image.Image != null)
{
var __w = Math.max(parseInt(_image.Image.width * g_dKoef_pix_to_mm), 1);
var __h = Math.max(parseInt(_image.Image.height * g_dKoef_pix_to_mm), 1);
var dKoef = Math.max(__w / _w, __h / _h);
if (dKoef > 1)
{
_w = Math.max(5, __w / dKoef);
_h = Math.max(5, __h / dKoef);
bIsCorrect = true;
}
else
{
_w = __w;
_h = __h;
}
}
w = __w;
h = __h;
}
else
{
w = 50;
h = 50;
}
}
else
{
w = nW;
h = nH;
}
var para_drawing = new ParaDrawing(w, h, null, editor.WordControl.m_oLogicDocument.DrawingDocument, editor.WordControl.m_oLogicDocument, null);
var word_image = DrawingObjectsController.prototype.createImage(bin, 0, 0, w, h);
para_drawing.Set_GraphicObject(word_image);
word_image.setParent(para_drawing);
para_drawing.Set_GraphicObject(word_image);
return para_drawing;
}
\ No newline at end of file
...@@ -358,8 +358,6 @@ ...@@ -358,8 +358,6 @@
if(window.USER_AGENT_SAFARI_MACOS && !worksheet.isCellEditMode) if(window.USER_AGENT_SAFARI_MACOS && !worksheet.isCellEditMode)
{ {
this._startCopyOrPaste();
this.element.appendChild(text); this.element.appendChild(text);
History.TurnOff(); History.TurnOff();
...@@ -383,13 +381,11 @@ ...@@ -383,13 +381,11 @@
} }
History.TurnOn(); History.TurnOn();
this._endCopyOrPaste();
return sBase64; return sBase64;
} }
else else
{ {
this._startCopyOrPaste();
//исключения для opera в случае копирования пустой html //исключения для opera в случае копирования пустой html
if($(text).find('td')[0] && $(text).find('td')[0].innerText == '' && AscBrowser.isOpera) if($(text).find('td')[0] && $(text).find('td')[0].innerText == '' && AscBrowser.isOpera)
$(text).find('td')[0].innerHTML = ' '; $(text).find('td')[0].innerHTML = ' ';
...@@ -450,8 +446,6 @@ ...@@ -450,8 +446,6 @@
t._selectElement(t._getStylesSelect); t._selectElement(t._getStylesSelect);
else else
t._selectElement(); t._selectElement();
this._endCopyOrPaste();
} }
}, },
...@@ -468,8 +462,6 @@ ...@@ -468,8 +462,6 @@
if(text == false) if(text == false)
return; return;
this._startCopyOrPaste();
t.element.appendChild(text); t.element.appendChild(text);
...@@ -504,8 +496,6 @@ ...@@ -504,8 +496,6 @@
t._selectElement(t._getStylesSelect); t._selectElement(t._getStylesSelect);
else else
t._selectElement();*/ t._selectElement();*/
this._endCopyOrPaste();
}, },
_getBinaryForCopy: function(worksheet) _getBinaryForCopy: function(worksheet)
...@@ -739,8 +729,6 @@ ...@@ -739,8 +729,6 @@
copyCellValue: function (value) { copyCellValue: function (value) {
var t = this; var t = this;
t._startCopyOrPaste();
if(activateLocalStorage || copyPasteUseBinary) if(activateLocalStorage || copyPasteUseBinary)
t._addValueToLocalStrg(value); t._addValueToLocalStrg(value);
var nodes = t._makeNodesFromCellValue(value); var nodes = t._makeNodesFromCellValue(value);
...@@ -763,8 +751,6 @@ ...@@ -763,8 +751,6 @@
t._selectElement(t._getStylesSelect, true); t._selectElement(t._getStylesSelect, true);
else else
t._selectElement(); t._selectElement();
this._endCopyOrPaste();
}, },
copyCellValueButton: function (value) { copyCellValueButton: function (value) {
...@@ -856,8 +842,6 @@ ...@@ -856,8 +842,6 @@
var t = this; var t = this;
t.elementText.style.display = "block"; t.elementText.style.display = "block";
t._startCopyOrPaste();
t.elementText.value = '\xa0'; t.elementText.value = '\xa0';
t.elementText.focus(); t.elementText.focus();
t.elementText.select(); t.elementText.select();
...@@ -897,8 +881,6 @@ ...@@ -897,8 +881,6 @@
callback(textInsert, []); callback(textInsert, []);
if(AscBrowser.isMozilla) if(AscBrowser.isMozilla)
t._getStylesSelect(); t._getStylesSelect();
t._endCopyOrPaste();
}, },
_interval_time); _interval_time);
}, },
...@@ -1015,8 +997,6 @@ ...@@ -1015,8 +997,6 @@
if(window.USER_AGENT_SAFARI_MACOS) if(window.USER_AGENT_SAFARI_MACOS)
return; return;
this._startCopyOrPaste();
var t = this; var t = this;
window.GlobalPasteFlagCounter = 1; window.GlobalPasteFlagCounter = 1;
isTruePaste = false; isTruePaste = false;
...@@ -1093,8 +1073,6 @@ ...@@ -1093,8 +1073,6 @@
if(!isTruePaste) if(!isTruePaste)
t._editorPasteExec(worksheet, pastebin); t._editorPasteExec(worksheet, pastebin);
t._endCopyOrPaste();
pastebin.style.display = ELEMENT_DISPAY_STYLE2; pastebin.style.display = ELEMENT_DISPAY_STYLE2;
if(AscBrowser.isIE) if(AscBrowser.isIE)
...@@ -1359,8 +1337,6 @@ ...@@ -1359,8 +1337,6 @@
document.body.appendChild(ifr); document.body.appendChild(ifr);
}; };
this._startCopyOrPaste();
ifr.style.display = "block"; ifr.style.display = "block";
var frameWindow = window.frames["pasteFrame"]; var frameWindow = window.frames["pasteFrame"];
if(frameWindow) if(frameWindow)
...@@ -1389,8 +1365,6 @@ ...@@ -1389,8 +1365,6 @@
e.preventDefault(); e.preventDefault();
} }
this._endCopyOrPaste();
return false; return false;
} }
}, },
...@@ -2250,7 +2224,7 @@ ...@@ -2250,7 +2224,7 @@
onlyFromLocalStorage = null; onlyFromLocalStorage = null;
node = this.element; node = this.element;
pasteFragment = node; pasteFragment = node;
}; }
//если находимся внутри шейпа //если находимся внутри шейпа
var isIntoShape = worksheet.objectRender.controller.getTargetDocContent(); var isIntoShape = worksheet.objectRender.controller.getTargetDocContent();
...@@ -2260,7 +2234,7 @@ ...@@ -2260,7 +2234,7 @@
var resultPasteInShape = this._pasteInShape(worksheet, node, onlyFromLocalStorage, isIntoShape); var resultPasteInShape = this._pasteInShape(worksheet, node, onlyFromLocalStorage, isIntoShape);
if(resultPasteInShape == true) if(resultPasteInShape == true)
return; return;
}; }
//****binary**** //****binary****
if(copyPasteUseBinary) if(copyPasteUseBinary)
...@@ -2274,16 +2248,38 @@ ...@@ -2274,16 +2248,38 @@
{ {
pasteFragment = binaryResult; pasteFragment = binaryResult;
node = binaryResult; node = binaryResult;
}; }
}; }
this.activeRange = worksheet.activeRange.clone(true); this.activeRange = worksheet.activeRange.clone(true);
//parse HTML History.TurnOff();
aResult = this._parseHtml(pasteFragment, node, worksheet, isText);
if(aResult) var t = this;
this._correctImageUrl(aResult, worksheet); var oPasteProcessor;
var oTempDrawingDocument = worksheet.model.DrawingDocument;
var newCDocument = new CDocument(oTempDrawingDocument);
newCDocument.bFromDocument = true;
//TODo!!!!!!
newCDocument.Content[0].bFromDocument = true;
newCDocument.theme = this.Api.wbModel.theme;
oTempDrawingDocument.m_oLogicDocument = newCDocument;
var oOldEditor = undefined;
if ("undefined" != typeof editor)
oOldEditor = editor;
editor = {WordControl: oTempDrawingDocument, isDocumentEditor: true};
var oPasteProcessor = new PasteProcessor({WordControl:{m_oLogicDocument: newCDocument}, FontLoader: {}}, false, false);
oPasteProcessor._Prepeare_recursive(node, true, true)
oPasteProcessor._Execute(node, {}, true, true, false);
editor = oOldEditor;
History.TurnOn();
var pasteFromBinaryWord = new Asc.pasteFromBinaryWord(t, worksheet);
pasteFromBinaryWord._paste(worksheet, {content: oPasteProcessor.aContent});
window.GlobalPasteFlagCounter = 0;
window.GlobalPasteFlag = false;
}, },
_correctImageUrl: function (aResult, worksheet) _correctImageUrl: function (aResult, worksheet)
...@@ -2634,6 +2630,16 @@ ...@@ -2634,6 +2630,16 @@
} }
} }
aResult[rowCountTrue][tC] = t._getArray(_tBody,isText); aResult[rowCountTrue][tC] = t._getArray(_tBody,isText);
var changeAResult = t._checkMaxTextLength(aResult, rowCountTrue, tC);
if(changeAResult)
{
aResult = changeAResult.aResult;
rowCountTrue = changeAResult.r;
tC = changeAResult.c;
}
if(undefined != _tBody && (_tBody.colSpan > 1 || _tBody.rowSpan > 1)) if(undefined != _tBody && (_tBody.colSpan > 1 || _tBody.rowSpan > 1))
{ {
mergeArr[n++] = { mergeArr[n++] = {
...@@ -2801,6 +2807,50 @@ ...@@ -2801,6 +2807,50 @@
return false; return false;
}, },
_checkMaxTextLength: function(aResult, r, c)
{
var result = false;
var isChange = false;
var currentCellData = aResult[r][c];
if(currentCellData && currentCellData[0])
{
currentCellData = currentCellData[0];
for(var i = 0; i < currentCellData.length; i++)
{
if(currentCellData[i] && currentCellData[i].text && currentCellData[i].text.length > c_oAscMaxCellOrCommentLength)
{
isChange = true;
var text = currentCellData[i].text;
var lengthOfText = text.length;
var iterCount = Math.ceil(lengthOfText / c_oAscMaxCellOrCommentLength);
var splitText;
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] = [];
aResult[r][c][0] = currentCellData;
aResult[r][c][0][0].text = splitText;
if(iterCount !== j + 1)
r++;
}
}
}
if(isChange)
result = {aResult: aResult, r: r, c: c};
}
return result;
},
_selectElement: function (callback, copyCellValue) { _selectElement: function (callback, copyCellValue) {
var t = this, selection, rangeToSelect, overflowBody, firstWidth; var t = this, selection, rangeToSelect, overflowBody, firstWidth;
...@@ -2814,8 +2864,6 @@ ...@@ -2814,8 +2864,6 @@
else else
document.body.style.overflow = 'hidden'; document.body.style.overflow = 'hidden';
this._startCopyOrPaste();
if (window.getSelection) {// all browsers, except IE before version 9 if (window.getSelection) {// all browsers, except IE before version 9
selection = window.getSelection(); selection = window.getSelection();
rangeToSelect = doc.createRange(); rangeToSelect = doc.createRange();
...@@ -2855,7 +2903,6 @@ ...@@ -2855,7 +2903,6 @@
doc.body.style["user-select"] = "none"; doc.body.style["user-select"] = "none";
doc.body.style["-webkit-user-select"] = "none"; doc.body.style["-webkit-user-select"] = "none";
t._endCopyOrPaste();
t.element.style.MozUserSelect = "none"; t.element.style.MozUserSelect = "none";
if(firstWidth) if(firstWidth)
...@@ -3884,32 +3931,7 @@ ...@@ -3884,32 +3931,7 @@
} }
return bin; return bin;
},
_startCopyOrPaste: function()
{
if(window.USER_AGENT_MACOS)
{
//this.element.style.width = "10000px";
//this.elementText.style.width = "10000px";
//var ifr = document.getElementById("pasteFrame");
//if(ifr)
//ifr.style.width = "10000px";
} }
},
_endCopyOrPaste: function()
{
if(window.USER_AGENT_MACOS)
{
//this.element.style.width = "100px";
//this.elementText.style.width = "100px";
//var ifr = document.getElementById("pasteFrame");
//if(ifr)
//ifr.style.width = "100px";
}
}
}; };
/** @constructor */ /** @constructor */
...@@ -3920,6 +3942,7 @@ ...@@ -3920,6 +3942,7 @@
this.aResult = []; this.aResult = [];
this.clipboard = clipboard; this.clipboard = clipboard;
this.ws = ws; this.ws = ws;
this.isUsuallyPutImages = null;
return this; return this;
} }
...@@ -3930,6 +3953,8 @@ ...@@ -3930,6 +3953,8 @@
{ {
var documentContent = pasteData.content; var documentContent = pasteData.content;
var activeRange = worksheet.activeRange.clone(true); var activeRange = worksheet.activeRange.clone(true);
if(pasteData.images && pasteData.images.length)
this.isUsuallyPutImages = true;
if(documentContent && documentContent.length) if(documentContent && documentContent.length)
{ {
...@@ -3941,8 +3966,8 @@ ...@@ -3941,8 +3966,8 @@
this.aResult.fontsNew = this.fontsNew; this.aResult.fontsNew = this.fontsNew;
this.aResult.rowSpanSpCount = 0; this.aResult.rowSpanSpCount = 0;
this.aResult.cellCount = coverDocument.width; this.aResult.cellCount = coverDocument.width;
this.aResult._images = pasteData.images; this.aResult._images = pasteData.images ? pasteData.images : this.aResult._images;
this.aResult._aPastedImages = pasteData.aPastedImages; this.aResult._aPastedImages = pasteData.aPastedImages ? pasteData.aPastedImages : this.aResult._aPastedImages;
worksheet.setSelectionInfo('paste', this.aResult, this); worksheet.setSelectionInfo('paste', this.aResult, this);
}, },
...@@ -4176,9 +4201,22 @@ ...@@ -4176,9 +4201,22 @@
break; break;
}; };
case para_Hyperlink://*hyperLink* case para_Hyperlink://*hyperLink*
{
//если несколько ссылок в одном параграфе, то отменяем ссылки
if(!oNewItem.doNotApplyHyperlink)
{
if(!oNewItem.hyperLink)
{ {
oNewItem.hyperLink = content[n].Value; oNewItem.hyperLink = content[n].Value;
oNewItem.toolTip = content[n].ToolTip; oNewItem.toolTip = content[n].ToolTip;
}
else
{
oNewItem.hyperLink = null;
oNewItem.toolTip = null;
oNewItem.doNotApplyHyperlink = true;
}
}
for(var h = 0; h < content[n].Content.length; h++) for(var h = 0; h < content[n].Content.length; h++)
{ {
...@@ -4336,6 +4374,9 @@ ...@@ -4336,6 +4374,9 @@
if(!aResult.addImagesFromWord) if(!aResult.addImagesFromWord)
aResult.addImagesFromWord = []; aResult.addImagesFromWord = [];
aResult.addImagesFromWord[aResult.addImagesFromWord.length] = {image: paraRunContent[pR], col: s + c1, row: row}; aResult.addImagesFromWord[aResult.addImagesFromWord.length] = {image: paraRunContent[pR], col: s + c1, row: row};
if(null === this.isUsuallyPutImages)
this._addImageToMap(paraRunContent[pR]);
}; };
case para_End: case para_End:
...@@ -4369,6 +4410,20 @@ ...@@ -4369,6 +4410,20 @@
return s; return s;
}, },
_addImageToMap: function(paraDrawing)
{
var aResult = this.aResult;
if(!aResult._aPastedImages)
aResult._aPastedImages = [];
if(!aResult._images)
aResult._images = [];
var oGraphicObj = paraDrawing.GraphicObj;
var sImageUrl = oGraphicObj.blipFill.RasterImageId;
aResult._aPastedImages[aResult._aPastedImages.length] = new CBuilderImages(oGraphicObj.blipFill, sImageUrl, null, oGraphicObj.spPr, null);
aResult._images[aResult._images.length] = sImageUrl;
},
_getAllNumberingText: function(Lvl, numberingText) _getAllNumberingText: function(Lvl, numberingText)
{ {
var preSpace, beetweenSpace, result; var preSpace, beetweenSpace, result;
......
...@@ -8326,16 +8326,18 @@ ...@@ -8326,16 +8326,18 @@
//загрузка шрифтов, в случае удачи на callback вставляем текст //загрузка шрифтов, в случае удачи на callback вставляем текст
t._loadFonts(val.fontsNew, function () { t._loadFonts(val.fontsNew, function () {
if(val.onlyImages !== true)
t._pasteFromLocalBuff(isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth);
var api = asc["editor"]; var api = asc["editor"];
if (val.addImages && val.addImages.length != 0 && !(window["Asc"]["editor"] && window["Asc"]["editor"].isChartEditor)) 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._insertImagesFromHTML(t, val); api.wb.clipboard._insertImagesFromHTML(t, val);
} }
else if(val.addImagesFromWord && val.addImagesFromWord.length != 0 && !(window["Asc"]["editor"] && window["Asc"]["editor"].isChartEditor)) else if(val.addImagesFromWord && val.addImagesFromWord.length != 0 && !(window["Asc"]["editor"] && window["Asc"]["editor"].isChartEditor))
{ {
//показываем плашку для отправки изображений на сервер
api.handlers.trigger("asc_onStartAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
var rData = {"id": api.documentId, "c":"imgurls", "vkey": api.documentVKey, "data": JSON.stringify(val._images)}; var rData = {"id": api.documentId, "c":"imgurls", "vkey": api.documentVKey, "data": JSON.stringify(val._images)};
api._asc_sendCommand(function(incomeObject){ api._asc_sendCommand(function(incomeObject){
if(incomeObject && "imgurls" == incomeObject.type) if(incomeObject && "imgurls" == incomeObject.type)
...@@ -8360,10 +8362,16 @@ ...@@ -8360,10 +8362,16 @@
} }
} }
} }
api.handlers.trigger("asc_onEndAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
if(val.onlyImages !== true)
t._pasteFromLocalBuff(isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth);
api.wb.clipboard._insertImagesFromBinaryWord(t, val, aImagesSync); api.wb.clipboard._insertImagesFromBinaryWord(t, val, aImagesSync);
}, rData ); }, rData );
} }
else if(val.onlyImages !== true)
t._pasteFromLocalBuff(isLargeRange, isLocal, val, bIsUpdate, canChangeColWidth);
History.EndTransaction(); History.EndTransaction();
}); });
......
...@@ -2865,60 +2865,3 @@ function ComparisonByZIndexSimple(obj1, obj2) ...@@ -2865,60 +2865,3 @@ function ComparisonByZIndexSimple(obj1, obj2)
return 1; return 1;
return 0; return 0;
} }
function CreateImageFromBinary(bin, nW, nH)
{
var w, h;
if (nW === undefined || nH === undefined)
{
var _image = editor.ImageLoader.map_image_index[bin];
if (_image != undefined && _image.Image != null && _image.Status == ImageLoadStatus.Complete)
{
var _w = Math.max(1, Page_Width - (X_Left_Margin + X_Right_Margin));
var _h = Math.max(1, Page_Height - (Y_Top_Margin + Y_Bottom_Margin));
var bIsCorrect = false;
if (_image.Image != null)
{
var __w = Math.max(parseInt(_image.Image.width * g_dKoef_pix_to_mm), 1);
var __h = Math.max(parseInt(_image.Image.height * g_dKoef_pix_to_mm), 1);
var dKoef = Math.max(__w / _w, __h / _h);
if (dKoef > 1)
{
_w = Math.max(5, __w / dKoef);
_h = Math.max(5, __h / dKoef);
bIsCorrect = true;
}
else
{
_w = __w;
_h = __h;
}
}
w = __w;
h = __h;
}
else
{
w = 50;
h = 50;
}
}
else
{
w = nW;
h = nH;
}
var para_drawing = new ParaDrawing(w, h, null, editor.WordControl.m_oLogicDocument.DrawingDocument, editor.WordControl.m_oLogicDocument, null);
var word_image = editor.WordControl.m_oLogicDocument.DrawingObjects.createImage(bin, 0, 0, w, h);
para_drawing.Set_GraphicObject(word_image);
word_image.setParent(para_drawing);
para_drawing.Set_GraphicObject(word_image);
return para_drawing;
}
\ No newline at end of file
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