1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/mutex.hxx>
21 #include <vcl/svapp.hxx>
22 #include <com/sun/star/graphic/GraphicType.hpp>
23 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
24 #include <vcl/graph.hxx>
25 #include "graphic.hxx"
26 #include <comphelper/servicehelper.hxx>
29 using namespace com::sun::star
;
31 namespace unographic
{
33 // -------------------
34 // - GraphicProvider -
35 // -------------------
42 // ------------------------------------------------------------------------------
50 // ------------------------------------------------------------------------------
52 void Graphic::init( const ::Graphic
& rGraphic
)
56 mpGraphic
= new ::Graphic( rGraphic
);
57 ::unographic::GraphicDescriptor::init( *mpGraphic
);
60 // ------------------------------------------------------------------------------
62 uno::Any SAL_CALL
Graphic::queryAggregation( const uno::Type
& rType
)
63 throw( uno::RuntimeException
)
66 if( rType
== ::getCppuType((const uno::Reference
< graphic::XGraphic
>*)0) )
67 aAny
<<= uno::Reference
< graphic::XGraphic
>( this );
68 else if( rType
== ::getCppuType((const uno::Reference
< awt::XBitmap
>*)0) )
69 aAny
<<= uno::Reference
< awt::XBitmap
>( this );
70 else if( rType
== ::getCppuType((const uno::Reference
< lang::XUnoTunnel
>*)0) )
71 aAny
<<= uno::Reference
< lang::XUnoTunnel
>(this);
73 aAny
<<= ::unographic::GraphicDescriptor::queryAggregation( rType
);
78 // ------------------------------------------------------------------------------
80 uno::Any SAL_CALL
Graphic::queryInterface( const uno::Type
& rType
)
81 throw( uno::RuntimeException
)
83 ::com::sun::star::uno::Any aReturn
= ::unographic::GraphicDescriptor::queryInterface( rType
);
84 if ( !aReturn
.hasValue() )
85 aReturn
= ::cppu::queryInterface ( rType
, static_cast< graphic::XGraphicTransformer
*>( this ) );
89 // ------------------------------------------------------------------------------
91 void SAL_CALL
Graphic::acquire()
94 ::unographic::GraphicDescriptor::acquire();
97 // ------------------------------------------------------------------------------
99 void SAL_CALL
Graphic::release() throw()
101 ::unographic::GraphicDescriptor::release();
104 // ------------------------------------------------------------------------------
108 class theGraphicUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theGraphicUnoTunnelId
> {};
111 uno::Sequence
< sal_Int8
> SAL_CALL
Graphic::getImplementationId_Static()
112 throw(uno::RuntimeException
)
114 return theGraphicUnoTunnelId::get().getSeq();
117 // ------------------------------------------------------------------------------
119 OUString
Graphic::getImplementationName_Static()
122 return OUString( "com.sun.star.comp.graphic.Graphic" );
125 // ------------------------------------------------------------------------------
127 uno::Sequence
< OUString
> Graphic::getSupportedServiceNames_Static()
130 uno::Sequence
< OUString
> aSeq( 1 );
132 aSeq
.getArray()[ 0 ] = OUString( "com.sun.star.graphic.Graphic" );
137 // ------------------------------------------------------------------------------
139 OUString SAL_CALL
Graphic::getImplementationName()
140 throw( uno::RuntimeException
)
142 return getImplementationName_Static();
145 // ------------------------------------------------------------------------------
147 sal_Bool SAL_CALL
Graphic::supportsService( const OUString
& rServiceName
)
148 throw( uno::RuntimeException
)
150 if( ::unographic::GraphicDescriptor::supportsService( rServiceName
) )
154 uno::Sequence
< OUString
> aSNL( getSupportedServiceNames() );
155 const OUString
* pArray
= aSNL
.getConstArray();
157 for( int i
= 0; i
< aSNL
.getLength(); i
++ )
158 if( pArray
[i
] == rServiceName
)
165 // ------------------------------------------------------------------------------
167 uno::Sequence
< OUString
> SAL_CALL
Graphic::getSupportedServiceNames()
168 throw( uno::RuntimeException
)
170 uno::Sequence
< OUString
> aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
171 uno::Sequence
< OUString
> aNew( getSupportedServiceNames_Static() );
172 sal_Int32 nOldCount
= aRet
.getLength();
174 aRet
.realloc( nOldCount
+ aNew
.getLength() );
176 for( sal_Int32 i
= 0; i
< aNew
.getLength(); ++i
)
177 aRet
[ nOldCount
++ ] = aNew
[ i
];
182 // ------------------------------------------------------------------------------
184 uno::Sequence
< uno::Type
> SAL_CALL
Graphic::getTypes()
185 throw(uno::RuntimeException
)
187 uno::Sequence
< uno::Type
> aRet( ::unographic::GraphicDescriptor::getTypes() );
188 sal_Int32 nOldCount
= aRet
.getLength();
190 aRet
.realloc( nOldCount
+ 2 );
191 aRet
[ nOldCount
] = ::getCppuType((const uno::Reference
< graphic::XGraphic
>*)0);
192 aRet
[ nOldCount
+1 ] = ::getCppuType((const uno::Reference
< awt::XBitmap
>*)0);
197 // ------------------------------------------------------------------------------
199 uno::Sequence
< sal_Int8
> SAL_CALL
Graphic::getImplementationId()
200 throw(uno::RuntimeException
)
202 return getImplementationId_Static();
205 // ------------------------------------------------------------------------------
207 ::sal_Int8 SAL_CALL
Graphic::getType()
208 throw (uno::RuntimeException
)
210 ::sal_Int8 cRet
= graphic::GraphicType::EMPTY
;
212 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
213 cRet
= ( ( mpGraphic
->GetType() == GRAPHIC_BITMAP
) ? graphic::GraphicType::PIXEL
: graphic::GraphicType::VECTOR
);
218 //----------------------------------------------------------------------
220 //----------------------------------------------------------------------
222 awt::Size SAL_CALL
Graphic::getSize( ) throw (uno::RuntimeException
)
224 SolarMutexGuard aGuard
;
227 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
228 aVclSize
= mpGraphic
->GetSizePixel();
230 return awt::Size( aVclSize
.Width(), aVclSize
.Height() );
233 //----------------------------------------------------------------------
235 uno::Sequence
< ::sal_Int8
> SAL_CALL
Graphic::getDIB( ) throw (uno::RuntimeException
)
237 SolarMutexGuard aGuard
;
239 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
242 aMem
<< mpGraphic
->GetBitmapEx().GetBitmap();
243 return ::com::sun::star::uno::Sequence
<sal_Int8
>( (sal_Int8
*) aMem
.GetData(), aMem
.Tell() );
247 return uno::Sequence
<sal_Int8
>();
251 //----------------------------------------------------------------------
253 uno::Sequence
< ::sal_Int8
> SAL_CALL
Graphic::getMaskDIB( ) throw (uno::RuntimeException
)
255 SolarMutexGuard aGuard
;
257 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
260 aMem
<< mpGraphic
->GetBitmapEx().GetMask();
261 return ::com::sun::star::uno::Sequence
<sal_Int8
>( (sal_Int8
*) aMem
.GetData(), aMem
.Tell() );
265 return uno::Sequence
<sal_Int8
>();
269 //----------------------------------------------------------------------
270 const ::Graphic
* Graphic::getImplementation( const uno::Reference
< uno::XInterface
>& rxIFace
)
273 uno::Reference
< lang::XUnoTunnel
> xTunnel( rxIFace
, uno::UNO_QUERY
);
274 return( xTunnel
.is() ? reinterpret_cast< ::Graphic
* >( xTunnel
->getSomething( getImplementationId_Static() ) ) : NULL
);
277 //----------------------------------------------------------------------
278 sal_Int64 SAL_CALL
Graphic::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
279 throw( uno::RuntimeException
)
281 return( ( rId
.getLength() == 16 && 0 == memcmp( getImplementationId().getConstArray(), rId
.getConstArray(), 16 ) ) ?
282 reinterpret_cast< sal_Int64
>( mpGraphic
) :
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */