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