1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <hintids.hxx>
22 #include <rtl/ustring.hxx>
23 #include <svtools/imap.hxx>
24 #include <svtools/imapobj.hxx>
25 #include <basic/sbx.hxx>
27 #include <fmtinfmt.hxx>
33 #include <swevent.hxx>
35 using namespace ::com::sun::star::uno
;
37 static Sequence
<Any
> *lcl_docbasic_convertArgs( SbxArray
& rArgs
)
39 Sequence
<Any
> *pRet
= 0;
41 sal_uInt16 nCount
= rArgs
.Count();
45 pRet
= new Sequence
<Any
>( nCount
);
46 Any
*pUnoArgs
= pRet
->getArray();
47 for( sal_uInt16 i
=0; i
<nCount
; i
++ )
49 SbxVariable
*pVar
= rArgs
.Get( i
+1 );
50 switch( pVar
->GetType() )
53 pUnoArgs
[i
] <<= OUString( pVar
->GetOUString() );
56 pUnoArgs
[i
] <<= (sal_Int16
)pVar
->GetChar() ;
59 pUnoArgs
[i
] <<= (sal_Int16
)pVar
->GetUShort();
62 pUnoArgs
[i
] <<= (sal_Int32
)pVar
->GetLong();
65 pUnoArgs
[i
].setValue(0, ::getVoidCppuType());
74 bool SwDoc::ExecMacro( const SvxMacro
& rMacro
, String
* pRet
, SbxArray
* pArgs
)
77 switch( rMacro
.GetScriptType() )
82 SbxValue
* pRetValue
= new SbxValue
;
84 eErr
= mpDocShell
->CallBasic( rMacro
.GetMacName(),
86 pArgs
, pRet
? pRetValue
: 0 );
88 if( pRet
&& SbxNULL
< pRetValue
->GetType() &&
89 SbxVOID
!= pRetValue
->GetType() )
91 // valid value, so set it
92 *pRet
= pRetValue
->GetOUString();
97 // ignore JavaScript calls
101 Sequence
<Any
> *pUnoArgs
= 0;
104 // better to rename the local function to lcl_translateBasic2Uno and
105 // a much shorter routine can be found in sfx2/source/doc/objmisc.cxx
106 pUnoArgs
= lcl_docbasic_convertArgs( *pArgs
);
111 pUnoArgs
= new Sequence
< Any
> (0);
114 // TODO - return value is not handled
116 Sequence
< sal_Int16
> aOutArgsIndex
;
117 Sequence
< Any
> aOutArgs
;
119 OSL_TRACE( "SwDoc::ExecMacro URL is %s", OUStringToOString( rMacro
.GetMacName(),
120 RTL_TEXTENCODING_UTF8
).getStr() );
122 eErr
= mpDocShell
->CallXScript(
123 rMacro
.GetMacName(), *pUnoArgs
, aRet
, aOutArgsIndex
, aOutArgs
);
135 sal_uInt16
SwDoc::CallEvent( sal_uInt16 nEvent
, const SwCallMouseEvent
& rCallEvent
,
136 bool bCheckPtr
, SbxArray
* pArgs
, const Link
* )
138 if( !mpDocShell
) // we can't do that without a DocShell!
142 const SvxMacroTableDtor
* pTbl
= 0;
143 switch( rCallEvent
.eType
)
145 case EVENT_OBJECT_INETATTR
:
148 const SfxPoolItem
* pItem
;
149 sal_uInt32 n
, nMaxItems
= GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT
);
150 for( n
= 0; n
< nMaxItems
; ++n
)
151 if( 0 != (pItem
= GetAttrPool().GetItem2( RES_TXTATR_INETFMT
, n
) )
152 && rCallEvent
.PTR
.pINetAttr
== pItem
)
154 bCheckPtr
= false; // misuse as a flag
159 pTbl
= rCallEvent
.PTR
.pINetAttr
->GetMacroTbl();
162 case EVENT_OBJECT_URLITEM
:
163 case EVENT_OBJECT_IMAGE
:
165 const SwFrmFmt
* pFmt
= (SwFrmFmt
*)rCallEvent
.PTR
.pFmt
;
168 if ( GetSpzFrmFmts()->Contains( pFmt
) )
169 bCheckPtr
= false; // misuse as a flag
172 pTbl
= &pFmt
->GetMacro().GetMacroTable();
176 case EVENT_OBJECT_IMAGEMAP
:
178 const IMapObject
* pIMapObj
= rCallEvent
.PTR
.IMAP
.pIMapObj
;
181 const SwFrmFmt
* pFmt
= (SwFrmFmt
*)rCallEvent
.PTR
.IMAP
.pFmt
;
182 const ImageMap
* pIMap
;
183 if( GetSpzFrmFmts()->Contains( pFmt
) &&
184 0 != (pIMap
= pFmt
->GetURL().GetMap()) )
186 for( sal_uInt16 nPos
= pIMap
->GetIMapObjectCount(); nPos
; )
187 if( pIMapObj
== pIMap
->GetIMapObject( --nPos
))
189 bCheckPtr
= false; // misuse as a flag
195 pTbl
= &pIMapObj
->GetMacroTable();
205 if( pTbl
->IsKeyValid( nEvent
) )
207 const SvxMacro
& rMacro
= *pTbl
->Get( nEvent
);
208 if( STARBASIC
== rMacro
.GetScriptType() )
210 nRet
+= 0 == mpDocShell
->CallBasic( rMacro
.GetMacName(),
211 rMacro
.GetLibName(), pArgs
) ? 1 : 0;
213 else if( EXTENDED_STYPE
== rMacro
.GetScriptType() )
215 Sequence
<Any
> *pUnoArgs
= 0;
219 pUnoArgs
= lcl_docbasic_convertArgs( *pArgs
);
224 pUnoArgs
= new Sequence
<Any
> (0);
228 Sequence
< sal_Int16
> aOutArgsIndex
;
229 Sequence
< Any
> aOutArgs
;
231 OSL_TRACE( "SwDoc::CallEvent URL is %s", OUStringToOString(
232 rMacro
.GetMacName(), RTL_TEXTENCODING_UTF8
).getStr() );
234 nRet
+= 0 == mpDocShell
->CallXScript(
235 rMacro
.GetMacName(), *pUnoArgs
,aRet
, aOutArgsIndex
, aOutArgs
) ? 1 : 0;
239 // JavaScript calls are ignored
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */