bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / test / ole / unoTocomCalls / XCallback_Impl / Callback.cpp
blobc60a1821942668610b528c50cde76c608e4704b6
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 .
19 // Callback.cpp : Implementation of CCallback
20 #include "stdafx.h"
21 #include "XCallback_Impl.h"
22 #include "Callback.h"
25 // CCallback
28 STDMETHODIMP CCallback::func1()
30 MessageBox( NULL, _T("Callback::func1 called"),_T(""), MB_OK);
31 return S_OK;
34 STDMETHODIMP CCallback::returnInterface(IDispatch **ppdisp)
36 if( ! ppdisp)
37 return E_POINTER;
38 CComPtr<IDispatch> spDisp;
39 spDisp.CoCreateInstance( L"XCallback_Impl.Simple");
40 *ppdisp= spDisp;
41 (*ppdisp)->AddRef();
42 return S_OK;
45 STDMETHODIMP CCallback::outInterface(IDispatch **ppdisp)
47 // return S_OK;
48 if( ! ppdisp)
49 return E_POINTER;
50 CComPtr<IDispatch> spDisp;
51 spDisp.CoCreateInstance( L"XCallback_Impl.Simple");
52 *ppdisp= spDisp;
53 (*ppdisp)->AddRef();
55 // MessageBox( NULL, _T("CCallback::outInterface"), _T(""), MB_OK);
56 return S_OK;
59 STDMETHODIMP CCallback::outValuesMixed(long val, long *pval, BSTR string)
61 USES_CONVERSION;
62 char buff[1024];
63 *pval = val+1;
64 sprintf( buff, "param1: %d, param2 out: %d, param3: %S", val, *pval, string);
65 MessageBox( NULL, A2T(buff), A2T("XCallback_Impl.Callback"), MB_OK);
66 return S_OK;
70 STDMETHODIMP CCallback::outValuesAll(
71 /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdisp,
72 /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppSimpleStruct,
73 /* [out] */ long __RPC_FAR *aSimpleEnum,
74 /* [out] */ SAFEARRAY __RPC_FAR * __RPC_FAR *outSeq,
75 /* [out] */ VARIANT __RPC_FAR *varAny,
76 /* [out] */ VARIANT_BOOL __RPC_FAR *aBool,
77 /* [out] */ short __RPC_FAR *aChar,
78 /* [out] */ BSTR __RPC_FAR *aString,
79 /* [out] */ float __RPC_FAR *aFloat,
80 /* [out] */ double __RPC_FAR *aDouble,
81 /* [out] */ unsigned char __RPC_FAR *aByte,
82 /* [out] */ short __RPC_FAR *aShort,
83 /* [out] */ long __RPC_FAR *aLong)
84 //)
86 // if( ! ppdisp || ! ppSimpleStruct || ! aSimpleEnum ||
87 // ! outSeq || !varAny ||! aBool || ! aChar ||
88 // ! aString || ! aFloat || ! aDouble || ! aByte ||
89 // ! aShort || ! aLong || ! aUShort || ! aULong)
90 // return E_POINTER;
92 HRESULT hr=S_OK;
93 hr= outInterface( ppdisp);
94 hr= outStruct( ppSimpleStruct);
95 hr= outEnum( aSimpleEnum);
96 hr= outSeqAny( outSeq);
97 hr= outAny( varAny);
98 hr= outBool( aBool);
99 hr= outChar( aChar);
100 hr= outString( aString);
101 hr= outFloat( aFloat);
102 hr= outDouble( aDouble);
103 hr= outByte( aByte);
104 hr= outShort( aShort);
105 hr= outLong( aLong);
106 return hr;
109 STDMETHODIMP CCallback::outStruct(IDispatch **outStruct)
111 // return S_OK;
112 if( !outStruct)
113 return E_POINTER;
114 HRESULT hr= E_FAIL;
115 // MessageBox( NULL, _T("CCallback::outStruct"), _T(""), MB_OK);
117 CComPtr<IDispatch> _dispMgr;
118 if( SUCCEEDED(hr= _dispMgr.CoCreateInstance(L"com.sun.star.ServiceManager")))
120 CComDispatchDriver manager( _dispMgr);
121 CComVariant param1(L"com.sun.star.reflection.CoreReflection");
122 CComVariant varRet;
123 hr= manager.Invoke1( L"createInstance", &param1, &varRet);
125 CComDispatchDriver reflection( varRet.pdispVal);
126 param1= L"oletest.SimpleStruct";
127 varRet.Clear();
128 hr= reflection.Invoke1( L"forName", &param1, &varRet);
130 CComDispatchDriver classSimpleStruct( varRet.pdispVal);
132 CComPtr<IDispatch> dispStruct;
133 param1.vt= VT_DISPATCH | VT_BYREF;
134 param1.ppdispVal= &dispStruct;
135 if( SUCCEEDED( hr= classSimpleStruct.Invoke1(L"createObject", &param1)))
137 // Set the value
138 CComDispatchDriver simpleStruct( dispStruct);
139 param1=L" this is a property string";
140 hr= simpleStruct.PutPropertyByName(L"message", &param1);
141 *outStruct= dispStruct;
142 (*outStruct)->AddRef();
143 hr= S_OK;
146 return hr;
149 STDMETHODIMP CCallback::outEnum(long *outEnum)
151 if( !outEnum)
152 return E_POINTER;
153 *outEnum= 1;
154 return S_OK;
157 STDMETHODIMP CCallback::outSeqAny(LPSAFEARRAY* outSeq)
159 // _CrtDbgBreak();
160 SAFEARRAY* pArr= SafeArrayCreateVector( VT_VARIANT, 0, 3);
161 CComVariant var[3];
162 var[0]=L" variant 0";
163 var[1]=L" variant 1";
164 var[2]=L"variant 2";
165 for( long i=0; i<3; i++)
167 SafeArrayPutElement( pArr, &i, (void*)&var[i]);
170 *outSeq= pArr;
171 return S_OK;
174 // ATLASSERT //VT_EMPTY
177 STDMETHODIMP CCallback::outAny(VARIANT *outAny)
179 if( ! outAny)
180 return E_POINTER;
181 outAny->vt= VT_BSTR;
182 outAny->bstrVal= SysAllocString( L"This is a string in a VARIANT");
184 return S_OK;
187 STDMETHODIMP CCallback::outBool(VARIANT_BOOL *outBool)
189 if( ! outBool)
190 return E_POINTER;
191 *outBool= VARIANT_TRUE;
192 return S_OK;
195 STDMETHODIMP CCallback::outChar(short *outChar)
197 if( !outChar)
198 return E_POINTER;
199 *outChar= (short)L'A';
200 return S_OK;
203 STDMETHODIMP CCallback::outString(BSTR *outString)
205 if( !outString)
206 return E_POINTER;
207 *outString= SysAllocString(L"This is a BSTR");
208 return S_OK;
211 STDMETHODIMP CCallback::outFloat(float *outFloat)
213 if( !outFloat)
214 return E_POINTER;
215 *outFloat= 3.14f;
216 return S_OK;
219 STDMETHODIMP CCallback::outDouble(double *outDouble)
221 if(!outDouble)
222 return E_POINTER;
224 *outDouble= 3.145;
225 return S_OK;
230 STDMETHODIMP CCallback::outShort(short *outShort)
232 if(!outShort)
233 return E_POINTER;
234 *outShort= -1;
235 return S_OK;
238 STDMETHODIMP CCallback::outLong(long *outLong)
240 if(!outLong)
241 return E_POINTER;
242 *outLong= 0xffffffff;
243 return S_OK;
248 STDMETHODIMP CCallback::outByte(unsigned char* outByte)
250 if(!outByte)
251 return E_POINTER;
252 *outByte= 0xff;
253 return S_OK;
256 STDMETHODIMP CCallback::inoutInterface(IDispatch **ppdisp)
258 if( !ppdisp)
259 return E_POINTER;
260 CComDispatchDriver disp( *ppdisp);
261 CComVariant param1(L"");
262 disp.Invoke1(L"func", &param1);
264 (*ppdisp)->Release();
266 CComPtr<IDispatch> outDisp;
267 outDisp.CoCreateInstance( L"XCallback_Impl.Simple");
268 *ppdisp= outDisp;
269 (*ppdisp)->AddRef();
271 return S_OK;
274 STDMETHODIMP CCallback::inoutStruct(IDispatch **inoutVal)
276 if( !inoutVal)
277 return E_POINTER;
278 HRESULT hr= S_OK;
279 USES_CONVERSION;
280 CComVariant var;
281 CComDispatchDriver disp( *inoutVal);
283 hr= disp.GetPropertyByName(L"message", &var);
284 MessageBox( NULL, W2T(var.bstrVal), _T("XCallback_Impl.Callback"), MB_OK);
286 (*inoutVal)->Release();
288 CComDispatchDriver dispStruct;
289 hr= outStruct( &dispStruct.p);
290 var.Clear();
291 var= L"This struct was created in XCallback_Imp.Callback";
292 hr= dispStruct.PutPropertyByName(L"message", &var);
294 *inoutVal= dispStruct;
295 (*inoutVal)->AddRef();
296 return hr;
299 STDMETHODIMP CCallback::inoutEnum(long *inoutVal)
301 if( !inoutVal)
302 return E_POINTER;
303 *inoutVal= *inoutVal+1;
305 return S_OK;
308 STDMETHODIMP CCallback::inoutSeqAny(LPSAFEARRAY *pArray)
310 if( !pArray)
311 return E_POINTER;
312 HRESULT hr= S_OK;
313 long lbound=0;
314 long ubound=0;
315 hr= SafeArrayGetLBound( *pArray, 1, &lbound);
316 hr= SafeArrayGetUBound( *pArray, 1, &ubound);
317 long count= ubound - lbound + 1;
319 // the Array is supposet to contain variants
320 CComVariant var;
321 for( long i=0; i<count; i++)
323 var.Clear();
324 hr= SafeArrayGetElement( *pArray, &i, (void*)&var);
327 SafeArrayDestroy( *pArray);
329 outSeqAny( pArray);
330 return S_OK;
333 STDMETHODIMP CCallback::inoutAny(VARIANT *inoutVal)
335 if( !inoutVal)
336 return E_POINTER;
337 USES_CONVERSION;
338 if( inoutVal->vt= VT_BSTR)
339 MessageBox( NULL, W2T( inoutVal->bstrVal), _T("XCallback_Impl.Callback"), MB_OK);
341 VariantClear( inoutVal);
342 inoutVal->vt= VT_BSTR;
343 inoutVal->bstrVal=SysAllocString( L" [string] XCallback_Impl.Callback inoutAny");
344 return S_OK;
347 STDMETHODIMP CCallback::inoutBool(VARIANT_BOOL *inoutVal)
349 if( !inoutVal)
350 return E_POINTER;
352 *inoutVal= *inoutVal == VARIANT_TRUE ? VARIANT_FALSE : VARIANT_TRUE;
353 return S_OK;
356 STDMETHODIMP CCallback::inoutChar(short *inoutVal)
358 if( !inoutVal)
359 return E_POINTER;
360 USES_CONVERSION;
361 char buff[256];
362 sprintf( buff, "character value: %C", *inoutVal);
363 MessageBox( NULL, A2T(buff), _T("XCallback_Impl.Callback"), MB_OK);
364 *inoutVal= L'B';
365 return S_OK;
368 STDMETHODIMP CCallback::inoutString(BSTR *inoutVal)
370 if( !inoutVal)
371 return E_POINTER;
372 USES_CONVERSION;
373 MessageBox( NULL, W2T(*inoutVal), _T("XCallback_Impl.Callback"), MB_OK);
374 SysFreeString(*inoutVal);
375 *inoutVal= SysAllocString(L"a string from XCallback_Impl.Callback");
377 return S_OK;
380 STDMETHODIMP CCallback::inoutFloat(float *inoutVal)
382 if( !inoutVal)
383 return E_POINTER;
384 *inoutVal = *inoutVal+1;
385 return S_OK;
388 STDMETHODIMP CCallback::inoutDouble(double *inoutVal)
390 if( !inoutVal)
391 return E_POINTER;
392 *inoutVal= *inoutVal+1;
393 return S_OK;
396 STDMETHODIMP CCallback::inoutByte(unsigned char *inoutVal)
398 if( !inoutVal)
399 return E_POINTER;
400 *inoutVal= 0xff;
401 return S_OK;
404 STDMETHODIMP CCallback::inoutShort(short *inoutVal)
406 if( !inoutVal)
407 return E_POINTER;
408 *inoutVal= -1;
409 return S_OK;
412 STDMETHODIMP CCallback::inoutLong(long* inoutVal)
414 if( !inoutVal)
415 return E_POINTER;
416 *inoutVal= 0xffffffff;
417 return S_OK;
420 STDMETHODIMP CCallback::inoutValuesAll(
421 /* [out][in] */ IDispatch __RPC_FAR *__RPC_FAR *aXSimple,
422 /* [out][in] */ IDispatch __RPC_FAR *__RPC_FAR *aStruct,
423 /* [out][in] */ long __RPC_FAR *aEnum,
424 /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *aSeq,
425 /* [out][in] */ VARIANT __RPC_FAR *aAny,
426 /* [out][in] */ VARIANT_BOOL __RPC_FAR *aBool,
427 /* [out][in] */ short __RPC_FAR *aChar,
428 /* [out][in] */ BSTR __RPC_FAR *aString,
429 /* [out][in] */ float __RPC_FAR *aFloat,
430 /* [out][in] */ double __RPC_FAR *aDouble,
431 /* [out][in] */ unsigned char __RPC_FAR *aByte,
432 /* [out][in] */ short __RPC_FAR *aShort,
433 /* [out][in] */ long __RPC_FAR *aLong)
435 inoutInterface( aXSimple);
436 inoutStruct( aStruct);
437 inoutEnum( aEnum);
438 inoutSeqAny( aSeq);
439 inoutAny( aAny);
440 inoutBool( aBool);
441 inoutChar( aChar);
442 inoutString( aString);
443 inoutFloat( aFloat);
444 inoutDouble( aDouble);
445 inoutByte( aByte);
446 inoutShort( aShort);
447 inoutLong( aLong);
449 return S_OK;
453 STDMETHODIMP CCallback::inValues(short aChar, long aLong, BSTR aString)
455 USES_CONVERSION;
456 wchar_t _char= (wchar_t) aChar;
457 char buff[1024];
458 sprintf( buff, "Parameters: char= %C, long= %d, string= %s", _char, aLong, W2A(aString));
459 MessageBox( NULL, A2T(buff), _T("XCallback_Impl.Callback"), MB_OK);
460 return S_OK;
463 STDMETHODIMP CCallback::outSeqByte(LPSAFEARRAY * outVal)
465 // TODO: Add your implementation code here
467 return S_OK;
470 STDMETHODIMP CCallback::inSeqByte( LPSAFEARRAY listeners)
473 return S_OK;
476 STDMETHODIMP CCallback::inSeqXEventListener( LPSAFEARRAY listeners, LPSAFEARRAY events)
478 HRESULT hr= S_OK;
479 long ubound= 0;
480 long lbound= 0;
481 long count= 0;
482 hr= SafeArrayGetUBound( listeners, 1, &ubound);
483 hr= SafeArrayGetLBound( listeners, 1, &lbound);
484 count= ubound - lbound +1;
486 // We assume that the count of EventObjects in events is the same
487 for( long i = 0; i < count; i++)
489 CComVariant varListener;
490 CComVariant varEvent;
491 hr= SafeArrayGetElement( listeners, &i, &varListener);
492 hr= SafeArrayGetElement( events, &i, &varEvent);
493 if( varListener.vt == VT_DISPATCH && varEvent.vt == VT_DISPATCH)
495 CComDispatchDriver disp( varListener.pdispVal);
496 hr= disp.Invoke1(L"disposing", &varEvent);
501 return S_OK;
505 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */