1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: InterfaceContainer.hxx,v $
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 _FRM_INTERFACE_CONTAINER_HXX_
32 #define _FRM_INTERFACE_CONTAINER_HXX_
35 #include <comphelper/stl_types.hxx>
36 #include <comphelper/types.hxx>
37 #include <comphelper/uno3.hxx>
38 #include <com/sun/star/container/XNameReplace.hpp>
39 #include <com/sun/star/container/XIndexReplace.hpp>
40 #include <com/sun/star/container/XNameContainer.hpp>
41 #include <com/sun/star/lang/XEventListener.hpp>
42 #include <com/sun/star/lang/EventObject.hpp>
43 #include <com/sun/star/container/XEnumerationAccess.hpp>
44 #include <com/sun/star/io/XPersistObject.hpp>
45 #include <com/sun/star/form/XFormComponent.hpp>
46 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
47 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
48 #include <com/sun/star/beans/XPropertySet.hpp>
49 #include <com/sun/star/script/XEventAttacherManager.hpp>
50 #include <com/sun/star/script/ScriptEvent.hpp>
51 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
52 #include <com/sun/star/container/XContainer.hpp>
53 #include <com/sun/star/container/XIndexContainer.hpp>
54 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
55 #include <com/sun/star/form/XFormComponent.hpp>
56 #include <com/sun/star/util/XCloneable.hpp>
57 #include <osl/mutex.hxx>
58 #include <cppuhelper/interfacecontainer.hxx>
59 #include <cppuhelper/component.hxx>
60 #include <cppuhelper/implbase8.hxx>
62 using namespace comphelper
;
64 //.........................................................................
67 //.........................................................................
70 //==================================================================
71 struct ElementDescription
74 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xInterface
;
75 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xPropertySet
;
76 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XChild
> xChild
;
77 ::com::sun::star::uno::Any aElementTypeInterface
;
80 ElementDescription( );
81 virtual ~ElementDescription();
84 ElementDescription( const ElementDescription
& ); // never implemented
85 ElementDescription
& operator=( const ElementDescription
& ); // never implemented
88 typedef ::std::vector
<InterfaceRef
> OInterfaceArray
;
89 typedef ::std::hash_multimap
< ::rtl::OUString
, InterfaceRef
, ::comphelper::UStringHash
, ::comphelper::UStringEqual
> OInterfaceMap
;
91 //==================================================================
92 // OInterfaceContainer
93 // implements a container for form components
94 //==================================================================
95 typedef ::cppu::ImplHelper8
< ::com::sun::star::container::XNameContainer
96 , ::com::sun::star::container::XIndexContainer
97 , ::com::sun::star::container::XContainer
98 , ::com::sun::star::container::XEnumerationAccess
99 , ::com::sun::star::script::XEventAttacherManager
100 , ::com::sun::star::beans::XPropertyChangeListener
101 , ::com::sun::star::io::XPersistObject
102 , ::com::sun::star::util::XCloneable
103 > OInterfaceContainer_BASE
;
105 class OInterfaceContainer
: public OInterfaceContainer_BASE
108 ::osl::Mutex
& m_rMutex
;
110 OInterfaceArray m_aItems
;
111 OInterfaceMap m_aMap
;
112 ::cppu::OInterfaceContainerHelper m_aContainerListeners
;
114 const ::com::sun::star::uno::Type m_aElementType
;
116 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> m_xServiceFactory
;
120 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XEventAttacherManager
> m_xEventAttacher
;
124 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
,
125 ::osl::Mutex
& _rMutex
,
126 const ::com::sun::star::uno::Type
& _rElementType
);
128 OInterfaceContainer( ::osl::Mutex
& _rMutex
, const OInterfaceContainer
& _cloneSource
);
130 // late constructor for cloning
131 void clonedFrom( const OInterfaceContainer
& _cloneSource
);
134 virtual ~OInterfaceContainer();
137 // ::com::sun::star::io::XPersistObject
138 virtual ::rtl::OUString SAL_CALL
getServiceName( ) throw(::com::sun::star::uno::RuntimeException
) = 0;
139 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
);
140 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
);
142 // ::com::sun::star::lang::XEventListener
143 virtual void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& _rSource
) throw(::com::sun::star::uno::RuntimeException
);
145 // ::com::sun::star::beans::XPropertyChangeListener
146 virtual void SAL_CALL
propertyChange(const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw (::com::sun::star::uno::RuntimeException
);
148 // ::com::sun::star::container::XElementAccess
149 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType() throw(::com::sun::star::uno::RuntimeException
) ;
150 virtual sal_Bool SAL_CALL
hasElements() throw(::com::sun::star::uno::RuntimeException
);
152 // ::com::sun::star::container::XEnumerationAccess
153 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createEnumeration() throw(::com::sun::star::uno::RuntimeException
);
155 // ::com::sun::star::container::XNameAccess
156 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
);
157 virtual StringSequence SAL_CALL
getElementNames( ) throw(::com::sun::star::uno::RuntimeException
);
158 virtual sal_Bool SAL_CALL
hasByName( const ::rtl::OUString
& aName
) throw(::com::sun::star::uno::RuntimeException
);
160 // ::com::sun::star::container::XNameReplace
161 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
);
163 // ::com::sun::star::container::XNameContainer
164 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
);
165 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
);
167 // ::com::sun::star::container::XIndexAccess
168 virtual sal_Int32 SAL_CALL
getCount() throw(::com::sun::star::uno::RuntimeException
);
169 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
);
171 // ::com::sun::star::container::XIndexReplace
172 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
);
174 // ::com::sun::star::container::XIndexContainer
175 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
);
176 virtual void SAL_CALL
removeByIndex(sal_Int32 _nIndex
) throw(::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
178 // ::com::sun::star::container::XContainer
179 virtual void SAL_CALL
addContainerListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerListener
>& _rxListener
) throw(::com::sun::star::uno::RuntimeException
);
180 virtual void SAL_CALL
removeContainerListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerListener
>& _rxListener
) throw(::com::sun::star::uno::RuntimeException
);
182 // ::com::sun::star::script::XEventAttacherManager
183 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
);
184 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
);
185 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
);
186 virtual void SAL_CALL
revokeScriptEvents( sal_Int32 nIndex
) throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
187 virtual void SAL_CALL
insertEntry( sal_Int32 nIndex
) throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
188 virtual void SAL_CALL
removeEntry( sal_Int32 nIndex
) throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
189 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
);
190 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
);
191 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
);
192 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
);
193 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
);
197 virtual void SAL_CALL
disposing();
198 virtual void removeElementsNoEvents(sal_Int32 nIndex
);
200 /** to be overridden if elements which are to be inserted into the container shall be checked
202 <p>the ElementDescription given can be used to cache information about the object - it will be passed
203 later on to implInserted/implReplaced.</p>
205 virtual void approveNewElement(
206 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxObject
,
207 ElementDescription
* _pElement
210 virtual ElementDescription
* createElementMetaData( );
212 /** inserts an object into our internal structures
215 the index at which position it should be inserted
217 if <TRUE/>, event knittings will be done
218 @param _pApprovalResult
219 must contain the result of an approveNewElement call. Can be <NULL/>, in this case, the approval
220 is done within implInsert.
222 if <TRUE/>, a notification about the insertion will be fired
226 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxObject
,
227 sal_Bool _bEvents
/* = sal_True */,
228 ElementDescription
* _pApprovalResult
/* = NULL */ ,
229 sal_Bool _bFire
/* = sal_True */
230 ) throw(::com::sun::star::lang::IllegalArgumentException
);
232 // called after the object is inserted, but before the "real listeners" are notified
233 virtual void implInserted( const ElementDescription
* _pElement
);
234 // called after the object is removed, but before the "real listeners" are notified
235 virtual void implRemoved(const InterfaceRef
& _rxObject
);
237 /** called after an object was replaced. The default implementation notifies our listeners, after releasing
240 virtual void impl_replacedElement(
241 const ::com::sun::star::container::ContainerEvent
& _rEvent
,
242 ::osl::ClearableMutexGuard
& _rInstanceLock
245 void SAL_CALL
writeEvents(const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XObjectOutputStream
>& _rxOutStream
);
246 void SAL_CALL
readEvents(const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XObjectInputStream
>& _rxInStream
);
248 /** replace an element, specified by position
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>
254 void implReplaceByIndex(
255 const sal_Int32 _nIndex
,
256 const ::com::sun::star::uno::Any
& _rNewElement
,
257 ::osl::ClearableMutexGuard
& _rClearBeforeNotify
260 /** removes an element, specified by position
262 @precond <arg>_nIndex</arg> is a valid index
263 @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
266 void implRemoveByIndex(
267 const sal_Int32 _nIndex
,
268 ::osl::ClearableMutexGuard
& _rClearBeforeNotify
271 /** validates the given index
272 @throws ::com::sun::star::lang::IndexOutOfBoundsException
273 if the given index does not denote a valid position in our childs array
275 void implCheckIndex( const sal_Int32 _nIndex
) SAL_THROW( ( ::com::sun::star::lang::IndexOutOfBoundsException
) );
278 // hack for Vba Events
279 void fakeVbaEventsHack( sal_Int32 _nIndex
);
281 // the runtime event format has changed from version SO5.2 to OOo
287 void transformEvents( const EventFormat _eTargetFormat
);
289 void impl_createEventAttacher_nothrow();
292 //==================================================================
294 //==================================================================
295 typedef ::cppu::ImplHelper1
< ::com::sun::star::form::XFormComponent
> OFormComponents_BASE
;
296 typedef ::cppu::OComponentHelper FormComponentsBase
;
297 // else MSVC kills itself on some statements
298 class OFormComponents
:public FormComponentsBase
299 ,public OInterfaceContainer
300 ,public OFormComponents_BASE
303 ::osl::Mutex m_aMutex
;
304 ::comphelper::InterfaceRef m_xParent
;
307 OFormComponents(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
);
308 OFormComponents( const OFormComponents
& _cloneSource
);
309 virtual ~OFormComponents();
311 DECLARE_UNO3_AGG_DEFAULTS(OFormComponents
, FormComponentsBase
);
313 virtual ::com::sun::star::uno::Any SAL_CALL
queryAggregation(const ::com::sun::star::uno::Type
& _rType
) throw(::com::sun::star::uno::RuntimeException
);
314 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
);
317 virtual void SAL_CALL
disposing();
319 // ::com::sun::star::form::XFormComponent
320 virtual ::comphelper::InterfaceRef SAL_CALL
getParent() throw(::com::sun::star::uno::RuntimeException
);
321 virtual void SAL_CALL
setParent(const ::comphelper::InterfaceRef
& Parent
) throw(::com::sun::star::lang::NoSupportException
, ::com::sun::star::uno::RuntimeException
);
324 using OInterfaceContainer::disposing
;
326 //.........................................................................
328 //.........................................................................
330 #endif // _FRM_INTERFACE_CONTAINER_HXX_