LibreOffice Module sw (master) 1
vbavariables.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#include "vbavariables.hxx"
20#include "vbavariable.hxx"
21#include <com/sun/star/beans/XPropertyContainer.hpp>
22#include <com/sun/star/beans/PropertyAttribute.hpp>
23
24using namespace ::ooo::vba;
25using namespace ::com::sun::star;
26
28static uno::Reference< container::XIndexAccess > createVariablesAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< beans::XPropertyAccess >& xUserDefined )
29{
30 // FIXME: the performance is poor?
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 ) ); });
38
39 uno::Reference< container::XIndexAccess > xVariables( new XNamedObjectCollectionHelper< word::XVariable >( std::move(aVariables) ) );
40 return xVariables;
41}
42
43SwVbaVariables::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 )
44{
45}
46// XEnumerationAccess
49{
51}
52uno::Reference< container::XEnumeration >
54{
55 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
56 return xEnumerationAccess->createEnumeration();
57}
58
60SwVbaVariables::createCollectionObject( const css::uno::Any& aSource )
61{
62 return aSource;
63}
64
65uno::Any SAL_CALL
66SwVbaVariables::Add( const OUString& rName, const uno::Any& rValue )
67{
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 );
75
76 return uno::Any( uno::Reference< word::XVariable >( new SwVbaVariable( getParent(), mxContext, mxUserDefined, rName ) ) );
77}
78
79OUString
81{
82 return "SwVbaVariables";
83}
84
85css::uno::Sequence<OUString>
87{
88 static uno::Sequence< OUString > const sNames
89 {
90 "ooo.vba.word.Variables"
91 };
92 return sNames;
93}
94
95/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
css::uno::Reference< css::beans::XPropertyAccess > mxUserDefined
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any SAL_CALL Add(const OUString &rName, const css::uno::Any &rValue) override
SwVbaVariables(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::beans::XPropertyAccess > &rUserDefined)
virtual OUString getServiceImplName() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
css::uno::Type const & get()
int nCount
dictionary props
bool hasValue()
static uno::Reference< container::XIndexAccess > createVariablesAccess(const uno::Reference< XHelperInterface > &xParent, const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< beans::XPropertyAccess > &xUserDefined)