update dev300-m58
[ooovba.git] / vcl / os2 / source / gdi / salvd.cxx
blobec024c366c72ba5ab351ddf65d1bde72fb65e2e3
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: salvd.cxx,v $
10 * $Revision: 1.5 $
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 #include <string.h>
33 #include <svpm.h>
35 #define _SV_SALVD_CXX
36 #include <saldata.hxx>
37 #include <salinst.h>
38 #include <salgdi.h>
39 #include <salvd.h>
41 #ifndef __H_FT2LIB
42 #include <wingdi.h>
43 #include <ft2lib.h>
44 #endif
46 // =======================================================================
48 HBITMAP ImplCreateVirDevBitmap( HDC hDC, HPS hPS, long nDX, long nDY,
49 USHORT nBitCount )
51 if( !nBitCount )
53 LONG nDevBitCount;
54 DevQueryCaps( hDC, CAPS_COLOR_BITCOUNT, 1, &nDevBitCount );
55 nBitCount = nDevBitCount;
58 LONG nPlanes;
59 DevQueryCaps( hDC, CAPS_COLOR_PLANES, 1, &nPlanes );
61 // entsprechende Bitmap zum OutputDevice erzeugen
62 HBITMAP hBitmap;
63 BITMAPINFOHEADER2 aBitmapInfo;
64 memset( &aBitmapInfo, 0, sizeof( BITMAPINFOHEADER2 ) );
65 aBitmapInfo.cbFix = sizeof( BITMAPINFOHEADER2 );
66 aBitmapInfo.cx = nDX;
67 aBitmapInfo.cy = nDY;
68 aBitmapInfo.cPlanes = nPlanes;
69 aBitmapInfo.cBitCount = (nBitCount < 4) ? 4 : nBitCount;
70 hBitmap = GpiCreateBitmap( hPS, &aBitmapInfo, 0, NULL, NULL );
71 return hBitmap;
74 // -----------------------------------------------------------------------
76 SalVirtualDevice* Os2SalInstance::CreateVirtualDevice( SalGraphics* pSGraphics,
77 long nDX, long nDY,
78 USHORT nBitCount,
79 const SystemGraphicsData* pData )
81 Os2SalGraphics* pGraphics = static_cast<Os2SalGraphics*>(pSGraphics);
82 HAB hAB = GetSalData()->mhAB;
83 SIZEL size;
85 // create device context (at this time allways display compatible)
86 DEVOPENSTRUC aDevOpenStruc = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
87 HDC hDC = DevOpenDC( hAB, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&aDevOpenStruc, 0 );
88 if ( !hDC )
89 return NULL;
91 // create presentation space
92 size.cx = nDX;
93 size.cy = nDY;
94 HPS hPS = Ft2CreatePS( hAB, hDC, &size, GPIT_MICRO | GPIA_ASSOC | PU_PELS );
95 if ( !hPS )
97 DevCloseDC( hDC );
98 return NULL;
101 // create bitmap for the virtual device
102 HBITMAP hBmp = ImplCreateVirDevBitmap( hDC, hPS, nDX, nDY, nBitCount );
103 if ( !hBmp )
105 Ft2DestroyPS( hPS );
106 DevCloseDC( hDC );
107 return NULL;
110 // init data
111 Os2SalVirtualDevice* pVDev = new Os2SalVirtualDevice;
112 Os2SalGraphics* pVirGraphics = new Os2SalGraphics;
114 pVirGraphics->mhDC = hDC;
115 pVirGraphics->mhPS = hPS;
116 pVirGraphics->mhWnd = 0;
117 pVirGraphics->mnHeight = nDY;
118 pVirGraphics->mbPrinter = FALSE;
119 pVirGraphics->mbVirDev = TRUE;
120 pVirGraphics->mbWindow = FALSE;
121 pVirGraphics->mbScreen = pGraphics->mbScreen;
122 ImplSalInitGraphics( pVirGraphics );
124 pVDev->mhDC = hDC;
125 pVDev->mhPS = hPS;
126 pVDev->mhBmp = hBmp;
127 pVDev->mhDefBmp = Ft2SetBitmap( hPS, hBmp );
128 pVDev->mpGraphics = pVirGraphics;
129 pVDev->mnBitCount = nBitCount;
130 pVDev->mbGraphics = FALSE;
131 return pVDev;
134 // -----------------------------------------------------------------------
136 void Os2SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice )
138 delete pDevice;
141 // =======================================================================
143 Os2SalVirtualDevice::Os2SalVirtualDevice()
147 // -----------------------------------------------------------------------
149 Os2SalVirtualDevice::~Os2SalVirtualDevice()
151 ImplSalDeInitGraphics( mpGraphics );
153 Ft2SetBitmap( mpGraphics->mhPS, mhDefBmp );
154 GpiDeleteBitmap( mhBmp );
155 Ft2DestroyPS( mpGraphics->mhPS );
156 DevCloseDC( mpGraphics->mhDC );
157 delete mpGraphics;
160 // -----------------------------------------------------------------------
162 SalGraphics* Os2SalVirtualDevice::GetGraphics()
164 if ( mbGraphics )
165 return NULL;
167 if ( mpGraphics )
168 mbGraphics = TRUE;
170 return mpGraphics;
173 // -----------------------------------------------------------------------
175 void Os2SalVirtualDevice::ReleaseGraphics( SalGraphics* )
177 mbGraphics = FALSE;
180 // -----------------------------------------------------------------------
182 BOOL Os2SalVirtualDevice::SetSize( long nDX, long nDY )
184 HBITMAP hNewBmp = ImplCreateVirDevBitmap( mhDC,
185 mhPS, nDX, nDY,
186 mnBitCount );
187 if ( hNewBmp )
189 Ft2SetBitmap( mhPS, hNewBmp );
190 GpiDeleteBitmap( mhBmp );
191 mhBmp = hNewBmp;
192 mpGraphics->mnHeight = nDY;
193 return TRUE;
195 else
196 return FALSE;
199 void Os2SalVirtualDevice::GetSize( long& rWidth, long& rHeight )
201 DevQueryCaps( mpGraphics->mhDC, CAPS_WIDTH, CAPS_WIDTH, (LONG*)rWidth );
202 DevQueryCaps( mpGraphics->mhDC, CAPS_HEIGHT, CAPS_HEIGHT, (LONG*)rHeight );