1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include <string.h> 25 26 #include <svpm.h> 27 28 #include <tools/svwin.h> 29 30 #include <vcl/sysdata.hxx> 31 32 #include <os2/saldata.hxx> 33 #include <os2/salinst.h> 34 #include <os2/salgdi.h> 35 #include <os2/salvd.h> 36 37 /* 38 #define _SV_SALVD_CXX 39 #include <saldata.hxx> 40 #include <salinst.h> 41 #include <salgdi.h> 42 #include <salvd.h> 43 */ 44 45 #ifndef __H_FT2LIB 46 #include <os2/wingdi.h> 47 #include <ft2lib.h> 48 #endif 49 50 // ======================================================================= 51 52 HBITMAP ImplCreateVirDevBitmap( HDC hDC, HPS hPS, long nDX, long nDY, 53 USHORT nBitCount ) 54 { 55 if( !nBitCount ) 56 { 57 LONG nDevBitCount; 58 DevQueryCaps( hDC, CAPS_COLOR_BITCOUNT, 1, &nDevBitCount ); 59 nBitCount = nDevBitCount; 60 } 61 62 LONG nPlanes; 63 DevQueryCaps( hDC, CAPS_COLOR_PLANES, 1, &nPlanes ); 64 65 // entsprechende Bitmap zum OutputDevice erzeugen 66 HBITMAP hBitmap; 67 BITMAPINFOHEADER2 aBitmapInfo; 68 memset( &aBitmapInfo, 0, sizeof( BITMAPINFOHEADER2 ) ); 69 aBitmapInfo.cbFix = sizeof( BITMAPINFOHEADER2 ); 70 aBitmapInfo.cx = nDX; 71 aBitmapInfo.cy = nDY; 72 aBitmapInfo.cPlanes = nPlanes; 73 aBitmapInfo.cBitCount = (nBitCount < 4) ? 4 : nBitCount; 74 hBitmap = GpiCreateBitmap( hPS, &aBitmapInfo, 0, NULL, NULL ); 75 return hBitmap; 76 } 77 78 // ----------------------------------------------------------------------- 79 80 SalVirtualDevice* Os2SalInstance::CreateVirtualDevice( SalGraphics* pSGraphics, 81 long nDX, long nDY, 82 USHORT nBitCount, 83 const SystemGraphicsData* pData ) 84 { 85 Os2SalGraphics* pGraphics = static_cast<Os2SalGraphics*>(pSGraphics); 86 HAB hAB = GetSalData()->mhAB; 87 SIZEL size; 88 89 // create device context (at this time allways display compatible) 90 DEVOPENSTRUC aDevOpenStruc = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL }; 91 HDC hDC = DevOpenDC( hAB, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&aDevOpenStruc, 0 ); 92 if ( !hDC ) 93 return NULL; 94 95 // create presentation space 96 size.cx = nDX; 97 size.cy = nDY; 98 HPS hPS = Ft2CreatePS( hAB, hDC, &size, GPIT_MICRO | GPIA_ASSOC | PU_PELS ); 99 if ( !hPS ) 100 { 101 DevCloseDC( hDC ); 102 return NULL; 103 } 104 105 // create bitmap for the virtual device 106 HBITMAP hBmp = ImplCreateVirDevBitmap( hDC, hPS, nDX, nDY, nBitCount ); 107 if ( !hBmp ) 108 { 109 Ft2DestroyPS( hPS ); 110 DevCloseDC( hDC ); 111 return NULL; 112 } 113 114 // init data 115 Os2SalVirtualDevice* pVDev = new Os2SalVirtualDevice; 116 Os2SalGraphics* pVirGraphics = new Os2SalGraphics; 117 118 pVirGraphics->mhDC = hDC; 119 pVirGraphics->mhPS = hPS; 120 pVirGraphics->mhWnd = 0; 121 pVirGraphics->mnHeight = nDY; 122 pVirGraphics->mbPrinter = FALSE; 123 pVirGraphics->mbVirDev = TRUE; 124 pVirGraphics->mbWindow = FALSE; 125 pVirGraphics->mbScreen = pGraphics->mbScreen; 126 ImplSalInitGraphics( pVirGraphics ); 127 128 pVDev->mhDC = hDC; 129 pVDev->mhPS = hPS; 130 pVDev->mhBmp = hBmp; 131 pVDev->mhDefBmp = Ft2SetBitmap( hPS, hBmp ); 132 pVDev->mpGraphics = pVirGraphics; 133 pVDev->mnBitCount = nBitCount; 134 pVDev->mbGraphics = FALSE; 135 return pVDev; 136 } 137 138 // ----------------------------------------------------------------------- 139 140 void Os2SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice ) 141 { 142 delete pDevice; 143 } 144 145 // ======================================================================= 146 147 Os2SalVirtualDevice::Os2SalVirtualDevice() 148 { 149 } 150 151 // ----------------------------------------------------------------------- 152 153 Os2SalVirtualDevice::~Os2SalVirtualDevice() 154 { 155 ImplSalDeInitGraphics( mpGraphics ); 156 157 Ft2SetBitmap( mpGraphics->mhPS, mhDefBmp ); 158 GpiDeleteBitmap( mhBmp ); 159 Ft2DestroyPS( mpGraphics->mhPS ); 160 DevCloseDC( mpGraphics->mhDC ); 161 delete mpGraphics; 162 } 163 164 // ----------------------------------------------------------------------- 165 166 SalGraphics* Os2SalVirtualDevice::GetGraphics() 167 { 168 if ( mbGraphics ) 169 return NULL; 170 171 if ( mpGraphics ) 172 mbGraphics = TRUE; 173 174 return mpGraphics; 175 } 176 177 // ----------------------------------------------------------------------- 178 179 void Os2SalVirtualDevice::ReleaseGraphics( SalGraphics* ) 180 { 181 mbGraphics = FALSE; 182 } 183 184 // ----------------------------------------------------------------------- 185 186 sal_Bool Os2SalVirtualDevice::SetSize( long nDX, long nDY ) 187 { 188 HBITMAP hNewBmp = ImplCreateVirDevBitmap( mhDC, 189 mhPS, nDX, nDY, 190 mnBitCount ); 191 if ( hNewBmp ) 192 { 193 Ft2SetBitmap( mhPS, hNewBmp ); 194 GpiDeleteBitmap( mhBmp ); 195 mhBmp = hNewBmp; 196 mpGraphics->mnHeight = nDY; 197 return TRUE; 198 } 199 else 200 return FALSE; 201 } 202 203 void Os2SalVirtualDevice::GetSize( long& rWidth, long& rHeight ) 204 { 205 DevQueryCaps( mpGraphics->mhDC, CAPS_WIDTH, CAPS_WIDTH, (LONG*)rWidth ); 206 DevQueryCaps( mpGraphics->mhDC, CAPS_HEIGHT, CAPS_HEIGHT, (LONG*)rHeight ); 207 } 208