summaryrefslogtreecommitdiff
path: root/forms/source/misc/InterfaceContainer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'forms/source/misc/InterfaceContainer.cxx')
-rw-r--r--forms/source/misc/InterfaceContainer.cxx183
1 files changed, 152 insertions, 31 deletions
diff --git a/forms/source/misc/InterfaceContainer.cxx b/forms/source/misc/InterfaceContainer.cxx
index f1b59d77af7e..b594df158d17 100644
--- a/forms/source/misc/InterfaceContainer.cxx
+++ b/forms/source/misc/InterfaceContainer.cxx
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: InterfaceContainer.cxx,v $
- * $Revision: 1.30 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
@@ -31,42 +28,49 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_forms.hxx"
-#include "frm_resource.hrc"
-#include "frm_resource.hxx"
-#include "InterfaceContainer.hxx"
-#include "property.hrc"
-#include "services.hxx"
-
-#include <com/sun/star/beans/XPropertySet.hpp>
-#include <com/sun/star/container/XNamed.hpp>
-#include <com/sun/star/io/WrongFormatException.hpp>
-#include <com/sun/star/io/XMarkableStream.hpp>
-#include <com/sun/star/lang/XComponent.hpp>
-#include <com/sun/star/util/XCloneable.hpp>
-
-#include <comphelper/container.hxx>
-#include <comphelper/enumhelper.hxx>
-#include <comphelper/eventattachermgr.hxx>
-#include <comphelper/property.hxx>
-#include <comphelper/sequence.hxx>
-#include <comphelper/types.hxx>
-#include <cppuhelper/exc_hlp.hxx>
-#include <cppuhelper/queryinterface.hxx>
-#include <rtl/logfile.hxx>
-#include <tools/debug.hxx>
-#include <tools/diagnose_ex.h>
-
-#include <algorithm>
-#include <memory>
+#include "frm_resource.hrc"
+#include "frm_resource.hxx"
+#include "InterfaceContainer.hxx"
+#include "property.hrc"
+#include "services.hxx"
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/container/XNamed.hpp>
+#include <com/sun/star/io/WrongFormatException.hpp>
+#include <com/sun/star/io/XMarkableStream.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/util/XCloneable.hpp>
+
+#include <comphelper/container.hxx>
+#include <comphelper/enumhelper.hxx>
+#include <comphelper/eventattachermgr.hxx>
+#include <comphelper/property.hxx>
+#include <comphelper/sequence.hxx>
+#include <comphelper/types.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+#include <cppuhelper/queryinterface.hxx>
+#include <rtl/logfile.hxx>
+#include <tools/debug.hxx>
+#include <tools/diagnose_ex.h>
+
+#include <algorithm>
+#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 +86,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 +876,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 +1187,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 +1238,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;
}