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>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <cppuhelper/queryinterface.hxx>
32 using namespace com::sun::star
;
34 namespace unographic
{
51 void Graphic::init( const ::Graphic
& rGraphic
)
55 mpGraphic
= new ::Graphic( rGraphic
);
56 ::unographic::GraphicDescriptor::init( *mpGraphic
);
61 uno::Any SAL_CALL
Graphic::queryAggregation( const uno::Type
& rType
)
62 throw( uno::RuntimeException
, std::exception
)
65 if( rType
== cppu::UnoType
<graphic::XGraphic
>::get())
66 aAny
<<= uno::Reference
< graphic::XGraphic
>( this );
67 else if( rType
== cppu::UnoType
<awt::XBitmap
>::get())
68 aAny
<<= uno::Reference
< awt::XBitmap
>( this );
69 else if( rType
== cppu::UnoType
<lang::XUnoTunnel
>::get())
70 aAny
<<= uno::Reference
< lang::XUnoTunnel
>(this);
72 aAny
<<= ::unographic::GraphicDescriptor::queryAggregation( rType
);
79 uno::Any SAL_CALL
Graphic::queryInterface( const uno::Type
& rType
)
80 throw( uno::RuntimeException
, std::exception
)
82 ::com::sun::star::uno::Any aReturn
= ::unographic::GraphicDescriptor::queryInterface( rType
);
83 if ( !aReturn
.hasValue() )
84 aReturn
= ::cppu::queryInterface ( rType
, static_cast< graphic::XGraphicTransformer
*>( this ) );
90 void SAL_CALL
Graphic::acquire()
93 ::unographic::GraphicDescriptor::acquire();
98 void SAL_CALL
Graphic::release() throw()
100 ::unographic::GraphicDescriptor::release();
103 OUString
Graphic::getImplementationName_Static()
106 return OUString( "com.sun.star.comp.graphic.Graphic" );
111 uno::Sequence
< OUString
> Graphic::getSupportedServiceNames_Static()
114 uno::Sequence
< OUString
> aSeq( 1 );
116 aSeq
.getArray()[ 0 ] = "com.sun.star.graphic.Graphic";
121 OUString SAL_CALL
Graphic::getImplementationName()
122 throw( uno::RuntimeException
, std::exception
)
124 return getImplementationName_Static();
127 sal_Bool SAL_CALL
Graphic::supportsService( const OUString
& rServiceName
)
128 throw( uno::RuntimeException
, std::exception
)
130 return cppu::supportsService( this, rServiceName
);
133 uno::Sequence
< OUString
> SAL_CALL
Graphic::getSupportedServiceNames()
134 throw( uno::RuntimeException
, std::exception
)
136 uno::Sequence
< OUString
> aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
137 uno::Sequence
< OUString
> aNew( getSupportedServiceNames_Static() );
138 sal_Int32 nOldCount
= aRet
.getLength();
140 aRet
.realloc( nOldCount
+ aNew
.getLength() );
142 for( sal_Int32 i
= 0; i
< aNew
.getLength(); ++i
)
143 aRet
[ nOldCount
++ ] = aNew
[ i
];
148 uno::Sequence
< uno::Type
> SAL_CALL
Graphic::getTypes()
149 throw(uno::RuntimeException
, std::exception
)
151 uno::Sequence
< uno::Type
> aRet( ::unographic::GraphicDescriptor::getTypes() );
152 sal_Int32 nOldCount
= aRet
.getLength();
154 aRet
.realloc( nOldCount
+ 2 );
155 aRet
[ nOldCount
] = cppu::UnoType
<graphic::XGraphic
>::get();
156 aRet
[ nOldCount
+1 ] = cppu::UnoType
<awt::XBitmap
>::get();
163 uno::Sequence
< sal_Int8
> SAL_CALL
Graphic::getImplementationId()
164 throw(uno::RuntimeException
, std::exception
)
166 return css::uno::Sequence
<sal_Int8
>();
171 ::sal_Int8 SAL_CALL
Graphic::getType()
172 throw (uno::RuntimeException
, std::exception
)
174 ::sal_Int8 cRet
= graphic::GraphicType::EMPTY
;
176 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
177 cRet
= ( ( mpGraphic
->GetType() == GRAPHIC_BITMAP
) ? graphic::GraphicType::PIXEL
: graphic::GraphicType::VECTOR
);
186 awt::Size SAL_CALL
Graphic::getSize( ) throw (uno::RuntimeException
, std::exception
)
188 SolarMutexGuard aGuard
;
191 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
192 aVclSize
= mpGraphic
->GetSizePixel();
194 return awt::Size( aVclSize
.Width(), aVclSize
.Height() );
199 uno::Sequence
< ::sal_Int8
> SAL_CALL
Graphic::getDIB( ) throw (uno::RuntimeException
, std::exception
)
201 SolarMutexGuard aGuard
;
203 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
207 WriteDIB(mpGraphic
->GetBitmapEx().GetBitmap(), aMem
, false, true);
208 return ::com::sun::star::uno::Sequence
<sal_Int8
>( static_cast<sal_Int8
const *>(aMem
.GetData()), aMem
.Tell() );
212 return uno::Sequence
<sal_Int8
>();
218 uno::Sequence
< ::sal_Int8
> SAL_CALL
Graphic::getMaskDIB( ) throw (uno::RuntimeException
, std::exception
)
220 SolarMutexGuard aGuard
;
222 if( mpGraphic
&& ( mpGraphic
->GetType() != GRAPHIC_NONE
) )
226 WriteDIB(mpGraphic
->GetBitmapEx().GetMask(), aMem
, false, true);
227 return ::com::sun::star::uno::Sequence
<sal_Int8
>( static_cast<sal_Int8
const *>(aMem
.GetData()), aMem
.Tell() );
231 return uno::Sequence
<sal_Int8
>();
236 const ::Graphic
* Graphic::getImplementation( const uno::Reference
< uno::XInterface
>& rxIFace
)
239 uno::Reference
< lang::XUnoTunnel
> xTunnel( rxIFace
, uno::UNO_QUERY
);
240 return( xTunnel
.is() ? reinterpret_cast< ::Graphic
* >( xTunnel
->getSomething( ::Graphic::getUnoTunnelId() ) ) : NULL
);
244 sal_Int64 SAL_CALL
Graphic::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
245 throw( uno::RuntimeException
, std::exception
)
247 return( ( rId
.getLength() == 16 && 0 == memcmp( ::Graphic::getUnoTunnelId().getConstArray(), rId
.getConstArray(), 16 ) ) ?
248 reinterpret_cast< sal_Int64
>( mpGraphic
) :
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */