<@script name="EventsMgr" also="Window Fields" hide="y"> Implements the %STUDIO% events manager (c) SAP AG 2003-2006. All rights reserved. <@func name="ENABLE_EVENTS" also="DISABLE_EVENTS Window!SETUP"> Enables the %STUDIO% global event handlers The HTML container to hook (usually the document body) Callback function for obtaining the context-sensitive menu Custom keyboard events handler. If omitted, the default keyboard handler will be used This function is automatically invoked by @Window!SETUP. Therefore, use this function only in windows where the @Window! script is not installed. function ENABLE_EVENTS(obj, onMenu, onKeyboard) { obj.onselectstart = __EVENTS.selection; obj.oncontextmenu = __EVENTS.contextmenu; obj.onmouseover = __EVENTS.mouseover; obj.onkeydown = onKeyboard || __EVENTS.keyboard; obj.onhelp = __EVENTS.help; window.onhelp = __EVENTS.help; obj.onmenu = onMenu || null; } <@func name="DISABLE_EVENTS" also="ENABLE_EVENTS Window!SETUP"> Disables the %STUDIO% global event handlers The HTML container to unhook (usually the document body) function DISABLE_EVENTS(obj) { obj.onselectstart = null; obj.oncontextmenu = null; obj.onmouseover = null; obj.onmousedown = null; obj.onkeydown = null; obj.onhelp = null; obj.onmenu = null; for (var i=0, E=obj.all, len=E.length; i Applies the specified glyph over the given object An HTML object The glyph to apply function SET_GLYPH(obj, glyph) { var gl=UPPER(glyph+''), st=UPPER(obj.currentStyle.state||''); if (obj.currentStyle.glyph == gl) return; obj.style.glyph = gl; obj.className = gl + (st ? ' '+gl+'-'+st : ''); } <@func name="SET_STATE" also="CLR_STATE SET_GLYPH"> Sets the given object to the specified state An HTML object The state to apply function SET_STATE(obj, state) { if (!obj) return; __EVENTS.clearObjectState(obj.runtimeStyle, obj.currentStyle, true); var gl=(obj.currentStyle.glyph || obj.className), st=UPPER(state||''); if (obj.currentStyle.state == st) return; obj.style.state = st; obj.className = gl + (st ? ' '+gl+'-'+st : ''); } <@func name="CLR_STATE" also="SET_STATE SET_GLYPH"> Clears the state of the given object An HTML object function CLR_STATE(obj) { if (!obj) return; __EVENTS.clearObjectState(obj.runtimeStyle, obj.currentStyle, true); if (!obj.currentStyle.state) return; obj.style.state = ''; obj.className = (obj.currentStyle.glyph || obj.className); } <@func name="SET_READONLY" also="Global!DISABLE"> Sets the given INPUT object as readonly or editable An HTML INPUT object ~true=readonly, ~false=editable function SET_READONLY(obj, flag) { if (!obj || obj.tagName != 'INPUT') return; flag = BOOL(flag); obj.readOnly = flag; obj.style.color = flag ? '#[DIS]' : ''; } <@func name="KEY_CODE"> Translates a keyboard event into corresponding key code (e.g., 'CS65' for Ctrl+shift+A) The keyboard event object The translated key code function KEY_CODE(evt) { var key=evt.keyCode+''; if (evt.shiftKey) key = 'S'+key; if (evt.ctrlKey) key = 'C'+key; if (evt.altKey) key = 'A'+key; return key; } /////////////////////////////////////////////////////////////////////////////////////////////////// // INTERNAL var __EVENTS = {}; __EVENTS.selection = function() { event.cancelBubble = true; event.returnValue = event.srcElement.isContentEditable; } __EVENTS.contextmenu = function() { try { var name, menu, src=event.srcElement; if (src.isContentEditable && __EVENTS.defaultEditMenu(event)) return; if (src.currentStyle.particle == 'menu') return; for (var e=src; e && !e.menu; e=e.parentElement); for (var p=src; p && !p.onmenu; p=p.parentElement); if (e) name = e.menu; if (p) menu = p.onmenu(name, src); if (!menu) menu=name; if (menu) CONTEXT_MENU(menu, src, 'SCREEN', event.screenX, event.screenY); } catch (e) {} event.returnValue = false; } __EVENTS.defaultEditMenu = function(event) { var src=event.srcElement, menu=[]; if (src && src.document && src.document.selection && src.document.selection.type!="None") var textSelected = true; if (textSelected){ menu.push({signal:'Cut', text:'#TEXT[XMIT_CUT]', icon:'#URL[dev~skin:icons.cut.gif]'}); menu.push({signal:'Copy', text:'#TEXT[XMIT_COPY]', icon:'#URL[dev~skin:icons.copy.gif]'}); } menu.push({signal:'Paste', text:'#TEXT[XMIT_PASTE]', icon:'#URL[dev~skin:icons.paste.gif]'}); if (src.tagName == 'INPUT' || src.tagName == 'TEXTAREA') { var p=src.parentElement, p2=p && p.parentElement || null; menu.push({}); menu.push({signal:'Select', text:'#TEXT[XMIT_SELECT_ALL]'}); if (p2 && p2.type == 'combo' && p2.history) { menu.push({signal:'ClearHist', text:'#TEXT[XMIT_CLEAR_HISTORY]'}); } } CONTEXT_MENU(menu, domenu, 'SCREEN', event.screenX, event.screenY); event.returnValue = false; return true; function domenu(cmd) { try { switch (cmd) { case 'Select': src.select(); break; case 'ClearHist': src.parentElement.parentElement.clearHistory(); break; case 'Paste': if (src.tagName == 'SPAN') { //clears text formatting before paste data onto treeview node (CSN#116267 2009) document.execCommand(cmd, false, window.clipboardData.getData("Text")); break; } default: document.execCommand(cmd); break; } } catch (e) {}; } } __EVENTS.mouseover = function() { var e=event.srcElement; if (!e) return; if (e.tagName == 'IMG' || e.currentStyle.particle == 'parent') e=e.parentElement; if (e.onmouseenter) return; var particle=e.currentStyle.particle; if (!particle) return; switch (particle) { case 'hover': e.onmouseenter = e.onmouseleave = __EVENTS.mouseclick; break; case 'press': e.onmouseenter = e.onmouseleave = e.onmousedown = e.onmouseup = __EVENTS.mouseclick; break; case 'toggle': case 'click': case 'menu': case 'combo': e.onmouseenter = e.onmouseleave = e.onmousedown = e.onmouseup = e.onclick = __EVENTS.mouseclick; break; } } __EVENTS.mouseclick = function() { var e=event.srcElement; if (e.tagName == 'IMG' || e.currentStyle.particle == 'parent') e=e.parentElement; try { var rt=e.runtimeStyle, ct=e.currentStyle; switch (event.type) { case 'mouseenter': if (ct.particle == 'combo'){ var prnt = e.parentElement; if (prnt.currentStyle.particle != "combo") break; for (var i=0, C=prnt.children, len=C.length; i=0x70 && code<=0x7F || evt.ctrlKey || evt.altKey) return $CTL.processKey(evt); } } __EVENTS.help = function() { SIGNAL('STARTUP_HELP'); return false; //return $CTL.processKey('112'); }