LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/doc - docbasic.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 102 0.0 %
Date: 2012-12-17 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          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             : #include <hintids.hxx>
      21             : 
      22             : #include <rtl/ustring.hxx>
      23             : #include <svtools/imap.hxx>
      24             : #include <svtools/imapobj.hxx>
      25             : #include <basic/sbx.hxx>
      26             : #include <frmfmt.hxx>
      27             : #include <fmtinfmt.hxx>
      28             : #include <fmturl.hxx>
      29             : #include <frmatr.hxx>
      30             : #include <docary.hxx>
      31             : #include <doc.hxx>
      32             : #include <docsh.hxx>
      33             : #include <swevent.hxx>
      34             : 
      35             : using namespace ::com::sun::star::uno;
      36             : using ::rtl::OUString;
      37             : 
      38           0 : static Sequence<Any> *lcl_docbasic_convertArgs( SbxArray& rArgs )
      39             : {
      40           0 :     Sequence<Any> *pRet = 0;
      41             : 
      42           0 :     sal_uInt16 nCount = rArgs.Count();
      43           0 :     if( nCount > 1 )
      44             :     {
      45           0 :         nCount--;
      46           0 :         pRet = new Sequence<Any>( nCount );
      47           0 :         Any *pUnoArgs = pRet->getArray();
      48           0 :         for( sal_uInt16 i=0; i<nCount; i++ )
      49             :         {
      50           0 :             SbxVariable *pVar = rArgs.Get( i+1 );
      51           0 :             switch( pVar->GetType() )
      52             :             {
      53             :             case SbxSTRING:
      54           0 :                 pUnoArgs[i] <<= OUString( pVar->GetOUString() );
      55           0 :                 break;
      56             :             case SbxCHAR:
      57           0 :                 pUnoArgs[i] <<= (sal_Int16)pVar->GetChar() ;
      58           0 :                 break;
      59             :             case SbxUSHORT:
      60           0 :                 pUnoArgs[i] <<= (sal_Int16)pVar->GetUShort();
      61           0 :                 break;
      62             :             case SbxLONG:
      63           0 :                 pUnoArgs[i] <<= (sal_Int32)pVar->GetLong();
      64           0 :                 break;
      65             :             default:
      66           0 :                 pUnoArgs[i].setValue(0, ::getVoidCppuType());
      67           0 :                 break;
      68             :             }
      69             :         }
      70             :     }
      71             : 
      72           0 :     return pRet;
      73             : }
      74             : 
      75           0 : bool SwDoc::ExecMacro( const SvxMacro& rMacro, String* pRet, SbxArray* pArgs )
      76             : {
      77           0 :     ErrCode eErr = 0;
      78           0 :     switch( rMacro.GetScriptType() )
      79             :     {
      80             :     case STARBASIC:
      81             :         {
      82           0 :             SbxBaseRef aRef;
      83           0 :             SbxValue* pRetValue = new SbxValue;
      84           0 :             aRef = pRetValue;
      85           0 :             eErr = pDocShell->CallBasic( rMacro.GetMacName(),
      86           0 :                                          rMacro.GetLibName(),
      87           0 :                                          pArgs, pRet ? pRetValue : 0 );
      88             : 
      89           0 :             if( pRet && SbxNULL <  pRetValue->GetType() &&
      90           0 :                         SbxVOID != pRetValue->GetType() )
      91             :             {
      92             :                 // valid value, so set it
      93           0 :                 *pRet = pRetValue->GetOUString();
      94           0 :             }
      95             :         }
      96           0 :         break;
      97             :     case JAVASCRIPT:
      98             :         // ignore JavaScript calls
      99           0 :         break;
     100             :     case EXTENDED_STYPE:
     101             :         {
     102           0 :             Sequence<Any> *pUnoArgs = 0;
     103           0 :             if( pArgs )
     104             :             {
     105             :                 // better to rename the local function to lcl_translateBasic2Uno and
     106             :                 // a much shorter routine can be found in sfx2/source/doc/objmisc.cxx
     107           0 :                 pUnoArgs = lcl_docbasic_convertArgs( *pArgs );
     108             :             }
     109             : 
     110           0 :             if (!pUnoArgs)
     111             :             {
     112           0 :                 pUnoArgs = new Sequence< Any > (0);
     113             :             }
     114             : 
     115             :             // TODO - return value is not handled
     116           0 :             Any aRet;
     117           0 :             Sequence< sal_Int16 > aOutArgsIndex;
     118           0 :             Sequence< Any > aOutArgs;
     119             : 
     120             :             OSL_TRACE( "SwDoc::ExecMacro URL is %s", rtl::OUStringToOString( rMacro.GetMacName(),
     121             :                 RTL_TEXTENCODING_UTF8).getStr() );
     122             : 
     123             :             eErr = pDocShell->CallXScript(
     124           0 :                 rMacro.GetMacName(), *pUnoArgs, aRet, aOutArgsIndex, aOutArgs);
     125             : 
     126           0 :             delete pUnoArgs;
     127           0 :             break;
     128             :         }
     129             :     }
     130             : 
     131           0 :     return 0 == eErr;
     132             : }
     133             : 
     134             : 
     135             : 
     136           0 : sal_uInt16 SwDoc::CallEvent( sal_uInt16 nEvent, const SwCallMouseEvent& rCallEvent,
     137             :                     bool bCheckPtr, SbxArray* pArgs, const Link* )
     138             : {
     139           0 :     if( !pDocShell )        // we can't do that without a DocShell!
     140           0 :         return 0;
     141             : 
     142           0 :     sal_uInt16 nRet = 0;
     143           0 :     const SvxMacroTableDtor* pTbl = 0;
     144           0 :     switch( rCallEvent.eType )
     145             :     {
     146             :     case EVENT_OBJECT_INETATTR:
     147           0 :         if( bCheckPtr  )
     148             :         {
     149             :             const SfxPoolItem* pItem;
     150           0 :             sal_uInt32 n, nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
     151           0 :             for( n = 0; n < nMaxItems; ++n )
     152           0 :                 if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_INETFMT, n ) )
     153             :                     && rCallEvent.PTR.pINetAttr == pItem )
     154             :                 {
     155           0 :                     bCheckPtr = false;       // misuse as a flag
     156           0 :                     break;
     157             :                 }
     158             :         }
     159           0 :         if( !bCheckPtr )
     160           0 :             pTbl = rCallEvent.PTR.pINetAttr->GetMacroTbl();
     161           0 :         break;
     162             : 
     163             :     case EVENT_OBJECT_URLITEM:
     164             :     case EVENT_OBJECT_IMAGE:
     165             :         {
     166           0 :             const SwFrmFmt* pFmt = (SwFrmFmt*)rCallEvent.PTR.pFmt;
     167           0 :             if( bCheckPtr )
     168             :             {
     169           0 :                 if ( GetSpzFrmFmts()->Contains( pFmt ) )
     170           0 :                     bCheckPtr = false;      // misuse as a flag
     171             :             }
     172           0 :             if( !bCheckPtr )
     173           0 :                 pTbl = &pFmt->GetMacro().GetMacroTable();
     174             :         }
     175           0 :         break;
     176             : 
     177             :     case EVENT_OBJECT_IMAGEMAP:
     178             :         {
     179           0 :             const IMapObject* pIMapObj = rCallEvent.PTR.IMAP.pIMapObj;
     180           0 :             if( bCheckPtr )
     181             :             {
     182           0 :                 const SwFrmFmt* pFmt = (SwFrmFmt*)rCallEvent.PTR.IMAP.pFmt;
     183             :                 const ImageMap* pIMap;
     184           0 :                 if( GetSpzFrmFmts()->Contains( pFmt ) &&
     185           0 :                     0 != (pIMap = pFmt->GetURL().GetMap()) )
     186             :                 {
     187           0 :                     for( sal_uInt16 nPos = pIMap->GetIMapObjectCount(); nPos; )
     188           0 :                         if( pIMapObj == pIMap->GetIMapObject( --nPos ))
     189             :                         {
     190           0 :                             bCheckPtr = false;      // misuse as a flag
     191           0 :                             break;
     192             :                         }
     193             :                 }
     194             :             }
     195           0 :             if( !bCheckPtr )
     196           0 :                 pTbl = &pIMapObj->GetMacroTable();
     197             :         }
     198           0 :         break;
     199             :     default:
     200           0 :         break;
     201             :     }
     202             : 
     203           0 :     if( pTbl )
     204             :     {
     205           0 :         nRet = 0x1;
     206           0 :         if( pTbl->IsKeyValid( nEvent ) )
     207             :         {
     208           0 :             const SvxMacro& rMacro = *pTbl->Get( nEvent );
     209           0 :             if( STARBASIC == rMacro.GetScriptType() )
     210             :             {
     211           0 :                 nRet += 0 == pDocShell->CallBasic( rMacro.GetMacName(),
     212           0 :                                     rMacro.GetLibName(), pArgs ) ? 1 : 0;
     213             :             }
     214           0 :             else if( EXTENDED_STYPE == rMacro.GetScriptType() )
     215             :             {
     216           0 :                 Sequence<Any> *pUnoArgs = 0;
     217             : 
     218           0 :                 if( pArgs )
     219             :                 {
     220           0 :                     pUnoArgs = lcl_docbasic_convertArgs( *pArgs );
     221             :                 }
     222             : 
     223           0 :                 if (!pUnoArgs)
     224             :                 {
     225           0 :                     pUnoArgs = new Sequence <Any> (0);
     226             :                 }
     227             : 
     228           0 :                 Any aRet;
     229           0 :                 Sequence< sal_Int16 > aOutArgsIndex;
     230           0 :                 Sequence< Any > aOutArgs;
     231             : 
     232             :                 OSL_TRACE( "SwDoc::CallEvent URL is %s", rtl::OUStringToOString(
     233             :                     rMacro.GetMacName(), RTL_TEXTENCODING_UTF8).getStr() );
     234             : 
     235             :                 nRet += 0 == pDocShell->CallXScript(
     236           0 :                     rMacro.GetMacName(), *pUnoArgs,aRet, aOutArgsIndex, aOutArgs) ? 1 : 0;
     237             : 
     238           0 :                 delete pUnoArgs;
     239             :             }
     240             :             // JavaScript calls are ignored
     241             :         }
     242             :     }
     243           0 :     return nRet;
     244             : }
     245             : 
     246             : 
     247             : 
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10