1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <com/sun/star/lang/XEventListener.hpp>
22 #include <com/sun/star/view/XSelectionChangeListener.hpp>
23 #include <cppuhelper/weakref.hxx>
24 #include <cppuhelper/implbase.hxx>
29 /** Adapter that enables adding listeners as weak UNO references. Thus, adding
30 an object as listener to a broadcaster does not increase its reference
33 <p>The helper class, of course, is held as hard reference at the
34 broadcaster, but this should never be a problem as the adapter's life time
35 depends on no other object.</p>
37 <p>Note that in order to remove an object as listener, you have to remove
38 the same wrapper that you added, i.e., you should store the adapter as a
39 member in the adapted class for later use.</p>
41 template< class Listener
>
42 class WeakListenerAdapter
: public
43 ::cppu::WeakImplHelper
< Listener
>
46 explicit WeakListenerAdapter( const css::uno::Reference
< Listener
> & xListener
) :
47 m_xListener( xListener
)
51 // ____ XEventListener (base of all listeners) ____
52 virtual void SAL_CALL
disposing(
53 const css::lang::EventObject
& Source
) override
55 css::uno::Reference
< css::lang::XEventListener
> xEventListener(
56 css::uno::Reference
< Listener
>( m_xListener
), css::uno::UNO_QUERY
);
57 if( xEventListener
.is())
58 xEventListener
->disposing( Source
);
61 css::uno::Reference
< Listener
> getListener() const
67 css::uno::WeakReference
< Listener
> m_xListener
;
70 class WeakSelectionChangeListenerAdapter final
:
71 public WeakListenerAdapter
< css::view::XSelectionChangeListener
>
74 explicit WeakSelectionChangeListenerAdapter(
75 const css::uno::Reference
< css::view::XSelectionChangeListener
> & xListener
);
76 virtual ~WeakSelectionChangeListenerAdapter() override
;
79 // ____ XSelectionChangeListener ____
80 virtual void SAL_CALL
selectionChanged(
81 const css::lang::EventObject
& aEvent
) override
;
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */