xref: /trunk/main/sfx2/source/inc/eventsupplier.hxx (revision 353d8f4d)
1*353d8f4dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*353d8f4dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*353d8f4dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*353d8f4dSAndrew Rist  * distributed with this work for additional information
6*353d8f4dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*353d8f4dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*353d8f4dSAndrew Rist  * "License"); you may not use this file except in compliance
9*353d8f4dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*353d8f4dSAndrew Rist  *
11*353d8f4dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*353d8f4dSAndrew Rist  *
13*353d8f4dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*353d8f4dSAndrew Rist  * software distributed under the License is distributed on an
15*353d8f4dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*353d8f4dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*353d8f4dSAndrew Rist  * specific language governing permissions and limitations
18*353d8f4dSAndrew Rist  * under the License.
19*353d8f4dSAndrew Rist  *
20*353d8f4dSAndrew Rist  *************************************************************/
21*353d8f4dSAndrew Rist 
22*353d8f4dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SFX_EVENTSUPPLIER_HXX_
25cdf0e10cSrcweir #define _SFX_EVENTSUPPLIER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
28cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp>
29cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp>
30cdf0e10cSrcweir #include <com/sun/star/document/XEventListener.hpp>
31cdf0e10cSrcweir #include <com/sun/star/document/XEventBroadcaster.hpp>
32cdf0e10cSrcweir #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
33cdf0e10cSrcweir #include <com/sun/star/document/XDocumentEventListener.hpp>
34cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
36cdf0e10cSrcweir #include <com/sun/star/task/XJobExecutor.hpp>
37cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
38cdf0e10cSrcweir #include <com/sun/star/uno/Type.hxx>
39cdf0e10cSrcweir #include <sal/types.h>
40cdf0e10cSrcweir #include <osl/mutex.hxx>
41cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
42cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
43cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
44cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
45cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>
46cdf0e10cSrcweir #include <cppuhelper/implbase7.hxx>
47cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
48cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx>
49cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <vos/mutex.hxx>
52cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
53cdf0e10cSrcweir #include <svl/lstner.hxx>
54cdf0e10cSrcweir #include <unotools/eventcfg.hxx>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir namespace comphelper
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     class NamedValueCollection;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #define NOSUCHELEMENTEXCEPTION		::com::sun::star::container::NoSuchElementException
64cdf0e10cSrcweir #define XNAMEREPLACE				::com::sun::star::container::XNameReplace
65cdf0e10cSrcweir #define DOCEVENTOBJECT				::com::sun::star::document::EventObject
66cdf0e10cSrcweir #define	XEVENTBROADCASTER			::com::sun::star::document::XEventBroadcaster
67cdf0e10cSrcweir #define XDOCEVENTLISTENER			::com::sun::star::document::XEventListener
68cdf0e10cSrcweir #define	XEVENTSSUPPLIER				::com::sun::star::document::XEventsSupplier
69cdf0e10cSrcweir #define XJOBEXECUTOR                ::com::sun::star::task::XJobExecutor
70cdf0e10cSrcweir #define EVENTOBJECT					::com::sun::star::lang::EventObject
71cdf0e10cSrcweir #define ILLEGALARGUMENTEXCEPTION	::com::sun::star::lang::IllegalArgumentException
72cdf0e10cSrcweir #define WRAPPEDTARGETEXCEPTION		::com::sun::star::lang::WrappedTargetException
73cdf0e10cSrcweir #define ANY							::com::sun::star::uno::Any
74cdf0e10cSrcweir #define	REFERENCE					::com::sun::star::uno::Reference
75cdf0e10cSrcweir #define WEAKREFERENCE               ::com::sun::star::uno::WeakReference
76cdf0e10cSrcweir #define RUNTIMEEXCEPTION			::com::sun::star::uno::RuntimeException
77cdf0e10cSrcweir #define SEQUENCE					::com::sun::star::uno::Sequence
78cdf0e10cSrcweir #define UNOTYPE						::com::sun::star::uno::Type
79cdf0e10cSrcweir #define OUSTRING					::rtl::OUString
80cdf0e10cSrcweir #define	OINTERFACECONTAINERHELPER   ::cppu::OInterfaceContainerHelper
81cdf0e10cSrcweir 
82cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
83cdf0e10cSrcweir 
84cdf0e10cSrcweir class SfxObjectShell;
85cdf0e10cSrcweir class SfxBaseModel;
86cdf0e10cSrcweir class SvxMacro;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------
89cdf0e10cSrcweir 
90cdf0e10cSrcweir class SfxEvents_Impl : public ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameReplace, ::com::sun::star::document::XEventListener  >
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	SEQUENCE< OUSTRING >			maEventNames;
93cdf0e10cSrcweir 	SEQUENCE< ANY >					maEventData;
94cdf0e10cSrcweir 	REFERENCE< XEVENTBROADCASTER >	mxBroadcaster;
95cdf0e10cSrcweir 	::osl::Mutex					maMutex;
96cdf0e10cSrcweir 	SfxObjectShell				   *mpObjShell;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     sal_Bool                    Warn_Impl( const String& );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir public:
101cdf0e10cSrcweir 								SfxEvents_Impl( SfxObjectShell* pShell,
102cdf0e10cSrcweir 												REFERENCE< XEVENTBROADCASTER > xBroadcaster );
103cdf0e10cSrcweir 							   ~SfxEvents_Impl();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	//  --- XNameReplace ---
106cdf0e10cSrcweir     virtual void SAL_CALL		replaceByName( const OUSTRING & aName, const ANY & aElement )
107cdf0e10cSrcweir 									throw( ILLEGALARGUMENTEXCEPTION, NOSUCHELEMENTEXCEPTION,
108cdf0e10cSrcweir 										   WRAPPEDTARGETEXCEPTION, RUNTIMEEXCEPTION );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	//  --- XNameAccess ( parent of XNameReplace ) ---
111cdf0e10cSrcweir     virtual ANY SAL_CALL		getByName( const OUSTRING& aName )
112cdf0e10cSrcweir 									throw( NOSUCHELEMENTEXCEPTION, WRAPPEDTARGETEXCEPTION,
113cdf0e10cSrcweir 										   RUNTIMEEXCEPTION );
114cdf0e10cSrcweir     virtual SEQUENCE< OUSTRING > SAL_CALL getElementNames() throw ( RUNTIMEEXCEPTION );
115cdf0e10cSrcweir     virtual sal_Bool SAL_CALL	hasByName( const OUSTRING& aName ) throw ( RUNTIMEEXCEPTION );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	//  --- XElementAccess ( parent of XNameAccess ) ---
118cdf0e10cSrcweir     virtual UNOTYPE SAL_CALL	getElementType() throw ( RUNTIMEEXCEPTION );
119cdf0e10cSrcweir     virtual sal_Bool SAL_CALL	hasElements() throw ( RUNTIMEEXCEPTION );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     // --- ::document::XEventListener ---
122cdf0e10cSrcweir     virtual void SAL_CALL		notifyEvent( const DOCEVENTOBJECT& aEvent )
123cdf0e10cSrcweir 									throw( RUNTIMEEXCEPTION );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     // --- ::lang::XEventListener ---
126cdf0e10cSrcweir     virtual void SAL_CALL		disposing( const EVENTOBJECT& Source )
127cdf0e10cSrcweir 									throw( RUNTIMEEXCEPTION );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     static SvxMacro*            ConvertToMacro( const ANY& rElement, SfxObjectShell* pDoc, sal_Bool bNormalizeMacro );
130cdf0e10cSrcweir 	static void					NormalizeMacro( const ANY& rIn, ANY& rOut, SfxObjectShell* pDoc );
131cdf0e10cSrcweir     static void					NormalizeMacro(
132cdf0e10cSrcweir                                     const ::comphelper::NamedValueCollection& i_eventDescriptor,
133cdf0e10cSrcweir                                     ::comphelper::NamedValueCollection& o_normalizedDescriptor,
134cdf0e10cSrcweir                                     SfxObjectShell* i_document );
135cdf0e10cSrcweir };
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //=============================================================================
138cdf0e10cSrcweir struct ModelCollectionMutexBase
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     public:
141cdf0e10cSrcweir         ::osl::Mutex m_aLock;
142cdf0e10cSrcweir };
143cdf0e10cSrcweir 
144cdf0e10cSrcweir //=============================================================================
145cdf0e10cSrcweir typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > > TModelList;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir //=============================================================================
148cdf0e10cSrcweir class ModelCollectionEnumeration : public ModelCollectionMutexBase
149cdf0e10cSrcweir                                  , public ::cppu::WeakImplHelper1< ::com::sun::star::container::XEnumeration >
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     //-------------------------------------------------------------------------
153cdf0e10cSrcweir     // member
154cdf0e10cSrcweir     //-------------------------------------------------------------------------
155cdf0e10cSrcweir     private:
156cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMGR;
157cdf0e10cSrcweir         TModelList m_lModels;
158cdf0e10cSrcweir         TModelList::iterator m_pEnumerationIt;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     //-------------------------------------------------------------------------
161cdf0e10cSrcweir     // native interface
162cdf0e10cSrcweir     //-------------------------------------------------------------------------
163cdf0e10cSrcweir     public:
164cdf0e10cSrcweir         ModelCollectionEnumeration(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMGR);
165cdf0e10cSrcweir         virtual ~ModelCollectionEnumeration();
166cdf0e10cSrcweir         void setModelList(const TModelList& rList);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     //-------------------------------------------------------------------------
169cdf0e10cSrcweir     // uno interface
170cdf0e10cSrcweir     //-------------------------------------------------------------------------
171cdf0e10cSrcweir     public:
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         // css.container.XEnumeration
174cdf0e10cSrcweir         virtual sal_Bool SAL_CALL hasMoreElements()
175cdf0e10cSrcweir             throw(::com::sun::star::uno::RuntimeException);
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         virtual ::com::sun::star::uno::Any SAL_CALL nextElement()
178cdf0e10cSrcweir             throw(::com::sun::star::container::NoSuchElementException,
179cdf0e10cSrcweir                   ::com::sun::star::lang::WrappedTargetException     ,
180cdf0e10cSrcweir                   ::com::sun::star::uno::RuntimeException            );
181cdf0e10cSrcweir };
182cdf0e10cSrcweir 
183cdf0e10cSrcweir //=============================================================================
184cdf0e10cSrcweir class SfxGlobalEvents_Impl : public ModelCollectionMutexBase
185cdf0e10cSrcweir                            , public ::cppu::WeakImplHelper7< ::com::sun::star::lang::XServiceInfo
186cdf0e10cSrcweir                                                            , ::com::sun::star::document::XEventsSupplier
187cdf0e10cSrcweir                                                            , ::com::sun::star::document::XEventBroadcaster
188cdf0e10cSrcweir                                                            , ::com::sun::star::document::XDocumentEventBroadcaster
189cdf0e10cSrcweir                                                            , ::com::sun::star::document::XEventListener
190cdf0e10cSrcweir                                                            , ::com::sun::star::document::XDocumentEventListener
191cdf0e10cSrcweir                                                            , ::com::sun::star::container::XSet >
192cdf0e10cSrcweir {
193cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xSMGR;
194cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > m_xEvents;
195cdf0e10cSrcweir     ::com::sun::star::uno::WeakReference< ::com::sun::star::document::XEventListener > m_xJobExecutorListener;
196cdf0e10cSrcweir 	OINTERFACECONTAINERHELPER m_aLegacyListeners;
197cdf0e10cSrcweir     OINTERFACECONTAINERHELPER m_aDocumentListeners;
198cdf0e10cSrcweir     TModelList m_lModels;
199cdf0e10cSrcweir 	GlobalEventConfig* pImp;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir public:
202cdf0e10cSrcweir     SfxGlobalEvents_Impl(const com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& xSMGR);
203cdf0e10cSrcweir     virtual ~SfxGlobalEvents_Impl();
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     SFX_DECL_XSERVICEINFO
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     // css.document.XEventBroadcaster
208cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents()
209cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& xListener)
212cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& xListener)
215cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     // css.document.XDocumentEventBroadcaster
218cdf0e10cSrcweir     virtual void SAL_CALL addDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException);
219cdf0e10cSrcweir     virtual void SAL_CALL removeDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException);
220cdf0e10cSrcweir     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);
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     // css.document.XEventListener
223cdf0e10cSrcweir     virtual void SAL_CALL notifyEvent(const ::com::sun::star::document::EventObject& aEvent)
224cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     // css.document.XDocumentEventListener
227cdf0e10cSrcweir     virtual void SAL_CALL documentEventOccured( const ::com::sun::star::document::DocumentEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     // css.container.XSet
230cdf0e10cSrcweir     virtual sal_Bool SAL_CALL has(const ::com::sun::star::uno::Any& aElement)
231cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     virtual void SAL_CALL insert(const ::com::sun::star::uno::Any& aElement)
234cdf0e10cSrcweir         throw(::com::sun::star::lang::IllegalArgumentException  ,
235cdf0e10cSrcweir               ::com::sun::star::container::ElementExistException,
236cdf0e10cSrcweir               ::com::sun::star::uno::RuntimeException           );
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     virtual void SAL_CALL remove(const ::com::sun::star::uno::Any& aElement)
239cdf0e10cSrcweir         throw(::com::sun::star::lang::IllegalArgumentException   ,
240cdf0e10cSrcweir               ::com::sun::star::container::NoSuchElementException,
241cdf0e10cSrcweir               ::com::sun::star::uno::RuntimeException            );
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     // css.container.XEnumerationAccess
244cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration()
245cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     // css.container.XElementAccess
248cdf0e10cSrcweir     virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
249cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements()
252cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     // css.lang.XEventListener
255cdf0e10cSrcweir     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& aEvent)
256cdf0e10cSrcweir         throw(::com::sun::star::uno::RuntimeException);
257cdf0e10cSrcweir 
258cdf0e10cSrcweir private:
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     // threadsafe
261cdf0e10cSrcweir     void implts_notifyJobExecution(const ::com::sun::star::document::EventObject& aEvent);
262cdf0e10cSrcweir     void implts_checkAndExecuteEventBindings(const ::com::sun::star::document::DocumentEvent& aEvent);
263cdf0e10cSrcweir     void implts_notifyListener(const ::com::sun::star::document::DocumentEvent& aEvent);
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     // not threadsafe
266cdf0e10cSrcweir     TModelList::iterator impl_searchDoc(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xModel);
267cdf0e10cSrcweir };
268cdf0e10cSrcweir 
269cdf0e10cSrcweir #endif
270