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"
22 //========================================================================
24 //========================================================================
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
)
141 hr
= VariantCopyInd( &m_varValue
, &value
);
144 if( SUCCEEDED( hr
= VariantChangeType( &var
, &type
, 0, VT_BSTR
)))
145 m_bstrType
= var
.bstrVal
;
149 // JScriptValue, IScriptOutParam-----------------------
150 STDMETHODIMP
JScriptValue::Get( VARIANT
*val
)
155 HRESULT hr
= VariantCopy( val
, &m_varValue
);
160 STDMETHODIMP
JScriptValue::InitOutParam()
165 m_bInOutParam
= false;
170 STDMETHODIMP
JScriptValue::InitInOutParam( VARIANT type
, VARIANT value
)
176 return Set( type
, value
);
179 STDMETHODIMP
JScriptValue::IsOutParam( VARIANT_BOOL
* flag
)
184 *flag
= m_bOutParam
? VARIANT_TRUE
: VARIANT_FALSE
;
189 STDMETHODIMP
JScriptValue::IsInOutParam( VARIANT_BOOL
* flag
)
194 *flag
= m_bInOutParam
? VARIANT_TRUE
: VARIANT_FALSE
;
199 STDMETHODIMP
JScriptValue::GetValue( BSTR
* type
, VARIANT
*value
)
205 if( SUCCEEDED( hr
= m_bstrType
.CopyTo( type
)))
206 hr
= VariantCopy( value
, &m_varValue
);
211 //##########################################################################################
213 //##########################################################################################
215 JScriptOutParam::JScriptOutParam()
219 JScriptOutParam::~JScriptOutParam()
224 // JScriptOutParam, IDispatch --------------------------------------------
225 STDMETHODIMP
JScriptOutParam::GetTypeInfoCount(UINT
* /*pctinfo*/)
230 // JScriptOutParam, IDispatch --------------------------------------------
231 STDMETHODIMP
JScriptOutParam::GetTypeInfo( UINT
/*iTInfo*/,
233 ITypeInfo
** /*ppTInfo*/)
238 // JScriptOutParam, IDispatch --------------------------------------------
239 STDMETHODIMP
JScriptOutParam::GetIDsOfNames( REFIID
/*riid*/,
250 CComBSTR
name(*rgszNames
);
253 if( name
== CComBSTR( L
"0") )
256 ret
= DISP_E_UNKNOWNNAME
;
261 // JScriptOutParam, IDispatch --------------------------------------------
262 STDMETHODIMP
JScriptOutParam::Invoke( DISPID dispIdMember
,
266 DISPPARAMS
*pDispParams
,
268 EXCEPINFO
* /*pExcepInfo*/,
272 switch( dispIdMember
)
274 case 0: // DISPID_VALUE
275 if( wFlags
& DISPATCH_PROPERTYGET
&& pVarResult
)
277 if( FAILED( VariantCopy( pVarResult
, &m_varValue
)))
280 else if( wFlags
& DISPATCH_PROPERTYPUT
|| wFlags
& DISPATCH_PROPERTYPUTREF
)
283 if( FAILED( VariantCopyInd( &m_varValue
, &pDispParams
->rgvarg
[0])))
290 if( wFlags
& DISPATCH_PROPERTYGET
&& pVarResult
)
292 if( FAILED( VariantCopy( pVarResult
, &m_varValue
)))
295 else if( wFlags
& DISPATCH_PROPERTYPUT
|| wFlags
& DISPATCH_PROPERTYPUTREF
)
298 if( FAILED( VariantCopyInd( &m_varValue
, &pDispParams
->rgvarg
[0])))
306 ret
= DISP_E_MEMBERNOTFOUND
;
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */