diff options
author | Matúš Kukan <matus.kukan@gmail.com> | 2011-09-05 19:55:58 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2011-09-05 20:01:57 +0200 |
commit | ad814e27cf7eea30266c4527334c273326d87891 (patch) | |
tree | 6702394f855dc49a73920faad8cd79299ad95f6d | |
parent | now we can ditch these unused methods (diff) | |
download | core-ad814e27cf7eea30266c4527334c273326d87891.tar.gz core-ad814e27cf7eea30266c4527334c273326d87891.zip |
unusedcode: vbahelper::CollectionBase class
-rw-r--r-- | unusedcode.easy | 4 | ||||
-rw-r--r-- | vbahelper/Library_vbahelper.mk | 1 | ||||
-rw-r--r-- | vbahelper/Package_inc.mk | 1 | ||||
-rwxr-xr-x | vbahelper/inc/vbahelper/collectionbase.hxx | 214 | ||||
-rwxr-xr-x | vbahelper/source/vbahelper/collectionbase.cxx | 332 |
5 files changed, 0 insertions, 552 deletions
diff --git a/unusedcode.easy b/unusedcode.easy index aaba53c34a56..16c3bbee6e6c 100644 --- a/unusedcode.easy +++ b/unusedcode.easy @@ -3079,10 +3079,6 @@ utl::OConfigurationValueContainer::OConfigurationValueContainer(com::sun::star:: utl::OConfigurationValueContainer::getServiceFactory() const utl::OConfigurationValueContainer::registerNullValueExchangeLocation(char const*, com::sun::star::uno::Any*) utl::TransliterationWrapper::compareSubstring(String const&, int, int, String const&, int, int) const -vbahelper::CollectionBase::CollectionBase(com::sun::star::uno::Type const&) -vbahelper::CollectionBase::getAnyItemOrThis(com::sun::star::uno::Any const&) -vbahelper::CollectionBase::initElements(std::vector<com::sun::star::beans::NamedValue, std::allocator<com::sun::star::beans::NamedValue> > const&, vbahelper::CollectionBase::ContainerType) -vbahelper::CollectionBase::initElements(std::vector<com::sun::star::uno::Reference<com::sun::star::container::XNamed>, std::allocator<com::sun::star::uno::Reference<com::sun::star::container::XNamed> > > const&, vbahelper::CollectionBase::ContainerType) vcl::Clipboard_getSupportedServiceNames() vcl::I18NStatus::addChoice(String const&, void*) vcl::I18NStatus::clearChoices() diff --git a/vbahelper/Library_vbahelper.mk b/vbahelper/Library_vbahelper.mk index 6ce7185c2974..a0788ed19637 100644 --- a/vbahelper/Library_vbahelper.mk +++ b/vbahelper/Library_vbahelper.mk @@ -75,7 +75,6 @@ $(eval $(call gb_Library_add_linked_libs,vbahelper,\ # add all source files that shall be compiled with exceptions enabled # the name is relative to $(SRCROOT) and must not contain an extension $(eval $(call gb_Library_add_exception_objects,vbahelper,\ - vbahelper/source/vbahelper/collectionbase \ vbahelper/source/vbahelper/vbaapplicationbase \ vbahelper/source/vbahelper/vbacolorformat \ vbahelper/source/vbahelper/vbacommandbar \ diff --git a/vbahelper/Package_inc.mk b/vbahelper/Package_inc.mk index ffdc2f43d6f7..87c169645a5d 100644 --- a/vbahelper/Package_inc.mk +++ b/vbahelper/Package_inc.mk @@ -27,7 +27,6 @@ #************************************************************************* $(eval $(call gb_Package_Package,vbahelper_inc,$(SRCDIR)/vbahelper/inc)) -$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/collectionbase.hxx,vbahelper/collectionbase.hxx)) $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/helperdecl.hxx,vbahelper/helperdecl.hxx)) $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbaaccesshelper.hxx,vbahelper/vbaaccesshelper.hxx)) $(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbaapplicationbase.hxx,vbahelper/vbaapplicationbase.hxx)) diff --git a/vbahelper/inc/vbahelper/collectionbase.hxx b/vbahelper/inc/vbahelper/collectionbase.hxx deleted file mode 100755 index ebb5bf8f2b9a..000000000000 --- a/vbahelper/inc/vbahelper/collectionbase.hxx +++ /dev/null @@ -1,214 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2011 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef VBAHELPER_COLLECTIONBASE_HXX -#define VBAHELPER_COLLECTIONBASE_HXX - -#include <vector> -#include <com/sun/star/beans/NamedValue.hpp> -#include <com/sun/star/container/XElementAccess.hpp> -#include <com/sun/star/container/XNamed.hpp> -#include <ooo/vba/XCollectionBase.hpp> -#include <cppuhelper/implbase1.hxx> -#include <vbahelper/vbahelper.hxx> - -namespace vbahelper { - -// ============================================================================ - -typedef ::cppu::WeakImplHelper1< ov::XCollectionBase > CollectionBase_BASE; - -/** Base class of VBA objects implementing the VBA collection concept. - - This base class intentionally does not include the interface - XHelperInterface supported by all application VBA object. There may be - other VBA objects that do not support the special methods provided by - XHelperInterface. - */ -class VBAHELPER_DLLPUBLIC CollectionBase : public CollectionBase_BASE -{ -public: - /** Enumerates different container types a VBA collection can be based on. */ - enum ContainerType - { - /** Container elements are VBA items. - - The initial container contains the final VBA items provided by the - VBA collection. No conversion takes place on item access. - */ - CONTAINER_NATIVE_VBA, - - /** Container elements will be converted to VBA items on demand. - - The initial container contains intermediate objects (e.g. UNO - objects) which will be converted to VBA items everytime the item is - accessed (e.g. item access method, enumeration). Changes in the - initial container are reflected by the collection. - */ - CONTAINER_CONVERT_ON_DEMAND, - }; - - // ------------------------------------------------------------------------ - - CollectionBase( const css::uno::Type& rElementType ); - - // ------------------------------------------------------------------------ - - // attributes - virtual sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); - // XEnumerationAccess - virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); - // XElementAccess - virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException); - // XDefaultMethod - virtual ::rtl::OUString SAL_CALL getDefaultMethodName() throw (css::uno::RuntimeException); - - // ------------------------------------------------------------------------ - - /** Associates this collection with the passed UNO container. - - @param rxElementAccess - The UNO container with the elements of this collection. Shall - support either XIndexAccess or XNameAccess, may support both. - - If the container does not support XIndexAccess, index access is - simulated based on the order returned by the function - XNameAccess::getElementNames(). - - If the container does not support XNameAccess, name access is - simulated by iterating the elements via index access and asking the - elements for their name via the interface XNamed. If the elements - do not support XNamed, the elements cannot be accessed by name. - - @param eContainerType - Specifies the type of the passed container. - */ - void initContainer( - const css::uno::Reference< css::container::XElementAccess >& rxElementAccess, - ContainerType eContainerType ) throw (css::uno::RuntimeException); - - /** Initializes this collection with copies of all elements in the passed - temporary STL vector. - - @param rElements - The STL vector with the named elements of this collection. - @param eContainerType - Specifies the type of the passed vector. - */ - void initElements( - const ::std::vector< css::uno::Reference< css::container::XNamed > >& rElements, - ContainerType eContainerType ) throw (css::uno::RuntimeException); - - /** Initializes this collection with copies of all elements in the passed - temporary STL vector. - - @param rElements - The STL vector with the named elements of this collection. - @param eContainerType - Specifies the type of the passed vector. - */ - void initElements( - const ::std::vector< css::beans::NamedValue >& rElements, - ContainerType eContainerType ) throw (css::uno::RuntimeException); - - /** Returns a VBA implementation object from the passed element. - - If the container type is CONTAINER_NATIVE_VBA, returns the passed - object unmodified. If the container type is CONTAINER_CONVERT_ON_DEMAND, - calls the virtual function implCreateCollectionItem() that implements - creation of the VBA implmentation object. - - @param rElement - The container element the VBA implementation object is based on. - - @param rIndex - The index or name that has been used to access the item. - */ - css::uno::Any createCollectionItem( - const css::uno::Any& rElement, - const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); - - /** Returns a collection item specified by its one-based item index. - - @param nIndex - The one-based index of the collection item. - */ - css::uno::Any getItemByIndex( sal_Int32 nIndex ) throw (css::uno::RuntimeException); - - /** Returns a collection item specified by its name. - - @param rName - The name of the collection item. - */ - css::uno::Any getItemByName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); - - /** Returns a collection item specified by its index or name. - - @param rIndex - The index or name of the collection item. May be empty, in that - case the entire collection is returned. - */ - css::uno::Any getAnyItemOrThis( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); - - /** Returns a collection item of a specific type specified by its index or - name. - - @param rIndex - The index or name of the collection item. - */ - template< typename XType > - inline css::uno::Reference< XType > getAnyItem( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException) - { css::uno::Any aRet; if( rIndex.hasValue() ) aRet = getAnyItemOrThis( rIndex ); return css::uno::Reference< XType >( aRet, css::uno::UNO_QUERY_THROW ); } - -protected: - /** Derived classes implement creation of a VBA implementation object from - the passed intermediate container element. - - May be kept unimplemented if container type is CONTAINER_NATIVE_VBA. - - @param rElement - The container element the VBA implementation object is based on. - - @param rIndex - The index or name used to access the item. Can be used by - implementations as a hint how to find or convert the VBA object. - */ - virtual css::uno::Any implCreateCollectionItem( const css::uno::Any& rElement, const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); - -private: - css::uno::Reference< css::container::XIndexAccess > mxIndexAccess; - css::uno::Reference< css::container::XNameAccess > mxNameAccess; - css::uno::Type maElementType; - bool mbConvertOnDemand; -}; - -// ============================================================================ - -} // namespace vbahelper - -#endif diff --git a/vbahelper/source/vbahelper/collectionbase.cxx b/vbahelper/source/vbahelper/collectionbase.cxx deleted file mode 100755 index 16fc673f54d5..000000000000 --- a/vbahelper/source/vbahelper/collectionbase.cxx +++ /dev/null @@ -1,332 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2011 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include <vbahelper/collectionbase.hxx> - -#include <map> -#include <com/sun/star/container/XIndexAccess.hpp> -#include <com/sun/star/container/XNameAccess.hpp> -#include <cppuhelper/implbase2.hxx> - -namespace vbahelper { - -using namespace ::com::sun::star; -using namespace ::ooo::vba; - -// ============================================================================ - -namespace { - -// ---------------------------------------------------------------------------- - -class CollectionEnumeration : public ::cppu::WeakImplHelper1< container::XEnumeration > -{ -public: - explicit CollectionEnumeration( const ::rtl::Reference< CollectionBase >& rxCollection ); - virtual sal_Bool SAL_CALL hasMoreElements() throw (uno::RuntimeException); - virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); - -private: - ::rtl::Reference< CollectionBase > mxCollection; - sal_Int32 mnCurrIndex; -}; - -CollectionEnumeration::CollectionEnumeration( const ::rtl::Reference< CollectionBase >& rxCollection ) : - mxCollection( rxCollection ), - mnCurrIndex( 1 ) // collection expects one-based indexes -{ -} - -sal_Bool SAL_CALL CollectionEnumeration::hasMoreElements() throw (uno::RuntimeException) -{ - return mnCurrIndex <= mxCollection->getCount(); -} - -uno::Any SAL_CALL CollectionEnumeration::nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) -{ - if( hasMoreElements() ) - return mxCollection->getItemByIndex( mnCurrIndex++ ); - throw container::NoSuchElementException(); -} - -// ---------------------------------------------------------------------------- - -struct IsLessIgnoreCase -{ - inline bool operator()( const ::rtl::OUString& rName1, const ::rtl::OUString& rName2 ) const - { return ::rtl_ustr_compareIgnoreAsciiCase_WithLength( rName1.getStr(), rName1.getLength(), rName2.getStr(), rName2.getLength() ) < 0; } -}; - -// ---------------------------------------------------------------------------- - -class SequenceToContainer : public ::cppu::WeakImplHelper2< container::XIndexAccess, container::XNameAccess > -{ -public: - explicit SequenceToContainer( const ::std::vector< uno::Reference< container::XNamed > >& rElements, const uno::Type& rElementType ); - explicit SequenceToContainer( const ::std::vector< beans::NamedValue >& rElements, const uno::Type& rElementType ); - // XIndexAccess - virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException); - virtual uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException); - // XNameAccess - virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& rName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); - virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw (uno::RuntimeException); - virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException); - // XElementAccess - virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException); - virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException); - -private: - typedef uno::Sequence< ::rtl::OUString > ElementNameSequence; - typedef ::std::vector< uno::Any > ElementVector; - typedef ::std::map< ::rtl::OUString, uno::Any, IsLessIgnoreCase > ElementMap; - - ElementNameSequence maElementNames; - ElementVector maElements; - ElementMap maElementMap; - uno::Type maElementType; -}; - -SequenceToContainer::SequenceToContainer( const ::std::vector< uno::Reference< container::XNamed > >& rElements, const uno::Type& rElementType ) : - maElementType( rElementType ) -{ - maElementNames.realloc( static_cast< sal_Int32 >( rElements.size() ) ); - maElements.reserve( rElements.size() ); - ::rtl::OUString* pElementName = maElementNames.getArray(); - for( ::std::vector< uno::Reference< container::XNamed > >::const_iterator aIt = rElements.begin(), aEnd = rElements.end(); aIt != aEnd; ++aIt, ++pElementName ) - { - uno::Reference< container::XNamed > xNamed = *aIt; - *pElementName = xNamed->getName(); - maElements.push_back( uno::Any( xNamed ) ); - // same name may occur multiple times, VBA returns first occurance - if( maElementMap.count( *pElementName ) == 0 ) - maElementMap[ *pElementName ] <<= xNamed; - } -} - -SequenceToContainer::SequenceToContainer( const ::std::vector< beans::NamedValue >& rElements, const uno::Type& rElementType ) : - maElementType( rElementType ) -{ - maElementNames.realloc( static_cast< sal_Int32 >( rElements.size() ) ); - maElements.reserve( rElements.size() ); - ::rtl::OUString* pElementName = maElementNames.getArray(); - for( ::std::vector< beans::NamedValue >::const_iterator aIt = rElements.begin(), aEnd = rElements.end(); aIt != aEnd; ++aIt, ++pElementName ) - { - *pElementName = aIt->Name; - maElements.push_back( aIt->Value ); - // same name may occur multiple times, VBA returns first occurance - if( maElementMap.count( *pElementName ) == 0 ) - maElementMap[ *pElementName ] = aIt->Value; - } -} - -sal_Int32 SAL_CALL SequenceToContainer::getCount() throw (uno::RuntimeException) -{ - return static_cast< sal_Int32 >( maElements.size() ); -} - -uno::Any SAL_CALL SequenceToContainer::getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) -{ - if( (0 <= nIndex) && (nIndex < getCount()) ) - return maElements[ static_cast< size_t >( nIndex ) ]; - throw lang::IndexOutOfBoundsException(); -} - -uno::Any SAL_CALL SequenceToContainer::getByName( const ::rtl::OUString& rName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) -{ - ElementMap::iterator aIt = maElementMap.find( rName ); - if( aIt != maElementMap.end() ) - return aIt->second; - throw container::NoSuchElementException(); -} - -uno::Sequence< ::rtl::OUString > SAL_CALL SequenceToContainer::getElementNames() throw (uno::RuntimeException) -{ - return maElementNames; -} - -sal_Bool SAL_CALL SequenceToContainer::hasByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException) -{ - return maElementMap.count( rName ) > 0; -} - -uno::Type SAL_CALL SequenceToContainer::getElementType() throw (uno::RuntimeException) -{ - return maElementType; -} - -sal_Bool SAL_CALL SequenceToContainer::hasElements() throw (uno::RuntimeException) -{ - return !maElements.empty(); -} - -} // namespace - -// ============================================================================ - -CollectionBase::CollectionBase( const uno::Type& rElementType ) : - maElementType( rElementType ), - mbConvertOnDemand( false ) -{ -} - -sal_Int32 SAL_CALL CollectionBase::getCount() throw (uno::RuntimeException) -{ - if( mxIndexAccess.is() ) - return mxIndexAccess->getCount(); - if( mxNameAccess.is() ) - return mxNameAccess->getElementNames().getLength(); - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); -} - -uno::Reference< container::XEnumeration > SAL_CALL CollectionBase::createEnumeration() throw (uno::RuntimeException) -{ - return new CollectionEnumeration( this ); -} - -uno::Type SAL_CALL CollectionBase::getElementType() throw (uno::RuntimeException) -{ - return maElementType; -} - -sal_Bool SAL_CALL CollectionBase::hasElements() throw (uno::RuntimeException) -{ - if( mxIndexAccess.is() ) - return mxIndexAccess->hasElements(); - if( mxNameAccess.is() ) - return mxNameAccess->hasElements(); - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); -} - -::rtl::OUString SAL_CALL CollectionBase::getDefaultMethodName() throw (uno::RuntimeException) -{ - static ::rtl::OUString saDefMethodName( RTL_CONSTASCII_USTRINGPARAM( "Item" ) ); - return saDefMethodName; -} - -// ---------------------------------------------------------------------------- - -void CollectionBase::initContainer( - const uno::Reference< container::XElementAccess >& rxElementAccess, - ContainerType eContainerType ) throw (uno::RuntimeException) -{ - mxIndexAccess.set( rxElementAccess, uno::UNO_QUERY ); - mxNameAccess.set( rxElementAccess, uno::UNO_QUERY ); - switch( eContainerType ) - { - case CONTAINER_NATIVE_VBA: - mbConvertOnDemand = false; - break; - case CONTAINER_CONVERT_ON_DEMAND: - mbConvertOnDemand = true; - break; - } -} - -void CollectionBase::initElements( const ::std::vector< uno::Reference< container::XNamed > >& rElements, ContainerType eContainerType ) throw (uno::RuntimeException) -{ - // SequenceToContainer derives twice from XElementAccess, need to resolve ambiguity - initContainer( static_cast< container::XIndexAccess* >( new SequenceToContainer( rElements, maElementType ) ), eContainerType ); -} - -void CollectionBase::initElements( const ::std::vector< beans::NamedValue >& rElements, ContainerType eContainerType ) throw (uno::RuntimeException) -{ - // SequenceToContainer derives twice from XElementAccess, need to resolve ambiguity - initContainer( static_cast< container::XIndexAccess* >( new SequenceToContainer( rElements, maElementType ) ), eContainerType ); -} - -uno::Any CollectionBase::createCollectionItem( const uno::Any& rElement, const uno::Any& rIndex ) throw (css::uno::RuntimeException) -{ - uno::Any aItem = mbConvertOnDemand ? implCreateCollectionItem( rElement, rIndex ) : rElement; - if( aItem.hasValue() ) - return aItem; - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item." ) ), 0 ); -} - -uno::Any CollectionBase::getItemByIndex( sal_Int32 nIndex ) throw (uno::RuntimeException) -{ - if( mxIndexAccess.is() ) - { - if( (1 <= nIndex) && (nIndex <= mxIndexAccess->getCount()) ) - // createCollectionItem() will convert from container element to VBA item - return createCollectionItem( mxIndexAccess->getByIndex( nIndex - 1 ), uno::Any( nIndex ) ); - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Index out of bounds." ) ), 0 ); - } - if( mxNameAccess.is() ) - { - uno::Sequence< ::rtl::OUString > aElementNames = mxNameAccess->getElementNames(); - if( (1 <= nIndex) && (nIndex <= aElementNames.getLength()) ) - // createCollectionItem() will convert from container element to VBA item - return createCollectionItem( mxNameAccess->getByName( aElementNames[ nIndex - 1 ] ), uno::Any( aElementNames[ nIndex - 1 ] ) ); - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Index out of bounds." ) ), 0 ); - } - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); -} - -uno::Any CollectionBase::getItemByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException) -{ - if( mxNameAccess.is() ) - { - if( rName.getLength() > 0 ) - // createCollectionItem() will convert from container element to VBA item - return createCollectionItem( mxNameAccess->getByName( rName ), uno::Any( rName ) ); - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item name." ) ), 0 ); - } - if( mxIndexAccess.is() ) - { - for( sal_Int32 nIndex = 0, nSize = mxIndexAccess->getCount(); nIndex < nSize; ++nIndex ) - { - uno::Any aElement = mxIndexAccess->getByIndex( nIndex ); - uno::Reference< container::XNamed > xNamed( aElement, uno::UNO_QUERY ); - if( xNamed.is() && xNamed->getName().equalsIgnoreAsciiCase( rName ) ) - // createCollectionItem() will convert from container element to VBA item - return createCollectionItem( aElement, uno::Any( nIndex ) ); - } - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item name." ) ), 0 ); - } - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); -} - -uno::Any CollectionBase::getAnyItemOrThis( const uno::Any& rIndex ) throw (uno::RuntimeException) -{ - if( !rIndex.hasValue() ) - return uno::Any( uno::Reference< XCollectionBase >( this ) ); - if( rIndex.has< ::rtl::OUString >() ) - return getItemByName( rIndex.get< ::rtl::OUString >() ); - // extractIntFromAny() throws if no index can be extracted - return getItemByIndex( extractIntFromAny( rIndex ) ); -} - -// protected ------------------------------------------------------------------ - -uno::Any CollectionBase::implCreateCollectionItem( const uno::Any& /*rElement*/, const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException) -{ - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Creation of VBA implementation object not implemented." ) ), 0 ); -} - -// ============================================================================ - -} // namespace vbahelper |