merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / vcl / canvasbitmap.cxx
blob55e12f11b361b5774da1700bc21477e0deb390f0
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: canvasbitmap.cxx,v $
10 * $Revision: 1.11 $
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 <tools/diagnose_ex.h>
36 #include "canvasbitmap.hxx"
38 #include <vcl/bmpacc.hxx>
40 using namespace ::com::sun::star;
43 namespace vclcanvas
45 // Currently, the only way to generate an XBitmap is from
46 // XGraphicDevice.getCompatibleBitmap(). Therefore, we don't even
47 // take a bitmap here, but a VDev directly.
48 CanvasBitmap::CanvasBitmap( const ::Size& rSize,
49 bool bAlphaBitmap,
50 rendering::XGraphicDevice& rDevice,
51 const OutDevProviderSharedPtr& rOutDevProvider )
53 // create bitmap for given reference device
54 // ========================================
55 const USHORT nBitCount( (USHORT)24U );
56 const BitmapPalette* pPalette = NULL;
58 Bitmap aBitmap( rSize, nBitCount, pPalette );
60 // only create alpha channel bitmap, if factory requested
61 // that. Providing alpha-channeled bitmaps by default has,
62 // especially under VCL, a huge performance penalty (have to
63 // use alpha VDev, then).
64 if( bAlphaBitmap )
66 AlphaMask aAlpha ( rSize );
68 maCanvasHelper.init( BitmapEx( aBitmap, aAlpha ),
69 rDevice,
70 rOutDevProvider );
72 else
74 maCanvasHelper.init( BitmapEx( aBitmap ),
75 rDevice,
76 rOutDevProvider );
80 CanvasBitmap::CanvasBitmap( const BitmapEx& rBitmap,
81 rendering::XGraphicDevice& rDevice,
82 const OutDevProviderSharedPtr& rOutDevProvider )
84 maCanvasHelper.init( rBitmap, rDevice, rOutDevProvider );
87 void SAL_CALL CanvasBitmap::disposing()
89 // forward to base
90 CanvasBitmap_Base::disposing();
93 #define IMPLEMENTATION_NAME "VCLCanvas.CanvasBitmap"
94 #define SERVICE_NAME "com.sun.star.rendering.CanvasBitmap"
96 ::rtl::OUString SAL_CALL CanvasBitmap::getImplementationName( ) throw (uno::RuntimeException)
98 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
101 sal_Bool SAL_CALL CanvasBitmap::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
103 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
106 uno::Sequence< ::rtl::OUString > SAL_CALL CanvasBitmap::getSupportedServiceNames( ) throw (uno::RuntimeException)
108 uno::Sequence< ::rtl::OUString > aRet(1);
109 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
111 return aRet;
114 BitmapEx CanvasBitmap::getBitmap() const
116 tools::LocalGuard aGuard;
118 // TODO(T3): Rework to use shared_ptr all over the place for
119 // BmpEx. This is highly un-threadsafe
120 return maCanvasHelper.getBitmap();
123 bool CanvasBitmap::repaint( const GraphicObjectSharedPtr& rGrf,
124 const rendering::ViewState& viewState,
125 const rendering::RenderState& renderState,
126 const ::Point& rPt,
127 const ::Size& rSz,
128 const GraphicAttr& rAttr ) const
130 tools::LocalGuard aGuard;
132 mbSurfaceDirty = true;
134 return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
137 uno::Any SAL_CALL CanvasBitmap::getFastPropertyValue( sal_Int32 nHandle ) throw (uno::RuntimeException)
139 if( nHandle == 0 ) {
140 BitmapEx* pBitmapEx = new BitmapEx( getBitmap() );
142 return uno::Any( reinterpret_cast<sal_Int64>( pBitmapEx ) );
145 return uno::Any( sal_Int64(0) );