Commit aad61903 authored by Sergey Luzyanin's avatar Sergey Luzyanin Committed by GitHub

Merge pull request #54 from ONLYOFFICE/release/v4.1.0

inserting ole objects in cell editor
parents 31544bae 9cca4eb0
...@@ -2357,6 +2357,29 @@ var editor; ...@@ -2357,6 +2357,29 @@ var editor;
this.handlers.trigger("asc_onEndAddShape"); this.handlers.trigger("asc_onEndAddShape");
}; };
spreadsheet_api.prototype.asc_addOleObjectAction = function(sLocalUrl, sData, sApplicationId, fWidth, fHeight, nWidthPix, nHeightPix)
{
var _image = this.ImageLoader.LoadImage(AscCommon.getFullImageSrc2(sLocalUrl), 1);
if (null != _image){
var ws = this.wb.getWorksheet();
if(ws.objectRender){
ws.objectRender.addOleObject(fWidth, fHeight, nWidthPix, nHeightPix, sLocalUrl, sData, sApplicationId);
}
}
};
spreadsheet_api.prototype.asc_editOleObjectAction = function(bResize, oOleObject, sImageUrl, sData, nPixWidth, nPixHeight)
{
if (oOleObject)
{
var ws = this.wb.getWorksheet();
if(ws.objectRender){
ws.objectRender.editOleObject(oOleObject, sData, sImageUrl, nPixWidth, nPixHeight, bResize);
}
}
};
spreadsheet_api.prototype.asc_isAddAutoshape = function() { spreadsheet_api.prototype.asc_isAddAutoshape = function() {
return this.isStartAddShape; return this.isStartAddShape;
}; };
......
...@@ -306,6 +306,22 @@ DrawingObjectsController.prototype.handleChartDoubleClick = function() ...@@ -306,6 +306,22 @@ DrawingObjectsController.prototype.handleChartDoubleClick = function()
this.checkSelectedObjectsAndFireCallback(function(){ this.checkSelectedObjectsAndFireCallback(function(){
drawingObjects.showChartSettings(); drawingObjects.showChartSettings();
}, []); }, []);
}
DrawingObjectsController.prototype.handleOleObjectDoubleClick = function(drawing, oleObject, e, x, y, pageIndex)
{
var drawingObjects = this.drawingObjects;
this.checkSelectedObjectsAndFireCallback(function(){
var pluginData = new Asc.CPluginData();
pluginData.setAttribute("data", oleObject.m_sData);
pluginData.setAttribute("guid", oleObject.m_sApplicationId);
pluginData.setAttribute("width", oleObject.extX);
pluginData.setAttribute("height", oleObject.extY);
pluginData.setAttribute("widthPix", oleObject.m_nPixWidth);
pluginData.setAttribute("heightPix", oleObject.m_nPixHeight);
pluginData.setAttribute("objectId", oleObject.Id);
window["Asc"]["editor"].asc_pluginRun(oleObject.m_sApplicationId, 0, pluginData);
this.onMouseUp(e, x, y);
}, []);
}; };
DrawingObjectsController.prototype.addChartDrawingObject = function(options) DrawingObjectsController.prototype.addChartDrawingObject = function(options)
...@@ -406,6 +422,31 @@ DrawingObjectsController.prototype.addImageFromParams = function(rasterImageId, ...@@ -406,6 +422,31 @@ DrawingObjectsController.prototype.addImageFromParams = function(rasterImageId,
this.startRecalculate(); this.startRecalculate();
}; };
DrawingObjectsController.prototype.addOleObjectFromParams = function(fPosX, fPosY, fWidth, fHeight, nWidthPix, nHeightPix, sLocalUrl, sData, sApplicationId){
History.Create_NewPoint();
var oOleObject = this.createOleObject(sData, sApplicationId, sLocalUrl, fPosX, fPosY, fWidth, fHeight, nWidthPix, nHeightPix);
this.resetSelection();
oOleObject.setWorksheet(this.drawingObjects.getWorksheetModel());
oOleObject.setDrawingObjects(this.drawingObjects);
oOleObject.addToDrawingObjects();
oOleObject.checkDrawingBaseCoords();
this.selectObject(oOleObject, 0);
oOleObject.addToRecalculate();
this.startRecalculate();
};
DrawingObjectsController.prototype.editOleObjectFromParams = function(oOleObject, sData, sImageUrl, nPixWidth, nPixHeight, bResize){
if(!bResize){
History.Create_NewPoint();
}
oOleObject.setData(sData);
var _blipFill = new AscFormat.CBlipFill();
_blipFill.RasterImageId = sImageUrl;
oOleObject.setBlipFill(_blipFill);
oOleObject.setPixSizes(nPixWidth, nPixHeight);
this.startRecalculate();
};
DrawingObjectsController.prototype.addTextArtFromParams = function(nStyle, dRectX, dRectY, dRectW, dRectH, wsmodel) DrawingObjectsController.prototype.addTextArtFromParams = function(nStyle, dRectX, dRectY, dRectW, dRectH, wsmodel)
{ {
......
...@@ -1890,56 +1890,59 @@ function DrawingObjects() { ...@@ -1890,56 +1890,59 @@ function DrawingObjects() {
// For object type // For object type
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
_this.addImageDrawingObject = function(imageUrl, options) {
if (imageUrl && !_this.isViewerMode()) {
var _image = api.ImageLoader.LoadImage(imageUrl, 1); _this.calculateObjectMetrics = function (object, width, height) {
var isOption = options && options.cell; // Обработка картинок большого разрешения
var metricCoeff = 1;
var calculateObjectMetrics = function (object, width, height) { var coordsFrom = _this.coordsManager.calculateCoords(object.from);
// Обработка картинок большого разрешения var realTopOffset = coordsFrom.y;
var metricCoeff = 1; var realLeftOffset = coordsFrom.x;
var coordsFrom = _this.coordsManager.calculateCoords(object.from); var areaWidth = worksheet.getCellLeft(worksheet.getLastVisibleCol(), 0) - worksheet.getCellLeft(worksheet.getFirstVisibleCol(true), 0); // по ширине
var realTopOffset = coordsFrom.y; if (areaWidth < width) {
var realLeftOffset = coordsFrom.x; metricCoeff = width / areaWidth;
var areaWidth = worksheet.getCellLeft(worksheet.getLastVisibleCol(), 0) - worksheet.getCellLeft(worksheet.getFirstVisibleCol(true), 0); // по ширине width = areaWidth;
if (areaWidth < width) { height /= metricCoeff;
metricCoeff = width / areaWidth; }
width = areaWidth; var areaHeight = worksheet.getCellTop(worksheet.getLastVisibleRow(), 0) - worksheet.getCellTop(worksheet.getFirstVisibleRow(true), 0); // по высоте
height /= metricCoeff; if (areaHeight < height) {
} metricCoeff = height / areaHeight;
var areaHeight = worksheet.getCellTop(worksheet.getLastVisibleRow(), 0) - worksheet.getCellTop(worksheet.getFirstVisibleRow(true), 0); // по высоте height = areaHeight;
if (areaHeight < height) { width /= metricCoeff;
metricCoeff = height / areaHeight; }
height = areaHeight; var findVal = pxToPt(realLeftOffset + width);
width /= metricCoeff; var toCell = worksheet.findCellByXY(findVal, 0, true, false, true);
} while (toCell.col === null && worksheet.cols.length < gc_nMaxCol) {
worksheet.expandColsOnScroll(true);
toCell = worksheet.findCellByXY(findVal, 0, true, false, true);
}
object.to.col = toCell.col;
object.to.colOff = ptToMm(toCell.colOff);
var findVal = pxToPt(realLeftOffset + width); findVal = pxToPt(realTopOffset + height);
var toCell = worksheet.findCellByXY(findVal, 0, true, false, true); toCell = worksheet.findCellByXY(0, findVal, true, true, false);
while (toCell.col === null && worksheet.cols.length < gc_nMaxCol) { while (toCell.row === null && worksheet.rows.length < gc_nMaxRow) {
worksheet.expandColsOnScroll(true); worksheet.expandRowsOnScroll(true);
toCell = worksheet.findCellByXY(findVal, 0, true, false, true); toCell = worksheet.findCellByXY(0, findVal, true, true, false);
} }
object.to.col = toCell.col; object.to.row = toCell.row;
object.to.colOff = ptToMm(toCell.colOff); object.to.rowOff = ptToMm(toCell.rowOff);
worksheet.handlers.trigger("reinitializeScroll");
};
_this.addImageDrawingObject = function(imageUrl, options) {
if (imageUrl && !_this.isViewerMode()) {
var _image = api.ImageLoader.LoadImage(imageUrl, 1);
var isOption = options && options.cell;
findVal = pxToPt(realTopOffset + height);
toCell = worksheet.findCellByXY(0, findVal, true, true, false);
while (toCell.row === null && worksheet.rows.length < gc_nMaxRow) {
worksheet.expandRowsOnScroll(true);
toCell = worksheet.findCellByXY(0, findVal, true, true, false);
}
object.to.row = toCell.row;
object.to.rowOff = ptToMm(toCell.rowOff);
worksheet.handlers.trigger("reinitializeScroll");
};
var addImageObject = function (_image) { var addImageObject = function (_image) {
...@@ -1964,7 +1967,7 @@ function DrawingObjects() { ...@@ -1964,7 +1967,7 @@ function DrawingObjects() {
} }
worksheet.expandRowsOnScroll(true); // для rowOff worksheet.expandRowsOnScroll(true); // для rowOff
calculateObjectMetrics(drawingObject, isOption ? options.width : _image.Image.width, isOption ? options.height : _image.Image.height); _this.calculateObjectMetrics(drawingObject, isOption ? options.width : _image.Image.width, isOption ? options.height : _image.Image.height);
var coordsFrom = _this.coordsManager.calculateCoords(drawingObject.from); var coordsFrom = _this.coordsManager.calculateCoords(drawingObject.from);
var coordsTo = _this.coordsManager.calculateCoords(drawingObject.to); var coordsTo = _this.coordsManager.calculateCoords(drawingObject.to);
...@@ -3065,6 +3068,44 @@ function DrawingObjects() { ...@@ -3065,6 +3068,44 @@ function DrawingObjects() {
return ret; return ret;
}; };
_this.addOleObject = function(fWidth, fHeight, nWidthPix, nHeightPix, sLocalUrl, sData, sApplicationId){
var drawingObject = _this.createDrawingObject();
drawingObject.worksheet = worksheet;
drawingObject.from.col = worksheet.getSelectedColumnIndex();
drawingObject.from.row = worksheet.getSelectedRowIndex();
// Проверяем начальные координаты при вставке
while (!worksheet.cols[drawingObject.from.col]) {
worksheet.expandColsOnScroll(true);
}
worksheet.expandColsOnScroll(true); // для colOff
while (!worksheet.rows[drawingObject.from.row]) {
worksheet.expandRowsOnScroll(true);
}
worksheet.expandRowsOnScroll(true); // для rowOff
_this.calculateObjectMetrics(drawingObject, nWidthPix, nHeightPix);
var coordsFrom = _this.coordsManager.calculateCoords(drawingObject.from);
_this.objectLocker.reset();
_this.objectLocker.addObjectId(AscCommon.g_oIdCounter.Get_NewId());
_this.objectLocker.checkObjects(function (bLock) {
if (bLock !== true)
return;
_this.controller.resetSelection();
_this.controller.addOleObjectFromParams(pxToMm(coordsFrom.x), pxToMm(coordsFrom.y), fWidth, fHeight, nWidthPix, nHeightPix, sLocalUrl, sData, sApplicationId);
worksheet.setSelectionShape(true);
});
};
_this.editOleObject = function(oOleObject, sData, sImageUrl, nPixWidth, nPixHeight, bResize){
this.controller.editOleObjectFromParams(oOleObject, sData, sImageUrl, nPixWidth, nPixHeight, bResize);
};
_this.groupGraphicObjects = function() { _this.groupGraphicObjects = function() {
if ( _this.controller.canGroup() ) { if ( _this.controller.canGroup() ) {
......
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