diff options
Diffstat (limited to '')
22 files changed, 2443 insertions, 0 deletions
diff --git a/include/vbahelper/helperdecl.hxx b/include/vbahelper/helperdecl.hxx new file mode 100644 index 000000000..7ee9f2793 --- /dev/null +++ b/include/vbahelper/helperdecl.hxx @@ -0,0 +1,51 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_VBAHELPER_HELPERDECL_HXX +#define INCLUDED_VBAHELPER_HELPERDECL_HXX + +#include <comphelper/servicedecl.hxx> + +namespace comphelper { +namespace service_decl { +template <typename ImplT_, typename WithArgsT = with_args<false> > +struct vba_service_class_ : public serviceimpl_base< detail::OwnServiceImpl<ImplT_>, WithArgsT > +{ + typedef serviceimpl_base< detail::OwnServiceImpl<ImplT_>, WithArgsT > baseT; + /** Default ctor. Implementation class without args, expecting + component context as single argument. + */ + vba_service_class_() : baseT() {} + template <typename PostProcessFuncT> + /** Ctor to pass a post processing function/functor. + + @tpl PostProcessDefaultT let your compiler deduce this + @param postProcessFunc function/functor that gets the yet unacquired + ImplT_ pointer returning a + uno::Reference<uno::XInterface> + */ + explicit vba_service_class_( PostProcessFuncT const& postProcessFunc ) : baseT( postProcessFunc ) {} +}; + +} // namespace service_decl +} // namespace comphelper + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbaaccesshelper.hxx b/include/vbahelper/vbaaccesshelper.hxx new file mode 100644 index 000000000..ce55e01e2 --- /dev/null +++ b/include/vbahelper/vbaaccesshelper.hxx @@ -0,0 +1,82 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBAACCESSHELPER_HXX +#define INCLUDED_VBAHELPER_VBAACCESSHELPER_HXX + +#include <memory> + +#include <basic/basmgr.hxx> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <osl/diagnose.h> +//#define VBAHELPER_DLLIMPLEMENTATION +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <sfx2/objsh.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> + +namespace ooo +{ + namespace vba + { + + inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell const * pShell ) + { + css::uno::Any aUnoVar; + if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) ) + throw css::lang::IllegalArgumentException(); + css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW ); + return xVBAFactory; + } + + /// @throws css::uno::Exception + inline css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell const * pShell, const char* _pAsciiName, const css::uno::Sequence< css::uno::Any >& aArgs ) + { + OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" ); + OUString sVarName( OUString::createFromAscii( _pAsciiName ) ); + css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs ); + return xIf; + } + + + inline bool isAlienDoc( SfxObjectShell const & rDocShell, const char* pMimeType ) + { + bool bRes( false ); + const SfxMedium *pMedium = rDocShell.GetMedium(); + std::shared_ptr<const SfxFilter> pFilt = pMedium ? pMedium->GetFilter() : nullptr; + if ( pFilt && pFilt->IsAlienFormat() ) + bRes = pFilt->GetMimeType().equalsAscii( pMimeType ); + return bRes; + } + inline bool isAlienExcelDoc( SfxObjectShell const & rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-excel" ); } + //VBAHELPER_DLLPRIVATE inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-word" ); } + // word seems to return an erroneous mime type :-/ "application/msword" not consistent with the excel one + inline bool isAlienWordDoc( SfxObjectShell const & rDocShell ) { return isAlienDoc( rDocShell, "application/msword" ); } + + } +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbaapplicationbase.hxx b/include/vbahelper/vbaapplicationbase.hxx new file mode 100644 index 000000000..24bac8204 --- /dev/null +++ b/include/vbahelper/vbaapplicationbase.hxx @@ -0,0 +1,86 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBAAPPLICATIONBASE_HXX +#define INCLUDED_VBAHELPER_VBAAPPLICATIONBASE_HXX + +#include <exception> +#include <memory> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <ooo/vba/XApplicationBase.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +typedef InheritedHelperInterfaceWeakImpl< ov::XApplicationBase > ApplicationBase_BASE; + +struct VbaApplicationBase_Impl; + +class VBAHELPER_DLLPUBLIC VbaApplicationBase : public ApplicationBase_BASE +{ + std::unique_ptr<VbaApplicationBase_Impl> m_pImpl; + +protected: + VbaApplicationBase( const css::uno::Reference< css::uno::XComponentContext >& xContext ); + virtual ~VbaApplicationBase() override; + + /// @throws css::uno::RuntimeException + virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() = 0; +public: + // XHelperInterface ( parent is itself ) + virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) override { return this; } + + virtual sal_Bool SAL_CALL getScreenUpdating() override; + virtual void SAL_CALL setScreenUpdating(sal_Bool bUpdate) override; + virtual sal_Bool SAL_CALL getDisplayStatusBar() override; + virtual void SAL_CALL setDisplayStatusBar(sal_Bool bDisplayStatusBar) override; + virtual sal_Bool SAL_CALL getInteractive() override; + virtual void SAL_CALL setInteractive( sal_Bool bInteractive ) override; + virtual sal_Bool SAL_CALL getVisible() override; + virtual void SAL_CALL setVisible( sal_Bool bVisible ) override; + virtual OUString SAL_CALL getCaption() override; + virtual void SAL_CALL setCaption( const OUString& sCaption ) override; + virtual void SAL_CALL OnKey( const OUString& Key, const css::uno::Any& Procedure ) override; + virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) override; + virtual OUString SAL_CALL getVersion() override; + virtual css::uno::Any SAL_CALL getVBE() override; + + virtual css::uno::Any SAL_CALL Run( const OUString& MacroName, const css::uno::Any& varg1, const css::uno::Any& varg2, const css::uno::Any& varg3, const css::uno::Any& varg4, const css::uno::Any& varg5, const css::uno::Any& varg6, const css::uno::Any& varg7, const css::uno::Any& varg8, const css::uno::Any& varg9, const css::uno::Any& varg10, const css::uno::Any& varg11, const css::uno::Any& varg12, const css::uno::Any& varg13, const css::uno::Any& varg14, const css::uno::Any& varg15, const css::uno::Any& varg16, const css::uno::Any& varg17, const css::uno::Any& varg18, const css::uno::Any& varg19, const css::uno::Any& varg20, const css::uno::Any& varg21, const css::uno::Any& varg22, const css::uno::Any& varg23, const css::uno::Any& varg24, const css::uno::Any& varg25, const css::uno::Any& varg26, const css::uno::Any& varg27, const css::uno::Any& varg28, const css::uno::Any& varg29, const css::uno::Any& varg30 ) override; + virtual void SAL_CALL OnTime( const css::uno::Any& aEarliestTime, const OUString& aFunction, const css::uno::Any& aLatestTime, const css::uno::Any& aSchedule ) override; + virtual float SAL_CALL CentimetersToPoints( float Centimeters ) override; + virtual void SAL_CALL Undo() override; + virtual void SAL_CALL Quit() override; + + // XHelperInterface + virtual OUString getServiceImplName() override; + virtual css::uno::Sequence<OUString> getServiceNames() override; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbacollectionimpl.hxx b/include/vbahelper/vbacollectionimpl.hxx new file mode 100644 index 000000000..9bb537e84 --- /dev/null +++ b/include/vbahelper/vbacollectionimpl.hxx @@ -0,0 +1,354 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_VBAHELPER_VBACOLLECTIONIMPL_HXX +#define INCLUDED_VBAHELPER_VBACOLLECTIONIMPL_HXX + +#include <exception> +#include <vector> + +#include <com/sun/star/container/NoSuchElementException.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/lang/WrappedTargetException.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/TypeClass.hpp> +#include <cppu/unotype.hxx> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/weakref.hxx> +#include <ooo/vba/XCollection.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace container { class XEnumerationAccess; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XHelperInterface; +} + +typedef ::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE; + + +/** 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( + const css::uno::Reference< css::container::XIndexAccess >& rxIndexAccess ) : + mxIndexAccess( rxIndexAccess ), mnIndex( 0 ) {} + + virtual sal_Bool SAL_CALL hasMoreElements() override + { + return mnIndex < mxIndexAccess->getCount(); + } + + virtual css::uno::Any SAL_CALL nextElement() override + { + if( !hasMoreElements() ) + throw css::container::NoSuchElementException(); + return mxIndexAccess->getByIndex( mnIndex++ ); + } + +private: + css::uno::Reference< css::container::XIndexAccess > mxIndexAccess; + sal_Int32 mnIndex; +}; + + +/** 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 ) ) {} + + virtual sal_Bool SAL_CALL hasMoreElements() override + { + return mxEnumeration->hasMoreElements(); + } + + virtual css::uno::Any SAL_CALL nextElement() override + { + return createCollectionObject( mxEnumeration->nextElement() ); + } + + /** Derived classes implement creation of a VBA implementation object from + the passed container element. */ + virtual css::uno::Any createCollectionObject( const css::uno::Any& rSource ) = 0; + +private: + css::uno::Reference< css::container::XEnumeration > mxEnumeration; +}; + + +// deprecated, use SimpleEnumerationBase instead! +class VBAHELPER_DLLPUBLIC EnumerationHelperImpl : public EnumerationHelper_BASE +{ +protected: + css::uno::WeakReference< ov::XHelperInterface > m_xParent; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::container::XEnumeration > m_xEnumeration; +public: + /// @throws css::uno::RuntimeException + EnumerationHelperImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XEnumeration >& xEnumeration ) : m_xParent( xParent ), m_xContext( xContext ), m_xEnumeration( xEnumeration ) { } + virtual sal_Bool SAL_CALL hasMoreElements( ) override { return m_xEnumeration->hasMoreElements(); } +}; + +// 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 : public EnumerationHelper_BASE + { + XNamedVec mXNamedVec; + typename XNamedVec::iterator mIt; + public: + XNamedEnumerationHelper( const XNamedVec& sMap ) : mXNamedVec( sMap ), mIt( mXNamedVec.begin() ) {} + + virtual sal_Bool SAL_CALL hasMoreElements( ) override + { + return ( mIt != mXNamedVec.end() ); + } + + virtual css::uno::Any SAL_CALL nextElement( ) override + { + if ( hasMoreElements() ) + return css::uno::makeAny( *mIt++ ); + throw css::container::NoSuchElementException(); + } + }; + + XNamedVec mXNamedVec; + typename XNamedVec::iterator cachePos; +public: + XNamedObjectCollectionHelper( const XNamedVec& sMap ) : mXNamedVec( sMap ), cachePos(mXNamedVec.begin()) {} + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType( ) override { return cppu::UnoType< OneIfc >::get(); } + virtual sal_Bool SAL_CALL hasElements( ) override { return ( mXNamedVec.size() > 0 ); } + // XNameAccess + virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override + { + if ( !hasByName(aName) ) + throw css::container::NoSuchElementException(); + return css::uno::makeAny( *cachePos ); + } + virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override + { + css::uno::Sequence< OUString > sNames( mXNamedVec.size() ); + OUString* pString = sNames.getArray(); + typename XNamedVec::iterator it = mXNamedVec.begin(); + typename XNamedVec::iterator it_end = mXNamedVec.end(); + + for ( ; it != it_end; ++it, ++pString ) + { + css::uno::Reference< css::container::XNamed > xName( *it, css::uno::UNO_QUERY_THROW ); + *pString = xName->getName(); + } + return sNames; + } + virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override + { + cachePos = mXNamedVec.begin(); + typename XNamedVec::iterator it_end = mXNamedVec.end(); + for ( ; cachePos != it_end; ++cachePos ) + { + css::uno::Reference< css::container::XNamed > xName( *cachePos, css::uno::UNO_QUERY_THROW ); + if ( aName == xName->getName() ) + break; + } + return ( cachePos != it_end ); + } + + // XElementAccess + virtual ::sal_Int32 SAL_CALL getCount( ) override { return mXNamedVec.size(); } + virtual css::uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override + { + if ( Index < 0 || Index >= getCount() ) + throw css::lang::IndexOutOfBoundsException(); + + return css::uno::makeAny( mXNamedVec[ Index ] ); + + } + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override + { + return new XNamedEnumerationHelper( mXNamedVec ); + } +}; + +// including a HelperInterface implementation +template< typename... Ifc > +class SAL_DLLPUBLIC_RTTI ScVbaCollectionBase : public InheritedHelperInterfaceImpl< Ifc... > +{ +typedef InheritedHelperInterfaceImpl< Ifc... > BaseColBase; +protected: + css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess; + css::uno::Reference< css::container::XNameAccess > m_xNameAccess; + bool mbIgnoreCase; + + /// @throws css::uno::RuntimeException + virtual css::uno::Any getItemByStringIndex( const OUString& sIndex ) + { + if ( !m_xNameAccess.is() ) + throw css::uno::RuntimeException("ScVbaCollectionBase string index access not supported by this object" ); + + if( mbIgnoreCase ) + { + const css::uno::Sequence< OUString > sElementNames = m_xNameAccess->getElementNames(); + for( const OUString& rName : sElementNames ) + { + if( rName.equalsIgnoreAsciiCase( sIndex ) ) + { + return createCollectionObject( m_xNameAccess->getByName( rName ) ); + } + } + } + return createCollectionObject( m_xNameAccess->getByName( sIndex ) ); + } + + /// @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("ScVbaCollectionBase numeric index access not supported by this object" ); + if ( nIndex <= 0 ) + { + throw css::lang::IndexOutOfBoundsException( + "index is 0 or negative" ); + } + // need to adjust for vba index ( for which first element is 1 ) + return createCollectionObject( m_xIndexAccess->getByIndex( nIndex - 1 ) ); + } + + void UpdateCollectionIndex( const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) + { + css::uno::Reference< css::container::XNameAccess > xNameAccess( xIndexAccess, css::uno::UNO_QUERY_THROW ); + m_xIndexAccess = xIndexAccess; + m_xNameAccess = xNameAccess; + } + +public: + ScVbaCollectionBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, bool bIgnoreCase = false ) : BaseColBase( xParent, xContext ), m_xIndexAccess( xIndexAccess ), mbIgnoreCase( bIgnoreCase ) { m_xNameAccess.set(m_xIndexAccess, css::uno::UNO_QUERY); } + + //XCollection + virtual ::sal_Int32 SAL_CALL getCount() override + { + return m_xIndexAccess->getCount(); + } + + virtual css::uno::Any SAL_CALL Item(const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/) override + { + if ( Index1.getValueTypeClass() != css::uno::TypeClass_STRING ) + { + sal_Int32 nIndex = 0; + + if ( !( Index1 >>= nIndex ) ) + { + throw css::lang::IndexOutOfBoundsException( "Couldn't convert index to Int32" ); + } + return getItemByIntIndex( nIndex ); + } + OUString aStringSheet; + + Index1 >>= aStringSheet; + return getItemByStringIndex( aStringSheet ); + } + + // XDefaultMethod + OUString SAL_CALL getDefaultMethodName( ) override + { + return "Item"; + } + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override = 0; + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() override = 0; + // XElementAccess + virtual sal_Bool SAL_CALL hasElements() override + { + return ( m_xIndexAccess->getCount() > 0 ); + } + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ) = 0; + +}; + +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; + +public: + /// @throws css::uno::RuntimeException + CollTestImplHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, bool bIgnoreCase = false ) : ImplBase( xParent, xContext, xIndexAccess, bIgnoreCase ) {} +}; + + +#endif //SC_VBA_COLLECTION_IMPL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbadialogbase.hxx b/include/vbahelper/vbadialogbase.hxx new file mode 100644 index 000000000..3125e5da2 --- /dev/null +++ b/include/vbahelper/vbadialogbase.hxx @@ -0,0 +1,60 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBADIALOGBASE_HXX +#define INCLUDED_VBAHELPER_VBADIALOGBASE_HXX + +#include <exception> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <ooo/vba/XDialogBase.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XDialogBase; + class XHelperInterface; +} + +typedef InheritedHelperInterfaceWeakImpl< ov::XDialogBase > VbaDialogBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaDialogBase : public VbaDialogBase_BASE +{ +protected: + sal_Int32 mnIndex; + css::uno::Reference< css::frame::XModel > m_xModel; +public: + VbaDialogBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel, sal_Int32 nIndex ):VbaDialogBase_BASE( xParent, xContext ), mnIndex( nIndex ), m_xModel( xModel ) {} + + // Methods + virtual void SAL_CALL Show() override; + virtual OUString mapIndexToName( sal_Int32 nIndex ) = 0; +}; + +#endif // INCLUDED_VBAHELPER_VBADIALOGBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbadialogsbase.hxx b/include/vbahelper/vbadialogsbase.hxx new file mode 100644 index 000000000..9b04b40cf --- /dev/null +++ b/include/vbahelper/vbadialogsbase.hxx @@ -0,0 +1,59 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBADIALOGSBASE_HXX +#define INCLUDED_VBAHELPER_VBADIALOGSBASE_HXX + +#include <exception> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <ooo/vba/XDialogsBase.hpp> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XDialogsBase; + class XHelperInterface; +} + +typedef InheritedHelperInterfaceWeakImpl< ov::XDialogsBase > VbaDialogsBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaDialogsBase : public VbaDialogsBase_BASE +{ +protected: + css::uno::Reference< css::frame::XModel > m_xModel; +public: + VbaDialogsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel >& xModel ): VbaDialogsBase_BASE( xParent, xContext ), m_xModel( xModel ) {} + + // XCollection + virtual ::sal_Int32 SAL_CALL getCount() override; + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index ) override; +}; + +#endif // INCLUDED_VBAHELPER_VBADIALOGSBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbadllapi.h b/include/vbahelper/vbadllapi.h new file mode 100644 index 000000000..ff4861de5 --- /dev/null +++ b/include/vbahelper/vbadllapi.h @@ -0,0 +1,34 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_VBAHELPER_VBADLLAPI_H +#define INCLUDED_VBAHELPER_VBADLLAPI_H + +#include <sal/types.h> + +#if defined(VBAHELPER_DLLIMPLEMENTATION) +#define VBAHELPER_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define VBAHELPER_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define VBAHELPER_DLLPRIVATE SAL_DLLPRIVATE + +#endif // INCLUDED_VBAHELPER_VBADLLAPI_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbadocumentbase.hxx b/include/vbahelper/vbadocumentbase.hxx new file mode 100644 index 000000000..60a0bbed9 --- /dev/null +++ b/include/vbahelper/vbadocumentbase.hxx @@ -0,0 +1,87 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBADOCUMENTBASE_HXX +#define INCLUDED_VBAHELPER_VBADOCUMENTBASE_HXX + +#include <exception> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <ooo/vba/XDocumentBase.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XDocumentBase; + class XHelperInterface; +} + +typedef InheritedHelperInterfaceWeakImpl< ooo::vba::XDocumentBase > VbaDocumentBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaDocumentBase : public VbaDocumentBase_BASE +{ +protected: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::uno::XInterface > mxVBProject; +protected: + const css::uno::Reference< css::frame::XModel >& getModel() const { return mxModel; } +public: + VbaDocumentBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::frame::XModel > const & xModel ); + VbaDocumentBase( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); + + // Attributes + virtual OUString SAL_CALL getName() override; + virtual OUString SAL_CALL getPath() override; + virtual OUString SAL_CALL getFullName() override; + virtual sal_Bool SAL_CALL getSaved() override; + virtual void SAL_CALL setSaved( sal_Bool bSave ) override; + virtual css::uno::Any SAL_CALL getVBProject() override; + + // Methods + virtual void SAL_CALL Close( const css::uno::Any &bSaveChanges, + const css::uno::Any &aFileName, + const css::uno::Any &bRouteWorkbook ) override; + /// @throws css::uno::RuntimeException + virtual void SAL_CALL Protect( const css::uno::Any &aPassword ); + virtual void SAL_CALL Unprotect( const css::uno::Any &aPassword ) override; + virtual void SAL_CALL Save() override; + virtual void SAL_CALL Activate() override; + + // XHelperInterface + virtual OUString getServiceImplName() override; + virtual css::uno::Sequence<OUString> getServiceNames() override; + + static OUString getNameFromModel( const css::uno::Reference< css::frame::XModel >& xModel ); +}; + +#endif // INCLUDED_VBAHELPER_VBADOCUMENTBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbadocumentsbase.hxx b/include/vbahelper/vbadocumentsbase.hxx new file mode 100644 index 000000000..3f8acd3e7 --- /dev/null +++ b/include/vbahelper/vbadocumentsbase.hxx @@ -0,0 +1,81 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBADOCUMENTSBASE_HXX +#define INCLUDED_VBAHELPER_VBADOCUMENTSBASE_HXX + +#include <exception> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <ooo/vba/XDocumentsBase.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbacollectionimpl.hxx> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> + +namespace com::sun::star { + namespace beans { struct PropertyValue; } + namespace container { class XEnumeration; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XDocumentsBase; + class XHelperInterface; +} + +typedef CollTestImplHelper< ooo::vba::XDocumentsBase > VbaDocumentsBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaDocumentsBase : public VbaDocumentsBase_BASE +{ +public: + enum DOCUMENT_TYPE + { + WORD_DOCUMENT = 1, + EXCEL_DOCUMENT + }; + +private: + DOCUMENT_TYPE meDocType; + +public: + /// @throws css::uno::RuntimeException + VbaDocumentsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, DOCUMENT_TYPE eDocType ); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() override = 0; + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override = 0; + + // VbaDocumentsBase_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ) override = 0; + +protected: + /// @throws css::uno::RuntimeException + css::uno::Any createDocument(); + /// @throws css::uno::RuntimeException + css::uno::Any openDocument( const OUString& Filename, const css::uno::Any& ReadOnly, const css::uno::Sequence< css::beans::PropertyValue >& rProps ); +}; + +#endif /* SC_ INCLUDED_VBAHELPER_VBADOCUMENTSBASE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbaeventshelperbase.hxx b/include/vbahelper/vbaeventshelperbase.hxx new file mode 100644 index 000000000..0126db442 --- /dev/null +++ b/include/vbahelper/vbaeventshelperbase.hxx @@ -0,0 +1,228 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_VBAHELPER_VBAEVENTSHELPERBASE_HXX +#define INCLUDED_VBAHELPER_VBAEVENTSHELPERBASE_HXX + +#include <deque> +#include <map> +#include <unordered_map> + +#include <com/sun/star/document/XEventListener.hpp> +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/util/XChangesListener.hpp> +#include <cppuhelper/implbase.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> + +namespace com::sun::star { + namespace document { struct EventObject; } + namespace frame { class XModel; } + namespace script::vba { class XVBAModuleInfo; } + namespace uno { class XComponentContext; } + namespace util { struct ChangesEvent; } +} + +class SfxObjectShell; + +typedef ::cppu::WeakImplHelper< + css::script::vba::XVBAEventProcessor, + css::document::XEventListener, + css::util::XChangesListener, + css::lang::XServiceInfo > VbaEventsHelperBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaEventsHelperBase : public VbaEventsHelperBase_BASE +{ +public: + VbaEventsHelperBase( + const css::uno::Sequence< css::uno::Any >& rArgs ); + virtual ~VbaEventsHelperBase() override; + + // script::vba::XVBAEventProcessor + virtual sal_Bool SAL_CALL hasVbaEventHandler( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) override; + virtual sal_Bool SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) override; + + // document::XEventListener + virtual void SAL_CALL notifyEvent( const css::document::EventObject& rEvent ) override; + + // util::XChangesListener + virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& rEvent ) override; + + // lang::XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& rEvent ) override; + + sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; + + // little helpers --------------------------------------------------------- + + /** Helper to execute event handlers without throwing any exceptions. */ + void processVbaEventNoThrow( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ); + + /** @throws css::lang::IllegalArgumentException if the passed sequence does not contain a value at the specified index. */ + static void checkArgument( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) + { if( (nIndex < 0) || (nIndex >= rArgs.getLength()) ) throw css::lang::IllegalArgumentException(); } + + /** @throws css::lang::IllegalArgumentException if the passed sequence does not contain a value of a specific at the specified index. */ + template< typename Type > + static void checkArgumentType( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) + { checkArgument( rArgs, nIndex ); if( !rArgs[ nIndex ].has< Type >() ) throw css::lang::IllegalArgumentException(); } + +protected: + + + struct EventHandlerInfo + { + sal_Int32 mnEventId; + sal_Int32 mnModuleType; + OUString maMacroName; + sal_Int32 mnCancelIndex; + css::uno::Any maUserData; + }; + + /** Registers a supported event handler. + + @param nEventId Event identifier from com.sun.star.script.vba.VBAEventId. + @param nModuleType Type of the module containing the event handler. + @param pcMacroName Name of the associated VBA event handler macro. + @param nCancelIndex 0-based index of Cancel parameter, or -1. + @param rUserData User data for free usage in derived implementations. */ + void registerEventHandler( + sal_Int32 nEventId, + sal_Int32 nModuleType, + const char* pcMacroName, + sal_Int32 nCancelIndex = -1, + const css::uno::Any& rUserData = css::uno::Any() ); + + + struct EventQueueEntry + { + sal_Int32 mnEventId; + css::uno::Sequence< css::uno::Any > maArgs; + /*implicit*/ EventQueueEntry( sal_Int32 nEventId ) : mnEventId( nEventId ) {} + EventQueueEntry( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) : mnEventId( nEventId ), maArgs( rArgs ) {} + }; + typedef ::std::deque< EventQueueEntry > EventQueue; + + /** Derived classes do additional preparations and return whether the + event handler has to be called. + + @throws css::uno::RuntimeException + */ + virtual bool implPrepareEvent( + EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) = 0; + + /** Derived classes have to return the argument list for the specified VBA event handler. + + @throws css::lang::IllegalArgumentException + @throws css::uno::RuntimeException + */ + virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) = 0; + + /** Derived classes may do additional postprocessing. Called even if the + event handler does not exist, or if an error occurred during execution. + + @throws css::uno::RuntimeException + */ + virtual void implPostProcessEvent( + EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, + bool bCancel ) = 0; + + /** Derived classes have to return the name of the Basic document module. + + @throws css::lang::IllegalArgumentException + @throws css::uno::RuntimeException + */ + virtual OUString implGetDocumentModuleName( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) const = 0; + +private: + typedef ::std::map< sal_Int32, OUString > ModulePathMap; + + /** Starts listening at the document model. */ + void startListening(); + /** Stops listening at the document model. */ + void stopListening(); + + /** Returns the event handler info struct for the specified event, or throws. + + + @throws css::lang::IllegalArgumentException + */ + const EventHandlerInfo& getEventHandlerInfo( sal_Int32 nEventId ) const; + + /** Searches the event handler in the document and returns its full script path. + + + @throws css::lang::IllegalArgumentException + @throws css::uno::RuntimeException + */ + OUString getEventHandlerPath( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ); + + /** On first call, accesses the Basic library containing the VBA source code. + + @throws css::uno::RuntimeException + */ + void ensureVBALibrary(); + + /** Returns the type of the Basic module with the specified name. + + @throws css::uno::RuntimeException + */ + sal_Int32 getModuleType( const OUString& rModuleName ); + + /** Updates the map containing paths to event handlers for a Basic module. + + @throws css::uno::RuntimeException + */ + ModulePathMap& updateModulePathMap( const OUString& rModuleName ); + +protected: + css::uno::Reference< css::frame::XModel > mxModel; + SfxObjectShell* mpShell; + +private: + typedef std::map< sal_Int32, EventHandlerInfo > EventHandlerInfoMap; + typedef std::unordered_map< OUString, ModulePathMap > EventHandlerPathMap; + + EventHandlerInfoMap maEventInfos; + EventHandlerPathMap maEventPaths; + css::uno::Reference< css::script::vba::XVBAModuleInfo > mxModuleInfos; + OUString maLibraryName; + bool mbDisposed; +}; + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbafontbase.hxx b/include/vbahelper/vbafontbase.hxx new file mode 100644 index 000000000..732a67bc1 --- /dev/null +++ b/include/vbahelper/vbafontbase.hxx @@ -0,0 +1,112 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBAFONTBASE_HXX +#define INCLUDED_VBAHELPER_VBAFONTBASE_HXX + +#include <exception> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <ooo/vba/XFontBase.hpp> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace beans { class XPropertySet; } + namespace container { class XIndexAccess; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XHelperInterface; +} + +typedef InheritedHelperInterfaceWeakImpl< ov::XFontBase > VbaFontBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaFontBase : public VbaFontBase_BASE +{ +protected: + css::uno::Reference< css::beans::XPropertySet > mxFont; + css::uno::Reference< css::container::XIndexAccess > mxPalette; + bool mbFormControl; + +public: + // use local constants there is no need to expose these constants + // externally. Looking at the Format->Character dialog it seem that + // these may in fact even be calculated. Leave hardcoded for now + // #FIXME #TBD investigate the code for dialog mentioned above + + // The font baseline is not specified. + static const short NORMAL = 0; + + // specifies a superscripted. + static const short SUPERSCRIPT = 33; + + // specifies a subscripted. + static const short SUBSCRIPT = -33; + + // specifies a height of superscripted font + static const sal_Int8 SUPERSCRIPTHEIGHT = 58; + + // specifies a height of subscripted font + static const sal_Int8 SUBSCRIPTHEIGHT = 58; + + // specifies a height of normal font + static const short NORMALHEIGHT = 100; + + /// @throws css::uno::RuntimeException + VbaFontBase( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xPalette, + const css::uno::Reference< css::beans::XPropertySet >& xPropertySet, + bool bFormControl = false ); + virtual ~VbaFontBase() override;// {} + + // Attributes + virtual css::uno::Any SAL_CALL getSize() override; + virtual void SAL_CALL setSize( const css::uno::Any& _size ) override; + virtual css::uno::Any SAL_CALL getColorIndex() override; + virtual void SAL_CALL setColorIndex( const css::uno::Any& _colorindex ) override; + virtual css::uno::Any SAL_CALL getBold() override; + virtual void SAL_CALL setBold( const css::uno::Any& _bold ) override; + virtual css::uno::Any SAL_CALL getUnderline() override = 0; + virtual void SAL_CALL setUnderline( const css::uno::Any& _underline ) override = 0; + virtual css::uno::Any SAL_CALL getStrikethrough() override; + virtual void SAL_CALL setStrikethrough( const css::uno::Any& _strikethrough ) override; + virtual css::uno::Any SAL_CALL getShadow() override; + virtual void SAL_CALL setShadow( const css::uno::Any& _shadow ) override; + virtual css::uno::Any SAL_CALL getItalic() override; + virtual void SAL_CALL setItalic( const css::uno::Any& _italic ) override; + virtual css::uno::Any SAL_CALL getSubscript() override; + virtual void SAL_CALL setSubscript( const css::uno::Any& _subscript ) override; + virtual css::uno::Any SAL_CALL getSuperscript() override; + virtual void SAL_CALL setSuperscript( const css::uno::Any& _superscript ) override; + virtual css::uno::Any SAL_CALL getName() override; + virtual void SAL_CALL setName( const css::uno::Any& _name ) override; + virtual css::uno::Any SAL_CALL getColor() override ; + virtual void SAL_CALL setColor( const css::uno::Any& _color ) override ; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbaglobalbase.hxx b/include/vbahelper/vbaglobalbase.hxx new file mode 100644 index 000000000..6cd5edb72 --- /dev/null +++ b/include/vbahelper/vbaglobalbase.hxx @@ -0,0 +1,64 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBAGLOBALBASE_HXX +#define INCLUDED_VBAHELPER_VBAGLOBALBASE_HXX + +#include <exception> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Exception.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <ooo/vba/XGlobalsBase.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace beans { struct PropertyValue; } + namespace uno { class XComponentContext; } + namespace uno { class XInterface; } +} + +namespace ooo::vba { + class XHelperInterface; +} + +typedef InheritedHelperInterfaceWeakImpl< ov::XGlobalsBase > Globals_BASE; +class VBAHELPER_DLLPUBLIC VbaGlobalsBase : public Globals_BASE +{ + const OUString msDocCtxName; +protected: + bool hasServiceName( const OUString& serviceName ); + void init( const css::uno::Sequence< css::beans::PropertyValue >& aInitArgs ); + +public: + VbaGlobalsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const OUString& sDocCtxName ); + virtual ~VbaGlobalsBase() override; + // XMultiServiceFactory + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const OUString& aServiceSpecifier ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const OUString& ServiceSpecifier, const css::uno::Sequence< css::uno::Any >& Arguments ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames( ) override; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbahelper.hxx b/include/vbahelper/vbahelper.hxx new file mode 100644 index 000000000..6f05013cb --- /dev/null +++ b/include/vbahelper/vbahelper.hxx @@ -0,0 +1,283 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBAHELPER_HXX +#define INCLUDED_VBAHELPER_VBAHELPER_HXX + +#include <memory> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <tools/color.hxx> +#include <vbahelper/vbadllapi.h> +#include <vcl/ptrstyle.hxx> +#include <vcl/errcode.hxx> + +namespace com::sun::star { + namespace awt { class XControl; } + namespace awt { class XDevice; } + namespace awt { class XUnitConversion; } + namespace awt { class XWindow; } + namespace beans { class XIntrospectionAccess; } + namespace beans { class XPropertySet; } + namespace beans { struct PropertyValue; } + namespace drawing { class XShape; } + namespace frame { class XModel; } + namespace script { class XTypeConverter; } + namespace uno { class Exception; } + namespace uno { class XComponentContext; } +} + +class SfxObjectShell; +class SfxViewFrame; +class SfxViewShell; + +namespace ooo +{ + namespace vba + { + /// @throws css::lang::IllegalArgumentException + template < class T > + css::uno::Reference< T > getXSomethingFromArgs( css::uno::Sequence< css::uno::Any > const & args, sal_Int32 nPos, bool bCanBeNull = true ) + { + if ( args.getLength() < ( nPos + 1) ) + throw css::lang::IllegalArgumentException(); + css::uno::Reference< T > aSomething( args[ nPos ], css::uno::UNO_QUERY ); + if ( !bCanBeNull && !aSomething.is() ) + throw css::lang::IllegalArgumentException(); + return aSomething; + } + + class XHelperInterface; + + /** Returns the VBA document implementation object representing the passed UNO document model. */ + VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getVBADocument( const css::uno::Reference< css::frame::XModel >& xModel ); + VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getUnoDocModule( const OUString& aModName, SfxObjectShell const * pShell ); + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel ); + + /// @throws css::uno::RuntimeException + css::uno::Reference< css::frame::XModel > getCurrentDoc( const OUString& sKey ); + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ); + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ); + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ); + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ); + + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC css::uno::Reference< css::beans::XIntrospectionAccess > getIntrospectionAccess( const css::uno::Any& aObject ); + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > const & getTypeConverter( const css::uno::Reference< css::uno::XComponentContext >& xContext ); + + VBAHELPER_DLLPUBLIC void dispatchRequests( const css::uno::Reference< css::frame::XModel>& xModel, const OUString& aUrl ); + VBAHELPER_DLLPUBLIC void dispatchRequests (const css::uno::Reference< css::frame::XModel>& xModel, const OUString & aUrl, const css::uno::Sequence< css::beans::PropertyValue >& sProps ); + VBAHELPER_DLLPUBLIC void dispatchExecute(SfxViewShell const * pView, sal_uInt16 nSlot ); + VBAHELPER_DLLPUBLIC sal_Int32 OORGBToXLRGB( sal_Int32 ); + inline sal_Int32 OORGBToXLRGB( ::Color n ) { return OORGBToXLRGB(sal_Int32(n)); } + VBAHELPER_DLLPUBLIC sal_Int32 XLRGBToOORGB( sal_Int32 ); + VBAHELPER_DLLPUBLIC css::uno::Any OORGBToXLRGB( const css::uno::Any& ); + VBAHELPER_DLLPUBLIC css::uno::Any XLRGBToOORGB( const css::uno::Any& ); + // provide a NULL object that can be passed as variant so that + // the object when passed to IsNull will return true. aNULL + // contains an empty object reference + VBAHELPER_DLLPUBLIC const css::uno::Any& aNULL(); + VBAHELPER_DLLPUBLIC void PrintOutHelper( SfxViewShell const * pViewShell, const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName, bool bSelection ); + VBAHELPER_DLLPUBLIC void PrintPreviewHelper( const css::uno::Any& EnableChanges, SfxViewShell const * ); + VBAHELPER_DLLPUBLIC void WaitUntilPreviewIsClosed( SfxViewFrame* ); + + /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value. + @throws css::uno::RuntimeException if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny ); + + /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string. + @throws css::uno::RuntimeException if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC OUString extractStringFromAny( const css::uno::Any& rAny, bool bUppercaseBool = false ); + /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string. + Returns rDefault, if rAny is empty. + @throws css::uno::RuntimeException if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC OUString extractStringFromAny( const css::uno::Any& rAny, const OUString& rDefault, bool bUppercaseBool ); + + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC OUString getAnyAsString( const css::uno::Any& pvargItem ); + VBAHELPER_DLLPUBLIC OUString VBAToRegexp(const OUString &rIn); // needs to be in a uno service ( already this code is duplicated in basic ) + VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, bool bVertical); + VBAHELPER_DLLPUBLIC double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, bool bVertical); + VBAHELPER_DLLPUBLIC double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, bool bVertical); + VBAHELPER_DLLPUBLIC sal_Int32 PointsToHmm( double fPoints ); + VBAHELPER_DLLPUBLIC double HmmToPoints( sal_Int32 nHmm ); + VBAHELPER_DLLPUBLIC PointerStyle getPointerStyle( const css::uno::Reference< css::frame::XModel >& ); + VBAHELPER_DLLPUBLIC void setCursorHelper( const css::uno::Reference< css::frame::XModel >& xModel, PointerStyle nPointer, bool bOverWrite ); + /// @throws css::uno::RuntimeException + VBAHELPER_DLLPUBLIC void setDefaultPropByIntrospection( const css::uno::Any& aObj, const css::uno::Any& aValue ); + VBAHELPER_DLLPUBLIC css::uno::Any getPropertyValue( const css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName ); + VBAHELPER_DLLPUBLIC bool setPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue ); + VBAHELPER_DLLPUBLIC void setOrAppendPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const OUString& aName, const css::uno::Any& aValue ); + +class VBAHELPER_DLLPUBLIC Millimeter +{ +//Factor to translate between points and hundredths of millimeters: +private: + double m_nMillimeter; + +public: + Millimeter(); + + Millimeter(double mm); + + void setInPoints(double points) ; + double getInHundredthsOfOneMillimeter() const; + static sal_Int32 getInHundredthsOfOneMillimeter(double points); + static double getInPoints(int _hmm); +}; + +class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace the ShapeHelper below +{ +public: + virtual ~AbstractGeometryAttributes() {} + virtual double getLeft() const = 0; + virtual void setLeft( double ) = 0; + virtual double getTop() const = 0; + virtual void setTop( double ) = 0; + virtual double getHeight() const = 0; + virtual void setHeight( double ) = 0; + virtual double getWidth() const = 0; + virtual void setWidth( double ) = 0; + + virtual double getInnerHeight() const { return 0.0; } + virtual void setInnerHeight( double ) {} + virtual double getInnerWidth() const { return 0.0; } + virtual void setInnerWidth( double ) {} + virtual double getOffsetX() const { return 0.0; } + virtual double getOffsetY() const { return 0.0; } +}; + +class VBAHELPER_DLLPUBLIC ShapeHelper +{ + css::uno::Reference< css::drawing::XShape > xShape; +public: + /// @throws css::script::BasicErrorException + /// @throws css::uno::RuntimeException + ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape); + + double getHeight() const; + void setHeight(double _fheight); + double getWidth() const; + void setWidth(double _fWidth); + double getLeft() const; + void setLeft(double _fLeft); + double getTop() const; + void setTop(double _fTop); +}; + +class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes final : public AbstractGeometryAttributes +{ + std::unique_ptr< ShapeHelper > m_pShapeHelper; +public: + ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::drawing::XShape >& xShape ); + virtual double getLeft() const override; + virtual void setLeft( double nLeft ) override; + virtual double getTop() const override; + virtual void setTop( double nTop ) override; + virtual double getHeight() const override; + virtual void setHeight( double nHeight ) override; + virtual double getWidth() const override; + virtual void setWidth( double nWidth) override; + virtual ~ConcreteXShapeGeometryAttributes() override; +}; + +#define VBA_LEFT "PositionX" +#define VBA_TOP "PositionY" + +class VBAHELPER_DLLPUBLIC UserFormGeometryHelper final : public AbstractGeometryAttributes +{ +public: + UserFormGeometryHelper( + const css::uno::Reference< css::awt::XControl >& xControl, + double fOffsetX, double fOffsetY ); + virtual double getLeft() const override; + virtual void setLeft( double fLeft ) override; + virtual double getTop() const override; + virtual void setTop( double fTop ) override; + virtual double getWidth() const override; + virtual void setWidth( double fWidth ) override; + virtual double getHeight() const override; + virtual void setHeight( double fHeight ) override; + virtual double getInnerWidth() const override; + virtual void setInnerWidth( double fWidth ) override; + virtual double getInnerHeight() const override; + virtual void setInnerHeight( double fHeight ) override; + virtual double getOffsetX() const override; + virtual double getOffsetY() const override; + +private: + double implGetPos( bool bPosY ) const; + void implSetPos( double fPos, bool bPosY ); + double implGetSize( bool bHeight, bool bOuter ) const; + void implSetSize( double fSize, bool bHeight, bool bOuter ); + +private: + css::uno::Reference< css::awt::XWindow > mxWindow; + css::uno::Reference< css::beans::XPropertySet > mxModelProps; + css::uno::Reference< css::awt::XUnitConversion > mxUnitConv; + double mfOffsetX; + double mfOffsetY; + bool mbDialog; +}; + +class VBAHELPER_DLLPUBLIC ContainerUtilities +{ + +public: + static OUString getUniqueName( const css::uno::Sequence< OUString >& _slist, const OUString& _sElementName, const OUString& _sSuffixSeparator); + static OUString getUniqueName( const css::uno::Sequence< OUString >& _slist, const OUString& _sElementName, const OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix ); + + static sal_Int32 FieldInList( const css::uno::Sequence< OUString >& SearchList, const OUString& SearchString ); +}; + +// really just a place holder to ease the porting pain +class VBAHELPER_DLLPUBLIC DebugHelper +{ +public: + /// @throws css::script::BasicErrorException + static void basicexception( const css::uno::Exception& ex, ErrCode err, const OUString& /*additionalArgument*/ ); + + /// @throws css::script::BasicErrorException + static void basicexception( ErrCode err, const OUString& additionalArgument ); + + /// @throws css::script::BasicErrorException + static void basicexception( const css::uno::Exception& ex ); + + /// @throws css::script::BasicErrorException + static void runtimeexception( ErrCode err ); +}; + + } // vba +} // ooo + +namespace ov = ooo::vba; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbahelperinterface.hxx b/include/vbahelper/vbahelperinterface.hxx new file mode 100644 index 000000000..5feb4ab83 --- /dev/null +++ b/include/vbahelper/vbahelperinterface.hxx @@ -0,0 +1,147 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBAHELPERINTERFACE_HXX +#define INCLUDED_VBAHELPER_VBAHELPERINTERFACE_HXX + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/weakref.hxx> +#include <ooo/vba/XHelperInterface.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbahelper.hxx> + +// use this class when you have an object like +// interface XAnInterface which contains XHelperInterface in its inheritance hierarchy +// interface XAnInterface +// { +// interface XHelperInterface; +// [attribute, string] name; +// } +// or +// interface XAnInterface : XHelperInterface; +// { +// [attribute, string] name; +// } +// +// then this class can provide a default implementation of XHelperInterface, +// you can use it like this +// typedef InheritedHelperInterfaceImpl< XAnInterface > > AnInterfaceImpl_BASE; +// class AnInterfaceImpl : public AnInterfaceImpl_BASE +// { +// public: +// AnInterface( const Reference< HelperInterface >& xParent ) : AnInterfaceImpl_BASE( xParent ) {} +// // implement XAnInterface methods only, no need to implement the XHelperInterface +// // methods +// virtual void setName( const OUString& ); +// virtual OUString getName(); +// } +// + +template< typename... Ifc > +class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceImpl : public Ifc... +{ +protected: + css::uno::WeakReference< ov::XHelperInterface > mxParent; + css::uno::Reference< css::uno::XComponentContext > mxContext; +public: + InheritedHelperInterfaceImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxParent( xParent ), mxContext( xContext ) {} + virtual OUString getServiceImplName() = 0; + virtual css::uno::Sequence<OUString> getServiceNames() = 0; + + // XHelperInterface Methods + virtual ::sal_Int32 SAL_CALL getCreator() override + { + return 0x53756E4F; + } + virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) override { return mxParent; } + + virtual css::uno::Any SAL_CALL Application( ) override { + // The application could certainly be passed around in the context - seems + // to make sense + css::uno::Reference< css::container::XNameAccess > xNameAccess( mxContext, css::uno::UNO_QUERY_THROW ); + return xNameAccess->getByName( "Application" ); + } + + // XServiceInfo Methods + virtual OUString SAL_CALL getImplementationName( ) override { return getServiceImplName(); } + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override + { + css::uno::Sequence< OUString > sServices = getSupportedServiceNames(); + const OUString* pStart = sServices.getConstArray(); + const OUString* pEnd = pStart + sServices.getLength(); + for ( ; pStart != pEnd ; ++pStart ) + if ( *pStart == ServiceName ) + return true; + return false; + } + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override + { + css::uno::Sequence< OUString > aNames = getServiceNames(); + return aNames; + } + }; + +template <typename... Ifc > +class SAL_DLLPUBLIC_TEMPLATE InheritedHelperInterfaceWeakImpl : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper< Ifc... > > +{ + typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper< Ifc... > > Base; +public: + InheritedHelperInterfaceWeakImpl< Ifc... >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} +}; + + +/** Helper macro to declare the methods 'getServiceImplName()' and + 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface in a class + declaration. + */ +#define VBAHELPER_DECL_XHELPERINTERFACE \ + virtual OUString getServiceImplName() override; \ + virtual css::uno::Sequence< OUString > getServiceNames() override; + + +/** Helper macro to implement the methods 'getServiceImplName()' and + 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface. Will + return the class name as service implementation name. + */ +#define VBAHELPER_IMPL_XHELPERINTERFACE( classname, servicename ) \ +OUString classname::getServiceImplName() \ +{ \ + return #classname; \ +} \ +css::uno::Sequence< OUString > classname::getServiceNames() \ +{ \ + static css::uno::Sequence< OUString > saServiceNames; \ + if( saServiceNames.getLength() == 0 ) \ + { \ + saServiceNames.realloc( 1 ); \ + saServiceNames[ 0 ] = servicename; \ + } \ + return saServiceNames; \ +} + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbapagesetupbase.hxx b/include/vbahelper/vbapagesetupbase.hxx new file mode 100644 index 000000000..c1b466836 --- /dev/null +++ b/include/vbahelper/vbapagesetupbase.hxx @@ -0,0 +1,79 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBAPAGESETUPBASE_HXX +#define INCLUDED_VBAHELPER_VBAPAGESETUPBASE_HXX + +#include <exception> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <ooo/vba/XPageSetupBase.hpp> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace beans { class XPropertySet; } + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XHelperInterface; +} + +typedef InheritedHelperInterfaceWeakImpl< ooo::vba::XPageSetupBase > VbaPageSetupBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaPageSetupBase : public VbaPageSetupBase_BASE +{ +protected: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::beans::XPropertySet > mxPageProps; + sal_Int32 mnOrientLandscape; + sal_Int32 mnOrientPortrait; + + /// @throws css::uno::RuntimeException + VbaPageSetupBase( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext ); +public: + + // Attribute + virtual double SAL_CALL getTopMargin() override; + virtual void SAL_CALL setTopMargin( double margin ) override; + virtual double SAL_CALL getBottomMargin() override; + virtual void SAL_CALL setBottomMargin( double margin ) override; + virtual double SAL_CALL getRightMargin() override; + virtual void SAL_CALL setRightMargin( double margin ) override; + virtual double SAL_CALL getLeftMargin() override; + virtual void SAL_CALL setLeftMargin( double margin ) override; + /// @throws css::uno::RuntimeException + virtual double SAL_CALL getHeaderMargin(); + /// @throws css::uno::RuntimeException + virtual void SAL_CALL setHeaderMargin( double margin ); + /// @throws css::uno::RuntimeException + virtual double SAL_CALL getFooterMargin(); + /// @throws css::uno::RuntimeException + virtual void SAL_CALL setFooterMargin( double margin ); + virtual sal_Int32 SAL_CALL getOrientation() override; + virtual void SAL_CALL setOrientation( sal_Int32 orientation ) override; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbapropvalue.hxx b/include/vbahelper/vbapropvalue.hxx new file mode 100644 index 000000000..ee6443f08 --- /dev/null +++ b/include/vbahelper/vbapropvalue.hxx @@ -0,0 +1,59 @@ +/* -*- 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 . + */ +#ifndef SC_VBA_PROPVALULE_HXX +#define SC_VBA_PROPVALULE_HXX + +#include <exception> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <cppuhelper/implbase.hxx> +#include <ooo/vba/XPropValue.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> + +class VBAHELPER_DLLPUBLIC PropListener +{ +public: + virtual void setValueEvent( const css::uno::Any& value ) = 0; + virtual css::uno::Any getValueEvent() = 0; + +protected: + ~PropListener() {} +}; + + +class VBAHELPER_DLLPUBLIC ScVbaPropValue final : public ::cppu::WeakImplHelper< ov::XPropValue > +{ + PropListener* m_pListener; +public: + ScVbaPropValue( PropListener* pListener ); + + // Attributes + virtual css::uno::Any SAL_CALL getValue() override; + virtual void SAL_CALL setValue( const css::uno::Any& _value ) override; + + OUString SAL_CALL getDefaultPropertyName() override { return "Value"; } + +}; +#endif //SC_VBA_PROPVALULE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbareturntypes.hxx b/include/vbahelper/vbareturntypes.hxx new file mode 100644 index 000000000..7893a72cd --- /dev/null +++ b/include/vbahelper/vbareturntypes.hxx @@ -0,0 +1,57 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBARETURNTYPES_HXX +#define INCLUDED_VBAHELPER_VBARETURNTYPES_HXX + +#include <com/sun/star/script/XDefaultProperty.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <cppuhelper/implbase.hxx> +#include <ooo/vba/msforms/XReturnInteger.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbahelper.hxx> + +namespace ooo +{ + namespace vba + { + template< typename T1, typename T2 > + class DefaultReturnHelper : public ::cppu::WeakImplHelper< T2, css::script::XDefaultProperty > + { + T1 mnValue; + public: + DefaultReturnHelper( const T1& nValue ) : mnValue( nValue ) {} + virtual void SAL_CALL setValue( T1 nValue ) override { mnValue = nValue; } + virtual T1 SAL_CALL getValue() override { return mnValue; } + OUString SAL_CALL getDefaultPropertyName( ) override { return "Value"; } + }; + + typedef DefaultReturnHelper< sal_Int32, ov::msforms::XReturnInteger > ReturnInteger_BASE; + class ReturnInteger final : public ReturnInteger_BASE + { + public: + ReturnInteger( sal_Int32 nValue ) : ReturnInteger_BASE( nValue ){} + }; + + } // vba +} // ooo + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbashape.hxx b/include/vbahelper/vbashape.hxx new file mode 100644 index 000000000..d6a79968b --- /dev/null +++ b/include/vbahelper/vbashape.hxx @@ -0,0 +1,136 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBASHAPE_HXX +#define INCLUDED_VBAHELPER_VBASHAPE_HXX + +#include <exception> +#include <memory> + +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <ooo/vba/msforms/XShape.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace beans { class XPropertySet; } + namespace drawing { class XShape; } + namespace drawing { class XShapes; } + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class ShapeHelper; + class XHelperInterface; + namespace msforms { class XFillFormat; } + namespace msforms { class XLineFormat; } + namespace msforms { class XPictureFormat; } +} + +typedef ::cppu::WeakImplHelper< ov::msforms::XShape, css::lang::XEventListener > ListeningShape; + +typedef InheritedHelperInterfaceImpl< ListeningShape > ScVbaShape_BASE; + +class VBAHELPER_DLLPUBLIC ScVbaShape : public ScVbaShape_BASE +{ +protected: + std::unique_ptr< ov::ShapeHelper > m_pShapeHelper; + css::uno::Reference< css::drawing::XShape > m_xShape; + css::uno::Reference< css::drawing::XShapes > m_xShapes; + css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; + sal_Int32 m_nType; + css::uno::Reference< css::frame::XModel > m_xModel; + void addListeners(); + /// @throws css::uno::RuntimeException + void removeShapeListener(); + /// @throws css::uno::RuntimeException + void removeShapesListener(); + virtual OUString getServiceImplName() override; + virtual css::uno::Sequence<OUString> getServiceNames() override; +public: + /// @throws css::lang::IllegalArgumentException + /// @throws css::uno::RuntimeException + ScVbaShape( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::drawing::XShapes >& xShapes, const css::uno::Reference< css::frame::XModel >& xModel, sal_Int32 nType ); + virtual ~ScVbaShape() override; + + /// @throws css::uno::RuntimeException + static sal_Int32 getType( const css::uno::Reference< css::drawing::XShape >& rShape ); + + static sal_Int32 getAutoShapeType( const css::uno::Reference< css::drawing::XShape >& rShape ); + + // Attributes + virtual OUString SAL_CALL getName() override; + virtual void SAL_CALL setName( const OUString& _name ) override; + virtual OUString SAL_CALL getAlternativeText() override; + virtual void SAL_CALL setAlternativeText( const OUString& _name ) override; + virtual double SAL_CALL getHeight() override; + virtual void SAL_CALL setHeight(double _height) override; + virtual double SAL_CALL getWidth() override; + virtual void SAL_CALL setWidth(double _width) override; + virtual double SAL_CALL getLeft() override; + virtual void SAL_CALL setLeft( double _left ) override; + virtual double SAL_CALL getTop() override; + virtual void SAL_CALL setTop( double _top ) override; + virtual sal_Bool SAL_CALL getVisible() override; + virtual void SAL_CALL setVisible( sal_Bool _visible ) override; + virtual sal_Int32 SAL_CALL getZOrderPosition() override; + virtual sal_Int32 SAL_CALL getType() override; + virtual double SAL_CALL getRotation() override; + virtual void SAL_CALL setRotation( double _rotation ) override; + virtual css::uno::Reference< ov::msforms::XLineFormat > SAL_CALL getLine() override; + virtual css::uno::Reference< ov::msforms::XFillFormat > SAL_CALL getFill() override; + virtual css::uno::Reference< ov::msforms::XPictureFormat > SAL_CALL getPictureFormat() override; + virtual sal_Bool SAL_CALL getLockAspectRatio() override; + virtual void SAL_CALL setLockAspectRatio( sal_Bool _lockaspectratio ) override; + virtual sal_Bool SAL_CALL getLockAnchor() override; + virtual void SAL_CALL setLockAnchor( sal_Bool _lockanchor ) override; + virtual ::sal_Int32 SAL_CALL getRelativeHorizontalPosition() override; + virtual void SAL_CALL setRelativeHorizontalPosition(::sal_Int32 _relativehorizontalposition) override; + virtual ::sal_Int32 SAL_CALL getRelativeVerticalPosition() override; + virtual void SAL_CALL setRelativeVerticalPosition(::sal_Int32 _relativeverticalposition) override; + + // Methods + virtual css::uno::Any SAL_CALL TextFrame( ) override; + virtual css::uno::Any SAL_CALL WrapFormat( ) override; + virtual void SAL_CALL Delete() override; + virtual void SAL_CALL ZOrder( sal_Int32 ZOrderCmd ) override; + virtual void SAL_CALL IncrementRotation( double Increment ) override; + virtual void SAL_CALL IncrementLeft( double Increment ) override; + virtual void SAL_CALL IncrementTop( double Increment ) override; + virtual void SAL_CALL ScaleHeight( double Factor, sal_Bool RelativeToOriginalSize, sal_Int32 Scale ) override; + virtual void SAL_CALL ScaleWidth( double Factor, sal_Bool RelativeToOriginalSize, sal_Int32 Scale ) override; + // Replace?? + virtual void SAL_CALL Select( const css::uno::Any& Replace ) override; + virtual css::uno::Any SAL_CALL ShapeRange( const css::uno::Any& index ) override; + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& rEventObject ) override; +}; +#endif // INCLUDED_VBAHELPER_VBASHAPE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbashaperange.hxx b/include/vbahelper/vbashaperange.hxx new file mode 100644 index 000000000..54a052cac --- /dev/null +++ b/include/vbahelper/vbashaperange.hxx @@ -0,0 +1,105 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBASHAPERANGE_HXX +#define INCLUDED_VBAHELPER_VBASHAPERANGE_HXX + +#include <exception> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <ooo/vba/msforms/XShapeRange.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbacollectionimpl.hxx> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> + +namespace com::sun::star { + namespace container { class XEnumeration; } + namespace container { class XIndexAccess; } + namespace drawing { class XDrawPage; } + namespace drawing { class XShapes; } + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XHelperInterface; + namespace msforms { class XFillFormat; } + namespace msforms { class XLineFormat; } + namespace msforms { class XShape; } +} + +typedef CollTestImplHelper< ov::msforms::XShapeRange > ScVbaShapeRange_BASE; + +class VBAHELPER_DLLPUBLIC ScVbaShapeRange final : public ScVbaShapeRange_BASE +{ +private: + css::uno::Reference< css::drawing::XDrawPage > m_xDrawPage; + css::uno::Reference< css::drawing::XShapes > m_xShapes; + css::uno::Reference< css::frame::XModel > m_xModel; + virtual OUString getServiceImplName() override; + virtual css::uno::Sequence<OUString> getServiceNames() override; + /// @throws css::uno::RuntimeException + css::uno::Reference< css::drawing::XShapes > const & getShapes() ; +public: + ScVbaShapeRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xShapes, const css::uno::Reference< css::drawing::XDrawPage>& xDrawShape, const css::uno::Reference< css::frame::XModel >& xModel ); + + // Methods + virtual void SAL_CALL Select( ) override; + virtual css::uno::Reference< ::ooo::vba::msforms::XShape > SAL_CALL Group() override; + virtual void SAL_CALL IncrementRotation( double Increment ) override; + virtual void SAL_CALL IncrementLeft( double Increment ) override ; + virtual void SAL_CALL IncrementTop( double Increment ) override; + virtual OUString SAL_CALL getName() override; + virtual void SAL_CALL setName( const OUString& _name ) override; + virtual double SAL_CALL getHeight() override; + virtual void SAL_CALL setHeight( double _height ) override; + virtual double SAL_CALL getWidth() override; + virtual void SAL_CALL setWidth( double _width ) override; + virtual double SAL_CALL getLeft() override; + virtual void SAL_CALL setLeft( double _left ) override; + virtual double SAL_CALL getTop() override; + virtual void SAL_CALL setTop( double _top ) override; + virtual css::uno::Reference< ov::msforms::XLineFormat > SAL_CALL getLine() override; + virtual css::uno::Reference< ov::msforms::XFillFormat > SAL_CALL getFill() override; + virtual sal_Bool SAL_CALL getLockAspectRatio() override; + virtual void SAL_CALL setLockAspectRatio( sal_Bool _lockaspectratio ) override; + virtual sal_Bool SAL_CALL getLockAnchor() override; + virtual void SAL_CALL setLockAnchor( sal_Bool _lockanchor ) override; + virtual ::sal_Int32 SAL_CALL getRelativeHorizontalPosition() override; + virtual void SAL_CALL setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) override; + virtual ::sal_Int32 SAL_CALL getRelativeVerticalPosition() override; + virtual void SAL_CALL setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) override; + virtual css::uno::Any SAL_CALL TextFrame( ) override; + virtual css::uno::Any SAL_CALL WrapFormat( ) override; + virtual void SAL_CALL ZOrder( sal_Int32 ZOrderCmd ) override; + //XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() override; + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override; + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ) override; +}; + +#endif // INCLUDED_VBAHELPER_VBASHAPERANGE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbashapes.hxx b/include/vbahelper/vbashapes.hxx new file mode 100644 index 000000000..cc8cdcdf1 --- /dev/null +++ b/include/vbahelper/vbashapes.hxx @@ -0,0 +1,99 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBASHAPES_HXX +#define INCLUDED_VBAHELPER_VBASHAPES_HXX + +#include <exception> + +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <ooo/vba/msforms/XShapes.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbacollectionimpl.hxx> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> + +namespace com::sun::star { + namespace container { class XEnumeration; } + namespace container { class XIndexAccess; } + namespace drawing { class XDrawPage; } + namespace drawing { class XShape; } + namespace drawing { class XShapes; } + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XHelperInterface; + namespace msforms { class XShapeRange; } +} + +typedef CollTestImplHelper< ov::msforms::XShapes > ScVbaShapes_BASE; + +class VBAHELPER_DLLPUBLIC ScVbaShapes final : public ScVbaShapes_BASE +{ +private: + css::uno::Reference< css::drawing::XShapes > m_xShapes; + css::uno::Reference< css::drawing::XDrawPage > m_xDrawPage; + sal_Int32 m_nNewShapeCount; + void initBaseCollection(); + css::uno::Reference< css::frame::XModel > m_xModel; + virtual OUString getServiceImplName() override; + virtual css::uno::Sequence<OUString> getServiceNames() override; + /// @throws css::uno::RuntimeException + css::uno::Reference< css::container::XIndexAccess > getShapesByArrayIndices( const css::uno::Any& Index ); + /// @throws css::uno::RuntimeException + css::uno::Reference< css::drawing::XShape > createShape( const OUString& service ); + /// @throws css::uno::RuntimeException + css::uno::Any AddRectangle( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight ); + /// @throws css::uno::RuntimeException + css::uno::Any AddEllipse( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight ); + /// @throws css::uno::RuntimeException + css::uno::Any AddTextboxInWriter( sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ); + OUString createName( const OUString& sName ); + //TODO helperapi using a writer document + //css::awt::Point calculateTopLeftMargin( css::uno::Reference< ov::XHelperInterface > xDocument ); + +public: + ScVbaShapes( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xShapes, const css::uno::Reference< css::frame::XModel >& xModel ); + /// @throws css::uno::RuntimeException + static void setDefaultShapeProperties( const css::uno::Reference< css::drawing::XShape >& xShape ); + static void setShape_NameProperty( const css::uno::Reference< css::drawing::XShape >& xShape, const OUString& sName ); + //XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() override; + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override; + + virtual void SAL_CALL SelectAll() override; + //helper::calc + virtual css::uno::Any SAL_CALL AddLine( sal_Int32 StartX, sal_Int32 StartY, sal_Int32 endX, sal_Int32 endY ) override; + virtual css::uno::Any SAL_CALL AddShape( sal_Int32 _nType, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) override; + virtual css::uno::Any SAL_CALL AddTextbox( sal_Int32 _nOrientation, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) override; + virtual css::uno::Reference< ov::msforms::XShapeRange > SAL_CALL Range( const css::uno::Any& shapes ) override; + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ) override; +}; + +#endif // INCLUDED_VBAHELPER_VBASHAPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbatextframe.hxx b/include/vbahelper/vbatextframe.hxx new file mode 100644 index 000000000..a93c511a8 --- /dev/null +++ b/include/vbahelper/vbatextframe.hxx @@ -0,0 +1,79 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_VBAHELPER_VBATEXTFRAME_HXX +#define INCLUDED_VBAHELPER_VBATEXTFRAME_HXX + +#include <exception> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <ooo/vba/msforms/XTextFrame.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace beans { class XPropertySet; } + namespace drawing { class XShape; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XHelperInterface; +} + +typedef InheritedHelperInterfaceWeakImpl< ov::msforms::XTextFrame > VbaTextFrame_BASE; + +class VBAHELPER_DLLPUBLIC VbaTextFrame : public VbaTextFrame_BASE +{ +protected: + css::uno::Reference< css::drawing::XShape > m_xShape; + css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; +protected: + virtual OUString getServiceImplName() override; + virtual css::uno::Sequence<OUString> getServiceNames() override; + void setAsMSObehavior(); + sal_Int32 getMargin( const OUString& sMarginType ); + void setMargin( const OUString& sMarginType, float fMargin ); +public: + VbaTextFrame( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext , css::uno::Reference< css::drawing::XShape > const & xShape); + // Attributes + virtual sal_Bool SAL_CALL getAutoSize() override; + virtual void SAL_CALL setAutoSize( sal_Bool _autosize ) override; + virtual float SAL_CALL getMarginBottom() override; + virtual void SAL_CALL setMarginBottom( float _marginbottom ) override; + virtual float SAL_CALL getMarginTop() override; + virtual void SAL_CALL setMarginTop( float _margintop ) override; + virtual float SAL_CALL getMarginLeft() override; + virtual void SAL_CALL setMarginLeft( float _marginleft ) override; + virtual float SAL_CALL getMarginRight() override; + virtual void SAL_CALL setMarginRight( float _marginright ) override; + + // Methods + virtual css::uno::Any SAL_CALL Characters( ) override; + +}; + +#endif//SC_ INCLUDED_VBAHELPER_VBATEXTFRAME_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vbahelper/vbawindowbase.hxx b/include/vbahelper/vbawindowbase.hxx new file mode 100644 index 000000000..bf2c6460c --- /dev/null +++ b/include/vbahelper/vbawindowbase.hxx @@ -0,0 +1,101 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_VBAHELPER_VBAWINDOWBASE_HXX +#define INCLUDED_VBAHELPER_VBAWINDOWBASE_HXX + +#include <exception> + +#include <cppuhelper/weakref.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <ooo/vba/XWindowBase.hpp> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <vbahelper/vbadllapi.h> +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace com::sun::star { + namespace awt { class XWindow2; } + namespace awt { class XWindow; } + namespace frame { class XController; } + namespace frame { class XModel; } + namespace uno { class XComponentContext; } +} + +namespace ooo::vba { + class XHelperInterface; +} + +typedef InheritedHelperInterfaceWeakImpl< ov::XWindowBase > WindowBaseImpl_BASE; + +class VBAHELPER_DLLPUBLIC VbaWindowBase : public WindowBaseImpl_BASE +{ +public: + /// @throws css::uno::RuntimeException + VbaWindowBase( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const css::uno::Reference< css::frame::XController >& xController ); + /// @throws css::uno::RuntimeException + VbaWindowBase( + css::uno::Sequence< css::uno::Any > const& aArgs, + css::uno::Reference< css::uno::XComponentContext > const& xContext ); + + // XWindowBase + virtual sal_Int32 SAL_CALL getHeight() override ; + virtual void SAL_CALL setHeight( sal_Int32 _height ) override ; + virtual sal_Int32 SAL_CALL getLeft() override ; + virtual void SAL_CALL setLeft( sal_Int32 _left ) override ; + virtual sal_Int32 SAL_CALL getTop() override ; + virtual void SAL_CALL setTop( sal_Int32 _top ) override ; + virtual sal_Bool SAL_CALL getVisible() override; + virtual void SAL_CALL setVisible( sal_Bool _visible ) override; + virtual sal_Int32 SAL_CALL getWidth() override ; + virtual void SAL_CALL setWidth( sal_Int32 _width ) override ; + + // XHelperInterface + virtual OUString getServiceImplName() override; + virtual css::uno::Sequence<OUString> getServiceNames() override; + +protected: + /// @throws css::uno::RuntimeException + css::uno::Reference< css::frame::XController > getController() const; + /// @throws css::uno::RuntimeException + css::uno::Reference< css::awt::XWindow > getWindow() const; + /// @throws css::uno::RuntimeException + css::uno::Reference< css::awt::XWindow2 > getWindow2() const; + + css::uno::Reference< css::frame::XModel > m_xModel; + +private: + /// @throws css::uno::RuntimeException + void construct( const css::uno::Reference< css::frame::XController >& xController ); + + css::uno::WeakReference< css::frame::XController > m_xController; + css::uno::WeakReference< css::awt::XWindow > m_xWindow; +}; + +#endif // INCLUDED_VBAHELPER_VBAWINDOWBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |