merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / cairo / cairo_canvascustomsprite.cxx
blob623d3ce3790a940f8b2bf6c31232c2ee42b68644
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: cairo_canvascustomsprite.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_canvas.hxx"
34 #include <canvas/debug.hxx>
35 #include <canvas/verbosetrace.hxx>
36 #include <tools/diagnose_ex.h>
38 #include <rtl/logfile.hxx>
39 #include <rtl/math.hxx>
41 #include <canvas/canvastools.hxx>
43 #include <basegfx/matrix/b2dhommatrix.hxx>
44 #include <basegfx/point/b2dpoint.hxx>
46 #include "cairo_canvascustomsprite.hxx"
47 #include "cairo_spritecanvas.hxx"
50 using namespace ::cairo;
51 using namespace ::com::sun::star;
53 namespace cairocanvas
55 CanvasCustomSprite::CanvasCustomSprite( const ::com::sun::star::geometry::RealSize2D& rSpriteSize,
56 const SpriteCanvasRef& rRefDevice ) :
57 mpSpriteCanvas( rRefDevice ),
58 maSize( ::canvas::tools::roundUp( rSpriteSize.Width ),
59 ::canvas::tools::roundUp( rSpriteSize.Height ) )
61 ENSURE_OR_THROW( rRefDevice.get(),
62 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
64 OSL_TRACE("sprite size: %d, %d",
65 ::canvas::tools::roundUp( rSpriteSize.Width ),
66 ::canvas::tools::roundUp( rSpriteSize.Height ));
68 mpBufferSurface = mpSpriteCanvas->createSurface( maSize );
70 maCanvasHelper.init( maSize,
71 *rRefDevice,
72 rRefDevice.get() );
73 maCanvasHelper.setSurface( mpBufferSurface, true );
75 maSpriteHelper.init( rSpriteSize,
76 rRefDevice );
77 maSpriteHelper.setSurface( mpBufferSurface );
79 // clear sprite to 100% transparent
80 maCanvasHelper.clear();
83 void SAL_CALL CanvasCustomSprite::disposing()
85 ::osl::MutexGuard aGuard( m_aMutex );
87 mpSpriteCanvas.clear();
88 mpBufferSurface.reset();
90 // forward to parent
91 CanvasCustomSpriteBaseT::disposing();
94 void CanvasCustomSprite::redraw( const CairoSharedPtr& pCairo,
95 bool bBufferedUpdate ) const
97 ::osl::MutexGuard aGuard( m_aMutex );
99 redraw( pCairo, maSpriteHelper.getPosPixel(), bBufferedUpdate );
102 void CanvasCustomSprite::redraw( const CairoSharedPtr& pCairo,
103 const ::basegfx::B2DPoint& rOrigOutputPos,
104 bool bBufferedUpdate ) const
106 ::osl::MutexGuard aGuard( m_aMutex );
108 maSpriteHelper.redraw( pCairo,
109 rOrigOutputPos,
110 mbSurfaceDirty,
111 bBufferedUpdate );
113 mbSurfaceDirty = false;
116 bool CanvasCustomSprite::repaint( const SurfaceSharedPtr& pSurface,
117 const rendering::ViewState& viewState,
118 const rendering::RenderState& renderState )
120 return maCanvasHelper.repaint( pSurface, viewState, renderState );
123 SurfaceSharedPtr CanvasCustomSprite::getSurface()
125 return mpBufferSurface;
128 SurfaceSharedPtr CanvasCustomSprite::createSurface( const ::basegfx::B2ISize& rSize, Content aContent )
130 return mpSpriteCanvas->createSurface(rSize,aContent);
133 SurfaceSharedPtr CanvasCustomSprite::createSurface( ::Bitmap& rBitmap )
135 return mpSpriteCanvas->createSurface(rBitmap);
138 SurfaceSharedPtr CanvasCustomSprite::changeSurface( bool bHasAlpha, bool bCopyContent )
140 if( !bHasAlpha && !bCopyContent )
142 OSL_TRACE("replacing sprite background surface");
144 mpBufferSurface = mpSpriteCanvas->createSurface( maSize, CAIRO_CONTENT_COLOR );
145 maSpriteHelper.setSurface( mpBufferSurface );
147 return mpBufferSurface;
150 return SurfaceSharedPtr();
153 OutputDevice* CanvasCustomSprite::getOutputDevice()
155 return mpSpriteCanvas->getOutputDevice();
158 #define IMPLEMENTATION_NAME "CairoCanvas.CanvasCustomSprite"
159 #define SERVICE_NAME "com.sun.star.rendering.CanvasCustomSprite"
161 ::rtl::OUString SAL_CALL CanvasCustomSprite::getImplementationName() throw( uno::RuntimeException )
163 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
166 sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
168 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
171 uno::Sequence< ::rtl::OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames() throw( uno::RuntimeException )
173 uno::Sequence< ::rtl::OUString > aRet(1);
174 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
176 return aRet;