1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_canvas.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <ctype.h> // don't ask. msdev breaks otherwise... 32*cdf0e10cSrcweir #include <vcl/window.hxx> 33*cdf0e10cSrcweir #include <vcl/canvastools.hxx> 34*cdf0e10cSrcweir #include <canvas/debug.hxx> 35*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 36*cdf0e10cSrcweir #include <canvas/canvastools.hxx> 37*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <osl/mutex.hxx> 40*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <com/sun/star/lang/NoSupportException.hpp> 43*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 44*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 45*cdf0e10cSrcweir #include "dx_linepolypolygon.hxx" 46*cdf0e10cSrcweir #include "dx_spritecanvas.hxx" 47*cdf0e10cSrcweir #include "dx_canvasbitmap.hxx" 48*cdf0e10cSrcweir #include "dx_devicehelper.hxx" 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #undef WB_LEFT 52*cdf0e10cSrcweir #undef WB_RIGHT 53*cdf0e10cSrcweir #include "dx_winstuff.hxx" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include <vcl/sysdata.hxx> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir using namespace ::com::sun::star; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir namespace dxcanvas 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir DeviceHelper::DeviceHelper() : 63*cdf0e10cSrcweir mpDevice( NULL ), 64*cdf0e10cSrcweir mnHDC(0) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir void DeviceHelper::init( HDC hdc, 69*cdf0e10cSrcweir rendering::XGraphicDevice& rDevice ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir mnHDC = hdc; 72*cdf0e10cSrcweir mpDevice = &rDevice; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir void DeviceHelper::disposing() 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir // release all references 78*cdf0e10cSrcweir mnHDC = 0; 79*cdf0e10cSrcweir mpDevice = NULL; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir geometry::RealSize2D DeviceHelper::getPhysicalResolution() 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir if( !mpDevice ) 85*cdf0e10cSrcweir return ::canvas::tools::createInfiniteSize2D(); // we're disposed 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir HDC hDC = getHDC(); 88*cdf0e10cSrcweir ENSURE_OR_THROW( hDC, 89*cdf0e10cSrcweir "DeviceHelper::getPhysicalResolution(): cannot retrieve HDC from window" ); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir const int nHorzRes( GetDeviceCaps( hDC, 92*cdf0e10cSrcweir LOGPIXELSX ) ); 93*cdf0e10cSrcweir const int nVertRes( GetDeviceCaps( hDC, 94*cdf0e10cSrcweir LOGPIXELSY ) ); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir return geometry::RealSize2D( nHorzRes*25.4, 97*cdf0e10cSrcweir nVertRes*25.4 ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir geometry::RealSize2D DeviceHelper::getPhysicalSize() 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir if( !mpDevice ) 103*cdf0e10cSrcweir return ::canvas::tools::createInfiniteSize2D(); // we're disposed 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir HDC hDC=getHDC(); 106*cdf0e10cSrcweir ENSURE_OR_THROW( hDC, 107*cdf0e10cSrcweir "DeviceHelper::getPhysicalSize(): cannot retrieve HDC from window" ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir const int nHorzSize( GetDeviceCaps( hDC, 110*cdf0e10cSrcweir HORZSIZE ) ); 111*cdf0e10cSrcweir const int nVertSize( GetDeviceCaps( hDC, 112*cdf0e10cSrcweir VERTSIZE ) ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir return geometry::RealSize2D( nHorzSize, 115*cdf0e10cSrcweir nVertSize ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir uno::Reference< rendering::XLinePolyPolygon2D > DeviceHelper::createCompatibleLinePolyPolygon( 119*cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 120*cdf0e10cSrcweir const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir if( !mpDevice ) 123*cdf0e10cSrcweir return uno::Reference< rendering::XLinePolyPolygon2D >(); // we're disposed 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir return uno::Reference< rendering::XLinePolyPolygon2D >( 126*cdf0e10cSrcweir new LinePolyPolygon( 127*cdf0e10cSrcweir ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence( points ) ) ); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir uno::Reference< rendering::XBezierPolyPolygon2D > DeviceHelper::createCompatibleBezierPolyPolygon( 131*cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 132*cdf0e10cSrcweir const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir if( !mpDevice ) 135*cdf0e10cSrcweir return uno::Reference< rendering::XBezierPolyPolygon2D >(); // we're disposed 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir return uno::Reference< rendering::XBezierPolyPolygon2D >( 138*cdf0e10cSrcweir new LinePolyPolygon( 139*cdf0e10cSrcweir ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence( points ) ) ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleBitmap( 143*cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 144*cdf0e10cSrcweir const geometry::IntegerSize2D& size ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir if( !mpDevice ) 147*cdf0e10cSrcweir return uno::Reference< rendering::XBitmap >(); // we're disposed 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir DXBitmapSharedPtr pBitmap( 150*cdf0e10cSrcweir new DXBitmap( 151*cdf0e10cSrcweir ::basegfx::unotools::b2ISizeFromIntegerSize2D(size), 152*cdf0e10cSrcweir false)); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // create a 24bit RGB system memory surface 155*cdf0e10cSrcweir return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice)); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileBitmap( 159*cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 160*cdf0e10cSrcweir const geometry::IntegerSize2D& /*size*/ ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir return uno::Reference< rendering::XVolatileBitmap >(); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir uno::Reference< rendering::XBitmap > DeviceHelper::createCompatibleAlphaBitmap( 166*cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 167*cdf0e10cSrcweir const geometry::IntegerSize2D& size ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir if( !mpDevice ) 170*cdf0e10cSrcweir return uno::Reference< rendering::XBitmap >(); // we're disposed 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir DXBitmapSharedPtr pBitmap( 173*cdf0e10cSrcweir new DXBitmap( 174*cdf0e10cSrcweir ::basegfx::unotools::b2ISizeFromIntegerSize2D(size), 175*cdf0e10cSrcweir true)); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // create a 32bit ARGB system memory surface 178*cdf0e10cSrcweir return uno::Reference< rendering::XBitmap >(new CanvasBitmap(pBitmap,mpDevice)); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir uno::Reference< rendering::XVolatileBitmap > DeviceHelper::createVolatileAlphaBitmap( 182*cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& /*rDevice*/, 183*cdf0e10cSrcweir const geometry::IntegerSize2D& /*size*/ ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return uno::Reference< rendering::XVolatileBitmap >(); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir sal_Bool DeviceHelper::hasFullScreenMode() 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir return false; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir sal_Bool DeviceHelper::enterFullScreenMode( sal_Bool /*bEnter*/ ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir return false; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir uno::Any DeviceHelper::isAccelerated() const 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir return ::com::sun::star::uno::makeAny(false); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir uno::Any DeviceHelper::getDeviceHandle() const 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir HDC hdc( getHDC() ); 206*cdf0e10cSrcweir if( hdc ) 207*cdf0e10cSrcweir return uno::makeAny( reinterpret_cast< sal_Int64 >(hdc) ); 208*cdf0e10cSrcweir else 209*cdf0e10cSrcweir return uno::Any(); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir uno::Any DeviceHelper::getSurfaceHandle() const 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir // TODO(F1): expose DirectDraw object 215*cdf0e10cSrcweir //return mpBackBuffer->getBitmap().get(); 216*cdf0e10cSrcweir return uno::Any(); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir namespace 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir struct DeviceColorSpace: public rtl::StaticWithInit<uno::Reference<rendering::XColorSpace>, 222*cdf0e10cSrcweir DeviceColorSpace> 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir uno::Reference<rendering::XColorSpace> operator()() 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir return vcl::unotools::createStandardColorSpace(); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir }; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir uno::Reference<rendering::XColorSpace> DeviceHelper::getColorSpace() const 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir // always the same 234*cdf0e10cSrcweir return DeviceColorSpace::get(); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir } 237