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