tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / inc / WeakListenerAdapter.hxx
blobe312f7bee56fd4b9106ae149c23abd469098c502
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 #pragma once
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>
26 namespace chart
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
31 count.
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 class WeakSelectionChangeListenerAdapter final :
42 public ::cppu::WeakImplHelper< css::view::XSelectionChangeListener >
44 public:
45 explicit WeakSelectionChangeListenerAdapter(
46 const css::uno::Reference< css::view::XSelectionChangeListener > & xListener )
47 : m_xListener( xListener ) {}
48 virtual ~WeakSelectionChangeListenerAdapter() override;
50 protected:
51 // ____ XSelectionChangeListener ____
52 virtual void SAL_CALL selectionChanged(
53 const css::lang::EventObject& aEvent ) override;
55 // ____ XEventListener (base of all listeners) ____
56 virtual void SAL_CALL disposing(
57 const css::lang::EventObject& Source ) override
59 css::uno::Reference< css::view::XSelectionChangeListener > xEventListener( m_xListener );
60 if( xEventListener.is())
61 xEventListener->disposing( Source );
64 private:
65 css::uno::WeakReference< css::view::XSelectionChangeListener > m_xListener;
68 } // namespace chart
70 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */