Commit 100312b5 authored by Oleg Korshul's avatar Oleg Korshul

mouse events from plugins

parent 3cad6ab0
...@@ -3504,6 +3504,7 @@ var editor; ...@@ -3504,6 +3504,7 @@ var editor;
prot["asc_pluginButtonClick"] = prot.asc_pluginButtonClick; prot["asc_pluginButtonClick"] = prot.asc_pluginButtonClick;
prot["asc_addOleObject"] = prot.asc_addOleObject; prot["asc_addOleObject"] = prot.asc_addOleObject;
prot["asc_editOleObject"] = prot.asc_editOleObject; prot["asc_editOleObject"] = prot.asc_editOleObject;
prot["asc_pluginEnableMouseEvents"] = prot.asc_pluginEnableMouseEvents;
// system input // system input
prot["SetTextBoxInputMode"] = prot.SetTextBoxInputMode; prot["SetTextBoxInputMode"] = prot.SetTextBoxInputMode;
......
...@@ -950,6 +950,18 @@ ...@@ -950,6 +950,18 @@
this.pluginsManager.buttonClick(id); this.pluginsManager.buttonClick(id);
}; };
baseEditorsApi.prototype.asc_pluginEnableMouseEvents = function(isEnable)
{
if (!this.pluginsManager)
return;
var _pluginData = new Asc.CPluginData();
_pluginData.setAttribute("type", "enableMouseEvent");
_pluginData.setAttribute("isEnabled", isEnable);
this.pluginsManager.sendMessage(_pluginData);
};
// Builder // Builder
baseEditorsApi.prototype.asc_nativeInitBuilder = function() baseEditorsApi.prototype.asc_nativeInitBuilder = function()
{ {
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
*/ */
(function(window, undefined){ (function(window, undefined)
{
function CPluginData() function CPluginData()
{ {
this.privateData = {}; this.privateData = {};
} }
CPluginData.prototype = CPluginData.prototype =
{ {
setAttribute : function(name, value) setAttribute : function(name, value)
...@@ -55,7 +57,7 @@ ...@@ -55,7 +57,7 @@
{ {
_data = JSON.stringify(this.privateData); _data = JSON.stringify(this.privateData);
} }
catch(err) catch (err)
{ {
_data = "{ \"data\" : \"\" }"; _data = "{ \"data\" : \"\" }";
} }
...@@ -68,9 +70,9 @@ ...@@ -68,9 +70,9 @@
{ {
this.privateData = JSON.parse(_data); this.privateData = JSON.parse(_data);
} }
catch(err) catch (err)
{ {
this.privateData = { "data" : "" }; this.privateData = {"data" : ""};
} }
} }
}; };
...@@ -207,7 +209,10 @@ ...@@ -207,7 +209,10 @@
if (-1 == id) if (-1 == id)
{ {
// защита от плохого плагина // защита от плохого плагина
this.closeAttackTimer = setTimeout(function(){ window.g_asc_plugins.close(); }, 5000); this.closeAttackTimer = setTimeout(function()
{
window.g_asc_plugins.close();
}, 5000);
} }
var _iframe = document.getElementById("plugin_iframe"); var _iframe = document.getElementById("plugin_iframe");
if (_iframe) if (_iframe)
...@@ -228,7 +233,10 @@ ...@@ -228,7 +233,10 @@
{ {
var text_data = { var text_data = {
data : "", data : "",
pushData : function(format, value) { this.data = value; } pushData : function(format, value)
{
this.data = value;
}
}; };
this.api.asc_CheckCopy(text_data, 1); this.api.asc_CheckCopy(text_data, 1);
...@@ -239,7 +247,10 @@ ...@@ -239,7 +247,10 @@
{ {
var text_data = { var text_data = {
data : "", data : "",
pushData : function(format, value) { this.data = value; } pushData : function(format, value)
{
this.data = value;
}
}; };
this.api.asc_CheckCopy(text_data, 2); this.api.asc_CheckCopy(text_data, 2);
...@@ -293,7 +304,7 @@ ...@@ -293,7 +304,7 @@
this.plugins.push(_p); this.plugins.push(_p);
} }
var _pluginsInstall = { "url" : this.path, "pluginsData" : [] }; var _pluginsInstall = {"url" : this.path, "pluginsData" : []};
for (var i = 0; i < this.plugins.length; i++) for (var i = 0; i < this.plugins.length; i++)
{ {
_pluginsInstall["pluginsData"].push(this.plugins[i].serialize()); _pluginsInstall["pluginsData"].push(this.plugins[i].serialize());
...@@ -311,6 +322,19 @@ ...@@ -311,6 +322,19 @@
{ {
//console.log("endLongAction"); //console.log("endLongAction");
this.api.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.SlowOperation); this.api.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.SlowOperation);
},
sendMessage : function(pluginData)
{
if (!this.current)
return;
var _iframe = document.getElementById("plugin_iframe");
if (_iframe)
{
pluginData.setAttribute("guid", this.current.guid);
_iframe.contentWindow.postMessage(pluginData.serialize(), "*");
}
} }
}; };
...@@ -348,49 +372,79 @@ ...@@ -348,49 +372,79 @@
window.g_asc_plugins.closeAttackTimer = -1; window.g_asc_plugins.closeAttackTimer = -1;
} }
if (value && value != "") { if (value && value != "")
try { {
if (window.g_asc_plugins.api.asc_canPaste()) { try
{
if (window.g_asc_plugins.api.asc_canPaste())
{
var _script = "(function(){ var Api = window.g_asc_plugins.api;\n" + value + "})();"; var _script = "(function(){ var Api = window.g_asc_plugins.api;\n" + value + "})();";
eval(_script); eval(_script);
if (pluginData.getAttribute("recalculate") == true) { if (pluginData.getAttribute("recalculate") == true)
{
var editorId = window.g_asc_plugins.api.getEditorId(); var editorId = window.g_asc_plugins.api.getEditorId();
if (AscCommon.c_oEditorId.Word === editorId) { if (AscCommon.c_oEditorId.Word === editorId)
{
var oLogicDocument = window.g_asc_plugins.api.WordControl ? var oLogicDocument = window.g_asc_plugins.api.WordControl ?
window.g_asc_plugins.api.WordControl.m_oLogicDocument : null; window.g_asc_plugins.api.WordControl.m_oLogicDocument : null;
var _fonts = oLogicDocument.Document_Get_AllFontNames(); var _fonts = oLogicDocument.Document_Get_AllFontNames();
var _imagesArray = oLogicDocument.Get_AllImageUrls(); var _imagesArray = oLogicDocument.Get_AllImageUrls();
var _images = {}; var _images = {};
for (var i = 0; i < _imagesArray.length; i++) { for (var i = 0; i < _imagesArray.length; i++)
{
_images[_imagesArray[i]] = _imagesArray[i]; _images[_imagesArray[i]] = _imagesArray[i];
} }
window.g_asc_plugins.images_rename = _images; window.g_asc_plugins.images_rename = _images;
AscCommon.Check_LoadingDataBeforePrepaste(window.g_asc_plugins.api, _fonts, _images, AscCommon.Check_LoadingDataBeforePrepaste(window.g_asc_plugins.api, _fonts, _images,
function () { function()
{
if (window.g_asc_plugins.api.WordControl && if (window.g_asc_plugins.api.WordControl &&
window.g_asc_plugins.api.WordControl.m_oLogicDocument && window.g_asc_plugins.api.WordControl.m_oLogicDocument &&
window.g_asc_plugins.api.WordControl.m_oLogicDocument.Reassign_ImageUrls) { window.g_asc_plugins.api.WordControl.m_oLogicDocument.Reassign_ImageUrls)
{
window.g_asc_plugins.api.WordControl.m_oLogicDocument.Reassign_ImageUrls( window.g_asc_plugins.api.WordControl.m_oLogicDocument.Reassign_ImageUrls(
window.g_asc_plugins.images_rename); window.g_asc_plugins.images_rename);
} }
delete window.g_asc_plugins.images_rename; delete window.g_asc_plugins.images_rename;
window.g_asc_plugins.api.asc_Recalculate(); window.g_asc_plugins.api.asc_Recalculate();
}); });
} else if (AscCommon.c_oEditorId.Spreadsheet === editorId) { }
else if (AscCommon.c_oEditorId.Spreadsheet === editorId)
{
window.g_asc_plugins.api.asc_Recalculate(); window.g_asc_plugins.api.asc_Recalculate();
} }
} }
} }
} catch (err) { } catch (err)
{
} }
} }
if ("close" == name) { if ("close" == name)
{
window.g_asc_plugins.close(); window.g_asc_plugins.close();
} }
} }
else if ("resize" == name)
{
var _sizes = JSON.parse(value);
window.g_asc_plugins.api.asc_fireCallback("asc_onPluginResize", _sizes["width"], _sizes["height"], function() {
// TODO: send resize end event
});
}
else if ("onmousemove" == name)
{
var _pos = JSON.parse(value);
window.g_asc_plugins.api.asc_fireCallback("asc_onPluginMouseMove", _pos["x"], _pos["y"]);
}
else if ("onmouseup" == name)
{
var _pos = JSON.parse(value);
window.g_asc_plugins.api.asc_fireCallback("asc_onPluginMouseUp", _pos["x"], _pos["y"]);
}
} }
} }
...@@ -414,9 +468,11 @@ ...@@ -414,9 +468,11 @@
window.g_asc_plugins.api = api; window.g_asc_plugins.api = api;
window.g_asc_plugins["api"] = window.g_asc_plugins.api; window.g_asc_plugins["api"] = window.g_asc_plugins.api;
window.g_asc_plugins.api.asc_registerCallback('asc_onDocumentContentReady', function(){ window.g_asc_plugins.api.asc_registerCallback('asc_onDocumentContentReady', function()
{
setTimeout(function(){ setTimeout(function()
{
window.g_asc_plugins.loadExtensionPlugins(window["Asc"]["extensionPlugins"]); window.g_asc_plugins.loadExtensionPlugins(window["Asc"]["extensionPlugins"]);
}, 10); }, 10);
...@@ -429,9 +485,15 @@ ...@@ -429,9 +485,15 @@
window["Asc"].CPluginData_wrap = function(obj) window["Asc"].CPluginData_wrap = function(obj)
{ {
if (!obj.getAttribute) if (!obj.getAttribute)
obj.getAttribute = function(name) { return this[name]; } obj.getAttribute = function(name)
{
return this[name];
};
if (!obj.setAttribute) if (!obj.setAttribute)
obj.setAttribute = function(name, value) { return this[name] = value; } obj.setAttribute = function(name, value)
{
return this[name] = value;
};
}; };
})(window, undefined); })(window, undefined);
...@@ -461,8 +523,8 @@ function TEST_PLUGINS() ...@@ -461,8 +523,8 @@ function TEST_PLUGINS()
isUpdateOleOnResize : true, isUpdateOleOnResize : true,
buttons : [ { text: "Ok", primary: true }, buttons : [{text : "Ok", primary : true},
{ text: "Cancel", primary: false } ] {text : "Cancel", primary : false}]
}, },
{ {
description : "about", description : "about",
...@@ -481,7 +543,7 @@ function TEST_PLUGINS() ...@@ -481,7 +543,7 @@ function TEST_PLUGINS()
isUpdateOleOnResize : false, isUpdateOleOnResize : false,
buttons : [ { "text": "Ok", "primary": true } ] buttons : [{"text" : "Ok", "primary" : true}]
} }
] ]
}, },
...@@ -507,7 +569,7 @@ function TEST_PLUGINS() ...@@ -507,7 +569,7 @@ function TEST_PLUGINS()
isUpdateOleOnResize : false, isUpdateOleOnResize : false,
buttons : [ { text: "Ok", primary: true } ] buttons : [{text : "Ok", primary : true}]
} }
] ]
}, },
...@@ -559,7 +621,7 @@ function TEST_PLUGINS() ...@@ -559,7 +621,7 @@ function TEST_PLUGINS()
isUpdateOleOnResize : false, isUpdateOleOnResize : false,
buttons : [ ] buttons : []
} }
] ]
}, },
...@@ -585,8 +647,8 @@ function TEST_PLUGINS() ...@@ -585,8 +647,8 @@ function TEST_PLUGINS()
isUpdateOleOnResize : false, isUpdateOleOnResize : false,
buttons : [ { text: "Ok", primary: true }, buttons : [{text : "Ok", primary : true},
{ text: "Cancel", primary: false } ] {text : "Cancel", primary : false}]
} }
] ]
}, },
...@@ -645,8 +707,8 @@ function TEST_PLUGINS() ...@@ -645,8 +707,8 @@ function TEST_PLUGINS()
"isUpdateOleOnResize" : false, "isUpdateOleOnResize" : false,
"buttons" : [ { "text": "Insert In Document", "primary": true}, "buttons" : [{"text" : "Insert In Document", "primary" : true},
{ "text": "Cancel", "primary": false } ] {"text" : "Cancel", "primary" : false}]
} }
] ]
}, },
...@@ -698,7 +760,7 @@ function TEST_PLUGINS() ...@@ -698,7 +760,7 @@ function TEST_PLUGINS()
"isUpdateOleOnResize" : false, "isUpdateOleOnResize" : false,
"buttons" : [ { "text": "Ok", "primary": true } ] "buttons" : [{"text" : "Ok", "primary" : true}]
} }
] ]
} }
......
...@@ -6766,6 +6766,8 @@ background-repeat: no-repeat;\ ...@@ -6766,6 +6766,8 @@ background-repeat: no-repeat;\
asc_docs_api.prototype["asc_pluginRun"] = asc_docs_api.prototype.asc_pluginRun; asc_docs_api.prototype["asc_pluginRun"] = asc_docs_api.prototype.asc_pluginRun;
asc_docs_api.prototype["asc_pluginResize"] = asc_docs_api.prototype.asc_pluginResize; asc_docs_api.prototype["asc_pluginResize"] = asc_docs_api.prototype.asc_pluginResize;
asc_docs_api.prototype["asc_pluginButtonClick"] = asc_docs_api.prototype.asc_pluginButtonClick; asc_docs_api.prototype["asc_pluginButtonClick"] = asc_docs_api.prototype.asc_pluginButtonClick;
asc_docs_api.prototype["asc_pluginEnableMouseEvents"] = asc_docs_api.prototype.asc_pluginEnableMouseEvents;
asc_docs_api.prototype["asc_addOleObject"] = asc_docs_api.prototype.asc_addOleObject; asc_docs_api.prototype["asc_addOleObject"] = asc_docs_api.prototype.asc_addOleObject;
asc_docs_api.prototype["asc_editOleObject"] = asc_docs_api.prototype.asc_editOleObject; asc_docs_api.prototype["asc_editOleObject"] = asc_docs_api.prototype.asc_editOleObject;
asc_docs_api.prototype["asc_InputClearKeyboardElement"] = asc_docs_api.prototype.asc_InputClearKeyboardElement; asc_docs_api.prototype["asc_InputClearKeyboardElement"] = asc_docs_api.prototype.asc_InputClearKeyboardElement;
......
...@@ -8883,6 +8883,8 @@ background-repeat: no-repeat;\ ...@@ -8883,6 +8883,8 @@ background-repeat: no-repeat;\
asc_docs_api.prototype["asc_pluginRun"] = asc_docs_api.prototype.asc_pluginRun; asc_docs_api.prototype["asc_pluginRun"] = asc_docs_api.prototype.asc_pluginRun;
asc_docs_api.prototype["asc_pluginResize"] = asc_docs_api.prototype.asc_pluginResize; asc_docs_api.prototype["asc_pluginResize"] = asc_docs_api.prototype.asc_pluginResize;
asc_docs_api.prototype["asc_pluginButtonClick"] = asc_docs_api.prototype.asc_pluginButtonClick; asc_docs_api.prototype["asc_pluginButtonClick"] = asc_docs_api.prototype.asc_pluginButtonClick;
asc_docs_api.prototype["asc_pluginEnableMouseEvents"] = asc_docs_api.prototype.asc_pluginEnableMouseEvents;
asc_docs_api.prototype["asc_nativeInitBuilder"] = asc_docs_api.prototype.asc_nativeInitBuilder; asc_docs_api.prototype["asc_nativeInitBuilder"] = asc_docs_api.prototype.asc_nativeInitBuilder;
asc_docs_api.prototype["asc_SetSilentMode"] = asc_docs_api.prototype.asc_SetSilentMode; asc_docs_api.prototype["asc_SetSilentMode"] = asc_docs_api.prototype.asc_SetSilentMode;
asc_docs_api.prototype["asc_addOleObject"] = asc_docs_api.prototype.asc_addOleObject; asc_docs_api.prototype["asc_addOleObject"] = asc_docs_api.prototype.asc_addOleObject;
......
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