fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / inc / EventListenerHelper.hxx
blob8872eb87f402d094b22b516480f0345443ea7ba6
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_EVENTLISTENERHELPER_HXX
20 #define INCLUDED_CHART2_SOURCE_INC_EVENTLISTENERHELPER_HXX
22 #include <com/sun/star/lang/XEventListener.hpp>
23 #include <com/sun/star/lang/XComponent.hpp>
25 #include <list>
26 #include <algorithm>
27 #include <functional>
28 #include <utility>
30 namespace chart
32 namespace EventListenerHelper
35 namespace impl
38 template< class InterfaceRef >
39 struct addListenerFunctor : public ::std::unary_function< InterfaceRef, void >
41 explicit addListenerFunctor( const ::com::sun::star::uno::Reference<
42 ::com::sun::star::lang::XEventListener > & xListener ) :
43 m_xListener( xListener )
46 void operator() ( const InterfaceRef & xObject )
48 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
49 xBroadcaster( xObject, ::com::sun::star::uno::UNO_QUERY );
50 if( xBroadcaster.is() && m_xListener.is())
51 xBroadcaster->addEventListener( m_xListener );
53 private:
54 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > m_xListener;
57 template< class InterfaceRef >
58 struct removeListenerFunctor : public ::std::unary_function< InterfaceRef, void >
60 explicit removeListenerFunctor( const ::com::sun::star::uno::Reference<
61 ::com::sun::star::lang::XEventListener > & xListener ) :
62 m_xListener( xListener )
65 void operator() ( const InterfaceRef & xObject )
67 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
68 xBroadcaster( xObject, ::com::sun::star::uno::UNO_QUERY );
69 if( xBroadcaster.is() && m_xListener.is())
70 xBroadcaster->removeEventListener( m_xListener );
72 private:
73 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > m_xListener;
76 template< class Pair >
77 struct addListenerToMappedElementFunctor : public ::std::unary_function< Pair, void >
79 explicit addListenerToMappedElementFunctor( const ::com::sun::star::uno::Reference<
80 ::com::sun::star::lang::XEventListener > & xListener ) :
81 m_xListener( xListener )
84 void operator() ( const Pair & aPair )
86 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
87 xBroadcaster( aPair.second, ::com::sun::star::uno::UNO_QUERY );
88 if( xBroadcaster.is() && m_xListener.is())
89 xBroadcaster->addEventListener( m_xListener );
91 private:
92 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > m_xListener;
95 template< class Pair >
96 struct removeListenerFromMappedElementFunctor : public ::std::unary_function< Pair, void >
98 explicit removeListenerFromMappedElementFunctor( const ::com::sun::star::uno::Reference<
99 ::com::sun::star::lang::XEventListener > & xListener ) :
100 m_xListener( xListener )
103 void operator() ( const Pair & aPair )
105 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
106 xBroadcaster( aPair.second, ::com::sun::star::uno::UNO_QUERY );
107 if( xBroadcaster.is() && m_xListener.is())
108 xBroadcaster->removeEventListener( m_xListener );
110 private:
111 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > m_xListener;
114 } // namespace impl
116 template< class InterfaceRef >
117 void addListener(
118 const InterfaceRef & xObject,
119 const ::com::sun::star::uno::Reference<
120 ::com::sun::star::lang::XEventListener > & xListener )
122 if( xListener.is())
124 impl::addListenerFunctor< InterfaceRef > aFunctor( xListener );
125 aFunctor( xObject );
129 template< class Container >
130 void addListenerToAllElements(
131 const Container & rContainer,
132 const ::com::sun::star::uno::Reference<
133 ::com::sun::star::lang::XEventListener > & xListener )
135 if( xListener.is())
136 ::std::for_each( rContainer.begin(), rContainer.end(),
137 impl::addListenerFunctor< typename Container::value_type >( xListener ));
140 template< class Container >
141 void addListenerToAllMapElements(
142 const Container & rContainer,
143 const ::com::sun::star::uno::Reference<
144 ::com::sun::star::lang::XEventListener > & xListener )
146 if( xListener.is())
147 ::std::for_each( rContainer.begin(), rContainer.end(),
148 impl::addListenerToMappedElementFunctor< typename Container::value_type >( xListener ));
151 template< typename T >
152 void addListenerToAllSequenceElements(
153 const ::com::sun::star::uno::Sequence< T > & rSequence,
154 const ::com::sun::star::uno::Reference<
155 ::com::sun::star::lang::XEventListener > & xListener )
157 if( xListener.is())
158 ::std::for_each( rSequence.getConstArray(), rSequence.getConstArray() + rSequence.getLength(),
159 impl::addListenerFunctor< T >( xListener ));
162 template< class InterfaceRef >
163 void removeListener(
164 const InterfaceRef & xObject,
165 const ::com::sun::star::uno::Reference<
166 ::com::sun::star::lang::XEventListener > & xListener )
168 if( xListener.is())
170 impl::removeListenerFunctor< InterfaceRef > aFunctor( xListener );
171 aFunctor( xObject );
175 template< class Container >
176 void removeListenerFromAllElements(
177 const Container & rContainer,
178 const ::com::sun::star::uno::Reference<
179 ::com::sun::star::lang::XEventListener > & xListener )
181 if( xListener.is())
182 ::std::for_each( rContainer.begin(), rContainer.end(),
183 impl::removeListenerFunctor< typename Container::value_type >( xListener ));
186 template< class Container >
187 void removeListenerFromAllMapElements(
188 const Container & rContainer,
189 const ::com::sun::star::uno::Reference<
190 ::com::sun::star::lang::XEventListener > & xListener )
192 if( xListener.is())
193 ::std::for_each( rContainer.begin(), rContainer.end(),
194 impl::removeListenerFromMappedElementFunctor< typename Container::value_type >( xListener ));
197 template< typename T >
198 void removeListenerFromAllSequenceElements(
199 const ::com::sun::star::uno::Sequence< T > & rSequence,
200 const ::com::sun::star::uno::Reference<
201 ::com::sun::star::lang::XEventListener > & xListener )
203 if( xListener.is())
204 ::std::for_each( rSequence.getConstArray(), rSequence.getConstArray() + rSequence.getLength(),
205 impl::removeListenerFunctor< T >( xListener ));
208 } // namespace EventListenerHelper
209 } // namespace chart
211 // INCLUDED_CHART2_SOURCE_INC_EVENTLISTENERHELPER_HXX
212 #endif
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */