diff options
Diffstat (limited to 'basic/source/uno/dlgcont.cxx')
-rwxr-xr-x[-rw-r--r--] | basic/source/uno/dlgcont.cxx | 113 |
1 files changed, 100 insertions, 13 deletions
diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx index f173ae5f18ff..04df56763a13 100644..100755 --- a/basic/source/uno/dlgcont.cxx +++ b/basic/source/uno/dlgcont.cxx @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -40,6 +41,7 @@ #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> #include "com/sun/star/resource/XStringResourceWithStorage.hpp" #include "com/sun/star/resource/XStringResourceWithLocation.hpp" +#include "com/sun/star/document/XGraphicObjectResolver.hpp" #include "dlgcont.hxx" #include "sbmodule.hxx" #include <comphelper/processfactory.hxx> @@ -68,11 +70,14 @@ using namespace com::sun::star::script; using namespace com::sun::star::xml::sax; using namespace com::sun::star; using namespace cppu; -using namespace rtl; using namespace osl; +using ::rtl::OUString; + using com::sun::star::uno::Reference; +#define GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:" + //============================================================================ // Implementation class SfxDialogLibraryContainer @@ -132,7 +137,7 @@ bool writeOasis2OOoLibraryElement( Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY ); OSL_ASSERT( xProps.is() ); OSL_VERIFY( xProps->getPropertyValue( - OUString::createFromAscii(("DefaultContext")) ) >>= xContext ); + OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext ); Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager() ); @@ -178,7 +183,7 @@ bool writeOasis2OOoLibraryElement( xml::sax::InputSource source; source.aInputStream = xInput; - source.sSystemId = OUString::createFromAscii( "virtual file" ); + source.sSystemId = OUString(RTL_CONSTASCII_USTRINGPARAM("virtual file")); xParser->parseStream( source ); @@ -224,6 +229,35 @@ void SAL_CALL SfxDialogLibraryContainer::writeLibraryElement xInput->closeInput(); } +void lcl_deepInspectForEmbeddedImages( const Reference< XInterface >& xIf, std::vector< rtl::OUString >& rvEmbedImgUrls ) +{ + static rtl::OUString sImageURL= OUString(RTL_CONSTASCII_USTRINGPARAM( "ImageURL" ) ); + Reference< beans::XPropertySet > xProps( xIf, UNO_QUERY ); + if ( xProps.is() ) + { + + if ( xProps->getPropertySetInfo()->hasPropertyByName( sImageURL ) ) + { + rtl::OUString sURL; + xProps->getPropertyValue( sImageURL ) >>= sURL; + if ( sURL.getLength() && sURL.compareToAscii( GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( GRAPHOBJ_URLPREFIX ) ) == 0 ) + rvEmbedImgUrls.push_back( sURL ); + } + } + Reference< XNameContainer > xContainer( xIf, UNO_QUERY ); + if ( xContainer.is() ) + { + Sequence< rtl::OUString > sNames = xContainer->getElementNames(); + sal_Int32 nContainees = sNames.getLength(); + for ( sal_Int32 index = 0; index < nContainees; ++index ) + { + Reference< XInterface > xCtrl; + xContainer->getByName( sNames[ index ] ) >>= xCtrl; + lcl_deepInspectForEmbeddedImages( xCtrl, rvEmbedImgUrls ); + } + } +} + void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< embed::XStorage >& xStorage ) throw ( RuntimeException ) { LibraryContainerMethodGuard aGuard( *this ); @@ -252,6 +286,54 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e SfxLibraryContainer::storeLibrariesToStorage( xStorage ); + // we need to export out any embedded image object(s) + // associated with any Dialogs. First, we need to actually gather any such urls + // for each dialog in this container + Sequence< OUString > sLibraries = getElementNames(); + for ( sal_Int32 i=0; i < sLibraries.getLength(); ++i ) + { + // libraries will already be loaded from above + Reference< XNameContainer > xLib; + getByName( sLibraries[ i ] ) >>= xLib; + if ( xLib.is() ) + { + Sequence< OUString > sDialogs = xLib->getElementNames(); + sal_Int32 nDialogs( sDialogs.getLength() ); + for ( sal_Int32 j=0; j < nDialogs; ++j ) + { + // Each Dialog has an associated xISP + Reference< io::XInputStreamProvider > xISP; + xLib->getByName( sDialogs[ j ] ) >>= xISP; + if ( xISP.is() ) + { + Reference< io::XInputStream > xInput( xISP->createInputStream() ); + Reference< XNameContainer > xDialogModel( mxMSF->createInstance + ( OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY ); + Reference< XComponentContext > xContext; + Reference< beans::XPropertySet > xProps( mxMSF, UNO_QUERY ); + OSL_ASSERT( xProps.is() ); + OSL_VERIFY( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext ); + ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, mxOwnerDocument ); + std::vector< rtl::OUString > vEmbeddedImageURLs; + lcl_deepInspectForEmbeddedImages( Reference< XInterface >( xDialogModel, UNO_QUERY ), vEmbeddedImageURLs ); + if ( vEmbeddedImageURLs.size() ) + { + // Export the images to the storage + Sequence< Any > aArgs( 1 ); + aArgs[ 0 ] <<= xStorage; + Reference< document::XGraphicObjectResolver > xGraphicResolver( mxMSF->createInstanceWithArguments( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Svx.GraphicExportHelper" ) ), aArgs ), UNO_QUERY ); + std::vector< rtl::OUString >::iterator it = vEmbeddedImageURLs.begin(); + std::vector< rtl::OUString >::iterator it_end = vEmbeddedImageURLs.end(); + if ( xGraphicResolver.is() ) + { + for ( sal_Int32 count = 0; it != it_end; ++it, ++count ) + xGraphicResolver->resolveGraphicObjectURL( *it ); + } + } + } + } + } + } mbOasis2OOoFormat = sal_False; } @@ -322,7 +404,7 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement try { // start parsing - xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, xContext ) ); + xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, xContext, mxOwnerDocument ) ); xParser->parseStream( source ); } catch( Exception& ) @@ -336,7 +418,7 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement // Create InputStream, TODO: Implement own InputStreamProvider // to avoid creating the DialogModel here! - Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext ); + Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, mxOwnerDocument ); aRetAny <<= xISP; return aRetAny; } @@ -352,8 +434,8 @@ SfxLibraryContainer* SfxDialogLibraryContainer::createInstanceImpl( void ) } -static OUString aResourceFileNameBase = OUString::createFromAscii( "DialogStrings" ); -static OUString aResourceFileCommentBase = OUString::createFromAscii( "# Strings for Dialog Library " ); +static OUString aResourceFileNameBase(RTL_CONSTASCII_USTRINGPARAM("DialogStrings")); +static OUString aResourceFileCommentBase(RTL_CONSTASCII_USTRINGPARAM("# Strings for Dialog Library ")); // Resource handling Reference< ::com::sun::star::resource::XStringResourcePersistence > @@ -380,7 +462,7 @@ Reference< ::com::sun::star::resource::XStringResourcePersistence > // TODO: Ctor xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance - ( OUString::createFromAscii( "com.sun.star.resource.StringResourceWithStorage" ) ), UNO_QUERY ); + ( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.resource.StringResourceWithStorage")) ), UNO_QUERY ); uno::Reference< embed::XStorage > xLibrariesStor; uno::Reference< embed::XStorage > xLibraryStor; @@ -428,7 +510,7 @@ Reference< ::com::sun::star::resource::XStringResourcePersistence > // TODO: Ctor xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance - ( OUString::createFromAscii( "com.sun.star.resource.StringResourceWithLocation" ) ), UNO_QUERY ); + ( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.resource.StringResourceWithLocation")) ), UNO_QUERY ); // TODO: Ctor if( xRet.is() ) @@ -484,7 +566,11 @@ void SfxDialogLibraryContainer::onNewRootStorage() } } - +sal_Bool SAL_CALL +SfxDialogLibraryContainer:: HasExecutableCode( const ::rtl::OUString& /*Library*/ ) throw (uno::RuntimeException) +{ + return sal_False; // dialog library has no executable code +} //============================================================================ // Service @@ -506,9 +592,9 @@ Sequence< ::rtl::OUString > SAL_CALL SfxDialogLibraryContainer::getSupportedServ Sequence< OUString > SfxDialogLibraryContainer::getSupportedServiceNames_static() { Sequence< OUString > aServiceNames( 2 ); - aServiceNames[0] = OUString::createFromAscii( "com.sun.star.script.DocumentDialogLibraryContainer" ); + aServiceNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.DocumentDialogLibraryContainer")); // plus, for compatibility: - aServiceNames[1] = OUString::createFromAscii( "com.sun.star.script.DialogLibraryContainer" ); + aServiceNames[1] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.DialogLibraryContainer")); return aServiceNames; } @@ -520,7 +606,7 @@ OUString SfxDialogLibraryContainer::getImplementationName_static() MutexGuard aGuard( Mutex::getGlobalMutex() ); if( bNeedsInit ) { - aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.DialogLibraryContainer" ); + aImplName = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.sfx2.DialogLibraryContainer")); bNeedsInit = sal_False; } return aImplName; @@ -656,3 +742,4 @@ bool SAL_CALL SfxDialogLibrary::isLibraryElementValid( ::com::sun::star::uno::An } //============================================================================ +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |