1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <oleembobj.hxx> 32*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedVerbs.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/embed/EntryInitModes.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedUpdateModes.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/embed/NeedsRunningStateException.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/embed/StateChangeInProgressException.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedObjectCreator.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/frame/XLoadable.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/document/XStorageBasedDocument.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/system/XSystemShellExecute.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <rtl/logfile.hxx> 56*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h> 57*cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx> 58*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir #include <targetstatecontrol.hxx> 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir #include <olecomponent.hxx> 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #include "ownview.hxx" 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir using namespace ::com::sun::star; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir #ifdef WNT 70*cdf0e10cSrcweir //---------------------------------------------- 71*cdf0e10cSrcweir void OleEmbeddedObject::SwitchComponentToRunningState_Impl() 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir if ( m_pOleComponent ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir try 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir m_pOleComponent->RunObject(); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir catch( embed::UnreachableStateException& ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir GetRidOfComponent(); 82*cdf0e10cSrcweir throw; 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir catch( embed::WrongStateException& ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir GetRidOfComponent(); 87*cdf0e10cSrcweir throw; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir else 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir throw embed::UnreachableStateException(); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir //---------------------------------------------- 97*cdf0e10cSrcweir uno::Sequence< sal_Int32 > OleEmbeddedObject::GetReachableStatesList_Impl( 98*cdf0e10cSrcweir const uno::Sequence< embed::VerbDescriptor >& aVerbList ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir uno::Sequence< sal_Int32 > aStates(2); 101*cdf0e10cSrcweir aStates[0] = embed::EmbedStates::LOADED; 102*cdf0e10cSrcweir aStates[1] = embed::EmbedStates::RUNNING; 103*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aVerbList.getLength(); nInd++ ) 104*cdf0e10cSrcweir if ( aVerbList[nInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_OPEN ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir aStates.realloc(3); 107*cdf0e10cSrcweir aStates[2] = embed::EmbedStates::ACTIVE; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir return aStates; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir //---------------------------------------------- 114*cdf0e10cSrcweir uno::Sequence< sal_Int32 > OleEmbeddedObject::GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir OSL_ENSURE( m_nObjectState != embed::EmbedStates::LOADED, "Loaded object is switched to running state without verbs using!" ); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // actually there will be only one verb 119*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::RUNNING && nNewState == embed::EmbedStates::ACTIVE ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir uno::Sequence< sal_Int32 > aVerbs( 1 ); 122*cdf0e10cSrcweir aVerbs[0] = embed::EmbedVerbs::MS_OLEVERB_OPEN; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir return uno::Sequence< sal_Int32 >(); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir #endif 128*cdf0e10cSrcweir //---------------------------------------------- 129*cdf0e10cSrcweir void OleEmbeddedObject::MoveListeners() 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir if ( m_pInterfaceContainer ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir // move state change listeners 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pStateChangeContainer = 136*cdf0e10cSrcweir m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< embed::XStateChangeListener >*) NULL ) ); 137*cdf0e10cSrcweir if ( pStateChangeContainer != NULL ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir uno::Reference< embed::XStateChangeBroadcaster > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 140*cdf0e10cSrcweir if ( xWrappedObject.is() ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper pIterator( *pStateChangeContainer ); 143*cdf0e10cSrcweir while ( pIterator.hasMoreElements() ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir try 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir xWrappedObject->addStateChangeListener( (embed::XStateChangeListener*)pIterator.next() ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir catch( uno::RuntimeException& ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir pIterator.remove(); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // move event listeners 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pEventContainer = 161*cdf0e10cSrcweir m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< document::XEventListener >*) NULL ) ); 162*cdf0e10cSrcweir if ( pEventContainer != NULL ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir uno::Reference< document::XEventBroadcaster > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 165*cdf0e10cSrcweir if ( xWrappedObject.is() ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper pIterator( *pEventContainer ); 168*cdf0e10cSrcweir while ( pIterator.hasMoreElements() ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir try 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir xWrappedObject->addEventListener( (document::XEventListener*)pIterator.next() ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir catch( uno::RuntimeException& ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir pIterator.remove(); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // move close listeners 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pCloseContainer = 186*cdf0e10cSrcweir m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) ); 187*cdf0e10cSrcweir if ( pCloseContainer != NULL ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir uno::Reference< util::XCloseBroadcaster > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 190*cdf0e10cSrcweir if ( xWrappedObject.is() ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper pIterator( *pCloseContainer ); 193*cdf0e10cSrcweir while ( pIterator.hasMoreElements() ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir try 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir xWrappedObject->addCloseListener( (util::XCloseListener*)pIterator.next() ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir catch( uno::RuntimeException& ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir pIterator.remove(); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir delete m_pInterfaceContainer; 209*cdf0e10cSrcweir m_pInterfaceContainer = NULL; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //---------------------------------------------- 214*cdf0e10cSrcweir uno::Reference< embed::XStorage > OleEmbeddedObject::CreateTemporarySubstorage( ::rtl::OUString& o_aStorageName ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir uno::Reference< embed::XStorage > xResult; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < 32000 && !xResult.is(); nInd++ ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir ::rtl::OUString aName = ::rtl::OUString::valueOf( nInd ); 221*cdf0e10cSrcweir aName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TMPSTOR" ) ); 222*cdf0e10cSrcweir aName += m_aEntryName; 223*cdf0e10cSrcweir if ( !m_xParentStorage->hasByName( aName ) ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir xResult = m_xParentStorage->openStorageElement( aName, embed::ElementModes::READWRITE ); 226*cdf0e10cSrcweir o_aStorageName = aName; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir if ( !xResult.is() ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir o_aStorageName = ::rtl::OUString(); 233*cdf0e10cSrcweir throw uno::RuntimeException(); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir return xResult; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir //---------------------------------------------- 240*cdf0e10cSrcweir ::rtl::OUString OleEmbeddedObject::MoveToTemporarySubstream() 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir ::rtl::OUString aResult; 243*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < 32000 && !aResult.getLength(); nInd++ ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir ::rtl::OUString aName = ::rtl::OUString::valueOf( nInd ); 246*cdf0e10cSrcweir aName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TMPSTREAM" ) ); 247*cdf0e10cSrcweir aName += m_aEntryName; 248*cdf0e10cSrcweir if ( !m_xParentStorage->hasByName( aName ) ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir m_xParentStorage->renameElement( m_aEntryName, aName ); 251*cdf0e10cSrcweir aResult = aName; 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if ( !aResult.getLength() ) 256*cdf0e10cSrcweir throw uno::RuntimeException(); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir return aResult; 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir //---------------------------------------------- 262*cdf0e10cSrcweir sal_Bool OleEmbeddedObject::TryToConvertToOOo() 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir sal_Bool bResult = sal_False; 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir ::rtl::OUString aStorageName; 267*cdf0e10cSrcweir ::rtl::OUString aTmpStreamName; 268*cdf0e10cSrcweir sal_Int32 nStep = 0; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir if ( m_pOleComponent || m_bReadOnly ) 271*cdf0e10cSrcweir return sal_False; 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir try 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir changeState( embed::EmbedStates::LOADED ); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir // the stream must be seekable 278*cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeekable( m_xObjectStream, uno::UNO_QUERY_THROW ); 279*cdf0e10cSrcweir xSeekable->seek( 0 ); 280*cdf0e10cSrcweir ::rtl::OUString aFilterName = OwnView_Impl::GetFilterNameFromExtentionAndInStream( m_xFactory, ::rtl::OUString(), m_xObjectStream->getInputStream() ); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // use the solution only for OOXML format currently 283*cdf0e10cSrcweir if ( aFilterName.getLength() 284*cdf0e10cSrcweir && ( aFilterName.equals( ::rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Calc MS Excel 2007 XML" ) ) ) 285*cdf0e10cSrcweir || aFilterName.equals( ::rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Impress MS PowerPoint 2007 XML" ) ) ) 286*cdf0e10cSrcweir || aFilterName.equals( ::rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "MS Word 2007 XML" ) ) ) ) ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xFilterFactory( 289*cdf0e10cSrcweir m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), 290*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir ::rtl::OUString aDocServiceName; 293*cdf0e10cSrcweir uno::Any aFilterAnyData = xFilterFactory->getByName( aFilterName ); 294*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aFilterData; 295*cdf0e10cSrcweir if ( aFilterAnyData >>= aFilterData ) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ ) 298*cdf0e10cSrcweir if ( aFilterData[nInd].Name.equalsAscii( "DocumentService" ) ) 299*cdf0e10cSrcweir aFilterData[nInd].Value >>= aDocServiceName; 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir if ( aDocServiceName.getLength() ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir // create the model 305*cdf0e10cSrcweir uno::Sequence< uno::Any > aArguments(1); 306*cdf0e10cSrcweir aArguments[0] <<= beans::NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EmbeddedObject" ) ), uno::makeAny( (sal_Bool)sal_True )); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir uno::Reference< util::XCloseable > xDocument( m_xFactory->createInstanceWithArguments( aDocServiceName, aArguments ), uno::UNO_QUERY_THROW ); 309*cdf0e10cSrcweir uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY_THROW ); 310*cdf0e10cSrcweir uno::Reference< document::XStorageBasedDocument > xStorDoc( xDocument, uno::UNO_QUERY_THROW ); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir // let the model behave as embedded one 313*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY_THROW ); 314*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aSeq( 1 ); 315*cdf0e10cSrcweir aSeq[0].Name = ::rtl::OUString::createFromAscii( "SetEmbedded" ); 316*cdf0e10cSrcweir aSeq[0].Value <<= sal_True; 317*cdf0e10cSrcweir xModel->attachResource( ::rtl::OUString(), aSeq ); 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // load the model from the stream 320*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs( 5 ); 321*cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString::createFromAscii( "HierarchicalDocumentName" ); 322*cdf0e10cSrcweir aArgs[0].Value <<= m_aEntryName; 323*cdf0e10cSrcweir aArgs[1].Name = ::rtl::OUString::createFromAscii( "ReadOnly" ); 324*cdf0e10cSrcweir aArgs[1].Value <<= sal_True; 325*cdf0e10cSrcweir aArgs[2].Name = ::rtl::OUString::createFromAscii( "FilterName" ); 326*cdf0e10cSrcweir aArgs[2].Value <<= aFilterName; 327*cdf0e10cSrcweir aArgs[3].Name = ::rtl::OUString::createFromAscii( "URL" ); 328*cdf0e10cSrcweir aArgs[3].Value <<= ::rtl::OUString::createFromAscii( "private:stream" ); 329*cdf0e10cSrcweir aArgs[4].Name = ::rtl::OUString::createFromAscii( "InputStream" ); 330*cdf0e10cSrcweir aArgs[4].Value <<= m_xObjectStream->getInputStream(); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir xSeekable->seek( 0 ); 333*cdf0e10cSrcweir xLoadable->load( aArgs ); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir // the model is successfuly loaded, create a new storage and store the model to the storage 336*cdf0e10cSrcweir uno::Reference< embed::XStorage > xTmpStorage = CreateTemporarySubstorage( aStorageName ); 337*cdf0e10cSrcweir xStorDoc->storeToStorage( xTmpStorage, uno::Sequence< beans::PropertyValue >() ); 338*cdf0e10cSrcweir xDocument->close( sal_True ); 339*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xStorProps( xTmpStorage, uno::UNO_QUERY_THROW ); 340*cdf0e10cSrcweir ::rtl::OUString aMediaType; 341*cdf0e10cSrcweir xStorProps->getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ) >>= aMediaType; 342*cdf0e10cSrcweir xTmpStorage->dispose(); 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir // look for the related embedded object factory 345*cdf0e10cSrcweir ::comphelper::MimeConfigurationHelper aConfigHelper( m_xFactory ); 346*cdf0e10cSrcweir ::rtl::OUString aEmbedFactory; 347*cdf0e10cSrcweir if ( aMediaType.getLength() ) 348*cdf0e10cSrcweir aEmbedFactory = aConfigHelper.GetFactoryNameByMediaType( aMediaType ); 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir if ( !aEmbedFactory.getLength() ) 351*cdf0e10cSrcweir throw uno::RuntimeException(); 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir uno::Reference< uno::XInterface > xFact = m_xFactory->createInstance( aEmbedFactory ); 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir uno::Reference< embed::XEmbedObjectCreator > xEmbCreator( xFact, uno::UNO_QUERY_THROW ); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir // now the object should be adjusted to become the wrapper 358*cdf0e10cSrcweir nStep = 1; 359*cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( m_xObjectStream, uno::UNO_QUERY_THROW ); 360*cdf0e10cSrcweir xComp->dispose(); 361*cdf0e10cSrcweir m_xObjectStream = uno::Reference< io::XStream >(); 362*cdf0e10cSrcweir m_nObjectState = -1; 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir nStep = 2; 365*cdf0e10cSrcweir aTmpStreamName = MoveToTemporarySubstream(); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir nStep = 3; 368*cdf0e10cSrcweir m_xParentStorage->renameElement( aStorageName, m_aEntryName ); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir nStep = 4; 371*cdf0e10cSrcweir m_xWrappedObject.set( xEmbCreator->createInstanceInitFromEntry( m_xParentStorage, m_aEntryName, uno::Sequence< beans::PropertyValue >(), uno::Sequence< beans::PropertyValue >() ), uno::UNO_QUERY_THROW ); 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir bResult = sal_True; // the change is no more revertable 374*cdf0e10cSrcweir try 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir m_xParentStorage->removeElement( aTmpStreamName ); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir catch( uno::Exception& ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir // the success of the removing is not so important 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir catch( uno::Exception& ) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir // repair the object if necessary 388*cdf0e10cSrcweir switch( nStep ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir case 4: 391*cdf0e10cSrcweir case 3: 392*cdf0e10cSrcweir if ( aTmpStreamName.getLength() && aTmpStreamName != m_aEntryName ) 393*cdf0e10cSrcweir try 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir if ( m_xParentStorage->hasByName( m_aEntryName ) ) 396*cdf0e10cSrcweir m_xParentStorage->removeElement( m_aEntryName ); 397*cdf0e10cSrcweir m_xParentStorage->renameElement( aTmpStreamName, m_aEntryName ); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir catch ( uno::Exception& ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir try { 402*cdf0e10cSrcweir close( sal_True ); 403*cdf0e10cSrcweir } catch( uno::Exception& ) {} 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir m_xParentStorage->dispose(); // ??? the storage has information loss, it should be closed without commiting! 406*cdf0e10cSrcweir throw uno::RuntimeException(); // the repairing is not possible 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir case 2: 409*cdf0e10cSrcweir try 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir m_xObjectStream = m_xParentStorage->openStreamElement( m_aEntryName, m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE ); 412*cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::LOADED; 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir catch( uno::Exception& ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir try { 417*cdf0e10cSrcweir close( sal_True ); 418*cdf0e10cSrcweir } catch( uno::Exception& ) {} 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir throw uno::RuntimeException(); // the repairing is not possible 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir // no break as designed! 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir case 1: 425*cdf0e10cSrcweir case 0: 426*cdf0e10cSrcweir if ( aStorageName.getLength() ) 427*cdf0e10cSrcweir try { 428*cdf0e10cSrcweir m_xParentStorage->removeElement( aStorageName ); 429*cdf0e10cSrcweir } catch( uno::Exception& ) { OSL_ASSERT( "Can not remove temporary storage!" ); } 430*cdf0e10cSrcweir break; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir if ( bResult ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir // the conversion was done successfuly, now the additional initializations should happen 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir MoveListeners(); 439*cdf0e10cSrcweir m_xWrappedObject->setClientSite( m_xClientSite ); 440*cdf0e10cSrcweir if ( m_xParent.is() ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir uno::Reference< container::XChild > xChild( m_xWrappedObject, uno::UNO_QUERY ); 443*cdf0e10cSrcweir if ( xChild.is() ) 444*cdf0e10cSrcweir xChild->setParent( m_xParent ); 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir return bResult; 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir //---------------------------------------------- 453*cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 nNewState ) 454*cdf0e10cSrcweir throw ( embed::UnreachableStateException, 455*cdf0e10cSrcweir embed::WrongStateException, 456*cdf0e10cSrcweir uno::Exception, 457*cdf0e10cSrcweir uno::RuntimeException ) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::changeState" ); 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir // begin wrapping related part ==================== 462*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 463*cdf0e10cSrcweir if ( xWrappedObject.is() ) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 466*cdf0e10cSrcweir xWrappedObject->changeState( nNewState ); 467*cdf0e10cSrcweir return; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir // end wrapping related part ==================== 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir if ( m_bDisposed ) 474*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 477*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 478*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir // in case the object is already in requested state 481*cdf0e10cSrcweir if ( m_nObjectState == nNewState ) 482*cdf0e10cSrcweir return; 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir #ifdef WNT 485*cdf0e10cSrcweir if ( m_pOleComponent ) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir if ( m_nTargetState != -1 ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir // means that the object is currently trying to reach the target state 490*cdf0e10cSrcweir throw embed::StateChangeInProgressException( ::rtl::OUString(), 491*cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 492*cdf0e10cSrcweir m_nTargetState ); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir TargetStateControl_Impl aControl( m_nTargetState, nNewState ); 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir // TODO: additional verbs can be a problem, since nobody knows how the object 498*cdf0e10cSrcweir // will behave after activation 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir sal_Int32 nOldState = m_nObjectState; 501*cdf0e10cSrcweir aGuard.clear(); 502*cdf0e10cSrcweir StateChangeNotification_Impl( sal_True, nOldState, nNewState ); 503*cdf0e10cSrcweir aGuard.reset(); 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir try 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir if ( nNewState == embed::EmbedStates::LOADED ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir // This means just closing of the current object 510*cdf0e10cSrcweir // If component can not be closed the object stays in loaded state 511*cdf0e10cSrcweir // and it holds reference to "incomplete" component 512*cdf0e10cSrcweir // If the object is switched to running state later 513*cdf0e10cSrcweir // the component will become "complete" 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir // the loaded state must be set before, because of notifications! 516*cdf0e10cSrcweir m_nObjectState = nNewState; 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController ); 520*cdf0e10cSrcweir m_pOleComponent->CloseObject(); 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir // GetRidOfComponent(); 524*cdf0e10cSrcweir aGuard.clear(); 525*cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ); 526*cdf0e10cSrcweir aGuard.reset(); 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir else if ( nNewState == embed::EmbedStates::RUNNING || nNewState == embed::EmbedStates::ACTIVE ) 529*cdf0e10cSrcweir { 530*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir // if the target object is in loaded state and a different state is specified 533*cdf0e10cSrcweir // as a new one the object first must be switched to running state. 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir // the component can exist already in nonrunning state 536*cdf0e10cSrcweir // it can be created during loading to detect type of object 537*cdf0e10cSrcweir CreateOleComponentAndLoad_Impl( m_pOleComponent ); 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir SwitchComponentToRunningState_Impl(); 540*cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 541*cdf0e10cSrcweir aGuard.clear(); 542*cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ); 543*cdf0e10cSrcweir aGuard.reset(); 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir if ( m_pOleComponent && m_bHasSizeToSet ) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir aGuard.clear(); 548*cdf0e10cSrcweir try { 549*cdf0e10cSrcweir m_pOleComponent->SetExtent( m_aSizeToSet, m_nAspectToSet ); 550*cdf0e10cSrcweir m_bHasSizeToSet = sal_False; 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir catch( uno::Exception& ) {} 553*cdf0e10cSrcweir aGuard.reset(); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir if ( m_nObjectState == nNewState ) 557*cdf0e10cSrcweir return; 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir // so now the object is either switched from Active to Running state or vise versa 561*cdf0e10cSrcweir // the notification about object state change will be done asynchronously 562*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::RUNNING && nNewState == embed::EmbedStates::ACTIVE ) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir // execute OPEN verb, if object does not reach active state it is an object's problem 565*cdf0e10cSrcweir aGuard.clear(); 566*cdf0e10cSrcweir m_pOleComponent->ExecuteVerb( embed::EmbedVerbs::MS_OLEVERB_OPEN ); 567*cdf0e10cSrcweir aGuard.reset(); 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir // some objects do not allow to set the size even in running state 570*cdf0e10cSrcweir if ( m_pOleComponent && m_bHasSizeToSet ) 571*cdf0e10cSrcweir { 572*cdf0e10cSrcweir aGuard.clear(); 573*cdf0e10cSrcweir try { 574*cdf0e10cSrcweir m_pOleComponent->SetExtent( m_aSizeToSet, m_nAspectToSet ); 575*cdf0e10cSrcweir m_bHasSizeToSet = sal_False; 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir catch( uno::Exception& ) {} 578*cdf0e10cSrcweir aGuard.reset(); 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir m_nObjectState = nNewState; 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir else if ( m_nObjectState == embed::EmbedStates::ACTIVE && nNewState == embed::EmbedStates::RUNNING ) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir aGuard.clear(); 586*cdf0e10cSrcweir m_pOleComponent->CloseObject(); 587*cdf0e10cSrcweir m_pOleComponent->RunObject(); // Should not fail, the object already was active 588*cdf0e10cSrcweir aGuard.reset(); 589*cdf0e10cSrcweir m_nObjectState = nNewState; 590*cdf0e10cSrcweir } 591*cdf0e10cSrcweir else 592*cdf0e10cSrcweir { 593*cdf0e10cSrcweir throw embed::UnreachableStateException(); 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir else 597*cdf0e10cSrcweir throw embed::UnreachableStateException(); 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir catch( uno::Exception& ) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir aGuard.clear(); 602*cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ); 603*cdf0e10cSrcweir throw; 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir else 607*cdf0e10cSrcweir #endif 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir throw embed::UnreachableStateException(); 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir //---------------------------------------------- 614*cdf0e10cSrcweir uno::Sequence< sal_Int32 > SAL_CALL OleEmbeddedObject::getReachableStates() 615*cdf0e10cSrcweir throw ( embed::WrongStateException, 616*cdf0e10cSrcweir uno::RuntimeException ) 617*cdf0e10cSrcweir { 618*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::getReachableStates" ); 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir // begin wrapping related part ==================== 621*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 622*cdf0e10cSrcweir if ( xWrappedObject.is() ) 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 625*cdf0e10cSrcweir return xWrappedObject->getReachableStates(); 626*cdf0e10cSrcweir } 627*cdf0e10cSrcweir // end wrapping related part ==================== 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 630*cdf0e10cSrcweir if ( m_bDisposed ) 631*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 634*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 635*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir #ifdef WNT 638*cdf0e10cSrcweir if ( m_pOleComponent ) 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir // the list of supported verbs can be retrieved only when object is in running state 643*cdf0e10cSrcweir throw embed::NeedsRunningStateException(); // TODO: 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir // the list of states can only be guessed based on standard verbs, 647*cdf0e10cSrcweir // since there is no way to detect what additional verbs do 648*cdf0e10cSrcweir return GetReachableStatesList_Impl( m_pOleComponent->GetVerbList() ); 649*cdf0e10cSrcweir } 650*cdf0e10cSrcweir else 651*cdf0e10cSrcweir #endif 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir return uno::Sequence< sal_Int32 >(); 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir //---------------------------------------------- 658*cdf0e10cSrcweir sal_Int32 SAL_CALL OleEmbeddedObject::getCurrentState() 659*cdf0e10cSrcweir throw ( embed::WrongStateException, 660*cdf0e10cSrcweir uno::RuntimeException ) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir // begin wrapping related part ==================== 663*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 664*cdf0e10cSrcweir if ( xWrappedObject.is() ) 665*cdf0e10cSrcweir { 666*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 667*cdf0e10cSrcweir return xWrappedObject->getCurrentState(); 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir // end wrapping related part ==================== 670*cdf0e10cSrcweir 671*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 672*cdf0e10cSrcweir if ( m_bDisposed ) 673*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 676*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 677*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir // TODO: Shouldn't we ask object? ( I guess no ) 680*cdf0e10cSrcweir return m_nObjectState; 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir namespace 684*cdf0e10cSrcweir { 685*cdf0e10cSrcweir bool lcl_CopyStream(uno::Reference<io::XInputStream> xIn, uno::Reference<io::XOutputStream> xOut) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir const sal_Int32 nChunkSize = 4096; 688*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aData(nChunkSize); 689*cdf0e10cSrcweir sal_Int32 nTotalRead = 0; 690*cdf0e10cSrcweir sal_Int32 nRead; 691*cdf0e10cSrcweir do 692*cdf0e10cSrcweir { 693*cdf0e10cSrcweir nRead = xIn->readBytes(aData, nChunkSize); 694*cdf0e10cSrcweir nTotalRead += nRead; 695*cdf0e10cSrcweir xOut->writeBytes(aData); 696*cdf0e10cSrcweir } while (nRead == nChunkSize); 697*cdf0e10cSrcweir return nTotalRead != 0; 698*cdf0e10cSrcweir } 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir //Dump the objects content to a tempfile, just the "CONTENTS" stream if 701*cdf0e10cSrcweir //there is one for non-compound documents, otherwise the whole content. 702*cdf0e10cSrcweir // 703*cdf0e10cSrcweir //On success a file is returned which must be removed by the caller 704*cdf0e10cSrcweir rtl::OUString lcl_ExtractObject(::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, 705*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xObjectStream) 706*cdf0e10cSrcweir { 707*cdf0e10cSrcweir rtl::OUString sUrl; 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir // the solution is only active for Unix systems 710*cdf0e10cSrcweir #ifndef WNT 711*cdf0e10cSrcweir uno::Reference <beans::XPropertySet> xNativeTempFile( 712*cdf0e10cSrcweir xFactory->createInstance( 713*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile"))), uno::UNO_QUERY_THROW); 714*cdf0e10cSrcweir uno::Reference < io::XStream > xStream(xNativeTempFile, uno::UNO_QUERY_THROW); 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 717*cdf0e10cSrcweir aArgs[0] <<= xObjectStream; 718*cdf0e10cSrcweir aArgs[1] <<= (sal_Bool)sal_True; // do not create copy 719*cdf0e10cSrcweir uno::Reference< container::XNameContainer > xNameContainer( 720*cdf0e10cSrcweir xFactory->createInstanceWithArguments( 721*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.OLESimpleStorage")), 722*cdf0e10cSrcweir aArgs ), uno::UNO_QUERY_THROW ); 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir uno::Reference< io::XStream > xCONTENTS; 725*cdf0e10cSrcweir xNameContainer->getByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CONTENTS"))) >>= xCONTENTS; 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir sal_Bool bCopied = xCONTENTS.is() && lcl_CopyStream(xCONTENTS->getInputStream(), xStream->getOutputStream()); 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeekableStor(xObjectStream, uno::UNO_QUERY); 730*cdf0e10cSrcweir if (xSeekableStor.is()) 731*cdf0e10cSrcweir xSeekableStor->seek(0); 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir if (!bCopied) 734*cdf0e10cSrcweir bCopied = lcl_CopyStream(xObjectStream->getInputStream(), xStream->getOutputStream()); 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir if (bCopied) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir xNativeTempFile->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile")), 739*cdf0e10cSrcweir uno::makeAny(sal_False)); 740*cdf0e10cSrcweir uno::Any aUrl = xNativeTempFile->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Uri"))); 741*cdf0e10cSrcweir aUrl >>= sUrl; 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir xNativeTempFile = uno::Reference<beans::XPropertySet>(); 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir uno::Reference<ucb::XSimpleFileAccess> xSimpleFileAccess( 746*cdf0e10cSrcweir xFactory->createInstance( 747*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess"))), 748*cdf0e10cSrcweir uno::UNO_QUERY_THROW); 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir xSimpleFileAccess->setReadOnly(sUrl, sal_True); 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir else 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir xNativeTempFile->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile")), 755*cdf0e10cSrcweir uno::makeAny(sal_True)); 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir #endif 758*cdf0e10cSrcweir return sUrl; 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir } 761*cdf0e10cSrcweir 762*cdf0e10cSrcweir //---------------------------------------------- 763*cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::doVerb( sal_Int32 nVerbID ) 764*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 765*cdf0e10cSrcweir embed::WrongStateException, 766*cdf0e10cSrcweir embed::UnreachableStateException, 767*cdf0e10cSrcweir uno::Exception, 768*cdf0e10cSrcweir uno::RuntimeException ) 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::doVerb" ); 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir // begin wrapping related part ==================== 773*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 774*cdf0e10cSrcweir if ( xWrappedObject.is() ) 775*cdf0e10cSrcweir { 776*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 777*cdf0e10cSrcweir xWrappedObject->doVerb( nVerbID ); 778*cdf0e10cSrcweir return; 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir // end wrapping related part ==================== 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 783*cdf0e10cSrcweir if ( m_bDisposed ) 784*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 785*cdf0e10cSrcweir 786*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 787*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 788*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir #ifdef WNT 791*cdf0e10cSrcweir if ( m_pOleComponent ) 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir sal_Int32 nOldState = m_nObjectState; 794*cdf0e10cSrcweir 795*cdf0e10cSrcweir // TODO/LATER detect target state here and do a notification 796*cdf0e10cSrcweir // StateChangeNotification_Impl( sal_True, nOldState, nNewState ); 797*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 798*cdf0e10cSrcweir { 799*cdf0e10cSrcweir // if the target object is in loaded state 800*cdf0e10cSrcweir // it must be switched to running state to execute verb 801*cdf0e10cSrcweir aGuard.clear(); 802*cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 803*cdf0e10cSrcweir aGuard.reset(); 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir try { 807*cdf0e10cSrcweir if ( !m_pOleComponent ) 808*cdf0e10cSrcweir throw uno::RuntimeException(); 809*cdf0e10cSrcweir 810*cdf0e10cSrcweir // ==== the STAMPIT related solution ============================= 811*cdf0e10cSrcweir m_aVerbExecutionController.StartControlExecution(); 812*cdf0e10cSrcweir // =============================================================== 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir m_pOleComponent->ExecuteVerb( nVerbID ); 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir // ==== the STAMPIT related solution ============================= 817*cdf0e10cSrcweir sal_Bool bModifiedOnExecution = m_aVerbExecutionController.EndControlExecution_WasModified(); 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir // this workaround is implemented for STAMPIT object 820*cdf0e10cSrcweir // if object was modified during verb execution it is saved here 821*cdf0e10cSrcweir if ( bModifiedOnExecution && m_pOleComponent->IsDirty() ) 822*cdf0e10cSrcweir SaveObject_Impl(); 823*cdf0e10cSrcweir // =============================================================== 824*cdf0e10cSrcweir } 825*cdf0e10cSrcweir catch( uno::Exception& ) 826*cdf0e10cSrcweir { 827*cdf0e10cSrcweir // ==== the STAMPIT related solution ============================= 828*cdf0e10cSrcweir m_aVerbExecutionController.EndControlExecution_WasModified(); 829*cdf0e10cSrcweir // =============================================================== 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir aGuard.clear(); 832*cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ); 833*cdf0e10cSrcweir throw; 834*cdf0e10cSrcweir } 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir // the following notification will be done asynchronously 837*cdf0e10cSrcweir // StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ); 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir else 840*cdf0e10cSrcweir #endif 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir if ( nVerbID == -9 ) 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir // the workaround verb to show the object in case no server is available 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir // if it is possible, the object will be converted to OOo format 847*cdf0e10cSrcweir if ( !m_bTriedConversion ) 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir m_bTriedConversion = sal_True; 850*cdf0e10cSrcweir if ( TryToConvertToOOo() ) 851*cdf0e10cSrcweir { 852*cdf0e10cSrcweir changeState( embed::EmbedStates::UI_ACTIVE ); 853*cdf0e10cSrcweir return; 854*cdf0e10cSrcweir } 855*cdf0e10cSrcweir } 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir if ( !m_pOwnView && m_xObjectStream.is() ) 858*cdf0e10cSrcweir { 859*cdf0e10cSrcweir try { 860*cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeekable( m_xObjectStream, uno::UNO_QUERY ); 861*cdf0e10cSrcweir if ( xSeekable.is() ) 862*cdf0e10cSrcweir xSeekable->seek( 0 ); 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir m_pOwnView = new OwnView_Impl( m_xFactory, m_xObjectStream->getInputStream() ); 865*cdf0e10cSrcweir m_pOwnView->acquire(); 866*cdf0e10cSrcweir } 867*cdf0e10cSrcweir catch( uno::RuntimeException& ) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir throw; 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir catch( uno::Exception& ) 872*cdf0e10cSrcweir { 873*cdf0e10cSrcweir } 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir if ( !m_pOwnView || !m_pOwnView->Open() ) 877*cdf0e10cSrcweir { 878*cdf0e10cSrcweir //Make a RO copy and see if the OS can find something to at 879*cdf0e10cSrcweir //least display the content for us 880*cdf0e10cSrcweir if (!m_aTempDumpURL.getLength()) 881*cdf0e10cSrcweir m_aTempDumpURL = lcl_ExtractObject(m_xFactory, m_xObjectStream); 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir if (m_aTempDumpURL.getLength()) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir uno::Reference< ::com::sun::star::system::XSystemShellExecute > xSystemShellExecute( m_xFactory->createInstance( 886*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.system.SystemShellExecute"))), 887*cdf0e10cSrcweir uno::UNO_QUERY_THROW); 888*cdf0e10cSrcweir xSystemShellExecute->execute(m_aTempDumpURL, ::rtl::OUString(), ::com::sun::star::system::SystemShellExecuteFlags::DEFAULTS); 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir else 891*cdf0e10cSrcweir throw embed::UnreachableStateException(); 892*cdf0e10cSrcweir } 893*cdf0e10cSrcweir } 894*cdf0e10cSrcweir else 895*cdf0e10cSrcweir { 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir throw embed::UnreachableStateException(); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir } 900*cdf0e10cSrcweir } 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir //---------------------------------------------- 903*cdf0e10cSrcweir uno::Sequence< embed::VerbDescriptor > SAL_CALL OleEmbeddedObject::getSupportedVerbs() 904*cdf0e10cSrcweir throw ( embed::WrongStateException, 905*cdf0e10cSrcweir uno::RuntimeException ) 906*cdf0e10cSrcweir { 907*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::getSupportedVerb" ); 908*cdf0e10cSrcweir 909*cdf0e10cSrcweir // begin wrapping related part ==================== 910*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 911*cdf0e10cSrcweir if ( xWrappedObject.is() ) 912*cdf0e10cSrcweir { 913*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 914*cdf0e10cSrcweir return xWrappedObject->getSupportedVerbs(); 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir // end wrapping related part ==================== 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 919*cdf0e10cSrcweir if ( m_bDisposed ) 920*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 923*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 924*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 925*cdf0e10cSrcweir #ifdef WNT 926*cdf0e10cSrcweir if ( m_pOleComponent ) 927*cdf0e10cSrcweir { 928*cdf0e10cSrcweir // registry could be used in this case 929*cdf0e10cSrcweir // if ( m_nObjectState == embed::EmbedStates::LOADED ) 930*cdf0e10cSrcweir // { 931*cdf0e10cSrcweir // // the list of supported verbs can be retrieved only when object is in running state 932*cdf0e10cSrcweir // throw embed::NeedsRunningStateException(); // TODO: 933*cdf0e10cSrcweir // } 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir return m_pOleComponent->GetVerbList(); 936*cdf0e10cSrcweir } 937*cdf0e10cSrcweir else 938*cdf0e10cSrcweir #endif 939*cdf0e10cSrcweir { 940*cdf0e10cSrcweir return uno::Sequence< embed::VerbDescriptor >(); 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir } 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir //---------------------------------------------- 945*cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::setClientSite( 946*cdf0e10cSrcweir const uno::Reference< embed::XEmbeddedClient >& xClient ) 947*cdf0e10cSrcweir throw ( embed::WrongStateException, 948*cdf0e10cSrcweir uno::RuntimeException ) 949*cdf0e10cSrcweir { 950*cdf0e10cSrcweir // begin wrapping related part ==================== 951*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 952*cdf0e10cSrcweir if ( xWrappedObject.is() ) 953*cdf0e10cSrcweir { 954*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 955*cdf0e10cSrcweir xWrappedObject->setClientSite( xClient ); 956*cdf0e10cSrcweir return; 957*cdf0e10cSrcweir } 958*cdf0e10cSrcweir // end wrapping related part ==================== 959*cdf0e10cSrcweir 960*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 961*cdf0e10cSrcweir if ( m_bDisposed ) 962*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 963*cdf0e10cSrcweir 964*cdf0e10cSrcweir if ( m_xClientSite != xClient) 965*cdf0e10cSrcweir { 966*cdf0e10cSrcweir if ( m_nObjectState != embed::EmbedStates::LOADED && m_nObjectState != embed::EmbedStates::RUNNING ) 967*cdf0e10cSrcweir throw embed::WrongStateException( 968*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The client site can not be set currently!\n" ), 969*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 970*cdf0e10cSrcweir 971*cdf0e10cSrcweir m_xClientSite = xClient; 972*cdf0e10cSrcweir } 973*cdf0e10cSrcweir } 974*cdf0e10cSrcweir 975*cdf0e10cSrcweir //---------------------------------------------- 976*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedClient > SAL_CALL OleEmbeddedObject::getClientSite() 977*cdf0e10cSrcweir throw ( embed::WrongStateException, 978*cdf0e10cSrcweir uno::RuntimeException ) 979*cdf0e10cSrcweir { 980*cdf0e10cSrcweir // begin wrapping related part ==================== 981*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 982*cdf0e10cSrcweir if ( xWrappedObject.is() ) 983*cdf0e10cSrcweir { 984*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 985*cdf0e10cSrcweir return xWrappedObject->getClientSite(); 986*cdf0e10cSrcweir } 987*cdf0e10cSrcweir // end wrapping related part ==================== 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 990*cdf0e10cSrcweir if ( m_bDisposed ) 991*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 992*cdf0e10cSrcweir 993*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 994*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 995*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 996*cdf0e10cSrcweir 997*cdf0e10cSrcweir return m_xClientSite; 998*cdf0e10cSrcweir } 999*cdf0e10cSrcweir 1000*cdf0e10cSrcweir //---------------------------------------------- 1001*cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::update() 1002*cdf0e10cSrcweir throw ( embed::WrongStateException, 1003*cdf0e10cSrcweir uno::Exception, 1004*cdf0e10cSrcweir uno::RuntimeException ) 1005*cdf0e10cSrcweir { 1006*cdf0e10cSrcweir // begin wrapping related part ==================== 1007*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 1008*cdf0e10cSrcweir if ( xWrappedObject.is() ) 1009*cdf0e10cSrcweir { 1010*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1011*cdf0e10cSrcweir xWrappedObject->update(); 1012*cdf0e10cSrcweir return; 1013*cdf0e10cSrcweir } 1014*cdf0e10cSrcweir // end wrapping related part ==================== 1015*cdf0e10cSrcweir 1016*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1017*cdf0e10cSrcweir if ( m_bDisposed ) 1018*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1019*cdf0e10cSrcweir 1020*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1021*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 1022*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1023*cdf0e10cSrcweir 1024*cdf0e10cSrcweir if ( m_nUpdateMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE ) 1025*cdf0e10cSrcweir { 1026*cdf0e10cSrcweir // TODO: update view representation 1027*cdf0e10cSrcweir } 1028*cdf0e10cSrcweir else 1029*cdf0e10cSrcweir { 1030*cdf0e10cSrcweir // the object must be up to date 1031*cdf0e10cSrcweir OSL_ENSURE( m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE, "Unknown update mode!\n" ); 1032*cdf0e10cSrcweir } 1033*cdf0e10cSrcweir } 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweir //---------------------------------------------- 1036*cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::setUpdateMode( sal_Int32 nMode ) 1037*cdf0e10cSrcweir throw ( embed::WrongStateException, 1038*cdf0e10cSrcweir uno::RuntimeException ) 1039*cdf0e10cSrcweir { 1040*cdf0e10cSrcweir // begin wrapping related part ==================== 1041*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 1042*cdf0e10cSrcweir if ( xWrappedObject.is() ) 1043*cdf0e10cSrcweir { 1044*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1045*cdf0e10cSrcweir xWrappedObject->setUpdateMode( nMode ); 1046*cdf0e10cSrcweir return; 1047*cdf0e10cSrcweir } 1048*cdf0e10cSrcweir // end wrapping related part ==================== 1049*cdf0e10cSrcweir 1050*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1051*cdf0e10cSrcweir if ( m_bDisposed ) 1052*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1055*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ), 1056*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1057*cdf0e10cSrcweir 1058*cdf0e10cSrcweir OSL_ENSURE( nMode == embed::EmbedUpdateModes::ALWAYS_UPDATE 1059*cdf0e10cSrcweir || nMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE, 1060*cdf0e10cSrcweir "Unknown update mode!\n" ); 1061*cdf0e10cSrcweir m_nUpdateMode = nMode; 1062*cdf0e10cSrcweir } 1063*cdf0e10cSrcweir 1064*cdf0e10cSrcweir //---------------------------------------------- 1065*cdf0e10cSrcweir sal_Int64 SAL_CALL OleEmbeddedObject::getStatus( sal_Int64 1066*cdf0e10cSrcweir nAspect 1067*cdf0e10cSrcweir ) 1068*cdf0e10cSrcweir throw ( embed::WrongStateException, 1069*cdf0e10cSrcweir uno::RuntimeException ) 1070*cdf0e10cSrcweir { 1071*cdf0e10cSrcweir // begin wrapping related part ==================== 1072*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 1073*cdf0e10cSrcweir if ( xWrappedObject.is() ) 1074*cdf0e10cSrcweir { 1075*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1076*cdf0e10cSrcweir return xWrappedObject->getStatus( nAspect ); 1077*cdf0e10cSrcweir } 1078*cdf0e10cSrcweir // end wrapping related part ==================== 1079*cdf0e10cSrcweir 1080*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1081*cdf0e10cSrcweir if ( m_bDisposed ) 1082*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1083*cdf0e10cSrcweir 1084*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1085*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object must be in running state!\n" ), 1086*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1087*cdf0e10cSrcweir 1088*cdf0e10cSrcweir sal_Int64 nResult = 0; 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir #ifdef WNT 1091*cdf0e10cSrcweir if ( m_bGotStatus && m_nStatusAspect == nAspect ) 1092*cdf0e10cSrcweir nResult = m_nStatus; 1093*cdf0e10cSrcweir else if ( m_pOleComponent ) 1094*cdf0e10cSrcweir { 1095*cdf0e10cSrcweir // OLE should allow to get status even in loaded state 1096*cdf0e10cSrcweir // if ( m_nObjectState == embed::EmbedStates::LOADED ) 1097*cdf0e10cSrcweir // changeState( m_nObjectState == embed::EmbedStates::RUNNING ); 1098*cdf0e10cSrcweir 1099*cdf0e10cSrcweir m_nStatus = m_pOleComponent->GetMiscStatus( nAspect ); 1100*cdf0e10cSrcweir m_nStatusAspect = nAspect; 1101*cdf0e10cSrcweir m_bGotStatus = sal_True; 1102*cdf0e10cSrcweir nResult = m_nStatus; 1103*cdf0e10cSrcweir } 1104*cdf0e10cSrcweir #endif 1105*cdf0e10cSrcweir 1106*cdf0e10cSrcweir // this implementation needs size to be provided after object loading/creating to work in optimal way 1107*cdf0e10cSrcweir return ( nResult | embed::EmbedMisc::EMBED_NEEDSSIZEONLOAD ); 1108*cdf0e10cSrcweir } 1109*cdf0e10cSrcweir 1110*cdf0e10cSrcweir //---------------------------------------------- 1111*cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::setContainerName( const ::rtl::OUString& sName ) 1112*cdf0e10cSrcweir throw ( uno::RuntimeException ) 1113*cdf0e10cSrcweir { 1114*cdf0e10cSrcweir // begin wrapping related part ==================== 1115*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 1116*cdf0e10cSrcweir if ( xWrappedObject.is() ) 1117*cdf0e10cSrcweir { 1118*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1119*cdf0e10cSrcweir xWrappedObject->setContainerName( sName ); 1120*cdf0e10cSrcweir return; 1121*cdf0e10cSrcweir } 1122*cdf0e10cSrcweir // end wrapping related part ==================== 1123*cdf0e10cSrcweir 1124*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1125*cdf0e10cSrcweir if ( m_bDisposed ) 1126*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1127*cdf0e10cSrcweir 1128*cdf0e10cSrcweir m_aContainerName = sName; 1129*cdf0e10cSrcweir } 1130*cdf0e10cSrcweir 1131*cdf0e10cSrcweir 1132