summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorDaniel Rentz <dr@openoffice.org>2010-07-06 18:07:29 +0200
committerDaniel Rentz <dr@openoffice.org>2010-07-06 18:07:29 +0200
commit5bf36f72a6f0a15998538005f944d593b1ae01e0 (patch)
tree572595ad645e290da7c88ab287abea79c9f770f9 /basic
parent91d3f3dd69d3fc0a8f91d303e05c3040858a05d7 (diff)
mib17: #162576# handle VBA UserForm_Resize and UserForm_Layout events
Diffstat (limited to 'basic')
-rw-r--r--basic/inc/basic/sbobjmod.hxx12
-rwxr-xr-xbasic/source/classes/sb.cxx21
-rw-r--r--basic/source/classes/sbxmod.cxx162
-rw-r--r--basic/source/runtime/methods.cxx3
4 files changed, 129 insertions, 69 deletions
diff --git a/basic/inc/basic/sbobjmod.hxx b/basic/inc/basic/sbobjmod.hxx
index 3d638a475f..9ff46d1931 100644
--- a/basic/inc/basic/sbobjmod.hxx
+++ b/basic/inc/basic/sbobjmod.hxx
@@ -36,6 +36,7 @@
#ifndef _SB_OBJMOD_HXX
#define _SB_OBJMOD_HXX
+#include <rtl/ref.hxx>
#include <basic/sbmod.hxx>
#include <basic/sbstar.hxx>
#include <com/sun/star/script/ModuleInfo.hpp>
@@ -60,10 +61,12 @@ public:
void SetUnoObject( const com::sun::star::uno::Any& aObj )throw ( com::sun::star::uno::RuntimeException ) ;
};
+class FormObjEventListenerImpl;
+
class SbUserFormModule : public SbObjModule
{
com::sun::star::script::ModuleInfo m_mInfo;
- css::uno::Reference<css::lang::XEventListener> m_DialogListener;
+ ::rtl::Reference< FormObjEventListenerImpl > m_DialogListener;
css::uno::Reference<css::awt::XDialog> m_xDialog;
css::uno::Reference<css::frame::XModel> m_xModel;
String sFormName;
@@ -76,16 +79,19 @@ class SbUserFormModule : public SbObjModule
public:
TYPEINFO();
SbUserFormModule( const String& rName, const com::sun::star::script::ModuleInfo& mInfo, bool bIsVBACompat );
+ virtual ~SbUserFormModule();
virtual SbxVariable* Find( const XubString& rName, SbxClassType t );
void ResetApiObj();
void Unload();
- void load();
+ void Load();
void triggerMethod( const String& );
void triggerMethod( const String&, css::uno::Sequence< css::uno::Any >& );
void triggerActivateEvent();
- void triggerDeActivateEvent();
+ void triggerDeactivateEvent();
void triggerInitializeEvent();
void triggerTerminateEvent();
+ void triggerLayoutEvent();
+ void triggerResizeEvent();
class SbUserFormModuleInstance* CreateInstance();
};
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 1ed50e9fd4..f8e0233d01 100755
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -339,27 +339,18 @@ SbxBase* SbFormFactory::Create( UINT16, UINT32 )
SbxObject* SbFormFactory::CreateObject( const String& rClassName )
{
- static String aLoadMethodName( RTL_CONSTASCII_USTRINGPARAM("load") );
-
- SbxObject* pRet = NULL;
- SbModule* pMod = pMOD;
- if( pMod )
+ if( SbModule* pMod = pMOD )
{
- SbxVariable* pVar = pMod->Find( rClassName, SbxCLASS_OBJECT );
- if( pVar )
+ if( SbxVariable* pVar = pMod->Find( rClassName, SbxCLASS_OBJECT ) )
{
- SbxBase* pObj = pVar->GetObject();
- SbUserFormModule* pFormModule = PTR_CAST( SbUserFormModule, pObj );
-
- if( pFormModule != NULL )
+ if( SbUserFormModule* pFormModule = PTR_CAST( SbUserFormModule, pVar->GetObject() ) )
{
- pFormModule->load();
- SbUserFormModuleInstance* pFormInstance = pFormModule->CreateInstance();
- pRet = pFormInstance;
+ pFormModule->Load();
+ return pFormModule->CreateInstance();
}
}
}
- return pRet;
+ return 0;
}
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index 03fe4ab14f..ca23411929 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -53,6 +53,7 @@
#include <basic/basrdll.hxx>
#include <vos/mutex.hxx>
#include <basic/sbobjmod.hxx>
+#include <cppuhelper/implbase2.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/script/ModuleType.hpp>
#include <com/sun/star/script/XVBACompat.hpp>
@@ -95,6 +96,7 @@ using namespace com::sun::star::script;
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/awt/XDialogProvider.hpp>
#include <com/sun/star/awt/XTopWindow.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/awt/XControl.hpp>
#include <cppuhelper/implbase1.hxx>
#include <comphelper/anytostring.hxx>
@@ -1985,9 +1987,9 @@ SbObjModule::Find( const XubString& rName, SbxClassType t )
return pVar;
}
-typedef ::cppu::WeakImplHelper1< awt::XTopWindowListener > EventListener_BASE;
+typedef ::cppu::WeakImplHelper2< awt::XTopWindowListener, awt::XWindowListener > FormObjEventListener_BASE;
-class FormObjEventListenerImpl : public EventListener_BASE
+class FormObjEventListenerImpl : public FormObjEventListener_BASE
{
SbUserFormModule* mpUserForm;
uno::Reference< lang::XComponent > mxComponent;
@@ -1997,39 +1999,57 @@ class FormObjEventListenerImpl : public EventListener_BASE
sal_Bool mbShowing;
FormObjEventListenerImpl(); // not defined
FormObjEventListenerImpl(const FormObjEventListenerImpl&); // not defined
+
public:
- FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False ), mbShowing( sal_False )
+ FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) :
+ mpUserForm( pUserForm ), mxComponent( xComponent) ,
+ mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False ), mbShowing( sal_False )
{
if ( mxComponent.is() )
{
- uno::Reference< awt::XTopWindow > xList( mxComponent, uno::UNO_QUERY_THROW );;
- OSL_TRACE("*********** Registering the listener");
- xList->addTopWindowListener( this );
+ OSL_TRACE("*********** Registering the listeners");
+ try
+ {
+ uno::Reference< awt::XTopWindow >( mxComponent, uno::UNO_QUERY_THROW )->addTopWindowListener( this );
+ }
+ catch( uno::Exception& ) {}
+ try
+ {
+ uno::Reference< awt::XWindow >( mxComponent, uno::UNO_QUERY_THROW )->addWindowListener( this );
+ }
+ catch( uno::Exception& ) {}
}
}
- ~FormObjEventListenerImpl()
+ virtual ~FormObjEventListenerImpl()
{
removeListener();
}
- sal_Bool isShowing() { return mbShowing; }
+
+ sal_Bool isShowing() const { return mbShowing; }
+
void removeListener()
{
- try
+ if ( mxComponent.is() && !mbDisposed )
{
- if ( mxComponent.is() && !mbDisposed )
+ OSL_TRACE("*********** Removing the listeners");
+ try
{
- uno::Reference< awt::XTopWindow > xList( mxComponent, uno::UNO_QUERY_THROW );;
- OSL_TRACE("*********** Removing the listener");
- xList->removeTopWindowListener( this );
- mxComponent = NULL;
+ uno::Reference< awt::XTopWindow >( mxComponent, uno::UNO_QUERY_THROW )->removeTopWindowListener( this );
}
+ catch( uno::Exception& ) {}
+ try
+ {
+ uno::Reference< awt::XWindow >( mxComponent, uno::UNO_QUERY_THROW )->removeWindowListener( this );
+ }
+ catch( uno::Exception& ) {}
}
- catch( uno::Exception& ) {}
- }
+ mxComponent.clear();
+ }
+
virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
{
- if ( mpUserForm )
+ if ( mpUserForm )
{
mbOpened = sal_True;
mbShowing = sal_True;
@@ -2076,12 +2096,23 @@ public:
}
//liuchen 2009-7-21
- virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) { mbOpened = sal_False; mbShowing = sal_False; }
- virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
- virtual void SAL_CALL windowNormalized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException){}
+ virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
+ {
+ mbOpened = sal_False;
+ mbShowing = sal_False;
+ }
+
+ virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
+ {
+ }
+
+ virtual void SAL_CALL windowNormalized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
+ {
+ }
+
virtual void SAL_CALL windowActivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
{
- if ( mpUserForm )
+ if ( mpUserForm )
{
mbActivated = sal_True;
if ( mbOpened )
@@ -2094,18 +2125,38 @@ public:
virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
{
- if ( mpUserForm )
- mpUserForm->triggerDeActivateEvent();
+ if ( mpUserForm )
+ mpUserForm->triggerDeactivateEvent();
}
+ virtual void SAL_CALL windowResized( const awt::WindowEvent& /*e*/ ) throw (uno::RuntimeException)
+ {
+ if ( mpUserForm )
+ {
+ mpUserForm->triggerResizeEvent();
+ mpUserForm->triggerLayoutEvent();
+ }
+ }
+
+ virtual void SAL_CALL windowMoved( const awt::WindowEvent& /*e*/ ) throw (uno::RuntimeException)
+ {
+ if ( mpUserForm )
+ mpUserForm->triggerLayoutEvent();
+ }
+
+ virtual void SAL_CALL windowShown( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
+ {
+ }
+
+ virtual void SAL_CALL windowHidden( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
+ {
+ }
- virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (uno::RuntimeException)
+ virtual void SAL_CALL disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException)
{
OSL_TRACE("** Userform/Dialog disposing");
mbDisposed = true;
- uno::Any aSource;
- aSource <<= Source;
- mxComponent = NULL;
+ mxComponent.clear();
if ( mpUserForm )
mpUserForm->ResetApiObj();
}
@@ -2119,6 +2170,10 @@ SbUserFormModule::SbUserFormModule( const String& rName, const com::sun::star::s
m_xModel.set( mInfo.ModuleObject, uno::UNO_QUERY_THROW );
}
+SbUserFormModule::~SbUserFormModule()
+{
+}
+
void SbUserFormModule::ResetApiObj()
{
if ( m_xDialog.is() ) // probably someone close the dialog window
@@ -2181,23 +2236,22 @@ void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any
void SbUserFormModule::triggerActivateEvent( void )
{
- OSL_TRACE("**** entering SbUserFormModule::triggerActivate");
- triggerMethod( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserForm_activate") ) );
- OSL_TRACE("**** leaving SbUserFormModule::triggerActivate");
+ OSL_TRACE("**** entering SbUserFormModule::triggerActivate");
+ triggerMethod( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserForm_Activate") ) );
+ OSL_TRACE("**** leaving SbUserFormModule::triggerActivate");
}
-void SbUserFormModule::triggerDeActivateEvent( void )
+void SbUserFormModule::triggerDeactivateEvent( void )
{
- OSL_TRACE("**** SbUserFormModule::triggerDeActivate");
- triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_DeActivate") ) );
+ OSL_TRACE("**** SbUserFormModule::triggerDeactivate");
+ triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_Deactivate") ) );
}
void SbUserFormModule::triggerInitializeEvent( void )
-
{
if ( mbInit )
return;
- OSL_TRACE("**** SbUserFormModule::triggerInitializeEvent");
+ OSL_TRACE("**** SbUserFormModule::triggerInitializeEvent");
static String aInitMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Initialize") );
triggerMethod( aInitMethodName );
mbInit = true;
@@ -2205,12 +2259,24 @@ void SbUserFormModule::triggerInitializeEvent( void )
void SbUserFormModule::triggerTerminateEvent( void )
{
- OSL_TRACE("**** SbUserFormModule::triggerTerminateEvent");
+ OSL_TRACE("**** SbUserFormModule::triggerTerminateEvent");
static String aTermMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Terminate") );
triggerMethod( aTermMethodName );
mbInit=false;
}
+void SbUserFormModule::triggerLayoutEvent( void )
+{
+ static String aMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Layout") );
+ triggerMethod( aMethodName );
+}
+
+void SbUserFormModule::triggerResizeEvent( void )
+{
+ static String aMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Resize") );
+ triggerMethod( aMethodName );
+}
+
SbUserFormModuleInstance* SbUserFormModule::CreateInstance()
{
SbUserFormModuleInstance* pInstance = new SbUserFormModuleInstance( this, GetName(), m_mInfo, IsVBACompat() );
@@ -2238,7 +2304,7 @@ SbxVariable* SbUserFormModuleInstance::Find( const XubString& rName, SbxClassTyp
}
-void SbUserFormModule::load()
+void SbUserFormModule::Load()
{
OSL_TRACE("** load() ");
// forces a load
@@ -2276,21 +2342,20 @@ void SbUserFormModule::Unload()
if( pMeth )
{
OSL_TRACE("Attempting too run the UnloadObjectMethod");
- m_xDialog = NULL; //release ref to the uno object
+ m_xDialog.clear(); //release ref to the uno object
SbxValues aVals;
- FormObjEventListenerImpl* pFormListener = dynamic_cast< FormObjEventListenerImpl* >( m_DialogListener.get() );
bool bWaitForDispose = true; // assume dialog is showing
- if ( pFormListener )
+ if ( m_DialogListener.get() )
{
- bWaitForDispose = pFormListener->isShowing();
+ bWaitForDispose = m_DialogListener->isShowing();
OSL_TRACE("Showing %d", bWaitForDispose );
}
pMeth->Get( aVals);
- if ( !bWaitForDispose )
- {
- // we've either already got a dispose or we'er never going to get one
+ if ( !bWaitForDispose )
+ {
+ // we've either already got a dispose or we'er never going to get one
ResetApiObj();
- } // else wait for dispose
+ } // else wait for dispose
OSL_TRACE("UnloadObject completed ( we hope )");
}
}
@@ -2328,13 +2393,12 @@ void SbUserFormModule::InitObject()
pDocObject = new SbUnoObject( GetName(), uno::makeAny( xVBAFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.UserForm")), aArgs ) ) );
uno::Reference< lang::XComponent > xComponent( aArgs[ 1 ], uno::UNO_QUERY_THROW );
// remove old listener if it exists
- FormObjEventListenerImpl* pFormListener = dynamic_cast< FormObjEventListenerImpl* >( m_DialogListener.get() );
- if ( pFormListener )
- pFormListener->removeListener();
+ if ( m_DialogListener.get() )
+ m_DialogListener->removeListener();
m_DialogListener = new FormObjEventListenerImpl( this, xComponent );
triggerInitializeEvent();
- }
+ }
}
catch( uno::Exception& )
{
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 41e7df439c..cafa0ee444 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -4134,8 +4134,7 @@ RTLFUNC(Load)
{
if( pObj->IsA( TYPE( SbUserFormModule ) ) )
{
- SbUserFormModule* pFormModule = ( SbUserFormModule* )pObj;
- pFormModule->load();
+ ((SbUserFormModule*)pObj)->Load();
}
else if( pObj->IsA( TYPE( SbxObject ) ) )
{