merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / vba / vbavariables.cxx
blob9242fd9ae49925dd7e16d84f5b5d55d45c601e79
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile:
10 * $Revision:
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbavariables.hxx"
31 #include "vbavariable.hxx"
32 #include <com/sun/star/beans/XPropertyContainer.hpp>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 using namespace ::ooo::vba;
36 using namespace ::com::sun::star;
38 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 )
40 // FIXME: the performance is poor?
41 XNamedObjectCollectionHelper< word::XVariable >::XNamedVec mVariables;
42 const uno::Sequence< beans::PropertyValue > props = xUserDefined->getPropertyValues();
43 sal_Int32 nCount = props.getLength();
44 mVariables.reserve( nCount );
45 for( sal_Int32 i=0; i < nCount; i++ )
46 mVariables.push_back( uno::Reference< word::XVariable > ( new SwVbaVariable( xParent, xContext, xUserDefined, props[i].Name ) ) );
48 uno::Reference< container::XIndexAccess > xVariables( new XNamedObjectCollectionHelper< word::XVariable >( mVariables ) );
49 return xVariables;
52 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 )
55 // XEnumerationAccess
56 uno::Type
57 SwVbaVariables::getElementType() throw (uno::RuntimeException)
59 return word::XVariable::static_type(0);
61 uno::Reference< container::XEnumeration >
62 SwVbaVariables::createEnumeration() throw (uno::RuntimeException)
64 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
65 return xEnumerationAccess->createEnumeration();
68 uno::Any
69 SwVbaVariables::createCollectionObject( const css::uno::Any& aSource )
71 return aSource;
74 uno::Any SAL_CALL
75 SwVbaVariables::Add( const rtl::OUString& rName, const uno::Any& rValue ) throw (uno::RuntimeException)
77 uno::Any aValue;
78 if( rValue.hasValue() )
79 aValue = rValue;
80 else
81 aValue <<= rtl::OUString();
82 uno::Reference< beans::XPropertyContainer > xPropertyContainer( mxUserDefined, uno::UNO_QUERY_THROW );
83 xPropertyContainer->addProperty( rName, beans::PropertyAttribute::MAYBEVOID | beans::PropertyAttribute::REMOVEABLE, aValue );
85 return uno::makeAny( uno::Reference< word::XVariable >( new SwVbaVariable( getParent(), mxContext, mxUserDefined, rName ) ) );
88 rtl::OUString&
89 SwVbaVariables::getServiceImplName()
91 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaVariables") );
92 return sImplName;
95 css::uno::Sequence<rtl::OUString>
96 SwVbaVariables::getServiceNames()
98 static uno::Sequence< rtl::OUString > sNames;
99 if ( sNames.getLength() == 0 )
101 sNames.realloc( 1 );
102 sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Variables") );
104 return sNames;