Update ooo320-m1
[ooovba.git] / goodies / source / unographic / graphic.cxx
blob84e197aab99a0bcdda70e324da9802f8bfacd6a0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: graphic.cxx,v $
10 * $Revision: 1.7 $
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"
33 #include <rtl/uuid.h>
34 #include <vos/mutex.hxx>
35 #ifndef _SV_SVAPP_HXX_
36 #include <vcl/svapp.hxx>
37 #endif
38 #include <com/sun/star/graphic/GraphicType.hpp>
40 #ifndef _COM_SUN_STAR_GRAPHIC_XGRAPHICTRANSOFMER_HPP_
41 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
42 #endif
44 #include <vcl/graph.hxx>
45 #include "graphic.hxx"
47 using namespace com::sun::star;
49 namespace unographic {
51 // -------------------
52 // - GraphicProvider -
53 // -------------------
55 Graphic::Graphic() :
56 mpGraphic( NULL )
60 // ------------------------------------------------------------------------------
62 Graphic::~Graphic()
63 throw()
65 delete mpGraphic;
68 // ------------------------------------------------------------------------------
70 void Graphic::init( const ::Graphic& rGraphic )
71 throw()
73 delete mpGraphic;
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 )
83 uno::Any aAny;
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);
90 else
91 aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType );
93 return aAny ;
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 ) );
104 return aReturn;
107 // ------------------------------------------------------------------------------
109 void SAL_CALL Graphic::acquire()
110 throw()
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 )
132 aId.realloc( 16 );
133 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
136 return aId;
139 // ------------------------------------------------------------------------------
141 ::rtl::OUString Graphic::getImplementationName_Static()
142 throw()
144 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.Graphic" ) );
147 // ------------------------------------------------------------------------------
149 uno::Sequence< ::rtl::OUString > Graphic::getSupportedServiceNames_Static()
150 throw()
152 uno::Sequence< ::rtl::OUString > aSeq( 1 );
154 aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.Graphic" ) );
156 return aSeq;
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 ) )
173 return true;
174 else
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 )
181 return true;
183 return false;
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 ];
201 return aRet;
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);
216 return aRet;
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 );
237 return cRet;
240 //----------------------------------------------------------------------
241 // XBitmap
242 //----------------------------------------------------------------------
244 awt::Size SAL_CALL Graphic::getSize( ) throw (uno::RuntimeException)
246 ::vos::OGuard aGuard( Application::GetSolarMutex() );
248 ::Size aVclSize;
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 ) )
263 SvMemoryStream aMem;
264 aMem << mpGraphic->GetBitmapEx().GetBitmap();
265 return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
267 else
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 ) )
281 SvMemoryStream aMem;
282 aMem << mpGraphic->GetBitmapEx().GetMask();
283 return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
285 else
287 return uno::Sequence<sal_Int8>();
291 //----------------------------------------------------------------------
292 const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace )
293 throw()
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 ) :
305 0 );