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