fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / inc / ModifyListenerHelper.hxx
blob648354044d41d29263b19fbe1588e1c6c82fd2e3
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 .
19 #ifndef INCLUDED_CHART2_SOURCE_INC_MODIFYLISTENERHELPER_HXX
20 #define INCLUDED_CHART2_SOURCE_INC_MODIFYLISTENERHELPER_HXX
22 #include <cppuhelper/interfacecontainer.hxx>
23 #include <com/sun/star/util/XModifyListener.hpp>
24 #include <com/sun/star/util/XModifyBroadcaster.hpp>
25 #include <com/sun/star/util/XModifiable.hpp>
26 #include <com/sun/star/uno/XWeak.hpp>
27 #include <cppuhelper/implbase1.hxx>
28 #include <cppuhelper/compbase2.hxx>
29 #include <cppuhelper/weakref.hxx>
31 #include "MutexContainer.hxx"
32 #include "charttoolsdllapi.hxx"
34 #include <list>
35 #include <algorithm>
36 #include <functional>
37 #include <utility>
39 namespace chart
41 namespace ModifyListenerHelper
44 OOO_DLLPUBLIC_CHARTTOOLS ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > createModifyEventForwarder();
46 /** This helper class serves as forwarder of modify events. It can be used
47 whenever an object has to send modify events after it gets a modify event of
48 one of its children.
50 <p>The listeners are held as WeakReferences if they support XWeak. Thus the
51 life time of the listeners is independent of the broadcaster's lifetime in
52 this case.</p>
54 class ModifyEventForwarder :
55 public MutexContainer,
56 public ::cppu::WeakComponentImplHelper2<
57 ::com::sun::star::util::XModifyBroadcaster,
58 ::com::sun::star::util::XModifyListener >
60 public:
61 ModifyEventForwarder();
63 void FireEvent( const ::com::sun::star::lang::EventObject & rEvent );
65 void AddListener(
66 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener );
67 void RemoveListener(
68 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener );
70 protected:
71 // ____ XModifyBroadcaster ____
72 virtual void SAL_CALL addModifyListener(
73 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener )
74 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
75 virtual void SAL_CALL removeModifyListener(
76 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener )
77 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
79 // ____ XModifyListener ____
80 virtual void SAL_CALL modified(
81 const ::com::sun::star::lang::EventObject& aEvent )
82 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
84 // ____ XEventListener (base of XModifyListener) ____
85 virtual void SAL_CALL disposing(
86 const ::com::sun::star::lang::EventObject& Source )
87 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
89 // ____ WeakComponentImplHelperBase ____
90 virtual void SAL_CALL disposing() SAL_OVERRIDE;
92 private:
93 /// call disposing() at all listeners and remove all listeners
94 void DisposeAndClear( const ::com::sun::star::uno::Reference<
95 ::com::sun::star::uno::XWeak > & xSource );
97 // ::osl::Mutex & m_rMutex;
98 ::cppu::OBroadcastHelper m_aModifyListeners;
100 typedef ::std::list<
101 ::std::pair<
102 ::com::sun::star::uno::WeakReference< ::com::sun::star::util::XModifyListener >,
103 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > > >
104 tListenerMap;
106 tListenerMap m_aListenerMap;
109 namespace impl
112 template< class InterfaceRef >
113 struct addListenerFunctor : public ::std::unary_function< InterfaceRef, void >
115 explicit addListenerFunctor( const ::com::sun::star::uno::Reference<
116 ::com::sun::star::util::XModifyListener > & xListener ) :
117 m_xListener( xListener )
120 void operator() ( const InterfaceRef & xObject )
122 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >
123 xBroadcaster( xObject, ::com::sun::star::uno::UNO_QUERY );
124 if( xBroadcaster.is() && m_xListener.is())
125 xBroadcaster->addModifyListener( m_xListener );
127 private:
128 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xListener;
131 template< class InterfaceRef >
132 struct removeListenerFunctor : public ::std::unary_function< InterfaceRef, void >
134 explicit removeListenerFunctor( const ::com::sun::star::uno::Reference<
135 ::com::sun::star::util::XModifyListener > & xListener ) :
136 m_xListener( xListener )
139 void operator() ( const InterfaceRef & xObject )
141 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >
142 xBroadcaster( xObject, ::com::sun::star::uno::UNO_QUERY );
143 if( xBroadcaster.is() && m_xListener.is())
144 xBroadcaster->removeModifyListener( m_xListener );
146 private:
147 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xListener;
150 template< class Pair >
151 struct addListenerToMappedElementFunctor : public ::std::unary_function< Pair, void >
153 explicit addListenerToMappedElementFunctor( const ::com::sun::star::uno::Reference<
154 ::com::sun::star::util::XModifyListener > & xListener ) :
155 m_xListener( xListener )
158 void operator() ( const Pair & aPair )
160 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >
161 xBroadcaster( aPair.second, ::com::sun::star::uno::UNO_QUERY );
162 if( xBroadcaster.is() && m_xListener.is())
163 xBroadcaster->addModifyListener( m_xListener );
165 private:
166 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xListener;
169 template< class Pair >
170 struct removeListenerFromMappedElementFunctor : public ::std::unary_function< Pair, void >
172 explicit removeListenerFromMappedElementFunctor( const ::com::sun::star::uno::Reference<
173 ::com::sun::star::util::XModifyListener > & xListener ) :
174 m_xListener( xListener )
177 void operator() ( const Pair & aPair )
179 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyBroadcaster >
180 xBroadcaster( aPair.second, ::com::sun::star::uno::UNO_QUERY );
181 if( xBroadcaster.is() && m_xListener.is())
182 xBroadcaster->removeModifyListener( m_xListener );
184 private:
185 ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xListener;
188 } // namespace impl
190 template< class InterfaceRef >
191 void addListener(
192 const InterfaceRef & xObject,
193 const ::com::sun::star::uno::Reference<
194 ::com::sun::star::util::XModifyListener > & xListener )
196 if( xListener.is())
198 impl::addListenerFunctor< InterfaceRef > aFunctor( xListener );
199 aFunctor( xObject );
203 template< class Container >
204 void addListenerToAllElements(
205 const Container & rContainer,
206 const ::com::sun::star::uno::Reference<
207 ::com::sun::star::util::XModifyListener > & xListener )
209 if( xListener.is())
210 ::std::for_each( rContainer.begin(), rContainer.end(),
211 impl::addListenerFunctor< typename Container::value_type >( xListener ));
214 template< class Container >
215 void addListenerToAllMapElements(
216 const Container & rContainer,
217 const ::com::sun::star::uno::Reference<
218 ::com::sun::star::util::XModifyListener > & xListener )
220 if( xListener.is())
221 ::std::for_each( rContainer.begin(), rContainer.end(),
222 impl::addListenerToMappedElementFunctor< typename Container::value_type >( xListener ));
225 template< typename T >
226 void addListenerToAllSequenceElements(
227 const ::com::sun::star::uno::Sequence< T > & rSequence,
228 const ::com::sun::star::uno::Reference<
229 ::com::sun::star::util::XModifyListener > & xListener )
231 if( xListener.is())
232 ::std::for_each( rSequence.getConstArray(), rSequence.getConstArray() + rSequence.getLength(),
233 impl::addListenerFunctor< T >( xListener ));
236 template< class InterfaceRef >
237 void removeListener(
238 const InterfaceRef & xObject,
239 const ::com::sun::star::uno::Reference<
240 ::com::sun::star::util::XModifyListener > & xListener )
242 if( xListener.is())
244 impl::removeListenerFunctor< InterfaceRef > aFunctor( xListener );
245 aFunctor( xObject );
249 template< class Container >
250 void removeListenerFromAllElements(
251 const Container & rContainer,
252 const ::com::sun::star::uno::Reference<
253 ::com::sun::star::util::XModifyListener > & xListener )
255 if( xListener.is())
256 ::std::for_each( rContainer.begin(), rContainer.end(),
257 impl::removeListenerFunctor< typename Container::value_type >( xListener ));
260 template< class Container >
261 void removeListenerFromAllMapElements(
262 const Container & rContainer,
263 const ::com::sun::star::uno::Reference<
264 ::com::sun::star::util::XModifyListener > & xListener )
266 if( xListener.is())
267 ::std::for_each( rContainer.begin(), rContainer.end(),
268 impl::removeListenerFromMappedElementFunctor< typename Container::value_type >( xListener ));
271 template< typename T >
272 void removeListenerFromAllSequenceElements(
273 const ::com::sun::star::uno::Sequence< T > & rSequence,
274 const ::com::sun::star::uno::Reference<
275 ::com::sun::star::util::XModifyListener > & xListener )
277 if( xListener.is())
278 ::std::for_each( rSequence.getConstArray(), rSequence.getConstArray() + rSequence.getLength(),
279 impl::removeListenerFunctor< T >( xListener ));
282 } // namespace ModifyListenerHelper
283 } // namespace chart
285 // INCLUDED_CHART2_SOURCE_INC_MODIFYLISTENERHELPER_HXX
286 #endif
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */