1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: graphic.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
34 #include <vos/mutex.hxx>
35 #ifndef _SV_SVAPP_HXX_
36 #include <vcl/svapp.hxx>
38 #include <com/sun/star/graphic/GraphicType.hpp>
40 #ifndef _COM_SUN_STAR_GRAPHIC_XGRAPHICTRANSOFMER_HPP_
41 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
44 #include <vcl/graph.hxx>
45 #include "graphic.hxx"
47 using namespace com::sun::star
;
49 namespace unographic
{
51 // -------------------
52 // - GraphicProvider -
53 // -------------------
60 // ------------------------------------------------------------------------------
68 // ------------------------------------------------------------------------------
70 void Graphic::init( const ::Graphic
& rGraphic
)
74 mpGraphic
= new ::Graphic( rGraphic
);
75 ::unographic::GraphicDescriptor::init( *mpGraphic
);
78 // ------------------------------------------------------------------------------
80 uno::Any SAL_CALL
Graphic::queryAggregation( const uno::Type
& rType
)
81 throw( uno::RuntimeException
)
84 if( rType
== ::getCppuType((const uno::Reference
< graphic::XGraphic
>*)0) )
85 aAny
<<= uno::Reference
< graphic::XGraphic
>( this );
86 else if( rType
== ::getCppuType((const uno::Reference
< awt::XBitmap
>*)0) )
87 aAny
<<= uno::Reference
< awt::XBitmap
>( this );
88 else if( rType
== ::getCppuType((const uno::Reference
< lang::XUnoTunnel
>*)0) )
89 aAny
<<= uno::Reference
< lang::XUnoTunnel
>(this);
91 aAny
<<= ::unographic::GraphicDescriptor::queryAggregation( rType
);
96 // ------------------------------------------------------------------------------
98 uno::Any SAL_CALL
Graphic::queryInterface( const uno::Type
& rType
)
99 throw( uno::RuntimeException
)
101 ::com::sun::star::uno::Any aReturn
= ::unographic::GraphicDescriptor::queryInterface( rType
);
102 if ( !aReturn
.hasValue() )
103 aReturn
= ::cppu::queryInterface ( rType
, static_cast< graphic::XGraphicTransformer
*>( this ) );
107 // ------------------------------------------------------------------------------
109 void SAL_CALL
Graphic::acquire()
112 ::unographic::GraphicDescriptor::acquire();
115 // ------------------------------------------------------------------------------
117 void SAL_CALL
Graphic::release() throw()
119 ::unographic::GraphicDescriptor::release();
122 // ------------------------------------------------------------------------------
124 uno::Sequence
< sal_Int8
> SAL_CALL
Graphic::getImplementationId_Static()
125 throw(uno::RuntimeException
)
127 vos::OGuard
aGuard( Application::GetSolarMutex() );
128 static uno::Sequence
< sal_Int8
> aId
;
130 if( aId
.getLength() == 0 )
133 rtl_createUuid( reinterpret_cast< sal_uInt8
* >( aId
.getArray() ), 0, sal_True
);
139 // ------------------------------------------------------------------------------
141 ::rtl::OUString
Graphic::getImplementationName_Static()
144 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.Graphic" ) );
147 // ------------------------------------------------------------------------------
149 uno::Sequence
< ::rtl::OUString
> Graphic::getSupportedServiceNames_Static()
152 uno::Sequence
< ::rtl::OUString
> aSeq( 1 );
154 aSeq
.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.Graphic" ) );
159 // ------------------------------------------------------------------------------
161 ::rtl::OUString SAL_CALL
Graphic::getImplementationName()
162 throw( uno::RuntimeException
)
164 return getImplementationName_Static();
167 // ------------------------------------------------------------------------------
169 sal_Bool SAL_CALL
Graphic::supportsService( const ::rtl::OUString
& rServiceName
)
170 throw( uno::RuntimeException
)
172 if( ::unographic::GraphicDescriptor::supportsService( rServiceName
) )
176 uno::Sequence
< ::rtl::OUString
> aSNL( getSupportedServiceNames() );
177 const ::rtl::OUString
* pArray
= aSNL
.getConstArray();
179 for( int i
= 0; i
< aSNL
.getLength(); i
++ )
180 if( pArray
[i
] == rServiceName
)
187 // ------------------------------------------------------------------------------
189 uno::Sequence
< ::rtl::OUString
> SAL_CALL
Graphic::getSupportedServiceNames()
190 throw( uno::RuntimeException
)
192 uno::Sequence
< ::rtl::OUString
> aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
193 uno::Sequence
< ::rtl::OUString
> aNew( getSupportedServiceNames_Static() );
194 sal_Int32 nOldCount
= aRet
.getLength();
196 aRet
.realloc( nOldCount
+ aNew
.getLength() );
198 for( sal_Int32 i
= 0; i
< aNew
.getLength(); ++i
)
199 aRet
[ nOldCount
++ ] = aNew
[ i
];
204 // ------------------------------------------------------------------------------
206 uno::Sequence
< uno::Type
> SAL_CALL
Graphic::getTypes()
207 throw(uno::RuntimeException
)
209 uno::Sequence
< uno::Type
> aRet( ::unographic::GraphicDescriptor::getTypes() );
210 sal_Int32 nOldCount
= aRet
.getLength();
212 aRet
.realloc( nOldCount
+ 2 );
213 aRet
[ nOldCount
] = ::getCppuType((const uno::Reference
< graphic::XGraphic
>*)0);
214 aRet
[ nOldCount
+1 ] = ::getCppuType((const uno::Reference
< awt::XBitmap
>*)0);
219 // ------------------------------------------------------------------------------
221 uno::Sequence
< sal_Int8
> SAL_CALL
Graphic::getImplementationId()
222 throw(uno::RuntimeException
)
224 return getImplementationId_Static();
227 // ------------------------------------------------------------------------------
229 ::sal_Int8 SAL_CALL
Graphic::getType()
230 throw (uno::RuntimeException
)
232 ::sal_Int8 cRet
= graphic::GraphicType::EMPTY
;
234 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
235 cRet
= ( ( mpGraphic
->GetType() == GRAPHIC_BITMAP
) ? graphic::GraphicType::PIXEL
: graphic::GraphicType::VECTOR
);
240 //----------------------------------------------------------------------
242 //----------------------------------------------------------------------
244 awt::Size SAL_CALL
Graphic::getSize( ) throw (uno::RuntimeException
)
246 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
249 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
250 aVclSize
= mpGraphic
->GetSizePixel();
252 return awt::Size( aVclSize
.Width(), aVclSize
.Height() );
255 //----------------------------------------------------------------------
257 uno::Sequence
< ::sal_Int8
> SAL_CALL
Graphic::getDIB( ) throw (uno::RuntimeException
)
259 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
261 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
264 aMem
<< mpGraphic
->GetBitmapEx().GetBitmap();
265 return ::com::sun::star::uno::Sequence
<sal_Int8
>( (sal_Int8
*) aMem
.GetData(), aMem
.Tell() );
269 return uno::Sequence
<sal_Int8
>();
273 //----------------------------------------------------------------------
275 uno::Sequence
< ::sal_Int8
> SAL_CALL
Graphic::getMaskDIB( ) throw (uno::RuntimeException
)
277 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
279 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
282 aMem
<< mpGraphic
->GetBitmapEx().GetMask();
283 return ::com::sun::star::uno::Sequence
<sal_Int8
>( (sal_Int8
*) aMem
.GetData(), aMem
.Tell() );
287 return uno::Sequence
<sal_Int8
>();
291 //----------------------------------------------------------------------
292 const ::Graphic
* Graphic::getImplementation( const uno::Reference
< uno::XInterface
>& rxIFace
)
295 uno::Reference
< lang::XUnoTunnel
> xTunnel( rxIFace
, uno::UNO_QUERY
);
296 return( xTunnel
.is() ? reinterpret_cast< ::Graphic
* >( xTunnel
->getSomething( getImplementationId_Static() ) ) : NULL
);
299 //----------------------------------------------------------------------
300 sal_Int64 SAL_CALL
Graphic::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
301 throw( uno::RuntimeException
)
303 return( ( rId
.getLength() == 16 && 0 == rtl_compareMemory( getImplementationId().getConstArray(), rId
.getConstArray(), 16 ) ) ?
304 reinterpret_cast< sal_Int64
>( mpGraphic
) :