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 <graphconvert.hxx>
38 #include "mtnotification.hxx"
39 #include "oleembobj.hxx"
42 using namespace ::com::sun::star
;
45 bool ConvertBufferToFormat( void* pBuf
,
47 const OUString
& aMimeType
,
50 // produces sequence with data in requested format and returns it in aResult
53 // First, in case the buffer is already in the requested format, then avoid a conversion.
54 SvMemoryStream
aMemoryStream(pBuf
, nBufSize
, StreamMode::READ
);
55 GraphicFilter
& rFilter
= GraphicFilter::GetGraphicFilter();
56 sal_uInt16 nRetFormat
= 0;
57 if (rFilter
.CanImportGraphic(OUString(), aMemoryStream
, GRFILTER_FORMAT_DONTKNOW
, &nRetFormat
) == GRFILTER_OK
&&
58 rFilter
.GetImportFormatMediaType(nRetFormat
) == aMimeType
)
60 aResult
<<= uno::Sequence
< sal_Int8
>( static_cast< const sal_Int8
* >( aMemoryStream
.GetData() ), aMemoryStream
.Seek( STREAM_SEEK_TO_END
) );
64 uno::Sequence
< sal_Int8
> aData( static_cast<sal_Int8
*>(pBuf
), nBufSize
);
65 uno::Reference
< io::XInputStream
> xIn
= new comphelper::SequenceInputStream( aData
);
68 uno::Reference
< graphic::XGraphicProvider
> xGraphicProvider( graphic::GraphicProvider::create(comphelper::getProcessComponentContext()));
69 uno::Sequence
< beans::PropertyValue
> aMediaProperties( 1 );
70 aMediaProperties
[0].Name
= "InputStream";
71 aMediaProperties
[0].Value
<<= xIn
;
72 uno::Reference
< graphic::XGraphic
> xGraphic( xGraphicProvider
->queryGraphic( aMediaProperties
) );
75 SvMemoryStream
aNewStream( 65535, 65535 );
76 uno::Reference
< io::XStream
> xOut
= new utl::OStreamWrapper( aNewStream
);
77 uno::Sequence
< beans::PropertyValue
> aOutMediaProperties( 2 );
78 aOutMediaProperties
[0].Name
= "OutputStream";
79 aOutMediaProperties
[0].Value
<<= xOut
;
80 aOutMediaProperties
[1].Name
= "MimeType";
81 aOutMediaProperties
[1].Value
<<= aMimeType
;
83 xGraphicProvider
->storeGraphic( xGraphic
, aOutMediaProperties
);
84 aResult
<<= uno::Sequence
< sal_Int8
>( static_cast< const sal_Int8
* >( aNewStream
.GetData() ), aNewStream
.Seek( STREAM_SEEK_TO_END
) );
88 catch (const uno::Exception
&)
96 // MainThreadNotificationRequest
98 MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Reference
< OleEmbeddedObject
>& xObj
, sal_uInt16 nNotificationType
, sal_uInt32 nAspect
)
99 : m_pObject( xObj
.get() )
100 , m_xObject( static_cast< embed::XEmbeddedObject
* >( xObj
.get() ) )
101 , m_nNotificationType( nNotificationType
)
102 , m_nAspect( nAspect
)
105 void SAL_CALL
MainThreadNotificationRequest::notify (const uno::Any
& ) throw (uno::RuntimeException
)
111 uno::Reference
< uno::XInterface
> xLock
= m_xObject
.get();
114 // this is the main thread, the solar mutex must be locked
115 if ( m_nNotificationType
== OLECOMP_ONCLOSE
)
116 m_pObject
->OnClosed_Impl();
117 else if ( m_nAspect
== embed::Aspects::MSOLE_CONTENT
)
118 m_pObject
->OnViewChanged_Impl();
119 else if ( m_nAspect
== embed::Aspects::MSOLE_ICON
)
120 OleEmbeddedObject::OnIconChanged_Impl();
123 catch( const uno::Exception
& )
125 // ignore all the errors
130 MainThreadNotificationRequest::~MainThreadNotificationRequest()
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */