summaryrefslogtreecommitdiff
path: root/sfx2/source/notify/eventsupplier.cxx
diff options
context:
space:
mode:
authorDirk Völzke <dv@openoffice.org>2001-02-09 10:28:12 +0000
committerDirk Völzke <dv@openoffice.org>2001-02-09 10:28:12 +0000
commitef315311bdef271a27e6348c66fe54515745f714 (patch)
treea560a4cdb5d7bf0422572a25a9e2d6e6d337d710 /sfx2/source/notify/eventsupplier.cxx
parent4ae73e52f32456c0a33d601f64f011baa3da63ed (diff)
#76800# Implementation of XEventsSupplier
Diffstat (limited to 'sfx2/source/notify/eventsupplier.cxx')
-rw-r--r--sfx2/source/notify/eventsupplier.cxx441
1 files changed, 441 insertions, 0 deletions
diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx
new file mode 100644
index 000000000000..6d6310b19302
--- /dev/null
+++ b/sfx2/source/notify/eventsupplier.cxx
@@ -0,0 +1,441 @@
+/*************************************************************************
+ *
+ * $RCSfile: eventsupplier.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: dv $ $Date: 2001-02-09 11:26:53 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+//--------------------------------------------------------------------------------------------------------
+
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
+#include <com/sun/star/beans/PropertyValue.hpp>
+#endif
+
+#ifndef _URLOBJ_HXX
+#include <tools/urlobj.hxx>
+#endif
+
+#ifndef _SFXMACITEM_HXX
+#include <svtools/macitem.hxx>
+#endif
+
+#ifndef _SFX_APPUNO_HXX
+#include <appuno.hxx>
+#endif
+#ifndef _SFX_OBJSH_HXX
+#include <objsh.hxx>
+#endif
+#ifndef _SFX_SFXBASEMODEL_HXX_
+#include <sfxbasemodel.hxx>
+#endif
+#ifndef _SFX_EVENTCONF_HXX
+#include <evntconf.hxx>
+#endif
+
+#ifndef _SFX_EVENTSUPPLIER_HXX_
+#include "eventsupplier.hxx"
+#endif
+
+#include "app.hxx"
+#include "sfxresid.hxx"
+
+#include "sfxsids.hrc"
+#include "sfxlocal.hrc"
+
+//--------------------------------------------------------------------------------------------------------
+
+#define EVENT_TYPE "EventType"
+#define SCRIPT "Script"
+#define STAR_BASIC "StarBasic"
+#define JAVA_SCRIPT "JavaScript"
+
+//--------------------------------------------------------------------------------------------------------
+
+#define PROPERTYVALUE ::com::sun::star::beans::PropertyValue
+#define UNO_QUERY ::com::sun::star::uno::UNO_QUERY
+
+//--------------------------------------------------------------------------------------------------------
+// XInterface / XTypeProvider
+//--------------------------------------------------------------------------------------------------------
+
+SFX_IMPL_XINTERFACE_2( SfxEvents_Impl, OWeakObject, XNAMEREPLACE, XEVENTLISTENER )
+SFX_IMPL_XTYPEPROVIDER_2( SfxEvents_Impl, XNAMEREPLACE, XEVENTLISTENER )
+
+//--------------------------------------------------------------------------------------------------------
+ // --- XNameReplace ---
+//--------------------------------------------------------------------------------------------------------
+void SAL_CALL SfxEvents_Impl::replaceByName( const OUSTRING & aName, const ANY & aElement )
+ throw( ILLEGALARGUMENTEXCEPTION, NOSUCHELEMENTEXCEPTION,
+ WRAPPEDTARGETEXCEPTION, RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and replace the data
+
+ long nCount = maEventNames.getLength();
+ OUSTRING* pNames = maEventNames.getArray();
+
+ for ( long i=0; i<nCount; i++ )
+ {
+ if ( pNames[i] == aName )
+ {
+ ANY* pElement = maEventData.getArray();
+ // check for correct type of the element
+ if ( ::getCppuType( (const SEQUENCE < PROPERTYVALUE > *)0 ) ==
+ aElement.getValueType() )
+ {
+ pElement[i] = aElement;
+
+ SvxMacro *pMacro = ConvertToMacro( aElement );
+ USHORT nID = (USHORT) SfxEventConfiguration::GetEventId_Impl( aName );
+
+ if ( nID && pMacro )
+ SFX_APP()->GetEventConfig()->ConfigureEvent( nID, *pMacro, mpObjShell );
+
+ if ( pMacro )
+ delete pMacro;
+ }
+ else
+ throw ILLEGALARGUMENTEXCEPTION();
+
+ return;
+ }
+ }
+
+ throw NOSUCHELEMENTEXCEPTION();
+}
+
+//--------------------------------------------------------------------------------------------------------
+// --- XNameAccess ---
+//--------------------------------------------------------------------------------------------------------
+ANY SAL_CALL SfxEvents_Impl::getByName( const OUSTRING& aName )
+ throw( NOSUCHELEMENTEXCEPTION, WRAPPEDTARGETEXCEPTION,
+ RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and return the data
+
+ long nCount = maEventNames.getLength();
+ OUSTRING* pNames = maEventNames.getArray();
+
+ for ( long i=0; i<nCount; i++ )
+ {
+ if ( pNames[i] == aName )
+ {
+ ANY* pElement = maEventData.getArray();
+ return pElement[i];
+ }
+ }
+
+ throw NOSUCHELEMENTEXCEPTION();
+
+ return ANY();
+}
+
+//--------------------------------------------------------------------------------------------------------
+SEQUENCE< OUSTRING > SAL_CALL SfxEvents_Impl::getElementNames() throw ( RUNTIMEEXCEPTION )
+{
+ return maEventNames;
+}
+
+//--------------------------------------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxEvents_Impl::hasByName( const OUSTRING& aName ) throw ( RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ // find the event in the list and return the data
+
+ long nCount = maEventNames.getLength();
+ OUSTRING* pNames = maEventNames.getArray();
+
+ for ( long i=0; i<nCount; i++ )
+ {
+ if ( pNames[i] == aName )
+ {
+ return sal_True;
+ }
+ }
+
+ return sal_False;
+}
+
+//--------------------------------------------------------------------------------------------------------
+// --- XElementAccess ( parent of XNameAccess ) ---
+//--------------------------------------------------------------------------------------------------------
+UNOTYPE SAL_CALL SfxEvents_Impl::getElementType() throw ( RUNTIMEEXCEPTION )
+{
+ UNOTYPE aElementType = ::getCppuType( (const SEQUENCE < PROPERTYVALUE > *)0 );
+ return aElementType;
+}
+
+//--------------------------------------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxEvents_Impl::hasElements() throw ( RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( maEventNames.getLength() )
+ return sal_True;
+ else
+ return sal_False;
+}
+
+//--------------------------------------------------------------------------------------------------------
+// --- ::document::XEventListener ---
+//--------------------------------------------------------------------------------------------------------
+void SAL_CALL SfxEvents_Impl::notifyEvent( const DOCEVENTOBJECT& aEvent ) throw( RUNTIMEEXCEPTION )
+{
+ ::osl::ClearableMutexGuard aGuard( maMutex );
+
+ // get the event name, find the coresponding data, execute the data
+
+ OUSTRING aName = aEvent.EventName;
+ OUSTRING* pNames = maEventNames.getArray();
+ long nCount = maEventNames.getLength();
+ long nIndex = 0;
+ sal_Bool bFound = sal_False;
+
+ while ( !bFound && ( nIndex < nCount ) )
+ {
+ if ( pNames[nIndex] == aName )
+ bFound = sal_True;
+ else
+ nIndex += 1;
+ }
+
+ if ( !bFound )
+ return;
+
+ SEQUENCE < PROPERTYVALUE > aProperties;
+ ANY aEventData = maEventData.getArray()[ nIndex ];
+
+ if ( aEventData >>= aProperties )
+ {
+ PROPERTYVALUE *pValues = aProperties.getArray();
+ sal_Bool bGotType = sal_False;
+ sal_Bool bGotScript = sal_False;
+ OUSTRING aType;
+ OUSTRING aScript;
+
+ nCount = aProperties.getLength();
+ nIndex = 0;
+ while ( ! ( bGotType && bGotScript ) && ( nIndex < nCount ) )
+ {
+ if ( pValues[ nIndex ].Name.compareToAscii( EVENT_TYPE ) == 0 )
+ {
+ bGotType = sal_True;
+ pValues[ nIndex ].Value >>= aType;
+ }
+ else if ( pValues[ nIndex ].Name.compareToAscii( SCRIPT ) == 0 )
+ {
+ bGotScript = sal_True;
+ pValues[ nIndex ].Value >>= aScript;
+ }
+ nIndex += 1;
+ }
+
+ if ( ( aType.compareToAscii( STAR_BASIC ) == 0 ) &&
+ ( aScript.len() ) )
+ {
+ aGuard.clear();
+ ErrCode nErr;
+ if ( Warn_Impl() )
+ nErr = SfxMacroLoader::loadMacro( aScript );
+ else
+ nErr = 0;
+ }
+ }
+}
+
+//--------------------------------------------------------------------------------------------------------
+// --- ::lang::XEventListener ---
+//--------------------------------------------------------------------------------------------------------
+void SAL_CALL SfxEvents_Impl::disposing( const EVENTOBJECT& Source ) throw( RUNTIMEEXCEPTION )
+{
+ ::osl::MutexGuard aGuard( maMutex );
+
+ if ( mxBroadcaster.is() )
+ {
+ mxBroadcaster->removeEventListener( this );
+ mxBroadcaster = NULL;
+ }
+}
+
+//--------------------------------------------------------------------------------------------------------
+//
+//--------------------------------------------------------------------------------------------------------
+SfxEvents_Impl::SfxEvents_Impl( SfxObjectShell* pShell,
+ REFERENCE< XEVENTBROADCASTER > xBroadcaster )
+{
+ // get the list of supported events and store it
+ maEventNames = pShell->GetEventNames();
+ maEventData = SEQUENCE < ANY > ( maEventNames.getLength() );
+
+ mpObjShell = pShell;
+ mxBroadcaster = xBroadcaster;
+
+ if ( mxBroadcaster.is() )
+ mxBroadcaster->addEventListener( this );
+}
+
+//--------------------------------------------------------------------------------------------------------
+SfxEvents_Impl::~SfxEvents_Impl()
+{
+ if ( mxBroadcaster.is() )
+ mxBroadcaster->removeEventListener( this );
+}
+
+//--------------------------------------------------------------------------------------------------------
+SvxMacro* SfxEvents_Impl::ConvertToMacro( ANY aElement )
+{
+ SvxMacro* pMacro = NULL;
+
+ SEQUENCE < PROPERTYVALUE > aProperties;
+
+ if ( aElement >>= aProperties )
+ {
+ PROPERTYVALUE *pValues = aProperties.getArray();
+ sal_Bool bGotType = sal_False;
+ sal_Bool bGotScript = sal_False;
+ OUSTRING aType;
+ OUSTRING aScriptURL;
+
+ long nCount = aProperties.getLength();
+ long nIndex = 0;
+
+ while ( ! ( bGotType && bGotScript ) && ( nIndex < nCount ) )
+ {
+ if ( pValues[ nIndex ].Name.compareToAscii( EVENT_TYPE ) == 0 )
+ {
+ bGotType = sal_True;
+ pValues[ nIndex ].Value >>= aType;
+ }
+ else if ( pValues[ nIndex ].Name.compareToAscii( SCRIPT ) == 0 )
+ {
+ bGotScript = sal_True;
+ pValues[ nIndex ].Value >>= aScriptURL;
+ }
+ nIndex += 1;
+ }
+
+ if ( bGotType && bGotScript )
+ {
+ // Get the type
+ ScriptType eType( STARBASIC );
+
+ if ( aType.compareToAscii( STAR_BASIC ) == COMPARE_EQUAL )
+ eType = STARBASIC;
+ else if ( aType.compareToAscii( JAVA_SCRIPT ) == COMPARE_EQUAL )
+ eType = JAVASCRIPT;
+ else
+ DBG_ERRORFILE( "ConvertToMacro: Unknown macro type" );
+
+ // Get the LibName
+ String aScript( aScriptURL );
+ String aLibName;
+ String aMacroName;
+
+ sal_uInt16 nHashPos = aScript.Search( '/', 8 );
+ sal_uInt16 nArgsPos = aScript.Search( '(' );
+
+ if ( ( nHashPos != STRING_NOTFOUND ) && ( nHashPos < nArgsPos ) )
+ {
+ String aBasMgrName( INetURLObject::decode(aScript.Copy( 8, nHashPos-8 ), INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET) );
+
+ if ( aBasMgrName.EqualsAscii(".") )
+ aLibName = mpObjShell->GetTitle( SFX_TITLE_APINAME );
+ else if ( aBasMgrName.Len() )
+ aLibName = aBasMgrName;
+ else
+ aLibName = SFX_APP()->GetName();
+
+ // Get the macro name
+ aMacroName = aScript.Copy( nHashPos+1, nArgsPos - nHashPos - 1 );
+
+ pMacro = new SvxMacro( aMacroName, aLibName, eType );
+ }
+ else
+ {
+ DBG_ERRORFILE( "ConvertToMacro: Unknown macro url format" );
+ }
+ }
+ }
+
+ return pMacro;
+}
+
+//--------------------------------------------------------------------------------------------------------
+sal_Bool SfxEvents_Impl::Warn_Impl()
+{
+ // Wenn das Macro sowieso nicht ausgef"uhrt wird, mu\s auch nicht gefragt werden
+ if ( !mpObjShell->IsSecure() )
+ return sal_False;
+
+ // Bei dokumentgebundenen Macros WarningStatus checken
+ // Wenn "Immer warnen" angeschaltet ist, Warnung ausgeben
+ sal_Bool bWarn = SFX_APP()->GetEventConfig()->IsWarningForced();
+
+ if ( bWarn )
+ {
+ SfxMacroQueryDlg_Impl aBox ( SfxResId( DLG_MACROQUERY ) );
+ if ( aBox.Execute() )
+ bWarn = sal_False;
+ }
+
+ return !bWarn;
+}
+