Debian Codegraph @

basic/source/classes/sbxmod.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21 #include <utility>
22 #include <vcl/svapp.hxx>
23 #include <tools/stream.hxx>
24 #include <comphelper/diagnose_ex.hxx>
25 #include <svl/SfxBroadcaster.hxx>
26 #include <basic/codecompletecache.hxx>
27 #include <basic/sbx.hxx>
28 #include <basic/sbuno.hxx>
29 #include <sbjsmeth.hxx>
30 #include <sbjsmod.hxx>
31 #include <sbintern.hxx>
32 #include <sbprop.hxx>
33 #include <filefmt.hxx>
34 #include <image.hxx>
35 #include <opcodes.hxx>
36 #include <runtime.hxx>
37 #include <token.hxx>
38 #include <sbunoobj.hxx>
39
40 #include <sal/log.hxx>
41
42 #include <basic/sberrors.hxx>
43 #include <sbobjmod.hxx>
44 #include <basic/vbahelper.hxx>
45 #include <comphelper/sequence.hxx>
46 #include <cppuhelper/implbase.hxx>
47 #include <unotools/eventcfg.hxx>
48 #include <com/sun/star/lang/XServiceInfo.hpp>
49 #include <com/sun/star/script/ModuleType.hpp>
50 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
51 #include <com/sun/star/script/vba/VBAScriptEventId.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
54 #include <com/sun/star/document/XDocumentEventListener.hpp>
55
56 #ifdef UNX
57 #include <sys/resource.h>
58 #endif
59
60 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
61 #include <comphelper/processfactory.hxx>
62 #include <comphelper/asyncquithandler.hxx>
63 #include <map>
64 #include <com/sun/star/reflection/ProxyFactory.hpp>
65 #include <com/sun/star/uno/XAggregation.hpp>
66 #include <com/sun/star/script/XInvocation.hpp>
67
68 #include <com/sun/star/awt/DialogProvider.hpp>
69 #include <com/sun/star/awt/XTopWindow.hpp>
70 #include <com/sun/star/awt/XWindow.hpp>
71 #include <ooo/vba/VbQueryClose.hpp>
72 #include <memory>
73 #include <sbxmod.hxx>
74 #include <parser.hxx>
75
76 #include <limits>
77
78 using namespace com::sun::star;
79 using namespace com::sun::star::lang;
80 using namespace com::sun::star::reflection;
81 using namespace com::sun::star::beans;
82 using namespace com::sun::star::script;
83 using namespace com::sun::star::uno;
84
85 typedef ::cppu::WeakImplHelper< XInvocation > DocObjectWrapper_BASE;
86 typedef std::map< sal_Int16, Any > OutParamMap;
87
88 namespace {
89
90 class DocObjectWrapper : public DocObjectWrapper_BASE
91 {
92 Reference< XAggregation > m_xAggProxy;
93 Reference< XInvocation > m_xAggInv;
94 Reference< XTypeProvider > m_xAggregateTypeProv;
95 Sequence< Type > m_Types;
96 SbModule* m_pMod;
97 /// @throws css::uno::RuntimeException
98 SbMethodRef getMethod( const OUString& aName );
99 /// @throws css::uno::RuntimeException
100 SbPropertyRef getProperty( const OUString& aName );
101
102 public:
103 explicit DocObjectWrapper( SbModule* pMod );
104
105 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() override
106 {
107 return css::uno::Sequence<sal_Int8>();
108 }
109
110 virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection( ) override;
111
112 virtual Any SAL_CALL invoke( const OUString& aFunctionName, const Sequence< Any >& aParams, Sequence< ::sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) override;
113 virtual void SAL_CALL setValue( const OUString& aPropertyName, const Any& aValue ) override;
114 virtual Any SAL_CALL getValue( const OUString& aPropertyName ) override;
115 virtual sal_Bool SAL_CALL hasMethod( const OUString& aName ) override;
116 virtual sal_Bool SAL_CALL hasProperty( const OUString& aName ) override;
117 virtual Any SAL_CALL queryInterface( const Type& aType ) override;
118
119 virtual Sequence< Type > SAL_CALL getTypes() override;
120 };
121
122 }
123
124 DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar )
125 {
126 SbObjModule* pMod = dynamic_cast<SbObjModule*>( pVar );
127 if ( !pMod )
128 return;
129
130 if ( pMod->GetModuleType() != ModuleType::DOCUMENT )
131 return;
132
133 // Use proxy factory service to create aggregatable proxy.
134 SbUnoObject* pUnoObj = dynamic_cast<SbUnoObject*>( pMod->GetObject() );
135 Reference< XInterface > xIf;
136 if ( pUnoObj )
137 {
138 Any aObj = pUnoObj->getUnoAny();
139 aObj >>= xIf;
140 if ( xIf.is() )
141 {
142 m_xAggregateTypeProv.set( xIf, UNO_QUERY );
143 m_xAggInv.set( xIf, UNO_QUERY );
144 }
145 }
146 if ( xIf.is() )
147 {
148 try
149 {
150 Reference< XProxyFactory > xProxyFac = ProxyFactory::create( comphelper::getProcessComponentContext() );
151 m_xAggProxy = xProxyFac->createProxy( xIf );
152 }
153 catch(const Exception& )
154 {
155 TOOLS_WARN_EXCEPTION( "basic", "DocObjectWrapper::DocObjectWrapper" );
156 }
157 }
158
159 if ( !m_xAggProxy.is() )
160 return;
161
162 osl_atomic_increment( &m_refCount );
163
164 /* i35609 - Fix crash on Solaris. The setDelegator call needs
165 to be in its own block to ensure that all temporary Reference
166 instances that are acquired during the call are released
167 before m_refCount is decremented again */
168 {
169 m_xAggProxy->setDelegator( getXWeak() );
170 }
171
172 osl_atomic_decrement( &m_refCount );
173 }
174
175 Sequence< Type > SAL_CALL DocObjectWrapper::getTypes()
176 {
177 if ( !m_Types.hasElements() )
178 {
179 Sequence< Type > sTypes;
180 if ( m_xAggregateTypeProv.is() )
181 {
182 sTypes = m_xAggregateTypeProv->getTypes();
183 }
184 m_Types = comphelper::concatSequences(sTypes,
185 Sequence { cppu::UnoType<XInvocation>::get() });
186 }
187 return m_Types;
188 }
189
190 Reference< XIntrospectionAccess > SAL_CALL
191 DocObjectWrapper::getIntrospection( )
192 {
193 return nullptr;
194 }
195
196 Any SAL_CALL
197 DocObjectWrapper::invoke( const OUString& aFunctionName, const Sequence< Any >& aParams, Sequence< ::sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam )
198 {
199 if ( m_xAggInv.is() && m_xAggInv->hasMethod( aFunctionName ) )
200 return m_xAggInv->invoke( aFunctionName, aParams, aOutParamIndex, aOutParam );
201 SbMethodRef pMethod = getMethod( aFunctionName );
202 if ( !pMethod.is() )
203 throw RuntimeException(u"DocObjectWrapper::invoke - Could not get the method reference!"_ustr);
204 // check number of parameters
205 sal_Int32 nParamsCount = aParams.getLength();
206 SbxInfo* pInfo = pMethod->GetInfo();
207 if ( pInfo )
208 {
209 sal_Int32 nSbxOptional = 0;
210 sal_uInt16 n = 1;
211 for ( const SbxParamInfo* pParamInfo = pInfo->GetParam( n ); pParamInfo; pParamInfo = pInfo->GetParam( ++n ) )
212 {
213 if ( pParamInfo->nFlags & SbxFlagBits::Optional )
214 ++nSbxOptional;
215 else
216 nSbxOptional = 0;
217 }
218 sal_Int32 nSbxCount = n - 1;
219 if ( nParamsCount < nSbxCount - nSbxOptional )
220 {
221 throw RuntimeException( u"wrong number of parameters!"_ustr );
222 }
223 }
224 // set parameters
225 SbxArrayRef xSbxParams;
226 if ( nParamsCount > 0 )
227 {
228 xSbxParams = new SbxArray;
229 const Any* pParams = aParams.getConstArray();
230 for ( sal_Int32 i = 0; i < nParamsCount; ++i )
231 {
232 SbxVariableRef xSbxVar = new SbxVariable( SbxVARIANT );
233 unoToSbxValue( xSbxVar.get(), pParams[i] );
234 xSbxParams->Put(xSbxVar.get(), static_cast<sal_uInt32>(i) + 1);
235
236 // Enable passing by ref
237 if ( xSbxVar->GetType() != SbxVARIANT )
238 xSbxVar->SetFlag( SbxFlagBits::Fixed );
239 }
240 }
241 if ( xSbxParams.is() )
242 pMethod->SetParameters( xSbxParams.get() );
243
244 // call method
245 SbxVariableRef xReturn = new SbxVariable;
246
247 pMethod->Call( xReturn.get() );
248 Any aReturn;
249 // get output parameters
250 if ( xSbxParams.is() )
251 {
252 SbxInfo* pInfo_ = pMethod->GetInfo();
253 if ( pInfo_ )
254 {
255 OutParamMap aOutParamMap;
256 for (sal_uInt32 n = 1, nCount = xSbxParams->Count(); n < nCount; ++n)
257 {
258 assert(n <= std::numeric_limits<sal_uInt16>::max());
259 const SbxParamInfo* pParamInfo = pInfo_->GetParam( sal::static_int_cast<sal_uInt16>(n) );
260 if ( pParamInfo && ( pParamInfo->eType & SbxBYREF ) != 0 )
261 {
262 SbxVariable* pVar = xSbxParams->Get(n);
263 if ( pVar )
264 {
265 SbxVariableRef xVar = pVar;
266 aOutParamMap.emplace( n - 1, sbxToUnoValue( xVar.get() ) );
267 }
268 }
269 }
270 sal_Int32 nOutParamCount = aOutParamMap.size();
271 aOutParamIndex.realloc( nOutParamCount );
272 aOutParam.realloc( nOutParamCount );
273 sal_Int16* pOutParamIndex = aOutParamIndex.getArray();
274 Any* pOutParam = aOutParam.getArray();
275 for (auto const& outParam : aOutParamMap)
276 {
277 *pOutParamIndex = outParam.first;
278 *pOutParam = outParam.second;
279 ++pOutParamIndex;
280 ++pOutParam;
281 }
282 }
283 }
284
285 // get return value
286 aReturn = sbxToUnoValue( xReturn.get() );
287
288 pMethod->SetParameters( nullptr );
289
290 return aReturn;
291 }
292
293 void SAL_CALL
294 DocObjectWrapper::setValue( const OUString& aPropertyName, const Any& aValue )
295 {
296 if ( m_xAggInv.is() && m_xAggInv->hasProperty( aPropertyName ) )
297 return m_xAggInv->setValue( aPropertyName, aValue );
298
299 SbPropertyRef pProperty = getProperty( aPropertyName );
300 if ( !pProperty.is() )
301 throw UnknownPropertyException(aPropertyName);
302 unoToSbxValue( pProperty.get(), aValue );
303 }
304
305 Any SAL_CALL
306 DocObjectWrapper::getValue( const OUString& aPropertyName )
307 {
308 if ( m_xAggInv.is() && m_xAggInv->hasProperty( aPropertyName ) )
309 return m_xAggInv->getValue( aPropertyName );
310
311 SbPropertyRef pProperty = getProperty( aPropertyName );
312 if ( !pProperty.is() )
313 throw UnknownPropertyException(aPropertyName);
314
315 SbxVariable* pProp = pProperty.get();
316 if ( pProp->GetType() == SbxEMPTY )
317 pProperty->Broadcast( SfxHintId::BasicDataWanted );
318
319 Any aRet = sbxToUnoValue( pProp );
320 return aRet;
321 }
322
323 sal_Bool SAL_CALL
324 DocObjectWrapper::hasMethod( const OUString& aName )
325 {
326 if ( m_xAggInv.is() && m_xAggInv->hasMethod( aName ) )
327 return true;
328 return getMethod( aName ).is();
329 }
330
331 sal_Bool SAL_CALL
332 DocObjectWrapper::hasProperty( const OUString& aName )
333 {
334 bool bRes = false;
335 if ( m_xAggInv.is() && m_xAggInv->hasProperty( aName ) )
336 bRes = true;
337 else bRes = getProperty( aName ).is();
338 return bRes;
339 }
340
341 Any SAL_CALL DocObjectWrapper::queryInterface( const Type& aType )
342 {
343 Any aRet = DocObjectWrapper_BASE::queryInterface( aType );
344 if ( aRet.hasValue() )
345 return aRet;
346 else if ( m_xAggProxy.is() )
347 aRet = m_xAggProxy->queryAggregation( aType );
348 return aRet;
349 }
350
351 SbMethodRef DocObjectWrapper::getMethod( const OUString& aName )
352 {
353 SbMethodRef pMethod;
354 if ( m_pMod )
355 {
356 SbxFlagBits nSaveFlgs = m_pMod->GetFlags();
357 // Limit search to this module
358 m_pMod->ResetFlag( SbxFlagBits::GlobalSearch );
359 pMethod = dynamic_cast<SbMethod*>(m_pMod->SbModule::Find(aName, SbxClassType::Method));
360 m_pMod->SetFlags( nSaveFlgs );
361 }
362
363 return pMethod;
364 }
365
366 SbPropertyRef DocObjectWrapper::getProperty( const OUString& aName )
367 {
368 SbPropertyRef pProperty;
369 if ( m_pMod )
370 {
371 SbxFlagBits nSaveFlgs = m_pMod->GetFlags();
372 // Limit search to this module.
373 m_pMod->ResetFlag( SbxFlagBits::GlobalSearch );
374 pProperty = dynamic_cast<SbProperty*>(m_pMod->SbModule::Find(aName, SbxClassType::Property));
375 m_pMod->SetFlag( nSaveFlgs );
376 }
377
378 return pProperty;
379 }
380
381
382 uno::Reference< frame::XModel > getDocumentModel( StarBASIC* pb )
383 {
384 uno::Reference< frame::XModel > xModel;
385 if( pb && pb->IsDocBasic() )
386 {
387 uno::Any aDoc;
388 if( pb->GetUNOConstant( u"ThisComponent"_ustr, aDoc ) )
389 xModel.set( aDoc, uno::UNO_QUERY );
390 }
391 return xModel;
392 }
393
394 static uno::Reference< vba::XVBACompatibility > getVBACompatibility( const uno::Reference< frame::XModel >& rxModel )
395 {
396 uno::Reference< vba::XVBACompatibility > xVBACompat;
397 try
398 {
399 uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW );
400 xVBACompat.set( xModelProps->getPropertyValue( u"BasicLibraries"_ustr ), uno::UNO_QUERY );
401 }
402 catch(const uno::Exception& )
403 {
404 }
405 return xVBACompat;
406 }
407
408 static bool getDefaultVBAMode( StarBASIC* pb )
409 {
410 uno::Reference< frame::XModel > xModel( getDocumentModel( pb ) );
411 if (!xModel.is())
412 return false;
413 uno::Reference< vba::XVBACompatibility > xVBACompat = getVBACompatibility( xModel );
414 return xVBACompat.is() && xVBACompat->getVBACompatibilityMode();
415 }
416
417 // A Basic module has set EXTSEARCH, so that the elements, that the module contains,
418 // could be found from other module.
419
420 SbModule::SbModule( const OUString& rName, bool bVBASupport )
421 : SbxObject( u"StarBASICModule"_ustr )
422 , mbVBASupport(bVBASupport), mbCompat(bVBASupport)
423 {
424 SetName( rName );
425 SetFlag( SbxFlagBits::ExtSearch | SbxFlagBits::GlobalSearch );
426 SetModuleType( script::ModuleType::NORMAL );
427
428 // #i92642: Set name property to initial name
429 SbxVariable* pNameProp = pProps->Find( u"Name"_ustr, SbxClassType::Property );
430 if( pNameProp != nullptr )
431 {
432 pNameProp->PutString( GetName() );
433 }
434 }
435
436 SbModule::~SbModule()
437 {
438 SAL_INFO("basic","Module named " << GetName() << " is destructing");
439 pImage.reset();
440 pBreaks.reset();
441 pClassData.reset();
442 mxWrapper = nullptr;
443 }
444
445 uno::Reference< script::XInvocation > const &
446 SbModule::GetUnoModule()
447 {
448 if ( !mxWrapper.is() )
449 mxWrapper = new DocObjectWrapper( this );
450
451 SAL_INFO("basic","Module named " << GetName() << " returning wrapper mxWrapper (0x" << mxWrapper.get() <<")" );
452 return mxWrapper;
453 }
454
455 bool SbModule::IsCompiled() const
456 {
457 return pImage != nullptr;
458 }
459
460 const SbxObject* SbModule::FindType( const OUString& aTypeName ) const
461 {
462 return pImage ? pImage->FindType( aTypeName ) : nullptr;
463 }
464
465
466 // From the code generator: deletion of images and the opposite of validation for entries
467
468 void SbModule::StartDefinitions()
469 {
470 pImage.reset();
471 if( pClassData )
472 pClassData->clear();
473
474 // methods and properties persist, but they are invalid;
475 // at least are the information under certain conditions clogged
476 sal_uInt32 i;
477 for (i = 0; i < pMethods->Count(); i++)
478 {
479 SbMethod* p = dynamic_cast<SbMethod*>(pMethods->Get(i));
480 if( p )
481 p->bInvalid = true;
482 }
483 for (i = 0; i < pProps->Count();)
484 {
485 SbProperty* p = dynamic_cast<SbProperty*>(pProps->Get(i));
486 if( p )
487 pProps->Remove( i );
488 else
489 i++;
490 }
491 }
492
493 // request/create method
494
495 SbMethod* SbModule::GetMethod( const OUString& rName, SbxDataType t )
496 {
497 SbxVariable* p = pMethods->Find( rName, SbxClassType::Method );
498 SbMethod* pMeth = dynamic_cast<SbMethod*>( p );
499 if( p && !pMeth )
500 {
501 pMethods->Remove( p );
502 }
503 if( !pMeth )
504 {
505 pMeth = new SbMethod( rName, t, this );
506 pMeth->SetParent( this );
507 pMeth->SetFlags( SbxFlagBits::Read );
508 pMethods->Put(pMeth, pMethods->Count());
509 StartListening(pMeth->GetBroadcaster(), DuplicateHandling::Prevent);
510 }
511 // The method is per default valid, because it could be
512 // created from the compiler (code generator) as well.
513 pMeth->bInvalid = false;
514 pMeth->ResetFlag( SbxFlagBits::Fixed );
515 pMeth->SetFlag( SbxFlagBits::Write );
516 pMeth->SetType( t );
517 pMeth->ResetFlag( SbxFlagBits::Write );
518 if( t != SbxVARIANT )
519 {
520 pMeth->SetFlag( SbxFlagBits::Fixed );
521 }
522 return pMeth;
523 }
524
525 SbMethod* SbModule::FindMethod( const OUString& rName, SbxClassType t )
526 {
527 return dynamic_cast<SbMethod*> (pMethods->Find( rName, t ));
528 }
529
530
531 // request/create property
532
533 SbProperty* SbModule::GetProperty( const OUString& rName, SbxDataType t )
534 {
535 SbxVariable* p = pProps->Find( rName, SbxClassType::Property );
536 SbProperty* pProp = dynamic_cast<SbProperty*>( p );
537 if( p && !pProp )
538 {
539 pProps->Remove( p );
540 }
541 if( !pProp )
542 {
543 pProp = new SbProperty( rName, t, this );
544 pProp->SetFlag( SbxFlagBits::ReadWrite );
545 pProp->SetParent( this );
546 pProps->Put(pProp, pProps->Count());
547 StartListening(pProp->GetBroadcaster(), DuplicateHandling::Prevent);
548 }
549 return pProp;
550 }
551
552 void SbModule::GetProcedureProperty( const OUString& rName, SbxDataType t )
553 {
554 SbxVariable* p = pProps->Find( rName, SbxClassType::Property );
555 SbProcedureProperty* pProp = dynamic_cast<SbProcedureProperty*>( p );
556 if( p && !pProp )
557 {
558 pProps->Remove( p );
559 }
560 if( !pProp )
561 {
562 tools::SvRef<SbProcedureProperty> pNewProp = new SbProcedureProperty( rName, t );
563 pNewProp->SetFlag( SbxFlagBits::ReadWrite );
564 pNewProp->SetParent( this );
565 pProps->Put(pNewProp.get(), pProps->Count());
566 StartListening(pNewProp->GetBroadcaster(), DuplicateHandling::Prevent);
567 }
568 }
569
570 void SbModule::GetIfaceMapperMethod( const OUString& rName, SbMethod* pImplMeth )
571 {
572 SbxVariable* p = pMethods->Find( rName, SbxClassType::Method );
573 SbIfaceMapperMethod* pMapperMethod = dynamic_cast<SbIfaceMapperMethod*>( p );
574 if( p && !pMapperMethod )
575 {
576 pMethods->Remove( p );
577 }
578 if( !pMapperMethod )
579 {
580 pMapperMethod = new SbIfaceMapperMethod( rName, pImplMeth );
581 pMapperMethod->SetParent( this );
582 pMapperMethod->SetFlags( SbxFlagBits::Read );
583 pMethods->Put(pMapperMethod, pMethods->Count());
584 }
585 pMapperMethod->bInvalid = false;
586 }
587
588 SbIfaceMapperMethod::~SbIfaceMapperMethod()
589 {
590 }
591
592
593 // From the code generator: remove invalid entries
594
595 void SbModule::EndDefinitions( bool bNewState )
596 {
597 for (sal_uInt32 i = 0; i < pMethods->Count();)
598 {
599 SbMethod* p = dynamic_cast<SbMethod*>(pMethods->Get(i));
600 if( p )
601 {
602 if( p->bInvalid )
603 {
604 pMethods->Remove( p );
605 }
606 else
607 {
608 p->bInvalid = bNewState;
609 i++;
610 }
611 }
612 else
613 i++;
614 }
615 SetModified( true );
616 }
617
618 void SbModule::Clear()
619 {
620 pImage.reset();
621 if( pClassData )
622 pClassData->clear();
623 SbxObject::Clear();
624 }
625
626
627 SbxVariable* SbModule::Find( const OUString& rName, SbxClassType t )
628 {
629 // make sure a search in an uninstantiated class module will fail
630 if (isClassModule() && !GetSbData()->bRunInit)
631 {
632 return nullptr;
633 }
634 SbxVariable* pRes = SbxObject::Find( rName, t );
635 if( !pRes && pImage )
636 {
637 SbiInstance* pInst = GetSbData()->pInst;
638 if( pInst && pInst->IsCompatibility() )
639 {
640 // Put enum types as objects into module,
641 // allows MyEnum.First notation
642 SbxArrayRef xArray = pImage->GetEnums();
643 if( xArray.is() )
644 {
645 SbxVariable* pEnumVar = xArray->Find( rName, SbxClassType::DontCare );
646 SbxObject* pEnumObject = dynamic_cast<SbxObject*>( pEnumVar );
647 if( pEnumObject )
648 {
649 bool bPrivate = pEnumObject->IsSet( SbxFlagBits::Private );
650 OUString aEnumName = pEnumObject->GetName();
651
652 pRes = new SbxVariable( SbxOBJECT );
653 pRes->SetName( aEnumName );
654 pRes->SetParent( this );
655 pRes->SetFlag( SbxFlagBits::Read );
656 if( bPrivate )
657 {
658 pRes->SetFlag( SbxFlagBits::Private );
659 }
660 pRes->PutObject( pEnumObject );
661 }
662 }
663 }
664 }
665 return pRes;
666 }
667
668 // Parent and BASIC are one!
669
670 void SbModule::SetParent( SbxObject* p )
671 {
672 pParent = p;
673 }
674
675 void SbModule::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
676 {
677 const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint);
678 if( !pHint )
679 return;
680
681 SbxVariable* pVar = pHint->GetVar();
682 SbProperty* pProp = dynamic_cast<SbProperty*>( pVar );
683 SbMethod* pMeth = dynamic_cast<SbMethod*>( pVar );
684 SbProcedureProperty* pProcProperty = dynamic_cast<SbProcedureProperty*>( pVar );
685 if( pProcProperty )
686 {
687
688 if( pHint->GetId() == SfxHintId::BasicDataWanted )
689 {
690 OUString aProcName = "Property Get "
691 + pProcProperty->GetName();
692
693 SbxVariable* pMethVar = Find( aProcName, SbxClassType::Method );
694 if( pMethVar )
695 {
696 SbxValues aVals;
697 aVals.eType = SbxVARIANT;
698
699 SbxArray* pArg = pVar->GetParameters();
700 sal_uInt32 nVarParCount = (pArg != nullptr) ? pArg->Count() : 0;
701 if( nVarParCount > 1 )
702 {
703 auto xMethParameters = tools::make_ref<SbxArray>();
704 xMethParameters->Put(pMethVar, 0); // Method as parameter 0
705 for( sal_uInt32 i = 1 ; i < nVarParCount ; ++i )
706 {
707 SbxVariable* pPar = pArg->Get(i);
708 xMethParameters->Put(pPar, i);
709 }
710
711 pMethVar->SetParameters( xMethParameters.get() );
712 pMethVar->Get( aVals );
713 pMethVar->SetParameters( nullptr );
714 }
715 else
716 {
717 pMethVar->Get( aVals );
718 }
719
720 pVar->Put( aVals );
721 }
722 }
723 else if( pHint->GetId() == SfxHintId::BasicDataChanged )
724 {
725 SbxVariable* pMethVar = nullptr;
726
727 bool bSet = pProcProperty->isSet();
728 if( bSet )
729 {
730 pProcProperty->setSet( false );
731
732 OUString aProcName = "Property Set "
733 + pProcProperty->GetName();
734 pMethVar = Find( aProcName, SbxClassType::Method );
735 }
736 if( !pMethVar ) // Let
737 {
738 OUString aProcName = "Property Let "
739 + pProcProperty->GetName();
740 pMethVar = Find( aProcName, SbxClassType::Method );
741 }
742
743 if( pMethVar )
744 {
745 // Setup parameters
746 SbxArrayRef xArray = new SbxArray;
747 xArray->Put(pMethVar, 0); // Method as parameter 0
748 xArray->Put(pVar, 1);
749 pMethVar->SetParameters( xArray.get() );
750
751 SbxValues aVals;
752 pMethVar->Get( aVals );
753 pMethVar->SetParameters( nullptr );
754 }
755 }
756 }
757 if( pProp )
758 {
759 if( pProp->GetModule() != this )
760 SetError( ERRCODE_BASIC_BAD_ACTION );
761 }
762 else if( pMeth )
763 {
764 if( pHint->GetId() == SfxHintId::BasicDataWanted )
765 {
766 if( pMeth->bInvalid && !Compile() )
767 {
768 // auto compile has not worked!
769 StarBASIC::Error( ERRCODE_BASIC_BAD_PROP_VALUE );
770 }
771 else
772 {
773 // Call of a subprogram
774 SbModule* pOld = GetSbData()->pMod;
775 GetSbData()->pMod = this;
776 Run( static_cast<SbMethod*>(pVar) );
777 GetSbData()->pMod = pOld;
778 }
779 }
780 }
781 else
782 {
783 // #i92642: Special handling for name property to avoid
784 // side effects when using name as variable implicitly
785 bool bForwardToSbxObject = true;
786
787 const SfxHintId nId = pHint->GetId();
788 if( (nId == SfxHintId::BasicDataWanted || nId == SfxHintId::BasicDataChanged) &&
789 pVar->GetName().equalsIgnoreAsciiCase( "name" ) )
790 {
791 bForwardToSbxObject = false;
792 }
793 if( bForwardToSbxObject )
794 {
795 SbxObject::Notify( rBC, rHint );
796 }
797 }
798 }
799
800 // The setting of the source makes the image invalid
801 // and scans the method definitions newly in
802
803 void SbModule::SetSource( const OUString& r )
804 {
805 // Default basic mode to library container mode, but... allow Option VBASupport 0/1 override
806 SetVBASupport( getDefaultVBAMode( static_cast< StarBASIC*>( GetParent() ) ) );
807 aOUSource = r;
808 StartDefinitions();
809 SbiTokenizer aTok( r );
810 aTok.SetCompatible( IsVBASupport() );
811
812 while( !aTok.IsEof() )
813 {
814 SbiToken eEndTok = NIL;
815
816 // Searching for SUB or FUNCTION
817 SbiToken eLastTok = NIL;
818 while( !aTok.IsEof() )
819 {
820 // #32385: not by declare
821 SbiToken eCurTok = aTok.Next();
822 if( eLastTok != DECLARE )
823 {
824 if( eCurTok == SUB )
825 {
826 eEndTok = ENDSUB; break;
827 }
828 if( eCurTok == FUNCTION )
829 {
830 eEndTok = ENDFUNC; break;
831 }
832 if( eCurTok == PROPERTY )
833 {
834 eEndTok = ENDPROPERTY; break;
835 }
836 if( eCurTok == OPTION )
837 {
838 eCurTok = aTok.Next();
839 if( eCurTok == COMPATIBLE )
840 {
841 mbCompat = true;
842 aTok.SetCompatible( true );
843 }
844 else if ( ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) )
845 {
846 bool bIsVBA = ( aTok.GetDbl()== 1 );
847 SetVBASupport( bIsVBA );
848 aTok.SetCompatible( bIsVBA );
849 }
850 else if (eCurTok == CLASSMODULE)
851 {
852 SetModuleType(css::script::ModuleType::CLASS);
853 }
854 }
855 }
856 eLastTok = eCurTok;
857 }
858 // Definition of the method
859 SbMethod* pMeth = nullptr;
860 if( eEndTok != NIL )
861 {
862 sal_uInt16 nLine1 = aTok.GetLine();
863 if( aTok.Next() == SYMBOL )
864 {
865 const OUString& rName_( aTok.GetSym() );
866 SbxDataType t = aTok.GetType();
867 if( t == SbxVARIANT && eEndTok == ENDSUB )
868 {
869 t = SbxVOID;
870 }
871 pMeth = GetMethod( rName_, t );
872 pMeth->nLine1 = pMeth->nLine2 = nLine1;
873 // The method is for a start VALID
874 pMeth->bInvalid = false;
875 }
876 else
877 {
878 eEndTok = NIL;
879 }
880 }
881 // Skip up to END SUB/END FUNCTION
882 if( eEndTok != NIL )
883 {
884 while( !aTok.IsEof() )
885 {
886 if( aTok.Next() == eEndTok )
887 {
888 pMeth->nLine2 = aTok.GetLine();
889 break;
890 }
891 }
892 if( aTok.IsEof() )
893 {
894 pMeth->nLine2 = aTok.GetLine();
895 }
896 }
897 }
898 EndDefinitions( true );
899 }
900
901 // Broadcast of a hint to all Basics
902
903 static void SendHint_( SbxObject* pObj, SfxHintId nId, SbMethod* p )
904 {
905 // Self a BASIC?
906 if( dynamic_cast<const StarBASIC *>(pObj) != nullptr && pObj->IsBroadcaster() )
907 pObj->GetBroadcaster().Broadcast( SbxHint( nId, p ) );
908 // Then ask for the subobjects
909 SbxArray* pObjs = pObj->GetObjects();
910 for (sal_uInt32 i = 0; i < pObjs->Count(); i++)
911 {
912 SbxVariable* pVar = pObjs->Get(i);
913 if( dynamic_cast<const SbxObject *>(pVar) != nullptr )
914 SendHint_( dynamic_cast<SbxObject*>( pVar), nId, p );
915 }
916 }
917
918 static void SendHint( SbxObject* pObj, SfxHintId nId, SbMethod* p )
919 {
920 while( pObj->GetParent() )
921 pObj = pObj->GetParent();
922 SendHint_( pObj, nId, p );
923 }
924
925 // #57841 Clear Uno-Objects, which were held in RTL functions,
926 // at the end of the program, so that nothing is held
927 static void ClearUnoObjectsInRTL_Impl_Rek( StarBASIC* pBasic )
928 {
929 // delete the return value of CreateUnoService
930 SbxVariable* pVar = pBasic->GetRtl()->Find( u"CreateUnoService"_ustr, SbxClassType::Method );
931 if( pVar )
932 {
933 pVar->SbxValue::Clear();
934 }
935 // delete the return value of CreateUnoDialog
936 pVar = pBasic->GetRtl()->Find( u"CreateUnoDialog"_ustr, SbxClassType::Method );
937 if( pVar )
938 {
939 pVar->SbxValue::Clear();
940 }
941 // delete the return value of CDec
942 pVar = pBasic->GetRtl()->Find( u"CDec"_ustr, SbxClassType::Method );
943 if( pVar )
944 {
945 pVar->SbxValue::Clear();
946 }
947 // delete return value of CreateObject
948 pVar = pBasic->GetRtl()->Find( u"CreateObject"_ustr, SbxClassType::Method );
949 if( pVar )
950 {
951 pVar->SbxValue::Clear();
952 }
953 // Go over all Sub-Basics
954 SbxArray* pObjs = pBasic->GetObjects();
955 sal_uInt32 nCount = pObjs->Count();
956 for( sal_uInt32 i = 0 ; i < nCount ; i++ )
957 {
958 SbxVariable* pObjVar = pObjs->Get(i);
959 StarBASIC* pSubBasic = dynamic_cast<StarBASIC*>( pObjVar );
960 if( pSubBasic )
961 {
962 ClearUnoObjectsInRTL_Impl_Rek( pSubBasic );
963 }
964 }
965 }
966
967 static void ClearUnoObjectsInRTL_Impl( StarBASIC* pBasic )
968 {
969 // #67781 Delete return values of the Uno-methods
970 clearUnoMethods();
971
972 ClearUnoObjectsInRTL_Impl_Rek( pBasic );
973
974 // Search for the topmost Basic
975 SbxObject* p = pBasic;
976 while( p->GetParent() )
977 p = p->GetParent();
978 if( static_cast<StarBASIC*>(p) != pBasic )
979 ClearUnoObjectsInRTL_Impl_Rek( static_cast<StarBASIC*>(p) );
980 }
981
982
983 void SbModule::SetVBASupport( bool bSupport )
984 {
985 if( mbVBASupport == bSupport )
986 return;
987
988 mbVBASupport = bSupport;
989 // initialize VBA document API
990 if( mbVBASupport ) try
991 {
992 mbCompat = true;
993 StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() );
994 uno::Reference< lang::XMultiServiceFactory > xFactory( getDocumentModel( pBasic ), uno::UNO_QUERY_THROW );
995 xFactory->createInstance( u"ooo.vba.VBAGlobals"_ustr );
996 }
997 catch( Exception& )
998 {
999 }
1000 }
1001
1002 namespace
1003 {
1004 class RunInitGuard
1005 {
1006 protected:
1007 std::unique_ptr<SbiRuntime> m_xRt;
1008 SbiGlobals* m_pSbData;
1009 SbModule* m_pOldMod;
1010 public:
1011 RunInitGuard(SbModule* pModule, SbMethod* pMethod, sal_uInt32 nArg, SbiGlobals* pSbData)
1012 : m_xRt(new SbiRuntime(pModule, pMethod, nArg))
1013 , m_pSbData(pSbData)
1014 , m_pOldMod(pSbData->pMod)
1015 {
1016 m_xRt->pNext = pSbData->pInst->pRun;
1017 m_pSbData->pMod = pModule;
1018 m_pSbData->pInst->pRun = m_xRt.get();
1019 }
1020 void run()
1021 {
1022 while (m_xRt->Step()) {}
1023 }
1024 virtual ~RunInitGuard()
1025 {
1026 m_pSbData->pInst->pRun = m_xRt->pNext;
1027 m_pSbData->pMod = m_pOldMod;
1028 m_xRt.reset();
1029 }
1030 };
1031
1032 class RunGuard : public RunInitGuard
1033 {
1034 private:
1035 bool m_bDelInst;
1036 public:
1037 RunGuard(SbModule* pModule, SbMethod* pMethod, sal_uInt32 nArg, SbiGlobals* pSbData, bool bDelInst)
1038 : RunInitGuard(pModule, pMethod, nArg, pSbData)
1039 , m_bDelInst(bDelInst)
1040 {
1041 if (m_xRt->pNext)
1042 m_xRt->pNext->block();
1043 }
1044 virtual ~RunGuard() override
1045 {
1046 if (m_xRt->pNext)
1047 m_xRt->pNext->unblock();
1048
1049 // #63710 It can happen by an another thread handling at events,
1050 // that the show call returns to a dialog (by closing the
1051 // dialog per UI), before a by an event triggered further call returned,
1052 // which stands in Basic more top in the stack and that had been run on
1053 // a Basic-Breakpoint. Then would the instance below destroyed. And if the Basic,
1054 // that stand still in the call, further runs, there is a GPF.
1055 // Thus here had to be wait until the other call comes back.
1056 if (m_bDelInst)
1057 {
1058 // Compare here with 1 instead of 0, because before nCallLvl--
1059 while (m_pSbData->pInst->nCallLvl != 1 && !Application::IsQuit())
1060 Application::Yield();
1061 }
1062
1063 m_pSbData->pInst->nCallLvl--; // Call-Level down again
1064
1065 // Exist an higher-ranking runtime instance?
1066 // Then take over BasicDebugFlags::Break, if set
1067 SbiRuntime* pRtNext = m_xRt->pNext;
1068 if (pRtNext && (m_xRt->GetDebugFlags() & BasicDebugFlags::Break))
1069 pRtNext->SetDebugFlags(BasicDebugFlags::Break);
1070 }
1071 };
1072 }
1073
1074 // Run a Basic-subprogram
1075 void SbModule::Run( SbMethod* pMeth )
1076 {
1077 SAL_INFO("basic","About to run " << pMeth->GetName() << ", vba compatmode is " << mbVBASupport );
1078
1079 static sal_uInt16 nMaxCallLevel = 0;
1080
1081 SbiGlobals* pSbData = GetSbData();
1082
1083 bool bDelInst = pSbData->pInst == nullptr;
1084 bool bQuit = false;
1085 StarBASICRef xBasic;
1086 uno::Reference< frame::XModel > xModel;
1087 uno::Reference< script::vba::XVBACompatibility > xVBACompat;
1088 if( bDelInst )
1089 {
1090 // #32779: Hold Basic during the execution
1091 xBasic = static_cast<StarBASIC*>( GetParent() );
1092
1093 pSbData->pInst = new SbiInstance( static_cast<StarBASIC*>(GetParent()) );
1094
1095 /* If a VBA script in a document is started, get the VBA compatibility
1096 interface from the document Basic library container, and notify all
1097 VBA script listeners about the started script. */
1098 if( mbVBASupport )
1099 {
1100 StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() );
1101 if( pBasic && pBasic->IsDocBasic() ) try
1102 {
1103 xModel.set( getDocumentModel( pBasic ), uno::UNO_SET_THROW );
1104 xVBACompat.set( getVBACompatibility( xModel ), uno::UNO_SET_THROW );
1105 xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::SCRIPT_STARTED, GetName() );
1106 }
1107 catch(const uno::Exception& )
1108 {
1109 }
1110 }
1111
1112 // Launcher problem
1113 // i80726 The Find below will generate an error in Testtool so we reset it unless there was one before already
1114 bool bWasError = SbxBase::GetError() != ERRCODE_NONE;
1115 SbxVariable* pMSOMacroRuntimeLibVar = Find( u"Launcher"_ustr, SbxClassType::Object );
1116 if ( !bWasError && (SbxBase::GetError() == ERRCODE_BASIC_PROC_UNDEFINED) )
1117 SbxBase::ResetError();
1118 if( pMSOMacroRuntimeLibVar )
1119 {
1120 StarBASIC* pMSOMacroRuntimeLib = dynamic_cast<StarBASIC*>( pMSOMacroRuntimeLibVar );
1121 if( pMSOMacroRuntimeLib )
1122 {
1123 SbxFlagBits nGblFlag = pMSOMacroRuntimeLib->GetFlags() & SbxFlagBits::GlobalSearch;
1124 pMSOMacroRuntimeLib->ResetFlag( SbxFlagBits::GlobalSearch );
1125 SbxVariable* pAppSymbol = pMSOMacroRuntimeLib->Find( u"Application"_ustr, SbxClassType::Method );
1126 pMSOMacroRuntimeLib->SetFlag( nGblFlag );
1127 if( pAppSymbol )
1128 {
1129 pMSOMacroRuntimeLib->SetFlag( SbxFlagBits::ExtSearch ); // Could have been disabled before
1130 pSbData->pMSOMacroRuntimLib = pMSOMacroRuntimeLib;
1131 }
1132 }
1133 }
1134
1135 if( nMaxCallLevel == 0 )
1136 {
1137 #ifdef UNX
1138 struct rlimit rl;
1139 getrlimit ( RLIMIT_STACK, &rl );
1140 #endif
1141 #if defined LINUX
1142 // Empiric value, 900 = needed bytes/Basic call level
1143 // for Linux including 10% safety margin
1144 nMaxCallLevel = rl.rlim_cur / 900;
1145 #elif defined __sun
1146 // Empiric value, 1650 = needed bytes/Basic call level
1147 // for Solaris including 10% safety margin
1148 nMaxCallLevel = rl.rlim_cur / 1650;
1149 #elif defined _WIN32
1150 nMaxCallLevel = 5800;
1151 #else
1152 nMaxCallLevel = MAXRECURSION;
1153 #endif
1154 }
1155 }
1156
1157 // Recursion to deep?
1158 if( ++pSbData->pInst->nCallLvl <= nMaxCallLevel )
1159 {
1160 // Define a globale variable in all Mods
1161 GlobalRunInit( /* bBasicStart = */ bDelInst );
1162
1163 // Appeared a compiler error? Then we don't launch
1164 if( !pSbData->bGlobalInitErr )
1165 {
1166 if( bDelInst )
1167 {
1168 SendHint( GetParent(), SfxHintId::BasicStart, pMeth );
1169
1170 // 1996-10-16: #31460 New concept for StepInto/Over/Out
1171 // For an explanation see runtime.cxx at SbiInstance::CalcBreakCallLevel()
1172 // Identify the BreakCallLevel
1173 pSbData->pInst->CalcBreakCallLevel( pMeth->GetDebugFlags() );
1174 }
1175
1176 {
1177 RunGuard xRuntimeGuard(this, pMeth, pMeth->nStart, pSbData, bDelInst);
1178
1179 if (mbVBASupport)
1180 pSbData->pInst->EnableCompatibility(true);
1181
1182 xRuntimeGuard.run();
1183 }
1184
1185 if( bDelInst )
1186 {
1187 // #57841 Clear Uno-Objects, which were held in RTL functions,
1188 // at the end of the program, so that nothing is held.
1189 ClearUnoObjectsInRTL_Impl( xBasic.get() );
1190
1191 clearNativeObjectWrapperVector();
1192
1193 SAL_WARN_IF(pSbData->pInst->nCallLvl != 0,"basic","BASIC-Call-Level > 0");
1194 delete pSbData->pInst;
1195 pSbData->pInst = nullptr;
1196 bDelInst = false;
1197
1198 // #i30690
1199 SolarMutexGuard aSolarGuard;
1200 SendHint( GetParent(), SfxHintId::BasicStop, pMeth );
1201
1202 GlobalRunDeInit();
1203
1204 if( xVBACompat.is() )
1205 {
1206 // notify all VBA script listeners about the stopped script
1207 try
1208 {
1209 xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::SCRIPT_STOPPED, GetName() );
1210 }
1211 catch(const uno::Exception& )
1212 {
1213 }
1214 // VBA always ensures screenupdating is enabled after completing
1215 ::basic::vba::lockControllersOfAllDocuments( xModel, false );
1216 ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, true );
1217 }
1218 }
1219 }
1220 else
1221 pSbData->pInst->nCallLvl--; // Call-Level down again
1222 }
1223 else
1224 {
1225 pSbData->pInst->nCallLvl--; // Call-Level down again
1226 StarBASIC::FatalError( ERRCODE_BASIC_STACK_OVERFLOW );
1227 }
1228
1229 StarBASIC* pBasic = dynamic_cast<StarBASIC*>( GetParent() );
1230 if( bDelInst )
1231 {
1232 // #57841 Clear Uno-Objects, which were held in RTL functions,
1233 // the end of the program, so that nothing is held.
1234 ClearUnoObjectsInRTL_Impl( xBasic.get() );
1235
1236 delete pSbData->pInst;
1237 pSbData->pInst = nullptr;
1238 }
1239 if ( pBasic && pBasic->IsDocBasic() && pBasic->IsQuitApplication() && !pSbData->pInst )
1240 bQuit = true;
1241 if ( bQuit )
1242 {
1243 Application::PostUserEvent( LINK( &AsyncQuitHandler::instance(), AsyncQuitHandler, OnAsyncQuit ) );
1244 }
1245 }
1246
1247 // Execute of the init method of a module after the loading
1248 // or the compilation
1249 void SbModule::RunInit()
1250 {
1251 if( !(pImage
1252 && !pImage->bInit
1253 && pImage->IsFlag( SbiImageFlags::INITCODE )) )
1254 return;
1255
1256 SbiGlobals* pSbData = GetSbData();
1257
1258 // Set flag, so that RunInit get active (Testtool)
1259 pSbData->bRunInit = true;
1260
1261 // The init code starts always here
1262 RunInitGuard(this, nullptr, 0, pSbData).run();
1263
1264 pImage->bInit = true;
1265 pImage->bFirstInit = false;
1266
1267 // RunInit is not active anymore
1268 pSbData->bRunInit = false;
1269 }
1270
1271 // Delete with private/dim declared variables
1272
1273 void SbModule::AddVarName( const OUString& aName )
1274 {
1275 // see if the name is added already
1276 for ( const auto& rModuleVariableName: mModuleVariableNames )
1277 {
1278 if ( aName == rModuleVariableName )
1279 return;
1280 }
1281 mModuleVariableNames.push_back( aName );
1282 }
1283
1284 void SbModule::RemoveVars()
1285 {
1286 for ( const auto& rModuleVariableName: mModuleVariableNames )
1287 {
1288 // We don't want a Find being called in a derived class ( e.g.
1289 // SbUserform because it could trigger say an initialise event
1290 // which would cause basic to be re-run in the middle of the init ( and remember RemoveVars is called from compile and we don't want code to run as part of the compile )
1291 SbxVariableRef p = SbModule::Find( rModuleVariableName, SbxClassType::Property );
1292 if( p.is() )
1293 Remove( p.get() );
1294 }
1295 }
1296
1297 void SbModule::ClearPrivateVars()
1298 {
1299 for (sal_uInt32 i = 0; i < pProps->Count(); i++)
1300 {
1301 SbProperty* p = dynamic_cast<SbProperty*>(pProps->Get(i));
1302 if( p )
1303 {
1304 // Delete not the arrays, only their content
1305 if( p->GetType() & SbxARRAY )
1306 {
1307 SbxArray* pArray = dynamic_cast<SbxArray*>( p->GetObject() );
1308 if( pArray )
1309 {
1310 for (sal_uInt32 j = 0; j < pArray->Count(); j++)
1311 {
1312 SbxVariable* pj = pArray->Get(j);
1313 pj->SbxValue::Clear();
1314 }
1315 }
1316 }
1317 else
1318 {
1319 p->SbxValue::Clear();
1320 }
1321 }
1322 }
1323 }
1324
1325 void SbModule::implClearIfVarDependsOnDeletedBasic(SbxVariable& rVar, StarBASIC* pDeletedBasic)
1326 {
1327 if (rVar.SbxValue::GetType() != SbxOBJECT || dynamic_cast<const SbProcedureProperty*>(&rVar) != nullptr)
1328 return;
1329
1330 SbxObject* p = dynamic_cast<SbxObject*>(rVar.GetObject());
1331 if (p == nullptr)
1332 return;
1333
1334 SbModule* pMod = dynamic_cast<SbModule*>( p );
1335 if( pMod != nullptr )
1336 pMod->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
1337
1338 while( (p = p->GetParent()) != nullptr )
1339 {
1340 if (p == pDeletedBasic)
1341 {
1342 rVar.SbxValue::Clear();
1343 break;
1344 }
1345 }
1346 }
1347
1348 void SbModule::ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic )
1349 {
1350 for (sal_uInt32 i = 0; i < pProps->Count(); i++)
1351 {
1352 SbProperty* p = dynamic_cast<SbProperty*>(pProps->Get(i));
1353 if( p )
1354 {
1355 if( p->GetType() & SbxARRAY )
1356 {
1357 SbxArray* pArray = dynamic_cast<SbxArray*>( p->GetObject() );
1358 if( pArray )
1359 {
1360 for (sal_uInt32 j = 0; j < pArray->Count(); j++)
1361 {
1362 SbxVariable* pVar = pArray->Get(j);
1363 implClearIfVarDependsOnDeletedBasic(*pVar, pDeletedBasic);
1364 }
1365 }
1366 }
1367 else
1368 {
1369 implClearIfVarDependsOnDeletedBasic(*p, pDeletedBasic);
1370 }
1371 }
1372 }
1373 }
1374
1375 void StarBASIC::ClearAllModuleVars()
1376 {
1377 // Initialise the own module
1378 for (const auto& rModule: pModules)
1379 {
1380 // Initialise only, if the startcode was already executed
1381 if( rModule->pImage && rModule->pImage->bInit && !rModule->isClassModule() && dynamic_cast<const SbObjModule*>( rModule.get()) == nullptr )
1382 rModule->ClearPrivateVars();
1383 }
1384
1385 }
1386
1387 // Execution of the init-code of all module
1388 void SbModule::GlobalRunInit( bool bBasicStart )
1389 {
1390 // If no Basic-Start, only initialise, if the module is not initialised
1391 if( !bBasicStart )
1392 if( !pImage || pImage->bInit )
1393 return;
1394
1395 // Initialise GlobalInitErr-Flag for Compiler-Error
1396 // With the help of this flags could be located in SbModule::Run() after the call of
1397 // GlobalRunInit, if at the initialising of the module
1398 // an error occurred. Then it will not be launched.
1399 GetSbData()->bGlobalInitErr = false;
1400
1401 // Parent of the module is a Basic
1402 StarBASIC *pBasic = dynamic_cast<StarBASIC*>( GetParent() );
1403 if( !pBasic )
1404 return;
1405
1406 pBasic->InitAllModules();
1407
1408 SbxObject* pParent_ = pBasic->GetParent();
1409 if( !pParent_ )
1410 return;
1411
1412 StarBASIC * pParentBasic = dynamic_cast<StarBASIC*>( pParent_ );
1413 if( !pParentBasic )
1414 return;
1415
1416 pParentBasic->InitAllModules( pBasic );
1417
1418 // #109018 Parent can also have a parent (library in doc)
1419 SbxObject* pParentParent = pParentBasic->GetParent();
1420 if( pParentParent )
1421 {
1422 StarBASIC * pParentParentBasic = dynamic_cast<StarBASIC*>( pParentParent );
1423 if( pParentParentBasic )
1424 pParentParentBasic->InitAllModules( pParentBasic );
1425 }
1426 }
1427
1428 void SbModule::GlobalRunDeInit()
1429 {
1430 StarBASIC *pBasic = dynamic_cast<StarBASIC*>( GetParent() );
1431 if( pBasic )
1432 {
1433 pBasic->DeInitAllModules();
1434
1435 SbxObject* pParent_ = pBasic->GetParent();
1436 if( pParent_ )
1437 pBasic = dynamic_cast<StarBASIC*>( pParent_ );
1438 if( pBasic )
1439 pBasic->DeInitAllModules();
1440 }
1441 }
1442
1443 // Search for the next STMNT-Command in the code. This was used from the STMNT-
1444 // Opcode to set the endcolumn.
1445
1446 const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine, sal_uInt16& nCol ) const
1447 {
1448 return FindNextStmnt( p, nLine, nCol, false );
1449 }
1450
1451 const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine, sal_uInt16& nCol,
1452 bool bFollowJumps, const SbiImage* pImg ) const
1453 {
1454 sal_uInt32 nPC = static_cast<sal_uInt32>( p - pImage->GetCode() );
1455 while( nPC < pImage->GetCodeSize() )
1456 {
1457 SbiOpcode eOp = static_cast<SbiOpcode>( *p++ );
1458 nPC++;
1459 if( bFollowJumps && eOp == SbiOpcode::JUMP_ && pImg )
1460 {
1461 SAL_WARN_IF( !pImg, "basic", "FindNextStmnt: pImg==NULL with FollowJumps option" );
1462 sal_uInt32 nOp1 = *p++; nOp1 |= *p++ << 8;
1463 nOp1 |= *p++ << 16; nOp1 |= *p++ << 24;
1464 p = pImg->GetCode() + nOp1;
1465 }
1466 else if( eOp >= SbiOpcode::SbOP1_START && eOp <= SbiOpcode::SbOP1_END )
1467 {
1468 p += 4;
1469 nPC += 4;
1470 }
1471 else if( eOp == SbiOpcode::STMNT_ )
1472 {
1473 sal_uInt32 nl, nc;
1474 nl = *p++; nl |= *p++ << 8;
1475 nl |= *p++ << 16 ; nl |= *p++ << 24;
1476 nc = *p++; nc |= *p++ << 8;
1477 nc |= *p++ << 16 ; nc |= *p++ << 24;
1478 nLine = static_cast<sal_uInt16>(nl); nCol = static_cast<sal_uInt16>(nc);
1479 return p;
1480 }
1481 else if( eOp >= SbiOpcode::SbOP2_START && eOp <= SbiOpcode::SbOP2_END )
1482 {
1483 p += 8;
1484 nPC += 8;
1485 }
1486 else if( eOp < SbiOpcode::SbOP0_START || eOp > SbiOpcode::SbOP0_END )
1487 {
1488 StarBASIC::FatalError( ERRCODE_BASIC_INTERNAL_ERROR );
1489 break;
1490 }
1491 }
1492 return nullptr;
1493 }
1494
1495 // Test, if a line contains STMNT-Opcodes
1496
1497 bool SbModule::IsBreakable( sal_uInt16 nLine ) const
1498 {
1499 if( !pImage )
1500 return false;
1501 const sal_uInt8* p = pImage->GetCode();
1502 sal_uInt16 nl, nc;
1503 while( ( p = FindNextStmnt( p, nl, nc ) ) != nullptr )
1504 if( nl == nLine )
1505 return true;
1506 return false;
1507 }
1508
1509 bool SbModule::IsBP( sal_uInt16 nLine ) const
1510 {
1511 if( pBreaks )
1512 {
1513 for( size_t i = 0; i < pBreaks->size(); i++ )
1514 {
1515 sal_uInt16 b = pBreaks->operator[]( i );
1516 if( b == nLine )
1517 return true;
1518 if( b < nLine )
1519 break;
1520 }
1521 }
1522 return false;
1523 }
1524
1525 bool SbModule::SetBP( sal_uInt16 nLine )
1526 {
1527 if( !IsBreakable( nLine ) )
1528 return false;
1529 if( !pBreaks )
1530 pBreaks.reset(new SbiBreakpoints);
1531 auto it = std::find_if(pBreaks->begin(), pBreaks->end(),
1532 [&nLine](const sal_uInt16 b) { return b <= nLine; });
1533 if (it != pBreaks->end() && *it == nLine)
1534 return true;
1535 pBreaks->insert( it, nLine );
1536
1537 // #38568: Set during runtime as well here BasicDebugFlags::Break
1538 if( GetSbData()->pInst && GetSbData()->pInst->pRun )
1539 GetSbData()->pInst->pRun->SetDebugFlags( BasicDebugFlags::Break );
1540
1541 return IsBreakable( nLine );
1542 }
1543
1544 bool SbModule::ClearBP( sal_uInt16 nLine )
1545 {
1546 bool bRes = false;
1547 if( pBreaks )
1548 {
1549 auto it = std::find_if(pBreaks->begin(), pBreaks->end(),
1550 [&nLine](const sal_uInt16 b) { return b <= nLine; });
1551 bRes = (it != pBreaks->end()) && (*it == nLine);
1552 if (bRes)
1553 pBreaks->erase(it);
1554 if (pBreaks->empty())
1555 pBreaks.reset();
1556 }
1557 return bRes;
1558 }
1559
1560 void SbModule::ClearAllBP()
1561 {
1562 pBreaks.reset();
1563 }
1564
1565 void
1566 SbModule::fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg ) const
1567 {
1568 if ( !pImg )
1569 pImg = pImage.get();
1570 for (sal_uInt32 i = 0; i < pMethods->Count(); i++)
1571 {
1572 SbMethod* pMeth = dynamic_cast<SbMethod*>(pMethods->Get(i));
1573 if( pMeth )
1574 {
1575 //fixup method start positions
1576 if ( bCvtToLegacy )
1577 pMeth->nStart = pImg->CalcLegacyOffset( pMeth->nStart );
1578 else
1579 pMeth->nStart = pImg->CalcNewOffset( static_cast<sal_uInt16>(pMeth->nStart) );
1580 }
1581 }
1582
1583 }
1584
1585 bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer )
1586 {
1587 Clear();
1588 if( !SbxObject::LoadData( rStrm, 1 ) )
1589 return false;
1590 // As a precaution...
1591 SetFlag( SbxFlagBits::ExtSearch | SbxFlagBits::GlobalSearch );
1592 sal_uInt8 bImage;
1593 rStrm.ReadUChar( bImage );
1594 if( !bImage )
1595 return true;
1596
1597 std::unique_ptr<SbiImage> p(new SbiImage);
1598 sal_uInt32 nImgVer = 0;
1599
1600 if( !p->Load( rStrm, nImgVer ) )
1601 {
1602 return false;
1603 }
1604 // If the image is in old format, we fix up the method start offsets
1605 if ( nImgVer < B_IMG_VERSION_12 )
1606 {
1607 fixUpMethodStart( false, p.get() );
1608 p->ReleaseLegacyBuffer();
1609 }
1610 aComment = p->aComment;
1611 SetName( p->aName );
1612 if( p->GetCodeSize() )
1613 {
1614 aOUSource = p->aOUSource;
1615 // Old version: image away
1616 if( nVer == 1 )
1617 {
1618 SetSource( p->aOUSource );
1619 }
1620 else
1621 pImage = std::move(p);
1622 }
1623 else
1624 {
1625 SetSource( p->aOUSource );
1626 }
1627 return true;
1628 }
1629
1630 std::pair<bool, sal_uInt32> SbModule::StoreData( SvStream& rStrm ) const
1631 {
1632 bool bFixup = ( pImage && !pImage->ExceedsLegacyLimits() );
1633 if ( bFixup )
1634 fixUpMethodStart( true );
1635 const auto [bSuccess, nVersion] = SbxObject::StoreData(rStrm);
1636 if (!bSuccess)
1637 return { false, 0 };
1638
1639 if( pImage )
1640 {
1641 pImage->aOUSource = aOUSource;
1642 pImage->aComment = aComment;
1643 pImage->aName = GetName();
1644 rStrm.WriteUChar( 1 );
1645 // # PCode is saved only for legacy formats only
1646 // It should be noted that it probably isn't necessary
1647 // It would be better not to store the image ( more flexible with
1648 // formats )
1649 bool bRes = pImage->Save( rStrm, nVersion );
1650 if ( bFixup )
1651 fixUpMethodStart( false ); // restore method starts
1652 return { bRes, nVersion };
1653
1654 }
1655 else
1656 {
1657 SbiImage aImg;
1658 aImg.aOUSource = aOUSource;
1659 aImg.aComment = aComment;
1660 aImg.aName = GetName();
1661 rStrm.WriteUChar( 1 );
1662 return { aImg.Save(rStrm, nVersion), nVersion };
1663 }
1664 }
1665
1666 bool SbModule::ExceedsImgVersion12ModuleSize()
1667 {
1668 if ( !IsCompiled() )
1669 Compile();
1670 return pImage && pImage->ExceedsImgVersion12Limits();
1671 }
1672
1673 namespace {
1674
1675 class ErrorHdlResetter
1676 {
1677 Link<StarBASIC*,bool> mErrHandler;
1678 bool mbError;
1679 public:
1680 ErrorHdlResetter()
1681 : mErrHandler(StarBASIC::GetGlobalErrorHdl()) // save error handler
1682 , mbError( false )
1683 {
1684 // set new error handler
1685 StarBASIC::SetGlobalErrorHdl( LINK( this, ErrorHdlResetter, BasicErrorHdl ) );
1686 }
1687 ~ErrorHdlResetter()
1688 {
1689 // restore error handler
1690 StarBASIC::SetGlobalErrorHdl(mErrHandler);
1691 }
1692 DECL_LINK( BasicErrorHdl, StarBASIC *, bool );
1693 bool HasError() const { return mbError; }
1694 };
1695
1696 }
1697
1698 IMPL_LINK( ErrorHdlResetter, BasicErrorHdl, StarBASIC *, /*pBasic*/, bool)
1699 {
1700 mbError = true;
1701 return false;
1702 }
1703
1704 void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
1705 {
1706 ErrorHdlResetter aErrHdl;
1707 SbxBase::ResetError();
1708
1709 SbiParser aParser(static_cast<StarBASIC*>(GetParent()), this );
1710 aParser.SetCodeCompleting(true);
1711
1712 while( aParser.Parse() ) {}
1713 SbiSymPool* pPool = aParser.pPool;
1714 aCache.Clear();
1715 for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i )
1716 {
1717 SbiSymDef* pSymDef = pPool->Get(i);
1718 //std::cerr << "i: " << i << ", type: " << pSymDef->GetType() << "; name:" << pSymDef->GetName() << std::endl;
1719 if( (pSymDef->GetType() != SbxEMPTY) && (pSymDef->GetType() != SbxNULL) )
1720 aCache.InsertGlobalVar( pSymDef->GetName(), aParser.aGblStrings.Find(pSymDef->GetTypeId()) );
1721
1722 SbiSymPool& rChildPool = pSymDef->GetPool();
1723 for(sal_uInt16 j = 0; j < rChildPool.GetSize(); ++j )
1724 {
1725 SbiSymDef* pChildSymDef = rChildPool.Get(j);
1726 //std::cerr << "j: " << j << ", type: " << pChildSymDef->GetType() << "; name:" << pChildSymDef->GetName() << std::endl;
1727 if( (pChildSymDef->GetType() != SbxEMPTY) && (pChildSymDef->GetType() != SbxNULL) )
1728 aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), aParser.aGblStrings.Find(pChildSymDef->GetTypeId()) );
1729 }
1730 }
1731 }
1732
1733
1734 OUString SbModule::GetKeywordCase( std::u16string_view sKeyword )
1735 {
1736 return SbiParser::GetKeywordCase( sKeyword );
1737 }
1738
1739 bool SbModule::HasExeCode()
1740 {
1741 // And empty Image always has the Global Chain set up
1742 static const unsigned char pEmptyImage[] = { 0x45, 0x0 , 0x0, 0x0, 0x0 };
1743 // let's be stricter for the moment than VBA
1744
1745 if (!IsCompiled())
1746 {
1747 ErrorHdlResetter aGblErrHdl;
1748 Compile();
1749 if (aGblErrHdl.HasError()) //assume unsafe on compile error
1750 return true;
1751 }
1752
1753 bool bRes = false;
1754 if (pImage && (pImage->GetCodeSize() != 5 || (memcmp(pImage->GetCode(), pEmptyImage, pImage->GetCodeSize()) != 0 )))
1755 bRes = true;
1756
1757 return bRes;
1758 }
1759
1760 // Store only image, no source
1761 void SbModule::StoreBinaryData( SvStream& rStrm )
1762 {
1763 if (!Compile())
1764 return;
1765
1766 const auto [bSuccess, nVersion] = SbxObject::StoreData(rStrm);
1767 if (!bSuccess)
1768 return;
1769
1770 pImage->aOUSource.clear();
1771 pImage->aComment = aComment;
1772 pImage->aName = GetName();
1773
1774 rStrm.WriteUChar(1);
1775 pImage->Save(rStrm, nVersion);
1776
1777 pImage->aOUSource = aOUSource;
1778 }
1779
1780 // Called for >= OO 1.0 passwd protected libraries only
1781
1782 void SbModule::LoadBinaryData( SvStream& rStrm )
1783 {
1784 OUString aKeepSource = aOUSource;
1785 LoadData( rStrm, 2 );
1786 LoadCompleted();
1787 aOUSource = aKeepSource;
1788 }
1789
1790 bool SbModule::LoadCompleted()
1791 {
1792 SbxArray* p = GetMethods().get();
1793 sal_uInt32 i;
1794 for (i = 0; i < p->Count(); i++)
1795 {
1796 SbMethod* q = dynamic_cast<SbMethod*>(p->Get(i));
1797 if( q )
1798 q->pMod = this;
1799 }
1800 p = GetProperties();
1801 for (i = 0; i < p->Count(); i++)
1802 {
1803 SbProperty* q = dynamic_cast<SbProperty*>(p->Get(i));
1804 if( q )
1805 q->pMod = this;
1806 }
1807 return true;
1808 }
1809
1810 void SbModule::handleProcedureProperties( SfxBroadcaster& rBC, const SfxHint& rHint )
1811 {
1812 bool bDone = false;
1813
1814 const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint);
1815 if( pHint )
1816 {
1817 SbxVariable* pVar = pHint->GetVar();
1818 SbProcedureProperty* pProcProperty = dynamic_cast<SbProcedureProperty*>( pVar );
1819 if( pProcProperty )
1820 {
1821 bDone = true;
1822
1823 if( pHint->GetId() == SfxHintId::BasicDataWanted )
1824 {
1825 OUString aProcName = "Property Get "
1826 + pProcProperty->GetName();
1827
1828 SbxVariable* pMeth = Find( aProcName, SbxClassType::Method );
1829 if( pMeth )
1830 {
1831 SbxValues aVals;
1832 aVals.eType = SbxVARIANT;
1833
1834 SbxArray* pArg = pVar->GetParameters();
1835 sal_uInt32 nVarParCount = (pArg != nullptr) ? pArg->Count() : 0;
1836 if( nVarParCount > 1 )
1837 {
1838 SbxArrayRef xMethParameters = new SbxArray;
1839 xMethParameters->Put(pMeth, 0); // Method as parameter 0
1840 for( sal_uInt32 i = 1 ; i < nVarParCount ; ++i )
1841 {
1842 SbxVariable* pPar = pArg->Get(i);
1843 xMethParameters->Put(pPar, i);
1844 }
1845
1846 pMeth->SetParameters( xMethParameters.get() );
1847 pMeth->Get( aVals );
1848 pMeth->SetParameters( nullptr );
1849 }
1850 else
1851 {
1852 pMeth->Get( aVals );
1853 }
1854
1855 pVar->Put( aVals );
1856 }
1857 }
1858 else if( pHint->GetId() == SfxHintId::BasicDataChanged )
1859 {
1860 SbxVariable* pMeth = nullptr;
1861
1862 bool bSet = pProcProperty->isSet();
1863 if( bSet )
1864 {
1865 pProcProperty->setSet( false );
1866
1867 OUString aProcName = "Property Set "
1868 + pProcProperty->GetName();
1869 pMeth = Find( aProcName, SbxClassType::Method );
1870 }
1871 if( !pMeth ) // Let
1872 {
1873 OUString aProcName = "Property Let "
1874 + pProcProperty->GetName();
1875 pMeth = Find( aProcName, SbxClassType::Method );
1876 }
1877
1878 if( pMeth )
1879 {
1880 // Setup parameters
1881 SbxArrayRef xArray = new SbxArray;
1882 xArray->Put(pMeth, 0); // Method as parameter 0
1883 xArray->Put(pVar, 1);
1884 pMeth->SetParameters( xArray.get() );
1885
1886 SbxValues aVals;
1887 pMeth->Get( aVals );
1888 pMeth->SetParameters( nullptr );
1889 }
1890 }
1891 }
1892 }
1893
1894 if( !bDone )
1895 SbModule::Notify( rBC, rHint );
1896 }
1897
1898
1899 // Implementation SbJScriptModule (Basic module for JavaScript source code)
1900 SbJScriptModule::SbJScriptModule()
1901 :SbModule( u""_ustr )
1902 {
1903 }
1904
1905 bool SbJScriptModule::LoadData( SvStream& rStrm, sal_uInt16 )
1906 {
1907 Clear();
1908 if( !SbxObject::LoadData( rStrm, 1 ) )
1909 return false;
1910
1911 // Get the source string
1912 aOUSource = rStrm.ReadUniOrByteString( osl_getThreadTextEncoding() );
1913 return true;
1914 }
1915
1916 std::pair<bool, sal_uInt32> SbJScriptModule::StoreData( SvStream& rStrm ) const
1917 {
1918 const auto [bSuccess, nVersion] = SbxObject::StoreData(rStrm);
1919 if( !bSuccess )
1920 return { false, 0 };
1921
1922 // Write the source string
1923 OUString aTmp = aOUSource;
1924 rStrm.WriteUniOrByteString( aTmp, osl_getThreadTextEncoding() );
1925 return { true, nVersion };
1926 }
1927
1928
1929 SbMethod::SbMethod( const OUString& r, SbxDataType t, SbModule* p )
1930 : SbxMethod( r, t ), pMod( p )
1931 {
1932 bInvalid = true;
1933 nStart = 0;
1934 nDebugFlags = BasicDebugFlags::NONE;
1935 nLine1 = 0;
1936 nLine2 = 0;
1937 refStatics = new SbxArray;
1938 mCaller = nullptr;
1939 // HACK due to 'Reference could not be saved'
1940 SetFlag( SbxFlagBits::NoModify );
1941 }
1942
1943 SbMethod::SbMethod( const SbMethod& r )
1944 : SvRefBase( r ), SbxMethod( r )
1945 {
1946 pMod = r.pMod;
1947 bInvalid = r.bInvalid;
1948 nStart = r.nStart;
1949 nDebugFlags = r.nDebugFlags;
1950 nLine1 = r.nLine1;
1951 nLine2 = r.nLine2;
1952 refStatics = r.refStatics;
1953 mCaller = r.mCaller;
1954 SetFlag( SbxFlagBits::NoModify );
1955 }
1956
1957 SbMethod::~SbMethod()
1958 {
1959 }
1960
1961 void SbMethod::ClearStatics()
1962 {
1963 refStatics = new SbxArray;
1964
1965 }
1966 SbxArray* SbMethod::GetStatics()
1967 {
1968 return refStatics.get();
1969 }
1970
1971 bool SbMethod::LoadData( SvStream& rStrm, sal_uInt16 nVer )
1972 {
1973 if( !SbxMethod::LoadData( rStrm, 1 ) )
1974 return false;
1975
1976 sal_uInt16 nFlag;
1977 rStrm.ReadUInt16( nFlag );
1978
1979 sal_Int16 nTempStart = static_cast<sal_Int16>(nStart);
1980
1981 if( nVer == 2 )
1982 {
1983 rStrm.ReadUInt16( nLine1 ).ReadUInt16( nLine2 ).ReadInt16( nTempStart ).ReadCharAsBool( bInvalid );
1984 //tdf#94617
1985 if (nFlag & 0x8000)
1986 {
1987 sal_uInt16 nMult = nFlag & 0x7FFF;
1988 sal_Int16 const nMax = std::numeric_limits<sal_Int16>::max();
1989 nStart = nMult * nMax + nTempStart;
1990 }
1991 else
1992 {
1993 nStart = nTempStart;
1994 }
1995 }
1996 else
1997 {
1998 nStart = nTempStart;
1999 }
2000
2001 // HACK due to 'Reference could not be saved'
2002 SetFlag( SbxFlagBits::NoModify );
2003
2004 return true;
2005 }
2006
2007 std::pair<bool, sal_uInt32> SbMethod::StoreData( SvStream& rStrm ) const
2008 {
2009 auto [bSuccess, nVersion] = SbxMethod::StoreData(rStrm);
2010 if( !bSuccess )
2011 return { false, 0 };
2012
2013 //tdf#94617
2014 const sal_uInt32 nMax = std::numeric_limits<sal_Int16>::max();
2015 // tdf#142391 - store method using binary format 0x13 only when actually needed, i.e.,
2016 // when method starts at an offset that would overflow 16 bits
2017 const sal_Int16 nStartTemp = nStart % nMax;
2018 sal_uInt16 nDebugFlagsTemp = static_cast<sal_uInt16>(nDebugFlags);
2019 if (nStart >= nMax)
2020 {
2021 assert(nStart <= nMax * 0x7FFF); // Larger addresses can't be stored in version 13
2022 nDebugFlagsTemp = (nStart / nMax) | 0x8000;
2023 nVersion = B_IMG_VERSION_13;
2024 }
2025
2026 rStrm.WriteUInt16( nDebugFlagsTemp )
2027 .WriteInt16( nLine1 )
2028 .WriteInt16( nLine2 )
2029 .WriteInt16( nStartTemp )
2030 .WriteBool( bInvalid );
2031
2032 return { true, nVersion };
2033 }
2034
2035 void SbMethod::GetLineRange( sal_uInt16& l1, sal_uInt16& l2 )
2036 {
2037 l1 = nLine1; l2 = nLine2;
2038 }
2039
2040 // Could later be deleted
2041
2042 SbxInfo* SbMethod::GetInfo()
2043 {
2044 return pInfo.get();
2045 }
2046
2047 // Interface to execute a method of the applications
2048 // With special RefCounting, so that the Basic was not fired of by CloseDocument()
2049 // The return value will be delivered as string.
2050 ErrCode SbMethod::Call( SbxValue* pRet, SbxVariable* pCaller )
2051 {
2052 if ( pCaller )
2053 {
2054 SAL_INFO("basic", "SbMethod::Call Have been passed a caller 0x" << pCaller );
2055 mCaller = pCaller;
2056 }
2057 // Increment the RefCount of the module
2058 tools::SvRef<SbModule> pMod_ = static_cast<SbModule*>(GetParent());
2059
2060 tools::SvRef<StarBASIC> xHolder = static_cast<StarBASIC*>(pMod_->GetParent());
2061
2062 // Establish the values to get the return value
2063 SbxValues aVals;
2064 aVals.eType = SbxVARIANT;
2065
2066 // #104083: Compile BEFORE get
2067 if( bInvalid && !pMod_->Compile() )
2068 StarBASIC::Error( ERRCODE_BASIC_BAD_PROP_VALUE );
2069
2070 // tdf#143582 - clear return value of the method before calling it
2071 Clear();
2072
2073 Get( aVals );
2074 if ( pRet )
2075 pRet->Put( aVals );
2076
2077 // Was there an error
2078 ErrCode nErr = SbxBase::GetError();
2079 SbxBase::ResetError();
2080
2081 mCaller = nullptr;
2082 return nErr;
2083 }
2084
2085
2086 // #100883 Own Broadcast for SbMethod
2087 void SbMethod::Broadcast( SfxHintId nHintId )
2088 {
2089 if( !mpBroadcaster || IsSet( SbxFlagBits::NoBroadcast ) )
2090 return;
2091
2092 // Because the method could be called from outside, test here once again
2093 // the authorisation
2094 if( nHintId == SfxHintId::BasicDataWanted )
2095 if( !CanRead() )
2096 return;
2097 if( nHintId == SfxHintId::BasicDataChanged )
2098 if( !CanWrite() )
2099 return;
2100
2101 if( pMod && !pMod->IsCompiled() )
2102 pMod->Compile();
2103
2104 // Block broadcasts while creating new method
2105 std::unique_ptr<SfxBroadcaster> pSaveBroadcaster = std::move(mpBroadcaster);
2106 SbMethodRef xThisCopy = new SbMethod( *this );
2107 if( mpPar.is() )
2108 {
2109 // Enregister this as element 0, but don't reset the parent!
2110 if( GetType() != SbxVOID ) {
2111 mpPar->PutDirect( xThisCopy.get(), 0 );
2112 }
2113 SetParameters( nullptr );
2114 }
2115
2116 mpBroadcaster = std::move(pSaveBroadcaster);
2117 mpBroadcaster->Broadcast( SbxHint( nHintId, xThisCopy.get() ) );
2118
2119 SbxFlagBits nSaveFlags = GetFlags();
2120 SetFlag( SbxFlagBits::ReadWrite );
2121 pSaveBroadcaster = std::move(mpBroadcaster);
2122 Put( xThisCopy->GetValues_Impl() );
2123 mpBroadcaster = std::move(pSaveBroadcaster);
2124 SetFlags( nSaveFlags );
2125 }
2126
2127
2128 // Implementation of SbJScriptMethod (method class as a wrapper for JavaScript-functions)
2129
2130 SbJScriptMethod::SbJScriptMethod( SbxDataType t )
2131 : SbMethod( u""_ustr, t, nullptr )
2132 {
2133 }
2134
2135 SbJScriptMethod::~SbJScriptMethod()
2136 {}
2137
2138
2139 SbObjModule::SbObjModule( const OUString& rName, const css::script::ModuleInfo& mInfo, bool bIsVbaCompatible )
2140 : SbModule( rName, bIsVbaCompatible )
2141 {
2142 SetModuleType( mInfo.ModuleType );
2143 if ( mInfo.ModuleType == script::ModuleType::FORM )
2144 {
2145 SetClassName( u"Form"_ustr );
2146 }
2147 else if ( mInfo.ModuleObject.is() )
2148 {
2149 SetUnoObject( uno::Any( mInfo.ModuleObject ) );
2150 }
2151 }
2152
2153 SbObjModule::~SbObjModule()
2154 {
2155 }
2156
2157 void
2158 SbObjModule::SetUnoObject( const uno::Any& aObj )
2159 {
2160 SbUnoObject* pUnoObj = pDocObject.get();
2161 if ( pUnoObj && pUnoObj->getUnoAny() == aObj ) // object is equal, nothing to do
2162 return;
2163 pDocObject = new SbUnoObject( GetName(), aObj );
2164
2165 css::uno::Reference< css::lang::XServiceInfo > xServiceInfo( aObj, css::uno::UNO_QUERY_THROW );
2166 if( xServiceInfo->supportsService( u"ooo.vba.excel.Worksheet"_ustr ) )
2167 {
2168 SetClassName( u"Worksheet"_ustr );
2169 }
2170 else if( xServiceInfo->supportsService( u"ooo.vba.excel.Workbook"_ustr ) )
2171 {
2172 SetClassName( u"Workbook"_ustr );
2173 }
2174 }
2175
2176 SbxVariable*
2177 SbObjModule::GetObject()
2178 {
2179 return pDocObject.get();
2180 }
2181 SbxVariable*
2182 SbObjModule::Find( const OUString& rName, SbxClassType t )
2183 {
2184 SbxVariable* pVar = nullptr;
2185 if ( pDocObject )
2186 pVar = pDocObject->Find( rName, t );
2187 if ( !pVar )
2188 pVar = SbModule::Find( rName, t );
2189 return pVar;
2190 }
2191
2192 void SbObjModule::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
2193 {
2194 SbModule::handleProcedureProperties( rBC, rHint );
2195 }
2196
2197
2198 typedef ::cppu::WeakImplHelper<
2199 awt::XTopWindowListener,
2200 awt::XWindowListener,
2201 document::XDocumentEventListener > FormObjEventListener_BASE;
2202
2203 class FormObjEventListenerImpl:
2204 public FormObjEventListener_BASE
2205 {
2206 SbUserFormModule* mpUserForm;
2207 uno::Reference< lang::XComponent > mxComponent;
2208 uno::Reference< frame::XModel > mxModel;
2209 bool mbDisposed;
2210 bool mbOpened;
2211 bool mbActivated;
2212 bool mbShowing;
2213
2214 public:
2215 FormObjEventListenerImpl(const FormObjEventListenerImpl&) = delete;
2216 const FormObjEventListenerImpl& operator=(const FormObjEventListenerImpl&) = delete;
2217 FormObjEventListenerImpl( SbUserFormModule* pUserForm, uno::Reference< lang::XComponent > xComponent, uno::Reference< frame::XModel > xModel ) :
2218 mpUserForm( pUserForm ), mxComponent(std::move( xComponent)), mxModel(std::move( xModel )),
2219 mbDisposed( false ), mbOpened( false ), mbActivated( false ), mbShowing( false )
2220 {
2221 if ( mxComponent.is() )
2222 {
2223 try
2224 {
2225 uno::Reference< awt::XTopWindow >( mxComponent, uno::UNO_QUERY_THROW )->addTopWindowListener( this );
2226 }
2227 catch(const uno::Exception& ) {}
2228 try
2229 {
2230 uno::Reference< awt::XWindow >( mxComponent, uno::UNO_QUERY_THROW )->addWindowListener( this );
2231 }
2232 catch(const uno::Exception& ) {}
2233 }
2234
2235 if ( mxModel.is() )
2236 {
2237 try
2238 {
2239 uno::Reference< document::XDocumentEventBroadcaster >( mxModel, uno::UNO_QUERY_THROW )->addDocumentEventListener( this );
2240 }
2241 catch(const uno::Exception& ) {}
2242 }
2243 }
2244
2245 virtual ~FormObjEventListenerImpl() override
2246 {
2247 removeListener();
2248 }
2249
2250 bool isShowing() const { return mbShowing; }
2251
2252 void removeListener()
2253 {
2254 if ( mxComponent.is() && !mbDisposed )
2255 {
2256 try
2257 {
2258 uno::Reference< awt::XTopWindow >( mxComponent, uno::UNO_QUERY_THROW )->removeTopWindowListener( this );
2259 }
2260 catch(const uno::Exception& ) {}
2261 try
2262 {
2263 uno::Reference< awt::XWindow >( mxComponent, uno::UNO_QUERY_THROW )->removeWindowListener( this );
2264 }
2265 catch(const uno::Exception& ) {}
2266 }
2267 mxComponent.clear();
2268
2269 if ( mxModel.is() && !mbDisposed )
2270 {
2271 try
2272 {
2273 uno::Reference< document::XDocumentEventBroadcaster >( mxModel, uno::UNO_QUERY_THROW )->removeDocumentEventListener( this );
2274 }
2275 catch(const uno::Exception& ) {}
2276 }
2277 mxModel.clear();
2278 }
2279
2280 virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) override
2281 {
2282 if ( mpUserForm )
2283 {
2284 mbOpened = true;
2285 mbShowing = true;
2286 if ( mbActivated )
2287 {
2288 mbOpened = mbActivated = false;
2289 mpUserForm->triggerActivateEvent();
2290 }
2291 }
2292 }
2293
2294
2295 virtual void SAL_CALL windowClosing( const lang::EventObject& /*e*/ ) override
2296 {
2297 #ifdef IN_THE_FUTURE
2298 uno::Reference< awt::XDialog > xDialog( e.Source, uno::UNO_QUERY );
2299 if ( xDialog.is() )
2300 {
2301 uno::Reference< awt::XControl > xControl( xDialog, uno::UNO_QUERY );
2302 if ( xControl->getPeer().is() )
2303 {
2304 uno::Reference< document::XVbaMethodParameter > xVbaMethodParameter( xControl->getPeer(), uno::UNO_QUERY );
2305 if ( xVbaMethodParameter.is() )
2306 {
2307 sal_Int8 nCancel = 0;
2308 sal_Int8 nCloseMode = ::ooo::vba::VbQueryClose::vbFormControlMenu;
2309
2310 Sequence< Any > aParams;
2311 aParams.realloc(2);
2312 aParams[0] <<= nCancel;
2313 aParams[1] <<= nCloseMode;
2314
2315 mpUserForm->triggerMethod( "Userform_QueryClose", aParams);
2316 return;
2317
2318 }
2319 }
2320 }
2321
2322 mpUserForm->triggerMethod( "Userform_QueryClose" );
2323 #endif
2324 }
2325
2326
2327 virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) override
2328 {
2329 mbOpened = false;
2330 mbShowing = false;
2331 }
2332
2333 virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) override
2334 {
2335 }
2336
2337 virtual void SAL_CALL windowNormalized( const lang::EventObject& /*e*/ ) override
2338 {
2339 }
2340
2341 virtual void SAL_CALL windowActivated( const lang::EventObject& /*e*/ ) override
2342 {
2343 if ( mpUserForm )
2344 {
2345 mbActivated = true;
2346 if ( mbOpened )
2347 {
2348 mbOpened = mbActivated = false;
2349 mpUserForm->triggerActivateEvent();
2350 }
2351 }
2352 }
2353
2354 virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) override
2355 {
2356 if ( mpUserForm )
2357 mpUserForm->triggerDeactivateEvent();
2358 }
2359
2360 virtual void SAL_CALL windowResized( const awt::WindowEvent& /*e*/ ) override
2361 {
2362 if ( mpUserForm )
2363 {
2364 mpUserForm->triggerResizeEvent();
2365 mpUserForm->triggerLayoutEvent();
2366 }
2367 }
2368
2369 virtual void SAL_CALL windowMoved( const awt::WindowEvent& /*e*/ ) override
2370 {
2371 if ( mpUserForm )
2372 mpUserForm->triggerLayoutEvent();
2373 }
2374
2375 virtual void SAL_CALL windowShown( const lang::EventObject& /*e*/ ) override
2376 {
2377 }
2378
2379 virtual void SAL_CALL windowHidden( const lang::EventObject& /*e*/ ) override
2380 {
2381 }
2382
2383 virtual void SAL_CALL documentEventOccured( const document::DocumentEvent& rEvent ) override
2384 {
2385 // early disposing on document event "OnUnload", to be sure Basic still exists when calling VBA "UserForm_Terminate"
2386 if( rEvent.EventName == GlobalEventConfig::GetEventName( GlobalEventId::CLOSEDOC ) )
2387 {
2388 SolarMutexGuard g;
2389 removeListener();
2390 mbDisposed = true;
2391 if ( mpUserForm )
2392 mpUserForm->ResetApiObj(); // will trigger "UserForm_Terminate"
2393 }
2394 }
2395
2396 virtual void SAL_CALL disposing( const lang::EventObject& /*Source*/ ) override
2397 {
2398 removeListener();
2399 mbDisposed = true;
2400 if ( mpUserForm )
2401 mpUserForm->ResetApiObj( false ); // pass false (too late to trigger VBA events here)
2402 }
2403 };
2404
2405 SbUserFormModule::SbUserFormModule( const OUString& rName, const css::script::ModuleInfo& mInfo, bool bIsCompat )
2406 : SbObjModule( rName, mInfo, bIsCompat )
2407 , m_mInfo( mInfo )
2408 , mbInit( false )
2409 {
2410 m_xModel.set( mInfo.ModuleObject, uno::UNO_QUERY_THROW );
2411 }
2412
2413 SbUserFormModule::~SbUserFormModule()
2414 {
2415 }
2416
2417 void SbUserFormModule::ResetApiObj( bool bTriggerTerminateEvent )
2418 {
2419 SAL_INFO("basic", " SbUserFormModule::ResetApiObj( " << (bTriggerTerminateEvent ? "true )" : "false )") );
2420 if ( bTriggerTerminateEvent && m_xDialog.is() ) // probably someone close the dialog window
2421 {
2422 triggerTerminateEvent();
2423 }
2424 pDocObject = nullptr;
2425 m_xDialog = nullptr;
2426 }
2427
2428 void SbUserFormModule::triggerMethod( const OUString& aMethodToRun )
2429 {
2430 Sequence< Any > aArguments;
2431 triggerMethod( aMethodToRun, aArguments );
2432 }
2433
2434 void SbUserFormModule::triggerMethod( const OUString& aMethodToRun, Sequence< Any >& aArguments )
2435 {
2436 SAL_INFO("basic", "trigger " << aMethodToRun);
2437 // Search method
2438 SbxVariable* pMeth = SbObjModule::Find( aMethodToRun, SbxClassType::Method );
2439 if( !pMeth )
2440 return;
2441
2442 if ( aArguments.hasElements() ) // Setup parameters
2443 {
2444 auto xArray = tools::make_ref<SbxArray>();
2445 xArray->Put(pMeth, 0); // Method as parameter 0
2446
2447 for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i )
2448 {
2449 auto xSbxVar = tools::make_ref<SbxVariable>( SbxVARIANT );
2450 unoToSbxValue( xSbxVar.get(), aArguments[i] );
2451 xArray->Put(xSbxVar.get(), static_cast<sal_uInt32>(i) + 1);
2452
2453 // Enable passing by ref
2454 if ( xSbxVar->GetType() != SbxVARIANT )
2455 xSbxVar->SetFlag( SbxFlagBits::Fixed );
2456 }
2457 pMeth->SetParameters( xArray.get() );
2458
2459 SbxValues aVals;
2460 pMeth->Get( aVals );
2461
2462 auto pArguments = aArguments.getArray();
2463 for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i )
2464 {
2465 pArguments[i] = sbxToUnoValue(xArray->Get(static_cast<sal_uInt32>(i) + 1));
2466 }
2467 pMeth->SetParameters( nullptr );
2468 }
2469 else
2470 {
2471 SbxValues aVals;
2472 pMeth->Get( aVals );
2473 }
2474 }
2475
2476 void SbUserFormModule::triggerActivateEvent()
2477 {
2478 triggerMethod( u"UserForm_Activate"_ustr );
2479 }
2480
2481 void SbUserFormModule::triggerDeactivateEvent()
2482 {
2483 triggerMethod( u"Userform_Deactivate"_ustr );
2484 }
2485
2486 void SbUserFormModule::triggerInitializeEvent()
2487 {
2488 if ( mbInit )
2489 return;
2490 triggerMethod(u"Userform_Initialize"_ustr);
2491 mbInit = true;
2492 }
2493
2494 void SbUserFormModule::triggerTerminateEvent()
2495 {
2496 triggerMethod(u"Userform_Terminate"_ustr);
2497 mbInit=false;
2498 }
2499
2500 void SbUserFormModule::triggerLayoutEvent()
2501 {
2502 triggerMethod(u"Userform_Layout"_ustr);
2503 }
2504
2505 void SbUserFormModule::triggerResizeEvent()
2506 {
2507 triggerMethod(u"Userform_Resize"_ustr);
2508 }
2509
2510 SbUserFormModuleInstance* SbUserFormModule::CreateInstance()
2511 {
2512 SbUserFormModuleInstance* pInstance = new SbUserFormModuleInstance( this, GetName(), m_mInfo, IsVBASupport() );
2513 return pInstance;
2514 }
2515
2516 SbUserFormModuleInstance::SbUserFormModuleInstance( SbUserFormModule* pParentModule,
2517 const OUString& rName, const css::script::ModuleInfo& mInfo, bool bIsVBACompat )
2518 : SbUserFormModule( rName, mInfo, bIsVBACompat )
2519 , m_pParentModule( pParentModule )
2520 {
2521 }
2522
2523 bool SbUserFormModuleInstance::IsClass( const OUString& rName ) const
2524 {
2525 bool bParentNameMatches = m_pParentModule->GetName().equalsIgnoreAsciiCase( rName );
2526 bool bRet = bParentNameMatches || SbxObject::IsClass( rName );
2527 return bRet;
2528 }
2529
2530 SbxVariable* SbUserFormModuleInstance::Find( const OUString& rName, SbxClassType t )
2531 {
2532 SbxVariable* pVar = m_pParentModule->Find( rName, t );
2533 return pVar;
2534 }
2535
2536
2537 void SbUserFormModule::Load()
2538 {
2539 // forces a load
2540 if ( !pDocObject.is() )
2541 InitObject();
2542 }
2543
2544
2545 void SbUserFormModule::Unload()
2546 {
2547 sal_Int8 nCancel = 0;
2548
2549 Sequence< Any > aParams = { Any(nCancel), Any(sal_Int8(::ooo::vba::VbQueryClose::vbFormCode)) };
2550
2551 triggerMethod( u"Userform_QueryClose"_ustr, aParams);
2552
2553 aParams[0] >>= nCancel;
2554 // basic boolean ( and what the user might use ) can be ambiguous ( e.g. basic true = -1 )
2555 // test against 0 ( false ) and assume anything else is true
2556 // ( Note: ) this used to work ( something changes somewhere )
2557 if (nCancel != 0)
2558 {
2559 return;
2560 }
2561
2562 if ( m_xDialog.is() )
2563 {
2564 triggerTerminateEvent();
2565 }
2566 // Search method
2567 SbxVariable* pMeth = SbObjModule::Find( u"UnloadObject"_ustr, SbxClassType::Method );
2568 if( !pMeth )
2569 return;
2570
2571 SAL_INFO("basic", "Attempting to run the UnloadObjectMethod");
2572 m_xDialog.clear(); //release ref to the uno object
2573 SbxValues aVals;
2574 bool bWaitForDispose = true; // assume dialog is showing
2575 if (m_DialogListener)
2576 {
2577 bWaitForDispose = m_DialogListener->isShowing();
2578 SAL_INFO("basic", "Showing " << bWaitForDispose );
2579 }
2580 pMeth->Get( aVals);
2581 if ( !bWaitForDispose )
2582 {
2583 // we've either already got a dispose or we are never going to get one
2584 ResetApiObj();
2585 } // else wait for dispose
2586 SAL_INFO("basic", "UnloadObject completed (we hope)");
2587 }
2588
2589
2590 void SbUserFormModule::InitObject()
2591 {
2592 try
2593 {
2594 SbUnoObject* pGlobs = static_cast<SbUnoObject*>(GetParent()->Find( u"VBAGlobals"_ustr, SbxClassType::DontCare ));
2595 if ( m_xModel.is() && pGlobs )
2596 {
2597 // broadcast INITIALIZE_USERFORM script event before the dialog is created
2598 Reference< script::vba::XVBACompatibility > xVBACompat( getVBACompatibility( m_xModel ), uno::UNO_SET_THROW );
2599 xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::INITIALIZE_USERFORM, GetName() );
2600 uno::Reference< lang::XMultiServiceFactory > xVBAFactory( pGlobs->getUnoAny(), uno::UNO_QUERY_THROW );
2601 const uno::Reference< uno::XComponentContext >& xContext = comphelper::getProcessComponentContext();
2602 OUString sDialogUrl( u"vnd.sun.star.script:"_ustr );
2603 OUString sProjectName( u"Standard"_ustr );
2604
2605 try
2606 {
2607 Reference< beans::XPropertySet > xProps( m_xModel, UNO_QUERY_THROW );
2608 uno::Reference< script::vba::XVBACompatibility > xVBAMode( xProps->getPropertyValue( u"BasicLibraries"_ustr ), uno::UNO_QUERY_THROW );
2609 sProjectName = xVBAMode->getProjectName();
2610 }
2611 catch(const Exception& ) {}
2612
2613 sDialogUrl += sProjectName + "." + GetName() + "?location=document";
2614
2615 uno::Reference< awt::XDialogProvider > xProvider = awt::DialogProvider::createWithModel( xContext, m_xModel );
2616 m_xDialog = xProvider->createDialog( sDialogUrl );
2617
2618 // create vba api object
2619 uno::Sequence< uno::Any > aArgs
2620 {
2621 uno::Any(),
2622 Any(m_xDialog),
2623 Any(m_xModel),
2624 Any(GetParent()->GetName())
2625 };
2626 pDocObject = new SbUnoObject( GetName(), uno::Any( xVBAFactory->createInstanceWithArguments( u"ooo.vba.msforms.UserForm"_ustr, aArgs ) ) );
2627
2628 uno::Reference< lang::XComponent > xComponent( m_xDialog, uno::UNO_QUERY_THROW );
2629
2630 // the dialog must be disposed at the end!
2631 StarBASIC* pParentBasic = nullptr;
2632 SbxObject* pCurObject = this;
2633 do
2634 {
2635 SbxObject* pObjParent = pCurObject->GetParent();
2636 pParentBasic = dynamic_cast<StarBASIC*>( pObjParent );
2637 pCurObject = pObjParent;
2638 }
2639 while( pParentBasic == nullptr && pCurObject != nullptr );
2640
2641 SAL_WARN_IF( pParentBasic == nullptr, "basic", "pParentBasic == NULL" );
2642 registerComponentToBeDisposedForBasic( xComponent, pParentBasic );
2643
2644 // if old listener object exists, remove it from dialog and document model
2645 if( m_DialogListener.is() )
2646 m_DialogListener->removeListener();
2647 m_DialogListener.set( new FormObjEventListenerImpl( this, xComponent, m_xModel ) );
2648
2649 triggerInitializeEvent();
2650 }
2651 }
2652 catch(const uno::Exception& )
2653 {
2654 }
2655
2656 }
2657
2658 SbxVariable*
2659 SbUserFormModule::Find( const OUString& rName, SbxClassType t )
2660 {
2661 if ( !pDocObject.is() && !GetSbData()->bRunInit && GetSbData()->pInst )
2662 InitObject();
2663 return SbObjModule::Find( rName, t );
2664 }
2665
2666 SbProperty::SbProperty( const OUString& r, SbxDataType t, SbModule* p )
2667 : SbxProperty( r, t ), pMod( p )
2668 {
2669 }
2670
2671 SbProperty::~SbProperty()
2672 {}
2673
2674
2675 SbProcedureProperty::~SbProcedureProperty()
2676 {}
2677
2678 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */