xref: /aoo41x/main/sw/source/ui/vba/vbavariables.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 "vbavariables.hxx"
24 #include "vbavariable.hxx"
25 #include <com/sun/star/beans/XPropertyContainer.hpp>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 
28 using namespace ::ooo::vba;
29 using namespace ::com::sun::star;
30 
createVariablesAccess(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<beans::XPropertyAccess> & xUserDefined)31 uno::Reference< container::XIndexAccess > createVariablesAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< beans::XPropertyAccess >& xUserDefined ) throw ( uno::RuntimeException )
32 {
33     // FIXME: the performance is poor?
34     XNamedObjectCollectionHelper< word::XVariable >::XNamedVec mVariables;
35     const uno::Sequence< beans::PropertyValue > props = xUserDefined->getPropertyValues();
36     sal_Int32 nCount = props.getLength();
37     mVariables.reserve( nCount );
38     for( sal_Int32 i=0; i < nCount; i++ )
39         mVariables.push_back( uno::Reference< word::XVariable > ( new SwVbaVariable( xParent, xContext, xUserDefined, props[i].Name ) ) );
40 
41     uno::Reference< container::XIndexAccess > xVariables( new XNamedObjectCollectionHelper< word::XVariable >( mVariables ) );
42     return xVariables;
43 }
44 
SwVbaVariables(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<::com::sun::star::uno::XComponentContext> & xContext,const uno::Reference<beans::XPropertyAccess> & rUserDefined)45 SwVbaVariables::SwVbaVariables( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertyAccess >& rUserDefined ): SwVbaVariables_BASE( xParent, xContext, createVariablesAccess( xParent, xContext, rUserDefined ) ),  mxUserDefined( rUserDefined )
46 {
47 }
48 // XEnumerationAccess
49 uno::Type
getElementType()50 SwVbaVariables::getElementType() throw (uno::RuntimeException)
51 {
52 	return word::XVariable::static_type(0);
53 }
54 uno::Reference< container::XEnumeration >
createEnumeration()55 SwVbaVariables::createEnumeration() throw (uno::RuntimeException)
56 {
57     uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
58     return xEnumerationAccess->createEnumeration();
59 }
60 
61 uno::Any
createCollectionObject(const css::uno::Any & aSource)62 SwVbaVariables::createCollectionObject( const css::uno::Any& aSource )
63 {
64     return aSource;
65 }
66 
67 uno::Any SAL_CALL
Add(const rtl::OUString & rName,const uno::Any & rValue)68 SwVbaVariables::Add( const rtl::OUString& rName, const uno::Any& rValue ) throw (uno::RuntimeException)
69 {
70     uno::Any aValue;
71     if( rValue.hasValue() )
72         aValue = rValue;
73     else
74         aValue <<= rtl::OUString();
75     uno::Reference< beans::XPropertyContainer > xPropertyContainer( mxUserDefined, uno::UNO_QUERY_THROW );
76     xPropertyContainer->addProperty( rName, beans::PropertyAttribute::MAYBEVOID | beans::PropertyAttribute::REMOVEABLE, aValue );
77 
78     return uno::makeAny( uno::Reference< word::XVariable >( new SwVbaVariable( getParent(), mxContext, mxUserDefined, rName ) ) );
79 }
80 
81 rtl::OUString&
getServiceImplName()82 SwVbaVariables::getServiceImplName()
83 {
84 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaVariables") );
85 	return sImplName;
86 }
87 
88 css::uno::Sequence<rtl::OUString>
getServiceNames()89 SwVbaVariables::getServiceNames()
90 {
91 	static uno::Sequence< rtl::OUString > sNames;
92 	if ( sNames.getLength() == 0 )
93 	{
94 		sNames.realloc( 1 );
95 		sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Variables") );
96 	}
97 	return sNames;
98 }
99