merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / vcl / devicehelper.cxx
blob77bde607ec90dea493df3555373d4988aa92f511
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: devicehelper.cxx,v $
10 * $Revision: 1.8 $
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 <canvas/canvastools.hxx>
38 #include <rtl/instance.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <vcl/canvastools.hxx>
41 #include <basegfx/tools/canvastools.hxx>
42 #include <basegfx/tools/unopolypolygon.hxx>
44 #include "devicehelper.hxx"
45 #include "spritecanvas.hxx"
46 #include "spritecanvashelper.hxx"
47 #include "canvasbitmap.hxx"
50 using namespace ::com::sun::star;
52 namespace vclcanvas
54 DeviceHelper::DeviceHelper() :
55 mpOutDev()
58 void DeviceHelper::init( const OutDevProviderSharedPtr& rOutDev )
60 mpOutDev = rOutDev;
63 geometry::RealSize2D DeviceHelper::getPhysicalResolution()
65 if( !mpOutDev )
66 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
68 // Map a one-by-one millimeter box to pixel
69 OutputDevice& rOutDev = mpOutDev->getOutDev();
70 const MapMode aOldMapMode( rOutDev.GetMapMode() );
71 rOutDev.SetMapMode( MapMode(MAP_MM) );
72 const Size aPixelSize( rOutDev.LogicToPixel(Size(1,1)) );
73 rOutDev.SetMapMode( aOldMapMode );
75 return ::vcl::unotools::size2DFromSize( aPixelSize );
78 geometry::RealSize2D DeviceHelper::getPhysicalSize()
80 if( !mpOutDev )
81 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
83 // Map the pixel dimensions of the output window to millimeter
84 OutputDevice& rOutDev = mpOutDev->getOutDev();
85 const MapMode aOldMapMode( rOutDev.GetMapMode() );
86 rOutDev.SetMapMode( MapMode(MAP_MM) );
87 const Size aLogSize( rOutDev.PixelToLogic(rOutDev.GetOutputSizePixel()) );
88 rOutDev.SetMapMode( aOldMapMode );
90 return ::vcl::unotools::size2DFromSize( aLogSize );
93 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
94 const uno::Reference< rendering::XGraphicDevice >& ,
95 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
97 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
98 if( !mpOutDev )
99 return xPoly; // we're disposed
101 xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
102 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
103 // vcl only handles even_odd polygons
104 xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
106 return xPoly;
109 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
110 const uno::Reference< rendering::XGraphicDevice >& ,
111 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
113 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
114 if( !mpOutDev )
115 return xPoly; // we're disposed
117 xPoly.set( new ::basegfx::unotools::UnoPolyPolygon(
118 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
119 // vcl only handles even_odd polygons
120 xPoly->setFillRule(rendering::FillRule_EVEN_ODD);
122 return xPoly;
125 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
126 const uno::Reference< rendering::XGraphicDevice >& rDevice,
127 const geometry::IntegerSize2D& size )
129 if( !mpOutDev )
130 return uno::Reference< rendering::XBitmap >(); // we're disposed
132 return uno::Reference< rendering::XBitmap >(
133 new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size),
134 false,
135 *rDevice.get(),
136 mpOutDev ) );
139 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
140 const uno::Reference< rendering::XGraphicDevice >& ,
141 const geometry::IntegerSize2D& )
143 return uno::Reference< rendering::XVolatileBitmap >();
146 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
147 const uno::Reference< rendering::XGraphicDevice >& rDevice,
148 const geometry::IntegerSize2D& size )
150 if( !mpOutDev )
151 return uno::Reference< rendering::XBitmap >(); // we're disposed
153 return uno::Reference< rendering::XBitmap >(
154 new CanvasBitmap( ::vcl::unotools::sizeFromIntegerSize2D(size),
155 true,
156 *rDevice.get(),
157 mpOutDev ) );
160 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
161 const uno::Reference< rendering::XGraphicDevice >& ,
162 const geometry::IntegerSize2D& )
164 return uno::Reference< rendering::XVolatileBitmap >();
167 sal_Bool DeviceHelper::hasFullScreenMode()
169 return false;
172 sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool bEnter )
174 (void)bEnter;
175 return false;
178 void DeviceHelper::disposing()
180 // release all references
181 mpOutDev.reset();
184 uno::Any DeviceHelper::isAccelerated() const
186 return ::com::sun::star::uno::makeAny(false);
189 uno::Any DeviceHelper::getDeviceHandle() const
191 if( !mpOutDev )
192 return uno::Any();
194 return uno::makeAny(
195 reinterpret_cast< sal_Int64 >(&mpOutDev->getOutDev()) );
198 uno::Any DeviceHelper::getSurfaceHandle() const
200 return getDeviceHandle();
203 namespace
205 struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
206 DeviceColorSpace>
208 uno::Reference<rendering::XColorSpace> operator()()
210 return vcl::unotools::createStandardColorSpace();
215 uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
217 // always the same
218 return DeviceColorSpace::get();
221 void DeviceHelper::dumpScreenContent() const
223 static sal_uInt32 nFilePostfixCount(0);
225 if( mpOutDev )
227 String aFilename( String::CreateFromAscii("dbg_frontbuffer") );
228 aFilename += String::CreateFromInt32(nFilePostfixCount);
229 aFilename += String::CreateFromAscii(".bmp");
231 SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
233 const ::Point aEmptyPoint;
234 OutputDevice& rOutDev = mpOutDev->getOutDev();
235 bool bOldMap( rOutDev.IsMapModeEnabled() );
236 rOutDev.EnableMapMode( FALSE );
237 aStream << rOutDev.GetBitmap(aEmptyPoint,
238 rOutDev.GetOutputSizePixel());
239 rOutDev.EnableMapMode( bOldMap );
241 ++nFilePostfixCount;