masterfix DEV300: #i10000# build fix
[LibreOffice.git] / extensions / source / ole / jscriptclasses.cxx
bloba38044f92a4cf231e55fb4828b1762022f62061c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "jscriptclasses.hxx"
32 //========================================================================
33 // JScriptValue
34 //========================================================================
35 JScriptValue::JScriptValue(): m_bOutParam(0), m_bInOutParam(0)
39 JScriptValue::~JScriptValue()
44 // JScriptValue, IDispatch --------------------------------------------
45 STDMETHODIMP JScriptValue::GetTypeInfoCount(UINT* /*pctinfo*/)
47 return E_NOTIMPL;
50 // JScriptValue, IDispatch --------------------------------------------
51 STDMETHODIMP JScriptValue::GetTypeInfo( UINT /*iTInfo*/,
52 LCID /*lcid*/,
53 ITypeInfo** /*ppTInfo*/)
55 return E_NOTIMPL;
58 // JScriptValue, IDispatch --------------------------------------------
59 STDMETHODIMP JScriptValue::GetIDsOfNames( REFIID /*riid*/,
60 LPOLESTR *rgszNames,
61 UINT /*cNames*/,
62 LCID /*lcid*/,
63 DISPID *rgDispId)
65 if( !rgDispId)
66 return E_POINTER;
69 HRESULT ret= S_OK;
70 CComBSTR name(*rgszNames);
71 name.ToLower();
73 if( name == CComBSTR( L"set") )
74 *rgDispId= 1;
75 else if( name == CComBSTR( L"get") )
76 *rgDispId= 2;
77 else if( name == CComBSTR( L"initoutparam") )
78 *rgDispId= 3;
79 else if( name == CComBSTR( L"initinoutparam") )
80 *rgDispId= 4;
81 else
82 ret= DISP_E_UNKNOWNNAME;
84 return ret;
87 // JScriptValue, IDispatch --------------------------------------------
88 STDMETHODIMP JScriptValue::Invoke( DISPID dispIdMember,
89 REFIID /*riid*/,
90 LCID /*lcid*/,
91 WORD wFlags,
92 DISPPARAMS *pDispParams,
93 VARIANT *pVarResult,
94 EXCEPINFO* /*pExcepInfo*/,
95 UINT* /*puArgErr*/)
97 if( pDispParams->cNamedArgs)
98 return DISP_E_NONAMEDARGS;
101 HRESULT ret= S_OK;
102 switch( dispIdMember)
104 case 0: // DISPID_VALUE
105 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
107 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
108 ret= E_FAIL;
110 else
111 ret= E_POINTER;
112 break;
113 case 1:
114 if( wFlags & DISPATCH_METHOD)
115 ret= Set( pDispParams->rgvarg[1], pDispParams->rgvarg[0]);
116 if( FAILED( ret))
117 ret= DISP_E_EXCEPTION;
118 break;
119 case 2:
120 if( wFlags & DISPATCH_METHOD)
121 ret= Get( pVarResult);
122 if( FAILED( ret))
123 ret= DISP_E_EXCEPTION;
124 break;
125 case 3:
126 if( wFlags & DISPATCH_METHOD)
127 ret= InitOutParam();
128 if( FAILED( ret))
129 ret= DISP_E_EXCEPTION;
130 break;
131 case 4:
132 if( wFlags & DISPATCH_METHOD)
133 ret= InitInOutParam( pDispParams->rgvarg[1], pDispParams->rgvarg[0]);
134 if( FAILED( ret))
135 ret= DISP_E_EXCEPTION;
136 break;
137 default:
138 ret= DISP_E_MEMBERNOTFOUND;
139 break;
142 return ret;
145 // JScriptValue, IScriptOutParam-----------------------
146 STDMETHODIMP JScriptValue::Set( VARIANT type, VARIANT value)
148 Lock();
149 HRESULT hr= S_OK;
150 m_varValue.Clear();
151 hr= VariantCopyInd( &m_varValue, &value);
152 VARIANT var;
153 VariantInit( &var);
154 if( SUCCEEDED( hr= VariantChangeType( &var, &type, 0, VT_BSTR)))
155 m_bstrType= var.bstrVal;
156 Unlock();
157 return hr;
159 // JScriptValue, IScriptOutParam-----------------------
160 STDMETHODIMP JScriptValue::Get( VARIANT *val)
162 Lock();
163 if( !val)
164 return E_POINTER;
165 HRESULT hr= VariantCopy( val, &m_varValue);
166 Unlock();
167 return hr;
170 STDMETHODIMP JScriptValue::InitOutParam()
172 Lock();
173 m_varValue.Clear();
174 m_bOutParam= true;
175 m_bInOutParam= false;
176 Unlock();
177 return S_OK;
180 STDMETHODIMP JScriptValue::InitInOutParam( VARIANT type, VARIANT value)
182 Lock();
183 m_bInOutParam= true;
184 m_bOutParam= false;
185 Unlock();
186 return Set( type, value);
189 STDMETHODIMP JScriptValue::IsOutParam( VARIANT_BOOL * flag)
191 Lock();
192 if( !flag)
193 return E_POINTER;
194 *flag= m_bOutParam ? VARIANT_TRUE : VARIANT_FALSE;
195 Unlock();
196 return S_OK;
199 STDMETHODIMP JScriptValue::IsInOutParam( VARIANT_BOOL * flag)
201 Lock();
202 if( !flag)
203 return E_POINTER;
204 *flag= m_bInOutParam ? VARIANT_TRUE : VARIANT_FALSE;
205 Unlock();
206 return S_OK;
209 STDMETHODIMP JScriptValue::GetValue( BSTR* type, VARIANT *value)
211 Lock();
212 if( !type || !value)
213 return E_POINTER;
214 HRESULT hr;
215 if( SUCCEEDED( hr= m_bstrType.CopyTo( type)))
216 hr= VariantCopy( value, &m_varValue);
217 Unlock();
218 return hr;
221 //##########################################################################################
222 // JScriptOutValue
223 //##########################################################################################
225 JScriptOutParam::JScriptOutParam()
229 JScriptOutParam::~JScriptOutParam()
234 // JScriptOutParam, IDispatch --------------------------------------------
235 STDMETHODIMP JScriptOutParam::GetTypeInfoCount(UINT* /*pctinfo*/)
237 return E_NOTIMPL;
240 // JScriptOutParam, IDispatch --------------------------------------------
241 STDMETHODIMP JScriptOutParam::GetTypeInfo( UINT /*iTInfo*/,
242 LCID /*lcid*/,
243 ITypeInfo** /*ppTInfo*/)
245 return E_NOTIMPL;
248 // JScriptOutParam, IDispatch --------------------------------------------
249 STDMETHODIMP JScriptOutParam::GetIDsOfNames( REFIID /*riid*/,
250 LPOLESTR *rgszNames,
251 UINT /*cNames*/,
252 LCID /*lcid*/,
253 DISPID *rgDispId)
255 if( !rgDispId)
256 return E_POINTER;
259 HRESULT ret= S_OK;
260 CComBSTR name(*rgszNames);
261 name.ToLower();
263 if( name == CComBSTR( L"0") )
264 *rgDispId= 1;
265 else
266 ret= DISP_E_UNKNOWNNAME;
268 return ret;
271 // JScriptOutParam, IDispatch --------------------------------------------
272 STDMETHODIMP JScriptOutParam::Invoke( DISPID dispIdMember,
273 REFIID /*riid*/,
274 LCID /*lcid*/,
275 WORD wFlags,
276 DISPPARAMS *pDispParams,
277 VARIANT *pVarResult,
278 EXCEPINFO* /*pExcepInfo*/,
279 UINT* /*puArgErr*/)
281 HRESULT ret= S_OK;
282 switch( dispIdMember)
284 case 0: // DISPID_VALUE
285 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
287 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
288 ret= E_FAIL;
290 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
292 m_varValue.Clear();
293 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
294 ret= E_FAIL;
296 else
297 ret= E_POINTER;
298 break;
299 case 1: //
300 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
302 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
303 ret= E_FAIL;
305 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
307 m_varValue.Clear();
308 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
309 ret= E_FAIL;
311 else
312 ret= E_POINTER;
313 break;
315 default:
316 ret= DISP_E_MEMBERNOTFOUND;
317 break;
320 return ret;