/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** A wrapper that holds a com.sun.star.container.XIndexAccess and provides a com.sun.star.container.XEnumeration.
Can be used to provide an enumeration from an index container that contains completely constructed/initialized VBA implementation objects. CANNOT be used to provide an enumeration from an index container with other objects (e.g. UNO objects) where construction of the VBA objects is needed first.
*/ class VBAHELPER_DLLPUBLIC SimpleIndexAccessToEnumeration final : public EnumerationHelper_BASE
{ public: /// @throws css::uno::RuntimeException explicit SimpleIndexAccessToEnumeration(
css::uno::Reference< css::container::XIndexAccess > xIndexAccess ) :
mxIndexAccess(std::move( xIndexAccess )), mnIndex( 0 ) {}
/** A wrapper that holds a com.sun.star.container.XEnumeration or a com.sun.star.container.XIndexAccess and provides an enumeration of VBA objects.
The method createCollectionObject() needs to be implemented by the derived class. This class can be used to convert an enumeration or an index container containing UNO objects to an enumeration providing the related VBA objects.
*/ class VBAHELPER_DLLPUBLIC SimpleEnumerationBase : public EnumerationHelper_BASE
{ public: /// @throws css::uno::RuntimeException explicit SimpleEnumerationBase( const css::uno::Reference< css::container::XIndexAccess >& rxIndexAccess ) :
mxEnumeration( new SimpleIndexAccessToEnumeration( rxIndexAccess ) ) {}
// a wrapper class for a providing a XIndexAccess, XNameAccess, XEnumerationAccess impl based on providing a vector of interfaces // only requirement is the object needs to implement XName
template< typename OneIfc > class XNamedObjectCollectionHelper final : public ::cppu::WeakImplHelper< css::container::XNameAccess,
css::container::XIndexAccess,
css::container::XEnumerationAccess >
{ public: typedef std::vector< css::uno::Reference< OneIfc > > XNamedVec; private:
class XNamedEnumerationHelper final : public EnumerationHelper_BASE
{
XNamedVec mXNamedVec; typename XNamedVec::iterator mIt; public:
XNamedEnumerationHelper( XNamedVec sMap ) : mXNamedVec(std::move( sMap )), mIt( mXNamedVec.begin() ) {}
/// @throws css::uno::RuntimeException /// @throws css::lang::IndexOutOfBoundsException virtual css::uno::Any getItemByIntIndex( const sal_Int32 nIndex )
{ if ( !m_xIndexAccess.is() ) throw css::uno::RuntimeException(u"ScVbaCollectionBase numeric index access not supported by this object"_ustr ); if ( nIndex <= 0 )
{ throw css::lang::IndexOutOfBoundsException(
u"index is 0 or negative"_ustr );
} // need to adjust for vba index ( for which first element is 1 ) return createCollectionObject( m_xIndexAccess->getByIndex( nIndex - 1 ) );
}
virtual css::uno::Any SAL_CALL Item(const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/) override
{
OUString aStringSheet; if (Index1.getValueTypeClass() == css::uno::TypeClass_DOUBLE)
{ // This is needed for ContentControls, where the unique integer ID // can be passed as float to simulate a "by name" lookup. double fIndex = 0;
Index1 >>= fIndex;
aStringSheet = OUString::number(fIndex);
} elseif (Index1.getValueTypeClass() != css::uno::TypeClass_STRING)
{
sal_Int32 nIndex = 0; if ( !( Index1 >>= nIndex ) )
{ throw css::lang::IndexOutOfBoundsException( u"Couldn't convert index to Int32"_ustr );
}
typedef ScVbaCollectionBase< ::cppu::WeakImplHelper<ov::XCollection> > CollImplBase; // compatible with the old collections ( pre XHelperInterface base class ) ( some internal objects still use this ) class VBAHELPER_DLLPUBLIC ScVbaCollectionBaseImpl : public CollImplBase
{ public: /// @throws css::uno::RuntimeException
ScVbaCollectionBaseImpl( const css::uno::Reference< ov::XHelperInterface > & xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) : CollImplBase( xParent, xContext, xIndexAccess){}
};
template < typename... Ifc > // where Ifc must implement XCollectionTest class SAL_DLLPUBLIC_RTTI CollTestImplHelper : public ScVbaCollectionBase< ::cppu::WeakImplHelper< Ifc... > >
{ typedef ScVbaCollectionBase< ::cppu::WeakImplHelper< Ifc... > > ImplBase;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.