LibreOffice Module comphelper (master) 1
SelectionMultiplex.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
22#include <com/sun/star/view/XSelectionSupplier.hpp>
23
24namespace comphelper
25{
26
27
28using namespace ::com::sun::star::uno;
29using namespace ::com::sun::star::lang;
30using namespace ::com::sun::star::view;
31
33{
34}
35
36
38{
39 // nothing to do here
40}
41
42
43OSelectionChangeMultiplexer::OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const Reference< XSelectionSupplier>& _rxSet)
44 :m_xSet(_rxSet)
45 ,m_pListener(_pListener)
46 ,m_nLockCount(0)
47{
48 osl_atomic_increment(&m_refCount);
49 {
50 Reference< XSelectionChangeListener> xPreventDelete(this);
51 m_xSet->addSelectionChangeListener(xPreventDelete);
52 }
53 osl_atomic_decrement(&m_refCount);
54}
55
56
58{
59}
60
61
63{
65}
66
67
69{
71}
72
73
74// XEventListener
75
76void SAL_CALL OSelectionChangeMultiplexer::disposing( const EventObject& _rSource)
77{
78 if (m_pListener)
79 {
80 // tell the listener
81 if (!locked())
82 m_pListener->_disposing(_rSource);
83 }
84
85 m_pListener = nullptr;
86
87 m_xSet = nullptr;
88}
89
90// XSelectionChangeListener
91
92void SAL_CALL OSelectionChangeMultiplexer::selectionChanged( const EventObject& _rEvent )
93{
94 if (m_pListener && !locked())
96}
97
99{
100 osl_atomic_increment(&m_refCount);
101 {
102 Reference< XSelectionChangeListener> xPreventDelete(this);
103 if(m_xSet.is())
104 m_xSet->removeSelectionChangeListener(xPreventDelete);
105 }
106 osl_atomic_decrement(&m_refCount);
107}
108
109}
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
simple listener adapter for selections
virtual void _disposing(const css::lang::EventObject &_rSource)
virtual void _selectionChanged(const css::lang::EventObject &aEvent)=0
sal_Int32 locked() const
get the lock count
virtual void SAL_CALL selectionChanged(const css::lang::EventObject &aEvent) override
css::uno::Reference< css::view::XSelectionSupplier > m_xSet
OSelectionChangeMultiplexer(const OSelectionChangeMultiplexer &)=delete
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
ULONG m_refCount