1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "descriptor.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <rtl/uuid.h>
34*cdf0e10cSrcweir #include <vos/mutex.hxx>
35*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
36*cdf0e10cSrcweir #include <svtools/filter.hxx>
37*cdf0e10cSrcweir #include <svl/itemprop.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/graphic/GraphicType.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include "vcl/graph.hxx"
45*cdf0e10cSrcweir #include "vcl/svapp.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #define UNOGRAPHIC_GRAPHICTYPE 	1
48*cdf0e10cSrcweir #define UNOGRAPHIC_MIMETYPE		2
49*cdf0e10cSrcweir #define UNOGRAPHIC_SIZEPIXEL	3
50*cdf0e10cSrcweir #define UNOGRAPHIC_SIZE100THMM	4
51*cdf0e10cSrcweir #define UNOGRAPHIC_BITSPERPIXEL	5
52*cdf0e10cSrcweir #define UNOGRAPHIC_TRANSPARENT	6
53*cdf0e10cSrcweir #define UNOGRAPHIC_ALPHA		7
54*cdf0e10cSrcweir #define UNOGRAPHIC_ANIMATED		8
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir using namespace ::com::sun::star;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir namespace unographic {
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // ---------------------
61*cdf0e10cSrcweir // - GraphicDescriptor -
62*cdf0e10cSrcweir // ---------------------
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir GraphicDescriptor::GraphicDescriptor() :
65*cdf0e10cSrcweir 	::comphelper::PropertySetHelper( createPropertySetInfo(), SAL_NO_ACQUIRE ),
66*cdf0e10cSrcweir 	mpGraphic( NULL ),
67*cdf0e10cSrcweir 	meType( GRAPHIC_NONE ),
68*cdf0e10cSrcweir 	mnBitsPerPixel ( 0 ),
69*cdf0e10cSrcweir 	mbTransparent ( false ),
70*cdf0e10cSrcweir 	mbAlpha( false ),
71*cdf0e10cSrcweir 	mbAnimated( false )
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir // ------------------------------------------------------------------------------
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir GraphicDescriptor::~GraphicDescriptor()
78*cdf0e10cSrcweir 	throw()
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir // ------------------------------------------------------------------------------
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir void GraphicDescriptor::init( const ::Graphic& rGraphic )
85*cdf0e10cSrcweir 	throw()
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 	mpGraphic = &rGraphic;
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir // ------------------------------------------------------------------------------
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir void GraphicDescriptor::init( const ::rtl::OUString& rURL )
93*cdf0e10cSrcweir 	throw()
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 	SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ );
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	if( pIStm )
98*cdf0e10cSrcweir 	{
99*cdf0e10cSrcweir 		implCreate( *pIStm, &rURL );
100*cdf0e10cSrcweir 		delete pIStm;
101*cdf0e10cSrcweir 	}
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir // ------------------------------------------------------------------------------
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir void GraphicDescriptor::init( const uno::Reference< io::XInputStream >& rxIStm, const ::rtl::OUString& rURL )
107*cdf0e10cSrcweir 	throw()
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir 	SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rxIStm );
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 	if( pIStm )
112*cdf0e10cSrcweir 	{
113*cdf0e10cSrcweir 		implCreate( *pIStm, &rURL );
114*cdf0e10cSrcweir 		delete pIStm;
115*cdf0e10cSrcweir 	}
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // ------------------------------------------------------------------------------
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir bool GraphicDescriptor::isValid() const
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	return( mpGraphic ? ( mpGraphic->GetType() != GRAPHIC_NONE ) : ( meType != GRAPHIC_NONE ) );
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir // ------------------------------------------------------------------------------
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir void GraphicDescriptor::implCreate( SvStream& rIStm, const ::rtl::OUString* pURL )
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir 	String aURL;
130*cdf0e10cSrcweir 	if( pURL )
131*cdf0e10cSrcweir 		aURL = *pURL;
132*cdf0e10cSrcweir 	::GraphicDescriptor aDescriptor( rIStm, &aURL );
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	mpGraphic = NULL;
135*cdf0e10cSrcweir 	maMimeType = ::rtl::OUString();
136*cdf0e10cSrcweir 	meType = GRAPHIC_NONE;
137*cdf0e10cSrcweir 	mnBitsPerPixel = 0;
138*cdf0e10cSrcweir 	mbTransparent = false;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	if( aDescriptor.Detect( true ) && aDescriptor.GetFileFormat() != GFF_NOT )
141*cdf0e10cSrcweir 	{
142*cdf0e10cSrcweir 		const char* 			pMimeType = NULL;
143*cdf0e10cSrcweir 		sal_uInt8 				cType = graphic::GraphicType::EMPTY;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 		switch( aDescriptor.GetFileFormat() )
146*cdf0e10cSrcweir 		{
147*cdf0e10cSrcweir 			case( GFF_BMP ): pMimeType = MIMETYPE_BMP; cType = graphic::GraphicType::PIXEL; break;
148*cdf0e10cSrcweir 			case( GFF_GIF ): pMimeType = MIMETYPE_GIF; cType = graphic::GraphicType::PIXEL; break;
149*cdf0e10cSrcweir 			case( GFF_JPG ): pMimeType = MIMETYPE_JPG; cType = graphic::GraphicType::PIXEL; break;
150*cdf0e10cSrcweir 			case( GFF_PCD ): pMimeType = MIMETYPE_PCD; cType = graphic::GraphicType::PIXEL; break;
151*cdf0e10cSrcweir 			case( GFF_PCX ): pMimeType = MIMETYPE_PCX; cType = graphic::GraphicType::PIXEL; break;
152*cdf0e10cSrcweir 			case( GFF_PNG ): pMimeType = MIMETYPE_PNG; cType = graphic::GraphicType::PIXEL; break;
153*cdf0e10cSrcweir 			case( GFF_TIF ): pMimeType = MIMETYPE_TIF; cType = graphic::GraphicType::PIXEL; break;
154*cdf0e10cSrcweir 			case( GFF_XBM ): pMimeType = MIMETYPE_XBM; cType = graphic::GraphicType::PIXEL; break;
155*cdf0e10cSrcweir 			case( GFF_XPM ): pMimeType = MIMETYPE_XPM; cType = graphic::GraphicType::PIXEL; break;
156*cdf0e10cSrcweir 			case( GFF_PBM ): pMimeType = MIMETYPE_PBM; cType = graphic::GraphicType::PIXEL; break;
157*cdf0e10cSrcweir 			case( GFF_PGM ): pMimeType = MIMETYPE_PGM; cType = graphic::GraphicType::PIXEL; break;
158*cdf0e10cSrcweir 			case( GFF_PPM ): pMimeType = MIMETYPE_PPM; cType = graphic::GraphicType::PIXEL; break;
159*cdf0e10cSrcweir 			case( GFF_RAS ): pMimeType = MIMETYPE_RAS; cType = graphic::GraphicType::PIXEL; break;
160*cdf0e10cSrcweir 			case( GFF_TGA ): pMimeType = MIMETYPE_TGA; cType = graphic::GraphicType::PIXEL; break;
161*cdf0e10cSrcweir 			case( GFF_PSD ): pMimeType = MIMETYPE_PSD; cType = graphic::GraphicType::PIXEL; break;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 			case( GFF_EPS ): pMimeType = MIMETYPE_EPS; cType = graphic::GraphicType::VECTOR; break;
164*cdf0e10cSrcweir 			case( GFF_DXF ): pMimeType = MIMETYPE_DXF; cType = graphic::GraphicType::VECTOR; break;
165*cdf0e10cSrcweir 			case( GFF_MET ): pMimeType = MIMETYPE_MET; cType = graphic::GraphicType::VECTOR; break;
166*cdf0e10cSrcweir 			case( GFF_PCT ): pMimeType = MIMETYPE_PCT; cType = graphic::GraphicType::VECTOR; break;
167*cdf0e10cSrcweir 			case( GFF_SGF ): pMimeType = MIMETYPE_SGF; cType = graphic::GraphicType::VECTOR; break;
168*cdf0e10cSrcweir 			case( GFF_SVM ): pMimeType = MIMETYPE_SVM; cType = graphic::GraphicType::VECTOR; break;
169*cdf0e10cSrcweir 			case( GFF_WMF ): pMimeType = MIMETYPE_WMF; cType = graphic::GraphicType::VECTOR; break;
170*cdf0e10cSrcweir 			case( GFF_SGV ): pMimeType = MIMETYPE_SGV; cType = graphic::GraphicType::VECTOR; break;
171*cdf0e10cSrcweir 			case( GFF_EMF ): pMimeType = MIMETYPE_EMF; cType = graphic::GraphicType::VECTOR; break;
172*cdf0e10cSrcweir 			case( GFF_SVG ): pMimeType = MIMETYPE_SVG; cType = graphic::GraphicType::VECTOR; break;
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 			default:
175*cdf0e10cSrcweir 			break;
176*cdf0e10cSrcweir 		}
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 		if( graphic::GraphicType::EMPTY != cType )
179*cdf0e10cSrcweir 		{
180*cdf0e10cSrcweir 			meType = ( ( graphic::GraphicType::PIXEL == cType ) ? GRAPHIC_BITMAP : GRAPHIC_GDIMETAFILE );
181*cdf0e10cSrcweir 			maMimeType = String( pMimeType, RTL_TEXTENCODING_ASCII_US );
182*cdf0e10cSrcweir 			maSizePixel = aDescriptor.GetSizePixel();
183*cdf0e10cSrcweir 			maSize100thMM = aDescriptor.GetSize_100TH_MM();
184*cdf0e10cSrcweir 			mnBitsPerPixel = aDescriptor.GetBitsPerPixel();
185*cdf0e10cSrcweir 			mbTransparent = ( graphic::GraphicType::VECTOR == cType );
186*cdf0e10cSrcweir 			mbAlpha = mbAnimated = false;
187*cdf0e10cSrcweir 		}
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir // ------------------------------------------------------------------------------
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir ::rtl::OUString GraphicDescriptor::getImplementationName_Static()
194*cdf0e10cSrcweir 	throw()
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.GraphicDescriptor" ) );
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir // ------------------------------------------------------------------------------
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > GraphicDescriptor::getSupportedServiceNames_Static()
202*cdf0e10cSrcweir 	throw(	)
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSeq( 1 );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 	aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicDescriptor" ) );
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 	return aSeq;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir // ------------------------------------------------------------------------------
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir uno::Any SAL_CALL GraphicDescriptor::queryAggregation( const uno::Type & rType )
214*cdf0e10cSrcweir 	throw( uno::RuntimeException )
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir 	uno::Any aAny;
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
219*cdf0e10cSrcweir 		aAny <<= uno::Reference< lang::XServiceInfo >(this);
220*cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
221*cdf0e10cSrcweir 		aAny <<= uno::Reference< lang::XTypeProvider >(this);
222*cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
223*cdf0e10cSrcweir 		aAny <<= uno::Reference< beans::XPropertySet >(this);
224*cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
225*cdf0e10cSrcweir 		aAny <<= uno::Reference< beans::XPropertyState >(this);
226*cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
227*cdf0e10cSrcweir 		aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
228*cdf0e10cSrcweir 	else
229*cdf0e10cSrcweir 		aAny <<= OWeakAggObject::queryAggregation( rType );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	return aAny;
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir // ------------------------------------------------------------------------------
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir uno::Any SAL_CALL GraphicDescriptor::queryInterface( const uno::Type & rType )
237*cdf0e10cSrcweir 	throw( uno::RuntimeException )
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir 	return OWeakAggObject::queryInterface( rType );
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir // ------------------------------------------------------------------------------
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir void SAL_CALL GraphicDescriptor::acquire()
245*cdf0e10cSrcweir 	throw()
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	OWeakAggObject::acquire();
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir // ------------------------------------------------------------------------------
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir void SAL_CALL GraphicDescriptor::release()
253*cdf0e10cSrcweir 	throw()
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir 	OWeakAggObject::release();
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir // ------------------------------------------------------------------------------
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir ::rtl::OUString SAL_CALL GraphicDescriptor::getImplementationName()
261*cdf0e10cSrcweir 	throw( uno::RuntimeException )
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir 	return getImplementationName_Static();
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir // ------------------------------------------------------------------------------
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir sal_Bool SAL_CALL GraphicDescriptor::supportsService( const rtl::OUString& ServiceName )
269*cdf0e10cSrcweir 	throw( uno::RuntimeException )
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString >	aSNL( getSupportedServiceNames() );
272*cdf0e10cSrcweir     const ::rtl::OUString*				pArray = aSNL.getConstArray();
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
275*cdf0e10cSrcweir         if( pArray[i] == ServiceName )
276*cdf0e10cSrcweir             return true;
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     return false;
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir // ------------------------------------------------------------------------------
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL GraphicDescriptor::getSupportedServiceNames()
284*cdf0e10cSrcweir 	throw( uno::RuntimeException )
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir // ------------------------------------------------------------------------------
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL GraphicDescriptor::getTypes()
292*cdf0e10cSrcweir 	throw( uno::RuntimeException )
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir 	uno::Sequence< uno::Type >	aTypes( 6 );
295*cdf0e10cSrcweir 	uno::Type* 					pTypes = aTypes.getArray();
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
298*cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
299*cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
300*cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
301*cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
302*cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 	return aTypes;
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir // ------------------------------------------------------------------------------
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL GraphicDescriptor::getImplementationId()
310*cdf0e10cSrcweir 	throw( uno::RuntimeException )
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	vos::OGuard 						aGuard( Application::GetSolarMutex() );
313*cdf0e10cSrcweir 	static uno::Sequence< sal_Int8 >	aId;
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 	if( aId.getLength() == 0 )
316*cdf0e10cSrcweir 	{
317*cdf0e10cSrcweir 		aId.realloc( 16 );
318*cdf0e10cSrcweir 		rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
319*cdf0e10cSrcweir 	}
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 	return aId;
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir // ------------------------------------------------------------------------------
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir ::comphelper::PropertySetInfo* GraphicDescriptor::createPropertySetInfo()
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir 	vos::OGuard 					aGuard( Application::GetSolarMutex() );
329*cdf0e10cSrcweir 	::comphelper::PropertySetInfo*	pRet = new ::comphelper::PropertySetInfo();
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	static ::comphelper::PropertyMapEntry aEntries[] =
332*cdf0e10cSrcweir 	{
333*cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "GraphicType" ), UNOGRAPHIC_GRAPHICTYPE, &::getCppuType( (const sal_Int8*)(0)), beans::PropertyAttribute::READONLY, 0 },
334*cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "MimeType" ), UNOGRAPHIC_MIMETYPE, &::getCppuType( (const ::rtl::OUString*)(0)), beans::PropertyAttribute::READONLY, 0 },
335*cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "SizePixel" ), UNOGRAPHIC_SIZEPIXEL, &::getCppuType( (const awt::Size*)(0)), beans::PropertyAttribute::READONLY, 0 },
336*cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "Size100thMM" ), UNOGRAPHIC_SIZE100THMM,	&::getCppuType( (const awt::Size*)(0)), beans::PropertyAttribute::READONLY, 0 },
337*cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "BitsPerPixel" ), UNOGRAPHIC_BITSPERPIXEL, &::getCppuType( (const sal_uInt8*)(0)), beans::PropertyAttribute::READONLY, 0 },
338*cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "Transparent" ), UNOGRAPHIC_TRANSPARENT, &::getCppuType( (const sal_Bool*)(0)), beans::PropertyAttribute::READONLY, 0 },
339*cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "Alpha" ), UNOGRAPHIC_ALPHA, &::getCppuType( (const sal_Bool*)(0)), beans::PropertyAttribute::READONLY, 0 },
340*cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "Animated" ), UNOGRAPHIC_ANIMATED, &::getCppuType( (const sal_Bool*)(0)), beans::PropertyAttribute::READONLY, 0 },
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		{ 0,0,0,0,0,0 }
343*cdf0e10cSrcweir 	};
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	pRet->acquire();
346*cdf0e10cSrcweir 	pRet->add( aEntries );
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 	return pRet;
349*cdf0e10cSrcweir }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir // ------------------------------------------------------------------------------
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir void GraphicDescriptor::_setPropertyValues( const comphelper::PropertyMapEntry** /*ppEntries*/, const uno::Any* /*pValues*/ )
354*cdf0e10cSrcweir 	throw( beans::UnknownPropertyException,
355*cdf0e10cSrcweir 		   beans::PropertyVetoException,
356*cdf0e10cSrcweir 		   lang::IllegalArgumentException,
357*cdf0e10cSrcweir 	   	   lang::WrappedTargetException )
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir 	// we only have readonly attributes
360*cdf0e10cSrcweir }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir // ------------------------------------------------------------------------------
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir void GraphicDescriptor::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValues )
365*cdf0e10cSrcweir 	throw( beans::UnknownPropertyException, lang::WrappedTargetException )
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 	while( *ppEntries )
370*cdf0e10cSrcweir 	{
371*cdf0e10cSrcweir 		switch( (*ppEntries)->mnHandle )
372*cdf0e10cSrcweir 		{
373*cdf0e10cSrcweir 			case( UNOGRAPHIC_GRAPHICTYPE ):
374*cdf0e10cSrcweir 			{
375*cdf0e10cSrcweir 				const GraphicType eType( mpGraphic ? mpGraphic->GetType() : meType );
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 				*pValues <<= ( ( eType == GRAPHIC_BITMAP ? graphic::GraphicType::PIXEL :
378*cdf0e10cSrcweir 								( eType == GRAPHIC_GDIMETAFILE ? graphic::GraphicType::VECTOR :
379*cdf0e10cSrcweir 								graphic::GraphicType::EMPTY ) ) );
380*cdf0e10cSrcweir 			}
381*cdf0e10cSrcweir 			break;
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 			case( UNOGRAPHIC_MIMETYPE ):
384*cdf0e10cSrcweir 			{
385*cdf0e10cSrcweir 				::rtl::OUString aMimeType;
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 				if( mpGraphic )
388*cdf0e10cSrcweir 				{
389*cdf0e10cSrcweir 					if( mpGraphic->IsLink() )
390*cdf0e10cSrcweir 					{
391*cdf0e10cSrcweir 						const char* pMimeType;
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 						switch( const_cast< Graphic* >( mpGraphic )->GetLink().GetType() )
394*cdf0e10cSrcweir 						{
395*cdf0e10cSrcweir 							case( GFX_LINK_TYPE_NATIVE_GIF ): pMimeType = MIMETYPE_GIF; break;
396*cdf0e10cSrcweir 							case( GFX_LINK_TYPE_NATIVE_JPG ): pMimeType = MIMETYPE_JPG; break;
397*cdf0e10cSrcweir 							case( GFX_LINK_TYPE_NATIVE_PNG ): pMimeType = MIMETYPE_PNG; break;
398*cdf0e10cSrcweir 							case( GFX_LINK_TYPE_NATIVE_WMF ): pMimeType = MIMETYPE_WMF; break;
399*cdf0e10cSrcweir 							case( GFX_LINK_TYPE_NATIVE_MET ): pMimeType = MIMETYPE_MET; break;
400*cdf0e10cSrcweir 							case( GFX_LINK_TYPE_NATIVE_PCT ): pMimeType = MIMETYPE_PCT ; break;
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 							default:
403*cdf0e10cSrcweir 								pMimeType = NULL;
404*cdf0e10cSrcweir 							break;
405*cdf0e10cSrcweir 						}
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 						if( pMimeType )
408*cdf0e10cSrcweir 							aMimeType = ::rtl::OUString::createFromAscii( pMimeType );
409*cdf0e10cSrcweir 					}
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 					if( !aMimeType.getLength() && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
412*cdf0e10cSrcweir 						aMimeType = ::rtl::OUString::createFromAscii( MIMETYPE_VCLGRAPHIC );
413*cdf0e10cSrcweir 				}
414*cdf0e10cSrcweir 				else
415*cdf0e10cSrcweir 					aMimeType = maMimeType;
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir  				*pValues <<= aMimeType;
418*cdf0e10cSrcweir 			}
419*cdf0e10cSrcweir 			break;
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 			case( UNOGRAPHIC_SIZEPIXEL ):
422*cdf0e10cSrcweir 			{
423*cdf0e10cSrcweir 				awt::Size aAWTSize( 0, 0 );
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 				if( mpGraphic )
426*cdf0e10cSrcweir 				{
427*cdf0e10cSrcweir 					if( mpGraphic->GetType() == GRAPHIC_BITMAP )
428*cdf0e10cSrcweir 					{
429*cdf0e10cSrcweir 						const Size aSizePix( mpGraphic->GetBitmapEx().GetSizePixel() );
430*cdf0e10cSrcweir 						aAWTSize = awt::Size( aSizePix.Width(), aSizePix.Height() );
431*cdf0e10cSrcweir 					}
432*cdf0e10cSrcweir 				}
433*cdf0e10cSrcweir 				else
434*cdf0e10cSrcweir 					aAWTSize = awt::Size( maSizePixel.Width(), maSizePixel.Height() );
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 				*pValues <<= aAWTSize;
437*cdf0e10cSrcweir 			}
438*cdf0e10cSrcweir 			break;
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 			case( UNOGRAPHIC_SIZE100THMM ):
441*cdf0e10cSrcweir 			{
442*cdf0e10cSrcweir 				awt::Size aAWTSize( 0, 0 );
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 				if( mpGraphic )
445*cdf0e10cSrcweir 				{
446*cdf0e10cSrcweir 					if( mpGraphic->GetPrefMapMode().GetMapUnit() != MAP_PIXEL )
447*cdf0e10cSrcweir 					{
448*cdf0e10cSrcweir 						const Size aSizeLog( OutputDevice::LogicToLogic( mpGraphic->GetPrefSize(), mpGraphic->GetPrefMapMode(), MAP_100TH_MM ) );
449*cdf0e10cSrcweir 						aAWTSize = awt::Size( aSizeLog.Width(), aSizeLog.Height() );
450*cdf0e10cSrcweir 					}
451*cdf0e10cSrcweir 				}
452*cdf0e10cSrcweir 				else
453*cdf0e10cSrcweir 					aAWTSize = awt::Size( maSize100thMM.Width(), maSize100thMM.Height() );
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir 				*pValues <<= aAWTSize;
456*cdf0e10cSrcweir 			}
457*cdf0e10cSrcweir 			break;
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 			case( UNOGRAPHIC_BITSPERPIXEL ):
460*cdf0e10cSrcweir 			{
461*cdf0e10cSrcweir 				sal_uInt16 nBitsPerPixel = 0;
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 				if( mpGraphic )
464*cdf0e10cSrcweir 				{
465*cdf0e10cSrcweir 					if( mpGraphic->GetType() == GRAPHIC_BITMAP )
466*cdf0e10cSrcweir 						nBitsPerPixel = mpGraphic->GetBitmapEx().GetBitmap().GetBitCount();
467*cdf0e10cSrcweir 				}
468*cdf0e10cSrcweir 				else
469*cdf0e10cSrcweir 					nBitsPerPixel = mnBitsPerPixel;
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 				*pValues <<= sal::static_int_cast< sal_Int8 >(nBitsPerPixel);
472*cdf0e10cSrcweir 			}
473*cdf0e10cSrcweir 			break;
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 			case( UNOGRAPHIC_TRANSPARENT ):
476*cdf0e10cSrcweir 			{
477*cdf0e10cSrcweir 				*pValues <<= static_cast< sal_Bool >( mpGraphic ? mpGraphic->IsTransparent() : mbTransparent );
478*cdf0e10cSrcweir 			}
479*cdf0e10cSrcweir 			break;
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 			case( UNOGRAPHIC_ALPHA ):
482*cdf0e10cSrcweir 			{
483*cdf0e10cSrcweir 				*pValues <<= static_cast< sal_Bool >( mpGraphic ? mpGraphic->IsAlpha() : mbAlpha );
484*cdf0e10cSrcweir 			}
485*cdf0e10cSrcweir 			break;
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 			case( UNOGRAPHIC_ANIMATED ):
488*cdf0e10cSrcweir 			{
489*cdf0e10cSrcweir 				*pValues <<= static_cast< sal_Bool >( mpGraphic ? mpGraphic->IsAnimated() : mbAnimated );
490*cdf0e10cSrcweir 			}
491*cdf0e10cSrcweir 			break;
492*cdf0e10cSrcweir 		}
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir 		++ppEntries;
495*cdf0e10cSrcweir 		++pValues;
496*cdf0e10cSrcweir 	}
497*cdf0e10cSrcweir }
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir }
500