update dev300-m58
[ooovba.git] / extensions / source / ole / jscriptclasses.cxx
blob196776a11806b584f73504bcf7ecf9cb345a8aad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: jscriptclasses.cxx,v $
10 * $Revision: 1.7 $
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 //========================================================================
36 // JScriptValue
37 //========================================================================
38 JScriptValue::JScriptValue(): m_bOutParam(0), m_bInOutParam(0)
42 JScriptValue::~JScriptValue()
47 // JScriptValue, IDispatch --------------------------------------------
48 STDMETHODIMP JScriptValue::GetTypeInfoCount(UINT* /*pctinfo*/)
50 return E_NOTIMPL;
53 // JScriptValue, IDispatch --------------------------------------------
54 STDMETHODIMP JScriptValue::GetTypeInfo( UINT /*iTInfo*/,
55 LCID /*lcid*/,
56 ITypeInfo** /*ppTInfo*/)
58 return E_NOTIMPL;
61 // JScriptValue, IDispatch --------------------------------------------
62 STDMETHODIMP JScriptValue::GetIDsOfNames( REFIID /*riid*/,
63 LPOLESTR *rgszNames,
64 UINT /*cNames*/,
65 LCID /*lcid*/,
66 DISPID *rgDispId)
68 if( !rgDispId)
69 return E_POINTER;
72 HRESULT ret= S_OK;
73 CComBSTR name(*rgszNames);
74 name.ToLower();
76 if( name == CComBSTR( L"set") )
77 *rgDispId= 1;
78 else if( name == CComBSTR( L"get") )
79 *rgDispId= 2;
80 else if( name == CComBSTR( L"initoutparam") )
81 *rgDispId= 3;
82 else if( name == CComBSTR( L"initinoutparam") )
83 *rgDispId= 4;
84 else
85 ret= DISP_E_UNKNOWNNAME;
87 return ret;
90 // JScriptValue, IDispatch --------------------------------------------
91 STDMETHODIMP JScriptValue::Invoke( DISPID dispIdMember,
92 REFIID /*riid*/,
93 LCID /*lcid*/,
94 WORD wFlags,
95 DISPPARAMS *pDispParams,
96 VARIANT *pVarResult,
97 EXCEPINFO* /*pExcepInfo*/,
98 UINT* /*puArgErr*/)
100 if( pDispParams->cNamedArgs)
101 return DISP_E_NONAMEDARGS;
104 HRESULT ret= S_OK;
105 switch( dispIdMember)
107 case 0: // DISPID_VALUE
108 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
110 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
111 ret= E_FAIL;
113 else
114 ret= E_POINTER;
115 break;
116 case 1:
117 if( wFlags & DISPATCH_METHOD)
118 ret= Set( pDispParams->rgvarg[1], pDispParams->rgvarg[0]);
119 if( FAILED( ret))
120 ret= DISP_E_EXCEPTION;
121 break;
122 case 2:
123 if( wFlags & DISPATCH_METHOD)
124 ret= Get( pVarResult);
125 if( FAILED( ret))
126 ret= DISP_E_EXCEPTION;
127 break;
128 case 3:
129 if( wFlags & DISPATCH_METHOD)
130 ret= InitOutParam();
131 if( FAILED( ret))
132 ret= DISP_E_EXCEPTION;
133 break;
134 case 4:
135 if( wFlags & DISPATCH_METHOD)
136 ret= InitInOutParam( pDispParams->rgvarg[1], pDispParams->rgvarg[0]);
137 if( FAILED( ret))
138 ret= DISP_E_EXCEPTION;
139 break;
140 default:
141 ret= DISP_E_MEMBERNOTFOUND;
142 break;
145 return ret;
148 // JScriptValue, IScriptOutParam-----------------------
149 STDMETHODIMP JScriptValue::Set( VARIANT type, VARIANT value)
151 Lock();
152 HRESULT hr= S_OK;
153 m_varValue.Clear();
154 hr= VariantCopyInd( &m_varValue, &value);
155 VARIANT var;
156 VariantInit( &var);
157 if( SUCCEEDED( hr= VariantChangeType( &var, &type, 0, VT_BSTR)))
158 m_bstrType= var.bstrVal;
159 Unlock();
160 return hr;
162 // JScriptValue, IScriptOutParam-----------------------
163 STDMETHODIMP JScriptValue::Get( VARIANT *val)
165 Lock();
166 if( !val)
167 return E_POINTER;
168 HRESULT hr= VariantCopy( val, &m_varValue);
169 Unlock();
170 return hr;
173 STDMETHODIMP JScriptValue::InitOutParam()
175 Lock();
176 m_varValue.Clear();
177 m_bOutParam= true;
178 m_bInOutParam= false;
179 Unlock();
180 return S_OK;
183 STDMETHODIMP JScriptValue::InitInOutParam( VARIANT type, VARIANT value)
185 Lock();
186 m_bInOutParam= true;
187 m_bOutParam= false;
188 Unlock();
189 return Set( type, value);
192 STDMETHODIMP JScriptValue::IsOutParam( VARIANT_BOOL * flag)
194 Lock();
195 if( !flag)
196 return E_POINTER;
197 *flag= m_bOutParam ? VARIANT_TRUE : VARIANT_FALSE;
198 Unlock();
199 return S_OK;
202 STDMETHODIMP JScriptValue::IsInOutParam( VARIANT_BOOL * flag)
204 Lock();
205 if( !flag)
206 return E_POINTER;
207 *flag= m_bInOutParam ? VARIANT_TRUE : VARIANT_FALSE;
208 Unlock();
209 return S_OK;
212 STDMETHODIMP JScriptValue::GetValue( BSTR* type, VARIANT *value)
214 Lock();
215 if( !type || !value)
216 return E_POINTER;
217 HRESULT hr;
218 if( SUCCEEDED( hr= m_bstrType.CopyTo( type)))
219 hr= VariantCopy( value, &m_varValue);
220 Unlock();
221 return hr;
224 //##########################################################################################
225 // JScriptOutValue
226 //##########################################################################################
228 JScriptOutParam::JScriptOutParam()
232 JScriptOutParam::~JScriptOutParam()
237 // JScriptOutParam, IDispatch --------------------------------------------
238 STDMETHODIMP JScriptOutParam::GetTypeInfoCount(UINT* /*pctinfo*/)
240 return E_NOTIMPL;
243 // JScriptOutParam, IDispatch --------------------------------------------
244 STDMETHODIMP JScriptOutParam::GetTypeInfo( UINT /*iTInfo*/,
245 LCID /*lcid*/,
246 ITypeInfo** /*ppTInfo*/)
248 return E_NOTIMPL;
251 // JScriptOutParam, IDispatch --------------------------------------------
252 STDMETHODIMP JScriptOutParam::GetIDsOfNames( REFIID /*riid*/,
253 LPOLESTR *rgszNames,
254 UINT /*cNames*/,
255 LCID /*lcid*/,
256 DISPID *rgDispId)
258 if( !rgDispId)
259 return E_POINTER;
262 HRESULT ret= S_OK;
263 CComBSTR name(*rgszNames);
264 name.ToLower();
266 if( name == CComBSTR( L"0") )
267 *rgDispId= 1;
268 else
269 ret= DISP_E_UNKNOWNNAME;
271 return ret;
274 // JScriptOutParam, IDispatch --------------------------------------------
275 STDMETHODIMP JScriptOutParam::Invoke( DISPID dispIdMember,
276 REFIID /*riid*/,
277 LCID /*lcid*/,
278 WORD wFlags,
279 DISPPARAMS *pDispParams,
280 VARIANT *pVarResult,
281 EXCEPINFO* /*pExcepInfo*/,
282 UINT* /*puArgErr*/)
284 HRESULT ret= S_OK;
285 switch( dispIdMember)
287 case 0: // DISPID_VALUE
288 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
290 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
291 ret= E_FAIL;
293 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
295 m_varValue.Clear();
296 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
297 ret= E_FAIL;
299 else
300 ret= E_POINTER;
301 break;
302 case 1: //
303 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
305 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
306 ret= E_FAIL;
308 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
310 m_varValue.Clear();
311 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
312 ret= E_FAIL;
314 else
315 ret= E_POINTER;
316 break;
318 default:
319 ret= DISP_E_MEMBERNOTFOUND;
320 break;
323 return ret;