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