diff options
author | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2011-03-25 10:40:25 +0100 |
---|---|---|
committer | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2011-03-25 10:40:25 +0100 |
commit | b46dab973c91c3a94bcda188a9888fef3fd16426 (patch) | |
tree | ecf2283bed35cbd42e3fb5fb541194d70179e51d /vbahelper/inc | |
parent | 61879c218dd0e6e94884e7c6e06e3c5c18540b4a (diff) |
calcvba: #164410# improve VBA compatibility implementation in various areas: Excel symbols, MSForms symbols, document and forms event handling
Diffstat (limited to 'vbahelper/inc')
-rwxr-xr-x | vbahelper/inc/vbahelper/collectionbase.hxx | 214 | ||||
-rw-r--r-- | vbahelper/inc/vbahelper/vbaapplicationbase.hxx | 1 | ||||
-rw-r--r-- | vbahelper/inc/vbahelper/vbacollectionimpl.hxx | 4 | ||||
-rw-r--r-- | vbahelper/inc/vbahelper/vbadocumentbase.hxx | 1 | ||||
-rwxr-xr-x | vbahelper/inc/vbahelper/vbaeventshelperbase.hxx | 68 | ||||
-rw-r--r-- | vbahelper/inc/vbahelper/vbahelper.hxx | 121 | ||||
-rw-r--r-- | vbahelper/inc/vbahelper/vbawindowbase.hxx | 37 | ||||
-rwxr-xr-x | vbahelper/inc/vbahelper/weakreference.hxx | 94 |
8 files changed, 468 insertions, 72 deletions
diff --git a/vbahelper/inc/vbahelper/collectionbase.hxx b/vbahelper/inc/vbahelper/collectionbase.hxx new file mode 100755 index 000000000000..ebb5bf8f2b9a --- /dev/null +++ b/vbahelper/inc/vbahelper/collectionbase.hxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VBAHELPER_COLLECTIONBASE_HXX +#define VBAHELPER_COLLECTIONBASE_HXX + +#include <vector> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/container/XElementAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <ooo/vba/XCollectionBase.hpp> +#include <cppuhelper/implbase1.hxx> +#include <vbahelper/vbahelper.hxx> + +namespace vbahelper { + +// ============================================================================ + +typedef ::cppu::WeakImplHelper1< ov::XCollectionBase > CollectionBase_BASE; + +/** Base class of VBA objects implementing the VBA collection concept. + + This base class intentionally does not include the interface + XHelperInterface supported by all application VBA object. There may be + other VBA objects that do not support the special methods provided by + XHelperInterface. + */ +class VBAHELPER_DLLPUBLIC CollectionBase : public CollectionBase_BASE +{ +public: + /** Enumerates different container types a VBA collection can be based on. */ + enum ContainerType + { + /** Container elements are VBA items. + + The initial container contains the final VBA items provided by the + VBA collection. No conversion takes place on item access. + */ + CONTAINER_NATIVE_VBA, + + /** Container elements will be converted to VBA items on demand. + + The initial container contains intermediate objects (e.g. UNO + objects) which will be converted to VBA items everytime the item is + accessed (e.g. item access method, enumeration). Changes in the + initial container are reflected by the collection. + */ + CONTAINER_CONVERT_ON_DEMAND, + }; + + // ------------------------------------------------------------------------ + + CollectionBase( const css::uno::Type& rElementType ); + + // ------------------------------------------------------------------------ + + // attributes + virtual sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException); + // XDefaultMethod + virtual ::rtl::OUString SAL_CALL getDefaultMethodName() throw (css::uno::RuntimeException); + + // ------------------------------------------------------------------------ + + /** Associates this collection with the passed UNO container. + + @param rxElementAccess + The UNO container with the elements of this collection. Shall + support either XIndexAccess or XNameAccess, may support both. + + If the container does not support XIndexAccess, index access is + simulated based on the order returned by the function + XNameAccess::getElementNames(). + + If the container does not support XNameAccess, name access is + simulated by iterating the elements via index access and asking the + elements for their name via the interface XNamed. If the elements + do not support XNamed, the elements cannot be accessed by name. + + @param eContainerType + Specifies the type of the passed container. + */ + void initContainer( + const css::uno::Reference< css::container::XElementAccess >& rxElementAccess, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Initializes this collection with copies of all elements in the passed + temporary STL vector. + + @param rElements + The STL vector with the named elements of this collection. + @param eContainerType + Specifies the type of the passed vector. + */ + void initElements( + const ::std::vector< css::uno::Reference< css::container::XNamed > >& rElements, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Initializes this collection with copies of all elements in the passed + temporary STL vector. + + @param rElements + The STL vector with the named elements of this collection. + @param eContainerType + Specifies the type of the passed vector. + */ + void initElements( + const ::std::vector< css::beans::NamedValue >& rElements, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Returns a VBA implementation object from the passed element. + + If the container type is CONTAINER_NATIVE_VBA, returns the passed + object unmodified. If the container type is CONTAINER_CONVERT_ON_DEMAND, + calls the virtual function implCreateCollectionItem() that implements + creation of the VBA implmentation object. + + @param rElement + The container element the VBA implementation object is based on. + + @param rIndex + The index or name that has been used to access the item. + */ + css::uno::Any createCollectionItem( + const css::uno::Any& rElement, + const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its one-based item index. + + @param nIndex + The one-based index of the collection item. + */ + css::uno::Any getItemByIndex( sal_Int32 nIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its name. + + @param rName + The name of the collection item. + */ + css::uno::Any getItemByName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its index or name. + + @param rIndex + The index or name of the collection item. May be empty, in that + case the entire collection is returned. + */ + css::uno::Any getAnyItemOrThis( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item of a specific type specified by its index or + name. + + @param rIndex + The index or name of the collection item. + */ + template< typename XType > + inline css::uno::Reference< XType > getAnyItem( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException) + { css::uno::Any aRet; if( rIndex.hasValue() ) aRet = getAnyItemOrThis( rIndex ); return css::uno::Reference< XType >( aRet, css::uno::UNO_QUERY_THROW ); } + +protected: + /** Derived classes implement creation of a VBA implementation object from + the passed intermediate container element. + + May be kept unimplemented if container type is CONTAINER_NATIVE_VBA. + + @param rElement + The container element the VBA implementation object is based on. + + @param rIndex + The index or name used to access the item. Can be used by + implementations as a hint how to find or convert the VBA object. + */ + virtual css::uno::Any implCreateCollectionItem( const css::uno::Any& rElement, const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + +private: + css::uno::Reference< css::container::XIndexAccess > mxIndexAccess; + css::uno::Reference< css::container::XNameAccess > mxNameAccess; + css::uno::Type maElementType; + bool mbConvertOnDemand; +}; + +// ============================================================================ + +} // namespace vbahelper + +#endif diff --git a/vbahelper/inc/vbahelper/vbaapplicationbase.hxx b/vbahelper/inc/vbahelper/vbaapplicationbase.hxx index 6902bc7b5042..10cf0ba6ab70 100644 --- a/vbahelper/inc/vbahelper/vbaapplicationbase.hxx +++ b/vbahelper/inc/vbahelper/vbaapplicationbase.hxx @@ -60,7 +60,6 @@ public: virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getVersion() throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL getVBE() throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL getVBProjects() throw (css::uno::RuntimeException); virtual void SAL_CALL Run( const ::rtl::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 ) throw (css::uno::RuntimeException); virtual void SAL_CALL OnTime( const css::uno::Any& aEarliestTime, const ::rtl::OUString& aFunction, const css::uno::Any& aLatestTime, const css::uno::Any& aSchedule ) throw (css::uno::RuntimeException); diff --git a/vbahelper/inc/vbahelper/vbacollectionimpl.hxx b/vbahelper/inc/vbahelper/vbacollectionimpl.hxx index 601d996a5e64..da0fd29267ae 100644 --- a/vbahelper/inc/vbahelper/vbacollectionimpl.hxx +++ b/vbahelper/inc/vbahelper/vbacollectionimpl.hxx @@ -88,8 +88,8 @@ private: /** 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 nextElement() needs to be implemented by the derived class. This - class can be used to convert an enumeration or an index container + 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 diff --git a/vbahelper/inc/vbahelper/vbadocumentbase.hxx b/vbahelper/inc/vbahelper/vbadocumentbase.hxx index 2588b7da1720..d1c7320fbfb1 100644 --- a/vbahelper/inc/vbahelper/vbadocumentbase.hxx +++ b/vbahelper/inc/vbahelper/vbadocumentbase.hxx @@ -37,6 +37,7 @@ class VBAHELPER_DLLPUBLIC VbaDocumentBase : public VbaDocumentBase_BASE { protected: css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::uno::XInterface > mxVBProject; protected: virtual css::uno::Reference< css::frame::XModel > getModel() { return mxModel; } VbaDocumentBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext); diff --git a/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx b/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx index 659837535ace..dc554d6a043f 100755 --- a/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx +++ b/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx @@ -28,20 +28,26 @@ #ifndef VBAHELPER_VBAEVENTSHELPERBASE_HXX #define VBAHELPER_VBAEVENTSHELPERBASE_HXX -#include <com/sun/star/lang/XEventListener.hpp> -#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> -#include <cppuhelper/implbase2.hxx> -#include <map> #include <deque> +#include <hash_map> +#include <map> +#include <com/sun/star/document/XEventListener.hpp> +#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> +#include <com/sun/star/util/XChangesListener.hpp> +#include <cppuhelper/implbase3.hxx> #include "vbahelper/vbahelper.hxx" namespace com { namespace sun { namespace star { + namespace script { namespace vba { class XVBAModuleInfo; } } namespace uno { class XComponentContext; } } } } // ============================================================================ -typedef ::cppu::WeakImplHelper2< css::script::vba::XVBAEventProcessor, css::lang::XEventListener > VbaEventsHelperBase_BASE; +typedef ::cppu::WeakImplHelper3< + css::script::vba::XVBAEventProcessor, + css::document::XEventListener, + css::util::XChangesListener > VbaEventsHelperBase_BASE; class VBAHELPER_DLLPUBLIC VbaEventsHelperBase : public VbaEventsHelperBase_BASE { @@ -51,15 +57,24 @@ public: const css::uno::Reference< css::uno::XComponentContext >& xContext ); virtual ~VbaEventsHelperBase(); - // XVBAEventProcessor + // script::vba::XVBAEventProcessor virtual sal_Bool SAL_CALL hasVbaEventHandler( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); - virtual void SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::script::provider::ScriptFrameworkErrorException, css::util::VetoException, css::uno::RuntimeException); + virtual sal_Bool SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::util::VetoException, css::uno::RuntimeException); - // XEventListener - virtual void SAL_CALL disposing( const css::lang::EventObject& aSource ) throw (css::uno::RuntimeException); + // document::XEventListener + virtual void SAL_CALL notifyEvent( const css::document::EventObject& rEvent ) throw (css::uno::RuntimeException); + + // util::XChangesListener + virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& rEvent ) throw (css::uno::RuntimeException); + + // lang::XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& rEvent ) throw (css::uno::RuntimeException); // 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, if the passed sequence does not contain a value at the specified index. */ static inline void checkArgument( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException) { if( (nIndex < 0) || (nIndex >= rArgs.getLength()) ) throw css::lang::IllegalArgumentException(); } @@ -72,12 +87,11 @@ public: protected: // ------------------------------------------------------------------------ - enum EventHandlerType { EVENTHANDLER_GLOBAL, EVENTHANDLER_DOCUMENT }; struct EventHandlerInfo { sal_Int32 mnEventId; + sal_Int32 mnModuleType; ::rtl::OUString maMacroName; - EventHandlerType meType; sal_Int32 mnCancelIndex; css::uno::Any maUserData; }; @@ -85,14 +99,14 @@ protected: /** 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 eType Document event or global event. @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 sal_Char* pcMacroName, - EventHandlerType eType = EVENTHANDLER_DOCUMENT, sal_Int32 nCancelIndex = -1, const css::uno::Any& rUserData = css::uno::Any() ); @@ -124,7 +138,6 @@ protected: virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, - bool bSuccess, bool bCancel ) throw (css::uno::RuntimeException) = 0; /** Derived classes have to return the name of the Basic document module. */ @@ -133,25 +146,42 @@ protected: const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException) = 0; private: + typedef ::std::map< sal_Int32, ::rtl::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. */ const EventHandlerInfo& getEventHandlerInfo( sal_Int32 nEventId ) const throw (css::lang::IllegalArgumentException); /** Searches the event handler in the document and returns its full script path. */ ::rtl::OUString getEventHandlerPath( const EventHandlerInfo& rInfo, - const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException); + const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); - /** Removes this instance from all broadcasters. */ - void stopListening(); + /** On first call, accesses the Basic library containing the VBA source code. */ + void ensureVBALibrary() throw (css::uno::RuntimeException); + + /** Returns the type of the Basic module with the specified name. */ + sal_Int32 getModuleType( const ::rtl::OUString& rModuleName ) throw (css::uno::RuntimeException); + + /** Updates the map containing paths to event handlers for a Basic module. */ + ModulePathMap& updateModulePathMap( const ::rtl::OUString& rModuleName ) throw (css::uno::RuntimeException); protected: css::uno::Reference< css::frame::XModel > mxModel; SfxObjectShell* mpShell; private: - typedef ::std::map< sal_Int32, EventHandlerInfo > EventHandlerMap; + typedef ::std::map< sal_Int32, EventHandlerInfo > EventHandlerInfoMap; + typedef ::std::hash_map< ::rtl::OUString, ModulePathMap, ::rtl::OUStringHash > EventHandlerPathMap; - EventHandlerMap maEvents; + EventHandlerInfoMap maEventInfos; + EventHandlerPathMap maEventPaths; + css::uno::Reference< css::script::vba::XVBAModuleInfo > mxModuleInfos; + ::rtl::OUString maLibraryName; bool mbDisposed; }; diff --git a/vbahelper/inc/vbahelper/vbahelper.hxx b/vbahelper/inc/vbahelper/vbahelper.hxx index 22dc9a8f6cc8..bf20541eff1e 100644 --- a/vbahelper/inc/vbahelper/vbahelper.hxx +++ b/vbahelper/inc/vbahelper/vbahelper.hxx @@ -63,7 +63,12 @@ namespace ooo throw css::lang::IllegalArgumentException(); return aSomething; } - VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ); + + 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 String& aModName, SfxObjectShell* pShell ); VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::uno::RuntimeException); VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException); @@ -90,18 +95,32 @@ namespace ooo VBAHELPER_DLLPUBLIC void PrintOutHelper( SfxViewShell* 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, sal_Bool bSelection ); VBAHELPER_DLLPUBLIC void PrintPreviewHelper( const css::uno::Any& EnableChanges, SfxViewShell* ); - /** Extracts a boolean value from the passed Any, which may contain sal_Bool or an integer or floating-point value. - Returns false, if the Any is empty or contains an incompatible type. */ - VBAHELPER_DLLPUBLIC bool extractBoolFromAny( bool& rbValue, const css::uno::Any& rAny ); - /** Extracts a boolean value from the passed Any, which may contain sal_Bool or an integer or floating-point value. + /** Extracts a 32-bit integer value from the passed Any, which may contain an integer or floating-point value. + Throws, if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC sal_Int32 extractIntFromAny( const css::uno::Any& rAny ) throw (css::uno::RuntimeException); + /** Extracts a 32-bit integer value from the passed Any, which may contain an integer or floating-point value. + Returns nDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC sal_Int32 extractIntFromAny( const css::uno::Any& rAny, sal_Int32 nDefault ) throw (css::uno::RuntimeException); + + /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value. Throws, if the Any is empty or contains an incompatible type. */ VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny ) throw (css::uno::RuntimeException); + /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value. + Returns bDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny, bool bDefault ) throw (css::uno::RuntimeException); + + /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string. + Throws, if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC ::rtl::OUString extractStringFromAny( const css::uno::Any& rAny, bool bUppercaseBool = false ) throw (css::uno::RuntimeException); + /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string. + Returns rDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC ::rtl::OUString extractStringFromAny( const css::uno::Any& rAny, const ::rtl::OUString& rDefault, bool bUppercaseBool = false ) throw (css::uno::RuntimeException); VBAHELPER_DLLPUBLIC rtl::OUString getAnyAsString( const css::uno::Any& pvargItem ) throw ( css::uno::RuntimeException ); VBAHELPER_DLLPUBLIC rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike = false); // needs to be in an uno service ( already this code is duplicated in basic ) - VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical); - VBAHELPER_DLLPUBLIC double PointsToPixels( css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical); - VBAHELPER_DLLPUBLIC double PixelsToPoints( css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical); VBAHELPER_DLLPUBLIC sal_Int32 PointsToHmm( double fPoints ); VBAHELPER_DLLPUBLIC double HmmToPoints( sal_Int32 nHmm ); VBAHELPER_DLLPUBLIC sal_Int32 getPointerStyle( const css::uno::Reference< css::frame::XModel >& ); @@ -135,14 +154,21 @@ class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace { public: virtual ~AbstractGeometryAttributes() {} - virtual double getLeft() = 0; + virtual double getLeft() const = 0; virtual void setLeft( double ) = 0; - virtual double getTop() = 0; + virtual double getTop() const = 0; virtual void setTop( double ) = 0; - virtual double getHeight() = 0; + virtual double getHeight() const = 0; virtual void setHeight( double ) = 0; - virtual double getWidth() = 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; } }; namespace msforms { @@ -156,20 +182,13 @@ protected: public: ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape) throw (css::script::BasicErrorException ); - double getHeight(); - - void setHeight(double _fheight) throw ( css::script::BasicErrorException ); - - double getWidth(); - + double getHeight() const; + void setHeight(double _fheight) throw ( css::script::BasicErrorException ); + double getWidth() const; void setWidth(double _fWidth) throw ( css::script::BasicErrorException ); - - double getLeft(); - + double getLeft() const; void setLeft(double _fLeft); - - double getTop(); - + double getTop() const; void setTop(double _fTop); }; @@ -178,13 +197,13 @@ class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes : public AbstractGeom std::auto_ptr< ShapeHelper > m_pShapeHelper; public: ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape ); - virtual double getLeft(); + virtual double getLeft() const; virtual void setLeft( double nLeft ); - virtual double getTop(); + virtual double getTop() const; virtual void setTop( double nTop ); - virtual double getHeight(); + virtual double getHeight() const; virtual void setHeight( double nHeight ); - virtual double getWidth(); + virtual double getWidth() const; virtual void setWidth( double nWidth); virtual ~ConcreteXShapeGeometryAttributes(); }; @@ -195,19 +214,39 @@ public: #define VBA_WIDTH "Width" class VBAHELPER_DLLPUBLIC UserFormGeometryHelper : public AbstractGeometryAttributes { +public: + UserFormGeometryHelper( + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::awt::XControl >& xControl, + double fOffsetX, double fOffsetY ); + virtual double getLeft() const; + virtual void setLeft( double fLeft ); + virtual double getTop() const; + virtual void setTop( double fTop ); + virtual double getWidth() const; + virtual void setWidth( double fWidth ); + virtual double getHeight() const; + virtual void setHeight( double fHeight ); + virtual double getInnerWidth() const; + virtual void setInnerWidth( double fWidth ); + virtual double getInnerHeight() const; + virtual void setInnerHeight( double fHeight ); + virtual double getOffsetX() const; + virtual double getOffsetY() const; + +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; sal_Bool mbDialog; - -public: - UserFormGeometryHelper( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::awt::XControl >& xControl ); - virtual double getLeft(); - virtual void setLeft( double nLeft ); - virtual double getTop(); - virtual void setTop( double nTop ); - virtual double getHeight(); - virtual void setHeight( double nHeight ); - virtual double getWidth(); - virtual void setWidth( double nWidth); }; class VBAHELPER_DLLPUBLIC ContainerUtilities @@ -230,8 +269,8 @@ public: static void exception( css::uno::Exception& ex ) throw( css::script::BasicErrorException ); }; - } // openoffice -} // org + } // vba +} // ooo namespace ov = ooo::vba; diff --git a/vbahelper/inc/vbahelper/vbawindowbase.hxx b/vbahelper/inc/vbahelper/vbawindowbase.hxx index f42c2a19854e..e9f1d40e4bd4 100644 --- a/vbahelper/inc/vbahelper/vbawindowbase.hxx +++ b/vbahelper/inc/vbahelper/vbawindowbase.hxx @@ -24,24 +24,30 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef VBA_WINDOWBASE_HXX #define VBA_WINDOWBASE_HXX -#include <cppuhelper/implbase1.hxx> -#include <ooo/vba/XWindowBase.hpp> -#include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/awt/XDevice.hpp> +#include <ooo/vba/XWindowBase.hpp> +#include <com/sun/star/awt/XWindow2.hpp> +#include <com/sun/star/frame/XController.hpp> #include <vbahelper/vbahelperinterface.hxx> -typedef InheritedHelperInterfaceImpl1<ov::XWindowBase > WindowBaseImpl_BASE; +typedef InheritedHelperInterfaceImpl1< ov::XWindowBase > WindowBaseImpl_BASE; class VBAHELPER_DLLPUBLIC VbaWindowBase : public WindowBaseImpl_BASE { -protected: - css::uno::Reference< css::frame::XModel > m_xModel; public: - VbaWindowBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel ); - VbaWindowBase( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext ); + 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 ) + throw (css::uno::RuntimeException); + VbaWindowBase( + css::uno::Sequence< css::uno::Any > const& aArgs, + css::uno::Reference< css::uno::XComponentContext > const& xContext ) + throw (css::uno::RuntimeException); // XWindowBase virtual sal_Int32 SAL_CALL getHeight() throw (css::uno::RuntimeException) ; @@ -58,6 +64,19 @@ public: // XHelperInterface virtual rtl::OUString& getServiceImplName(); virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +protected: + css::uno::Reference< css::frame::XController > getController() throw (css::uno::RuntimeException); + css::uno::Reference< css::awt::XWindow > getWindow() throw (css::uno::RuntimeException); + css::uno::Reference< css::awt::XWindow2 > getWindow2() throw (css::uno::RuntimeException); + + css::uno::Reference< css::frame::XModel > m_xModel; + +private: + void construct( const css::uno::Reference< css::frame::XController >& xController ) throw (css::uno::RuntimeException); + + css::uno::WeakReference< css::frame::XController > m_xController; + css::uno::WeakReference< css::awt::XWindow > m_xWindow; }; #endif //VBA_WINDOWBASE_HXX diff --git a/vbahelper/inc/vbahelper/weakreference.hxx b/vbahelper/inc/vbahelper/weakreference.hxx new file mode 100755 index 000000000000..661f3bc5d73e --- /dev/null +++ b/vbahelper/inc/vbahelper/weakreference.hxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VBAHELPER_WEAKREFERENCE_HXX +#define VBAHELPER_WEAKREFERENCE_HXX + +#include <cppuhelper/weakref.hxx> +#include <rtl/ref.hxx> + +namespace vbahelper { + +// ============================================================================ + +/** A weak reference holding any UNO implementation object. + + The held object must implement the ::com::sun::star::uno::XWeak interface. + + In difference to the ::com::sun::star::uno::WeakReference<> implementation + from cppuhelper/weakref.hxx, the class type of this weak reference is not + restricted to UNO interface types, but can be used for any C++ class type + implementing the XWeak interface somehow (e.g. ::cppu::WeakImplHelperN<>, + ::cppu::ImplInheritanceHelperN<>, etc.). + */ +template< typename ObjectType > +class WeakReference +{ +public: + /** Default constructor. Creates an empty weak reference. + */ + inline explicit WeakReference() SAL_THROW( () ) : mpObject( 0 ) {} + + /** Initializes this weak reference with the passed reference to an object. + */ + inline explicit WeakReference( const ::rtl::Reference< ObjectType >& rxObject ) SAL_THROW( () ) : + mxWeakRef( rxObject.get() ), mpObject( rxObject.get() ) {} + + /** Releases this weak reference and takes over the passed reference. + */ + inline WeakReference& SAL_CALL operator=( const ::rtl::Reference< ObjectType >& rxObject ) SAL_THROW( () ) + { + mxWeakRef = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak >( rxObject.get() ); + mpObject = rxObject.get(); + return *this; + } + + /** Gets an RTL reference to the referenced object. + + @return Reference or null, if the weakly referenced object is gone. + */ + inline SAL_CALL operator ::rtl::Reference< ObjectType >() SAL_THROW( () ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak > xRef = mxWeakRef; + ::rtl::Reference< ObjectType > xObject; + if( xRef.is() ) + xObject = mpObject; + else + mpObject = 0; + return xObject; + } + +private: + ::com::sun::star::uno::WeakReference< ::com::sun::star::uno::XWeak > mxWeakRef; + ObjectType* mpObject; +}; + +// ============================================================================ + +} // namespace vbahelper + +#endif |