LibreOffice Module extensions (master) 1
jscriptclasses.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "jscriptclasses.hxx"
21
22
23// JScriptValue
24
25JScriptValue::JScriptValue(): m_bOutParam(false), m_bInOutParam(false)
26{
27}
28
30{
31}
32
33
34// JScriptValue, IDispatch --------------------------------------------
35COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::GetTypeInfoCount(UINT* /*pctinfo*/)
36{
37 return E_NOTIMPL;
38}
39
40// JScriptValue, IDispatch --------------------------------------------
41COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::GetTypeInfo( UINT /*iTInfo*/,
42 LCID /*lcid*/,
43 ITypeInfo** /*ppTInfo*/)
44{
45 return E_NOTIMPL;
46}
47
48// JScriptValue, IDispatch --------------------------------------------
49COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::GetIDsOfNames( REFIID /*riid*/,
50 LPOLESTR *rgszNames,
51 UINT /*cNames*/,
52 LCID /*lcid*/,
53 DISPID *rgDispId)
54{
55 if( !rgDispId)
56 return E_POINTER;
57
58
59 HRESULT ret= S_OK;
60 CComBSTR name(*rgszNames);
61 name.ToLower();
62
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;
73
74 return ret;
75}
76
77// JScriptValue, IDispatch --------------------------------------------
78COM_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*/)
86{
87 if( pDispParams->cNamedArgs)
88 return DISP_E_NONAMEDARGS;
89
90
91 HRESULT ret= S_OK;
92 switch( dispIdMember)
93 {
94 case 0: // DISPID_VALUE
95 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
96 {
97 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
98 ret= E_FAIL;
99 }
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;
130 }
131
132 return ret;
133}
134
135// JScriptValue, IScriptOutParam-----------------------
136COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::Set( VARIANT type, VARIANT value)
137{
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;
147}
148// JScriptValue, IScriptOutParam-----------------------
149COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::Get( VARIANT *val)
150{
151 Lock();
152 if( !val)
153 return E_POINTER;
154 HRESULT hr= VariantCopy( val, &m_varValue);
155 Unlock();
156 return hr;
157}
158
159COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::InitOutParam()
160{
161 Lock();
162 m_varValue.Clear();
163 m_bOutParam= true;
164 m_bInOutParam= false;
165 Unlock();
166 return S_OK;
167}
168
169COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::InitInOutParam( VARIANT type, VARIANT value)
170{
171 Lock();
172 m_bInOutParam= true;
173 m_bOutParam= false;
174 Unlock();
175 return Set( type, value);
176}
177
178COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::IsOutParam( VARIANT_BOOL * flag)
179{
180 Lock();
181 if( !flag)
182 return E_POINTER;
183 *flag= m_bOutParam ? VARIANT_TRUE : VARIANT_FALSE;
184 Unlock();
185 return S_OK;
186}
187
188COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::IsInOutParam( VARIANT_BOOL * flag)
189{
190 Lock();
191 if( !flag)
192 return E_POINTER;
193 *flag= m_bInOutParam ? VARIANT_TRUE : VARIANT_FALSE;
194 Unlock();
195 return S_OK;
196}
197
198COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptValue::GetValue( BSTR* type, VARIANT *value)
199{
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;
208}
209
210
211// JScriptOutValue
212
213
215{
216}
217
219{
220}
221
222
223// JScriptOutParam, IDispatch --------------------------------------------
224COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptOutParam::GetTypeInfoCount(UINT* /*pctinfo*/)
225{
226 return E_NOTIMPL;
227}
228
229// JScriptOutParam, IDispatch --------------------------------------------
230COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptOutParam::GetTypeInfo( UINT /*iTInfo*/,
231 LCID /*lcid*/,
232 ITypeInfo** /*ppTInfo*/)
233{
234 return E_NOTIMPL;
235}
236
237// JScriptOutParam, IDispatch --------------------------------------------
238COM_DECLSPEC_NOTHROW STDMETHODIMP JScriptOutParam::GetIDsOfNames( REFIID /*riid*/,
239 LPOLESTR *rgszNames,
240 UINT /*cNames*/,
241 LCID /*lcid*/,
242 DISPID *rgDispId)
243{
244 if( !rgDispId)
245 return E_POINTER;
246
247
248 HRESULT ret= S_OK;
249 CComBSTR name(*rgszNames);
250 name.ToLower();
251
252 if( name == CComBSTR( L"0") )
253 *rgDispId= 1;
254 else
255 ret= DISP_E_UNKNOWNNAME;
256
257 return ret;
258}
259
260// JScriptOutParam, IDispatch --------------------------------------------
261COM_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*/)
269{
270 HRESULT ret= S_OK;
271 switch( dispIdMember)
272 {
273 case 0: // DISPID_VALUE
274 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
275 {
276 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
277 ret= E_FAIL;
278 }
279 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
280 {
281 m_varValue.Clear();
282 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
283 ret= E_FAIL;
284 }
285 else
286 ret= E_POINTER;
287 break;
288 case 1:
289 if( wFlags & DISPATCH_PROPERTYGET && pVarResult)
290 {
291 if( FAILED( VariantCopy( pVarResult, &m_varValue)))
292 ret= E_FAIL;
293 }
294 else if( wFlags & DISPATCH_PROPERTYPUT || wFlags & DISPATCH_PROPERTYPUTREF)
295 {
296 m_varValue.Clear();
297 if( FAILED( VariantCopyInd( &m_varValue, &pDispParams->rgvarg[0])))
298 ret= E_FAIL;
299 }
300 else
301 ret= E_POINTER;
302 break;
303
304 default:
305 ret= DISP_E_MEMBERNOTFOUND;
306 break;
307 }
308
309 return ret;
310}
311
312/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
STDMETHOD() GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) override
STDMETHOD() GetTypeInfoCount(UINT *pctinfo) override
STDMETHOD() Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) override
CComVariant m_varValue
virtual ~JScriptOutParam()
STDMETHOD() GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) override
STDMETHOD() Get(VARIANT *val) override
STDMETHOD() Set(VARIANT type, VARIANT value) override
CComVariant m_varValue
STDMETHOD() IsInOutParam(VARIANT_BOOL *flag) override
STDMETHOD() GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) override
virtual ~JScriptValue()
STDMETHOD() GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) override
STDMETHOD() GetValue(BSTR *type, VARIANT *value) override
STDMETHOD() InitInOutParam(VARIANT type, VARIANT value) override
STDMETHOD() GetTypeInfoCount(UINT *pctinfo) override
CComBSTR m_bstrType
STDMETHOD() IsOutParam(VARIANT_BOOL *flag) override
STDMETHOD() Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) override
STDMETHOD() InitOutParam() override
IJScriptValueObject VARIANT value
Definition: comifaces.hxx:28
Any value
const char * name
unsigned short WORD
#define VT_BSTR
return hr
Definition: so_activex.cxx:446
ResultType type