Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / inc / WeakListenerAdapter.hxx
blob08568f25316aa2597a3b86a02d5a6d549cf0c5ea
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_WEAKLISTENERADAPTER_HXX
20 #define INCLUDED_CHART2_SOURCE_INC_WEAKLISTENERADAPTER_HXX
22 #include <com/sun/star/lang/XEventListener.hpp>
23 #include <com/sun/star/util/XModifyListener.hpp>
24 #include <com/sun/star/view/XSelectionChangeListener.hpp>
25 #include <cppuhelper/weakref.hxx>
26 #include <cppuhelper/implbase.hxx>
28 namespace chart
31 /** Adapter that enables adding listeners as weak UNO references. Thus, adding
32 an object as listener to a broadcaster does not increase its reference
33 count.
35 <p>The helper class, of course, is held as hard reference at the
36 broadcaster, but this should never be a problem as the adapter's life time
37 depends on no other object.</p>
39 <p>Note that in order to remove an object as listener, you have to remove
40 the same wrapper that you added, i.e., you should store the adapter as a
41 member in the adapted class for later use.</p>
43 template< class Listener >
44 class WeakListenerAdapter : public
45 ::cppu::WeakImplHelper< Listener >
47 public:
48 explicit WeakListenerAdapter( const css::uno::Reference< Listener > & xListener ) :
49 m_xListener( xListener )
51 explicit WeakListenerAdapter( const css::uno::WeakReference< Listener > & xListener ) :
52 m_xListener( xListener )
55 protected:
56 // ____ XEventListener (base of all listeners) ____
57 virtual void SAL_CALL disposing(
58 const css::lang::EventObject& Source ) override
60 css::uno::Reference< css::lang::XEventListener > xEventListener(
61 css::uno::Reference< Listener >( m_xListener), css::uno::UNO_QUERY );
62 if( xEventListener.is())
63 xEventListener->disposing( Source );
66 css::uno::Reference< Listener > getListener() const
68 return m_xListener;
71 private:
72 css::uno::WeakReference< Listener > m_xListener;
75 class WeakModifyListenerAdapter :
76 public WeakListenerAdapter< css::util::XModifyListener >
78 public:
79 explicit WeakModifyListenerAdapter(
80 const css::uno::WeakReference< css::util::XModifyListener > & xListener );
81 virtual ~WeakModifyListenerAdapter() override;
83 protected:
84 // ____ XModifyListener ____
85 virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
88 class WeakSelectionChangeListenerAdapter :
89 public WeakListenerAdapter< css::view::XSelectionChangeListener >
91 public:
92 explicit WeakSelectionChangeListenerAdapter(
93 const css::uno::Reference< css::view::XSelectionChangeListener > & xListener );
94 virtual ~WeakSelectionChangeListenerAdapter() override;
96 protected:
97 // ____ XSelectionChangeListener ____
98 virtual void SAL_CALL selectionChanged(
99 const css::lang::EventObject& aEvent ) override;
102 } // namespace chart
104 // INCLUDED_CHART2_SOURCE_INC_WEAKLISTENERADAPTER_HXX
105 #endif
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */