LibreOffice Module embeddedobj (master) 1
graphconvert.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
34#include <tools/stream.hxx>
35#include <vcl/graphicfilter.hxx>
36
37#include "graphconvert.hxx"
38#include "mtnotification.hxx"
39#include <oleembobj.hxx>
40
41
42using namespace ::com::sun::star;
43
44
45bool ConvertBufferToFormat( void* pBuf,
46 sal_uInt32 nBufSize,
47 const OUString& aMimeType,
48 uno::Any& aResult )
49{
50 // produces sequence with data in requested format and returns it in aResult
51 if ( pBuf )
52 {
53 // First, in case the buffer is already in the requested format, then avoid a conversion.
54 SvMemoryStream aMemoryStream(pBuf, nBufSize, StreamMode::READ);
56 sal_uInt16 nRetFormat = 0;
57 if (rFilter.CanImportGraphic(u"", aMemoryStream, GRFILTER_FORMAT_DONTKNOW, &nRetFormat) == ERRCODE_NONE &&
58 rFilter.GetImportFormatMediaType(nRetFormat) == aMimeType)
59 {
60 aResult <<= uno::Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemoryStream.GetData() ), aMemoryStream.TellEnd() );
61 return true;
62 }
63
64 uno::Sequence < sal_Int8 > aData( static_cast<sal_Int8*>(pBuf), nBufSize );
65 uno::Reference < io::XInputStream > xIn = new comphelper::SequenceInputStream( aData );
66 try
67 {
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 ) );
72 if( xGraphic.is() )
73 {
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),
79 };
80
81 xGraphicProvider->storeGraphic( xGraphic, aOutMediaProperties );
82 aResult <<= uno::Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aNewStream.GetData() ), aNewStream.TellEnd() );
83 return true;
84 }
85 }
86 catch (const uno::Exception&)
87 {}
88 }
89
90 return false;
91}
92
93
94// MainThreadNotificationRequest
95
96MainThreadNotificationRequest::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 )
101{}
102
104{
105 if ( m_pObject )
106 {
107 try
108 {
109 uno::Reference< uno::XInterface > xLock = m_xObject.get();
110 if ( xLock.is() )
111 {
112 // this is the main thread, the solar mutex must be locked
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();
119 }
120 }
121 catch( const uno::Exception& )
122 {
123 // ignore all the errors
124 }
125 }
126}
127
129{
130}
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static GraphicFilter & GetGraphicFilter()
ErrCode CanImportGraphic(const INetURLObject &rPath, sal_uInt16 nFormat, sal_uInt16 *pDeterminedFormat)
OleEmbeddedObject * m_pObject
virtual void SAL_CALL notify(const css::uno::Any &rUserData) override
MainThreadNotificationRequest(const ::rtl::Reference< OleEmbeddedObject > &xObj, sal_uInt16 nNotificationType, sal_uInt32 nAspect=0)
css::uno::WeakReference< css::embed::XEmbeddedObject > m_xObject
const void * GetData()
virtual sal_uInt64 TellEnd() override
float u
#define ERRCODE_NONE
bool ConvertBufferToFormat(void *pBuf, sal_uInt32 nBufSize, const OUString &aMimeType, uno::Any &aResult)
#define GRFILTER_FORMAT_DONTKNOW
#define OLECOMP_ONCLOSE
constexpr OUStringLiteral aData
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
const sal_Unicode *const aMimeType[]
signed char sal_Int8