Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / embeddedobj / source / msole / graphconvert.cxx
blob77caf58c7910d0c291809bcba7c8768efa1792a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <com/sun/star/embed/Aspects.hpp>
33 #include <com/sun/star/io/XInputStream.hpp>
34 #include <com/sun/star/io/XOutputStream.hpp>
35 #include <com/sun/star/graphic/GraphicProvider.hpp>
36 #include <com/sun/star/graphic/XGraphicProvider.hpp>
37 #include <com/sun/star/graphic/XGraphic.hpp>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <osl/mutex.hxx>
40 #include <unotools/streamwrap.hxx>
41 #include <comphelper/processfactory.hxx>
42 #include <comphelper/seqstream.hxx>
43 #include <tools/stream.hxx>
45 #include "mtnotification.hxx"
46 #include "oleembobj.hxx"
49 using namespace ::com::sun::star;
52 sal_Bool ConvertBufferToFormat( void* pBuf,
53 sal_uInt32 nBufSize,
54 const ::rtl::OUString& aMimeType,
55 uno::Any& aResult )
57 // produces sequence with data in requested format and returns it in aResult
58 if ( pBuf )
60 uno::Sequence < sal_Int8 > aData( (sal_Int8*)pBuf, nBufSize );
61 uno::Reference < io::XInputStream > xIn = new comphelper::SequenceInputStream( aData );
62 try
64 uno::Reference < graphic::XGraphicProvider > xGraphicProvider( graphic::GraphicProvider::create(comphelper::getProcessComponentContext()));
65 uno::Sequence< beans::PropertyValue > aMediaProperties( 1 );
66 aMediaProperties[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "InputStream" ));
67 aMediaProperties[0].Value <<= xIn;
68 uno::Reference< graphic::XGraphic > xGraphic( xGraphicProvider->queryGraphic( aMediaProperties ) );
69 if( xGraphic.is() )
71 SvMemoryStream aNewStream( 65535, 65535 );
72 uno::Reference < io::XStream > xOut = new utl::OStreamWrapper( aNewStream );
73 uno::Sequence< beans::PropertyValue > aOutMediaProperties( 2 );
74 aOutMediaProperties[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "OutputStream" ));
75 aOutMediaProperties[0].Value <<= xOut;
76 aOutMediaProperties[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MimeType" ));
77 aOutMediaProperties[1].Value <<= aMimeType;
79 xGraphicProvider->storeGraphic( xGraphic, aOutMediaProperties );
80 aResult <<= uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aNewStream.GetData() ), aNewStream.Seek( STREAM_SEEK_TO_END ) );
81 return sal_True;
84 catch (const uno::Exception&)
88 return sal_False;
91 // =====================================================================
92 // MainThreadNotificationRequest
93 // =====================================================================
94 MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Reference< OleEmbeddedObject >& xObj, sal_uInt16 nNotificationType, sal_uInt32 nAspect )
95 : m_pObject( xObj.get() )
96 , m_xObject( static_cast< embed::XEmbeddedObject* >( xObj.get() ) )
97 , m_nNotificationType( nNotificationType )
98 , m_nAspect( nAspect )
101 void SAL_CALL MainThreadNotificationRequest::notify (const uno::Any& ) throw (uno::RuntimeException)
103 if ( m_pObject )
107 uno::Reference< uno::XInterface > xLock = m_xObject.get();
108 if ( xLock.is() )
110 // this is the main thread, the solar mutex must be locked
111 if ( m_nNotificationType == OLECOMP_ONCLOSE )
112 m_pObject->OnClosed_Impl();
113 else if ( m_nAspect == embed::Aspects::MSOLE_CONTENT )
114 m_pObject->OnViewChanged_Impl();
115 else if ( m_nAspect == embed::Aspects::MSOLE_ICON )
116 m_pObject->OnIconChanged_Impl();
119 catch( const uno::Exception& )
121 // ignore all the errors
126 MainThreadNotificationRequest::~MainThreadNotificationRequest()
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */