Lines 95-147
Link Here
|
95 |
|
95 |
|
96 |
Reference< frame::XModel > getModelFromBasic( SbxObject* pBasic ) |
96 |
Reference< frame::XModel > getModelFromBasic( SbxObject* pBasic ) |
97 |
{ |
97 |
{ |
98 |
Reference< frame::XModel > xModel; |
98 |
OSL_PRECOND( pBasic != NULL, "getModelFromBasic: illegal call!" ); |
|
|
99 |
if ( !pBasic ) |
100 |
return NULL; |
99 |
|
101 |
|
100 |
SbxObject* basicChosen = pBasic; |
102 |
// look for the ThisComponent variable, first in the parent (which |
|
|
103 |
// might be the document's Basic), then in the parent's parent (which might be |
104 |
// the application Basic) |
105 |
const ::rtl::OUString sThisComponent( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) ); |
106 |
SbxVariable* pThisComponent = NULL; |
101 |
|
107 |
|
102 |
if ( basicChosen == NULL) |
108 |
SbxObject* pLookup = pBasic->GetParent(); |
|
|
109 |
while ( pLookup && !pThisComponent ) |
103 |
{ |
110 |
{ |
104 |
OSL_TRACE("getModelFromBasic() StarBASIC* is NULL" ); |
111 |
pThisComponent = pLookup->Find( sThisComponent, SbxCLASS_OBJECT ); |
105 |
return xModel; |
112 |
pLookup = pLookup->GetParent(); |
106 |
} |
113 |
} |
107 |
SbxObject* p = pBasic; |
114 |
if ( !pThisComponent ) |
108 |
SbxObject* pParent = p->GetParent(); |
|
|
109 |
SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL; |
110 |
|
111 |
if( pParentParent ) |
112 |
{ |
115 |
{ |
113 |
basicChosen = pParentParent; |
116 |
OSL_TRACE("Failed to get ThisComponent"); |
114 |
} |
117 |
return NULL; |
115 |
else if( pParent ) |
|
|
116 |
{ |
117 |
basicChosen = pParent; |
118 |
} |
118 |
} |
119 |
|
119 |
|
|
|
120 |
Any aThisComponent( sbxToUnoValue( pThisComponent ) ); |
121 |
Reference< frame::XModel > xModel( aThisComponent, UNO_QUERY ); |
122 |
if ( !xModel.is() ) |
123 |
{ |
124 |
// it's no XModel. Okay, ThisComponent nowadays is allowed to be a controller. |
125 |
Reference< frame::XController > xController( aThisComponent, UNO_QUERY ); |
126 |
if ( xController.is() ) |
127 |
xModel = xController->getModel(); |
128 |
} |
120 |
|
129 |
|
121 |
Any aModel; |
130 |
if ( !xModel.is() ) |
122 |
SbxVariable *pCompVar = basicChosen->Find( UniString(RTL_CONSTASCII_USTRINGPARAM("ThisComponent")), SbxCLASS_OBJECT ); |
131 |
{ |
|
|
132 |
OSL_ENSURE( false, "::getModelFromBasic: ThisComponent didn't lead me to a document model!" ); |
133 |
return NULL; |
134 |
} |
123 |
|
135 |
|
124 |
if ( pCompVar ) |
136 |
#if OSL_DEBUG_LEVEL > 0 |
125 |
{ |
137 |
OSL_TRACE("Have model ThisComponent points to url %s", |
126 |
aModel = sbxToUnoValue( pCompVar ); |
138 |
::rtl::OUStringToOString( xModel->getURL(), |
127 |
if ( sal_False == ( aModel >>= xModel ) || |
139 |
RTL_TEXTENCODING_ASCII_US ).pData->buffer ); |
128 |
!xModel.is() ) |
140 |
#endif |
129 |
{ |
|
|
130 |
OSL_TRACE("Failed to extract model from thisComponent "); |
131 |
return xModel; |
132 |
} |
133 |
else |
134 |
{ |
135 |
OSL_TRACE("Have model ThisComponent points to url %s", |
136 |
::rtl::OUStringToOString( xModel->getURL(), |
137 |
RTL_TEXTENCODING_ASCII_US ).pData->buffer ); |
138 |
|
141 |
|
139 |
} |
|
|
140 |
} |
141 |
else |
142 |
{ |
143 |
OSL_TRACE("Failed to get ThisComponent"); |
144 |
} |
145 |
return xModel; |
142 |
return xModel; |
146 |
} |
143 |
} |
147 |
|
144 |
|