2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-17 12:30:48 +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 .
|
|
|
|
*/
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2006-09-17 08:59:51 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "propacc.hxx"
|
|
|
|
|
2007-06-27 13:18:20 +00:00
|
|
|
#include <basic/sbstar.hxx>
|
2013-09-09 20:00:48 +02:00
|
|
|
#include <basic/sbuno.hxx>
|
2013-11-01 08:54:20 +00:00
|
|
|
#include <sbunoobj.hxx>
|
|
|
|
#include <limits.h>
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2007-06-05 14:10:29 +00:00
|
|
|
using com::sun::star::uno::Reference;
|
2012-06-12 22:25:23 +02:00
|
|
|
using namespace com::sun::star;
|
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;
|
|
|
|
|
2012-06-09 18:07:07 +02:00
|
|
|
struct SbCompare_UString_PropertyValue_Impl
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-12-30 13:07:28 -02:00
|
|
|
bool operator() (PropertyValue const & lhs, const OUString& rhs)
|
2012-06-09 18:07:07 +02:00
|
|
|
{
|
2012-06-12 22:43:05 +02:00
|
|
|
return lhs.Name.compareTo(rhs) < 0;
|
2012-06-09 18:07:07 +02:00
|
|
|
}
|
|
|
|
};
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2013-10-12 09:45:17 +03:00
|
|
|
extern "C" int SAL_CALL SbCompare_UString_Property_Impl( const void *arg1, const void *arg2 )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2015-03-28 18:58:08 +01:00
|
|
|
const OUString *pArg1 = static_cast<OUString const *>(arg1);
|
|
|
|
const Property *pArg2 = static_cast<Property const *>(arg2);
|
2000-09-18 15:18:56 +00:00
|
|
|
return pArg1->compareTo( pArg2->Name );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
SbPropertyValues::SbPropertyValues()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
SbPropertyValues::~SbPropertyValues()
|
|
|
|
{
|
2013-06-04 17:16:58 +02:00
|
|
|
m_xInfo.clear();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo(void) throw( RuntimeException, std::exception )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
// create on demand?
|
2012-06-12 22:30:01 +02:00
|
|
|
if (!m_xInfo.is())
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-06-12 22:30:01 +02:00
|
|
|
SbPropertySetInfo *pInfo = new SbPropertySetInfo( m_aPropVals );
|
|
|
|
m_xInfo.set(pInfo);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2012-06-12 22:30:01 +02:00
|
|
|
return m_xInfo;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2012-12-30 13:07:28 -02:00
|
|
|
size_t SbPropertyValues::GetIndex_Impl( const OUString &rPropName ) const
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-06-09 18:07:07 +02:00
|
|
|
SbPropertyValueArr_Impl::const_iterator it = std::lower_bound(
|
2012-06-12 22:30:01 +02:00
|
|
|
m_aPropVals.begin(), m_aPropVals.end(), rPropName,
|
2012-06-09 18:07:07 +02:00
|
|
|
SbCompare_UString_PropertyValue_Impl() );
|
2012-06-12 22:30:01 +02:00
|
|
|
if (it == m_aPropVals.end())
|
2012-06-12 22:25:23 +02:00
|
|
|
{
|
|
|
|
throw beans::UnknownPropertyException(
|
|
|
|
"Property not found: " + rPropName,
|
|
|
|
const_cast<SbPropertyValues&>(*this));
|
|
|
|
}
|
2012-06-12 22:30:01 +02:00
|
|
|
return it - m_aPropVals.begin();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
void SbPropertyValues::setPropertyValue(
|
2012-12-30 13:07:28 -02:00
|
|
|
const 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,
|
2014-02-25 21:31:58 +01:00
|
|
|
::com::sun::star::uno::RuntimeException, std::exception)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-06-12 22:25:23 +02:00
|
|
|
size_t const nIndex = GetIndex_Impl( aPropertyName );
|
2012-06-12 22:43:05 +02:00
|
|
|
PropertyValue & rPropVal = m_aPropVals[nIndex];
|
|
|
|
rPropVal.Value = aValue;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
Any SbPropertyValues::getPropertyValue(
|
2012-12-30 13:07:28 -02:00
|
|
|
const OUString& aPropertyName)
|
2001-09-12 10:55:40 +00:00
|
|
|
throw(::com::sun::star::beans::UnknownPropertyException,
|
|
|
|
::com::sun::star::lang::WrappedTargetException,
|
2014-02-25 21:31:58 +01:00
|
|
|
::com::sun::star::uno::RuntimeException, std::exception)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-06-12 22:25:23 +02:00
|
|
|
size_t const nIndex = GetIndex_Impl( aPropertyName );
|
2012-06-12 22:43:05 +02:00
|
|
|
return m_aPropVals[nIndex].Value;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
void SbPropertyValues::addPropertyChangeListener(
|
2012-12-30 13:07:28 -02:00
|
|
|
const OUString& aPropertyName,
|
2000-09-18 15:18:56 +00:00
|
|
|
const Reference< XPropertyChangeListener >& )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw (std::exception)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-06-19 16:39:43 +00:00
|
|
|
(void)aPropertyName;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
void SbPropertyValues::removePropertyChangeListener(
|
2012-12-30 13:07:28 -02:00
|
|
|
const OUString& aPropertyName,
|
2000-09-18 15:18:56 +00:00
|
|
|
const Reference< XPropertyChangeListener >& )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw (std::exception)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-06-19 16:39:43 +00:00
|
|
|
(void)aPropertyName;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
void SbPropertyValues::addVetoableChangeListener(
|
2012-12-30 13:07:28 -02:00
|
|
|
const OUString& aPropertyName,
|
2000-09-18 15:18:56 +00:00
|
|
|
const Reference< XVetoableChangeListener >& )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(std::exception)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-06-19 16:39:43 +00:00
|
|
|
(void)aPropertyName;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
void SbPropertyValues::removeVetoableChangeListener(
|
2012-12-30 13:07:28 -02:00
|
|
|
const OUString& aPropertyName,
|
2000-09-18 15:18:56 +00:00
|
|
|
const Reference< XVetoableChangeListener >& )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(std::exception)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-06-19 16:39:43 +00:00
|
|
|
(void)aPropertyName;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Sequence< PropertyValue > SbPropertyValues::getPropertyValues(void) throw (::com::sun::star::uno::RuntimeException, std::exception)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-06-12 22:30:01 +02:00
|
|
|
Sequence<PropertyValue> aRet( m_aPropVals.size() );
|
2012-06-12 22:43:05 +02:00
|
|
|
for (size_t n = 0; n < m_aPropVals.size(); ++n)
|
|
|
|
aRet.getArray()[n] = m_aPropVals[n];
|
2000-09-18 15:18:56 +00:00
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
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,
|
2014-02-25 21:31:58 +01:00
|
|
|
::com::sun::star::uno::RuntimeException, std::exception)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-06-12 22:30:01 +02:00
|
|
|
if ( !m_aPropVals.empty() )
|
2014-05-28 12:20:55 +01:00
|
|
|
throw IllegalArgumentException();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
const PropertyValue *pPropVals = rPropertyValues.getConstArray();
|
2012-06-12 22:43:05 +02:00
|
|
|
for (sal_Int32 n = 0; n < rPropertyValues.getLength(); ++n)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
PropertyValue *pPropVal = new PropertyValue(pPropVals[n]);
|
2012-06-12 22:30:01 +02:00
|
|
|
m_aPropVals.push_back( pPropVal );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:41:32 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
//PropertySetInfoImpl
|
|
|
|
|
|
|
|
PropertySetInfoImpl::PropertySetInfoImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-30 13:07:28 -02:00
|
|
|
sal_Int32 PropertySetInfoImpl::GetIndex_Impl( const OUString &rPropName ) const
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
Property *pP;
|
2015-03-28 18:58:08 +01:00
|
|
|
pP = static_cast<Property*>(
|
2000-09-18 15:18:56 +00:00
|
|
|
bsearch( &rPropName, _aProps.getConstArray(), _aProps.getLength(),
|
|
|
|
sizeof( Property ),
|
2015-03-28 18:58:08 +01:00
|
|
|
SbCompare_UString_Property_Impl ));
|
2011-05-18 13:57:48 +02:00
|
|
|
return pP ? sal::static_int_cast<sal_Int32>( pP - _aProps.getConstArray() ) : -1;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-30 13:07:28 -02:00
|
|
|
Property PropertySetInfoImpl::getPropertyByName(const OUString& Name) throw( RuntimeException )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-10-12 13:25:24 +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();
|
|
|
|
}
|
|
|
|
|
2014-04-04 16:52:44 +02:00
|
|
|
bool PropertySetInfoImpl::hasPropertyByName(const OUString& Name) throw( RuntimeException )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-10-12 13:25:24 +00:00
|
|
|
sal_Int32 nIndex = GetIndex_Impl( Name );
|
2000-09-18 15:18:56 +00:00
|
|
|
return USHRT_MAX != nIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
SbPropertySetInfo::SbPropertySetInfo( const SbPropertyValueArr_Impl &rPropVals )
|
|
|
|
{
|
2012-06-09 18:07:07 +02:00
|
|
|
aImpl._aProps.realloc( rPropVals.size() );
|
|
|
|
for ( sal_uInt16 n = 0; n < rPropVals.size(); ++n )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
Property &rProp = aImpl._aProps.getArray()[n];
|
2012-06-12 22:43:05 +02:00
|
|
|
const PropertyValue &rPropVal = rPropVals[n];
|
2000-09-18 15:18:56 +00:00
|
|
|
rProp.Name = rPropVal.Name;
|
|
|
|
rProp.Handle = rPropVal.Handle;
|
2015-04-01 08:35:28 +02:00
|
|
|
rProp.Type = cppu::UnoType<cppu::UnoVoidType>::get();
|
2000-09-18 15:18:56 +00:00
|
|
|
rProp.Attributes = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
SbPropertySetInfo::~SbPropertySetInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Sequence< Property > SbPropertySetInfo::getProperties(void) throw( RuntimeException, std::exception )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
return aImpl.getProperties();
|
|
|
|
}
|
|
|
|
|
2012-12-30 13:07:28 -02:00
|
|
|
Property SbPropertySetInfo::getPropertyByName(const OUString& Name)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( RuntimeException, std::exception )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
return aImpl.getPropertyByName( Name );
|
|
|
|
}
|
|
|
|
|
2012-12-30 13:07:28 -02:00
|
|
|
sal_Bool SbPropertySetInfo::hasPropertyByName(const OUString& Name)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( RuntimeException, std::exception )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
return aImpl.hasPropertyByName( Name );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2014-04-04 16:52:44 +02:00
|
|
|
void RTL_Impl_CreatePropertySet( StarBASIC* pBasic, SbxArray& rPar, bool bWrite )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-06-19 16:39:43 +00:00
|
|
|
(void)pBasic;
|
|
|
|
(void)bWrite;
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Get class names of struct
|
2012-12-30 13:07:28 -02:00
|
|
|
OUString aServiceName( "stardiv.uno.beans.PropertySet");
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
Reference< XInterface > xInterface = (OWeakObject*) new SbPropertyValues();
|
|
|
|
|
|
|
|
SbxVariableRef refVar = rPar.Get(0);
|
|
|
|
if( xInterface.is() )
|
|
|
|
{
|
2009-04-25 00:18:20 +00:00
|
|
|
// Set PropertyValues
|
2000-09-18 15:18:56 +00:00
|
|
|
Any aArgAsAny = sbxToUnoValue( rPar.Get(1),
|
2015-04-01 08:35:28 +02:00
|
|
|
cppu::UnoType<Sequence<PropertyValue>>::get() );
|
2015-03-28 18:58:08 +01:00
|
|
|
Sequence<PropertyValue> const *pArg =
|
|
|
|
static_cast<Sequence<PropertyValue> const *>(aArgAsAny.getValue());
|
2000-09-18 15:18:56 +00:00
|
|
|
Reference< XPropertyAccess > xPropAcc = Reference< XPropertyAccess >::query( xInterface );
|
|
|
|
xPropAcc->setPropertyValues( *pArg );
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// 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 )
|
|
|
|
{
|
2009-04-25 00:18:20 +00:00
|
|
|
// Return object
|
2000-09-18 15:18:56 +00:00
|
|
|
refVar->PutObject( (SbUnoObject*)xUnoObj );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Object could not be created
|
2000-09-18 15:18:56 +00:00
|
|
|
refVar->PutObject( NULL );
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|