xref: /aoo42x/main/sw/source/ui/vba/vbavariable.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "vbavariable.hxx"
24 #include <vbahelper/vbahelper.hxx>
25 #include <tools/diagnose_ex.h>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 
29 using namespace ::ooo::vba;
30 using namespace ::com::sun::star;
31 
SwVbaVariable(const uno::Reference<ooo::vba::XHelperInterface> & rParent,const uno::Reference<uno::XComponentContext> & rContext,const uno::Reference<beans::XPropertyAccess> & rUserDefined,const rtl::OUString & rName)32 SwVbaVariable::SwVbaVariable( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,
33     const uno::Reference< beans::XPropertyAccess >& rUserDefined, const rtl::OUString& rName ) throw ( uno::RuntimeException ) :
34     SwVbaVariable_BASE( rParent, rContext ), mxUserDefined( rUserDefined ), maName( rName )
35 {
36 }
37 
~SwVbaVariable()38 SwVbaVariable::~SwVbaVariable()
39 {
40 }
41 
42 rtl::OUString SAL_CALL
getName()43 SwVbaVariable::getName() throw ( css::uno::RuntimeException )
44 {
45     return maName;
46 }
47 
48 void SAL_CALL
setName(const rtl::OUString &)49 SwVbaVariable::setName( const rtl::OUString& ) throw ( css::uno::RuntimeException )
50 {
51     throw uno::RuntimeException( rtl::OUString(
52             RTL_CONSTASCII_USTRINGPARAM(" Fail to set name")), uno::Reference< uno::XInterface >() );
53 }
54 
55 uno::Any SAL_CALL
getValue()56 SwVbaVariable::getValue() throw ( css::uno::RuntimeException )
57 {
58     uno::Reference< beans::XPropertySet > xProp( mxUserDefined, uno::UNO_QUERY_THROW );
59     return xProp->getPropertyValue( maName );
60 }
61 
62 void SAL_CALL
setValue(const uno::Any & rValue)63 SwVbaVariable::setValue( const uno::Any& rValue ) throw ( css::uno::RuntimeException )
64 {
65     // FIXME: fail to set the value if the new type of vaue is differenct from the original one.
66     uno::Reference< beans::XPropertySet > xProp( mxUserDefined, uno::UNO_QUERY_THROW );
67     xProp->setPropertyValue( maName, rValue );
68 }
69 
70 sal_Int32 SAL_CALL
getIndex()71 SwVbaVariable::getIndex() throw ( css::uno::RuntimeException )
72 {
73     const uno::Sequence< beans::PropertyValue > props = mxUserDefined->getPropertyValues();
74     for (sal_Int32 i = 0; i < props.getLength(); ++i)
75     {
76         if( maName.equals( props[i].Name ) )
77             return i+1;
78     }
79 
80     return 0;
81 }
82 
83 rtl::OUString&
getServiceImplName()84 SwVbaVariable::getServiceImplName()
85 {
86 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaVariable") );
87 	return sImplName;
88 }
89 
90 uno::Sequence< rtl::OUString >
getServiceNames()91 SwVbaVariable::getServiceNames()
92 {
93 	static uno::Sequence< rtl::OUString > aServiceNames;
94 	if ( aServiceNames.getLength() == 0 )
95 	{
96 		aServiceNames.realloc( 1 );
97 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Variable" ) );
98 	}
99 	return aServiceNames;
100 }
101 
102