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/dibtools.hxx>
25 #include <vcl/graph.hxx>
26 #include "graphic.hxx"
27 #include <comphelper/servicehelper.hxx>
30 using namespace com::sun::star
;
32 namespace unographic
{
34 // -------------------
35 // - GraphicProvider -
36 // -------------------
43 // ------------------------------------------------------------------------------
51 // ------------------------------------------------------------------------------
53 void Graphic::init( const ::Graphic
& rGraphic
)
57 mpGraphic
= new ::Graphic( rGraphic
);
58 ::unographic::GraphicDescriptor::init( *mpGraphic
);
61 // ------------------------------------------------------------------------------
63 uno::Any SAL_CALL
Graphic::queryAggregation( const uno::Type
& rType
)
64 throw( uno::RuntimeException
)
67 if( rType
== ::getCppuType((const uno::Reference
< graphic::XGraphic
>*)0) )
68 aAny
<<= uno::Reference
< graphic::XGraphic
>( this );
69 else if( rType
== ::getCppuType((const uno::Reference
< awt::XBitmap
>*)0) )
70 aAny
<<= uno::Reference
< awt::XBitmap
>( this );
71 else if( rType
== ::getCppuType((const uno::Reference
< lang::XUnoTunnel
>*)0) )
72 aAny
<<= uno::Reference
< lang::XUnoTunnel
>(this);
74 aAny
<<= ::unographic::GraphicDescriptor::queryAggregation( rType
);
79 // ------------------------------------------------------------------------------
81 uno::Any SAL_CALL
Graphic::queryInterface( const uno::Type
& rType
)
82 throw( uno::RuntimeException
)
84 ::com::sun::star::uno::Any aReturn
= ::unographic::GraphicDescriptor::queryInterface( rType
);
85 if ( !aReturn
.hasValue() )
86 aReturn
= ::cppu::queryInterface ( rType
, static_cast< graphic::XGraphicTransformer
*>( this ) );
90 // ------------------------------------------------------------------------------
92 void SAL_CALL
Graphic::acquire()
95 ::unographic::GraphicDescriptor::acquire();
98 // ------------------------------------------------------------------------------
100 void SAL_CALL
Graphic::release() throw()
102 ::unographic::GraphicDescriptor::release();
105 // ------------------------------------------------------------------------------
109 class theGraphicUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theGraphicUnoTunnelId
> {};
112 uno::Sequence
< sal_Int8
> SAL_CALL
Graphic::getImplementationId_Static()
113 throw(uno::RuntimeException
)
115 return theGraphicUnoTunnelId::get().getSeq();
118 // ------------------------------------------------------------------------------
120 OUString
Graphic::getImplementationName_Static()
123 return OUString( "com.sun.star.comp.graphic.Graphic" );
126 // ------------------------------------------------------------------------------
128 uno::Sequence
< OUString
> Graphic::getSupportedServiceNames_Static()
131 uno::Sequence
< OUString
> aSeq( 1 );
133 aSeq
.getArray()[ 0 ] = "com.sun.star.graphic.Graphic";
138 // ------------------------------------------------------------------------------
140 OUString SAL_CALL
Graphic::getImplementationName()
141 throw( uno::RuntimeException
)
143 return getImplementationName_Static();
146 // ------------------------------------------------------------------------------
148 sal_Bool SAL_CALL
Graphic::supportsService( const OUString
& rServiceName
)
149 throw( uno::RuntimeException
)
151 if( ::unographic::GraphicDescriptor::supportsService( rServiceName
) )
155 uno::Sequence
< OUString
> aSNL( getSupportedServiceNames() );
156 const OUString
* pArray
= aSNL
.getConstArray();
158 for( int i
= 0; i
< aSNL
.getLength(); i
++ )
159 if( pArray
[i
] == rServiceName
)
166 // ------------------------------------------------------------------------------
168 uno::Sequence
< OUString
> SAL_CALL
Graphic::getSupportedServiceNames()
169 throw( uno::RuntimeException
)
171 uno::Sequence
< OUString
> aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
172 uno::Sequence
< OUString
> aNew( getSupportedServiceNames_Static() );
173 sal_Int32 nOldCount
= aRet
.getLength();
175 aRet
.realloc( nOldCount
+ aNew
.getLength() );
177 for( sal_Int32 i
= 0; i
< aNew
.getLength(); ++i
)
178 aRet
[ nOldCount
++ ] = aNew
[ i
];
183 // ------------------------------------------------------------------------------
185 uno::Sequence
< uno::Type
> SAL_CALL
Graphic::getTypes()
186 throw(uno::RuntimeException
)
188 uno::Sequence
< uno::Type
> aRet( ::unographic::GraphicDescriptor::getTypes() );
189 sal_Int32 nOldCount
= aRet
.getLength();
191 aRet
.realloc( nOldCount
+ 2 );
192 aRet
[ nOldCount
] = ::getCppuType((const uno::Reference
< graphic::XGraphic
>*)0);
193 aRet
[ nOldCount
+1 ] = ::getCppuType((const uno::Reference
< awt::XBitmap
>*)0);
198 // ------------------------------------------------------------------------------
200 uno::Sequence
< sal_Int8
> SAL_CALL
Graphic::getImplementationId()
201 throw(uno::RuntimeException
)
203 return getImplementationId_Static();
206 // ------------------------------------------------------------------------------
208 ::sal_Int8 SAL_CALL
Graphic::getType()
209 throw (uno::RuntimeException
)
211 ::sal_Int8 cRet
= graphic::GraphicType::EMPTY
;
213 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
214 cRet
= ( ( mpGraphic
->GetType() == GRAPHIC_BITMAP
) ? graphic::GraphicType::PIXEL
: graphic::GraphicType::VECTOR
);
219 //----------------------------------------------------------------------
221 //----------------------------------------------------------------------
223 awt::Size SAL_CALL
Graphic::getSize( ) throw (uno::RuntimeException
)
225 SolarMutexGuard aGuard
;
228 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
229 aVclSize
= mpGraphic
->GetSizePixel();
231 return awt::Size( aVclSize
.Width(), aVclSize
.Height() );
234 //----------------------------------------------------------------------
236 uno::Sequence
< ::sal_Int8
> SAL_CALL
Graphic::getDIB( ) throw (uno::RuntimeException
)
238 SolarMutexGuard aGuard
;
240 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
244 WriteDIB(mpGraphic
->GetBitmapEx().GetBitmap(), aMem
, false, true);
245 return ::com::sun::star::uno::Sequence
<sal_Int8
>( (sal_Int8
*) aMem
.GetData(), aMem
.Tell() );
249 return uno::Sequence
<sal_Int8
>();
253 //----------------------------------------------------------------------
255 uno::Sequence
< ::sal_Int8
> SAL_CALL
Graphic::getMaskDIB( ) throw (uno::RuntimeException
)
257 SolarMutexGuard aGuard
;
259 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
263 WriteDIB(mpGraphic
->GetBitmapEx().GetMask(), aMem
, false, true);
264 return ::com::sun::star::uno::Sequence
<sal_Int8
>( (sal_Int8
*) aMem
.GetData(), aMem
.Tell() );
268 return uno::Sequence
<sal_Int8
>();
272 //----------------------------------------------------------------------
273 const ::Graphic
* Graphic::getImplementation( const uno::Reference
< uno::XInterface
>& rxIFace
)
276 uno::Reference
< lang::XUnoTunnel
> xTunnel( rxIFace
, uno::UNO_QUERY
);
277 return( xTunnel
.is() ? reinterpret_cast< ::Graphic
* >( xTunnel
->getSomething( getImplementationId_Static() ) ) : NULL
);
280 //----------------------------------------------------------------------
281 sal_Int64 SAL_CALL
Graphic::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
282 throw( uno::RuntimeException
)
284 return( ( rId
.getLength() == 16 && 0 == memcmp( getImplementationId().getConstArray(), rId
.getConstArray(), 16 ) ) ?
285 reinterpret_cast< sal_Int64
>( mpGraphic
) :
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */