2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-21 14:30:25 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2007-07-06 09:20:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <comphelper/SelectionMultiplex.hxx>
|
|
|
|
#include <osl/diagnose.h>
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
namespace comphelper
|
|
|
|
{
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::view;
|
|
|
|
|
|
|
|
OSelectionChangeListener::~OSelectionChangeListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 15:54:52 +00:00
|
|
|
void OSelectionChangeListener::_disposing(const EventObject&)
|
|
|
|
throw (RuntimeException, std::exception)
|
2007-07-06 09:20:04 +00:00
|
|
|
{
|
|
|
|
// nothing to do here
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
void OSelectionChangeListener::setAdapter(OSelectionChangeMultiplexer* pAdapter)
|
|
|
|
{
|
|
|
|
if (m_pAdapter)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
|
|
|
m_pAdapter->release();
|
2015-11-10 10:11:47 +01:00
|
|
|
m_pAdapter = nullptr;
|
2007-07-06 09:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pAdapter)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
|
|
|
m_pAdapter = pAdapter;
|
|
|
|
m_pAdapter->acquire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 15:01:55 +02:00
|
|
|
OSelectionChangeMultiplexer::OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const Reference< XSelectionSupplier>& _rxSet)
|
2007-07-06 09:20:04 +00:00
|
|
|
:m_xSet(_rxSet)
|
|
|
|
,m_pListener(_pListener)
|
|
|
|
,m_nLockCount(0)
|
|
|
|
{
|
|
|
|
m_pListener->setAdapter(this);
|
2012-09-22 01:51:12 -05:00
|
|
|
osl_atomic_increment(&m_refCount);
|
2007-07-06 09:20:04 +00:00
|
|
|
{
|
|
|
|
Reference< XSelectionChangeListener> xPreventDelete(this);
|
|
|
|
m_xSet->addSelectionChangeListener(xPreventDelete);
|
|
|
|
}
|
2012-09-22 01:51:12 -05:00
|
|
|
osl_atomic_decrement(&m_refCount);
|
2007-07-06 09:20:04 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
OSelectionChangeMultiplexer::~OSelectionChangeMultiplexer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
void OSelectionChangeMultiplexer::lock()
|
|
|
|
{
|
|
|
|
++m_nLockCount;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
void OSelectionChangeMultiplexer::unlock()
|
|
|
|
{
|
|
|
|
--m_nLockCount;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
// XEventListener
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void SAL_CALL OSelectionChangeMultiplexer::disposing( const EventObject& _rSource) throw( RuntimeException, std::exception)
|
2007-07-06 09:20:04 +00:00
|
|
|
{
|
|
|
|
if (m_pListener)
|
|
|
|
{
|
|
|
|
// tell the listener
|
|
|
|
if (!locked())
|
|
|
|
m_pListener->_disposing(_rSource);
|
|
|
|
// disconnect the listener
|
|
|
|
if (m_pListener) // may have been reset whilest calling into _disposing
|
2015-11-10 10:11:47 +01:00
|
|
|
m_pListener->setAdapter(nullptr);
|
2007-07-06 09:20:04 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 10:11:47 +01:00
|
|
|
m_pListener = nullptr;
|
2007-07-06 09:20:04 +00:00
|
|
|
|
2016-04-04 15:01:55 +02:00
|
|
|
m_xSet = nullptr;
|
2007-07-06 09:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XSelectionChangeListener
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void SAL_CALL OSelectionChangeMultiplexer::selectionChanged( const EventObject& _rEvent ) throw( RuntimeException, std::exception)
|
2007-07-06 09:20:04 +00:00
|
|
|
{
|
|
|
|
if (m_pListener && !locked())
|
|
|
|
m_pListener->_selectionChanged(_rEvent);
|
|
|
|
}
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
}
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-07-06 09:20:04 +00:00
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|