android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbavariables.cxx
blob6505eb23e049aab91c15a401b7fd5a6d9c95d77d
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 .
19 #include "vbavariables.hxx"
20 #include "vbavariable.hxx"
21 #include <com/sun/star/beans/XPropertyContainer.hpp>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
24 using namespace ::ooo::vba;
25 using namespace ::com::sun::star;
27 /// @throws uno::RuntimeException
28 static uno::Reference< container::XIndexAccess > createVariablesAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< beans::XPropertyAccess >& xUserDefined )
30 // FIXME: the performance is poor?
31 XNamedObjectCollectionHelper< word::XVariable >::XNamedVec aVariables;
32 const uno::Sequence< beans::PropertyValue > props = xUserDefined->getPropertyValues();
33 sal_Int32 nCount = props.getLength();
34 aVariables.reserve( nCount );
35 std::transform(props.begin(), props.end(), std::back_inserter(aVariables),
36 [&xParent, &xContext, &xUserDefined](const beans::PropertyValue& rProp) -> uno::Reference< word::XVariable > {
37 return uno::Reference< word::XVariable > ( new SwVbaVariable( xParent, xContext, xUserDefined, rProp.Name ) ); });
39 uno::Reference< container::XIndexAccess > xVariables( new XNamedObjectCollectionHelper< word::XVariable >( std::move(aVariables) ) );
40 return xVariables;
43 SwVbaVariables::SwVbaVariables( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertyAccess >& rUserDefined ): SwVbaVariables_BASE( xParent, xContext, createVariablesAccess( xParent, xContext, rUserDefined ) ), mxUserDefined( rUserDefined )
46 // XEnumerationAccess
47 uno::Type
48 SwVbaVariables::getElementType()
50 return cppu::UnoType<word::XVariable>::get();
52 uno::Reference< container::XEnumeration >
53 SwVbaVariables::createEnumeration()
55 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
56 return xEnumerationAccess->createEnumeration();
59 uno::Any
60 SwVbaVariables::createCollectionObject( const css::uno::Any& aSource )
62 return aSource;
65 uno::Any SAL_CALL
66 SwVbaVariables::Add( const OUString& rName, const uno::Any& rValue )
68 uno::Any aValue;
69 if( rValue.hasValue() )
70 aValue = rValue;
71 else
72 aValue <<= OUString();
73 uno::Reference< beans::XPropertyContainer > xPropertyContainer( mxUserDefined, uno::UNO_QUERY_THROW );
74 xPropertyContainer->addProperty( rName, beans::PropertyAttribute::MAYBEVOID | beans::PropertyAttribute::REMOVABLE, aValue );
76 return uno::Any( uno::Reference< word::XVariable >( new SwVbaVariable( getParent(), mxContext, mxUserDefined, rName ) ) );
79 OUString
80 SwVbaVariables::getServiceImplName()
82 return "SwVbaVariables";
85 css::uno::Sequence<OUString>
86 SwVbaVariables::getServiceNames()
88 static uno::Sequence< OUString > const sNames
90 "ooo.vba.word.Variables"
92 return sNames;
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */