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