LCOV - code coverage report
Current view: top level - sw/source/core/doc - docbasic.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 14 101 13.9 %
Date: 2012-08-25 Functions: 1 3 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 167 3.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <hintids.hxx>
      30                 :            : 
      31                 :            : #include <rtl/ustring.hxx>
      32                 :            : #include <svtools/imap.hxx>
      33                 :            : #include <svtools/imapobj.hxx>
      34                 :            : #include <basic/sbx.hxx>
      35                 :            : #include <frmfmt.hxx>
      36                 :            : #include <fmtinfmt.hxx>
      37                 :            : #include <fmturl.hxx>
      38                 :            : #include <frmatr.hxx>
      39                 :            : #include <docary.hxx>
      40                 :            : #include <doc.hxx>
      41                 :            : #include <docsh.hxx>
      42                 :            : #include <swevent.hxx>
      43                 :            : 
      44                 :            : using namespace ::com::sun::star::uno;
      45                 :            : using ::rtl::OUString;
      46                 :            : 
      47                 :          0 : static Sequence<Any> *lcl_docbasic_convertArgs( SbxArray& rArgs )
      48                 :            : {
      49                 :          0 :     Sequence<Any> *pRet = 0;
      50                 :            : 
      51                 :          0 :     sal_uInt16 nCount = rArgs.Count();
      52         [ #  # ]:          0 :     if( nCount > 1 )
      53                 :            :     {
      54                 :          0 :         nCount--;
      55         [ #  # ]:          0 :         pRet = new Sequence<Any>( nCount );
      56                 :          0 :         Any *pUnoArgs = pRet->getArray();
      57         [ #  # ]:          0 :         for( sal_uInt16 i=0; i<nCount; i++ )
      58                 :            :         {
      59                 :          0 :             SbxVariable *pVar = rArgs.Get( i+1 );
      60   [ #  #  #  #  :          0 :             switch( pVar->GetType() )
                      # ]
      61                 :            :             {
      62                 :            :             case SbxSTRING:
      63         [ #  # ]:          0 :                 pUnoArgs[i] <<= OUString( pVar->GetString() );
      64                 :          0 :                 break;
      65                 :            :             case SbxCHAR:
      66         [ #  # ]:          0 :                 pUnoArgs[i] <<= (sal_Int16)pVar->GetChar() ;
      67                 :          0 :                 break;
      68                 :            :             case SbxUSHORT:
      69         [ #  # ]:          0 :                 pUnoArgs[i] <<= (sal_Int16)pVar->GetUShort();
      70                 :          0 :                 break;
      71                 :            :             case SbxLONG:
      72         [ #  # ]:          0 :                 pUnoArgs[i] <<= (sal_Int32)pVar->GetLong();
      73                 :          0 :                 break;
      74                 :            :             default:
      75                 :          0 :                 pUnoArgs[i].setValue(0, ::getVoidCppuType());
      76                 :          0 :                 break;
      77                 :            :             }
      78                 :            :         }
      79                 :            :     }
      80                 :            : 
      81                 :          0 :     return pRet;
      82                 :            : }
      83                 :            : 
      84                 :          0 : sal_Bool SwDoc::ExecMacro( const SvxMacro& rMacro, String* pRet, SbxArray* pArgs )
      85                 :            : {
      86                 :          0 :     ErrCode eErr = 0;
      87   [ #  #  #  # ]:          0 :     switch( rMacro.GetScriptType() )
      88                 :            :     {
      89                 :            :     case STARBASIC:
      90                 :            :         {
      91                 :          0 :             SbxBaseRef aRef;
      92 [ #  # ][ #  # ]:          0 :             SbxValue* pRetValue = new SbxValue;
      93         [ #  # ]:          0 :             aRef = pRetValue;
      94                 :          0 :             eErr = pDocShell->CallBasic( rMacro.GetMacName(),
      95                 :          0 :                                          rMacro.GetLibName(),
      96         [ #  # ]:          0 :                                          pArgs, pRet ? pRetValue : 0 );
           [ #  #  #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      97                 :            : 
      98 [ #  # ][ #  # ]:          0 :             if( pRet && SbxNULL <  pRetValue->GetType() &&
         [ #  # ][ #  # ]
                 [ #  # ]
      99         [ #  # ]:          0 :                         SbxVOID != pRetValue->GetType() )
     100                 :            :                 // valid value, so set it
     101 [ #  # ][ #  # ]:          0 :                 *pRet = pRetValue->GetString();
                 [ #  # ]
     102                 :            :         }
     103                 :          0 :         break;
     104                 :            :     case JAVASCRIPT:
     105                 :            :         // ignore JavaScript calls
     106                 :          0 :         break;
     107                 :            :     case EXTENDED_STYPE:
     108                 :            :         {
     109                 :          0 :             Sequence<Any> *pUnoArgs = 0;
     110         [ #  # ]:          0 :             if( pArgs )
     111                 :            :             {
     112                 :            :                 // better to rename the local function to lcl_translateBasic2Uno and
     113                 :            :                 // a much shorter routine can be found in sfx2/source/doc/objmisc.cxx
     114         [ #  # ]:          0 :                 pUnoArgs = lcl_docbasic_convertArgs( *pArgs );
     115                 :            :             }
     116                 :            : 
     117         [ #  # ]:          0 :             if (!pUnoArgs)
     118                 :            :             {
     119         [ #  # ]:          0 :                 pUnoArgs = new Sequence< Any > (0);
     120                 :            :             }
     121                 :            : 
     122                 :            :             // TODO - return value is not handled
     123                 :          0 :             Any aRet;
     124         [ #  # ]:          0 :             Sequence< sal_Int16 > aOutArgsIndex;
     125         [ #  # ]:          0 :             Sequence< Any > aOutArgs;
     126                 :            : 
     127                 :            :             OSL_TRACE( "SwDoc::ExecMacro URL is %s", rtl::OUStringToOString( rMacro.GetMacName(),
     128                 :            :                 RTL_TEXTENCODING_UTF8).getStr() );
     129                 :            : 
     130                 :            :             eErr = pDocShell->CallXScript(
     131 [ #  # ][ #  # ]:          0 :                 rMacro.GetMacName(), *pUnoArgs, aRet, aOutArgsIndex, aOutArgs);
                 [ #  # ]
     132                 :            : 
     133 [ #  # ][ #  # ]:          0 :             delete pUnoArgs;
     134 [ #  # ][ #  # ]:          0 :             break;
     135                 :            :         }
     136                 :            :     }
     137                 :            : 
     138                 :          0 :     return 0 == eErr;
     139                 :            : }
     140                 :            : 
     141                 :            : 
     142                 :            : 
     143                 :         12 : sal_uInt16 SwDoc::CallEvent( sal_uInt16 nEvent, const SwCallMouseEvent& rCallEvent,
     144                 :            :                     sal_Bool bCheckPtr, SbxArray* pArgs, const Link* )
     145                 :            : {
     146         [ -  + ]:         12 :     if( !pDocShell )        // we can't do that without a DocShell!
     147                 :          0 :         return 0;
     148                 :            : 
     149                 :         12 :     sal_uInt16 nRet = 0;
     150                 :         12 :     const SvxMacroTableDtor* pTbl = 0;
     151   [ -  +  -  - ]:         12 :     switch( rCallEvent.eType )
     152                 :            :     {
     153                 :            :     case EVENT_OBJECT_INETATTR:
     154         [ #  # ]:          0 :         if( bCheckPtr  )
     155                 :            :         {
     156                 :            :             const SfxPoolItem* pItem;
     157                 :          0 :             sal_uInt32 n, nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
     158         [ #  # ]:          0 :             for( n = 0; n < nMaxItems; ++n )
     159 [ #  # ][ #  # ]:          0 :                 if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_INETFMT, n ) )
                 [ #  # ]
     160                 :            :                     && rCallEvent.PTR.pINetAttr == pItem )
     161                 :            :                 {
     162                 :          0 :                     bCheckPtr = sal_False;       // misuse as a flag
     163                 :          0 :                     break;
     164                 :            :                 }
     165                 :            :         }
     166         [ #  # ]:          0 :         if( !bCheckPtr )
     167                 :          0 :             pTbl = rCallEvent.PTR.pINetAttr->GetMacroTbl();
     168                 :          0 :         break;
     169                 :            : 
     170                 :            :     case EVENT_OBJECT_URLITEM:
     171                 :            :     case EVENT_OBJECT_IMAGE:
     172                 :            :         {
     173                 :         12 :             const SwFrmFmt* pFmt = (SwFrmFmt*)rCallEvent.PTR.pFmt;
     174         [ -  + ]:         12 :             if( bCheckPtr )
     175                 :            :             {
     176         [ #  # ]:          0 :                 if ( GetSpzFrmFmts()->Contains( pFmt ) )
     177                 :          0 :                     bCheckPtr = sal_False;      // misuse as a flag
     178                 :            :             }
     179         [ +  - ]:         12 :             if( !bCheckPtr )
     180                 :         12 :                 pTbl = &pFmt->GetMacro().GetMacroTable();
     181                 :            :         }
     182                 :         12 :         break;
     183                 :            : 
     184                 :            :     case EVENT_OBJECT_IMAGEMAP:
     185                 :            :         {
     186                 :          0 :             const IMapObject* pIMapObj = rCallEvent.PTR.IMAP.pIMapObj;
     187         [ #  # ]:          0 :             if( bCheckPtr )
     188                 :            :             {
     189                 :          0 :                 const SwFrmFmt* pFmt = (SwFrmFmt*)rCallEvent.PTR.IMAP.pFmt;
     190                 :            :                 const ImageMap* pIMap;
     191   [ #  #  #  # ]:          0 :                 if( GetSpzFrmFmts()->Contains( pFmt ) &&
                 [ #  # ]
     192                 :          0 :                     0 != (pIMap = pFmt->GetURL().GetMap()) )
     193                 :            :                 {
     194         [ #  # ]:          0 :                     for( sal_uInt16 nPos = pIMap->GetIMapObjectCount(); nPos; )
     195         [ #  # ]:          0 :                         if( pIMapObj == pIMap->GetIMapObject( --nPos ))
     196                 :            :                         {
     197                 :          0 :                             bCheckPtr = sal_False;      // misuse as a flag
     198                 :          0 :                             break;
     199                 :            :                         }
     200                 :            :                 }
     201                 :            :             }
     202         [ #  # ]:          0 :             if( !bCheckPtr )
     203                 :          0 :                 pTbl = &pIMapObj->GetMacroTable();
     204                 :            :         }
     205                 :          0 :         break;
     206                 :            :     default:
     207                 :          0 :         break;
     208                 :            :     }
     209                 :            : 
     210         [ +  - ]:         12 :     if( pTbl )
     211                 :            :     {
     212                 :         12 :         nRet = 0x1;
     213         [ -  + ]:         12 :         if( pTbl->IsKeyValid( nEvent ) )
     214                 :            :         {
     215                 :          0 :             const SvxMacro& rMacro = *pTbl->Get( nEvent );
     216         [ #  # ]:          0 :             if( STARBASIC == rMacro.GetScriptType() )
     217                 :            :             {
     218                 :          0 :                 nRet += 0 == pDocShell->CallBasic( rMacro.GetMacName(),
     219 [ #  # ][ #  # ]:          0 :                                     rMacro.GetLibName(), pArgs ) ? 1 : 0;
         [ #  # ][ #  # ]
     220                 :            :             }
     221         [ #  # ]:          0 :             else if( EXTENDED_STYPE == rMacro.GetScriptType() )
     222                 :            :             {
     223                 :          0 :                 Sequence<Any> *pUnoArgs = 0;
     224                 :            : 
     225         [ #  # ]:          0 :                 if( pArgs )
     226                 :            :                 {
     227         [ #  # ]:          0 :                     pUnoArgs = lcl_docbasic_convertArgs( *pArgs );
     228                 :            :                 }
     229                 :            : 
     230         [ #  # ]:          0 :                 if (!pUnoArgs)
     231                 :            :                 {
     232         [ #  # ]:          0 :                     pUnoArgs = new Sequence <Any> (0);
     233                 :            :                 }
     234                 :            : 
     235                 :          0 :                 Any aRet;
     236         [ #  # ]:          0 :                 Sequence< sal_Int16 > aOutArgsIndex;
     237         [ #  # ]:          0 :                 Sequence< Any > aOutArgs;
     238                 :            : 
     239                 :            :                 OSL_TRACE( "SwDoc::CallEvent URL is %s", rtl::OUStringToOString(
     240                 :            :                     rMacro.GetMacName(), RTL_TEXTENCODING_UTF8).getStr() );
     241                 :            : 
     242                 :            :                 nRet += 0 == pDocShell->CallXScript(
     243 [ #  # ][ #  # ]:          0 :                     rMacro.GetMacName(), *pUnoArgs,aRet, aOutArgsIndex, aOutArgs) ? 1 : 0;
         [ #  # ][ #  # ]
     244                 :            : 
     245 [ #  # ][ #  # ]:          0 :                 delete pUnoArgs;
         [ #  # ][ #  # ]
     246                 :            :             }
     247                 :            :             // JavaScript calls are ignored
     248                 :            :         }
     249                 :            :     }
     250                 :         12 :     return nRet;
     251                 :            : }
     252                 :            : 
     253                 :            : 
     254                 :            : 
     255                 :            : 
     256                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10