xref: /aoo41x/main/forms/source/component/imgprod.cxx (revision 24acc546)
1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "imgprod.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
30cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
33cdf0e10cSrcweir #include <svtools/filter.hxx>
34cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef SVTOOLS_SOURCE_MISC_IMAGERESOURCEACCESS_HXX
37cdf0e10cSrcweir #include "svtools/imageresourceaccess.hxx"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // --------------------
42cdf0e10cSrcweir // - ImgProdLockBytes -
43cdf0e10cSrcweir // --------------------
44cdf0e10cSrcweir 
45cdf0e10cSrcweir class ImgProdLockBytes : public SvLockBytes
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 		xStmRef;
48cdf0e10cSrcweir 	::com::sun::star::uno::Sequence<sal_Int8>		maSeq;
49cdf0e10cSrcweir 
ImgProdLockBytes()50cdf0e10cSrcweir 						ImgProdLockBytes() {};
51cdf0e10cSrcweir 
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 						ImgProdLockBytes( SvStream* pStm, sal_Bool bOwner );
55cdf0e10cSrcweir 						ImgProdLockBytes( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > & rStreamRef );
56cdf0e10cSrcweir 	virtual				~ImgProdLockBytes();
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	virtual ErrCode		ReadAt( sal_Size nPos, void* pBuffer, sal_Size nCount, sal_Size* pRead ) const;
59cdf0e10cSrcweir 	virtual ErrCode		WriteAt( sal_Size nPos, const void* pBuffer, sal_Size nCount, sal_Size* pWritten );
60cdf0e10cSrcweir 	virtual ErrCode		Flush() const;
61cdf0e10cSrcweir 	virtual ErrCode		SetSize( sal_Size nSize );
62cdf0e10cSrcweir 	virtual ErrCode		Stat( SvLockBytesStat*, SvLockBytesStatFlag ) const;
63cdf0e10cSrcweir };
64cdf0e10cSrcweir 
65cdf0e10cSrcweir // ------------------------------------------------------------------------
66cdf0e10cSrcweir 
ImgProdLockBytes(SvStream * pStm,sal_Bool bOwner)67cdf0e10cSrcweir ImgProdLockBytes::ImgProdLockBytes( SvStream* pStm, sal_Bool bOwner ) :
68cdf0e10cSrcweir 		SvLockBytes( pStm, bOwner )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ------------------------------------------------------------------------
73cdf0e10cSrcweir 
ImgProdLockBytes(::com::sun::star::uno::Reference<::com::sun::star::io::XInputStream> & rStmRef)74cdf0e10cSrcweir ImgProdLockBytes::ImgProdLockBytes( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > & rStmRef ) :
75cdf0e10cSrcweir 		xStmRef( rStmRef )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	if( xStmRef.is() )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		const sal_uInt32	nBytesToRead = 65535;
80cdf0e10cSrcweir 		sal_uInt32			nRead;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 		do
83cdf0e10cSrcweir 		{
84cdf0e10cSrcweir 			::com::sun::star::uno::Sequence< sal_Int8 > aReadSeq;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 			nRead = xStmRef->readSomeBytes( aReadSeq, nBytesToRead );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 			if( nRead )
89cdf0e10cSrcweir 			{
90cdf0e10cSrcweir 				const sal_uInt32 nOldLength = maSeq.getLength();
91cdf0e10cSrcweir 				maSeq.realloc( nOldLength + nRead );
92cdf0e10cSrcweir 				rtl_copyMemory( maSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
93cdf0e10cSrcweir 			}
94cdf0e10cSrcweir 		}
95cdf0e10cSrcweir 		while( nBytesToRead == nRead );
96cdf0e10cSrcweir 	}
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir // ------------------------------------------------------------------------
100cdf0e10cSrcweir 
~ImgProdLockBytes()101cdf0e10cSrcweir ImgProdLockBytes::~ImgProdLockBytes()
102cdf0e10cSrcweir {
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir // ------------------------------------------------------------------------
106cdf0e10cSrcweir 
ReadAt(sal_Size nPos,void * pBuffer,sal_Size nCount,sal_Size * pRead) const107cdf0e10cSrcweir ErrCode ImgProdLockBytes::ReadAt( sal_Size nPos, void* pBuffer, sal_Size nCount, sal_Size* pRead ) const
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	if( GetStream() )
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		( (SvStream*) GetStream() )->ResetError();
112cdf0e10cSrcweir 		const ErrCode nErr = SvLockBytes::ReadAt( nPos, pBuffer, nCount, pRead );
113cdf0e10cSrcweir 		( (SvStream*) GetStream() )->ResetError();
114cdf0e10cSrcweir 		return nErr;
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 	else
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		const sal_Size nSeqLen = maSeq.getLength();
119cdf0e10cSrcweir 		ErrCode nErr = ERRCODE_NONE;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 		if( nPos < nSeqLen )
122cdf0e10cSrcweir 		{
123cdf0e10cSrcweir 			if( ( nPos + nCount ) > nSeqLen )
124cdf0e10cSrcweir 				nCount = nSeqLen - nPos;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 			memcpy( pBuffer, maSeq.getConstArray() + nPos, nCount );
127cdf0e10cSrcweir 			*pRead = nCount;
128cdf0e10cSrcweir 		}
129cdf0e10cSrcweir 		else
130cdf0e10cSrcweir 			*pRead = 0UL;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 		return nErr;
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir // ------------------------------------------------------------------------
137cdf0e10cSrcweir 
WriteAt(sal_Size nPos,const void * pBuffer,sal_Size nCount,sal_Size * pWritten)138cdf0e10cSrcweir ErrCode ImgProdLockBytes::WriteAt( sal_Size nPos, const void* pBuffer, sal_Size nCount, sal_Size* pWritten )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	if( GetStream() )
141cdf0e10cSrcweir 		return SvLockBytes::WriteAt( nPos, pBuffer, nCount, pWritten );
142cdf0e10cSrcweir 	else
143cdf0e10cSrcweir 	{
144cdf0e10cSrcweir 		DBG_ASSERT( xStmRef.is(), "ImgProdLockBytes::WriteAt: xInputStream has no reference..." );
145cdf0e10cSrcweir 		return ERRCODE_IO_CANTWRITE;
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir // ------------------------------------------------------------------------
150cdf0e10cSrcweir 
Flush() const151cdf0e10cSrcweir ErrCode ImgProdLockBytes::Flush() const
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	return ERRCODE_NONE;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // ------------------------------------------------------------------------
157cdf0e10cSrcweir 
SetSize(sal_Size nSize)158cdf0e10cSrcweir ErrCode ImgProdLockBytes::SetSize( sal_Size nSize )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	if( GetStream() )
161cdf0e10cSrcweir 		return SvLockBytes::SetSize( nSize );
162cdf0e10cSrcweir 	else
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		DBG_ERROR( "ImgProdLockBytes::SetSize not supported for xInputStream..." );
165cdf0e10cSrcweir 		return ERRCODE_IO_CANTWRITE;
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir // ------------------------------------------------------------------------
170cdf0e10cSrcweir 
Stat(SvLockBytesStat * pStat,SvLockBytesStatFlag eFlag) const171cdf0e10cSrcweir ErrCode ImgProdLockBytes::Stat( SvLockBytesStat* pStat, SvLockBytesStatFlag eFlag ) const
172cdf0e10cSrcweir {
173cdf0e10cSrcweir 	if( GetStream() )
174cdf0e10cSrcweir 		return SvLockBytes::Stat( pStat, eFlag );
175cdf0e10cSrcweir 	else
176cdf0e10cSrcweir 	{
177cdf0e10cSrcweir 		DBG_ASSERT( xStmRef.is(), "ImgProdLockBytes::Stat: xInputStream has no reference..." );
178cdf0e10cSrcweir 		pStat->nSize = maSeq.getLength();
179cdf0e10cSrcweir 		return ERRCODE_NONE;
180cdf0e10cSrcweir 	}
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir // -----------------
184cdf0e10cSrcweir // - ImageProducer -
185cdf0e10cSrcweir // -----------------
186cdf0e10cSrcweir 
ImageProducer()187cdf0e10cSrcweir ImageProducer::ImageProducer() :
188cdf0e10cSrcweir 	mpStm		( NULL ),
189cdf0e10cSrcweir 	mbConsInit	( sal_False )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir 	mpGraphic = new Graphic;
192cdf0e10cSrcweir 	DBG_ASSERT( Application::GetFilterHdl().IsSet(), "ImageProducer::ImageProducer(): No filter handler set" );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir // ------------------------------------------------------------
196cdf0e10cSrcweir 
~ImageProducer()197cdf0e10cSrcweir ImageProducer::~ImageProducer()
198cdf0e10cSrcweir {
199cdf0e10cSrcweir 	delete mpGraphic;
200cdf0e10cSrcweir 	mpGraphic = NULL;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	delete mpStm;
203cdf0e10cSrcweir 	mpStm = NULL;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	for( void* pCons = maConsList.First(); pCons; pCons = maConsList.Next() )
206cdf0e10cSrcweir 		delete (::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir // ------------------------------------------------------------
210cdf0e10cSrcweir 
211cdf0e10cSrcweir // ::com::sun::star::uno::XInterface
queryInterface(const::com::sun::star::uno::Type & rType)212cdf0e10cSrcweir ::com::sun::star::uno::Any ImageProducer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
215cdf0e10cSrcweir 										SAL_STATIC_CAST( ::com::sun::star::lang::XInitialization*, this ),
216cdf0e10cSrcweir 										SAL_STATIC_CAST( ::com::sun::star::awt::XImageProducer*, this ) );
217cdf0e10cSrcweir 	return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir // ------------------------------------------------------------
221cdf0e10cSrcweir 
addConsumer(const::com::sun::star::uno::Reference<::com::sun::star::awt::XImageConsumer> & rxConsumer)222cdf0e10cSrcweir void ImageProducer::addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& rxConsumer ) throw(::com::sun::star::uno::RuntimeException)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	DBG_ASSERT( rxConsumer.is(), "::AddConsumer(...): No consumer referenced!" );
225cdf0e10cSrcweir 	if( rxConsumer.is() )
226cdf0e10cSrcweir 		maConsList.Insert( new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > ( rxConsumer ), LIST_APPEND );
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir // ------------------------------------------------------------
230cdf0e10cSrcweir 
removeConsumer(const::com::sun::star::uno::Reference<::com::sun::star::awt::XImageConsumer> & rxConsumer)231cdf0e10cSrcweir void ImageProducer::removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& rxConsumer ) throw(::com::sun::star::uno::RuntimeException)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	for( sal_uInt32 n = maConsList.Count(); n; )
234cdf0e10cSrcweir 	{
235cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > * pRef = (::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) maConsList.GetObject( --n );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 		if( *pRef == rxConsumer )
238cdf0e10cSrcweir 		{
239cdf0e10cSrcweir 			delete pRef;
240cdf0e10cSrcweir 			maConsList.Remove( n );
241cdf0e10cSrcweir 			break;
242cdf0e10cSrcweir 		}
243cdf0e10cSrcweir 	}
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir // ------------------------------------------------------------
247cdf0e10cSrcweir 
SetImage(const::rtl::OUString & rPath)248cdf0e10cSrcweir void ImageProducer::SetImage( const ::rtl::OUString& rPath )
249cdf0e10cSrcweir {
250cdf0e10cSrcweir 	maURL = rPath;
251cdf0e10cSrcweir 	mpGraphic->Clear();
252cdf0e10cSrcweir 	mbConsInit = sal_False;
253cdf0e10cSrcweir 	delete mpStm;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     if ( ::svt::GraphicAccess::isSupportedURL( maURL ) )
256cdf0e10cSrcweir     {
257cdf0e10cSrcweir         mpStm = ::svt::GraphicAccess::getImageStream( ::comphelper::getProcessServiceFactory(), maURL );
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir     else if( maURL.getLength() )
260cdf0e10cSrcweir 	{
261cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( maURL, STREAM_STD_READ );
262cdf0e10cSrcweir 		mpStm = pIStm ? new SvStream( new ImgProdLockBytes( pIStm, sal_True ) ) : NULL;
263cdf0e10cSrcweir 	}
264cdf0e10cSrcweir 	else
265cdf0e10cSrcweir 		mpStm = NULL;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir // ------------------------------------------------------------
269cdf0e10cSrcweir 
SetImage(SvStream & rStm)270cdf0e10cSrcweir void ImageProducer::SetImage( SvStream& rStm )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir 	maURL = ::rtl::OUString();
273cdf0e10cSrcweir 	mpGraphic->Clear();
274cdf0e10cSrcweir 	mbConsInit = sal_False;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	delete mpStm;
277cdf0e10cSrcweir 	mpStm = new SvStream( new ImgProdLockBytes( &rStm, sal_False ) );
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir // ------------------------------------------------------------
281cdf0e10cSrcweir 
setImage(::com::sun::star::uno::Reference<::com::sun::star::io::XInputStream> & rInputStmRef)282cdf0e10cSrcweir void ImageProducer::setImage( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > & rInputStmRef )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir 	maURL = ::rtl::OUString();
285cdf0e10cSrcweir 	mpGraphic->Clear();
286cdf0e10cSrcweir 	mbConsInit = sal_False;
287cdf0e10cSrcweir 	delete mpStm;
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	if( rInputStmRef.is() )
290cdf0e10cSrcweir 		mpStm = new SvStream( new ImgProdLockBytes( rInputStmRef ) );
291cdf0e10cSrcweir 	else
292cdf0e10cSrcweir 		mpStm = NULL;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir // ------------------------------------------------------------
296cdf0e10cSrcweir 
NewDataAvailable()297cdf0e10cSrcweir void ImageProducer::NewDataAvailable()
298cdf0e10cSrcweir {
299cdf0e10cSrcweir 	if( ( GRAPHIC_NONE == mpGraphic->GetType() ) || mpGraphic->GetContext() )
300cdf0e10cSrcweir 		startProduction();
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir // ------------------------------------------------------------
304cdf0e10cSrcweir 
startProduction()305cdf0e10cSrcweir void ImageProducer::startProduction() throw(::com::sun::star::uno::RuntimeException)
306cdf0e10cSrcweir {
307cdf0e10cSrcweir 	if( maConsList.Count() || maDoneHdl.IsSet() )
308cdf0e10cSrcweir 	{
309cdf0e10cSrcweir         bool bNotifyEmptyGraphics = false;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 		// valid stream or filled graphic? => update consumers
312cdf0e10cSrcweir 		if( mpStm || ( mpGraphic->GetType() != GRAPHIC_NONE ) )
313cdf0e10cSrcweir 		{
314cdf0e10cSrcweir 			// if we already have a graphic, we don't have to import again;
315cdf0e10cSrcweir 			// graphic is cleared if a new Stream is set
316cdf0e10cSrcweir 			if( ( mpGraphic->GetType() == GRAPHIC_NONE ) || mpGraphic->GetContext() )
317cdf0e10cSrcweir 			{
318cdf0e10cSrcweir 				if ( ImplImportGraphic( *mpGraphic ) && maDoneHdl.IsSet() )
319cdf0e10cSrcweir                     maDoneHdl.Call( mpGraphic );
320cdf0e10cSrcweir 			}
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 			if( mpGraphic->GetType() != GRAPHIC_NONE )
323cdf0e10cSrcweir 				ImplUpdateData( *mpGraphic );
324cdf0e10cSrcweir             else
325cdf0e10cSrcweir                 bNotifyEmptyGraphics = true;
326cdf0e10cSrcweir 		}
327cdf0e10cSrcweir 		else
328cdf0e10cSrcweir             bNotifyEmptyGraphics = true;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir         if ( bNotifyEmptyGraphics )
331cdf0e10cSrcweir 		{
332cdf0e10cSrcweir 			// reset image
333cdf0e10cSrcweir 			List	aTmp;
334cdf0e10cSrcweir 			void*	pCons;
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 			// create temporary list to hold interfaces
337cdf0e10cSrcweir 			for( pCons = maConsList.First(); pCons; pCons = maConsList.Next() )
338cdf0e10cSrcweir 				aTmp.Insert( new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > ( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons ), LIST_APPEND );
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 			// iterate through interfaces
341cdf0e10cSrcweir 			for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
342cdf0e10cSrcweir 			{
343cdf0e10cSrcweir 				( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons )->init( 0, 0 );
344cdf0e10cSrcweir 				( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons )->complete( ::com::sun::star::awt::ImageStatus::IMAGESTATUS_STATICIMAGEDONE, this );
345cdf0e10cSrcweir 			}
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 			// delete interfaces in temporary list
348cdf0e10cSrcweir 			for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
349cdf0e10cSrcweir 				delete (::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons;
350cdf0e10cSrcweir 
351cdf0e10cSrcweir             if ( maDoneHdl.IsSet() )
352cdf0e10cSrcweir                 maDoneHdl.Call( NULL );
353cdf0e10cSrcweir 		}
354cdf0e10cSrcweir 	}
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir // ------------------------------------------------------------
358cdf0e10cSrcweir 
ImplImportGraphic(Graphic & rGraphic)359cdf0e10cSrcweir sal_Bool ImageProducer::ImplImportGraphic( Graphic& rGraphic )
360cdf0e10cSrcweir {
361cdf0e10cSrcweir     if( ERRCODE_IO_PENDING == mpStm->GetError() )
362cdf0e10cSrcweir 		mpStm->ResetError();
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	mpStm->Seek( 0UL );
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 	sal_Bool bRet = GraphicConverter::Import( *mpStm, rGraphic ) == ERRCODE_NONE;
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 	if( ERRCODE_IO_PENDING == mpStm->GetError() )
369cdf0e10cSrcweir 		mpStm->ResetError();
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	return bRet;
372cdf0e10cSrcweir }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir // ------------------------------------------------------------
375cdf0e10cSrcweir 
ImplUpdateData(const Graphic & rGraphic)376cdf0e10cSrcweir void ImageProducer::ImplUpdateData( const Graphic& rGraphic )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir 	ImplInitConsumer( rGraphic );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 	if( mbConsInit && maConsList.Count() )
381cdf0e10cSrcweir 	{
382cdf0e10cSrcweir 		List	aTmp;
383cdf0e10cSrcweir 		void*	pCons;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 		ImplUpdateConsumer( rGraphic );
386cdf0e10cSrcweir 		mbConsInit = sal_False;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 		// create temporary list to hold interfaces
389cdf0e10cSrcweir 		for( pCons = maConsList.First(); pCons; pCons = maConsList.Next() )
390cdf0e10cSrcweir 			aTmp.Insert( new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > ( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons ), LIST_APPEND );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 		// iterate through interfaces
393cdf0e10cSrcweir 		for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
394cdf0e10cSrcweir 			( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons )->complete( ::com::sun::star::awt::ImageStatus::IMAGESTATUS_STATICIMAGEDONE, this );
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 		// delete interfaces in temporary list
397cdf0e10cSrcweir 		for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
398cdf0e10cSrcweir 			delete (::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons;
399cdf0e10cSrcweir 	}
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir // ------------------------------------------------------------
403cdf0e10cSrcweir 
ImplInitConsumer(const Graphic & rGraphic)404cdf0e10cSrcweir void ImageProducer::ImplInitConsumer( const Graphic& rGraphic )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir 	Bitmap				aBmp( rGraphic.GetBitmapEx().GetBitmap() );
407cdf0e10cSrcweir 	BitmapReadAccess*	pBmpAcc = aBmp.AcquireReadAccess();
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 	if(	pBmpAcc )
410cdf0e10cSrcweir 	{
411cdf0e10cSrcweir 		List             aTmp;
412cdf0e10cSrcweir 		void *           pCons;
413cdf0e10cSrcweir 		sal_uInt16       nPalCount = 0;
414cdf0e10cSrcweir 		sal_uInt32       nRMask = 0;
415cdf0e10cSrcweir 		sal_uInt32       nGMask = 0;
416cdf0e10cSrcweir 		sal_uInt32       nBMask = 0;
417cdf0e10cSrcweir 		sal_uInt32       nAMask = 0;
418cdf0e10cSrcweir 		::com::sun::star::uno::Sequence< sal_Int32 >	aRGBPal;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 		if( pBmpAcc->HasPalette() )
421cdf0e10cSrcweir 		{
422cdf0e10cSrcweir 			nPalCount = pBmpAcc->GetPaletteEntryCount();
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 			if( nPalCount )
425cdf0e10cSrcweir 			{
426cdf0e10cSrcweir 				aRGBPal = ::com::sun::star::uno::Sequence< sal_Int32 >( nPalCount + 1 );
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 				sal_Int32* pTmp = aRGBPal.getArray();
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 				for( sal_uInt32 i = 0; i < nPalCount; i++, pTmp++ )
431cdf0e10cSrcweir 				{
432cdf0e10cSrcweir 					const BitmapColor& rCol = pBmpAcc->GetPaletteColor( (sal_uInt16) i );
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 					*pTmp = ( (sal_Int32) rCol.GetRed() ) << (sal_Int32)(24L);
435cdf0e10cSrcweir 					*pTmp |= ( (sal_Int32) rCol.GetGreen() ) << (sal_Int32)(16L);
436cdf0e10cSrcweir 					*pTmp |= ( (sal_Int32) rCol.GetBlue() ) << (sal_Int32)(8L);
437cdf0e10cSrcweir 					*pTmp |= (sal_Int32)(0x000000ffL);
438cdf0e10cSrcweir 				}
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 				if( rGraphic.IsTransparent() )
441cdf0e10cSrcweir 				{
442cdf0e10cSrcweir 					// append transparent entry
443cdf0e10cSrcweir 					*pTmp = (sal_Int32)(0xffffff00L);
444cdf0e10cSrcweir 					mnTransIndex = nPalCount;
445cdf0e10cSrcweir 					nPalCount++;
446cdf0e10cSrcweir 				}
447cdf0e10cSrcweir 				else
448cdf0e10cSrcweir 					mnTransIndex = 0;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 			}
451cdf0e10cSrcweir 		}
452cdf0e10cSrcweir 		else
453cdf0e10cSrcweir 		{
454cdf0e10cSrcweir 			nRMask = 0xff000000UL;
455cdf0e10cSrcweir 			nGMask = 0x00ff0000UL;
456cdf0e10cSrcweir 			nBMask = 0x0000ff00UL;
457cdf0e10cSrcweir 			nAMask = 0x000000ffUL;
458cdf0e10cSrcweir 		}
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 		// create temporary list to hold interfaces
461cdf0e10cSrcweir 		for( pCons = maConsList.First(); pCons; pCons = maConsList.Next() )
462cdf0e10cSrcweir 			aTmp.Insert( new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > ( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons ), LIST_APPEND );
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 		// iterate through interfaces
465cdf0e10cSrcweir 		for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
466cdf0e10cSrcweir 		{
467cdf0e10cSrcweir 			( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons )->init( pBmpAcc->Width(), pBmpAcc->Height() );
468cdf0e10cSrcweir 			( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons )->setColorModel( pBmpAcc->GetBitCount(),
469cdf0e10cSrcweir 													   aRGBPal, nRMask, nGMask, nBMask, nAMask );
470cdf0e10cSrcweir 		}
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 		// delete interfaces in temporary list
473cdf0e10cSrcweir 		for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
474cdf0e10cSrcweir 			delete (::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons;
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 		aBmp.ReleaseAccess( pBmpAcc );
477cdf0e10cSrcweir 		mbConsInit = sal_True;
478cdf0e10cSrcweir 	}
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir // ------------------------------------------------------------
482cdf0e10cSrcweir 
ImplUpdateConsumer(const Graphic & rGraphic)483cdf0e10cSrcweir void ImageProducer::ImplUpdateConsumer( const Graphic& rGraphic )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir 	BitmapEx			aBmpEx( rGraphic.GetBitmapEx() );
486cdf0e10cSrcweir 	Bitmap				aBmp( aBmpEx.GetBitmap() );
487cdf0e10cSrcweir 	BitmapReadAccess*	pBmpAcc = aBmp.AcquireReadAccess();
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 	if( pBmpAcc )
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 		List				aTmp;
492cdf0e10cSrcweir 		void*				pCons;
493cdf0e10cSrcweir 		Bitmap				aMask( aBmpEx.GetMask() );
494cdf0e10cSrcweir 		BitmapReadAccess*	pMskAcc = !!aMask ? aMask.AcquireReadAccess() : NULL;
495cdf0e10cSrcweir 		const long			nWidth = pBmpAcc->Width();
496cdf0e10cSrcweir 		const long			nHeight = pBmpAcc->Height();
497cdf0e10cSrcweir 		const long			nStartX = 0L;
498cdf0e10cSrcweir 		const long			nEndX = nWidth - 1L;
499cdf0e10cSrcweir 		const long			nStartY = 0L;
500cdf0e10cSrcweir 		const long			nEndY = nHeight - 1L;
501cdf0e10cSrcweir 		const long			nPartWidth = nEndX - nStartX + 1;
502cdf0e10cSrcweir 		const long			nPartHeight = nEndY - nStartY + 1;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 		if( !pMskAcc )
505cdf0e10cSrcweir 		{
506cdf0e10cSrcweir 			aMask = Bitmap( aBmp.GetSizePixel(), 1 );
507cdf0e10cSrcweir 			aMask.Erase( COL_BLACK );
508cdf0e10cSrcweir 			pMskAcc = aMask.AcquireReadAccess();
509cdf0e10cSrcweir 		}
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 		// create temporary list to hold interfaces
512cdf0e10cSrcweir 		for( pCons = maConsList.First(); pCons; pCons = maConsList.Next() )
513cdf0e10cSrcweir 			aTmp.Insert( new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > ( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons ), LIST_APPEND );
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 		if( pBmpAcc->HasPalette() )
516cdf0e10cSrcweir 		{
517cdf0e10cSrcweir 			const BitmapColor aWhite( pMskAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 			if( mnTransIndex < 256 )
520cdf0e10cSrcweir 			{
521cdf0e10cSrcweir 				::com::sun::star::uno::Sequence<sal_Int8>	aData( nPartWidth * nPartHeight );
522cdf0e10cSrcweir 				sal_Int8*									pTmp = aData.getArray();
523cdf0e10cSrcweir 
524cdf0e10cSrcweir 				for( long nY = nStartY; nY <= nEndY; nY++ )
525cdf0e10cSrcweir 				{
526cdf0e10cSrcweir 					for( long nX = nStartX; nX <= nEndX; nX++ )
527cdf0e10cSrcweir 					{
528cdf0e10cSrcweir 						if( pMskAcc->GetPixel( nY, nX ) == aWhite )
529cdf0e10cSrcweir 							*pTmp++ = sal::static_int_cast< sal_Int8 >(
530cdf0e10cSrcweir                                 mnTransIndex );
531cdf0e10cSrcweir 						else
532cdf0e10cSrcweir 							*pTmp++ = pBmpAcc->GetPixel( nY, nX ).GetIndex();
533cdf0e10cSrcweir 					}
534cdf0e10cSrcweir 				}
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 				// iterate through interfaces
537cdf0e10cSrcweir 				for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
538cdf0e10cSrcweir 					( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons )->setPixelsByBytes( nStartX, nStartY, nPartWidth, nPartHeight,
539cdf0e10cSrcweir 																	   aData, 0UL, nPartWidth );
540cdf0e10cSrcweir 			}
541cdf0e10cSrcweir 			else
542cdf0e10cSrcweir 			{
543cdf0e10cSrcweir 				::com::sun::star::uno::Sequence<sal_Int32>	aData( nPartWidth * nPartHeight );
544cdf0e10cSrcweir 				sal_Int32*									pTmp = aData.getArray();
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 				for( long nY = nStartY; nY <= nEndY; nY++ )
547cdf0e10cSrcweir 				{
548cdf0e10cSrcweir 					for( long nX = nStartX; nX <= nEndX; nX++ )
549cdf0e10cSrcweir 					{
550cdf0e10cSrcweir 						if( pMskAcc->GetPixel( nY, nX ) == aWhite )
551cdf0e10cSrcweir 							*pTmp++ = mnTransIndex;
552cdf0e10cSrcweir 						else
553cdf0e10cSrcweir 							*pTmp++ = pBmpAcc->GetPixel( nY, nX ).GetIndex();
554cdf0e10cSrcweir 					}
555cdf0e10cSrcweir 				}
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 				// iterate through interfaces
558cdf0e10cSrcweir 				for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
559cdf0e10cSrcweir 					( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons )->setPixelsByLongs( nStartX, nStartY, nPartWidth, nPartHeight,
560cdf0e10cSrcweir 																	   aData, 0UL, nPartWidth );
561cdf0e10cSrcweir 			}
562cdf0e10cSrcweir 		}
563cdf0e10cSrcweir 		else
564cdf0e10cSrcweir 		{
565cdf0e10cSrcweir 			::com::sun::star::uno::Sequence<sal_Int32> 	aData( nPartWidth * nPartHeight );
566cdf0e10cSrcweir 			const BitmapColor							aWhite( pMskAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
567cdf0e10cSrcweir 			sal_Int32*									pTmp = aData.getArray();
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 			for( long nY = nStartY; nY <= nEndY; nY++ )
570cdf0e10cSrcweir 			{
571cdf0e10cSrcweir 				for( long nX = nStartX; nX <= nEndX; nX++, pTmp++ )
572cdf0e10cSrcweir 				{
573cdf0e10cSrcweir 					const BitmapColor aCol( pBmpAcc->GetPixel( nY, nX ) );
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 					*pTmp = ( (sal_Int32) aCol.GetRed() ) << (sal_Int32)(24L);
576cdf0e10cSrcweir 					*pTmp |= ( (sal_Int32) aCol.GetGreen() ) << (sal_Int32)(16L);
577cdf0e10cSrcweir 					*pTmp |= ( (sal_Int32) aCol.GetBlue() ) << (sal_Int32)(8L);
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 					if( pMskAcc->GetPixel( nY, nX ) != aWhite )
580cdf0e10cSrcweir 						*pTmp |= 0x000000ffUL;
581cdf0e10cSrcweir 				}
582cdf0e10cSrcweir 			}
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 			// iterate through interfaces
585cdf0e10cSrcweir 			for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
586cdf0e10cSrcweir 				( *(::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons )->setPixelsByLongs( nStartX, nStartY, nPartWidth, nPartHeight,
587cdf0e10cSrcweir 																   aData, 0UL, nPartWidth );
588cdf0e10cSrcweir 		}
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 		// delete interfaces in temporary list
591cdf0e10cSrcweir 		for( pCons = aTmp.First(); pCons; pCons = aTmp.Next() )
592cdf0e10cSrcweir 			delete (::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer > *) pCons;
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 		aBmp.ReleaseAccess( pBmpAcc );
595cdf0e10cSrcweir 		aMask.ReleaseAccess( pMskAcc );
596cdf0e10cSrcweir 	}
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
initialize(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & aArguments)599cdf0e10cSrcweir void ImageProducer::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
600cdf0e10cSrcweir {
601cdf0e10cSrcweir 	if ( aArguments.getLength() == 1 )
602cdf0e10cSrcweir 	{
603cdf0e10cSrcweir 		::com::sun::star::uno::Any aArg = aArguments.getConstArray()[0];
604cdf0e10cSrcweir 		rtl::OUString aURL;
605cdf0e10cSrcweir 		if ( aArg >>= aURL )
606cdf0e10cSrcweir 		{
607cdf0e10cSrcweir 			SetImage( aURL );
608cdf0e10cSrcweir 		}
609cdf0e10cSrcweir 	}
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir namespace frm
613cdf0e10cSrcweir {
614cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
ImageProducer_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> &)615cdf0e10cSrcweir SAL_CALL ImageProducer_CreateInstance(
616cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& )
617cdf0e10cSrcweir {
618cdf0e10cSrcweir 	return ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface >(
619cdf0e10cSrcweir 		( ::cppu::OWeakObject* ) new ImageProducer );
620cdf0e10cSrcweir }
621cdf0e10cSrcweir } // namespace frm
622