2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-29 14:02:24 +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:19:33 +00:00
|
|
|
|
2014-05-10 18:10:59 +02:00
|
|
|
#include <comphelper/containermultiplexer.hxx>
|
2007-07-06 09:19:33 +00:00
|
|
|
#include <osl/diagnose.h>
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-07-06 09:19:33 +00:00
|
|
|
namespace comphelper
|
|
|
|
{
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-07-06 09:19:33 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
|
|
|
|
OContainerListener::OContainerListener(::osl::Mutex& _rMutex)
|
2015-11-10 10:11:47 +01:00
|
|
|
:m_pAdapter(nullptr)
|
2007-07-06 09:19:33 +00:00
|
|
|
,m_rMutex(_rMutex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:19:33 +00:00
|
|
|
OContainerListener::~OContainerListener()
|
|
|
|
{
|
|
|
|
if (m_pAdapter)
|
|
|
|
{
|
|
|
|
m_pAdapter->dispose();
|
2015-11-10 10:11:47 +01:00
|
|
|
m_pAdapter = nullptr;
|
2007-07-06 09:19:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 15:54:52 +00:00
|
|
|
void OContainerListener::_elementInserted( const ContainerEvent& /*_rEvent*/ )
|
|
|
|
throw (RuntimeException, std::exception)
|
2007-07-06 09:19:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 15:54:52 +00:00
|
|
|
void OContainerListener::_elementRemoved( const ContainerEvent& )
|
|
|
|
throw (RuntimeException, std::exception)
|
2007-07-06 09:19:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 15:54:52 +00:00
|
|
|
void OContainerListener::_elementReplaced( const ContainerEvent& /*_rEvent*/ )
|
|
|
|
throw (RuntimeException, std::exception)
|
2007-07-06 09:19:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 15:54:52 +00:00
|
|
|
void OContainerListener::_disposing(const EventObject& )
|
|
|
|
throw (RuntimeException, std::exception)
|
2007-07-06 09:19:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:19:33 +00:00
|
|
|
void OContainerListener::setAdapter(OContainerListenerAdapter* 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:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pAdapter)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
|
|
|
m_pAdapter = pAdapter;
|
|
|
|
m_pAdapter->acquire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener* _pListener,
|
|
|
|
const Reference< XContainer >& _rxContainer)
|
|
|
|
:m_xContainer(_rxContainer)
|
|
|
|
,m_pListener(_pListener)
|
|
|
|
{
|
|
|
|
if (m_pListener)
|
|
|
|
m_pListener->setAdapter(this);
|
|
|
|
|
2015-04-21 08:39:10 +02:00
|
|
|
osl_atomic_increment(&m_refCount);
|
2007-07-06 09:19:33 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_xContainer->addContainerListener(this);
|
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
2014-03-29 18:24:30 +01:00
|
|
|
OSL_FAIL("Exception caught!");
|
2007-07-06 09:19:33 +00:00
|
|
|
}
|
2015-04-21 08:39:10 +02:00
|
|
|
osl_atomic_decrement(&m_refCount);
|
2007-07-06 09:19:33 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:19:33 +00:00
|
|
|
OContainerListenerAdapter::~OContainerListenerAdapter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-07-06 09:19:33 +00:00
|
|
|
void OContainerListenerAdapter::dispose()
|
|
|
|
{
|
|
|
|
if (m_xContainer.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference< XContainerListener > xPreventDelete(this);
|
|
|
|
m_xContainer->removeContainerListener(xPreventDelete);
|
2015-11-10 10:11:47 +01:00
|
|
|
m_pListener->setAdapter(nullptr);
|
2007-07-06 09:19:33 +00:00
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
2011-04-13 10:50:04 +01:00
|
|
|
OSL_FAIL("Exception caught!");
|
2007-07-06 09:19:33 +00:00
|
|
|
}
|
2015-11-10 10:11:47 +01:00
|
|
|
m_xContainer = nullptr;
|
|
|
|
m_pListener = nullptr;
|
2007-07-06 09:19:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void SAL_CALL OContainerListenerAdapter::disposing( const EventObject& _rSource) throw(RuntimeException, std::exception)
|
2007-07-06 09:19:33 +00:00
|
|
|
{
|
|
|
|
if (m_pListener)
|
|
|
|
{
|
|
|
|
// tell the listener
|
2016-06-23 14:30:14 +02:00
|
|
|
m_pListener->_disposing(_rSource);
|
2007-07-06 09:19:33 +00:00
|
|
|
// disconnect the listener
|
|
|
|
if ( m_pListener )
|
2015-11-10 10:11:47 +01:00
|
|
|
m_pListener->setAdapter(nullptr);
|
2007-07-06 09:19:33 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 10:11:47 +01:00
|
|
|
m_xContainer = nullptr;
|
|
|
|
m_pListener = nullptr;
|
2007-07-06 09:19:33 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void SAL_CALL OContainerListenerAdapter::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
|
2007-07-06 09:19:33 +00:00
|
|
|
{
|
2016-06-23 14:30:14 +02:00
|
|
|
if (m_pListener)
|
2007-07-06 09:19:33 +00:00
|
|
|
m_pListener->_elementInserted(_rEvent);
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void SAL_CALL OContainerListenerAdapter::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
|
2007-07-06 09:19:33 +00:00
|
|
|
{
|
2016-06-23 14:30:14 +02:00
|
|
|
if (m_pListener)
|
2007-07-06 09:19:33 +00:00
|
|
|
m_pListener->_elementRemoved(_rEvent);
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void SAL_CALL OContainerListenerAdapter::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
|
2007-07-06 09:19:33 +00:00
|
|
|
{
|
2016-06-23 14:30:14 +02:00
|
|
|
if (m_pListener)
|
2007-07-06 09:19:33 +00:00
|
|
|
m_pListener->_elementReplaced(_rEvent);
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-07-06 09:19:33 +00:00
|
|
|
} // namespace comphelper
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-07-06 09:19:33 +00:00
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|