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