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