merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / directx / dx_devicehelper.cxx
blobc2af14802093c90e9765b1370adb23bb0b19986e
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: dx_devicehelper.cxx,v $
10 * $Revision: 1.4 $
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 <ctype.h> // don't ask. msdev breaks otherwise...
35 #include <vcl/window.hxx>
36 #include <vcl/canvastools.hxx>
37 #include <canvas/debug.hxx>
38 #include <canvas/verbosetrace.hxx>
39 #include <canvas/canvastools.hxx>
40 #include <tools/diagnose_ex.h>
42 #include <osl/mutex.hxx>
43 #include <cppuhelper/compbase1.hxx>
45 #include <com/sun/star/lang/NoSupportException.hpp>
46 #include <toolkit/helper/vclunohelper.hxx>
47 #include <basegfx/tools/canvastools.hxx>
48 #include "dx_linepolypolygon.hxx"
49 #include "dx_spritecanvas.hxx"
50 #include "dx_canvasbitmap.hxx"
51 #include "dx_devicehelper.hxx"
54 #undef WB_LEFT
55 #undef WB_RIGHT
56 #include "dx_winstuff.hxx"
59 #include <vcl/sysdata.hxx>
61 using namespace ::com::sun::star;
63 namespace dxcanvas
65 DeviceHelper::DeviceHelper() :
66 mpDevice( NULL ),
67 mnHDC(0)
71 void DeviceHelper::init( HDC hdc,
72 rendering::XGraphicDevice& rDevice )
74 mnHDC = hdc;
75 mpDevice = &rDevice;
78 void DeviceHelper::disposing()
80 // release all references
81 mnHDC = 0;
82 mpDevice = NULL;
85 geometry::RealSize2D DeviceHelper::getPhysicalResolution()
87 if( !mpDevice )
88 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
90 HDC hDC = getHDC();
91 ENSURE_OR_THROW( hDC,
92 "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" );
94 const int nHorzRes( GetDeviceCaps( hDC,
95 LOGPIXELSX ) );
96 const int nVertRes( GetDeviceCaps( hDC,
97 LOGPIXELSY ) );
99 return geometry::RealSize2D( nHorzRes*25.4,
100 nVertRes*25.4 );
103 geometry::RealSize2D DeviceHelper::getPhysicalSize()
105 if( !mpDevice )
106 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
108 HDC hDC=getHDC();
109 ENSURE_OR_THROW( hDC,
110 "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" );
112 const int nHorzSize( GetDeviceCaps( hDC,
113 HORZSIZE ) );
114 const int nVertSize( GetDeviceCaps( hDC,
115 VERTSIZE ) );
117 return geometry::RealSize2D( nHorzSize,
118 nVertSize );
121 uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon(
122 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
123 const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points )
125 if( !mpDevice )
126 return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed
128 return uno::Reference< rendering::XLinePolyPolygon2D >(
129 new LinePolyPolygon(
130 ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) );
133 uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon(
134 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
135 const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points )
137 if( !mpDevice )
138 return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed
140 return uno::Reference< rendering::XBezierPolyPolygon2D >(
141 new LinePolyPolygon(
142 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) );
145 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap(
146 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
147 const geometry::IntegerSize2D& size )
149 if( !mpDevice )
150 return uno::Reference< rendering::XBitmap >(); // we're disposed
152 DXBitmapSharedPtr pBitmap(
153 new DXBitmap(
154 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
155 false));
157 // create a 24bit RGB system memory surface
158 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
161 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap(
162 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
163 const geometry::IntegerSize2D& /*size*/ )
165 return uno::Reference< rendering::XVolatileBitmap >();
168 uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap(
169 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
170 const geometry::IntegerSize2D& size )
172 if( !mpDevice )
173 return uno::Reference< rendering::XBitmap >(); // we're disposed
175 DXBitmapSharedPtr pBitmap(
176 new DXBitmap(
177 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size),
178 true));
180 // create a 32bit ARGB system memory surface
181 return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice));
184 uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap(
185 const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/,
186 const geometry::IntegerSize2D& /*size*/ )
188 return uno::Reference< rendering::XVolatileBitmap >();
191 sal_Bool DeviceHelper::hasFullScreenMode()
193 return false;
196 sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool /*bEnter*/ )
198 return false;
201 uno::Any DeviceHelper::isAccelerated() const
203 return ::com::sun::star::uno::makeAny(false);
206 uno::Any DeviceHelper::getDeviceHandle() const
208 HDC hdc( getHDC() );
209 if( hdc )
210 return uno::makeAny( reinterpret_cast< sal_Int64 >(hdc) );
211 else
212 return uno::Any();
215 uno::Any DeviceHelper::getSurfaceHandle() const
217 // TODO(F1): expose DirectDraw object
218 //return mpBackBuffer->getBitmap().get();
219 return uno::Any();
222 namespace
224 struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>,
225 DeviceColorSpace>
227 uno::Reference<rendering::XColorSpace> operator()()
229 return vcl::unotools::createStandardColorSpace();
234 uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const
236 // always the same
237 return DeviceColorSpace::get();