merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / inc / WeakListenerAdapter.hxx
blob56352f6a885632f9819d98224ab9c37c7bea98ab
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WeakListenerAdapter.hxx,v $
10 * $Revision: 1.4.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CHART2_WEAKLISTENERADAPTER_HXX
31 #define CHART2_WEAKLISTENERADAPTER_HXX
33 #include <com/sun/star/uno/XWeak.hpp>
34 #include <com/sun/star/lang/XEventListener.hpp>
35 #include <com/sun/star/util/XModifyListener.hpp>
36 #include <com/sun/star/view/XSelectionChangeListener.hpp>
37 #include <cppuhelper/weakref.hxx>
38 #include <cppuhelper/implbase1.hxx>
40 namespace chart
42 // --------------------------------------------------------------------------------
44 /** Adapter that enables adding listeners as weak UNO references. Thus, adding
45 an object as listener to a broadcaster does not increase its reference
46 count.
48 <p>The helper class, of course, is held as hard reference at the
49 broadcaster, but this should never be a problem as the adapter's life time
50 depends on no other object.</p>
52 <p>Note that in order to remove an object as listener, you have to remove
53 the same wrapper that you added, i.e., you should store the adapter as a
54 member in the adaptee class for later use.</p>
56 template< class Listener >
57 class WeakListenerAdapter : public
58 ::cppu::WeakImplHelper1< Listener >
60 public:
61 explicit WeakListenerAdapter( const ::com::sun::star::uno::Reference< Listener > & xListener ) :
62 m_xListener( xListener )
64 explicit WeakListenerAdapter( const ::com::sun::star::uno::WeakReference< Listener > & xListener ) :
65 m_xListener( xListener )
67 virtual ~WeakListenerAdapter()
70 protected:
71 // ____ XEventListener (base of all listeners) ____
72 virtual void SAL_CALL disposing(
73 const ::com::sun::star::lang::EventObject& Source )
74 throw (::com::sun::star::uno::RuntimeException)
76 ::com::sun::star::uno::Reference<
77 ::com::sun::star::lang::XEventListener > xEventListener =
78 ::com::sun::star::uno::Reference<
79 ::com::sun::star::lang::XEventListener >(
80 ::com::sun::star::uno::Reference< Listener >( m_xListener), ::com::sun::star::uno::UNO_QUERY );
81 if( xEventListener.is())
82 xEventListener->disposing( Source );
85 ::com::sun::star::uno::Reference< Listener > getListener() const
87 return m_xListener;
90 private:
91 ::com::sun::star::uno::WeakReference< Listener > m_xListener;
94 // --------------------------------------------------------------------------------
96 class WeakModifyListenerAdapter :
97 public WeakListenerAdapter< ::com::sun::star::util::XModifyListener >
99 public:
100 explicit WeakModifyListenerAdapter(
101 const ::com::sun::star::uno::WeakReference< ::com::sun::star::util::XModifyListener > & xListener );
102 virtual ~WeakModifyListenerAdapter();
104 protected:
105 // ____ XModifyListener ____
106 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent )
107 throw (::com::sun::star::uno::RuntimeException);
110 // --------------------------------------------------------------------------------
112 class WeakSelectionChangeListenerAdapter :
113 public WeakListenerAdapter< ::com::sun::star::view::XSelectionChangeListener >
115 public:
116 explicit WeakSelectionChangeListenerAdapter(
117 const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener > & xListener );
118 virtual ~WeakSelectionChangeListenerAdapter();
120 protected:
121 // ____ XSelectionChangeListener ____
122 virtual void SAL_CALL selectionChanged(
123 const ::com::sun::star::lang::EventObject& aEvent )
124 throw (::com::sun::star::uno::RuntimeException);
127 } // namespace chart
129 // CHART2_WEAKLISTENERADAPTER_HXX
130 #endif