nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / inc / InterfaceContainer.hxx
blob690b93d49da6915b88ed0814014dbf5746e85628
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 INCLUDED_FORMS_SOURCE_INC_INTERFACECONTAINER_HXX
21 #define INCLUDED_FORMS_SOURCE_INC_INTERFACECONTAINER_HXX
23 #include <comphelper/uno3.hxx>
24 #include <com/sun/star/container/XNameContainer.hpp>
25 #include <com/sun/star/lang/EventObject.hpp>
26 #include <com/sun/star/container/XEnumerationAccess.hpp>
27 #include <com/sun/star/io/XPersistObject.hpp>
28 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
29 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/script/XEventAttacherManager.hpp>
32 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
33 #include <com/sun/star/container/XContainer.hpp>
34 #include <com/sun/star/container/XIndexContainer.hpp>
35 #include <com/sun/star/form/XFormComponent.hpp>
36 #include <com/sun/star/util/XCloneable.hpp>
37 #include <osl/mutex.hxx>
38 #include <comphelper/interfacecontainer2.hxx>
39 #include <cppuhelper/component.hxx>
40 #include <cppuhelper/implbase1.hxx>
41 #include <cppuhelper/implbase8.hxx>
42 #include <unordered_map>
44 namespace com::sun::star::uno { class XComponentContext; }
46 using namespace comphelper;
49 namespace frm
53 struct ElementDescription
55 public:
56 css::uno::Reference< css::uno::XInterface > xInterface;
57 css::uno::Reference< css::beans::XPropertySet > xPropertySet;
58 css::uno::Reference< css::container::XChild > xChild;
59 css::uno::Any aElementTypeInterface;
61 public:
62 ElementDescription( );
64 private:
65 ElementDescription( const ElementDescription& ) = delete;
66 ElementDescription& operator=( const ElementDescription& ) = delete;
69 typedef std::vector<css::uno::Reference<css::uno::XInterface>> OInterfaceArray;
70 typedef std::unordered_multimap< OUString, css::uno::Reference<css::uno::XInterface> > OInterfaceMap;
73 // OInterfaceContainer
74 // implements a container for form components
76 typedef ::cppu::ImplHelper8 < css::container::XNameContainer
77 , css::container::XIndexContainer
78 , css::container::XContainer
79 , css::container::XEnumerationAccess
80 , css::script::XEventAttacherManager
81 , css::beans::XPropertyChangeListener
82 , css::io::XPersistObject
83 , css::util::XCloneable
84 > OInterfaceContainer_BASE;
86 class OInterfaceContainer : public OInterfaceContainer_BASE
88 protected:
89 ::osl::Mutex& m_rMutex;
91 OInterfaceArray m_aItems;
92 OInterfaceMap m_aMap;
93 ::comphelper::OInterfaceContainerHelper2 m_aContainerListeners;
95 const css::uno::Type m_aElementType;
97 css::uno::Reference< css::uno::XComponentContext> m_xContext;
100 // EventManager
101 css::uno::Reference< css::script::XEventAttacherManager> m_xEventAttacher;
103 public:
104 OInterfaceContainer(
105 const css::uno::Reference< css::uno::XComponentContext>& _rxFactory,
106 ::osl::Mutex& _rMutex,
107 const css::uno::Type& _rElementType);
109 OInterfaceContainer( ::osl::Mutex& _rMutex, const OInterfaceContainer& _cloneSource );
111 // late constructor for cloning
112 /// @throws css::uno::RuntimeException
113 void clonedFrom(const OInterfaceContainer& _cloneSource);
115 protected:
116 virtual ~OInterfaceContainer();
118 public:
119 // css::io::XPersistObject
120 virtual OUString SAL_CALL getServiceName( ) override = 0;
121 virtual void SAL_CALL write( const css::uno::Reference< css::io::XObjectOutputStream >& OutStream ) override;
122 virtual void SAL_CALL read( const css::uno::Reference< css::io::XObjectInputStream >& InStream ) override;
124 // css::lang::XEventListener
125 virtual void SAL_CALL disposing(const css::lang::EventObject& _rSource) override;
127 // css::beans::XPropertyChangeListener
128 virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override;
130 // css::container::XElementAccess
131 virtual css::uno::Type SAL_CALL getElementType() override ;
132 virtual sal_Bool SAL_CALL hasElements() override;
134 // css::container::XEnumerationAccess
135 virtual css::uno::Reference< css::container::XEnumeration> SAL_CALL createEnumeration() override;
137 // css::container::XNameAccess
138 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
139 virtual css::uno::Sequence<OUString> SAL_CALL getElementNames( ) override;
140 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
142 // css::container::XNameReplace
143 virtual void SAL_CALL replaceByName(const OUString& Name, const css::uno::Any& _rElement) override;
145 // css::container::XNameContainer
146 virtual void SAL_CALL insertByName(const OUString& Name, const css::uno::Any& _rElement) override;
147 virtual void SAL_CALL removeByName(const OUString& Name) override;
149 // css::container::XIndexAccess
150 virtual sal_Int32 SAL_CALL getCount() override;
151 virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 _nIndex) override;
153 // css::container::XIndexReplace
154 virtual void SAL_CALL replaceByIndex(sal_Int32 _nIndex, const css::uno::Any& _rElement) override;
156 // css::container::XIndexContainer
157 virtual void SAL_CALL insertByIndex(sal_Int32 _nIndex, const css::uno::Any& Element) override;
158 virtual void SAL_CALL removeByIndex(sal_Int32 _nIndex) override;
160 // css::container::XContainer
161 virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener>& _rxListener) override;
162 virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener>& _rxListener) override;
164 // css::script::XEventAttacherManager
165 virtual void SAL_CALL registerScriptEvent( sal_Int32 nIndex, const css::script::ScriptEventDescriptor& aScriptEvent ) override;
166 virtual void SAL_CALL registerScriptEvents( sal_Int32 nIndex, const css::uno::Sequence< css::script::ScriptEventDescriptor >& aScriptEvents ) override;
167 virtual void SAL_CALL revokeScriptEvent( sal_Int32 nIndex, const OUString& aListenerType, const OUString& aEventMethod, const OUString& aRemoveListenerParam ) override;
168 virtual void SAL_CALL revokeScriptEvents( sal_Int32 nIndex ) override;
169 virtual void SAL_CALL insertEntry( sal_Int32 nIndex ) override;
170 virtual void SAL_CALL removeEntry( sal_Int32 nIndex ) override;
171 virtual css::uno::Sequence< css::script::ScriptEventDescriptor > SAL_CALL getScriptEvents( sal_Int32 Index ) override;
172 virtual void SAL_CALL attach( sal_Int32 nIndex, const css::uno::Reference< css::uno::XInterface >& xObject, const css::uno::Any& aHelper ) override;
173 virtual void SAL_CALL detach( sal_Int32 nIndex, const css::uno::Reference< css::uno::XInterface >& xObject ) override;
174 virtual void SAL_CALL addScriptListener( const css::uno::Reference< css::script::XScriptListener >& xListener ) override;
175 virtual void SAL_CALL removeScriptListener( const css::uno::Reference< css::script::XScriptListener >& Listener ) override;
177 protected:
178 // helper
179 virtual void SAL_CALL disposing();
180 void removeElementsNoEvents();
182 /** to be overridden if elements which are to be inserted into the container shall be checked
184 <p>the ElementDescription given can be used to cache information about the object - it will be passed
185 later on to implInserted/implReplaced.</p>
187 virtual void approveNewElement(
188 const css::uno::Reference< css::beans::XPropertySet >& _rxObject,
189 ElementDescription* _pElement
192 virtual ElementDescription* createElementMetaData( );
194 /** inserts an object into our internal structures
196 @param _nIndex
197 the index at which position it should be inserted
198 @param _bEvents
199 if <TRUE/>, event knittings will be done
200 @param _pApprovalResult
201 must contain the result of an approveNewElement call. Can be <NULL/>, in this case, the approval
202 is done within implInsert.
203 @param _bFire
204 if <TRUE/>, a notification about the insertion will be fired
205 @throws css::lang::IllegalArgumentException
207 void implInsert(
208 sal_Int32 _nIndex,
209 const css::uno::Reference< css::beans::XPropertySet >& _rxObject,
210 bool _bEvents /* = sal_True */,
211 ElementDescription* _pApprovalResult /* = NULL */ ,
212 bool _bFire /* = sal_True */
215 // called after the object is inserted, but before the "real listeners" are notified
216 virtual void implInserted( const ElementDescription* _pElement );
217 // called after the object is removed, but before the "real listeners" are notified
218 virtual void implRemoved(const css::uno::Reference<css::uno::XInterface>& _rxObject);
220 /** called after an object was replaced. The default implementation notifies our listeners, after releasing
221 the instance lock.
223 virtual void impl_replacedElement(
224 const css::container::ContainerEvent& _rEvent,
225 ::osl::ClearableMutexGuard& _rInstanceLock
228 void SAL_CALL writeEvents(const css::uno::Reference< css::io::XObjectOutputStream>& _rxOutStream);
229 void SAL_CALL readEvents(const css::uno::Reference< css::io::XObjectInputStream>& _rxInStream);
231 /** replace an element, specified by position
233 @precond <arg>_nIndex</arg> is a valid index
234 @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
237 void implReplaceByIndex(
238 const sal_Int32 _nIndex,
239 const css::uno::Any& _rNewElement,
240 ::osl::ClearableMutexGuard& _rClearBeforeNotify
243 /** removes an element, specified by position
245 @precond <arg>_nIndex</arg> is a valid index
246 @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
249 void implRemoveByIndex(
250 const sal_Int32 _nIndex,
251 ::osl::ClearableMutexGuard& _rClearBeforeNotify
254 /** validates the given index
255 @throws css::lang::IndexOutOfBoundsException
256 if the given index does not denote a valid position in our children array
258 void implCheckIndex( const sal_Int32 _nIndex );
260 private:
261 // hack for Vba Events
262 void impl_addVbEvents_nolck_nothrow( const sal_Int32 i_nIndex );
264 void transformEvents();
266 void impl_createEventAttacher_nothrow();
269 typedef ::cppu::ImplHelper1< css::form::XFormComponent> OFormComponents_BASE;
270 class OFormComponents :public ::cppu::OComponentHelper
271 ,public OInterfaceContainer
272 ,public OFormComponents_BASE
274 protected:
275 ::osl::Mutex m_aMutex;
276 css::uno::Reference<css::uno::XInterface> m_xParent;
278 public:
279 OFormComponents(const css::uno::Reference< css::uno::XComponentContext>& _rxFactory);
280 OFormComponents( const OFormComponents& _cloneSource );
281 virtual ~OFormComponents() override;
283 DECLARE_UNO3_AGG_DEFAULTS(OFormComponents, ::cppu::OComponentHelper)
285 virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
286 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
288 // OComponentHelper
289 virtual void SAL_CALL disposing() override;
291 // css::form::XFormComponent
292 virtual css::uno::Reference<css::uno::XInterface> SAL_CALL getParent() override;
293 virtual void SAL_CALL setParent(const css::uno::Reference<css::uno::XInterface>& Parent) override;
295 // XEventListener
296 using OInterfaceContainer::disposing;
299 } // namespace frm
302 #endif // INCLUDED_FORMS_SOURCE_INC_INTERFACECONTAINER_HXX
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */