update dev300-m58
[ooovba.git] / embeddedobj / source / msole / graphconvert.cxx
blobdb79473e343cc4c0f59a556870a0db1c661335f3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: graphconvert.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
33 #include <com/sun/star/uno/Any.hxx>
34 #include <com/sun/star/uno/Reference.hxx>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include <com/sun/star/embed/Aspects.hpp>
38 #include "mtnotification.hxx"
39 #include "oleembobj.hxx"
41 // TODO: when conversion service is ready this headers should disappear
42 #include <svtools/filter.hxx>
43 #include <vcl/graph.hxx>
45 #include <tools/link.hxx>
46 #include <vcl/svapp.hxx>
47 #include <vos/mutex.hxx>
50 using namespace ::com::sun::star;
53 sal_Bool ConvertBufferToFormat( void* pBuf,
54 sal_uInt32 nBufSize,
55 const ::rtl::OUString& aFormatShortName,
56 uno::Any& aResult )
58 // produces sequence with data in requested format and returns it in aResult
59 if ( pBuf )
61 SvMemoryStream aBufStream( pBuf, nBufSize, STREAM_READ );
62 aBufStream.ObjectOwnsMemory( sal_False );
64 Graphic aGraph;
65 GraphicFilter aGrFilter( sal_True );
66 if ( aGrFilter.ImportGraphic( aGraph, String(), aBufStream ) == ERRCODE_NONE )
68 sal_uInt16 nFormat = aGrFilter.GetExportFormatNumberForShortName( aFormatShortName );
70 if ( nFormat != GRFILTER_FORMAT_DONTKNOW )
72 SvMemoryStream aNewStream( 65535, 65535 );
73 if ( aGrFilter.ExportGraphic( aGraph, String(), aNewStream, nFormat ) == ERRCODE_NONE )
77 aNewStream.Seek( 0 );
78 SvFileStream aFile( String::CreateFromAscii( "file:///d:/test.png" ), STREAM_STD_READWRITE);
79 aFile.SetStreamSize( 0 );
80 aNewStream >> aFile;
84 aResult <<= uno::Sequence< sal_Int8 >(
85 reinterpret_cast< const sal_Int8* >( aNewStream.GetData() ),
86 aNewStream.Seek( STREAM_SEEK_TO_END ) );
87 return sal_True;
93 return sal_False;
96 // =====================================================================
97 // MainThreadNotificationRequest
98 // =====================================================================
100 MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Reference< OleEmbeddedObject >& xObj, sal_uInt16 nNotificationType, sal_uInt32 nAspect )
101 : m_pObject( xObj.get() )
102 , m_xObject( static_cast< embed::XEmbeddedObject* >( xObj.get() ) )
103 , m_nNotificationType( nNotificationType )
104 , m_nAspect( nAspect )
107 void MainThreadNotificationRequest::mainThreadWorkerStart( MainThreadNotificationRequest* pMTRequest )
109 if ( Application::GetMainThreadIdentifier() == osl_getThreadIdentifier( NULL ) )
111 // this is the main thread
112 worker( pMTRequest, pMTRequest );
114 else
115 Application::PostUserEvent( STATIC_LINK( NULL, MainThreadNotificationRequest, worker ), pMTRequest );
118 IMPL_STATIC_LINK_NOINSTANCE( MainThreadNotificationRequest, worker, MainThreadNotificationRequest*, pMTRequest )
120 if ( pMTRequest )
122 if ( pMTRequest->m_pObject )
126 uno::Reference< uno::XInterface > xLock = pMTRequest->m_xObject.get();
127 if ( xLock.is() )
129 // this is the main thread, the solar mutex must be locked
130 ::vos::OGuard aGuard( Application::GetSolarMutex() );
131 if ( pMTRequest->m_nNotificationType == OLECOMP_ONCLOSE )
132 pMTRequest->m_pObject->OnClosed_Impl();
133 else if ( pMTRequest->m_nAspect == embed::Aspects::MSOLE_CONTENT )
134 pMTRequest->m_pObject->OnViewChanged_Impl();
135 else if ( pMTRequest->m_nAspect == embed::Aspects::MSOLE_ICON )
136 pMTRequest->m_pObject->OnIconChanged_Impl();
139 catch( uno::Exception& )
141 // ignore all the errors
145 delete pMTRequest;
148 return 0;
151 // =====================================================================