1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docbasic.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
37 #ifndef _RTL_USTRING_HXX //autogen
38 #include <rtl/ustring.hxx>
40 #include <svtools/imap.hxx>
41 #include <svtools/imapobj.hxx>
42 #include <basic/sbx.hxx>
44 #include <fmtinfmt.hxx>
52 #include <swevent.hxx>
54 using namespace ::com::sun::star::uno
;
55 using ::rtl::OUString
;
57 static Sequence
<Any
> *lcl_docbasic_convertArgs( SbxArray
& rArgs
)
59 Sequence
<Any
> *pRet
= 0;
61 USHORT nCount
= rArgs
.Count();
65 pRet
= new Sequence
<Any
>( nCount
);
66 Any
*pUnoArgs
= pRet
->getArray();
67 for( USHORT i
=0; i
<nCount
; i
++ )
69 SbxVariable
*pVar
= rArgs
.Get( i
+1 );
70 switch( pVar
->GetType() )
73 pUnoArgs
[i
] <<= OUString( pVar
->GetString() );
76 pUnoArgs
[i
] <<= (sal_Int16
)pVar
->GetChar() ;
79 pUnoArgs
[i
] <<= (sal_Int16
)pVar
->GetUShort();
82 pUnoArgs
[i
] <<= (sal_Int32
)pVar
->GetLong();
85 pUnoArgs
[i
].setValue(0, ::getVoidCppuType());
94 BOOL
SwDoc::ExecMacro( const SvxMacro
& rMacro
, String
* pRet
, SbxArray
* pArgs
)
97 switch( rMacro
.GetScriptType() )
102 SbxValue
* pRetValue
= new SbxValue
;
104 eErr
= pDocShell
->CallBasic( rMacro
.GetMacName(),
106 0, pArgs
, pRet
? pRetValue
: 0 );
108 if( pRet
&& SbxNULL
< pRetValue
->GetType() &&
109 SbxVOID
!= pRetValue
->GetType() )
110 // gueltiger Wert, also setzen
111 *pRet
= pRetValue
->GetString();
115 // ignore JavaScript calls
119 Sequence
<Any
> *pUnoArgs
= 0;
122 // better to rename the local function to lcl_translateBasic2Uno and
123 // a much shorter routine can be found in sfx2/source/doc/objmisc.cxx
124 pUnoArgs
= lcl_docbasic_convertArgs( *pArgs
);
129 pUnoArgs
= new Sequence
< Any
> (0);
132 // TODO - return value is not handled
134 Sequence
< sal_Int16
> aOutArgsIndex
;
135 Sequence
< Any
> aOutArgs
;
137 OSL_TRACE( "SwDoc::ExecMacro URL is %s", ByteString( rMacro
.GetMacName(),
138 RTL_TEXTENCODING_UTF8
).GetBuffer() );
140 eErr
= pDocShell
->CallXScript(
141 rMacro
.GetMacName(), *pUnoArgs
, aRet
, aOutArgsIndex
, aOutArgs
);
143 //*pRet = pRetValue->GetString();
144 // use the AnyConverter to return a String if appropriate?
146 // need to call something like lcl_translateUno2Basic
147 // pArgs = lcl_translateUno2Basic( pUnoArgs );
159 USHORT
SwDoc::CallEvent( USHORT nEvent
, const SwCallMouseEvent
& rCallEvent
,
160 BOOL bCheckPtr
, SbxArray
* pArgs
, const Link
* )
162 if( !pDocShell
) // ohne DocShell geht das nicht!
166 const SvxMacroTableDtor
* pTbl
= 0;
167 switch( rCallEvent
.eType
)
169 case EVENT_OBJECT_INETATTR
:
172 const SfxPoolItem
* pItem
;
173 USHORT n
, nMaxItems
= GetAttrPool().GetItemCount( RES_TXTATR_INETFMT
);
174 for( n
= 0; n
< nMaxItems
; ++n
)
175 if( 0 != (pItem
= GetAttrPool().GetItem( RES_TXTATR_INETFMT
, n
) )
176 && rCallEvent
.PTR
.pINetAttr
== pItem
)
178 bCheckPtr
= FALSE
; // als Flag missbrauchen
183 pTbl
= rCallEvent
.PTR
.pINetAttr
->GetMacroTbl();
186 case EVENT_OBJECT_URLITEM
:
187 case EVENT_OBJECT_IMAGE
:
189 const SwFrmFmtPtr pFmt
= (SwFrmFmtPtr
)rCallEvent
.PTR
.pFmt
;
192 USHORT nPos
= GetSpzFrmFmts()->GetPos( pFmt
);
193 if( USHRT_MAX
!= nPos
)
194 bCheckPtr
= FALSE
; // als Flag missbrauchen
197 pTbl
= &pFmt
->GetMacro().GetMacroTable();
201 case EVENT_OBJECT_IMAGEMAP
:
203 const IMapObject
* pIMapObj
= rCallEvent
.PTR
.IMAP
.pIMapObj
;
206 const SwFrmFmtPtr pFmt
= (SwFrmFmtPtr
)rCallEvent
.PTR
.IMAP
.pFmt
;
207 USHORT nPos
= GetSpzFrmFmts()->GetPos( pFmt
);
208 const ImageMap
* pIMap
;
209 if( USHRT_MAX
!= nPos
&&
210 0 != (pIMap
= pFmt
->GetURL().GetMap()) )
212 for( nPos
= pIMap
->GetIMapObjectCount(); nPos
; )
213 if( pIMapObj
== pIMap
->GetIMapObject( --nPos
))
215 bCheckPtr
= FALSE
; // als Flag missbrauchen
221 pTbl
= &pIMapObj
->GetMacroTable();
231 if( pTbl
->IsKeyValid( nEvent
) )
233 const SvxMacro
& rMacro
= *pTbl
->Get( nEvent
);
234 if( STARBASIC
== rMacro
.GetScriptType() )
236 nRet
+= 0 == pDocShell
->CallBasic( rMacro
.GetMacName(),
237 rMacro
.GetLibName(), 0, pArgs
) ? 1 : 0;
239 else if( EXTENDED_STYPE
== rMacro
.GetScriptType() )
241 Sequence
<Any
> *pUnoArgs
= 0;
245 pUnoArgs
= lcl_docbasic_convertArgs( *pArgs
);
250 pUnoArgs
= new Sequence
<Any
> (0);
254 Sequence
< sal_Int16
> aOutArgsIndex
;
255 Sequence
< Any
> aOutArgs
;
257 OSL_TRACE( "SwDoc::CallEvent URL is %s", ByteString(
258 rMacro
.GetMacName(), RTL_TEXTENCODING_UTF8
).GetBuffer() );
260 nRet
+= 0 == pDocShell
->CallXScript(
261 rMacro
.GetMacName(), *pUnoArgs
,aRet
, aOutArgsIndex
, aOutArgs
) ? 1 : 0;
263 //*pRet = pRetValue->GetString();
264 // use the AnyConverter to return a String if appropriate?
266 // need to call something like lcl_translateUno2Basic
267 // pArgs = lcl_translateUno2Basic( pUnoArgs );
271 // JavaScript calls are ignored