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 _FRM_INTERFACE_CONTAINER_HXX_
21 : #define _FRM_INTERFACE_CONTAINER_HXX_
22 :
23 : #include <boost/unordered_map.hpp>
24 : #include <comphelper/stl_types.hxx>
25 : #include <comphelper/types.hxx>
26 : #include <comphelper/uno3.hxx>
27 : #include <com/sun/star/container/XNameReplace.hpp>
28 : #include <com/sun/star/container/XIndexReplace.hpp>
29 : #include <com/sun/star/container/XNameContainer.hpp>
30 : #include <com/sun/star/lang/XEventListener.hpp>
31 : #include <com/sun/star/lang/EventObject.hpp>
32 : #include <com/sun/star/container/XEnumerationAccess.hpp>
33 : #include <com/sun/star/io/XPersistObject.hpp>
34 : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
35 : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
36 : #include <com/sun/star/beans/XPropertySet.hpp>
37 : #include <com/sun/star/script/XEventAttacherManager.hpp>
38 : #include <com/sun/star/script/ScriptEvent.hpp>
39 : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
40 : #include <com/sun/star/container/XContainer.hpp>
41 : #include <com/sun/star/container/XIndexContainer.hpp>
42 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 : #include <com/sun/star/form/XFormComponent.hpp>
44 : #include <com/sun/star/util/XCloneable.hpp>
45 : #include <osl/mutex.hxx>
46 : #include <cppuhelper/interfacecontainer.hxx>
47 : #include <cppuhelper/component.hxx>
48 : #include <cppuhelper/implbase8.hxx>
49 :
50 : using namespace comphelper;
51 :
52 : //.........................................................................
53 : namespace frm
54 : {
55 : //.........................................................................
56 :
57 :
58 : //==================================================================
59 : struct ElementDescription
60 : {
61 : public:
62 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xInterface;
63 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropertySet;
64 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild;
65 : ::com::sun::star::uno::Any aElementTypeInterface;
66 :
67 : public:
68 : ElementDescription( );
69 : virtual ~ElementDescription();
70 :
71 : private:
72 : ElementDescription( const ElementDescription& ); // never implemented
73 : ElementDescription& operator=( const ElementDescription& ); // never implemented
74 : };
75 :
76 : typedef ::std::vector<InterfaceRef> OInterfaceArray;
77 : typedef ::boost::unordered_multimap< ::rtl::OUString, InterfaceRef, ::rtl::OUStringHash, ::comphelper::UStringEqual> OInterfaceMap;
78 :
79 : //==================================================================
80 : // OInterfaceContainer
81 : // implements a container for form components
82 : //==================================================================
83 : typedef ::cppu::ImplHelper8 < ::com::sun::star::container::XNameContainer
84 : , ::com::sun::star::container::XIndexContainer
85 : , ::com::sun::star::container::XContainer
86 : , ::com::sun::star::container::XEnumerationAccess
87 : , ::com::sun::star::script::XEventAttacherManager
88 : , ::com::sun::star::beans::XPropertyChangeListener
89 : , ::com::sun::star::io::XPersistObject
90 : , ::com::sun::star::util::XCloneable
91 : > OInterfaceContainer_BASE;
92 :
93 : class OInterfaceContainer : public OInterfaceContainer_BASE
94 : {
95 : protected:
96 : ::osl::Mutex& m_rMutex;
97 :
98 : OInterfaceArray m_aItems;
99 : OInterfaceMap m_aMap;
100 : ::cppu::OInterfaceContainerHelper m_aContainerListeners;
101 :
102 : const ::com::sun::star::uno::Type m_aElementType;
103 :
104 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory> m_xServiceFactory;
105 :
106 :
107 : // EventManager
108 : ::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacherManager> m_xEventAttacher;
109 :
110 : public:
111 : OInterfaceContainer(
112 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory,
113 : ::osl::Mutex& _rMutex,
114 : const ::com::sun::star::uno::Type& _rElementType);
115 :
116 : OInterfaceContainer( ::osl::Mutex& _rMutex, const OInterfaceContainer& _cloneSource );
117 :
118 : // late constructor for cloning
119 : void clonedFrom( const OInterfaceContainer& _cloneSource );
120 :
121 : protected:
122 : virtual ~OInterfaceContainer();
123 :
124 : public:
125 : // ::com::sun::star::io::XPersistObject
126 : virtual ::rtl::OUString SAL_CALL getServiceName( ) throw(::com::sun::star::uno::RuntimeException) = 0;
127 : virtual void SAL_CALL write( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream >& OutStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
128 : virtual void SAL_CALL read( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream >& InStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
129 :
130 : // ::com::sun::star::lang::XEventListener
131 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException);
132 :
133 : // ::com::sun::star::beans::XPropertyChangeListener
134 : virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw (::com::sun::star::uno::RuntimeException);
135 :
136 : // ::com::sun::star::container::XElementAccess
137 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException) ;
138 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
139 :
140 : // ::com::sun::star::container::XEnumerationAccess
141 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration> SAL_CALL createEnumeration() throw(::com::sun::star::uno::RuntimeException);
142 :
143 : // ::com::sun::star::container::XNameAccess
144 : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
145 : virtual StringSequence SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException);
146 : virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
147 :
148 : // ::com::sun::star::container::XNameReplace
149 : virtual void SAL_CALL replaceByName(const ::rtl::OUString& Name, const ::com::sun::star::uno::Any& _rElement) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
150 :
151 : // ::com::sun::star::container::XNameContainer
152 : virtual void SAL_CALL insertByName(const ::rtl::OUString& Name, const ::com::sun::star::uno::Any& _rElement) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
153 : virtual void SAL_CALL removeByName(const ::rtl::OUString& Name) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
154 :
155 : // ::com::sun::star::container::XIndexAccess
156 : virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException);
157 : virtual ::com::sun::star::uno::Any SAL_CALL getByIndex(sal_Int32 _nIndex) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
158 :
159 : // ::com::sun::star::container::XIndexReplace
160 : virtual void SAL_CALL replaceByIndex(sal_Int32 _nIndex, const ::com::sun::star::uno::Any& _rElement) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
161 :
162 : // ::com::sun::star::container::XIndexContainer
163 : virtual void SAL_CALL insertByIndex(sal_Int32 _nIndex, const ::com::sun::star::uno::Any& Element) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
164 : virtual void SAL_CALL removeByIndex(sal_Int32 _nIndex) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
165 :
166 : // ::com::sun::star::container::XContainer
167 : virtual void SAL_CALL addContainerListener(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
168 : virtual void SAL_CALL removeContainerListener(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
169 :
170 : // ::com::sun::star::script::XEventAttacherManager
171 : virtual void SAL_CALL registerScriptEvent( sal_Int32 nIndex, const ::com::sun::star::script::ScriptEventDescriptor& aScriptEvent ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
172 : virtual void SAL_CALL registerScriptEvents( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& aScriptEvents ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
173 : virtual void SAL_CALL revokeScriptEvent( sal_Int32 nIndex, const ::rtl::OUString& aListenerType, const ::rtl::OUString& aEventMethod, const ::rtl::OUString& aRemoveListenerParam ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
174 : virtual void SAL_CALL revokeScriptEvents( sal_Int32 nIndex ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
175 : virtual void SAL_CALL insertEntry( sal_Int32 nIndex ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
176 : virtual void SAL_CALL removeEntry( sal_Int32 nIndex ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
177 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor > SAL_CALL getScriptEvents( sal_Int32 Index ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
178 : virtual void SAL_CALL attach( sal_Int32 nIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xObject, const ::com::sun::star::uno::Any& aHelper ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ServiceNotRegisteredException, ::com::sun::star::uno::RuntimeException);
179 : virtual void SAL_CALL detach( sal_Int32 nIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xObject ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
180 : virtual void SAL_CALL addScriptListener( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& xListener ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
181 : virtual void SAL_CALL removeScriptListener( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XScriptListener >& Listener ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
182 :
183 : protected:
184 : // helper
185 : virtual void SAL_CALL disposing();
186 : virtual void removeElementsNoEvents(sal_Int32 nIndex);
187 :
188 : /** to be overridden if elements which are to be inserted into the container shall be checked
189 :
190 : <p>the ElementDescription given can be used to cache information about the object - it will be passed
191 : later on to implInserted/implReplaced.</p>
192 : */
193 : virtual void approveNewElement(
194 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject,
195 : ElementDescription* _pElement
196 : );
197 :
198 : virtual ElementDescription* createElementMetaData( );
199 :
200 : /** inserts an object into our internal structures
201 :
202 : @param _nIndex
203 : the index at which position it should be inserted
204 : @param _bEvents
205 : if <TRUE/>, event knittings will be done
206 : @param _pApprovalResult
207 : must contain the result of an approveNewElement call. Can be <NULL/>, in this case, the approval
208 : is done within implInsert.
209 : @param _bFire
210 : if <TRUE/>, a notification about the insertion will be fired
211 : */
212 : void implInsert(
213 : sal_Int32 _nIndex,
214 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject,
215 : sal_Bool _bEvents /* = sal_True */,
216 : ElementDescription* _pApprovalResult /* = NULL */ ,
217 : sal_Bool _bFire /* = sal_True */
218 : ) throw(::com::sun::star::lang::IllegalArgumentException);
219 :
220 : // called after the object is inserted, but before the "real listeners" are notified
221 : virtual void implInserted( const ElementDescription* _pElement );
222 : // called after the object is removed, but before the "real listeners" are notified
223 : virtual void implRemoved(const InterfaceRef& _rxObject);
224 :
225 : /** called after an object was replaced. The default implementation notifies our listeners, after releasing
226 : the instance lock.
227 : */
228 : virtual void impl_replacedElement(
229 : const ::com::sun::star::container::ContainerEvent& _rEvent,
230 : ::osl::ClearableMutexGuard& _rInstanceLock
231 : );
232 :
233 : void SAL_CALL writeEvents(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream);
234 : void SAL_CALL readEvents(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream);
235 :
236 : /** replace an element, specified by position
237 :
238 : @precond <arg>_nIndex</arg> is a valid index
239 : @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
240 :
241 : */
242 : void implReplaceByIndex(
243 : const sal_Int32 _nIndex,
244 : const ::com::sun::star::uno::Any& _rNewElement,
245 : ::osl::ClearableMutexGuard& _rClearBeforeNotify
246 : );
247 :
248 : /** removes an element, specified by position
249 :
250 : @precond <arg>_nIndex</arg> is a valid index
251 : @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
252 :
253 : */
254 : void implRemoveByIndex(
255 : const sal_Int32 _nIndex,
256 : ::osl::ClearableMutexGuard& _rClearBeforeNotify
257 : );
258 :
259 : /** validates the given index
260 : @throws ::com::sun::star::lang::IndexOutOfBoundsException
261 : if the given index does not denote a valid position in our children array
262 : */
263 : void implCheckIndex( const sal_Int32 _nIndex ) SAL_THROW( ( ::com::sun::star::lang::IndexOutOfBoundsException ) );
264 :
265 : private:
266 : // hack for Vba Events
267 : void impl_addVbEvents_nolck_nothrow( const sal_Int32 i_nIndex );
268 :
269 : // the runtime event format has changed from version SO5.2 to OOo
270 : enum EventFormat
271 : {
272 : efVersionSO5x,
273 : efVersionSO6x
274 : };
275 : void transformEvents( const EventFormat _eTargetFormat );
276 :
277 : void impl_createEventAttacher_nothrow();
278 : };
279 :
280 : //==================================================================
281 : //= OFormComponents
282 : //==================================================================
283 : typedef ::cppu::ImplHelper1< ::com::sun::star::form::XFormComponent> OFormComponents_BASE;
284 : typedef ::cppu::OComponentHelper FormComponentsBase;
285 : // else MSVC kills itself on some statements
286 : class OFormComponents :public FormComponentsBase
287 : ,public OInterfaceContainer
288 : ,public OFormComponents_BASE
289 : {
290 : protected:
291 : ::osl::Mutex m_aMutex;
292 : ::comphelper::InterfaceRef m_xParent;
293 :
294 : public:
295 : OFormComponents(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
296 : OFormComponents( const OFormComponents& _cloneSource );
297 : virtual ~OFormComponents();
298 :
299 2541 : DECLARE_UNO3_AGG_DEFAULTS(OFormComponents, FormComponentsBase);
300 :
301 : virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
302 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException);
303 :
304 : // OComponentHelper
305 : virtual void SAL_CALL disposing();
306 :
307 : // ::com::sun::star::form::XFormComponent
308 : virtual ::comphelper::InterfaceRef SAL_CALL getParent() throw(::com::sun::star::uno::RuntimeException);
309 : virtual void SAL_CALL setParent(const ::comphelper::InterfaceRef& Parent) throw(::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
310 :
311 : // XEventListener
312 : using OInterfaceContainer::disposing;
313 : };
314 : //.........................................................................
315 : } // namespace frm
316 : //.........................................................................
317 :
318 : #endif // _FRM_INTERFACE_CONTAINER_HXX_
319 :
320 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|