1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/XNameReplace.hpp>
25 #include <com/sun/star/container/XIndexReplace.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/lang/XEventListener.hpp>
28 #include <com/sun/star/lang/EventObject.hpp>
29 #include <com/sun/star/container/XEnumerationAccess.hpp>
30 #include <com/sun/star/io/XPersistObject.hpp>
31 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
32 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/script/XEventAttacherManager.hpp>
35 #include <com/sun/star/script/ScriptEvent.hpp>
36 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
37 #include <com/sun/star/container/XContainer.hpp>
38 #include <com/sun/star/container/XIndexContainer.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/form/XFormComponent.hpp>
41 #include <com/sun/star/util/XCloneable.hpp>
42 #include <osl/mutex.hxx>
43 #include <comphelper/interfacecontainer2.hxx>
44 #include <cppuhelper/component.hxx>
45 #include <cppuhelper/implbase1.hxx>
46 #include <cppuhelper/implbase8.hxx>
47 #include <unordered_map>
49 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{
50 class XComponentContext
;
53 using namespace comphelper
;
60 struct ElementDescription
63 css::uno::Reference
< css::uno::XInterface
> xInterface
;
64 css::uno::Reference
< css::beans::XPropertySet
> xPropertySet
;
65 css::uno::Reference
< css::container::XChild
> xChild
;
66 css::uno::Any aElementTypeInterface
;
69 ElementDescription( );
72 ElementDescription( const ElementDescription
& ) = delete;
73 ElementDescription
& operator=( const ElementDescription
& ) = delete;
76 typedef std::vector
<css::uno::Reference
<css::uno::XInterface
>> OInterfaceArray
;
77 typedef std::unordered_multimap
< OUString
, css::uno::Reference
<css::uno::XInterface
> > OInterfaceMap
;
80 // OInterfaceContainer
81 // implements a container for form components
83 typedef ::cppu::ImplHelper8
< css::container::XNameContainer
84 , css::container::XIndexContainer
85 , css::container::XContainer
86 , css::container::XEnumerationAccess
87 , css::script::XEventAttacherManager
88 , css::beans::XPropertyChangeListener
89 , css::io::XPersistObject
90 , css::util::XCloneable
91 > OInterfaceContainer_BASE
;
93 class OInterfaceContainer
: public OInterfaceContainer_BASE
96 ::osl::Mutex
& m_rMutex
;
98 OInterfaceArray m_aItems
;
100 ::comphelper::OInterfaceContainerHelper2 m_aContainerListeners
;
102 const css::uno::Type m_aElementType
;
104 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
108 css::uno::Reference
< css::script::XEventAttacherManager
> m_xEventAttacher
;
112 const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
,
113 ::osl::Mutex
& _rMutex
,
114 const css::uno::Type
& _rElementType
);
116 OInterfaceContainer( ::osl::Mutex
& _rMutex
, const OInterfaceContainer
& _cloneSource
);
118 // late constructor for cloning
119 /// @throws css::uno::RuntimeException
120 void clonedFrom(const OInterfaceContainer
& _cloneSource
);
123 virtual ~OInterfaceContainer();
126 // css::io::XPersistObject
127 virtual OUString SAL_CALL
getServiceName( ) override
= 0;
128 virtual void SAL_CALL
write( const css::uno::Reference
< css::io::XObjectOutputStream
>& OutStream
) override
;
129 virtual void SAL_CALL
read( const css::uno::Reference
< css::io::XObjectInputStream
>& InStream
) override
;
131 // css::lang::XEventListener
132 virtual void SAL_CALL
disposing(const css::lang::EventObject
& _rSource
) override
;
134 // css::beans::XPropertyChangeListener
135 virtual void SAL_CALL
propertyChange(const css::beans::PropertyChangeEvent
& evt
) override
;
137 // css::container::XElementAccess
138 virtual css::uno::Type SAL_CALL
getElementType() override
;
139 virtual sal_Bool SAL_CALL
hasElements() override
;
141 // css::container::XEnumerationAccess
142 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration() override
;
144 // css::container::XNameAccess
145 virtual css::uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
146 virtual css::uno::Sequence
<OUString
> SAL_CALL
getElementNames( ) override
;
147 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
149 // css::container::XNameReplace
150 virtual void SAL_CALL
replaceByName(const OUString
& Name
, const css::uno::Any
& _rElement
) override
;
152 // css::container::XNameContainer
153 virtual void SAL_CALL
insertByName(const OUString
& Name
, const css::uno::Any
& _rElement
) override
;
154 virtual void SAL_CALL
removeByName(const OUString
& Name
) override
;
156 // css::container::XIndexAccess
157 virtual sal_Int32 SAL_CALL
getCount() override
;
158 virtual css::uno::Any SAL_CALL
getByIndex(sal_Int32 _nIndex
) override
;
160 // css::container::XIndexReplace
161 virtual void SAL_CALL
replaceByIndex(sal_Int32 _nIndex
, const css::uno::Any
& _rElement
) override
;
163 // css::container::XIndexContainer
164 virtual void SAL_CALL
insertByIndex(sal_Int32 _nIndex
, const css::uno::Any
& Element
) override
;
165 virtual void SAL_CALL
removeByIndex(sal_Int32 _nIndex
) override
;
167 // css::container::XContainer
168 virtual void SAL_CALL
addContainerListener(const css::uno::Reference
< css::container::XContainerListener
>& _rxListener
) override
;
169 virtual void SAL_CALL
removeContainerListener(const css::uno::Reference
< css::container::XContainerListener
>& _rxListener
) override
;
171 // css::script::XEventAttacherManager
172 virtual void SAL_CALL
registerScriptEvent( sal_Int32 nIndex
, const css::script::ScriptEventDescriptor
& aScriptEvent
) override
;
173 virtual void SAL_CALL
registerScriptEvents( sal_Int32 nIndex
, const css::uno::Sequence
< css::script::ScriptEventDescriptor
>& aScriptEvents
) override
;
174 virtual void SAL_CALL
revokeScriptEvent( sal_Int32 nIndex
, const OUString
& aListenerType
, const OUString
& aEventMethod
, const OUString
& aRemoveListenerParam
) override
;
175 virtual void SAL_CALL
revokeScriptEvents( sal_Int32 nIndex
) override
;
176 virtual void SAL_CALL
insertEntry( sal_Int32 nIndex
) override
;
177 virtual void SAL_CALL
removeEntry( sal_Int32 nIndex
) override
;
178 virtual css::uno::Sequence
< css::script::ScriptEventDescriptor
> SAL_CALL
getScriptEvents( sal_Int32 Index
) override
;
179 virtual void SAL_CALL
attach( sal_Int32 nIndex
, const css::uno::Reference
< css::uno::XInterface
>& xObject
, const css::uno::Any
& aHelper
) override
;
180 virtual void SAL_CALL
detach( sal_Int32 nIndex
, const css::uno::Reference
< css::uno::XInterface
>& xObject
) override
;
181 virtual void SAL_CALL
addScriptListener( const css::uno::Reference
< css::script::XScriptListener
>& xListener
) override
;
182 virtual void SAL_CALL
removeScriptListener( const css::uno::Reference
< css::script::XScriptListener
>& Listener
) override
;
186 virtual void SAL_CALL
disposing();
187 void removeElementsNoEvents();
189 /** to be overridden if elements which are to be inserted into the container shall be checked
191 <p>the ElementDescription given can be used to cache information about the object - it will be passed
192 later on to implInserted/implReplaced.</p>
194 virtual void approveNewElement(
195 const css::uno::Reference
< css::beans::XPropertySet
>& _rxObject
,
196 ElementDescription
* _pElement
199 virtual ElementDescription
* createElementMetaData( );
201 /** inserts an object into our internal structures
204 the index at which position it should be inserted
206 if <TRUE/>, event knittings will be done
207 @param _pApprovalResult
208 must contain the result of an approveNewElement call. Can be <NULL/>, in this case, the approval
209 is done within implInsert.
211 if <TRUE/>, a notification about the insertion will be fired
212 @throws css::lang::IllegalArgumentException
216 const css::uno::Reference
< css::beans::XPropertySet
>& _rxObject
,
217 bool _bEvents
/* = sal_True */,
218 ElementDescription
* _pApprovalResult
/* = NULL */ ,
219 bool _bFire
/* = sal_True */
222 // called after the object is inserted, but before the "real listeners" are notified
223 virtual void implInserted( const ElementDescription
* _pElement
);
224 // called after the object is removed, but before the "real listeners" are notified
225 virtual void implRemoved(const css::uno::Reference
<css::uno::XInterface
>& _rxObject
);
227 /** called after an object was replaced. The default implementation notifies our listeners, after releasing
230 virtual void impl_replacedElement(
231 const css::container::ContainerEvent
& _rEvent
,
232 ::osl::ClearableMutexGuard
& _rInstanceLock
235 void SAL_CALL
writeEvents(const css::uno::Reference
< css::io::XObjectOutputStream
>& _rxOutStream
);
236 void SAL_CALL
readEvents(const css::uno::Reference
< css::io::XObjectInputStream
>& _rxInStream
);
238 /** replace an element, specified by position
240 @precond <arg>_nIndex</arg> is a valid index
241 @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
244 void implReplaceByIndex(
245 const sal_Int32 _nIndex
,
246 const css::uno::Any
& _rNewElement
,
247 ::osl::ClearableMutexGuard
& _rClearBeforeNotify
250 /** removes an element, specified by position
252 @precond <arg>_nIndex</arg> is a valid index
253 @precond our mutex is locked exactly once, by the guard specified with <arg>_rClearBeforeNotify</arg>
256 void implRemoveByIndex(
257 const sal_Int32 _nIndex
,
258 ::osl::ClearableMutexGuard
& _rClearBeforeNotify
261 /** validates the given index
262 @throws css::lang::IndexOutOfBoundsException
263 if the given index does not denote a valid position in our children array
265 void implCheckIndex( const sal_Int32 _nIndex
);
268 // hack for Vba Events
269 void impl_addVbEvents_nolck_nothrow( const sal_Int32 i_nIndex
);
271 void transformEvents();
273 void impl_createEventAttacher_nothrow();
276 typedef ::cppu::ImplHelper1
< css::form::XFormComponent
> OFormComponents_BASE
;
277 class OFormComponents
:public ::cppu::OComponentHelper
278 ,public OInterfaceContainer
279 ,public OFormComponents_BASE
282 ::osl::Mutex m_aMutex
;
283 css::uno::Reference
<css::uno::XInterface
> m_xParent
;
286 OFormComponents(const css::uno::Reference
< css::uno::XComponentContext
>& _rxFactory
);
287 OFormComponents( const OFormComponents
& _cloneSource
);
288 virtual ~OFormComponents() override
;
290 DECLARE_UNO3_AGG_DEFAULTS(OFormComponents
, ::cppu::OComponentHelper
)
292 virtual css::uno::Any SAL_CALL
queryAggregation(const css::uno::Type
& _rType
) override
;
293 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
296 virtual void SAL_CALL
disposing() override
;
298 // css::form::XFormComponent
299 virtual css::uno::Reference
<css::uno::XInterface
> SAL_CALL
getParent() override
;
300 virtual void SAL_CALL
setParent(const css::uno::Reference
<css::uno::XInterface
>& Parent
) override
;
303 using OInterfaceContainer::disposing
;
309 #endif // INCLUDED_FORMS_SOURCE_INC_INTERFACECONTAINER_HXX
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */