1*bfd08df8SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*bfd08df8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*bfd08df8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*bfd08df8SAndrew Rist  * distributed with this work for additional information
6*bfd08df8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*bfd08df8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*bfd08df8SAndrew Rist  * "License"); you may not use this file except in compliance
9*bfd08df8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*bfd08df8SAndrew Rist  *
11*bfd08df8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*bfd08df8SAndrew Rist  *
13*bfd08df8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*bfd08df8SAndrew Rist  * software distributed under the License is distributed on an
15*bfd08df8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*bfd08df8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*bfd08df8SAndrew Rist  * specific language governing permissions and limitations
18*bfd08df8SAndrew Rist  * under the License.
19*bfd08df8SAndrew Rist  *
20*bfd08df8SAndrew Rist  *************************************************************/
21*bfd08df8SAndrew Rist 
22*bfd08df8SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx"
26cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
27cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
28cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
29cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
31cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
32cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicProvider.hpp>
33cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp>
34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
35cdf0e10cSrcweir #include <tools/link.hxx>
36cdf0e10cSrcweir #include <vos/mutex.hxx>
37cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
38cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
39cdf0e10cSrcweir #include <comphelper/seqstream.hxx>
40cdf0e10cSrcweir #include <tools/stream.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include "mtnotification.hxx"
43cdf0e10cSrcweir #include "oleembobj.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using namespace ::com::sun::star;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
ConvertBufferToFormat(void * pBuf,sal_uInt32 nBufSize,const::rtl::OUString & aMimeType,uno::Any & aResult)49cdf0e10cSrcweir sal_Bool ConvertBufferToFormat( void* pBuf,
50cdf0e10cSrcweir 								sal_uInt32 nBufSize,
51cdf0e10cSrcweir 								const ::rtl::OUString& aMimeType,
52cdf0e10cSrcweir 								uno::Any& aResult )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	// produces sequence with data in requested format and returns it in aResult
55cdf0e10cSrcweir 	if ( pBuf )
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		uno::Sequence < sal_Int8 > aData( (sal_Int8*)pBuf, nBufSize );
58cdf0e10cSrcweir 		uno::Reference < io::XInputStream > xIn = new comphelper::SequenceInputStream( aData );
59cdf0e10cSrcweir 		try
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir 			uno::Reference < graphic::XGraphicProvider > xGraphicProvider( comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.graphic.GraphicProvider") ), uno::UNO_QUERY );
62cdf0e10cSrcweir 			if( xGraphicProvider.is() )
63cdf0e10cSrcweir 			{
64cdf0e10cSrcweir 				uno::Sequence< beans::PropertyValue > aMediaProperties( 1 );
65cdf0e10cSrcweir 				aMediaProperties[0].Name = ::rtl::OUString::createFromAscii( "InputStream" );
66cdf0e10cSrcweir 				aMediaProperties[0].Value <<= xIn;
67cdf0e10cSrcweir 				uno::Reference< graphic::XGraphic > xGraphic( xGraphicProvider->queryGraphic( aMediaProperties  ) );
68cdf0e10cSrcweir 				if( xGraphic.is() )
69cdf0e10cSrcweir 				{
70cdf0e10cSrcweir 					SvMemoryStream aNewStream( 65535, 65535 );
71cdf0e10cSrcweir //					uno::Reference < io::XOutputStream > xOut = new utl::OOutputStreamHelper( aNewStream.GetLockBytes() );
72cdf0e10cSrcweir 					uno::Reference < io::XStream > xOut = new utl::OStreamWrapper( aNewStream );
73cdf0e10cSrcweir 					uno::Sequence< beans::PropertyValue > aOutMediaProperties( 2 );
74cdf0e10cSrcweir 					aOutMediaProperties[0].Name = ::rtl::OUString::createFromAscii( "OutputStream" );
75cdf0e10cSrcweir 					aOutMediaProperties[0].Value <<= xOut;
76cdf0e10cSrcweir 					aOutMediaProperties[1].Name = ::rtl::OUString::createFromAscii( "MimeType" );
77cdf0e10cSrcweir 					aOutMediaProperties[1].Value <<= aMimeType;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 					xGraphicProvider->storeGraphic( xGraphic, aOutMediaProperties );
80cdf0e10cSrcweir 					aResult <<= uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aNewStream.GetData() ), aNewStream.Seek( STREAM_SEEK_TO_END ) );
81cdf0e10cSrcweir 					return sal_True;
82cdf0e10cSrcweir 				}
83cdf0e10cSrcweir 			}
84cdf0e10cSrcweir 		}
85cdf0e10cSrcweir 		catch (uno::Exception&)
86cdf0e10cSrcweir 		{}
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	return sal_False;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // =====================================================================
93cdf0e10cSrcweir // MainThreadNotificationRequest
94cdf0e10cSrcweir // =====================================================================
MainThreadNotificationRequest(const::rtl::Reference<OleEmbeddedObject> & xObj,sal_uInt16 nNotificationType,sal_uInt32 nAspect)95cdf0e10cSrcweir MainThreadNotificationRequest::MainThreadNotificationRequest( const ::rtl::Reference< OleEmbeddedObject >& xObj, sal_uInt16 nNotificationType, sal_uInt32 nAspect )
96cdf0e10cSrcweir : m_pObject( xObj.get() )
97cdf0e10cSrcweir , m_xObject( static_cast< embed::XEmbeddedObject* >( xObj.get() ) )
98cdf0e10cSrcweir , m_nNotificationType( nNotificationType )
99cdf0e10cSrcweir , m_nAspect( nAspect )
100cdf0e10cSrcweir {}
101cdf0e10cSrcweir 
notify(const uno::Any &)102cdf0e10cSrcweir void SAL_CALL MainThreadNotificationRequest::notify (const uno::Any& ) throw (uno::RuntimeException)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	if ( m_pObject )
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		try
107cdf0e10cSrcweir 		{
108cdf0e10cSrcweir 			uno::Reference< uno::XInterface > xLock = m_xObject.get();
109cdf0e10cSrcweir 			if ( xLock.is() )
110cdf0e10cSrcweir 			{
111cdf0e10cSrcweir 				// this is the main thread, the solar mutex must be locked
112cdf0e10cSrcweir 				if ( m_nNotificationType == OLECOMP_ONCLOSE )
113cdf0e10cSrcweir 					m_pObject->OnClosed_Impl();
114cdf0e10cSrcweir 				else if ( m_nAspect == embed::Aspects::MSOLE_CONTENT )
115cdf0e10cSrcweir 					m_pObject->OnViewChanged_Impl();
116cdf0e10cSrcweir 				else if ( m_nAspect == embed::Aspects::MSOLE_ICON )
117cdf0e10cSrcweir 					m_pObject->OnIconChanged_Impl();
118cdf0e10cSrcweir 			}
119cdf0e10cSrcweir 		}
120cdf0e10cSrcweir 		catch( uno::Exception& )
121cdf0e10cSrcweir 		{
122cdf0e10cSrcweir 			// ignore all the errors
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
~MainThreadNotificationRequest()127cdf0e10cSrcweir MainThreadNotificationRequest::~MainThreadNotificationRequest()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir }
130