Line data Source code
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 0 : SwVbaVariable::SwVbaVariable( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,
29 : const uno::Reference< beans::XPropertyAccess >& rUserDefined, const OUString& rName ) throw ( uno::RuntimeException ) :
30 0 : SwVbaVariable_BASE( rParent, rContext ), mxUserDefined( rUserDefined ), maName( rName )
31 : {
32 0 : }
33 :
34 0 : SwVbaVariable::~SwVbaVariable()
35 : {
36 0 : }
37 :
38 : OUString SAL_CALL
39 0 : SwVbaVariable::getName() throw ( css::uno::RuntimeException, std::exception )
40 : {
41 0 : return maName;
42 : }
43 :
44 : void SAL_CALL
45 0 : SwVbaVariable::setName( const OUString& ) throw ( css::uno::RuntimeException, std::exception )
46 : {
47 0 : throw uno::RuntimeException(" Fail to set name", uno::Reference< uno::XInterface >() );
48 : }
49 :
50 : uno::Any SAL_CALL
51 0 : SwVbaVariable::getValue() throw ( css::uno::RuntimeException, std::exception )
52 : {
53 0 : uno::Reference< beans::XPropertySet > xProp( mxUserDefined, uno::UNO_QUERY_THROW );
54 0 : return xProp->getPropertyValue( maName );
55 : }
56 :
57 : void SAL_CALL
58 0 : SwVbaVariable::setValue( const uno::Any& rValue ) throw ( css::uno::RuntimeException, std::exception )
59 : {
60 : // FIXME: fail to set the value if the new type of vaue is differenct from the original one.
61 0 : uno::Reference< beans::XPropertySet > xProp( mxUserDefined, uno::UNO_QUERY_THROW );
62 0 : xProp->setPropertyValue( maName, rValue );
63 0 : }
64 :
65 : sal_Int32 SAL_CALL
66 0 : SwVbaVariable::getIndex() throw ( css::uno::RuntimeException, std::exception )
67 : {
68 0 : const uno::Sequence< beans::PropertyValue > props = mxUserDefined->getPropertyValues();
69 0 : for (sal_Int32 i = 0; i < props.getLength(); ++i)
70 : {
71 0 : if( maName.equals( props[i].Name ) )
72 0 : return i+1;
73 : }
74 :
75 0 : return 0;
76 : }
77 :
78 : OUString
79 0 : SwVbaVariable::getServiceImplName()
80 : {
81 0 : return OUString("SwVbaVariable");
82 : }
83 :
84 : uno::Sequence< OUString >
85 0 : SwVbaVariable::getServiceNames()
86 : {
87 0 : static uno::Sequence< OUString > aServiceNames;
88 0 : if ( aServiceNames.getLength() == 0 )
89 : {
90 0 : aServiceNames.realloc( 1 );
91 0 : aServiceNames[ 0 ] = "ooo.vba.word.Variable";
92 : }
93 0 : return aServiceNames;
94 : }
95 :
96 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|