Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
27 : #include <string.h>
28 :
29 : using namespace com::sun::star;
30 :
31 : namespace unographic {
32 :
33 : // -------------------
34 : // - GraphicProvider -
35 : // -------------------
36 :
37 132 : Graphic::Graphic() :
38 132 : mpGraphic( NULL )
39 : {
40 132 : }
41 :
42 : // ------------------------------------------------------------------------------
43 :
44 264 : Graphic::~Graphic()
45 264 : throw()
46 : {
47 132 : delete mpGraphic;
48 264 : }
49 :
50 : // ------------------------------------------------------------------------------
51 :
52 132 : void Graphic::init( const ::Graphic& rGraphic )
53 : throw()
54 : {
55 132 : delete mpGraphic;
56 132 : mpGraphic = new ::Graphic( rGraphic );
57 132 : ::unographic::GraphicDescriptor::init( *mpGraphic );
58 132 : }
59 :
60 : // ------------------------------------------------------------------------------
61 :
62 225 : uno::Any SAL_CALL Graphic::queryAggregation( const uno::Type& rType )
63 : throw( uno::RuntimeException )
64 : {
65 225 : uno::Any aAny;
66 225 : if( rType == ::getCppuType((const uno::Reference< graphic::XGraphic >*)0) )
67 13 : aAny <<= uno::Reference< graphic::XGraphic >( this );
68 212 : else if( rType == ::getCppuType((const uno::Reference< awt::XBitmap >*)0) )
69 86 : aAny <<= uno::Reference< awt::XBitmap >( this );
70 126 : else if( rType == ::getCppuType((const uno::Reference< lang::XUnoTunnel >*)0) )
71 53 : aAny <<= uno::Reference< lang::XUnoTunnel >(this);
72 : else
73 73 : aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType );
74 :
75 225 : return aAny ;
76 : }
77 :
78 : // ------------------------------------------------------------------------------
79 :
80 225 : uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType )
81 : throw( uno::RuntimeException )
82 : {
83 225 : ::com::sun::star::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType );
84 225 : if ( !aReturn.hasValue() )
85 0 : aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) );
86 225 : return aReturn;
87 : }
88 :
89 : // ------------------------------------------------------------------------------
90 :
91 1584 : void SAL_CALL Graphic::acquire()
92 : throw()
93 : {
94 1584 : ::unographic::GraphicDescriptor::acquire();
95 1584 : }
96 :
97 : // ------------------------------------------------------------------------------
98 :
99 1584 : void SAL_CALL Graphic::release() throw()
100 : {
101 1584 : ::unographic::GraphicDescriptor::release();
102 1584 : }
103 :
104 : // ------------------------------------------------------------------------------
105 :
106 : namespace
107 : {
108 : class theGraphicUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theGraphicUnoTunnelId > {};
109 : }
110 :
111 106 : uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId_Static()
112 : throw(uno::RuntimeException)
113 : {
114 106 : return theGraphicUnoTunnelId::get().getSeq();
115 : }
116 :
117 : // ------------------------------------------------------------------------------
118 :
119 0 : ::rtl::OUString Graphic::getImplementationName_Static()
120 : throw()
121 : {
122 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.Graphic" ) );
123 : }
124 :
125 : // ------------------------------------------------------------------------------
126 :
127 0 : uno::Sequence< ::rtl::OUString > Graphic::getSupportedServiceNames_Static()
128 : throw()
129 : {
130 0 : uno::Sequence< ::rtl::OUString > aSeq( 1 );
131 :
132 0 : aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.Graphic" ) );
133 :
134 0 : return aSeq;
135 : }
136 :
137 : // ------------------------------------------------------------------------------
138 :
139 0 : ::rtl::OUString SAL_CALL Graphic::getImplementationName()
140 : throw( uno::RuntimeException )
141 : {
142 0 : return getImplementationName_Static();
143 : }
144 :
145 : // ------------------------------------------------------------------------------
146 :
147 0 : sal_Bool SAL_CALL Graphic::supportsService( const ::rtl::OUString& rServiceName )
148 : throw( uno::RuntimeException )
149 : {
150 0 : if( ::unographic::GraphicDescriptor::supportsService( rServiceName ) )
151 0 : return true;
152 : else
153 : {
154 0 : uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
155 0 : const ::rtl::OUString* pArray = aSNL.getConstArray();
156 :
157 0 : for( int i = 0; i < aSNL.getLength(); i++ )
158 0 : if( pArray[i] == rServiceName )
159 0 : return true;
160 :
161 0 : return false;
162 : }
163 : }
164 :
165 : // ------------------------------------------------------------------------------
166 :
167 0 : uno::Sequence< ::rtl::OUString > SAL_CALL Graphic::getSupportedServiceNames()
168 : throw( uno::RuntimeException )
169 : {
170 0 : uno::Sequence< ::rtl::OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
171 0 : uno::Sequence< ::rtl::OUString > aNew( getSupportedServiceNames_Static() );
172 0 : sal_Int32 nOldCount = aRet.getLength();
173 :
174 0 : aRet.realloc( nOldCount + aNew.getLength() );
175 :
176 0 : for( sal_Int32 i = 0; i < aNew.getLength(); ++i )
177 0 : aRet[ nOldCount++ ] = aNew[ i ];
178 :
179 0 : return aRet;
180 : }
181 :
182 : // ------------------------------------------------------------------------------
183 :
184 0 : uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
185 : throw(uno::RuntimeException)
186 : {
187 0 : uno::Sequence< uno::Type > aRet( ::unographic::GraphicDescriptor::getTypes() );
188 0 : sal_Int32 nOldCount = aRet.getLength();
189 :
190 0 : aRet.realloc( nOldCount + 2 );
191 0 : aRet[ nOldCount ] = ::getCppuType((const uno::Reference< graphic::XGraphic>*)0);
192 0 : aRet[ nOldCount+1 ] = ::getCppuType((const uno::Reference< awt::XBitmap>*)0);
193 :
194 0 : return aRet;
195 : }
196 :
197 : // ------------------------------------------------------------------------------
198 :
199 106 : uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
200 : throw(uno::RuntimeException)
201 : {
202 106 : return getImplementationId_Static();
203 : }
204 :
205 : // ------------------------------------------------------------------------------
206 :
207 0 : ::sal_Int8 SAL_CALL Graphic::getType()
208 : throw (uno::RuntimeException)
209 : {
210 0 : ::sal_Int8 cRet = graphic::GraphicType::EMPTY;
211 :
212 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
213 0 : cRet = ( ( mpGraphic->GetType() == GRAPHIC_BITMAP ) ? graphic::GraphicType::PIXEL : graphic::GraphicType::VECTOR );
214 :
215 0 : return cRet;
216 : }
217 :
218 : //----------------------------------------------------------------------
219 : // XBitmap
220 : //----------------------------------------------------------------------
221 :
222 74 : awt::Size SAL_CALL Graphic::getSize( ) throw (uno::RuntimeException)
223 : {
224 74 : SolarMutexGuard aGuard;
225 :
226 74 : ::Size aVclSize;
227 74 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
228 74 : aVclSize = mpGraphic->GetSizePixel();
229 :
230 74 : return awt::Size( aVclSize.Width(), aVclSize.Height() );
231 : }
232 :
233 : //----------------------------------------------------------------------
234 :
235 0 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getDIB( ) throw (uno::RuntimeException)
236 : {
237 0 : SolarMutexGuard aGuard;
238 :
239 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
240 : {
241 0 : SvMemoryStream aMem;
242 0 : aMem << mpGraphic->GetBitmapEx().GetBitmap();
243 0 : return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
244 : }
245 : else
246 : {
247 0 : return uno::Sequence<sal_Int8>();
248 0 : }
249 : }
250 :
251 : //----------------------------------------------------------------------
252 :
253 0 : uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getMaskDIB( ) throw (uno::RuntimeException)
254 : {
255 0 : SolarMutexGuard aGuard;
256 :
257 0 : if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) )
258 : {
259 0 : SvMemoryStream aMem;
260 0 : aMem << mpGraphic->GetBitmapEx().GetMask();
261 0 : return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
262 : }
263 : else
264 : {
265 0 : return uno::Sequence<sal_Int8>();
266 0 : }
267 : }
268 :
269 : //----------------------------------------------------------------------
270 0 : const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace )
271 : throw()
272 : {
273 0 : uno::Reference< lang::XUnoTunnel > xTunnel( rxIFace, uno::UNO_QUERY );
274 0 : return( xTunnel.is() ? reinterpret_cast< ::Graphic* >( xTunnel->getSomething( getImplementationId_Static() ) ) : NULL );
275 : }
276 :
277 : //----------------------------------------------------------------------
278 53 : sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId )
279 : throw( uno::RuntimeException )
280 : {
281 212 : return( ( rId.getLength() == 16 && 0 == memcmp( getImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) ?
282 : reinterpret_cast< sal_Int64 >( mpGraphic ) :
283 265 : 0 );
284 : }
285 :
286 : }
287 :
288 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|