summaryrefslogtreecommitdiff
path: root/basic/source/classes/eventatt.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'basic/source/classes/eventatt.cxx')
-rw-r--r--basic/source/classes/eventatt.cxx71
1 files changed, 33 insertions, 38 deletions
diff --git a/basic/source/classes/eventatt.cxx b/basic/source/classes/eventatt.cxx
index 7776b57829..b0c8f4b3c3 100644
--- a/basic/source/classes/eventatt.cxx
+++ b/basic/source/classes/eventatt.cxx
@@ -95,53 +95,48 @@ Any sbxToUnoValue( SbxVariable* pVar );
Reference< frame::XModel > getModelFromBasic( SbxObject* pBasic )
{
- Reference< frame::XModel > xModel;
-
- SbxObject* basicChosen = pBasic;
-
- if ( basicChosen == NULL)
+ OSL_PRECOND( pBasic != NULL, "getModelFromBasic: illegal call!" );
+ if ( !pBasic )
+ return NULL;
+
+ // look for the ThisComponent variable, first in the parent (which
+ // might be the document's Basic), then in the parent's parent (which might be
+ // the application Basic)
+ const ::rtl::OUString sThisComponent( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) );
+ SbxVariable* pThisComponent = NULL;
+
+ SbxObject* pLookup = pBasic->GetParent();
+ while ( pLookup && !pThisComponent )
{
- OSL_TRACE("getModelFromBasic() StarBASIC* is NULL" );
- return xModel;
+ pThisComponent = pLookup->Find( sThisComponent, SbxCLASS_OBJECT );
+ pLookup = pLookup->GetParent();
}
- SbxObject* p = pBasic;
- SbxObject* pParent = p->GetParent();
- SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL;
-
- if( pParentParent )
+ if ( !pThisComponent )
{
- basicChosen = pParentParent;
+ OSL_TRACE("Failed to get ThisComponent");
+ // the application Basic, at the latest, should have this variable
+ return NULL;
}
- else if( pParent )
+
+ Any aThisComponent( sbxToUnoValue( pThisComponent ) );
+ Reference< frame::XModel > xModel( aThisComponent, UNO_QUERY );
+ if ( !xModel.is() )
{
- basicChosen = pParent;
+ // it's no XModel. Okay, ThisComponent nowadays is allowed to be a controller.
+ Reference< frame::XController > xController( aThisComponent, UNO_QUERY );
+ if ( xController.is() )
+ xModel = xController->getModel();
}
+ if ( !xModel.is() )
+ return NULL;
- Any aModel;
- SbxVariable *pCompVar = basicChosen->Find( UniString(RTL_CONSTASCII_USTRINGPARAM("ThisComponent")), SbxCLASS_OBJECT );
+#if OSL_DEBUG_LEVEL > 0
+ OSL_TRACE("Have model ThisComponent points to url %s",
+ ::rtl::OUStringToOString( xModel->getURL(),
+ RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+#endif
- if ( pCompVar )
- {
- aModel = sbxToUnoValue( pCompVar );
- if ( sal_False == ( aModel >>= xModel ) ||
- !xModel.is() )
- {
- OSL_TRACE("Failed to extract model from thisComponent ");
- return xModel;
- }
- else
- {
- OSL_TRACE("Have model ThisComponent points to url %s",
- ::rtl::OUStringToOString( xModel->getURL(),
- RTL_TEXTENCODING_ASCII_US ).pData->buffer );
-
- }
- }
- else
- {
- OSL_TRACE("Failed to get ThisComponent");
- }
return xModel;
}