2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-07-17 12:30:48 +01:00
/*
* This file is part of the LibreOffice project .
2000-09-18 15:18:56 +00:00
*
2012-07-17 12:30:48 +01:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
2005-09-29 11:43:39 +00:00
*
2012-07-17 12:30:48 +01:00
* This file incorporates work covered by the following license notice :
2005-09-29 11:43:39 +00:00
*
2012-07-17 12:30:48 +01:00
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 15:18:56 +00:00
2006-09-17 09:00:50 +00:00
2000-09-18 15:18:56 +00:00
# include <vcl/svapp.hxx>
# include <tools/stream.hxx>
2019-03-01 14:42:38 +02:00
# include <tools/diagnose_ex.h>
2014-07-16 21:22:34 +02:00
# include <svl/SfxBroadcaster.hxx>
2019-11-08 17:23:15 +01:00
# include <basic/codecompletecache.hxx>
2007-06-27 13:19:36 +00:00
# include <basic/sbx.hxx>
2013-09-09 20:00:48 +02:00
# include <basic/sbuno.hxx>
2000-09-18 15:18:56 +00:00
# include <sbjsmeth.hxx>
2017-10-09 17:04:39 +03:00
# include <sbjsmod.hxx>
# include <sbintern.hxx>
2019-11-08 17:23:15 +01:00
# include <sbprop.hxx>
2017-10-09 17:04:39 +03:00
# include <image.hxx>
# include <opcodes.hxx>
# include <runtime.hxx>
# include <token.hxx>
# include <sbunoobj.hxx>
2008-11-28 11:39:37 +00:00
2013-11-11 21:25:36 -06:00
# include <sal/log.hxx>
2008-11-28 11:39:37 +00:00
2019-11-08 17:23:15 +01:00
# include <basic/sberrors.hxx>
2017-10-09 17:04:39 +03:00
# include <sbobjmod.hxx>
2011-02-21 12:34:10 +01:00
# include <basic/vbahelper.hxx>
2019-03-02 08:28:03 +02:00
# include <comphelper/sequence.hxx>
2015-07-02 17:14:33 +09:00
# include <cppuhelper/implbase.hxx>
2011-02-11 15:06:12 +01:00
# include <unotools/eventcfg.hxx>
2010-03-02 12:39:31 +00:00
# include <com/sun/star/lang/XServiceInfo.hpp>
2010-04-16 17:28:52 +02:00
# include <com/sun/star/script/ModuleType.hpp>
2010-07-27 14:43:33 +02:00
# include <com/sun/star/script/vba/XVBACompatibility.hpp>
2011-03-25 10:40:25 +01:00
# include <com/sun/star/script/vba/VBAScriptEventId.hpp>
2010-04-26 13:09:41 +01:00
# include <com/sun/star/beans/XPropertySet.hpp>
2015-04-22 14:42:23 +02:00
# include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
# include <com/sun/star/document/XDocumentEventListener.hpp>
2000-09-18 15:18:56 +00:00
2004-03-17 12:32:25 +00:00
# ifdef UNX
# include <sys/resource.h>
# endif
2000-09-18 15:18:56 +00:00
2009-09-18 15:24:22 +00:00
# include <com/sun/star/lang/XMultiServiceFactory.hpp>
# include <comphelper/processfactory.hxx>
2018-03-05 21:52:05 +02:00
# include <comphelper/asyncquithandler.hxx>
2010-07-01 16:23:26 +02:00
# include <map>
2012-11-27 11:00:51 +02:00
# include <com/sun/star/reflection/ProxyFactory.hpp>
2010-07-01 16:23:26 +02:00
# include <com/sun/star/uno/XAggregation.hpp>
# include <com/sun/star/script/XInvocation.hpp>
2013-01-18 09:18:17 +02:00
# include <com/sun/star/awt/DialogProvider.hpp>
2010-03-02 12:39:31 +00:00
# include <com/sun/star/awt/XTopWindow.hpp>
2010-07-06 18:07:29 +02:00
# include <com/sun/star/awt/XWindow.hpp>
2011-03-25 10:40:25 +01:00
# include <ooo/vba/VbQueryClose.hpp>
2015-09-17 17:10:47 +01:00
# include <memory>
2017-10-09 17:04:39 +03:00
# include <sbxmod.hxx>
# include <parser.hxx>
2014-06-25 14:57:44 +02:00
2015-09-18 17:06:29 +02:00
# include <limits>
2014-06-25 14:57:44 +02:00
using namespace com : : sun : : star ;
using namespace com : : sun : : star : : lang ;
using namespace com : : sun : : star : : reflection ;
using namespace com : : sun : : star : : beans ;
using namespace com : : sun : : star : : script ;
using namespace com : : sun : : star : : uno ;
2010-07-01 16:23:26 +02:00
2015-07-02 17:14:33 +09:00
typedef : : cppu : : WeakImplHelper < XInvocation > DocObjectWrapper_BASE ;
2017-02-15 22:31:33 +02:00
typedef std : : map < sal_Int16 , Any > OutParamMap ;
2010-07-01 16:23:26 +02:00
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
namespace {
2010-07-01 16:23:26 +02:00
class DocObjectWrapper : public DocObjectWrapper_BASE
{
Reference < XAggregation > m_xAggProxy ;
Reference < XInvocation > m_xAggInv ;
Reference < XTypeProvider > m_xAggregateTypeProv ;
Sequence < Type > m_Types ;
SbModule * m_pMod ;
2017-01-19 18:00:50 +01:00
/// @throws css::uno::RuntimeException
2017-01-26 12:28:58 +01:00
SbMethodRef getMethod ( const OUString & aName ) ;
2017-01-19 18:00:50 +01:00
/// @throws css::uno::RuntimeException
2017-01-26 12:28:58 +01:00
SbPropertyRef getProperty ( const OUString & aName ) ;
2010-07-01 16:23:26 +02:00
public :
2015-06-01 21:04:06 +01:00
explicit DocObjectWrapper ( SbModule * pMod ) ;
2010-07-01 16:23:26 +02:00
2017-01-26 12:28:58 +01:00
virtual Sequence < sal_Int8 > SAL_CALL getImplementationId ( ) override
2010-07-01 16:23:26 +02:00
{
2014-03-10 11:13:32 +01:00
return css : : uno : : Sequence < sal_Int8 > ( ) ;
2010-07-01 16:23:26 +02:00
}
2017-01-26 12:28:58 +01:00
virtual Reference < XIntrospectionAccess > SAL_CALL getIntrospection ( ) override ;
2010-07-01 16:23:26 +02:00
2017-01-26 12:28:58 +01:00
virtual Any SAL_CALL invoke ( const OUString & aFunctionName , const Sequence < Any > & aParams , Sequence < : : sal_Int16 > & aOutParamIndex , Sequence < Any > & aOutParam ) override ;
virtual void SAL_CALL setValue ( const OUString & aPropertyName , const Any & aValue ) override ;
virtual Any SAL_CALL getValue ( const OUString & aPropertyName ) override ;
virtual sal_Bool SAL_CALL hasMethod ( const OUString & aName ) override ;
virtual sal_Bool SAL_CALL hasProperty ( const OUString & aName ) override ;
virtual Any SAL_CALL queryInterface ( const Type & aType ) override ;
2010-07-01 16:23:26 +02:00
2017-01-26 12:28:58 +01:00
virtual Sequence < Type > SAL_CALL getTypes ( ) override ;
2010-07-01 16:23:26 +02:00
} ;
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
}
2016-11-28 09:00:15 +01:00
DocObjectWrapper : : DocObjectWrapper ( SbModule * pVar ) : m_pMod ( pVar )
2010-07-01 16:23:26 +02:00
{
2015-09-28 11:42:43 +02:00
SbObjModule * pMod = dynamic_cast < SbObjModule * > ( pVar ) ;
2010-07-01 16:23:26 +02:00
if ( pMod )
{
if ( pMod - > GetModuleType ( ) = = ModuleType : : DOCUMENT )
{
// Use proxy factory service to create aggregatable proxy.
2015-09-28 11:42:43 +02:00
SbUnoObject * pUnoObj = dynamic_cast < SbUnoObject * > ( pMod - > GetObject ( ) ) ;
2010-07-01 16:23:26 +02:00
Reference < XInterface > xIf ;
if ( pUnoObj )
{
Any aObj = pUnoObj - > getUnoAny ( ) ;
aObj > > = xIf ;
if ( xIf . is ( ) )
{
m_xAggregateTypeProv . set ( xIf , UNO_QUERY ) ;
m_xAggInv . set ( xIf , UNO_QUERY ) ;
}
}
if ( xIf . is ( ) )
{
try
{
2012-11-27 11:00:51 +02:00
Reference < XProxyFactory > xProxyFac = ProxyFactory : : create ( comphelper : : getProcessComponentContext ( ) ) ;
2010-07-01 16:23:26 +02:00
m_xAggProxy = xProxyFac - > createProxy ( xIf ) ;
}
2011-08-24 11:22:56 +09:00
catch ( const Exception & )
2010-07-01 16:23:26 +02:00
{
2019-08-15 15:56:55 +02:00
TOOLS_WARN_EXCEPTION ( " basic " , " DocObjectWrapper::DocObjectWrapper " ) ;
2010-07-01 16:23:26 +02:00
}
}
if ( m_xAggProxy . is ( ) )
{
2012-09-22 01:51:12 -05:00
osl_atomic_increment ( & m_refCount ) ;
2010-07-01 16:23:26 +02:00
/* i35609 - Fix crash on Solaris. The setDelegator call needs
to be in its own block to ensure that all temporary Reference
instances that are acquired during the call are released
before m_refCount is decremented again */
{
m_xAggProxy - > setDelegator ( static_cast < cppu : : OWeakObject * > ( this ) ) ;
}
2019-02-08 09:27:38 +02:00
osl_atomic_decrement ( & m_refCount ) ;
2010-07-01 16:23:26 +02:00
}
}
}
}
Sequence < Type > SAL_CALL DocObjectWrapper : : getTypes ( )
{
2019-05-04 23:42:17 +03:00
if ( ! m_Types . hasElements ( ) )
2010-07-01 16:23:26 +02:00
{
Sequence < Type > sTypes ;
if ( m_xAggregateTypeProv . is ( ) )
2012-11-03 09:07:25 -05:00
{
2010-07-01 16:23:26 +02:00
sTypes = m_xAggregateTypeProv - > getTypes ( ) ;
2012-11-03 09:07:25 -05:00
}
2019-03-02 08:28:03 +02:00
m_Types = comphelper : : concatSequences ( sTypes ,
Sequence { cppu : : UnoType < XInvocation > : : get ( ) } ) ;
2010-07-01 16:23:26 +02:00
}
return m_Types ;
}
Reference < XIntrospectionAccess > SAL_CALL
2017-01-26 12:28:58 +01:00
DocObjectWrapper : : getIntrospection ( )
2010-07-01 16:23:26 +02:00
{
2015-11-10 10:10:36 +01:00
return nullptr ;
2010-07-01 16:23:26 +02:00
}
Any SAL_CALL
2017-01-26 12:28:58 +01:00
DocObjectWrapper : : invoke ( const OUString & aFunctionName , const Sequence < Any > & aParams , Sequence < : : sal_Int16 > & aOutParamIndex , Sequence < Any > & aOutParam )
2010-07-01 16:23:26 +02:00
{
if ( m_xAggInv . is ( ) & & m_xAggInv - > hasMethod ( aFunctionName ) )
return m_xAggInv - > invoke ( aFunctionName , aParams , aOutParamIndex , aOutParam ) ;
SbMethodRef pMethod = getMethod ( aFunctionName ) ;
2017-01-25 12:03:58 +02:00
if ( ! pMethod . is ( ) )
2010-07-01 16:23:26 +02:00
throw RuntimeException ( ) ;
// check number of parameters
sal_Int32 nParamsCount = aParams . getLength ( ) ;
SbxInfo * pInfo = pMethod - > GetInfo ( ) ;
if ( pInfo )
{
sal_Int32 nSbxOptional = 0 ;
2011-01-10 14:40:57 +01:00
sal_uInt16 n = 1 ;
2010-07-01 16:23:26 +02:00
for ( const SbxParamInfo * pParamInfo = pInfo - > GetParam ( n ) ; pParamInfo ; pParamInfo = pInfo - > GetParam ( + + n ) )
{
2015-07-27 11:31:24 +02:00
if ( pParamInfo - > nFlags & SbxFlagBits : : Optional )
2010-07-01 16:23:26 +02:00
+ + nSbxOptional ;
else
nSbxOptional = 0 ;
}
sal_Int32 nSbxCount = n - 1 ;
if ( nParamsCount < nSbxCount - nSbxOptional )
{
2014-05-22 07:53:36 +02:00
throw RuntimeException ( " wrong number of parameters! " ) ;
2010-07-01 16:23:26 +02:00
}
}
// set parameters
SbxArrayRef xSbxParams ;
if ( nParamsCount > 0 )
{
xSbxParams = new SbxArray ;
const Any * pParams = aParams . getConstArray ( ) ;
for ( sal_Int32 i = 0 ; i < nParamsCount ; + + i )
{
SbxVariableRef xSbxVar = new SbxVariable ( SbxVARIANT ) ;
2016-10-05 22:00:51 +02:00
unoToSbxValue ( xSbxVar . get ( ) , pParams [ i ] ) ;
2019-12-09 13:06:03 +03:00
xSbxParams - > Put32 ( xSbxVar . get ( ) , static_cast < sal_uInt32 > ( i ) + 1 ) ;
2010-07-01 16:23:26 +02:00
// Enable passing by ref
if ( xSbxVar - > GetType ( ) ! = SbxVARIANT )
2015-07-27 11:31:24 +02:00
xSbxVar - > SetFlag ( SbxFlagBits : : Fixed ) ;
2010-07-01 16:23:26 +02:00
}
}
2017-01-25 12:03:58 +02:00
if ( xSbxParams . is ( ) )
2016-10-05 22:00:51 +02:00
pMethod - > SetParameters ( xSbxParams . get ( ) ) ;
2010-07-01 16:23:26 +02:00
// call method
SbxVariableRef xReturn = new SbxVariable ;
2016-10-05 22:00:51 +02:00
pMethod - > Call ( xReturn . get ( ) ) ;
2010-07-01 16:23:26 +02:00
Any aReturn ;
// get output parameters
2017-01-25 12:03:58 +02:00
if ( xSbxParams . is ( ) )
2010-07-01 16:23:26 +02:00
{
SbxInfo * pInfo_ = pMethod - > GetInfo ( ) ;
if ( pInfo_ )
{
OutParamMap aOutParamMap ;
2019-12-09 13:06:03 +03:00
for ( sal_uInt32 n = 1 , nCount = xSbxParams - > Count32 ( ) ; n < nCount ; + + n )
2010-07-01 16:23:26 +02:00
{
2019-12-09 13:06:03 +03:00
assert ( n < = std : : numeric_limits < sal_uInt16 > : : max ( ) ) ;
const SbxParamInfo * pParamInfo = pInfo_ - > GetParam ( sal : : static_int_cast < sal_uInt16 > ( n ) ) ;
2010-07-01 16:23:26 +02:00
if ( pParamInfo & & ( pParamInfo - > eType & SbxBYREF ) ! = 0 )
{
2019-12-09 13:06:03 +03:00
SbxVariable * pVar = xSbxParams - > Get32 ( n ) ;
2010-07-01 16:23:26 +02:00
if ( pVar )
{
SbxVariableRef xVar = pVar ;
2017-08-10 16:43:55 +02:00
aOutParamMap . emplace ( n - 1 , sbxToUnoValue ( xVar . get ( ) ) ) ;
2010-07-01 16:23:26 +02:00
}
}
}
sal_Int32 nOutParamCount = aOutParamMap . size ( ) ;
aOutParamIndex . realloc ( nOutParamCount ) ;
aOutParam . realloc ( nOutParamCount ) ;
sal_Int16 * pOutParamIndex = aOutParamIndex . getArray ( ) ;
Any * pOutParam = aOutParam . getArray ( ) ;
2018-02-24 16:27:42 +01:00
for ( auto const & outParam : aOutParamMap )
2010-07-01 16:23:26 +02:00
{
2018-02-24 16:27:42 +01:00
* pOutParamIndex = outParam . first ;
* pOutParam = outParam . second ;
+ + pOutParamIndex ;
+ + pOutParam ;
2010-07-01 16:23:26 +02:00
}
}
}
// get return value
2016-10-05 22:00:51 +02:00
aReturn = sbxToUnoValue ( xReturn . get ( ) ) ;
2010-07-01 16:23:26 +02:00
2015-11-10 10:10:36 +01:00
pMethod - > SetParameters ( nullptr ) ;
2010-07-01 16:23:26 +02:00
return aReturn ;
}
void SAL_CALL
2017-01-26 12:28:58 +01:00
DocObjectWrapper : : setValue ( const OUString & aPropertyName , const Any & aValue )
2010-07-01 16:23:26 +02:00
{
if ( m_xAggInv . is ( ) & & m_xAggInv - > hasProperty ( aPropertyName ) )
return m_xAggInv - > setValue ( aPropertyName , aValue ) ;
SbPropertyRef pProperty = getProperty ( aPropertyName ) ;
2017-01-25 12:03:58 +02:00
if ( ! pProperty . is ( ) )
2019-09-26 14:52:33 +02:00
throw UnknownPropertyException ( aPropertyName ) ;
2016-10-05 22:00:51 +02:00
unoToSbxValue ( pProperty . get ( ) , aValue ) ;
2010-07-01 16:23:26 +02:00
}
Any SAL_CALL
2017-01-26 12:28:58 +01:00
DocObjectWrapper : : getValue ( const OUString & aPropertyName )
2010-07-01 16:23:26 +02:00
{
if ( m_xAggInv . is ( ) & & m_xAggInv - > hasProperty ( aPropertyName ) )
return m_xAggInv - > getValue ( aPropertyName ) ;
SbPropertyRef pProperty = getProperty ( aPropertyName ) ;
2017-01-25 12:03:58 +02:00
if ( ! pProperty . is ( ) )
2019-09-26 14:52:33 +02:00
throw UnknownPropertyException ( aPropertyName ) ;
2010-07-01 16:23:26 +02:00
2016-10-05 22:00:51 +02:00
SbxVariable * pProp = pProperty . get ( ) ;
2010-07-01 16:23:26 +02:00
if ( pProp - > GetType ( ) = = SbxEMPTY )
2016-12-08 10:26:01 +02:00
pProperty - > Broadcast ( SfxHintId : : BasicDataWanted ) ;
2010-07-01 16:23:26 +02:00
Any aRet = sbxToUnoValue ( pProp ) ;
return aRet ;
}
2014-04-03 13:52:06 +02:00
sal_Bool SAL_CALL
2017-01-26 12:28:58 +01:00
DocObjectWrapper : : hasMethod ( const OUString & aName )
2010-07-01 16:23:26 +02:00
{
if ( m_xAggInv . is ( ) & & m_xAggInv - > hasMethod ( aName ) )
2016-04-20 17:14:08 +02:00
return true ;
2017-01-25 12:03:58 +02:00
return getMethod ( aName ) . is ( ) ;
2010-07-01 16:23:26 +02:00
}
2014-04-03 13:52:06 +02:00
sal_Bool SAL_CALL
2017-01-26 12:28:58 +01:00
DocObjectWrapper : : hasProperty ( const OUString & aName )
2010-07-01 16:23:26 +02:00
{
2014-04-04 16:52:44 +02:00
bool bRes = false ;
2010-07-01 16:23:26 +02:00
if ( m_xAggInv . is ( ) & & m_xAggInv - > hasProperty ( aName ) )
2014-04-04 16:52:44 +02:00
bRes = true ;
2017-01-25 12:03:58 +02:00
else bRes = getProperty ( aName ) . is ( ) ;
2010-07-01 16:23:26 +02:00
return bRes ;
}
Any SAL_CALL DocObjectWrapper : : queryInterface ( const Type & aType )
{
Any aRet = DocObjectWrapper_BASE : : queryInterface ( aType ) ;
if ( aRet . hasValue ( ) )
return aRet ;
else if ( m_xAggProxy . is ( ) )
aRet = m_xAggProxy - > queryAggregation ( aType ) ;
return aRet ;
}
2017-01-26 12:28:58 +01:00
SbMethodRef DocObjectWrapper : : getMethod ( const OUString & aName )
2010-07-01 16:23:26 +02:00
{
2018-09-04 13:44:45 +02:00
SbMethodRef pMethod ;
2010-07-01 16:23:26 +02:00
if ( m_pMod )
{
2014-08-21 14:41:58 +02:00
SbxFlagBits nSaveFlgs = m_pMod - > GetFlags ( ) ;
2010-07-01 16:23:26 +02:00
// Limit search to this module
2015-07-27 11:31:24 +02:00
m_pMod - > ResetFlag ( SbxFlagBits : : GlobalSearch ) ;
2016-05-21 16:22:07 +02:00
pMethod = dynamic_cast < SbMethod * > ( m_pMod - > SbModule : : Find ( aName , SbxClassType : : Method ) ) ;
2010-07-01 16:23:26 +02:00
m_pMod - > SetFlags ( nSaveFlgs ) ;
}
return pMethod ;
}
2017-01-26 12:28:58 +01:00
SbPropertyRef DocObjectWrapper : : getProperty ( const OUString & aName )
2010-07-01 16:23:26 +02:00
{
2018-09-04 13:44:45 +02:00
SbPropertyRef pProperty ;
2010-07-01 16:23:26 +02:00
if ( m_pMod )
{
2014-08-21 14:41:58 +02:00
SbxFlagBits nSaveFlgs = m_pMod - > GetFlags ( ) ;
2010-07-01 16:23:26 +02:00
// Limit search to this module.
2015-07-27 11:31:24 +02:00
m_pMod - > ResetFlag ( SbxFlagBits : : GlobalSearch ) ;
2016-05-21 16:22:07 +02:00
pProperty = dynamic_cast < SbProperty * > ( m_pMod - > SbModule : : Find ( aName , SbxClassType : : Property ) ) ;
2010-07-01 16:23:26 +02:00
m_pMod - > SetFlag ( nSaveFlgs ) ;
}
return pProperty ;
}
2000-09-18 15:18:56 +00:00
2011-03-25 10:40:25 +01:00
uno : : Reference < frame : : XModel > getDocumentModel ( StarBASIC * pb )
2010-04-26 13:09:41 +01:00
{
2011-03-25 10:40:25 +01:00
uno : : Reference < frame : : XModel > xModel ;
if ( pb & & pb - > IsDocBasic ( ) )
2010-04-26 13:09:41 +01:00
{
uno : : Any aDoc ;
2011-03-25 10:40:25 +01:00
if ( pb - > GetUNOConstant ( " ThisComponent " , aDoc ) )
xModel . set ( aDoc , uno : : UNO_QUERY ) ;
2010-04-26 13:09:41 +01:00
}
2011-03-25 10:40:25 +01:00
return xModel ;
}
2018-09-15 19:13:19 +02:00
static uno : : Reference < vba : : XVBACompatibility > getVBACompatibility ( const uno : : Reference < frame : : XModel > & rxModel )
2011-03-25 10:40:25 +01:00
{
uno : : Reference < vba : : XVBACompatibility > xVBACompat ;
try
{
uno : : Reference < beans : : XPropertySet > xModelProps ( rxModel , uno : : UNO_QUERY_THROW ) ;
2013-01-09 00:14:10 +02:00
xVBACompat . set ( xModelProps - > getPropertyValue ( " BasicLibraries " ) , uno : : UNO_QUERY ) ;
2011-03-25 10:40:25 +01:00
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & )
2011-03-25 10:40:25 +01:00
{
2010-04-26 13:09:41 +01:00
}
2011-03-25 10:40:25 +01:00
return xVBACompat ;
}
2018-09-15 19:13:19 +02:00
static bool getDefaultVBAMode ( StarBASIC * pb )
2011-03-25 10:40:25 +01:00
{
2018-02-08 19:31:20 +02:00
uno : : Reference < frame : : XModel > xModel ( getDocumentModel ( pb ) ) ;
if ( ! xModel . is ( ) )
return false ;
uno : : Reference < vba : : XVBACompatibility > xVBACompat = getVBACompatibility ( xModel ) ;
2011-03-25 10:40:25 +01:00
return xVBACompat . is ( ) & & xVBACompat - > getVBACompatibilityMode ( ) ;
2010-04-26 13:09:41 +01:00
}
2017-02-13 22:18:09 +01:00
// A Basic module has set EXTSEARCH, so that the elements, that the module contains,
2010-10-06 22:33:21 +02:00
// could be found from other module.
2000-09-18 15:18:56 +00:00
2014-03-26 11:18:51 +02:00
SbModule : : SbModule ( const OUString & rName , bool bVBACompat )
2013-01-09 00:14:10 +02:00
: SbxObject ( " StarBASICModule " ) ,
2019-12-03 15:02:05 +02:00
pImage ( nullptr ) , pBreaks ( nullptr ) , mbVBACompat ( bVBACompat ) , bIsProxyModule ( false )
2000-09-18 15:18:56 +00:00
{
SetName ( rName ) ;
2015-07-27 11:31:24 +02:00
SetFlag ( SbxFlagBits : : ExtSearch | SbxFlagBits : : GlobalSearch ) ;
2010-04-16 17:28:52 +02:00
SetModuleType ( script : : ModuleType : : NORMAL ) ;
2010-06-15 20:02:53 +02:00
2018-11-30 19:58:46 +01:00
// #i92642: Set name property to initial name
2016-05-21 16:22:07 +02:00
SbxVariable * pNameProp = pProps - > Find ( " Name " , SbxClassType : : Property ) ;
2015-11-10 10:10:36 +01:00
if ( pNameProp ! = nullptr )
2012-11-03 09:07:25 -05:00
{
2010-06-15 20:02:53 +02:00
pNameProp - > PutString ( GetName ( ) ) ;
2012-11-03 09:07:25 -05:00
}
2000-09-18 15:18:56 +00:00
}
SbModule : : ~ SbModule ( )
{
2017-04-12 11:39:06 +02:00
SAL_INFO ( " basic " , " Module named " < < GetName ( ) < < " is destructing " ) ;
2019-12-03 15:02:05 +02:00
delete pImage ;
delete pBreaks ;
2018-01-16 14:41:21 +02:00
pClassData . reset ( ) ;
2015-11-10 10:10:36 +01:00
mxWrapper = nullptr ;
2010-07-01 16:23:26 +02:00
}
2016-07-18 09:22:27 +02:00
uno : : Reference < script : : XInvocation > const &
2010-07-01 16:23:26 +02:00
SbModule : : GetUnoModule ( )
{
if ( ! mxWrapper . is ( ) )
mxWrapper = new DocObjectWrapper ( this ) ;
2017-04-12 11:39:06 +02:00
SAL_INFO ( " basic " , " Module named " < < GetName ( ) < < " returning wrapper mxWrapper (0x " < < mxWrapper . get ( ) < < " ) " ) ;
2010-07-01 16:23:26 +02:00
return mxWrapper ;
2000-09-18 15:18:56 +00:00
}
2014-03-26 11:18:51 +02:00
bool SbModule : : IsCompiled ( ) const
2000-09-18 15:18:56 +00:00
{
2015-11-10 10:10:36 +01:00
return pImage ! = nullptr ;
2000-09-18 15:18:56 +00:00
}
2014-03-12 15:36:41 +02:00
const SbxObject * SbModule : : FindType ( const OUString & aTypeName ) const
2004-03-17 12:32:25 +00:00
{
2015-11-10 10:10:36 +01:00
return pImage ? pImage - > FindType ( aTypeName ) : nullptr ;
2004-03-17 12:32:25 +00:00
}
2014-11-10 15:05:25 +01:00
// From the code generator: deletion of images and the opposite of validation for entries
2000-09-18 15:18:56 +00:00
void SbModule : : StartDefinitions ( )
{
2019-12-03 15:02:05 +02:00
delete pImage ; pImage = nullptr ;
2005-03-29 10:48:33 +00:00
if ( pClassData )
pClassData - > clear ( ) ;
2010-10-06 22:33:21 +02:00
// methods and properties persist, but they are invalid;
// at least are the information under certain conditions clogged
2019-12-09 13:06:03 +03:00
sal_uInt32 i ;
for ( i = 0 ; i < pMethods - > Count32 ( ) ; i + + )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbMethod * p = dynamic_cast < SbMethod * > ( pMethods - > Get32 ( i ) ) ;
2000-09-18 15:18:56 +00:00
if ( p )
2014-03-26 11:18:51 +02:00
p - > bInvalid = true ;
2000-09-18 15:18:56 +00:00
}
2019-12-09 13:06:03 +03:00
for ( i = 0 ; i < pProps - > Count32 ( ) ; )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbProperty * p = dynamic_cast < SbProperty * > ( pProps - > Get32 ( i ) ) ;
2000-09-18 15:18:56 +00:00
if ( p )
pProps - > Remove ( i ) ;
else
i + + ;
}
}
2010-10-06 22:33:21 +02:00
// request/create method
2000-09-18 15:18:56 +00:00
2012-11-06 23:34:23 -06:00
SbMethod * SbModule : : GetMethod ( const OUString & rName , SbxDataType t )
2000-09-18 15:18:56 +00:00
{
2016-05-21 16:22:07 +02:00
SbxVariable * p = pMethods - > Find ( rName , SbxClassType : : Method ) ;
2018-08-09 16:30:57 +02:00
SbMethod * pMeth = dynamic_cast < SbMethod * > ( p ) ;
2000-09-18 15:18:56 +00:00
if ( p & & ! pMeth )
2012-11-03 09:07:25 -05:00
{
2000-09-18 15:18:56 +00:00
pMethods - > Remove ( p ) ;
2012-11-03 09:07:25 -05:00
}
2000-09-18 15:18:56 +00:00
if ( ! pMeth )
{
pMeth = new SbMethod ( rName , t , this ) ;
pMeth - > SetParent ( this ) ;
2015-07-27 11:31:24 +02:00
pMeth - > SetFlags ( SbxFlagBits : : Read ) ;
2019-12-09 13:06:03 +03:00
pMethods - > Put32 ( pMeth , pMethods - > Count32 ( ) ) ;
2018-02-15 14:10:30 +00:00
StartListening ( pMeth - > GetBroadcaster ( ) , DuplicateHandling : : Prevent ) ;
2000-09-18 15:18:56 +00:00
}
2010-10-06 22:33:21 +02:00
// The method is per default valid, because it could be
// created from the compiler (code generator) as well.
2014-03-26 11:18:51 +02:00
pMeth - > bInvalid = false ;
2015-07-27 11:31:24 +02:00
pMeth - > ResetFlag ( SbxFlagBits : : Fixed ) ;
pMeth - > SetFlag ( SbxFlagBits : : Write ) ;
2000-09-18 15:18:56 +00:00
pMeth - > SetType ( t ) ;
2015-07-27 11:31:24 +02:00
pMeth - > ResetFlag ( SbxFlagBits : : Write ) ;
2000-09-18 15:18:56 +00:00
if ( t ! = SbxVARIANT )
2012-11-03 09:07:25 -05:00
{
2015-07-27 11:31:24 +02:00
pMeth - > SetFlag ( SbxFlagBits : : Fixed ) ;
2012-11-03 09:07:25 -05:00
}
2000-09-18 15:18:56 +00:00
return pMeth ;
}
2016-04-24 21:00:05 +02:00
SbMethod * SbModule : : FindMethod ( const OUString & rName , SbxClassType t )
{
return dynamic_cast < SbMethod * > ( pMethods - > Find ( rName , t ) ) ;
}
2010-10-06 22:33:21 +02:00
// request/create property
2000-09-18 15:18:56 +00:00
2012-11-06 23:34:23 -06:00
SbProperty * SbModule : : GetProperty ( const OUString & rName , SbxDataType t )
2000-09-18 15:18:56 +00:00
{
2016-05-21 16:22:07 +02:00
SbxVariable * p = pProps - > Find ( rName , SbxClassType : : Property ) ;
2018-08-09 16:30:57 +02:00
SbProperty * pProp = dynamic_cast < SbProperty * > ( p ) ;
2000-09-18 15:18:56 +00:00
if ( p & & ! pProp )
2012-11-03 09:07:25 -05:00
{
2000-09-18 15:18:56 +00:00
pProps - > Remove ( p ) ;
2012-11-03 09:07:25 -05:00
}
2000-09-18 15:18:56 +00:00
if ( ! pProp )
{
pProp = new SbProperty ( rName , t , this ) ;
2015-07-27 11:31:24 +02:00
pProp - > SetFlag ( SbxFlagBits : : ReadWrite ) ;
2000-09-18 15:18:56 +00:00
pProp - > SetParent ( this ) ;
2019-12-09 13:06:03 +03:00
pProps - > Put32 ( pProp , pProps - > Count32 ( ) ) ;
2018-02-15 14:10:30 +00:00
StartListening ( pProp - > GetBroadcaster ( ) , DuplicateHandling : : Prevent ) ;
2000-09-18 15:18:56 +00:00
}
return pProp ;
}
2016-01-11 14:31:00 +02:00
void SbModule : : GetProcedureProperty ( const OUString & rName , SbxDataType t )
2004-11-02 10:52:32 +00:00
{
2016-05-21 16:22:07 +02:00
SbxVariable * p = pProps - > Find ( rName , SbxClassType : : Property ) ;
2018-08-09 16:30:57 +02:00
SbProcedureProperty * pProp = dynamic_cast < SbProcedureProperty * > ( p ) ;
2004-11-02 10:52:32 +00:00
if ( p & & ! pProp )
2012-11-03 09:07:25 -05:00
{
2004-11-02 10:52:32 +00:00
pProps - > Remove ( p ) ;
2012-11-03 09:07:25 -05:00
}
2004-11-02 10:52:32 +00:00
if ( ! pProp )
{
pProp = new SbProcedureProperty ( rName , t ) ;
2015-07-27 11:31:24 +02:00
pProp - > SetFlag ( SbxFlagBits : : ReadWrite ) ;
2004-11-02 10:52:32 +00:00
pProp - > SetParent ( this ) ;
2019-12-09 13:06:03 +03:00
pProps - > Put32 ( pProp , pProps - > Count32 ( ) ) ;
2018-02-15 14:10:30 +00:00
StartListening ( pProp - > GetBroadcaster ( ) , DuplicateHandling : : Prevent ) ;
2004-11-02 10:52:32 +00:00
}
}
2016-01-11 14:31:00 +02:00
void SbModule : : GetIfaceMapperMethod ( const OUString & rName , SbMethod * pImplMeth )
2005-03-29 10:48:33 +00:00
{
2016-05-21 16:22:07 +02:00
SbxVariable * p = pMethods - > Find ( rName , SbxClassType : : Method ) ;
2018-08-09 16:30:57 +02:00
SbIfaceMapperMethod * pMapperMethod = dynamic_cast < SbIfaceMapperMethod * > ( p ) ;
2005-03-29 10:48:33 +00:00
if ( p & & ! pMapperMethod )
2012-11-03 09:07:25 -05:00
{
2005-03-29 10:48:33 +00:00
pMethods - > Remove ( p ) ;
2012-11-03 09:07:25 -05:00
}
2005-03-29 10:48:33 +00:00
if ( ! pMapperMethod )
{
pMapperMethod = new SbIfaceMapperMethod ( rName , pImplMeth ) ;
pMapperMethod - > SetParent ( this ) ;
2015-07-27 11:31:24 +02:00
pMapperMethod - > SetFlags ( SbxFlagBits : : Read ) ;
2019-12-09 13:06:03 +03:00
pMethods - > Put32 ( pMapperMethod , pMethods - > Count32 ( ) ) ;
2005-03-29 10:48:33 +00:00
}
2014-03-26 11:18:51 +02:00
pMapperMethod - > bInvalid = false ;
2005-03-29 10:48:33 +00:00
}
SbIfaceMapperMethod : : ~ SbIfaceMapperMethod ( )
{
}
2010-10-06 22:33:21 +02:00
// From the code generator: remove invalid entries
2000-09-18 15:18:56 +00:00
2014-03-26 11:18:51 +02:00
void SbModule : : EndDefinitions ( bool bNewState )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
for ( sal_uInt32 i = 0 ; i < pMethods - > Count32 ( ) ; )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbMethod * p = dynamic_cast < SbMethod * > ( pMethods - > Get32 ( i ) ) ;
2000-09-18 15:18:56 +00:00
if ( p )
{
if ( p - > bInvalid )
2013-07-23 23:00:55 +02:00
{
2000-09-18 15:18:56 +00:00
pMethods - > Remove ( p ) ;
2013-07-23 23:00:55 +02:00
}
2000-09-18 15:18:56 +00:00
else
{
p - > bInvalid = bNewState ;
i + + ;
}
}
2005-03-29 10:48:33 +00:00
else
i + + ;
2000-09-18 15:18:56 +00:00
}
2014-03-26 11:18:51 +02:00
SetModified ( true ) ;
2000-09-18 15:18:56 +00:00
}
void SbModule : : Clear ( )
{
2019-12-03 15:02:05 +02:00
delete pImage ; pImage = nullptr ;
2005-03-29 10:48:33 +00:00
if ( pClassData )
pClassData - > clear ( ) ;
2000-09-18 15:18:56 +00:00
SbxObject : : Clear ( ) ;
}
2004-11-15 15:34:15 +00:00
2012-11-06 23:34:23 -06:00
SbxVariable * SbModule : : Find ( const OUString & rName , SbxClassType t )
2004-11-15 15:34:15 +00:00
{
2016-10-23 12:56:00 +02:00
// make sure a search in an uninstantiated class module will fail
2004-11-15 15:34:15 +00:00
SbxVariable * pRes = SbxObject : : Find ( rName , t ) ;
2010-06-15 20:02:53 +02:00
if ( bIsProxyModule & & ! GetSbData ( ) - > bRunInit )
2012-11-03 09:07:25 -05:00
{
2015-11-10 10:10:36 +01:00
return nullptr ;
2012-11-03 09:07:25 -05:00
}
2004-11-15 15:34:15 +00:00
if ( ! pRes & & pImage )
{
2012-01-15 16:15:08 +01:00
SbiInstance * pInst = GetSbData ( ) - > pInst ;
2004-11-15 15:34:15 +00:00
if ( pInst & & pInst - > IsCompatibility ( ) )
{
// Put enum types as objects into module,
// allows MyEnum.First notation
SbxArrayRef xArray = pImage - > GetEnums ( ) ;
2017-01-25 12:03:58 +02:00
if ( xArray . is ( ) )
2004-11-15 15:34:15 +00:00
{
2016-05-21 16:22:07 +02:00
SbxVariable * pEnumVar = xArray - > Find ( rName , SbxClassType : : DontCare ) ;
2015-09-28 11:42:43 +02:00
SbxObject * pEnumObject = dynamic_cast < SbxObject * > ( pEnumVar ) ;
2004-11-15 15:34:15 +00:00
if ( pEnumObject )
{
2015-07-27 11:31:24 +02:00
bool bPrivate = pEnumObject - > IsSet ( SbxFlagBits : : Private ) ;
2012-11-06 23:34:23 -06:00
OUString aEnumName = pEnumObject - > GetName ( ) ;
2004-11-15 15:34:15 +00:00
pRes = new SbxVariable ( SbxOBJECT ) ;
pRes - > SetName ( aEnumName ) ;
pRes - > SetParent ( this ) ;
2015-07-27 11:31:24 +02:00
pRes - > SetFlag ( SbxFlagBits : : Read ) ;
2004-11-15 15:34:15 +00:00
if ( bPrivate )
2012-11-03 09:07:25 -05:00
{
2015-07-27 11:31:24 +02:00
pRes - > SetFlag ( SbxFlagBits : : Private ) ;
2012-11-03 09:07:25 -05:00
}
2004-11-15 15:34:15 +00:00
pRes - > PutObject ( pEnumObject ) ;
}
}
}
}
return pRes ;
}
2010-10-06 22:33:21 +02:00
// Parent and BASIC are one!
2000-09-18 15:18:56 +00:00
void SbModule : : SetParent ( SbxObject * p )
{
pParent = p ;
}
2015-06-24 12:06:34 +02:00
void SbModule : : Notify ( SfxBroadcaster & rBC , const SfxHint & rHint )
2000-09-18 15:18:56 +00:00
{
2014-08-27 16:57:21 +02:00
const SbxHint * pHint = dynamic_cast < const SbxHint * > ( & rHint ) ;
2000-09-18 15:18:56 +00:00
if ( pHint )
{
SbxVariable * pVar = pHint - > GetVar ( ) ;
2015-09-28 11:42:43 +02:00
SbProperty * pProp = dynamic_cast < SbProperty * > ( pVar ) ;
SbMethod * pMeth = dynamic_cast < SbMethod * > ( pVar ) ;
SbProcedureProperty * pProcProperty = dynamic_cast < SbProcedureProperty * > ( pVar ) ;
2010-10-06 10:16:27 +01:00
if ( pProcProperty )
{
2016-12-08 10:26:01 +02:00
if ( pHint - > GetId ( ) = = SfxHintId : : BasicDataWanted )
2010-10-06 10:16:27 +01:00
{
2016-07-01 14:07:52 +03:00
OUString aProcName = " Property Get "
+ pProcProperty - > GetName ( ) ;
2010-10-06 10:16:27 +01:00
2016-05-21 16:22:07 +02:00
SbxVariable * pMethVar = Find ( aProcName , SbxClassType : : Method ) ;
2010-10-06 10:16:27 +01:00
if ( pMethVar )
{
SbxValues aVals ;
aVals . eType = SbxVARIANT ;
SbxArray * pArg = pVar - > GetParameters ( ) ;
2019-12-09 13:06:03 +03:00
sal_uInt32 nVarParCount = ( pArg ! = nullptr ) ? pArg - > Count32 ( ) : 0 ;
2010-10-06 10:16:27 +01:00
if ( nVarParCount > 1 )
{
2016-02-21 17:51:28 +01:00
auto xMethParameters = tools : : make_ref < SbxArray > ( ) ;
2019-12-09 13:06:03 +03:00
xMethParameters - > Put32 ( pMethVar , 0 ) ; // Method as parameter 0
for ( sal_uInt32 i = 1 ; i < nVarParCount ; + + i )
2010-10-06 10:16:27 +01:00
{
2019-12-09 13:06:03 +03:00
SbxVariable * pPar = pArg - > Get32 ( i ) ;
xMethParameters - > Put32 ( pPar , i ) ;
2010-10-06 10:16:27 +01:00
}
2016-10-05 22:00:51 +02:00
pMethVar - > SetParameters ( xMethParameters . get ( ) ) ;
2010-10-06 10:16:27 +01:00
pMethVar - > Get ( aVals ) ;
2015-11-10 10:10:36 +01:00
pMethVar - > SetParameters ( nullptr ) ;
2010-10-06 10:16:27 +01:00
}
else
{
pMethVar - > Get ( aVals ) ;
}
pVar - > Put ( aVals ) ;
}
}
2016-12-08 10:26:01 +02:00
else if ( pHint - > GetId ( ) = = SfxHintId : : BasicDataChanged )
2010-10-06 10:16:27 +01:00
{
2015-11-10 10:10:36 +01:00
SbxVariable * pMethVar = nullptr ;
2010-10-06 10:16:27 +01:00
bool bSet = pProcProperty - > isSet ( ) ;
if ( bSet )
{
pProcProperty - > setSet ( false ) ;
2016-07-01 14:07:52 +03:00
OUString aProcName = " Property Set "
+ pProcProperty - > GetName ( ) ;
2016-05-21 16:22:07 +02:00
pMethVar = Find ( aProcName , SbxClassType : : Method ) ;
2010-10-06 10:16:27 +01:00
}
if ( ! pMethVar ) // Let
{
2016-07-01 14:07:52 +03:00
OUString aProcName = " Property Let "
+ pProcProperty - > GetName ( ) ;
2016-05-21 16:22:07 +02:00
pMethVar = Find ( aProcName , SbxClassType : : Method ) ;
2010-10-06 10:16:27 +01:00
}
if ( pMethVar )
{
// Setup parameters
SbxArrayRef xArray = new SbxArray ;
2019-12-09 13:06:03 +03:00
xArray - > Put32 ( pMethVar , 0 ) ; // Method as parameter 0
xArray - > Put32 ( pVar , 1 ) ;
2016-10-05 22:00:51 +02:00
pMethVar - > SetParameters ( xArray . get ( ) ) ;
2010-10-06 10:16:27 +01:00
SbxValues aVals ;
pMethVar - > Get ( aVals ) ;
2015-11-10 10:10:36 +01:00
pMethVar - > SetParameters ( nullptr ) ;
2010-10-06 10:16:27 +01:00
}
}
}
2000-09-18 15:18:56 +00:00
if ( pProp )
{
if ( pProp - > GetModule ( ) ! = this )
2017-08-28 17:03:09 +02:00
SetError ( ERRCODE_BASIC_BAD_ACTION ) ;
2000-09-18 15:18:56 +00:00
}
else if ( pMeth )
{
2016-12-08 10:26:01 +02:00
if ( pHint - > GetId ( ) = = SfxHintId : : BasicDataWanted )
2000-09-18 15:18:56 +00:00
{
if ( pMeth - > bInvalid & & ! Compile ( ) )
2012-11-03 09:07:25 -05:00
{
2010-10-06 22:33:21 +02:00
// auto compile has not worked!
2015-07-27 13:04:00 +02:00
StarBASIC : : Error ( ERRCODE_BASIC_BAD_PROP_VALUE ) ;
2012-11-03 09:07:25 -05:00
}
2000-09-18 15:18:56 +00:00
else
{
2010-10-06 22:33:21 +02:00
// Call of a subprogram
2012-01-15 16:15:08 +01:00
SbModule * pOld = GetSbData ( ) - > pMod ;
GetSbData ( ) - > pMod = this ;
2014-10-01 16:01:34 +02:00
Run ( static_cast < SbMethod * > ( pVar ) ) ;
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pMod = pOld ;
2000-09-18 15:18:56 +00:00
}
}
}
else
2010-06-15 20:02:53 +02:00
{
// #i92642: Special handling for name property to avoid
2014-04-10 10:34:23 +02:00
// side effects when using name as variable implicitly
2010-06-15 20:02:53 +02:00
bool bForwardToSbxObject = true ;
2016-12-08 10:26:01 +02:00
const SfxHintId nId = pHint - > GetId ( ) ;
if ( ( nId = = SfxHintId : : BasicDataWanted | | nId = = SfxHintId : : BasicDataChanged ) & &
2012-11-06 23:34:23 -06:00
pVar - > GetName ( ) . equalsIgnoreAsciiCase ( " name " ) )
2012-11-03 09:07:25 -05:00
{
2010-06-15 20:02:53 +02:00
bForwardToSbxObject = false ;
2012-11-03 09:07:25 -05:00
}
2010-06-15 20:02:53 +02:00
if ( bForwardToSbxObject )
2012-11-03 09:07:25 -05:00
{
2015-06-24 12:06:34 +02:00
SbxObject : : Notify ( rBC , rHint ) ;
2012-11-03 09:07:25 -05:00
}
2010-06-15 20:02:53 +02:00
}
2000-09-18 15:18:56 +00:00
}
}
2010-10-06 22:33:21 +02:00
// The setting of the source makes the image invalid
// and scans the method definitions newly in
2000-09-18 15:18:56 +00:00
2012-11-06 23:34:23 -06:00
void SbModule : : SetSource32 ( const OUString & r )
2003-04-23 15:56:27 +00:00
{
2019-08-31 19:29:31 +02:00
// Default basic mode to library container mode, but... allow Option VBASupport 0/1 override
2011-03-25 10:40:25 +01:00
SetVBACompat ( getDefaultVBAMode ( static_cast < StarBASIC * > ( GetParent ( ) ) ) ) ;
2003-04-23 15:56:27 +00:00
aOUSource = r ;
2000-09-18 15:18:56 +00:00
StartDefinitions ( ) ;
SbiTokenizer aTok ( r ) ;
2012-11-03 09:07:25 -05:00
aTok . SetCompatible ( IsVBACompat ( ) ) ;
2013-07-29 22:27:41 +02:00
2000-09-18 15:18:56 +00:00
while ( ! aTok . IsEof ( ) )
{
SbiToken eEndTok = NIL ;
2010-10-06 22:33:21 +02:00
// Searching for SUB or FUNCTION
2000-09-18 15:18:56 +00:00
SbiToken eLastTok = NIL ;
while ( ! aTok . IsEof ( ) )
{
2010-10-06 22:33:21 +02:00
// #32385: not by declare
2000-09-18 15:18:56 +00:00
SbiToken eCurTok = aTok . Next ( ) ;
if ( eLastTok ! = DECLARE )
{
if ( eCurTok = = SUB )
{
eEndTok = ENDSUB ; break ;
}
if ( eCurTok = = FUNCTION )
{
eEndTok = ENDFUNC ; break ;
}
2005-03-29 10:48:33 +00:00
if ( eCurTok = = PROPERTY )
{
eEndTok = ENDPROPERTY ; break ;
}
2010-04-26 13:09:41 +01:00
if ( eCurTok = = OPTION )
{
eCurTok = aTok . Next ( ) ;
if ( eCurTok = = COMPATIBLE )
2012-11-03 09:07:25 -05:00
{
2010-04-26 13:09:41 +01:00
aTok . SetCompatible ( true ) ;
2012-11-03 09:07:25 -05:00
}
2010-04-26 13:09:41 +01:00
else if ( ( eCurTok = = VBASUPPORT ) & & ( aTok . Next ( ) = = NUMBER ) )
{
2014-03-26 11:18:51 +02:00
bool bIsVBA = ( aTok . GetDbl ( ) = = 1 ) ;
2012-11-03 09:07:25 -05:00
SetVBACompat ( bIsVBA ) ;
2010-04-26 13:09:41 +01:00
aTok . SetCompatible ( bIsVBA ) ;
}
}
2000-09-18 15:18:56 +00:00
}
eLastTok = eCurTok ;
}
2010-10-06 22:33:21 +02:00
// Definition of the method
2015-11-10 10:10:36 +01:00
SbMethod * pMeth = nullptr ;
2000-09-18 15:18:56 +00:00
if ( eEndTok ! = NIL )
{
2011-01-10 14:40:57 +01:00
sal_uInt16 nLine1 = aTok . GetLine ( ) ;
2000-09-18 15:18:56 +00:00
if ( aTok . Next ( ) = = SYMBOL )
{
2012-11-06 23:34:23 -06:00
OUString aName_ ( aTok . GetSym ( ) ) ;
2000-09-18 15:18:56 +00:00
SbxDataType t = aTok . GetType ( ) ;
if ( t = = SbxVARIANT & & eEndTok = = ENDSUB )
2012-11-06 23:34:23 -06:00
{
2000-09-18 15:18:56 +00:00
t = SbxVOID ;
2012-11-06 23:34:23 -06:00
}
2006-06-19 16:40:39 +00:00
pMeth = GetMethod ( aName_ , t ) ;
2000-09-18 15:18:56 +00:00
pMeth - > nLine1 = pMeth - > nLine2 = nLine1 ;
2010-10-06 22:33:21 +02:00
// The method is for a start VALID
2014-03-26 11:18:51 +02:00
pMeth - > bInvalid = false ;
2000-09-18 15:18:56 +00:00
}
else
2012-11-06 23:34:23 -06:00
{
2000-09-18 15:18:56 +00:00
eEndTok = NIL ;
2012-11-06 23:34:23 -06:00
}
2000-09-18 15:18:56 +00:00
}
2010-10-06 22:33:21 +02:00
// Skip up to END SUB/END FUNCTION
2000-09-18 15:18:56 +00:00
if ( eEndTok ! = NIL )
{
while ( ! aTok . IsEof ( ) )
{
if ( aTok . Next ( ) = = eEndTok )
{
pMeth - > nLine2 = aTok . GetLine ( ) ;
break ;
}
}
if ( aTok . IsEof ( ) )
2012-11-06 23:34:23 -06:00
{
2000-09-18 15:18:56 +00:00
pMeth - > nLine2 = aTok . GetLine ( ) ;
2012-11-06 23:34:23 -06:00
}
2000-09-18 15:18:56 +00:00
}
}
2014-03-26 11:18:51 +02:00
EndDefinitions ( true ) ;
2000-09-18 15:18:56 +00:00
}
2010-10-06 22:33:21 +02:00
// Broadcast of a hint to all Basics
2000-09-18 15:18:56 +00:00
2016-12-08 10:26:01 +02:00
static void SendHint_ ( SbxObject * pObj , SfxHintId nId , SbMethod * p )
2000-09-18 15:18:56 +00:00
{
2010-10-06 22:33:21 +02:00
// Self a BASIC?
2015-09-30 16:10:07 +02:00
if ( dynamic_cast < const StarBASIC * > ( pObj ) ! = nullptr & & pObj - > IsBroadcaster ( ) )
2000-09-18 15:18:56 +00:00
pObj - > GetBroadcaster ( ) . Broadcast ( SbxHint ( nId , p ) ) ;
2010-10-06 22:33:21 +02:00
// Then ask for the subobjects
2000-09-18 15:18:56 +00:00
SbxArray * pObjs = pObj - > GetObjects ( ) ;
2019-12-09 13:06:03 +03:00
for ( sal_uInt32 i = 0 ; i < pObjs - > Count32 ( ) ; i + + )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbxVariable * pVar = pObjs - > Get32 ( i ) ;
2015-09-30 16:10:07 +02:00
if ( dynamic_cast < const SbxObject * > ( pVar ) ! = nullptr )
2016-04-05 23:11:48 +02:00
SendHint_ ( dynamic_cast < SbxObject * > ( pVar ) , nId , p ) ;
2000-09-18 15:18:56 +00:00
}
}
2016-12-08 10:26:01 +02:00
static void SendHint ( SbxObject * pObj , SfxHintId nId , SbMethod * p )
2000-09-18 15:18:56 +00:00
{
while ( pObj - > GetParent ( ) )
pObj = pObj - > GetParent ( ) ;
2016-04-05 23:11:48 +02:00
SendHint_ ( pObj , nId , p ) ;
2000-09-18 15:18:56 +00:00
}
2010-10-06 22:33:21 +02:00
// #57841 Clear Uno-Objects, which were helt in RTL functions,
// at the end of the program, so that nothing were helt.
2018-09-15 19:13:19 +02:00
static void ClearUnoObjectsInRTL_Impl_Rek ( StarBASIC * pBasic )
2000-09-18 15:18:56 +00:00
{
2010-10-06 22:33:21 +02:00
// delete the return value of CreateUnoService
2016-05-21 16:22:07 +02:00
SbxVariable * pVar = pBasic - > GetRtl ( ) - > Find ( " CreateUnoService " , SbxClassType : : Method ) ;
2000-09-18 15:18:56 +00:00
if ( pVar )
2012-11-06 23:34:23 -06:00
{
2000-09-18 15:18:56 +00:00
pVar - > SbxValue : : Clear ( ) ;
2012-11-06 23:34:23 -06:00
}
2010-10-06 22:33:21 +02:00
// delete the return value of CreateUnoDialog
2016-05-21 16:22:07 +02:00
pVar = pBasic - > GetRtl ( ) - > Find ( " CreateUnoDialog " , SbxClassType : : Method ) ;
2002-01-08 09:57:34 +00:00
if ( pVar )
2012-11-06 23:34:23 -06:00
{
2002-01-08 09:57:34 +00:00
pVar - > SbxValue : : Clear ( ) ;
2012-11-06 23:34:23 -06:00
}
2010-10-06 22:33:21 +02:00
// delete the return value of CDec
2016-05-21 16:22:07 +02:00
pVar = pBasic - > GetRtl ( ) - > Find ( " CDec " , SbxClassType : : Method ) ;
2004-03-17 12:32:25 +00:00
if ( pVar )
2012-11-06 23:34:23 -06:00
{
2004-03-17 12:32:25 +00:00
pVar - > SbxValue : : Clear ( ) ;
2012-11-06 23:34:23 -06:00
}
2010-10-06 22:33:21 +02:00
// delete return value of CreateObject
2016-05-21 16:22:07 +02:00
pVar = pBasic - > GetRtl ( ) - > Find ( " CreateObject " , SbxClassType : : Method ) ;
2006-08-04 09:54:10 +00:00
if ( pVar )
2012-11-06 23:34:23 -06:00
{
2006-08-04 09:54:10 +00:00
pVar - > SbxValue : : Clear ( ) ;
2012-11-06 23:34:23 -06:00
}
2010-10-06 22:33:21 +02:00
// Go over all Sub-Basics
2000-09-18 15:18:56 +00:00
SbxArray * pObjs = pBasic - > GetObjects ( ) ;
2019-12-09 13:06:03 +03:00
sal_uInt32 nCount = pObjs - > Count32 ( ) ;
for ( sal_uInt32 i = 0 ; i < nCount ; i + + )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbxVariable * pObjVar = pObjs - > Get32 ( i ) ;
2015-09-28 11:42:43 +02:00
StarBASIC * pSubBasic = dynamic_cast < StarBASIC * > ( pObjVar ) ;
2000-09-18 15:18:56 +00:00
if ( pSubBasic )
2012-11-06 23:34:23 -06:00
{
2000-09-18 15:18:56 +00:00
ClearUnoObjectsInRTL_Impl_Rek ( pSubBasic ) ;
2012-11-06 23:34:23 -06:00
}
2000-09-18 15:18:56 +00:00
}
}
2018-09-15 19:13:19 +02:00
static void ClearUnoObjectsInRTL_Impl ( StarBASIC * pBasic )
2000-09-18 15:18:56 +00:00
{
2010-10-06 22:33:21 +02:00
// #67781 Delete return values of the Uno-methods
2000-09-18 15:18:56 +00:00
clearUnoMethods ( ) ;
2003-03-18 15:28:40 +00:00
ClearUnoObjectsInRTL_Impl_Rek ( pBasic ) ;
2010-10-06 22:33:21 +02:00
// Search for the topmost Basic
2000-09-18 15:18:56 +00:00
SbxObject * p = pBasic ;
while ( p - > GetParent ( ) )
p = p - > GetParent ( ) ;
2014-10-01 16:01:34 +02:00
if ( static_cast < StarBASIC * > ( p ) ! = pBasic )
ClearUnoObjectsInRTL_Impl_Rek ( static_cast < StarBASIC * > ( p ) ) ;
2000-09-18 15:18:56 +00:00
}
2012-04-20 20:01:54 +01:00
2000-09-18 15:18:56 +00:00
2012-04-20 20:01:54 +01:00
void SbModule : : SetVBACompat ( bool bCompat )
2010-03-02 12:39:31 +00:00
{
2011-03-21 10:30:30 +01:00
if ( mbVBACompat ! = bCompat )
{
mbVBACompat = bCompat ;
// initialize VBA document API
if ( mbVBACompat ) try
{
StarBASIC * pBasic = static_cast < StarBASIC * > ( GetParent ( ) ) ;
uno : : Reference < lang : : XMultiServiceFactory > xFactory ( getDocumentModel ( pBasic ) , uno : : UNO_QUERY_THROW ) ;
2013-01-09 00:14:10 +02:00
xFactory - > createInstance ( " ooo.vba.VBAGlobals " ) ;
2011-03-21 10:30:30 +01:00
}
catch ( Exception & )
{
}
}
2010-03-02 12:39:31 +00:00
}
2012-04-20 20:01:54 +01:00
2019-11-14 15:05:56 +00:00
namespace
{
class RunInitGuard
{
protected :
std : : unique_ptr < SbiRuntime > m_xRt ;
SbiGlobals * m_pSbData ;
SbModule * m_pOldMod ;
public :
RunInitGuard ( SbModule * pModule , SbMethod * pMethod , sal_uInt32 nArg , SbiGlobals * pSbData )
: m_xRt ( new SbiRuntime ( pModule , pMethod , nArg ) )
, m_pSbData ( pSbData )
, m_pOldMod ( pSbData - > pMod )
{
m_xRt - > pNext = pSbData - > pInst - > pRun ;
m_pSbData - > pMod = pModule ;
m_pSbData - > pInst - > pRun = m_xRt . get ( ) ;
}
void run ( )
{
while ( m_xRt - > Step ( ) ) { }
}
virtual ~ RunInitGuard ( )
{
m_pSbData - > pInst - > pRun = m_xRt - > pNext ;
m_pSbData - > pMod = m_pOldMod ;
m_xRt . reset ( ) ;
}
} ;
class RunGuard : public RunInitGuard
{
private :
bool m_bDelInst ;
public :
RunGuard ( SbModule * pModule , SbMethod * pMethod , sal_uInt32 nArg , SbiGlobals * pSbData , bool bDelInst )
: RunInitGuard ( pModule , pMethod , nArg , pSbData )
, m_bDelInst ( bDelInst )
{
if ( m_xRt - > pNext )
m_xRt - > pNext - > block ( ) ;
}
virtual ~ RunGuard ( ) override
{
if ( m_xRt - > pNext )
m_xRt - > pNext - > unblock ( ) ;
// #63710 It can happen by an another thread handling at events,
// that the show call returns to a dialog (by closing the
// dialog per UI), before a by an event triggered further call returned,
// which stands in Basic more top in the stack and that had been run on
// a Basic-Breakpoint. Then would the instance below destroyed. And if the Basic,
// that stand still in the call, further runs, there is a GPF.
// Thus here had to be wait until the other call comes back.
if ( m_bDelInst )
{
// Compare here with 1 instead of 0, because before nCallLvl--
while ( m_pSbData - > pInst - > nCallLvl ! = 1 )
Application : : Yield ( ) ;
}
m_pSbData - > pInst - > nCallLvl - - ; // Call-Level down again
// Exist an higher-ranking runtime instance?
// Then take over BasicDebugFlags::Break, if set
SbiRuntime * pRtNext = m_xRt - > pNext ;
if ( pRtNext & & ( m_xRt - > GetDebugFlags ( ) & BasicDebugFlags : : Break ) )
pRtNext - > SetDebugFlags ( BasicDebugFlags : : Break ) ;
}
} ;
}
2010-10-06 22:33:21 +02:00
// Run a Basic-subprogram
2015-04-27 15:46:52 +02:00
void SbModule : : Run ( SbMethod * pMeth )
2000-09-18 15:18:56 +00:00
{
2017-04-12 11:39:06 +02:00
SAL_INFO ( " basic " , " About to run " < < pMeth - > GetName ( ) < < " , vba compatmode is " < < mbVBACompat ) ;
2015-09-18 17:06:29 +02:00
2011-01-10 14:40:57 +01:00
static sal_uInt16 nMaxCallLevel = 0 ;
2004-03-17 12:32:25 +00:00
2019-10-28 19:35:42 +00:00
SbiGlobals * pSbData = GetSbData ( ) ;
bool bDelInst = pSbData - > pInst = = nullptr ;
2012-11-03 09:07:25 -05:00
bool bQuit = false ;
2000-09-18 15:18:56 +00:00
StarBASICRef xBasic ;
2011-03-25 10:40:25 +01:00
uno : : Reference < frame : : XModel > xModel ;
uno : : Reference < script : : vba : : XVBACompatibility > xVBACompat ;
2000-09-18 15:18:56 +00:00
if ( bDelInst )
{
2010-10-06 22:33:21 +02:00
// #32779: Hold Basic during the execution
2014-10-01 16:01:34 +02:00
xBasic = static_cast < StarBASIC * > ( GetParent ( ) ) ;
2000-09-18 15:18:56 +00:00
2019-10-28 19:35:42 +00:00
pSbData - > pInst = new SbiInstance ( static_cast < StarBASIC * > ( GetParent ( ) ) ) ;
2000-09-18 15:18:56 +00:00
2011-03-25 10:40:25 +01:00
/* If a VBA script in a document is started, get the VBA compatibility
interface from the document Basic library container , and notify all
VBA script listeners about the started script . */
if ( mbVBACompat )
{
StarBASIC * pBasic = static_cast < StarBASIC * > ( GetParent ( ) ) ;
if ( pBasic & & pBasic - > IsDocBasic ( ) ) try
{
xModel . set ( getDocumentModel ( pBasic ) , uno : : UNO_SET_THROW ) ;
xVBACompat . set ( getVBACompatibility ( xModel ) , uno : : UNO_SET_THROW ) ;
xVBACompat - > broadcastVBAScriptEvent ( script : : vba : : VBAScriptEventId : : SCRIPT_STARTED , GetName ( ) ) ;
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & )
2011-03-25 10:40:25 +01:00
{
}
}
2007-08-03 08:55:16 +00:00
// Launcher problem
2015-09-29 17:42:11 +02:00
// i80726 The Find below will generate an error in Testtool so we reset it unless there was one before already
2017-06-14 13:34:55 +02:00
bool bWasError = SbxBase : : GetError ( ) ! = ERRCODE_NONE ;
2016-05-21 16:22:07 +02:00
SbxVariable * pMSOMacroRuntimeLibVar = Find ( " Launcher " , SbxClassType : : Object ) ;
2017-08-28 17:03:09 +02:00
if ( ! bWasError & & ( SbxBase : : GetError ( ) = = ERRCODE_BASIC_PROC_UNDEFINED ) )
2007-08-17 07:15:47 +00:00
SbxBase : : ResetError ( ) ;
2007-08-03 08:55:16 +00:00
if ( pMSOMacroRuntimeLibVar )
{
2015-09-28 11:42:43 +02:00
StarBASIC * pMSOMacroRuntimeLib = dynamic_cast < StarBASIC * > ( pMSOMacroRuntimeLibVar ) ;
2007-08-03 08:55:16 +00:00
if ( pMSOMacroRuntimeLib )
{
2015-07-27 11:31:24 +02:00
SbxFlagBits nGblFlag = pMSOMacroRuntimeLib - > GetFlags ( ) & SbxFlagBits : : GlobalSearch ;
pMSOMacroRuntimeLib - > ResetFlag ( SbxFlagBits : : GlobalSearch ) ;
2016-05-21 16:22:07 +02:00
SbxVariable * pAppSymbol = pMSOMacroRuntimeLib - > Find ( " Application " , SbxClassType : : Method ) ;
2007-08-03 08:55:16 +00:00
pMSOMacroRuntimeLib - > SetFlag ( nGblFlag ) ;
if ( pAppSymbol )
{
2015-07-27 11:31:24 +02:00
pMSOMacroRuntimeLib - > SetFlag ( SbxFlagBits : : ExtSearch ) ; // Could have been disabled before
2019-10-28 19:35:42 +00:00
pSbData - > pMSOMacroRuntimLib = pMSOMacroRuntimeLib ;
2007-08-03 08:55:16 +00:00
}
}
}
2004-03-17 12:32:25 +00:00
if ( nMaxCallLevel = = 0 )
{
# ifdef UNX
struct rlimit rl ;
getrlimit ( RLIMIT_STACK , & rl ) ;
# endif
2006-10-12 13:26:01 +00:00
# if defined LINUX
2004-03-17 12:32:25 +00:00
// Empiric value, 900 = needed bytes/Basic call level
// for Linux including 10% safety margin
nMaxCallLevel = rl . rlim_cur / 900 ;
2017-02-08 12:54:04 +01:00
# elif defined __sun
2004-03-17 12:32:25 +00:00
// Empiric value, 1650 = needed bytes/Basic call level
// for Solaris including 10% safety margin
nMaxCallLevel = rl . rlim_cur / 1650 ;
2019-03-01 14:01:43 +01:00
# elif defined _WIN32
2004-03-17 12:32:25 +00:00
nMaxCallLevel = 5800 ;
# else
nMaxCallLevel = MAXRECURSION ;
# endif
}
2000-09-18 15:18:56 +00:00
}
2004-03-17 12:32:25 +00:00
2010-10-06 22:33:21 +02:00
// Recursion to deep?
2019-10-28 19:35:42 +00:00
if ( + + pSbData - > pInst - > nCallLvl < = nMaxCallLevel )
2000-09-18 15:18:56 +00:00
{
2010-10-06 22:33:21 +02:00
// Define a globale variable in all Mods
2000-09-18 15:18:56 +00:00
GlobalRunInit ( /* bBasicStart = */ bDelInst ) ;
2010-10-06 22:33:21 +02:00
// Appeared a compiler error? Then we don't launch
2019-10-28 19:35:42 +00:00
if ( ! pSbData - > bGlobalInitErr )
2000-09-18 15:18:56 +00:00
{
if ( bDelInst )
{
2016-12-08 10:26:01 +02:00
SendHint ( GetParent ( ) , SfxHintId : : BasicStart , pMeth ) ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// 1996-10-16: #31460 New concept for StepInto/Over/Out
// For an explanation see runtime.cxx at SbiInstance::CalcBreakCallLevel()
// Identify the BreakCallLevel
2019-10-28 19:35:42 +00:00
pSbData - > pInst - > CalcBreakCallLevel ( pMeth - > GetDebugFlags ( ) ) ;
2000-09-18 15:18:56 +00:00
}
2019-11-14 15:05:56 +00:00
auto xRuntimeGuard ( std : : make_unique < RunGuard > ( this , pMeth , pMeth - > nStart , pSbData , bDelInst ) ) ;
2010-07-26 14:20:03 +02:00
2010-03-02 12:39:31 +00:00
if ( mbVBACompat )
2010-07-26 14:20:03 +02:00
{
2019-10-28 19:35:42 +00:00
pSbData - > pInst - > EnableCompatibility ( true ) ;
2010-07-26 14:20:03 +02:00
}
2015-09-18 17:06:29 +02:00
2019-11-14 15:05:56 +00:00
xRuntimeGuard - > run ( ) ;
2000-09-18 15:18:56 +00:00
2019-11-14 15:05:56 +00:00
xRuntimeGuard . reset ( ) ;
2000-09-18 15:18:56 +00:00
if ( bDelInst )
{
2010-10-06 22:33:21 +02:00
// #57841 Clear Uno-Objects, which were helt in RTL functions,
// at the end of the program, so that nothing were helt.
2016-10-05 22:00:51 +02:00
ClearUnoObjectsInRTL_Impl ( xBasic . get ( ) ) ;
2000-09-18 15:18:56 +00:00
2010-09-08 16:34:55 +02:00
clearNativeObjectWrapperVector ( ) ;
2019-10-28 19:35:42 +00:00
SAL_WARN_IF ( pSbData - > pInst - > nCallLvl ! = 0 , " basic " , " BASIC-Call-Level > 0 " ) ;
delete pSbData - > pInst ;
pSbData - > pInst = nullptr ;
2016-02-22 16:53:50 +02:00
bDelInst = false ;
2004-11-15 12:29:17 +00:00
// #i30690
2010-10-13 02:47:36 -05:00
SolarMutexGuard aSolarGuard ;
2016-12-08 10:26:01 +02:00
SendHint ( GetParent ( ) , SfxHintId : : BasicStop , pMeth ) ;
2001-09-04 09:20:53 +00:00
GlobalRunDeInit ( ) ;
2010-08-23 11:16:00 +02:00
2011-03-25 10:40:25 +01:00
if ( xVBACompat . is ( ) )
{
// notify all VBA script listeners about the stopped script
try
{
xVBACompat - > broadcastVBAScriptEvent ( script : : vba : : VBAScriptEventId : : SCRIPT_STOPPED , GetName ( ) ) ;
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & )
2011-03-25 10:40:25 +01:00
{
}
// VBA always ensures screenupdating is enabled after completing
2014-03-26 12:03:10 +02:00
: : basic : : vba : : lockControllersOfAllDocuments ( xModel , false ) ;
: : basic : : vba : : enableContainerWindowsOfAllDocuments ( xModel , true ) ;
2011-03-25 10:40:25 +01:00
}
2000-09-18 15:18:56 +00:00
}
}
2002-07-10 09:54:53 +00:00
else
2019-10-28 19:35:42 +00:00
pSbData - > pInst - > nCallLvl - - ; // Call-Level down again
2000-09-18 15:18:56 +00:00
}
else
2003-04-23 15:56:27 +00:00
{
2019-10-28 19:35:42 +00:00
pSbData - > pInst - > nCallLvl - - ; // Call-Level down again
2015-07-27 13:04:00 +02:00
StarBASIC : : FatalError ( ERRCODE_BASIC_STACK_OVERFLOW ) ;
2003-04-23 15:56:27 +00:00
}
2009-09-29 14:47:18 +00:00
2015-09-28 11:42:43 +02:00
StarBASIC * pBasic = dynamic_cast < StarBASIC * > ( GetParent ( ) ) ;
2000-09-18 15:18:56 +00:00
if ( bDelInst )
{
2010-10-06 22:33:21 +02:00
// #57841 Clear Uno-Objects, which were helt in RTL functions,
// the end of the program, so that nothing were helt.
2016-10-05 22:00:51 +02:00
ClearUnoObjectsInRTL_Impl ( xBasic . get ( ) ) ;
2000-09-18 15:18:56 +00:00
2019-10-28 19:35:42 +00:00
delete pSbData - > pInst ;
pSbData - > pInst = nullptr ;
2000-09-18 15:18:56 +00:00
}
2019-10-28 19:35:42 +00:00
if ( pBasic & & pBasic - > IsDocBasic ( ) & & pBasic - > IsQuitApplication ( ) & & ! pSbData - > pInst )
2010-10-06 10:16:27 +01:00
bQuit = true ;
2019-02-08 09:27:38 +02:00
if ( bQuit )
2009-09-29 14:47:18 +00:00
{
2015-10-20 11:44:49 +02:00
Application : : PostUserEvent ( LINK ( & AsyncQuitHandler : : instance ( ) , AsyncQuitHandler , OnAsyncQuit ) ) ;
2009-09-29 14:47:18 +00:00
}
2000-09-18 15:18:56 +00:00
}
2010-10-06 22:33:21 +02:00
// Execute of the init method of a module after the loading
// or the compilation
2000-09-18 15:18:56 +00:00
void SbModule : : RunInit ( )
{
if ( pImage
& & ! pImage - > bInit
2015-02-27 11:22:50 +02:00
& & pImage - > IsFlag ( SbiImageFlags : : INITCODE ) )
2000-09-18 15:18:56 +00:00
{
2019-11-11 11:10:29 +00:00
SbiGlobals * pSbData = GetSbData ( ) ;
2018-07-17 23:17:56 +02:00
// Set flag, so that RunInit get active (Testtool)
2019-11-11 11:10:29 +00:00
pSbData - > bRunInit = true ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// The init code starts always here
2019-11-14 15:05:56 +00:00
auto xRuntimeGuard ( std : : make_unique < RunInitGuard > ( this , nullptr , 0 , pSbData ) ) ;
2019-11-11 14:16:08 +00:00
xRuntimeGuard - > run ( ) ;
xRuntimeGuard . reset ( ) ;
2010-07-26 14:20:03 +02:00
2012-08-15 09:44:54 +09:00
pImage - > bInit = true ;
pImage - > bFirstInit = false ;
2000-09-18 15:18:56 +00:00
2018-07-17 23:17:56 +02:00
// RunInit is not active anymore
2019-11-11 11:10:29 +00:00
pSbData - > bRunInit = false ;
2000-09-18 15:18:56 +00:00
}
}
2010-10-06 22:33:21 +02:00
// Delete with private/dim declared variables
2010-07-05 13:58:36 +02:00
2012-11-06 23:34:23 -06:00
void SbModule : : AddVarName ( const OUString & aName )
2010-07-05 13:58:36 +02:00
{
2013-03-03 17:11:39 +01:00
// see if the name is added already
2015-12-06 14:29:18 +01:00
for ( const auto & rModuleVariableName : mModuleVariableNames )
2010-07-05 13:58:36 +02:00
{
2015-12-06 14:29:18 +01:00
if ( aName = = rModuleVariableName )
2010-07-05 13:58:36 +02:00
return ;
}
mModuleVariableNames . push_back ( aName ) ;
}
void SbModule : : RemoveVars ( )
{
2015-12-06 14:29:18 +01:00
for ( const auto & rModuleVariableName : mModuleVariableNames )
2010-07-05 13:58:36 +02:00
{
// We don't want a Find being called in a derived class ( e.g.
// SbUserform because it could trigger say an initialise event
// 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 )
2016-05-21 16:22:07 +02:00
SbxVariableRef p = SbModule : : Find ( rModuleVariableName , SbxClassType : : Property ) ;
2017-01-25 12:03:58 +02:00
if ( p . is ( ) )
2016-10-05 22:00:51 +02:00
Remove ( p . get ( ) ) ;
2010-07-05 13:58:36 +02:00
}
}
2000-09-18 15:18:56 +00:00
void SbModule : : ClearPrivateVars ( )
{
2019-12-09 13:06:03 +03:00
for ( sal_uInt32 i = 0 ; i < pProps - > Count32 ( ) ; i + + )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbProperty * p = dynamic_cast < SbProperty * > ( pProps - > Get32 ( i ) ) ;
2000-09-18 15:18:56 +00:00
if ( p )
{
2010-10-06 22:33:21 +02:00
// Delete not the arrays, only their content
2000-09-18 15:18:56 +00:00
if ( p - > GetType ( ) & SbxARRAY )
{
2015-09-28 11:42:43 +02:00
SbxArray * pArray = dynamic_cast < SbxArray * > ( p - > GetObject ( ) ) ;
2000-09-18 15:18:56 +00:00
if ( pArray )
{
2019-12-09 13:06:03 +03:00
for ( sal_uInt32 j = 0 ; j < pArray - > Count32 ( ) ; j + + )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbxVariable * pj = pArray - > Get32 ( j ) ;
2000-09-18 15:18:56 +00:00
pj - > SbxValue : : Clear ( ) ;
}
}
}
else
{
p - > SbxValue : : Clear ( ) ;
}
}
}
}
2010-09-21 08:58:34 +02:00
void SbModule : : implClearIfVarDependsOnDeletedBasic ( SbxVariable * pVar , StarBASIC * pDeletedBasic )
{
2017-05-19 11:25:32 +02:00
if ( pVar - > SbxValue : : GetType ( ) ! = SbxOBJECT | | dynamic_cast < const SbProcedureProperty * > ( pVar ) ! = nullptr )
2010-09-21 08:58:34 +02:00
return ;
2015-09-28 11:42:43 +02:00
SbxObject * pObj = dynamic_cast < SbxObject * > ( pVar - > GetObject ( ) ) ;
2015-11-10 10:10:36 +01:00
if ( pObj ! = nullptr )
2010-09-21 08:58:34 +02:00
{
SbxObject * p = pObj ;
2015-09-28 11:42:43 +02:00
SbModule * pMod = dynamic_cast < SbModule * > ( p ) ;
2015-11-10 10:10:36 +01:00
if ( pMod ! = nullptr )
2010-09-21 08:58:34 +02:00
pMod - > ClearVarsDependingOnDeletedBasic ( pDeletedBasic ) ;
2015-11-10 10:10:36 +01:00
while ( ( p = p - > GetParent ( ) ) ! = nullptr )
2010-09-21 08:58:34 +02:00
{
2015-09-28 11:42:43 +02:00
StarBASIC * pBasic = dynamic_cast < StarBASIC * > ( p ) ;
2015-11-10 10:10:36 +01:00
if ( pBasic ! = nullptr & & pBasic = = pDeletedBasic )
2010-09-21 08:58:34 +02:00
{
pVar - > SbxValue : : Clear ( ) ;
break ;
}
}
}
}
void SbModule : : ClearVarsDependingOnDeletedBasic ( StarBASIC * pDeletedBasic )
{
2019-12-09 13:06:03 +03:00
for ( sal_uInt32 i = 0 ; i < pProps - > Count32 ( ) ; i + + )
2010-09-21 08:58:34 +02:00
{
2019-12-09 13:06:03 +03:00
SbProperty * p = dynamic_cast < SbProperty * > ( pProps - > Get32 ( i ) ) ;
2010-09-21 08:58:34 +02:00
if ( p )
{
if ( p - > GetType ( ) & SbxARRAY )
{
2015-09-28 11:42:43 +02:00
SbxArray * pArray = dynamic_cast < SbxArray * > ( p - > GetObject ( ) ) ;
2010-09-21 08:58:34 +02:00
if ( pArray )
{
2019-12-09 13:06:03 +03:00
for ( sal_uInt32 j = 0 ; j < pArray - > Count32 ( ) ; j + + )
2010-09-21 08:58:34 +02:00
{
2019-12-09 13:06:03 +03:00
SbxVariable * pVar = pArray - > Get32 ( j ) ;
2010-09-21 08:58:34 +02:00
implClearIfVarDependsOnDeletedBasic ( pVar , pDeletedBasic ) ;
}
}
}
else
{
implClearIfVarDependsOnDeletedBasic ( p , pDeletedBasic ) ;
}
}
}
}
2015-04-14 12:44:47 +02:00
void StarBASIC : : ClearAllModuleVars ( )
2000-09-18 15:18:56 +00:00
{
2010-10-06 22:33:21 +02:00
// Initialise the own module
2015-12-19 15:18:01 +01:00
for ( const auto & rModule : pModules )
2000-09-18 15:18:56 +00:00
{
2010-10-06 22:33:21 +02:00
// Initialise only, if the startcode was already executed
2017-05-19 11:25:32 +02:00
if ( rModule - > pImage & & rModule - > pImage - > bInit & & ! rModule - > isProxyModule ( ) & & dynamic_cast < const SbObjModule * > ( rModule . get ( ) ) = = nullptr )
2015-12-19 15:18:01 +01:00
rModule - > ClearPrivateVars ( ) ;
2000-09-18 15:18:56 +00:00
}
2001-07-03 09:46:50 +00:00
2000-09-18 15:18:56 +00:00
}
2010-10-06 22:33:21 +02:00
// Execution of the init-code of all module
2012-09-07 04:59:11 +09:00
void SbModule : : GlobalRunInit ( bool bBasicStart )
2000-09-18 15:18:56 +00:00
{
2010-10-06 22:33:21 +02:00
// If no Basic-Start, only initialise, if the module is not initialised
2000-09-18 15:18:56 +00:00
if ( ! bBasicStart )
if ( ! ( pImage & & ! pImage - > bInit ) )
return ;
2010-10-06 22:33:21 +02:00
// Initialise GlobalInitErr-Flag for Compiler-Error
// With the help of this flags could be located in SbModule::Run() after the call of
2016-01-04 12:37:59 +01:00
// GlobalRunInit, if at the initialising of the module
2010-12-04 13:16:21 +09:00
// an error occurred. Then it will not be launched.
2012-08-21 22:54:26 +09:00
GetSbData ( ) - > bGlobalInitErr = false ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// Parent of the module is a Basic
2015-09-28 11:42:43 +02:00
StarBASIC * pBasic = dynamic_cast < StarBASIC * > ( GetParent ( ) ) ;
2000-09-18 15:18:56 +00:00
if ( pBasic )
{
pBasic - > InitAllModules ( ) ;
2006-06-19 16:40:39 +00:00
SbxObject * pParent_ = pBasic - > GetParent ( ) ;
if ( pParent_ )
2003-05-22 07:52:42 +00:00
{
2015-09-28 11:42:43 +02:00
StarBASIC * pParentBasic = dynamic_cast < StarBASIC * > ( pParent_ ) ;
2003-05-22 07:52:42 +00:00
if ( pParentBasic )
{
pParentBasic - > InitAllModules ( pBasic ) ;
// #109018 Parent can also have a parent (library in doc)
SbxObject * pParentParent = pParentBasic - > GetParent ( ) ;
if ( pParentParent )
{
2015-09-28 11:42:43 +02:00
StarBASIC * pParentParentBasic = dynamic_cast < StarBASIC * > ( pParentParent ) ;
2003-05-22 07:52:42 +00:00
if ( pParentParentBasic )
pParentParentBasic - > InitAllModules ( pParentBasic ) ;
}
}
}
2000-09-18 15:18:56 +00:00
}
}
2015-04-14 12:44:47 +02:00
void SbModule : : GlobalRunDeInit ( )
2001-09-04 09:20:53 +00:00
{
2015-09-28 11:42:43 +02:00
StarBASIC * pBasic = dynamic_cast < StarBASIC * > ( GetParent ( ) ) ;
2001-09-04 09:20:53 +00:00
if ( pBasic )
{
pBasic - > DeInitAllModules ( ) ;
2006-06-19 16:40:39 +00:00
SbxObject * pParent_ = pBasic - > GetParent ( ) ;
if ( pParent_ )
2015-09-28 11:42:43 +02:00
pBasic = dynamic_cast < StarBASIC * > ( pParent_ ) ;
2001-09-04 09:20:53 +00:00
if ( pBasic )
pBasic - > DeInitAllModules ( ) ;
}
}
2010-10-06 22:33:21 +02:00
// Search for the next STMNT-Command in the code. This was used from the STMNT-
// Opcode to set the endcolumn.
2000-09-18 15:18:56 +00:00
2011-01-10 14:40:57 +01:00
const sal_uInt8 * SbModule : : FindNextStmnt ( const sal_uInt8 * p , sal_uInt16 & nLine , sal_uInt16 & nCol ) const
2002-08-09 09:27:16 +00:00
{
2014-03-26 11:18:51 +02:00
return FindNextStmnt ( p , nLine , nCol , false ) ;
2002-08-09 09:27:16 +00:00
}
2011-01-10 14:40:57 +01:00
const sal_uInt8 * SbModule : : FindNextStmnt ( const sal_uInt8 * p , sal_uInt16 & nLine , sal_uInt16 & nCol ,
2014-03-26 11:18:51 +02:00
bool bFollowJumps , const SbiImage * pImg ) const
2000-09-18 15:18:56 +00:00
{
2018-01-12 20:29:14 +01:00
sal_uInt32 nPC = static_cast < sal_uInt32 > ( p - reinterpret_cast < const sal_uInt8 * > ( pImage - > GetCode ( ) ) ) ;
2000-09-18 15:18:56 +00:00
while ( nPC < pImage - > GetCodeSize ( ) )
{
2018-01-15 09:07:14 +01:00
SbiOpcode eOp = static_cast < SbiOpcode > ( * p + + ) ;
2000-09-18 15:18:56 +00:00
nPC + + ;
2016-04-05 21:22:43 +02:00
if ( bFollowJumps & & eOp = = SbiOpcode : : JUMP_ & & pImg )
2002-08-09 09:27:16 +00:00
{
2013-01-09 00:14:10 +02:00
SAL_WARN_IF ( ! pImg , " basic " , " FindNextStmnt: pImg==NULL with FollowJumps option " ) ;
2011-01-10 14:40:57 +01:00
sal_uInt32 nOp1 = * p + + ; nOp1 | = * p + + < < 8 ;
2006-11-01 15:13:15 +00:00
nOp1 | = * p + + < < 16 ; nOp1 | = * p + + < < 24 ;
2015-01-17 18:13:51 +01:00
p = reinterpret_cast < const sal_uInt8 * > ( pImg - > GetCode ( ) ) + nOp1 ;
2002-08-09 09:27:16 +00:00
}
2016-04-05 21:22:43 +02:00
else if ( eOp > = SbiOpcode : : SbOP1_START & & eOp < = SbiOpcode : : SbOP1_END )
2016-02-22 16:53:50 +02:00
{
p + = 4 ;
nPC + = 4 ;
}
2016-04-05 21:22:43 +02:00
else if ( eOp = = SbiOpcode : : STMNT_ )
2000-09-18 15:18:56 +00:00
{
2011-01-10 14:40:57 +01:00
sal_uInt32 nl , nc ;
2000-09-18 15:18:56 +00:00
nl = * p + + ; nl | = * p + + < < 8 ;
2006-11-01 15:13:15 +00:00
nl | = * p + + < < 16 ; nl | = * p + + < < 24 ;
2000-09-18 15:18:56 +00:00
nc = * p + + ; nc | = * p + + < < 8 ;
2006-11-01 15:13:15 +00:00
nc | = * p + + < < 16 ; nc | = * p + + < < 24 ;
2018-01-12 20:29:14 +01:00
nLine = static_cast < sal_uInt16 > ( nl ) ; nCol = static_cast < sal_uInt16 > ( nc ) ;
2000-09-18 15:18:56 +00:00
return p ;
}
2016-04-05 21:22:43 +02:00
else if ( eOp > = SbiOpcode : : SbOP2_START & & eOp < = SbiOpcode : : SbOP2_END )
2016-02-22 16:53:50 +02:00
{
p + = 8 ;
nPC + = 8 ;
}
2016-04-05 21:22:43 +02:00
else if ( ! ( eOp > = SbiOpcode : : SbOP0_START & & eOp < = SbiOpcode : : SbOP0_END ) )
2000-09-18 15:18:56 +00:00
{
2015-07-27 13:04:00 +02:00
StarBASIC : : FatalError ( ERRCODE_BASIC_INTERNAL_ERROR ) ;
2000-09-18 15:18:56 +00:00
break ;
}
}
2015-11-10 10:10:36 +01:00
return nullptr ;
2000-09-18 15:18:56 +00:00
}
2010-10-06 22:33:21 +02:00
// Test, if a line contains STMNT-Opcodes
2000-09-18 15:18:56 +00:00
2014-03-26 11:18:51 +02:00
bool SbModule : : IsBreakable ( sal_uInt16 nLine ) const
2000-09-18 15:18:56 +00:00
{
if ( ! pImage )
2014-03-26 11:18:51 +02:00
return false ;
2015-01-17 18:13:51 +01:00
const sal_uInt8 * p = reinterpret_cast < const sal_uInt8 * > ( pImage - > GetCode ( ) ) ;
2011-01-10 14:40:57 +01:00
sal_uInt16 nl , nc ;
2015-11-10 10:10:36 +01:00
while ( ( p = FindNextStmnt ( p , nl , nc ) ) ! = nullptr )
2000-09-18 15:18:56 +00:00
if ( nl = = nLine )
2014-03-26 11:18:51 +02:00
return true ;
return false ;
2000-09-18 15:18:56 +00:00
}
2014-03-26 11:18:51 +02:00
bool SbModule : : IsBP ( sal_uInt16 nLine ) const
2000-09-18 15:18:56 +00:00
{
if ( pBreaks )
{
2010-10-07 22:07:22 +02:00
for ( size_t i = 0 ; i < pBreaks - > size ( ) ; i + + )
2000-09-18 15:18:56 +00:00
{
2011-01-10 14:40:57 +01:00
sal_uInt16 b = pBreaks - > operator [ ] ( i ) ;
2000-09-18 15:18:56 +00:00
if ( b = = nLine )
2014-03-26 11:18:51 +02:00
return true ;
2000-09-18 15:18:56 +00:00
if ( b < nLine )
break ;
}
}
2014-03-26 11:18:51 +02:00
return false ;
2000-09-18 15:18:56 +00:00
}
2014-03-26 11:18:51 +02:00
bool SbModule : : SetBP ( sal_uInt16 nLine )
2000-09-18 15:18:56 +00:00
{
if ( ! IsBreakable ( nLine ) )
2014-03-26 11:18:51 +02:00
return false ;
2000-09-18 15:18:56 +00:00
if ( ! pBreaks )
2019-12-03 15:02:05 +02:00
pBreaks = new SbiBreakpoints ;
2019-03-13 21:11:09 +03:00
auto it = std : : find_if ( pBreaks - > begin ( ) , pBreaks - > end ( ) ,
[ & nLine ] ( const sal_uInt16 b ) { return b < = nLine ; } ) ;
if ( it ! = pBreaks - > end ( ) & & * it = = nLine )
return true ;
pBreaks - > insert ( it , nLine ) ;
2000-09-18 15:18:56 +00:00
2016-11-23 12:31:54 +02:00
// #38568: Set during runtime as well here BasicDebugFlags::Break
2012-01-15 16:15:08 +01:00
if ( GetSbData ( ) - > pInst & & GetSbData ( ) - > pInst - > pRun )
2016-11-23 12:31:54 +02:00
GetSbData ( ) - > pInst - > pRun - > SetDebugFlags ( BasicDebugFlags : : Break ) ;
2000-09-18 15:18:56 +00:00
return IsBreakable ( nLine ) ;
}
2014-03-26 11:18:51 +02:00
bool SbModule : : ClearBP ( sal_uInt16 nLine )
2000-09-18 15:18:56 +00:00
{
2014-03-26 11:18:51 +02:00
bool bRes = false ;
2000-09-18 15:18:56 +00:00
if ( pBreaks )
{
2019-03-13 21:11:09 +03:00
auto it = std : : find_if ( pBreaks - > begin ( ) , pBreaks - > end ( ) ,
[ & nLine ] ( const sal_uInt16 b ) { return b < = nLine ; } ) ;
bRes = ( it ! = pBreaks - > end ( ) ) & & ( * it = = nLine ) ;
if ( bRes )
2000-09-18 15:18:56 +00:00
{
2019-03-13 21:11:09 +03:00
pBreaks - > erase ( it ) ;
2000-09-18 15:18:56 +00:00
}
2010-10-07 22:07:22 +02:00
if ( pBreaks - > empty ( ) )
2016-02-22 16:53:50 +02:00
{
2019-12-03 15:02:05 +02:00
delete pBreaks ;
pBreaks = nullptr ;
2016-02-22 16:53:50 +02:00
}
2000-09-18 15:18:56 +00:00
}
return bRes ;
}
void SbModule : : ClearAllBP ( )
{
2019-12-03 15:02:05 +02:00
delete pBreaks ;
pBreaks = nullptr ;
2000-09-18 15:18:56 +00:00
}
2006-11-01 15:13:15 +00:00
void
SbModule : : fixUpMethodStart ( bool bCvtToLegacy , SbiImage * pImg ) const
{
if ( ! pImg )
2019-12-03 15:02:05 +02:00
pImg = pImage ;
2019-12-09 13:06:03 +03:00
for ( sal_uInt32 i = 0 ; i < pMethods - > Count32 ( ) ; i + + )
2006-11-01 15:13:15 +00:00
{
2019-12-09 13:06:03 +03:00
SbMethod * pMeth = dynamic_cast < SbMethod * > ( pMethods - > Get32 ( i ) ) ;
2006-11-01 15:13:15 +00:00
if ( pMeth )
{
//fixup method start positions
if ( bCvtToLegacy )
pMeth - > nStart = pImg - > CalcLegacyOffset ( pMeth - > nStart ) ;
else
2018-01-12 20:29:14 +01:00
pMeth - > nStart = pImg - > CalcNewOffset ( static_cast < sal_uInt16 > ( pMeth - > nStart ) ) ;
2006-11-01 15:13:15 +00:00
}
}
}
2014-03-26 11:18:51 +02:00
bool SbModule : : LoadData ( SvStream & rStrm , sal_uInt16 nVer )
2000-09-18 15:18:56 +00:00
{
Clear ( ) ;
if ( ! SbxObject : : LoadData ( rStrm , 1 ) )
2014-03-26 11:18:51 +02:00
return false ;
2010-10-06 22:33:21 +02:00
// As a precaution...
2015-07-27 11:31:24 +02:00
SetFlag ( SbxFlagBits : : ExtSearch | SbxFlagBits : : GlobalSearch ) ;
2011-01-10 14:40:57 +01:00
sal_uInt8 bImage ;
2014-02-05 10:41:04 +02:00
rStrm . ReadUChar ( bImage ) ;
2000-09-18 15:18:56 +00:00
if ( bImage )
{
2019-12-03 15:02:05 +02:00
SbiImage * p = new SbiImage ;
2011-01-10 14:40:57 +01:00
sal_uInt32 nImgVer = 0 ;
2006-11-01 15:13:15 +00:00
if ( ! p - > Load ( rStrm , nImgVer ) )
2000-09-18 15:18:56 +00:00
{
2019-12-03 15:02:05 +02:00
delete p ;
2014-03-26 11:18:51 +02:00
return false ;
2000-09-18 15:18:56 +00:00
}
2006-11-01 15:13:15 +00:00
// If the image is in old format, we fix up the method start offsets
if ( nImgVer < B_EXT_IMG_VERSION )
{
2019-12-03 15:02:05 +02:00
fixUpMethodStart ( false , p ) ;
2006-11-01 15:13:15 +00:00
p - > ReleaseLegacyBuffer ( ) ;
}
2000-09-18 15:18:56 +00:00
aComment = p - > aComment ;
SetName ( p - > aName ) ;
if ( p - > GetCodeSize ( ) )
{
2003-04-23 15:56:27 +00:00
aOUSource = p - > aOUSource ;
2010-10-06 22:33:21 +02:00
// Old version: image away
2000-09-18 15:18:56 +00:00
if ( nVer = = 1 )
{
2003-04-23 15:56:27 +00:00
SetSource32 ( p - > aOUSource ) ;
2019-12-03 15:02:05 +02:00
delete p ;
2000-09-18 15:18:56 +00:00
}
else
2019-12-03 15:02:05 +02:00
pImage = p ;
2000-09-18 15:18:56 +00:00
}
else
{
2003-04-23 15:56:27 +00:00
SetSource32 ( p - > aOUSource ) ;
2019-12-03 15:02:05 +02:00
delete p ;
2000-09-18 15:18:56 +00:00
}
}
2014-03-26 11:18:51 +02:00
return true ;
2000-09-18 15:18:56 +00:00
}
2014-03-26 11:18:51 +02:00
bool SbModule : : StoreData ( SvStream & rStrm ) const
2000-09-18 15:18:56 +00:00
{
2012-08-15 09:44:54 +09:00
bool bFixup = ( pImage & & ! pImage - > ExceedsLegacyLimits ( ) ) ;
2006-11-01 15:13:15 +00:00
if ( bFixup )
fixUpMethodStart ( true ) ;
2014-03-26 11:18:51 +02:00
bool bRet = SbxObject : : StoreData ( rStrm ) ;
2006-11-01 15:13:15 +00:00
if ( ! bRet )
2014-03-26 11:18:51 +02:00
return false ;
2006-11-01 15:13:15 +00:00
2000-09-18 15:18:56 +00:00
if ( pImage )
{
2003-04-23 15:56:27 +00:00
pImage - > aOUSource = aOUSource ;
2000-09-18 15:18:56 +00:00
pImage - > aComment = aComment ;
pImage - > aName = GetName ( ) ;
2014-09-25 06:07:13 +02:00
rStrm . WriteUChar ( 1 ) ;
2006-11-01 15:13:15 +00:00
// # PCode is saved only for legacy formats only
// It should be noted that it probably isn't necessary
// It would be better not to store the image ( more flexible with
// formats )
bool bRes = pImage - > Save ( rStrm , B_LEGACYVERSION ) ;
if ( bFixup )
fixUpMethodStart ( false ) ; // restore method starts
return bRes ;
2000-09-18 15:18:56 +00:00
}
else
{
SbiImage aImg ;
2003-04-23 15:56:27 +00:00
aImg . aOUSource = aOUSource ;
2000-09-18 15:18:56 +00:00
aImg . aComment = aComment ;
aImg . aName = GetName ( ) ;
2014-09-25 06:07:13 +02:00
rStrm . WriteUChar ( 1 ) ;
2000-09-18 15:18:56 +00:00
return aImg . Save ( rStrm ) ;
}
}
2014-03-26 11:18:51 +02:00
bool SbModule : : ExceedsLegacyModuleSize ( )
2006-11-01 15:13:15 +00:00
{
if ( ! IsCompiled ( ) )
Compile ( ) ;
2017-04-19 13:10:54 +02:00
return pImage & & pImage - > ExceedsLegacyLimits ( ) ;
2006-11-01 15:13:15 +00:00
}
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
namespace {
2010-10-06 10:16:27 +01:00
class ErrorHdlResetter
{
2015-05-14 09:20:01 +02:00
Link < StarBASIC * , bool > mErrHandler ;
2014-04-04 16:52:44 +02:00
bool mbError ;
public :
2018-09-02 14:52:11 +02:00
ErrorHdlResetter ( )
: mErrHandler ( StarBASIC : : GetGlobalErrorHdl ( ) ) // save error handler
, mbError ( false )
2010-10-06 10:16:27 +01:00
{
// set new error handler
StarBASIC : : SetGlobalErrorHdl ( LINK ( this , ErrorHdlResetter , BasicErrorHdl ) ) ;
}
~ ErrorHdlResetter ( )
{
// restore error handler
StarBASIC : : SetGlobalErrorHdl ( mErrHandler ) ;
}
2016-10-05 07:56:12 +02:00
DECL_LINK ( BasicErrorHdl , StarBASIC * , bool ) ;
2019-09-03 11:47:17 +02:00
bool HasError ( ) const { return mbError ; }
2010-10-06 10:16:27 +01:00
} ;
2014-04-04 16:52:44 +02:00
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
}
2016-10-05 07:56:12 +02:00
IMPL_LINK ( ErrorHdlResetter , BasicErrorHdl , StarBASIC * , /*pBasic*/ , bool )
2010-10-06 10:16:27 +01:00
{
mbError = true ;
2015-05-14 09:20:01 +02:00
return false ;
2010-10-06 10:16:27 +01:00
}
2013-07-24 17:27:02 +02:00
void SbModule : : GetCodeCompleteDataFromParse ( CodeCompleteDataCache & aCache )
GSOC work week 2, getting infromation from variables and print on terminal
This is an early version. I use the BASIC parser to parse the source,
then the infromation is extracted from the symbol table built by parser.
Error reporting is suppressed, beacuse it is not needed fro code completition.
I placed my function inside SbModule, and created a struct called CodeCompletitionData, which holds the object's name, it's parent, and it's type name.
This function, SbMethod::GetCodeCompleteDataFromParse() is called from Basic IDE's Notify function, which updates a cache(actually, reassigns a viariable :) ).
Later, in the EditorWindow::KeyInput function there is a check wheteher dot key is pressed. After that, the actual variable (or word) is being looked up in the vector that holds code completition data. And finally, if it is found, it's methods are printed on the terminal.
Change-Id: Idaf19baa8f720b8b117a76dc3cc2f90dd04fd155
2013-06-21 14:10:31 +02:00
{
ErrorHdlResetter aErrHdl ;
SbxBase : : ResetError ( ) ;
2015-09-17 17:10:47 +01:00
std : : unique_ptr < SbiParser > pParser ( new SbiParser ( static_cast < StarBASIC * > ( GetParent ( ) ) , this ) ) ;
2013-07-07 19:43:05 +02:00
pParser - > SetCodeCompleting ( true ) ;
GSOC work week 2, getting infromation from variables and print on terminal
This is an early version. I use the BASIC parser to parse the source,
then the infromation is extracted from the symbol table built by parser.
Error reporting is suppressed, beacuse it is not needed fro code completition.
I placed my function inside SbModule, and created a struct called CodeCompletitionData, which holds the object's name, it's parent, and it's type name.
This function, SbMethod::GetCodeCompleteDataFromParse() is called from Basic IDE's Notify function, which updates a cache(actually, reassigns a viariable :) ).
Later, in the EditorWindow::KeyInput function there is a check wheteher dot key is pressed. After that, the actual variable (or word) is being looked up in the vector that holds code completition data. And finally, if it is found, it's methods are printed on the terminal.
Change-Id: Idaf19baa8f720b8b117a76dc3cc2f90dd04fd155
2013-06-21 14:10:31 +02:00
while ( pParser - > Parse ( ) ) { }
SbiSymPool * pPool = pParser - > pPool ;
2013-07-24 17:27:02 +02:00
aCache . Clear ( ) ;
GSOC work week 2, getting infromation from variables and print on terminal
This is an early version. I use the BASIC parser to parse the source,
then the infromation is extracted from the symbol table built by parser.
Error reporting is suppressed, beacuse it is not needed fro code completition.
I placed my function inside SbModule, and created a struct called CodeCompletitionData, which holds the object's name, it's parent, and it's type name.
This function, SbMethod::GetCodeCompleteDataFromParse() is called from Basic IDE's Notify function, which updates a cache(actually, reassigns a viariable :) ).
Later, in the EditorWindow::KeyInput function there is a check wheteher dot key is pressed. After that, the actual variable (or word) is being looked up in the vector that holds code completition data. And finally, if it is found, it's methods are printed on the terminal.
Change-Id: Idaf19baa8f720b8b117a76dc3cc2f90dd04fd155
2013-06-21 14:10:31 +02:00
for ( sal_uInt16 i = 0 ; i < pPool - > GetSize ( ) ; + + i )
{
SbiSymDef * pSymDef = pPool - > Get ( i ) ;
2013-08-19 13:53:38 +02:00
//std::cerr << "i: " << i << ", type: " << pSymDef->GetType() << "; name:" << pSymDef->GetName() << std::endl;
2015-03-01 16:54:57 +01:00
if ( ( pSymDef - > GetType ( ) ! = SbxEMPTY ) & & ( pSymDef - > GetType ( ) ! = SbxNULL ) )
2013-08-19 13:53:38 +02:00
aCache . InsertGlobalVar ( pSymDef - > GetName ( ) , pParser - > aGblStrings . Find ( pSymDef - > GetTypeId ( ) ) ) ;
GSOC work week 2, getting infromation from variables and print on terminal
This is an early version. I use the BASIC parser to parse the source,
then the infromation is extracted from the symbol table built by parser.
Error reporting is suppressed, beacuse it is not needed fro code completition.
I placed my function inside SbModule, and created a struct called CodeCompletitionData, which holds the object's name, it's parent, and it's type name.
This function, SbMethod::GetCodeCompleteDataFromParse() is called from Basic IDE's Notify function, which updates a cache(actually, reassigns a viariable :) ).
Later, in the EditorWindow::KeyInput function there is a check wheteher dot key is pressed. After that, the actual variable (or word) is being looked up in the vector that holds code completition data. And finally, if it is found, it's methods are printed on the terminal.
Change-Id: Idaf19baa8f720b8b117a76dc3cc2f90dd04fd155
2013-06-21 14:10:31 +02:00
2016-04-25 09:59:16 +02:00
SbiSymPool & rChildPool = pSymDef - > GetPool ( ) ;
for ( sal_uInt16 j = 0 ; j < rChildPool . GetSize ( ) ; + + j )
GSOC work week 2, getting infromation from variables and print on terminal
This is an early version. I use the BASIC parser to parse the source,
then the infromation is extracted from the symbol table built by parser.
Error reporting is suppressed, beacuse it is not needed fro code completition.
I placed my function inside SbModule, and created a struct called CodeCompletitionData, which holds the object's name, it's parent, and it's type name.
This function, SbMethod::GetCodeCompleteDataFromParse() is called from Basic IDE's Notify function, which updates a cache(actually, reassigns a viariable :) ).
Later, in the EditorWindow::KeyInput function there is a check wheteher dot key is pressed. After that, the actual variable (or word) is being looked up in the vector that holds code completition data. And finally, if it is found, it's methods are printed on the terminal.
Change-Id: Idaf19baa8f720b8b117a76dc3cc2f90dd04fd155
2013-06-21 14:10:31 +02:00
{
2016-04-25 09:59:16 +02:00
SbiSymDef * pChildSymDef = rChildPool . Get ( j ) ;
2013-08-19 13:53:38 +02:00
//std::cerr << "j: " << j << ", type: " << pChildSymDef->GetType() << "; name:" << pChildSymDef->GetName() << std::endl;
2015-03-01 16:54:57 +01:00
if ( ( pChildSymDef - > GetType ( ) ! = SbxEMPTY ) & & ( pChildSymDef - > GetType ( ) ! = SbxNULL ) )
2013-08-19 13:53:38 +02:00
aCache . InsertLocalVar ( pSymDef - > GetName ( ) , pChildSymDef - > GetName ( ) , pParser - > aGblStrings . Find ( pChildSymDef - > GetTypeId ( ) ) ) ;
GSOC work week 2, getting infromation from variables and print on terminal
This is an early version. I use the BASIC parser to parse the source,
then the infromation is extracted from the symbol table built by parser.
Error reporting is suppressed, beacuse it is not needed fro code completition.
I placed my function inside SbModule, and created a struct called CodeCompletitionData, which holds the object's name, it's parent, and it's type name.
This function, SbMethod::GetCodeCompleteDataFromParse() is called from Basic IDE's Notify function, which updates a cache(actually, reassigns a viariable :) ).
Later, in the EditorWindow::KeyInput function there is a check wheteher dot key is pressed. After that, the actual variable (or word) is being looked up in the vector that holds code completition data. And finally, if it is found, it's methods are printed on the terminal.
Change-Id: Idaf19baa8f720b8b117a76dc3cc2f90dd04fd155
2013-06-21 14:10:31 +02:00
}
}
}
2013-07-07 19:43:05 +02:00
2015-04-10 11:07:36 +02:00
OUString SbModule : : GetKeywordCase ( const OUString & sKeyword )
2013-08-13 18:11:26 +02:00
{
return SbiParser : : GetKeywordCase ( sKeyword ) ;
}
2010-10-06 10:16:27 +01:00
bool SbModule : : HasExeCode ( )
{
2010-11-01 12:28:23 +00:00
// And empty Image always has the Global Chain set up
static const unsigned char pEmptyImage [ ] = { 0x45 , 0x0 , 0x0 , 0x0 , 0x0 } ;
// lets be stricter for the moment than VBA
2010-10-06 10:16:27 +01:00
2010-11-01 12:28:23 +00:00
if ( ! IsCompiled ( ) )
{
2010-10-06 10:16:27 +01:00
ErrorHdlResetter aGblErrHdl ;
2010-11-01 12:28:23 +00:00
Compile ( ) ;
if ( aGblErrHdl . HasError ( ) ) //assume unsafe on compile error
return true ;
}
2010-10-06 10:16:27 +01:00
bool bRes = false ;
2010-11-01 12:28:23 +00:00
if ( pImage & & ! ( pImage - > GetCodeSize ( ) = = 5 & & ( memcmp ( pImage - > GetCode ( ) , pEmptyImage , pImage - > GetCodeSize ( ) ) = = 0 ) ) )
2010-10-06 10:16:27 +01:00
bRes = true ;
2010-11-01 12:28:23 +00:00
2010-10-06 10:16:27 +01:00
return bRes ;
}
2006-11-01 15:13:15 +00:00
2001-10-23 11:06:51 +00:00
// Store only image, no source
2017-04-04 14:13:00 +02:00
void SbModule : : StoreBinaryData ( SvStream & rStrm )
2001-10-23 11:06:51 +00:00
{
2016-02-15 11:26:45 +00:00
if ( ! Compile ( ) )
return ;
2001-10-23 11:06:51 +00:00
2016-02-15 11:26:45 +00:00
if ( ! SbxObject : : StoreData ( rStrm ) )
return ;
2001-10-23 11:06:51 +00:00
2016-02-15 11:26:45 +00:00
pImage - > aOUSource . clear ( ) ;
pImage - > aComment = aComment ;
pImage - > aName = GetName ( ) ;
rStrm . WriteUChar ( 1 ) ;
2017-04-04 14:13:00 +02:00
pImage - > Save ( rStrm ) ;
2016-02-15 11:26:45 +00:00
pImage - > aOUSource = aOUSource ;
2001-10-23 11:06:51 +00:00
}
2006-11-01 15:13:15 +00:00
// Called for >= OO 1.0 passwd protected libraries only
2016-01-11 14:31:00 +02:00
void SbModule : : LoadBinaryData ( SvStream & rStrm )
2001-10-23 11:06:51 +00:00
{
2012-11-06 23:34:23 -06:00
OUString aKeepSource = aOUSource ;
2016-01-11 14:31:00 +02:00
LoadData ( rStrm , 2 ) ;
2005-07-08 08:58:33 +00:00
LoadCompleted ( ) ;
2003-04-23 15:56:27 +00:00
aOUSource = aKeepSource ;
2001-10-23 11:06:51 +00:00
}
2014-03-26 11:18:51 +02:00
bool SbModule : : LoadCompleted ( )
2000-09-18 15:18:56 +00:00
{
2016-10-05 22:00:51 +02:00
SbxArray * p = GetMethods ( ) . get ( ) ;
2019-12-09 13:06:03 +03:00
sal_uInt32 i ;
for ( i = 0 ; i < p - > Count32 ( ) ; i + + )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbMethod * q = dynamic_cast < SbMethod * > ( p - > Get32 ( i ) ) ;
2000-09-18 15:18:56 +00:00
if ( q )
q - > pMod = this ;
}
p = GetProperties ( ) ;
2019-12-09 13:06:03 +03:00
for ( i = 0 ; i < p - > Count32 ( ) ; i + + )
2000-09-18 15:18:56 +00:00
{
2019-12-09 13:06:03 +03:00
SbProperty * q = dynamic_cast < SbProperty * > ( p - > Get32 ( i ) ) ;
2000-09-18 15:18:56 +00:00
if ( q )
q - > pMod = this ;
}
2014-03-26 11:18:51 +02:00
return true ;
2000-09-18 15:18:56 +00:00
}
2010-08-23 10:54:49 +02:00
void SbModule : : handleProcedureProperties ( SfxBroadcaster & rBC , const SfxHint & rHint )
{
bool bDone = false ;
2014-08-27 16:57:21 +02:00
const SbxHint * pHint = dynamic_cast < const SbxHint * > ( & rHint ) ;
2010-08-23 10:54:49 +02:00
if ( pHint )
{
SbxVariable * pVar = pHint - > GetVar ( ) ;
2015-09-28 11:42:43 +02:00
SbProcedureProperty * pProcProperty = dynamic_cast < SbProcedureProperty * > ( pVar ) ;
2010-08-23 10:54:49 +02:00
if ( pProcProperty )
{
bDone = true ;
2016-12-08 10:26:01 +02:00
if ( pHint - > GetId ( ) = = SfxHintId : : BasicDataWanted )
2010-08-23 10:54:49 +02:00
{
2016-07-01 14:07:52 +03:00
OUString aProcName = " Property Get "
+ pProcProperty - > GetName ( ) ;
2010-08-23 10:54:49 +02:00
2016-05-21 16:22:07 +02:00
SbxVariable * pMeth = Find ( aProcName , SbxClassType : : Method ) ;
2010-08-23 10:54:49 +02:00
if ( pMeth )
{
SbxValues aVals ;
aVals . eType = SbxVARIANT ;
SbxArray * pArg = pVar - > GetParameters ( ) ;
2019-12-09 13:06:03 +03:00
sal_uInt32 nVarParCount = ( pArg ! = nullptr ) ? pArg - > Count32 ( ) : 0 ;
2010-08-23 10:54:49 +02:00
if ( nVarParCount > 1 )
{
SbxArrayRef xMethParameters = new SbxArray ;
2019-12-09 13:06:03 +03:00
xMethParameters - > Put32 ( pMeth , 0 ) ; // Method as parameter 0
for ( sal_uInt32 i = 1 ; i < nVarParCount ; + + i )
2010-08-23 10:54:49 +02:00
{
2019-12-09 13:06:03 +03:00
SbxVariable * pPar = pArg - > Get32 ( i ) ;
xMethParameters - > Put32 ( pPar , i ) ;
2010-08-23 10:54:49 +02:00
}
2016-10-05 22:00:51 +02:00
pMeth - > SetParameters ( xMethParameters . get ( ) ) ;
2010-08-23 10:54:49 +02:00
pMeth - > Get ( aVals ) ;
2015-11-10 10:10:36 +01:00
pMeth - > SetParameters ( nullptr ) ;
2010-08-23 10:54:49 +02:00
}
else
{
pMeth - > Get ( aVals ) ;
}
pVar - > Put ( aVals ) ;
}
}
2016-12-08 10:26:01 +02:00
else if ( pHint - > GetId ( ) = = SfxHintId : : BasicDataChanged )
2010-08-23 10:54:49 +02:00
{
2015-11-10 10:10:36 +01:00
SbxVariable * pMeth = nullptr ;
2010-08-23 10:54:49 +02:00
bool bSet = pProcProperty - > isSet ( ) ;
if ( bSet )
{
pProcProperty - > setSet ( false ) ;
2016-07-01 14:07:52 +03:00
OUString aProcName = " Property Set "
+ pProcProperty - > GetName ( ) ;
2016-05-21 16:22:07 +02:00
pMeth = Find ( aProcName , SbxClassType : : Method ) ;
2010-08-23 10:54:49 +02:00
}
if ( ! pMeth ) // Let
{
2016-07-01 14:07:52 +03:00
OUString aProcName = " Property Let "
+ pProcProperty - > GetName ( ) ;
2016-05-21 16:22:07 +02:00
pMeth = Find ( aProcName , SbxClassType : : Method ) ;
2010-08-23 10:54:49 +02:00
}
if ( pMeth )
{
// Setup parameters
SbxArrayRef xArray = new SbxArray ;
2019-12-09 13:06:03 +03:00
xArray - > Put32 ( pMeth , 0 ) ; // Method as parameter 0
xArray - > Put32 ( pVar , 1 ) ;
2016-10-05 22:00:51 +02:00
pMeth - > SetParameters ( xArray . get ( ) ) ;
2010-08-23 10:54:49 +02:00
SbxValues aVals ;
pMeth - > Get ( aVals ) ;
2015-11-10 10:10:36 +01:00
pMeth - > SetParameters ( nullptr ) ;
2010-08-23 10:54:49 +02:00
}
}
}
}
if ( ! bDone )
SbModule : : Notify ( rBC , rHint ) ;
2000-09-18 15:18:56 +00:00
}
2010-08-23 10:54:49 +02:00
2011-12-12 22:35:05 +01:00
// Implementation SbJScriptModule (Basic module for JavaScript source code)
2017-05-09 12:14:32 +02:00
SbJScriptModule : : SbJScriptModule ( )
: SbModule ( " " )
2000-09-18 15:18:56 +00:00
{
}
2017-07-02 22:35:38 +02:00
bool SbJScriptModule : : LoadData ( SvStream & rStrm , sal_uInt16 )
2000-09-18 15:18:56 +00:00
{
Clear ( ) ;
if ( ! SbxObject : : LoadData ( rStrm , 1 ) )
2014-03-26 11:18:51 +02:00
return false ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// Get the source string
2012-01-06 08:50:03 +00:00
aOUSource = rStrm . ReadUniOrByteString ( osl_getThreadTextEncoding ( ) ) ;
2014-03-26 11:18:51 +02:00
return true ;
2000-09-18 15:18:56 +00:00
}
2014-03-26 11:18:51 +02:00
bool SbJScriptModule : : StoreData ( SvStream & rStrm ) const
2000-09-18 15:18:56 +00:00
{
if ( ! SbxObject : : StoreData ( rStrm ) )
2014-03-26 11:18:51 +02:00
return false ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// Write the source string
2012-11-06 23:34:23 -06:00
OUString aTmp = aOUSource ;
2011-12-21 10:45:54 +00:00
rStrm . WriteUniOrByteString ( aTmp , osl_getThreadTextEncoding ( ) ) ;
2014-03-26 11:18:51 +02:00
return true ;
2000-09-18 15:18:56 +00:00
}
2012-11-06 23:34:23 -06:00
SbMethod : : SbMethod ( const OUString & r , SbxDataType t , SbModule * p )
2000-09-18 15:18:56 +00:00
: SbxMethod ( r , t ) , pMod ( p )
{
2014-03-26 11:18:51 +02:00
bInvalid = true ;
2016-11-23 12:31:54 +02:00
nStart = 0 ;
nDebugFlags = BasicDebugFlags : : NONE ;
nLine1 = 0 ;
2000-09-18 15:18:56 +00:00
nLine2 = 0 ;
2016-11-23 12:31:54 +02:00
refStatics = new SbxArray ;
mCaller = nullptr ;
2018-08-13 17:11:07 +02:00
// HACK due to 'Reference could not be saved'
2015-07-27 11:31:24 +02:00
SetFlag ( SbxFlagBits : : NoModify ) ;
2000-09-18 15:18:56 +00:00
}
2003-04-23 15:56:27 +00:00
SbMethod : : SbMethod ( const SbMethod & r )
2006-06-19 16:40:39 +00:00
: SvRefBase ( r ) , SbxMethod ( r )
2003-04-23 15:56:27 +00:00
{
pMod = r . pMod ;
bInvalid = r . bInvalid ;
nStart = r . nStart ;
nDebugFlags = r . nDebugFlags ;
nLine1 = r . nLine1 ;
nLine2 = r . nLine2 ;
2019-02-08 09:27:38 +02:00
refStatics = r . refStatics ;
2010-10-06 10:16:27 +01:00
mCaller = r . mCaller ;
2015-07-27 11:31:24 +02:00
SetFlag ( SbxFlagBits : : NoModify ) ;
2003-04-23 15:56:27 +00:00
}
2000-09-18 15:18:56 +00:00
SbMethod : : ~ SbMethod ( )
2003-04-23 15:56:27 +00:00
{
}
2000-09-18 15:18:56 +00:00
2008-07-02 08:57:20 +00:00
void SbMethod : : ClearStatics ( )
{
refStatics = new SbxArray ;
}
2000-09-18 15:18:56 +00:00
SbxArray * SbMethod : : GetStatics ( )
{
2016-10-05 22:00:51 +02:00
return refStatics . get ( ) ;
2000-09-18 15:18:56 +00:00
}
2014-03-26 11:18:51 +02:00
bool SbMethod : : LoadData ( SvStream & rStrm , sal_uInt16 nVer )
2000-09-18 15:18:56 +00:00
{
if ( ! SbxMethod : : LoadData ( rStrm , 1 ) )
2014-03-26 11:18:51 +02:00
return false ;
2015-09-18 17:06:29 +02:00
sal_uInt16 nFlag ;
rStrm . ReadUInt16 ( nFlag ) ;
2018-01-12 20:29:14 +01:00
sal_Int16 nTempStart = static_cast < sal_Int16 > ( nStart ) ;
2015-09-18 17:06:29 +02:00
2000-09-18 15:18:56 +00:00
if ( nVer = = 2 )
2015-09-18 17:06:29 +02:00
{
2014-03-26 11:18:51 +02:00
rStrm . ReadUInt16 ( nLine1 ) . ReadUInt16 ( nLine2 ) . ReadInt16 ( nTempStart ) . ReadCharAsBool ( bInvalid ) ;
2015-09-18 17:06:29 +02:00
//tdf#94617
if ( nFlag & 0x8000 )
{
sal_uInt16 nMult = nFlag & 0x7FFF ;
2017-06-19 16:02:12 +02:00
sal_Int16 const nMax = std : : numeric_limits < sal_Int16 > : : max ( ) ;
2015-09-18 17:06:29 +02:00
nStart = nMult * nMax + nTempStart ;
}
else
{
nStart = nTempStart ;
}
}
else
{
nStart = nTempStart ;
}
2018-08-13 17:11:07 +02:00
// HACK due to 'Reference could not be saved'
2015-07-27 11:31:24 +02:00
SetFlag ( SbxFlagBits : : NoModify ) ;
2015-09-18 17:06:29 +02:00
2014-03-26 11:18:51 +02:00
return true ;
2000-09-18 15:18:56 +00:00
}
2014-03-26 11:18:51 +02:00
bool SbMethod : : StoreData ( SvStream & rStrm ) const
2000-09-18 15:18:56 +00:00
{
if ( ! SbxMethod : : StoreData ( rStrm ) )
2014-03-26 11:18:51 +02:00
return false ;
2015-09-18 17:06:29 +02:00
//tdf#94617
sal_Int16 nMax = std : : numeric_limits < sal_Int16 > : : max ( ) ;
sal_Int16 nStartTemp = nStart % nMax ;
sal_uInt16 nDebugFlagsTemp = nStart / nMax ;
nDebugFlagsTemp | = 0x8000 ;
rStrm . WriteUInt16 ( nDebugFlagsTemp )
2015-01-16 08:07:06 +02:00
. WriteInt16 ( nLine1 )
. WriteInt16 ( nLine2 )
2015-09-18 17:06:29 +02:00
. WriteInt16 ( nStartTemp )
2015-04-17 14:55:13 +02:00
. WriteBool ( bInvalid ) ;
2015-09-18 17:06:29 +02:00
2014-03-26 11:18:51 +02:00
return true ;
2000-09-18 15:18:56 +00:00
}
2011-01-10 14:40:57 +01:00
void SbMethod : : GetLineRange ( sal_uInt16 & l1 , sal_uInt16 & l2 )
2000-09-18 15:18:56 +00:00
{
l1 = nLine1 ; l2 = nLine2 ;
}
2010-10-06 22:33:21 +02:00
// Could later be deleted
2000-09-18 15:18:56 +00:00
SbxInfo * SbMethod : : GetInfo ( )
{
2016-10-05 22:00:51 +02:00
return pInfo . get ( ) ;
2000-09-18 15:18:56 +00:00
}
2010-10-06 22:33:21 +02:00
// Interface to execute a method of the applications
2011-03-21 12:55:40 +01:00
// With special RefCounting, so that the Basic was not fired of by CloseDocument()
2010-10-06 22:33:21 +02:00
// The return value will be delivered as string.
2010-10-06 10:16:27 +01:00
ErrCode SbMethod : : Call ( SbxValue * pRet , SbxVariable * pCaller )
2000-09-18 15:18:56 +00:00
{
2010-10-06 10:16:27 +01:00
if ( pCaller )
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " SbMethod::Call Have been passed a caller 0x " < < pCaller ) ;
2010-10-06 10:16:27 +01:00
mCaller = pCaller ;
}
2017-05-13 15:23:33 +02:00
// Increment the RefCount of the module
2016-02-21 17:51:28 +01:00
tools : : SvRef < SbModule > pMod_ = static_cast < SbModule * > ( GetParent ( ) ) ;
2000-09-18 15:18:56 +00:00
2020-01-25 15:05:53 +02:00
tools : : SvRef < StarBASIC > xHolder = static_cast < StarBASIC * > ( pMod_ - > GetParent ( ) ) ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// Establish the values to get the return value
2000-09-18 15:18:56 +00:00
SbxValues aVals ;
aVals . eType = SbxVARIANT ;
2002-10-25 09:03:13 +00:00
// #104083: Compile BEFORE get
2006-06-19 16:40:39 +00:00
if ( bInvalid & & ! pMod_ - > Compile ( ) )
2015-07-27 13:04:00 +02:00
StarBASIC : : Error ( ERRCODE_BASIC_BAD_PROP_VALUE ) ;
2002-10-25 09:03:13 +00:00
2000-09-18 15:18:56 +00:00
Get ( aVals ) ;
if ( pRet )
pRet - > Put ( aVals ) ;
2010-10-06 22:33:21 +02:00
// Was there an error
2000-09-18 15:18:56 +00:00
ErrCode nErr = SbxBase : : GetError ( ) ;
SbxBase : : ResetError ( ) ;
2015-11-10 10:10:36 +01:00
mCaller = nullptr ;
2000-09-18 15:18:56 +00:00
return nErr ;
}
2003-04-23 15:56:27 +00:00
// #100883 Own Broadcast for SbMethod
2016-12-08 10:26:01 +02:00
void SbMethod : : Broadcast ( SfxHintId nHintId )
2003-04-23 15:56:27 +00:00
{
2018-01-16 15:05:33 +02:00
if ( mpBroadcaster & & ! IsSet ( SbxFlagBits : : NoBroadcast ) )
2003-04-23 15:56:27 +00:00
{
2010-10-06 22:33:21 +02:00
// Because the method could be called from outside, test here once again
// the authorisation
2016-12-08 10:26:01 +02:00
if ( nHintId = = SfxHintId : : BasicDataWanted )
2003-04-23 15:56:27 +00:00
if ( ! CanRead ( ) )
return ;
2016-12-08 10:26:01 +02:00
if ( nHintId = = SfxHintId : : BasicDataChanged )
2003-04-23 15:56:27 +00:00
if ( ! CanWrite ( ) )
return ;
2003-07-01 13:52:35 +00:00
if ( pMod & & ! pMod - > IsCompiled ( ) )
2003-04-23 15:56:27 +00:00
pMod - > Compile ( ) ;
// Block broadcasts while creating new method
2018-01-16 15:05:33 +02:00
std : : unique_ptr < SfxBroadcaster > pSaveBroadcaster = std : : move ( mpBroadcaster ) ;
2003-04-23 15:56:27 +00:00
SbMethod * pThisCopy = new SbMethod ( * this ) ;
SbMethodRef xHolder = pThisCopy ;
2017-01-25 12:03:58 +02:00
if ( mpPar . is ( ) )
2003-04-23 15:56:27 +00:00
{
2014-06-02 12:04:31 +02:00
// Enregister this as element 0, but don't reset the parent!
2015-08-14 11:45:09 +02:00
if ( GetType ( ) ! = SbxVOID ) {
2007-08-03 08:55:16 +00:00
mpPar - > PutDirect ( pThisCopy , 0 ) ;
2014-06-02 11:12:11 +02:00
}
2015-11-10 10:10:36 +01:00
SetParameters ( nullptr ) ;
2003-04-23 15:56:27 +00:00
}
2018-01-16 15:05:33 +02:00
mpBroadcaster = std : : move ( pSaveBroadcaster ) ;
mpBroadcaster - > Broadcast ( SbxHint ( nHintId , pThisCopy ) ) ;
2003-04-23 15:56:27 +00:00
2014-08-21 14:41:58 +02:00
SbxFlagBits nSaveFlags = GetFlags ( ) ;
2015-07-27 11:31:24 +02:00
SetFlag ( SbxFlagBits : : ReadWrite ) ;
2018-01-16 15:05:33 +02:00
pSaveBroadcaster = std : : move ( mpBroadcaster ) ;
2003-04-23 15:56:27 +00:00
Put ( pThisCopy - > GetValues_Impl ( ) ) ;
2018-01-16 15:05:33 +02:00
mpBroadcaster = std : : move ( pSaveBroadcaster ) ;
2003-04-23 15:56:27 +00:00
SetFlags ( nSaveFlags ) ;
}
}
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// Implementation of SbJScriptMethod (method class as a wrapper for JavaScript-functions)
2000-09-18 15:18:56 +00:00
2017-05-09 12:14:32 +02:00
SbJScriptMethod : : SbJScriptMethod ( SbxDataType t )
: SbMethod ( " " , t , nullptr )
2000-09-18 15:18:56 +00:00
{
}
SbJScriptMethod : : ~ SbJScriptMethod ( )
{ }
2015-07-20 09:21:24 +02:00
SbObjModule : : SbObjModule ( const OUString & rName , const css : : script : : ModuleInfo & mInfo , bool bIsVbaCompatible )
2010-03-02 12:39:31 +00:00
: SbModule ( rName , bIsVbaCompatible )
{
SetModuleType ( mInfo . ModuleType ) ;
2010-04-16 17:28:52 +02:00
if ( mInfo . ModuleType = = script : : ModuleType : : FORM )
2010-03-02 12:39:31 +00:00
{
2013-01-09 00:14:10 +02:00
SetClassName ( " Form " ) ;
2010-03-02 12:39:31 +00:00
}
else if ( mInfo . ModuleObject . is ( ) )
2012-11-06 23:34:23 -06:00
{
2017-02-03 08:54:47 +02:00
SetUnoObject ( uno : : Any ( mInfo . ModuleObject ) ) ;
2012-11-06 23:34:23 -06:00
}
2010-03-02 12:39:31 +00:00
}
2010-08-30 09:45:08 +02:00
SbObjModule : : ~ SbObjModule ( )
{
}
2010-03-02 12:39:31 +00:00
void
2017-01-26 12:28:58 +01:00
SbObjModule : : SetUnoObject ( const uno : : Any & aObj )
2010-03-02 12:39:31 +00:00
{
2016-10-05 22:00:51 +02:00
SbUnoObject * pUnoObj = dynamic_cast < SbUnoObject * > ( pDocObject . get ( ) ) ;
2010-03-02 12:39:31 +00:00
if ( pUnoObj & & pUnoObj - > getUnoAny ( ) = = aObj ) // object is equal, nothing to do
return ;
2015-04-08 17:45:08 +02:00
pDocObject = new SbUnoObject ( GetName ( ) , aObj ) ;
2010-03-02 12:39:31 +00:00
2015-07-20 09:21:24 +02:00
css : : uno : : Reference < css : : lang : : XServiceInfo > xServiceInfo ( aObj , css : : uno : : UNO_QUERY_THROW ) ;
2013-01-09 00:14:10 +02:00
if ( xServiceInfo - > supportsService ( " ooo.vba.excel.Worksheet " ) )
2010-03-02 12:39:31 +00:00
{
2013-01-09 00:14:10 +02:00
SetClassName ( " Worksheet " ) ;
2010-03-02 12:39:31 +00:00
}
2013-01-09 00:14:10 +02:00
else if ( xServiceInfo - > supportsService ( " ooo.vba.excel.Workbook " ) )
2010-03-02 12:39:31 +00:00
{
2013-01-09 00:14:10 +02:00
SetClassName ( " Workbook " ) ;
2010-03-02 12:39:31 +00:00
}
}
SbxVariable *
SbObjModule : : GetObject ( )
{
2016-10-05 22:00:51 +02:00
return pDocObject . get ( ) ;
2010-03-02 12:39:31 +00:00
}
SbxVariable *
2012-11-06 23:34:23 -06:00
SbObjModule : : Find ( const OUString & rName , SbxClassType t )
2010-03-02 12:39:31 +00:00
{
2015-11-10 10:10:36 +01:00
SbxVariable * pVar = nullptr ;
2016-10-05 22:00:51 +02:00
if ( pDocObject . get ( ) )
2010-03-02 12:39:31 +00:00
pVar = pDocObject - > Find ( rName , t ) ;
if ( ! pVar )
pVar = SbModule : : Find ( rName , t ) ;
return pVar ;
}
2015-06-24 12:06:34 +02:00
void SbObjModule : : Notify ( SfxBroadcaster & rBC , const SfxHint & rHint )
2010-08-23 10:54:49 +02:00
{
SbModule : : handleProcedureProperties ( rBC , rHint ) ;
}
2015-07-02 17:14:33 +09:00
typedef : : cppu : : WeakImplHelper <
2011-02-11 15:06:12 +01:00
awt : : XTopWindowListener ,
awt : : XWindowListener ,
2015-04-22 14:42:23 +02:00
document : : XDocumentEventListener > FormObjEventListener_BASE ;
2010-03-02 12:39:31 +00:00
2014-04-09 10:11:46 +02:00
class FormObjEventListenerImpl :
2016-03-06 21:19:25 -08:00
public FormObjEventListener_BASE
2010-03-02 12:39:31 +00:00
{
SbUserFormModule * mpUserForm ;
uno : : Reference < lang : : XComponent > mxComponent ;
2011-02-11 15:06:12 +01:00
uno : : Reference < frame : : XModel > mxModel ;
2010-03-02 12:39:31 +00:00
bool mbDisposed ;
2013-10-01 23:16:43 +09:00
bool mbOpened ;
bool mbActivated ;
bool mbShowing ;
2011-02-11 15:06:12 +01:00
2010-03-02 12:39:31 +00:00
public :
2016-03-06 21:19:25 -08:00
FormObjEventListenerImpl ( const FormObjEventListenerImpl & ) = delete ;
const FormObjEventListenerImpl & operator = ( const FormObjEventListenerImpl & ) = delete ;
2011-02-11 15:06:12 +01:00
FormObjEventListenerImpl ( SbUserFormModule * pUserForm , const uno : : Reference < lang : : XComponent > & xComponent , const uno : : Reference < frame : : XModel > & xModel ) :
mpUserForm ( pUserForm ) , mxComponent ( xComponent ) , mxModel ( xModel ) ,
2013-10-01 23:16:43 +09:00
mbDisposed ( false ) , mbOpened ( false ) , mbActivated ( false ) , mbShowing ( false )
2010-03-02 12:39:31 +00:00
{
2010-03-05 20:14:25 +00:00
if ( mxComponent . is ( ) )
2010-03-02 12:39:31 +00:00
{
2010-07-06 18:07:29 +02:00
try
{
uno : : Reference < awt : : XTopWindow > ( mxComponent , uno : : UNO_QUERY_THROW ) - > addTopWindowListener ( this ) ;
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & ) { }
2010-07-06 18:07:29 +02:00
try
{
uno : : Reference < awt : : XWindow > ( mxComponent , uno : : UNO_QUERY_THROW ) - > addWindowListener ( this ) ;
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & ) { }
2010-03-02 12:39:31 +00:00
}
2011-02-11 15:06:12 +01:00
if ( mxModel . is ( ) )
{
try
{
2015-04-22 14:42:23 +02:00
uno : : Reference < document : : XDocumentEventBroadcaster > ( mxModel , uno : : UNO_QUERY_THROW ) - > addDocumentEventListener ( this ) ;
2011-02-11 15:06:12 +01:00
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & ) { }
2011-02-11 15:06:12 +01:00
}
2010-03-02 12:39:31 +00:00
}
2016-09-13 13:09:01 +02:00
virtual ~ FormObjEventListenerImpl ( ) override
2010-03-02 12:39:31 +00:00
{
removeListener ( ) ;
}
2010-07-06 18:07:29 +02:00
2013-10-01 23:16:43 +09:00
bool isShowing ( ) const { return mbShowing ; }
2010-07-06 18:07:29 +02:00
2010-03-02 12:39:31 +00:00
void removeListener ( )
{
2010-07-06 18:07:29 +02:00
if ( mxComponent . is ( ) & & ! mbDisposed )
2010-03-02 12:39:31 +00:00
{
2010-07-06 18:07:29 +02:00
try
2010-03-02 12:39:31 +00:00
{
2010-07-06 18:07:29 +02:00
uno : : Reference < awt : : XTopWindow > ( mxComponent , uno : : UNO_QUERY_THROW ) - > removeTopWindowListener ( this ) ;
2010-03-02 12:39:31 +00:00
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & ) { }
2010-07-06 18:07:29 +02:00
try
{
uno : : Reference < awt : : XWindow > ( mxComponent , uno : : UNO_QUERY_THROW ) - > removeWindowListener ( this ) ;
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & ) { }
2010-03-02 12:39:31 +00:00
}
2010-07-06 18:07:29 +02:00
mxComponent . clear ( ) ;
2011-02-11 15:06:12 +01:00
if ( mxModel . is ( ) & & ! mbDisposed )
{
try
{
2015-04-22 14:42:23 +02:00
uno : : Reference < document : : XDocumentEventBroadcaster > ( mxModel , uno : : UNO_QUERY_THROW ) - > removeDocumentEventListener ( this ) ;
2011-02-11 15:06:12 +01:00
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & ) { }
2011-02-11 15:06:12 +01:00
}
mxModel . clear ( ) ;
2010-03-02 12:39:31 +00:00
}
2010-07-06 18:07:29 +02:00
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowOpened ( const lang : : EventObject & /*e*/ ) override
2010-03-02 12:39:31 +00:00
{
2010-07-06 18:07:29 +02:00
if ( mpUserForm )
2010-03-02 12:39:31 +00:00
{
2013-10-01 23:16:43 +09:00
mbOpened = true ;
mbShowing = true ;
2010-03-02 12:39:31 +00:00
if ( mbActivated )
{
2013-10-01 23:16:43 +09:00
mbOpened = mbActivated = false ;
2010-03-02 12:39:31 +00:00
mpUserForm - > triggerActivateEvent ( ) ;
}
}
}
2010-10-19 23:45:24 -05:00
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowClosing ( const lang : : EventObject & /*e*/ ) override
2010-03-02 12:39:31 +00:00
{
2012-09-12 14:35:23 +01:00
# ifdef IN_THE_FUTURE
2010-03-02 12:39:31 +00:00
uno : : Reference < awt : : XDialog > xDialog ( e . Source , uno : : UNO_QUERY ) ;
if ( xDialog . is ( ) )
{
uno : : Reference < awt : : XControl > xControl ( xDialog , uno : : UNO_QUERY ) ;
if ( xControl - > getPeer ( ) . is ( ) )
{
uno : : Reference < document : : XVbaMethodParameter > xVbaMethodParameter ( xControl - > getPeer ( ) , uno : : UNO_QUERY ) ;
if ( xVbaMethodParameter . is ( ) )
{
sal_Int8 nCancel = 0 ;
2011-03-25 10:40:25 +01:00
sal_Int8 nCloseMode = : : ooo : : vba : : VbQueryClose : : vbFormControlMenu ;
2010-03-02 12:39:31 +00:00
Sequence < Any > aParams ;
aParams . realloc ( 2 ) ;
aParams [ 0 ] < < = nCancel ;
aParams [ 1 ] < < = nCloseMode ;
2013-01-09 00:14:10 +02:00
mpUserForm - > triggerMethod ( " Userform_QueryClose " , aParams ) ;
2010-03-02 12:39:31 +00:00
return ;
}
}
}
2013-01-09 00:14:10 +02:00
mpUserForm - > triggerMethod ( " Userform_QueryClose " ) ;
2012-09-12 14:35:23 +01:00
# endif
2010-03-02 12:39:31 +00:00
}
2010-10-19 23:45:24 -05:00
2010-03-02 12:39:31 +00:00
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowClosed ( const lang : : EventObject & /*e*/ ) override
2010-07-06 18:07:29 +02:00
{
2013-10-01 23:16:43 +09:00
mbOpened = false ;
mbShowing = false ;
2010-07-06 18:07:29 +02:00
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowMinimized ( const lang : : EventObject & /*e*/ ) override
2010-07-06 18:07:29 +02:00
{
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowNormalized ( const lang : : EventObject & /*e*/ ) override
2010-07-06 18:07:29 +02:00
{
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowActivated ( const lang : : EventObject & /*e*/ ) override
2010-03-02 12:39:31 +00:00
{
2010-07-06 18:07:29 +02:00
if ( mpUserForm )
2010-03-02 12:39:31 +00:00
{
2013-10-01 23:16:43 +09:00
mbActivated = true ;
2010-03-02 12:39:31 +00:00
if ( mbOpened )
{
2013-10-01 23:16:43 +09:00
mbOpened = mbActivated = false ;
2010-03-02 12:39:31 +00:00
mpUserForm - > triggerActivateEvent ( ) ;
}
}
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowDeactivated ( const lang : : EventObject & /*e*/ ) override
2010-03-02 12:39:31 +00:00
{
2010-07-06 18:07:29 +02:00
if ( mpUserForm )
mpUserForm - > triggerDeactivateEvent ( ) ;
2010-03-02 12:39:31 +00:00
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowResized ( const awt : : WindowEvent & /*e*/ ) override
2010-07-06 18:07:29 +02:00
{
if ( mpUserForm )
{
mpUserForm - > triggerResizeEvent ( ) ;
mpUserForm - > triggerLayoutEvent ( ) ;
}
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowMoved ( const awt : : WindowEvent & /*e*/ ) override
2010-07-06 18:07:29 +02:00
{
if ( mpUserForm )
mpUserForm - > triggerLayoutEvent ( ) ;
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowShown ( const lang : : EventObject & /*e*/ ) override
2010-07-06 18:07:29 +02:00
{
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL windowHidden ( const lang : : EventObject & /*e*/ ) override
2010-07-06 18:07:29 +02:00
{
}
2010-03-02 12:39:31 +00:00
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL documentEventOccured ( const document : : DocumentEvent & rEvent ) override
2011-02-11 15:06:12 +01:00
{
2016-01-04 12:37:59 +01:00
// early disposing on document event "OnUnload", to be sure Basic still exists when calling VBA "UserForm_Terminate"
2015-04-28 15:01:43 +02:00
if ( rEvent . EventName = = GlobalEventConfig : : GetEventName ( GlobalEventId : : CLOSEDOC ) )
2011-02-11 15:06:12 +01:00
{
removeListener ( ) ;
mbDisposed = true ;
if ( mpUserForm )
mpUserForm - > ResetApiObj ( ) ; // will trigger "UserForm_Terminate"
}
}
2017-01-26 12:28:58 +01:00
virtual void SAL_CALL disposing ( const lang : : EventObject & /*Source*/ ) override
2010-03-02 12:39:31 +00:00
{
2011-02-11 15:06:12 +01:00
removeListener ( ) ;
2010-03-02 12:39:31 +00:00
mbDisposed = true ;
if ( mpUserForm )
2011-02-11 15:06:12 +01:00
mpUserForm - > ResetApiObj ( false ) ; // pass false (too late to trigger VBA events here)
2010-03-02 12:39:31 +00:00
}
} ;
2015-07-20 09:21:24 +02:00
SbUserFormModule : : SbUserFormModule ( const OUString & rName , const css : : script : : ModuleInfo & mInfo , bool bIsCompat )
2010-06-15 20:02:53 +02:00
: SbObjModule ( rName , mInfo , bIsCompat )
, m_mInfo ( mInfo )
, mbInit ( false )
2010-03-02 12:39:31 +00:00
{
2010-06-15 20:02:53 +02:00
m_xModel . set ( mInfo . ModuleObject , uno : : UNO_QUERY_THROW ) ;
2010-03-02 12:39:31 +00:00
}
2010-07-06 18:07:29 +02:00
SbUserFormModule : : ~ SbUserFormModule ( )
{
}
2010-09-20 09:48:40 +02:00
void SbUserFormModule : : ResetApiObj ( bool bTriggerTerminateEvent )
2010-03-02 12:39:31 +00:00
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " SbUserFormModule::ResetApiObj( " < < ( bTriggerTerminateEvent ? " true ) " : " false ) " ) ) ;
2010-09-20 09:48:40 +02:00
if ( bTriggerTerminateEvent & & m_xDialog . is ( ) ) // probably someone close the dialog window
2010-03-02 12:39:31 +00:00
{
2010-06-15 20:02:53 +02:00
triggerTerminateEvent ( ) ;
}
2015-11-10 10:10:36 +01:00
pDocObject = nullptr ;
m_xDialog = nullptr ;
2010-03-02 12:39:31 +00:00
}
2012-11-06 23:34:23 -06:00
void SbUserFormModule : : triggerMethod ( const OUString & aMethodToRun )
2010-03-02 12:39:31 +00:00
{
Sequence < Any > aArguments ;
triggerMethod ( aMethodToRun , aArguments ) ;
}
2011-03-25 10:40:25 +01:00
2012-11-06 23:34:23 -06:00
void SbUserFormModule : : triggerMethod ( const OUString & aMethodToRun , Sequence < Any > & aArguments )
2010-03-02 12:39:31 +00:00
{
2017-09-19 13:58:34 +03:00
SAL_INFO ( " basic " , " trigger " < < aMethodToRun ) ;
2010-03-02 12:39:31 +00:00
// Search method
2016-05-21 16:22:07 +02:00
SbxVariable * pMeth = SbObjModule : : Find ( aMethodToRun , SbxClassType : : Method ) ;
2010-03-02 12:39:31 +00:00
if ( pMeth )
{
2019-05-04 23:42:17 +03:00
if ( aArguments . hasElements ( ) ) // Setup parameters
2010-03-02 12:39:31 +00:00
{
2016-02-21 17:51:28 +01:00
auto xArray = tools : : make_ref < SbxArray > ( ) ;
2019-12-09 13:06:03 +03:00
xArray - > Put32 ( pMeth , 0 ) ; // Method as parameter 0
2010-03-02 12:39:31 +00:00
for ( sal_Int32 i = 0 ; i < aArguments . getLength ( ) ; + + i )
{
2016-02-21 17:51:28 +01:00
auto xSbxVar = tools : : make_ref < SbxVariable > ( SbxVARIANT ) ;
2016-10-05 22:00:51 +02:00
unoToSbxValue ( xSbxVar . get ( ) , aArguments [ i ] ) ;
2019-12-09 13:06:03 +03:00
xArray - > Put32 ( xSbxVar . get ( ) , static_cast < sal_uInt32 > ( i ) + 1 ) ;
2010-03-02 12:39:31 +00:00
// Enable passing by ref
if ( xSbxVar - > GetType ( ) ! = SbxVARIANT )
2015-07-27 11:31:24 +02:00
xSbxVar - > SetFlag ( SbxFlagBits : : Fixed ) ;
2010-03-02 12:39:31 +00:00
}
2016-10-05 22:00:51 +02:00
pMeth - > SetParameters ( xArray . get ( ) ) ;
2010-03-02 12:39:31 +00:00
SbxValues aVals ;
pMeth - > Get ( aVals ) ;
for ( sal_Int32 i = 0 ; i < aArguments . getLength ( ) ; + + i )
{
2019-12-09 13:06:03 +03:00
aArguments [ i ] = sbxToUnoValue ( xArray - > Get32 ( static_cast < sal_uInt32 > ( i ) + 1 ) ) ;
2010-03-02 12:39:31 +00:00
}
2015-11-10 10:10:36 +01:00
pMeth - > SetParameters ( nullptr ) ;
2010-03-02 12:39:31 +00:00
}
else
{
SbxValues aVals ;
pMeth - > Get ( aVals ) ;
}
}
}
2015-04-14 12:44:47 +02:00
void SbUserFormModule : : triggerActivateEvent ( )
2010-03-02 12:39:31 +00:00
{
2013-01-09 00:14:10 +02:00
triggerMethod ( " UserForm_Activate " ) ;
2010-03-02 12:39:31 +00:00
}
2015-04-14 12:44:47 +02:00
void SbUserFormModule : : triggerDeactivateEvent ( )
2010-03-02 12:39:31 +00:00
{
2013-01-09 00:14:10 +02:00
triggerMethod ( " Userform_Deactivate " ) ;
2010-03-02 12:39:31 +00:00
}
2015-04-14 12:44:47 +02:00
void SbUserFormModule : : triggerInitializeEvent ( )
2010-03-02 12:39:31 +00:00
{
if ( mbInit )
return ;
2015-11-06 09:34:39 +01:00
triggerMethod ( " Userform_Initialize " ) ;
2010-03-02 12:39:31 +00:00
mbInit = true ;
}
2015-04-14 12:44:47 +02:00
void SbUserFormModule : : triggerTerminateEvent ( )
2010-03-02 12:39:31 +00:00
{
2015-11-06 09:34:39 +01:00
triggerMethod ( " Userform_Terminate " ) ;
2010-03-02 12:39:31 +00:00
mbInit = false ;
}
2015-04-14 12:44:47 +02:00
void SbUserFormModule : : triggerLayoutEvent ( )
2010-07-06 18:07:29 +02:00
{
2015-11-06 09:34:39 +01:00
triggerMethod ( " Userform_Layout " ) ;
2010-07-06 18:07:29 +02:00
}
2015-04-14 12:44:47 +02:00
void SbUserFormModule : : triggerResizeEvent ( )
2010-07-06 18:07:29 +02:00
{
2015-11-06 09:34:39 +01:00
triggerMethod ( " Userform_Resize " ) ;
2010-07-06 18:07:29 +02:00
}
2010-06-15 20:02:53 +02:00
SbUserFormModuleInstance * SbUserFormModule : : CreateInstance ( )
{
SbUserFormModuleInstance * pInstance = new SbUserFormModuleInstance ( this , GetName ( ) , m_mInfo , IsVBACompat ( ) ) ;
return pInstance ;
}
SbUserFormModuleInstance : : SbUserFormModuleInstance ( SbUserFormModule * pParentModule ,
2015-07-20 09:21:24 +02:00
const OUString & rName , const css : : script : : ModuleInfo & mInfo , bool bIsVBACompat )
2010-06-15 20:02:53 +02:00
: SbUserFormModule ( rName , mInfo , bIsVBACompat )
, m_pParentModule ( pParentModule )
{
}
2014-04-04 09:57:50 +02:00
bool SbUserFormModuleInstance : : IsClass ( const OUString & rName ) const
2010-06-15 20:02:53 +02:00
{
2014-04-04 09:57:50 +02:00
bool bParentNameMatches = m_pParentModule - > GetName ( ) . equalsIgnoreAsciiCase ( rName ) ;
bool bRet = bParentNameMatches | | SbxObject : : IsClass ( rName ) ;
2010-06-15 20:02:53 +02:00
return bRet ;
}
2012-11-06 23:34:23 -06:00
SbxVariable * SbUserFormModuleInstance : : Find ( const OUString & rName , SbxClassType t )
2010-06-15 20:02:53 +02:00
{
SbxVariable * pVar = m_pParentModule - > Find ( rName , t ) ;
return pVar ;
}
2010-07-06 18:07:29 +02:00
void SbUserFormModule : : Load ( )
2010-03-02 12:39:31 +00:00
{
// forces a load
2017-01-25 12:03:58 +02:00
if ( ! pDocObject . is ( ) )
2010-03-02 12:39:31 +00:00
InitObject ( ) ;
}
2010-10-19 23:45:24 -05:00
2010-03-02 12:39:31 +00:00
void SbUserFormModule : : Unload ( )
{
sal_Int8 nCancel = 0 ;
Sequence < Any > aParams ;
aParams . realloc ( 2 ) ;
aParams [ 0 ] < < = nCancel ;
2017-06-19 16:02:12 +02:00
aParams [ 1 ] < < = sal_Int8 ( : : ooo : : vba : : VbQueryClose : : vbFormCode ) ;
2010-03-02 12:39:31 +00:00
2013-01-09 00:14:10 +02:00
triggerMethod ( " Userform_QueryClose " , aParams ) ;
2010-03-02 12:39:31 +00:00
aParams [ 0 ] > > = nCancel ;
2010-10-06 10:16:27 +01:00
// basic boolean ( and what the user might use ) can be ambiguous ( e.g. basic true = -1 )
2014-02-06 23:21:40 +01:00
// test against 0 ( false ) and assume anything else is true
2010-10-06 10:16:27 +01:00
// ( Note: ) this used to work ( something changes somewhere )
if ( nCancel ! = 0 )
2010-03-02 12:39:31 +00:00
{
return ;
}
if ( m_xDialog . is ( ) )
{
triggerTerminateEvent ( ) ;
}
// Search method
2016-05-21 16:22:07 +02:00
SbxVariable * pMeth = SbObjModule : : Find ( " UnloadObject " , SbxClassType : : Method ) ;
2010-03-02 12:39:31 +00:00
if ( pMeth )
{
2019-02-06 20:14:05 +00:00
SAL_INFO ( " basic " , " Attempting to run the UnloadObjectMethod " ) ;
2010-07-06 18:07:29 +02:00
m_xDialog . clear ( ) ; //release ref to the uno object
2010-03-02 12:39:31 +00:00
SbxValues aVals ;
bool bWaitForDispose = true ; // assume dialog is showing
2018-10-16 15:23:12 +02:00
if ( m_DialogListener )
2010-03-02 12:39:31 +00:00
{
2010-07-06 18:07:29 +02:00
bWaitForDispose = m_DialogListener - > isShowing ( ) ;
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " Showing " < < bWaitForDispose ) ;
2010-03-02 12:39:31 +00:00
}
pMeth - > Get ( aVals ) ;
2010-07-06 18:07:29 +02:00
if ( ! bWaitForDispose )
{
2018-11-30 19:58:46 +01:00
// we've either already got a dispose or we are never going to get one
2010-03-02 12:39:31 +00:00
ResetApiObj ( ) ;
2010-07-06 18:07:29 +02:00
} // else wait for dispose
2019-02-06 20:14:05 +00:00
SAL_INFO ( " basic " , " UnloadObject completed (we hope) " ) ;
2010-03-02 12:39:31 +00:00
}
}
2010-10-19 23:45:24 -05:00
2010-03-02 12:39:31 +00:00
void SbUserFormModule : : InitObject ( )
{
try
{
2017-06-19 16:02:12 +02:00
SbUnoObject * pGlobs = static_cast < SbUnoObject * > ( GetParent ( ) - > Find ( " VBAGlobals " , SbxClassType : : DontCare ) ) ;
2010-03-02 12:39:31 +00:00
if ( m_xModel . is ( ) & & pGlobs )
{
2011-03-25 10:40:25 +01:00
// broadcast INITIALIZE_USERFORM script event before the dialog is created
Reference < script : : vba : : XVBACompatibility > xVBACompat ( getVBACompatibility ( m_xModel ) , uno : : UNO_SET_THROW ) ;
xVBACompat - > broadcastVBAScriptEvent ( script : : vba : : VBAScriptEventId : : INITIALIZE_USERFORM , GetName ( ) ) ;
2010-03-02 12:39:31 +00:00
uno : : Reference < lang : : XMultiServiceFactory > xVBAFactory ( pGlobs - > getUnoAny ( ) , uno : : UNO_QUERY_THROW ) ;
2013-01-18 09:18:17 +02:00
uno : : Reference < uno : : XComponentContext > xContext = comphelper : : getProcessComponentContext ( ) ;
2012-11-06 23:34:23 -06:00
OUString sDialogUrl ( " vnd.sun.star.script: " ) ;
OUString sProjectName ( " Standard " ) ;
2010-11-02 16:22:07 +00:00
try
{
Reference < beans : : XPropertySet > xProps ( m_xModel , UNO_QUERY_THROW ) ;
2013-01-09 00:14:10 +02:00
uno : : Reference < script : : vba : : XVBACompatibility > xVBAMode ( xProps - > getPropertyValue ( " BasicLibraries " ) , uno : : UNO_QUERY_THROW ) ;
2010-11-02 16:22:07 +00:00
sProjectName = xVBAMode - > getProjectName ( ) ;
}
2011-08-24 11:22:56 +09:00
catch ( const Exception & ) { }
2010-11-02 16:22:07 +00:00
2019-10-10 16:23:37 +02:00
sDialogUrl + = sProjectName + " . " + GetName ( ) + " ?location=document " ;
2010-03-02 12:39:31 +00:00
2013-01-18 09:18:17 +02:00
uno : : Reference < awt : : XDialogProvider > xProvider = awt : : DialogProvider : : createWithModel ( xContext , m_xModel ) ;
2010-03-02 12:39:31 +00:00
m_xDialog = xProvider - > createDialog ( sDialogUrl ) ;
// create vba api object
2013-01-18 09:18:17 +02:00
uno : : Sequence < uno : : Any > aArgs ( 4 ) ;
2010-03-02 12:39:31 +00:00
aArgs [ 0 ] = uno : : Any ( ) ;
aArgs [ 1 ] < < = m_xDialog ;
aArgs [ 2 ] < < = m_xModel ;
2017-05-19 17:19:14 +02:00
aArgs [ 3 ] < < = GetParent ( ) - > GetName ( ) ;
2017-02-03 08:54:47 +02:00
pDocObject = new SbUnoObject ( GetName ( ) , uno : : Any ( xVBAFactory - > createInstanceWithArguments ( " ooo.vba.msforms.UserForm " , aArgs ) ) ) ;
2011-02-11 15:06:12 +01:00
uno : : Reference < lang : : XComponent > xComponent ( m_xDialog , uno : : UNO_QUERY_THROW ) ;
2010-08-30 13:55:39 +02:00
// the dialog must be disposed at the end!
2015-11-10 10:10:36 +01:00
StarBASIC * pParentBasic = nullptr ;
2011-02-11 15:06:12 +01:00
SbxObject * pCurObject = this ;
do
2010-08-30 13:55:39 +02:00
{
2011-02-11 15:06:12 +01:00
SbxObject * pObjParent = pCurObject - > GetParent ( ) ;
2015-09-28 11:42:43 +02:00
pParentBasic = dynamic_cast < StarBASIC * > ( pObjParent ) ;
2011-02-11 15:06:12 +01:00
pCurObject = pObjParent ;
2010-08-30 13:55:39 +02:00
}
2015-11-10 10:10:36 +01:00
while ( pParentBasic = = nullptr & & pCurObject ! = nullptr ) ;
2010-08-30 13:55:39 +02:00
2015-11-10 10:10:36 +01:00
SAL_WARN_IF ( pParentBasic = = nullptr , " basic " , " pParentBasic == NULL " ) ;
2011-02-11 15:06:12 +01:00
registerComponentToBeDisposedForBasic ( xComponent , pParentBasic ) ;
2010-08-30 13:55:39 +02:00
2011-02-11 15:06:12 +01:00
// if old listener object exists, remove it from dialog and document model
if ( m_DialogListener . is ( ) )
2010-07-06 18:07:29 +02:00
m_DialogListener - > removeListener ( ) ;
2011-02-11 15:06:12 +01:00
m_DialogListener . set ( new FormObjEventListenerImpl ( this , xComponent , m_xModel ) ) ;
2010-03-02 12:39:31 +00:00
triggerInitializeEvent ( ) ;
}
}
2011-08-24 11:22:56 +09:00
catch ( const uno : : Exception & )
2010-03-02 12:39:31 +00:00
{
}
}
SbxVariable *
2013-01-09 00:14:10 +02:00
SbUserFormModule : : Find ( const OUString & rName , SbxClassType t )
2010-03-02 12:39:31 +00:00
{
2017-01-25 12:03:58 +02:00
if ( ! pDocObject . is ( ) & & ! GetSbData ( ) - > bRunInit & & GetSbData ( ) - > pInst )
2010-03-02 12:39:31 +00:00
InitObject ( ) ;
return SbObjModule : : Find ( rName , t ) ;
}
2000-09-18 15:18:56 +00:00
2012-11-06 23:34:23 -06:00
SbProperty : : SbProperty ( const OUString & r , SbxDataType t , SbModule * p )
2000-09-18 15:18:56 +00:00
: SbxProperty ( r , t ) , pMod ( p )
{
}
SbProperty : : ~ SbProperty ( )
{ }
2004-11-02 10:52:32 +00:00
SbProcedureProperty : : ~ SbProcedureProperty ( )
{ }
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */