xref: /aoo41x/main/vcl/os2/source/gdi/salvd.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <string.h>
29 
30 #include <svpm.h>
31 
32 #define _SV_SALVD_CXX
33 #include <saldata.hxx>
34 #include <salinst.h>
35 #include <salgdi.h>
36 #include <salvd.h>
37 
38 #ifndef __H_FT2LIB
39 #include <wingdi.h>
40 #include <ft2lib.h>
41 #endif
42 
43 // =======================================================================
44 
45 HBITMAP ImplCreateVirDevBitmap( HDC hDC, HPS hPS, long nDX, long nDY,
46 								USHORT nBitCount )
47 {
48 	if( !nBitCount )
49 	{
50 		LONG nDevBitCount;
51 		DevQueryCaps( hDC, CAPS_COLOR_BITCOUNT, 1, &nDevBitCount );
52 		nBitCount = nDevBitCount;
53 	}
54 
55 	LONG nPlanes;
56 	DevQueryCaps( hDC, CAPS_COLOR_PLANES, 1, &nPlanes );
57 
58 	// entsprechende Bitmap zum OutputDevice erzeugen
59 	HBITMAP hBitmap;
60 	BITMAPINFOHEADER2 aBitmapInfo;
61 	memset( &aBitmapInfo, 0, sizeof( BITMAPINFOHEADER2 ) );
62 	aBitmapInfo.cbFix	  = sizeof( BITMAPINFOHEADER2 );
63 	aBitmapInfo.cx		  = nDX;
64 	aBitmapInfo.cy		  = nDY;
65 	aBitmapInfo.cPlanes   = nPlanes;
66 	aBitmapInfo.cBitCount = (nBitCount < 4) ? 4 : nBitCount;
67 	hBitmap  = GpiCreateBitmap( hPS, &aBitmapInfo, 0, NULL, NULL );
68 	return hBitmap;
69 }
70 
71 // -----------------------------------------------------------------------
72 
73 SalVirtualDevice* Os2SalInstance::CreateVirtualDevice( SalGraphics* pSGraphics,
74 													long nDX, long nDY,
75 													USHORT nBitCount,
76 												   	const SystemGraphicsData* pData )
77 {
78     Os2SalGraphics* pGraphics = static_cast<Os2SalGraphics*>(pSGraphics);
79 	HAB 	hAB = GetSalData()->mhAB;
80 	SIZEL	size;
81 
82 	// create device context (at this time allways display compatible)
83 	DEVOPENSTRUC aDevOpenStruc = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
84 	HDC hDC = DevOpenDC( hAB, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&aDevOpenStruc, 0 );
85 	if ( !hDC )
86 		return NULL;
87 
88 	// create presentation space
89 	size.cx = nDX;
90 	size.cy = nDY;
91 	HPS hPS = Ft2CreatePS( hAB, hDC, &size, GPIT_MICRO | GPIA_ASSOC | PU_PELS );
92 	if ( !hPS )
93 	{
94 		DevCloseDC( hDC );
95 		return NULL;
96 	}
97 
98 	// create bitmap for the virtual device
99 	HBITMAP hBmp = ImplCreateVirDevBitmap( hDC, hPS, nDX, nDY, nBitCount );
100 	if ( !hBmp )
101 	{
102 		Ft2DestroyPS( hPS );
103 		DevCloseDC( hDC );
104 		return NULL;
105 	}
106 
107 	// init data
108 	Os2SalVirtualDevice*	pVDev				= new Os2SalVirtualDevice;
109 	Os2SalGraphics*		pVirGraphics		= new Os2SalGraphics;
110 
111 	pVirGraphics->mhDC		= hDC;
112 	pVirGraphics->mhPS		= hPS;
113 	pVirGraphics->mhWnd		= 0;
114 	pVirGraphics->mnHeight	= nDY;
115 	pVirGraphics->mbPrinter	= FALSE;
116 	pVirGraphics->mbVirDev	= TRUE;
117 	pVirGraphics->mbWindow	= FALSE;
118 	pVirGraphics->mbScreen	= pGraphics->mbScreen;
119 	ImplSalInitGraphics( pVirGraphics );
120 
121 	pVDev->mhDC				= hDC;
122 	pVDev->mhPS				= hPS;
123 	pVDev->mhBmp			= hBmp;
124 	pVDev->mhDefBmp			= Ft2SetBitmap( hPS, hBmp );
125 	pVDev->mpGraphics		= pVirGraphics;
126 	pVDev->mnBitCount		= nBitCount;
127 	pVDev->mbGraphics		= FALSE;
128 	return pVDev;
129 }
130 
131 // -----------------------------------------------------------------------
132 
133 void Os2SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice )
134 {
135 	delete pDevice;
136 }
137 
138 // =======================================================================
139 
140 Os2SalVirtualDevice::Os2SalVirtualDevice()
141 {
142 }
143 
144 // -----------------------------------------------------------------------
145 
146 Os2SalVirtualDevice::~Os2SalVirtualDevice()
147 {
148 	ImplSalDeInitGraphics( mpGraphics );
149 
150 	Ft2SetBitmap( mpGraphics->mhPS, mhDefBmp );
151 	GpiDeleteBitmap( mhBmp );
152 	Ft2DestroyPS( mpGraphics->mhPS );
153 	DevCloseDC( mpGraphics->mhDC );
154 	delete mpGraphics;
155 }
156 
157 // -----------------------------------------------------------------------
158 
159 SalGraphics* Os2SalVirtualDevice::GetGraphics()
160 {
161 	if ( mbGraphics )
162 		return NULL;
163 
164 	if ( mpGraphics )
165 		mbGraphics = TRUE;
166 
167 	return mpGraphics;
168 }
169 
170 // -----------------------------------------------------------------------
171 
172 void Os2SalVirtualDevice::ReleaseGraphics( SalGraphics* )
173 {
174 	mbGraphics = FALSE;
175 }
176 
177 // -----------------------------------------------------------------------
178 
179 BOOL Os2SalVirtualDevice::SetSize( long nDX, long nDY )
180 {
181 	HBITMAP hNewBmp = ImplCreateVirDevBitmap( mhDC,
182 											  mhPS, nDX, nDY,
183 											  mnBitCount );
184 	if ( hNewBmp )
185 	{
186 		Ft2SetBitmap( mhPS, hNewBmp );
187 		GpiDeleteBitmap( mhBmp );
188 		mhBmp = hNewBmp;
189 		mpGraphics->mnHeight  = nDY;
190 		return TRUE;
191 	}
192 	else
193 		return FALSE;
194 }
195 
196 void Os2SalVirtualDevice::GetSize( long& rWidth, long& rHeight )
197 {
198     DevQueryCaps( mpGraphics->mhDC, CAPS_WIDTH, CAPS_WIDTH, (LONG*)rWidth );
199     DevQueryCaps( mpGraphics->mhDC, CAPS_HEIGHT, CAPS_HEIGHT, (LONG*)rHeight );
200 }
201