bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / inc / WeakListenerAdapter.hxx
blobc47cf56062f12b9e28fbf3ccd3e40c106eba6030
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 CHART2_WEAKLISTENERADAPTER_HXX
20 #define CHART2_WEAKLISTENERADAPTER_HXX
22 #include <com/sun/star/uno/XWeak.hpp>
23 #include <com/sun/star/lang/XEventListener.hpp>
24 #include <com/sun/star/util/XModifyListener.hpp>
25 #include <com/sun/star/view/XSelectionChangeListener.hpp>
26 #include <cppuhelper/weakref.hxx>
27 #include <cppuhelper/implbase1.hxx>
29 namespace chart
31 // --------------------------------------------------------------------------------
33 /** Adapter that enables adding listeners as weak UNO references. Thus, adding
34 an object as listener to a broadcaster does not increase its reference
35 count.
37 <p>The helper class, of course, is held as hard reference at the
38 broadcaster, but this should never be a problem as the adapter's life time
39 depends on no other object.</p>
41 <p>Note that in order to remove an object as listener, you have to remove
42 the same wrapper that you added, i.e., you should store the adapter as a
43 member in the adaptee class for later use.</p>
45 template< class Listener >
46 class WeakListenerAdapter : public
47 ::cppu::WeakImplHelper1< Listener >
49 public:
50 explicit WeakListenerAdapter( const ::com::sun::star::uno::Reference< Listener > & xListener ) :
51 m_xListener( xListener )
53 explicit WeakListenerAdapter( const ::com::sun::star::uno::WeakReference< Listener > & xListener ) :
54 m_xListener( xListener )
56 virtual ~WeakListenerAdapter()
59 protected:
60 // ____ XEventListener (base of all listeners) ____
61 virtual void SAL_CALL disposing(
62 const ::com::sun::star::lang::EventObject& Source )
63 throw (::com::sun::star::uno::RuntimeException)
65 ::com::sun::star::uno::Reference<
66 ::com::sun::star::lang::XEventListener > xEventListener =
67 ::com::sun::star::uno::Reference<
68 ::com::sun::star::lang::XEventListener >(
69 ::com::sun::star::uno::Reference< Listener >( m_xListener), ::com::sun::star::uno::UNO_QUERY );
70 if( xEventListener.is())
71 xEventListener->disposing( Source );
74 ::com::sun::star::uno::Reference< Listener > getListener() const
76 return m_xListener;
79 private:
80 ::com::sun::star::uno::WeakReference< Listener > m_xListener;
83 // --------------------------------------------------------------------------------
85 class WeakModifyListenerAdapter :
86 public WeakListenerAdapter< ::com::sun::star::util::XModifyListener >
88 public:
89 explicit WeakModifyListenerAdapter(
90 const ::com::sun::star::uno::WeakReference< ::com::sun::star::util::XModifyListener > & xListener );
91 virtual ~WeakModifyListenerAdapter();
93 protected:
94 // ____ XModifyListener ____
95 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent )
96 throw (::com::sun::star::uno::RuntimeException);
99 // --------------------------------------------------------------------------------
101 class WeakSelectionChangeListenerAdapter :
102 public WeakListenerAdapter< ::com::sun::star::view::XSelectionChangeListener >
104 public:
105 explicit WeakSelectionChangeListenerAdapter(
106 const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener > & xListener );
107 virtual ~WeakSelectionChangeListenerAdapter();
109 protected:
110 // ____ XSelectionChangeListener ____
111 virtual void SAL_CALL selectionChanged(
112 const ::com::sun::star::lang::EventObject& aEvent )
113 throw (::com::sun::star::uno::RuntimeException);
116 } // namespace chart
118 // CHART2_WEAKLISTENERADAPTER_HXX
119 #endif
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */