tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / extensions / source / ole / jscriptclasses.cxx
blob8fc371c4c29a6df375e69c6b99be2c01182732c0
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"
23 // JScriptValue
25 JScriptValue::JScriptValue(): m_bOutParam(false), m_bInOutParam(false)
29 JScriptValue::~JScriptValue()
34 // JScriptValue, IDispatch --------------------------------------------
35 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::GetTypeInfoCount(UINT* /*pctinfo*/)
37 return E_NOTIMPL;
40 // JScriptValue, IDispatch --------------------------------------------
41 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::GetTypeInfo( UINT /*iTInfo*/,
42 LCID /*lcid*/,
43 ITypeInfo** /*ppTInfo*/)
45 return E_NOTIMPL;
48 // JScriptValue, IDispatch --------------------------------------------
49 COM_DECLSPEC_NOTHROW 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 COM_DECLSPEC_NOTHROW 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 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::Set( VARIANT type, VARIANT value)
138 Lock();
139 m_varValue.Clear();
140 HRESULT hr= VariantCopyInd( &m_varValue, &value);
141 VARIANT var;
142 VariantInit( &var);
143 if( SUCCEEDED( hr= VariantChangeType( &var, &type, 0, VT_BSTR)))
144 m_bstrType= var.bstrVal;
145 Unlock();
146 return hr;
148 // JScriptValue, IScriptOutParam-----------------------
149 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::Get( VARIANT *val)
151 Lock();
152 if( !val)
153 return E_POINTER;
154 HRESULT hr= VariantCopy( val, &m_varValue);
155 Unlock();
156 return hr;
159 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::InitOutParam()
161 Lock();
162 m_varValue.Clear();
163 m_bOutParam= true;
164 m_bInOutParam= false;
165 Unlock();
166 return S_OK;
169 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::InitInOutParam( VARIANT type, VARIANT value)
171 Lock();
172 m_bInOutParam= true;
173 m_bOutParam= false;
174 Unlock();
175 return Set( type, value);
178 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::IsOutParam( VARIANT_BOOL * flag)
180 Lock();
181 if( !flag)
182 return E_POINTER;
183 *flag= m_bOutParam ? VARIANT_TRUE : VARIANT_FALSE;
184 Unlock();
185 return S_OK;
188 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::IsInOutParam( VARIANT_BOOL * flag)
190 Lock();
191 if( !flag)
192 return E_POINTER;
193 *flag= m_bInOutParam ? VARIANT_TRUE : VARIANT_FALSE;
194 Unlock();
195 return S_OK;
198 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::GetValue( BSTR* type, VARIANT *value)
200 Lock();
201 if( !type || !value)
202 return E_POINTER;
203 HRESULT hr;
204 if( SUCCEEDED( hr= m_bstrType.CopyTo( type)))
205 hr= VariantCopy( value, &m_varValue);
206 Unlock();
207 return hr;
211 // JScriptOutValue
214 JScriptOutParam::JScriptOutParam()
218 JScriptOutParam::~JScriptOutParam()
223 // JScriptOutParam, IDispatch --------------------------------------------
224 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptOutParam::GetTypeInfoCount(UINT* /*pctinfo*/)
226 return E_NOTIMPL;
229 // JScriptOutParam, IDispatch --------------------------------------------
230 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptOutParam::GetTypeInfo( UINT /*iTInfo*/,
231 LCID /*lcid*/,
232 ITypeInfo** /*ppTInfo*/)
234 return E_NOTIMPL;
237 // JScriptOutParam, IDispatch --------------------------------------------
238 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptOutParam::GetIDsOfNames( REFIID /*riid*/,
239 LPOLESTR *rgszNames,
240 UINT /*cNames*/,
241 LCID /*lcid*/,
242 DISPID *rgDispId)
244 if( !rgDispId)
245 return E_POINTER;
248 HRESULT ret= S_OK;
249 CComBSTR name(*rgszNames);
250 name.ToLower();
252 if( name == CComBSTR( L"0") )
253 *rgDispId= 1;
254 else
255 ret= DISP_E_UNKNOWNNAME;
257 return ret;
260 // JScriptOutParam, IDispatch --------------------------------------------
261 COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptOutParam::Invoke( DISPID dispIdMember,
262 REFIID /*riid*/,
263 LCID /*lcid*/,
264 WORD wFlags,
265 DISPPARAMS *pDispParams,
266 VARIANT *pVarResult,
267 EXCEPINFO* /*pExcepInfo*/,
268 UINT* /*puArgErr*/)
270 HRESULT ret= S_OK;
271 switch( dispIdMember)
273 case 0: // DISPID_VALUE
274 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
276 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
277 ret= E_FAIL;
279 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
281 m_varValue.Clear();
282 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
283 ret= E_FAIL;
285 else
286 ret= E_POINTER;
287 break;
288 case 1:
289 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
291 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
292 ret= E_FAIL;
294 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
296 m_varValue.Clear();
297 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
298 ret= E_FAIL;
300 else
301 ret= E_POINTER;
302 break;
304 default:
305 ret= DISP_E_MEMBERNOTFOUND;
306 break;
309 return ret;
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */