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 <list>
# include <vcl/svapp.hxx>
# include <tools/stream.hxx>
2009-10-16 00:05:16 +02:00
# include <svl/brdcst.hxx>
2000-09-18 15:18:56 +00:00
# include <tools/shl.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>
2011-02-08 12:44:14 +01:00
# include "sbdiagnose.hxx"
2000-09-18 15:18:56 +00:00
# include "sb.hxx"
# include <sbjsmeth.hxx>
# include "sbjsmod.hxx"
# include "sbintern.hxx"
# 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
2007-06-27 13:19:36 +00:00
# include <basic/basrdll.hxx>
2010-10-16 03:18:35 -05:00
# include <osl/mutex.hxx>
2013-12-11 10:39:57 +02:00
# include "sbobjmod.hxx"
2011-02-21 12:34:10 +01:00
# include <basic/vbahelper.hxx>
2011-02-11 15:06:12 +01:00
# include <cppuhelper/implbase3.hxx>
# include <unotools/eventcfg.hxx>
2012-12-14 12:58:00 +02:00
# include <com/sun/star/frame/Desktop.hpp>
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>
2011-02-11 15:06:12 +01:00
# include <com/sun/star/document/XEventBroadcaster.hpp>
# include <com/sun/star/document/XEventListener.hpp>
2000-09-18 15:18:56 +00:00
2010-04-26 13:09:41 +01:00
using namespace com : : sun : : star ;
2008-11-28 11:39:37 +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
# include <stdio.h>
2009-09-18 15:24:22 +00:00
# include <com/sun/star/frame/XDesktop.hpp>
# include <com/sun/star/lang/XMultiServiceFactory.hpp>
# include <comphelper/processfactory.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 <cppuhelper/implbase1.hxx>
# include <com/sun/star/uno/XAggregation.hpp>
# include <com/sun/star/script/XInvocation.hpp>
2011-04-28 00:12:58 +02:00
using namespace : : com : : sun : : star ;
2010-07-01 16:23:26 +02:00
using namespace com : : sun : : star : : lang ;
using namespace com : : sun : : star : : reflection ;
using namespace com : : sun : : star : : beans ;
using namespace com : : sun : : star : : script ;
2013-04-26 17:14:48 +02:00
using namespace com : : sun : : star : : uno ;
2000-09-18 15:18:56 +00:00
2010-03-02 12:39:31 +00:00
# include <com/sun/star/script/XLibraryContainer.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>
2010-03-02 12:39:31 +00:00
# include <com/sun/star/awt/XControl.hpp>
# include <comphelper/anytostring.hxx>
2011-03-25 10:40:25 +01:00
# include <ooo/vba/VbQueryClose.hpp>
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
# include "sbcomp.hxx"
2010-07-01 16:23:26 +02:00
typedef : : cppu : : WeakImplHelper1 < XInvocation > DocObjectWrapper_BASE ;
typedef : : std : : map < sal_Int16 , Any , : : std : : less < sal_Int16 > > OutParamMap ;
class DocObjectWrapper : public DocObjectWrapper_BASE
{
Reference < XAggregation > m_xAggProxy ;
Reference < XInvocation > m_xAggInv ;
Reference < XTypeProvider > m_xAggregateTypeProv ;
Sequence < Type > m_Types ;
SbModule * m_pMod ;
2012-11-06 23:34:23 -06:00
SbMethodRef getMethod ( const OUString & aName ) throw ( RuntimeException ) ;
SbPropertyRef getProperty ( const OUString & aName ) throw ( RuntimeException ) ;
OUString mName ; // for debugging
2010-07-01 16:23:26 +02:00
public :
DocObjectWrapper ( SbModule * pMod ) ;
2010-07-26 19:13:47 +02:00
virtual ~ DocObjectWrapper ( ) ;
2010-07-01 16:23:26 +02:00
virtual void SAL_CALL acquire ( ) throw ( ) ;
virtual void SAL_CALL release ( ) throw ( ) ;
2010-07-26 19:13:47 +02:00
virtual Sequence < sal_Int8 > SAL_CALL getImplementationId ( ) throw ( RuntimeException )
2010-07-01 16:23:26 +02:00
{
2010-07-26 19:13:47 +02:00
if ( ! m_xAggregateTypeProv . is ( ) )
throw RuntimeException ( ) ;
2010-07-01 16:23:26 +02:00
return m_xAggregateTypeProv - > getImplementationId ( ) ;
}
virtual Reference < XIntrospectionAccess > SAL_CALL getIntrospection ( ) throw ( RuntimeException ) ;
2012-11-06 23:34:23 -06:00
virtual Any SAL_CALL invoke ( const OUString & aFunctionName , const Sequence < Any > & aParams , Sequence < : : sal_Int16 > & aOutParamIndex , Sequence < Any > & aOutParam ) throw ( IllegalArgumentException , CannotConvertException , InvocationTargetException , RuntimeException ) ;
virtual void SAL_CALL setValue ( const OUString & aPropertyName , const Any & aValue ) throw ( UnknownPropertyException , CannotConvertException , InvocationTargetException , RuntimeException ) ;
virtual Any SAL_CALL getValue ( const OUString & aPropertyName ) throw ( UnknownPropertyException , RuntimeException ) ;
virtual : : sal_Bool SAL_CALL hasMethod ( const OUString & aName ) throw ( RuntimeException ) ;
virtual : : sal_Bool SAL_CALL hasProperty ( const OUString & aName ) throw ( RuntimeException ) ;
2010-07-01 16:23:26 +02:00
virtual Any SAL_CALL queryInterface ( const Type & aType ) throw ( RuntimeException ) ;
virtual Sequence < Type > SAL_CALL getTypes ( ) throw ( RuntimeException ) ;
} ;
DocObjectWrapper : : DocObjectWrapper ( SbModule * pVar ) : m_pMod ( pVar ) , mName ( pVar - > GetName ( ) )
{
SbObjModule * pMod = PTR_CAST ( SbObjModule , pVar ) ;
if ( pMod )
{
if ( pMod - > GetModuleType ( ) = = ModuleType : : DOCUMENT )
{
// Use proxy factory service to create aggregatable proxy.
SbUnoObject * pUnoObj = PTR_CAST ( SbUnoObject , pMod - > GetObject ( ) ) ;
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
{
2013-01-09 00:14:10 +02:00
SAL_WARN ( " basic " , " DocObjectWrapper::DocObjectWrapper: Caught exception! " ) ;
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 ) ) ;
}
2012-09-22 01:51:12 -05:00
osl_atomic_decrement ( & m_refCount ) ;
2010-07-01 16:23:26 +02:00
}
}
}
}
void SAL_CALL
DocObjectWrapper : : acquire ( ) throw ( )
{
2012-09-22 01:51:12 -05:00
osl_atomic_increment ( & m_refCount ) ;
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " DocObjectWrapper::acquire( " < < OUStringToOString ( mName , RTL_TEXTENCODING_UTF8 ) . getStr ( ) < < " ) 0x " < < this < < " refcount is now " < < m_refCount ) ;
2010-07-01 16:23:26 +02:00
}
void SAL_CALL
DocObjectWrapper : : release ( ) throw ( )
{
2012-09-22 01:51:12 -05:00
if ( osl_atomic_decrement ( & m_refCount ) = = 0 )
2010-07-01 16:23:26 +02:00
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " DocObjectWrapper::release( " < < OUStringToOString ( mName , RTL_TEXTENCODING_UTF8 ) . getStr ( ) < < " ) 0x " < < this < < " refcount is now " < < m_refCount ) ;
2010-07-01 16:23:26 +02:00
delete this ;
}
else
2012-11-03 09:07:25 -05:00
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " DocObjectWrapper::release( " < < OUStringToOString ( mName , RTL_TEXTENCODING_UTF8 ) . getStr ( ) < < " ) 0x " < < this < < " refcount is now " < < m_refCount ) ;
2012-11-03 09:07:25 -05:00
}
2010-07-01 16:23:26 +02:00
}
DocObjectWrapper : : ~ DocObjectWrapper ( )
{
}
Sequence < Type > SAL_CALL DocObjectWrapper : : getTypes ( )
throw ( RuntimeException )
{
if ( m_Types . getLength ( ) = = 0 )
{
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
}
2010-07-01 16:23:26 +02:00
m_Types . realloc ( sTypes . getLength ( ) + 1 ) ;
Type * pPtr = m_Types . getArray ( ) ;
for ( int i = 0 ; i < m_Types . getLength ( ) ; + + i , + + pPtr )
{
if ( i = = 0 )
2012-11-03 09:07:25 -05:00
{
2013-12-12 11:09:57 +01:00
* pPtr = cppu : : UnoType < XInvocation > : : get ( ) ;
2012-11-03 09:07:25 -05:00
}
2010-07-01 16:23:26 +02:00
else
2012-11-03 09:07:25 -05:00
{
2010-07-01 16:23:26 +02:00
* pPtr = sTypes [ i - 1 ] ;
2012-11-03 09:07:25 -05:00
}
2010-07-01 16:23:26 +02:00
}
}
return m_Types ;
}
Reference < XIntrospectionAccess > SAL_CALL
DocObjectWrapper : : getIntrospection ( ) throw ( RuntimeException )
{
return NULL ;
}
Any SAL_CALL
2012-11-06 23:34:23 -06:00
DocObjectWrapper : : invoke ( const OUString & aFunctionName , const Sequence < Any > & aParams , Sequence < : : sal_Int16 > & aOutParamIndex , Sequence < Any > & aOutParam ) throw ( IllegalArgumentException , CannotConvertException , InvocationTargetException , RuntimeException )
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 ) ;
if ( ! pMethod )
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 ) )
{
if ( ( pParamInfo - > nFlags & SBX_OPTIONAL ) ! = 0 )
+ + nSbxOptional ;
else
nSbxOptional = 0 ;
}
sal_Int32 nSbxCount = n - 1 ;
if ( nParamsCount < nSbxCount - nSbxOptional )
{
2013-01-09 00:14:10 +02:00
throw RuntimeException ( " wrong number of parameters! " , Reference < XInterface > ( ) ) ;
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 ) ;
unoToSbxValue ( static_cast < SbxVariable * > ( xSbxVar ) , pParams [ i ] ) ;
2011-01-10 14:40:57 +01:00
xSbxParams - > Put ( xSbxVar , static_cast < sal_uInt16 > ( i ) + 1 ) ;
2010-07-01 16:23:26 +02:00
// Enable passing by ref
if ( xSbxVar - > GetType ( ) ! = SbxVARIANT )
xSbxVar - > SetFlag ( SBX_FIXED ) ;
}
}
if ( xSbxParams . Is ( ) )
pMethod - > SetParameters ( xSbxParams ) ;
// call method
SbxVariableRef xReturn = new SbxVariable ;
2011-01-24 14:50:41 +00:00
pMethod - > Call ( xReturn ) ;
2010-07-01 16:23:26 +02:00
Any aReturn ;
// get output parameters
if ( xSbxParams . Is ( ) )
{
SbxInfo * pInfo_ = pMethod - > GetInfo ( ) ;
if ( pInfo_ )
{
OutParamMap aOutParamMap ;
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 n = 1 , nCount = xSbxParams - > Count ( ) ; n < nCount ; + + n )
2010-07-01 16:23:26 +02:00
{
const SbxParamInfo * pParamInfo = pInfo_ - > GetParam ( n ) ;
if ( pParamInfo & & ( pParamInfo - > eType & SbxBYREF ) ! = 0 )
{
SbxVariable * pVar = xSbxParams - > Get ( n ) ;
if ( pVar )
{
SbxVariableRef xVar = pVar ;
aOutParamMap . insert ( OutParamMap : : value_type ( n - 1 , sbxToUnoValue ( xVar ) ) ) ;
}
}
}
sal_Int32 nOutParamCount = aOutParamMap . size ( ) ;
aOutParamIndex . realloc ( nOutParamCount ) ;
aOutParam . realloc ( nOutParamCount ) ;
sal_Int16 * pOutParamIndex = aOutParamIndex . getArray ( ) ;
Any * pOutParam = aOutParam . getArray ( ) ;
for ( OutParamMap : : iterator aIt = aOutParamMap . begin ( ) ; aIt ! = aOutParamMap . end ( ) ; + + aIt , + + pOutParamIndex , + + pOutParam )
{
* pOutParamIndex = aIt - > first ;
* pOutParam = aIt - > second ;
}
}
}
// get return value
aReturn = sbxToUnoValue ( xReturn ) ;
pMethod - > SetParameters ( NULL ) ;
return aReturn ;
}
void SAL_CALL
2012-11-06 23:34:23 -06:00
DocObjectWrapper : : setValue ( const OUString & aPropertyName , const Any & aValue ) throw ( UnknownPropertyException , CannotConvertException , InvocationTargetException , RuntimeException )
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 ) ;
if ( ! pProperty . Is ( ) )
throw UnknownPropertyException ( ) ;
unoToSbxValue ( ( SbxVariable * ) pProperty , aValue ) ;
}
Any SAL_CALL
2012-11-06 23:34:23 -06:00
DocObjectWrapper : : getValue ( const OUString & aPropertyName ) throw ( UnknownPropertyException , RuntimeException )
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 ) ;
if ( ! pProperty . Is ( ) )
throw UnknownPropertyException ( ) ;
SbxVariable * pProp = ( SbxVariable * ) pProperty ;
if ( pProp - > GetType ( ) = = SbxEMPTY )
pProperty - > Broadcast ( SBX_HINT_DATAWANTED ) ;
Any aRet = sbxToUnoValue ( pProp ) ;
return aRet ;
}
: : sal_Bool SAL_CALL
2012-11-06 23:34:23 -06:00
DocObjectWrapper : : hasMethod ( const OUString & aName ) throw ( RuntimeException )
2010-07-01 16:23:26 +02:00
{
if ( m_xAggInv . is ( ) & & m_xAggInv - > hasMethod ( aName ) )
return sal_True ;
return getMethod ( aName ) . Is ( ) ;
}
: : sal_Bool SAL_CALL
2012-11-06 23:34:23 -06:00
DocObjectWrapper : : hasProperty ( const OUString & aName ) throw ( RuntimeException )
2010-07-01 16:23:26 +02:00
{
sal_Bool bRes = sal_False ;
if ( m_xAggInv . is ( ) & & m_xAggInv - > hasProperty ( aName ) )
bRes = sal_True ;
else bRes = getProperty ( aName ) . Is ( ) ;
return bRes ;
}
Any SAL_CALL DocObjectWrapper : : queryInterface ( const Type & aType )
throw ( RuntimeException )
{
Any aRet = DocObjectWrapper_BASE : : queryInterface ( aType ) ;
if ( aRet . hasValue ( ) )
return aRet ;
else if ( m_xAggProxy . is ( ) )
aRet = m_xAggProxy - > queryAggregation ( aType ) ;
return aRet ;
}
2012-11-06 23:34:23 -06:00
SbMethodRef DocObjectWrapper : : getMethod ( const OUString & aName ) throw ( RuntimeException )
2010-07-01 16:23:26 +02:00
{
SbMethodRef pMethod = NULL ;
if ( m_pMod )
{
2011-01-10 14:40:57 +01:00
sal_uInt16 nSaveFlgs = m_pMod - > GetFlags ( ) ;
2010-07-01 16:23:26 +02:00
// Limit search to this module
m_pMod - > ResetFlag ( SBX_GBLSEARCH ) ;
pMethod = ( SbMethod * ) m_pMod - > SbModule : : Find ( aName , SbxCLASS_METHOD ) ;
m_pMod - > SetFlags ( nSaveFlgs ) ;
}
return pMethod ;
}
2012-11-06 23:34:23 -06:00
SbPropertyRef DocObjectWrapper : : getProperty ( const OUString & aName ) throw ( RuntimeException )
2010-07-01 16:23:26 +02:00
{
SbPropertyRef pProperty = NULL ;
if ( m_pMod )
{
2011-01-10 14:40:57 +01:00
sal_uInt16 nSaveFlgs = m_pMod - > GetFlags ( ) ;
2010-07-01 16:23:26 +02:00
// Limit search to this module.
m_pMod - > ResetFlag ( SBX_GBLSEARCH ) ;
pProperty = ( SbProperty * ) m_pMod - > SbModule : : Find ( aName , SbxCLASS_PROPERTY ) ;
m_pMod - > SetFlag ( nSaveFlgs ) ;
}
return pProperty ;
}
2000-09-18 15:18:56 +00:00
TYPEINIT1 ( SbModule , SbxObject )
TYPEINIT1 ( SbMethod , SbxMethod )
TYPEINIT1 ( SbProperty , SbxProperty )
2005-03-29 10:48:33 +00:00
TYPEINIT1 ( SbProcedureProperty , SbxProperty )
2000-09-18 15:18:56 +00:00
TYPEINIT1 ( SbJScriptModule , SbModule )
TYPEINIT1 ( SbJScriptMethod , SbMethod )
2010-03-02 12:39:31 +00:00
TYPEINIT1 ( SbObjModule , SbModule )
TYPEINIT1 ( SbUserFormModule , SbObjModule )
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 ;
}
uno : : Reference < vba : : XVBACompatibility > getVBACompatibility ( const uno : : Reference < frame : : XModel > & rxModel )
{
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 ;
}
bool getDefaultVBAMode ( StarBASIC * pb )
{
uno : : Reference < vba : : XVBACompatibility > xVBACompat = getVBACompatibility ( getDocumentModel ( pb ) ) ;
return xVBACompat . is ( ) & & xVBACompat - > getVBACompatibilityMode ( ) ;
2010-04-26 13:09:41 +01:00
}
2009-09-18 15:24:22 +00:00
class AsyncQuitHandler
{
AsyncQuitHandler ( ) { }
AsyncQuitHandler ( const AsyncQuitHandler & ) ;
public :
static AsyncQuitHandler & instance ( )
{
static AsyncQuitHandler dInst ;
return dInst ;
}
void QuitApplication ( )
{
2012-12-14 12:58:00 +02:00
uno : : Reference < frame : : XDesktop2 > xDeskTop = frame : : Desktop : : create ( comphelper : : getProcessComponentContext ( ) ) ;
xDeskTop - > terminate ( ) ;
2009-09-18 15:24:22 +00:00
}
DECL_LINK ( OnAsyncQuit , void * ) ;
} ;
2009-09-23 14:06:30 +00:00
IMPL_LINK ( AsyncQuitHandler , OnAsyncQuit , void * , /*pNull*/ )
2009-09-18 15:24:22 +00:00
{
QuitApplication ( ) ;
return 0L ;
}
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// A Basic module has set EXTSEARCH, so that the elements, that the modul contains,
// could be found from other module.
2000-09-18 15:18:56 +00:00
2012-11-06 23:34:23 -06:00
SbModule : : SbModule ( const OUString & rName , sal_Bool bVBACompat )
2013-01-09 00:14:10 +02:00
: SbxObject ( " StarBASICModule " ) ,
2010-03-02 12:39:31 +00:00
pImage ( NULL ) , pBreaks ( NULL ) , pClassData ( NULL ) , mbVBACompat ( bVBACompat ) , pDocObject ( NULL ) , bIsProxyModule ( false )
2000-09-18 15:18:56 +00:00
{
SetName ( rName ) ;
SetFlag ( SBX_EXTSEARCH | SBX_GBLSEARCH ) ;
2010-04-16 17:28:52 +02:00
SetModuleType ( script : : ModuleType : : NORMAL ) ;
2010-06-15 20:02:53 +02:00
// #i92642: Set name property to intitial name
2013-01-09 00:14:10 +02:00
SbxVariable * pNameProp = pProps - > Find ( " Name " , SbxCLASS_PROPERTY ) ;
2010-06-15 20:02:53 +02:00
if ( pNameProp ! = NULL )
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 ( )
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " Module named " < < OUStringToOString ( GetName ( ) , RTL_TEXTENCODING_UTF8 ) . getStr ( ) < < " is destructing " ) ;
2012-01-26 01:02:30 +09:00
delete pImage ;
delete pBreaks ;
delete pClassData ;
mxWrapper = NULL ;
2010-07-01 16:23:26 +02:00
}
uno : : Reference < script : : XInvocation >
SbModule : : GetUnoModule ( )
{
if ( ! mxWrapper . is ( ) )
mxWrapper = new DocObjectWrapper ( this ) ;
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " Module named " < < OUStringToOString ( GetName ( ) , RTL_TEXTENCODING_UTF8 ) . getStr ( ) < < " returning wrapper mxWrapper (0x " < < mxWrapper . get ( ) < < " ) " ) ;
2010-07-01 16:23:26 +02:00
return mxWrapper ;
2000-09-18 15:18:56 +00:00
}
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : IsCompiled ( ) const
2000-09-18 15:18:56 +00:00
{
2011-01-10 14:40:57 +01:00
return sal_Bool ( pImage ! = 0 ) ;
2000-09-18 15:18:56 +00:00
}
2012-11-06 23:34:23 -06:00
const SbxObject * SbModule : : FindType ( OUString aTypeName ) const
2004-03-17 12:32:25 +00:00
{
return pImage ? pImage - > FindType ( aTypeName ) : NULL ;
}
2010-10-06 22:33:21 +02:00
// From the code generator: deletion of images and the oposite of validation for entries
2000-09-18 15:18:56 +00:00
void SbModule : : StartDefinitions ( )
{
delete pImage ; pImage = NULL ;
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
2011-01-10 14:40:57 +01:00
sal_uInt16 i ;
2000-09-18 15:18:56 +00:00
for ( i = 0 ; i < pMethods - > Count ( ) ; i + + )
{
SbMethod * p = PTR_CAST ( SbMethod , pMethods - > Get ( i ) ) ;
if ( p )
2011-01-10 14:40:57 +01:00
p - > bInvalid = sal_True ;
2000-09-18 15:18:56 +00:00
}
for ( i = 0 ; i < pProps - > Count ( ) ; )
{
SbProperty * p = PTR_CAST ( SbProperty , pProps - > Get ( i ) ) ;
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
{
SbxVariable * p = pMethods - > Find ( rName , SbxCLASS_METHOD ) ;
SbMethod * pMeth = p ? PTR_CAST ( SbMethod , p ) : NULL ;
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 ) ;
pMeth - > SetFlags ( SBX_READ ) ;
pMethods - > Put ( pMeth , pMethods - > Count ( ) ) ;
2011-01-10 14:40:57 +01:00
StartListening ( pMeth - > GetBroadcaster ( ) , sal_True ) ;
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.
2011-01-10 14:40:57 +01:00
pMeth - > bInvalid = sal_False ;
2000-09-18 15:18:56 +00:00
pMeth - > ResetFlag ( SBX_FIXED ) ;
pMeth - > SetFlag ( SBX_WRITE ) ;
pMeth - > SetType ( t ) ;
pMeth - > ResetFlag ( SBX_WRITE ) ;
if ( t ! = SbxVARIANT )
2012-11-03 09:07:25 -05:00
{
2000-09-18 15:18:56 +00:00
pMeth - > SetFlag ( SBX_FIXED ) ;
2012-11-03 09:07:25 -05:00
}
2000-09-18 15:18:56 +00:00
return pMeth ;
}
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
{
SbxVariable * p = pProps - > Find ( rName , SbxCLASS_PROPERTY ) ;
SbProperty * pProp = p ? PTR_CAST ( SbProperty , p ) : NULL ;
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 ) ;
pProp - > SetFlag ( SBX_READWRITE ) ;
pProp - > SetParent ( this ) ;
pProps - > Put ( pProp , pProps - > Count ( ) ) ;
2011-01-10 14:40:57 +01:00
StartListening ( pProp - > GetBroadcaster ( ) , sal_True ) ;
2000-09-18 15:18:56 +00:00
}
return pProp ;
}
2012-11-06 23:34:23 -06:00
SbProcedureProperty * SbModule : : GetProcedureProperty ( const OUString & rName , SbxDataType t )
2004-11-02 10:52:32 +00:00
{
SbxVariable * p = pProps - > Find ( rName , SbxCLASS_PROPERTY ) ;
SbProcedureProperty * pProp = p ? PTR_CAST ( SbProcedureProperty , p ) : NULL ;
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 ) ;
pProp - > SetFlag ( SBX_READWRITE ) ;
pProp - > SetParent ( this ) ;
pProps - > Put ( pProp , pProps - > Count ( ) ) ;
2011-01-10 14:40:57 +01:00
StartListening ( pProp - > GetBroadcaster ( ) , sal_True ) ;
2004-11-02 10:52:32 +00:00
}
return pProp ;
}
2012-11-06 23:34:23 -06:00
SbIfaceMapperMethod * SbModule : : GetIfaceMapperMethod ( const OUString & rName , SbMethod * pImplMeth )
2005-03-29 10:48:33 +00:00
{
SbxVariable * p = pMethods - > Find ( rName , SbxCLASS_METHOD ) ;
SbIfaceMapperMethod * pMapperMethod = p ? PTR_CAST ( SbIfaceMapperMethod , p ) : NULL ;
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 ) ;
pMapperMethod - > SetFlags ( SBX_READ ) ;
pMethods - > Put ( pMapperMethod , pMethods - > Count ( ) ) ;
}
2011-01-10 14:40:57 +01:00
pMapperMethod - > bInvalid = sal_False ;
2005-03-29 10:48:33 +00:00
return pMapperMethod ;
}
SbIfaceMapperMethod : : ~ SbIfaceMapperMethod ( )
{
}
TYPEINIT1 ( SbIfaceMapperMethod , SbMethod )
2004-11-02 10:52:32 +00:00
2010-10-06 22:33:21 +02:00
// From the code generator: remove invalid entries
2000-09-18 15:18:56 +00:00
2011-01-10 14:40:57 +01:00
void SbModule : : EndDefinitions ( sal_Bool bNewState )
2000-09-18 15:18:56 +00:00
{
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 i = 0 ; i < pMethods - > Count ( ) ; )
2000-09-18 15:18:56 +00:00
{
SbMethod * p = PTR_CAST ( SbMethod , pMethods - > Get ( i ) ) ;
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
}
2011-01-10 14:40:57 +01:00
SetModified ( sal_True ) ;
2000-09-18 15:18:56 +00:00
}
void SbModule : : Clear ( )
{
delete pImage ; pImage = NULL ;
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
{
2010-03-02 12:39:31 +00:00
// make sure a search in an uninstatiated 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
{
2010-03-02 12:39:31 +00:00
return NULL ;
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 ( ) ;
if ( xArray . Is ( ) )
{
SbxVariable * pEnumVar = xArray - > Find ( rName , SbxCLASS_DONTCARE ) ;
SbxObject * pEnumObject = PTR_CAST ( SbxObject , pEnumVar ) ;
if ( pEnumObject )
{
bool bPrivate = pEnumObject - > IsSet ( SBX_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 ) ;
pRes - > SetFlag ( SBX_READ ) ;
if ( bPrivate )
2012-11-03 09:07:25 -05:00
{
2004-11-15 15:34:15 +00:00
pRes - > SetFlag ( SBX_PRIVATE ) ;
2012-11-03 09:07:25 -05:00
}
2004-11-15 15:34:15 +00:00
pRes - > PutObject ( pEnumObject ) ;
}
}
}
}
return pRes ;
}
2012-11-06 23:34:23 -06:00
const OUString & SbModule : : GetSource32 ( ) const
2003-04-23 15:56:27 +00:00
{
return aOUSource ;
}
2012-11-06 23:34:23 -06:00
const OUString & SbModule : : GetSource ( ) const
2000-09-18 15:18:56 +00:00
{
2012-11-06 23:34:23 -06:00
static OUString aRetStr ;
2003-04-23 15:56:27 +00:00
aRetStr = aOUSource ;
return aRetStr ;
2000-09-18 15:18:56 +00:00
}
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 ;
}
void SbModule : : SFX_NOTIFY ( SfxBroadcaster & rBC , const TypeId & rBCType ,
const SfxHint & rHint , const TypeId & rHintType )
{
const SbxHint * pHint = PTR_CAST ( SbxHint , & rHint ) ;
if ( pHint )
{
SbxVariable * pVar = pHint - > GetVar ( ) ;
SbProperty * pProp = PTR_CAST ( SbProperty , pVar ) ;
SbMethod * pMeth = PTR_CAST ( SbMethod , pVar ) ;
2010-10-06 10:16:27 +01:00
SbProcedureProperty * pProcProperty = PTR_CAST ( SbProcedureProperty , pVar ) ;
if ( pProcProperty )
{
if ( pHint - > GetId ( ) = = SBX_HINT_DATAWANTED )
{
2012-11-06 23:34:23 -06:00
OUString aProcName ( " Property Get " ) ;
2010-10-06 10:16:27 +01:00
aProcName + = pProcProperty - > GetName ( ) ;
SbxVariable * pMethVar = Find ( aProcName , SbxCLASS_METHOD ) ;
if ( pMethVar )
{
SbxValues aVals ;
aVals . eType = SbxVARIANT ;
SbxArray * pArg = pVar - > GetParameters ( ) ;
2011-03-12 02:42:58 +01:00
sal_uInt16 nVarParCount = ( pArg ! = NULL ) ? pArg - > Count ( ) : 0 ;
2010-10-06 10:16:27 +01:00
if ( nVarParCount > 1 )
{
SbxArrayRef xMethParameters = new SbxArray ;
xMethParameters - > Put ( pMethVar , 0 ) ; // Method as parameter 0
2011-03-12 02:42:58 +01:00
for ( sal_uInt16 i = 1 ; i < nVarParCount ; + + i )
2010-10-06 10:16:27 +01:00
{
SbxVariable * pPar = pArg - > Get ( i ) ;
xMethParameters - > Put ( pPar , i ) ;
}
pMethVar - > SetParameters ( xMethParameters ) ;
pMethVar - > Get ( aVals ) ;
pMethVar - > SetParameters ( NULL ) ;
}
else
{
pMethVar - > Get ( aVals ) ;
}
pVar - > Put ( aVals ) ;
}
}
else if ( pHint - > GetId ( ) = = SBX_HINT_DATACHANGED )
{
SbxVariable * pMethVar = NULL ;
bool bSet = pProcProperty - > isSet ( ) ;
if ( bSet )
{
pProcProperty - > setSet ( false ) ;
2012-11-06 23:34:23 -06:00
OUString aProcName ( " Property Set " ) ;
2010-10-06 10:16:27 +01:00
aProcName + = pProcProperty - > GetName ( ) ;
pMethVar = Find ( aProcName , SbxCLASS_METHOD ) ;
}
if ( ! pMethVar ) // Let
{
2012-11-06 23:34:23 -06:00
OUString aProcName ( " Property Let " ) ;
2010-10-06 10:16:27 +01:00
aProcName + = pProcProperty - > GetName ( ) ;
pMethVar = Find ( aProcName , SbxCLASS_METHOD ) ;
}
if ( pMethVar )
{
// Setup parameters
SbxArrayRef xArray = new SbxArray ;
xArray - > Put ( pMethVar , 0 ) ; // Method as parameter 0
xArray - > Put ( pVar , 1 ) ;
pMethVar - > SetParameters ( xArray ) ;
SbxValues aVals ;
pMethVar - > Get ( aVals ) ;
pMethVar - > SetParameters ( NULL ) ;
}
}
}
2000-09-18 15:18:56 +00:00
if ( pProp )
{
if ( pProp - > GetModule ( ) ! = this )
SetError ( SbxERR_BAD_ACTION ) ;
}
else if ( pMeth )
{
if ( pHint - > GetId ( ) = = SBX_HINT_DATAWANTED )
{
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!
2000-09-18 15:18:56 +00:00
StarBASIC : : Error ( SbERR_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 ;
2000-09-18 15:18:56 +00:00
Run ( ( 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
// side effects when using name as variable implicitely
bool bForwardToSbxObject = true ;
2011-01-10 14:40:57 +01:00
sal_uIntPtr nId = pHint - > GetId ( ) ;
2010-06-15 20:02:53 +02:00
if ( ( nId = = SBX_HINT_DATAWANTED | | nId = = SBX_HINT_DATACHANGED ) & &
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
{
2010-06-15 20:02:53 +02:00
SbxObject : : SFX_NOTIFY ( rBC , rBCType , rHint , rHintType ) ;
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 : : SetSource ( const OUString & r )
2000-09-18 15:18:56 +00:00
{
2003-04-23 15:56:27 +00:00
SetSource32 ( r ) ;
}
2012-11-06 23:34:23 -06:00
void SbModule : : SetSource32 ( const OUString & r )
2003-04-23 15:56:27 +00:00
{
2010-04-26 13:09:41 +01: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 ) )
{
2012-11-03 09:07:25 -05:00
sal_Bool bIsVBA = ( aTok . GetDbl ( ) = = 1 ) ;
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
2006-10-12 13:26:01 +00:00
SbMethod * pMeth = NULL ;
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
2011-01-10 14:40:57 +01:00
pMeth - > bInvalid = sal_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
}
}
2011-01-10 14:40:57 +01:00
EndDefinitions ( sal_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
2011-01-10 14:40:57 +01:00
static void _SendHint ( SbxObject * pObj , sal_uIntPtr nId , SbMethod * p )
2000-09-18 15:18:56 +00:00
{
2010-10-06 22:33:21 +02:00
// Self a BASIC?
2000-09-18 15:18:56 +00:00
if ( pObj - > IsA ( TYPE ( StarBASIC ) ) & & pObj - > IsBroadcaster ( ) )
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 ( ) ;
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 i = 0 ; i < pObjs - > Count ( ) ; i + + )
2000-09-18 15:18:56 +00:00
{
SbxVariable * pVar = pObjs - > Get ( i ) ;
if ( pVar - > IsA ( TYPE ( SbxObject ) ) )
_SendHint ( PTR_CAST ( SbxObject , pVar ) , nId , p ) ;
}
}
2011-01-10 14:40:57 +01:00
static void SendHint ( SbxObject * pObj , sal_uIntPtr nId , SbMethod * p )
2000-09-18 15:18:56 +00:00
{
while ( pObj - > GetParent ( ) )
pObj = pObj - > GetParent ( ) ;
_SendHint ( pObj , nId , p ) ;
}
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.
2000-09-18 15:18:56 +00:00
void ClearUnoObjectsInRTL_Impl_Rek ( StarBASIC * pBasic )
{
2010-10-06 22:33:21 +02:00
// delete the return value of CreateUnoService
2012-11-06 23:34:23 -06:00
static OUString aName ( " CreateUnoService " ) ;
2000-09-18 15:18:56 +00:00
SbxVariable * pVar = pBasic - > GetRtl ( ) - > Find ( aName , SbxCLASS_METHOD ) ;
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
2012-11-06 23:34:23 -06:00
static OUString aName2 ( " CreateUnoDialog " ) ;
2002-01-08 09:57:34 +00:00
pVar = pBasic - > GetRtl ( ) - > Find ( aName2 , SbxCLASS_METHOD ) ;
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
2012-11-06 23:34:23 -06:00
static OUString aName3 ( " CDec " ) ;
2004-03-17 12:32:25 +00:00
pVar = pBasic - > GetRtl ( ) - > Find ( aName3 , SbxCLASS_METHOD ) ;
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
2012-11-06 23:34:23 -06:00
static OUString aName4 ( " CreateObject " ) ;
2006-08-04 09:54:10 +00:00
pVar = pBasic - > GetRtl ( ) - > Find ( aName4 , SbxCLASS_METHOD ) ;
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 ( ) ;
2011-01-10 14:40:57 +01:00
sal_uInt16 nCount = pObjs - > Count ( ) ;
for ( sal_uInt16 i = 0 ; i < nCount ; i + + )
2000-09-18 15:18:56 +00:00
{
SbxVariable * pObjVar = pObjs - > Get ( i ) ;
StarBASIC * pSubBasic = PTR_CAST ( StarBASIC , pObjVar ) ;
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
}
}
void ClearUnoObjectsInRTL_Impl ( StarBASIC * pBasic )
{
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 ( ) ;
2010-02-12 16:56:44 +01:00
clearUnoServiceCtors ( ) ;
2000-09-18 15:18:56 +00:00
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 ( ) ;
2003-03-18 15:28:40 +00:00
if ( ( ( StarBASIC * ) p ) ! = pBasic )
ClearUnoObjectsInRTL_Impl_Rek ( ( StarBASIC * ) p ) ;
2000-09-18 15:18:56 +00:00
}
2012-04-20 20:01:54 +01:00
bool SbModule : : IsVBACompat ( ) const
2010-03-02 12:39:31 +00:00
{
return mbVBACompat ;
}
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
2010-10-06 22:33:21 +02:00
// Run a Basic-subprogram
2011-01-10 14:40:57 +01:00
sal_uInt16 SbModule : : Run ( SbMethod * pMeth )
2000-09-18 15:18:56 +00:00
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " About to run " < < OUStringToOString ( pMeth - > GetName ( ) , RTL_TEXTENCODING_UTF8 ) . getStr ( ) < < " , vba compatmode is " < < mbVBACompat ) ;
2011-01-10 14:40:57 +01:00
static sal_uInt16 nMaxCallLevel = 0 ;
2004-03-17 12:32:25 +00:00
2011-01-10 14:40:57 +01:00
sal_uInt16 nRes = 0 ;
2012-09-07 04:59:11 +09:00
bool bDelInst = ( GetSbData ( ) - > pInst = = NULL ) ;
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
2000-09-18 15:18:56 +00:00
xBasic = ( StarBASIC * ) GetParent ( ) ;
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pInst = new SbiInstance ( ( 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
2007-08-17 07:15:47 +00:00
// i80726 The Find below will genarate an error in Testtool so we reset it unless there was one before already
2013-10-01 23:16:43 +09:00
bool bWasError = SbxBase : : GetError ( ) ! = 0 ;
2013-01-09 00:14:10 +02:00
SbxVariable * pMSOMacroRuntimeLibVar = Find ( " Launcher " , SbxCLASS_OBJECT ) ;
2007-08-17 07:15:47 +00:00
if ( ! bWasError & & ( SbxBase : : GetError ( ) = = SbxERR_PROC_UNDEFINED ) )
SbxBase : : ResetError ( ) ;
2007-08-03 08:55:16 +00:00
if ( pMSOMacroRuntimeLibVar )
{
StarBASIC * pMSOMacroRuntimeLib = PTR_CAST ( StarBASIC , pMSOMacroRuntimeLibVar ) ;
if ( pMSOMacroRuntimeLib )
{
2011-01-10 14:40:57 +01:00
sal_uInt16 nGblFlag = pMSOMacroRuntimeLib - > GetFlags ( ) & SBX_GBLSEARCH ;
2007-08-03 08:55:16 +00:00
pMSOMacroRuntimeLib - > ResetFlag ( SBX_GBLSEARCH ) ;
2013-01-09 00:14:10 +02:00
SbxVariable * pAppSymbol = pMSOMacroRuntimeLib - > Find ( " Application " , SbxCLASS_METHOD ) ;
2007-08-03 08:55:16 +00:00
pMSOMacroRuntimeLib - > SetFlag ( nGblFlag ) ;
if ( pAppSymbol )
{
pMSOMacroRuntimeLib - > SetFlag ( SBX_EXTSEARCH ) ; // Could have been disabled before
GetSbData ( ) - > pMSOMacroRuntimLib = pMSOMacroRuntimeLib ;
}
}
}
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 ;
2006-10-12 13:26:01 +00:00
# elif defined SOLARIS
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 ;
2006-10-12 13:26:01 +00: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?
2012-01-15 16:15:08 +01:00
if ( + + GetSbData ( ) - > 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
2012-08-21 22:54:26 +09:00
if ( ! GetSbData ( ) - > bGlobalInitErr )
2000-09-18 15:18:56 +00:00
{
if ( bDelInst )
{
SendHint ( GetParent ( ) , SBX_HINT_BASICSTART , pMeth ) ;
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
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pInst - > CalcBreakCallLevel ( pMeth - > GetDebugFlags ( ) ) ;
2000-09-18 15:18:56 +00:00
}
2012-01-15 16:15:08 +01:00
SbModule * pOldMod = GetSbData ( ) - > pMod ;
GetSbData ( ) - > pMod = this ;
2000-09-18 15:18:56 +00:00
SbiRuntime * pRt = new SbiRuntime ( this , pMeth , pMeth - > nStart ) ;
2010-07-26 14:20:03 +02:00
2012-01-15 16:15:08 +01:00
pRt - > pNext = GetSbData ( ) - > pInst - > pRun ;
2005-09-29 17:38:55 +00:00
if ( pRt - > pNext )
pRt - > pNext - > block ( ) ;
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pInst - > pRun = pRt ;
2010-03-02 12:39:31 +00:00
if ( mbVBACompat )
2010-07-26 14:20:03 +02:00
{
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pInst - > EnableCompatibility ( sal_True ) ;
2010-07-26 14:20:03 +02:00
}
2000-09-18 15:18:56 +00:00
while ( pRt - > Step ( ) ) { }
2005-09-29 17:38:55 +00:00
if ( pRt - > pNext )
pRt - > pNext - > unblock ( ) ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// #63710 It can happen by an another thread handling at events,
// that the show call returns to an 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.
2000-09-18 15:18:56 +00:00
if ( bDelInst )
{
2010-10-06 22:33:21 +02:00
// Compare here with 1 instead of 0, because before nCallLvl--
2012-01-15 16:15:08 +01:00
while ( GetSbData ( ) - > pInst - > nCallLvl ! = 1 )
2000-09-18 15:18:56 +00:00
GetpApp ( ) - > Yield ( ) ;
}
2011-01-10 14:40:57 +01:00
nRes = sal_True ;
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pInst - > pRun = pRt - > pNext ;
GetSbData ( ) - > pInst - > nCallLvl - - ; // Call-Level down again
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// Exist an higher-ranking runtime instance?
// Then take over SbDEBUG_BREAK, if set
2000-09-18 15:18:56 +00:00
SbiRuntime * pRtNext = pRt - > pNext ;
if ( pRtNext & & ( pRt - > GetDebugFlags ( ) & SbDEBUG_BREAK ) )
pRtNext - > SetDebugFlags ( SbDEBUG_BREAK ) ;
delete pRt ;
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pMod = pOldMod ;
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.
2000-09-18 15:18:56 +00:00
ClearUnoObjectsInRTL_Impl ( xBasic ) ;
2010-09-08 16:34:55 +02:00
clearNativeObjectWrapperVector ( ) ;
2013-01-09 00:14:10 +02:00
SAL_WARN_IF ( GetSbData ( ) - > pInst - > nCallLvl ! = 0 , " basic " , " BASIC-Call-Level > 0 " ) ;
2012-09-07 04:59:11 +09:00
delete GetSbData ( ) - > pInst , GetSbData ( ) - > pInst = NULL , bDelInst = false ;
2004-11-15 12:29:17 +00:00
// #i30690
2010-10-13 02:47:36 -05:00
SolarMutexGuard aSolarGuard ;
2000-09-18 15:18:56 +00:00
SendHint ( GetParent ( ) , SBX_HINT_BASICSTOP , pMeth ) ;
2001-09-04 09:20:53 +00:00
GlobalRunDeInit ( ) ;
2010-08-23 11:16:00 +02:00
2011-02-13 20:21:59 +01:00
# ifdef DBG_UTIL
2011-02-08 12:44:14 +01:00
ResetCapturedAssertions ( ) ;
2011-02-13 20:21:59 +01:00
# endif
2011-02-08 12:44:14 +01: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
: : basic : : vba : : lockControllersOfAllDocuments ( xModel , sal_False ) ;
: : basic : : vba : : enableContainerWindowsOfAllDocuments ( xModel , sal_True ) ;
}
2010-09-14 15:23:33 +02:00
2010-08-23 11:16:00 +02:00
# ifdef DBG_TRACE_BASIC
dbg_DeInitTrace ( ) ;
# endif
2000-09-18 15:18:56 +00:00
}
}
2002-07-10 09:54:53 +00:00
else
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pInst - > nCallLvl - - ; // Call-Level down again
2000-09-18 15:18:56 +00:00
}
else
2003-04-23 15:56:27 +00:00
{
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pInst - > nCallLvl - - ; // Call-Level down again
2000-09-18 15:18:56 +00:00
StarBASIC : : FatalError ( SbERR_STACK_OVERFLOW ) ;
2003-04-23 15:56:27 +00:00
}
2009-09-29 14:47:18 +00:00
StarBASIC * pBasic = PTR_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.
2000-09-18 15:18:56 +00:00
ClearUnoObjectsInRTL_Impl ( xBasic ) ;
2012-01-15 16:15:08 +01:00
delete GetSbData ( ) - > pInst ;
GetSbData ( ) - > pInst = NULL ;
2000-09-18 15:18:56 +00:00
}
2012-01-15 16:15:08 +01:00
if ( pBasic & & pBasic - > IsDocBasic ( ) & & pBasic - > IsQuitApplication ( ) & & ! GetSbData ( ) - > pInst )
2010-10-06 10:16:27 +01:00
bQuit = true ;
if ( bQuit )
2009-09-29 14:47:18 +00:00
{
Application : : PostUserEvent ( LINK ( & AsyncQuitHandler : : instance ( ) , AsyncQuitHandler , OnAsyncQuit ) , NULL ) ;
}
2000-09-18 15:18:56 +00:00
return nRes ;
}
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
& & pImage - > GetFlag ( SBIMG_INITCODE ) )
{
2010-10-06 22:33:21 +02:00
// Set flag, so that RunInit get activ (Testtool)
2012-08-21 22:54:26 +09:00
GetSbData ( ) - > bRunInit = true ;
2000-09-18 15:18:56 +00:00
2012-01-15 16:15:08 +01:00
SbModule * pOldMod = GetSbData ( ) - > pMod ;
GetSbData ( ) - > pMod = this ;
2010-10-06 22:33:21 +02:00
// The init code starts always here
2000-09-18 15:18:56 +00:00
SbiRuntime * pRt = new SbiRuntime ( this , NULL , 0 ) ;
2010-07-26 14:20:03 +02:00
2012-01-15 16:15:08 +01:00
pRt - > pNext = GetSbData ( ) - > pInst - > pRun ;
GetSbData ( ) - > pInst - > pRun = pRt ;
2000-09-18 15:18:56 +00:00
while ( pRt - > Step ( ) ) { }
2010-07-26 14:20:03 +02:00
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pInst - > pRun = pRt - > pNext ;
2000-09-18 15:18:56 +00:00
delete pRt ;
2012-01-15 16:15:08 +01:00
GetSbData ( ) - > pMod = pOldMod ;
2012-08-15 09:44:54 +09:00
pImage - > bInit = true ;
pImage - > bFirstInit = false ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// RunInit is not activ anymore
2012-08-21 22:54:26 +09:00
GetSbData ( ) - > 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
2012-11-06 23:34:23 -06:00
std : : vector < OUString > : : iterator it_end = mModuleVariableNames . end ( ) ;
for ( std : : vector < OUString > : : iterator it = mModuleVariableNames . begin ( ) ; it ! = it_end ; + + it )
2010-07-05 13:58:36 +02:00
{
if ( aName = = * it )
return ;
}
mModuleVariableNames . push_back ( aName ) ;
}
void SbModule : : RemoveVars ( )
{
2012-11-06 23:34:23 -06:00
std : : vector < OUString > : : iterator it_end = mModuleVariableNames . end ( ) ;
for ( std : : vector < OUString > : : iterator it = mModuleVariableNames . begin ( ) ; it ! = it_end ; + + it )
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 )
SbxVariableRef p = SbModule : : Find ( * it , SbxCLASS_PROPERTY ) ;
if ( p . Is ( ) )
Remove ( p ) ;
}
}
2000-09-18 15:18:56 +00:00
void SbModule : : ClearPrivateVars ( )
{
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 i = 0 ; i < pProps - > Count ( ) ; i + + )
2000-09-18 15:18:56 +00:00
{
SbProperty * p = PTR_CAST ( SbProperty , pProps - > Get ( i ) ) ;
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 )
{
SbxArray * pArray = PTR_CAST ( SbxArray , p - > GetObject ( ) ) ;
if ( pArray )
{
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 j = 0 ; j < pArray - > Count ( ) ; j + + )
2000-09-18 15:18:56 +00:00
{
SbxVariable * pj = PTR_CAST ( SbxVariable , pArray - > Get ( j ) ) ;
pj - > SbxValue : : Clear ( ) ;
}
}
}
else
{
p - > SbxValue : : Clear ( ) ;
}
}
}
}
2010-09-21 08:58:34 +02:00
void SbModule : : implClearIfVarDependsOnDeletedBasic ( SbxVariable * pVar , StarBASIC * pDeletedBasic )
{
if ( pVar - > SbxValue : : GetType ( ) ! = SbxOBJECT | | pVar - > ISA ( SbProcedureProperty ) )
return ;
SbxObject * pObj = PTR_CAST ( SbxObject , pVar - > GetObject ( ) ) ;
if ( pObj ! = NULL )
{
SbxObject * p = pObj ;
SbModule * pMod = PTR_CAST ( SbModule , p ) ;
if ( pMod ! = NULL )
pMod - > ClearVarsDependingOnDeletedBasic ( pDeletedBasic ) ;
while ( ( p = p - > GetParent ( ) ) ! = NULL )
{
StarBASIC * pBasic = PTR_CAST ( StarBASIC , p ) ;
if ( pBasic ! = NULL & & pBasic = = pDeletedBasic )
{
pVar - > SbxValue : : Clear ( ) ;
break ;
}
}
}
}
void SbModule : : ClearVarsDependingOnDeletedBasic ( StarBASIC * pDeletedBasic )
{
( void ) pDeletedBasic ;
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 i = 0 ; i < pProps - > Count ( ) ; i + + )
2010-09-21 08:58:34 +02:00
{
SbProperty * p = PTR_CAST ( SbProperty , pProps - > Get ( i ) ) ;
if ( p )
{
if ( p - > GetType ( ) & SbxARRAY )
{
SbxArray * pArray = PTR_CAST ( SbxArray , p - > GetObject ( ) ) ;
if ( pArray )
{
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 j = 0 ; j < pArray - > Count ( ) ; j + + )
2010-09-21 08:58:34 +02:00
{
SbxVariable * pVar = PTR_CAST ( SbxVariable , pArray - > Get ( j ) ) ;
implClearIfVarDependsOnDeletedBasic ( pVar , pDeletedBasic ) ;
}
}
}
else
{
implClearIfVarDependsOnDeletedBasic ( p , pDeletedBasic ) ;
}
}
}
}
2000-09-18 15:18:56 +00:00
void StarBASIC : : ClearAllModuleVars ( void )
{
2010-10-06 22:33:21 +02:00
// Initialise the own module
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 nMod = 0 ; nMod < pModules - > Count ( ) ; nMod + + )
2000-09-18 15:18:56 +00:00
{
SbModule * pModule = ( SbModule * ) pModules - > Get ( nMod ) ;
2010-10-06 22:33:21 +02:00
// Initialise only, if the startcode was already executed
2010-08-24 13:40:40 +02:00
if ( pModule - > pImage & & pModule - > pImage - > bInit & & ! pModule - > isProxyModule ( ) & & ! pModule - > ISA ( SbObjModule ) )
2000-09-18 15:18:56 +00:00
pModule - > ClearPrivateVars ( ) ;
}
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
// GlobalRunInit, if at the intialising 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
2000-09-18 15:18:56 +00:00
StarBASIC * pBasic = PTR_CAST ( StarBASIC , GetParent ( ) ) ;
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
{
2006-06-19 16:40:39 +00:00
StarBASIC * pParentBasic = PTR_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 )
{
StarBASIC * pParentParentBasic = PTR_CAST ( StarBASIC , pParentParent ) ;
if ( pParentParentBasic )
pParentParentBasic - > InitAllModules ( pParentBasic ) ;
}
}
}
2000-09-18 15:18:56 +00:00
}
}
2001-09-04 09:20:53 +00:00
void SbModule : : GlobalRunDeInit ( void )
{
StarBASIC * pBasic = PTR_CAST ( StarBASIC , GetParent ( ) ) ;
if ( pBasic )
{
pBasic - > DeInitAllModules ( ) ;
2006-06-19 16:40:39 +00:00
SbxObject * pParent_ = pBasic - > GetParent ( ) ;
if ( pParent_ )
pBasic = PTR_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
{
2011-01-10 14:40:57 +01:00
return FindNextStmnt ( p , nLine , nCol , sal_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 ,
sal_Bool bFollowJumps , const SbiImage * pImg ) const
2000-09-18 15:18:56 +00:00
{
2011-01-10 14:40:57 +01:00
sal_uInt32 nPC = ( sal_uInt32 ) ( p - ( const sal_uInt8 * ) pImage - > GetCode ( ) ) ;
2000-09-18 15:18:56 +00:00
while ( nPC < pImage - > GetCodeSize ( ) )
{
SbiOpcode eOp = ( SbiOpcode ) ( * p + + ) ;
nPC + + ;
2002-08-09 09:27:16 +00:00
if ( bFollowJumps & & eOp = = _JUMP & & pImg )
{
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 ;
2011-01-10 14:40:57 +01:00
p = ( const sal_uInt8 * ) pImg - > GetCode ( ) + nOp1 ;
2002-08-09 09:27:16 +00:00
}
else if ( eOp > = SbOP1_START & & eOp < = SbOP1_END )
2006-11-01 15:13:15 +00:00
p + = 4 , nPC + = 4 ;
2000-09-18 15:18:56 +00:00
else if ( eOp = = _STMNT )
{
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 ;
2011-01-10 14:40:57 +01:00
nLine = ( sal_uInt16 ) nl ; nCol = ( sal_uInt16 ) nc ;
2000-09-18 15:18:56 +00:00
return p ;
}
else if ( eOp > = SbOP2_START & & eOp < = SbOP2_END )
2006-11-01 15:13:15 +00:00
p + = 8 , nPC + = 8 ;
2000-09-18 15:18:56 +00:00
else if ( ! ( eOp > = SbOP0_START & & eOp < = SbOP0_END ) )
{
StarBASIC : : FatalError ( SbERR_INTERNAL_ERROR ) ;
break ;
}
}
return NULL ;
}
2010-10-06 22:33:21 +02:00
// Test, if a line contains STMNT-Opcodes
2000-09-18 15:18:56 +00:00
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : IsBreakable ( sal_uInt16 nLine ) const
2000-09-18 15:18:56 +00:00
{
if ( ! pImage )
2011-01-10 14:40:57 +01:00
return sal_False ;
const sal_uInt8 * p = ( const sal_uInt8 * ) pImage - > GetCode ( ) ;
sal_uInt16 nl , nc ;
2000-09-18 15:18:56 +00:00
while ( ( p = FindNextStmnt ( p , nl , nc ) ) ! = NULL )
if ( nl = = nLine )
2011-01-10 14:40:57 +01:00
return sal_True ;
return sal_False ;
2000-09-18 15:18:56 +00:00
}
2011-01-10 14:40:57 +01:00
sal_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 )
2011-01-10 14:40:57 +01:00
return sal_True ;
2000-09-18 15:18:56 +00:00
if ( b < nLine )
break ;
}
}
2011-01-10 14:40:57 +01:00
return sal_False ;
2000-09-18 15:18:56 +00:00
}
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : SetBP ( sal_uInt16 nLine )
2000-09-18 15:18:56 +00:00
{
if ( ! IsBreakable ( nLine ) )
2011-01-10 14:40:57 +01:00
return sal_False ;
2000-09-18 15:18:56 +00:00
if ( ! pBreaks )
pBreaks = new SbiBreakpoints ;
2010-10-07 22:07:22 +02:00
size_t i ;
for ( 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 )
2011-01-10 14:40:57 +01:00
return sal_True ;
2000-09-18 15:18:56 +00:00
if ( b < nLine )
break ;
}
2010-10-07 22:07:22 +02:00
pBreaks - > insert ( pBreaks - > begin ( ) + i , nLine ) ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// #38568: Set during runtime as well here SbDEBUG_BREAK
2012-01-15 16:15:08 +01:00
if ( GetSbData ( ) - > pInst & & GetSbData ( ) - > pInst - > pRun )
GetSbData ( ) - > pInst - > pRun - > SetDebugFlags ( SbDEBUG_BREAK ) ;
2000-09-18 15:18:56 +00:00
return IsBreakable ( nLine ) ;
}
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : ClearBP ( sal_uInt16 nLine )
2000-09-18 15:18:56 +00:00
{
2011-01-10 14:40:57 +01:00
sal_Bool bRes = sal_False ;
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 )
{
2010-10-07 22:07:22 +02:00
pBreaks - > erase ( pBreaks - > begin ( ) + i ) ;
2011-01-10 14:40:57 +01:00
bRes = sal_True ;
2010-10-07 22:07:22 +02:00
break ;
2000-09-18 15:18:56 +00:00
}
if ( b < nLine )
break ;
}
2010-10-07 22:07:22 +02:00
if ( pBreaks - > empty ( ) )
2000-09-18 15:18:56 +00:00
delete pBreaks , pBreaks = NULL ;
}
return bRes ;
}
void SbModule : : ClearAllBP ( )
{
2010-10-07 22:07:22 +02:00
delete pBreaks ;
pBreaks = NULL ;
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 )
pImg = pImage ;
2011-01-10 14:40:57 +01:00
for ( sal_uInt32 i = 0 ; i < pMethods - > Count ( ) ; i + + )
2006-11-01 15:13:15 +00:00
{
2011-01-10 14:40:57 +01:00
SbMethod * pMeth = PTR_CAST ( SbMethod , pMethods - > Get ( ( sal_uInt16 ) i ) ) ;
2006-11-01 15:13:15 +00:00
if ( pMeth )
{
//fixup method start positions
if ( bCvtToLegacy )
pMeth - > nStart = pImg - > CalcLegacyOffset ( pMeth - > nStart ) ;
else
2011-01-10 14:40:57 +01:00
pMeth - > nStart = pImg - > CalcNewOffset ( ( sal_uInt16 ) pMeth - > nStart ) ;
2006-11-01 15:13:15 +00:00
}
}
}
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : LoadData ( SvStream & rStrm , sal_uInt16 nVer )
2000-09-18 15:18:56 +00:00
{
Clear ( ) ;
if ( ! SbxObject : : LoadData ( rStrm , 1 ) )
2011-01-10 14:40:57 +01:00
return sal_False ;
2010-10-06 22:33:21 +02:00
// As a precaution...
2000-09-18 15:18:56 +00:00
SetFlag ( SBX_EXTSEARCH | SBX_GBLSEARCH ) ;
2011-01-10 14:40:57 +01:00
sal_uInt8 bImage ;
2000-09-18 15:18:56 +00:00
rStrm > > bImage ;
if ( bImage )
{
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
{
delete p ;
2011-01-10 14:40:57 +01:00
return sal_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 )
{
fixUpMethodStart ( false , p ) ;
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 ) ;
2000-09-18 15:18:56 +00:00
delete p ;
}
else
pImage = p ;
}
else
{
2003-04-23 15:56:27 +00:00
SetSource32 ( p - > aOUSource ) ;
2000-09-18 15:18:56 +00:00
delete p ;
}
}
2011-01-10 14:40:57 +01:00
return sal_True ;
2000-09-18 15:18:56 +00:00
}
2011-01-10 14:40:57 +01:00
sal_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 ) ;
2011-01-10 14:40:57 +01:00
sal_Bool bRet = SbxObject : : StoreData ( rStrm ) ;
2006-11-01 15:13:15 +00:00
if ( ! bRet )
2011-01-10 14:40:57 +01:00
return sal_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-01-08 08:48:26 +02:00
rStrm . WriteUChar ( ( sal_uInt8 ) 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-01-08 08:48:26 +02:00
rStrm . WriteUChar ( ( sal_uInt8 ) 1 ) ;
2000-09-18 15:18:56 +00:00
return aImg . Save ( rStrm ) ;
}
}
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : ExceedsLegacyModuleSize ( )
2006-11-01 15:13:15 +00:00
{
if ( ! IsCompiled ( ) )
Compile ( ) ;
if ( pImage & & pImage - > ExceedsLegacyLimits ( ) )
return true ;
return false ;
}
2010-10-06 10:16:27 +01:00
class ErrorHdlResetter
{
Link mErrHandler ;
bool mbError ;
public :
ErrorHdlResetter ( ) : mbError ( false )
{
// save error handler
mErrHandler = StarBASIC : : GetGlobalErrorHdl ( ) ;
// set new error handler
StarBASIC : : SetGlobalErrorHdl ( LINK ( this , ErrorHdlResetter , BasicErrorHdl ) ) ;
}
~ ErrorHdlResetter ( )
{
// restore error handler
StarBASIC : : SetGlobalErrorHdl ( mErrHandler ) ;
}
DECL_LINK ( BasicErrorHdl , StarBASIC * ) ;
bool HasError ( ) { return mbError ; }
} ;
IMPL_LINK ( ErrorHdlResetter , BasicErrorHdl , StarBASIC * , /*pBasic*/ )
{
mbError = true ;
return 0 ;
}
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 ( ) ;
SbiParser * pParser = new SbiParser ( ( 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;
if ( ( pSymDef - > GetType ( ) ! = SbxEMPTY ) | | ( pSymDef - > GetType ( ) ! = SbxNULL ) )
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
SbiSymPool & pChildPool = pSymDef - > GetPool ( ) ;
for ( sal_uInt16 j = 0 ; j < pChildPool . GetSize ( ) ; + + j )
{
SbiSymDef * pChildSymDef = pChildPool . Get ( j ) ;
2013-08-19 13:53:38 +02:00
//std::cerr << "j: " << j << ", type: " << pChildSymDef->GetType() << "; name:" << pChildSymDef->GetName() << std::endl;
if ( ( pChildSymDef - > GetType ( ) ! = SbxEMPTY ) | | ( pChildSymDef - > GetType ( ) ! = SbxNULL ) )
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
}
}
delete pParser ;
}
2013-07-07 19:43:05 +02:00
SbxArrayRef SbModule : : GetMethods ( )
{
return pMethods ;
}
2013-08-13 18:11:26 +02:00
OUString SbModule : : GetKeywordCase ( const OUString & sKeyword ) const
{
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
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : StoreBinaryData ( SvStream & rStrm )
2006-11-01 15:13:15 +00:00
{
return StoreBinaryData ( rStrm , 0 ) ;
}
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : StoreBinaryData ( SvStream & rStrm , sal_uInt16 nVer )
2001-10-23 11:06:51 +00:00
{
2011-01-10 14:40:57 +01:00
sal_Bool bRet = Compile ( ) ;
2001-10-23 11:06:51 +00:00
if ( bRet )
{
2012-08-15 09:44:54 +09:00
bool bFixup = ( ! nVer & & ! pImage - > ExceedsLegacyLimits ( ) ) ; // save in old image format, fix up method starts
2006-11-01 15:13:15 +00:00
if ( bFixup ) // save in old image format, fix up method starts
fixUpMethodStart ( true ) ;
2001-11-14 10:11:32 +00:00
bRet = SbxObject : : StoreData ( rStrm ) ;
2001-10-23 11:06:51 +00:00
if ( bRet )
{
2012-11-06 23:34:23 -06:00
pImage - > aOUSource = OUString ( ) ;
2001-10-23 11:06:51 +00:00
pImage - > aComment = aComment ;
pImage - > aName = GetName ( ) ;
2014-01-08 08:48:26 +02:00
rStrm . WriteUChar ( ( sal_uInt8 ) 1 ) ;
2006-11-01 15:13:15 +00:00
if ( nVer )
bRet = pImage - > Save ( rStrm , B_EXT_IMG_VERSION ) ;
else
bRet = pImage - > Save ( rStrm , B_LEGACYVERSION ) ;
if ( bFixup )
fixUpMethodStart ( false ) ; // restore method starts
2001-10-23 11:06:51 +00:00
2003-04-23 15:56:27 +00:00
pImage - > aOUSource = aOUSource ;
2001-10-23 11:06:51 +00:00
}
}
return bRet ;
}
2006-11-01 15:13:15 +00:00
// Called for >= OO 1.0 passwd protected libraries only
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : LoadBinaryData ( SvStream & rStrm )
2001-10-23 11:06:51 +00:00
{
2012-11-06 23:34:23 -06:00
OUString aKeepSource = aOUSource ;
2001-10-23 11:06:51 +00:00
bool bRet = 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
return bRet ;
}
2011-01-10 14:40:57 +01:00
sal_Bool SbModule : : LoadCompleted ( )
2000-09-18 15:18:56 +00:00
{
SbxArray * p = GetMethods ( ) ;
2011-01-10 14:40:57 +01:00
sal_uInt16 i ;
2000-09-18 15:18:56 +00:00
for ( i = 0 ; i < p - > Count ( ) ; i + + )
{
SbMethod * q = PTR_CAST ( SbMethod , p - > Get ( i ) ) ;
if ( q )
q - > pMod = this ;
}
p = GetProperties ( ) ;
for ( i = 0 ; i < p - > Count ( ) ; i + + )
{
SbProperty * q = PTR_CAST ( SbProperty , p - > Get ( i ) ) ;
if ( q )
q - > pMod = this ;
}
2011-01-10 14:40:57 +01:00
return sal_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 ;
const SbxHint * pHint = PTR_CAST ( SbxHint , & rHint ) ;
if ( pHint )
{
SbxVariable * pVar = pHint - > GetVar ( ) ;
SbProcedureProperty * pProcProperty = PTR_CAST ( SbProcedureProperty , pVar ) ;
if ( pProcProperty )
{
bDone = true ;
if ( pHint - > GetId ( ) = = SBX_HINT_DATAWANTED )
{
2012-11-06 23:34:23 -06:00
OUString aProcName ( " Property Get " ) ;
2010-08-23 10:54:49 +02:00
aProcName + = pProcProperty - > GetName ( ) ;
SbxVariable * pMeth = Find ( aProcName , SbxCLASS_METHOD ) ;
if ( pMeth )
{
SbxValues aVals ;
aVals . eType = SbxVARIANT ;
SbxArray * pArg = pVar - > GetParameters ( ) ;
2011-01-10 14:40:57 +01:00
sal_uInt16 nVarParCount = ( pArg ! = NULL ) ? pArg - > Count ( ) : 0 ;
2010-08-23 10:54:49 +02:00
if ( nVarParCount > 1 )
{
SbxArrayRef xMethParameters = new SbxArray ;
xMethParameters - > Put ( pMeth , 0 ) ; // Method as parameter 0
2011-01-10 14:40:57 +01:00
for ( sal_uInt16 i = 1 ; i < nVarParCount ; + + i )
2010-08-23 10:54:49 +02:00
{
SbxVariable * pPar = pArg - > Get ( i ) ;
xMethParameters - > Put ( pPar , i ) ;
}
pMeth - > SetParameters ( xMethParameters ) ;
pMeth - > Get ( aVals ) ;
pMeth - > SetParameters ( NULL ) ;
}
else
{
pMeth - > Get ( aVals ) ;
}
pVar - > Put ( aVals ) ;
}
}
else if ( pHint - > GetId ( ) = = SBX_HINT_DATACHANGED )
{
SbxVariable * pMeth = NULL ;
bool bSet = pProcProperty - > isSet ( ) ;
if ( bSet )
{
pProcProperty - > setSet ( false ) ;
2012-11-06 23:34:23 -06:00
OUString aProcName ( " Property Set " ) ;
2010-08-23 10:54:49 +02:00
aProcName + = pProcProperty - > GetName ( ) ;
pMeth = Find ( aProcName , SbxCLASS_METHOD ) ;
}
if ( ! pMeth ) // Let
{
2013-03-13 14:37:01 +00:00
OUString aProcName ( " Property Let " ) ;
2010-08-23 10:54:49 +02:00
aProcName + = pProcProperty - > GetName ( ) ;
pMeth = Find ( aProcName , SbxCLASS_METHOD ) ;
}
if ( pMeth )
{
// Setup parameters
SbxArrayRef xArray = new SbxArray ;
xArray - > Put ( pMeth , 0 ) ; // Method as parameter 0
xArray - > Put ( pVar , 1 ) ;
pMeth - > SetParameters ( xArray ) ;
SbxValues aVals ;
pMeth - > Get ( aVals ) ;
pMeth - > SetParameters ( NULL ) ;
}
}
}
}
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)
2012-11-06 23:34:23 -06:00
SbJScriptModule : : SbJScriptModule ( const OUString & rName )
2000-09-18 15:18:56 +00:00
: SbModule ( rName )
{
}
2011-01-10 14:40:57 +01:00
sal_Bool SbJScriptModule : : LoadData ( SvStream & rStrm , sal_uInt16 nVer )
2000-09-18 15:18:56 +00:00
{
2006-06-19 16:40:39 +00:00
( void ) nVer ;
2000-09-18 15:18:56 +00:00
Clear ( ) ;
if ( ! SbxObject : : LoadData ( rStrm , 1 ) )
2011-01-10 14:40:57 +01:00
return sal_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 ( ) ) ;
2011-01-10 14:40:57 +01:00
return sal_True ;
2000-09-18 15:18:56 +00:00
}
2011-01-10 14:40:57 +01:00
sal_Bool SbJScriptModule : : StoreData ( SvStream & rStrm ) const
2000-09-18 15:18:56 +00:00
{
if ( ! SbxObject : : StoreData ( rStrm ) )
2011-01-10 14:40:57 +01:00
return sal_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 ( ) ) ;
2011-01-10 14:40:57 +01:00
return sal_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 )
{
2011-01-10 14:40:57 +01:00
bInvalid = sal_True ;
2000-09-18 15:18:56 +00:00
nStart =
nDebugFlags =
nLine1 =
nLine2 = 0 ;
2008-07-02 08:57:20 +00:00
refStatics = new SbxArray ;
2010-10-06 10:16:27 +01:00
mCaller = 0 ;
2011-03-21 12:55:40 +01:00
// HACK due to 'Referenz could not be saved'
2000-09-18 15:18:56 +00:00
SetFlag ( SBX_NO_MODIFY ) ;
}
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 ;
2008-07-02 08:57:20 +00:00
refStatics = r . refStatics ;
2010-10-06 10:16:27 +01:00
mCaller = r . mCaller ;
2003-04-23 15:56:27 +00:00
SetFlag ( SBX_NO_MODIFY ) ;
}
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 ( )
{
2008-07-02 08:57:20 +00:00
return refStatics ;
2000-09-18 15:18:56 +00:00
}
2011-01-10 14:40:57 +01:00
sal_Bool SbMethod : : LoadData ( SvStream & rStrm , sal_uInt16 nVer )
2000-09-18 15:18:56 +00:00
{
if ( ! SbxMethod : : LoadData ( rStrm , 1 ) )
2011-01-10 14:40:57 +01:00
return sal_False ;
sal_Int16 n ;
2000-09-18 15:18:56 +00:00
rStrm > > n ;
2011-01-10 14:40:57 +01:00
sal_Int16 nTempStart = ( sal_Int16 ) nStart ;
2000-09-18 15:18:56 +00:00
if ( nVer = = 2 )
2006-11-01 15:13:15 +00:00
rStrm > > nLine1 > > nLine2 > > nTempStart > > bInvalid ;
2011-03-21 12:55:40 +01:00
// HACK ue to 'Referenz could not be saved'
2000-09-18 15:18:56 +00:00
SetFlag ( SBX_NO_MODIFY ) ;
2006-11-01 15:13:15 +00:00
nStart = nTempStart ;
2011-01-10 14:40:57 +01:00
return sal_True ;
2000-09-18 15:18:56 +00:00
}
2011-01-10 14:40:57 +01:00
sal_Bool SbMethod : : StoreData ( SvStream & rStrm ) const
2000-09-18 15:18:56 +00:00
{
if ( ! SbxMethod : : StoreData ( rStrm ) )
2011-01-10 14:40:57 +01:00
return sal_False ;
2014-01-08 08:48:26 +02:00
rStrm . WriteInt16 ( ( sal_Int16 ) nDebugFlags )
. WriteInt16 ( ( sal_Int16 ) nLine1 )
. WriteInt16 ( ( sal_Int16 ) nLine2 )
. WriteInt16 ( ( sal_Int16 ) nStart )
. WriteUChar ( ( sal_uInt8 ) bInvalid ) ;
2011-01-10 14:40:57 +01:00
return sal_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 ( )
{
return pInfo ;
}
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 ;
}
2000-09-18 15:18:56 +00:00
// RefCount vom Modul hochzaehlen
2006-06-19 16:40:39 +00:00
SbModule * pMod_ = ( SbModule * ) GetParent ( ) ;
pMod_ - > AddRef ( ) ;
2000-09-18 15:18:56 +00:00
2010-10-06 22:33:21 +02:00
// Increment the RefCount of the Basic
2006-06-19 16:40:39 +00:00
StarBASIC * pBasic = ( StarBASIC * ) pMod_ - > GetParent ( ) ;
2000-09-18 15:18:56 +00:00
pBasic - > AddRef ( ) ;
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 ( ) )
2002-10-25 09:03:13 +00:00
StarBASIC : : Error ( SbERR_BAD_PROP_VALUE ) ;
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 ( ) ;
2010-10-06 22:33:21 +02:00
// Release objects
2006-06-19 16:40:39 +00:00
pMod_ - > ReleaseRef ( ) ;
2000-09-18 15:18:56 +00:00
pBasic - > ReleaseRef ( ) ;
2010-10-06 10:16:27 +01:00
mCaller = 0 ;
2000-09-18 15:18:56 +00:00
return nErr ;
}
2003-04-23 15:56:27 +00:00
// #100883 Own Broadcast for SbMethod
2011-01-10 14:40:57 +01:00
void SbMethod : : Broadcast ( sal_uIntPtr nHintId )
2003-04-23 15:56:27 +00:00
{
2011-11-04 21:54:43 +00:00
if ( pCst & & ! IsSet ( SBX_NO_BROADCAST ) )
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
2003-04-23 15:56:27 +00:00
if ( nHintId & SBX_HINT_DATAWANTED )
if ( ! CanRead ( ) )
return ;
if ( nHintId & SBX_HINT_DATACHANGED )
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
SfxBroadcaster * pSave = pCst ;
pCst = NULL ;
SbMethod * pThisCopy = new SbMethod ( * this ) ;
SbMethodRef xHolder = pThisCopy ;
2006-06-19 16:40:39 +00:00
if ( mpPar . Is ( ) )
2003-04-23 15:56:27 +00:00
{
2010-10-06 22:33:21 +02:00
// Enrigister this as element 0, but don't reset the parent!
2007-08-03 08:55:16 +00:00
if ( GetType ( ) ! = SbxVOID )
mpPar - > PutDirect ( pThisCopy , 0 ) ;
2003-04-23 15:56:27 +00:00
SetParameters ( NULL ) ;
}
pCst = pSave ;
pSave - > Broadcast ( SbxHint ( nHintId , pThisCopy ) ) ;
2011-01-10 14:40:57 +01:00
sal_uInt16 nSaveFlags = GetFlags ( ) ;
2003-04-23 15:56:27 +00:00
SetFlag ( SBX_READWRITE ) ;
pCst = NULL ;
Put ( pThisCopy - > GetValues_Impl ( ) ) ;
pCst = pSave ;
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
2012-11-06 23:34:23 -06:00
SbJScriptMethod : : SbJScriptMethod ( const OUString & r , SbxDataType t , SbModule * p )
2000-09-18 15:18:56 +00:00
: SbMethod ( r , t , p )
{
}
SbJScriptMethod : : ~ SbJScriptMethod ( )
{ }
2012-11-06 23:34:23 -06:00
SbObjModule : : SbObjModule ( const OUString & rName , const com : : sun : : star : : 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
{
2010-03-02 12:39:31 +00:00
SetUnoObject ( uno : : makeAny ( 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
SbObjModule : : SetUnoObject ( const uno : : Any & aObj ) throw ( uno : : RuntimeException )
{
SbUnoObject * pUnoObj = PTR_CAST ( SbUnoObject , ( SbxVariable * ) pDocObject ) ;
if ( pUnoObj & & pUnoObj - > getUnoAny ( ) = = aObj ) // object is equal, nothing to do
return ;
pDocObject = new SbUnoObject ( GetName ( ) , uno : : makeAny ( aObj ) ) ;
com : : sun : : star : : uno : : Reference < com : : sun : : star : : lang : : XServiceInfo > xServiceInfo ( aObj , com : : sun : : star : : 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 ( )
{
return pDocObject ;
}
SbxVariable *
2012-11-06 23:34:23 -06:00
SbObjModule : : Find ( const OUString & rName , SbxClassType t )
2010-03-02 12:39:31 +00:00
{
SbxVariable * pVar = NULL ;
2010-04-07 17:00:09 +01:00
if ( pDocObject )
2010-03-02 12:39:31 +00:00
pVar = pDocObject - > Find ( rName , t ) ;
if ( ! pVar )
pVar = SbModule : : Find ( rName , t ) ;
return pVar ;
}
2010-08-23 10:54:49 +02:00
void SbObjModule : : SFX_NOTIFY ( SfxBroadcaster & rBC , const TypeId & rBCType ,
const SfxHint & rHint , const TypeId & rHintType )
{
SbModule : : handleProcedureProperties ( rBC , rHint ) ;
}
2011-02-11 15:06:12 +01:00
typedef : : cppu : : WeakImplHelper3 <
awt : : XTopWindowListener ,
awt : : XWindowListener ,
document : : XEventListener > FormObjEventListener_BASE ;
2010-03-02 12:39:31 +00:00
2010-07-06 18:07:29 +02:00
class FormObjEventListenerImpl : 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
FormObjEventListenerImpl ( const FormObjEventListenerImpl & ) ; // not defined
2011-02-11 15:06:12 +01:00
FormObjEventListenerImpl & operator = ( const FormObjEventListenerImpl & ) ; // not defined
2010-07-06 18:07:29 +02:00
2010-03-02 12:39:31 +00:00
public :
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
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " *********** Registering the listeners " ) ;
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
{
uno : : Reference < document : : XEventBroadcaster > ( mxModel , uno : : UNO_QUERY_THROW ) - > addEventListener ( this ) ;
}
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
}
2010-07-06 18:07:29 +02:00
virtual ~ FormObjEventListenerImpl ( )
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
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " *********** Removing the listeners " ) ;
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
{
uno : : Reference < document : : XEventBroadcaster > ( mxModel , uno : : UNO_QUERY_THROW ) - > removeEventListener ( this ) ;
}
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
2010-03-02 12:39:31 +00:00
virtual void SAL_CALL windowOpened ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
{
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
2012-09-12 17:18:17 +02:00
virtual void SAL_CALL windowClosing ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
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
2010-07-06 18:07:29 +02:00
virtual void SAL_CALL windowClosed ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
{
2013-10-01 23:16:43 +09:00
mbOpened = false ;
mbShowing = false ;
2010-07-06 18:07:29 +02:00
}
virtual void SAL_CALL windowMinimized ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
{
}
virtual void SAL_CALL windowNormalized ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
{
}
2010-03-02 12:39:31 +00:00
virtual void SAL_CALL windowActivated ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
{
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 ( ) ;
}
}
}
virtual void SAL_CALL windowDeactivated ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
{
2010-07-06 18:07:29 +02:00
if ( mpUserForm )
mpUserForm - > triggerDeactivateEvent ( ) ;
2010-03-02 12:39:31 +00:00
}
2010-07-06 18:07:29 +02:00
virtual void SAL_CALL windowResized ( const awt : : WindowEvent & /*e*/ ) throw ( uno : : RuntimeException )
{
if ( mpUserForm )
{
mpUserForm - > triggerResizeEvent ( ) ;
mpUserForm - > triggerLayoutEvent ( ) ;
}
}
virtual void SAL_CALL windowMoved ( const awt : : WindowEvent & /*e*/ ) throw ( uno : : RuntimeException )
{
if ( mpUserForm )
mpUserForm - > triggerLayoutEvent ( ) ;
}
virtual void SAL_CALL windowShown ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
{
}
virtual void SAL_CALL windowHidden ( const lang : : EventObject & /*e*/ ) throw ( uno : : RuntimeException )
{
}
2010-03-02 12:39:31 +00:00
2011-02-11 15:06:12 +01:00
virtual void SAL_CALL notifyEvent ( const document : : EventObject & rEvent ) throw ( uno : : RuntimeException )
{
// early dosposing on document event "OnUnload", to be sure Basic still exists when calling VBA "UserForm_Terminate"
if ( rEvent . EventName = = GlobalEventConfig : : GetEventName ( STR_EVENT_CLOSEDOC ) )
{
removeListener ( ) ;
mbDisposed = true ;
if ( mpUserForm )
mpUserForm - > ResetApiObj ( ) ; // will trigger "UserForm_Terminate"
}
}
2010-07-06 18:07:29 +02:00
virtual void SAL_CALL disposing ( const lang : : EventObject & /*Source*/ ) throw ( uno : : RuntimeException )
2010-03-02 12:39:31 +00:00
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " ** Userform/Dialog disposing " ) ;
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
}
} ;
2012-11-06 23:34:23 -06:00
SbUserFormModule : : SbUserFormModule ( const OUString & rName , const com : : sun : : star : : 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 ( ) ;
}
pDocObject = NULL ;
2010-03-02 12:39:31 +00:00
m_xDialog = NULL ;
}
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
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " *** trigger " < < OUStringToOString ( aMethodToRun , RTL_TEXTENCODING_UTF8 ) . getStr ( ) < < " *** " ) ;
2010-03-02 12:39:31 +00:00
// Search method
SbxVariable * pMeth = SbObjModule : : Find ( aMethodToRun , SbxCLASS_METHOD ) ;
if ( pMeth )
{
if ( aArguments . getLength ( ) > 0 ) // Setup parameters
{
SbxArrayRef xArray = new SbxArray ;
xArray - > Put ( pMeth , 0 ) ; // Method as parameter 0
for ( sal_Int32 i = 0 ; i < aArguments . getLength ( ) ; + + i )
{
SbxVariableRef xSbxVar = new SbxVariable ( SbxVARIANT ) ;
unoToSbxValue ( static_cast < SbxVariable * > ( xSbxVar ) , aArguments [ i ] ) ;
2011-01-10 14:40:57 +01:00
xArray - > Put ( xSbxVar , static_cast < sal_uInt16 > ( i ) + 1 ) ;
2010-03-02 12:39:31 +00:00
// Enable passing by ref
if ( xSbxVar - > GetType ( ) ! = SbxVARIANT )
xSbxVar - > SetFlag ( SBX_FIXED ) ;
}
pMeth - > SetParameters ( xArray ) ;
SbxValues aVals ;
pMeth - > Get ( aVals ) ;
for ( sal_Int32 i = 0 ; i < aArguments . getLength ( ) ; + + i )
{
2011-01-10 14:40:57 +01:00
aArguments [ i ] = sbxToUnoValue ( xArray - > Get ( static_cast < sal_uInt16 > ( i ) + 1 ) ) ;
2010-03-02 12:39:31 +00:00
}
pMeth - > SetParameters ( NULL ) ;
}
else
{
SbxValues aVals ;
pMeth - > Get ( aVals ) ;
}
}
}
void SbUserFormModule : : triggerActivateEvent ( void )
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " **** entering SbUserFormModule::triggerActivate " ) ;
triggerMethod ( " UserForm_Activate " ) ;
SAL_INFO ( " basic " , " **** leaving SbUserFormModule::triggerActivate " ) ;
2010-03-02 12:39:31 +00:00
}
2010-07-06 18:07:29 +02:00
void SbUserFormModule : : triggerDeactivateEvent ( void )
2010-03-02 12:39:31 +00:00
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " **** SbUserFormModule::triggerDeactivate " ) ;
triggerMethod ( " Userform_Deactivate " ) ;
2010-03-02 12:39:31 +00:00
}
void SbUserFormModule : : triggerInitializeEvent ( void )
{
if ( mbInit )
return ;
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " **** SbUserFormModule::triggerInitializeEvent " ) ;
2012-11-06 23:34:23 -06:00
static OUString aInitMethodName ( " Userform_Initialize " ) ;
2010-03-02 12:39:31 +00:00
triggerMethod ( aInitMethodName ) ;
mbInit = true ;
}
void SbUserFormModule : : triggerTerminateEvent ( void )
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " **** SbUserFormModule::triggerTerminateEvent " ) ;
2012-11-06 23:34:23 -06:00
static OUString aTermMethodName ( " Userform_Terminate " ) ;
2010-03-02 12:39:31 +00:00
triggerMethod ( aTermMethodName ) ;
mbInit = false ;
}
2010-07-06 18:07:29 +02:00
void SbUserFormModule : : triggerLayoutEvent ( void )
{
2012-11-06 23:34:23 -06:00
static OUString aMethodName ( " Userform_Layout " ) ;
2010-07-06 18:07:29 +02:00
triggerMethod ( aMethodName ) ;
}
void SbUserFormModule : : triggerResizeEvent ( void )
{
2012-11-06 23:34:23 -06:00
static OUString aMethodName ( " Userform_Resize " ) ;
2010-07-06 18:07:29 +02:00
triggerMethod ( aMethodName ) ;
}
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 ,
2012-11-06 23:34:23 -06:00
const OUString & rName , const com : : sun : : star : : script : : ModuleInfo & mInfo , bool bIsVBACompat )
2010-06-15 20:02:53 +02:00
: SbUserFormModule ( rName , mInfo , bIsVBACompat )
, m_pParentModule ( pParentModule )
{
}
2012-11-06 23:34:23 -06:00
sal_Bool SbUserFormModuleInstance : : IsClass ( const OUString & rName ) const
2010-06-15 20:02:53 +02:00
{
2012-11-06 23:34:23 -06:00
sal_Bool bParentNameMatches = m_pParentModule - > GetName ( ) . equalsIgnoreAsciiCase ( rName ) ;
2011-01-10 14:40:57 +01:00
sal_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
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " ** load() " ) ;
2010-03-02 12:39:31 +00:00
// forces a load
if ( ! pDocObject )
InitObject ( ) ;
}
2010-10-19 23:45:24 -05:00
2010-03-02 12:39:31 +00:00
void SbUserFormModule : : Unload ( )
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " ** Unload() " ) ;
2010-03-02 12:39:31 +00:00
sal_Int8 nCancel = 0 ;
2011-03-25 10:40:25 +01:00
sal_Int8 nCloseMode = : : ooo : : vba : : VbQueryClose : : vbFormCode ;
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
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 )
// test agains 0 ( false ) and assume anything else is true
// ( 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
2013-01-09 00:14:10 +02:00
SbxVariable * pMeth = SbObjModule : : Find ( " UnloadObject " , SbxCLASS_METHOD ) ;
2010-03-02 12:39:31 +00:00
if ( pMeth )
{
2013-01-09 00:14:10 +02:00
SAL_INFO ( " basic " , " Attempting too 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
2010-07-06 18:07:29 +02:00
if ( m_DialogListener . get ( ) )
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 )
{
// we've either already got a dispose or we'er 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
2013-01-09 00:14:10 +02: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
2010-08-30 13:55:39 +02:00
void registerComponentToBeDisposedForBasic ( Reference < XComponent > xComponent , StarBASIC * pBasic ) ;
2010-03-02 12:39:31 +00:00
void SbUserFormModule : : InitObject ( )
{
try
{
2012-11-06 23:34:23 -06:00
OUString aHook ( " VBAGlobals " ) ;
2010-03-02 12:39:31 +00:00
SbUnoObject * pGlobs = ( SbUnoObject * ) GetParent ( ) - > Find ( aHook , SbxCLASS_DONTCARE ) ;
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
2012-11-06 23:34:23 -06:00
sDialogUrl = 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 ;
2013-04-07 12:06:47 +02:00
aArgs [ 3 ] < < = OUString ( GetParent ( ) - > GetName ( ) ) ;
2013-01-09 00:14:10 +02:00
pDocObject = new SbUnoObject ( GetName ( ) , uno : : makeAny ( 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!
2011-02-11 15:06:12 +01:00
StarBASIC * pParentBasic = NULL ;
SbxObject * pCurObject = this ;
do
2010-08-30 13:55:39 +02:00
{
2011-02-11 15:06:12 +01:00
SbxObject * pObjParent = pCurObject - > GetParent ( ) ;
pParentBasic = PTR_CAST ( StarBASIC , pObjParent ) ;
pCurObject = pObjParent ;
2010-08-30 13:55:39 +02:00
}
2011-02-11 15:06:12 +01:00
while ( pParentBasic = = NULL & & pCurObject ! = NULL ) ;
2010-08-30 13:55:39 +02:00
2013-01-09 00:14:10 +02:00
SAL_WARN_IF ( pParentBasic = = NULL , " 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
{
2012-01-15 16:15:08 +01:00
if ( ! pDocObject & & ! 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 )
{
2011-01-10 14:40:57 +01:00
bInvalid = sal_False ;
2000-09-18 15:18:56 +00:00
}
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: */