1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basic.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdio.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "sb.hxx" 34*cdf0e10cSrcweir #include <tools/rcid.h> 35*cdf0e10cSrcweir #include <tools/config.hxx> 36*cdf0e10cSrcweir #include <tools/stream.hxx> 37*cdf0e10cSrcweir #ifndef __RSC //autogen 38*cdf0e10cSrcweir #include <tools/errinf.hxx> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #include <basic/sbx.hxx> 41*cdf0e10cSrcweir #include <tools/list.hxx> 42*cdf0e10cSrcweir #include <tools/shl.hxx> 43*cdf0e10cSrcweir #include <tools/rc.hxx> 44*cdf0e10cSrcweir #include <vcl/svapp.hxx> 45*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 46*cdf0e10cSrcweir #include "sbunoobj.hxx" 47*cdf0e10cSrcweir #include "sbjsmeth.hxx" 48*cdf0e10cSrcweir #include "sbjsmod.hxx" 49*cdf0e10cSrcweir #include "sbintern.hxx" 50*cdf0e10cSrcweir #include "disas.hxx" 51*cdf0e10cSrcweir #include "runtime.hxx" 52*cdf0e10cSrcweir #include <basic/sbuno.hxx> 53*cdf0e10cSrcweir #include <basic/sbobjmod.hxx> 54*cdf0e10cSrcweir #include "stdobj.hxx" 55*cdf0e10cSrcweir #include "filefmt.hxx" 56*cdf0e10cSrcweir #include "sb.hrc" 57*cdf0e10cSrcweir #include <basrid.hxx> 58*cdf0e10cSrcweir #include <vos/mutex.hxx> 59*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 60*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/util/XCloseBroadcaster.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/util/XCloseListener.hpp> 63*cdf0e10cSrcweir #include "errobject.hxx" 64*cdf0e10cSrcweir #include <map> 65*cdf0e10cSrcweir #include <hash_map> 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir #include <com/sun/star/script/ModuleType.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/script/ModuleInfo.hpp> 69*cdf0e10cSrcweir using namespace ::com::sun::star::script; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // #pragma SW_SEGMENT_CLASS( SBASIC, SBASIC_CODE ) 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir SV_IMPL_VARARR(SbTextPortions,SbTextPortion) 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir TYPEINIT1(StarBASIC,SbxObject) 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir #define RTLNAME "@SBRTL" 78*cdf0e10cSrcweir // i#i68894# 79*cdf0e10cSrcweir using namespace ::com::sun::star; 80*cdf0e10cSrcweir using com::sun::star::uno::Reference; 81*cdf0e10cSrcweir using com::sun::star::uno::Any; 82*cdf0e10cSrcweir using com::sun::star::uno::UNO_QUERY; 83*cdf0e10cSrcweir using com::sun::star::lang::XMultiServiceFactory; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir const static String aThisComponent( RTL_CONSTASCII_USTRINGPARAM("ThisComponent") ); 86*cdf0e10cSrcweir const static String aVBAHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // ============================================================================ 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir class DocBasicItem : public ::cppu::WeakImplHelper1< util::XCloseListener > 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir public: 93*cdf0e10cSrcweir explicit DocBasicItem( StarBASIC& rDocBasic ); 94*cdf0e10cSrcweir virtual ~DocBasicItem(); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir inline const SbxObjectRef& getClassModules() const { return mxClassModules; } 97*cdf0e10cSrcweir inline bool isDocClosed() const { return mbDocClosed; } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir void clearDependingVarsOnDelete( StarBASIC& rDeletedBasic ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir void startListening(); 102*cdf0e10cSrcweir void stopListening(); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir virtual void SAL_CALL queryClosing( const lang::EventObject& rSource, sal_Bool bGetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException); 105*cdf0e10cSrcweir virtual void SAL_CALL notifyClosing( const lang::EventObject& rSource ) throw (uno::RuntimeException); 106*cdf0e10cSrcweir virtual void SAL_CALL disposing( const lang::EventObject& rSource ) throw (uno::RuntimeException); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir private: 109*cdf0e10cSrcweir StarBASIC& mrDocBasic; 110*cdf0e10cSrcweir SbxObjectRef mxClassModules; 111*cdf0e10cSrcweir bool mbDocClosed; 112*cdf0e10cSrcweir bool mbDisposed; 113*cdf0e10cSrcweir }; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir DocBasicItem::DocBasicItem( StarBASIC& rDocBasic ) : 118*cdf0e10cSrcweir mrDocBasic( rDocBasic ), 119*cdf0e10cSrcweir mxClassModules( new SbxObject( String() ) ), 120*cdf0e10cSrcweir mbDocClosed( false ), 121*cdf0e10cSrcweir mbDisposed( false ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir DocBasicItem::~DocBasicItem() 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir stopListening(); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir void DocBasicItem::clearDependingVarsOnDelete( StarBASIC& rDeletedBasic ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir mrDocBasic.implClearDependingVarsOnDelete( &rDeletedBasic ); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir void DocBasicItem::startListening() 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir Any aThisComp; 138*cdf0e10cSrcweir mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp ); 139*cdf0e10cSrcweir Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY ); 140*cdf0e10cSrcweir mbDisposed = !xCloseBC.is(); 141*cdf0e10cSrcweir if( xCloseBC.is() ) 142*cdf0e10cSrcweir try { xCloseBC->addCloseListener( this ); } catch( uno::Exception& ) {} 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir void DocBasicItem::stopListening() 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir if( mbDisposed ) return; 148*cdf0e10cSrcweir mbDisposed = true; 149*cdf0e10cSrcweir Any aThisComp; 150*cdf0e10cSrcweir mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp ); 151*cdf0e10cSrcweir Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY ); 152*cdf0e10cSrcweir if( xCloseBC.is() ) 153*cdf0e10cSrcweir try { xCloseBC->removeCloseListener( this ); } catch( uno::Exception& ) {} 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir void SAL_CALL DocBasicItem::queryClosing( const lang::EventObject& /*rSource*/, sal_Bool /*bGetsOwnership*/ ) throw (util::CloseVetoException, uno::RuntimeException) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir void SAL_CALL DocBasicItem::notifyClosing( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir stopListening(); 163*cdf0e10cSrcweir mbDocClosed = true; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir void SAL_CALL DocBasicItem::disposing( const lang::EventObject& /*rEvent*/ ) throw (uno::RuntimeException) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir stopListening(); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir namespace { 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir typedef ::rtl::Reference< DocBasicItem > DocBasicItemRef; 176*cdf0e10cSrcweir typedef std::map< const StarBASIC*, DocBasicItemRef > DocBasicItemMap; 177*cdf0e10cSrcweir static DocBasicItemMap GaDocBasicItems; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir const DocBasicItem* lclFindDocBasicItem( const StarBASIC* pDocBasic ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir DocBasicItemMap::iterator it = GaDocBasicItems.find( pDocBasic ); 182*cdf0e10cSrcweir return (it != GaDocBasicItems.end()) ? it->second.get() : 0; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir void lclInsertDocBasicItem( StarBASIC& rDocBasic ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir DocBasicItemRef& rxDocBasicItem = GaDocBasicItems[ &rDocBasic ]; 188*cdf0e10cSrcweir rxDocBasicItem.set( new DocBasicItem( rDocBasic ) ); 189*cdf0e10cSrcweir rxDocBasicItem->startListening(); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir void lclRemoveDocBasicItem( StarBASIC& rDocBasic ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir DocBasicItemMap::iterator it = GaDocBasicItems.find( &rDocBasic ); 195*cdf0e10cSrcweir if( it != GaDocBasicItems.end() ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir it->second->stopListening(); 198*cdf0e10cSrcweir GaDocBasicItems.erase( it ); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir DocBasicItemMap::iterator it_end = GaDocBasicItems.end(); 201*cdf0e10cSrcweir for( it = GaDocBasicItems.begin(); it != it_end; ++it ) 202*cdf0e10cSrcweir it->second->clearDependingVarsOnDelete( rDocBasic ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir StarBASIC* lclGetDocBasicForModule( SbModule* pModule ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir StarBASIC* pRetBasic = NULL; 208*cdf0e10cSrcweir SbxObject* pCurParent = pModule; 209*cdf0e10cSrcweir while( pCurParent->GetParent() != NULL ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir pCurParent = pCurParent->GetParent(); 212*cdf0e10cSrcweir StarBASIC* pDocBasic = PTR_CAST( StarBASIC, pCurParent ); 213*cdf0e10cSrcweir if( pDocBasic != NULL && pDocBasic->IsDocBasic() ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir pRetBasic = pDocBasic; 216*cdf0e10cSrcweir break; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir return pRetBasic; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir } // namespace 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // ============================================================================ 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir SbxObject* StarBASIC::getVBAGlobals( ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir if ( !pVBAGlobals ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir Any aThisDoc; 231*cdf0e10cSrcweir if ( GetUNOConstant("ThisComponent", aThisDoc) ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir Reference< XMultiServiceFactory > xDocFac( aThisDoc, UNO_QUERY ); 234*cdf0e10cSrcweir if ( xDocFac.is() ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir try 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir xDocFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) ); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir catch( Exception& ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir // Ignore 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir pVBAGlobals = (SbUnoObject*)Find( aVBAHook , SbxCLASS_DONTCARE ); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir return pVBAGlobals; 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // i#i68894# 252*cdf0e10cSrcweir SbxVariable* StarBASIC::VBAFind( const String& rName, SbxClassType t ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir if( rName == aThisComponent ) 255*cdf0e10cSrcweir return NULL; 256*cdf0e10cSrcweir // rename to init globals 257*cdf0e10cSrcweir if ( getVBAGlobals( ) ) 258*cdf0e10cSrcweir return pVBAGlobals->Find( rName, t ); 259*cdf0e10cSrcweir return NULL; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir // Create array for conversion SFX <-> VB error code 263*cdf0e10cSrcweir struct SFX_VB_ErrorItem 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir sal_uInt16 nErrorVB; 266*cdf0e10cSrcweir SbError nErrorSFX; 267*cdf0e10cSrcweir }; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir const SFX_VB_ErrorItem __FAR_DATA SFX_VB_ErrorTab[] = 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir { 1, SbERR_BASIC_EXCEPTION }, // #87844 Map exception to error code 1 272*cdf0e10cSrcweir { 2, SbERR_SYNTAX }, 273*cdf0e10cSrcweir { 3, SbERR_NO_GOSUB }, 274*cdf0e10cSrcweir { 4, SbERR_REDO_FROM_START }, 275*cdf0e10cSrcweir { 5, SbERR_BAD_ARGUMENT }, 276*cdf0e10cSrcweir { 6, SbERR_MATH_OVERFLOW }, 277*cdf0e10cSrcweir { 7, SbERR_NO_MEMORY }, 278*cdf0e10cSrcweir { 8, SbERR_ALREADY_DIM }, 279*cdf0e10cSrcweir { 9, SbERR_OUT_OF_RANGE }, 280*cdf0e10cSrcweir { 10, SbERR_DUPLICATE_DEF }, 281*cdf0e10cSrcweir { 11, SbERR_ZERODIV }, 282*cdf0e10cSrcweir { 12, SbERR_VAR_UNDEFINED }, 283*cdf0e10cSrcweir { 13, SbERR_CONVERSION }, 284*cdf0e10cSrcweir { 14, SbERR_BAD_PARAMETER }, 285*cdf0e10cSrcweir { 18, SbERR_USER_ABORT }, 286*cdf0e10cSrcweir { 20, SbERR_BAD_RESUME }, 287*cdf0e10cSrcweir { 28, SbERR_STACK_OVERFLOW }, 288*cdf0e10cSrcweir { 35, SbERR_PROC_UNDEFINED }, 289*cdf0e10cSrcweir { 48, SbERR_BAD_DLL_LOAD }, 290*cdf0e10cSrcweir { 49, SbERR_BAD_DLL_CALL }, 291*cdf0e10cSrcweir { 51, SbERR_INTERNAL_ERROR }, 292*cdf0e10cSrcweir { 52, SbERR_BAD_CHANNEL }, 293*cdf0e10cSrcweir { 53, SbERR_FILE_NOT_FOUND }, 294*cdf0e10cSrcweir { 54, SbERR_BAD_FILE_MODE }, 295*cdf0e10cSrcweir { 55, SbERR_FILE_ALREADY_OPEN }, 296*cdf0e10cSrcweir { 57, SbERR_IO_ERROR }, 297*cdf0e10cSrcweir { 58, SbERR_FILE_EXISTS }, 298*cdf0e10cSrcweir { 59, SbERR_BAD_RECORD_LENGTH }, 299*cdf0e10cSrcweir { 61, SbERR_DISK_FULL }, 300*cdf0e10cSrcweir { 62, SbERR_READ_PAST_EOF }, 301*cdf0e10cSrcweir { 63, SbERR_BAD_RECORD_NUMBER }, 302*cdf0e10cSrcweir { 67, SbERR_TOO_MANY_FILES }, 303*cdf0e10cSrcweir { 68, SbERR_NO_DEVICE }, 304*cdf0e10cSrcweir { 70, SbERR_ACCESS_DENIED }, 305*cdf0e10cSrcweir { 71, SbERR_NOT_READY }, 306*cdf0e10cSrcweir { 73, SbERR_NOT_IMPLEMENTED }, 307*cdf0e10cSrcweir { 74, SbERR_DIFFERENT_DRIVE }, 308*cdf0e10cSrcweir { 75, SbERR_ACCESS_ERROR }, 309*cdf0e10cSrcweir { 76, SbERR_PATH_NOT_FOUND }, 310*cdf0e10cSrcweir { 91, SbERR_NO_OBJECT }, 311*cdf0e10cSrcweir { 93, SbERR_BAD_PATTERN }, 312*cdf0e10cSrcweir { 94, SBERR_IS_NULL }, 313*cdf0e10cSrcweir { 250, SbERR_DDE_ERROR }, 314*cdf0e10cSrcweir { 280, SbERR_DDE_WAITINGACK }, 315*cdf0e10cSrcweir { 281, SbERR_DDE_OUTOFCHANNELS }, 316*cdf0e10cSrcweir { 282, SbERR_DDE_NO_RESPONSE }, 317*cdf0e10cSrcweir { 283, SbERR_DDE_MULT_RESPONSES }, 318*cdf0e10cSrcweir { 284, SbERR_DDE_CHANNEL_LOCKED }, 319*cdf0e10cSrcweir { 285, SbERR_DDE_NOTPROCESSED }, 320*cdf0e10cSrcweir { 286, SbERR_DDE_TIMEOUT }, 321*cdf0e10cSrcweir { 287, SbERR_DDE_USER_INTERRUPT }, 322*cdf0e10cSrcweir { 288, SbERR_DDE_BUSY }, 323*cdf0e10cSrcweir { 289, SbERR_DDE_NO_DATA }, 324*cdf0e10cSrcweir { 290, SbERR_DDE_WRONG_DATA_FORMAT }, 325*cdf0e10cSrcweir { 291, SbERR_DDE_PARTNER_QUIT }, 326*cdf0e10cSrcweir { 292, SbERR_DDE_CONV_CLOSED }, 327*cdf0e10cSrcweir { 293, SbERR_DDE_NO_CHANNEL }, 328*cdf0e10cSrcweir { 294, SbERR_DDE_INVALID_LINK }, 329*cdf0e10cSrcweir { 295, SbERR_DDE_QUEUE_OVERFLOW }, 330*cdf0e10cSrcweir { 296, SbERR_DDE_LINK_ALREADY_EST }, 331*cdf0e10cSrcweir { 297, SbERR_DDE_LINK_INV_TOPIC }, 332*cdf0e10cSrcweir { 298, SbERR_DDE_DLL_NOT_FOUND }, 333*cdf0e10cSrcweir { 323, SbERR_CANNOT_LOAD }, 334*cdf0e10cSrcweir { 341, SbERR_BAD_INDEX }, 335*cdf0e10cSrcweir { 366, SbERR_NO_ACTIVE_OBJECT }, 336*cdf0e10cSrcweir { 380, SbERR_BAD_PROP_VALUE }, 337*cdf0e10cSrcweir { 382, SbERR_PROP_READONLY }, 338*cdf0e10cSrcweir { 394, SbERR_PROP_WRITEONLY }, 339*cdf0e10cSrcweir { 420, SbERR_INVALID_OBJECT }, 340*cdf0e10cSrcweir { 423, SbERR_NO_METHOD }, 341*cdf0e10cSrcweir { 424, SbERR_NEEDS_OBJECT }, 342*cdf0e10cSrcweir { 425, SbERR_INVALID_USAGE_OBJECT }, 343*cdf0e10cSrcweir { 430, SbERR_NO_OLE }, 344*cdf0e10cSrcweir { 438, SbERR_BAD_METHOD }, 345*cdf0e10cSrcweir { 440, SbERR_OLE_ERROR }, 346*cdf0e10cSrcweir { 445, SbERR_BAD_ACTION }, 347*cdf0e10cSrcweir { 446, SbERR_NO_NAMED_ARGS }, 348*cdf0e10cSrcweir { 447, SbERR_BAD_LOCALE }, 349*cdf0e10cSrcweir { 448, SbERR_NAMED_NOT_FOUND }, 350*cdf0e10cSrcweir { 449, SbERR_NOT_OPTIONAL }, 351*cdf0e10cSrcweir { 450, SbERR_WRONG_ARGS }, 352*cdf0e10cSrcweir { 451, SbERR_NOT_A_COLL }, 353*cdf0e10cSrcweir { 452, SbERR_BAD_ORDINAL }, 354*cdf0e10cSrcweir { 453, SbERR_DLLPROC_NOT_FOUND }, 355*cdf0e10cSrcweir { 460, SbERR_BAD_CLIPBD_FORMAT }, 356*cdf0e10cSrcweir { 951, SbERR_UNEXPECTED }, 357*cdf0e10cSrcweir { 952, SbERR_EXPECTED }, 358*cdf0e10cSrcweir { 953, SbERR_SYMBOL_EXPECTED }, 359*cdf0e10cSrcweir { 954, SbERR_VAR_EXPECTED }, 360*cdf0e10cSrcweir { 955, SbERR_LABEL_EXPECTED }, 361*cdf0e10cSrcweir { 956, SbERR_LVALUE_EXPECTED }, 362*cdf0e10cSrcweir { 957, SbERR_VAR_DEFINED }, 363*cdf0e10cSrcweir { 958, SbERR_PROC_DEFINED }, 364*cdf0e10cSrcweir { 959, SbERR_LABEL_DEFINED }, 365*cdf0e10cSrcweir { 960, SbERR_UNDEF_VAR }, 366*cdf0e10cSrcweir { 961, SbERR_UNDEF_ARRAY }, 367*cdf0e10cSrcweir { 962, SbERR_UNDEF_PROC }, 368*cdf0e10cSrcweir { 963, SbERR_UNDEF_LABEL }, 369*cdf0e10cSrcweir { 964, SbERR_UNDEF_TYPE }, 370*cdf0e10cSrcweir { 965, SbERR_BAD_EXIT }, 371*cdf0e10cSrcweir { 966, SbERR_BAD_BLOCK }, 372*cdf0e10cSrcweir { 967, SbERR_BAD_BRACKETS }, 373*cdf0e10cSrcweir { 968, SbERR_BAD_DECLARATION }, 374*cdf0e10cSrcweir { 969, SbERR_BAD_PARAMETERS }, 375*cdf0e10cSrcweir { 970, SbERR_BAD_CHAR_IN_NUMBER }, 376*cdf0e10cSrcweir { 971, SbERR_MUST_HAVE_DIMS }, 377*cdf0e10cSrcweir { 972, SbERR_NO_IF }, 378*cdf0e10cSrcweir { 973, SbERR_NOT_IN_SUBR }, 379*cdf0e10cSrcweir { 974, SbERR_NOT_IN_MAIN }, 380*cdf0e10cSrcweir { 975, SbERR_WRONG_DIMS }, 381*cdf0e10cSrcweir { 976, SbERR_BAD_OPTION }, 382*cdf0e10cSrcweir { 977, SbERR_CONSTANT_REDECLARED }, 383*cdf0e10cSrcweir { 978, SbERR_PROG_TOO_LARGE }, 384*cdf0e10cSrcweir { 979, SbERR_NO_STRINGS_ARRAYS }, 385*cdf0e10cSrcweir { 1000, SbERR_PROPERTY_NOT_FOUND }, 386*cdf0e10cSrcweir { 1001, SbERR_METHOD_NOT_FOUND }, 387*cdf0e10cSrcweir { 1002, SbERR_ARG_MISSING }, 388*cdf0e10cSrcweir { 1003, SbERR_BAD_NUMBER_OF_ARGS }, 389*cdf0e10cSrcweir { 1004, SbERR_METHOD_FAILED }, 390*cdf0e10cSrcweir { 1005, SbERR_SETPROP_FAILED }, 391*cdf0e10cSrcweir { 1006, SbERR_GETPROP_FAILED }, 392*cdf0e10cSrcweir { 1007, SbERR_BASIC_COMPAT }, 393*cdf0e10cSrcweir { 0xFFFF, 0xFFFFFFFFL } // End mark 394*cdf0e10cSrcweir }; 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir // The StarBASIC factory is a hack. When a SbModule is created, its pointer 397*cdf0e10cSrcweir // is saved and given to the following SbProperties/SbMethods. This restores 398*cdf0e10cSrcweir // the Modul-relationshop. But it works only when a modul is loaded. 399*cdf0e10cSrcweir // Can cause troubles with separately loaded properties! 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir SbxBase* SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir if( nCreator == SBXCR_SBX ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir String aEmpty; 406*cdf0e10cSrcweir switch( nSbxId ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir case SBXID_BASIC: 409*cdf0e10cSrcweir return new StarBASIC( NULL ); 410*cdf0e10cSrcweir case SBXID_BASICMOD: 411*cdf0e10cSrcweir return new SbModule( aEmpty ); 412*cdf0e10cSrcweir case SBXID_BASICPROP: 413*cdf0e10cSrcweir return new SbProperty( aEmpty, SbxVARIANT, NULL ); 414*cdf0e10cSrcweir case SBXID_BASICMETHOD: 415*cdf0e10cSrcweir return new SbMethod( aEmpty, SbxVARIANT, NULL ); 416*cdf0e10cSrcweir case SBXID_JSCRIPTMOD: 417*cdf0e10cSrcweir return new SbJScriptModule( aEmpty ); 418*cdf0e10cSrcweir case SBXID_JSCRIPTMETH: 419*cdf0e10cSrcweir return new SbJScriptMethod( aEmpty, SbxVARIANT, NULL ); 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir return NULL; 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir SbxObject* SbiFactory::CreateObject( const String& rClass ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir if( rClass.EqualsIgnoreCaseAscii( "StarBASIC" ) ) 428*cdf0e10cSrcweir return new StarBASIC( NULL ); 429*cdf0e10cSrcweir else 430*cdf0e10cSrcweir if( rClass.EqualsIgnoreCaseAscii( "StarBASICModule" ) ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir String aEmpty; 433*cdf0e10cSrcweir return new SbModule( aEmpty ); 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir else 436*cdf0e10cSrcweir if( rClass.EqualsIgnoreCaseAscii( "Collection" ) ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") ); 439*cdf0e10cSrcweir return new BasicCollection( aCollectionName ); 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir else 442*cdf0e10cSrcweir if( rClass.EqualsIgnoreCaseAscii( "FileSystemObject" ) ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir try 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW ); 447*cdf0e10cSrcweir ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.FileSystemObject" ) ); 448*cdf0e10cSrcweir Reference< XInterface > xInterface( xFactory->createInstance( aServiceName ), UNO_SET_THROW ); 449*cdf0e10cSrcweir return new SbUnoObject( aServiceName, uno::makeAny( xInterface ) ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir catch( Exception& ) 452*cdf0e10cSrcweir {} 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir return NULL; 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir // Factory class to create OLE objects 460*cdf0e10cSrcweir class SbOLEFactory : public SbxFactory 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir public: 463*cdf0e10cSrcweir virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX ); 464*cdf0e10cSrcweir virtual SbxObject* CreateObject( const String& ); 465*cdf0e10cSrcweir }; 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir SbxBase* SbOLEFactory::Create( sal_uInt16, sal_uInt32 ) 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir // Not supported 470*cdf0e10cSrcweir return NULL; 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir SbUnoObject* createOLEObject_Impl( const String& aType ); // sbunoobj.cxx 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir SbxObject* SbOLEFactory::CreateObject( const String& rClassName ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir SbxObject* pRet = createOLEObject_Impl( rClassName ); 478*cdf0e10cSrcweir return pRet; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir //======================================================================== 483*cdf0e10cSrcweir // SbFormFactory, show user forms by: dim as new <user form name> 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir class SbFormFactory : public SbxFactory 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir public: 488*cdf0e10cSrcweir virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX ); 489*cdf0e10cSrcweir virtual SbxObject* CreateObject( const String& ); 490*cdf0e10cSrcweir }; 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir SbxBase* SbFormFactory::Create( sal_uInt16, sal_uInt32 ) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir // Not supported 495*cdf0e10cSrcweir return NULL; 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir SbxObject* SbFormFactory::CreateObject( const String& rClassName ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir if( SbModule* pMod = pMOD ) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir if( SbxVariable* pVar = pMod->Find( rClassName, SbxCLASS_OBJECT ) ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir if( SbUserFormModule* pFormModule = PTR_CAST( SbUserFormModule, pVar->GetObject() ) ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir bool bInitState = pFormModule->getInitState(); 507*cdf0e10cSrcweir if( bInitState ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir // Not the first instantiate, reset 510*cdf0e10cSrcweir bool bTriggerTerminateEvent = false; 511*cdf0e10cSrcweir pFormModule->ResetApiObj( bTriggerTerminateEvent ); 512*cdf0e10cSrcweir pFormModule->setInitState( false ); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir else 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir pFormModule->Load(); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir return pFormModule->CreateInstance(); 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir return 0; 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir //======================================================================== 527*cdf0e10cSrcweir // SbTypeFactory 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir SbxObject* pRet = new SbxObject( rTypeObj ); 532*cdf0e10cSrcweir pRet->PutObject( pRet ); 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir // Copy the properties, not only the reference to them 535*cdf0e10cSrcweir SbxArray* pProps = pRet->GetProperties(); 536*cdf0e10cSrcweir sal_uInt32 nCount = pProps->Count32(); 537*cdf0e10cSrcweir for( sal_uInt32 i = 0 ; i < nCount ; i++ ) 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir SbxVariable* pVar = pProps->Get32( i ); 540*cdf0e10cSrcweir SbxProperty* pProp = PTR_CAST( SbxProperty, pVar ); 541*cdf0e10cSrcweir if( pProp ) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir SbxProperty* pNewProp = new SbxProperty( *pProp ); 544*cdf0e10cSrcweir SbxDataType eVarType = pVar->GetType(); 545*cdf0e10cSrcweir if( eVarType & SbxARRAY ) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir SbxBase* pParObj = pVar->GetObject(); 548*cdf0e10cSrcweir SbxDimArray* pSource = PTR_CAST(SbxDimArray,pParObj); 549*cdf0e10cSrcweir SbxDimArray* pDest = new SbxDimArray( pVar->GetType() ); 550*cdf0e10cSrcweir sal_Int32 lb = 0; 551*cdf0e10cSrcweir sal_Int32 ub = 0; 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir pDest->setHasFixedSize( pSource->hasFixedSize() ); 554*cdf0e10cSrcweir if ( pSource->GetDims() && pSource->hasFixedSize() ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir for ( sal_Int32 j = 1 ; j <= pSource->GetDims(); ++j ) 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir pSource->GetDim32( (sal_Int32)j, lb, ub ); 559*cdf0e10cSrcweir pDest->AddDim32( lb, ub ); 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir else 563*cdf0e10cSrcweir pDest->unoAddDim( 0, -1 ); // variant array 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir sal_uInt16 nSavFlags = pVar->GetFlags(); 566*cdf0e10cSrcweir pNewProp->ResetFlag( SBX_FIXED ); 567*cdf0e10cSrcweir // need to reset the FIXED flag 568*cdf0e10cSrcweir // when calling PutObject ( because the type will not match Object ) 569*cdf0e10cSrcweir pNewProp->PutObject( pDest ); 570*cdf0e10cSrcweir pNewProp->SetFlags( nSavFlags ); 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir if( eVarType == SbxOBJECT ) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir SbxBase* pObjBase = pVar->GetObject(); 575*cdf0e10cSrcweir SbxObject* pSrcObj = PTR_CAST(SbxObject,pObjBase); 576*cdf0e10cSrcweir SbxObject* pDestObj = NULL; 577*cdf0e10cSrcweir if( pSrcObj != NULL ) 578*cdf0e10cSrcweir pDestObj = cloneTypeObjectImpl( *pSrcObj ); 579*cdf0e10cSrcweir pNewProp->PutObject( pDestObj ); 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir pProps->PutDirect( pNewProp, i ); 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir return pRet; 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir // Factory class to create user defined objects (type command) 588*cdf0e10cSrcweir class SbTypeFactory : public SbxFactory 589*cdf0e10cSrcweir { 590*cdf0e10cSrcweir public: 591*cdf0e10cSrcweir virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 = SBXCR_SBX ); 592*cdf0e10cSrcweir virtual SbxObject* CreateObject( const String& ); 593*cdf0e10cSrcweir }; 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir SbxBase* SbTypeFactory::Create( sal_uInt16, sal_uInt32 ) 596*cdf0e10cSrcweir { 597*cdf0e10cSrcweir // Not supported 598*cdf0e10cSrcweir return NULL; 599*cdf0e10cSrcweir } 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir SbxObject* SbTypeFactory::CreateObject( const String& rClassName ) 602*cdf0e10cSrcweir { 603*cdf0e10cSrcweir SbxObject* pRet = NULL; 604*cdf0e10cSrcweir SbModule* pMod = pMOD; 605*cdf0e10cSrcweir if( pMod ) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir const SbxObject* pObj = pMod->FindType( rClassName ); 608*cdf0e10cSrcweir if( pObj ) 609*cdf0e10cSrcweir pRet = cloneTypeObjectImpl( *pObj ); 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir return pRet; 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir SbxObject* createUserTypeImpl( const String& rClassName ) 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir SbxObject* pRetObj = pTYPEFAC->CreateObject( rClassName ); 617*cdf0e10cSrcweir return pRetObj; 618*cdf0e10cSrcweir } 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir TYPEINIT1(SbClassModuleObject,SbModule) 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule ) 624*cdf0e10cSrcweir : SbModule( pClassModule->GetName() ) 625*cdf0e10cSrcweir , mpClassModule( pClassModule ) 626*cdf0e10cSrcweir , mbInitializeEventDone( false ) 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir aOUSource = pClassModule->aOUSource; 629*cdf0e10cSrcweir aComment = pClassModule->aComment; 630*cdf0e10cSrcweir pImage = pClassModule->pImage; 631*cdf0e10cSrcweir pBreaks = pClassModule->pBreaks; 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir SetClassName( pClassModule->GetName() ); 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir // Allow search only internally 636*cdf0e10cSrcweir ResetFlag( SBX_GBLSEARCH ); 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir // Copy the methods from original class module 639*cdf0e10cSrcweir SbxArray* pClassMethods = pClassModule->GetMethods(); 640*cdf0e10cSrcweir sal_uInt32 nMethodCount = pClassMethods->Count32(); 641*cdf0e10cSrcweir sal_uInt32 i; 642*cdf0e10cSrcweir for( i = 0 ; i < nMethodCount ; i++ ) 643*cdf0e10cSrcweir { 644*cdf0e10cSrcweir SbxVariable* pVar = pClassMethods->Get32( i ); 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir // Exclude SbIfaceMapperMethod to copy them in a second step 647*cdf0e10cSrcweir SbIfaceMapperMethod* pIfaceMethod = PTR_CAST( SbIfaceMapperMethod, pVar ); 648*cdf0e10cSrcweir if( !pIfaceMethod ) 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir SbMethod* pMethod = PTR_CAST(SbMethod, pVar ); 651*cdf0e10cSrcweir if( pMethod ) 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir sal_uInt16 nFlags_ = pMethod->GetFlags(); 654*cdf0e10cSrcweir pMethod->SetFlag( SBX_NO_BROADCAST ); 655*cdf0e10cSrcweir SbMethod* pNewMethod = new SbMethod( *pMethod ); 656*cdf0e10cSrcweir pNewMethod->ResetFlag( SBX_NO_BROADCAST ); 657*cdf0e10cSrcweir pMethod->SetFlags( nFlags_ ); 658*cdf0e10cSrcweir pNewMethod->pMod = this; 659*cdf0e10cSrcweir pNewMethod->SetParent( this ); 660*cdf0e10cSrcweir pMethods->PutDirect( pNewMethod, i ); 661*cdf0e10cSrcweir StartListening( pNewMethod->GetBroadcaster(), sal_True ); 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir // Copy SbIfaceMapperMethod in a second step to ensure that 667*cdf0e10cSrcweir // the corresponding base methods have already been copied 668*cdf0e10cSrcweir for( i = 0 ; i < nMethodCount ; i++ ) 669*cdf0e10cSrcweir { 670*cdf0e10cSrcweir SbxVariable* pVar = pClassMethods->Get32( i ); 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir SbIfaceMapperMethod* pIfaceMethod = PTR_CAST( SbIfaceMapperMethod, pVar ); 673*cdf0e10cSrcweir if( pIfaceMethod ) 674*cdf0e10cSrcweir { 675*cdf0e10cSrcweir SbMethod* pImplMethod = pIfaceMethod->getImplMethod(); 676*cdf0e10cSrcweir if( !pImplMethod ) 677*cdf0e10cSrcweir { 678*cdf0e10cSrcweir DBG_ERROR( "No ImplMethod" ); 679*cdf0e10cSrcweir continue; 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir // Search for own copy of ImplMethod 683*cdf0e10cSrcweir String aImplMethodName = pImplMethod->GetName(); 684*cdf0e10cSrcweir SbxVariable* p = pMethods->Find( aImplMethodName, SbxCLASS_METHOD ); 685*cdf0e10cSrcweir SbMethod* pImplMethodCopy = p ? PTR_CAST(SbMethod,p) : NULL; 686*cdf0e10cSrcweir if( !pImplMethodCopy ) 687*cdf0e10cSrcweir { 688*cdf0e10cSrcweir DBG_ERROR( "Found no ImplMethod copy" ); 689*cdf0e10cSrcweir continue; 690*cdf0e10cSrcweir } 691*cdf0e10cSrcweir SbIfaceMapperMethod* pNewIfaceMethod = 692*cdf0e10cSrcweir new SbIfaceMapperMethod( pIfaceMethod->GetName(), pImplMethodCopy ); 693*cdf0e10cSrcweir pMethods->PutDirect( pNewIfaceMethod, i ); 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir // Copy the properties from original class module 698*cdf0e10cSrcweir SbxArray* pClassProps = pClassModule->GetProperties(); 699*cdf0e10cSrcweir sal_uInt32 nPropertyCount = pClassProps->Count32(); 700*cdf0e10cSrcweir for( i = 0 ; i < nPropertyCount ; i++ ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir SbxVariable* pVar = pClassProps->Get32( i ); 703*cdf0e10cSrcweir SbProcedureProperty* pProcedureProp = PTR_CAST( SbProcedureProperty, pVar ); 704*cdf0e10cSrcweir if( pProcedureProp ) 705*cdf0e10cSrcweir { 706*cdf0e10cSrcweir sal_uInt16 nFlags_ = pProcedureProp->GetFlags(); 707*cdf0e10cSrcweir pProcedureProp->SetFlag( SBX_NO_BROADCAST ); 708*cdf0e10cSrcweir SbProcedureProperty* pNewProp = new SbProcedureProperty 709*cdf0e10cSrcweir ( pProcedureProp->GetName(), pProcedureProp->GetType() ); 710*cdf0e10cSrcweir // ( pProcedureProp->GetName(), pProcedureProp->GetType(), this ); 711*cdf0e10cSrcweir pNewProp->SetFlags( nFlags_ ); // Copy flags 712*cdf0e10cSrcweir pNewProp->ResetFlag( SBX_NO_BROADCAST ); // except the Broadcast if it was set 713*cdf0e10cSrcweir pProcedureProp->SetFlags( nFlags_ ); 714*cdf0e10cSrcweir pProps->PutDirect( pNewProp, i ); 715*cdf0e10cSrcweir StartListening( pNewProp->GetBroadcaster(), sal_True ); 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir else 718*cdf0e10cSrcweir { 719*cdf0e10cSrcweir SbxProperty* pProp = PTR_CAST( SbxProperty, pVar ); 720*cdf0e10cSrcweir if( pProp ) 721*cdf0e10cSrcweir { 722*cdf0e10cSrcweir sal_uInt16 nFlags_ = pProp->GetFlags(); 723*cdf0e10cSrcweir pProp->SetFlag( SBX_NO_BROADCAST ); 724*cdf0e10cSrcweir SbxProperty* pNewProp = new SbxProperty( *pProp ); 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir // Special handling for modules instances and collections, they need 727*cdf0e10cSrcweir // to be instantiated, otherwise all refer to the same base object 728*cdf0e10cSrcweir SbxDataType eVarType = pProp->GetType(); 729*cdf0e10cSrcweir if( eVarType == SbxOBJECT ) 730*cdf0e10cSrcweir { 731*cdf0e10cSrcweir SbxBase* pObjBase = pProp->GetObject(); 732*cdf0e10cSrcweir SbxObject* pObj = PTR_CAST(SbxObject,pObjBase); 733*cdf0e10cSrcweir if( pObj != NULL ) 734*cdf0e10cSrcweir { 735*cdf0e10cSrcweir String aObjClass = pObj->GetClassName(); 736*cdf0e10cSrcweir 737*cdf0e10cSrcweir SbClassModuleObject* pClassModuleObj = PTR_CAST(SbClassModuleObject,pObjBase); 738*cdf0e10cSrcweir if( pClassModuleObj != NULL ) 739*cdf0e10cSrcweir { 740*cdf0e10cSrcweir SbModule* pLclClassModule = pClassModuleObj->getClassModule(); 741*cdf0e10cSrcweir SbClassModuleObject* pNewObj = new SbClassModuleObject( pLclClassModule ); 742*cdf0e10cSrcweir pNewObj->SetName( pProp->GetName() ); 743*cdf0e10cSrcweir pNewObj->SetParent( pLclClassModule->pParent ); 744*cdf0e10cSrcweir pNewProp->PutObject( pNewObj ); 745*cdf0e10cSrcweir } 746*cdf0e10cSrcweir else if( aObjClass.EqualsIgnoreCaseAscii( "Collection" ) ) 747*cdf0e10cSrcweir { 748*cdf0e10cSrcweir String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") ); 749*cdf0e10cSrcweir BasicCollection* pNewCollection = new BasicCollection( aCollectionName ); 750*cdf0e10cSrcweir pNewCollection->SetName( pProp->GetName() ); 751*cdf0e10cSrcweir pNewCollection->SetParent( pClassModule->pParent ); 752*cdf0e10cSrcweir pNewProp->PutObject( pNewCollection ); 753*cdf0e10cSrcweir } 754*cdf0e10cSrcweir } 755*cdf0e10cSrcweir } 756*cdf0e10cSrcweir 757*cdf0e10cSrcweir pNewProp->ResetFlag( SBX_NO_BROADCAST ); 758*cdf0e10cSrcweir pNewProp->SetParent( this ); 759*cdf0e10cSrcweir pProps->PutDirect( pNewProp, i ); 760*cdf0e10cSrcweir pProp->SetFlags( nFlags_ ); 761*cdf0e10cSrcweir } 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir } 764*cdf0e10cSrcweir SetModuleType( ModuleType::CLASS ); 765*cdf0e10cSrcweir mbVBACompat = pClassModule->mbVBACompat; 766*cdf0e10cSrcweir } 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir SbClassModuleObject::~SbClassModuleObject() 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir // do not trigger termination event when document is already closed 771*cdf0e10cSrcweir if( StarBASIC::IsRunning() ) 772*cdf0e10cSrcweir if( StarBASIC* pDocBasic = lclGetDocBasicForModule( this ) ) 773*cdf0e10cSrcweir if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) ) 774*cdf0e10cSrcweir if( !pDocBasicItem->isDocClosed() ) 775*cdf0e10cSrcweir triggerTerminateEvent(); 776*cdf0e10cSrcweir 777*cdf0e10cSrcweir // Must be deleted by base class dtor because this data 778*cdf0e10cSrcweir // is not owned by the SbClassModuleObject object 779*cdf0e10cSrcweir pImage = NULL; 780*cdf0e10cSrcweir pBreaks = NULL; 781*cdf0e10cSrcweir } 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir void SbClassModuleObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, 784*cdf0e10cSrcweir const SfxHint& rHint, const TypeId& rHintType ) 785*cdf0e10cSrcweir { 786*cdf0e10cSrcweir handleProcedureProperties( rBC, rHint ); 787*cdf0e10cSrcweir } 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir SbxVariable* SbClassModuleObject::Find( const XubString& rName, SbxClassType t ) 790*cdf0e10cSrcweir { 791*cdf0e10cSrcweir SbxVariable* pRes = SbxObject::Find( rName, t ); 792*cdf0e10cSrcweir if( pRes ) 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir triggerInitializeEvent(); 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir SbIfaceMapperMethod* pIfaceMapperMethod = PTR_CAST(SbIfaceMapperMethod,pRes); 797*cdf0e10cSrcweir if( pIfaceMapperMethod ) 798*cdf0e10cSrcweir { 799*cdf0e10cSrcweir pRes = pIfaceMapperMethod->getImplMethod(); 800*cdf0e10cSrcweir pRes->SetFlag( SBX_EXTFOUND ); 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir return pRes; 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir void SbClassModuleObject::triggerInitializeEvent( void ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir static String aInitMethodName( RTL_CONSTASCII_USTRINGPARAM("Class_Initialize") ); 809*cdf0e10cSrcweir 810*cdf0e10cSrcweir if( mbInitializeEventDone ) 811*cdf0e10cSrcweir return; 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir mbInitializeEventDone = true; 814*cdf0e10cSrcweir 815*cdf0e10cSrcweir // Search method 816*cdf0e10cSrcweir SbxVariable* pMeth = SbxObject::Find( aInitMethodName, SbxCLASS_METHOD ); 817*cdf0e10cSrcweir if( pMeth ) 818*cdf0e10cSrcweir { 819*cdf0e10cSrcweir SbxValues aVals; 820*cdf0e10cSrcweir pMeth->Get( aVals ); 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir 824*cdf0e10cSrcweir void SbClassModuleObject::triggerTerminateEvent( void ) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir static String aTermMethodName( RTL_CONSTASCII_USTRINGPARAM("Class_Terminate") ); 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir if( !mbInitializeEventDone || GetSbData()->bRunInit ) 829*cdf0e10cSrcweir return; 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir // Search method 832*cdf0e10cSrcweir SbxVariable* pMeth = SbxObject::Find( aTermMethodName, SbxCLASS_METHOD ); 833*cdf0e10cSrcweir if( pMeth ) 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir SbxValues aVals; 836*cdf0e10cSrcweir pMeth->Get( aVals ); 837*cdf0e10cSrcweir } 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir 841*cdf0e10cSrcweir SbClassData::SbClassData( void ) 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir mxIfaces = new SbxArray(); 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir void SbClassData::clear( void ) 847*cdf0e10cSrcweir { 848*cdf0e10cSrcweir mxIfaces->Clear(); 849*cdf0e10cSrcweir maRequiredTypes.clear(); 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir SbClassFactory::SbClassFactory( void ) 853*cdf0e10cSrcweir { 854*cdf0e10cSrcweir String aDummyName; 855*cdf0e10cSrcweir xClassModules = new SbxObject( aDummyName ); 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir SbClassFactory::~SbClassFactory() 859*cdf0e10cSrcweir {} 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir void SbClassFactory::AddClassModule( SbModule* pClassModule ) 862*cdf0e10cSrcweir { 863*cdf0e10cSrcweir SbxObjectRef xToUseClassModules = xClassModules; 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir if( StarBASIC* pDocBasic = lclGetDocBasicForModule( pClassModule ) ) 866*cdf0e10cSrcweir if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) ) 867*cdf0e10cSrcweir xToUseClassModules = pDocBasicItem->getClassModules(); 868*cdf0e10cSrcweir 869*cdf0e10cSrcweir SbxObject* pParent = pClassModule->GetParent(); 870*cdf0e10cSrcweir xToUseClassModules->Insert( pClassModule ); 871*cdf0e10cSrcweir pClassModule->SetParent( pParent ); 872*cdf0e10cSrcweir } 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir void SbClassFactory::RemoveClassModule( SbModule* pClassModule ) 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir xClassModules->Remove( pClassModule ); 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir 879*cdf0e10cSrcweir SbxBase* SbClassFactory::Create( sal_uInt16, sal_uInt32 ) 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir // Not supported 882*cdf0e10cSrcweir return NULL; 883*cdf0e10cSrcweir } 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir SbxObject* SbClassFactory::CreateObject( const String& rClassName ) 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir SbxObjectRef xToUseClassModules = xClassModules; 888*cdf0e10cSrcweir 889*cdf0e10cSrcweir if( SbModule* pMod = pMOD ) 890*cdf0e10cSrcweir if( StarBASIC* pDocBasic = lclGetDocBasicForModule( pMod ) ) 891*cdf0e10cSrcweir if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) ) 892*cdf0e10cSrcweir xToUseClassModules = pDocBasicItem->getClassModules(); 893*cdf0e10cSrcweir 894*cdf0e10cSrcweir SbxVariable* pVar = xToUseClassModules->Find( rClassName, SbxCLASS_OBJECT ); 895*cdf0e10cSrcweir SbxObject* pRet = NULL; 896*cdf0e10cSrcweir if( pVar ) 897*cdf0e10cSrcweir { 898*cdf0e10cSrcweir SbModule* pVarMod = (SbModule*)pVar; 899*cdf0e10cSrcweir pRet = new SbClassModuleObject( pVarMod ); 900*cdf0e10cSrcweir } 901*cdf0e10cSrcweir return pRet; 902*cdf0e10cSrcweir } 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir SbModule* SbClassFactory::FindClass( const String& rClassName ) 905*cdf0e10cSrcweir { 906*cdf0e10cSrcweir SbxVariable* pVar = xClassModules->Find( rClassName, SbxCLASS_DONTCARE ); 907*cdf0e10cSrcweir SbModule* pMod = pVar ? (SbModule*)pVar : NULL; 908*cdf0e10cSrcweir return pMod; 909*cdf0e10cSrcweir } 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir StarBASIC::StarBASIC( StarBASIC* p, sal_Bool bIsDocBasic ) 912*cdf0e10cSrcweir : SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASIC") ) ), bDocBasic( bIsDocBasic ) 913*cdf0e10cSrcweir { 914*cdf0e10cSrcweir SetParent( p ); 915*cdf0e10cSrcweir pLibInfo = NULL; 916*cdf0e10cSrcweir bNoRtl = bBreak = sal_False; 917*cdf0e10cSrcweir bVBAEnabled = sal_False; 918*cdf0e10cSrcweir pModules = new SbxArray; 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir if( !GetSbData()->nInst++ ) 921*cdf0e10cSrcweir { 922*cdf0e10cSrcweir pSBFAC = new SbiFactory; 923*cdf0e10cSrcweir AddFactory( pSBFAC ); 924*cdf0e10cSrcweir pTYPEFAC = new SbTypeFactory; 925*cdf0e10cSrcweir AddFactory( pTYPEFAC ); 926*cdf0e10cSrcweir pCLASSFAC = new SbClassFactory; 927*cdf0e10cSrcweir AddFactory( pCLASSFAC ); 928*cdf0e10cSrcweir pOLEFAC = new SbOLEFactory; 929*cdf0e10cSrcweir AddFactory( pOLEFAC ); 930*cdf0e10cSrcweir pFORMFAC = new SbFormFactory; 931*cdf0e10cSrcweir AddFactory( pFORMFAC ); 932*cdf0e10cSrcweir pUNOFAC = new SbUnoFactory; 933*cdf0e10cSrcweir AddFactory( pUNOFAC ); 934*cdf0e10cSrcweir } 935*cdf0e10cSrcweir pRtl = new SbiStdObject( String( RTL_CONSTASCII_USTRINGPARAM(RTLNAME) ), this ); 936*cdf0e10cSrcweir // Search via StarBasic is always global 937*cdf0e10cSrcweir SetFlag( SBX_GBLSEARCH ); 938*cdf0e10cSrcweir pVBAGlobals = NULL; 939*cdf0e10cSrcweir bQuit = sal_False; 940*cdf0e10cSrcweir 941*cdf0e10cSrcweir if( bDocBasic ) 942*cdf0e10cSrcweir lclInsertDocBasicItem( *this ); 943*cdf0e10cSrcweir } 944*cdf0e10cSrcweir 945*cdf0e10cSrcweir // #51727 Override SetModified so that the modified state 946*cdf0e10cSrcweir // is not given to the parent 947*cdf0e10cSrcweir void StarBASIC::SetModified( sal_Bool b ) 948*cdf0e10cSrcweir { 949*cdf0e10cSrcweir SbxBase::SetModified( b ); 950*cdf0e10cSrcweir } 951*cdf0e10cSrcweir 952*cdf0e10cSrcweir extern void lcl_closeTraceFile(); 953*cdf0e10cSrcweir 954*cdf0e10cSrcweir StarBASIC::~StarBASIC() 955*cdf0e10cSrcweir { 956*cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC 957*cdf0e10cSrcweir lcl_closeTraceFile(); 958*cdf0e10cSrcweir #endif 959*cdf0e10cSrcweir 960*cdf0e10cSrcweir // Needs to be first action as it can trigger events 961*cdf0e10cSrcweir disposeComVariablesForBasic( this ); 962*cdf0e10cSrcweir 963*cdf0e10cSrcweir if( !--GetSbData()->nInst ) 964*cdf0e10cSrcweir { 965*cdf0e10cSrcweir RemoveFactory( pSBFAC ); 966*cdf0e10cSrcweir delete pSBFAC; pSBFAC = NULL; 967*cdf0e10cSrcweir RemoveFactory( pUNOFAC ); 968*cdf0e10cSrcweir delete pUNOFAC; pUNOFAC = NULL; 969*cdf0e10cSrcweir RemoveFactory( pTYPEFAC ); 970*cdf0e10cSrcweir delete pTYPEFAC; pTYPEFAC = NULL; 971*cdf0e10cSrcweir RemoveFactory( pCLASSFAC ); 972*cdf0e10cSrcweir delete pCLASSFAC; pCLASSFAC = NULL; 973*cdf0e10cSrcweir RemoveFactory( pOLEFAC ); 974*cdf0e10cSrcweir delete pOLEFAC; pOLEFAC = NULL; 975*cdf0e10cSrcweir RemoveFactory( pFORMFAC ); 976*cdf0e10cSrcweir delete pFORMFAC; pFORMFAC = NULL; 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir #ifdef DBG_UTIL 979*cdf0e10cSrcweir // There is no need to clean SbiData at program end, 980*cdf0e10cSrcweir // but we dislike MLK's at Purify 981*cdf0e10cSrcweir // TODO: Where else??? 982*cdf0e10cSrcweir SbiGlobals** pp = (SbiGlobals**) ::GetAppData( SHL_SBC ); 983*cdf0e10cSrcweir SbiGlobals* p = *pp; 984*cdf0e10cSrcweir if( p ) 985*cdf0e10cSrcweir { 986*cdf0e10cSrcweir delete p; 987*cdf0e10cSrcweir *pp = 0; 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir #endif 990*cdf0e10cSrcweir } 991*cdf0e10cSrcweir else if( bDocBasic ) 992*cdf0e10cSrcweir { 993*cdf0e10cSrcweir SbxError eOld = SbxBase::GetError(); 994*cdf0e10cSrcweir 995*cdf0e10cSrcweir lclRemoveDocBasicItem( *this ); 996*cdf0e10cSrcweir 997*cdf0e10cSrcweir SbxBase::ResetError(); 998*cdf0e10cSrcweir if( eOld != SbxERR_OK ) 999*cdf0e10cSrcweir SbxBase::SetError( eOld ); 1000*cdf0e10cSrcweir } 1001*cdf0e10cSrcweir 1002*cdf0e10cSrcweir // #100326 Set Parent NULL in registered listeners 1003*cdf0e10cSrcweir if( xUnoListeners.Is() ) 1004*cdf0e10cSrcweir { 1005*cdf0e10cSrcweir sal_uInt16 uCount = xUnoListeners->Count(); 1006*cdf0e10cSrcweir for( sal_uInt16 i = 0 ; i < uCount ; i++ ) 1007*cdf0e10cSrcweir { 1008*cdf0e10cSrcweir SbxVariable* pListenerObj = xUnoListeners->Get( i ); 1009*cdf0e10cSrcweir pListenerObj->SetParent( NULL ); 1010*cdf0e10cSrcweir } 1011*cdf0e10cSrcweir xUnoListeners = NULL; 1012*cdf0e10cSrcweir } 1013*cdf0e10cSrcweir 1014*cdf0e10cSrcweir clearUnoMethodsForBasic( this ); 1015*cdf0e10cSrcweir } 1016*cdf0e10cSrcweir 1017*cdf0e10cSrcweir // Override new() operator, so that everyone can create a new instance 1018*cdf0e10cSrcweir void* StarBASIC::operator new( size_t n ) 1019*cdf0e10cSrcweir { 1020*cdf0e10cSrcweir if( n < sizeof( StarBASIC ) ) 1021*cdf0e10cSrcweir { 1022*cdf0e10cSrcweir // DBG_ASSERT( sal_False, "Warnung: inkompatibler BASIC-Stand!" ); 1023*cdf0e10cSrcweir n = sizeof( StarBASIC ); 1024*cdf0e10cSrcweir } 1025*cdf0e10cSrcweir return ::operator new( n ); 1026*cdf0e10cSrcweir } 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir void StarBASIC::operator delete( void* p ) 1029*cdf0e10cSrcweir { 1030*cdf0e10cSrcweir ::operator delete( p ); 1031*cdf0e10cSrcweir } 1032*cdf0e10cSrcweir 1033*cdf0e10cSrcweir void StarBASIC::implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic ) 1034*cdf0e10cSrcweir { 1035*cdf0e10cSrcweir if( this != pDeletedBasic ) 1036*cdf0e10cSrcweir { 1037*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pModules->Count(); i++ ) 1038*cdf0e10cSrcweir { 1039*cdf0e10cSrcweir SbModule* p = (SbModule*)pModules->Get( i ); 1040*cdf0e10cSrcweir p->ClearVarsDependingOnDeletedBasic( pDeletedBasic ); 1041*cdf0e10cSrcweir } 1042*cdf0e10cSrcweir } 1043*cdf0e10cSrcweir 1044*cdf0e10cSrcweir for( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ ) 1045*cdf0e10cSrcweir { 1046*cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj ); 1047*cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar); 1048*cdf0e10cSrcweir if( pBasic && pBasic != pDeletedBasic ) 1049*cdf0e10cSrcweir pBasic->implClearDependingVarsOnDelete( pDeletedBasic ); 1050*cdf0e10cSrcweir } 1051*cdf0e10cSrcweir } 1052*cdf0e10cSrcweir 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir /************************************************************************** 1055*cdf0e10cSrcweir * 1056*cdf0e10cSrcweir * Creation/Managment of modules 1057*cdf0e10cSrcweir * 1058*cdf0e10cSrcweir **************************************************************************/ 1059*cdf0e10cSrcweir 1060*cdf0e10cSrcweir SbModule* StarBASIC::MakeModule( const String& rName, const String& rSrc ) 1061*cdf0e10cSrcweir { 1062*cdf0e10cSrcweir return MakeModule32( rName, rSrc ); 1063*cdf0e10cSrcweir } 1064*cdf0e10cSrcweir 1065*cdf0e10cSrcweir SbModule* StarBASIC::MakeModule32( const String& rName, const ::rtl::OUString& rSrc ) 1066*cdf0e10cSrcweir { 1067*cdf0e10cSrcweir ModuleInfo mInfo; 1068*cdf0e10cSrcweir mInfo.ModuleType = ModuleType::NORMAL; 1069*cdf0e10cSrcweir return MakeModule32( rName, mInfo, rSrc ); 1070*cdf0e10cSrcweir } 1071*cdf0e10cSrcweir SbModule* StarBASIC::MakeModule32( const String& rName, const ModuleInfo& mInfo, const rtl::OUString& rSrc ) 1072*cdf0e10cSrcweir { 1073*cdf0e10cSrcweir 1074*cdf0e10cSrcweir OSL_TRACE("create module %s type mInfo %d", rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr(), mInfo.ModuleType ); 1075*cdf0e10cSrcweir SbModule* p = NULL; 1076*cdf0e10cSrcweir switch ( mInfo.ModuleType ) 1077*cdf0e10cSrcweir { 1078*cdf0e10cSrcweir case ModuleType::DOCUMENT: 1079*cdf0e10cSrcweir // In theory we should be able to create Object modules 1080*cdf0e10cSrcweir // in ordinary basic ( in vba mode thought these are create 1081*cdf0e10cSrcweir // by the application/basic and not by the user ) 1082*cdf0e10cSrcweir p = new SbObjModule( rName, mInfo, isVBAEnabled() ); 1083*cdf0e10cSrcweir break; 1084*cdf0e10cSrcweir case ModuleType::CLASS: 1085*cdf0e10cSrcweir p = new SbModule( rName, isVBAEnabled() ); 1086*cdf0e10cSrcweir p->SetModuleType( ModuleType::CLASS ); 1087*cdf0e10cSrcweir break; 1088*cdf0e10cSrcweir case ModuleType::FORM: 1089*cdf0e10cSrcweir p = new SbUserFormModule( rName, mInfo, isVBAEnabled() ); 1090*cdf0e10cSrcweir break; 1091*cdf0e10cSrcweir default: 1092*cdf0e10cSrcweir p = new SbModule( rName, isVBAEnabled() ); 1093*cdf0e10cSrcweir 1094*cdf0e10cSrcweir } 1095*cdf0e10cSrcweir p->SetSource32( rSrc ); 1096*cdf0e10cSrcweir p->SetParent( this ); 1097*cdf0e10cSrcweir pModules->Insert( p, pModules->Count() ); 1098*cdf0e10cSrcweir SetModified( sal_True ); 1099*cdf0e10cSrcweir return p; 1100*cdf0e10cSrcweir } 1101*cdf0e10cSrcweir 1102*cdf0e10cSrcweir void StarBASIC::Insert( SbxVariable* pVar ) 1103*cdf0e10cSrcweir { 1104*cdf0e10cSrcweir if( pVar->IsA( TYPE(SbModule) ) ) 1105*cdf0e10cSrcweir { 1106*cdf0e10cSrcweir pModules->Insert( pVar, pModules->Count() ); 1107*cdf0e10cSrcweir pVar->SetParent( this ); 1108*cdf0e10cSrcweir StartListening( pVar->GetBroadcaster(), sal_True ); 1109*cdf0e10cSrcweir } 1110*cdf0e10cSrcweir else 1111*cdf0e10cSrcweir { 1112*cdf0e10cSrcweir sal_Bool bWasModified = IsModified(); 1113*cdf0e10cSrcweir SbxObject::Insert( pVar ); 1114*cdf0e10cSrcweir if( !bWasModified && pVar->IsSet( SBX_DONTSTORE ) ) 1115*cdf0e10cSrcweir SetModified( sal_False ); 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir } 1118*cdf0e10cSrcweir 1119*cdf0e10cSrcweir void StarBASIC::Remove( SbxVariable* pVar ) 1120*cdf0e10cSrcweir { 1121*cdf0e10cSrcweir if( pVar->IsA( TYPE(SbModule) ) ) 1122*cdf0e10cSrcweir { 1123*cdf0e10cSrcweir // #87540 Can be last reference! 1124*cdf0e10cSrcweir SbxVariableRef xVar = pVar; 1125*cdf0e10cSrcweir pModules->Remove( pVar ); 1126*cdf0e10cSrcweir pVar->SetParent( 0 ); 1127*cdf0e10cSrcweir EndListening( pVar->GetBroadcaster() ); 1128*cdf0e10cSrcweir } 1129*cdf0e10cSrcweir else 1130*cdf0e10cSrcweir SbxObject::Remove( pVar ); 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir 1133*cdf0e10cSrcweir sal_Bool StarBASIC::Compile( SbModule* pMod ) 1134*cdf0e10cSrcweir { 1135*cdf0e10cSrcweir return pMod ? pMod->Compile() : sal_False; 1136*cdf0e10cSrcweir } 1137*cdf0e10cSrcweir 1138*cdf0e10cSrcweir sal_Bool StarBASIC::Disassemble( SbModule* pMod, String& rText ) 1139*cdf0e10cSrcweir { 1140*cdf0e10cSrcweir rText.Erase(); 1141*cdf0e10cSrcweir if( pMod ) 1142*cdf0e10cSrcweir pMod->Disassemble( rText ); 1143*cdf0e10cSrcweir return sal_Bool( rText.Len() != 0 ); 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir void StarBASIC::Clear() 1147*cdf0e10cSrcweir { 1148*cdf0e10cSrcweir while( pModules->Count() ) 1149*cdf0e10cSrcweir pModules->Remove( pModules->Count() - 1 ); 1150*cdf0e10cSrcweir } 1151*cdf0e10cSrcweir 1152*cdf0e10cSrcweir SbModule* StarBASIC::FindModule( const String& rName ) 1153*cdf0e10cSrcweir { 1154*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pModules->Count(); i++ ) 1155*cdf0e10cSrcweir { 1156*cdf0e10cSrcweir SbModule* p = (SbModule*) pModules->Get( i ); 1157*cdf0e10cSrcweir if( p->GetName().EqualsIgnoreCaseAscii( rName ) ) 1158*cdf0e10cSrcweir return p; 1159*cdf0e10cSrcweir } 1160*cdf0e10cSrcweir return NULL; 1161*cdf0e10cSrcweir } 1162*cdf0e10cSrcweir 1163*cdf0e10cSrcweir 1164*cdf0e10cSrcweir struct ClassModuleRunInitItem 1165*cdf0e10cSrcweir { 1166*cdf0e10cSrcweir SbModule* m_pModule; 1167*cdf0e10cSrcweir bool m_bProcessing; 1168*cdf0e10cSrcweir bool m_bRunInitDone; 1169*cdf0e10cSrcweir //ModuleVector m_vModulesDependingOnThisModule; 1170*cdf0e10cSrcweir 1171*cdf0e10cSrcweir ClassModuleRunInitItem( void ) 1172*cdf0e10cSrcweir : m_pModule( NULL ) 1173*cdf0e10cSrcweir , m_bProcessing( false ) 1174*cdf0e10cSrcweir , m_bRunInitDone( false ) 1175*cdf0e10cSrcweir {} 1176*cdf0e10cSrcweir ClassModuleRunInitItem( SbModule* pModule ) 1177*cdf0e10cSrcweir : m_pModule( pModule ) 1178*cdf0e10cSrcweir , m_bProcessing( false ) 1179*cdf0e10cSrcweir , m_bRunInitDone( false ) 1180*cdf0e10cSrcweir {} 1181*cdf0e10cSrcweir }; 1182*cdf0e10cSrcweir 1183*cdf0e10cSrcweir // Derive from has_map type instead of typedef 1184*cdf0e10cSrcweir // to allow forward declaration in sbmod.hxx 1185*cdf0e10cSrcweir class ModuleInitDependencyMap : public 1186*cdf0e10cSrcweir std::hash_map< ::rtl::OUString, ClassModuleRunInitItem, 1187*cdf0e10cSrcweir ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > 1188*cdf0e10cSrcweir {}; 1189*cdf0e10cSrcweir 1190*cdf0e10cSrcweir void SbModule::implProcessModuleRunInit( ModuleInitDependencyMap& rMap, ClassModuleRunInitItem& rItem ) 1191*cdf0e10cSrcweir { 1192*cdf0e10cSrcweir rItem.m_bProcessing = true; 1193*cdf0e10cSrcweir 1194*cdf0e10cSrcweir //bool bAnyDependencies = true; 1195*cdf0e10cSrcweir SbModule* pModule = rItem.m_pModule; 1196*cdf0e10cSrcweir if( pModule->pClassData != NULL ) 1197*cdf0e10cSrcweir { 1198*cdf0e10cSrcweir StringVector& rReqTypes = pModule->pClassData->maRequiredTypes; 1199*cdf0e10cSrcweir if( rReqTypes.size() > 0 ) 1200*cdf0e10cSrcweir { 1201*cdf0e10cSrcweir for( StringVector::iterator it = rReqTypes.begin() ; it != rReqTypes.end() ; ++it ) 1202*cdf0e10cSrcweir { 1203*cdf0e10cSrcweir String& rStr = *it; 1204*cdf0e10cSrcweir 1205*cdf0e10cSrcweir // Is required type a class module? 1206*cdf0e10cSrcweir ModuleInitDependencyMap::iterator itFind = rMap.find( rStr ); 1207*cdf0e10cSrcweir if( itFind != rMap.end() ) 1208*cdf0e10cSrcweir { 1209*cdf0e10cSrcweir ClassModuleRunInitItem& rParentItem = itFind->second; 1210*cdf0e10cSrcweir if( rParentItem.m_bProcessing ) 1211*cdf0e10cSrcweir { 1212*cdf0e10cSrcweir // TODO: raise error? 1213*cdf0e10cSrcweir DBG_ERROR( "Cyclic module dependency detected" ); 1214*cdf0e10cSrcweir continue; 1215*cdf0e10cSrcweir } 1216*cdf0e10cSrcweir 1217*cdf0e10cSrcweir if( !rParentItem.m_bRunInitDone ) 1218*cdf0e10cSrcweir implProcessModuleRunInit( rMap, rParentItem ); 1219*cdf0e10cSrcweir } 1220*cdf0e10cSrcweir } 1221*cdf0e10cSrcweir } 1222*cdf0e10cSrcweir } 1223*cdf0e10cSrcweir 1224*cdf0e10cSrcweir pModule->RunInit(); 1225*cdf0e10cSrcweir rItem.m_bRunInitDone = true; 1226*cdf0e10cSrcweir rItem.m_bProcessing = false; 1227*cdf0e10cSrcweir } 1228*cdf0e10cSrcweir 1229*cdf0e10cSrcweir // Run Init-Code of all modules (including inserted libraries) 1230*cdf0e10cSrcweir void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit ) 1231*cdf0e10cSrcweir { 1232*cdf0e10cSrcweir ::vos::OGuard guard( Application::GetSolarMutex() ); 1233*cdf0e10cSrcweir 1234*cdf0e10cSrcweir // Init own modules 1235*cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ ) 1236*cdf0e10cSrcweir { 1237*cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod ); 1238*cdf0e10cSrcweir if( !pModule->IsCompiled() ) 1239*cdf0e10cSrcweir pModule->Compile(); 1240*cdf0e10cSrcweir } 1241*cdf0e10cSrcweir // compile modules first then RunInit ( otherwise there is 1242*cdf0e10cSrcweir // can be order dependency, e.g. classmodule A has a member 1243*cdf0e10cSrcweir // of of type classmodule B and classmodule B hasn't been compiled yet ) 1244*cdf0e10cSrcweir 1245*cdf0e10cSrcweir // Consider required types to init in right order. Class modules 1246*cdf0e10cSrcweir // that are required by other modules have to be initialized first. 1247*cdf0e10cSrcweir ModuleInitDependencyMap aMIDMap; 1248*cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ ) 1249*cdf0e10cSrcweir { 1250*cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod ); 1251*cdf0e10cSrcweir String aModuleName = pModule->GetName(); 1252*cdf0e10cSrcweir if( pModule->isProxyModule() ) 1253*cdf0e10cSrcweir aMIDMap[aModuleName] = ClassModuleRunInitItem( pModule ); 1254*cdf0e10cSrcweir } 1255*cdf0e10cSrcweir 1256*cdf0e10cSrcweir ModuleInitDependencyMap::iterator it; 1257*cdf0e10cSrcweir for( it = aMIDMap.begin() ; it != aMIDMap.end(); ++it ) 1258*cdf0e10cSrcweir { 1259*cdf0e10cSrcweir ClassModuleRunInitItem& rItem = it->second; 1260*cdf0e10cSrcweir SbModule::implProcessModuleRunInit( aMIDMap, rItem ); 1261*cdf0e10cSrcweir } 1262*cdf0e10cSrcweir 1263*cdf0e10cSrcweir // Call RunInit on standard modules 1264*cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ ) 1265*cdf0e10cSrcweir { 1266*cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod ); 1267*cdf0e10cSrcweir if( !pModule->isProxyModule() ) 1268*cdf0e10cSrcweir pModule->RunInit(); 1269*cdf0e10cSrcweir } 1270*cdf0e10cSrcweir 1271*cdf0e10cSrcweir // Check all objects if they are BASIC, 1272*cdf0e10cSrcweir // if yes initialize 1273*cdf0e10cSrcweir for ( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ ) 1274*cdf0e10cSrcweir { 1275*cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj ); 1276*cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar); 1277*cdf0e10cSrcweir if( pBasic && pBasic != pBasicNotToInit ) 1278*cdf0e10cSrcweir pBasic->InitAllModules(); 1279*cdf0e10cSrcweir } 1280*cdf0e10cSrcweir } 1281*cdf0e10cSrcweir 1282*cdf0e10cSrcweir // #88329 Put modules back to not initialised state to 1283*cdf0e10cSrcweir // force reinitialisation at next start 1284*cdf0e10cSrcweir void StarBASIC::DeInitAllModules( void ) 1285*cdf0e10cSrcweir { 1286*cdf0e10cSrcweir // Deinit own modules 1287*cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ ) 1288*cdf0e10cSrcweir { 1289*cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod ); 1290*cdf0e10cSrcweir if( pModule->pImage && !pModule->isProxyModule() && !pModule->ISA(SbObjModule) ) 1291*cdf0e10cSrcweir pModule->pImage->bInit = false; 1292*cdf0e10cSrcweir } 1293*cdf0e10cSrcweir 1294*cdf0e10cSrcweir for ( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ ) 1295*cdf0e10cSrcweir { 1296*cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj ); 1297*cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar); 1298*cdf0e10cSrcweir if( pBasic ) 1299*cdf0e10cSrcweir pBasic->DeInitAllModules(); 1300*cdf0e10cSrcweir } 1301*cdf0e10cSrcweir } 1302*cdf0e10cSrcweir 1303*cdf0e10cSrcweir // #43011 For TestTool, to delete global vars 1304*cdf0e10cSrcweir void StarBASIC::ClearGlobalVars( void ) 1305*cdf0e10cSrcweir { 1306*cdf0e10cSrcweir SbxArrayRef xProps( GetProperties() ); 1307*cdf0e10cSrcweir sal_uInt16 nPropCount = xProps->Count(); 1308*cdf0e10cSrcweir for ( sal_uInt16 nProp = 0 ; nProp < nPropCount ; ++nProp ) 1309*cdf0e10cSrcweir { 1310*cdf0e10cSrcweir SbxBase* pVar = xProps->Get( nProp ); 1311*cdf0e10cSrcweir pVar->Clear(); 1312*cdf0e10cSrcweir } 1313*cdf0e10cSrcweir SetModified( sal_True ); 1314*cdf0e10cSrcweir } 1315*cdf0e10cSrcweir 1316*cdf0e10cSrcweir // This implementation at first searches within the runtime library, 1317*cdf0e10cSrcweir // then it looks for an element within one module. This moudle can be 1318*cdf0e10cSrcweir // a public var or an entrypoint. If it is not found and we look for a 1319*cdf0e10cSrcweir // method and a module with the given name is found the search continues 1320*cdf0e10cSrcweir // for entrypoint "Main". 1321*cdf0e10cSrcweir // If this fails again a conventional search over objects is performend. 1322*cdf0e10cSrcweir SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t ) 1323*cdf0e10cSrcweir { 1324*cdf0e10cSrcweir static String aMainStr( RTL_CONSTASCII_USTRINGPARAM("Main") ); 1325*cdf0e10cSrcweir 1326*cdf0e10cSrcweir SbxVariable* pRes = NULL; 1327*cdf0e10cSrcweir SbModule* pNamed = NULL; 1328*cdf0e10cSrcweir // "Extended" search in Runtime Lib 1329*cdf0e10cSrcweir // but only if SbiRuntime has not set the flag 1330*cdf0e10cSrcweir if( !bNoRtl ) 1331*cdf0e10cSrcweir { 1332*cdf0e10cSrcweir if( t == SbxCLASS_DONTCARE || t == SbxCLASS_OBJECT ) 1333*cdf0e10cSrcweir { 1334*cdf0e10cSrcweir if( rName.EqualsIgnoreCaseAscii( RTLNAME ) ) 1335*cdf0e10cSrcweir pRes = pRtl; 1336*cdf0e10cSrcweir } 1337*cdf0e10cSrcweir if( !pRes ) 1338*cdf0e10cSrcweir pRes = ((SbiStdObject*) (SbxObject*) pRtl)->Find( rName, t ); 1339*cdf0e10cSrcweir if( pRes ) 1340*cdf0e10cSrcweir pRes->SetFlag( SBX_EXTFOUND ); 1341*cdf0e10cSrcweir } 1342*cdf0e10cSrcweir // Search module 1343*cdf0e10cSrcweir if( !pRes ) 1344*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pModules->Count(); i++ ) 1345*cdf0e10cSrcweir { 1346*cdf0e10cSrcweir SbModule* p = (SbModule*) pModules->Get( i ); 1347*cdf0e10cSrcweir if( p->IsVisible() ) 1348*cdf0e10cSrcweir { 1349*cdf0e10cSrcweir // Remember modul fpr Main() call 1350*cdf0e10cSrcweir // or is the name equal?!? 1351*cdf0e10cSrcweir if( p->GetName().EqualsIgnoreCaseAscii( rName ) ) 1352*cdf0e10cSrcweir { 1353*cdf0e10cSrcweir if( t == SbxCLASS_OBJECT || t == SbxCLASS_DONTCARE ) 1354*cdf0e10cSrcweir { 1355*cdf0e10cSrcweir pRes = p; break; 1356*cdf0e10cSrcweir } 1357*cdf0e10cSrcweir pNamed = p; 1358*cdf0e10cSrcweir } 1359*cdf0e10cSrcweir // Only variables qualified by the Module Name e.g. Sheet1.foo 1360*cdf0e10cSrcweir // should work for Documant && Class type Modules 1361*cdf0e10cSrcweir sal_Int32 nType = p->GetModuleType(); 1362*cdf0e10cSrcweir if ( nType == ModuleType::DOCUMENT || nType == ModuleType::FORM ) 1363*cdf0e10cSrcweir continue; 1364*cdf0e10cSrcweir 1365*cdf0e10cSrcweir // otherwise check if the element is available 1366*cdf0e10cSrcweir // unset GBLSEARCH-Flag (due to Rekursion) 1367*cdf0e10cSrcweir sal_uInt16 nGblFlag = p->GetFlags() & SBX_GBLSEARCH; 1368*cdf0e10cSrcweir p->ResetFlag( SBX_GBLSEARCH ); 1369*cdf0e10cSrcweir pRes = p->Find( rName, t ); 1370*cdf0e10cSrcweir p->SetFlag( nGblFlag ); 1371*cdf0e10cSrcweir if( pRes ) 1372*cdf0e10cSrcweir break; 1373*cdf0e10cSrcweir } 1374*cdf0e10cSrcweir } 1375*cdf0e10cSrcweir if( !pRes && pNamed && ( t == SbxCLASS_METHOD || t == SbxCLASS_DONTCARE ) && 1376*cdf0e10cSrcweir !pNamed->GetName().EqualsIgnoreCaseAscii( aMainStr ) ) 1377*cdf0e10cSrcweir pRes = pNamed->Find( aMainStr, SbxCLASS_METHOD ); 1378*cdf0e10cSrcweir if( !pRes ) 1379*cdf0e10cSrcweir pRes = SbxObject::Find( rName, t ); 1380*cdf0e10cSrcweir return pRes; 1381*cdf0e10cSrcweir } 1382*cdf0e10cSrcweir 1383*cdf0e10cSrcweir sal_Bool StarBASIC::Call( const String& rName, SbxArray* pParam ) 1384*cdf0e10cSrcweir { 1385*cdf0e10cSrcweir sal_Bool bRes = SbxObject::Call( rName, pParam ); 1386*cdf0e10cSrcweir if( !bRes ) 1387*cdf0e10cSrcweir { 1388*cdf0e10cSrcweir SbxError eErr = SbxBase::GetError(); 1389*cdf0e10cSrcweir SbxBase::ResetError(); 1390*cdf0e10cSrcweir if( eErr != SbxERR_OK ) 1391*cdf0e10cSrcweir RTError( (SbError)eErr, 0, 0, 0 ); 1392*cdf0e10cSrcweir } 1393*cdf0e10cSrcweir return bRes; 1394*cdf0e10cSrcweir } 1395*cdf0e10cSrcweir 1396*cdf0e10cSrcweir // Find method via name (e.g. query via BASIC IDE) 1397*cdf0e10cSrcweir SbxBase* StarBASIC::FindSBXInCurrentScope( const String& rName ) 1398*cdf0e10cSrcweir { 1399*cdf0e10cSrcweir if( !pINST ) 1400*cdf0e10cSrcweir return NULL; 1401*cdf0e10cSrcweir if( !pINST->pRun ) 1402*cdf0e10cSrcweir return NULL; 1403*cdf0e10cSrcweir return pINST->pRun->FindElementExtern( rName ); 1404*cdf0e10cSrcweir } 1405*cdf0e10cSrcweir 1406*cdf0e10cSrcweir // Preserve old interface 1407*cdf0e10cSrcweir SbxVariable* StarBASIC::FindVarInCurrentScopy 1408*cdf0e10cSrcweir ( const String& rName, sal_uInt16& rStatus ) 1409*cdf0e10cSrcweir { 1410*cdf0e10cSrcweir rStatus = 1; // Presumption: nothing found 1411*cdf0e10cSrcweir SbxVariable* pVar = NULL; 1412*cdf0e10cSrcweir SbxBase* pSbx = FindSBXInCurrentScope( rName ); 1413*cdf0e10cSrcweir if( pSbx ) 1414*cdf0e10cSrcweir { 1415*cdf0e10cSrcweir if( !pSbx->ISA(SbxMethod) && !pSbx->ISA(SbxObject) ) 1416*cdf0e10cSrcweir pVar = PTR_CAST(SbxVariable,pSbx); 1417*cdf0e10cSrcweir } 1418*cdf0e10cSrcweir if( pVar ) 1419*cdf0e10cSrcweir rStatus = 0; // We found something 1420*cdf0e10cSrcweir return pVar; 1421*cdf0e10cSrcweir } 1422*cdf0e10cSrcweir 1423*cdf0e10cSrcweir void StarBASIC::QuitAndExitApplication() 1424*cdf0e10cSrcweir { 1425*cdf0e10cSrcweir Stop(); 1426*cdf0e10cSrcweir bQuit = sal_True; 1427*cdf0e10cSrcweir } 1428*cdf0e10cSrcweir 1429*cdf0e10cSrcweir void StarBASIC::Stop() 1430*cdf0e10cSrcweir { 1431*cdf0e10cSrcweir SbiInstance* p = pINST; 1432*cdf0e10cSrcweir while( p ) 1433*cdf0e10cSrcweir { 1434*cdf0e10cSrcweir p->Stop(); 1435*cdf0e10cSrcweir p = p->pNext; 1436*cdf0e10cSrcweir } 1437*cdf0e10cSrcweir } 1438*cdf0e10cSrcweir 1439*cdf0e10cSrcweir sal_Bool StarBASIC::IsRunning() 1440*cdf0e10cSrcweir { 1441*cdf0e10cSrcweir return sal_Bool( pINST != NULL ); 1442*cdf0e10cSrcweir } 1443*cdf0e10cSrcweir 1444*cdf0e10cSrcweir /************************************************************************** 1445*cdf0e10cSrcweir * 1446*cdf0e10cSrcweir * Object factories and others 1447*cdf0e10cSrcweir * 1448*cdf0e10cSrcweir **************************************************************************/ 1449*cdf0e10cSrcweir 1450*cdf0e10cSrcweir // Activation of an object. There is no need to access active objects 1451*cdf0e10cSrcweir // with name via BASIC. If NULL is given, everything is activated. 1452*cdf0e10cSrcweir void StarBASIC::ActivateObject( const String* pName, sal_Bool bActivate ) 1453*cdf0e10cSrcweir { 1454*cdf0e10cSrcweir if( pName ) 1455*cdf0e10cSrcweir { 1456*cdf0e10cSrcweir SbxObject* p = (SbxObject*) SbxObject::Find( *pName, SbxCLASS_OBJECT ); 1457*cdf0e10cSrcweir if( p ) 1458*cdf0e10cSrcweir { 1459*cdf0e10cSrcweir if( bActivate ) 1460*cdf0e10cSrcweir p->SetFlag( SBX_EXTSEARCH ); 1461*cdf0e10cSrcweir else 1462*cdf0e10cSrcweir p->ResetFlag( SBX_EXTSEARCH ); 1463*cdf0e10cSrcweir } 1464*cdf0e10cSrcweir } 1465*cdf0e10cSrcweir else 1466*cdf0e10cSrcweir { 1467*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < GetObjects()->Count(); i++ ) 1468*cdf0e10cSrcweir { 1469*cdf0e10cSrcweir SbxObject* p = (SbxObject*) GetObjects()->Get( i ); 1470*cdf0e10cSrcweir if( bActivate ) 1471*cdf0e10cSrcweir p->SetFlag( SBX_EXTSEARCH ); 1472*cdf0e10cSrcweir else 1473*cdf0e10cSrcweir p->ResetFlag( SBX_EXTSEARCH ); 1474*cdf0e10cSrcweir } 1475*cdf0e10cSrcweir } 1476*cdf0e10cSrcweir } 1477*cdf0e10cSrcweir 1478*cdf0e10cSrcweir /************************************************************************** 1479*cdf0e10cSrcweir * 1480*cdf0e10cSrcweir * Debugging and error handling 1481*cdf0e10cSrcweir * 1482*cdf0e10cSrcweir **************************************************************************/ 1483*cdf0e10cSrcweir 1484*cdf0e10cSrcweir SbMethod* StarBASIC::GetActiveMethod( sal_uInt16 nLevel ) 1485*cdf0e10cSrcweir { 1486*cdf0e10cSrcweir if( pINST ) 1487*cdf0e10cSrcweir return pINST->GetCaller( nLevel ); 1488*cdf0e10cSrcweir else 1489*cdf0e10cSrcweir return NULL; 1490*cdf0e10cSrcweir } 1491*cdf0e10cSrcweir 1492*cdf0e10cSrcweir SbModule* StarBASIC::GetActiveModule() 1493*cdf0e10cSrcweir { 1494*cdf0e10cSrcweir if( pINST && !IsCompilerError() ) 1495*cdf0e10cSrcweir return pINST->GetActiveModule(); 1496*cdf0e10cSrcweir else 1497*cdf0e10cSrcweir return pCMOD; 1498*cdf0e10cSrcweir } 1499*cdf0e10cSrcweir 1500*cdf0e10cSrcweir sal_uInt16 StarBASIC::BreakPoint( sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 ) 1501*cdf0e10cSrcweir { 1502*cdf0e10cSrcweir SetErrorData( 0, l, c1, c2 ); 1503*cdf0e10cSrcweir bBreak = sal_True; 1504*cdf0e10cSrcweir if( GetSbData()->aBreakHdl.IsSet() ) 1505*cdf0e10cSrcweir return (sal_uInt16) GetSbData()->aBreakHdl.Call( this ); 1506*cdf0e10cSrcweir else 1507*cdf0e10cSrcweir return BreakHdl(); 1508*cdf0e10cSrcweir } 1509*cdf0e10cSrcweir 1510*cdf0e10cSrcweir sal_uInt16 StarBASIC::StepPoint( sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 ) 1511*cdf0e10cSrcweir { 1512*cdf0e10cSrcweir SetErrorData( 0, l, c1, c2 ); 1513*cdf0e10cSrcweir bBreak = sal_False; 1514*cdf0e10cSrcweir if( GetSbData()->aBreakHdl.IsSet() ) 1515*cdf0e10cSrcweir return (sal_uInt16) GetSbData()->aBreakHdl.Call( this ); 1516*cdf0e10cSrcweir else 1517*cdf0e10cSrcweir return BreakHdl(); 1518*cdf0e10cSrcweir } 1519*cdf0e10cSrcweir 1520*cdf0e10cSrcweir sal_uInt16 __EXPORT StarBASIC::BreakHdl() 1521*cdf0e10cSrcweir { 1522*cdf0e10cSrcweir return (sal_uInt16) ( aBreakHdl.IsSet() 1523*cdf0e10cSrcweir ? aBreakHdl.Call( this ) : SbDEBUG_CONTINUE ); 1524*cdf0e10cSrcweir } 1525*cdf0e10cSrcweir 1526*cdf0e10cSrcweir // Calls for error handler and break handler 1527*cdf0e10cSrcweir sal_uInt16 StarBASIC::GetLine() { return GetSbData()->nLine; } 1528*cdf0e10cSrcweir sal_uInt16 StarBASIC::GetCol1() { return GetSbData()->nCol1; } 1529*cdf0e10cSrcweir sal_uInt16 StarBASIC::GetCol2() { return GetSbData()->nCol2; } 1530*cdf0e10cSrcweir 1531*cdf0e10cSrcweir // Specific to error handler 1532*cdf0e10cSrcweir SbError StarBASIC::GetErrorCode() { return GetSbData()->nCode; } 1533*cdf0e10cSrcweir const String& StarBASIC::GetErrorText() { return GetSbData()->aErrMsg; } 1534*cdf0e10cSrcweir sal_Bool StarBASIC::IsCompilerError() { return GetSbData()->bCompiler; } 1535*cdf0e10cSrcweir void StarBASIC::SetGlobalLanguageMode( SbLanguageMode eLanguageMode ) 1536*cdf0e10cSrcweir { 1537*cdf0e10cSrcweir GetSbData()->eLanguageMode = eLanguageMode; 1538*cdf0e10cSrcweir } 1539*cdf0e10cSrcweir SbLanguageMode StarBASIC::GetGlobalLanguageMode() 1540*cdf0e10cSrcweir { 1541*cdf0e10cSrcweir return GetSbData()->eLanguageMode; 1542*cdf0e10cSrcweir } 1543*cdf0e10cSrcweir // Local settings 1544*cdf0e10cSrcweir SbLanguageMode StarBASIC::GetLanguageMode() 1545*cdf0e10cSrcweir { 1546*cdf0e10cSrcweir // Use global settings? 1547*cdf0e10cSrcweir if( eLanguageMode == SB_LANG_GLOBAL ) 1548*cdf0e10cSrcweir return GetSbData()->eLanguageMode; 1549*cdf0e10cSrcweir else 1550*cdf0e10cSrcweir return eLanguageMode; 1551*cdf0e10cSrcweir } 1552*cdf0e10cSrcweir 1553*cdf0e10cSrcweir // AB: 29.3.96 1554*cdf0e10cSrcweir // Das Mapping zwischen alten und neuen Fehlercodes erfolgt, indem die Tabelle 1555*cdf0e10cSrcweir // SFX_VB_ErrorTab[] durchsucht wird. Dies ist zwar nicht besonders performant, 1556*cdf0e10cSrcweir // verbraucht aber viel weniger Speicher als entsprechende switch-Bloecke. 1557*cdf0e10cSrcweir // Die Umrechnung von Fehlercodes muss nicht schnell sein, daher auch keine 1558*cdf0e10cSrcweir // binaere Suche bei VB-Error -> SFX-Error. 1559*cdf0e10cSrcweir 1560*cdf0e10cSrcweir // Neue Fehler-Codes auf alte, Sbx-Kompatible zurueckmappen 1561*cdf0e10cSrcweir sal_uInt16 StarBASIC::GetVBErrorCode( SbError nError ) 1562*cdf0e10cSrcweir { 1563*cdf0e10cSrcweir sal_uInt16 nRet = 0; 1564*cdf0e10cSrcweir 1565*cdf0e10cSrcweir if( SbiRuntime::isVBAEnabled() ) 1566*cdf0e10cSrcweir { 1567*cdf0e10cSrcweir switch( nError ) 1568*cdf0e10cSrcweir { 1569*cdf0e10cSrcweir case SbERR_BASIC_ARRAY_FIX: 1570*cdf0e10cSrcweir return 10; 1571*cdf0e10cSrcweir case SbERR_BASIC_STRING_OVERFLOW: 1572*cdf0e10cSrcweir return 14; 1573*cdf0e10cSrcweir case SbERR_BASIC_EXPR_TOO_COMPLEX: 1574*cdf0e10cSrcweir return 16; 1575*cdf0e10cSrcweir case SbERR_BASIC_OPER_NOT_PERFORM: 1576*cdf0e10cSrcweir return 17; 1577*cdf0e10cSrcweir case SbERR_BASIC_TOO_MANY_DLL: 1578*cdf0e10cSrcweir return 47; 1579*cdf0e10cSrcweir case SbERR_BASIC_LOOP_NOT_INIT: 1580*cdf0e10cSrcweir return 92; 1581*cdf0e10cSrcweir default: 1582*cdf0e10cSrcweir nRet = 0; 1583*cdf0e10cSrcweir } 1584*cdf0e10cSrcweir } 1585*cdf0e10cSrcweir 1586*cdf0e10cSrcweir // Suchschleife 1587*cdf0e10cSrcweir const SFX_VB_ErrorItem* pErrItem; 1588*cdf0e10cSrcweir sal_uInt16 nIndex = 0; 1589*cdf0e10cSrcweir do 1590*cdf0e10cSrcweir { 1591*cdf0e10cSrcweir pErrItem = SFX_VB_ErrorTab + nIndex; 1592*cdf0e10cSrcweir if( pErrItem->nErrorSFX == nError ) 1593*cdf0e10cSrcweir { 1594*cdf0e10cSrcweir nRet = pErrItem->nErrorVB; 1595*cdf0e10cSrcweir break; 1596*cdf0e10cSrcweir } 1597*cdf0e10cSrcweir nIndex++; 1598*cdf0e10cSrcweir } 1599*cdf0e10cSrcweir while( pErrItem->nErrorVB != 0xFFFF ); // bis End-Marke 1600*cdf0e10cSrcweir return nRet; 1601*cdf0e10cSrcweir } 1602*cdf0e10cSrcweir 1603*cdf0e10cSrcweir SbError StarBASIC::GetSfxFromVBError( sal_uInt16 nError ) 1604*cdf0e10cSrcweir { 1605*cdf0e10cSrcweir SbError nRet = 0L; 1606*cdf0e10cSrcweir 1607*cdf0e10cSrcweir if( SbiRuntime::isVBAEnabled() ) 1608*cdf0e10cSrcweir { 1609*cdf0e10cSrcweir switch( nError ) 1610*cdf0e10cSrcweir { 1611*cdf0e10cSrcweir case 1: 1612*cdf0e10cSrcweir case 2: 1613*cdf0e10cSrcweir case 4: 1614*cdf0e10cSrcweir case 8: 1615*cdf0e10cSrcweir case 12: 1616*cdf0e10cSrcweir case 73: 1617*cdf0e10cSrcweir return 0L; 1618*cdf0e10cSrcweir case 10: 1619*cdf0e10cSrcweir return SbERR_BASIC_ARRAY_FIX; 1620*cdf0e10cSrcweir case 14: 1621*cdf0e10cSrcweir return SbERR_BASIC_STRING_OVERFLOW; 1622*cdf0e10cSrcweir case 16: 1623*cdf0e10cSrcweir return SbERR_BASIC_EXPR_TOO_COMPLEX; 1624*cdf0e10cSrcweir case 17: 1625*cdf0e10cSrcweir return SbERR_BASIC_OPER_NOT_PERFORM; 1626*cdf0e10cSrcweir case 47: 1627*cdf0e10cSrcweir return SbERR_BASIC_TOO_MANY_DLL; 1628*cdf0e10cSrcweir case 92: 1629*cdf0e10cSrcweir return SbERR_BASIC_LOOP_NOT_INIT; 1630*cdf0e10cSrcweir default: 1631*cdf0e10cSrcweir nRet = 0L; 1632*cdf0e10cSrcweir } 1633*cdf0e10cSrcweir } 1634*cdf0e10cSrcweir const SFX_VB_ErrorItem* pErrItem; 1635*cdf0e10cSrcweir sal_uInt16 nIndex = 0; 1636*cdf0e10cSrcweir do 1637*cdf0e10cSrcweir { 1638*cdf0e10cSrcweir pErrItem = SFX_VB_ErrorTab + nIndex; 1639*cdf0e10cSrcweir if( pErrItem->nErrorVB == nError ) 1640*cdf0e10cSrcweir { 1641*cdf0e10cSrcweir nRet = pErrItem->nErrorSFX; 1642*cdf0e10cSrcweir break; 1643*cdf0e10cSrcweir } 1644*cdf0e10cSrcweir else if( pErrItem->nErrorVB > nError ) 1645*cdf0e10cSrcweir break; // kann nicht mehr gefunden werden 1646*cdf0e10cSrcweir 1647*cdf0e10cSrcweir nIndex++; 1648*cdf0e10cSrcweir } 1649*cdf0e10cSrcweir while( pErrItem->nErrorVB != 0xFFFF ); // bis End-Marke 1650*cdf0e10cSrcweir return nRet; 1651*cdf0e10cSrcweir } 1652*cdf0e10cSrcweir 1653*cdf0e10cSrcweir // Error- / Break-Daten setzen 1654*cdf0e10cSrcweir void StarBASIC::SetErrorData 1655*cdf0e10cSrcweir ( SbError nCode, sal_uInt16 nLine, sal_uInt16 nCol1, sal_uInt16 nCol2 ) 1656*cdf0e10cSrcweir { 1657*cdf0e10cSrcweir SbiGlobals& aGlobals = *GetSbData(); 1658*cdf0e10cSrcweir aGlobals.nCode = nCode; 1659*cdf0e10cSrcweir aGlobals.nLine = nLine; 1660*cdf0e10cSrcweir aGlobals.nCol1 = nCol1; 1661*cdf0e10cSrcweir aGlobals.nCol2 = nCol2; 1662*cdf0e10cSrcweir } 1663*cdf0e10cSrcweir 1664*cdf0e10cSrcweir //---------------------------------------------------------------- 1665*cdf0e10cSrcweir // Hilfsklasse zum Zugriff auf String SubResourcen einer Resource. 1666*cdf0e10cSrcweir // Quelle: sfx2\source\doc\docfile.cxx (TLX) 1667*cdf0e10cSrcweir struct BasicStringList_Impl : private Resource 1668*cdf0e10cSrcweir { 1669*cdf0e10cSrcweir ResId aResId; 1670*cdf0e10cSrcweir 1671*cdf0e10cSrcweir BasicStringList_Impl( ResId& rErrIdP, sal_uInt16 nId) 1672*cdf0e10cSrcweir : Resource( rErrIdP ),aResId(nId, *rErrIdP.GetResMgr() ){} 1673*cdf0e10cSrcweir ~BasicStringList_Impl() { FreeResource(); } 1674*cdf0e10cSrcweir 1675*cdf0e10cSrcweir String GetString(){ return String( aResId ); } 1676*cdf0e10cSrcweir sal_Bool IsErrorTextAvailable( void ) 1677*cdf0e10cSrcweir { return IsAvailableRes(aResId.SetRT(RSC_STRING)); } 1678*cdf0e10cSrcweir }; 1679*cdf0e10cSrcweir //---------------------------------------------------------------- 1680*cdf0e10cSrcweir 1681*cdf0e10cSrcweir // #60175 Flag, das bei Basic-Fehlern das Anziehen der SFX-Resourcen verhindert 1682*cdf0e10cSrcweir static sal_Bool bStaticSuppressSfxResource = sal_False; 1683*cdf0e10cSrcweir 1684*cdf0e10cSrcweir void StarBASIC::StaticSuppressSfxResource( sal_Bool bSuppress ) 1685*cdf0e10cSrcweir { 1686*cdf0e10cSrcweir bStaticSuppressSfxResource = bSuppress; 1687*cdf0e10cSrcweir } 1688*cdf0e10cSrcweir 1689*cdf0e10cSrcweir // Hack for #83750, use bStaticSuppressSfxResource as setup flag 1690*cdf0e10cSrcweir sal_Bool runsInSetup( void ) 1691*cdf0e10cSrcweir { 1692*cdf0e10cSrcweir return bStaticSuppressSfxResource; 1693*cdf0e10cSrcweir } 1694*cdf0e10cSrcweir 1695*cdf0e10cSrcweir 1696*cdf0e10cSrcweir void StarBASIC::MakeErrorText( SbError nId, const String& aMsg ) 1697*cdf0e10cSrcweir { 1698*cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 1699*cdf0e10cSrcweir 1700*cdf0e10cSrcweir if( bStaticSuppressSfxResource ) 1701*cdf0e10cSrcweir { 1702*cdf0e10cSrcweir GetSbData()->aErrMsg = String( RTL_CONSTASCII_USTRINGPARAM("No resource: Error message not available") ); 1703*cdf0e10cSrcweir return; 1704*cdf0e10cSrcweir } 1705*cdf0e10cSrcweir 1706*cdf0e10cSrcweir sal_uInt16 nOldID = GetVBErrorCode( nId ); 1707*cdf0e10cSrcweir 1708*cdf0e10cSrcweir // Hilfsklasse instanzieren 1709*cdf0e10cSrcweir BasResId aId( RID_BASIC_START ); 1710*cdf0e10cSrcweir BasicStringList_Impl aMyStringList( aId, sal_uInt16(nId & ERRCODE_RES_MASK) ); 1711*cdf0e10cSrcweir 1712*cdf0e10cSrcweir if( aMyStringList.IsErrorTextAvailable() ) 1713*cdf0e10cSrcweir { 1714*cdf0e10cSrcweir // Merge Message mit Zusatztext 1715*cdf0e10cSrcweir String aMsg1 = aMyStringList.GetString(); 1716*cdf0e10cSrcweir // Argument-Platzhalter durch %s ersetzen 1717*cdf0e10cSrcweir String aSrgStr( RTL_CONSTASCII_USTRINGPARAM("$(ARG1)") ); 1718*cdf0e10cSrcweir sal_uInt16 nResult = aMsg1.Search( aSrgStr ); 1719*cdf0e10cSrcweir 1720*cdf0e10cSrcweir if( nResult != STRING_NOTFOUND ) 1721*cdf0e10cSrcweir { 1722*cdf0e10cSrcweir aMsg1.Erase( nResult, aSrgStr.Len() ); 1723*cdf0e10cSrcweir aMsg1.Insert( aMsg, nResult ); 1724*cdf0e10cSrcweir } 1725*cdf0e10cSrcweir GetSbData()->aErrMsg = aMsg1; 1726*cdf0e10cSrcweir } 1727*cdf0e10cSrcweir else if( nOldID != 0 ) 1728*cdf0e10cSrcweir { 1729*cdf0e10cSrcweir String aStdMsg( RTL_CONSTASCII_USTRINGPARAM("Fehler ") ); 1730*cdf0e10cSrcweir aStdMsg += String::CreateFromInt32( nOldID); 1731*cdf0e10cSrcweir aStdMsg += String( RTL_CONSTASCII_USTRINGPARAM(": Kein Fehlertext verfuegbar!") ); 1732*cdf0e10cSrcweir GetSbData()->aErrMsg = aStdMsg; 1733*cdf0e10cSrcweir } 1734*cdf0e10cSrcweir else 1735*cdf0e10cSrcweir GetSbData()->aErrMsg = String::EmptyString(); 1736*cdf0e10cSrcweir 1737*cdf0e10cSrcweir } 1738*cdf0e10cSrcweir 1739*cdf0e10cSrcweir sal_Bool StarBASIC::CError 1740*cdf0e10cSrcweir ( SbError code, const String& rMsg, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 ) 1741*cdf0e10cSrcweir { 1742*cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 1743*cdf0e10cSrcweir 1744*cdf0e10cSrcweir // Compiler-Fehler waehrend der Laufzeit -> Programm anhalten 1745*cdf0e10cSrcweir if( IsRunning() ) 1746*cdf0e10cSrcweir { 1747*cdf0e10cSrcweir // #109018 Check if running Basic is affected 1748*cdf0e10cSrcweir StarBASIC* pStartedBasic = pINST->GetBasic(); 1749*cdf0e10cSrcweir if( pStartedBasic != this ) 1750*cdf0e10cSrcweir return sal_False; 1751*cdf0e10cSrcweir 1752*cdf0e10cSrcweir Stop(); 1753*cdf0e10cSrcweir } 1754*cdf0e10cSrcweir 1755*cdf0e10cSrcweir // Flag setzen, damit GlobalRunInit den Fehler mitbekommt 1756*cdf0e10cSrcweir GetSbData()->bGlobalInitErr = sal_True; 1757*cdf0e10cSrcweir 1758*cdf0e10cSrcweir // Fehlertext basteln 1759*cdf0e10cSrcweir MakeErrorText( code, rMsg ); 1760*cdf0e10cSrcweir 1761*cdf0e10cSrcweir // Umsetzung des Codes fuer String-Transport in SFX-Error 1762*cdf0e10cSrcweir if( rMsg.Len() ) 1763*cdf0e10cSrcweir code = (sal_uIntPtr)*new StringErrorInfo( code, String(rMsg) ); 1764*cdf0e10cSrcweir 1765*cdf0e10cSrcweir SetErrorData( code, l, c1, c2 ); 1766*cdf0e10cSrcweir GetSbData()->bCompiler = sal_True; 1767*cdf0e10cSrcweir sal_Bool bRet; 1768*cdf0e10cSrcweir if( GetSbData()->aErrHdl.IsSet() ) 1769*cdf0e10cSrcweir bRet = (sal_Bool) GetSbData()->aErrHdl.Call( this ); 1770*cdf0e10cSrcweir else 1771*cdf0e10cSrcweir bRet = ErrorHdl(); 1772*cdf0e10cSrcweir GetSbData()->bCompiler = sal_False; // nur sal_True fuer Error-Handler 1773*cdf0e10cSrcweir return bRet; 1774*cdf0e10cSrcweir } 1775*cdf0e10cSrcweir 1776*cdf0e10cSrcweir sal_Bool StarBASIC::RTError 1777*cdf0e10cSrcweir ( SbError code, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 ) 1778*cdf0e10cSrcweir { 1779*cdf0e10cSrcweir return RTError( code, String(), l, c1, c2 ); 1780*cdf0e10cSrcweir } 1781*cdf0e10cSrcweir 1782*cdf0e10cSrcweir sal_Bool StarBASIC::RTError( SbError code, const String& rMsg, sal_uInt16 l, sal_uInt16 c1, sal_uInt16 c2 ) 1783*cdf0e10cSrcweir { 1784*cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 1785*cdf0e10cSrcweir 1786*cdf0e10cSrcweir SbError c = code; 1787*cdf0e10cSrcweir if( (c & ERRCODE_CLASS_MASK) == ERRCODE_CLASS_COMPILER ) 1788*cdf0e10cSrcweir c = 0; 1789*cdf0e10cSrcweir MakeErrorText( c, rMsg ); 1790*cdf0e10cSrcweir 1791*cdf0e10cSrcweir // Umsetzung des Codes fuer String-Transport in SFX-Error 1792*cdf0e10cSrcweir if( rMsg.Len() ) 1793*cdf0e10cSrcweir { 1794*cdf0e10cSrcweir // very confusing, even though MakeErrorText sets up the error text 1795*cdf0e10cSrcweir // seems that this is not used ( if rMsg already has content ) 1796*cdf0e10cSrcweir // In the case of VBA MakeErrorText also formats the error to be alittle more 1797*cdf0e10cSrcweir // like vba ( adds an error number etc ) 1798*cdf0e10cSrcweir if ( SbiRuntime::isVBAEnabled() && ( code == SbERR_BASIC_COMPAT ) ) 1799*cdf0e10cSrcweir { 1800*cdf0e10cSrcweir String aTmp = '\''; 1801*cdf0e10cSrcweir aTmp += String::CreateFromInt32( SbxErrObject::getUnoErrObject()->getNumber() ); 1802*cdf0e10cSrcweir aTmp += String( RTL_CONSTASCII_USTRINGPARAM("\'\n") ); 1803*cdf0e10cSrcweir aTmp += GetSbData()->aErrMsg.Len() ? GetSbData()->aErrMsg : rMsg; 1804*cdf0e10cSrcweir code = (sal_uIntPtr)*new StringErrorInfo( code, aTmp ); 1805*cdf0e10cSrcweir } 1806*cdf0e10cSrcweir else 1807*cdf0e10cSrcweir code = (sal_uIntPtr)*new StringErrorInfo( code, String(rMsg) ); 1808*cdf0e10cSrcweir } 1809*cdf0e10cSrcweir 1810*cdf0e10cSrcweir SetErrorData( code, l, c1, c2 ); 1811*cdf0e10cSrcweir if( GetSbData()->aErrHdl.IsSet() ) 1812*cdf0e10cSrcweir return (sal_Bool) GetSbData()->aErrHdl.Call( this ); 1813*cdf0e10cSrcweir else 1814*cdf0e10cSrcweir return ErrorHdl(); 1815*cdf0e10cSrcweir } 1816*cdf0e10cSrcweir 1817*cdf0e10cSrcweir void StarBASIC::Error( SbError n ) 1818*cdf0e10cSrcweir { 1819*cdf0e10cSrcweir Error( n, String() ); 1820*cdf0e10cSrcweir } 1821*cdf0e10cSrcweir 1822*cdf0e10cSrcweir void StarBASIC::Error( SbError n, const String& rMsg ) 1823*cdf0e10cSrcweir { 1824*cdf0e10cSrcweir if( pINST ) 1825*cdf0e10cSrcweir pINST->Error( n, rMsg ); 1826*cdf0e10cSrcweir } 1827*cdf0e10cSrcweir 1828*cdf0e10cSrcweir void StarBASIC::FatalError( SbError n ) 1829*cdf0e10cSrcweir { 1830*cdf0e10cSrcweir if( pINST ) 1831*cdf0e10cSrcweir pINST->FatalError( n ); 1832*cdf0e10cSrcweir } 1833*cdf0e10cSrcweir 1834*cdf0e10cSrcweir void StarBASIC::FatalError( SbError _errCode, const String& _details ) 1835*cdf0e10cSrcweir { 1836*cdf0e10cSrcweir if( pINST ) 1837*cdf0e10cSrcweir pINST->FatalError( _errCode, _details ); 1838*cdf0e10cSrcweir } 1839*cdf0e10cSrcweir 1840*cdf0e10cSrcweir SbError StarBASIC::GetErrBasic() 1841*cdf0e10cSrcweir { 1842*cdf0e10cSrcweir if( pINST ) 1843*cdf0e10cSrcweir return pINST->GetErr(); 1844*cdf0e10cSrcweir else 1845*cdf0e10cSrcweir return 0; 1846*cdf0e10cSrcweir } 1847*cdf0e10cSrcweir 1848*cdf0e10cSrcweir // #66536 Zusatz-Message fuer RTL-Funktion Error zugreifbar machen 1849*cdf0e10cSrcweir String StarBASIC::GetErrorMsg() 1850*cdf0e10cSrcweir { 1851*cdf0e10cSrcweir if( pINST ) 1852*cdf0e10cSrcweir return pINST->GetErrorMsg(); 1853*cdf0e10cSrcweir else 1854*cdf0e10cSrcweir return String(); 1855*cdf0e10cSrcweir } 1856*cdf0e10cSrcweir 1857*cdf0e10cSrcweir sal_uInt16 StarBASIC::GetErl() 1858*cdf0e10cSrcweir { 1859*cdf0e10cSrcweir if( pINST ) 1860*cdf0e10cSrcweir return pINST->GetErl(); 1861*cdf0e10cSrcweir else 1862*cdf0e10cSrcweir return 0; 1863*cdf0e10cSrcweir } 1864*cdf0e10cSrcweir 1865*cdf0e10cSrcweir sal_Bool __EXPORT StarBASIC::ErrorHdl() 1866*cdf0e10cSrcweir { 1867*cdf0e10cSrcweir return (sal_Bool) ( aErrorHdl.IsSet() 1868*cdf0e10cSrcweir ? aErrorHdl.Call( this ) : sal_False ); 1869*cdf0e10cSrcweir } 1870*cdf0e10cSrcweir 1871*cdf0e10cSrcweir Link StarBASIC::GetGlobalErrorHdl() 1872*cdf0e10cSrcweir { 1873*cdf0e10cSrcweir return GetSbData()->aErrHdl; 1874*cdf0e10cSrcweir } 1875*cdf0e10cSrcweir 1876*cdf0e10cSrcweir void StarBASIC::SetGlobalErrorHdl( const Link& rLink ) 1877*cdf0e10cSrcweir { 1878*cdf0e10cSrcweir GetSbData()->aErrHdl = rLink; 1879*cdf0e10cSrcweir } 1880*cdf0e10cSrcweir 1881*cdf0e10cSrcweir 1882*cdf0e10cSrcweir Link StarBASIC::GetGlobalBreakHdl() 1883*cdf0e10cSrcweir { 1884*cdf0e10cSrcweir return GetSbData()->aBreakHdl; 1885*cdf0e10cSrcweir } 1886*cdf0e10cSrcweir 1887*cdf0e10cSrcweir void StarBASIC::SetGlobalBreakHdl( const Link& rLink ) 1888*cdf0e10cSrcweir { 1889*cdf0e10cSrcweir GetSbData()->aBreakHdl = rLink; 1890*cdf0e10cSrcweir } 1891*cdf0e10cSrcweir 1892*cdf0e10cSrcweir SbxArrayRef StarBASIC::getUnoListeners( void ) 1893*cdf0e10cSrcweir { 1894*cdf0e10cSrcweir if( !xUnoListeners.Is() ) 1895*cdf0e10cSrcweir xUnoListeners = new SbxArray(); 1896*cdf0e10cSrcweir return xUnoListeners; 1897*cdf0e10cSrcweir } 1898*cdf0e10cSrcweir 1899*cdf0e10cSrcweir 1900*cdf0e10cSrcweir /************************************************************************** 1901*cdf0e10cSrcweir * 1902*cdf0e10cSrcweir * Laden und Speichern 1903*cdf0e10cSrcweir * 1904*cdf0e10cSrcweir **************************************************************************/ 1905*cdf0e10cSrcweir 1906*cdf0e10cSrcweir sal_Bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer ) 1907*cdf0e10cSrcweir { 1908*cdf0e10cSrcweir if( !SbxObject::LoadData( r, nVer ) ) 1909*cdf0e10cSrcweir return sal_False; 1910*cdf0e10cSrcweir 1911*cdf0e10cSrcweir // #95459 Delete dialogs, otherwise endless recursion 1912*cdf0e10cSrcweir // in SbxVarable::GetType() if dialogs are accessed 1913*cdf0e10cSrcweir sal_uInt16 nObjCount = pObjs->Count(); 1914*cdf0e10cSrcweir SbxVariable** ppDeleteTab = new SbxVariable*[ nObjCount ]; 1915*cdf0e10cSrcweir sal_uInt16 nObj; 1916*cdf0e10cSrcweir 1917*cdf0e10cSrcweir for( nObj = 0 ; nObj < nObjCount ; nObj++ ) 1918*cdf0e10cSrcweir { 1919*cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj ); 1920*cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST( StarBASIC, pVar ); 1921*cdf0e10cSrcweir ppDeleteTab[nObj] = pBasic ? NULL : pVar; 1922*cdf0e10cSrcweir } 1923*cdf0e10cSrcweir for( nObj = 0 ; nObj < nObjCount ; nObj++ ) 1924*cdf0e10cSrcweir { 1925*cdf0e10cSrcweir SbxVariable* pVar = ppDeleteTab[nObj]; 1926*cdf0e10cSrcweir if( pVar ) 1927*cdf0e10cSrcweir pObjs->Remove( pVar ); 1928*cdf0e10cSrcweir } 1929*cdf0e10cSrcweir delete[] ppDeleteTab; 1930*cdf0e10cSrcweir 1931*cdf0e10cSrcweir sal_uInt16 nMod; 1932*cdf0e10cSrcweir pModules->Clear(); 1933*cdf0e10cSrcweir r >> nMod; 1934*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nMod; i++ ) 1935*cdf0e10cSrcweir { 1936*cdf0e10cSrcweir SbModule* pMod = (SbModule*) SbxBase::Load( r ); 1937*cdf0e10cSrcweir if( !pMod ) 1938*cdf0e10cSrcweir return sal_False; 1939*cdf0e10cSrcweir else if( pMod->ISA(SbJScriptModule) ) 1940*cdf0e10cSrcweir { 1941*cdf0e10cSrcweir // Ref zuweisen, damit pMod deleted wird 1942*cdf0e10cSrcweir SbModuleRef xRef = pMod; 1943*cdf0e10cSrcweir } 1944*cdf0e10cSrcweir else 1945*cdf0e10cSrcweir { 1946*cdf0e10cSrcweir pMod->SetParent( this ); 1947*cdf0e10cSrcweir pModules->Put( pMod, i ); 1948*cdf0e10cSrcweir } 1949*cdf0e10cSrcweir } 1950*cdf0e10cSrcweir // HACK fuer SFX-Mist! 1951*cdf0e10cSrcweir SbxVariable* p = Find( String( RTL_CONSTASCII_USTRINGPARAM("FALSE") ), SbxCLASS_PROPERTY ); 1952*cdf0e10cSrcweir if( p ) 1953*cdf0e10cSrcweir Remove( p ); 1954*cdf0e10cSrcweir p = Find( String( RTL_CONSTASCII_USTRINGPARAM("TRUE") ), SbxCLASS_PROPERTY ); 1955*cdf0e10cSrcweir if( p ) 1956*cdf0e10cSrcweir Remove( p ); 1957*cdf0e10cSrcweir // Ende des Hacks! 1958*cdf0e10cSrcweir // Suche ueber StarBASIC ist immer global 1959*cdf0e10cSrcweir DBG_ASSERT( IsSet( SBX_GBLSEARCH ), "Basic ohne GBLSEARCH geladen" ); 1960*cdf0e10cSrcweir SetFlag( SBX_GBLSEARCH ); 1961*cdf0e10cSrcweir return sal_True; 1962*cdf0e10cSrcweir } 1963*cdf0e10cSrcweir 1964*cdf0e10cSrcweir sal_Bool StarBASIC::StoreData( SvStream& r ) const 1965*cdf0e10cSrcweir { 1966*cdf0e10cSrcweir if( !SbxObject::StoreData( r ) ) 1967*cdf0e10cSrcweir return sal_False; 1968*cdf0e10cSrcweir r << (sal_uInt16) pModules->Count(); 1969*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pModules->Count(); i++ ) 1970*cdf0e10cSrcweir { 1971*cdf0e10cSrcweir SbModule* p = (SbModule*) pModules->Get( i ); 1972*cdf0e10cSrcweir if( !p->Store( r ) ) 1973*cdf0e10cSrcweir return sal_False; 1974*cdf0e10cSrcweir } 1975*cdf0e10cSrcweir return sal_True; 1976*cdf0e10cSrcweir } 1977*cdf0e10cSrcweir 1978*cdf0e10cSrcweir sal_Bool StarBASIC::LoadOldModules( SvStream& ) 1979*cdf0e10cSrcweir { 1980*cdf0e10cSrcweir return sal_False; 1981*cdf0e10cSrcweir } 1982*cdf0e10cSrcweir 1983*cdf0e10cSrcweir bool StarBASIC::GetUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut ) 1984*cdf0e10cSrcweir { 1985*cdf0e10cSrcweir bool bRes = false; 1986*cdf0e10cSrcweir ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) ); 1987*cdf0e10cSrcweir SbUnoObject* pGlobs = dynamic_cast<SbUnoObject*>( Find( sVarName, SbxCLASS_DONTCARE ) ); 1988*cdf0e10cSrcweir if ( pGlobs ) 1989*cdf0e10cSrcweir { 1990*cdf0e10cSrcweir aOut = pGlobs->getUnoAny(); 1991*cdf0e10cSrcweir bRes = true; 1992*cdf0e10cSrcweir } 1993*cdf0e10cSrcweir return bRes; 1994*cdf0e10cSrcweir } 1995*cdf0e10cSrcweir 1996*cdf0e10cSrcweir Reference< frame::XModel > StarBASIC::GetModelFromBasic( SbxObject* pBasic ) 1997*cdf0e10cSrcweir { 1998*cdf0e10cSrcweir OSL_PRECOND( pBasic != NULL, "getModelFromBasic: illegal call!" ); 1999*cdf0e10cSrcweir if ( !pBasic ) 2000*cdf0e10cSrcweir return NULL; 2001*cdf0e10cSrcweir 2002*cdf0e10cSrcweir // look for the ThisComponent variable, first in the parent (which 2003*cdf0e10cSrcweir // might be the document's Basic), then in the parent's parent (which might be 2004*cdf0e10cSrcweir // the application Basic) 2005*cdf0e10cSrcweir const ::rtl::OUString sThisComponent( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) ); 2006*cdf0e10cSrcweir SbxVariable* pThisComponent = NULL; 2007*cdf0e10cSrcweir 2008*cdf0e10cSrcweir SbxObject* pLookup = pBasic->GetParent(); 2009*cdf0e10cSrcweir while ( pLookup && !pThisComponent ) 2010*cdf0e10cSrcweir { 2011*cdf0e10cSrcweir pThisComponent = pLookup->Find( sThisComponent, SbxCLASS_OBJECT ); 2012*cdf0e10cSrcweir pLookup = pLookup->GetParent(); 2013*cdf0e10cSrcweir } 2014*cdf0e10cSrcweir if ( !pThisComponent ) 2015*cdf0e10cSrcweir { 2016*cdf0e10cSrcweir OSL_TRACE("Failed to get ThisComponent"); 2017*cdf0e10cSrcweir // the application Basic, at the latest, should have this variable 2018*cdf0e10cSrcweir return NULL; 2019*cdf0e10cSrcweir } 2020*cdf0e10cSrcweir 2021*cdf0e10cSrcweir Any aThisComponentAny( sbxToUnoValue( pThisComponent ) ); 2022*cdf0e10cSrcweir Reference< frame::XModel > xModel( aThisComponentAny, UNO_QUERY ); 2023*cdf0e10cSrcweir if ( !xModel.is() ) 2024*cdf0e10cSrcweir { 2025*cdf0e10cSrcweir // it's no XModel. Okay, ThisComponent nowadays is allowed to be a controller. 2026*cdf0e10cSrcweir Reference< frame::XController > xController( aThisComponentAny, UNO_QUERY ); 2027*cdf0e10cSrcweir if ( xController.is() ) 2028*cdf0e10cSrcweir xModel = xController->getModel(); 2029*cdf0e10cSrcweir } 2030*cdf0e10cSrcweir 2031*cdf0e10cSrcweir if ( !xModel.is() ) 2032*cdf0e10cSrcweir return NULL; 2033*cdf0e10cSrcweir 2034*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 2035*cdf0e10cSrcweir OSL_TRACE("Have model ThisComponent points to url %s", 2036*cdf0e10cSrcweir ::rtl::OUStringToOString( xModel->getURL(), 2037*cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 2038*cdf0e10cSrcweir #endif 2039*cdf0e10cSrcweir 2040*cdf0e10cSrcweir return xModel; 2041*cdf0e10cSrcweir } 2042*cdf0e10cSrcweir 2043*cdf0e10cSrcweir 2044*cdf0e10cSrcweir //======================================================================== 2045*cdf0e10cSrcweir // #118116 Implementation Collection object 2046*cdf0e10cSrcweir 2047*cdf0e10cSrcweir TYPEINIT1(BasicCollection,SbxObject) 2048*cdf0e10cSrcweir 2049*cdf0e10cSrcweir static const char pCountStr[] = "Count"; 2050*cdf0e10cSrcweir static const char pAddStr[] = "Add"; 2051*cdf0e10cSrcweir static const char pItemStr[] = "Item"; 2052*cdf0e10cSrcweir static const char pRemoveStr[] = "Remove"; 2053*cdf0e10cSrcweir static sal_uInt16 nCountHash = 0, nAddHash, nItemHash, nRemoveHash; 2054*cdf0e10cSrcweir 2055*cdf0e10cSrcweir SbxInfoRef BasicCollection::xAddInfo = NULL; 2056*cdf0e10cSrcweir SbxInfoRef BasicCollection::xItemInfo = NULL; 2057*cdf0e10cSrcweir 2058*cdf0e10cSrcweir BasicCollection::BasicCollection( const XubString& rClass ) 2059*cdf0e10cSrcweir : SbxObject( rClass ) 2060*cdf0e10cSrcweir { 2061*cdf0e10cSrcweir if( !nCountHash ) 2062*cdf0e10cSrcweir { 2063*cdf0e10cSrcweir nCountHash = MakeHashCode( String::CreateFromAscii( pCountStr ) ); 2064*cdf0e10cSrcweir nAddHash = MakeHashCode( String::CreateFromAscii( pAddStr ) ); 2065*cdf0e10cSrcweir nItemHash = MakeHashCode( String::CreateFromAscii( pItemStr ) ); 2066*cdf0e10cSrcweir nRemoveHash = MakeHashCode( String::CreateFromAscii( pRemoveStr ) ); 2067*cdf0e10cSrcweir } 2068*cdf0e10cSrcweir Initialize(); 2069*cdf0e10cSrcweir 2070*cdf0e10cSrcweir } 2071*cdf0e10cSrcweir 2072*cdf0e10cSrcweir BasicCollection::~BasicCollection() 2073*cdf0e10cSrcweir {} 2074*cdf0e10cSrcweir 2075*cdf0e10cSrcweir void BasicCollection::Clear() 2076*cdf0e10cSrcweir { 2077*cdf0e10cSrcweir SbxObject::Clear(); 2078*cdf0e10cSrcweir Initialize(); 2079*cdf0e10cSrcweir } 2080*cdf0e10cSrcweir 2081*cdf0e10cSrcweir void BasicCollection::Initialize() 2082*cdf0e10cSrcweir { 2083*cdf0e10cSrcweir xItemArray = new SbxArray(); 2084*cdf0e10cSrcweir SetType( SbxOBJECT ); 2085*cdf0e10cSrcweir SetFlag( SBX_FIXED ); 2086*cdf0e10cSrcweir ResetFlag( SBX_WRITE ); 2087*cdf0e10cSrcweir SbxVariable* p; 2088*cdf0e10cSrcweir p = Make( String::CreateFromAscii( pCountStr ), SbxCLASS_PROPERTY, SbxINTEGER ); 2089*cdf0e10cSrcweir p->ResetFlag( SBX_WRITE ); 2090*cdf0e10cSrcweir p->SetFlag( SBX_DONTSTORE ); 2091*cdf0e10cSrcweir p = Make( String::CreateFromAscii( pAddStr ), SbxCLASS_METHOD, SbxEMPTY ); 2092*cdf0e10cSrcweir p->SetFlag( SBX_DONTSTORE ); 2093*cdf0e10cSrcweir p = Make( String::CreateFromAscii( pItemStr ), SbxCLASS_METHOD, SbxVARIANT ); 2094*cdf0e10cSrcweir p->SetFlag( SBX_DONTSTORE ); 2095*cdf0e10cSrcweir p = Make( String::CreateFromAscii( pRemoveStr ), SbxCLASS_METHOD, SbxEMPTY ); 2096*cdf0e10cSrcweir p->SetFlag( SBX_DONTSTORE ); 2097*cdf0e10cSrcweir if ( !xAddInfo.Is() ) 2098*cdf0e10cSrcweir { 2099*cdf0e10cSrcweir xAddInfo = new SbxInfo; 2100*cdf0e10cSrcweir xAddInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("Item") ), SbxVARIANT, SBX_READ ); 2101*cdf0e10cSrcweir xAddInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("Key") ), SbxVARIANT, SBX_READ | SBX_OPTIONAL ); 2102*cdf0e10cSrcweir xAddInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("Before") ), SbxVARIANT, SBX_READ | SBX_OPTIONAL ); 2103*cdf0e10cSrcweir xAddInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("After") ), SbxVARIANT, SBX_READ | SBX_OPTIONAL ); 2104*cdf0e10cSrcweir } 2105*cdf0e10cSrcweir if ( !xItemInfo.Is() ) 2106*cdf0e10cSrcweir { 2107*cdf0e10cSrcweir xItemInfo = new SbxInfo; 2108*cdf0e10cSrcweir xItemInfo->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("Index") ), SbxVARIANT, SBX_READ | SBX_OPTIONAL); 2109*cdf0e10cSrcweir } 2110*cdf0e10cSrcweir } 2111*cdf0e10cSrcweir 2112*cdf0e10cSrcweir SbxVariable* BasicCollection::Find( const XubString& rName, SbxClassType t ) 2113*cdf0e10cSrcweir { 2114*cdf0e10cSrcweir SbxVariable* pFind = SbxObject::Find( rName, t ); 2115*cdf0e10cSrcweir return pFind; 2116*cdf0e10cSrcweir } 2117*cdf0e10cSrcweir 2118*cdf0e10cSrcweir void BasicCollection::SFX_NOTIFY( SfxBroadcaster& rCst, const TypeId& rId1, 2119*cdf0e10cSrcweir const SfxHint& rHint, const TypeId& rId2 ) 2120*cdf0e10cSrcweir { 2121*cdf0e10cSrcweir const SbxHint* p = PTR_CAST(SbxHint,&rHint); 2122*cdf0e10cSrcweir if( p ) 2123*cdf0e10cSrcweir { 2124*cdf0e10cSrcweir sal_uIntPtr nId = p->GetId(); 2125*cdf0e10cSrcweir sal_Bool bRead = sal_Bool( nId == SBX_HINT_DATAWANTED ); 2126*cdf0e10cSrcweir sal_Bool bWrite = sal_Bool( nId == SBX_HINT_DATACHANGED ); 2127*cdf0e10cSrcweir sal_Bool bRequestInfo = sal_Bool( nId == SBX_HINT_INFOWANTED ); 2128*cdf0e10cSrcweir SbxVariable* pVar = p->GetVar(); 2129*cdf0e10cSrcweir SbxArray* pArg = pVar->GetParameters(); 2130*cdf0e10cSrcweir XubString aVarName( pVar->GetName() ); 2131*cdf0e10cSrcweir if( bRead || bWrite ) 2132*cdf0e10cSrcweir { 2133*cdf0e10cSrcweir if( pVar->GetHashCode() == nCountHash 2134*cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pCountStr ) ) 2135*cdf0e10cSrcweir pVar->PutLong( xItemArray->Count32() ); 2136*cdf0e10cSrcweir else if( pVar->GetHashCode() == nAddHash 2137*cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pAddStr ) ) 2138*cdf0e10cSrcweir CollAdd( pArg ); 2139*cdf0e10cSrcweir else if( pVar->GetHashCode() == nItemHash 2140*cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pItemStr ) ) 2141*cdf0e10cSrcweir CollItem( pArg ); 2142*cdf0e10cSrcweir else if( pVar->GetHashCode() == nRemoveHash 2143*cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pRemoveStr ) ) 2144*cdf0e10cSrcweir CollRemove( pArg ); 2145*cdf0e10cSrcweir else 2146*cdf0e10cSrcweir SbxObject::SFX_NOTIFY( rCst, rId1, rHint, rId2 ); 2147*cdf0e10cSrcweir return; 2148*cdf0e10cSrcweir } 2149*cdf0e10cSrcweir else if ( bRequestInfo ) 2150*cdf0e10cSrcweir { 2151*cdf0e10cSrcweir if( pVar->GetHashCode() == nAddHash 2152*cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pAddStr ) ) 2153*cdf0e10cSrcweir pVar->SetInfo( xAddInfo ); 2154*cdf0e10cSrcweir else if( pVar->GetHashCode() == nItemHash 2155*cdf0e10cSrcweir && aVarName.EqualsIgnoreCaseAscii( pItemStr ) ) 2156*cdf0e10cSrcweir pVar->SetInfo( xItemInfo ); 2157*cdf0e10cSrcweir } 2158*cdf0e10cSrcweir } 2159*cdf0e10cSrcweir SbxObject::SFX_NOTIFY( rCst, rId1, rHint, rId2 ); 2160*cdf0e10cSrcweir } 2161*cdf0e10cSrcweir 2162*cdf0e10cSrcweir sal_Int32 BasicCollection::implGetIndex( SbxVariable* pIndexVar ) 2163*cdf0e10cSrcweir { 2164*cdf0e10cSrcweir sal_Int32 nIndex = -1; 2165*cdf0e10cSrcweir if( pIndexVar->GetType() == SbxSTRING ) 2166*cdf0e10cSrcweir nIndex = implGetIndexForName( pIndexVar->GetString() ); 2167*cdf0e10cSrcweir else 2168*cdf0e10cSrcweir nIndex = pIndexVar->GetLong() - 1; 2169*cdf0e10cSrcweir return nIndex; 2170*cdf0e10cSrcweir } 2171*cdf0e10cSrcweir 2172*cdf0e10cSrcweir sal_Int32 BasicCollection::implGetIndexForName( const String& rName ) 2173*cdf0e10cSrcweir { 2174*cdf0e10cSrcweir sal_Int32 nIndex = -1; 2175*cdf0e10cSrcweir sal_Int32 nCount = xItemArray->Count32(); 2176*cdf0e10cSrcweir sal_Int32 nNameHash = MakeHashCode( rName ); 2177*cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nCount ; i++ ) 2178*cdf0e10cSrcweir { 2179*cdf0e10cSrcweir SbxVariable* pVar = xItemArray->Get32( i ); 2180*cdf0e10cSrcweir if( pVar->GetHashCode() == nNameHash && 2181*cdf0e10cSrcweir pVar->GetName().EqualsIgnoreCaseAscii( rName ) ) 2182*cdf0e10cSrcweir { 2183*cdf0e10cSrcweir nIndex = i; 2184*cdf0e10cSrcweir break; 2185*cdf0e10cSrcweir } 2186*cdf0e10cSrcweir } 2187*cdf0e10cSrcweir return nIndex; 2188*cdf0e10cSrcweir } 2189*cdf0e10cSrcweir 2190*cdf0e10cSrcweir void BasicCollection::CollAdd( SbxArray* pPar_ ) 2191*cdf0e10cSrcweir { 2192*cdf0e10cSrcweir sal_uInt16 nCount = pPar_->Count(); 2193*cdf0e10cSrcweir if( nCount < 2 || nCount > 5 ) 2194*cdf0e10cSrcweir { 2195*cdf0e10cSrcweir SetError( SbxERR_WRONG_ARGS ); 2196*cdf0e10cSrcweir return; 2197*cdf0e10cSrcweir } 2198*cdf0e10cSrcweir 2199*cdf0e10cSrcweir SbxVariable* pItem = pPar_->Get(1); 2200*cdf0e10cSrcweir if( pItem ) 2201*cdf0e10cSrcweir { 2202*cdf0e10cSrcweir int nNextIndex; 2203*cdf0e10cSrcweir if( nCount < 4 ) 2204*cdf0e10cSrcweir { 2205*cdf0e10cSrcweir nNextIndex = xItemArray->Count(); 2206*cdf0e10cSrcweir } 2207*cdf0e10cSrcweir else 2208*cdf0e10cSrcweir { 2209*cdf0e10cSrcweir SbxVariable* pBefore = pPar_->Get(3); 2210*cdf0e10cSrcweir if( nCount == 5 ) 2211*cdf0e10cSrcweir { 2212*cdf0e10cSrcweir if( !( pBefore->IsErr() || ( pBefore->GetType() == SbxEMPTY ) ) ) 2213*cdf0e10cSrcweir { 2214*cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT ); 2215*cdf0e10cSrcweir return; 2216*cdf0e10cSrcweir } 2217*cdf0e10cSrcweir SbxVariable* pAfter = pPar_->Get(4); 2218*cdf0e10cSrcweir sal_Int32 nAfterIndex = implGetIndex( pAfter ); 2219*cdf0e10cSrcweir if( nAfterIndex == -1 ) 2220*cdf0e10cSrcweir { 2221*cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT ); 2222*cdf0e10cSrcweir return; 2223*cdf0e10cSrcweir } 2224*cdf0e10cSrcweir nNextIndex = nAfterIndex + 1; 2225*cdf0e10cSrcweir } 2226*cdf0e10cSrcweir else // if( nCount == 4 ) 2227*cdf0e10cSrcweir { 2228*cdf0e10cSrcweir sal_Int32 nBeforeIndex = implGetIndex( pBefore ); 2229*cdf0e10cSrcweir if( nBeforeIndex == -1 ) 2230*cdf0e10cSrcweir { 2231*cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT ); 2232*cdf0e10cSrcweir return; 2233*cdf0e10cSrcweir } 2234*cdf0e10cSrcweir nNextIndex = nBeforeIndex; 2235*cdf0e10cSrcweir } 2236*cdf0e10cSrcweir } 2237*cdf0e10cSrcweir 2238*cdf0e10cSrcweir SbxVariableRef pNewItem = new SbxVariable( *pItem ); 2239*cdf0e10cSrcweir if( nCount >= 3 ) 2240*cdf0e10cSrcweir { 2241*cdf0e10cSrcweir SbxVariable* pKey = pPar_->Get(2); 2242*cdf0e10cSrcweir if( !( pKey->IsErr() || ( pKey->GetType() == SbxEMPTY ) ) ) 2243*cdf0e10cSrcweir { 2244*cdf0e10cSrcweir if( pKey->GetType() != SbxSTRING ) 2245*cdf0e10cSrcweir { 2246*cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT ); 2247*cdf0e10cSrcweir return; 2248*cdf0e10cSrcweir } 2249*cdf0e10cSrcweir String aKey = pKey->GetString(); 2250*cdf0e10cSrcweir if( implGetIndexForName( aKey ) != -1 ) 2251*cdf0e10cSrcweir { 2252*cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT ); 2253*cdf0e10cSrcweir return; 2254*cdf0e10cSrcweir } 2255*cdf0e10cSrcweir pNewItem->SetName( aKey ); 2256*cdf0e10cSrcweir } 2257*cdf0e10cSrcweir } 2258*cdf0e10cSrcweir pNewItem->SetFlag( SBX_READWRITE ); 2259*cdf0e10cSrcweir xItemArray->Insert32( pNewItem, nNextIndex ); 2260*cdf0e10cSrcweir } 2261*cdf0e10cSrcweir else 2262*cdf0e10cSrcweir { 2263*cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT ); 2264*cdf0e10cSrcweir return; 2265*cdf0e10cSrcweir } 2266*cdf0e10cSrcweir } 2267*cdf0e10cSrcweir 2268*cdf0e10cSrcweir void BasicCollection::CollItem( SbxArray* pPar_ ) 2269*cdf0e10cSrcweir { 2270*cdf0e10cSrcweir if( pPar_->Count() != 2 ) 2271*cdf0e10cSrcweir { 2272*cdf0e10cSrcweir SetError( SbxERR_WRONG_ARGS ); 2273*cdf0e10cSrcweir return; 2274*cdf0e10cSrcweir } 2275*cdf0e10cSrcweir SbxVariable* pRes = NULL; 2276*cdf0e10cSrcweir SbxVariable* p = pPar_->Get( 1 ); 2277*cdf0e10cSrcweir sal_Int32 nIndex = implGetIndex( p ); 2278*cdf0e10cSrcweir if( nIndex >= 0 && nIndex < (sal_Int32)xItemArray->Count32() ) 2279*cdf0e10cSrcweir pRes = xItemArray->Get32( nIndex ); 2280*cdf0e10cSrcweir if( !pRes ) 2281*cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT ); 2282*cdf0e10cSrcweir else 2283*cdf0e10cSrcweir *(pPar_->Get(0)) = *pRes; 2284*cdf0e10cSrcweir } 2285*cdf0e10cSrcweir 2286*cdf0e10cSrcweir void BasicCollection::CollRemove( SbxArray* pPar_ ) 2287*cdf0e10cSrcweir { 2288*cdf0e10cSrcweir if( pPar_ == NULL || pPar_->Count() != 2 ) 2289*cdf0e10cSrcweir { 2290*cdf0e10cSrcweir SetError( SbxERR_WRONG_ARGS ); 2291*cdf0e10cSrcweir return; 2292*cdf0e10cSrcweir } 2293*cdf0e10cSrcweir 2294*cdf0e10cSrcweir SbxVariable* p = pPar_->Get( 1 ); 2295*cdf0e10cSrcweir sal_Int32 nIndex = implGetIndex( p ); 2296*cdf0e10cSrcweir if( nIndex >= 0 && nIndex < (sal_Int32)xItemArray->Count32() ) 2297*cdf0e10cSrcweir { 2298*cdf0e10cSrcweir xItemArray->Remove32( nIndex ); 2299*cdf0e10cSrcweir 2300*cdf0e10cSrcweir // Correct for stack if necessary 2301*cdf0e10cSrcweir SbiInstance* pInst = pINST; 2302*cdf0e10cSrcweir SbiRuntime* pRT = pInst ? pInst->pRun : NULL; 2303*cdf0e10cSrcweir if( pRT ) 2304*cdf0e10cSrcweir { 2305*cdf0e10cSrcweir SbiForStack* pStack = pRT->FindForStackItemForCollection( this ); 2306*cdf0e10cSrcweir if( pStack != NULL ) 2307*cdf0e10cSrcweir { 2308*cdf0e10cSrcweir if( pStack->nCurCollectionIndex >= nIndex ) 2309*cdf0e10cSrcweir --pStack->nCurCollectionIndex; 2310*cdf0e10cSrcweir } 2311*cdf0e10cSrcweir } 2312*cdf0e10cSrcweir } 2313*cdf0e10cSrcweir else 2314*cdf0e10cSrcweir SetError( SbERR_BAD_ARGUMENT ); 2315*cdf0e10cSrcweir } 2316*cdf0e10cSrcweir 2317