[Libreoffice-commits] .: oox/inc oox/source sc/source sw/source
Noel Power
noelp at kemper.freedesktop.org
Mon Sep 5 02:44:02 PDT 2011
oox/inc/oox/ole/vbaproject.hxx | 3 +
oox/source/ole/vbaproject.cxx | 18 ++++++++++
sc/source/filter/excel/excimp8.cxx | 49 ++++++++--------------------
sw/source/filter/ww8/ww8par.cxx | 64 +++++++++++--------------------------
4 files changed, 56 insertions(+), 78 deletions(-)
New commits:
commit 8be4261608251630017f88faae0fbf696016a96a
Author: Noel Power <noel.power at novell.com>
Date: Mon Sep 5 10:45:21 2011 +0100
access oox vbaproject import directly
diff --git a/oox/inc/oox/ole/vbaproject.hxx b/oox/inc/oox/ole/vbaproject.hxx
index 001188f..91f399d 100644
--- a/oox/inc/oox/ole/vbaproject.hxx
+++ b/oox/inc/oox/ole/vbaproject.hxx
@@ -131,6 +131,9 @@ public:
const GraphicHelper& rGraphicHelper,
bool bDefaultColorBgr = true );
+ void importVbaProject(
+ StorageBase& rVbaPrjStrg );
+
/** Registers a macro atatcher object. For details, see description of the
VbaMacroAttacherBase class. */
void registerMacroAttacher( const VbaMacroAttacherRef& rxAttacher );
diff --git a/oox/source/ole/vbaproject.cxx b/oox/source/ole/vbaproject.cxx
index 8e5d2eb..1173783 100644
--- a/oox/source/ole/vbaproject.cxx
+++ b/oox/source/ole/vbaproject.cxx
@@ -168,6 +168,24 @@ VbaProject::~VbaProject()
{
}
+
+void VbaProject::importVbaProject( StorageBase& rVbaPrjStrg )
+{
+ // create GraphicHelper
+ Reference< ::com::sun::star::frame::XFrame > xFrame;
+ if ( mxDocModel.is() )
+ {
+ Reference< ::com::sun::star::frame::XController > xController = mxDocModel->getCurrentController();
+ xFrame = xController.is() ? xController->getFrame() : NULL;
+ }
+ StorageRef noStorage;
+ // if the GraphicHelper tries to use noStorage it will of course crash
+ // but.. this shouldn't happen as there is no reason for GraphicHelper
+ // to do that when importing VBA projects
+ GraphicHelper grfHlp( mxContext, xFrame, noStorage );
+ importVbaProject( rVbaPrjStrg, grfHlp );
+}
+
void VbaProject::importVbaProject( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr )
{
if( rVbaPrjStrg.isStorage() )
diff --git a/sc/source/filter/excel/excimp8.cxx b/sc/source/filter/excel/excimp8.cxx
index 6ede078..e89da0c 100644
--- a/sc/source/filter/excel/excimp8.cxx
+++ b/sc/source/filter/excel/excimp8.cxx
@@ -110,13 +110,13 @@
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/script/ModuleInfo.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
-#include <com/sun/star/document/XFilter.hpp>
-#include <com/sun/star/document/XImporter.hpp>
-#include <comphelper/mediadescriptor.hxx>
#include <cppuhelper/component_context.hxx>
#include <sfx2/app.hxx>
#include "xltoolbar.hxx"
-
+#include <oox/ole/vbaproject.hxx>
+#include <oox/ole/olestorage.hxx>
+#include <unotools/streamwrap.hxx>
+#include <comphelper/componentcontext.hxx>
using namespace com::sun::star;
using namespace ::comphelper;
@@ -359,39 +359,20 @@ void ImportExcel8::ReadBasic( void )
}
try
{
- uno::Reference< lang::XComponent > xComponent( pShell->GetModel(), uno::UNO_QUERY_THROW );
- uno::Sequence< beans::NamedValue > aArgSeq( 1 );
-
- // collect names of embedded form controls, as specified in the VBA project
- aArgSeq[ 0 ].Name = CREATE_OUSTRING( "OleNameOverrideInfo" );
- uno::Reference< container::XNameContainer > xOleNameOverrideSink( new OleNameOverrideContainer );
- aArgSeq[ 0 ].Value <<= xOleNameOverrideSink;
-
- uno::Sequence< uno::Any > aArgs( 2 );
- // framework calls filter objects with factory as first argument
- aArgs[ 0 ] <<= getProcessServiceFactory();
- aArgs[ 1 ] <<= aArgSeq;
-
- uno::Reference< document::XImporter > xImporter( ScfApiHelper::CreateInstanceWithArgs( CREATE_OUSTRING( "com.sun.star.comp.oox.xls.ExcelVbaProjectFilter" ), aArgs ), uno::UNO_QUERY_THROW );
- xImporter->setTargetDocument( xComponent );
-
- MediaDescriptor aMediaDesc;
+ ::comphelper::ComponentContext aCtx( ::comphelper::getProcessServiceFactory() );
SfxMedium& rMedium = GetMedium();
- SfxItemSet* pItemSet = rMedium.GetItemSet();
- if( pItemSet )
+ uno::Reference< io::XInputStream > xIn = rMedium.GetInputStream();
+ oox::ole::OleStorage root( aCtx.getUNOContext(), xIn, false );
+ oox::StorageRef vbaStg = root.openSubStorage( CREATE_OUSTRING( "_VBA_PROJECT_CUR" ), false );
+ if ( vbaStg.get() )
{
- if( const SfxStringItem* pItem = static_cast< const SfxStringItem* >( pItemSet->GetItem( SID_FILE_NAME ) ) )
- aMediaDesc[ MediaDescriptor::PROP_URL() ] <<= ::rtl::OUString( pItem->GetValue() );
- if( const SfxStringItem* pItem = static_cast< const SfxStringItem* >( pItemSet->GetItem( SID_PASSWORD ) ) )
- aMediaDesc[ MediaDescriptor::PROP_PASSWORD() ] <<= ::rtl::OUString( pItem->GetValue() );
+ oox::ole::VbaProject aVbaPrj( aCtx.getUNOContext(), pShell->GetModel(), CREATE_OUSTRING( "Calc") );
+ // collect names of embedded form controls, as specified in the VBA project
+ uno::Reference< container::XNameContainer > xOleNameOverrideSink( new OleNameOverrideContainer );
+ aVbaPrj.setOleOverridesSink( xOleNameOverrideSink );
+ aVbaPrj.importVbaProject( *vbaStg );
+ GetObjectManager().SetOleNameOverrideInfo( xOleNameOverrideSink );
}
- aMediaDesc[ MediaDescriptor::PROP_INPUTSTREAM() ] <<= rMedium.GetInputStream();
- aMediaDesc[ MediaDescriptor::PROP_INTERACTIONHANDLER() ] <<= rMedium.GetInteractionHandler();
-
- // call the filter
- uno::Reference< document::XFilter > xFilter( xImporter, uno::UNO_QUERY_THROW );
- xFilter->filter( aMediaDesc.getAsConstPropertyValueList() );
- GetObjectManager().SetOleNameOverrideInfo( xOleNameOverrideSink );
}
catch( uno::Exception& )
{
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 53cac2e..7e5aaa1 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -175,6 +175,11 @@ using namespace nsHdFtFlags;
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <comphelper/mediadescriptor.hxx>
+#include <oox/ole/vbaproject.hxx>
+#include <oox/ole/olestorage.hxx>
+#include <unotools/streamwrap.hxx>
+#include <comphelper/componentcontext.hxx>
+
using ::comphelper::MediaDescriptor;
using ::comphelper::getProcessServiceFactory;
@@ -182,57 +187,29 @@ using ::comphelper::getProcessServiceFactory;
class BasicProjImportHelper
{
SwDocShell& mrDocShell;
+ uno::Reference< uno::XComponentContext > mxCtx;
public:
- BasicProjImportHelper( SwDocShell& rShell ) : mrDocShell( rShell ) {}
- bool import();
- bool import( const com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue >& aArgSeq );
+ BasicProjImportHelper( SwDocShell& rShell ) : mrDocShell( rShell )
+ {
+ comphelper::ComponentContext aCtx( ::comphelper::getProcessServiceFactory() );
+ mxCtx = aCtx.getUNOContext();
+ }
+ bool import( const uno::Reference< io::XInputStream >& rxIn );
rtl::OUString getProjectName();
};
-bool BasicProjImportHelper::import()
-{
- uno::Sequence< beans::NamedValue > aArgSeq;
- return import( aArgSeq );
-}
-
-bool BasicProjImportHelper::import( const uno::Sequence< beans::NamedValue >& aArgSeq )
+bool BasicProjImportHelper::import( const uno::Reference< io::XInputStream >& rxIn )
{
bool bRet = false;
try
{
- uno::Reference< lang::XComponent > xComponent( mrDocShell.GetModel(), uno::UNO_QUERY_THROW );
- // #TODO #FIXME, get rid of the uno access, better ( and less lines I suspect ) to
- // access this directly ( just need to figure out what stream manipulation I need to
- // do )
- uno::Reference< lang::XMultiServiceFactory > xFac( getProcessServiceFactory(), uno::UNO_QUERY_THROW );
- uno::Reference< document::XImporter > xImporter;
- if ( aArgSeq.getLength() )
+ oox::ole::OleStorage root( mxCtx, rxIn, false );
+ oox::StorageRef vbaStg = root.openSubStorage( CREATE_OUSTRING( "Macros" ), false );
+ if ( vbaStg.get() )
{
- uno::Sequence< uno::Any > aArgs( 2 );
- aArgs[ 0 ] <<= getProcessServiceFactory();
- aArgs[ 1 ] <<= aArgSeq;
- xImporter.set( xFac->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.oox.WordVbaProjectFilter" ) ), aArgs ), uno::UNO_QUERY_THROW );
+ oox::ole::VbaProject aVbaPrj( mxCtx, mrDocShell.GetModel(), CREATE_CONST_ASC( "Writer") );
+ aVbaPrj.importVbaProject( *vbaStg );
}
- else
- xImporter.set( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.oox.WordVbaProjectFilter" ) )), uno::UNO_QUERY_THROW );
- xImporter->setTargetDocument( xComponent );
-
- MediaDescriptor aMediaDesc;
- SfxMedium& rMedium = *mrDocShell.GetMedium();
- SfxItemSet* pItemSet = rMedium.GetItemSet();
- if( pItemSet )
- {
- if( const SfxStringItem* pItem = static_cast< const SfxStringItem* >( pItemSet->GetItem( SID_FILE_NAME ) ) )
- aMediaDesc[ MediaDescriptor::PROP_URL() ] <<= ::rtl::OUString( pItem->GetValue() );
- if( const SfxStringItem* pItem = static_cast< const SfxStringItem* >( pItemSet->GetItem( SID_PASSWORD ) ) )
- aMediaDesc[ MediaDescriptor::PROP_PASSWORD() ] <<= ::rtl::OUString( pItem->GetValue() );
- }
- aMediaDesc[ MediaDescriptor::PROP_INPUTSTREAM() ] <<= rMedium.GetInputStream();
- aMediaDesc[ MediaDescriptor::PROP_INTERACTIONHANDLER() ] <<= rMedium.GetInteractionHandler();
-
- // call the filter
- uno::Reference< document::XFilter > xFilter( xImporter, uno::UNO_QUERY_THROW );
- bRet = xFilter->filter( aMediaDesc.getAsConstPropertyValueList() );
}
catch( const uno::Exception& )
{
@@ -4330,8 +4307,7 @@ bool SwWW8ImplReader::ReadGlobalTemplateSettings( const rtl::OUString& sCreatedF
BasicProjImportHelper aBasicImporter( *mpDocShell );
// Import vba via oox filter
- aBasicImporter.import();
-
+ aBasicImporter.import( mpDocShell->GetMedium()->GetInputStream() );
lcl_createTemplateToProjectEntry( xPrjNameCache, aURL, aBasicImporter.getProjectName() );
// Read toolbars & menus
SvStorageStreamRef refMainStream = rRoot->OpenSotStream( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocument") ) );
@@ -4615,7 +4591,7 @@ sal_uLong SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos)
BasicProjImportHelper aBasicImporter( *mpDocShell );
// Import vba via oox filter
- bool bRet = aBasicImporter.import();
+ bool bRet = aBasicImporter.import( mpDocShell->GetMedium()->GetInputStream() );
lcl_createTemplateToProjectEntry( xPrjNameCache, sCreatedFrom, aBasicImporter.getProjectName() );
WW8Customizations aCustomisations( pTableStream, *pWwFib );
More information about the Libreoffice-commits
mailing list