LibreOffice Module basic (master) 1
propacc.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <propacc.hxx>
22
23#include <basic/sberrors.hxx>
24#include <basic/sbstar.hxx>
25#include <basic/sbuno.hxx>
26#include <sbunoobj.hxx>
27
30#include <o3tl/any.hxx>
31
32#include <algorithm>
33
35using namespace com::sun::star;
36using namespace com::sun::star::uno;
37using namespace com::sun::star::lang;
38using namespace com::sun::star::beans;
39using namespace cppu;
40
41static bool SbCompare_UString_PropertyValue_Impl(PropertyValue const & lhs, const OUString& rhs)
42{
43 return lhs.Name.compareTo(rhs) < 0;
44}
45
46
48
49
51
53{
54 // create on demand?
55 if (!m_xInfo.is())
56 {
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));
61 }
62 return m_xInfo;
63}
64
65
66size_t SbPropertyValues::GetIndex_Impl( const OUString &rPropName ) const
67{
68 SbPropertyValueArr_Impl::const_iterator it = std::lower_bound(
69 m_aPropVals.begin(), m_aPropVals.end(), rPropName,
71 if (it == m_aPropVals.end() || it->Name != rPropName)
72 {
73 throw beans::UnknownPropertyException(
74 "Property not found: " + rPropName,
75 const_cast<SbPropertyValues&>(*this));
76 }
77 return it - m_aPropVals.begin();
78}
79
80
82 const OUString& aPropertyName,
83 const Any& aValue)
84{
85 size_t const nIndex = GetIndex_Impl( aPropertyName );
86 PropertyValue & rPropVal = m_aPropVals[nIndex];
87 rPropVal.Value = aValue;
88}
89
90
92 const OUString& aPropertyName)
93{
94 size_t const nIndex = GetIndex_Impl( aPropertyName );
95 return m_aPropVals[nIndex].Value;
96}
97
98
100 const OUString&,
102{}
103
104
106 const OUString&,
108{}
109
110
112 const OUString&,
114{}
115
116
118 const OUString&,
120{}
121
122
124{
126}
127
128
130{
131 if (!m_aPropVals.empty())
132 throw IllegalArgumentException("m_aPropVals not empty", getXWeak(), -1);
133
134 for (const PropertyValue& i : rPropertyValues)
135 {
136 m_aPropVals.push_back(i);
137 }
138}
139
140
142{
143 // We need at least one parameter
144 // TODO: In this case < 2 is not correct ;-)
145 if (rPar.Count() < 2)
146 {
148 return;
149 }
150
151 // Get class names of struct
152
153 Reference xInterface(getXWeak(new SbPropertyValues()));
154
155 SbxVariableRef refVar = rPar.Get(0);
156 // Set PropertyValues
157 Any aArgAsAny = sbxToUnoValue(rPar.Get(1),
159 auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
160 Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
161 xPropAcc->setPropertyValues( *pArg );
162
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() )
166 {
167 // Return object
168 refVar->PutObject( xUnoObj.get() );
169 return;
170 }
171
172 // Object could not be created
173 refVar->PutObject( nullptr );
174}
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t GetIndex_Impl(const OUString &rPropName) const
Definition: propacc.cxx:66
css::uno::Reference< css::beans::XPropertySetInfo > m_xInfo
Definition: propacc.hxx:41
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &) override
Definition: propacc.cxx:105
virtual void SAL_CALL removeVetoableChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &) override
Definition: propacc.cxx:117
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues() override
Definition: propacc.cxx:123
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &PropertyValues_) override
Definition: propacc.cxx:129
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: propacc.cxx:81
SbPropertyValueArr_Impl m_aPropVals
Definition: propacc.hxx:39
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &) override
Definition: propacc.cxx:99
virtual ~SbPropertyValues() override
virtual void SAL_CALL addVetoableChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &) override
Definition: propacc.cxx:111
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: propacc.cxx:91
SbPropertyInfoArr_Impl m_aPropInfos
Definition: propacc.hxx:40
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: propacc.cxx:52
Definition: sbx.hxx:95
sal_uInt32 Count() const
Definition: sbxarray.cxx:87
SbxVariable * Get(sal_uInt32)
Definition: sbxarray.cxx:108
static void Error(ErrCode, const OUString &rMsg={})
Definition: sb.cxx:1683
sal_Int32 nIndex
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
int i
static bool SbCompare_UString_PropertyValue_Impl(PropertyValue const &lhs, const OUString &rhs)
Definition: propacc.cxx:41
void RTL_Impl_CreatePropertySet(SbxArray &rPar)
Definition: propacc.cxx:141
#define ERRCODE_BASIC_BAD_ARGUMENT
Definition: sberrors.hxx:26
Any sbxToUnoValue(const SbxValue *pVar)
Definition: sbunoobj.cxx:1137