bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / inc / InterfaceContainer.hxx
blobea5963512ce44b8d58da792264b2e3e341fadf4c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _FRM_INTERFACE_CONTAINER_HXX_
21 #define _FRM_INTERFACE_CONTAINER_HXX_
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>
50 using namespace comphelper;
52 //.........................................................................
53 namespace frm
55 //.........................................................................
58 //==================================================================
59 struct ElementDescription
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;
67 public:
68 ElementDescription( );
69 virtual ~ElementDescription();
71 private:
72 ElementDescription( const ElementDescription& ); // never implemented
73 ElementDescription& operator=( const ElementDescription& ); // never implemented
76 typedef ::std::vector<InterfaceRef> OInterfaceArray;
77 typedef ::boost::unordered_multimap< OUString, InterfaceRef, OUStringHash, ::comphelper::UStringEqual> OInterfaceMap;
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;
93 class OInterfaceContainer : public OInterfaceContainer_BASE
95 protected:
96 ::osl::Mutex& m_rMutex;
98 OInterfaceArray m_aItems;
99 OInterfaceMap m_aMap;
100 ::cppu::OInterfaceContainerHelper m_aContainerListeners;
102 const ::com::sun::star::uno::Type m_aElementType;
104 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory> m_xServiceFactory;
107 // EventManager
108 ::com::sun::star::uno::Reference< ::com::sun::star::script::XEventAttacherManager> m_xEventAttacher;
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);
116 OInterfaceContainer( ::osl::Mutex& _rMutex, const OInterfaceContainer& _cloneSource );
118 // late constructor for cloning
119 void clonedFrom( const OInterfaceContainer& _cloneSource );
121 protected:
122 virtual ~OInterfaceContainer();
124 public:
125 // ::com::sun::star::io::XPersistObject
126 virtual 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);
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);
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);
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);
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);
143 // ::com::sun::star::container::XNameAccess
144 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const 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 OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
148 // ::com::sun::star::container::XNameReplace
149 virtual void SAL_CALL replaceByName(const 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);
151 // ::com::sun::star::container::XNameContainer
152 virtual void SAL_CALL insertByName(const 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 OUString& Name) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
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);
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);
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);
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);
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 OUString& aListenerType, const OUString& aEventMethod, const 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);
183 protected:
184 // helper
185 virtual void SAL_CALL disposing();
186 virtual void removeElementsNoEvents(sal_Int32 nIndex);
188 /** to be overridden if elements which are to be inserted into the container shall be checked
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>
193 virtual void approveNewElement(
194 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject,
195 ElementDescription* _pElement
198 virtual ElementDescription* createElementMetaData( );
200 /** inserts an object into our internal structures
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
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);
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);
225 /** called after an object was replaced. The default implementation notifies our listeners, after releasing
226 the instance lock.
228 virtual void impl_replacedElement(
229 const ::com::sun::star::container::ContainerEvent& _rEvent,
230 ::osl::ClearableMutexGuard& _rInstanceLock
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);
236 /** replace an element, specified by position
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>
242 void implReplaceByIndex(
243 const sal_Int32 _nIndex,
244 const ::com::sun::star::uno::Any& _rNewElement,
245 ::osl::ClearableMutexGuard& _rClearBeforeNotify
248 /** removes 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 implRemoveByIndex(
255 const sal_Int32 _nIndex,
256 ::osl::ClearableMutexGuard& _rClearBeforeNotify
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
263 void implCheckIndex( const sal_Int32 _nIndex ) SAL_THROW( ( ::com::sun::star::lang::IndexOutOfBoundsException ) );
265 private:
266 // hack for Vba Events
267 void impl_addVbEvents_nolck_nothrow( const sal_Int32 i_nIndex );
269 // the runtime event format has changed from version SO5.2 to OOo
270 enum EventFormat
272 efVersionSO5x,
273 efVersionSO6x
275 void transformEvents( const EventFormat _eTargetFormat );
277 void impl_createEventAttacher_nothrow();
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
290 protected:
291 ::osl::Mutex m_aMutex;
292 ::comphelper::InterfaceRef m_xParent;
294 public:
295 OFormComponents(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
296 OFormComponents( const OFormComponents& _cloneSource );
297 virtual ~OFormComponents();
299 DECLARE_UNO3_AGG_DEFAULTS(OFormComponents, FormComponentsBase);
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);
304 // OComponentHelper
305 virtual void SAL_CALL disposing();
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);
311 // XEventListener
312 using OInterfaceContainer::disposing;
314 //.........................................................................
315 } // namespace frm
316 //.........................................................................
318 #endif // _FRM_INTERFACE_CONTAINER_HXX_
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */