Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / embeddedobj / source / msole / graphconvert.cxx
blob9883c490cb16e1330dac60fa5d67fd0d1a9ea53c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/uno/Any.hxx>
21 #include <com/sun/star/uno/Reference.hxx>
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/embed/Aspects.hpp>
24 #include <com/sun/star/io/XInputStream.hpp>
25 #include <com/sun/star/io/XOutputStream.hpp>
26 #include <com/sun/star/graphic/GraphicProvider.hpp>
27 #include <com/sun/star/graphic/XGraphicProvider.hpp>
28 #include <com/sun/star/graphic/XGraphic.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <osl/mutex.hxx>
31 #include <unotools/streamwrap.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <comphelper/seqstream.hxx>
34 #include <tools/stream.hxx>
36 #include "mtnotification.hxx"
37 #include "oleembobj.hxx"
40 using namespace ::com::sun::star;
43 sal_Bool ConvertBufferToFormat( void* pBuf,
44 sal_uInt32 nBufSize,
45 const OUString& aMimeType,
46 uno::Any& aResult )
48 // produces sequence with data in requested format and returns it in aResult
49 if ( pBuf )
51 uno::Sequence < sal_Int8 > aData( (sal_Int8*)pBuf, nBufSize );
52 uno::Reference < io::XInputStream > xIn = new comphelper::SequenceInputStream( aData );
53 try
55 uno::Reference < graphic::XGraphicProvider > xGraphicProvider( graphic::GraphicProvider::create(comphelper::getProcessComponentContext()));
56 uno::Sequence< beans::PropertyValue > aMediaProperties( 1 );
57 aMediaProperties[0].Name = "InputStream";
58 aMediaProperties[0].Value <<= xIn;
59 uno::Reference< graphic::XGraphic > xGraphic( xGraphicProvider->queryGraphic( aMediaProperties ) );
60 if( xGraphic.is() )
62 SvMemoryStream aNewStream( 65535, 65535 );
63 uno::Reference < io::XStream > xOut = new utl::OStreamWrapper( aNewStream );
64 uno::Sequence< beans::PropertyValue > aOutMediaProperties( 2 );
65 aOutMediaProperties[0].Name = "OutputStream";
66 aOutMediaProperties[0].Value <<= xOut;
67 aOutMediaProperties[1].Name = "MimeType";
68 aOutMediaProperties[1].Value <<= aMimeType;
70 xGraphicProvider->storeGraphic( xGraphic, aOutMediaProperties );
71 aResult <<= uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aNewStream.GetData() ), aNewStream.Seek( STREAM_SEEK_TO_END ) );
72 return sal_True;
75 catch (const uno::Exception&)
79 return sal_False;
82 // =====================================================================
83 // MainThreadNotificationRequest
84 // =====================================================================
85 MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Reference< OleEmbeddedObject >& xObj, sal_uInt16 nNotificationType, sal_uInt32 nAspect )
86 : m_pObject( xObj.get() )
87 , m_xObject( static_cast< embed::XEmbeddedObject* >( xObj.get() ) )
88 , m_nNotificationType( nNotificationType )
89 , m_nAspect( nAspect )
92 void SAL_CALL MainThreadNotificationRequest::notify (const uno::Any& ) throw (uno::RuntimeException)
94 if ( m_pObject )
96 try
98 uno::Reference< uno::XInterface > xLock = m_xObject.get();
99 if ( xLock.is() )
101 // this is the main thread, the solar mutex must be locked
102 if ( m_nNotificationType == OLECOMP_ONCLOSE )
103 m_pObject->OnClosed_Impl();
104 else if ( m_nAspect == embed::Aspects::MSOLE_CONTENT )
105 m_pObject->OnViewChanged_Impl();
106 else if ( m_nAspect == embed::Aspects::MSOLE_ICON )
107 m_pObject->OnIconChanged_Impl();
110 catch( const uno::Exception& )
112 // ignore all the errors
117 MainThreadNotificationRequest::~MainThreadNotificationRequest()
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */