summaryrefslogtreecommitdiffstats
path: root/basic/source/classes/propacc.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /basic/source/classes/propacc.cxx
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--basic/source/classes/propacc.cxx191
1 files changed, 191 insertions, 0 deletions
diff --git a/basic/source/classes/propacc.cxx b/basic/source/classes/propacc.cxx
new file mode 100644
index 000000000..45d13ffbb
--- /dev/null
+++ b/basic/source/classes/propacc.cxx
@@ -0,0 +1,191 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 .
+ */
+
+
+#include <propacc.hxx>
+
+#include <basic/sberrors.hxx>
+#include <basic/sbstar.hxx>
+#include <basic/sbuno.hxx>
+#include <sbunoobj.hxx>
+
+#include <comphelper/propertysetinfo.hxx>
+#include <comphelper/sequence.hxx>
+#include <o3tl/any.hxx>
+
+#include <algorithm>
+
+using com::sun::star::uno::Reference;
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::beans;
+using namespace cppu;
+
+static bool SbCompare_UString_PropertyValue_Impl(PropertyValue const & lhs, const OUString& rhs)
+{
+ return lhs.Name.compareTo(rhs) < 0;
+}
+
+
+SbPropertyValues::SbPropertyValues()
+{
+}
+
+
+SbPropertyValues::~SbPropertyValues()
+{
+ m_xInfo.clear();
+}
+
+Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo()
+{
+ // create on demand?
+ if (!m_xInfo.is())
+ {
+ 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));
+ }
+ return m_xInfo;
+}
+
+
+size_t SbPropertyValues::GetIndex_Impl( const OUString &rPropName ) const
+{
+ SbPropertyValueArr_Impl::const_iterator it = std::lower_bound(
+ m_aPropVals.begin(), m_aPropVals.end(), rPropName,
+ SbCompare_UString_PropertyValue_Impl );
+ if (it == m_aPropVals.end() || it->Name != rPropName)
+ {
+ throw beans::UnknownPropertyException(
+ "Property not found: " + rPropName,
+ const_cast<SbPropertyValues&>(*this));
+ }
+ return it - m_aPropVals.begin();
+}
+
+
+void SbPropertyValues::setPropertyValue(
+ const OUString& aPropertyName,
+ const Any& aValue)
+{
+ size_t const nIndex = GetIndex_Impl( aPropertyName );
+ PropertyValue & rPropVal = m_aPropVals[nIndex];
+ rPropVal.Value = aValue;
+}
+
+
+Any SbPropertyValues::getPropertyValue(
+ const OUString& aPropertyName)
+{
+ size_t const nIndex = GetIndex_Impl( aPropertyName );
+ return m_aPropVals[nIndex].Value;
+}
+
+
+void SbPropertyValues::addPropertyChangeListener(
+ const OUString&,
+ const Reference< XPropertyChangeListener >& )
+{}
+
+
+void SbPropertyValues::removePropertyChangeListener(
+ const OUString&,
+ const Reference< XPropertyChangeListener >& )
+{}
+
+
+void SbPropertyValues::addVetoableChangeListener(
+ const OUString&,
+ const Reference< XVetoableChangeListener >& )
+{}
+
+
+void SbPropertyValues::removeVetoableChangeListener(
+ const OUString&,
+ const Reference< XVetoableChangeListener >& )
+{}
+
+
+Sequence< PropertyValue > SbPropertyValues::getPropertyValues()
+{
+ return comphelper::containerToSequence(m_aPropVals);
+}
+
+
+void SbPropertyValues::setPropertyValues(const Sequence< PropertyValue >& rPropertyValues )
+{
+ if (!m_aPropVals.empty())
+ throw IllegalArgumentException();
+
+ for (const PropertyValue& i : rPropertyValues)
+ {
+ m_aPropVals.push_back(i);
+ }
+}
+
+
+void RTL_Impl_CreatePropertySet( SbxArray& rPar )
+{
+ // We need at least one parameter
+ // TODO: In this case < 2 is not correct ;-)
+ if ( rPar.Count32() < 2 )
+ {
+ StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return;
+ }
+
+ // Get class names of struct
+
+ Reference< XInterface > xInterface = static_cast<OWeakObject*>(new SbPropertyValues());
+
+ SbxVariableRef refVar = rPar.Get32(0);
+ if( xInterface.is() )
+ {
+ // Set PropertyValues
+ Any aArgAsAny = sbxToUnoValue( rPar.Get32(1),
+ cppu::UnoType<Sequence<PropertyValue>>::get() );
+ auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
+ Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
+ xPropAcc->setPropertyValues( *pArg );
+
+ // Build a SbUnoObject and return it
+ auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", Any(xInterface) );
+ if( xUnoObj->getUnoAny().hasValue() )
+ {
+ // Return object
+ refVar->PutObject( xUnoObj.get() );
+ return;
+ }
+ }
+
+ // Object could not be created
+ refVar->PutObject( nullptr );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */