LibreOffice Module sw (master) 1
vbavariable.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 "vbavariable.hxx"
20#include <com/sun/star/beans/XPropertySet.hpp>
21#include <com/sun/star/beans/PropertyValue.hpp>
22#include <utility>
23
24using namespace ::ooo::vba;
25using namespace ::com::sun::star;
26
27SwVbaVariable::SwVbaVariable( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,
28 uno::Reference< beans::XPropertyAccess > xUserDefined, OUString aVariableName ) :
29 SwVbaVariable_BASE( rParent, rContext ), mxUserDefined(std::move( xUserDefined )), maVariableName(std::move( aVariableName ))
30{
31}
32
34{
35}
36
37OUString SAL_CALL
39{
40 return maVariableName;
41}
42
43void SAL_CALL
44SwVbaVariable::setName( const OUString& )
45{
46 throw uno::RuntimeException(" Fail to set name" );
47}
48
49uno::Any SAL_CALL
51{
52 uno::Reference< beans::XPropertySet > xProp( mxUserDefined, uno::UNO_QUERY_THROW );
53 return xProp->getPropertyValue( maVariableName );
54}
55
56void SAL_CALL
58{
59 // FIXME: fail to set the value if the new type of value is different from the original one.
60 uno::Reference< beans::XPropertySet > xProp( mxUserDefined, uno::UNO_QUERY_THROW );
61 xProp->setPropertyValue( maVariableName, rValue );
62}
63
64sal_Int32 SAL_CALL
66{
67 const uno::Sequence< beans::PropertyValue > props = mxUserDefined->getPropertyValues();
68 auto pProp = std::find_if(props.begin(), props.end(),
69 [this](const beans::PropertyValue& rProp) { return rProp.Name == maVariableName; });
70 if (pProp != props.end())
71 return static_cast<sal_Int32>(std::distance(props.begin(), pProp)) + 1;
72
73 return 0;
74}
75
76OUString
78{
79 return "SwVbaVariable";
80}
81
82uno::Sequence< OUString >
84{
85 static uno::Sequence< OUString > const aServiceNames
86 {
87 "ooo.vba.word.Variable"
88 };
89 return aServiceNames;
90}
91
92/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~SwVbaVariable() override
Definition: vbavariable.cxx:33
SwVbaVariable(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, css::uno::Reference< css::beans::XPropertyAccess > xUserDefined, OUString aName)
Definition: vbavariable.cxx:27
virtual void SAL_CALL setName(const OUString &) override
Definition: vbavariable.cxx:44
virtual css::uno::Any SAL_CALL getValue() override
Definition: vbavariable.cxx:50
css::uno::Reference< css::beans::XPropertyAccess > mxUserDefined
Definition: vbavariable.hxx:31
virtual void SAL_CALL setValue(const css::uno::Any &rValue) override
Definition: vbavariable.cxx:57
OUString maVariableName
Definition: vbavariable.hxx:32
virtual OUString getServiceImplName() override
Definition: vbavariable.cxx:77
virtual OUString SAL_CALL getName() override
Definition: vbavariable.cxx:38
virtual sal_Int32 SAL_CALL getIndex() override
Definition: vbavariable.cxx:65
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbavariable.cxx:83
Sequence< OUString > aServiceNames
dictionary props