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 "jscriptclasses.hxx"
25 JScriptValue::JScriptValue(): m_bOutParam(0), m_bInOutParam(0)
29 JScriptValue::~JScriptValue()
34 // JScriptValue, IDispatch --------------------------------------------
35 STDMETHODIMP
JScriptValue::GetTypeInfoCount(UINT
* /*pctinfo*/)
40 // JScriptValue, IDispatch --------------------------------------------
41 STDMETHODIMP
JScriptValue::GetTypeInfo( UINT
/*iTInfo*/,
43 ITypeInfo
** /*ppTInfo*/)
48 // JScriptValue, IDispatch --------------------------------------------
49 STDMETHODIMP
JScriptValue::GetIDsOfNames( REFIID
/*riid*/,
60 CComBSTR
name(*rgszNames
);
63 if( name
== CComBSTR( L
"set") )
65 else if( name
== CComBSTR( L
"get") )
67 else if( name
== CComBSTR( L
"initoutparam") )
69 else if( name
== CComBSTR( L
"initinoutparam") )
72 ret
= DISP_E_UNKNOWNNAME
;
77 // JScriptValue, IDispatch --------------------------------------------
78 STDMETHODIMP
JScriptValue::Invoke( DISPID dispIdMember
,
82 DISPPARAMS
*pDispParams
,
84 EXCEPINFO
* /*pExcepInfo*/,
87 if( pDispParams
->cNamedArgs
)
88 return DISP_E_NONAMEDARGS
;
94 case 0: // DISPID_VALUE
95 if( wFlags
& DISPATCH_PROPERTYGET
&& pVarResult
)
97 if( FAILED( VariantCopy( pVarResult
, &m_varValue
)))
104 if( wFlags
& DISPATCH_METHOD
)
105 ret
= Set( pDispParams
->rgvarg
[1], pDispParams
->rgvarg
[0]);
107 ret
= DISP_E_EXCEPTION
;
110 if( wFlags
& DISPATCH_METHOD
)
111 ret
= Get( pVarResult
);
113 ret
= DISP_E_EXCEPTION
;
116 if( wFlags
& DISPATCH_METHOD
)
119 ret
= DISP_E_EXCEPTION
;
122 if( wFlags
& DISPATCH_METHOD
)
123 ret
= InitInOutParam( pDispParams
->rgvarg
[1], pDispParams
->rgvarg
[0]);
125 ret
= DISP_E_EXCEPTION
;
128 ret
= DISP_E_MEMBERNOTFOUND
;
135 // JScriptValue, IScriptOutParam-----------------------
136 STDMETHODIMP
JScriptValue::Set( VARIANT type
, VARIANT value
)
140 HRESULT hr
= VariantCopyInd( &m_varValue
, &value
);
143 if( SUCCEEDED( hr
= VariantChangeType( &var
, &type
, 0, VT_BSTR
)))
144 m_bstrType
= var
.bstrVal
;
148 // JScriptValue, IScriptOutParam-----------------------
149 STDMETHODIMP
JScriptValue::Get( VARIANT
*val
)
154 HRESULT hr
= VariantCopy( val
, &m_varValue
);
159 STDMETHODIMP
JScriptValue::InitOutParam()
164 m_bInOutParam
= false;
169 STDMETHODIMP
JScriptValue::InitInOutParam( VARIANT type
, VARIANT value
)
175 return Set( type
, value
);
178 STDMETHODIMP
JScriptValue::IsOutParam( VARIANT_BOOL
* flag
)
183 *flag
= m_bOutParam
? VARIANT_TRUE
: VARIANT_FALSE
;
188 STDMETHODIMP
JScriptValue::IsInOutParam( VARIANT_BOOL
* flag
)
193 *flag
= m_bInOutParam
? VARIANT_TRUE
: VARIANT_FALSE
;
198 STDMETHODIMP
JScriptValue::GetValue( BSTR
* type
, VARIANT
*value
)
204 if( SUCCEEDED( hr
= m_bstrType
.CopyTo( type
)))
205 hr
= VariantCopy( value
, &m_varValue
);
214 JScriptOutParam::JScriptOutParam()
218 JScriptOutParam::~JScriptOutParam()
223 // JScriptOutParam, IDispatch --------------------------------------------
224 STDMETHODIMP
JScriptOutParam::GetTypeInfoCount(UINT
* /*pctinfo*/)
229 // JScriptOutParam, IDispatch --------------------------------------------
230 STDMETHODIMP
JScriptOutParam::GetTypeInfo( UINT
/*iTInfo*/,
232 ITypeInfo
** /*ppTInfo*/)
237 // JScriptOutParam, IDispatch --------------------------------------------
238 STDMETHODIMP
JScriptOutParam::GetIDsOfNames( REFIID
/*riid*/,
249 CComBSTR
name(*rgszNames
);
252 if( name
== CComBSTR( L
"0") )
255 ret
= DISP_E_UNKNOWNNAME
;
260 // JScriptOutParam, IDispatch --------------------------------------------
261 STDMETHODIMP
JScriptOutParam::Invoke( DISPID dispIdMember
,
265 DISPPARAMS
*pDispParams
,
267 EXCEPINFO
* /*pExcepInfo*/,
271 switch( dispIdMember
)
273 case 0: // DISPID_VALUE
274 if( wFlags
& DISPATCH_PROPERTYGET
&& pVarResult
)
276 if( FAILED( VariantCopy( pVarResult
, &m_varValue
)))
279 else if( wFlags
& DISPATCH_PROPERTYPUT
|| wFlags
& DISPATCH_PROPERTYPUTREF
)
282 if( FAILED( VariantCopyInd( &m_varValue
, &pDispParams
->rgvarg
[0])))
289 if( wFlags
& DISPATCH_PROPERTYGET
&& pVarResult
)
291 if( FAILED( VariantCopy( pVarResult
, &m_varValue
)))
294 else if( wFlags
& DISPATCH_PROPERTYPUT
|| wFlags
& DISPATCH_PROPERTYPUTREF
)
297 if( FAILED( VariantCopyInd( &m_varValue
, &pDispParams
->rgvarg
[0])))
305 ret
= DISP_E_MEMBERNOTFOUND
;
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */