1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5d119d52dSAndrew Rist * distributed with this work for additional information
6d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist * software distributed under the License is distributed on an
15d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist * KIND, either express or implied. See the License for the
17d119d52dSAndrew Rist * specific language governing permissions and limitations
18d119d52dSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20d119d52dSAndrew Rist *************************************************************/
21d119d52dSAndrew Rist
22d119d52dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTL_URL_HPP_
31cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir
34cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTL_XURLTRANSFORMER_HPP_
35cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <tools/urlobj.hxx>
38cdf0e10cSrcweir #include <tools/diagnose_ex.h>
39cdf0e10cSrcweir #include <svl/macitem.hxx>
40cdf0e10cSrcweir #include <sfx2/appuno.hxx>
41cdf0e10cSrcweir #include <sfx2/objsh.hxx>
42cdf0e10cSrcweir #include <sfx2/sfxbasemodel.hxx>
43cdf0e10cSrcweir #include <sfx2/evntconf.hxx>
44cdf0e10cSrcweir #include <unotools/eventcfg.hxx>
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include <unotools/securityoptions.hxx>
47cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
48cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
49cdf0e10cSrcweir #include "eventsupplier.hxx"
50cdf0e10cSrcweir
51cdf0e10cSrcweir #include <sfx2/app.hxx>
52cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
53cdf0e10cSrcweir
54cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
55cdf0e10cSrcweir #include "sfxlocal.hrc"
56cdf0e10cSrcweir #include <sfx2/docfile.hxx>
57cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
58cdf0e10cSrcweir #include <sfx2/frame.hxx>
59cdf0e10cSrcweir
60cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
61cdf0e10cSrcweir
62cdf0e10cSrcweir #define MACRO_PRFIX "macro://"
63cdf0e10cSrcweir #define MACRO_POSTFIX "()"
64cdf0e10cSrcweir
65cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
66cdf0e10cSrcweir
67cdf0e10cSrcweir #define PROPERTYVALUE ::com::sun::star::beans::PropertyValue
68cdf0e10cSrcweir #define UNO_QUERY ::com::sun::star::uno::UNO_QUERY
69cdf0e10cSrcweir
70cdf0e10cSrcweir namespace css = ::com::sun::star;
71cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
72cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
73cdf0e10cSrcweir
74cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
75cdf0e10cSrcweir // --- XNameReplace ---
76cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
replaceByName(const OUSTRING & aName,const ANY & rElement)77cdf0e10cSrcweir void SAL_CALL SfxEvents_Impl::replaceByName( const OUSTRING & aName, const ANY & rElement )
78cdf0e10cSrcweir throw( ILLEGALARGUMENTEXCEPTION, NOSUCHELEMENTEXCEPTION,
79cdf0e10cSrcweir WRAPPEDTARGETEXCEPTION, RUNTIMEEXCEPTION )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir ::osl::MutexGuard aGuard( maMutex );
82cdf0e10cSrcweir
83cdf0e10cSrcweir // find the event in the list and replace the data
84cdf0e10cSrcweir long nCount = maEventNames.getLength();
85cdf0e10cSrcweir for ( long i=0; i<nCount; i++ )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir if ( maEventNames[i] == aName )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir // check for correct type of the element
901b257601SMichael Stahl if ( !::comphelper::NamedValueCollection::canExtractFrom( rElement ) )
91cdf0e10cSrcweir throw ILLEGALARGUMENTEXCEPTION();
921b257601SMichael Stahl ::comphelper::NamedValueCollection const aEventDescriptor( rElement );
93cdf0e10cSrcweir
94cdf0e10cSrcweir // create Configuration at first, creation might call this method also and that would overwrite everything
95cdf0e10cSrcweir // we might have stored before!
96cdf0e10cSrcweir if ( mpObjShell && !mpObjShell->IsLoading() )
97cdf0e10cSrcweir mpObjShell->SetModified( sal_True );
98cdf0e10cSrcweir
99cdf0e10cSrcweir ::comphelper::NamedValueCollection aNormalizedDescriptor;
100cdf0e10cSrcweir NormalizeMacro( aEventDescriptor, aNormalizedDescriptor, mpObjShell );
101cdf0e10cSrcweir
102cdf0e10cSrcweir ::rtl::OUString sType;
103cdf0e10cSrcweir if ( ( aNormalizedDescriptor.size() == 1 )
104cdf0e10cSrcweir && ( aNormalizedDescriptor.has( PROP_EVENT_TYPE ) == 0 )
105cdf0e10cSrcweir && ( aNormalizedDescriptor.get( PROP_EVENT_TYPE ) >>= sType )
106cdf0e10cSrcweir && ( sType.getLength() == 0 )
107cdf0e10cSrcweir )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir // An empty event type means no binding. Therefore reset data
110cdf0e10cSrcweir // to reflect that state.
111cdf0e10cSrcweir // (that's for compatibility only. Nowadays, the Tools/Customize dialog should
112cdf0e10cSrcweir // set an empty sequence to indicate the request for resetting the assignment.)
113cdf0e10cSrcweir OSL_ENSURE( false, "legacy event assignment format detected" );
114cdf0e10cSrcweir aNormalizedDescriptor.clear();
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
117cdf0e10cSrcweir if ( !aNormalizedDescriptor.empty() )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir maEventData[i] <<= aNormalizedDescriptor.getPropertyValues();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir else
122cdf0e10cSrcweir {
123cdf0e10cSrcweir maEventData[i].clear();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir return;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir throw NOSUCHELEMENTEXCEPTION();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
133cdf0e10cSrcweir // --- XNameAccess ---
134cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
getByName(const OUSTRING & aName)135cdf0e10cSrcweir ANY SAL_CALL SfxEvents_Impl::getByName( const OUSTRING& aName )
136cdf0e10cSrcweir throw( NOSUCHELEMENTEXCEPTION, WRAPPEDTARGETEXCEPTION,
137cdf0e10cSrcweir RUNTIMEEXCEPTION )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir ::osl::MutexGuard aGuard( maMutex );
140cdf0e10cSrcweir
141cdf0e10cSrcweir // find the event in the list and return the data
142cdf0e10cSrcweir
143cdf0e10cSrcweir long nCount = maEventNames.getLength();
144cdf0e10cSrcweir
145cdf0e10cSrcweir for ( long i=0; i<nCount; i++ )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir if ( maEventNames[i] == aName )
148cdf0e10cSrcweir return maEventData[i];
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir throw NOSUCHELEMENTEXCEPTION();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
getElementNames()155cdf0e10cSrcweir SEQUENCE< OUSTRING > SAL_CALL SfxEvents_Impl::getElementNames() throw ( RUNTIMEEXCEPTION )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir return maEventNames;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
hasByName(const OUSTRING & aName)161cdf0e10cSrcweir sal_Bool SAL_CALL SfxEvents_Impl::hasByName( const OUSTRING& aName ) throw ( RUNTIMEEXCEPTION )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir ::osl::MutexGuard aGuard( maMutex );
164cdf0e10cSrcweir
165cdf0e10cSrcweir // find the event in the list and return the data
166cdf0e10cSrcweir
167cdf0e10cSrcweir long nCount = maEventNames.getLength();
168cdf0e10cSrcweir
169cdf0e10cSrcweir for ( long i=0; i<nCount; i++ )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir if ( maEventNames[i] == aName )
172cdf0e10cSrcweir return sal_True;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir
175cdf0e10cSrcweir return sal_False;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
178cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
179cdf0e10cSrcweir // --- XElementAccess ( parent of XNameAccess ) ---
180cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
getElementType()181cdf0e10cSrcweir UNOTYPE SAL_CALL SfxEvents_Impl::getElementType() throw ( RUNTIMEEXCEPTION )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir UNOTYPE aElementType = ::getCppuType( (const SEQUENCE < PROPERTYVALUE > *)0 );
184cdf0e10cSrcweir return aElementType;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
hasElements()188cdf0e10cSrcweir sal_Bool SAL_CALL SfxEvents_Impl::hasElements() throw ( RUNTIMEEXCEPTION )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir ::osl::MutexGuard aGuard( maMutex );
191cdf0e10cSrcweir
192cdf0e10cSrcweir if ( maEventNames.getLength() )
193cdf0e10cSrcweir return sal_True;
194cdf0e10cSrcweir else
195cdf0e10cSrcweir return sal_False;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
Execute(ANY & aEventData,const css::document::DocumentEvent & aTrigger,SfxObjectShell * pDoc)198cdf0e10cSrcweir static void Execute( ANY& aEventData, const css::document::DocumentEvent& aTrigger, SfxObjectShell* pDoc )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir SEQUENCE < PROPERTYVALUE > aProperties;
201cdf0e10cSrcweir if ( aEventData >>= aProperties )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir OUSTRING aPrefix = OUSTRING( RTL_CONSTASCII_USTRINGPARAM( MACRO_PRFIX ) );
204cdf0e10cSrcweir OUSTRING aType;
205cdf0e10cSrcweir OUSTRING aScript;
206cdf0e10cSrcweir OUSTRING aLibrary;
207cdf0e10cSrcweir OUSTRING aMacroName;
208*4fdfc99eSArrigo Marchiori OUSTRING aReferer;
209cdf0e10cSrcweir
210cdf0e10cSrcweir sal_Int32 nCount = aProperties.getLength();
211cdf0e10cSrcweir
212cdf0e10cSrcweir if ( !nCount )
213cdf0e10cSrcweir return;
214cdf0e10cSrcweir
215cdf0e10cSrcweir sal_Int32 nIndex = 0;
216cdf0e10cSrcweir while ( nIndex < nCount )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir if ( aProperties[ nIndex ].Name.compareToAscii( PROP_EVENT_TYPE ) == 0 )
219cdf0e10cSrcweir aProperties[ nIndex ].Value >>= aType;
220cdf0e10cSrcweir else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_SCRIPT ) == 0 )
221cdf0e10cSrcweir aProperties[ nIndex ].Value >>= aScript;
222cdf0e10cSrcweir else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_LIBRARY ) == 0 )
223cdf0e10cSrcweir aProperties[ nIndex ].Value >>= aLibrary;
224cdf0e10cSrcweir else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_MACRO_NAME ) == 0 )
225cdf0e10cSrcweir aProperties[ nIndex ].Value >>= aMacroName;
226*4fdfc99eSArrigo Marchiori else if ( aProperties[ nIndex ].Name.compareToAscii( "Referer" ) == 0 )
227*4fdfc99eSArrigo Marchiori aProperties[ nIndex ].Value >>= aReferer;
228cdf0e10cSrcweir else {
229cdf0e10cSrcweir DBG_ERROR("Unknown property value!");
230cdf0e10cSrcweir }
231cdf0e10cSrcweir nIndex += 1;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir
234cdf0e10cSrcweir if ( aType.compareToAscii( STAR_BASIC ) == 0 && aScript.getLength() )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir com::sun::star::uno::Any aAny;
237*4fdfc99eSArrigo Marchiori SfxMacroLoader::loadMacro( aScript, aAny, aReferer, pDoc );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir else if ( aType.compareToAscii( "Service" ) == 0 ||
240cdf0e10cSrcweir aType.compareToAscii( "Script" ) == 0 )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir if ( aScript.getLength() )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir SfxViewFrame* pView = pDoc ?
245cdf0e10cSrcweir SfxViewFrame::GetFirst( pDoc ) :
246cdf0e10cSrcweir SfxViewFrame::Current();
247cdf0e10cSrcweir
248cdf0e10cSrcweir ::com::sun::star::uno::Reference
249cdf0e10cSrcweir < ::com::sun::star::util::XURLTransformer > xTrans(
250cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance(
251cdf0e10cSrcweir rtl::OUString::createFromAscii(
252cdf0e10cSrcweir "com.sun.star.util.URLTransformer" ) ),
253cdf0e10cSrcweir UNO_QUERY );
254cdf0e10cSrcweir
255cdf0e10cSrcweir ::com::sun::star::util::URL aURL;
256cdf0e10cSrcweir aURL.Complete = aScript;
257cdf0e10cSrcweir xTrans->parseStrict( aURL );
258cdf0e10cSrcweir
2595e07d634SDamjan Jovanovic if ( aURL.Protocol.equals( ::rtl::OUString::createFromAscii( "vnd.sun.star.script:" ) ) )
2605e07d634SDamjan Jovanovic {
261cdf0e10cSrcweir ::com::sun::star::uno::Reference
262cdf0e10cSrcweir < ::com::sun::star::frame::XDispatchProvider > xProv;
263cdf0e10cSrcweir
264cdf0e10cSrcweir if ( pView != NULL )
265cdf0e10cSrcweir {
266cdf0e10cSrcweir xProv = ::com::sun::star::uno::Reference
267cdf0e10cSrcweir < ::com::sun::star::frame::XDispatchProvider > (
268cdf0e10cSrcweir pView->GetFrame().GetFrameInterface(), UNO_QUERY );
269cdf0e10cSrcweir }
270cdf0e10cSrcweir else
271cdf0e10cSrcweir {
272cdf0e10cSrcweir xProv = ::com::sun::star::uno::Reference
273cdf0e10cSrcweir < ::com::sun::star::frame::XDispatchProvider > (
274cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance(
275cdf0e10cSrcweir rtl::OUString::createFromAscii(
276cdf0e10cSrcweir "com.sun.star.frame.Desktop" ) ),
277cdf0e10cSrcweir UNO_QUERY );
278cdf0e10cSrcweir }
279cdf0e10cSrcweir
280cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatch > xDisp;
281cdf0e10cSrcweir if ( xProv.is() )
282cdf0e10cSrcweir xDisp = xProv->queryDispatch( aURL, ::rtl::OUString(), 0 );
283cdf0e10cSrcweir
284cdf0e10cSrcweir if ( xDisp.is() )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir //::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1);
287cdf0e10cSrcweir //aArgs[0].Name = rtl::OUString::createFromAscii("Referer");
288cdf0e10cSrcweir //aArs[0].Value <<= ::rtl::OUString( pDoc->GetMedium()->GetName() );
289cdf0e10cSrcweir //xDisp->dispatch( aURL, aArgs );
290cdf0e10cSrcweir
291cdf0e10cSrcweir css::beans::PropertyValue aEventParam;
292cdf0e10cSrcweir aEventParam.Value <<= aTrigger;
293cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > aDispatchArgs( &aEventParam, 1 );
294cdf0e10cSrcweir xDisp->dispatch( aURL, aDispatchArgs );
295cdf0e10cSrcweir }
296cdf0e10cSrcweir }
297cdf0e10cSrcweir }
2985e07d634SDamjan Jovanovic }
299cdf0e10cSrcweir else if ( aType.getLength() == 0 )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir // Empty type means no active binding for the event. Just ignore do nothing.
302cdf0e10cSrcweir }
303cdf0e10cSrcweir else
304cdf0e10cSrcweir {
305cdf0e10cSrcweir DBG_ERRORFILE( "notifyEvent(): Unsupported event type" );
306cdf0e10cSrcweir }
307cdf0e10cSrcweir }
308cdf0e10cSrcweir }
309cdf0e10cSrcweir
310cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
311cdf0e10cSrcweir // --- ::document::XEventListener ---
312cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
notifyEvent(const DOCEVENTOBJECT & aEvent)313cdf0e10cSrcweir void SAL_CALL SfxEvents_Impl::notifyEvent( const DOCEVENTOBJECT& aEvent ) throw( RUNTIMEEXCEPTION )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( maMutex );
316cdf0e10cSrcweir
317cdf0e10cSrcweir // get the event name, find the coresponding data, execute the data
318cdf0e10cSrcweir
319cdf0e10cSrcweir OUSTRING aName = aEvent.EventName;
320cdf0e10cSrcweir long nCount = maEventNames.getLength();
321cdf0e10cSrcweir long nIndex = 0;
322cdf0e10cSrcweir sal_Bool bFound = sal_False;
323cdf0e10cSrcweir
324cdf0e10cSrcweir while ( !bFound && ( nIndex < nCount ) )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir if ( maEventNames[nIndex] == aName )
327cdf0e10cSrcweir bFound = sal_True;
328cdf0e10cSrcweir else
329cdf0e10cSrcweir nIndex += 1;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir
332cdf0e10cSrcweir if ( !bFound )
333cdf0e10cSrcweir return;
334cdf0e10cSrcweir
335cdf0e10cSrcweir ANY aEventData = maEventData[ nIndex ];
336cdf0e10cSrcweir aGuard.clear();
337cdf0e10cSrcweir Execute( aEventData, css::document::DocumentEvent(aEvent.Source, aEvent.EventName, NULL, css::uno::Any()), mpObjShell );
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
341cdf0e10cSrcweir // --- ::lang::XEventListener ---
342cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
disposing(const EVENTOBJECT &)343cdf0e10cSrcweir void SAL_CALL SfxEvents_Impl::disposing( const EVENTOBJECT& /*Source*/ ) throw( RUNTIMEEXCEPTION )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir ::osl::MutexGuard aGuard( maMutex );
346cdf0e10cSrcweir
347cdf0e10cSrcweir if ( mxBroadcaster.is() )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir mxBroadcaster->removeEventListener( this );
350cdf0e10cSrcweir mxBroadcaster = NULL;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir }
353cdf0e10cSrcweir
354cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
355cdf0e10cSrcweir //
356cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
SfxEvents_Impl(SfxObjectShell * pShell,REFERENCE<XEVENTBROADCASTER> xBroadcaster)357cdf0e10cSrcweir SfxEvents_Impl::SfxEvents_Impl( SfxObjectShell* pShell,
358cdf0e10cSrcweir REFERENCE< XEVENTBROADCASTER > xBroadcaster )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir // get the list of supported events and store it
361cdf0e10cSrcweir if ( pShell )
362cdf0e10cSrcweir maEventNames = pShell->GetEventNames();
363cdf0e10cSrcweir else
364cdf0e10cSrcweir maEventNames = GlobalEventConfig().getElementNames();
365cdf0e10cSrcweir
366cdf0e10cSrcweir maEventData = SEQUENCE < ANY > ( maEventNames.getLength() );
367cdf0e10cSrcweir
368cdf0e10cSrcweir mpObjShell = pShell;
369cdf0e10cSrcweir mxBroadcaster = xBroadcaster;
370cdf0e10cSrcweir
371cdf0e10cSrcweir if ( mxBroadcaster.is() )
372cdf0e10cSrcweir mxBroadcaster->addEventListener( this );
373cdf0e10cSrcweir }
374cdf0e10cSrcweir
375cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
~SfxEvents_Impl()376cdf0e10cSrcweir SfxEvents_Impl::~SfxEvents_Impl()
377cdf0e10cSrcweir {
378cdf0e10cSrcweir }
379cdf0e10cSrcweir
380cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
ConvertToMacro(const ANY & rElement,SfxObjectShell * pObjShell,sal_Bool bNormalizeMacro)381cdf0e10cSrcweir SvxMacro* SfxEvents_Impl::ConvertToMacro( const ANY& rElement, SfxObjectShell* pObjShell, sal_Bool bNormalizeMacro )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir SvxMacro* pMacro = NULL;
384cdf0e10cSrcweir SEQUENCE < PROPERTYVALUE > aProperties;
385cdf0e10cSrcweir ANY aAny;
386cdf0e10cSrcweir if ( bNormalizeMacro )
387cdf0e10cSrcweir NormalizeMacro( rElement, aAny, pObjShell );
388cdf0e10cSrcweir else
389cdf0e10cSrcweir aAny = rElement;
390cdf0e10cSrcweir
391cdf0e10cSrcweir if ( aAny >>= aProperties )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir OUSTRING aType;
394cdf0e10cSrcweir OUSTRING aScriptURL;
395cdf0e10cSrcweir OUSTRING aLibrary;
396cdf0e10cSrcweir OUSTRING aMacroName;
397cdf0e10cSrcweir
398cdf0e10cSrcweir long nCount = aProperties.getLength();
399cdf0e10cSrcweir long nIndex = 0;
400cdf0e10cSrcweir
401cdf0e10cSrcweir if ( !nCount )
402cdf0e10cSrcweir return pMacro;
403cdf0e10cSrcweir
404cdf0e10cSrcweir while ( nIndex < nCount )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir if ( aProperties[ nIndex ].Name.compareToAscii( PROP_EVENT_TYPE ) == 0 )
407cdf0e10cSrcweir aProperties[ nIndex ].Value >>= aType;
408cdf0e10cSrcweir else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_SCRIPT ) == 0 )
409cdf0e10cSrcweir aProperties[ nIndex ].Value >>= aScriptURL;
410cdf0e10cSrcweir else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_LIBRARY ) == 0 )
411cdf0e10cSrcweir aProperties[ nIndex ].Value >>= aLibrary;
412cdf0e10cSrcweir else if ( aProperties[ nIndex ].Name.compareToAscii( PROP_MACRO_NAME ) == 0 )
413cdf0e10cSrcweir aProperties[ nIndex ].Value >>= aMacroName;
414cdf0e10cSrcweir else {
415cdf0e10cSrcweir DBG_ERROR("Unknown propery value!");
416cdf0e10cSrcweir }
417cdf0e10cSrcweir nIndex += 1;
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
420cdf0e10cSrcweir // Get the type
421cdf0e10cSrcweir ScriptType eType( STARBASIC );
422cdf0e10cSrcweir if ( aType.compareToAscii( STAR_BASIC ) == COMPARE_EQUAL )
423cdf0e10cSrcweir eType = STARBASIC;
424cdf0e10cSrcweir else if ( aType.compareToAscii( "Script" ) == COMPARE_EQUAL && aScriptURL.getLength() )
425cdf0e10cSrcweir eType = EXTENDED_STYPE;
426cdf0e10cSrcweir else if ( aType.compareToAscii( SVX_MACRO_LANGUAGE_JAVASCRIPT ) == COMPARE_EQUAL )
427cdf0e10cSrcweir eType = JAVASCRIPT;
428cdf0e10cSrcweir else {
429cdf0e10cSrcweir DBG_ERRORFILE( "ConvertToMacro: Unknown macro type" );
430cdf0e10cSrcweir }
431cdf0e10cSrcweir
432cdf0e10cSrcweir if ( aMacroName.getLength() )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir if ( aLibrary.compareToAscii("application") == 0 )
435cdf0e10cSrcweir aLibrary = SFX_APP()->GetName();
436cdf0e10cSrcweir else
437cdf0e10cSrcweir aLibrary = ::rtl::OUString();
438cdf0e10cSrcweir pMacro = new SvxMacro( aMacroName, aLibrary, eType );
439cdf0e10cSrcweir }
440cdf0e10cSrcweir else if ( eType == EXTENDED_STYPE )
441cdf0e10cSrcweir pMacro = new SvxMacro( aScriptURL, aType );
442cdf0e10cSrcweir }
443cdf0e10cSrcweir
444cdf0e10cSrcweir return pMacro;
445cdf0e10cSrcweir }
446cdf0e10cSrcweir
NormalizeMacro(const ANY & rEvent,ANY & rRet,SfxObjectShell * pDoc)447cdf0e10cSrcweir void SfxEvents_Impl::NormalizeMacro( const ANY& rEvent, ANY& rRet, SfxObjectShell* pDoc )
448cdf0e10cSrcweir {
449cdf0e10cSrcweir const ::comphelper::NamedValueCollection aEventDescriptor( rEvent );
450cdf0e10cSrcweir ::comphelper::NamedValueCollection aEventDescriptorOut;
451cdf0e10cSrcweir
452cdf0e10cSrcweir NormalizeMacro( aEventDescriptor, aEventDescriptorOut, pDoc );
453cdf0e10cSrcweir
454cdf0e10cSrcweir rRet <<= aEventDescriptorOut.getPropertyValues();
455cdf0e10cSrcweir }
456cdf0e10cSrcweir
NormalizeMacro(const::comphelper::NamedValueCollection & i_eventDescriptor,::comphelper::NamedValueCollection & o_normalizedDescriptor,SfxObjectShell * i_document)457cdf0e10cSrcweir void SfxEvents_Impl::NormalizeMacro( const ::comphelper::NamedValueCollection& i_eventDescriptor,
458cdf0e10cSrcweir ::comphelper::NamedValueCollection& o_normalizedDescriptor, SfxObjectShell* i_document )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir SfxObjectShell* pDoc = i_document;
461cdf0e10cSrcweir if ( !pDoc )
462cdf0e10cSrcweir pDoc = SfxObjectShell::Current();
463cdf0e10cSrcweir
464cdf0e10cSrcweir ::rtl::OUString aType = i_eventDescriptor.getOrDefault( PROP_EVENT_TYPE, ::rtl::OUString() );
465cdf0e10cSrcweir ::rtl::OUString aScript = i_eventDescriptor.getOrDefault( PROP_SCRIPT, ::rtl::OUString() );
466cdf0e10cSrcweir ::rtl::OUString aLibrary = i_eventDescriptor.getOrDefault( PROP_LIBRARY, ::rtl::OUString() );
467cdf0e10cSrcweir ::rtl::OUString aMacroName = i_eventDescriptor.getOrDefault( PROP_MACRO_NAME, ::rtl::OUString() );
468cdf0e10cSrcweir
469cdf0e10cSrcweir if ( aType.getLength() )
470cdf0e10cSrcweir o_normalizedDescriptor.put( PROP_EVENT_TYPE, aType );
471cdf0e10cSrcweir if ( aScript.getLength() )
472cdf0e10cSrcweir o_normalizedDescriptor.put( PROP_SCRIPT, aScript );
473cdf0e10cSrcweir
474cdf0e10cSrcweir if ( aType.compareToAscii( STAR_BASIC ) == 0 )
475cdf0e10cSrcweir {
476cdf0e10cSrcweir if ( aScript.getLength() )
477cdf0e10cSrcweir {
478cdf0e10cSrcweir if ( !aMacroName.getLength() || !aLibrary.getLength() )
479cdf0e10cSrcweir {
480cdf0e10cSrcweir sal_Int32 nHashPos = aScript.indexOf( '/', 8 );
481cdf0e10cSrcweir sal_Int32 nArgsPos = aScript.indexOf( '(' );
482cdf0e10cSrcweir if ( ( nHashPos != STRING_NOTFOUND ) && ( nHashPos < nArgsPos ) )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir OUSTRING aBasMgrName( INetURLObject::decode( aScript.copy( 8, nHashPos-8 ), INET_HEX_ESCAPE, INetURLObject::DECODE_WITH_CHARSET ) );
485cdf0e10cSrcweir if ( aBasMgrName.compareToAscii(".") == 0 )
486cdf0e10cSrcweir aLibrary = pDoc->GetTitle();
487cdf0e10cSrcweir /*
488cdf0e10cSrcweir else if ( aBasMgrName.getLength() )
489cdf0e10cSrcweir aLibrary = aBasMgrName;
490cdf0e10cSrcweir */
491cdf0e10cSrcweir else
492cdf0e10cSrcweir aLibrary = SFX_APP()->GetName();
493cdf0e10cSrcweir
494cdf0e10cSrcweir // Get the macro name
495cdf0e10cSrcweir aMacroName = aScript.copy( nHashPos+1, nArgsPos - nHashPos - 1 );
496cdf0e10cSrcweir }
497cdf0e10cSrcweir else
498cdf0e10cSrcweir {
499cdf0e10cSrcweir DBG_ERRORFILE( "ConvertToMacro: Unknown macro url format" );
500cdf0e10cSrcweir }
501cdf0e10cSrcweir }
502cdf0e10cSrcweir }
503cdf0e10cSrcweir else if ( aMacroName.getLength() )
504cdf0e10cSrcweir {
505cdf0e10cSrcweir aScript = OUSTRING( RTL_CONSTASCII_USTRINGPARAM( MACRO_PRFIX ) );
506cdf0e10cSrcweir if ( aLibrary.compareTo( SFX_APP()->GetName() ) != 0 && aLibrary.compareToAscii("StarDesktop") != 0 && aLibrary.compareToAscii("application") != 0 )
507cdf0e10cSrcweir aScript += String('.');
508cdf0e10cSrcweir
509cdf0e10cSrcweir aScript += String('/');
510cdf0e10cSrcweir aScript += aMacroName;
511cdf0e10cSrcweir aScript += OUSTRING( RTL_CONSTASCII_USTRINGPARAM( MACRO_POSTFIX ) );
512cdf0e10cSrcweir }
513cdf0e10cSrcweir else
514cdf0e10cSrcweir // wrong properties
515cdf0e10cSrcweir return;
516cdf0e10cSrcweir
517cdf0e10cSrcweir if ( aLibrary.compareToAscii("document") != 0 )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir if ( !aLibrary.getLength() || (pDoc && ( String(aLibrary) == pDoc->GetTitle( SFX_TITLE_APINAME ) || String(aLibrary) == pDoc->GetTitle() )) )
520cdf0e10cSrcweir aLibrary = String::CreateFromAscii("document");
521cdf0e10cSrcweir else
522cdf0e10cSrcweir aLibrary = String::CreateFromAscii("application");
523cdf0e10cSrcweir }
524cdf0e10cSrcweir
525cdf0e10cSrcweir o_normalizedDescriptor.put( PROP_SCRIPT, aScript );
526cdf0e10cSrcweir o_normalizedDescriptor.put( PROP_LIBRARY, aLibrary );
527cdf0e10cSrcweir o_normalizedDescriptor.put( PROP_MACRO_NAME, aMacroName );
528cdf0e10cSrcweir }
529cdf0e10cSrcweir }
530cdf0e10cSrcweir
ModelCollectionEnumeration(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)531cdf0e10cSrcweir ModelCollectionEnumeration::ModelCollectionEnumeration(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
532cdf0e10cSrcweir : ModelCollectionMutexBase( )
533cdf0e10cSrcweir , m_xSMGR (xSMGR )
534cdf0e10cSrcweir , m_pEnumerationIt (m_lModels.begin())
535cdf0e10cSrcweir {
536cdf0e10cSrcweir }
537cdf0e10cSrcweir
~ModelCollectionEnumeration()538cdf0e10cSrcweir ModelCollectionEnumeration::~ModelCollectionEnumeration()
539cdf0e10cSrcweir {
540cdf0e10cSrcweir }
541cdf0e10cSrcweir
setModelList(const TModelList & rList)542cdf0e10cSrcweir void ModelCollectionEnumeration::setModelList(const TModelList& rList)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir // SAFE ->
545cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
546cdf0e10cSrcweir m_lModels = rList;
547cdf0e10cSrcweir m_pEnumerationIt = m_lModels.begin();
548cdf0e10cSrcweir aLock.clear();
549cdf0e10cSrcweir // <- SAFE
550cdf0e10cSrcweir }
551cdf0e10cSrcweir
hasMoreElements()552cdf0e10cSrcweir sal_Bool SAL_CALL ModelCollectionEnumeration::hasMoreElements()
553cdf0e10cSrcweir throw(css::uno::RuntimeException)
554cdf0e10cSrcweir {
555cdf0e10cSrcweir // SAFE ->
556cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
557cdf0e10cSrcweir return (m_pEnumerationIt != m_lModels.end());
558cdf0e10cSrcweir // <- SAFE
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
nextElement()561cdf0e10cSrcweir css::uno::Any SAL_CALL ModelCollectionEnumeration::nextElement()
562cdf0e10cSrcweir throw(css::container::NoSuchElementException,
563cdf0e10cSrcweir css::lang::WrappedTargetException ,
564cdf0e10cSrcweir css::uno::RuntimeException )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir // SAFE ->
567cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
568cdf0e10cSrcweir if (m_pEnumerationIt == m_lModels.end())
569cdf0e10cSrcweir throw css::container::NoSuchElementException(
570cdf0e10cSrcweir ::rtl::OUString::createFromAscii("End of model enumeration reached."),
571cdf0e10cSrcweir static_cast< css::container::XEnumeration* >(this));
572cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel(*m_pEnumerationIt, UNO_QUERY);
573cdf0e10cSrcweir ++m_pEnumerationIt;
574cdf0e10cSrcweir aLock.clear();
575cdf0e10cSrcweir // <- SAFE
576cdf0e10cSrcweir
577cdf0e10cSrcweir return css::uno::makeAny(xModel);
578cdf0e10cSrcweir }
579cdf0e10cSrcweir
580cdf0e10cSrcweir SFX_IMPL_XSERVICEINFO( SfxGlobalEvents_Impl, "com.sun.star.frame.GlobalEventBroadcaster", "com.sun.star.comp.sfx2.GlobalEventBroadcaster" )
581cdf0e10cSrcweir SFX_IMPL_ONEINSTANCEFACTORY( SfxGlobalEvents_Impl );
582cdf0e10cSrcweir
583cdf0e10cSrcweir //-----------------------------------------------------------------------------
SfxGlobalEvents_Impl(const com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xSMGR)584cdf0e10cSrcweir SfxGlobalEvents_Impl::SfxGlobalEvents_Impl( const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& xSMGR)
585cdf0e10cSrcweir : ModelCollectionMutexBase( )
586cdf0e10cSrcweir , m_xSMGR (xSMGR )
587cdf0e10cSrcweir , m_aLegacyListeners (m_aLock)
588cdf0e10cSrcweir , m_aDocumentListeners (m_aLock)
589cdf0e10cSrcweir , pImp (0 )
590cdf0e10cSrcweir {
591cdf0e10cSrcweir m_refCount++;
592cdf0e10cSrcweir SFX_APP();
593cdf0e10cSrcweir pImp = new GlobalEventConfig();
594cdf0e10cSrcweir m_xEvents = pImp;
595cdf0e10cSrcweir m_xJobExecutorListener = css::uno::Reference< css::document::XEventListener >(
596cdf0e10cSrcweir xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.task.JobExecutor")),
597cdf0e10cSrcweir UNO_QUERY);
598cdf0e10cSrcweir m_refCount--;
599cdf0e10cSrcweir }
600cdf0e10cSrcweir
601cdf0e10cSrcweir //-----------------------------------------------------------------------------
~SfxGlobalEvents_Impl()602cdf0e10cSrcweir SfxGlobalEvents_Impl::~SfxGlobalEvents_Impl()
603cdf0e10cSrcweir {
604cdf0e10cSrcweir }
605cdf0e10cSrcweir
606cdf0e10cSrcweir //-----------------------------------------------------------------------------
getEvents()607cdf0e10cSrcweir css::uno::Reference< css::container::XNameReplace > SAL_CALL SfxGlobalEvents_Impl::getEvents()
608cdf0e10cSrcweir throw(css::uno::RuntimeException)
609cdf0e10cSrcweir {
610cdf0e10cSrcweir // SAFE ->
611cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
612cdf0e10cSrcweir return m_xEvents;
613cdf0e10cSrcweir // <- SAFE
614cdf0e10cSrcweir }
615cdf0e10cSrcweir
616cdf0e10cSrcweir //-----------------------------------------------------------------------------
addEventListener(const css::uno::Reference<css::document::XEventListener> & xListener)617cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::addEventListener(const css::uno::Reference< css::document::XEventListener >& xListener)
618cdf0e10cSrcweir throw(css::uno::RuntimeException)
619cdf0e10cSrcweir {
620cdf0e10cSrcweir // container is threadsafe
621cdf0e10cSrcweir m_aLegacyListeners.addInterface(xListener);
622cdf0e10cSrcweir }
623cdf0e10cSrcweir
624cdf0e10cSrcweir //-----------------------------------------------------------------------------
removeEventListener(const css::uno::Reference<css::document::XEventListener> & xListener)625cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::removeEventListener(const css::uno::Reference< css::document::XEventListener >& xListener)
626cdf0e10cSrcweir throw(css::uno::RuntimeException)
627cdf0e10cSrcweir {
628cdf0e10cSrcweir // container is threadsafe
629cdf0e10cSrcweir m_aLegacyListeners.removeInterface(xListener);
630cdf0e10cSrcweir }
631cdf0e10cSrcweir
632cdf0e10cSrcweir //-----------------------------------------------------------------------------
addDocumentEventListener(const css::uno::Reference<css::document::XDocumentEventListener> & _Listener)633cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::addDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& _Listener )
634cdf0e10cSrcweir throw(css::uno::RuntimeException)
635cdf0e10cSrcweir {
636cdf0e10cSrcweir m_aDocumentListeners.addInterface( _Listener );
637cdf0e10cSrcweir }
638cdf0e10cSrcweir
639cdf0e10cSrcweir //-----------------------------------------------------------------------------
removeDocumentEventListener(const css::uno::Reference<css::document::XDocumentEventListener> & _Listener)640cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::removeDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& _Listener )
641cdf0e10cSrcweir throw(css::uno::RuntimeException)
642cdf0e10cSrcweir {
643cdf0e10cSrcweir m_aDocumentListeners.removeInterface( _Listener );
644cdf0e10cSrcweir }
645cdf0e10cSrcweir
646cdf0e10cSrcweir //-----------------------------------------------------------------------------
notifyDocumentEvent(const::rtl::OUString &,const css::uno::Reference<css::frame::XController2> &,const css::uno::Any &)647cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::notifyDocumentEvent( const ::rtl::OUString& /*_EventName*/,
648cdf0e10cSrcweir const css::uno::Reference< css::frame::XController2 >& /*_ViewController*/, const css::uno::Any& /*_Supplement*/ )
649cdf0e10cSrcweir throw (css::lang::IllegalArgumentException, css::lang::NoSupportException, css::uno::RuntimeException)
650cdf0e10cSrcweir {
651cdf0e10cSrcweir // we're a multiplexer only, no chance to generate artifical events here
652cdf0e10cSrcweir throw css::lang::NoSupportException(::rtl::OUString(), *this);
653cdf0e10cSrcweir }
654cdf0e10cSrcweir
655cdf0e10cSrcweir //-----------------------------------------------------------------------------
notifyEvent(const css::document::EventObject & aEvent)656cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::notifyEvent(const css::document::EventObject& aEvent)
657cdf0e10cSrcweir throw(css::uno::RuntimeException)
658cdf0e10cSrcweir {
659cdf0e10cSrcweir css::document::DocumentEvent aDocEvent(aEvent.Source, aEvent.EventName, NULL, css::uno::Any());
660cdf0e10cSrcweir implts_notifyJobExecution(aEvent);
661cdf0e10cSrcweir implts_checkAndExecuteEventBindings(aDocEvent);
662cdf0e10cSrcweir implts_notifyListener(aDocEvent);
663cdf0e10cSrcweir }
664cdf0e10cSrcweir
665cdf0e10cSrcweir //-----------------------------------------------------------------------------
documentEventOccured(const::css::document::DocumentEvent & _Event)666cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::documentEventOccured( const ::css::document::DocumentEvent& _Event )
667cdf0e10cSrcweir throw (::css::uno::RuntimeException)
668cdf0e10cSrcweir {
669cdf0e10cSrcweir implts_notifyJobExecution(css::document::EventObject(_Event.Source, _Event.EventName));
670cdf0e10cSrcweir implts_checkAndExecuteEventBindings(_Event);
671cdf0e10cSrcweir implts_notifyListener(_Event);
672cdf0e10cSrcweir }
673cdf0e10cSrcweir
674cdf0e10cSrcweir //-----------------------------------------------------------------------------
disposing(const css::lang::EventObject & aEvent)675cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::disposing(const css::lang::EventObject& aEvent)
676cdf0e10cSrcweir throw(css::uno::RuntimeException)
677cdf0e10cSrcweir {
678cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xDoc(aEvent.Source, UNO_QUERY);
679cdf0e10cSrcweir
680cdf0e10cSrcweir // SAFE ->
681cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
682cdf0e10cSrcweir TModelList::iterator pIt = impl_searchDoc(xDoc);
683cdf0e10cSrcweir if (pIt != m_lModels.end())
684cdf0e10cSrcweir m_lModels.erase(pIt);
685cdf0e10cSrcweir aLock.clear();
686cdf0e10cSrcweir // <- SAFE
687cdf0e10cSrcweir }
688cdf0e10cSrcweir
689cdf0e10cSrcweir //-----------------------------------------------------------------------------
has(const css::uno::Any & aElement)690cdf0e10cSrcweir sal_Bool SAL_CALL SfxGlobalEvents_Impl::has(const css::uno::Any& aElement)
691cdf0e10cSrcweir throw (css::uno::RuntimeException)
692cdf0e10cSrcweir {
693cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xDoc;
694cdf0e10cSrcweir aElement >>= xDoc;
695cdf0e10cSrcweir
696cdf0e10cSrcweir sal_Bool bHas = sal_False;
697cdf0e10cSrcweir
698cdf0e10cSrcweir // SAFE ->
699cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
700cdf0e10cSrcweir TModelList::iterator pIt = impl_searchDoc(xDoc);
701cdf0e10cSrcweir if (pIt != m_lModels.end())
702cdf0e10cSrcweir bHas = sal_True;
703cdf0e10cSrcweir aLock.clear();
704cdf0e10cSrcweir // <- SAFE
705cdf0e10cSrcweir
706cdf0e10cSrcweir return bHas;
707cdf0e10cSrcweir }
708cdf0e10cSrcweir
709cdf0e10cSrcweir //-----------------------------------------------------------------------------
insert(const css::uno::Any & aElement)710cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::insert( const css::uno::Any& aElement )
711cdf0e10cSrcweir throw (css::lang::IllegalArgumentException ,
712cdf0e10cSrcweir css::container::ElementExistException,
713cdf0e10cSrcweir css::uno::RuntimeException )
714cdf0e10cSrcweir {
715cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xDoc;
716cdf0e10cSrcweir aElement >>= xDoc;
717cdf0e10cSrcweir if (!xDoc.is())
718cdf0e10cSrcweir throw css::lang::IllegalArgumentException(
719cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Cant locate at least the model parameter."),
720cdf0e10cSrcweir static_cast< css::container::XSet* >(this),
721cdf0e10cSrcweir 0);
722cdf0e10cSrcweir
723cdf0e10cSrcweir // SAFE ->
724cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
725cdf0e10cSrcweir TModelList::iterator pIt = impl_searchDoc(xDoc);
726cdf0e10cSrcweir if (pIt != m_lModels.end())
727cdf0e10cSrcweir throw css::container::ElementExistException(
728cdf0e10cSrcweir ::rtl::OUString(),
729cdf0e10cSrcweir static_cast< css::container::XSet* >(this));
730cdf0e10cSrcweir m_lModels.push_back(xDoc);
731cdf0e10cSrcweir aLock.clear();
732cdf0e10cSrcweir // <- SAFE
733cdf0e10cSrcweir
734cdf0e10cSrcweir css::uno::Reference< css::document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, UNO_QUERY );
735cdf0e10cSrcweir if (xDocBroadcaster.is())
736cdf0e10cSrcweir xDocBroadcaster->addDocumentEventListener(this);
737cdf0e10cSrcweir else
738cdf0e10cSrcweir {
739cdf0e10cSrcweir // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
740cdf0e10cSrcweir css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xDoc, UNO_QUERY);
741cdf0e10cSrcweir if (xBroadcaster.is())
742cdf0e10cSrcweir xBroadcaster->addEventListener(static_cast< css::document::XEventListener* >(this));
743cdf0e10cSrcweir }
744cdf0e10cSrcweir }
745cdf0e10cSrcweir
746cdf0e10cSrcweir //-----------------------------------------------------------------------------
remove(const css::uno::Any & aElement)747cdf0e10cSrcweir void SAL_CALL SfxGlobalEvents_Impl::remove( const css::uno::Any& aElement )
748cdf0e10cSrcweir throw (css::lang::IllegalArgumentException ,
749cdf0e10cSrcweir css::container::NoSuchElementException,
750cdf0e10cSrcweir css::uno::RuntimeException )
751cdf0e10cSrcweir {
752cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xDoc;
753cdf0e10cSrcweir aElement >>= xDoc;
754cdf0e10cSrcweir if (!xDoc.is())
755cdf0e10cSrcweir throw css::lang::IllegalArgumentException(
756cdf0e10cSrcweir ::rtl::OUString::createFromAscii("Cant locate at least the model parameter."),
757cdf0e10cSrcweir static_cast< css::container::XSet* >(this),
758cdf0e10cSrcweir 0);
759cdf0e10cSrcweir
760cdf0e10cSrcweir // SAFE ->
761cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
762cdf0e10cSrcweir TModelList::iterator pIt = impl_searchDoc(xDoc);
763cdf0e10cSrcweir if (pIt == m_lModels.end())
764cdf0e10cSrcweir throw css::container::NoSuchElementException(
765cdf0e10cSrcweir ::rtl::OUString(),
766cdf0e10cSrcweir static_cast< css::container::XSet* >(this));
767cdf0e10cSrcweir m_lModels.erase(pIt);
768cdf0e10cSrcweir aLock.clear();
769cdf0e10cSrcweir // <- SAFE
770cdf0e10cSrcweir
771cdf0e10cSrcweir css::uno::Reference< css::document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, UNO_QUERY );
772cdf0e10cSrcweir if (xDocBroadcaster.is())
773cdf0e10cSrcweir xDocBroadcaster->removeDocumentEventListener(this);
774cdf0e10cSrcweir else
775cdf0e10cSrcweir {
776cdf0e10cSrcweir // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
777cdf0e10cSrcweir css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xDoc, UNO_QUERY);
778cdf0e10cSrcweir if (xBroadcaster.is())
779cdf0e10cSrcweir xBroadcaster->removeEventListener(static_cast< css::document::XEventListener* >(this));
780cdf0e10cSrcweir }
781cdf0e10cSrcweir }
782cdf0e10cSrcweir
783cdf0e10cSrcweir //-----------------------------------------------------------------------------
createEnumeration()784cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > SAL_CALL SfxGlobalEvents_Impl::createEnumeration()
785cdf0e10cSrcweir throw (css::uno::RuntimeException)
786cdf0e10cSrcweir {
787cdf0e10cSrcweir // SAFE ->
788cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
789cdf0e10cSrcweir ModelCollectionEnumeration* pEnum = new ModelCollectionEnumeration(m_xSMGR);
790cdf0e10cSrcweir pEnum->setModelList(m_lModels);
791cdf0e10cSrcweir css::uno::Reference< css::container::XEnumeration > xEnum(
792cdf0e10cSrcweir static_cast< css::container::XEnumeration* >(pEnum),
793cdf0e10cSrcweir UNO_QUERY);
794cdf0e10cSrcweir aLock.clear();
795cdf0e10cSrcweir // <- SAFE
796cdf0e10cSrcweir
797cdf0e10cSrcweir return xEnum;
798cdf0e10cSrcweir }
799cdf0e10cSrcweir
800cdf0e10cSrcweir //-----------------------------------------------------------------------------
getElementType()801cdf0e10cSrcweir css::uno::Type SAL_CALL SfxGlobalEvents_Impl::getElementType()
802cdf0e10cSrcweir throw (css::uno::RuntimeException)
803cdf0e10cSrcweir {
804cdf0e10cSrcweir return ::getCppuType(static_cast< css::uno::Reference< css::frame::XModel >* >(NULL));
805cdf0e10cSrcweir }
806cdf0e10cSrcweir
807cdf0e10cSrcweir //-----------------------------------------------------------------------------
hasElements()808cdf0e10cSrcweir sal_Bool SAL_CALL SfxGlobalEvents_Impl::hasElements()
809cdf0e10cSrcweir throw (css::uno::RuntimeException)
810cdf0e10cSrcweir {
811cdf0e10cSrcweir // SAFE ->
812cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
813cdf0e10cSrcweir return (m_lModels.size()>0);
814cdf0e10cSrcweir // <- SAFE
815cdf0e10cSrcweir }
816cdf0e10cSrcweir
817cdf0e10cSrcweir //-----------------------------------------------------------------------------
implts_notifyJobExecution(const css::document::EventObject & aEvent)818cdf0e10cSrcweir void SfxGlobalEvents_Impl::implts_notifyJobExecution(const css::document::EventObject& aEvent)
819cdf0e10cSrcweir {
820cdf0e10cSrcweir try
821cdf0e10cSrcweir {
822cdf0e10cSrcweir // SAFE ->
823cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
824cdf0e10cSrcweir css::uno::Reference< css::document::XEventListener > xJobExecutor(m_xJobExecutorListener);
825cdf0e10cSrcweir aLock.clear();
826cdf0e10cSrcweir // <- SAFE
827cdf0e10cSrcweir if (xJobExecutor.is())
828cdf0e10cSrcweir xJobExecutor->notifyEvent(aEvent);
829cdf0e10cSrcweir }
830cdf0e10cSrcweir catch(const css::uno::RuntimeException& exRun)
831cdf0e10cSrcweir { throw exRun; }
832cdf0e10cSrcweir catch(const css::uno::Exception&)
833cdf0e10cSrcweir {}
834cdf0e10cSrcweir }
835cdf0e10cSrcweir
836cdf0e10cSrcweir //-----------------------------------------------------------------------------
implts_checkAndExecuteEventBindings(const css::document::DocumentEvent & aEvent)837cdf0e10cSrcweir void SfxGlobalEvents_Impl::implts_checkAndExecuteEventBindings(const css::document::DocumentEvent& aEvent)
838cdf0e10cSrcweir {
839cdf0e10cSrcweir try
840cdf0e10cSrcweir {
841cdf0e10cSrcweir // SAFE ->
842cdf0e10cSrcweir ::osl::ResettableMutexGuard aLock(m_aLock);
843cdf0e10cSrcweir css::uno::Reference< css::container::XNameReplace > xEvents = m_xEvents;
844cdf0e10cSrcweir aLock.clear();
845cdf0e10cSrcweir // <- SAFE
846cdf0e10cSrcweir
847cdf0e10cSrcweir css::uno::Any aAny;
848cdf0e10cSrcweir if ( xEvents.is() && xEvents->hasByName( aEvent.EventName ) )
849cdf0e10cSrcweir aAny = xEvents->getByName(aEvent.EventName);
850cdf0e10cSrcweir Execute(aAny, aEvent, 0);
851cdf0e10cSrcweir }
852cdf0e10cSrcweir catch ( css::uno::RuntimeException const & )
853cdf0e10cSrcweir {
854cdf0e10cSrcweir throw;
855cdf0e10cSrcweir }
856cdf0e10cSrcweir catch ( css::uno::Exception const & )
857cdf0e10cSrcweir {
858cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
859cdf0e10cSrcweir }
860cdf0e10cSrcweir }
861cdf0e10cSrcweir
862cdf0e10cSrcweir //-----------------------------------------------------------------------------
implts_notifyListener(const css::document::DocumentEvent & aEvent)863cdf0e10cSrcweir void SfxGlobalEvents_Impl::implts_notifyListener(const css::document::DocumentEvent& aEvent)
864cdf0e10cSrcweir {
865cdf0e10cSrcweir // containers are threadsafe
866cdf0e10cSrcweir css::document::EventObject aLegacyEvent(aEvent.Source, aEvent.EventName);
867cdf0e10cSrcweir m_aLegacyListeners.notifyEach( &css::document::XEventListener::notifyEvent, aLegacyEvent );
868cdf0e10cSrcweir
869cdf0e10cSrcweir m_aDocumentListeners.notifyEach( &css::document::XDocumentEventListener::documentEventOccured, aEvent );
870cdf0e10cSrcweir }
871cdf0e10cSrcweir
872cdf0e10cSrcweir //-----------------------------------------------------------------------------
873cdf0e10cSrcweir // not threadsafe ... must be locked from outside!
impl_searchDoc(const css::uno::Reference<css::frame::XModel> & xModel)874cdf0e10cSrcweir TModelList::iterator SfxGlobalEvents_Impl::impl_searchDoc(const css::uno::Reference< css::frame::XModel >& xModel)
875cdf0e10cSrcweir {
876cdf0e10cSrcweir if (!xModel.is())
877cdf0e10cSrcweir return m_lModels.end();
878cdf0e10cSrcweir
879cdf0e10cSrcweir TModelList::iterator pIt;
880cdf0e10cSrcweir for ( pIt = m_lModels.begin();
881cdf0e10cSrcweir pIt != m_lModels.end() ;
882cdf0e10cSrcweir ++pIt )
883cdf0e10cSrcweir {
884cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xContainerDoc(*pIt, UNO_QUERY);
885cdf0e10cSrcweir if (xContainerDoc == xModel)
886cdf0e10cSrcweir break;
887cdf0e10cSrcweir }
888cdf0e10cSrcweir
889cdf0e10cSrcweir return pIt;
890cdf0e10cSrcweir }
891cdf0e10cSrcweir
892