Files
libreoffice/dbaccess/source/core/dataaccess/documentevents.cxx

225 lines
8.7 KiB
C++
Raw Normal View History

/* -*- 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.
*
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/.
*
2012-06-14 17:39:53 +01:00
* This file incorporates work covered by the following license notice:
*
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>
#include <osl/diagnose.h>
2008-10-16 06:57:26 +00:00
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/sequence.hxx>
2008-10-16 06:57:26 +00:00
#include <algorithm>
#include <functional>
#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;
// DocumentEvents_Data
struct DocumentEvents_Data
2008-10-16 06:57:26 +00:00
{
::cppu::OWeakObject& rParent;
::osl::Mutex& rMutex;
DocumentEventsData& rEventsData;
2008-10-16 06:57:26 +00:00
DocumentEvents_Data( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, DocumentEventsData& _rEventsData )
2008-10-16 06:57:26 +00:00
:rParent( _rParent )
,rMutex( _rMutex )
,rEventsData( _rEventsData )
2008-10-16 06:57:26 +00:00
{
}
DocumentEvents_Data(const DocumentEvents_Data&) = delete;
const DocumentEvents_Data& operator=(const DocumentEvents_Data&) = delete;
2008-10-16 06:57:26 +00:00
};
// helper
2008-10-16 06:57:26 +00:00
struct DocumentEventData
{
const sal_Char* pAsciiEventName;
bool bNeedsSyncNotify;
};
namespace
{
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 },
CWS-TOOLING: integrate CWS dba31h 2009-01-29 10:47:07 +0100 oj r267102 : decl OpCodeMap as friend 2009-01-26 09:41:21 +0100 fs r266905 : #i97137# 2009-01-26 09:10:39 +0100 fs r266903 : #i10000 2009-01-26 09:00:17 +0100 fs r266901 : re-enable user admin for MySQL native 2009-01-23 21:56:08 +0100 fs r266851 : #i97137# 2009-01-23 21:32:40 +0100 fs r266850 : #i97042# 2009-01-23 11:23:59 +0100 msc r266800 : #i98387# 2009-01-23 11:17:05 +0100 msc r266798 : #i98387# 2009-01-23 10:56:33 +0100 fs r266795 : for the moment, disable user administration for MySQL native 2009-01-21 15:08:54 +0100 fs r266672 : removed some advanced settings for MySQL native - letting the user control them does not make sense for this particular type 2009-01-21 13:55:13 +0100 oj r266668 : #i98317# wrong var set 2009-01-21 13:41:22 +0100 fs r266664 : #i98315# 2009-01-21 13:13:09 +0100 oj r266661 : #i97032# enable locking for OOo 2009-01-21 13:11:26 +0100 oj r266660 : #i97032# enable locking for OOo 2009-01-21 10:10:50 +0100 oj r266634 : #i98174# merge conflict resolved 2009-01-21 08:48:58 +0100 fs r266628 : CWS-TOOLING: rebase CWS dba31h to trunk@266428 (milestone: DEV300:m39) 2009-01-20 12:54:32 +0100 fs r266570 : #i98277# 2009-01-19 10:46:31 +0100 fs r266480 : #i97995# 2009-01-19 08:42:09 +0100 fs r266470 : #i97042# provided my mod@openoffice.org: support more SQL comment styles 2009-01-19 07:55:43 +0100 oj r266468 : #i98115# check function name as well 2009-01-16 10:21:28 +0100 oj r266404 : #i97861# remove invalid assertion 2009-01-16 10:18:31 +0100 oj r266403 : #i97861# ini var with false 2009-01-15 14:09:50 +0100 oj r266371 : #i97810# saveas fix 2009-01-15 11:54:18 +0100 oj r266360 : remove : from mysql 2009-01-15 11:07:46 +0100 oj r266355 : insert JNI fixes for method names 2009-01-15 10:54:44 +0100 oj r266351 : fix for parameter subst 2009-01-14 14:41:34 +0100 oj r266308 : parameter subst 2009-01-14 14:40:20 +0100 oj r266307 : add missing try catch 2009-01-14 14:38:34 +0100 oj r266306 : new service for parameter subst 2009-01-14 14:37:52 +0100 oj r266305 : missing types for hyper 2009-01-09 15:28:36 +0100 fs r266090 : #i97889# 2009-01-09 14:16:15 +0100 fs r266082 : #i97892# provided by npower: when reading the xlink:href attrib, use the graphic resolver only if appropriate 2009-01-08 21:31:21 +0100 fs r266041 : #i97346# 2009-01-08 14:51:56 +0100 fs r266012 : #i97871# showPreviewFor: bail out if preview is disabled
2009-02-17 15:39:54 +00:00
{ "OnSubComponentOpened", false },
{ "OnSubComponentClosed", false },
{ nullptr, false }
2008-10-16 06:57:26 +00:00
};
return s_aData;
}
}
// DocumentEvents
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 )
{
OUString sEventName = OUString::createFromAscii( pEventData->pAsciiEventName );
DocumentEventsData::const_iterator existingPos = m_pData->rEventsData.find( sEventName );
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();
}
bool DocumentEvents::needsSynchronousNotification( const OUString& _rEventName )
2008-10-16 06:57:26 +00:00
{
const DocumentEventData* pEventData = lcl_getDocumentEventData();
while ( pEventData->pAsciiEventName )
{
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;
}
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 );
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" ) )
{
OUString sEventType = aCheck.getOrDefault( "EventType", OUString() );
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" ) )
{
OUString sScript = aCheck.getOrDefault( "Script", OUString() );
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;
}
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 );
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;
}
Sequence< OUString > SAL_CALL DocumentEvents::getElementNames( ) throw (RuntimeException, std::exception)
2008-10-16 06:57:26 +00:00
{
::osl::MutexGuard aGuard( m_pData->rMutex );
return comphelper::mapKeysToSequence( m_pData->rEventsData );
2008-10-16 06:57:26 +00: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 );
return m_pData->rEventsData.find( _Name ) != m_pData->rEventsData.end();
2008-10-16 06:57:26 +00:00
}
Type SAL_CALL DocumentEvents::getElementType( ) throw (RuntimeException, std::exception)
2008-10-16 06:57:26 +00:00
{
return ::cppu::UnoType< Sequence< PropertyValue > >::get();
}
sal_Bool SAL_CALL DocumentEvents::hasElements( ) throw (RuntimeException, std::exception)
2008-10-16 06:57:26 +00:00
{
::osl::MutexGuard aGuard( m_pData->rMutex );
return !m_pData->rEventsData.empty();
2008-10-16 06:57:26 +00:00
}
} // namespace dbaccess
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */