summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorSJacobi <Sven-Jacobi@gmx.de>2013-03-11 13:29:47 +0100
committerCédric Bosdonnat <cedric.bosdonnat@free.fr>2013-03-11 15:45:38 +0100
commita09e0137c11ce47f7d4fc598b19d18a7d8951bf1 (patch)
tree7bd05ed0881d4a2f3cebce2c20c68003d2ee53bb /oox
parent8933f19100adbf9f2601db0f3ac67dd3b1887ef7 (diff)
pptx import:supporting FilterData properties:PageRange and ImportNotesPages
Change-Id: I9da8455bb10e93f1ae6c4894d4f15ff7fbcdfa07
Diffstat (limited to 'oox')
-rw-r--r--oox/inc/oox/core/filterbase.hxx4
-rw-r--r--oox/inc/oox/ppt/presentationfragmenthandler.hxx3
-rw-r--r--oox/source/core/filterbase.cxx9
-rw-r--r--oox/source/ppt/presentationfragmenthandler.cxx269
4 files changed, 174 insertions, 111 deletions
diff --git a/oox/inc/oox/core/filterbase.hxx b/oox/inc/oox/core/filterbase.hxx
index 171ae5f7d76b..5f47ea9fcef2 100644
--- a/oox/inc/oox/core/filterbase.hxx
+++ b/oox/inc/oox/core/filterbase.hxx
@@ -32,6 +32,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/implbase5.hxx>
+#include <comphelper/sequenceashashmap.hxx>
#include "oox/helper/binarystreambase.hxx"
#include "oox/helper/storagebase.hxx"
#include "oox/dllapi.h"
@@ -140,6 +141,9 @@ public:
const ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator >&
getStatusIndicator() const;
+ /** Returns the FilterData */
+ ::comphelper::SequenceAsHashMap& getFilterData() const;
+
/** Returns the media descriptor. */
::comphelper::MediaDescriptor& getMediaDescriptor() const;
diff --git a/oox/inc/oox/ppt/presentationfragmenthandler.hxx b/oox/inc/oox/ppt/presentationfragmenthandler.hxx
index 694336894ea5..bb9488437266 100644
--- a/oox/inc/oox/ppt/presentationfragmenthandler.hxx
+++ b/oox/inc/oox/ppt/presentationfragmenthandler.hxx
@@ -48,6 +48,9 @@ protected:
const oox::ppt::SlidePersistPtr pPersist );
private:
+
+ void importSlide(sal_uInt32 nSlide, sal_Bool bFirstSlide, sal_Bool bImportNotes);
+
std::vector< rtl::OUString > maSlideMasterVector;
std::vector< rtl::OUString > maSlidesVector;
std::vector< rtl::OUString > maNotesMasterVector;
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index 3c3e8c34c15d..8643d2c75d74 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -132,6 +132,7 @@ struct FilterBaseImpl
FilterDirection meDirection;
SequenceAsHashMap maArguments;
+ SequenceAsHashMap maFilterData;
MediaDescriptor maMediaDesc;
OUString maFileUrl;
StorageRef mxStorage;
@@ -202,6 +203,8 @@ void FilterBaseImpl::finalizeFilter()
{
try
{
+ // writing back the FilterData to the MediaDescriptor
+ maMediaDesc["FilterData"] = makeAny(maFilterData.getAsConstPropertyValueList());
// write the descriptor back to the document model (adds the passwords)
mxModel->attachResource( maFileUrl, maMediaDesc.getAsConstPropertyValueList() );
// unlock the model controllers
@@ -278,6 +281,11 @@ MediaDescriptor& FilterBase::getMediaDescriptor() const
return mxImpl->maMediaDesc;
}
+SequenceAsHashMap& FilterBase::getFilterData() const
+{
+ return mxImpl->maFilterData;
+}
+
const OUString& FilterBase::getFileUrl() const
{
return mxImpl->maFileUrl;
@@ -548,6 +556,7 @@ void FilterBase::setMediaDescriptor( const Sequence< PropertyValue >& rMediaDesc
mxImpl->mxStatusIndicator = mxImpl->maMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_STATUSINDICATOR(), Reference< XStatusIndicator >() );
mxImpl->mxInteractionHandler = mxImpl->maMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_INTERACTIONHANDLER(), Reference< XInteractionHandler >() );
mxImpl->mxParentShape = mxImpl->maMediaDesc.getUnpackedValueOrDefault( "ParentShape", mxImpl->mxParentShape );
+ mxImpl->maFilterData = mxImpl->maMediaDesc.getUnpackedValueOrDefault( "FilterData", Sequence< PropertyValue >() );
// Check for ISO OOXML
OUString sFilterName = mxImpl->maMediaDesc.getUnpackedValueOrDefault( "FilterName", OUString() );
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx
index 6d077e7e26d2..c2fdf536b0e4 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -19,6 +19,7 @@
#include "comphelper/anytostring.hxx"
#include "cppuhelper/exc_hlp.hxx"
+#include <tools/multisel.hxx>
#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
#include <com/sun/star/drawing/XDrawPages.hpp>
@@ -130,133 +131,123 @@ void ResolveTextFields( XmlFilterBase& rFilter )
}
}
-void PresentationFragmentHandler::finalizeImport()
+void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, sal_Bool bFirstPage, sal_Bool bImportNotesPage)
{
- // todo: localized progress bar text
- const Reference< task::XStatusIndicator >& rxStatusIndicator( getFilter().getStatusIndicator() );
- if ( rxStatusIndicator.is() )
- rxStatusIndicator->start( OUString(), 10000 );
+ PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
- try
- {
- PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
+ Reference< frame::XModel > xModel( rFilter.getModel() );
+ Reference< drawing::XDrawPage > xSlide;
- Reference< frame::XModel > xModel( rFilter.getModel() );
- Reference< drawing::XDrawPage > xSlide;
- sal_uInt32 nSlide;
+ // importing slide pages and its corresponding notes page
+ Reference< drawing::XDrawPagesSupplier > xDPS( xModel, uno::UNO_QUERY_THROW );
+ Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY_THROW );
- // importing slide pages and its corresponding notes page
- Reference< drawing::XDrawPagesSupplier > xDPS( xModel, uno::UNO_QUERY_THROW );
- Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY_THROW );
+ try {
- for( nSlide = 0; nSlide < maSlidesVector.size(); nSlide++ )
+ if( bFirstPage )
+ xDrawPages->getByIndex( 0 ) >>= xSlide;
+ else
+ xSlide = xDrawPages->insertNewByIndex( xDrawPages->getCount() );
+
+ OUString aSlideFragmentPath = getFragmentPathFromRelId( maSlidesVector[ nSlide ] );
+ if( !aSlideFragmentPath.isEmpty() )
{
- if ( rxStatusIndicator.is() )
- rxStatusIndicator->setValue( ( nSlide * 10000 ) / maSlidesVector.size() );
+ SlidePersistPtr pMasterPersistPtr;
+ SlidePersistPtr pSlidePersistPtr( new SlidePersist( rFilter, sal_False, sal_False, xSlide,
+ ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
- if( nSlide == 0 )
- xDrawPages->getByIndex( 0 ) >>= xSlide;
- else
- xSlide = xDrawPages->insertNewByIndex( nSlide );
+ FragmentHandlerRef xSlideFragmentHandler( new SlideFragmentHandler( rFilter, aSlideFragmentPath, pSlidePersistPtr, Slide ) );
- OUString aSlideFragmentPath = getFragmentPathFromRelId( maSlidesVector[ nSlide ] );
- if( !aSlideFragmentPath.isEmpty() )
+ // importing the corresponding masterpage/layout
+ OUString aLayoutFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideLayout" ) );
+ if ( !aLayoutFragmentPath.isEmpty() )
{
- OUString aMasterFragmentPath;
- SlidePersistPtr pMasterPersistPtr;
- SlidePersistPtr pSlidePersistPtr( new SlidePersist( rFilter, sal_False, sal_False, xSlide,
- ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
-
- FragmentHandlerRef xSlideFragmentHandler( new SlideFragmentHandler( rFilter, aSlideFragmentPath, pSlidePersistPtr, Slide ) );
-
- // importing the corresponding masterpage/layout
- OUString aLayoutFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideLayout" ) );
- if ( !aLayoutFragmentPath.isEmpty() )
+ // importing layout
+ RelationsRef xLayoutRelations = rFilter.importRelations( aLayoutFragmentPath );
+ OUString aMasterFragmentPath = xLayoutRelations->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideMaster" ) );
+ if( !aMasterFragmentPath.isEmpty() )
{
- // importing layout
- RelationsRef xLayoutRelations = rFilter.importRelations( aLayoutFragmentPath );
- aMasterFragmentPath = xLayoutRelations->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideMaster" ) );
- if( !aMasterFragmentPath.isEmpty() )
+ // check if the corresponding masterpage+layout has already been imported
+ std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
+ std::vector< SlidePersistPtr >::iterator aIter( rMasterPages.begin() );
+ while( aIter != rMasterPages.end() )
{
- // check if the corresponding masterpage+layout has already been imported
- std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
- std::vector< SlidePersistPtr >::iterator aIter( rMasterPages.begin() );
- while( aIter != rMasterPages.end() )
+ if ( ( (*aIter)->getPath() == aMasterFragmentPath ) && ( (*aIter)->getLayoutPath() == aLayoutFragmentPath ) )
{
- if ( ( (*aIter)->getPath() == aMasterFragmentPath ) && ( (*aIter)->getLayoutPath() == aLayoutFragmentPath ) )
- {
- pMasterPersistPtr = *aIter;
- break;
- }
- ++aIter;
+ pMasterPersistPtr = *aIter;
+ break;
}
+ ++aIter;
+ }
- if ( !pMasterPersistPtr.get() )
- { // masterpersist not found, we have to load it
- Reference< drawing::XDrawPage > xMasterPage;
- Reference< drawing::XMasterPagesSupplier > xMPS( xModel, uno::UNO_QUERY_THROW );
- Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_QUERY_THROW );
-
- if( !(rFilter.getMasterPages().size() ))
- xMasterPages->getByIndex( 0 ) >>= xMasterPage;
+ if ( !pMasterPersistPtr.get() )
+ { // masterpersist not found, we have to load it
+ Reference< drawing::XDrawPage > xMasterPage;
+ Reference< drawing::XMasterPagesSupplier > xMPS( xModel, uno::UNO_QUERY_THROW );
+ Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_QUERY_THROW );
+
+ if( !(rFilter.getMasterPages().size() ))
+ xMasterPages->getByIndex( 0 ) >>= xMasterPage;
+ else
+ xMasterPage = xMasterPages->insertNewByIndex( xMasterPages->getCount() );
+
+ pMasterPersistPtr = SlidePersistPtr( new SlidePersist( rFilter, sal_True, sal_False, xMasterPage,
+ ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
+ pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath );
+ rFilter.getMasterPages().push_back( pMasterPersistPtr );
+ rFilter.setActualSlidePersist( pMasterPersistPtr );
+ FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aMasterFragmentPath, pMasterPersistPtr, Master ) );
+
+ // set the correct theme
+ OUString aThemeFragmentPath = xMasterFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "theme" ) );
+ if( !aThemeFragmentPath.isEmpty() )
+ {
+ std::map< OUString, oox::drawingml::ThemePtr >& rThemes( rFilter.getThemes() );
+ std::map< OUString, oox::drawingml::ThemePtr >::iterator aIter2( rThemes.find( aThemeFragmentPath ) );
+ if( aIter2 == rThemes.end() )
+ {
+ oox::drawingml::ThemePtr pThemePtr( new oox::drawingml::Theme() );
+ pMasterPersistPtr->setTheme( pThemePtr );
+ Reference<xml::dom::XDocument> xDoc=
+ rFilter.importFragment(aThemeFragmentPath);
+
+ rFilter.importFragment(
+ new ThemeFragmentHandler(
+ rFilter, aThemeFragmentPath, *pThemePtr ),
+ Reference<xml::sax::XFastSAXSerializable>(
+ xDoc,
+ UNO_QUERY_THROW));
+ rThemes[ aThemeFragmentPath ] = pThemePtr;
+ pThemePtr->setFragment(xDoc);
+ }
else
- xMasterPage = xMasterPages->insertNewByIndex( xMasterPages->getCount() );
-
- pMasterPersistPtr = SlidePersistPtr( new SlidePersist( rFilter, sal_True, sal_False, xMasterPage,
- ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
- pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath );
- rFilter.getMasterPages().push_back( pMasterPersistPtr );
- rFilter.setActualSlidePersist( pMasterPersistPtr );
- FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aMasterFragmentPath, pMasterPersistPtr, Master ) );
-
- // set the correct theme
- OUString aThemeFragmentPath = xMasterFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "theme" ) );
- if( !aThemeFragmentPath.isEmpty() )
{
- std::map< OUString, oox::drawingml::ThemePtr >& rThemes( rFilter.getThemes() );
- std::map< OUString, oox::drawingml::ThemePtr >::iterator aIter2( rThemes.find( aThemeFragmentPath ) );
- if( aIter2 == rThemes.end() )
- {
- oox::drawingml::ThemePtr pThemePtr( new oox::drawingml::Theme() );
- pMasterPersistPtr->setTheme( pThemePtr );
- Reference<xml::dom::XDocument> xDoc=
- rFilter.importFragment(aThemeFragmentPath);
-
- rFilter.importFragment(
- new ThemeFragmentHandler(
- rFilter, aThemeFragmentPath, *pThemePtr ),
- Reference<xml::sax::XFastSAXSerializable>(
- xDoc,
- UNO_QUERY_THROW));
- rThemes[ aThemeFragmentPath ] = pThemePtr;
- pThemePtr->setFragment(xDoc);
- }
- else
- {
- pMasterPersistPtr->setTheme( (*aIter2).second );
- }
+ pMasterPersistPtr->setTheme( (*aIter2).second );
}
- importSlide( xMasterFragmentHandler, pMasterPersistPtr );
- rFilter.importFragment( new LayoutFragmentHandler( rFilter, aLayoutFragmentPath, pMasterPersistPtr ) );
- pMasterPersistPtr->createBackground( rFilter );
- pMasterPersistPtr->createXShapes( rFilter );
}
+ importSlide( xMasterFragmentHandler, pMasterPersistPtr );
+ rFilter.importFragment( new LayoutFragmentHandler( rFilter, aLayoutFragmentPath, pMasterPersistPtr ) );
+ pMasterPersistPtr->createBackground( rFilter );
+ pMasterPersistPtr->createXShapes( rFilter );
}
}
+ }
- // importing slide page
- if (pMasterPersistPtr.get()) {
- pSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
- pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme() );
- Reference< drawing::XMasterPageTarget > xMasterPageTarget( pSlidePersistPtr->getPage(), UNO_QUERY );
- if( xMasterPageTarget.is() )
- xMasterPageTarget->setMasterPage( pMasterPersistPtr->getPage() );
- }
- rFilter.getDrawPages().push_back( pSlidePersistPtr );
- rFilter.setActualSlidePersist( pSlidePersistPtr );
- importSlide( xSlideFragmentHandler, pSlidePersistPtr );
- pSlidePersistPtr->createBackground( rFilter );
- pSlidePersistPtr->createXShapes( rFilter );
+ // importing slide page
+ if (pMasterPersistPtr.get()) {
+ pSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
+ pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme() );
+ Reference< drawing::XMasterPageTarget > xMasterPageTarget( pSlidePersistPtr->getPage(), UNO_QUERY );
+ if( xMasterPageTarget.is() )
+ xMasterPageTarget->setMasterPage( pMasterPersistPtr->getPage() );
+ }
+ rFilter.getDrawPages().push_back( pSlidePersistPtr );
+ rFilter.setActualSlidePersist( pSlidePersistPtr );
+ importSlide( xSlideFragmentHandler, pSlidePersistPtr );
+ pSlidePersistPtr->createBackground( rFilter );
+ pSlidePersistPtr->createXShapes( rFilter );
+
+ if(bImportNotesPage) {
// now importing the notes page
OUString aNotesFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "notesSlide" ) );
@@ -281,7 +272,6 @@ void PresentationFragmentHandler::finalizeImport()
}
}
}
- ResolveTextFields( rFilter );
}
catch( uno::Exception& )
{
@@ -292,10 +282,67 @@ void PresentationFragmentHandler::finalizeImport()
RTL_TEXTENCODING_UTF8 )).getStr() );
}
+}
+
+void PresentationFragmentHandler::finalizeImport()
+{
+ PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
+
+ sal_Int32 nPageCount = maSlidesVector.size();
+
+ // we will take the FilterData property "PageRange" if available, otherwise full range is used
+ comphelper::SequenceAsHashMap& rFilterData = rFilter.getFilterData();
+
+ // writing back the original PageCount of this document, it can be accessed from the XModel
+ // via getArgs after the import.
+ rFilterData["OriginalPageCount"] = makeAny(nPageCount);
+ sal_Bool bImportNotesPages = rFilterData.getUnpackedValueOrDefault("ImportNotesPages", sal_True);
+ OUString aPageRange = rFilterData.getUnpackedValueOrDefault("PageRange", OUString());
+
+ if( !aPageRange.getLength() )
+ {
+ aPageRange = OUStringBuffer()
+ .append( static_cast< sal_Int32 >( 1 ) )
+ .append( static_cast< sal_Unicode >( '-' ) )
+ .append( nPageCount ).makeStringAndClear();
+ }
+
+ StringRangeEnumerator aRangeEnumerator( aPageRange, 0, nPageCount - 1 );
+ StringRangeEnumerator::Iterator aIter = aRangeEnumerator.begin();
+ StringRangeEnumerator::Iterator aEnd = aRangeEnumerator.end();
+ if(aIter!=aEnd) {
+
+ // todo: localized progress bar text
+ const Reference< task::XStatusIndicator >& rxStatusIndicator( getFilter().getStatusIndicator() );
+ if ( rxStatusIndicator.is() )
+ rxStatusIndicator->start( OUString(), 10000 );
- // todo error handling;
- if ( rxStatusIndicator.is() )
- rxStatusIndicator->end();
+ try
+ {
+ int nPagesImported = 0;
+ while (aIter!=aEnd)
+ {
+ if ( rxStatusIndicator.is() )
+ rxStatusIndicator->setValue((nPagesImported * 10000) / aRangeEnumerator.size());
+
+ importSlide(*aIter, !nPagesImported, bImportNotesPages);
+ nPagesImported++;
+ ++aIter;
+ }
+ ResolveTextFields( rFilter );
+ }
+ catch( uno::Exception& )
+ {
+ OSL_FAIL( OString("oox::ppt::PresentationFragmentHandler::finalizeImport(), "
+ "exception caught: " +
+ OUStringToOString(
+ comphelper::anyToString( cppu::getCaughtException() ),
+ RTL_TEXTENCODING_UTF8 )).getStr() );
+ }
+ // todo error handling;
+ if ( rxStatusIndicator.is() )
+ rxStatusIndicator->end();
+ }
}
// CT_Presentation
@@ -362,7 +409,7 @@ bool PresentationFragmentHandler::importSlide( const FragmentHandlerRef& rxSlide
try
{
if ( pSlidePersistPtr->isNotesPage() )
- xPropertySet->setPropertyValue( "sIsHeaderVisible", Any( aHeaderFooter.mbHeader ) );
+ xPropertySet->setPropertyValue( "IsHeaderVisible", Any( aHeaderFooter.mbHeader ) );
xPropertySet->setPropertyValue( "IsFooterVisible", Any( aHeaderFooter.mbFooter ) );
xPropertySet->setPropertyValue( "IsDateTimeVisible", Any( aHeaderFooter.mbDateTime ) );
xPropertySet->setPropertyValue( "IsPageNumberVisible", Any( aHeaderFooter.mbSlideNumber ) );