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
|
|
|
|
2017-10-09 17:04:39 +03:00
|
|
|
#include <propacc.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2019-02-28 04:42:42 +01:00
|
|
|
#include <basic/sberrors.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>
|
2015-09-11 23:42:10 +02:00
|
|
|
|
|
|
|
#include <comphelper/propertysetinfo.hxx>
|
2015-11-19 09:14:59 +02:00
|
|
|
#include <comphelper/sequence.hxx>
|
2016-06-14 16:02:55 +02:00
|
|
|
#include <o3tl/any.hxx>
|
2015-09-11 23:42:10 +02:00
|
|
|
|
2015-10-25 16:54:21 +01:00
|
|
|
#include <algorithm>
|
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;
|
|
|
|
|
2018-10-19 16:01:19 +02:00
|
|
|
static bool SbCompare_UString_PropertyValue_Impl(PropertyValue const & lhs, const OUString& rhs)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2018-10-19 16:01:19 +02:00
|
|
|
return lhs.Name.compareTo(rhs) < 0;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
2020-05-20 14:03:43 +02:00
|
|
|
SbPropertyValues::SbPropertyValues() = default;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2020-05-20 14:03:43 +02:00
|
|
|
SbPropertyValues::~SbPropertyValues() = default;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo()
|
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
|
|
|
{
|
2015-09-11 23:42:10 +02:00
|
|
|
uno::Sequence<beans::Property> props(m_aPropVals.size());
|
|
|
|
for (size_t n = 0; n < m_aPropVals.size(); ++n)
|
|
|
|
{
|
|
|
|
Property &rProp = props.getArray()[n];
|
|
|
|
const PropertyValue &rPropVal = m_aPropVals[n];
|
|
|
|
rProp.Name = rPropVal.Name;
|
|
|
|
rProp.Handle = rPropVal.Handle;
|
|
|
|
rProp.Type = cppu::UnoType<void>::get();
|
|
|
|
rProp.Attributes = 0;
|
|
|
|
}
|
|
|
|
m_xInfo.set(new ::comphelper::PropertySetInfo(props));
|
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
|
|
|
|
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,
|
2018-10-19 16:01:19 +02:00
|
|
|
SbCompare_UString_PropertyValue_Impl );
|
2019-02-18 10:10:07 +02:00
|
|
|
if (it == m_aPropVals.end() || it->Name != rPropName)
|
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)
|
|
|
|
{
|
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)
|
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(
|
2017-07-02 22:35:38 +02:00
|
|
|
const OUString&,
|
2000-09-18 15:18:56 +00:00
|
|
|
const Reference< XPropertyChangeListener >& )
|
2017-07-02 22:35:38 +02:00
|
|
|
{}
|
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(
|
2017-07-02 22:35:38 +02:00
|
|
|
const OUString&,
|
2000-09-18 15:18:56 +00:00
|
|
|
const Reference< XPropertyChangeListener >& )
|
2017-07-02 22:35:38 +02:00
|
|
|
{}
|
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(
|
2017-07-02 22:35:38 +02:00
|
|
|
const OUString&,
|
2000-09-18 15:18:56 +00:00
|
|
|
const Reference< XVetoableChangeListener >& )
|
2017-07-02 22:35:38 +02:00
|
|
|
{}
|
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(
|
2017-07-02 22:35:38 +02:00
|
|
|
const OUString&,
|
2000-09-18 15:18:56 +00:00
|
|
|
const Reference< XVetoableChangeListener >& )
|
2017-07-02 22:35:38 +02:00
|
|
|
{}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
Sequence< PropertyValue > SbPropertyValues::getPropertyValues()
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2015-11-19 09:14:59 +02:00
|
|
|
return comphelper::containerToSequence(m_aPropVals);
|
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::setPropertyValues(const Sequence< PropertyValue >& rPropertyValues )
|
|
|
|
{
|
2015-10-25 16:54:21 +01:00
|
|
|
if (!m_aPropVals.empty())
|
2014-05-28 12:20:55 +01:00
|
|
|
throw IllegalArgumentException();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2020-05-15 09:56:35 +02:00
|
|
|
for (const PropertyValue& i : rPropertyValues)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2020-05-15 09:56:35 +02:00
|
|
|
m_aPropVals.push_back(i);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:41:32 +01:00
|
|
|
|
2017-07-02 22:35:38 +02:00
|
|
|
void RTL_Impl_CreatePropertySet( SbxArray& rPar )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2009-04-25 00:18:20 +00:00
|
|
|
// We need at least one parameter
|
|
|
|
// TODO: In this case < 2 is not correct ;-)
|
2019-12-09 13:06:03 +03:00
|
|
|
if ( rPar.Count32() < 2 )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2015-07-27 13:04:00 +02:00
|
|
|
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
|
2000-09-18 15:18:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Get class names of struct
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2015-06-08 16:23:17 +02:00
|
|
|
Reference< XInterface > xInterface = static_cast<OWeakObject*>(new SbPropertyValues());
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2019-12-09 13:06:03 +03:00
|
|
|
SbxVariableRef refVar = rPar.Get32(0);
|
2000-09-18 15:18:56 +00:00
|
|
|
if( xInterface.is() )
|
|
|
|
{
|
2009-04-25 00:18:20 +00:00
|
|
|
// Set PropertyValues
|
2019-12-09 13:06:03 +03:00
|
|
|
Any aArgAsAny = sbxToUnoValue( rPar.Get32(1),
|
2015-04-01 08:35:28 +02:00
|
|
|
cppu::UnoType<Sequence<PropertyValue>>::get() );
|
2016-06-14 16:02:55 +02:00
|
|
|
auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
|
2015-10-29 15:48:45 +02:00
|
|
|
Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
|
2000-09-18 15:18:56 +00:00
|
|
|
xPropAcc->setPropertyValues( *pArg );
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Build a SbUnoObject and return it
|
2016-05-03 08:39:03 +02:00
|
|
|
auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", Any(xInterface) );
|
2016-06-14 16:02:55 +02:00
|
|
|
if( xUnoObj->getUnoAny().hasValue() )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2009-04-25 00:18:20 +00:00
|
|
|
// Return object
|
2016-02-21 17:51:28 +01:00
|
|
|
refVar->PutObject( xUnoObj.get() );
|
2000-09-18 15:18:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Object could not be created
|
2015-11-10 10:10:36 +01:00
|
|
|
refVar->PutObject( nullptr );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|