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: jscriptclasses.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_extensions.hxx"
33 #include "jscriptclasses.hxx"
35 //========================================================================
37 //========================================================================
38 JScriptValue::JScriptValue(): m_bOutParam(0), m_bInOutParam(0)
42 JScriptValue::~JScriptValue()
47 // JScriptValue, IDispatch --------------------------------------------
48 STDMETHODIMP
JScriptValue::GetTypeInfoCount(UINT
* /*pctinfo*/)
53 // JScriptValue, IDispatch --------------------------------------------
54 STDMETHODIMP
JScriptValue::GetTypeInfo( UINT
/*iTInfo*/,
56 ITypeInfo
** /*ppTInfo*/)
61 // JScriptValue, IDispatch --------------------------------------------
62 STDMETHODIMP
JScriptValue::GetIDsOfNames( REFIID
/*riid*/,
73 CComBSTR
name(*rgszNames
);
76 if( name
== CComBSTR( L
"set") )
78 else if( name
== CComBSTR( L
"get") )
80 else if( name
== CComBSTR( L
"initoutparam") )
82 else if( name
== CComBSTR( L
"initinoutparam") )
85 ret
= DISP_E_UNKNOWNNAME
;
90 // JScriptValue, IDispatch --------------------------------------------
91 STDMETHODIMP
JScriptValue::Invoke( DISPID dispIdMember
,
95 DISPPARAMS
*pDispParams
,
97 EXCEPINFO
* /*pExcepInfo*/,
100 if( pDispParams
->cNamedArgs
)
101 return DISP_E_NONAMEDARGS
;
105 switch( dispIdMember
)
107 case 0: // DISPID_VALUE
108 if( wFlags
& DISPATCH_PROPERTYGET
&& pVarResult
)
110 if( FAILED( VariantCopy( pVarResult
, &m_varValue
)))
117 if( wFlags
& DISPATCH_METHOD
)
118 ret
= Set( pDispParams
->rgvarg
[1], pDispParams
->rgvarg
[0]);
120 ret
= DISP_E_EXCEPTION
;
123 if( wFlags
& DISPATCH_METHOD
)
124 ret
= Get( pVarResult
);
126 ret
= DISP_E_EXCEPTION
;
129 if( wFlags
& DISPATCH_METHOD
)
132 ret
= DISP_E_EXCEPTION
;
135 if( wFlags
& DISPATCH_METHOD
)
136 ret
= InitInOutParam( pDispParams
->rgvarg
[1], pDispParams
->rgvarg
[0]);
138 ret
= DISP_E_EXCEPTION
;
141 ret
= DISP_E_MEMBERNOTFOUND
;
148 // JScriptValue, IScriptOutParam-----------------------
149 STDMETHODIMP
JScriptValue::Set( VARIANT type
, VARIANT value
)
154 hr
= VariantCopyInd( &m_varValue
, &value
);
157 if( SUCCEEDED( hr
= VariantChangeType( &var
, &type
, 0, VT_BSTR
)))
158 m_bstrType
= var
.bstrVal
;
162 // JScriptValue, IScriptOutParam-----------------------
163 STDMETHODIMP
JScriptValue::Get( VARIANT
*val
)
168 HRESULT hr
= VariantCopy( val
, &m_varValue
);
173 STDMETHODIMP
JScriptValue::InitOutParam()
178 m_bInOutParam
= false;
183 STDMETHODIMP
JScriptValue::InitInOutParam( VARIANT type
, VARIANT value
)
189 return Set( type
, value
);
192 STDMETHODIMP
JScriptValue::IsOutParam( VARIANT_BOOL
* flag
)
197 *flag
= m_bOutParam
? VARIANT_TRUE
: VARIANT_FALSE
;
202 STDMETHODIMP
JScriptValue::IsInOutParam( VARIANT_BOOL
* flag
)
207 *flag
= m_bInOutParam
? VARIANT_TRUE
: VARIANT_FALSE
;
212 STDMETHODIMP
JScriptValue::GetValue( BSTR
* type
, VARIANT
*value
)
218 if( SUCCEEDED( hr
= m_bstrType
.CopyTo( type
)))
219 hr
= VariantCopy( value
, &m_varValue
);
224 //##########################################################################################
226 //##########################################################################################
228 JScriptOutParam::JScriptOutParam()
232 JScriptOutParam::~JScriptOutParam()
237 // JScriptOutParam, IDispatch --------------------------------------------
238 STDMETHODIMP
JScriptOutParam::GetTypeInfoCount(UINT
* /*pctinfo*/)
243 // JScriptOutParam, IDispatch --------------------------------------------
244 STDMETHODIMP
JScriptOutParam::GetTypeInfo( UINT
/*iTInfo*/,
246 ITypeInfo
** /*ppTInfo*/)
251 // JScriptOutParam, IDispatch --------------------------------------------
252 STDMETHODIMP
JScriptOutParam::GetIDsOfNames( REFIID
/*riid*/,
263 CComBSTR
name(*rgszNames
);
266 if( name
== CComBSTR( L
"0") )
269 ret
= DISP_E_UNKNOWNNAME
;
274 // JScriptOutParam, IDispatch --------------------------------------------
275 STDMETHODIMP
JScriptOutParam::Invoke( DISPID dispIdMember
,
279 DISPPARAMS
*pDispParams
,
281 EXCEPINFO
* /*pExcepInfo*/,
285 switch( dispIdMember
)
287 case 0: // DISPID_VALUE
288 if( wFlags
& DISPATCH_PROPERTYGET
&& pVarResult
)
290 if( FAILED( VariantCopy( pVarResult
, &m_varValue
)))
293 else if( wFlags
& DISPATCH_PROPERTYPUT
|| wFlags
& DISPATCH_PROPERTYPUTREF
)
296 if( FAILED( VariantCopyInd( &m_varValue
, &pDispParams
->rgvarg
[0])))
303 if( wFlags
& DISPATCH_PROPERTYGET
&& pVarResult
)
305 if( FAILED( VariantCopy( pVarResult
, &m_varValue
)))
308 else if( wFlags
& DISPATCH_PROPERTYPUT
|| wFlags
& DISPATCH_PROPERTYPUTREF
)
311 if( FAILED( VariantCopyInd( &m_varValue
, &pDispParams
->rgvarg
[0])))
319 ret
= DISP_E_MEMBERNOTFOUND
;