1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _SFX_EVENTSUPPLIER_HXX_ 29*cdf0e10cSrcweir #define _SFX_EVENTSUPPLIER_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/document/XEventListener.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/document/XEventBroadcaster.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentEventListener.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/task/XJobExecutor.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 42*cdf0e10cSrcweir #include <com/sun/star/uno/Type.hxx> 43*cdf0e10cSrcweir #include <sal/types.h> 44*cdf0e10cSrcweir #include <osl/mutex.hxx> 45*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 46*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 47*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 48*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 49*cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 50*cdf0e10cSrcweir #include <cppuhelper/implbase7.hxx> 51*cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx> 52*cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx> 53*cdf0e10cSrcweir #include <sfx2/sfxuno.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <vos/mutex.hxx> 56*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 57*cdf0e10cSrcweir #include <svl/lstner.hxx> 58*cdf0e10cSrcweir #include <unotools/eventcfg.hxx> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir namespace comphelper 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir class NamedValueCollection; 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------------- 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir #define NOSUCHELEMENTEXCEPTION ::com::sun::star::container::NoSuchElementException 68*cdf0e10cSrcweir #define XNAMEREPLACE ::com::sun::star::container::XNameReplace 69*cdf0e10cSrcweir #define DOCEVENTOBJECT ::com::sun::star::document::EventObject 70*cdf0e10cSrcweir #define XEVENTBROADCASTER ::com::sun::star::document::XEventBroadcaster 71*cdf0e10cSrcweir #define XDOCEVENTLISTENER ::com::sun::star::document::XEventListener 72*cdf0e10cSrcweir #define XEVENTSSUPPLIER ::com::sun::star::document::XEventsSupplier 73*cdf0e10cSrcweir #define XJOBEXECUTOR ::com::sun::star::task::XJobExecutor 74*cdf0e10cSrcweir #define EVENTOBJECT ::com::sun::star::lang::EventObject 75*cdf0e10cSrcweir #define ILLEGALARGUMENTEXCEPTION ::com::sun::star::lang::IllegalArgumentException 76*cdf0e10cSrcweir #define WRAPPEDTARGETEXCEPTION ::com::sun::star::lang::WrappedTargetException 77*cdf0e10cSrcweir #define ANY ::com::sun::star::uno::Any 78*cdf0e10cSrcweir #define REFERENCE ::com::sun::star::uno::Reference 79*cdf0e10cSrcweir #define WEAKREFERENCE ::com::sun::star::uno::WeakReference 80*cdf0e10cSrcweir #define RUNTIMEEXCEPTION ::com::sun::star::uno::RuntimeException 81*cdf0e10cSrcweir #define SEQUENCE ::com::sun::star::uno::Sequence 82*cdf0e10cSrcweir #define UNOTYPE ::com::sun::star::uno::Type 83*cdf0e10cSrcweir #define OUSTRING ::rtl::OUString 84*cdf0e10cSrcweir #define OINTERFACECONTAINERHELPER ::cppu::OInterfaceContainerHelper 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------------- 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir class SfxObjectShell; 89*cdf0e10cSrcweir class SfxBaseModel; 90*cdf0e10cSrcweir class SvxMacro; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------------- 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir class SfxEvents_Impl : public ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameReplace, ::com::sun::star::document::XEventListener > 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir SEQUENCE< OUSTRING > maEventNames; 97*cdf0e10cSrcweir SEQUENCE< ANY > maEventData; 98*cdf0e10cSrcweir REFERENCE< XEVENTBROADCASTER > mxBroadcaster; 99*cdf0e10cSrcweir ::osl::Mutex maMutex; 100*cdf0e10cSrcweir SfxObjectShell *mpObjShell; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir sal_Bool Warn_Impl( const String& ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir public: 105*cdf0e10cSrcweir SfxEvents_Impl( SfxObjectShell* pShell, 106*cdf0e10cSrcweir REFERENCE< XEVENTBROADCASTER > xBroadcaster ); 107*cdf0e10cSrcweir ~SfxEvents_Impl(); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // --- XNameReplace --- 110*cdf0e10cSrcweir virtual void SAL_CALL replaceByName( const OUSTRING & aName, const ANY & aElement ) 111*cdf0e10cSrcweir throw( ILLEGALARGUMENTEXCEPTION, NOSUCHELEMENTEXCEPTION, 112*cdf0e10cSrcweir WRAPPEDTARGETEXCEPTION, RUNTIMEEXCEPTION ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // --- XNameAccess ( parent of XNameReplace ) --- 115*cdf0e10cSrcweir virtual ANY SAL_CALL getByName( const OUSTRING& aName ) 116*cdf0e10cSrcweir throw( NOSUCHELEMENTEXCEPTION, WRAPPEDTARGETEXCEPTION, 117*cdf0e10cSrcweir RUNTIMEEXCEPTION ); 118*cdf0e10cSrcweir virtual SEQUENCE< OUSTRING > SAL_CALL getElementNames() throw ( RUNTIMEEXCEPTION ); 119*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasByName( const OUSTRING& aName ) throw ( RUNTIMEEXCEPTION ); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // --- XElementAccess ( parent of XNameAccess ) --- 122*cdf0e10cSrcweir virtual UNOTYPE SAL_CALL getElementType() throw ( RUNTIMEEXCEPTION ); 123*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements() throw ( RUNTIMEEXCEPTION ); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // --- ::document::XEventListener --- 126*cdf0e10cSrcweir virtual void SAL_CALL notifyEvent( const DOCEVENTOBJECT& aEvent ) 127*cdf0e10cSrcweir throw( RUNTIMEEXCEPTION ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // --- ::lang::XEventListener --- 130*cdf0e10cSrcweir virtual void SAL_CALL disposing( const EVENTOBJECT& Source ) 131*cdf0e10cSrcweir throw( RUNTIMEEXCEPTION ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir static SvxMacro* ConvertToMacro( const ANY& rElement, SfxObjectShell* pDoc, sal_Bool bNormalizeMacro ); 134*cdf0e10cSrcweir static void NormalizeMacro( const ANY& rIn, ANY& rOut, SfxObjectShell* pDoc ); 135*cdf0e10cSrcweir static void NormalizeMacro( 136*cdf0e10cSrcweir const ::comphelper::NamedValueCollection& i_eventDescriptor, 137*cdf0e10cSrcweir ::comphelper::NamedValueCollection& o_normalizedDescriptor, 138*cdf0e10cSrcweir SfxObjectShell* i_document ); 139*cdf0e10cSrcweir }; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir //============================================================================= 142*cdf0e10cSrcweir struct ModelCollectionMutexBase 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir public: 145*cdf0e10cSrcweir ::osl::Mutex m_aLock; 146*cdf0e10cSrcweir }; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir //============================================================================= 149*cdf0e10cSrcweir typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > > TModelList; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir //============================================================================= 152*cdf0e10cSrcweir class ModelCollectionEnumeration : public ModelCollectionMutexBase 153*cdf0e10cSrcweir , public ::cppu::WeakImplHelper1< ::com::sun::star::container::XEnumeration > 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir //------------------------------------------------------------------------- 157*cdf0e10cSrcweir // member 158*cdf0e10cSrcweir //------------------------------------------------------------------------- 159*cdf0e10cSrcweir private: 160*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMGR; 161*cdf0e10cSrcweir TModelList m_lModels; 162*cdf0e10cSrcweir TModelList::iterator m_pEnumerationIt; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir //------------------------------------------------------------------------- 165*cdf0e10cSrcweir // native interface 166*cdf0e10cSrcweir //------------------------------------------------------------------------- 167*cdf0e10cSrcweir public: 168*cdf0e10cSrcweir ModelCollectionEnumeration(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMGR); 169*cdf0e10cSrcweir virtual ~ModelCollectionEnumeration(); 170*cdf0e10cSrcweir void setModelList(const TModelList& rList); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir //------------------------------------------------------------------------- 173*cdf0e10cSrcweir // uno interface 174*cdf0e10cSrcweir //------------------------------------------------------------------------- 175*cdf0e10cSrcweir public: 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // css.container.XEnumeration 178*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasMoreElements() 179*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL nextElement() 182*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, 183*cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException , 184*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ); 185*cdf0e10cSrcweir }; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir //============================================================================= 188*cdf0e10cSrcweir class SfxGlobalEvents_Impl : public ModelCollectionMutexBase 189*cdf0e10cSrcweir , public ::cppu::WeakImplHelper7< ::com::sun::star::lang::XServiceInfo 190*cdf0e10cSrcweir , ::com::sun::star::document::XEventsSupplier 191*cdf0e10cSrcweir , ::com::sun::star::document::XEventBroadcaster 192*cdf0e10cSrcweir , ::com::sun::star::document::XDocumentEventBroadcaster 193*cdf0e10cSrcweir , ::com::sun::star::document::XEventListener 194*cdf0e10cSrcweir , ::com::sun::star::document::XDocumentEventListener 195*cdf0e10cSrcweir , ::com::sun::star::container::XSet > 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMGR; 198*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > m_xEvents; 199*cdf0e10cSrcweir ::com::sun::star::uno::WeakReference< ::com::sun::star::document::XEventListener > m_xJobExecutorListener; 200*cdf0e10cSrcweir OINTERFACECONTAINERHELPER m_aLegacyListeners; 201*cdf0e10cSrcweir OINTERFACECONTAINERHELPER m_aDocumentListeners; 202*cdf0e10cSrcweir TModelList m_lModels; 203*cdf0e10cSrcweir GlobalEventConfig* pImp; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir public: 206*cdf0e10cSrcweir SfxGlobalEvents_Impl(const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& xSMGR); 207*cdf0e10cSrcweir virtual ~SfxGlobalEvents_Impl(); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir SFX_DECL_XSERVICEINFO 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // css.document.XEventBroadcaster 212*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents() 213*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& xListener) 216*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& xListener) 219*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // css.document.XDocumentEventBroadcaster 222*cdf0e10cSrcweir virtual void SAL_CALL addDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException); 223*cdf0e10cSrcweir virtual void SAL_CALL removeDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException); 224*cdf0e10cSrcweir virtual void SAL_CALL notifyDocumentEvent( const ::rtl::OUString& _EventName, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _ViewController, const ::com::sun::star::uno::Any& _Supplement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir // css.document.XEventListener 227*cdf0e10cSrcweir virtual void SAL_CALL notifyEvent(const ::com::sun::star::document::EventObject& aEvent) 228*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir // css.document.XDocumentEventListener 231*cdf0e10cSrcweir virtual void SAL_CALL documentEventOccured( const ::com::sun::star::document::DocumentEvent& Event ) throw (::com::sun::star::uno::RuntimeException); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir // css.container.XSet 234*cdf0e10cSrcweir virtual sal_Bool SAL_CALL has(const ::com::sun::star::uno::Any& aElement) 235*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir virtual void SAL_CALL insert(const ::com::sun::star::uno::Any& aElement) 238*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException , 239*cdf0e10cSrcweir ::com::sun::star::container::ElementExistException, 240*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir virtual void SAL_CALL remove(const ::com::sun::star::uno::Any& aElement) 243*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException , 244*cdf0e10cSrcweir ::com::sun::star::container::NoSuchElementException, 245*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException ); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // css.container.XEnumerationAccess 248*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration() 249*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // css.container.XElementAccess 252*cdf0e10cSrcweir virtual ::com::sun::star::uno::Type SAL_CALL getElementType() 253*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements() 256*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // css.lang.XEventListener 259*cdf0e10cSrcweir virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& aEvent) 260*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir private: 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir // threadsafe 265*cdf0e10cSrcweir void implts_notifyJobExecution(const ::com::sun::star::document::EventObject& aEvent); 266*cdf0e10cSrcweir void implts_checkAndExecuteEventBindings(const ::com::sun::star::document::DocumentEvent& aEvent); 267*cdf0e10cSrcweir void implts_notifyListener(const ::com::sun::star::document::DocumentEvent& aEvent); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir // not threadsafe 270*cdf0e10cSrcweir TModelList::iterator impl_searchDoc(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel); 271*cdf0e10cSrcweir }; 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir #endif 274