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 <unotools/streamwrap.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/propertyvalue.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(u
"", aMemoryStream
, GRFILTER_FORMAT_DONTKNOW
, &nRetFormat
) == ERRCODE_NONE
&&
58 rFilter
.GetImportFormatMediaType(nRetFormat
) == aMimeType
)
60 aResult
<<= uno::Sequence
< sal_Int8
>( static_cast< const sal_Int8
* >( aMemoryStream
.GetData() ), aMemoryStream
.TellEnd() );
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
{ comphelper::makePropertyValue(
70 "InputStream", 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
{
77 comphelper::makePropertyValue("OutputStream", xOut
),
78 comphelper::makePropertyValue("MimeType", aMimeType
)
81 xGraphicProvider
->storeGraphic( xGraphic
, aOutMediaProperties
);
82 aResult
<<= uno::Sequence
< sal_Int8
>( static_cast< const sal_Int8
* >( aNewStream
.GetData() ), aNewStream
.TellEnd() );
86 catch (const uno::Exception
&)
94 // MainThreadNotificationRequest
96 MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Reference
< OleEmbeddedObject
>& xObj
, sal_uInt16 nNotificationType
, sal_uInt32 nAspect
)
97 : m_pObject( xObj
.get() )
98 , m_xObject( static_cast< embed::XEmbeddedObject
* >( xObj
.get() ) )
99 , m_nNotificationType( nNotificationType
)
100 , m_nAspect( nAspect
)
103 void SAL_CALL
MainThreadNotificationRequest::notify (const uno::Any
& )
109 uno::Reference
< uno::XInterface
> xLock
= m_xObject
.get();
112 // this is the main thread, the solar mutex must be locked
113 if ( m_nNotificationType
== OLECOMP_ONCLOSE
)
114 m_pObject
->OnClosed_Impl();
115 else if ( m_nAspect
== embed::Aspects::MSOLE_CONTENT
)
116 m_pObject
->OnViewChanged_Impl();
117 else if ( m_nAspect
== embed::Aspects::MSOLE_ICON
)
118 OleEmbeddedObject::OnIconChanged_Impl();
121 catch( const uno::Exception
& )
123 // ignore all the errors
128 MainThreadNotificationRequest::~MainThreadNotificationRequest()
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */