1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dx_devicehelper.cxx,v $
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"
56 #include "dx_winstuff.hxx"
59 #include <vcl/sysdata.hxx>
61 using namespace ::com::sun::star
;
65 DeviceHelper::DeviceHelper() :
71 void DeviceHelper::init( HDC hdc
,
72 rendering::XGraphicDevice
& rDevice
)
78 void DeviceHelper::disposing()
80 // release all references
85 geometry::RealSize2D
DeviceHelper::getPhysicalResolution()
88 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
92 "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" );
94 const int nHorzRes( GetDeviceCaps( hDC
,
96 const int nVertRes( GetDeviceCaps( hDC
,
99 return geometry::RealSize2D( nHorzRes
*25.4,
103 geometry::RealSize2D
DeviceHelper::getPhysicalSize()
106 return ::canvas::tools::createInfiniteSize2D(); // we're disposed
109 ENSURE_OR_THROW( hDC
,
110 "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" );
112 const int nHorzSize( GetDeviceCaps( hDC
,
114 const int nVertSize( GetDeviceCaps( hDC
,
117 return geometry::RealSize2D( nHorzSize
,
121 uno::Reference
< rendering::XLinePolyPolygon2D
> DeviceHelper::createCompatibleLinePolyPolygon(
122 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
123 const uno::Sequence
< uno::Sequence
< geometry::RealPoint2D
> >& points
)
126 return uno::Reference
< rendering::XLinePolyPolygon2D
>(); // we're disposed
128 return uno::Reference
< rendering::XLinePolyPolygon2D
>(
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
)
138 return uno::Reference
< rendering::XBezierPolyPolygon2D
>(); // we're disposed
140 return uno::Reference
< rendering::XBezierPolyPolygon2D
>(
142 ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points
) ) );
145 uno::Reference
< rendering::XBitmap
> DeviceHelper::createCompatibleBitmap(
146 const uno::Reference
< rendering::XGraphicDevice
>& /*rDevice*/,
147 const geometry::IntegerSize2D
& size
)
150 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
152 DXBitmapSharedPtr
pBitmap(
154 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size
),
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
)
173 return uno::Reference
< rendering::XBitmap
>(); // we're disposed
175 DXBitmapSharedPtr
pBitmap(
177 ::basegfx::unotools::b2ISizeFromIntegerSize2D(size
),
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()
196 sal_Bool
DeviceHelper::enterFullScreenMode( sal_Bool
/*bEnter*/ )
201 uno::Any
DeviceHelper::isAccelerated() const
203 return ::com::sun::star::uno::makeAny(false);
206 uno::Any
DeviceHelper::getDeviceHandle() const
210 return uno::makeAny( reinterpret_cast< sal_Int64
>(hdc
) );
215 uno::Any
DeviceHelper::getSurfaceHandle() const
217 // TODO(F1): expose DirectDraw object
218 //return mpBackBuffer->getBitmap().get();
224 struct DeviceColorSpace
: public rtl::StaticWithInit
<uno::Reference
<rendering::XColorSpace
>,
227 uno::Reference
<rendering::XColorSpace
> operator()()
229 return vcl::unotools::createStandardColorSpace();
234 uno::Reference
<rendering::XColorSpace
> DeviceHelper::getColorSpace() const
237 return DeviceColorSpace::get();