1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef CHART2_WEAKLISTENERADAPTER_HXX
28 #define CHART2_WEAKLISTENERADAPTER_HXX
30 #include <com/sun/star/uno/XWeak.hpp>
31 #include <com/sun/star/lang/XEventListener.hpp>
32 #include <com/sun/star/util/XModifyListener.hpp>
33 #include <com/sun/star/view/XSelectionChangeListener.hpp>
34 #include <cppuhelper/weakref.hxx>
35 #include <cppuhelper/implbase1.hxx>
39 // --------------------------------------------------------------------------------
41 /** Adapter that enables adding listeners as weak UNO references. Thus, adding
42 an object as listener to a broadcaster does not increase its reference
45 <p>The helper class, of course, is held as hard reference at the
46 broadcaster, but this should never be a problem as the adapter's life time
47 depends on no other object.</p>
49 <p>Note that in order to remove an object as listener, you have to remove
50 the same wrapper that you added, i.e., you should store the adapter as a
51 member in the adaptee class for later use.</p>
53 template< class Listener
>
54 class WeakListenerAdapter
: public
55 ::cppu::WeakImplHelper1
< Listener
>
58 explicit WeakListenerAdapter( const ::com::sun::star::uno::Reference
< Listener
> & xListener
) :
59 m_xListener( xListener
)
61 explicit WeakListenerAdapter( const ::com::sun::star::uno::WeakReference
< Listener
> & xListener
) :
62 m_xListener( xListener
)
64 virtual ~WeakListenerAdapter()
68 // ____ XEventListener (base of all listeners) ____
69 virtual void SAL_CALL
disposing(
70 const ::com::sun::star::lang::EventObject
& Source
)
71 throw (::com::sun::star::uno::RuntimeException
)
73 ::com::sun::star::uno::Reference
<
74 ::com::sun::star::lang::XEventListener
> xEventListener
=
75 ::com::sun::star::uno::Reference
<
76 ::com::sun::star::lang::XEventListener
>(
77 ::com::sun::star::uno::Reference
< Listener
>( m_xListener
), ::com::sun::star::uno::UNO_QUERY
);
78 if( xEventListener
.is())
79 xEventListener
->disposing( Source
);
82 ::com::sun::star::uno::Reference
< Listener
> getListener() const
88 ::com::sun::star::uno::WeakReference
< Listener
> m_xListener
;
91 // --------------------------------------------------------------------------------
93 class WeakModifyListenerAdapter
:
94 public WeakListenerAdapter
< ::com::sun::star::util::XModifyListener
>
97 explicit WeakModifyListenerAdapter(
98 const ::com::sun::star::uno::WeakReference
< ::com::sun::star::util::XModifyListener
> & xListener
);
99 virtual ~WeakModifyListenerAdapter();
102 // ____ XModifyListener ____
103 virtual void SAL_CALL
modified( const ::com::sun::star::lang::EventObject
& aEvent
)
104 throw (::com::sun::star::uno::RuntimeException
);
107 // --------------------------------------------------------------------------------
109 class WeakSelectionChangeListenerAdapter
:
110 public WeakListenerAdapter
< ::com::sun::star::view::XSelectionChangeListener
>
113 explicit WeakSelectionChangeListenerAdapter(
114 const ::com::sun::star::uno::Reference
< ::com::sun::star::view::XSelectionChangeListener
> & xListener
);
115 virtual ~WeakSelectionChangeListenerAdapter();
118 // ____ XSelectionChangeListener ____
119 virtual void SAL_CALL
selectionChanged(
120 const ::com::sun::star::lang::EventObject
& aEvent
)
121 throw (::com::sun::star::uno::RuntimeException
);
126 // CHART2_WEAKLISTENERADAPTER_HXX