xref: /trunk/main/vcl/os2/source/gdi/salvd.cxx (revision 2d7884914f8f9b4a298efe36f7357992ec4c096c)
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 #define _SV_SALVD_CXX
29 #include <saldata.hxx>
30 #include <salinst.h>
31 #include <salgdi.h>
32 #include <salvd.h>
33 
34 #ifndef __H_FT2LIB
35 #include <wingdi.h>
36 #include <ft2lib.h>
37 #endif
38 
39 // =======================================================================
40 
41 HBITMAP ImplCreateVirDevBitmap( HDC hDC, HPS hPS, long nDX, long nDY,
42                                 USHORT nBitCount )
43 {
44     if( !nBitCount )
45     {
46         LONG nDevBitCount;
47         DevQueryCaps( hDC, CAPS_COLOR_BITCOUNT, 1, &nDevBitCount );
48         nBitCount = nDevBitCount;
49     }
50 
51     LONG nPlanes;
52     DevQueryCaps( hDC, CAPS_COLOR_PLANES, 1, &nPlanes );
53 
54     // entsprechende Bitmap zum OutputDevice erzeugen
55     HBITMAP hBitmap;
56     BITMAPINFOHEADER2 aBitmapInfo;
57     memset( &aBitmapInfo, 0, sizeof( BITMAPINFOHEADER2 ) );
58     aBitmapInfo.cbFix     = sizeof( BITMAPINFOHEADER2 );
59     aBitmapInfo.cx        = nDX;
60     aBitmapInfo.cy        = nDY;
61     aBitmapInfo.cPlanes   = nPlanes;
62     aBitmapInfo.cBitCount = (nBitCount < 4) ? 4 : nBitCount;
63     hBitmap  = GpiCreateBitmap( hPS, &aBitmapInfo, 0, NULL, NULL );
64     return hBitmap;
65 }
66 
67 // -----------------------------------------------------------------------
68 
69 SalVirtualDevice* Os2SalInstance::CreateVirtualDevice( SalGraphics* pSGraphics,
70                                                     long nDX, long nDY,
71                                                     USHORT nBitCount,
72                                                     const SystemGraphicsData* pData )
73 {
74     Os2SalGraphics* pGraphics = static_cast<Os2SalGraphics*>(pSGraphics);
75     HAB     hAB = GetSalData()->mhAB;
76     SIZEL   size;
77 
78     // create device context (at this time allways display compatible)
79     DEVOPENSTRUC aDevOpenStruc = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
80     HDC hDC = DevOpenDC( hAB, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&aDevOpenStruc, 0 );
81     if ( !hDC )
82         return NULL;
83 
84     // create presentation space
85     size.cx = nDX;
86     size.cy = nDY;
87     HPS hPS = Ft2CreatePS( hAB, hDC, &size, GPIT_MICRO | GPIA_ASSOC | PU_PELS );
88     if ( !hPS )
89     {
90         DevCloseDC( hDC );
91         return NULL;
92     }
93 
94     // create bitmap for the virtual device
95     HBITMAP hBmp = ImplCreateVirDevBitmap( hDC, hPS, nDX, nDY, nBitCount );
96     if ( !hBmp )
97     {
98         Ft2DestroyPS( hPS );
99         DevCloseDC( hDC );
100         return NULL;
101     }
102 
103     // init data
104     Os2SalVirtualDevice*    pVDev               = new Os2SalVirtualDevice;
105     Os2SalGraphics*     pVirGraphics        = new Os2SalGraphics;
106 
107     pVirGraphics->mhDC      = hDC;
108     pVirGraphics->mhPS      = hPS;
109     pVirGraphics->mhWnd     = 0;
110     pVirGraphics->mnHeight  = nDY;
111     pVirGraphics->mbPrinter = FALSE;
112     pVirGraphics->mbVirDev  = TRUE;
113     pVirGraphics->mbWindow  = FALSE;
114     pVirGraphics->mbScreen  = pGraphics->mbScreen;
115     ImplSalInitGraphics( pVirGraphics );
116 
117     pVDev->mhDC             = hDC;
118     pVDev->mhPS             = hPS;
119     pVDev->mhBmp            = hBmp;
120     pVDev->mhDefBmp         = Ft2SetBitmap( hPS, hBmp );
121     pVDev->mpGraphics       = pVirGraphics;
122     pVDev->mnBitCount       = nBitCount;
123     pVDev->mbGraphics       = FALSE;
124     return pVDev;
125 }
126 
127 // -----------------------------------------------------------------------
128 
129 void Os2SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice )
130 {
131     delete pDevice;
132 }
133 
134 // =======================================================================
135 
136 Os2SalVirtualDevice::Os2SalVirtualDevice()
137 {
138 }
139 
140 // -----------------------------------------------------------------------
141 
142 Os2SalVirtualDevice::~Os2SalVirtualDevice()
143 {
144     ImplSalDeInitGraphics( mpGraphics );
145 
146     Ft2SetBitmap( mpGraphics->mhPS, mhDefBmp );
147     GpiDeleteBitmap( mhBmp );
148     Ft2DestroyPS( mpGraphics->mhPS );
149     DevCloseDC( mpGraphics->mhDC );
150     delete mpGraphics;
151 }
152 
153 // -----------------------------------------------------------------------
154 
155 SalGraphics* Os2SalVirtualDevice::GetGraphics()
156 {
157     if ( mbGraphics )
158         return NULL;
159 
160     if ( mpGraphics )
161         mbGraphics = TRUE;
162 
163     return mpGraphics;
164 }
165 
166 // -----------------------------------------------------------------------
167 
168 void Os2SalVirtualDevice::ReleaseGraphics( SalGraphics* )
169 {
170     mbGraphics = FALSE;
171 }
172 
173 // -----------------------------------------------------------------------
174 
175 BOOL Os2SalVirtualDevice::SetSize( long nDX, long nDY )
176 {
177     HBITMAP hNewBmp = ImplCreateVirDevBitmap( mhDC,
178                                               mhPS, nDX, nDY,
179                                               mnBitCount );
180     if ( hNewBmp )
181     {
182         Ft2SetBitmap( mhPS, hNewBmp );
183         GpiDeleteBitmap( mhBmp );
184         mhBmp = hNewBmp;
185         mpGraphics->mnHeight  = nDY;
186         return TRUE;
187     }
188     else
189         return FALSE;
190 }
191 
192 void Os2SalVirtualDevice::GetSize( long& rWidth, long& rHeight )
193 {
194     DevQueryCaps( mpGraphics->mhDC, CAPS_WIDTH, CAPS_WIDTH, (LONG*)rWidth );
195     DevQueryCaps( mpGraphics->mhDC, CAPS_HEIGHT, CAPS_HEIGHT, (LONG*)rHeight );
196 }
197