diff options
author | Mathias Bauer <mba@openoffice.org> | 2009-12-10 15:12:53 +0100 |
---|---|---|
committer | Mathias Bauer <mba@openoffice.org> | 2009-12-10 15:12:53 +0100 |
commit | e96b9a1dee34c0fc4cb9823164a1d8e4c917986b (patch) | |
tree | 2d3a3efe2029117647412df699f5b43bd9a8d27c | |
parent | CWS-TOOLING: integrate CWS killnonpro (diff) | |
download | core-e96b9a1dee34c0fc4cb9823164a1d8e4c917986b.tar.gz core-e96b9a1dee34c0fc4cb9823164a1d8e4c917986b.zip |
#i107449#: replace code using vcl and svtools
-rw-r--r-- | embeddedobj/prj/build.lst | 2 | ||||
-rw-r--r-- | embeddedobj/source/msole/graphconvert.cxx | 119 | ||||
-rw-r--r-- | embeddedobj/source/msole/makefile.mk | 7 | ||||
-rw-r--r-- | embeddedobj/source/msole/mtnotification.hxx | 12 | ||||
-rw-r--r-- | embeddedobj/source/msole/olecomponent.cxx | 28 |
5 files changed, 73 insertions, 95 deletions
diff --git a/embeddedobj/prj/build.lst b/embeddedobj/prj/build.lst index 02a057ca814f..a61305e19221 100644 --- a/embeddedobj/prj/build.lst +++ b/embeddedobj/prj/build.lst @@ -1,4 +1,4 @@ -eo embeddedobj : offuh sal cppu cppuhelper comphelper sot svtools NULL +eo embeddedobj : offuh sal cppu cppuhelper comphelper tools unotools vos NULL eo embeddedobj usr1 - all eo_mkout NULL eo embeddedobj\inc nmake - all eo_inc NULL eo embeddedobj\source\commonembedding nmake - all eo_commonembed eo_inc NULL diff --git a/embeddedobj/source/msole/graphconvert.cxx b/embeddedobj/source/msole/graphconvert.cxx index 55cae585bf65..daa52ced0428 100644 --- a/embeddedobj/source/msole/graphconvert.cxx +++ b/embeddedobj/source/msole/graphconvert.cxx @@ -34,17 +34,19 @@ #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/embed/Aspects.hpp> - -#include "mtnotification.hxx" -#include "oleembobj.hxx" - -// TODO: when conversion service is ready this headers should disappear -#include <svtools/filter.hxx> -#include <vcl/graph.hxx> - +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/graphic/XGraphicProvider.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> #include <tools/link.hxx> #include <vcl/svapp.hxx> #include <vos/mutex.hxx> +#include <unotools/streamhelper.hxx> +#include <comphelper/processfactory.hxx> + +#include "mtnotification.hxx" +#include "oleembobj.hxx" using namespace ::com::sun::star; @@ -52,7 +54,7 @@ using namespace ::com::sun::star; sal_Bool ConvertBufferToFormat( void* pBuf, sal_uInt32 nBufSize, - const ::rtl::OUString& aFormatShortName, + const ::rtl::OUString& aMimeType, uno::Any& aResult ) { // produces sequence with data in requested format and returns it in aResult @@ -60,34 +62,34 @@ sal_Bool ConvertBufferToFormat( void* pBuf, { SvMemoryStream aBufStream( pBuf, nBufSize, STREAM_READ ); aBufStream.ObjectOwnsMemory( sal_False ); - - Graphic aGraph; - GraphicFilter aGrFilter( sal_True ); - if ( aGrFilter.ImportGraphic( aGraph, String(), aBufStream ) == ERRCODE_NONE ) + uno::Reference < io::XInputStream > xIn = new utl::OInputStreamHelper( aBufStream.GetLockBytes(), nBufSize ); + try { - sal_uInt16 nFormat = aGrFilter.GetExportFormatNumberForShortName( aFormatShortName ); - - if ( nFormat != GRFILTER_FORMAT_DONTKNOW ) + uno::Reference < graphic::XGraphicProvider > xGraphicProvider( comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.graphics.GraphicProvider") ), uno::UNO_QUERY ); + if( xGraphicProvider.is() ) { - SvMemoryStream aNewStream( 65535, 65535 ); - if ( aGrFilter.ExportGraphic( aGraph, String(), aNewStream, nFormat ) == ERRCODE_NONE ) + uno::Sequence< beans::PropertyValue > aMediaProperties( 1 ); + aMediaProperties[0].Name = ::rtl::OUString::createFromAscii( "InputStream" ); + aMediaProperties[0].Value <<= xIn; + uno::Reference< graphic::XGraphic > xGraphic( xGraphicProvider->queryGraphic( aMediaProperties ) ); + if( xGraphic.is() ) { - /* - { - aNewStream.Seek( 0 ); - SvFileStream aFile( String::CreateFromAscii( "file:///d:/test.png" ), STREAM_STD_READWRITE); - aFile.SetStreamSize( 0 ); - aNewStream >> aFile; - } - */ - - aResult <<= uno::Sequence< sal_Int8 >( - reinterpret_cast< const sal_Int8* >( aNewStream.GetData() ), - aNewStream.Seek( STREAM_SEEK_TO_END ) ); + SvMemoryStream aNewStream( 65535, 65535 ); + uno::Reference < io::XOutputStream > xOut = new utl::OOutputStreamHelper( aNewStream.GetLockBytes() ); + uno::Sequence< beans::PropertyValue > aOutMediaProperties( 2 ); + aMediaProperties[0].Name = ::rtl::OUString::createFromAscii( "OutputStream" ); + aMediaProperties[0].Value <<= xOut; + aMediaProperties[1].Name = ::rtl::OUString::createFromAscii( "MimeType" ); + aMediaProperties[0].Value <<= aMimeType; + + xGraphicProvider->storeGraphic( xGraphic, aOutMediaProperties ); + aResult <<= uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aNewStream.GetData() ), aNewStream.Seek( STREAM_SEEK_TO_END ) ); return sal_True; } } } + catch (uno::Exception&) + {} } return sal_False; @@ -96,7 +98,6 @@ sal_Bool ConvertBufferToFormat( void* pBuf, // ===================================================================== // MainThreadNotificationRequest // ===================================================================== - MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Reference< OleEmbeddedObject >& xObj, sal_uInt16 nNotificationType, sal_uInt32 nAspect ) : m_pObject( xObj.get() ) , m_xObject( static_cast< embed::XEmbeddedObject* >( xObj.get() ) ) @@ -104,49 +105,31 @@ MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Refer , m_nAspect( nAspect ) {} -void MainThreadNotificationRequest::mainThreadWorkerStart( MainThreadNotificationRequest* pMTRequest ) +void SAL_CALL MainThreadNotificationRequest::notify (const uno::Any& ) throw (uno::RuntimeException)
{ - if ( Application::GetMainThreadIdentifier() == osl_getThreadIdentifier( NULL ) ) + if ( m_pObject ) { - // this is the main thread - worker( pMTRequest, pMTRequest ); - } - else - Application::PostUserEvent( STATIC_LINK( NULL, MainThreadNotificationRequest, worker ), pMTRequest ); -} - -IMPL_STATIC_LINK_NOINSTANCE( MainThreadNotificationRequest, worker, MainThreadNotificationRequest*, pMTRequest ) -{ - if ( pMTRequest ) - { - if ( pMTRequest->m_pObject ) + try { - try + uno::Reference< uno::XInterface > xLock = m_xObject.get(); + if ( xLock.is() ) { - uno::Reference< uno::XInterface > xLock = pMTRequest->m_xObject.get(); - if ( xLock.is() ) - { - // this is the main thread, the solar mutex must be locked - ::vos::OGuard aGuard( Application::GetSolarMutex() ); - if ( pMTRequest->m_nNotificationType == OLECOMP_ONCLOSE ) - pMTRequest->m_pObject->OnClosed_Impl(); - else if ( pMTRequest->m_nAspect == embed::Aspects::MSOLE_CONTENT ) - pMTRequest->m_pObject->OnViewChanged_Impl(); - else if ( pMTRequest->m_nAspect == embed::Aspects::MSOLE_ICON ) - pMTRequest->m_pObject->OnIconChanged_Impl(); - } - } - catch( uno::Exception& ) - { - // ignore all the errors + // this is the main thread, the solar mutex must be locked + if ( m_nNotificationType == OLECOMP_ONCLOSE ) + m_pObject->OnClosed_Impl(); + else if ( m_nAspect == embed::Aspects::MSOLE_CONTENT ) + m_pObject->OnViewChanged_Impl(); + else if ( m_nAspect == embed::Aspects::MSOLE_ICON ) + m_pObject->OnIconChanged_Impl(); } } - - delete pMTRequest; + catch( uno::Exception& ) + { + // ignore all the errors + } } - - return 0; } -// ===================================================================== - +MainThreadNotificationRequest::~MainThreadNotificationRequest() +{ +} diff --git a/embeddedobj/source/msole/makefile.mk b/embeddedobj/source/msole/makefile.mk index 2af3f28183d2..d095bed73aa9 100644 --- a/embeddedobj/source/msole/makefile.mk +++ b/embeddedobj/source/msole/makefile.mk @@ -91,13 +91,14 @@ EXCEPTIONSFILES += \ SHL1OBJS= $(SLOFILES) SHL1STDLIBS=\ + $(UNOTOOLSLIB)\ $(SALLIB)\ $(VOSLIB)\ $(CPPULIB)\ $(CPPUHELPERLIB)\ $(COMPHELPERLIB)\ - $(TOOLSLIB)\ - $(SVTOOLLIB) + $(TOOLSLIB) + .IF "$(GUI)"=="WNT" .IF "$(COM)"=="GCC" @@ -107,7 +108,6 @@ EMBOBJLIB=iembobj.lib .ENDIF SHL1STDLIBS+=\ - $(VCLLIB)\ $(EMBOBJLIB)\ $(OLE32LIB)\ $(GDI32LIB)\ @@ -118,7 +118,6 @@ DEF1EXPORTFILE= exports.dxp .ELIF "$(GUI)"=="OS2" SHL1STDLIBS+=\ - $(VCLLIB)\ iembobj.lib DEF1EXPORTFILE= exports.dxp diff --git a/embeddedobj/source/msole/mtnotification.hxx b/embeddedobj/source/msole/mtnotification.hxx index 46366fe62014..3f4d4fd624cc 100644 --- a/embeddedobj/source/msole/mtnotification.hxx +++ b/embeddedobj/source/msole/mtnotification.hxx @@ -30,7 +30,8 @@ #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/embed/XEmbeddedObject.hpp> -#include <cppuhelper/weakref.hxx> +#include <com/sun/star/awt/XCallback.hpp> +#include <cppuhelper/implbase1.hxx> #include <rtl/ref.hxx> @@ -39,7 +40,7 @@ class OleEmbeddedObject; #define OLECOMP_ONVIEWCHANGE 1 #define OLECOMP_ONCLOSE 2 -class MainThreadNotificationRequest +class MainThreadNotificationRequest : public cppu::WeakImplHelper1< com::sun::star::awt::XCallback > { OleEmbeddedObject* m_pObject; ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XEmbeddedObject > m_xObject; @@ -48,11 +49,10 @@ class MainThreadNotificationRequest sal_uInt32 m_nAspect; public: + virtual void SAL_CALL notify (const com::sun::star::uno::Any& rUserData) + throw (com::sun::star::uno::RuntimeException); MainThreadNotificationRequest( const ::rtl::Reference< OleEmbeddedObject >& xObj, sal_uInt16 nNotificationType, sal_uInt32 nAspect = 0 ); - - static long worker( MainThreadNotificationRequest*, MainThreadNotificationRequest* ); - - static void mainThreadWorkerStart( MainThreadNotificationRequest* ); + ~MainThreadNotificationRequest(); }; diff --git a/embeddedobj/source/msole/olecomponent.cxx b/embeddedobj/source/msole/olecomponent.cxx index 4402c94e097f..05aa7020baf2 100644 --- a/embeddedobj/source/msole/olecomponent.cxx +++ b/embeddedobj/source/msole/olecomponent.cxx @@ -37,10 +37,9 @@ #include <com/sun/star/ucb/XSimpleFileAccess.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/io/XTruncate.hpp> - +#include <com/sun/star/awt/XRequestCallback.hpp> #include <platform.h> - #include <cppuhelper/interfacecontainer.h> #include <comphelper/mimeconfighelper.hxx> #include <comphelper/storagehelper.hxx> @@ -194,43 +193,36 @@ struct OleComponentNative_Impl { ComSmart< IStorage > m_pIStorage; FormatEtcList m_aFormatsList; uno::Sequence< datatransfer::DataFlavor > m_aSupportedGraphFormats; - uno::Sequence< ::rtl::OUString > m_aGraphShortFormats; //short names for formats from previous sequence OleComponentNative_Impl() { // TODO: Extend format list m_aSupportedGraphFormats.realloc( 5 ); - m_aGraphShortFormats.realloc( 5 ); m_aSupportedGraphFormats[0] = datatransfer::DataFlavor( ::rtl::OUString::createFromAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ), ::rtl::OUString::createFromAscii( "Windows Enhanced Metafile" ), getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); - m_aGraphShortFormats[0] = ::rtl::OUString::createFromAscii( "EMF" ); m_aSupportedGraphFormats[1] = datatransfer::DataFlavor( ::rtl::OUString::createFromAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ), ::rtl::OUString::createFromAscii( "Windows Metafile" ), getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); - m_aGraphShortFormats[1] = ::rtl::OUString::createFromAscii( "WMF" ); m_aSupportedGraphFormats[2] = datatransfer::DataFlavor( ::rtl::OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ), ::rtl::OUString::createFromAscii( "Bitmap" ), getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); - m_aGraphShortFormats[2] = ::rtl::OUString::createFromAscii( "BMP" ); m_aSupportedGraphFormats[3] = datatransfer::DataFlavor( ::rtl::OUString::createFromAscii( "image/png" ), ::rtl::OUString::createFromAscii( "PNG" ), getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); - m_aGraphShortFormats[3] = ::rtl::OUString::createFromAscii( "PNG" ); m_aSupportedGraphFormats[0] = datatransfer::DataFlavor( ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ), ::rtl::OUString::createFromAscii( "GDIMetafile" ), getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); - m_aGraphShortFormats[0] = ::rtl::OUString::createFromAscii( "SVM" ); } void AddSupportedFormat( const FORMATETC& aFormatEtc ); @@ -372,7 +364,7 @@ sal_Bool OleComponentNative_Impl::ConvertDataForFlavor( const STGMEDIUM& aMedium && aFlavor.DataType == m_aSupportedGraphFormats[nInd].DataType && aFlavor.DataType == getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ) { - bAnyIsReady = ConvertBufferToFormat( ( void* )pBuf, nBufSize, m_aGraphShortFormats[nInd], aResult ); + bAnyIsReady = ConvertBufferToFormat( ( void* )pBuf, nBufSize, m_aSupportedGraphFormats[nInd].MimeType, aResult ); break; } } @@ -1424,9 +1416,11 @@ void OleComponent::OnViewChange_Impl( sal_uInt32 dwAspect ) if ( xLockObject.is() ) { - // the request will be deleted immedeatelly after execution by it's implementation - MainThreadNotificationRequest* pMTNotifRequest = new MainThreadNotificationRequest( xLockObject, OLECOMP_ONVIEWCHANGE, dwAspect ); - MainThreadNotificationRequest::mainThreadWorkerStart( pMTNotifRequest ); + uno::Reference < awt::XRequestCallback > xRequestCallback(
+ m_xFactory->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.awt.AsyncCallback") ),
+ uno::UNO_QUERY );
+ xRequestCallback->addCallback( new MainThreadNotificationRequest( xLockObject, OLECOMP_ONVIEWCHANGE, dwAspect ), uno::Any() );
} } @@ -1443,9 +1437,11 @@ void OleComponent::OnClose_Impl() if ( xLockObject.is() ) { - // the request will be deleted immedeatelly after execution by it's implementation - MainThreadNotificationRequest* pMTNotifRequest = new MainThreadNotificationRequest( xLockObject, OLECOMP_ONCLOSE ); - MainThreadNotificationRequest::mainThreadWorkerStart( pMTNotifRequest ); + uno::Reference < awt::XRequestCallback > xRequestCallback(
+ m_xFactory->createInstance(
+ ::rtl::OUString::createFromAscii("com.sun.star.awt.AsyncCallback") ),
+ uno::UNO_QUERY );
+ xRequestCallback->addCallback( new MainThreadNotificationRequest( xLockObject, OLECOMP_ONCLOSE ), uno::Any() );
} } |