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