1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 // SOActiveX.cpp : Implementation of CSOActiveX
22 #pragma warning (push,1)
23 #pragma warning (disable:4265)
26 #include "so_activex.h"
27 #include "SOActiveX.h"
28 #include "SOComWindowPeer.h"
29 #include "SODispatchInterceptor.h"
30 #include "SOActionsApproval.h"
34 #define STAROFFICE_WINDOWCLASS "SOParentWindow"
39 void OutputError_Impl( HWND hw
, HRESULT ErrorCode
)
43 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
44 FORMAT_MESSAGE_FROM_SYSTEM
,
47 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
52 ::MessageBoxA( hw
, (LPCTSTR
)sMessage
, NULL
, MB_OK
| MB_ICONINFORMATION
);
53 LocalFree( sMessage
);
56 HRESULT
ExecuteFunc( IDispatch
* idispUnoObject
,
60 CComVariant
* pResult
)
66 HRESULT hr
= idispUnoObject
->GetIDsOfNames( IID_NULL
, &sFuncName
, 1, LOCALE_USER_DEFAULT
, &id
);
67 if( !SUCCEEDED( hr
) ) return hr
;
69 DISPPARAMS dispparams
= { params
, 0, count
, 0};
73 hr
= idispUnoObject
->Invoke( id
, IID_NULL
,LOCALE_USER_DEFAULT
, DISPATCH_METHOD
,
74 &dispparams
, pResult
, &myInfo
, 0);
76 // for debugging purposes
78 // if ( !SUCCEEDED( hr ) )
79 // ::MessageBox( NULL, OLE2A( myInfo.bstrDescription ), OLE2A( myInfo.bstrSource ), MB_OK | MB_ICONINFORMATION );
84 HRESULT
GetIDispByFunc( IDispatch
* idispUnoObject
,
88 CComPtr
<IDispatch
>& pdispResult
)
94 HRESULT hr
= ExecuteFunc( idispUnoObject
, sFuncName
, params
, count
, &result
);
95 if( !SUCCEEDED( hr
) ) return hr
;
97 if( result
.vt
!= VT_DISPATCH
|| result
.pdispVal
== NULL
)
100 pdispResult
= CComPtr
<IDispatch
>( result
.pdispVal
);
105 HRESULT
PutPropertiesToIDisp( IDispatch
* pdispObject
,
106 OLECHAR
** sMemberNames
,
107 CComVariant
* pVariant
,
110 for( unsigned int ind
= 0; ind
< count
; ind
++ )
113 HRESULT hr
= pdispObject
->GetIDsOfNames( IID_NULL
, &sMemberNames
[ind
], 1, LOCALE_USER_DEFAULT
, &id
);
114 if( !SUCCEEDED( hr
) ) return hr
;
116 hr
= CComDispatchDriver::PutProperty( pdispObject
, id
, &pVariant
[ind
] );
117 if( !SUCCEEDED( hr
) ) return hr
;
123 HRESULT
GetPropertiesFromIDisp( IDispatch
* pdispObject
,
124 OLECHAR
** sMemberNames
,
125 CComVariant
* pVariant
,
128 for( unsigned int ind
= 0; ind
< count
; ind
++ )
131 HRESULT hr
= pdispObject
->GetIDsOfNames( IID_NULL
, &sMemberNames
[ind
], 1, LOCALE_USER_DEFAULT
, &id
);
132 if( !SUCCEEDED( hr
) ) return hr
;
134 hr
= CComDispatchDriver::GetProperty( pdispObject
, id
, &pVariant
[ind
] );
135 if( !SUCCEEDED( hr
) ) return hr
;
143 CSOActiveX::CSOActiveX()
145 , mCurFileUrl( L
"private:factory/swriter" )
150 , mpDispatchInterceptor( NULL
)
151 , mnVersion( SO_NOT_DETECTED
)
152 , mbReadyForActivation( FALSE
)
153 , mbDrawLocked( FALSE
)
155 CLSID clsFactory
= {0x82154420,0x0FBF,0x11d4,{0x83, 0x13,0x00,0x50,0x04,0x52,0x6A,0xB4}};
156 HRESULT hr
= CoCreateInstance( clsFactory
, NULL
, CLSCTX_ALL
, __uuidof(IDispatch
), (void**)&mpDispFactory
);
157 if( !SUCCEEDED( hr
) )
158 OutputError_Impl( NULL
, hr
);
160 mPWinClass
.style
= CS_HREDRAW
|CS_VREDRAW
;
161 mPWinClass
.lpfnWndProc
= ::DefWindowProc
;
162 mPWinClass
.cbClsExtra
= 0;
163 mPWinClass
.cbWndExtra
= 0;
164 mPWinClass
.hInstance
= (HINSTANCE
) GetModuleHandle(NULL
); //myInstance;
165 mPWinClass
.hIcon
= NULL
;
166 mPWinClass
.hCursor
= NULL
;
167 mPWinClass
.hbrBackground
= (HBRUSH
) COLOR_BACKGROUND
;
168 mPWinClass
.lpszMenuName
= NULL
;
169 mPWinClass
.lpszClassName
= STAROFFICE_WINDOWCLASS
;
171 RegisterClass(&mPWinClass
);
174 CSOActiveX::~CSOActiveX()
180 HRESULT
CSOActiveX::Cleanup()
182 CComVariant dummyResult
;
184 if( mpDispatchInterceptor
)
188 // remove dispatch interceptor
189 CComQIPtr
< IDispatch
, &IID_IDispatch
> pIDispDispInter( mpDispatchInterceptor
);
190 CComVariant
aVariant( pIDispDispInter
);
191 ExecuteFunc( mpDispFrame
,
192 L
"releaseDispatchProviderInterceptor",
198 mpDispatchInterceptor
->ClearParent();
199 mpDispatchInterceptor
->Release();
200 mpDispatchInterceptor
= NULL
;
203 mpDispTempFile
= CComPtr
< IDispatch
>();
204 mbReadyForActivation
= FALSE
;
206 if( mpInstanceLocker
)
208 ExecuteFunc( mpInstanceLocker
, L
"dispose", NULL
, 0, &dummyResult
);
209 mpInstanceLocker
= CComPtr
< IDispatch
>();
214 BOOL bCloserActivated
= FALSE
;
216 CComPtr
<IDispatch
> pDispDocumentCloser
;
217 CComVariant
aDocCloser( L
"com.sun.star.embed.DocumentCloser" );
218 HRESULT hr
= GetIDispByFunc( mpDispFactory
,
222 pDispDocumentCloser
);
223 if ( SUCCEEDED( hr
) && pDispDocumentCloser
)
225 SAFEARRAY FAR
* pInitFrame
= SafeArrayCreateVector( VT_VARIANT
, 0, 1 );
227 CComVariant
pFrameVariant( mpDispFrame
);
228 SafeArrayPutElement( pInitFrame
, &nInitInd
, &pFrameVariant
);
229 CComVariant aVarInitFrame
;
230 aVarInitFrame
.vt
= VT_ARRAY
| VT_VARIANT
; aVarInitFrame
.parray
= pInitFrame
;
231 hr
= ExecuteFunc( pDispDocumentCloser
, L
"initialize", &aVarInitFrame
, 1, &dummyResult
);
232 if( SUCCEEDED( hr
) )
234 // the following call will let the closing happen
235 hr
= ExecuteFunc( pDispDocumentCloser
, L
"dispose", NULL
, 0, &dummyResult
);
236 bCloserActivated
= SUCCEEDED( hr
);
240 if ( !bCloserActivated
)
242 CComVariant aPropVar
;
243 aPropVar
.vt
= VT_BOOL
; aPropVar
.boolVal
= VARIANT_TRUE
;
244 if ( !SUCCEEDED( ExecuteFunc( mpDispFrame
, L
"close", &aPropVar
, 1, &dummyResult
) ) )
245 ExecuteFunc( mpDispFrame
, L
"dispose", NULL
, 0, &dummyResult
);
248 mpDispFrame
= CComPtr
< IDispatch
>();
251 if( ::IsWindow( mOffWin
) )
252 ::DestroyWindow( mOffWin
);
259 HRESULT
CSOActiveX::TerminateOffice()
262 CComPtr
<IDispatch
> pdispDesktop
;
263 CComVariant
aDesktopServiceName( L
"com.sun.star.frame.Desktop" );
265 HRESULT hr
= GetIDispByFunc( mpDispFactory
, L
"createInstance", &aDesktopServiceName
, 1, pdispDesktop
);
266 if( !pdispDesktop
|| !SUCCEEDED( hr
) ) return hr
;
268 // create tree of frames
269 CComPtr
<IDispatch
> pdispChildren
;
270 hr
= GetIDispByFunc( pdispDesktop
, L
"getFrames", NULL
, 0, pdispChildren
);
271 if( !pdispChildren
|| !SUCCEEDED( hr
) ) return hr
;
274 CComVariant
nFlag( 4 );
275 hr
= ExecuteFunc( pdispChildren
, L
"queryFrames", &nFlag
, 1, &aFrames
);
276 if ( SUCCEEDED( hr
) )
278 if ( ( aFrames
.vt
== ( VT_ARRAY
| VT_DISPATCH
) || aFrames
.vt
== ( VT_ARRAY
| VT_VARIANT
) )
279 && ( !aFrames
.parray
|| aFrames
.parray
->cDims
== 1 && aFrames
.parray
->rgsabound
[0].cElements
== 0 ) )
281 // there is no frames open
282 // TODO: check whether the frames are hidden if they are open?
283 CComVariant dummyResult
;
284 hr
= ExecuteFunc( pdispDesktop
, L
"terminate", NULL
, 0, &dummyResult
);
291 STDMETHODIMP
CSOActiveX::InitNew ()
293 mnVersion
= GetVersionConnected();
298 STDMETHODIMP
CSOActiveX::Load ( LPSTREAM
/*pStm*/ )
300 mnVersion
= GetVersionConnected();
304 // for now just ignore
309 STDMETHODIMP
CSOActiveX::Load( LPPROPERTYBAG pPropBag
, LPERRORLOG
/*pErrorLog*/ )
311 mnVersion
= GetVersionConnected();
313 IPropertyBag2
* pPropBag2
;
314 HRESULT hr
= pPropBag
->QueryInterface( IID_IPropertyBag2
, (void**)&pPropBag2
);
315 //ATLASSERT( hr >= 0 );
317 if( !SUCCEEDED( hr
) )
321 hr
= pPropBag2
->CountProperties( &aNum
);
322 //ATLASSERT( hr >= 0 );
323 if( !SUCCEEDED( hr
) )
326 PROPBAG2
* aPropNames
= new PROPBAG2
[aNum
];
327 unsigned long aReaded
;
329 hr
= pPropBag2
->GetPropertyInfo( 0,
333 //ATLASSERT( hr >= 0 );
334 if( !SUCCEEDED( hr
) )
340 CComVariant
* aVal
= new CComVariant
[aNum
];
341 HRESULT
* hvs
= new HRESULT
[aNum
];
342 hr
= pPropBag2
->Read( aNum
,
347 //ATLASSERT( hr >= 0 );
348 if( !SUCCEEDED( hr
) )
357 for( unsigned long ind
= 0; ind
< aNum
; ind
++ )
359 // all information from the 'object' tag is in strings
360 if( aVal
[ind
].vt
== VT_BSTR
&& !strcmp( OLE2T( aPropNames
[ind
].pstrName
), "src" ) )
362 mCurFileUrl
= wcsdup( aVal
[ind
].bstrVal
);
364 else if( aVal
[ind
].vt
== VT_BSTR
365 && !strcmp( OLE2T( aPropNames
[ind
].pstrName
), "readonly" ) )
367 if( !strcmp( OLE2T( aVal
[ind
].bstrVal
), "true" ) )
386 mbReadyForActivation
= FALSE
;
387 hr
= CBindStatusCallback
<CSOActiveX
>::Download( this, &CSOActiveX::CallbackCreateXInputStream
, mCurFileUrl
, m_spClientSite
, FALSE
);
388 if ( hr
== MK_S_ASYNCHRONOUS
)
391 if ( !SUCCEEDED( hr
) )
393 // trigger initialization without stream
403 HRESULT
CSOActiveX::GetUnoStruct( OLECHAR
* sStructName
, CComPtr
<IDispatch
>& pdispResult
)
405 CComVariant
aComStruct( sStructName
);
406 return GetIDispByFunc( mpDispFactory
, L
"Bridge_GetStruct", &aComStruct
, 1, pdispResult
);
409 HRESULT
CSOActiveX::GetUrlStruct( OLECHAR
* sUrl
, CComPtr
<IDispatch
>& pdispUrl
)
411 HRESULT hr
= GetUnoStruct( L
"com.sun.star.util.URL", pdispUrl
);
412 if( !SUCCEEDED( hr
) ) return hr
;
414 OLECHAR
* sURLMemberName
= L
"Complete";
416 hr
= pdispUrl
->GetIDsOfNames( IID_NULL
, &sURLMemberName
, 1, LOCALE_USER_DEFAULT
, &nURLID
);
417 if( !SUCCEEDED( hr
) ) return hr
;
418 CComVariant
aComUrl( sUrl
);
419 hr
= CComDispatchDriver::PutProperty( pdispUrl
, nURLID
, &aComUrl
);
420 if( !SUCCEEDED( hr
) ) return hr
;
422 CComPtr
<IDispatch
> pdispTransformer
;
423 CComVariant
aServiceName( L
"com.sun.star.util.URLTransformer" );
424 hr
= GetIDispByFunc( mpDispFactory
,
429 if( !SUCCEEDED( hr
) ) return hr
;
431 CComVariant dummyResult
;
432 CComVariant aParam
[2];
433 aParam
[1].ppdispVal
= &pdispUrl
;
434 aParam
[1].vt
= VT_DISPATCH
| VT_BYREF
;
435 aParam
[0] = CComVariant( L
"file:///" );
437 hr
= ExecuteFunc( pdispTransformer
, L
"parseSmart", aParam
, 2, &dummyResult
);
438 if( !SUCCEEDED( hr
) || dummyResult
.vt
!= VT_BOOL
|| !dummyResult
.boolVal
) return hr
;
443 HRESULT
CSOActiveX::SetLayoutManagerProps()
448 CComVariant pVarLayoutMgr
;
449 OLECHAR
* sLMPropName
= L
"LayoutManager";
450 HRESULT hr
= GetPropertiesFromIDisp( mpDispFrame
, &sLMPropName
, &pVarLayoutMgr
, 1 );
451 if( pVarLayoutMgr
.vt
!= VT_DISPATCH
|| pVarLayoutMgr
.pdispVal
== NULL
)
454 CComPtr
<IDispatch
> pdispLM( pVarLayoutMgr
.pdispVal
);
457 if( !SUCCEEDED( hr
) || !pdispLM
)
460 OLECHAR
* sATName
= L
"AutomaticToolbars";
462 pATProp
.vt
= VT_BOOL
; pATProp
.boolVal
= VARIANT_FALSE
;
463 hr
= PutPropertiesToIDisp( pdispLM
, &sATName
, &pATProp
, 1 );
468 HRESULT
CSOActiveX::CreateFrameOldWay( HWND hwnd
, int width
, int height
)
473 // create window handle holder
474 CComPtr
< CComObject
< SOComWindowPeer
> > pPeerToSend
= new CComObject
<SOComWindowPeer
>();
475 pPeerToSend
->SetHWNDInternally( hwnd
);
476 CComQIPtr
< IDispatch
, &IID_IDispatch
> pIDispToSend( pPeerToSend
);
478 // create rectangle structure
479 CComPtr
<IDispatch
> pdispRectangle
;
480 HRESULT hr
= GetUnoStruct( L
"com.sun.star.awt.Rectangle", pdispRectangle
);
481 if( !SUCCEEDED( hr
) ) return hr
;
483 OLECHAR
* sRectMemberNames
[4] = { L
"X",
487 CComVariant pRectVariant
[4];
488 pRectVariant
[0] = pRectVariant
[1] = pRectVariant
[2] = pRectVariant
[3] = CComVariant( 0 );
490 hr
= PutPropertiesToIDisp( pdispRectangle
, sRectMemberNames
, pRectVariant
, 4 );
491 if( !SUCCEEDED( hr
) ) return hr
;
493 // create WindowDescriptor structure
494 CComPtr
<IDispatch
> pdispWinDescr
;
495 hr
= GetUnoStruct( L
"com.sun.star.awt.WindowDescriptor", pdispWinDescr
);
496 if( !SUCCEEDED( hr
) ) return hr
;
498 // fill in descriptor with info
499 OLECHAR
* sDescriptorMemberNames
[6] = { L
"Type",
500 L
"WindowServiceName",
504 L
"WindowAttributes" };
505 CComVariant pDescriptorVar
[6];
506 pDescriptorVar
[0] = CComVariant( 0 );
507 pDescriptorVar
[1] = CComVariant( L
"workwindow" );
508 pDescriptorVar
[2] = CComVariant( 1 );
509 pDescriptorVar
[3] = CComVariant( pIDispToSend
);
510 pDescriptorVar
[4] = CComVariant( pdispRectangle
);
511 pDescriptorVar
[5] = CComVariant( 33 );
512 hr
= PutPropertiesToIDisp( pdispWinDescr
, sDescriptorMemberNames
, pDescriptorVar
, 6 );
513 if( !SUCCEEDED( hr
) ) return hr
;
515 // create XToolkit instance
516 CComPtr
<IDispatch
> pdispToolkit
;
517 CComVariant
aServiceName( L
"com.sun.star.awt.Toolkit" );
518 hr
= GetIDispByFunc( mpDispFactory
, L
"createInstance", &aServiceName
, 1, pdispToolkit
);
519 if( !SUCCEEDED( hr
) ) return hr
;
521 // create window with toolkit
522 CComVariant
aWinDescr( pdispWinDescr
);
523 hr
= GetIDispByFunc( pdispToolkit
, L
"createWindow", &aWinDescr
, 1, mpDispWin
);
524 if( !SUCCEEDED( hr
) ) return hr
;
527 aServiceName
= CComVariant( L
"com.sun.star.frame.Task" );
528 hr
= GetIDispByFunc( mpDispFactory
, L
"createInstance", &aServiceName
, 1, mpDispFrame
);
529 if( !SUCCEEDED( hr
) || !mpDispFrame
)
531 // the interface com.sun.star.frame.Task is removed in 6.1
532 // but the interface com.sun.star.frame.Frame has some bugs in 6.0
533 aServiceName
= CComVariant( L
"com.sun.star.frame.Frame" );
534 hr
= GetIDispByFunc( mpDispFactory
, L
"createInstance", &aServiceName
, 1, mpDispFrame
);
535 if( !SUCCEEDED( hr
) ) return hr
;
539 CComVariant dummyResult
;
540 CComVariant
aDispWin( mpDispWin
);
541 hr
= ExecuteFunc( mpDispFrame
, L
"initialize", &aDispWin
, 1, &dummyResult
);
542 if( !SUCCEEDED( hr
) ) return hr
;
544 // set some properties to the layout manager, ignore errors for now
545 SetLayoutManagerProps();
548 CComPtr
<IDispatch
> pdispDesktop
;
549 aServiceName
= CComVariant( L
"com.sun.star.frame.Desktop" );
550 hr
= GetIDispByFunc( mpDispFactory
, L
"createInstance", &aServiceName
, 1, pdispDesktop
);
551 if( !SUCCEEDED( hr
) ) return hr
;
553 // create tree of frames
554 CComPtr
<IDispatch
> pdispChildren
;
555 hr
= GetIDispByFunc( pdispDesktop
, L
"getFrames", NULL
, 0, pdispChildren
);
556 if( !SUCCEEDED( hr
) ) return hr
;
558 // insert new frame into desctop hierarchy
559 CComVariant
aDispFrame( mpDispFrame
);
560 hr
= ExecuteFunc( pdispChildren
, L
"append", &aDispFrame
, 1, &dummyResult
);
561 if( !SUCCEEDED( hr
) ) return hr
;
564 CComVariant
aTransparent( (long)0xFFFFFFFF );
565 hr
= ExecuteFunc( mpDispWin
, L
"setBackground", &aTransparent
, 1, &dummyResult
);
566 if( !SUCCEEDED( hr
) ) return hr
;
568 CComVariant
aTrue( TRUE
);
569 hr
= ExecuteFunc( mpDispWin
, L
"setVisible", &aTrue
, 1, &dummyResult
);
570 if( !SUCCEEDED( hr
) ) return hr
;
572 CComVariant aPosArgs
[5];
573 aPosArgs
[4] = CComVariant( 0 );
574 aPosArgs
[3] = CComVariant( 0 );
575 aPosArgs
[2] = CComVariant( width
);
576 aPosArgs
[1] = CComVariant( height
);
577 aPosArgs
[0] = CComVariant( 12 );
578 hr
= ExecuteFunc( mpDispWin
, L
"setPosSize", aPosArgs
, 5, &dummyResult
);
579 if( !SUCCEEDED( hr
) ) return hr
;
581 // create frame locker if there is such service
582 aServiceName
= CComVariant( L
"com.sun.star.embed.InstanceLocker" );
583 hr
= GetIDispByFunc( mpDispFactory
, L
"createInstance", &aServiceName
, 1, mpInstanceLocker
);
584 if( SUCCEEDED( hr
) && mpInstanceLocker
)
586 SAFEARRAY FAR
* pInitVals
= SafeArrayCreateVector( VT_VARIANT
, 0, 3 );
588 // the first sequence element
590 CComVariant
pFrameVariant( mpDispFrame
);
591 SafeArrayPutElement( pInitVals
, &nInitInd
, &pFrameVariant
);
593 // the second sequence element
595 CComVariant
pStrArr( 1L );
596 SafeArrayPutElement( pInitVals
, &nInitInd
, &pStrArr
);
598 // the third sequence element
600 CComPtr
<IDispatch
> pdispValueObj
;
601 hr
= GetIDispByFunc( mpDispFactory
, L
"Bridge_GetValueObject", NULL
, 0, pdispValueObj
);
602 if( !SUCCEEDED( hr
) || !pdispValueObj
) return hr
;
604 CComVariant aValueArgs
[2];
605 aValueArgs
[1] = CComVariant( L
"com.sun.star.embed.XActionsApproval" );
606 CComPtr
< CComObject
< SOActionsApproval
> > pApproval( new CComObject
<SOActionsApproval
>() );
607 aValueArgs
[0] = CComVariant ( pApproval
);
609 hr
= ExecuteFunc( pdispValueObj
, L
"Set", aValueArgs
, 2, &dummyResult
);
610 if( !SUCCEEDED( hr
) ) return hr
;
612 CComVariant
aValueObj( pdispValueObj
);
613 SafeArrayPutElement( pInitVals
, &nInitInd
, &aValueObj
);
615 // execute initialize()
616 CComVariant aVarInitVals
;
617 aVarInitVals
.vt
= VT_ARRAY
| VT_VARIANT
; aVarInitVals
.parray
= pInitVals
;
618 hr
= ExecuteFunc( mpInstanceLocker
, L
"initialize", &aVarInitVals
, 1, &dummyResult
);
619 if( !SUCCEEDED( hr
) ) return hr
;
625 HRESULT
CSOActiveX::CallLoadComponentFromURL1PBool( OLECHAR
* sUrl
, OLECHAR
* sArgName
, BOOL sArgVal
)
627 SAFEARRAY FAR
* pPropVals
= SafeArrayCreateVector( VT_DISPATCH
, 0, 1 );
629 CComPtr
<IDispatch
> pdispPropVal
;
630 HRESULT hr
= GetUnoStruct( L
"com.sun.star.beans.PropertyValue", pdispPropVal
);
631 if( !SUCCEEDED( hr
) ) return hr
;
633 OLECHAR
* sPropMemberNames
[2] = { L
"Name", L
"Value" };
634 CComVariant pPropVar
[2];
635 pPropVar
[0] = CComVariant( sArgName
);
636 pPropVar
[1].vt
= VT_BOOL
; pPropVar
[1].boolVal
= sArgVal
? VARIANT_TRUE
: VARIANT_FALSE
;
637 hr
= PutPropertiesToIDisp( pdispPropVal
, sPropMemberNames
, pPropVar
, 2 );
638 if( !SUCCEEDED( hr
) ) return hr
;
640 SafeArrayPutElement( pPropVals
, &ix
, pdispPropVal
);
642 CComVariant aDispArgs
[4];
643 aDispArgs
[3] = CComVariant( sUrl
);
644 aDispArgs
[2] = CComVariant( L
"_self" );
645 aDispArgs
[1] = CComVariant( 0 );
646 // aDispArgs[0] = CComVariant( pPropVals ); such constructor is not defined ??!
647 aDispArgs
[0].vt
= VT_ARRAY
| VT_DISPATCH
; aDispArgs
[0].parray
= pPropVals
;
649 CComVariant dummyResult
;
650 hr
= ExecuteFunc( mpDispFrame
, L
"loadComponentFromURL", aDispArgs
, 4, &dummyResult
);
651 if( !SUCCEEDED( hr
) ) return hr
;
656 HRESULT
CSOActiveX::CallDispatchMethod( OLECHAR
* sUrl
,
657 CComVariant
* aArgNames
,
658 CComVariant
* aArgVals
,
661 CComPtr
<IDispatch
> pdispURL
;
662 HRESULT hr
= GetUrlStruct( sUrl
, pdispURL
);
663 if( !SUCCEEDED( hr
) ) return hr
;
665 CComPtr
<IDispatch
> pdispXDispatch
;
666 CComVariant aArgs
[3];
667 aArgs
[2] = CComVariant( pdispURL
);
668 aArgs
[1] = CComVariant( L
"" );
669 aArgs
[0] = CComVariant( (int)0 );
670 hr
= GetIDispByFunc( mpDispFrame
,
675 if( !SUCCEEDED( hr
) ) return hr
;
677 SAFEARRAY FAR
* pPropVals
= SafeArrayCreateVector( VT_DISPATCH
, 0, count
);
678 for( long ix
= 0; ix
< (long)count
; ix
++ )
680 CComPtr
<IDispatch
> pdispPropVal
;
681 hr
= GetUnoStruct( L
"com.sun.star.beans.PropertyValue", pdispPropVal
);
682 if( !SUCCEEDED( hr
) ) return hr
;
684 OLECHAR
* sPropMemberNames
[2] = { L
"Name", L
"Value" };
685 CComVariant pPropVar
[2];
686 pPropVar
[0] = aArgNames
[ix
];
687 pPropVar
[1] = aArgVals
[ix
];
688 hr
= PutPropertiesToIDisp( pdispPropVal
, sPropMemberNames
, pPropVar
, 2 );
689 if( !SUCCEEDED( hr
) ) return hr
;
691 SafeArrayPutElement( pPropVals
, &ix
, pdispPropVal
);
694 CComVariant aDispArgs
[2];
695 aDispArgs
[1] = CComVariant( pdispURL
);
696 // aDispArgs[0] = CComVariant( pPropVals ); such constructor is not defined ??!
697 aDispArgs
[0].vt
= VT_ARRAY
| VT_DISPATCH
; aDispArgs
[0].parray
= pPropVals
;
699 CComVariant dummyResult
;
700 hr
= ExecuteFunc( pdispXDispatch
, L
"dispatch", aDispArgs
, 2, &dummyResult
);
701 if( !SUCCEEDED( hr
) ) return hr
;
706 void CSOActiveX::CallbackCreateXInputStream( CBindStatusCallback
<CSOActiveX
>* /*pbsc*/, BYTE
* pBytes
, DWORD dwSize
)
708 if ( mbReadyForActivation
)
711 BOOL bSuccess
= FALSE
;
712 BOOL bFinishDownload
= FALSE
;
715 // means the download is finished, dwSize contains hresult
716 bFinishDownload
= TRUE
;
717 if ( SUCCEEDED( dwSize
) )
724 if ( !mpDispTempFile
)
726 CComVariant
aServiceName( L
"com.sun.star.io.TempFile" );
727 hr
= GetIDispByFunc( mpDispFactory
,
734 if( SUCCEEDED( hr
) && mpDispTempFile
)
736 SAFEARRAY FAR
* pDataArray
= SafeArrayCreateVector( VT_I1
, 0, dwSize
);
740 hr
= SafeArrayLock( pDataArray
);
741 if ( SUCCEEDED( hr
) )
743 for( DWORD ix
= 0; ix
< dwSize
; ix
++ )
744 ((BYTE
*)(pDataArray
->pvData
))[ix
] = pBytes
[ix
];
745 hr
= SafeArrayUnlock( pDataArray
);
746 if ( SUCCEEDED( hr
) )
748 CComVariant aArgs
[1];
749 aArgs
[0].vt
= VT_ARRAY
| VT_I1
; aArgs
[0].parray
= pDataArray
;
750 CComVariant dummyResult
;
751 hr
= ExecuteFunc( mpDispTempFile
, L
"writeBytes", aArgs
, 1, &dummyResult
);
752 if( SUCCEEDED( hr
) )
762 // the download failed, let StarOffice download
763 bFinishDownload
= TRUE
;
764 mpDispTempFile
= CComPtr
< IDispatch
>();
767 if ( bFinishDownload
)
769 // trigger the loading now
771 mbReadyForActivation
= TRUE
;
778 HRESULT
CSOActiveX::LoadURLToFrame( )
780 CComVariant aArgNames
[4] = { L
"ReadOnly", L
"ViewOnly", L
"AsTemplate", L
"InputStream" };
781 CComVariant aArgVals
[4];
782 unsigned int nCount
= 3; // the 4-th argument is used only if the stream can be retrieved
784 aArgVals
[0].vt
= VT_BOOL
; aArgVals
[0].boolVal
= mbViewOnly
? VARIANT_TRUE
: VARIANT_FALSE
;
785 aArgVals
[1].vt
= VT_BOOL
; aArgVals
[1].boolVal
= mbViewOnly
? VARIANT_TRUE
: VARIANT_FALSE
;
786 aArgVals
[2].vt
= VT_BOOL
; aArgVals
[2].boolVal
= VARIANT_FALSE
;
788 if ( mpDispTempFile
)
790 aArgVals
[3] = CComVariant( mpDispTempFile
);
794 HRESULT hr
= CallDispatchMethod( mCurFileUrl
, aArgNames
, aArgVals
, nCount
);
795 if( !SUCCEEDED( hr
) ) return hr
;
797 CComVariant
aBarName( L
"MenuBarVisible" );
799 aBarVis
.vt
= VT_BOOL
; aBarVis
.boolVal
= VARIANT_FALSE
;
800 hr
= CallDispatchMethod( L
"slot:6661", &aBarName
, &aBarVis
, 1 );
801 // does not work for some documents, but it is no error
802 // if( !SUCCEEDED( hr ) ) return hr;
804 // try to get the model and set the presetation specific property, the setting will fail for other document formats
805 CComPtr
<IDispatch
> pdispController
;
806 hr
= GetIDispByFunc( mpDispFrame
, L
"getController", NULL
, 0, pdispController
);
807 if ( SUCCEEDED( hr
) && pdispController
)
809 CComPtr
<IDispatch
> pdispModel
;
810 hr
= GetIDispByFunc( pdispController
, L
"getModel", NULL
, 0, pdispModel
);
811 if ( SUCCEEDED( hr
) && pdispModel
)
813 CComPtr
<IDispatch
> pdispPres
;
814 hr
= GetIDispByFunc( pdispModel
, L
"getPresentation", NULL
, 0, pdispPres
);
815 if ( SUCCEEDED( hr
) && pdispPres
)
817 // this is a presentation
818 // let the slide show be shown in the document window
819 OLECHAR
* pPropName
= L
"IsFullScreen";
820 CComVariant pPresProp
;
821 pPresProp
.vt
= VT_BOOL
; pPresProp
.boolVal
= VARIANT_FALSE
;
822 hr
= PutPropertiesToIDisp( pdispPres
, &pPropName
, &pPresProp
, 1 );
824 // start the slide show
825 if ( SUCCEEDED( hr
) )
827 CComVariant dummyResult
;
828 ExecuteFunc( pdispPres
, L
"Start", NULL
, 0, &dummyResult
);
834 // create dispatch interceptor
835 mpDispatchInterceptor
= new CComObject
< SODispatchInterceptor
>();
836 mpDispatchInterceptor
->AddRef();
837 mpDispatchInterceptor
->SetParent( this );
838 CComQIPtr
< IDispatch
, &IID_IDispatch
> pIDispDispInter( mpDispatchInterceptor
);
840 // register dispatch interceptor in the frame
841 CComVariant
aDispVariant( pIDispDispInter
);
842 CComVariant dummyResult
;
843 hr
= ExecuteFunc( mpDispFrame
,
844 L
"registerDispatchProviderInterceptor",
849 if( !SUCCEEDED( hr
) ) return hr
;
854 SOVersion
CSOActiveX::GetVersionConnected()
856 SOVersion bResult
= SO_NOT_DETECTED
;
859 // create ConfigurationProvider instance
860 CComPtr
<IDispatch
> pdispConfProv
;
861 CComVariant
aServiceName( L
"com.sun.star.configuration.ConfigurationProvider" );
862 HRESULT hr
= GetIDispByFunc( mpDispFactory
,
868 if( SUCCEEDED( hr
) && pdispConfProv
)
870 CComPtr
<IDispatch
> pdispConfAccess
;
872 SAFEARRAY
* pInitParams
= SafeArrayCreateVector( VT_VARIANT
, 0, 1 );
877 CComVariant
aConfPath( L
"org.openoffice.Setup" );
878 SafeArrayPutElement( pInitParams
, &ix
, &aConfPath
);
880 CComVariant aArgs
[2];
881 aArgs
[1] = CComVariant( L
"com.sun.star.configuration.ConfigurationAccess" );
882 aArgs
[0].vt
= VT_ARRAY
| VT_VARIANT
; aArgs
[0].parray
= pInitParams
;
884 hr
= GetIDispByFunc( pdispConfProv
,
885 L
"createInstanceWithArguments",
890 if( SUCCEEDED( hr
) && pdispConfAccess
)
892 CComVariant aOfficeName
;
894 CComVariant
aProductName( L
"Product/ooName" );
895 hr
= ExecuteFunc( pdispConfAccess
,
896 L
"getByHierarchicalName",
901 if( SUCCEEDED( hr
) && aOfficeName
.vt
== VT_BSTR
)
903 CComVariant aOfficeVersion
;
905 CComVariant
aProductVersion( L
"Product/ooSetupVersion" );
906 hr
= ExecuteFunc( pdispConfAccess
,
907 L
"getByHierarchicalName",
912 if( SUCCEEDED( hr
) && aOfficeVersion
.vt
== VT_BSTR
)
915 if( !strcmp( OLE2T( aOfficeName
.bstrVal
), "StarOffice" ) )
917 if( !strncmp( OLE2T( aOfficeVersion
.bstrVal
), "6.1", 3 ) )
919 else if( !strncmp( OLE2T( aOfficeVersion
.bstrVal
), "6.0", 3 ) )
921 else if( !strncmp( OLE2T( aOfficeVersion
.bstrVal
), "5.2", 3 ) )
924 bResult
= SO_UNKNOWN
;
928 if( !strncmp( OLE2T( aOfficeVersion
.bstrVal
), "1.1", 3 ) )
930 else if( !strncmp( OLE2T( aOfficeVersion
.bstrVal
), "1.0", 3 ) )
933 bResult
= OO_UNKNOWN
;
949 LockingGuard( BOOL
& bLocked
)
950 : mbLocked( bLocked
)
961 HRESULT
CSOActiveX::OnDrawAdvanced( ATL_DRAWINFO
& di
)
963 // This method is called only in main thread, no need to lock it
965 // Get read of reentrance problems
968 LockingGuard
aGuard( mbDrawLocked
);
970 if( m_spInPlaceSite
&& mCurFileUrl
&& mbReadyForActivation
)
973 HRESULT hr
= m_spInPlaceSite
->GetWindow( &hwnd
);
974 if( !SUCCEEDED( hr
) ) return hr
;
976 if( mParentWin
!= hwnd
|| !mOffWin
)
980 CComVariant dummyResult
;
981 CComVariant aPropVar
;
982 aPropVar
.vt
= VT_BOOL
; aPropVar
.boolVal
= VARIANT_FALSE
;
983 HRESULT hr
= ExecuteFunc( mpDispFrame
, L
"close", &aPropVar
, 1, &dummyResult
);
985 mpDispFrame
= CComPtr
<IDispatch
>();
989 mOffWin
= CreateWindow(
990 STAROFFICE_WINDOWCLASS
,
992 WS_CHILD
| WS_CLIPCHILDREN
| WS_BORDER
,
995 di
.prcBounds
->right
- di
.prcBounds
->left
,
996 di
.prcBounds
->bottom
- di
.prcBounds
->top
,
1002 ::ShowWindow( mOffWin
, SW_SHOW
);
1007 ::GetWindowRect( mOffWin
, &aRect
);
1009 if( aRect
.left
!= di
.prcBounds
->left
|| aRect
.top
!= di
.prcBounds
->top
1010 || aRect
.right
!= di
.prcBounds
->right
|| aRect
.bottom
!= di
.prcBounds
->bottom
)
1012 // on this state the office window should exist already
1013 ::SetWindowPos( mOffWin
,
1017 di
.prcBounds
->right
- di
.prcBounds
->left
,
1018 di
.prcBounds
->bottom
- di
.prcBounds
->top
,
1021 CComVariant aPosArgs
[5];
1022 aPosArgs
[4] = CComVariant( 0 );
1023 aPosArgs
[3] = CComVariant( 0 );
1024 aPosArgs
[2] = CComVariant( int(di
.prcBounds
->right
- di
.prcBounds
->left
) );
1025 aPosArgs
[1] = CComVariant( int(di
.prcBounds
->bottom
- di
.prcBounds
->top
) );
1026 aPosArgs
[0] = CComVariant( 12 );
1027 CComVariant dummyResult
;
1028 hr
= ExecuteFunc( mpDispWin
, L
"setPosSize", aPosArgs
, 5, &dummyResult
);
1029 if( !SUCCEEDED( hr
) ) return hr
;
1035 OutputError_Impl( mOffWin
, CS_E_INVALID_VERSION
);
1041 hr
= CreateFrameOldWay( mOffWin
,
1042 di
.prcBounds
->right
- di
.prcBounds
->left
,
1043 di
.prcBounds
->bottom
- di
.prcBounds
->top
);
1045 if( !SUCCEEDED( hr
) )
1047 // if the frame can not be opened do not try any more
1048 mbReadyForActivation
= FALSE
;
1049 OutputError_Impl( mOffWin
, STG_E_ABNORMALAPIEXIT
);
1056 hr
= LoadURLToFrame();
1059 if( !SUCCEEDED( hr
) )
1061 // if the document can not be opened do not try any more
1062 mbReadyForActivation
= FALSE
;
1064 OutputError_Impl( mOffWin
, STG_E_ABNORMALAPIEXIT
);
1072 // activate the fallback
1073 CComControl
<CSOActiveX
>::OnDrawAdvanced( di
);
1079 HRESULT
CSOActiveX::OnDraw( ATL_DRAWINFO
& di
)
1081 // fallback that is activated by the parent class
1083 FillRect( di
.hdcDraw
, (RECT
*)di
.prcBounds
, (HBRUSH
)COLOR_BACKGROUND
);
1088 STDMETHODIMP
CSOActiveX::SetClientSite( IOleClientSite
* aClientSite
)
1090 HRESULT hr
= IOleObjectImpl
<CSOActiveX
>::SetClientSite( aClientSite
);
1094 //ATLASSERT( mWebBrowser2 );
1096 AtlUnadvise( mWebBrowser2
, DIID_DWebBrowserEvents2
, mCookie
);
1100 CComPtr
<IOleContainer
> aContainer
;
1101 m_spClientSite
->GetContainer( &aContainer
);
1102 // ATLASSERT( aContainer );
1104 if( SUCCEEDED( hr
) && aContainer
)
1106 CComQIPtr
<IServiceProvider
, &IID_IServiceProvider
> aServiceProvider( aContainer
);
1107 //ATLASSERT( aServiceProvider );
1109 if( aServiceProvider
)
1111 aServiceProvider
->QueryService( SID_SInternetExplorer
,
1113 (void**)&mWebBrowser2
);
1114 // ATLASSERT( mWebBrowser2 );
1116 AtlAdvise( mWebBrowser2
, GetUnknown(), DIID_DWebBrowserEvents2
, &mCookie
);
1123 STDMETHODIMP
CSOActiveX::Invoke(DISPID dispidMember
,
1127 DISPPARAMS
* pDispParams
,
1128 VARIANT
* pvarResult
,
1129 EXCEPINFO
* pExcepInfo
,
1132 if (riid
!= IID_NULL
)
1133 return DISP_E_UNKNOWNINTERFACE
;
1136 return DISP_E_PARAMNOTOPTIONAL
;
1138 if ( dispidMember
== DISPID_ONQUIT
)
1141 IDispatchImpl
<ISOActiveX
, &IID_ISOActiveX
,
1142 &LIBID_SO_ACTIVEXLib
>::Invoke(
1143 dispidMember
, riid
, lcid
, wFlags
, pDispParams
,
1144 pvarResult
, pExcepInfo
, puArgErr
);
1149 HRESULT
CSOActiveX::GetURL( const OLECHAR
* url
,
1150 const OLECHAR
* target
)
1152 CComVariant aEmpty1
, aEmpty2
, aEmpty3
;
1153 CComVariant
aUrl( url
);
1154 CComVariant aTarget
;
1156 aTarget
= CComVariant( target
);
1158 return mWebBrowser2
->Navigate2( &aUrl
,
1168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */