1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
35 #include <vcl/graphicfilter.hxx>
37 #include "mtnotification.hxx"
38 #include "oleembobj.hxx"
41 using namespace ::com::sun::star
;
44 sal_Bool
ConvertBufferToFormat( void* pBuf
,
46 const OUString
& aMimeType
,
49 // produces sequence with data in requested format and returns it in aResult
52 // First, in case the buffer is already in the requested format, then avoid a conversion.
53 SvMemoryStream
aMemoryStream(pBuf
, nBufSize
, StreamMode::READ
);
54 GraphicFilter
& rFilter
= GraphicFilter::GetGraphicFilter();
55 sal_uInt16 nRetFormat
= 0;
56 if (rFilter
.CanImportGraphic(OUString(), aMemoryStream
, GRFILTER_FORMAT_DONTKNOW
, &nRetFormat
) == GRFILTER_OK
&&
57 rFilter
.GetImportFormatMediaType(nRetFormat
) == aMimeType
)
59 aResult
<<= uno::Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( aMemoryStream
.GetData() ), aMemoryStream
.Seek( STREAM_SEEK_TO_END
) );
63 uno::Sequence
< sal_Int8
> aData( (sal_Int8
*)pBuf
, nBufSize
);
64 uno::Reference
< io::XInputStream
> xIn
= new comphelper::SequenceInputStream( aData
);
67 uno::Reference
< graphic::XGraphicProvider
> xGraphicProvider( graphic::GraphicProvider::create(comphelper::getProcessComponentContext()));
68 uno::Sequence
< beans::PropertyValue
> aMediaProperties( 1 );
69 aMediaProperties
[0].Name
= "InputStream";
70 aMediaProperties
[0].Value
<<= xIn
;
71 uno::Reference
< graphic::XGraphic
> xGraphic( xGraphicProvider
->queryGraphic( aMediaProperties
) );
74 SvMemoryStream
aNewStream( 65535, 65535 );
75 uno::Reference
< io::XStream
> xOut
= new utl::OStreamWrapper( aNewStream
);
76 uno::Sequence
< beans::PropertyValue
> aOutMediaProperties( 2 );
77 aOutMediaProperties
[0].Name
= "OutputStream";
78 aOutMediaProperties
[0].Value
<<= xOut
;
79 aOutMediaProperties
[1].Name
= "MimeType";
80 aOutMediaProperties
[1].Value
<<= aMimeType
;
82 xGraphicProvider
->storeGraphic( xGraphic
, aOutMediaProperties
);
83 aResult
<<= uno::Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( aNewStream
.GetData() ), aNewStream
.Seek( STREAM_SEEK_TO_END
) );
87 catch (const uno::Exception
&)
95 // MainThreadNotificationRequest
97 MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Reference
< OleEmbeddedObject
>& xObj
, sal_uInt16 nNotificationType
, sal_uInt32 nAspect
)
98 : m_pObject( xObj
.get() )
99 , m_xObject( static_cast< embed::XEmbeddedObject
* >( xObj
.get() ) )
100 , m_nNotificationType( nNotificationType
)
101 , m_nAspect( nAspect
)
104 void SAL_CALL
MainThreadNotificationRequest::notify (const uno::Any
& ) throw (uno::RuntimeException
)
110 uno::Reference
< uno::XInterface
> xLock
= m_xObject
.get();
113 // this is the main thread, the solar mutex must be locked
114 if ( m_nNotificationType
== OLECOMP_ONCLOSE
)
115 m_pObject
->OnClosed_Impl();
116 else if ( m_nAspect
== embed::Aspects::MSOLE_CONTENT
)
117 m_pObject
->OnViewChanged_Impl();
118 else if ( m_nAspect
== embed::Aspects::MSOLE_ICON
)
119 m_pObject
->OnIconChanged_Impl();
122 catch( const uno::Exception
& )
124 // ignore all the errors
129 MainThreadNotificationRequest::~MainThreadNotificationRequest()
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */