bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / ole / jscriptclasses.cxx
blob663450ada561a77d13a77b536f5e164918c1b7ca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 //========================================================================
23 // JScriptValue
24 //========================================================================
25 JScriptValue::JScriptValue(): m_bOutParam(0), m_bInOutParam(0)
29 JScriptValue::~JScriptValue()
34 // JScriptValue, IDispatch --------------------------------------------
35 STDMETHODIMP JScriptValue::GetTypeInfoCount(UINT* /*pctinfo*/)
37 return E_NOTIMPL;
40 // JScriptValue, IDispatch --------------------------------------------
41 STDMETHODIMP JScriptValue::GetTypeInfo( UINT /*iTInfo*/,
42 LCID /*lcid*/,
43 ITypeInfo** /*ppTInfo*/)
45 return E_NOTIMPL;
48 // JScriptValue, IDispatch --------------------------------------------
49 STDMETHODIMP JScriptValue::GetIDsOfNames( REFIID /*riid*/,
50 LPOLESTR *rgszNames,
51 UINT /*cNames*/,
52 LCID /*lcid*/,
53 DISPID *rgDispId)
55 if( !rgDispId)
56 return E_POINTER;
59 HRESULT ret= S_OK;
60 CComBSTR name(*rgszNames);
61 name.ToLower();
63 if( name == CComBSTR( L"set") )
64 *rgDispId= 1;
65 else if( name == CComBSTR( L"get") )
66 *rgDispId= 2;
67 else if( name == CComBSTR( L"initoutparam") )
68 *rgDispId= 3;
69 else if( name == CComBSTR( L"initinoutparam") )
70 *rgDispId= 4;
71 else
72 ret= DISP_E_UNKNOWNNAME;
74 return ret;
77 // JScriptValue, IDispatch --------------------------------------------
78 STDMETHODIMP JScriptValue::Invoke( DISPID dispIdMember,
79 REFIID /*riid*/,
80 LCID /*lcid*/,
81 WORD wFlags,
82 DISPPARAMS *pDispParams,
83 VARIANT *pVarResult,
84 EXCEPINFO* /*pExcepInfo*/,
85 UINT* /*puArgErr*/)
87 if( pDispParams->cNamedArgs)
88 return DISP_E_NONAMEDARGS;
91 HRESULT ret= S_OK;
92 switch( dispIdMember)
94 case 0: // DISPID_VALUE
95 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
97 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
98 ret= E_FAIL;
100 else
101 ret= E_POINTER;
102 break;
103 case 1:
104 if( wFlags & DISPATCH_METHOD)
105 ret= Set( pDispParams->rgvarg[1], pDispParams->rgvarg[0]);
106 if( FAILED( ret))
107 ret= DISP_E_EXCEPTION;
108 break;
109 case 2:
110 if( wFlags & DISPATCH_METHOD)
111 ret= Get( pVarResult);
112 if( FAILED( ret))
113 ret= DISP_E_EXCEPTION;
114 break;
115 case 3:
116 if( wFlags & DISPATCH_METHOD)
117 ret= InitOutParam();
118 if( FAILED( ret))
119 ret= DISP_E_EXCEPTION;
120 break;
121 case 4:
122 if( wFlags & DISPATCH_METHOD)
123 ret= InitInOutParam( pDispParams->rgvarg[1], pDispParams->rgvarg[0]);
124 if( FAILED( ret))
125 ret= DISP_E_EXCEPTION;
126 break;
127 default:
128 ret= DISP_E_MEMBERNOTFOUND;
129 break;
132 return ret;
135 // JScriptValue, IScriptOutParam-----------------------
136 STDMETHODIMP JScriptValue::Set( VARIANT type, VARIANT value)
138 Lock();
139 HRESULT hr= S_OK;
140 m_varValue.Clear();
141 hr= VariantCopyInd( &m_varValue, &value);
142 VARIANT var;
143 VariantInit( &var);
144 if( SUCCEEDED( hr= VariantChangeType( &var, &type, 0, VT_BSTR)))
145 m_bstrType= var.bstrVal;
146 Unlock();
147 return hr;
149 // JScriptValue, IScriptOutParam-----------------------
150 STDMETHODIMP JScriptValue::Get( VARIANT *val)
152 Lock();
153 if( !val)
154 return E_POINTER;
155 HRESULT hr= VariantCopy( val, &m_varValue);
156 Unlock();
157 return hr;
160 STDMETHODIMP JScriptValue::InitOutParam()
162 Lock();
163 m_varValue.Clear();
164 m_bOutParam= true;
165 m_bInOutParam= false;
166 Unlock();
167 return S_OK;
170 STDMETHODIMP JScriptValue::InitInOutParam( VARIANT type, VARIANT value)
172 Lock();
173 m_bInOutParam= true;
174 m_bOutParam= false;
175 Unlock();
176 return Set( type, value);
179 STDMETHODIMP JScriptValue::IsOutParam( VARIANT_BOOL * flag)
181 Lock();
182 if( !flag)
183 return E_POINTER;
184 *flag= m_bOutParam ? VARIANT_TRUE : VARIANT_FALSE;
185 Unlock();
186 return S_OK;
189 STDMETHODIMP JScriptValue::IsInOutParam( VARIANT_BOOL * flag)
191 Lock();
192 if( !flag)
193 return E_POINTER;
194 *flag= m_bInOutParam ? VARIANT_TRUE : VARIANT_FALSE;
195 Unlock();
196 return S_OK;
199 STDMETHODIMP JScriptValue::GetValue( BSTR* type, VARIANT *value)
201 Lock();
202 if( !type || !value)
203 return E_POINTER;
204 HRESULT hr;
205 if( SUCCEEDED( hr= m_bstrType.CopyTo( type)))
206 hr= VariantCopy( value, &m_varValue);
207 Unlock();
208 return hr;
211 //##########################################################################################
212 // JScriptOutValue
213 //##########################################################################################
215 JScriptOutParam::JScriptOutParam()
219 JScriptOutParam::~JScriptOutParam()
224 // JScriptOutParam, IDispatch --------------------------------------------
225 STDMETHODIMP JScriptOutParam::GetTypeInfoCount(UINT* /*pctinfo*/)
227 return E_NOTIMPL;
230 // JScriptOutParam, IDispatch --------------------------------------------
231 STDMETHODIMP JScriptOutParam::GetTypeInfo( UINT /*iTInfo*/,
232 LCID /*lcid*/,
233 ITypeInfo** /*ppTInfo*/)
235 return E_NOTIMPL;
238 // JScriptOutParam, IDispatch --------------------------------------------
239 STDMETHODIMP JScriptOutParam::GetIDsOfNames( REFIID /*riid*/,
240 LPOLESTR *rgszNames,
241 UINT /*cNames*/,
242 LCID /*lcid*/,
243 DISPID *rgDispId)
245 if( !rgDispId)
246 return E_POINTER;
249 HRESULT ret= S_OK;
250 CComBSTR name(*rgszNames);
251 name.ToLower();
253 if( name == CComBSTR( L"0") )
254 *rgDispId= 1;
255 else
256 ret= DISP_E_UNKNOWNNAME;
258 return ret;
261 // JScriptOutParam, IDispatch --------------------------------------------
262 STDMETHODIMP JScriptOutParam::Invoke( DISPID dispIdMember,
263 REFIID /*riid*/,
264 LCID /*lcid*/,
265 WORD wFlags,
266 DISPPARAMS *pDispParams,
267 VARIANT *pVarResult,
268 EXCEPINFO* /*pExcepInfo*/,
269 UINT* /*puArgErr*/)
271 HRESULT ret= S_OK;
272 switch( dispIdMember)
274 case 0: // DISPID_VALUE
275 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
277 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
278 ret= E_FAIL;
280 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
282 m_varValue.Clear();
283 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
284 ret= E_FAIL;
286 else
287 ret= E_POINTER;
288 break;
289 case 1: //
290 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
292 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
293 ret= E_FAIL;
295 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
297 m_varValue.Clear();
298 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
299 ret= E_FAIL;
301 else
302 ret= E_POINTER;
303 break;
305 default:
306 ret= DISP_E_MEMBERNOTFOUND;
307 break;
310 return ret;
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */