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