tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / basic / source / classes / propacc.cxx
blob3f72c50f0683e335f642189f5c20b7e8dc177cca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <propacc.hxx>
23 #include <basic/sberrors.hxx>
24 #include <basic/sbstar.hxx>
25 #include <basic/sbuno.hxx>
26 #include <sbunoobj.hxx>
28 #include <comphelper/propertysetinfo.hxx>
29 #include <comphelper/sequence.hxx>
30 #include <o3tl/any.hxx>
32 #include <algorithm>
34 using com::sun::star::uno::Reference;
35 using namespace com::sun::star;
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star::lang;
38 using namespace com::sun::star::beans;
39 using namespace cppu;
41 static bool SbCompare_UString_PropertyValue_Impl(PropertyValue const & lhs, const OUString& rhs)
43 return lhs.Name.compareTo(rhs) < 0;
47 SbPropertyValues::SbPropertyValues() = default;
50 SbPropertyValues::~SbPropertyValues() = default;
52 Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo()
54 // create on demand?
55 if (!m_xInfo.is())
57 assert(m_aPropInfos.empty());
58 for (auto const& it : m_aPropVals)
59 m_aPropInfos.emplace_back(it.Name, it.Handle, cppu::UnoType<void>::get(), 0, 0);
60 m_xInfo.set(new ::comphelper::PropertySetInfo(m_aPropInfos));
62 return m_xInfo;
66 size_t SbPropertyValues::GetIndex_Impl( const OUString &rPropName ) const
68 SbPropertyValueArr_Impl::const_iterator it = std::lower_bound(
69 m_aPropVals.begin(), m_aPropVals.end(), rPropName,
70 SbCompare_UString_PropertyValue_Impl );
71 if (it == m_aPropVals.end() || it->Name != rPropName)
73 throw beans::UnknownPropertyException(
74 "Property not found: " + rPropName,
75 const_cast<SbPropertyValues&>(*this));
77 return it - m_aPropVals.begin();
81 void SbPropertyValues::setPropertyValue(
82 const OUString& aPropertyName,
83 const Any& aValue)
85 size_t const nIndex = GetIndex_Impl( aPropertyName );
86 PropertyValue & rPropVal = m_aPropVals[nIndex];
87 rPropVal.Value = aValue;
91 Any SbPropertyValues::getPropertyValue(
92 const OUString& aPropertyName)
94 size_t const nIndex = GetIndex_Impl( aPropertyName );
95 return m_aPropVals[nIndex].Value;
99 void SbPropertyValues::addPropertyChangeListener(
100 const OUString&,
101 const Reference< XPropertyChangeListener >& )
105 void SbPropertyValues::removePropertyChangeListener(
106 const OUString&,
107 const Reference< XPropertyChangeListener >& )
111 void SbPropertyValues::addVetoableChangeListener(
112 const OUString&,
113 const Reference< XVetoableChangeListener >& )
117 void SbPropertyValues::removeVetoableChangeListener(
118 const OUString&,
119 const Reference< XVetoableChangeListener >& )
123 Sequence< PropertyValue > SbPropertyValues::getPropertyValues()
125 return comphelper::containerToSequence(m_aPropVals);
129 void SbPropertyValues::setPropertyValues(const Sequence< PropertyValue >& rPropertyValues )
131 if (!m_aPropVals.empty())
132 throw IllegalArgumentException(u"m_aPropVals not empty"_ustr, getXWeak(), -1);
134 for (const PropertyValue& i : rPropertyValues)
136 m_aPropVals.push_back(i);
141 void RTL_Impl_CreatePropertySet( SbxArray& rPar )
143 // We need at least one parameter
144 // TODO: In this case < 2 is not correct ;-)
145 if (rPar.Count() < 2)
147 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
148 return;
151 // Get class names of struct
153 Reference xInterface(getXWeak(new SbPropertyValues()));
155 SbxVariableRef refVar = rPar.Get(0);
156 // Set PropertyValues
157 Any aArgAsAny = sbxToUnoValue(rPar.Get(1),
158 cppu::UnoType<Sequence<PropertyValue>>::get() );
159 auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
160 Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
161 xPropAcc->setPropertyValues( *pArg );
163 // Build a SbUnoObject and return it
164 auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", Any(xInterface) );
165 if( xUnoObj->getUnoAny().hasValue() )
167 // Return object
168 refVar->PutObject( xUnoObj.get() );
169 return;
172 // Object could not be created
173 refVar->PutObject( nullptr );
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */