LCOV - code coverage report
Current view: top level - basic/source/classes - sb.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 340 1013 33.6 %
Date: 2012-08-25 Functions: 65 154 42.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 364 2306 15.8 %

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

Generated by: LCOV version 1.10