1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * The Contents of this file are made available subject to the terms of 4*cdf0e10cSrcweir * the BSD license. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * All rights reserved. 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * Redistribution and use in source and binary forms, with or without 10*cdf0e10cSrcweir * modification, are permitted provided that the following conditions 11*cdf0e10cSrcweir * are met: 12*cdf0e10cSrcweir * 1. Redistributions of source code must retain the above copyright 13*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer. 14*cdf0e10cSrcweir * 2. Redistributions in binary form must reproduce the above copyright 15*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer in the 16*cdf0e10cSrcweir * documentation and/or other materials provided with the distribution. 17*cdf0e10cSrcweir * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18*cdf0e10cSrcweir * contributors may be used to endorse or promote products derived 19*cdf0e10cSrcweir * from this software without specific prior written permission. 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*cdf0e10cSrcweir * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*cdf0e10cSrcweir * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*cdf0e10cSrcweir * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*cdf0e10cSrcweir * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*cdf0e10cSrcweir * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*cdf0e10cSrcweir * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*cdf0e10cSrcweir * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29*cdf0e10cSrcweir * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30*cdf0e10cSrcweir * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31*cdf0e10cSrcweir * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*cdf0e10cSrcweir * 33*cdf0e10cSrcweir *************************************************************************/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir // SOActiveX.cpp : Implementation of CSOActiveX 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include "stdafx2.h" 38*cdf0e10cSrcweir #include "so_activex.h" 39*cdf0e10cSrcweir #include "SOActiveX.h" 40*cdf0e10cSrcweir #include "SOComWindowPeer.h" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #define STAROFFICE_WINDOWCLASS "SOParentWindow" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #define BARS_NUMBER 3 45*cdf0e10cSrcweir #define BARS_TO_SHOW 2 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir OLECHAR* pSlotUrl[BARS_NUMBER] = 48*cdf0e10cSrcweir {L"slot:5910" // SID_TOGGLEFUNCTIONBAR 49*cdf0e10cSrcweir ,L"slot:5920" // SID_TOGGLESTATUSBAR 50*cdf0e10cSrcweir ,L"slot:6661" // SID_TOGGLE_MENUBAR 51*cdf0e10cSrcweir // ,L"slot:10603" // SID_HYPERLINK_INSERT 52*cdf0e10cSrcweir }; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir OLECHAR* pSlotName[BARS_NUMBER] = 55*cdf0e10cSrcweir {L"FunctionBarVisible" // SID_TOGGLEFUNCTIONBAR 56*cdf0e10cSrcweir ,L"StatusBarVisible" // SID_TOGGLESTATUSBAR 57*cdf0e10cSrcweir ,L"MenuBarVisible" // SID_TOGGLE_MENUBAR 58*cdf0e10cSrcweir // ,L"InsertHyperlink" // SID_HYPERLINK_INSERT 59*cdf0e10cSrcweir }; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir HRESULT ExecuteFunc( IDispatch* idispUnoObject, 66*cdf0e10cSrcweir OLECHAR* sFuncName, 67*cdf0e10cSrcweir CComVariant* params, 68*cdf0e10cSrcweir unsigned int count, 69*cdf0e10cSrcweir CComVariant* pResult ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir if( !idispUnoObject ) 72*cdf0e10cSrcweir return E_FAIL; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir DISPID id; 75*cdf0e10cSrcweir HRESULT hr = idispUnoObject->GetIDsOfNames( IID_NULL, &sFuncName, 1, LOCALE_USER_DEFAULT, &id); 76*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir DISPPARAMS dispparams= { params, 0, count, 0}; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir // DEBUG 81*cdf0e10cSrcweir EXCEPINFO myInfo; 82*cdf0e10cSrcweir return idispUnoObject->Invoke( id, IID_NULL,LOCALE_USER_DEFAULT, DISPATCH_METHOD, 83*cdf0e10cSrcweir &dispparams, pResult, &myInfo, 0); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir HRESULT GetIDispByFunc( IDispatch* idispUnoObject, 87*cdf0e10cSrcweir OLECHAR* sFuncName, 88*cdf0e10cSrcweir CComVariant* params, 89*cdf0e10cSrcweir unsigned int count, 90*cdf0e10cSrcweir CComPtr<IDispatch>& pdispResult ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir if( !idispUnoObject ) 93*cdf0e10cSrcweir return E_FAIL; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir CComVariant result; 96*cdf0e10cSrcweir HRESULT hr = ExecuteFunc( idispUnoObject, sFuncName, params, count, &result ); 97*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir if( result.vt != VT_DISPATCH || result.pdispVal == NULL ) 100*cdf0e10cSrcweir return hr; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir pdispResult = CComPtr<IDispatch>( result.pdispVal ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir return S_OK; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir HRESULT PutPropertiesToIDisp( IDispatch* pdispObject, 108*cdf0e10cSrcweir OLECHAR** sMemberNames, 109*cdf0e10cSrcweir CComVariant* pVariant, 110*cdf0e10cSrcweir unsigned int count ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir for( unsigned int ind = 0; ind < count; ind++ ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir DISPID id; 115*cdf0e10cSrcweir HRESULT hr = pdispObject->GetIDsOfNames( IID_NULL, &sMemberNames[ind], 1, LOCALE_USER_DEFAULT, &id ); 116*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir hr = CComDispatchDriver::PutProperty( pdispObject, id, &pVariant[ind] ); 119*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir return S_OK; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 126*cdf0e10cSrcweir // CSOActiveX 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir CSOActiveX::CSOActiveX() 129*cdf0e10cSrcweir : mCookie(0) 130*cdf0e10cSrcweir , mCurFileUrl( L"private:factory/swriter" ) 131*cdf0e10cSrcweir , mbLoad( FALSE ) 132*cdf0e10cSrcweir , mParentWin( NULL ) 133*cdf0e10cSrcweir , mOffWin( NULL ) 134*cdf0e10cSrcweir , mbViewOnly( FALSE ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir CLSID clsFactory = {0x82154420,0x0FBF,0x11d4,{0x83, 0x13,0x00,0x50,0x04,0x52,0x6A,0xB4}}; 137*cdf0e10cSrcweir HRESULT hr = CoCreateInstance( clsFactory, NULL, CLSCTX_ALL, __uuidof(IDispatch), (void**)&mpDispFactory); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir mPWinClass.style = CS_HREDRAW|CS_VREDRAW; 140*cdf0e10cSrcweir mPWinClass.lpfnWndProc = ::DefWindowProc; 141*cdf0e10cSrcweir mPWinClass.cbClsExtra = 0; 142*cdf0e10cSrcweir mPWinClass.cbWndExtra = 0; 143*cdf0e10cSrcweir mPWinClass.hInstance = (HINSTANCE) GetModuleHandle(NULL); //myInstance; 144*cdf0e10cSrcweir mPWinClass.hIcon = NULL; 145*cdf0e10cSrcweir mPWinClass.hCursor = NULL; 146*cdf0e10cSrcweir mPWinClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND; 147*cdf0e10cSrcweir mPWinClass.lpszMenuName = NULL; 148*cdf0e10cSrcweir mPWinClass.lpszClassName = STAROFFICE_WINDOWCLASS; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir RegisterClass(&mPWinClass); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir CSOActiveX::~CSOActiveX() 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir Cleanup(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir HRESULT CSOActiveX::Cleanup() 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir if( mpDispFrame && mbViewOnly ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir ShowSomeBars(); 164*cdf0e10cSrcweir mbViewOnly = FALSE; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir if( mpDispFrame ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir // mpDispFrame->dispose(); 170*cdf0e10cSrcweir CComVariant dummyResult; 171*cdf0e10cSrcweir ExecuteFunc( mpDispFrame, L"dispose", NULL, 0, &dummyResult ); 172*cdf0e10cSrcweir mpDispFrame = CComPtr< IDispatch >(); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir if( ::IsWindow( mOffWin ) ) 176*cdf0e10cSrcweir ::DestroyWindow( mOffWin ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir return S_OK; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir STDMETHODIMP CSOActiveX::InitNew () 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir mbLoad = TRUE; 185*cdf0e10cSrcweir return S_OK; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir STDMETHODIMP CSOActiveX::Load ( LPSTREAM pStm ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir mbLoad = TRUE; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir // may be later? 193*cdf0e10cSrcweir // for now just ignore 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir return S_OK; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir STDMETHODIMP CSOActiveX::Load( LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir IPropertyBag2* pPropBag2; 201*cdf0e10cSrcweir HRESULT hr = pPropBag->QueryInterface( IID_IPropertyBag2, (void**)&pPropBag2 ); 202*cdf0e10cSrcweir ATLASSERT( hr >= 0 ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) 205*cdf0e10cSrcweir return hr; 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir unsigned long aNum; 208*cdf0e10cSrcweir hr = pPropBag2->CountProperties( &aNum ); 209*cdf0e10cSrcweir ATLASSERT( hr >= 0 ); 210*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) 211*cdf0e10cSrcweir return hr; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir PROPBAG2* aPropNames = new PROPBAG2[aNum]; 214*cdf0e10cSrcweir unsigned long aReaded; 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir hr = pPropBag2->GetPropertyInfo( 0, 217*cdf0e10cSrcweir aNum, 218*cdf0e10cSrcweir aPropNames, 219*cdf0e10cSrcweir &aReaded ); 220*cdf0e10cSrcweir ATLASSERT( hr >= 0 ); 221*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir delete[] aPropNames; 224*cdf0e10cSrcweir return hr; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir CComVariant* aVal = new CComVariant[aNum]; 228*cdf0e10cSrcweir HRESULT* hvs = new HRESULT[aNum]; 229*cdf0e10cSrcweir hr = pPropBag2->Read( aNum, 230*cdf0e10cSrcweir aPropNames, 231*cdf0e10cSrcweir NULL, 232*cdf0e10cSrcweir aVal, 233*cdf0e10cSrcweir hvs ); 234*cdf0e10cSrcweir ATLASSERT( hr >= 0 ); 235*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir delete[] hvs; 238*cdf0e10cSrcweir delete[] aVal; 239*cdf0e10cSrcweir delete[] aPropNames; 240*cdf0e10cSrcweir return hr; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir USES_CONVERSION; 244*cdf0e10cSrcweir for( unsigned long ind = 0; ind < aNum; ind++ ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir // all information from the 'object' tag is in strings 247*cdf0e10cSrcweir if( aVal[ind].vt == VT_BSTR && !strcmp( OLE2T( aPropNames[ind].pstrName ), "src" ) ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir mCurFileUrl = wcsdup( aVal[ind].bstrVal ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir else if( aVal[ind].vt == VT_BSTR 252*cdf0e10cSrcweir && !strcmp( OLE2T( aPropNames[ind].pstrName ), "readonly" ) ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir if( !strcmp( OLE2T( aVal[ind].bstrVal ), "true" ) ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir mbViewOnly = TRUE; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir else 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir // the default value 261*cdf0e10cSrcweir mbViewOnly = FALSE; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir delete[] hvs; 267*cdf0e10cSrcweir delete[] aVal; 268*cdf0e10cSrcweir delete[] aPropNames; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir if( !mpDispFactory ) 271*cdf0e10cSrcweir return hr; 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir mbLoad = TRUE; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir Invalidate(); 276*cdf0e10cSrcweir UpdateWindow(); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir return hr; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir HRESULT CSOActiveX::GetUnoStruct( OLECHAR* sStructName, CComPtr<IDispatch>& pdispResult ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir return GetIDispByFunc( mpDispFactory, L"Bridge_GetStruct", &CComVariant( sStructName ), 1, pdispResult ); 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir HRESULT CSOActiveX::GetUrlStruct( OLECHAR* sUrl, CComPtr<IDispatch>& pdispUrl ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir HRESULT hr = GetUnoStruct( L"com.sun.star.util.URL", pdispUrl ); 289*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir OLECHAR* sURLMemberName = L"Complete"; 292*cdf0e10cSrcweir DISPID nURLID; 293*cdf0e10cSrcweir hr = pdispUrl->GetIDsOfNames( IID_NULL, &sURLMemberName, 1, LOCALE_USER_DEFAULT, &nURLID ); 294*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 295*cdf0e10cSrcweir hr = CComDispatchDriver::PutProperty( pdispUrl, nURLID, &CComVariant( sUrl ) ); 296*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir CComPtr<IDispatch> pdispTransformer; 299*cdf0e10cSrcweir hr = GetIDispByFunc( mpDispFactory, 300*cdf0e10cSrcweir L"createInstance", 301*cdf0e10cSrcweir &CComVariant( L"com.sun.star.util.URLTransformer" ), 302*cdf0e10cSrcweir 1, 303*cdf0e10cSrcweir pdispTransformer ); 304*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir CComVariant dummyResult; 307*cdf0e10cSrcweir CComVariant aInOutParam; 308*cdf0e10cSrcweir aInOutParam.ppdispVal = &pdispUrl; 309*cdf0e10cSrcweir aInOutParam.vt = VT_DISPATCH | VT_BYREF; 310*cdf0e10cSrcweir hr = ExecuteFunc( pdispTransformer, L"parseStrict", &aInOutParam, 1, &dummyResult ); 311*cdf0e10cSrcweir if( !SUCCEEDED( hr ) || dummyResult.vt != VT_BOOL || !dummyResult.boolVal ) return hr; 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir return S_OK; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir HRESULT CSOActiveX::CreateFrameOldWay( HWND hwnd, int width, int height ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir if( !mpDispFactory ) 320*cdf0e10cSrcweir return E_FAIL; 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // create window handle holder 323*cdf0e10cSrcweir CComPtr< CComObject< SOComWindowPeer > > pPeerToSend = new CComObject<SOComWindowPeer>( hwnd ); 324*cdf0e10cSrcweir pPeerToSend->SetHWNDInternally( hwnd ); 325*cdf0e10cSrcweir CComQIPtr< IDispatch, &IID_IDispatch > pIDispToSend( pPeerToSend ); 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir // create rectangle structure 328*cdf0e10cSrcweir CComPtr<IDispatch> pdispRectangle; 329*cdf0e10cSrcweir HRESULT hr = GetUnoStruct( L"com.sun.star.awt.Rectangle", pdispRectangle ); 330*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir OLECHAR* sRectMemberNames[4] = { L"X", 333*cdf0e10cSrcweir L"Y", 334*cdf0e10cSrcweir L"Width", 335*cdf0e10cSrcweir L"Height" }; 336*cdf0e10cSrcweir CComVariant pRectVariant[4]; 337*cdf0e10cSrcweir pRectVariant[0] = pRectVariant[1] = pRectVariant[2] = pRectVariant[3] = CComVariant( 0 ); 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir hr = PutPropertiesToIDisp( pdispRectangle, sRectMemberNames, pRectVariant, 4 ); 340*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir // create WindowDescriptor structure 343*cdf0e10cSrcweir CComPtr<IDispatch> pdispWinDescr; 344*cdf0e10cSrcweir hr = GetUnoStruct( L"com.sun.star.awt.WindowDescriptor", pdispWinDescr ); 345*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir // fill in descriptor with info 348*cdf0e10cSrcweir OLECHAR* sDescriptorMemberNames[6] = { L"Type", 349*cdf0e10cSrcweir L"WindowServiceName", 350*cdf0e10cSrcweir L"ParentIndex", 351*cdf0e10cSrcweir L"Parent", 352*cdf0e10cSrcweir L"Bounds", 353*cdf0e10cSrcweir L"WindowAttributes" }; 354*cdf0e10cSrcweir CComVariant pDescriptorVar[6]; 355*cdf0e10cSrcweir pDescriptorVar[0] = CComVariant( 0 ); 356*cdf0e10cSrcweir pDescriptorVar[1] = CComVariant( L"workwindow" ); 357*cdf0e10cSrcweir pDescriptorVar[2] = CComVariant( 1 ); 358*cdf0e10cSrcweir pDescriptorVar[3] = CComVariant( pIDispToSend ); 359*cdf0e10cSrcweir pDescriptorVar[4] = CComVariant( pdispRectangle ); 360*cdf0e10cSrcweir pDescriptorVar[5] = CComVariant( 33 ); 361*cdf0e10cSrcweir hr = PutPropertiesToIDisp( pdispWinDescr, sDescriptorMemberNames, pDescriptorVar, 6 ); 362*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir // create XToolkit instance 365*cdf0e10cSrcweir CComPtr<IDispatch> pdispToolkit; 366*cdf0e10cSrcweir hr = GetIDispByFunc( mpDispFactory, L"createInstance", &CComVariant( L"com.sun.star.awt.Toolkit" ), 1, pdispToolkit ); 367*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir // create window with toolkit 370*cdf0e10cSrcweir hr = GetIDispByFunc( pdispToolkit, L"createWindow", &CComVariant( pdispWinDescr ), 1, mpDispWin ); 371*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir // create frame 374*cdf0e10cSrcweir hr = GetIDispByFunc( mpDispFactory, L"createInstance", &CComVariant( L"com.sun.star.frame.Task" ), 1, mpDispFrame ); 375*cdf0e10cSrcweir if( !SUCCEEDED( hr ) || !mpDispFrame ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir // the interface com.sun.star.frame.Task is removed in 6.1 378*cdf0e10cSrcweir // but the interface com.sun.star.frame.Frame has some bugs in 6.0 379*cdf0e10cSrcweir hr = GetIDispByFunc( mpDispFactory, L"createInstance", &CComVariant( L"com.sun.star.frame.Frame" ), 1, mpDispFrame ); 380*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir // initialize frame 384*cdf0e10cSrcweir CComVariant dummyResult; 385*cdf0e10cSrcweir hr = ExecuteFunc( mpDispFrame, L"initialize", &CComVariant( mpDispWin ), 1, &dummyResult ); 386*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir // create desktop 389*cdf0e10cSrcweir CComPtr<IDispatch> pdispDesktop; 390*cdf0e10cSrcweir hr = GetIDispByFunc( mpDispFactory, L"createInstance", &CComVariant( L"com.sun.star.frame.Desktop" ), 1, pdispDesktop ); 391*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir // create tree of frames 394*cdf0e10cSrcweir CComPtr<IDispatch> pdispChildren; 395*cdf0e10cSrcweir hr = GetIDispByFunc( pdispDesktop, L"getFrames", NULL, 0, pdispChildren ); 396*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir // insert new frame into desctop hierarchy 399*cdf0e10cSrcweir hr = ExecuteFunc( pdispChildren, L"append", &CComVariant( mpDispFrame ), 1, &dummyResult ); 400*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir // initialize window 403*cdf0e10cSrcweir hr = ExecuteFunc( mpDispWin, L"setBackground", &CComVariant( (long)0xFFFFFFFF ), 1, &dummyResult ); 404*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir hr = ExecuteFunc( mpDispWin, L"setVisible", &CComVariant( TRUE ), 1, &dummyResult ); 407*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir CComVariant aPosArgs[5]; 410*cdf0e10cSrcweir aPosArgs[4] = CComVariant( 0 ); 411*cdf0e10cSrcweir aPosArgs[3] = CComVariant( 0 ); 412*cdf0e10cSrcweir aPosArgs[2] = CComVariant( width ); 413*cdf0e10cSrcweir aPosArgs[1] = CComVariant( height ); 414*cdf0e10cSrcweir aPosArgs[0] = CComVariant( 12 ); 415*cdf0e10cSrcweir hr = ExecuteFunc( mpDispWin, L"setPosSize", aPosArgs, 5, &dummyResult ); 416*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir return S_OK; 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir HRESULT CSOActiveX::CallDispatch1PBool( OLECHAR* sUrl, OLECHAR* sArgName, BOOL sArgVal ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir CComPtr<IDispatch> pdispURL; 425*cdf0e10cSrcweir HRESULT hr = GetUrlStruct( sUrl, pdispURL ); 426*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir CComPtr<IDispatch> pdispXDispatch; 429*cdf0e10cSrcweir CComVariant aArgs[3]; 430*cdf0e10cSrcweir aArgs[2] = CComVariant( pdispURL ); 431*cdf0e10cSrcweir aArgs[1] = CComVariant( L"" ); 432*cdf0e10cSrcweir aArgs[0] = CComVariant( (int)0 ); 433*cdf0e10cSrcweir hr = GetIDispByFunc( mpDispFrame, 434*cdf0e10cSrcweir L"queryDispatch", 435*cdf0e10cSrcweir aArgs, 436*cdf0e10cSrcweir 3, 437*cdf0e10cSrcweir pdispXDispatch ); 438*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir SAFEARRAY FAR* pPropVals = SafeArrayCreateVector( VT_DISPATCH, 0, 1 ); 441*cdf0e10cSrcweir long ix = 0; 442*cdf0e10cSrcweir CComPtr<IDispatch> pdispPropVal; 443*cdf0e10cSrcweir hr = GetUnoStruct( L"com.sun.star.beans.PropertyValue", pdispPropVal ); 444*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir OLECHAR* sPropMemberNames[2] = { L"Name", L"Value" }; 447*cdf0e10cSrcweir CComVariant pPropVar[2]; 448*cdf0e10cSrcweir pPropVar[0] = CComVariant( sArgName ); 449*cdf0e10cSrcweir pPropVar[1] = CComVariant(); pPropVar[1].vt = VT_BOOL; pPropVar[1].boolVal = sArgVal ? VARIANT_TRUE : VARIANT_FALSE ; 450*cdf0e10cSrcweir hr = PutPropertiesToIDisp( pdispPropVal, sPropMemberNames, pPropVar, 2 ); 451*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir SafeArrayPutElement( pPropVals, &ix, pdispPropVal ); 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir CComVariant aDispArgs[2]; 456*cdf0e10cSrcweir aDispArgs[1] = CComVariant( pdispURL ); 457*cdf0e10cSrcweir // aDispArgs[0] = CComVariant( pPropVals ); such constructor is not defined ??! 458*cdf0e10cSrcweir aDispArgs[0] = CComVariant(); aDispArgs[0].vt = VT_ARRAY | VT_DISPATCH; aDispArgs[0].parray = pPropVals; 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir CComVariant dummyResult; 461*cdf0e10cSrcweir hr = ExecuteFunc( pdispXDispatch, L"dispatch", aDispArgs, 2, &dummyResult ); 462*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir return S_OK; 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir HRESULT CSOActiveX::ShowSomeBars() 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir // show FunctionBar and StatusBar 470*cdf0e10cSrcweir for( int ind = 0; ind < BARS_TO_SHOW; ind ++ ) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir HRESULT hr = CallDispatch1PBool( pSlotUrl[ind], pSlotName[ind], TRUE ); 473*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir return S_OK; 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir HRESULT CSOActiveX::HideAllBars() 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir for( int ind = 0; ind < BARS_NUMBER; ind ++ ) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir HRESULT hr = CallDispatch1PBool( pSlotUrl[ind], pSlotName[ind], FALSE ); 484*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir return S_OK; 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir HRESULT CSOActiveX::LoadURLToFrame( ) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir HRESULT hr = CallDispatch1PBool( mCurFileUrl, L"ReadOnly", mbViewOnly ); 493*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir if( mbViewOnly ) 496*cdf0e10cSrcweir HideAllBars(); 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir return S_OK; 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir HRESULT CSOActiveX::OnDrawAdvanced( ATL_DRAWINFO& di ) 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir if( m_spInPlaceSite && mCurFileUrl ) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir HWND hwnd; 506*cdf0e10cSrcweir HRESULT hr = m_spInPlaceSite->GetWindow( &hwnd ); 507*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir if( mParentWin != hwnd || !mOffWin ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir if( mpDispFrame ) 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir CComVariant dummyResult; 514*cdf0e10cSrcweir ExecuteFunc( mpDispFrame, L"dispose", NULL, 0, &dummyResult ); 515*cdf0e10cSrcweir mpDispFrame = CComPtr<IDispatch>(); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir mParentWin = hwnd; 519*cdf0e10cSrcweir mOffWin = CreateWindow( 520*cdf0e10cSrcweir STAROFFICE_WINDOWCLASS, 521*cdf0e10cSrcweir "OfficeContainer", 522*cdf0e10cSrcweir WS_CHILD | WS_CLIPCHILDREN | WS_BORDER, 523*cdf0e10cSrcweir di.prcBounds->left, 524*cdf0e10cSrcweir di.prcBounds->top, 525*cdf0e10cSrcweir di.prcBounds->right - di.prcBounds->left, 526*cdf0e10cSrcweir di.prcBounds->bottom - di.prcBounds->top, 527*cdf0e10cSrcweir mParentWin, 528*cdf0e10cSrcweir NULL, 529*cdf0e10cSrcweir NULL, 530*cdf0e10cSrcweir NULL ); 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir ::ShowWindow( mOffWin, SW_SHOW ); 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir else 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir RECT aRect; 537*cdf0e10cSrcweir ::GetWindowRect( mOffWin, &aRect ); 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir if( aRect.left != di.prcBounds->left || aRect.top != di.prcBounds->top 540*cdf0e10cSrcweir || aRect.right != di.prcBounds->right || aRect.bottom != di.prcBounds->bottom ) 541*cdf0e10cSrcweir { 542*cdf0e10cSrcweir // on this state the office window should exist already 543*cdf0e10cSrcweir ::SetWindowPos( mOffWin, 544*cdf0e10cSrcweir HWND_TOP, 545*cdf0e10cSrcweir di.prcBounds->left, 546*cdf0e10cSrcweir di.prcBounds->top, 547*cdf0e10cSrcweir di.prcBounds->right - di.prcBounds->left, 548*cdf0e10cSrcweir di.prcBounds->bottom - di.prcBounds->top, 549*cdf0e10cSrcweir SWP_NOZORDER ); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir CComVariant aPosArgs[5]; 552*cdf0e10cSrcweir aPosArgs[4] = CComVariant( 0 ); 553*cdf0e10cSrcweir aPosArgs[3] = CComVariant( 0 ); 554*cdf0e10cSrcweir aPosArgs[2] = CComVariant( int(di.prcBounds->right - di.prcBounds->left) ); 555*cdf0e10cSrcweir aPosArgs[1] = CComVariant( int(di.prcBounds->bottom - di.prcBounds->top) ); 556*cdf0e10cSrcweir aPosArgs[0] = CComVariant( 12 ); 557*cdf0e10cSrcweir CComVariant dummyResult; 558*cdf0e10cSrcweir hr = ExecuteFunc( mpDispWin, L"setPosSize", aPosArgs, 5, &dummyResult ); 559*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir if( ! mpDispFrame ) 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir hr = CreateFrameOldWay( mOffWin, 566*cdf0e10cSrcweir di.prcBounds->right - di.prcBounds->left, 567*cdf0e10cSrcweir di.prcBounds->bottom - di.prcBounds->top ); 568*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir if( mbLoad ) 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir hr = LoadURLToFrame(); 574*cdf0e10cSrcweir if( !SUCCEEDED( hr ) ) return hr; 575*cdf0e10cSrcweir mbLoad = FALSE; 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir return S_OK; 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir STDMETHODIMP CSOActiveX::SetClientSite( IOleClientSite* aClientSite ) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir HRESULT hr = IOleObjectImpl<CSOActiveX>::SetClientSite( aClientSite ); 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir if( !aClientSite ) 588*cdf0e10cSrcweir { 589*cdf0e10cSrcweir ATLASSERT( mWebBrowser2 ); 590*cdf0e10cSrcweir if( mWebBrowser2 ) 591*cdf0e10cSrcweir AtlUnadvise( mWebBrowser2, DIID_DWebBrowserEvents2, mCookie ); 592*cdf0e10cSrcweir return hr; 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir CComPtr<IOleContainer> aContainer; 596*cdf0e10cSrcweir m_spClientSite->GetContainer( &aContainer ); 597*cdf0e10cSrcweir ATLASSERT( aContainer ); 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir if( SUCCEEDED( hr ) && aContainer ) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir CComQIPtr<IServiceProvider, &IID_IServiceProvider> aServiceProvider( aContainer ); 602*cdf0e10cSrcweir ATLASSERT( aServiceProvider ); 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir if( aServiceProvider ) 605*cdf0e10cSrcweir { 606*cdf0e10cSrcweir aServiceProvider->QueryService( SID_SInternetExplorer, 607*cdf0e10cSrcweir IID_IWebBrowser, 608*cdf0e10cSrcweir (void**)&mWebBrowser2 ); 609*cdf0e10cSrcweir ATLASSERT( mWebBrowser2 ); 610*cdf0e10cSrcweir if( mWebBrowser2 ) 611*cdf0e10cSrcweir AtlAdvise( mWebBrowser2, GetUnknown(), DIID_DWebBrowserEvents2, &mCookie ); 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir return hr; 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir STDMETHODIMP CSOActiveX::Invoke(DISPID dispidMember, 619*cdf0e10cSrcweir REFIID riid, 620*cdf0e10cSrcweir LCID lcid, 621*cdf0e10cSrcweir WORD wFlags, 622*cdf0e10cSrcweir DISPPARAMS* pDispParams, 623*cdf0e10cSrcweir VARIANT* pvarResult, 624*cdf0e10cSrcweir EXCEPINFO* pExcepInfo, 625*cdf0e10cSrcweir UINT* puArgErr) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir if (riid != IID_NULL) 628*cdf0e10cSrcweir return DISP_E_UNKNOWNINTERFACE; 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir if (!pDispParams) 631*cdf0e10cSrcweir return DISP_E_PARAMNOTOPTIONAL; 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir if ( dispidMember == DISPID_ONQUIT ) 634*cdf0e10cSrcweir Cleanup(); 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir IDispatchImpl<ISOActiveX, &IID_ISOActiveX, 637*cdf0e10cSrcweir &LIBID_SO_ACTIVEXLib>::Invoke( 638*cdf0e10cSrcweir dispidMember, riid, lcid, wFlags, pDispParams, 639*cdf0e10cSrcweir pvarResult, pExcepInfo, puArgErr); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir return S_OK; 642*cdf0e10cSrcweir } 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir // --------------------------------------------------------------------------- 645*cdf0e10cSrcweir 646