Files
libreoffice/embeddedobj/source/msole/oleembed.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1182 lines
43 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-09-27 13:52:10 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2003-11-13 16:01:50 +00:00
#include <oleembobj.hxx>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/EmbedVerbs.hpp>
#include <com/sun/star/embed/UnreachableStateException.hpp>
2003-11-13 16:01:50 +00:00
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/EmbedUpdateModes.hpp>
#include <com/sun/star/embed/NeedsRunningStateException.hpp>
#include <com/sun/star/embed/StateChangeInProgressException.hpp>
#include <com/sun/star/embed/EmbedMisc.hpp>
#include <com/sun/star/embed/XEmbedObjectCreator.hpp>
#include <com/sun/star/io/TempFile.hpp>
#include <com/sun/star/io/XSeekable.hpp>
2003-11-13 16:01:50 +00:00
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/XLoadable.hpp>
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
2010-05-26 15:38:21 +02:00
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/system/SystemShellExecute.hpp>
2010-05-26 15:38:21 +02:00
#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
2003-11-13 16:01:50 +00:00
#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/interfacecontainer.h>
#include <comphelper/processfactory.hxx>
#include <comphelper/mimeconfighelper.hxx>
#include <sal/log.hxx>
#include <tools/diagnose_ex.h>
#include <targetstatecontrol.hxx>
#include "ownview.hxx"
#if defined(_WIN32)
#include "olecomponent.hxx"
#endif
2003-11-13 16:01:50 +00:00
using namespace ::com::sun::star;
#ifdef _WIN32
void OleEmbeddedObject::SwitchComponentToRunningState_Impl()
{
if ( !m_pOleComponent )
{
throw embed::UnreachableStateException();
}
try
{
m_pOleComponent->RunObject();
}
catch( const embed::UnreachableStateException& )
{
GetRidOfComponent();
throw;
}
catch( const embed::WrongStateException& )
{
GetRidOfComponent();
throw;
}
}
2003-11-13 16:01:50 +00:00
uno::Sequence< sal_Int32 > OleEmbeddedObject::GetReachableStatesList_Impl(
const uno::Sequence< embed::VerbDescriptor >& aVerbList )
2003-11-13 16:01:50 +00:00
{
uno::Sequence< sal_Int32 > aStates(2);
aStates[0] = embed::EmbedStates::LOADED;
aStates[1] = embed::EmbedStates::RUNNING;
for ( sal_Int32 nInd = 0; nInd < aVerbList.getLength(); nInd++ )
if ( aVerbList[nInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_OPEN )
{
aStates.realloc(3);
aStates[2] = embed::EmbedStates::ACTIVE;
}
return aStates;
2003-11-13 16:01:50 +00:00
}
2003-11-13 16:01:50 +00:00
uno::Sequence< sal_Int32 > OleEmbeddedObject::GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState )
{
SAL_WARN_IF( m_nObjectState == embed::EmbedStates::LOADED, "embeddedobj.ole", "Loaded object is switched to running state without verbs using!" );
2003-11-13 16:01:50 +00:00
// actually there will be only one verb
if ( m_nObjectState == embed::EmbedStates::RUNNING && nNewState == embed::EmbedStates::ACTIVE )
2003-11-13 16:01:50 +00:00
{
uno::Sequence< sal_Int32 > aVerbs( 1 );
aVerbs[0] = embed::EmbedVerbs::MS_OLEVERB_OPEN;
}
return uno::Sequence< sal_Int32 >();
}
#endif
void OleEmbeddedObject::MoveListeners()
{
if ( m_pInterfaceContainer )
{
// move state change listeners
{
::cppu::OInterfaceContainerHelper* pStateChangeContainer =
m_pInterfaceContainer->getContainer( cppu::UnoType<embed::XStateChangeListener>::get());
if ( pStateChangeContainer != nullptr )
{
if ( m_xWrappedObject.is() )
{
::cppu::OInterfaceIteratorHelper pIterator( *pStateChangeContainer );
while ( pIterator.hasMoreElements() )
{
try
{
m_xWrappedObject->addStateChangeListener( static_cast<embed::XStateChangeListener*>(pIterator.next()) );
}
2011-12-09 02:56:30 +09:00
catch( const uno::RuntimeException& )
{
pIterator.remove();
}
}
}
}
}
// move event listeners
{
::cppu::OInterfaceContainerHelper* pEventContainer =
m_pInterfaceContainer->getContainer( cppu::UnoType<document::XEventListener>::get());
if ( pEventContainer != nullptr )
{
if ( m_xWrappedObject.is() )
{
::cppu::OInterfaceIteratorHelper pIterator( *pEventContainer );
while ( pIterator.hasMoreElements() )
{
try
{
m_xWrappedObject->addEventListener( static_cast<document::XEventListener*>(pIterator.next()) );
}
2011-12-09 02:56:30 +09:00
catch( const uno::RuntimeException& )
{
pIterator.remove();
}
}
}
}
}
// move close listeners
{
::cppu::OInterfaceContainerHelper* pCloseContainer =
m_pInterfaceContainer->getContainer( cppu::UnoType<util::XCloseListener>::get());
if ( pCloseContainer != nullptr )
{
if ( m_xWrappedObject.is() )
{
::cppu::OInterfaceIteratorHelper pIterator( *pCloseContainer );
while ( pIterator.hasMoreElements() )
{
try
{
m_xWrappedObject->addCloseListener( static_cast<util::XCloseListener*>(pIterator.next()) );
}
2011-12-09 02:56:30 +09:00
catch( const uno::RuntimeException& )
{
pIterator.remove();
}
}
}
}
}
m_pInterfaceContainer.reset();
}
}
uno::Reference< embed::XStorage > OleEmbeddedObject::CreateTemporarySubstorage( OUString& o_aStorageName )
{
uno::Reference< embed::XStorage > xResult;
for ( sal_Int32 nInd = 0; nInd < 32000 && !xResult.is(); nInd++ )
{
OUString aName = OUString::number( nInd ) + "TMPSTOR" + m_aEntryName;
if ( !m_xParentStorage->hasByName( aName ) )
{
xResult = m_xParentStorage->openStorageElement( aName, embed::ElementModes::READWRITE );
o_aStorageName = aName;
}
}
if ( !xResult.is() )
{
o_aStorageName.clear();
throw uno::RuntimeException();
}
return xResult;
}
OUString OleEmbeddedObject::MoveToTemporarySubstream()
{
OUString aResult;
for ( sal_Int32 nInd = 0; nInd < 32000 && aResult.isEmpty(); nInd++ )
{
OUString aName = OUString::number( nInd ) + "TMPSTREAM" + m_aEntryName;
if ( !m_xParentStorage->hasByName( aName ) )
{
m_xParentStorage->renameElement( m_aEntryName, aName );
aResult = aName;
}
}
if ( aResult.isEmpty() )
throw uno::RuntimeException();
return aResult;
}
bool OleEmbeddedObject::TryToConvertToOOo( const uno::Reference< io::XStream >& xStream )
{
bool bResult = false;
OUString aStorageName;
OUString aTmpStreamName;
sal_Int32 nStep = 0;
if ( m_pOleComponent || m_bReadOnly )
return false;
try
{
changeState( embed::EmbedStates::LOADED );
// the stream must be seekable
uno::Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY_THROW );
xSeekable->seek( 0 );
m_aFilterName = OwnView_Impl::GetFilterNameFromExtentionAndInStream( m_xFactory, OUString(), xStream->getInputStream() );
if ( !m_aFilterName.isEmpty()
&& ( m_aFilterName == "Calc MS Excel 2007 XML" || m_aFilterName == "Impress MS PowerPoint 2007 XML" || m_aFilterName == "MS Word 2007 XML"
|| m_aFilterName == "MS Excel 97 Vorlage/Template" || m_aFilterName == "MS Word 97 Vorlage" ) )
{
uno::Reference< container::XNameAccess > xFilterFactory(
m_xFactory->createInstance("com.sun.star.document.FilterFactory"),
uno::UNO_QUERY_THROW );
OUString aDocServiceName;
uno::Any aFilterAnyData = xFilterFactory->getByName( m_aFilterName );
uno::Sequence< beans::PropertyValue > aFilterData;
if ( aFilterAnyData >>= aFilterData )
{
for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
if ( aFilterData[nInd].Name == "DocumentService" )
aFilterData[nInd].Value >>= aDocServiceName;
}
if ( !aDocServiceName.isEmpty() )
{
// create the model
uno::Sequence< uno::Any > aArguments(1);
aArguments[0] <<= beans::NamedValue( "EmbeddedObject", uno::makeAny( true ));
uno::Reference< util::XCloseable > xDocument( m_xFactory->createInstanceWithArguments( aDocServiceName, aArguments ), uno::UNO_QUERY_THROW );
uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY_THROW );
uno::Reference< document::XStorageBasedDocument > xStorDoc( xDocument, uno::UNO_QUERY_THROW );
// let the model behave as embedded one
uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY_THROW );
uno::Sequence< beans::PropertyValue > aSeq( 1 );
aSeq[0].Name = "SetEmbedded";
aSeq[0].Value <<= true;
xModel->attachResource( OUString(), aSeq );
// load the model from the stream
uno::Sequence< beans::PropertyValue > aArgs( 5 );
aArgs[0].Name = "HierarchicalDocumentName";
aArgs[0].Value <<= m_aEntryName;
aArgs[1].Name = "ReadOnly";
aArgs[1].Value <<= true;
aArgs[2].Name = "FilterName";
aArgs[2].Value <<= m_aFilterName;
aArgs[3].Name = "URL";
aArgs[3].Value <<= OUString( "private:stream" );
aArgs[4].Name = "InputStream";
aArgs[4].Value <<= xStream->getInputStream();
xSeekable->seek( 0 );
xLoadable->load( aArgs );
// the model is successfully loaded, create a new storage and store the model to the storage
uno::Reference< embed::XStorage > xTmpStorage = CreateTemporarySubstorage( aStorageName );
xStorDoc->storeToStorage( xTmpStorage, uno::Sequence< beans::PropertyValue >() );
xDocument->close( true );
uno::Reference< beans::XPropertySet > xStorProps( xTmpStorage, uno::UNO_QUERY_THROW );
OUString aMediaType;
xStorProps->getPropertyValue("MediaType") >>= aMediaType;
xTmpStorage->dispose();
// look for the related embedded object factory
::comphelper::MimeConfigurationHelper aConfigHelper( comphelper::getComponentContext(m_xFactory) );
OUString aEmbedFactory;
if ( !aMediaType.isEmpty() )
aEmbedFactory = aConfigHelper.GetFactoryNameByMediaType( aMediaType );
if ( aEmbedFactory.isEmpty() )
throw uno::RuntimeException();
uno::Reference< uno::XInterface > xFact = m_xFactory->createInstance( aEmbedFactory );
uno::Reference< embed::XEmbedObjectCreator > xEmbCreator( xFact, uno::UNO_QUERY_THROW );
// now the object should be adjusted to become the wrapper
nStep = 1;
uno::Reference< lang::XComponent > xComp( m_xObjectStream, uno::UNO_QUERY_THROW );
xComp->dispose();
m_xObjectStream.clear();
m_nObjectState = -1;
nStep = 2;
aTmpStreamName = MoveToTemporarySubstream();
nStep = 3;
m_xParentStorage->renameElement( aStorageName, m_aEntryName );
nStep = 4;
m_xWrappedObject.set( xEmbCreator->createInstanceInitFromEntry( m_xParentStorage, m_aEntryName, uno::Sequence< beans::PropertyValue >(), uno::Sequence< beans::PropertyValue >() ), uno::UNO_QUERY_THROW );
// remember parent document name to show in the title bar
m_xWrappedObject->setContainerName( m_aContainerName );
bResult = true; // the change is no more revertable
try
{
m_xParentStorage->removeElement( aTmpStreamName );
}
2011-12-09 02:56:30 +09:00
catch( const uno::Exception& )
{
// the success of the removing is not so important
}
}
}
}
2011-12-09 02:56:30 +09:00
catch( const uno::Exception& )
{
// repair the object if necessary
switch( nStep )
{
case 4:
case 3:
if ( !aTmpStreamName.isEmpty() && aTmpStreamName != m_aEntryName )
try
{
if ( m_xParentStorage->hasByName( m_aEntryName ) )
m_xParentStorage->removeElement( m_aEntryName );
m_xParentStorage->renameElement( aTmpStreamName, m_aEntryName );
}
catch ( const uno::Exception& ex )
{
css::uno::Any anyEx = cppu::getCaughtException();
try {
close( true );
2011-12-09 02:56:30 +09:00
} catch( const uno::Exception& ) {}
Many spelling fixes: directories a* - g*. Attempt to clean up most but certainly not all the spelling mistakes that found home in OpenOffice through decades. We could probably blame the international nature of the code but it is somewhat shameful that this wasn't done before. (cherry picked from commit a6efc99d19d533fcf53106b6667bafba4d364370) Conflicts: accessibility/bridge/org/openoffice/java/accessibility/AccessibleTextImpl.java accessibility/bridge/org/openoffice/java/accessibility/Component.java accessibility/bridge/org/openoffice/java/accessibility/Container.java accessibility/bridge/org/openoffice/java/accessibility/DescendantManager.java accessibility/bridge/org/openoffice/java/accessibility/Dialog.java accessibility/bridge/org/openoffice/java/accessibility/Frame.java accessibility/bridge/org/openoffice/java/accessibility/List.java accessibility/bridge/org/openoffice/java/accessibility/Menu.java accessibility/bridge/org/openoffice/java/accessibility/Table.java accessibility/bridge/org/openoffice/java/accessibility/Tree.java accessibility/bridge/org/openoffice/java/accessibility/Window.java accessibility/bridge/source/java/WindowsAccessBridgeAdapter.cxx accessibility/inc/accessibility/extended/AccessibleBrowseBoxBase.hxx accessibility/inc/accessibility/extended/AccessibleGridControlBase.hxx accessibility/inc/accessibility/standard/vclxaccessiblebox.hxx accessibility/source/extended/accessibleiconchoicectrlentry.cxx accessibility/source/extended/accessiblelistboxentry.cxx accessibility/source/extended/accessibletablistbox.cxx accessibility/source/extended/accessibletablistboxtable.cxx accessibility/workben/org/openoffice/accessibility/awb/canvas/Canvas.java accessibility/workben/org/openoffice/accessibility/misc/OfficeConnection.java apple_remote/AppleRemote.m autodoc/inc/ary/cpp/c_gate.hxx autodoc/inc/ary/cpp/cp_ce.hxx autodoc/inc/ary/cpp/cp_def.hxx autodoc/inc/ary/cpp/cp_type.hxx autodoc/inc/ary/doc/d_parametrized.hxx autodoc/inc/ary/idl/i_type.hxx autodoc/source/ary/inc/cross_refs.hxx autodoc/source/ary/inc/sorted_idset.hxx autodoc/source/display/html/outfile.hxx autodoc/source/display/html/pagemake.cxx autodoc/source/display/idl/hi_env.hxx autodoc/source/parser/inc/tokens/tokproct.hxx autodoc/source/parser_i/inc/s2_luidl/tokproct.hxx autodoc/source/parser_i/inc/tokens/tkp2.hxx automation/inc/automation/commtypes.hxx automation/inc/automation/simplecm.hxx automation/source/server/recorder.cxx automation/source/server/recorder.hxx automation/source/server/statemnt.cxx automation/source/simplecm/packethandler.hxx automation/source/simplecm/simplecm.cxx avmedia/source/framework/soundhandler.cxx basegfx/inc/basegfx/range/rangeexpander.hxx basic/inc/basic/sbxdef.hxx basic/source/classes/sbunoobj.cxx basic/source/classes/sbxmod.cxx basic/source/comp/dim.cxx basic/source/comp/exprgen.cxx basic/source/runtime/step1.cxx basic/source/runtime/step2.cxx basic/source/sbx/sbxint.cxx basic/source/uno/namecont.cxx basic/workben/mgrtest.cxx bean/com/sun/star/beans/LocalOfficeConnection.java bean/com/sun/star/beans/LocalOfficeWindow.java bean/com/sun/star/comp/beans/LocalOfficeConnection.java bean/com/sun/star/comp/beans/LocalOfficeWindow.java bean/com/sun/star/comp/beans/OOoBean.java bridges/inc/bridges/cpp_uno/bridge.hxx bridges/source/cpp_uno/cc50_solaris_intel/cpp2uno.cxx bridges/source/cpp_uno/cc50_solaris_intel/except.cxx bridges/source/cpp_uno/cc50_solaris_intel/uno2cpp.cxx bridges/source/cpp_uno/cc50_solaris_sparc/cpp2uno.cxx bridges/source/cpp_uno/cc50_solaris_sparc/except.cxx bridges/source/cpp_uno/cc50_solaris_sparc/uno2cpp.cxx bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx bridges/source/cpp_uno/gcc3_macosx_powerpc/cpp2uno.cxx bridges/source/cpp_uno/gcc3_macosx_x86-64/uno2cpp.cxx bridges/source/cpp_uno/gcc3_netbsd_intel/cpp2uno.cxx bridges/source/cpp_uno/gcc3_netbsd_intel/except.cxx bridges/source/cpp_uno/gcc3_netbsd_intel/uno2cpp.cxx bridges/source/cpp_uno/gcc3_os2_intel/cpp2uno.cxx bridges/source/cpp_uno/gcc3_os2_intel/except.cxx bridges/source/cpp_uno/gcc3_os2_intel/uno2cpp.cxx bridges/source/cpp_uno/mingw_x86-64/uno2cpp.cxx bridges/source/cpp_uno/msvc_win32_intel/except.cxx bridges/source/cpp_uno/s5abi_macosx_x86-64/except.cxx bridges/source/cpp_uno/shared/component.cxx bridges/source/jni_uno/jni_base.h bridges/source/jni_uno/jni_bridge.cxx bridges/source/jni_uno/jni_java2uno.cxx bridges/source/jni_uno/jni_uno2java.cxx canvas/inc/canvas/base/doublebitmapbase.hxx canvas/inc/canvas/base/floatbitmapbase.hxx canvas/inc/canvas/base/integerbitmapbase.hxx canvas/source/cairo/cairo_canvasbitmap.cxx canvas/source/cairo/cairo_textlayout.cxx chart2/source/controller/dialogs/ObjectNameProvider.cxx chart2/source/view/diagram/VDiagram.cxx chart2/source/view/main/ChartView.cxx cli_ure/source/native/makefile.mk cli_ure/source/uno_bridge/cli_data.cxx codemaker/source/javamaker/javatype.cxx comphelper/inc/comphelper/componentcontext.hxx comphelper/inc/comphelper/interaction.hxx comphelper/inc/comphelper/locale.hxx comphelper/inc/comphelper/string.hxx comphelper/source/container/embeddedobjectcontainer.cxx comphelper/source/misc/accessiblecontexthelper.cxx comphelper/source/misc/asyncnotification.cxx comphelper/source/misc/locale.cxx comphelper/source/misc/mediadescriptor.cxx comphelper/source/misc/numberedcollection.cxx comphelper/source/misc/proxyaggregation.cxx comphelper/source/misc/scopeguard.cxx comphelper/source/misc/sequenceashashmap.cxx configure.in connectivity/source/commontools/parameters.cxx connectivity/source/drivers/dbase/DTable.cxx connectivity/source/drivers/evoab2/NStatement.cxx connectivity/source/drivers/file/FPreparedStatement.cxx connectivity/source/drivers/jdbc/DatabaseMetaData.cxx connectivity/source/inc/flat/ETable.hxx connectivity/source/parse/sqlnode.cxx cosv/inc/cosv/persist.hxx cosv/inc/cosv/ploc_dir.hxx cosv/inc/cosv/tpl/dyn.hxx cppu/source/LogBridge/LogBridge.cxx cppu/source/uno/data.cxx cppuhelper/source/bootstrap.cxx cppuhelper/source/component_context.cxx cppuhelper/source/propshlp.cxx cppuhelper/source/servicefactory.cxx cpputools/source/registercomponent/registercomponent.cxx cui/source/customize/acccfg.cxx cui/source/dialogs/about.cxx cui/source/dialogs/commonlingui.hxx cui/source/dialogs/showcols.cxx cui/source/inc/cuihyperdlg.hxx cui/source/inc/cuitabline.hxx cui/source/options/optsave.src cui/source/tabpages/tpline.cxx cui/source/tabpages/transfrm.cxx dbaccess/source/core/api/CacheSet.cxx dbaccess/source/core/api/KeySet.cxx dbaccess/source/core/api/RowSet.cxx dbaccess/source/core/api/RowSet.hxx dbaccess/source/core/api/RowSetBase.cxx dbaccess/source/core/api/RowSetBase.hxx dbaccess/source/core/api/RowSetCache.cxx dbaccess/source/core/api/querycomposer.cxx dbaccess/source/ext/adabas/Acomponentmodule.hxx dbaccess/source/ui/app/AppControllerDnD.cxx dbaccess/source/ui/app/AppDetailView.cxx dbaccess/source/ui/browser/brwctrlr.cxx dbaccess/source/ui/browser/sbagrid.cxx dbaccess/source/ui/browser/unodatbr.cxx dbaccess/source/ui/dlg/AdabasStat.hxx dbaccess/source/ui/dlg/UserAdmin.cxx dbaccess/source/ui/dlg/directsql.cxx dbaccess/source/ui/dlg/generalpage.hxx dbaccess/source/ui/dlg/tablespage.cxx dbaccess/source/ui/inc/JoinTableView.hxx dbaccess/source/ui/inc/TableController.hxx dbaccess/source/ui/inc/UITools.hxx dbaccess/source/ui/inc/brwctrlr.hxx dbaccess/source/ui/inc/datasourcemap.hxx dbaccess/source/ui/querydesign/JoinTableView.cxx dbaccess/source/ui/querydesign/QueryDesignView.cxx dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx dbaccess/source/ui/querydesign/TableWindow.cxx dbaccess/source/ui/querydesign/querycontroller.cxx dbaccess/source/ui/relationdesign/RelationTableView.cxx dbaccess/source/ui/tabledesign/TableController.cxx desktop/source/app/app.cxx desktop/source/app/appinit.cxx desktop/source/app/langselect.cxx desktop/source/app/officeipcthread.cxx desktop/source/deployment/manager/dp_extensionmanager.cxx desktop/source/deployment/misc/dp_misc.cxx desktop/source/deployment/misc/dp_resource.cxx desktop/source/deployment/registry/dp_backend.cxx desktop/source/deployment/registry/package/dp_package.cxx desktop/source/migration/cfgfilter.cxx desktop/source/migration/migration.cxx desktop/source/splash/splash.cxx desktop/win32/source/QuickStart/QuickStart.cpp desktop/win32/source/setup/setup.cpp drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx dtrans/source/win32/clipb/MtaOleClipb.hxx dtrans/source/win32/clipb/WinClipbImpl.cxx editeng/source/editeng/editview.cxx editeng/source/editeng/impedit2.cxx editeng/source/editeng/impedit3.cxx editeng/source/editeng/impedit4.cxx editeng/source/editeng/textconv.hxx editeng/source/misc/unolingu.cxx embeddedobj/source/commonembedding/persistence.cxx embeddedobj/source/general/dummyobject.cxx embeddedobj/source/msole/olecomponent.cxx embeddedobj/source/msole/olepersist.cxx embeddedobj/test/Container1/NativeView.java extensions/source/bibliography/framectr.cxx extensions/source/macosx/spotlight/OOoContentDataParser.m extensions/source/macosx/spotlight/unzip.h extensions/source/macosx/spotlight/unzip.m extensions/source/oooimprovement/myconfigurationhelper.hxx extensions/source/propctrlr/eventhandler.cxx extensions/source/propctrlr/formcomponenthandler.cxx extensions/source/propctrlr/pcrcomponentcontext.hxx extensions/source/scanner/twain.cxx extensions/source/update/check/updatecheckconfig.hxx external/mingwheaders/mingw_atl_headers.patch extras/source/misc_config/wizard/web/layouts/source.xml.xsl fileaccess/source/FileAccess.cxx filter/inc/filter/msfilter/msocximex.hxx filter/inc/filter/msfilter/svxmsbas.hxx filter/qa/complex/filter/detection/typeDetection/Helper.java filter/source/config/cache/basecontainer.cxx filter/source/config/cache/cacheitem.hxx filter/source/config/cache/contenthandlerfactory.cxx filter/source/config/cache/filtercache.cxx filter/source/config/cache/filtercache.hxx filter/source/config/cache/filterfactory.cxx filter/source/config/cache/frameloaderfactory.cxx filter/source/config/cache/querytokenizer.hxx filter/source/config/cache/typedetection.cxx filter/source/config/cache/typedetection.hxx filter/source/config/cache/versions.hxx filter/source/config/fragments/makefile.mk filter/source/config/tools/merge/pyAltFCFGMerge filter/source/flash/swfwriter.cxx filter/source/flash/swfwriter1.cxx filter/source/msfilter/msdffimp.cxx filter/source/msfilter/msocximex.cxx filter/source/msfilter/msvbahelper.cxx filter/source/msfilter/svxmsbas.cxx filter/source/xmlfilterdetect/filterdetect.cxx filter/source/xslt/import/uof2/uof2odf.xsl filter/source/xslt/odf2xhtml/export/xhtml/body.xsl filter/source/xsltfilter/com/sun/star/comp/xsltfilter/Base64.java forms/source/xforms/convert.hxx forms/source/xforms/model.cxx fpicker/source/aqua/SalAquaFilePicker.mm fpicker/source/office/fpinteraction.cxx fpicker/source/unx/gnome/SalGtkFolderPicker.cxx fpicker/source/unx/kde4/KDE4FilePicker.cxx fpicker/source/win32/filepicker/PreviewCtrl.cxx fpicker/source/win32/filepicker/PreviewCtrl.hxx fpicker/source/win32/filepicker/VistaFilePicker.cxx fpicker/source/win32/filepicker/VistaFilePickerImpl.hxx fpicker/source/win32/filepicker/helppopupwindow.hxx fpicker/source/win32/folderpicker/MtaFop.hxx framework/inc/classes/droptargetlistener.hxx framework/inc/classes/filtercache.hxx framework/inc/classes/filtercachedata.hxx framework/inc/classes/protocolhandlercache.hxx framework/inc/classes/servicemanager.hxx framework/inc/commands.h framework/inc/dispatch/basedispatcher.hxx framework/inc/dispatch/blankdispatcher.hxx framework/inc/dispatch/closedispatcher.hxx framework/inc/dispatch/createdispatcher.hxx framework/inc/dispatch/dispatchprovider.hxx framework/inc/dispatch/helpagentdispatcher.hxx framework/inc/dispatch/mailtodispatcher.hxx framework/inc/dispatch/menudispatcher.hxx framework/inc/dispatch/oxt_handler.hxx framework/inc/dispatch/popupmenudispatcher.hxx framework/inc/dispatch/selfdispatcher.hxx framework/inc/dispatch/servicehandler.hxx framework/inc/dispatch/startmoduledispatcher.hxx framework/inc/dispatch/systemexec.hxx framework/inc/helper/fixeddocumentproperties.hxx framework/inc/helper/ocomponentaccess.hxx framework/inc/helper/oframes.hxx framework/inc/helper/otasksenumeration.hxx framework/inc/helper/persistentwindowstate.hxx framework/inc/helper/statusindicator.hxx framework/inc/helper/statusindicatorfactory.hxx framework/inc/helper/tagwindowasmodified.hxx framework/inc/helper/titlebarupdate.hxx framework/inc/helper/vclstatusindicator.hxx framework/inc/interaction/quietinteraction.hxx framework/inc/jobs/helponstartup.hxx framework/inc/jobs/job.hxx framework/inc/jobs/jobdata.hxx framework/inc/jobs/jobexecutor.hxx framework/inc/loadstate.h framework/inc/macros/debug/assertion.hxx framework/inc/macros/debug/event.hxx framework/inc/macros/debug/filterdbg.hxx framework/inc/macros/debug/memorymeasure.hxx framework/inc/macros/debug/timemeasure.hxx framework/inc/macros/xserviceinfo.hxx framework/inc/queries.h framework/inc/recording/dispatchrecordersupplier.hxx framework/inc/services/autorecovery.hxx framework/inc/services/backingcomp.hxx framework/inc/services/contenthandlerfactory.hxx framework/inc/services/desktop.hxx framework/inc/services/detectorfactory.hxx framework/inc/services/frame.hxx framework/inc/services/frameloaderfactory.hxx framework/inc/services/layoutmanager.hxx framework/inc/services/license.hxx framework/inc/services/logindialog.hxx framework/inc/services/modulemanager.hxx framework/inc/services/pathsettings.hxx framework/inc/services/pluginframe.hxx framework/inc/services/substitutepathvars.hxx framework/inc/services/task.hxx framework/inc/services/taskcreatorsrv.hxx framework/inc/stdtypes.h framework/inc/threadhelp/fairrwlock.hxx framework/inc/threadhelp/inoncopyable.h framework/inc/threadhelp/itransactionmanager.h framework/inc/threadhelp/lockhelper.hxx framework/inc/threadhelp/readguard.hxx framework/inc/threadhelp/resetableguard.hxx framework/inc/threadhelp/transactionguard.hxx framework/inc/threadhelp/writeguard.hxx framework/inc/uifactory/uielementfactorymanager.hxx framework/inc/xml/acceleratorconfigurationreader.hxx framework/qa/complex/dispatches/checkdispatchapi.java framework/qa/complex/framework/autosave/AutoSave.java framework/qa/complex/framework/autosave/Protocol.java framework/qa/complex/framework/recovery/RecoveryTest.java framework/qa/complex/loadAllDocuments/StreamSimulator.java framework/source/accelerators/acceleratorconfiguration.cxx framework/source/accelerators/acceleratorexecute.cxx framework/source/accelerators/acceleratorexecute.hxx framework/source/accelerators/keymapping.cxx framework/source/accelerators/presethandler.cxx framework/source/application/framework.cxx framework/source/application/login.cxx framework/source/classes/framecontainer.cxx framework/source/classes/menumanager.cxx framework/source/classes/taskcreator.cxx framework/source/dispatch/closedispatcher.cxx framework/source/dispatch/dispatchprovider.cxx framework/source/dispatch/helpagentdispatcher.cxx framework/source/dispatch/interceptionhelper.cxx framework/source/dispatch/mailtodispatcher.cxx framework/source/dispatch/menudispatcher.cxx framework/source/dispatch/oxt_handler.cxx framework/source/dispatch/servicehandler.cxx framework/source/fwe/classes/framelistanalyzer.cxx framework/source/fwe/dispatch/interaction.cxx framework/source/fwe/helper/titlehelper.cxx framework/source/fwe/helper/undomanagerhelper.cxx framework/source/fwe/xml/eventsdocumenthandler.cxx framework/source/fwe/xml/statusbardocumenthandler.cxx framework/source/fwe/xml/toolboxdocumenthandler.cxx framework/source/fwi/classes/protocolhandlercache.cxx framework/source/fwi/threadhelp/lockhelper.cxx framework/source/fwi/threadhelp/transactionmanager.cxx framework/source/helper/persistentwindowstate.cxx framework/source/helper/statusindicatorfactory.cxx framework/source/helper/vclstatusindicator.cxx framework/source/inc/accelerators/acceleratorcache.hxx framework/source/inc/accelerators/acceleratorconfiguration.hxx framework/source/inc/accelerators/presethandler.hxx framework/source/inc/accelerators/storageholder.hxx framework/source/inc/loadenv/actionlockguard.hxx framework/source/inc/loadenv/loadenv.hxx framework/source/inc/loadenv/loadenvexception.hxx framework/source/inc/pattern/frame.hxx framework/source/inc/pattern/storages.hxx framework/source/inc/pattern/window.hxx framework/source/jobs/helponstartup.cxx framework/source/jobs/job.cxx framework/source/jobs/jobdata.cxx framework/source/jobs/jobdispatch.cxx framework/source/jobs/jobresult.cxx framework/source/jobs/joburl.cxx framework/source/jobs/shelljob.cxx framework/source/loadenv/loadenv.cxx framework/source/services/autorecovery.cxx framework/source/services/backingwindow.cxx framework/source/services/desktop.cxx framework/source/services/frame.cxx framework/source/services/modulemanager.cxx framework/source/services/pathsettings.cxx framework/source/services/substitutepathvars.cxx framework/source/uiconfiguration/moduleuicfgsupplier.cxx framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx framework/source/uiconfiguration/uicategorydescription.cxx framework/source/uiconfiguration/uiconfigurationmanagerimpl.cxx framework/source/uiconfiguration/windowstateconfiguration.cxx framework/source/uielement/uicommanddescription.cxx framework/source/unotypes/fwk.xml framework/source/xml/imagesdocumenthandler.cxx framework/test/test.cxx framework/test/test_componentenumeration.bas framework/test/test_statusindicatorfactory.bas framework/test/threadtest.cxx framework/test/threadtest/threadtest.cxx framework/test/typecfg/cfgview.cxx framework/test/typecfg/xml2xcd.cxx include/basegfx/polygon/b2dpolygon.hxx include/canvas/base/graphicdevicebase.hxx include/canvas/canvastools.hxx include/comphelper/configurationhelper.hxx include/comphelper/embeddedobjectcontainer.hxx include/comphelper/propagg.hxx include/comphelper/sequenceashashmap.hxx include/connectivity/sqlerror.hxx include/connectivity/sqlnode.hxx include/cppuhelper/propshlp.hxx include/editeng/AccessibleContextBase.hxx include/framework/framelistanalyzer.hxx sfx2/source/dialog/backingcomp.cxx vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx Change-Id: I2618bf83c0e30f68f23ff25f6eb466df04d34c6d
2014-04-29 19:05:05 +00:00
m_xParentStorage->dispose(); // ??? the storage has information loss, it should be closed without committing!
throw css::lang::WrappedTargetRuntimeException( ex.Message,
nullptr, anyEx ); // the repairing is not possible
}
[[fallthrough]];
case 2:
try
{
m_xObjectStream = m_xParentStorage->openStreamElement( m_aEntryName, m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE );
m_nObjectState = embed::EmbedStates::LOADED;
}
catch( const uno::Exception& ex )
{
css::uno::Any anyEx = cppu::getCaughtException();
try {
close( true );
2011-12-09 02:56:30 +09:00
} catch( const uno::Exception& ) {}
throw css::lang::WrappedTargetRuntimeException( ex.Message,
nullptr, anyEx ); // the repairing is not possible
}
[[fallthrough]];
case 1:
case 0:
if ( !aStorageName.isEmpty() )
try {
m_xParentStorage->removeElement( aStorageName );
} catch( const uno::Exception& ) { SAL_WARN( "embeddedobj.ole", "Can not remove temporary storage!" ); }
break;
}
}
if ( bResult )
{
// the conversion was done successfully, now the additional initializations should happen
MoveListeners();
m_xWrappedObject->setClientSite( m_xClientSite );
if ( m_xParent.is() )
{
uno::Reference< container::XChild > xChild( m_xWrappedObject, uno::UNO_QUERY );
if ( xChild.is() )
xChild->setParent( m_xParent );
}
}
return bResult;
}
2003-11-13 16:01:50 +00:00
void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 nNewState )
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->changeState( nNewState );
return;
}
// end wrapping related part ====================
::osl::ResettableMutexGuard aGuard( m_aMutex );
2003-11-13 16:01:50 +00:00
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object has no persistence!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
// in case the object is already in requested state
if ( m_nObjectState == nNewState )
return;
#ifdef _WIN32
if ( m_pOleComponent )
2003-11-13 16:01:50 +00:00
{
if ( m_nTargetState != -1 )
{
// means that the object is currently trying to reach the target state
throw embed::StateChangeInProgressException( OUString(),
uno::Reference< uno::XInterface >(),
m_nTargetState );
}
TargetStateControl_Impl aControl( m_nTargetState, nNewState );
// TODO: additional verbs can be a problem, since nobody knows how the object
// will behave after activation
2003-11-13 16:01:50 +00:00
sal_Int32 nOldState = m_nObjectState;
aGuard.clear();
StateChangeNotification_Impl( true, nOldState, nNewState );
aGuard.reset();
2003-11-13 16:01:50 +00:00
try
2003-11-13 16:01:50 +00:00
{
if ( nNewState == embed::EmbedStates::LOADED )
{
// This means just closing of the current object
// If component can not be closed the object stays in loaded state
// and it holds reference to "incomplete" component
// If the object is switched to running state later
// the component will become "complete"
// the loaded state must be set before, because of notifications!
m_nObjectState = nNewState;
{
VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController );
m_pOleComponent->CloseObject();
}
aGuard.clear();
StateChangeNotification_Impl( false, nOldState, m_nObjectState );
aGuard.reset();
}
else if ( nNewState == embed::EmbedStates::RUNNING || nNewState == embed::EmbedStates::ACTIVE )
{
if ( m_nObjectState == embed::EmbedStates::LOADED )
{
// if the target object is in loaded state and a different state is specified
// as a new one the object first must be switched to running state.
// the component can exist already in nonrunning state
// it can be created during loading to detect type of object
CreateOleComponentAndLoad_Impl( m_pOleComponent );
SwitchComponentToRunningState_Impl();
m_nObjectState = embed::EmbedStates::RUNNING;
aGuard.clear();
StateChangeNotification_Impl( false, nOldState, m_nObjectState );
aGuard.reset();
if ( m_pOleComponent && m_bHasSizeToSet )
{
aGuard.clear();
try {
m_pOleComponent->SetExtent( m_aSizeToSet, m_nAspectToSet );
m_bHasSizeToSet = false;
}
2011-12-09 02:56:30 +09:00
catch( const uno::Exception& ) {}
aGuard.reset();
}
if ( m_nObjectState == nNewState )
return;
}
// so now the object is either switched from Active to Running state or viceversa
// the notification about object state change will be done asynchronously
if ( m_nObjectState == embed::EmbedStates::RUNNING && nNewState == embed::EmbedStates::ACTIVE )
{
// execute OPEN verb, if object does not reach active state it is an object's problem
aGuard.clear();
m_pOleComponent->ExecuteVerb( embed::EmbedVerbs::MS_OLEVERB_OPEN );
aGuard.reset();
// some objects do not allow to set the size even in running state
if ( m_pOleComponent && m_bHasSizeToSet )
{
aGuard.clear();
try {
m_pOleComponent->SetExtent( m_aSizeToSet, m_nAspectToSet );
m_bHasSizeToSet = false;
}
catch( uno::Exception& ) {}
aGuard.reset();
}
m_nObjectState = nNewState;
}
else if ( m_nObjectState == embed::EmbedStates::ACTIVE && nNewState == embed::EmbedStates::RUNNING )
{
aGuard.clear();
m_pOleComponent->CloseObject();
m_pOleComponent->RunObject(); // Should not fail, the object already was active
aGuard.reset();
m_nObjectState = nNewState;
}
else
{
throw embed::UnreachableStateException();
}
}
else
throw embed::UnreachableStateException();
2003-11-13 16:01:50 +00:00
}
catch( uno::Exception& )
2003-11-13 16:01:50 +00:00
{
aGuard.clear();
StateChangeNotification_Impl( false, nOldState, m_nObjectState );
throw;
2003-11-13 16:01:50 +00:00
}
}
2003-12-15 14:37:44 +00:00
else
#endif
{
2003-12-15 14:37:44 +00:00
throw embed::UnreachableStateException();
}
2003-11-13 16:01:50 +00:00
}
2003-11-13 16:01:50 +00:00
uno::Sequence< sal_Int32 > SAL_CALL OleEmbeddedObject::getReachableStates()
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
return xWrappedObject->getReachableStates();
}
// end wrapping related part ====================
2003-11-13 16:01:50 +00:00
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object has no persistence!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
#ifdef _WIN32
if ( m_pOleComponent )
2003-11-13 16:01:50 +00:00
{
if ( m_nObjectState == embed::EmbedStates::LOADED )
{
// the list of supported verbs can be retrieved only when object is in running state
throw embed::NeedsRunningStateException(); // TODO:
}
2003-12-15 14:37:44 +00:00
// the list of states can only be guessed based on standard verbs,
// since there is no way to detect what additional verbs do
return GetReachableStatesList_Impl( m_pOleComponent->GetVerbList() );
}
else
2003-12-15 14:37:44 +00:00
#endif
{
return uno::Sequence< sal_Int32 >();
}
2003-11-13 16:01:50 +00:00
}
2003-11-13 16:01:50 +00:00
sal_Int32 SAL_CALL OleEmbeddedObject::getCurrentState()
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
return xWrappedObject->getCurrentState();
}
// end wrapping related part ====================
2003-11-13 16:01:50 +00:00
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object has no persistence!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
// TODO: Shouldn't we ask object? ( I guess no )
return m_nObjectState;
}
2010-05-26 15:38:21 +02:00
namespace
{
bool lcl_CopyStream(const uno::Reference<io::XInputStream>& xIn, const uno::Reference<io::XOutputStream>& xOut, sal_Int32 nMaxCopy = SAL_MAX_INT32)
2010-05-26 15:38:21 +02:00
{
if (nMaxCopy <= 0)
return false;
2010-05-26 15:38:21 +02:00
const sal_Int32 nChunkSize = 4096;
uno::Sequence< sal_Int8 > aData(nChunkSize);
sal_Int32 nTotalRead = 0;
sal_Int32 nRead;
do
{
if (nTotalRead + aData.getLength() > nMaxCopy)
{
aData.realloc(nMaxCopy - nTotalRead);
}
nRead = xIn->readBytes(aData, aData.getLength());
2010-05-26 15:38:21 +02:00
nTotalRead += nRead;
xOut->writeBytes(aData);
} while (nRead == nChunkSize && nTotalRead <= nMaxCopy);
2010-05-26 15:38:21 +02:00
return nTotalRead != 0;
}
uno::Reference < io::XStream > lcl_GetExtractedStream( OUString& rUrl,
const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory,
const css::uno::Reference< css::io::XStream >& xObjectStream )
2010-05-26 15:38:21 +02:00
{
uno::Reference <beans::XPropertySet> xNativeTempFile(
io::TempFile::create(comphelper::getComponentContext(xFactory)),
uno::UNO_QUERY_THROW);
2010-05-26 15:38:21 +02:00
uno::Reference < io::XStream > xStream(xNativeTempFile, uno::UNO_QUERY_THROW);
uno::Sequence< uno::Any > aArgs( 2 );
aArgs[0] <<= xObjectStream;
aArgs[1] <<= true; // do not create copy
2010-05-26 15:38:21 +02:00
uno::Reference< container::XNameContainer > xNameContainer(
xFactory->createInstanceWithArguments(
"com.sun.star.embed.OLESimpleStorage",
2010-05-26 15:38:21 +02:00
aArgs ), uno::UNO_QUERY_THROW );
//various stream names that can contain the real document contents for
//this object in a straightforward direct way
static const OUStringLiteral aStreamNames[] =
{
"CONTENTS",
"Package",
"EmbeddedOdf",
"WordDocument",
"Workbook",
"PowerPoint Document"
};
bool bCopied = false;
for (size_t i = 0; i < SAL_N_ELEMENTS(aStreamNames) && !bCopied; ++i)
{
uno::Reference<io::XStream> xEmbeddedFile;
try
{
xNameContainer->getByName(aStreamNames[i]) >>= xEmbeddedFile;
}
catch (const container::NoSuchElementException&)
{
// ignore
}
bCopied = xEmbeddedFile.is() && lcl_CopyStream(xEmbeddedFile->getInputStream(), xStream->getOutputStream());
}
2010-05-26 15:38:21 +02:00
if (!bCopied)
{
uno::Reference< io::XStream > xOle10Native;
try
{
xNameContainer->getByName("\1Ole10Native") >>= xOle10Native;
}
catch (container::NoSuchElementException const&)
{
// ignore
}
if (xOle10Native.is())
{
const uno::Reference<io::XInputStream> xIn = xOle10Native->getInputStream();
xIn->skipBytes(4); //size of the entire stream minus 4 bytes
xIn->skipBytes(2); //word that represent the directory type
uno::Sequence< sal_Int8 > aData(1);
sal_Int32 nRead;
do
{
nRead = xIn->readBytes(aData, 1);
} while (nRead == 1 && aData[0] != 0); // file name plus extension of the attachment null terminated
do
{
nRead = xIn->readBytes(aData, 1);
} while (nRead == 1 && aData[0] != 0); // Fully Qualified File name with extension
xIn->skipBytes(1); //single byte
xIn->skipBytes(1); //single byte
xIn->skipBytes(2); //Word that represent the directory type
xIn->skipBytes(4); //len of string
do
{
nRead = xIn->readBytes(aData, 1);
} while (nRead == 1 && aData[0] != 0); // Actual string representing the file path
uno::Sequence< sal_Int8 > aLenData(4);
xIn->readBytes(aLenData, 4); //len of attachment
sal_uInt32 nLen = static_cast<sal_uInt32>(
(aLenData[0] & 0xFF) |
((aLenData[1] & 0xFF) << 8) |
((aLenData[2] & 0xFF) << 16) |
((aLenData[3] & 0xFF) << 24));
bCopied = lcl_CopyStream(xIn, xStream->getOutputStream(), nLen);
}
}
2010-05-26 15:38:21 +02:00
uno::Reference< io::XSeekable > xSeekableStor(xObjectStream, uno::UNO_QUERY);
if (xSeekableStor.is())
xSeekableStor->seek(0);
if (!bCopied)
bCopied = lcl_CopyStream(xObjectStream->getInputStream(), xStream->getOutputStream());
if (bCopied)
{
xNativeTempFile->setPropertyValue("RemoveFile",
uno::makeAny(false));
uno::Any aUrl = xNativeTempFile->getPropertyValue("Uri");
aUrl >>= rUrl;
2010-05-26 15:38:21 +02:00
xNativeTempFile.clear();
2010-05-26 15:38:21 +02:00
uno::Reference < ucb::XSimpleFileAccess3 > xSimpleFileAccess(
ucb::SimpleFileAccess::create( comphelper::getComponentContext(xFactory) ) );
2010-05-26 15:38:21 +02:00
xSimpleFileAccess->setReadOnly(rUrl, true);
2010-05-26 15:38:21 +02:00
}
else
{
xNativeTempFile->setPropertyValue("RemoveFile",
uno::makeAny(true));
2010-05-26 15:38:21 +02:00
}
return xStream;
}
//Dump the objects content to a tempfile, just the "CONTENTS" stream if
//there is one for non-compound documents, otherwise the whole content.
//On success a file is returned which must be removed by the caller
OUString lcl_ExtractObject(const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory,
const css::uno::Reference< css::io::XStream >& xObjectStream)
{
OUString sUrl;
// the solution is only active for Unix systems
#ifndef _WIN32
lcl_GetExtractedStream(sUrl, xFactory, xObjectStream);
2012-04-15 15:52:16 +02:00
#else
(void) xFactory;
(void) xObjectStream;
2010-05-26 15:38:21 +02:00
#endif
return sUrl;
}
uno::Reference < io::XStream > lcl_ExtractObjectStream( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory,
const css::uno::Reference< css::io::XStream >& xObjectStream )
{
OUString sUrl;
return lcl_GetExtractedStream( sUrl, xFactory, xObjectStream );
}
2010-05-26 15:38:21 +02:00
}
2003-11-13 16:01:50 +00:00
void SAL_CALL OleEmbeddedObject::doVerb( sal_Int32 nVerbID )
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->doVerb(embed::EmbedVerbs::MS_OLEVERB_OPEN); // open content in the window not in-place
return;
}
// end wrapping related part ====================
::osl::ResettableMutexGuard aGuard( m_aMutex );
2003-11-13 16:01:50 +00:00
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object has no persistence!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
#ifdef _WIN32
if ( m_pOleComponent )
2003-11-13 16:01:50 +00:00
{
sal_Int32 nOldState = m_nObjectState;
2003-11-13 16:01:50 +00:00
// TODO/LATER detect target state here and do a notification
// StateChangeNotification_Impl( sal_True, nOldState, nNewState );
if ( m_nObjectState == embed::EmbedStates::LOADED )
{
// if the target object is in loaded state
// it must be switched to running state to execute verb
aGuard.clear();
changeState( embed::EmbedStates::RUNNING );
aGuard.reset();
}
try {
if ( !m_pOleComponent )
throw uno::RuntimeException();
// ==== the STAMPIT related solution =============================
m_aVerbExecutionController.StartControlExecution();
m_pOleComponent->ExecuteVerb( nVerbID );
m_pOleComponent->SetHostName( OUString(), m_aContainerName );
// ==== the STAMPIT related solution =============================
bool bModifiedOnExecution = m_aVerbExecutionController.EndControlExecution_WasModified();
// this workaround is implemented for STAMPIT object
// if object was modified during verb execution it is saved here
if ( bModifiedOnExecution && m_pOleComponent->IsDirty() )
SaveObject_Impl();
}
catch( uno::Exception& )
{
// ==== the STAMPIT related solution =============================
m_aVerbExecutionController.EndControlExecution_WasModified();
aGuard.clear();
StateChangeNotification_Impl( false, nOldState, m_nObjectState );
throw;
}
}
else
2003-12-15 14:37:44 +00:00
#endif
{
if ( nVerbID != -9 )
{
throw embed::UnreachableStateException();
}
// the workaround verb to show the object in case no server is available
// if it is possible, the object will be converted to OOo format
if ( !m_bTriedConversion )
{
m_bTriedConversion = true;
if ( TryToConvertToOOo( m_xObjectStream ) )
{
changeState( embed::EmbedStates::ACTIVE );
return;
}
}
if ( !m_xOwnView.is() && m_xObjectStream.is() && m_aFilterName != "Text" )
{
try {
uno::Reference< io::XSeekable > xSeekable( m_xObjectStream, uno::UNO_QUERY );
if ( xSeekable.is() )
xSeekable->seek( 0 );
m_xOwnView = new OwnView_Impl( m_xFactory, m_xObjectStream->getInputStream() );
}
catch( uno::RuntimeException& )
{
throw;
}
catch (uno::Exception const&)
2010-05-26 15:38:21 +02:00
{
TOOLS_WARN_EXCEPTION("embeddedobj.ole", "OleEmbeddedObject::doVerb: -9 fallback path:");
}
}
2010-05-26 15:38:21 +02:00
// it may be the OLE Storage, try to extract stream
if ( !m_xOwnView.is() && m_xObjectStream.is() && m_aFilterName == "Text" )
{
uno::Reference< io::XStream > xStream = lcl_ExtractObjectStream( m_xFactory, m_xObjectStream );
if ( TryToConvertToOOo( xStream ) )
{
changeState( embed::EmbedStates::ACTIVE );
return;
2010-05-26 15:38:21 +02:00
}
}
if (!m_xOwnView.is() || !m_xOwnView->Open())
2010-05-26 15:38:21 +02:00
{
//Make a RO copy and see if the OS can find something to at
//least display the content for us
if (m_aTempDumpURL.isEmpty())
m_aTempDumpURL = lcl_ExtractObject(m_xFactory, m_xObjectStream);
if (m_aTempDumpURL.isEmpty())
throw embed::UnreachableStateException();
uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute(
css::system::SystemShellExecute::create(comphelper::getComponentContext(m_xFactory)) );
xSystemShellExecute->execute(m_aTempDumpURL, OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY);
2010-05-26 15:38:21 +02:00
}
}
2003-11-13 16:01:50 +00:00
}
uno::Sequence< embed::VerbDescriptor > SAL_CALL OleEmbeddedObject::getSupportedVerbs()
2003-11-13 16:01:50 +00:00
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
return xWrappedObject->getSupportedVerbs();
}
// end wrapping related part ====================
2003-11-13 16:01:50 +00:00
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object has no persistence!",
static_cast< ::cppu::OWeakObject* >(this) );
#ifdef _WIN32
if ( m_pOleComponent )
2003-11-13 16:01:50 +00:00
{
// registry could be used in this case
// if ( m_nObjectState == embed::EmbedStates::LOADED )
// {
// // the list of supported verbs can be retrieved only when object is in running state
// throw embed::NeedsRunningStateException(); // TODO:
// }
2003-12-15 14:37:44 +00:00
return m_pOleComponent->GetVerbList();
}
else
2003-12-15 14:37:44 +00:00
#endif
{
return uno::Sequence< embed::VerbDescriptor >();
}
2003-11-13 16:01:50 +00:00
}
2003-11-13 16:01:50 +00:00
void SAL_CALL OleEmbeddedObject::setClientSite(
const uno::Reference< embed::XEmbeddedClient >& xClient )
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->setClientSite( xClient );
return;
}
// end wrapping related part ====================
2003-11-13 16:01:50 +00:00
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_xClientSite != xClient)
{
if ( m_nObjectState != embed::EmbedStates::LOADED && m_nObjectState != embed::EmbedStates::RUNNING )
throw embed::WrongStateException(
"The client site can not be set currently!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
m_xClientSite = xClient;
}
2003-11-13 16:01:50 +00:00
}
2003-11-13 16:01:50 +00:00
uno::Reference< embed::XEmbeddedClient > SAL_CALL OleEmbeddedObject::getClientSite()
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
return xWrappedObject->getClientSite();
}
// end wrapping related part ====================
2003-11-13 16:01:50 +00:00
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object has no persistence!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
return m_xClientSite;
}
2003-11-13 16:01:50 +00:00
void SAL_CALL OleEmbeddedObject::update()
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->update();
return;
}
// end wrapping related part ====================
2003-11-13 16:01:50 +00:00
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object has no persistence!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
if ( m_nUpdateMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE )
2003-11-13 16:01:50 +00:00
{
// TODO: update view representation
}
else
{
// the object must be up to date
SAL_WARN_IF( m_nUpdateMode != embed::EmbedUpdateModes::ALWAYS_UPDATE, "embeddedobj.ole", "Unknown update mode!" );
2003-11-13 16:01:50 +00:00
}
}
2003-11-13 16:01:50 +00:00
void SAL_CALL OleEmbeddedObject::setUpdateMode( sal_Int32 nMode )
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->setUpdateMode( nMode );
return;
}
// end wrapping related part ====================
2003-11-13 16:01:50 +00:00
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object has no persistence!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
OSL_ENSURE( nMode == embed::EmbedUpdateModes::ALWAYS_UPDATE
|| nMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE,
"Unknown update mode!" );
2003-11-13 16:01:50 +00:00
m_nUpdateMode = nMode;
}
sal_Int64 SAL_CALL OleEmbeddedObject::getStatus( sal_Int64
nAspect
)
2003-11-13 16:01:50 +00:00
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
return xWrappedObject->getStatus( nAspect );
}
// end wrapping related part ====================
2003-11-13 16:01:50 +00:00
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 )
throw embed::WrongStateException( "The object must be in running state!",
static_cast< ::cppu::OWeakObject* >(this) );
2003-11-13 16:01:50 +00:00
sal_Int64 nResult = 0;
#ifdef _WIN32
if ( m_bGotStatus && m_nStatusAspect == nAspect )
nResult = m_nStatus;
else if ( m_pOleComponent )
{
m_nStatus = m_pOleComponent->GetMiscStatus( nAspect );
m_nStatusAspect = nAspect;
m_bGotStatus = true;
nResult = m_nStatus;
}
2003-12-15 14:37:44 +00:00
#endif
// this implementation needs size to be provided after object loading/creating to work in optimal way
return ( nResult | embed::EmbedMisc::EMBED_NEEDSSIZEONLOAD );
2003-11-13 16:01:50 +00:00
}
void SAL_CALL OleEmbeddedObject::setContainerName( const OUString& sName )
{
// begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
if ( xWrappedObject.is() )
{
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->setContainerName( sName );
return;
}
// end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex );
if ( m_bDisposed )
throw lang::DisposedException(); // TODO
m_aContainerName = sName;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */