LibreOffice Module chart2 (master) 1
ModifyListenerHelper.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#pragma once
20
21#include <com/sun/star/util/XModifyListener.hpp>
22#include <com/sun/star/util/XModifyBroadcaster.hpp>
25#include <rtl/ref.hxx>
26
27#include <mutex>
28#include <algorithm>
29#include <utility>
30
31namespace chart
32{
33
40 css::util::XModifyBroadcaster,
41 css::util::XModifyListener >
42{
43public:
45
46 // ____ XModifyBroadcaster ____
47 virtual void SAL_CALL addModifyListener(
48 const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
49 virtual void SAL_CALL removeModifyListener(
50 const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
51
52 // ____ XModifyListener ____
53 virtual void SAL_CALL modified(
54 const css::lang::EventObject& aEvent ) override;
55
56private:
57 // ____ XEventListener (base of XModifyListener) ____
58 virtual void SAL_CALL disposing(
59 const css::lang::EventObject& Source ) override;
60
61 // ____ WeakComponentImplHelperBase ____
62 virtual void disposing(std::unique_lock<std::mutex>& ) override;
63
65};
66
67}
68
70{
71
72namespace impl
73{
74
75template< class InterfaceRef >
77{
78 explicit addListenerFunctor( css::uno::Reference< css::util::XModifyListener > xListener ) :
79 m_xListener(std::move( xListener ))
80 {}
81
82 void operator() ( const InterfaceRef & xObject )
83 {
84 css::uno::Reference< css::util::XModifyBroadcaster >
85 xBroadcaster( xObject, css::uno::UNO_QUERY );
86 if( xBroadcaster.is() && m_xListener.is())
87 xBroadcaster->addModifyListener( m_xListener );
88 }
89private:
90 css::uno::Reference< css::util::XModifyListener > m_xListener;
91};
92
93template< class InterfaceRef >
95{
96 explicit removeListenerFunctor( css::uno::Reference< css::util::XModifyListener > xListener ) :
97 m_xListener(std::move( xListener ))
98 {}
99
100 void operator() ( const InterfaceRef & xObject )
101 {
102 css::uno::Reference< css::util::XModifyBroadcaster >
103 xBroadcaster( xObject, css::uno::UNO_QUERY );
104 if( xBroadcaster.is() && m_xListener.is())
105 xBroadcaster->removeModifyListener( m_xListener );
106 }
107private:
108 css::uno::Reference< css::util::XModifyListener > m_xListener;
109};
110
111template< class Pair >
113{
114 explicit addListenerToMappedElementFunctor( css::uno::Reference< css::util::XModifyListener > xListener ) :
115 m_xListener(std::move( xListener ))
116 {}
117
118 void operator() ( const Pair & aPair )
119 {
120 css::uno::Reference< css::util::XModifyBroadcaster >
121 xBroadcaster( aPair.second, css::uno::UNO_QUERY );
122 if( xBroadcaster.is() && m_xListener.is())
123 xBroadcaster->addModifyListener( m_xListener );
124 }
125private:
126 css::uno::Reference< css::util::XModifyListener > m_xListener;
127};
128
129template< class Pair >
131{
132 explicit removeListenerFromMappedElementFunctor( css::uno::Reference< css::util::XModifyListener > xListener ) :
133 m_xListener(std::move( xListener ))
134 {}
135
136 void operator() ( const Pair & aPair )
137 {
138 css::uno::Reference< css::util::XModifyBroadcaster >
139 xBroadcaster( aPair.second, css::uno::UNO_QUERY );
140 if( xBroadcaster.is() && m_xListener.is())
141 xBroadcaster->removeModifyListener( m_xListener );
142 }
143private:
144 css::uno::Reference< css::util::XModifyListener > m_xListener;
145};
146
147} // namespace impl
148
149template< class InterfaceRef >
151 const InterfaceRef & xObject,
152 const css::uno::Reference< css::util::XModifyListener > & xListener )
153{
154 if( xListener.is())
155 {
156 impl::addListenerFunctor< InterfaceRef > aFunctor( xListener );
157 aFunctor( xObject );
158 }
159}
160template< class T >
162 const rtl::Reference<T> & xBroadcaster,
163 const css::uno::Reference< css::util::XModifyListener > & xListener )
164{
165 if( xBroadcaster && xListener )
166 xBroadcaster->addModifyListener( xListener );
167}
168
169template< class Container >
171 const Container & rContainer,
172 const css::uno::Reference< css::util::XModifyListener > & xListener )
173{
174 if( xListener.is())
175 std::for_each( rContainer.begin(), rContainer.end(),
177}
178
179template< class T >
181 const std::vector<rtl::Reference<T>> & rContainer,
182 const css::uno::Reference< css::util::XModifyListener > & xListener )
183{
184 if( !xListener )
185 return;
186 for (auto const & i : rContainer)
187 i->addModifyListener(xListener);
188}
189
190template< class Container >
192 const Container & rContainer,
193 const css::uno::Reference< css::util::XModifyListener > & xListener )
194{
195 if( xListener.is())
196 std::for_each( rContainer.begin(), rContainer.end(),
198}
199
200template< class InterfaceRef >
202 const InterfaceRef & xObject,
203 const css::uno::Reference< css::util::XModifyListener > & xListener )
204{
205 if( xListener.is())
206 {
208 aFunctor( xObject );
209 }
210}
211
212template< class T >
214 const rtl::Reference<T> & xBroadcaster,
215 const css::uno::Reference< css::util::XModifyListener > & xListener )
216{
217 if( xBroadcaster && xListener )
218 xBroadcaster->removeModifyListener( xListener );
219}
220
221template< class Container >
223 const Container & rContainer,
224 const css::uno::Reference< css::util::XModifyListener > & xListener )
225{
226 if( xListener.is())
227 std::for_each( rContainer.begin(), rContainer.end(),
229}
230
231template< class T >
233 const std::vector<rtl::Reference<T>> & rContainer,
234 const css::uno::Reference< css::util::XModifyListener > & xListener )
235{
236 if( !xListener )
237 return;
238 for (auto const & i : rContainer)
239 i->removeModifyListener(xListener);
240}
241
242template< class Container >
244 const Container & rContainer,
245 const css::uno::Reference< css::util::XModifyListener > & xListener )
246{
247 if( xListener.is())
248 std::for_each( rContainer.begin(), rContainer.end(),
250}
251
252} // namespace chart::ModifyListenerHelper
253
254/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
This helper class serves as forwarder of modify events.
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
comphelper::OInterfaceContainerHelper4< css::util::XModifyListener > m_aModifyListeners
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
void addListenerToAllMapElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
void removeListenerFromAllElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
void addListenerToAllElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
void removeListenerFromAllMapElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
int i
css::uno::Reference< css::util::XModifyListener > m_xListener
addListenerFunctor(css::uno::Reference< css::util::XModifyListener > xListener)
addListenerToMappedElementFunctor(css::uno::Reference< css::util::XModifyListener > xListener)
css::uno::Reference< css::util::XModifyListener > m_xListener
removeListenerFromMappedElementFunctor(css::uno::Reference< css::util::XModifyListener > xListener)
removeListenerFunctor(css::uno::Reference< css::util::XModifyListener > xListener)
css::uno::Reference< css::util::XModifyListener > m_xListener