diff options
author | Vladimir Glazunov <vg@openoffice.org> | 2010-02-04 16:22:08 +0100 |
---|---|---|
committer | Vladimir Glazunov <vg@openoffice.org> | 2010-02-04 16:22:08 +0100 |
commit | aaabb811e48afafd02552d6f4cdec688683c644b (patch) | |
tree | c360efc23e9d36f6ace616270dc64837245f234e /forms/source | |
parent | 250f8b1b2ed681d4692fe13e167b6b6a39ceec0f (diff) | |
parent | 5d395870aa610623688f91118ffaad6a9489abff (diff) |
CWS-TOOLING: integrate CWS ab71
Diffstat (limited to 'forms/source')
-rw-r--r-- | forms/source/inc/InterfaceContainer.hxx | 3 | ||||
-rw-r--r-- | forms/source/misc/InterfaceContainer.cxx | 124 | ||||
-rw-r--r-- | forms/source/misc/makefile.mk | 10 |
3 files changed, 137 insertions, 0 deletions
diff --git a/forms/source/inc/InterfaceContainer.hxx b/forms/source/inc/InterfaceContainer.hxx index 3af34e161..e26de0127 100644 --- a/forms/source/inc/InterfaceContainer.hxx +++ b/forms/source/inc/InterfaceContainer.hxx @@ -275,6 +275,9 @@ protected: void implCheckIndex( const sal_Int32 _nIndex ) SAL_THROW( ( ::com::sun::star::lang::IndexOutOfBoundsException ) ); private: + // hack for Vba Events + void fakeVbaEventsHack( sal_Int32 _nIndex ); + // the runtime event format has changed from version SO5.2 to OOo enum EventFormat { diff --git a/forms/source/misc/InterfaceContainer.cxx b/forms/source/misc/InterfaceContainer.cxx index 18a865418..47eda9eb5 100644 --- a/forms/source/misc/InterfaceContainer.cxx +++ b/forms/source/misc/InterfaceContainer.cxx @@ -60,13 +60,20 @@ #include <memory>
//......................................................................... +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/document/XCodeNameQuery.hpp> +#include <ooo/vba/XVBAToOOEventDescGen.hpp> +#include <comphelper/processfactory.hxx> + namespace frm { //......................................................................... +using namespace ::com::sun::star::frame; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::document; using namespace ::com::sun::star::container; using namespace ::com::sun::star::script; using namespace ::com::sun::star::io; @@ -82,6 +89,90 @@ namespace } } +bool +lcl_hasVbaEvents( const Sequence< ScriptEventDescriptor >& sEvents ) +{ + const ScriptEventDescriptor* pDesc = sEvents.getConstArray(); + const ScriptEventDescriptor* pEnd = ( pDesc + sEvents.getLength() ); + for ( ; pDesc != pEnd; ++pDesc ) + { + if ( pDesc->ScriptType.equals( rtl::OUString::createFromAscii( "VBAInterop" ) ) ) + return true; + } + return false; +} + +Sequence< ScriptEventDescriptor > +lcl_stripVbaEvents( const Sequence< ScriptEventDescriptor >& sEvents ) +{ + Sequence< ScriptEventDescriptor > sStripped( sEvents.getLength() ); + + const ScriptEventDescriptor* pDesc = sEvents.getConstArray(); + const ScriptEventDescriptor* pEnd = ( pDesc + sEvents.getLength() ); + sal_Int32 nCopied = 0; + for ( ; pDesc != pEnd; ++pDesc ) + { + if ( !pDesc->ScriptType.equals( rtl::OUString::createFromAscii( "VBAInterop" ) ) ) + { + sStripped[ nCopied++ ] = *pDesc; + } + } + if ( nCopied ) + sStripped.realloc( nCopied ); + return sStripped; +} + +void +OInterfaceContainer::fakeVbaEventsHack( sal_Int32 _nIndex ) +{ + // we are dealing with form controls + try + { + Reference< XFormComponent > xForm( static_cast< XContainer* >(this), UNO_QUERY_THROW ); + // grand-parent should be the model, no parent ? if not + // we'll ignore, we'll get called back here anyway ) + Reference< XChild > xChild( xForm->getParent(), UNO_QUERY_THROW ); + Reference< XModel > xDocOwner( xChild->getParent(), UNO_QUERY ); + OSL_TRACE(" Is DOC ????? %s", xDocOwner.is() ? "true" : "false" ); + if ( xDocOwner.is() ) + { + bool hasVBABindings = lcl_hasVbaEvents( m_xEventAttacher->getScriptEvents( _nIndex ) ); + if ( hasVBABindings ) + { + OSL_TRACE("Has VBA bindings already, returning "); + return; + } + Reference< XMultiServiceFactory > xFac( comphelper::getProcessServiceFactory(), UNO_QUERY ); + Reference< XMultiServiceFactory > xDocFac( xDocOwner, UNO_QUERY ); + if ( xFac.is() && xDocFac.is() ) + { + try + { + Reference< ooo::vba::XVBAToOOEventDescGen > xDescSupplier( xFac->createInstance( rtl::OUString::createFromAscii( "ooo.vba.VBAToOOEventDesc" ) ), UNO_QUERY_THROW ); + Reference< XInterface > xIf( getByIndex( _nIndex ) , UNO_QUERY_THROW ); + Reference< XCodeNameQuery > xNameQuery( xDocFac->createInstance( rtl::OUString::createFromAscii( "ooo.vba.VBACodeNameProvider" ) ), UNO_QUERY_THROW ); + + rtl::OUString sCodeName; + sCodeName = xNameQuery->getCodeNameForObject( xIf ); + Reference< XPropertySet > xProps( xIf, UNO_QUERY ); + rtl::OUString sServiceName; + xProps->getPropertyValue( rtl::OUString::createFromAscii("DefaultControl" ) ) >>= sServiceName; + + Sequence< ScriptEventDescriptor > vbaEvents = xDescSupplier->getEventDescriptions( xFac->createInstance( sServiceName ), sCodeName ); + // register the vba script events + if ( m_xEventAttacher.is() ) + m_xEventAttacher->registerScriptEvents( _nIndex, vbaEvents ); + } + catch( Exception& ){ OSL_TRACE("lcl_fakevbaevents - Caught Exception trying to create control eventstuff "); } + } + + } + } + catch( Exception& ) + { + } + +} //================================================================== //= ElementDescription //================================================================== @@ -788,6 +879,23 @@ void OInterfaceContainer::implInsert(sal_Int32 _nIndex, const Reference< XProper { m_xEventAttacher->insertEntry(_nIndex); m_xEventAttacher->attach( _nIndex, pElementMetaData->xInterface, makeAny( _rxElement ) ); + // insert fake events? + Reference< XEventAttacherManager > xMgr ( pElementMetaData->xInterface, UNO_QUERY ); + if ( xMgr.is() ) + { + OInterfaceContainer* pIfcMgr = dynamic_cast< OInterfaceContainer* >( xMgr.get() ); + sal_Int32 nLen = pIfcMgr->getCount(); + for ( sal_Int32 i = 0; (i < nLen) && pIfcMgr ; ++i ) + { + // add fake events to the control at index i + pIfcMgr->fakeVbaEventsHack( i ); + } + } + else + { + // add fake events to the control at index i + fakeVbaEventsHack( _nIndex ); + } } // notify derived classes @@ -1082,20 +1190,29 @@ void SAL_CALL OInterfaceContainer::removeByName(const ::rtl::OUString& Name) thr //------------------------------------------------------------------------ void SAL_CALL OInterfaceContainer::registerScriptEvent( sal_Int32 nIndex, const ScriptEventDescriptor& aScriptEvent ) throw(IllegalArgumentException, RuntimeException) { + OSL_TRACE("*** registerScriptEvent %d", nIndex); if ( m_xEventAttacher.is() ) + { m_xEventAttacher->registerScriptEvent( nIndex, aScriptEvent ); + fakeVbaEventsHack( nIndex ); // add fake vba events + } } //------------------------------------------------------------------------ void SAL_CALL OInterfaceContainer::registerScriptEvents( sal_Int32 nIndex, const Sequence< ScriptEventDescriptor >& aScriptEvents ) throw(IllegalArgumentException, RuntimeException) { + OSL_TRACE("*** registerScriptEvent(s) %d", nIndex); if ( m_xEventAttacher.is() ) + { m_xEventAttacher->registerScriptEvents( nIndex, aScriptEvents ); + fakeVbaEventsHack( nIndex ); // add fake vba events + } } //------------------------------------------------------------------------ void SAL_CALL OInterfaceContainer::revokeScriptEvent( sal_Int32 nIndex, const ::rtl::OUString& aListenerType, const ::rtl::OUString& aEventMethod, const ::rtl::OUString& aRemoveListenerParam ) throw(IllegalArgumentException, RuntimeException) { + OSL_TRACE("*** revokeScriptEvent %d listenertype %s, eventMethod %s", nIndex, rtl::OUStringToOString( aListenerType, RTL_TEXTENCODING_UTF8 ).getStr(), rtl::OUStringToOString( aEventMethod, RTL_TEXTENCODING_UTF8 ).getStr()); if ( m_xEventAttacher.is() ) m_xEventAttacher->revokeScriptEvent( nIndex, aListenerType, aEventMethod, aRemoveListenerParam ); } @@ -1124,9 +1241,16 @@ void SAL_CALL OInterfaceContainer::removeEntry( sal_Int32 nIndex ) throw(Illegal //------------------------------------------------------------------------ Sequence< ScriptEventDescriptor > SAL_CALL OInterfaceContainer::getScriptEvents( sal_Int32 nIndex ) throw(IllegalArgumentException, RuntimeException) { + OSL_TRACE("getScriptEvents"); Sequence< ScriptEventDescriptor > aReturn; if ( m_xEventAttacher.is() ) + { aReturn = m_xEventAttacher->getScriptEvents( nIndex ); + if ( lcl_hasVbaEvents( aReturn ) ) + { + aReturn = lcl_stripVbaEvents( aReturn ); + } + } return aReturn; } diff --git a/forms/source/misc/makefile.mk b/forms/source/misc/makefile.mk index b03109ba6..9422ba70d 100644 --- a/forms/source/misc/makefile.mk +++ b/forms/source/misc/makefile.mk @@ -45,6 +45,7 @@ ENABLE_EXCEPTIONS=TRUE # --- Types ------------------------------------- INCPRE+=$(SOLARINCDIR)$/offuh +INCPRE*=$(INCCOM)$/$(TARGET) # --- Files ------------------------------------- @@ -62,3 +63,12 @@ SLOFILES= $(SLO)$/limitedformats.obj \ .INCLUDE : target.mk +ALLTAR : \ + $(MISC)$/$(TARGET).don \ + +$(SLOFILES) : $(MISC)$/$(TARGET).don + +$(MISC)$/$(TARGET).don : $(SOLARBINDIR)$/oovbaapi.rdb + +$(CPPUMAKER) -O$(INCCOM)$/$(TARGET) -BUCR $(SOLARBINDIR)$/oovbaapi.rdb -X$(SOLARBINDIR)$/types.rdb && echo > $@ + echo $@ + |