Files
libreoffice/basic/source/classes/propacc.cxx

431 lines
14 KiB
C++
Raw Normal View History

2000-09-18 15:18:56 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 15:18:56 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 15:18:56 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 15:18:56 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 15:18:56 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 15:18:56 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_basic.hxx"
2000-09-18 15:18:56 +00:00
#include "propacc.hxx"
#include <tools/urlobj.hxx>
#include <tools/errcode.hxx>
#include <svl/svarray.hxx>
#include <basic/sbstar.hxx>
2000-09-18 15:18:56 +00:00
#include <sbunoobj.hxx>
using com::sun::star::uno::Reference;
2000-09-18 15:18:56 +00:00
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace cppu;
//========================================================================
// Declaration conversion from Sbx to UNO with known target type
2002-04-29 10:26:00 +00:00
Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, Property* pUnoProperty = NULL );
2000-09-18 15:18:56 +00:00
//========================================================================
#ifdef WNT
#define CDECL _cdecl
#endif
#if defined(UNX) || defined(OS2)
2000-09-18 15:18:56 +00:00
#define CDECL
#endif
int CDECL SbCompare_PropertyValues_Impl( const void *arg1, const void *arg2 )
{
return ((PropertyValue*)arg1)->Name.compareTo( ((PropertyValue*)arg2)->Name );
}
extern "C" int CDECL SbCompare_UString_PropertyValue_Impl( const void *arg1, const void *arg2 )
2000-09-18 15:18:56 +00:00
{
const ::rtl::OUString *pArg1 = (::rtl::OUString*) arg1;
2000-09-18 15:18:56 +00:00
const PropertyValue **pArg2 = (const PropertyValue**) arg2;
return pArg1->compareTo( (*pArg2)->Name );
}
int CDECL SbCompare_Properties_Impl( const void *arg1, const void *arg2 )
{
return ((Property*)arg1)->Name.compareTo( ((Property*)arg2)->Name );
}
extern "C" int CDECL SbCompare_UString_Property_Impl( const void *arg1, const void *arg2 )
2000-09-18 15:18:56 +00:00
{
const ::rtl::OUString *pArg1 = (::rtl::OUString*) arg1;
2000-09-18 15:18:56 +00:00
const Property *pArg2 = (Property*) arg2;
return pArg1->compareTo( pArg2->Name );
}
//----------------------------------------------------------------------------
SbPropertyValues::SbPropertyValues()
{
}
//----------------------------------------------------------------------------
SbPropertyValues::~SbPropertyValues()
{
_xInfo = Reference< XPropertySetInfo >();
for ( USHORT n = 0; n < _aPropVals.Count(); ++n )
delete _aPropVals.GetObject( n );
}
//----------------------------------------------------------------------------
Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo(void) throw( RuntimeException )
{
// create on demand?
if ( !_xInfo.is() )
{
SbPropertySetInfo *pInfo = new SbPropertySetInfo( _aPropVals );
((SbPropertyValues*)this)->_xInfo = (XPropertySetInfo*)pInfo;
}
return _xInfo;
}
//-------------------------------------------------------------------------
INT32 SbPropertyValues::GetIndex_Impl( const ::rtl::OUString &rPropName ) const
2000-09-18 15:18:56 +00:00
{
PropertyValue **ppPV;
ppPV = (PropertyValue **)
bsearch( &rPropName, _aPropVals.GetData(), _aPropVals.Count(),
sizeof( PropertyValue* ),
SbCompare_UString_PropertyValue_Impl );
return ppPV ? ( (ppPV-_aPropVals.GetData()) / sizeof(ppPV) ) : USHRT_MAX;
}
//----------------------------------------------------------------------------
void SbPropertyValues::setPropertyValue(
const ::rtl::OUString& aPropertyName,
2000-09-18 15:18:56 +00:00
const Any& aValue)
2001-09-12 10:55:40 +00:00
throw (::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::beans::PropertyVetoException,
::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException)
2000-09-18 15:18:56 +00:00
{
INT32 nIndex = GetIndex_Impl( aPropertyName );
PropertyValue *pPropVal = _aPropVals.GetObject(
sal::static_int_cast< USHORT >(nIndex));
2000-09-18 15:18:56 +00:00
pPropVal->Value = aValue;
}
//----------------------------------------------------------------------------
Any SbPropertyValues::getPropertyValue(
const ::rtl::OUString& aPropertyName)
2001-09-12 10:55:40 +00:00
throw(::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException)
2000-09-18 15:18:56 +00:00
{
INT32 nIndex = GetIndex_Impl( aPropertyName );
2000-09-18 15:18:56 +00:00
if ( nIndex != USHRT_MAX )
return _aPropVals.GetObject(
sal::static_int_cast< USHORT >(nIndex))->Value;
2000-09-18 15:18:56 +00:00
return Any();
}
//----------------------------------------------------------------------------
void SbPropertyValues::addPropertyChangeListener(
const ::rtl::OUString& aPropertyName,
2000-09-18 15:18:56 +00:00
const Reference< XPropertyChangeListener >& )
2001-09-12 10:55:40 +00:00
throw ()
2000-09-18 15:18:56 +00:00
{
(void)aPropertyName;
2000-09-18 15:18:56 +00:00
}
//----------------------------------------------------------------------------
void SbPropertyValues::removePropertyChangeListener(
const ::rtl::OUString& aPropertyName,
2000-09-18 15:18:56 +00:00
const Reference< XPropertyChangeListener >& )
2001-09-12 10:55:40 +00:00
throw ()
2000-09-18 15:18:56 +00:00
{
(void)aPropertyName;
2000-09-18 15:18:56 +00:00
}
//----------------------------------------------------------------------------
void SbPropertyValues::addVetoableChangeListener(
const ::rtl::OUString& aPropertyName,
2000-09-18 15:18:56 +00:00
const Reference< XVetoableChangeListener >& )
2001-09-12 10:55:40 +00:00
throw()
2000-09-18 15:18:56 +00:00
{
(void)aPropertyName;
2000-09-18 15:18:56 +00:00
}
//----------------------------------------------------------------------------
void SbPropertyValues::removeVetoableChangeListener(
const ::rtl::OUString& aPropertyName,
2000-09-18 15:18:56 +00:00
const Reference< XVetoableChangeListener >& )
2001-09-12 10:55:40 +00:00
throw()
2000-09-18 15:18:56 +00:00
{
(void)aPropertyName;
2000-09-18 15:18:56 +00:00
}
//----------------------------------------------------------------------------
2001-09-12 10:55:40 +00:00
Sequence< PropertyValue > SbPropertyValues::getPropertyValues(void) throw (::com::sun::star::uno::RuntimeException)
2000-09-18 15:18:56 +00:00
{
Sequence<PropertyValue> aRet( _aPropVals.Count());
for ( USHORT n = 0; n < _aPropVals.Count(); ++n )
aRet.getArray()[n] = *_aPropVals.GetObject(n);
return aRet;
}
//----------------------------------------------------------------------------
void SbPropertyValues::setPropertyValues(const Sequence< PropertyValue >& rPropertyValues )
2001-09-12 10:55:40 +00:00
throw (::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::beans::PropertyVetoException,
::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException)
2000-09-18 15:18:56 +00:00
{
if ( _aPropVals.Count() )
throw PropertyExistException();
const PropertyValue *pPropVals = rPropertyValues.getConstArray();
for ( sal_Int16 n = 0; n < rPropertyValues.getLength(); ++n )
{
PropertyValue *pPropVal = new PropertyValue(pPropVals[n]);
_aPropVals.Insert( pPropVal, n );
}
}
//============================================================================
//PropertySetInfoImpl
PropertySetInfoImpl::PropertySetInfoImpl()
{
}
INT32 PropertySetInfoImpl::GetIndex_Impl( const ::rtl::OUString &rPropName ) const
2000-09-18 15:18:56 +00:00
{
Property *pP;
pP = (Property*)
bsearch( &rPropName, _aProps.getConstArray(), _aProps.getLength(),
sizeof( Property ),
SbCompare_UString_Property_Impl );
return pP ? sal::static_int_cast<INT32>( (pP-_aProps.getConstArray()) / sizeof(pP) ) : -1;
2000-09-18 15:18:56 +00:00
}
2001-09-12 10:55:40 +00:00
Sequence< Property > PropertySetInfoImpl::getProperties(void) throw()
2000-09-18 15:18:56 +00:00
{
return _aProps;
}
Property PropertySetInfoImpl::getPropertyByName(const ::rtl::OUString& Name) throw( RuntimeException )
2000-09-18 15:18:56 +00:00
{
sal_Int32 nIndex = GetIndex_Impl( Name );
2000-09-18 15:18:56 +00:00
if( USHRT_MAX != nIndex )
return _aProps.getConstArray()[ nIndex ];
return Property();
}
sal_Bool PropertySetInfoImpl::hasPropertyByName(const ::rtl::OUString& Name) throw( RuntimeException )
2000-09-18 15:18:56 +00:00
{
sal_Int32 nIndex = GetIndex_Impl( Name );
2000-09-18 15:18:56 +00:00
return USHRT_MAX != nIndex;
}
//============================================================================
SbPropertySetInfo::SbPropertySetInfo()
{
}
//----------------------------------------------------------------------------
SbPropertySetInfo::SbPropertySetInfo( const SbPropertyValueArr_Impl &rPropVals )
{
aImpl._aProps.realloc( rPropVals.Count() );
for ( USHORT n = 0; n < rPropVals.Count(); ++n )
{
Property &rProp = aImpl._aProps.getArray()[n];
const PropertyValue &rPropVal = *rPropVals.GetObject(n);
rProp.Name = rPropVal.Name;
rProp.Handle = rPropVal.Handle;
rProp.Type = getCppuVoidType();
rProp.Attributes = 0;
}
}
//----------------------------------------------------------------------------
SbPropertySetInfo::~SbPropertySetInfo()
{
}
//-------------------------------------------------------------------------
Sequence< Property > SbPropertySetInfo::getProperties(void) throw( RuntimeException )
{
return aImpl.getProperties();
}
Property SbPropertySetInfo::getPropertyByName(const ::rtl::OUString& Name)
2000-09-18 15:18:56 +00:00
throw( RuntimeException )
{
return aImpl.getPropertyByName( Name );
}
BOOL SbPropertySetInfo::hasPropertyByName(const ::rtl::OUString& Name)
2000-09-18 15:18:56 +00:00
throw( RuntimeException )
{
return aImpl.hasPropertyByName( Name );
}
//----------------------------------------------------------------------------
SbPropertyContainer::SbPropertyContainer()
{
}
//----------------------------------------------------------------------------
SbPropertyContainer::~SbPropertyContainer()
{
}
//----------------------------------------------------------------------------
void SbPropertyContainer::addProperty(const ::rtl::OUString& Name,
2000-09-18 15:18:56 +00:00
INT16 Attributes,
const Any& DefaultValue)
throw( PropertyExistException, IllegalTypeException,
IllegalArgumentException, RuntimeException )
{
(void)Name;
(void)Attributes;
(void)DefaultValue;
2000-09-18 15:18:56 +00:00
}
//----------------------------------------------------------------------------
void SbPropertyContainer::removeProperty(const ::rtl::OUString& Name)
2000-09-18 15:18:56 +00:00
throw( UnknownPropertyException, RuntimeException )
{
(void)Name;
2000-09-18 15:18:56 +00:00
}
//----------------------------------------------------------------------------
// XPropertySetInfo
2001-09-12 10:55:40 +00:00
Sequence< Property > SbPropertyContainer::getProperties(void) throw ()
2000-09-18 15:18:56 +00:00
{
return aImpl.getProperties();
}
Property SbPropertyContainer::getPropertyByName(const ::rtl::OUString& Name)
2000-09-18 15:18:56 +00:00
throw( RuntimeException )
{
return aImpl.getPropertyByName( Name );
}
BOOL SbPropertyContainer::hasPropertyByName(const ::rtl::OUString& Name)
2000-09-18 15:18:56 +00:00
throw( RuntimeException )
{
return aImpl.hasPropertyByName( Name );
}
//----------------------------------------------------------------------------
Sequence< PropertyValue > SbPropertyContainer::getPropertyValues(void)
{
return Sequence<PropertyValue>();
}
//----------------------------------------------------------------------------
void SbPropertyContainer::setPropertyValues(const Sequence< PropertyValue >& PropertyValues_)
{
(void)PropertyValues_;
2000-09-18 15:18:56 +00:00
}
//----------------------------------------------------------------------------
void RTL_Impl_CreatePropertySet( StarBASIC* pBasic, SbxArray& rPar, BOOL bWrite )
{
(void)pBasic;
(void)bWrite;
// We need at least one parameter
// TODO: In this case < 2 is not correct ;-)
2000-09-18 15:18:56 +00:00
if ( rPar.Count() < 2 )
{
StarBASIC::Error( SbERR_BAD_ARGUMENT );
return;
}
// Get class names of struct
2000-09-18 15:18:56 +00:00
String aServiceName( RTL_CONSTASCII_USTRINGPARAM("stardiv.uno.beans.PropertySet") );
#if 0
// Service suchen und instanzieren
Reference< XMultiServiceFactory > xServiceManager = getProcessServiceFactory();
Reference< XInterface > xInterface;
if( xProv.is() )
xInterface = xProv->newInstance();
#else
Reference< XInterface > xInterface = (OWeakObject*) new SbPropertyValues();
#endif
SbxVariableRef refVar = rPar.Get(0);
if( xInterface.is() )
{
// Set PropertyValues
2000-09-18 15:18:56 +00:00
Any aArgAsAny = sbxToUnoValue( rPar.Get(1),
2002-04-29 10:26:00 +00:00
getCppuType( (Sequence<PropertyValue>*)0 ) );
2000-09-18 15:18:56 +00:00
Sequence<PropertyValue> *pArg =
(Sequence<PropertyValue>*) aArgAsAny.getValue();
Reference< XPropertyAccess > xPropAcc = Reference< XPropertyAccess >::query( xInterface );
xPropAcc->setPropertyValues( *pArg );
// Build a SbUnoObject and return it
2000-09-18 15:18:56 +00:00
Any aAny;
aAny <<= xInterface;
SbUnoObjectRef xUnoObj = new SbUnoObject( aServiceName, aAny );
if( xUnoObj->getUnoAny().getValueType().getTypeClass() != TypeClass_VOID )
{
// Return object
2000-09-18 15:18:56 +00:00
refVar->PutObject( (SbUnoObject*)xUnoObj );
return;
}
}
// Object could not be created
2000-09-18 15:18:56 +00:00
refVar->PutObject( NULL );
}