2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-14 17:39:53 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2010-02-12 15:01:35 +01:00
|
|
|
*
|
2012-06-14 17:39:53 +01:00
|
|
|
* 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/.
|
2010-02-12 15:01:35 +01:00
|
|
|
*
|
2012-06-14 17:39:53 +01:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2010-02-12 15:01:35 +01:00
|
|
|
*
|
2012-06-14 17:39:53 +01:00
|
|
|
* 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 .
|
|
|
|
*/
|
2008-10-16 06:57:26 +00:00
|
|
|
|
|
|
|
#include "documentevents.hxx"
|
|
|
|
|
|
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
|
|
|
|
2014-11-14 22:52:35 +01:00
|
|
|
#include <osl/diagnose.h>
|
2008-10-16 06:57:26 +00:00
|
|
|
#include <comphelper/namedvaluecollection.hxx>
|
2015-11-19 13:43:23 +02:00
|
|
|
#include <comphelper/sequence.hxx>
|
2008-10-16 06:57:26 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2015-08-17 14:40:17 +02:00
|
|
|
#include <o3tl/functional.hxx>
|
2008-10-16 06:57:26 +00:00
|
|
|
|
|
|
|
namespace dbaccess
|
|
|
|
{
|
|
|
|
|
|
|
|
using ::com::sun::star::uno::XInterface;
|
|
|
|
using ::com::sun::star::uno::Exception;
|
|
|
|
using ::com::sun::star::uno::RuntimeException;
|
|
|
|
using ::com::sun::star::uno::Any;
|
|
|
|
using ::com::sun::star::uno::makeAny;
|
|
|
|
using ::com::sun::star::beans::PropertyValue;
|
|
|
|
using ::com::sun::star::container::NoSuchElementException;
|
|
|
|
using ::com::sun::star::lang::WrappedTargetException;
|
|
|
|
using ::com::sun::star::lang::IllegalArgumentException;
|
|
|
|
using ::com::sun::star::uno::Sequence;
|
|
|
|
using ::com::sun::star::uno::Type;
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// DocumentEvents_Data
|
2016-04-08 14:58:51 +02:00
|
|
|
struct DocumentEvents_Data
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
::cppu::OWeakObject& rParent;
|
|
|
|
::osl::Mutex& rMutex;
|
2009-04-24 18:34:24 +00:00
|
|
|
DocumentEventsData& rEventsData;
|
2008-10-16 06:57:26 +00:00
|
|
|
|
2009-04-24 18:34:24 +00:00
|
|
|
DocumentEvents_Data( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, DocumentEventsData& _rEventsData )
|
2008-10-16 06:57:26 +00:00
|
|
|
:rParent( _rParent )
|
|
|
|
,rMutex( _rMutex )
|
2009-04-24 18:34:24 +00:00
|
|
|
,rEventsData( _rEventsData )
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
}
|
2016-04-08 14:58:51 +02:00
|
|
|
DocumentEvents_Data(const DocumentEvents_Data&) = delete;
|
|
|
|
const DocumentEvents_Data& operator=(const DocumentEvents_Data&) = delete;
|
2008-10-16 06:57:26 +00:00
|
|
|
};
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// helper
|
2008-10-16 06:57:26 +00:00
|
|
|
struct DocumentEventData
|
|
|
|
{
|
|
|
|
const sal_Char* pAsciiEventName;
|
|
|
|
bool bNeedsSyncNotify;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2016-03-11 00:49:47 +01:00
|
|
|
const DocumentEventData* lcl_getDocumentEventData()
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
static const DocumentEventData s_aData[] = {
|
|
|
|
{ "OnCreate", true },
|
|
|
|
{ "OnLoadFinished", true },
|
|
|
|
{ "OnNew", false }, // compatibility, see http://www.openoffice.org/issues/show_bug.cgi?id=46484
|
|
|
|
{ "OnLoad", false }, // compatibility, see http://www.openoffice.org/issues/show_bug.cgi?id=46484
|
|
|
|
{ "OnSaveAs", true },
|
|
|
|
{ "OnSaveAsDone", false },
|
|
|
|
{ "OnSaveAsFailed", false },
|
|
|
|
{ "OnSave", true },
|
|
|
|
{ "OnSaveDone", false },
|
|
|
|
{ "OnSaveFailed", false },
|
|
|
|
{ "OnSaveTo", true },
|
|
|
|
{ "OnSaveToDone", false },
|
|
|
|
{ "OnSaveToFailed", false },
|
|
|
|
{ "OnPrepareUnload", true },
|
|
|
|
{ "OnUnload", true },
|
|
|
|
{ "OnFocus", false },
|
|
|
|
{ "OnUnfocus", false },
|
|
|
|
{ "OnModifyChanged", false },
|
|
|
|
{ "OnViewCreated", false },
|
|
|
|
{ "OnPrepareViewClosing", true },
|
|
|
|
{ "OnViewClosed", false },
|
|
|
|
{ "OnTitleChanged", false },
|
2009-02-17 15:39:54 +00:00
|
|
|
{ "OnSubComponentOpened", false },
|
|
|
|
{ "OnSubComponentClosed", false },
|
2015-11-10 10:13:39 +01:00
|
|
|
{ nullptr, false }
|
2008-10-16 06:57:26 +00:00
|
|
|
};
|
|
|
|
return s_aData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// DocumentEvents
|
2009-04-24 18:34:24 +00:00
|
|
|
DocumentEvents::DocumentEvents( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, DocumentEventsData& _rEventsData )
|
|
|
|
:m_pData( new DocumentEvents_Data( _rParent, _rMutex, _rEventsData ) )
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
const DocumentEventData* pEventData = lcl_getDocumentEventData();
|
|
|
|
while ( pEventData->pAsciiEventName )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sEventName = OUString::createFromAscii( pEventData->pAsciiEventName );
|
2016-03-28 19:17:45 +02:00
|
|
|
DocumentEventsData::const_iterator existingPos = m_pData->rEventsData.find( sEventName );
|
2009-04-24 18:34:24 +00:00
|
|
|
if ( existingPos == m_pData->rEventsData.end() )
|
|
|
|
m_pData->rEventsData[ sEventName ] = Sequence< PropertyValue >();
|
2008-10-16 06:57:26 +00:00
|
|
|
++pEventData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentEvents::~DocumentEvents()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL DocumentEvents::acquire() throw()
|
|
|
|
{
|
|
|
|
m_pData->rParent.acquire();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL DocumentEvents::release() throw()
|
|
|
|
{
|
|
|
|
m_pData->rParent.release();
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
bool DocumentEvents::needsSynchronousNotification( const OUString& _rEventName )
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
const DocumentEventData* pEventData = lcl_getDocumentEventData();
|
|
|
|
while ( pEventData->pAsciiEventName )
|
|
|
|
{
|
2013-11-05 14:39:55 +02:00
|
|
|
if ( _rEventName.equalsAscii( pEventData->pAsciiEventName ) )
|
2008-10-16 06:57:26 +00:00
|
|
|
return pEventData->bNeedsSyncNotify;
|
|
|
|
++pEventData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is an unknown event ... assume async notification
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void SAL_CALL DocumentEvents::replaceByName( const OUString& _Name, const Any& _Element ) throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_pData->rMutex );
|
|
|
|
|
2009-04-24 18:34:24 +00:00
|
|
|
DocumentEventsData::iterator elementPos = m_pData->rEventsData.find( _Name );
|
|
|
|
if ( elementPos == m_pData->rEventsData.end() )
|
2008-10-16 06:57:26 +00:00
|
|
|
throw NoSuchElementException( _Name, *this );
|
|
|
|
|
|
|
|
Sequence< PropertyValue > aEventDescriptor;
|
|
|
|
if ( _Element.hasValue() && !( _Element >>= aEventDescriptor ) )
|
|
|
|
throw IllegalArgumentException( _Element.getValueTypeName(), *this, 2 );
|
|
|
|
|
|
|
|
// Weird enough, the event assignment UI has (well: had) the idea of using an empty "EventType"/"Script"
|
|
|
|
// to indicate the event descriptor should be reset, instead of just passing an empty event descriptor.
|
|
|
|
::comphelper::NamedValueCollection aCheck( aEventDescriptor );
|
|
|
|
if ( aCheck.has( "EventType" ) )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sEventType = aCheck.getOrDefault( "EventType", OUString() );
|
2011-12-19 18:10:37 -02:00
|
|
|
OSL_ENSURE( !sEventType.isEmpty(), "DocumentEvents::replaceByName: doing a reset via an empty EventType is weird!" );
|
|
|
|
if ( sEventType.isEmpty() )
|
2008-10-16 06:57:26 +00:00
|
|
|
aEventDescriptor.realloc( 0 );
|
|
|
|
}
|
|
|
|
if ( aCheck.has( "Script" ) )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sScript = aCheck.getOrDefault( "Script", OUString() );
|
2011-12-19 18:10:37 -02:00
|
|
|
OSL_ENSURE( !sScript.isEmpty(), "DocumentEvents::replaceByName: doing a reset via an empty Script is weird!" );
|
|
|
|
if ( sScript.isEmpty() )
|
2008-10-16 06:57:26 +00:00
|
|
|
aEventDescriptor.realloc( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
elementPos->second = aEventDescriptor;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Any SAL_CALL DocumentEvents::getByName( const OUString& _Name ) throw (NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_pData->rMutex );
|
|
|
|
|
2009-04-24 18:34:24 +00:00
|
|
|
DocumentEventsData::const_iterator elementPos = m_pData->rEventsData.find( _Name );
|
|
|
|
if ( elementPos == m_pData->rEventsData.end() )
|
2008-10-16 06:57:26 +00:00
|
|
|
throw NoSuchElementException( _Name, *this );
|
|
|
|
|
|
|
|
Any aReturn;
|
|
|
|
const Sequence< PropertyValue >& rEventDesc( elementPos->second );
|
|
|
|
if ( rEventDesc.getLength() > 0 )
|
|
|
|
aReturn <<= rEventDesc;
|
|
|
|
return aReturn;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Sequence< OUString > SAL_CALL DocumentEvents::getElementNames( ) throw (RuntimeException, std::exception)
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_pData->rMutex );
|
|
|
|
|
2015-11-19 13:43:23 +02:00
|
|
|
return comphelper::mapKeysToSequence( m_pData->rEventsData );
|
2008-10-16 06:57:26 +00:00
|
|
|
}
|
|
|
|
|
2014-04-03 13:52:06 +02:00
|
|
|
sal_Bool SAL_CALL DocumentEvents::hasByName( const OUString& _Name ) throw (RuntimeException, std::exception)
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_pData->rMutex );
|
|
|
|
|
2009-04-24 18:34:24 +00:00
|
|
|
return m_pData->rEventsData.find( _Name ) != m_pData->rEventsData.end();
|
2008-10-16 06:57:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Type SAL_CALL DocumentEvents::getElementType( ) throw (RuntimeException, std::exception)
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
return ::cppu::UnoType< Sequence< PropertyValue > >::get();
|
|
|
|
}
|
|
|
|
|
2014-04-03 13:52:06 +02:00
|
|
|
sal_Bool SAL_CALL DocumentEvents::hasElements( ) throw (RuntimeException, std::exception)
|
2008-10-16 06:57:26 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_pData->rMutex );
|
2009-04-24 18:34:24 +00:00
|
|
|
return !m_pData->rEventsData.empty();
|
2008-10-16 06:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dbaccess
|
2013-08-17 23:43:14 +02:00
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|