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 #include <string.h> 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <svpm.h> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #define _SV_SALVD_CXX 33*cdf0e10cSrcweir #include <saldata.hxx> 34*cdf0e10cSrcweir #include <salinst.h> 35*cdf0e10cSrcweir #include <salgdi.h> 36*cdf0e10cSrcweir #include <salvd.h> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #ifndef __H_FT2LIB 39*cdf0e10cSrcweir #include <wingdi.h> 40*cdf0e10cSrcweir #include <ft2lib.h> 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // ======================================================================= 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir HBITMAP ImplCreateVirDevBitmap( HDC hDC, HPS hPS, long nDX, long nDY, 46*cdf0e10cSrcweir USHORT nBitCount ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir if( !nBitCount ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir LONG nDevBitCount; 51*cdf0e10cSrcweir DevQueryCaps( hDC, CAPS_COLOR_BITCOUNT, 1, &nDevBitCount ); 52*cdf0e10cSrcweir nBitCount = nDevBitCount; 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir LONG nPlanes; 56*cdf0e10cSrcweir DevQueryCaps( hDC, CAPS_COLOR_PLANES, 1, &nPlanes ); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // entsprechende Bitmap zum OutputDevice erzeugen 59*cdf0e10cSrcweir HBITMAP hBitmap; 60*cdf0e10cSrcweir BITMAPINFOHEADER2 aBitmapInfo; 61*cdf0e10cSrcweir memset( &aBitmapInfo, 0, sizeof( BITMAPINFOHEADER2 ) ); 62*cdf0e10cSrcweir aBitmapInfo.cbFix = sizeof( BITMAPINFOHEADER2 ); 63*cdf0e10cSrcweir aBitmapInfo.cx = nDX; 64*cdf0e10cSrcweir aBitmapInfo.cy = nDY; 65*cdf0e10cSrcweir aBitmapInfo.cPlanes = nPlanes; 66*cdf0e10cSrcweir aBitmapInfo.cBitCount = (nBitCount < 4) ? 4 : nBitCount; 67*cdf0e10cSrcweir hBitmap = GpiCreateBitmap( hPS, &aBitmapInfo, 0, NULL, NULL ); 68*cdf0e10cSrcweir return hBitmap; 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // ----------------------------------------------------------------------- 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir SalVirtualDevice* Os2SalInstance::CreateVirtualDevice( SalGraphics* pSGraphics, 74*cdf0e10cSrcweir long nDX, long nDY, 75*cdf0e10cSrcweir USHORT nBitCount, 76*cdf0e10cSrcweir const SystemGraphicsData* pData ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir Os2SalGraphics* pGraphics = static_cast<Os2SalGraphics*>(pSGraphics); 79*cdf0e10cSrcweir HAB hAB = GetSalData()->mhAB; 80*cdf0e10cSrcweir SIZEL size; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // create device context (at this time allways display compatible) 83*cdf0e10cSrcweir DEVOPENSTRUC aDevOpenStruc = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL }; 84*cdf0e10cSrcweir HDC hDC = DevOpenDC( hAB, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&aDevOpenStruc, 0 ); 85*cdf0e10cSrcweir if ( !hDC ) 86*cdf0e10cSrcweir return NULL; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // create presentation space 89*cdf0e10cSrcweir size.cx = nDX; 90*cdf0e10cSrcweir size.cy = nDY; 91*cdf0e10cSrcweir HPS hPS = Ft2CreatePS( hAB, hDC, &size, GPIT_MICRO | GPIA_ASSOC | PU_PELS ); 92*cdf0e10cSrcweir if ( !hPS ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir DevCloseDC( hDC ); 95*cdf0e10cSrcweir return NULL; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // create bitmap for the virtual device 99*cdf0e10cSrcweir HBITMAP hBmp = ImplCreateVirDevBitmap( hDC, hPS, nDX, nDY, nBitCount ); 100*cdf0e10cSrcweir if ( !hBmp ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir Ft2DestroyPS( hPS ); 103*cdf0e10cSrcweir DevCloseDC( hDC ); 104*cdf0e10cSrcweir return NULL; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // init data 108*cdf0e10cSrcweir Os2SalVirtualDevice* pVDev = new Os2SalVirtualDevice; 109*cdf0e10cSrcweir Os2SalGraphics* pVirGraphics = new Os2SalGraphics; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir pVirGraphics->mhDC = hDC; 112*cdf0e10cSrcweir pVirGraphics->mhPS = hPS; 113*cdf0e10cSrcweir pVirGraphics->mhWnd = 0; 114*cdf0e10cSrcweir pVirGraphics->mnHeight = nDY; 115*cdf0e10cSrcweir pVirGraphics->mbPrinter = FALSE; 116*cdf0e10cSrcweir pVirGraphics->mbVirDev = TRUE; 117*cdf0e10cSrcweir pVirGraphics->mbWindow = FALSE; 118*cdf0e10cSrcweir pVirGraphics->mbScreen = pGraphics->mbScreen; 119*cdf0e10cSrcweir ImplSalInitGraphics( pVirGraphics ); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir pVDev->mhDC = hDC; 122*cdf0e10cSrcweir pVDev->mhPS = hPS; 123*cdf0e10cSrcweir pVDev->mhBmp = hBmp; 124*cdf0e10cSrcweir pVDev->mhDefBmp = Ft2SetBitmap( hPS, hBmp ); 125*cdf0e10cSrcweir pVDev->mpGraphics = pVirGraphics; 126*cdf0e10cSrcweir pVDev->mnBitCount = nBitCount; 127*cdf0e10cSrcweir pVDev->mbGraphics = FALSE; 128*cdf0e10cSrcweir return pVDev; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // ----------------------------------------------------------------------- 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir void Os2SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir delete pDevice; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // ======================================================================= 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir Os2SalVirtualDevice::Os2SalVirtualDevice() 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // ----------------------------------------------------------------------- 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir Os2SalVirtualDevice::~Os2SalVirtualDevice() 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir ImplSalDeInitGraphics( mpGraphics ); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir Ft2SetBitmap( mpGraphics->mhPS, mhDefBmp ); 151*cdf0e10cSrcweir GpiDeleteBitmap( mhBmp ); 152*cdf0e10cSrcweir Ft2DestroyPS( mpGraphics->mhPS ); 153*cdf0e10cSrcweir DevCloseDC( mpGraphics->mhDC ); 154*cdf0e10cSrcweir delete mpGraphics; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // ----------------------------------------------------------------------- 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir SalGraphics* Os2SalVirtualDevice::GetGraphics() 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir if ( mbGraphics ) 162*cdf0e10cSrcweir return NULL; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir if ( mpGraphics ) 165*cdf0e10cSrcweir mbGraphics = TRUE; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir return mpGraphics; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // ----------------------------------------------------------------------- 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir void Os2SalVirtualDevice::ReleaseGraphics( SalGraphics* ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir mbGraphics = FALSE; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // ----------------------------------------------------------------------- 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir BOOL Os2SalVirtualDevice::SetSize( long nDX, long nDY ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir HBITMAP hNewBmp = ImplCreateVirDevBitmap( mhDC, 182*cdf0e10cSrcweir mhPS, nDX, nDY, 183*cdf0e10cSrcweir mnBitCount ); 184*cdf0e10cSrcweir if ( hNewBmp ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir Ft2SetBitmap( mhPS, hNewBmp ); 187*cdf0e10cSrcweir GpiDeleteBitmap( mhBmp ); 188*cdf0e10cSrcweir mhBmp = hNewBmp; 189*cdf0e10cSrcweir mpGraphics->mnHeight = nDY; 190*cdf0e10cSrcweir return TRUE; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir else 193*cdf0e10cSrcweir return FALSE; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir void Os2SalVirtualDevice::GetSize( long& rWidth, long& rHeight ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir DevQueryCaps( mpGraphics->mhDC, CAPS_WIDTH, CAPS_WIDTH, (LONG*)rWidth ); 199*cdf0e10cSrcweir DevQueryCaps( mpGraphics->mhDC, CAPS_HEIGHT, CAPS_HEIGHT, (LONG*)rHeight ); 200*cdf0e10cSrcweir } 201