fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / inc / WeakListenerAdapter.hxx
blob1b7c3def267f7b4a7416364436167bd7ff15dfb6
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/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
32 /** Adapter that enables adding listeners as weak UNO references. Thus, adding
33 an object as listener to a broadcaster does not increase its reference
34 count.
36 <p>The helper class, of course, is held as hard reference at the
37 broadcaster, but this should never be a problem as the adapter's life time
38 depends on no other object.</p>
40 <p>Note that in order to remove an object as listener, you have to remove
41 the same wrapper that you added, i.e., you should store the adapter as a
42 member in the adaptee class for later use.</p>
44 template< class Listener >
45 class WeakListenerAdapter : public
46 ::cppu::WeakImplHelper1< Listener >
48 public:
49 explicit WeakListenerAdapter( const ::com::sun::star::uno::Reference< Listener > & xListener ) :
50 m_xListener( xListener )
52 explicit WeakListenerAdapter( const ::com::sun::star::uno::WeakReference< Listener > & xListener ) :
53 m_xListener( xListener )
55 virtual ~WeakListenerAdapter()
58 protected:
59 // ____ XEventListener (base of all listeners) ____
60 virtual void SAL_CALL disposing(
61 const ::com::sun::star::lang::EventObject& Source )
62 throw (::com::sun::star::uno::RuntimeException)
64 ::com::sun::star::uno::Reference<
65 ::com::sun::star::lang::XEventListener > xEventListener =
66 ::com::sun::star::uno::Reference<
67 ::com::sun::star::lang::XEventListener >(
68 ::com::sun::star::uno::Reference< Listener >( m_xListener), ::com::sun::star::uno::UNO_QUERY );
69 if( xEventListener.is())
70 xEventListener->disposing( Source );
73 ::com::sun::star::uno::Reference< Listener > getListener() const
75 return m_xListener;
78 private:
79 ::com::sun::star::uno::WeakReference< Listener > m_xListener;
82 class WeakModifyListenerAdapter :
83 public WeakListenerAdapter< ::com::sun::star::util::XModifyListener >
85 public:
86 explicit WeakModifyListenerAdapter(
87 const ::com::sun::star::uno::WeakReference< ::com::sun::star::util::XModifyListener > & xListener );
88 virtual ~WeakModifyListenerAdapter();
90 protected:
91 // ____ XModifyListener ____
92 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent )
93 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
96 class WeakSelectionChangeListenerAdapter :
97 public WeakListenerAdapter< ::com::sun::star::view::XSelectionChangeListener >
99 public:
100 explicit WeakSelectionChangeListenerAdapter(
101 const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener > & xListener );
102 virtual ~WeakSelectionChangeListenerAdapter();
104 protected:
105 // ____ XSelectionChangeListener ____
106 virtual void SAL_CALL selectionChanged(
107 const ::com::sun::star::lang::EventObject& aEvent )
108 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
111 } // namespace chart
113 // INCLUDED_CHART2_SOURCE_INC_WEAKLISTENERADAPTER_HXX
114 #endif
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */