/*
*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
* DocumentHolder.js
*
* DocumentHolder controller
*
* Created by Alexander Yuzhin on 1/15/14
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
*
*/
var c_paragraphLinerule = {
LINERULE_LEAST: 0,
LINERULE_AUTO: 1,
LINERULE_EXACT: 2
};
var c_tableBorder = {
BORDER_VERTICAL_LEFT: 0,
BORDER_HORIZONTAL_TOP: 1,
BORDER_VERTICAL_RIGHT: 2,
BORDER_HORIZONTAL_BOTTOM: 3,
BORDER_VERTICAL_CENTER: 4,
BORDER_HORIZONTAL_CENTER: 5,
BORDER_INNER: 6,
BORDER_OUTER: 7,
BORDER_ALL: 8,
BORDER_NONE: 9,
BORDER_ALL_TABLE: 10, // table border and all cell borders
BORDER_NONE_TABLE: 11, // table border and no cell borders
BORDER_INNER_TABLE: 12, // table border and inner cell borders
BORDER_OUTER_TABLE: 13 // table border and outer cell borders
};
var c_paragraphTextAlignment = {
RIGHT: 0,
LEFT: 1,
CENTERED: 2,
JUSTIFIED: 3
};
var c_paragraphSpecial = {
NONE_SPECIAL: 0,
FIRST_LINE: 1,
HANGING: 2
};
define([
'core',
'presentationeditor/main/app/view/DocumentHolder'
], function () {
'use strict';
PE.Controllers.DocumentHolder = Backbone.Controller.extend({
models: [],
collections: [],
views: [
'DocumentHolder'
],
initialize: function() {
this.addListeners({
'DocumentHolder': {
'createdelayedelements': this.createDelayedElements,
'equation:callback': this.equationCallback,
'layout:change': this.onLayoutChange,
'theme:change': this.onThemeChange
}
});
var me = this;
me.usertips = [];
me._TtHeight = 20;
me.fastcoauthtips = [];
me._state = {};
me.mode = {};
me._isDisabled = false;
me.screenTip = {
toolTip: new Common.UI.Tooltip({
owner: this,
html: true,
title: '
Press Ctrl and click link'
// style: 'word-wrap: break-word;'
}),
strTip: '',
isHidden: true,
isVisible: false
};
me.userTooltip = true;
me.wrapEvents = {
userTipMousover: _.bind(me.userTipMousover, me),
userTipMousout: _.bind(me.userTipMousout, me),
onKeyUp: _.bind(me.onKeyUp, me)
};
// Hotkeys
// ---------------------
var keymap = {};
me.hkComments = 'alt+h';
keymap[me.hkComments] = function() {
if (me.api.can_AddQuotedComment()!==false && me.documentHolder.slidesCount>0) {
me.addComment();
}
};
me.hkPreview = 'command+f5,ctrl+f5';
keymap[me.hkPreview] = function(e) {
var isResized = false;
e.preventDefault();
e.stopPropagation();
if (me.documentHolder.slidesCount>0) {
Common.NotificationCenter.trigger('preview:start', 0);
}
};
Common.util.Shortcuts.delegateShortcuts({shortcuts:keymap});
},
onLaunch: function() {
this.documentHolder = this.createView('DocumentHolder').render();
this.documentHolder.el.tabIndex = -1;
this.onAfterRender();
var me = this;
Common.NotificationCenter.on({
'window:show': function(e){
me.screenTip.toolTip.hide();
me.screenTip.isVisible = false;
/** coauthoring begin **/
me.userTipHide();
/** coauthoring end **/
me.mode && me.mode.isDesktopApp && me.api && me.api.asc_onShowPopupWindow();
},
'modal:show': function(e){
me.hideTips();
},
'layout:changed': function(e){
me.screenTip.toolTip.hide();
me.screenTip.isVisible = false;
/** coauthoring begin **/
me.userTipHide();
/** coauthoring end **/
me.hideTips();
me.onDocumentHolderResize();
},
'preview:show': function(e){
me.isPreviewVisible = true;
me.screenTip && (me.screenTip.tipLength = -1); // redraw link tip
},
'preview:hide': function(e){
me.isPreviewVisible = false;
me.screenTip && (me.screenTip.tipLength = -1); // redraw link tip
}
});
},
setApi: function(api) {
this.api = api;
var me = this;
if (me.api) {
me.api.asc_registerCallback('asc_onContextMenu', _.bind(me.onContextMenu, me));
me.api.asc_registerCallback('asc_onMouseMoveStart', _.bind(me.onMouseMoveStart, me));
me.api.asc_registerCallback('asc_onMouseMoveEnd', _.bind(me.onMouseMoveEnd, me));
me.api.asc_registerCallback('asc_onPaintSlideNum', _.bind(me.onPaintSlideNum, me));
me.api.asc_registerCallback('asc_onEndPaintSlideNum', _.bind(me.onEndPaintSlideNum, me));
me.api.asc_registerCallback('asc_onCountPages', _.bind(me.onApiCountPages, me));
me.api.asc_registerCallback('asc_onCurrentPage', _.bind(me.onApiCurrentPages, me));
me.documentHolder.slidesCount = me.api.getCountPages();
//hyperlink
me.api.asc_registerCallback('asc_onHyperlinkClick', _.bind(me.onHyperlinkClick, me));
me.api.asc_registerCallback('asc_onMouseMove', _.bind(me.onMouseMove, me));
if (me.mode.isEdit===true) {
me.api.asc_registerCallback('asc_onDialogAddHyperlink', _.bind(me.onDialogAddHyperlink, me));
me.api.asc_registerCallback('asc_doubleClickOnChart', _.bind(me.editChartClick, me));
me.api.asc_registerCallback('asc_doubleClickOnTableOleObject', _.bind(me.onDoubleClickOnTableOleObject, me));
me.api.asc_registerCallback('asc_onSpellCheckVariantsFound', _.bind(me.onSpellCheckVariantsFound, me));
me.api.asc_registerCallback('asc_onShowSpecialPasteOptions', _.bind(me.onShowSpecialPasteOptions, me));
me.api.asc_registerCallback('asc_onHideSpecialPasteOptions', _.bind(me.onHideSpecialPasteOptions, me));
me.api.asc_registerCallback('asc_ChangeCropState', _.bind(me.onChangeCropState, me));
me.api.asc_registerCallback('asc_onHidePlaceholderActions', _.bind(me.onHidePlaceholderActions, me));
me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Image, _.bind(me.onInsertImage, me, true));
me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.ImageUrl, _.bind(me.onInsertImageUrl, me, true));
me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Chart, _.bind(me.onClickPlaceholderChart, me));
me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Table, _.bind(me.onClickPlaceholderTable, me));
me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Video, _.bind(me.onClickPlaceholder, me, AscCommon.PlaceholderButtonType.Video));
me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Audio, _.bind(me.onClickPlaceholder, me, AscCommon.PlaceholderButtonType.Audio));
}
me.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(me.onCoAuthoringDisconnect, me));
Common.NotificationCenter.on('api:disconnect', _.bind(me.onCoAuthoringDisconnect, me));
me.api.asc_registerCallback('asc_onTextLanguage', _.bind(me.onTextLanguage, me));
me.api.asc_registerCallback('asc_onShowForeignCursorLabel', _.bind(me.onShowForeignCursorLabel, me));
me.api.asc_registerCallback('asc_onHideForeignCursorLabel', _.bind(me.onHideForeignCursorLabel, me));
me.api.asc_registerCallback('asc_onFocusObject', _.bind(me.onFocusObject, me));
me.api.asc_registerCallback('asc_onUpdateThemeIndex', _.bind(me.onApiUpdateThemeIndex, me));
me.api.asc_registerCallback('asc_onLockDocumentTheme', _.bind(me.onApiLockDocumentTheme, me));
me.api.asc_registerCallback('asc_onUnLockDocumentTheme', _.bind(me.onApiUnLockDocumentTheme, me));
me.api.asc_registerCallback('asc_onStartDemonstration', _.bind(me.onApiStartDemonstration));
me.documentHolder.setApi(me.api);
}
return me;
},
setMode: function(mode) {
var me = this;
me.mode = mode;
/** coauthoring begin **/
!(me.mode.canCoAuthoring && me.mode.canComments)
? Common.util.Shortcuts.suspendEvents(me.hkComments)
: Common.util.Shortcuts.resumeEvents(me.hkComments);
/** coauthoring end **/
me.editorConfig = {user: mode.user};
me.documentHolder.setMode(mode);
},
onAfterRender: function(ct){
var me = this;
var meEl = me.documentHolder.cmpEl;
if (meEl) {
meEl.on('contextmenu', function(e) {
e.preventDefault();
e.stopPropagation();
return false;
});
meEl.on('click', function(e){
if (e.target.localName == 'canvas') {
if (me._preventClick)
me._preventClick = false;
else
meEl.focus();
}
});
meEl.on('mousedown', function(e){
if (e.target.localName == 'canvas')
Common.UI.Menu.Manager.hideAll();
});
//NOTE: set mouse wheel handler
var addEvent = function( elem, type, fn ) {
elem.addEventListener ? elem.addEventListener( type, fn, false ) : elem.attachEvent( "on" + type, fn );
};
var eventname=(/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
addEvent(me.documentHolder.el, eventname, _.bind(me.handleDocumentWheel, me));
}
!Common.Utils.isChrome ? $(document).on('mousewheel', _.bind(me.handleDocumentWheel, me)) :
document.addEventListener('mousewheel', _.bind(me.handleDocumentWheel, me), {passive: false});
$(document).on('keydown', _.bind(me.handleDocumentKeyDown, me));
$(window).on('resize', _.bind(me.onDocumentHolderResize, me));
var viewport = me.getApplication().getController('Viewport').getView('Viewport');
viewport.hlayout.on('layout:resizedrag', _.bind(me.onDocumentHolderResize, me));
},
createDelayedElements: function(view, type) {
var me = this,
view = me.documentHolder;
if (type=='view') {
view.menuViewCopy.on('click', _.bind(me.onCutCopyPaste, me));
view.menuViewAddComment.on('click', _.bind(me.addComment, me));
view.menuViewUndo.on('click', _.bind(me.onUndo, me));
view.mnuPreview.on('click', _.bind(me.onPreview, me));
view.mnuSelectAll.on('click', _.bind(me.onSelectAll, me));
view.mnuPrintSelection.on('click', _.bind(me.onPrintSelection, me));
return;
}
var diagramEditor = this.getApplication().getController('Common.Controllers.ExternalDiagramEditor').getView('Common.Views.ExternalDiagramEditor');
if (diagramEditor) {
diagramEditor.on('internalmessage', _.bind(function(cmp, message) {
var command = message.data.command;
var data = message.data.data;
if (this.api) {
( diagramEditor.isEditMode() )
? this.api.asc_editChartDrawingObject(data)
: this.api.asc_addChartDrawingObject(data, diagramEditor.getPlaceholder());
}
}, this));
diagramEditor.on('hide', _.bind(function(cmp, message) {
if (this.api) {
this.api.asc_onCloseChartFrame();
this.api.asc_enableKeyEvents(true);
}
var me = this;
setTimeout(function(){
me.editComplete();
}, 10);
}, this));
}
var oleEditor = this.getApplication().getController('Common.Controllers.ExternalOleEditor').getView('Common.Views.ExternalOleEditor');
if (oleEditor) {
oleEditor.on('internalmessage', _.bind(function(cmp, message) {
var command = message.data.command;
var data = message.data.data;
if (this.api) {
oleEditor.isEditMode()
? this.api.asc_editTableOleObject(data)
: this.api.asc_addTableOleObject(data);
}
}, this));
oleEditor.on('hide', _.bind(function(cmp, message) {
if (this.api) {
this.api.asc_enableKeyEvents(true);
}
var me = this;
setTimeout(function(){
me.editComplete();
}, 10);
}, this));
}
view.menuSlidePaste.on('click', _.bind(me.onCutCopyPaste, me));
view.menuParaCopy.on('click', _.bind(me.onCutCopyPaste, me));
view.menuParaPaste.on('click', _.bind(me.onCutCopyPaste, me));
view.menuParaCut.on('click', _.bind(me.onCutCopyPaste, me));
view.menuImgCopy.on('click', _.bind(me.onCutCopyPaste, me));
view.menuImgPaste.on('click', _.bind(me.onCutCopyPaste, me));
view.menuImgCut.on('click', _.bind(me.onCutCopyPaste, me));
view.menuTableCopy.on('click', _.bind(me.onCutCopyPaste, me));
view.menuTablePaste.on('click', _.bind(me.onCutCopyPaste, me));
view.menuTableCut.on('click', _.bind(me.onCutCopyPaste, me));
view.menuAddHyperlinkPara.on('click', _.bind(me.addHyperlink, me));
view.menuAddHyperlinkTable.on('click', _.bind(me.addHyperlink, me));
view.menuEditHyperlinkPara.on('click', _.bind(me.editHyperlink, me));
view.menuEditHyperlinkTable.on('click', _.bind(me.editHyperlink, me));
view.menuRemoveHyperlinkPara.on('click', _.bind(me.removeHyperlink, me));
view.menuRemoveHyperlinkTable.on('click', _.bind(me.removeHyperlink, me));
view.menuChartEdit.on('click', _.bind(me.editChartClick, me, undefined));
view.menuAddCommentPara.on('click', _.bind(me.addComment, me));
view.menuAddCommentTable.on('click', _.bind(me.addComment, me));
view.menuAddCommentImg.on('click', _.bind(me.addComment, me));
view.menuAddToLayoutImg.on('click', _.bind(me.addToLayout, me));
view.menuAddToLayoutTable.on('click', _.bind(me.addToLayout, me));
view.menuImgReplace.menu.on('item:click', _.bind(me.onImgReplace, me));
view.langParaMenu.menu.on('item:click', _.bind(me.onLangMenu, me, 'para'));
view.langTableMenu.menu.on('item:click', _.bind(me.onLangMenu, me, 'table'));
view.mnuPreview.on('click', _.bind(me.onPreview, me));
view.mnuSelectAll.on('click', _.bind(me.onSelectAll, me));
view.mnuPrintSelection.on('click', _.bind(me.onPrintSelection, me));
view.mnuNewSlide.on('click', _.bind(me.onNewSlide, me));
view.mnuDuplicateSlide.on('click', _.bind(me.onDuplicateSlide, me));
view.mnuDeleteSlide.on('click', _.bind(me.onDeleteSlide, me));
view.mnuResetSlide.on('click', _.bind(me.onResetSlide, me));
view.mnuMoveSlideToStart.on('click', _.bind(me.onMoveSlideToStart, me));
view.mnuMoveSlideToEnd.on('click', _.bind(me.onMoveSlideToEnd, me));
view.menuSlideSettings.on('click', _.bind(me.onSlideSettings, me));
view.mnuSlideHide.on('click', _.bind(me.onSlideHide, me));
view.mnuTableMerge.on('click', _.bind(me.onTableMerge, me));
view.mnuTableSplit.on('click', _.bind(me.onTableSplit, me));
view.menuTableCellAlign.menu.on('item:click', _.bind(me.tableCellsVAlign, me));
view.menuTableDistRows.on('click', _.bind(me.onTableDistRows, me));
view.menuTableDistCols.on('click', _.bind(me.onTableDistCols, me));
view.menuIgnoreSpellTable.on('click', _.bind(me.onIgnoreSpell, me));
view.menuIgnoreSpellPara.on('click', _.bind(me.onIgnoreSpell, me));
view.menuIgnoreAllSpellTable.on('click', _.bind(me.onIgnoreSpell, me));
view.menuIgnoreAllSpellPara.on('click', _.bind(me.onIgnoreSpell, me));
view.menuToDictionaryTable.on('click', _.bind(me.onToDictionary, me));
view.menuToDictionaryPara.on('click', _.bind(me.onToDictionary, me));
view.menuTableAdvanced.on('click', _.bind(me.onTableAdvanced, me));
view.menuImageAdvanced.on('click', _.bind(me.onImageAdvanced, me));
view.menuImgOriginalSize.on('click', _.bind(me.onImgOriginalSize, me));
view.menuImgShapeRotate.menu.items[0].on('click', _.bind(me.onImgRotate, me));
view.menuImgShapeRotate.menu.items[1].on('click', _.bind(me.onImgRotate, me));
view.menuImgShapeRotate.menu.items[3].on('click', _.bind(me.onImgFlip, me));
view.menuImgShapeRotate.menu.items[4].on('click', _.bind(me.onImgFlip, me));
view.menuImgCrop.menu.on('item:click', _.bind(me.onImgCrop, me));
view.menuImgEditPoints.on('click', _.bind(me.onImgEditPoints, me));
view.menuShapeAdvanced.on('click', _.bind(me.onShapeAdvanced, me));
view.menuParagraphAdvanced.on('click', _.bind(me.onParagraphAdvanced, me));
view.menuChartAdvanced.on('click', _.bind(me.onChartAdvanced, me));
view.mnuGroupImg.on('click', _.bind(me.onGroupImg, me));
view.mnuUnGroupImg.on('click', _.bind(me.onUnGroupImg, me));
view.mnuArrangeFront.on('click', _.bind(me.onArrangeFront, me));
view.mnuArrangeBack.on('click', _.bind(me.onArrangeBack, me));
view.mnuArrangeForward.on('click', _.bind(me.onArrangeForward, me));
view.mnuArrangeBackward.on('click', _.bind(me.onArrangeBackward, me));
view.menuImgShapeAlign.menu.on('item:click', _.bind(me.onImgShapeAlign, me));
view.menuParagraphVAlign.menu.on('item:click', _.bind(me.onParagraphVAlign, me));
view.menuParagraphDirection.menu.on('item:click', _.bind(me.onParagraphDirection, me));
view.menuTableSelectText.menu.on('item:click', _.bind(me.tableSelectText, me));
view.menuTableInsertText.menu.on('item:click', _.bind(me.tableInsertText, me));
view.menuTableDeleteText.menu.on('item:click', _.bind(me.tableDeleteText, me));
},
getView: function (name) {
return !name ?
this.documentHolder : Backbone.Controller.prototype.getView.call()
},
showPopupMenu: function(menu, value, event, docElement, eOpts){
var me = this;
if (!_.isUndefined(menu) && menu !== null){
Common.UI.Menu.Manager.hideAll();
var showPoint = [event.get_X(), event.get_Y()],
menuContainer = $(me.documentHolder.el).find(Common.Utils.String.format('#menu-container-{0}', menu.id));
if (event.get_Type() == Asc.c_oAscContextMenuTypes.Thumbnails) {
showPoint[0] -= 3;
showPoint[1] -= 3;
}
if (!menu.rendered) {
// Prepare menu container
if (menuContainer.length < 1) {
menuContainer = $(Common.Utils.String.format('