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