Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / comphelper / source / misc / SelectionMultiplex.cxx
blob438eaa80d718230c945e888882ab6a04e4df5fc0
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 .
21 #include <comphelper/SelectionMultiplex.hxx>
22 #include <com/sun/star/view/XSelectionSupplier.hpp>
24 namespace comphelper
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::view;
32 OSelectionChangeListener::~OSelectionChangeListener()
37 void OSelectionChangeListener::_disposing(const EventObject&)
39 // nothing to do here
43 OSelectionChangeMultiplexer::OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const Reference< XSelectionSupplier>& _rxSet)
44 :m_xSet(_rxSet)
45 ,m_pListener(_pListener)
46 ,m_nLockCount(0)
48 osl_atomic_increment(&m_refCount);
50 Reference< XSelectionChangeListener> xPreventDelete(this);
51 m_xSet->addSelectionChangeListener(xPreventDelete);
53 osl_atomic_decrement(&m_refCount);
57 OSelectionChangeMultiplexer::~OSelectionChangeMultiplexer()
62 void OSelectionChangeMultiplexer::lock()
64 ++m_nLockCount;
68 void OSelectionChangeMultiplexer::unlock()
70 --m_nLockCount;
74 // XEventListener
76 void SAL_CALL OSelectionChangeMultiplexer::disposing( const EventObject& _rSource)
78 if (m_pListener)
80 // tell the listener
81 if (!locked())
82 m_pListener->_disposing(_rSource);
85 m_pListener = nullptr;
87 m_xSet = nullptr;
90 // XSelectionChangeListener
92 void SAL_CALL OSelectionChangeMultiplexer::selectionChanged( const EventObject& _rEvent )
94 if (m_pListener && !locked())
95 m_pListener->_selectionChanged(_rEvent);
98 void OSelectionChangeMultiplexer::dispose()
100 osl_atomic_increment(&m_refCount);
102 Reference< XSelectionChangeListener> xPreventDelete(this);
103 if(m_xSet.is())
104 m_xSet->removeSelectionChangeListener(xPreventDelete);
106 osl_atomic_decrement(&m_refCount);
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */