1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
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
) );
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
)
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();
69 SwVbaVariables::createCollectionObject( const css::uno::Any
& aSource
)
75 SwVbaVariables::Add( const rtl::OUString
& rName
, const uno::Any
& rValue
) throw (uno::RuntimeException
)
78 if( rValue
.hasValue() )
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
) ) );
89 SwVbaVariables::getServiceImplName()
91 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaVariables") );
95 css::uno::Sequence
<rtl::OUString
>
96 SwVbaVariables::getServiceNames()
98 static uno::Sequence
< rtl::OUString
> sNames
;
99 if ( sNames
.getLength() == 0 )
102 sNames
[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Variables") );