From c8e3633a352c2fda3aebb9781288a926e7a88c42 Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Thu, 3 Aug 2017 19:58:22 +0200 Subject: Make ActiveX controls import working again (PPTX / XLSX) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It used to work earlier, but there were an issue with the shape id and so controls were not find. Also in PPTX import the persistStorage attribute was handled only for parent controls and not for other kind of controls. Change-Id: I9784166b65407b79b6dfed8a38087b55b1b69835 Reviewed-on: https://gerrit.libreoffice.org/40751 Reviewed-by: Tamás Zolnai Tested-by: Tamás Zolnai --- oox/source/ole/axcontrolfragment.cxx | 19 +++++++++++++++++++ oox/source/ppt/slidefragmenthandler.cxx | 1 - oox/source/vml/vmldrawing.cxx | 10 ++-------- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'oox') diff --git a/oox/source/ole/axcontrolfragment.cxx b/oox/source/ole/axcontrolfragment.cxx index fb8a4652c01b..351a4bd2aec7 100644 --- a/oox/source/ole/axcontrolfragment.cxx +++ b/oox/source/ole/axcontrolfragment.cxx @@ -130,11 +130,30 @@ ContextHandlerRef AxControlFragment::onCreateContext( sal_Int32 nElement, const Reference< XInputStream > xStrgStrm = getFilter().openInputStream( aFragmentPath ); if( xStrgStrm.is() ) { + // Try to import as a parent control + bool bImportedAsParent = false; OleStorage aStorage( getFilter().getComponentContext(), xStrgStrm, false ); BinaryXInputStream aInStrm( aStorage.openInputStream( "f" ), true ); if( !aInStrm.isEof() ) + { if( AxContainerModelBase* pModel = dynamic_cast< AxContainerModelBase* >( mrControl.createModelFromGuid( aClassId ) ) ) + { pModel->importBinaryModel( aInStrm ); + bImportedAsParent = true; + } + } + // Import it as a non-parent control + if(!bImportedAsParent) + { + BinaryXInputStream aInStrm2(aStorage.openInputStream("contents"), true); + if (!aInStrm2.isEof()) + { + if (ControlModelBase* pModel = mrControl.createModelFromGuid(aClassId)) + { + pModel->importBinaryModel(aInStrm2); + } + } + } } } } diff --git a/oox/source/ppt/slidefragmenthandler.cxx b/oox/source/ppt/slidefragmenthandler.cxx index 9d6fcf16aa99..3a967eea14ce 100644 --- a/oox/source/ppt/slidefragmenthandler.cxx +++ b/oox/source/ppt/slidefragmenthandler.cxx @@ -139,7 +139,6 @@ SlideFragmentHandler::~SlideFragmentHandler() case PPT_TOKEN( control ): { ::oox::vml::ControlInfo aInfo; - aInfo.setShapeId( rAttribs.getInteger( XML_spid, 0 ) ); aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) ); aInfo.maName = rAttribs.getXString( XML_name, OUString() ); mpSlidePersistPtr->getDrawing()->registerControl( aInfo ); diff --git a/oox/source/vml/vmldrawing.cxx b/oox/source/vml/vmldrawing.cxx index 34d798b62d10..6cb8f4dc7ebe 100644 --- a/oox/source/vml/vmldrawing.cxx +++ b/oox/source/vml/vmldrawing.cxx @@ -82,11 +82,6 @@ ControlInfo::ControlInfo() { } -void ControlInfo::setShapeId( sal_Int32 nShapeId ) -{ - maShapeId = lclGetShapeId( nShapeId ); -} - Drawing::Drawing( XmlFilterBase& rFilter, const Reference< XDrawPage >& rxDrawPage, DrawingType eType ) : mrFilter( rFilter ), mxDrawPage( rxDrawPage ), @@ -129,10 +124,9 @@ void Drawing::registerOleObject( const OleObjectInfo& rOleObject ) void Drawing::registerControl( const ControlInfo& rControl ) { - OSL_ENSURE( !rControl.maShapeId.isEmpty(), "Drawing::registerControl - missing form control shape id" ); OSL_ENSURE( !rControl.maName.isEmpty(), "Drawing::registerControl - missing form control name" ); - OSL_ENSURE( maControls.count( rControl.maShapeId ) == 0, "Drawing::registerControl - form control already registered" ); - maControls.insert( ControlInfoMap::value_type( rControl.maShapeId, rControl ) ); + OSL_ENSURE( maControls.count( rControl.maName ) == 0, "Drawing::registerControl - form control already registered" ); + maControls.insert( ControlInfoMap::value_type( rControl.maName, rControl ) ); } void Drawing::finalizeFragmentImport() -- cgit