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 "vbavariable.hxx" 28 #include <vbahelper/vbahelper.hxx> 29 #include <tools/diagnose_ex.h> 30 #include <com/sun/star/beans/XPropertySet.hpp> 31 #include <com/sun/star/beans/PropertyValue.hpp> 32 33 using namespace ::ooo::vba; 34 using namespace ::com::sun::star; 35 36 SwVbaVariable::SwVbaVariable( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, 37 const uno::Reference< beans::XPropertyAccess >& rUserDefined, const rtl::OUString& rName ) throw ( uno::RuntimeException ) : 38 SwVbaVariable_BASE( rParent, rContext ), mxUserDefined( rUserDefined ), maName( rName ) 39 { 40 } 41 42 SwVbaVariable::~SwVbaVariable() 43 { 44 } 45 46 rtl::OUString SAL_CALL 47 SwVbaVariable::getName() throw ( css::uno::RuntimeException ) 48 { 49 return maName; 50 } 51 52 void SAL_CALL 53 SwVbaVariable::setName( const rtl::OUString& ) throw ( css::uno::RuntimeException ) 54 { 55 throw uno::RuntimeException( rtl::OUString( 56 RTL_CONSTASCII_USTRINGPARAM(" Fail to set name")), uno::Reference< uno::XInterface >() ); 57 } 58 59 uno::Any SAL_CALL 60 SwVbaVariable::getValue() throw ( css::uno::RuntimeException ) 61 { 62 uno::Reference< beans::XPropertySet > xProp( mxUserDefined, uno::UNO_QUERY_THROW ); 63 return xProp->getPropertyValue( maName ); 64 } 65 66 void SAL_CALL 67 SwVbaVariable::setValue( const uno::Any& rValue ) throw ( css::uno::RuntimeException ) 68 { 69 // FIXME: fail to set the value if the new type of vaue is differenct from the original one. 70 uno::Reference< beans::XPropertySet > xProp( mxUserDefined, uno::UNO_QUERY_THROW ); 71 xProp->setPropertyValue( maName, rValue ); 72 } 73 74 sal_Int32 SAL_CALL 75 SwVbaVariable::getIndex() throw ( css::uno::RuntimeException ) 76 { 77 const uno::Sequence< beans::PropertyValue > props = mxUserDefined->getPropertyValues(); 78 for (sal_Int32 i = 0; i < props.getLength(); ++i) 79 { 80 if( maName.equals( props[i].Name ) ) 81 return i+1; 82 } 83 84 return 0; 85 } 86 87 rtl::OUString& 88 SwVbaVariable::getServiceImplName() 89 { 90 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaVariable") ); 91 return sImplName; 92 } 93 94 uno::Sequence< rtl::OUString > 95 SwVbaVariable::getServiceNames() 96 { 97 static uno::Sequence< rtl::OUString > aServiceNames; 98 if ( aServiceNames.getLength() == 0 ) 99 { 100 aServiceNames.realloc( 1 ); 101 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Variable" ) ); 102 } 103 return aServiceNames; 104 } 105 106