source: trunk/src/gdi32/devcontext.cpp@ 10469

Last change on this file since 10469 was 10469, checked in by sandervl, 22 years ago

CreateDCA: special handling of FILE and FILE: ports

File size: 17.3 KB
Line 
1/* $Id: devcontext.cpp,v 1.3 2004-02-18 14:05:48 sandervl Exp $ */
2
3/*
4 * GDI32 device context apis
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1998 Patrick Haller
8 * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#include <os2win.h>
14#include <stdlib.h>
15#include <stdarg.h>
16#include <string.h>
17#include <odinwrap.h>
18#include <misc.h>
19#include "callback.h"
20#include "unicode.h"
21#include "dibsect.h"
22#include <codepage.h>
23#include "oslibgpi.h"
24#include "oslibgdi.h"
25#include <dcdata.h>
26#include <winuser32.h>
27#include "font.h"
28#include <stats.h>
29#include <objhandle.h>
30#include <winspool.h>
31#include "region.h"
32#include <wingdi32.h>
33
34#define DBG_LOCALLOG DBG_devcontext
35#include "dbglocal.h"
36
37typedef BOOL (* WIN32API PFN_SPLQUERYPMQUEUENAME)(LPSTR pDeviceName, LPSTR lpszPMQueue, INT cbPMQueue);
38
39#ifdef DEBUG
40void dprintfDEVMODE(DEVMODEA *lpInitData);
41#else
42#define dprintfDEVMODE(a)
43#endif
44
45static const char *szDisplay = "DISPLAY";
46
47//******************************************************************************
48// GetPMQueueName
49//
50// Get the PM printer queue name associated with the printer name
51//
52// NOTE: We can't have a hardcoded dependency on WINSPOOL in GDI32, so get the
53// function address dynamically
54//
55//******************************************************************************
56static BOOL GetPMQueueName(LPSTR pDeviceName, LPSTR lpszPMQueue, INT cbPMQueue)
57{
58 return FALSE;
59}
60//******************************************************************************
61//******************************************************************************
62HDC WIN32API CreateDCA(LPCSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszOutput, const DEVMODEA *lpInitData)
63{
64 HDC hdc;
65 char szDevice[256];
66
67 // 2001-05-28 PH
68 // Ziff Davis Benchmarks come in here with "display".
69 // Obviously, Windows does accept case-insensitive driver names,
70 // whereas Open32 doesn't.
71 if(lpszDriver && !stricmp(lpszDriver, szDisplay)) {
72 lpszDriver = szDisplay;
73 }
74 else
75 { //Check if it's a printer device
76 if(GetPMQueueName((LPSTR)lpszDevice, szDevice, sizeof(szDevice)) == TRUE)
77 {
78 dprintf(("Rename printer %s to PM Queue %s", lpszDevice, szDevice));
79 lpszDevice = szDevice;
80
81 //Must ignore port name here or else the wrong queue might be used
82 //(unless we are told to print to file)
83 if (lpszOutput && strcmp(lpszOutput, "FILE:") != 0 && strcmp(lpszOutput, "FILE") != 0)
84 lpszOutput = NULL;
85 }
86 }
87
88 //SvL: Open32 tests lpszDriver for NULL even though it's ignored
89 if(lpszDriver == NULL) {
90 lpszDriver = lpszDevice;
91 }
92
93 if(lpInitData) {
94 dprintfDEVMODE((DEVMODEA *)lpInitData);
95 }
96
97 hdc = O32_CreateDC(lpszDriver, lpszDevice, lpszOutput, lpInitData);
98 if(hdc) {
99 OSLibGpiSetCp(hdc, GetDisplayCodepage());
100 STATS_CreateDCA(hdc, lpszDriver, lpszDevice, lpszOutput, lpInitData);
101 }
102
103 dprintf(("GDI32: CreateDCA %s %s %s %x returned %x", lpszDriver, lpszDevice, lpszOutput, lpInitData, hdc));
104 return hdc;
105}
106//******************************************************************************
107//******************************************************************************
108HDC WIN32API CreateDCW( LPCWSTR arg1, LPCWSTR arg2, LPCWSTR arg3, const DEVMODEW * arg4)
109{
110 char *astring4, *astring5;
111
112 char *astring1 = UnicodeToAsciiString((LPWSTR)arg1);
113 char *astring2 = UnicodeToAsciiString((LPWSTR)arg2);
114 char *astring3 = UnicodeToAsciiString((LPWSTR)arg3);
115
116 if(arg4)
117 {
118 astring4 = UnicodeToAsciiString((LPWSTR)(arg4->dmDeviceName));
119 astring5 = UnicodeToAsciiString((LPWSTR)(arg4->dmFormName));
120 }
121
122 HDC rc;
123 DEVMODEA devmode;
124
125 if(arg4)
126 {
127 strcpy((char*)devmode.dmDeviceName, astring4);
128 strcpy((char*)devmode.dmFormName, astring5);
129
130 devmode.dmSpecVersion = arg4->dmSpecVersion;
131 devmode.dmDriverVersion = arg4->dmDriverVersion;
132 devmode.dmSize = arg4->dmSize;
133 devmode.dmDriverExtra = arg4->dmDriverExtra;
134 devmode.dmFields = arg4->dmFields;
135#if (__IBMCPP__ == 360)
136 devmode.dmOrientation = arg4->dmOrientation;
137 devmode.dmPaperSize = arg4->dmPaperSize;
138 devmode.dmPaperLength = arg4->dmPaperLength;
139 devmode.dmPaperWidth = arg4->dmPaperWidth;
140#else
141 devmode.s1.dmOrientation = arg4->s1.dmOrientation;
142 devmode.s1.dmPaperSize = arg4->s1.dmPaperSize;
143 devmode.s1.dmPaperLength = arg4->s1.dmPaperLength;
144 devmode.s1.dmPaperWidth = arg4->s1.dmPaperWidth;
145#endif
146 devmode.dmScale = arg4->dmScale;
147 devmode.dmCopies = arg4->dmCopies;
148 devmode.dmDefaultSource = arg4->dmDefaultSource;
149 devmode.dmPrintQuality = arg4->dmPrintQuality;
150 devmode.dmColor = arg4->dmColor;
151 devmode.dmDuplex = arg4->dmDuplex;
152 devmode.dmYResolution = arg4->dmYResolution;
153 devmode.dmTTOption = arg4->dmTTOption;
154 devmode.dmCollate = arg4->dmCollate;
155 devmode.dmLogPixels = arg4->dmLogPixels;
156 devmode.dmBitsPerPel = arg4->dmBitsPerPel;
157 devmode.dmPelsWidth = arg4->dmPelsWidth;
158 devmode.dmPelsHeight = arg4->dmPelsHeight;
159 devmode.dmDisplayFlags = arg4->dmDisplayFlags;
160 devmode.dmDisplayFrequency = arg4->dmDisplayFrequency;
161 devmode.dmICMMethod = arg4->dmICMMethod;
162 devmode.dmICMIntent = arg4->dmICMIntent;
163 devmode.dmMediaType = arg4->dmMediaType;
164 devmode.dmDitherType = arg4->dmDitherType;
165 devmode.dmReserved1 = arg4->dmReserved1;
166 devmode.dmReserved2 = arg4->dmReserved2;
167 rc = CreateDCA(astring1,astring2,astring3,&devmode);
168 }
169 else
170 rc = CreateDCA(astring1,astring2,astring3, NULL);
171
172 FreeAsciiString(astring1);
173 FreeAsciiString(astring2);
174 FreeAsciiString(astring3);
175
176 if(arg4)
177 {
178 FreeAsciiString(astring4);
179 FreeAsciiString(astring5);
180 }
181
182 return rc;
183}
184//******************************************************************************
185//******************************************************************************
186HDC WIN32API CreateICA(LPCSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszOutput,
187 const DEVMODEA *lpdvmInit)
188{
189 HDC hdc;
190 char szDevice[256];
191
192 //SvL: Open32 tests for "DISPLAY"
193 if(lpszDriver && !stricmp(lpszDriver, szDisplay)) {
194 lpszDriver = szDisplay;
195 }
196 else
197 { //Check if it's a printer device
198 if(GetPMQueueName((LPSTR)lpszDevice, szDevice, sizeof(szDevice)) == TRUE)
199 {
200 dprintf(("Rename printer %s to PM Queue %s", lpszDevice, szDevice));
201 lpszDevice = szDevice;
202 //Must ignore port name here or else the wrong queue might be used
203 //(unless we are told to print to file)
204 if (lpszOutput && strcmp(lpszOutput, "FILE:") != 0 && strcmp(lpszOutput, "FILE") != 0)
205 lpszOutput = NULL;
206 }
207 }
208
209 //SvL: Open32 tests lpszDriver for NULL even though it's ignored
210 if(lpszDriver == NULL) {
211 lpszDriver = lpszDevice;
212 }
213 hdc = O32_CreateIC(lpszDriver, lpszDevice, lpszOutput, lpdvmInit);
214
215 dprintf(("GDI32: CreateICA %s %s %s %x returned %x", lpszDriver, lpszDevice, lpszOutput, lpdvmInit, hdc));
216
217 if(hdc) STATS_CreateICA(hdc, lpszDriver, lpszDevice, lpszOutput, lpdvmInit);
218 return hdc;
219}
220//******************************************************************************
221//******************************************************************************
222HDC WIN32API CreateICW( LPCWSTR arg1, LPCWSTR arg2, LPCWSTR arg3, const DEVMODEW * arg4)
223{
224 char *astring4, *astring5;
225
226 char *astring1 = UnicodeToAsciiString((LPWSTR)arg1);
227 char *astring2 = UnicodeToAsciiString((LPWSTR)arg2);
228 char *astring3 = UnicodeToAsciiString((LPWSTR)arg3);
229 if(arg4)
230 {
231 astring4 = UnicodeToAsciiString((LPWSTR)(arg4->dmDeviceName));
232 astring5 = UnicodeToAsciiString((LPWSTR)(arg4->dmFormName));
233 }
234
235 HDC rc;
236 DEVMODEA devmode;
237
238 if(arg4)
239 {
240 strcpy((char*)devmode.dmDeviceName, astring4);
241 strcpy((char*)devmode.dmFormName, astring5);
242
243 devmode.dmSpecVersion = arg4->dmSpecVersion;
244 devmode.dmDriverVersion = arg4->dmDriverVersion;
245 devmode.dmSize = arg4->dmSize;
246 devmode.dmDriverExtra = arg4->dmDriverExtra;
247 devmode.dmFields = arg4->dmFields;
248#if (__IBMCPP__ == 360)
249 devmode.dmOrientation = arg4->dmOrientation;
250 devmode.dmPaperSize = arg4->dmPaperSize;
251 devmode.dmPaperLength = arg4->dmPaperLength;
252 devmode.dmPaperWidth = arg4->dmPaperWidth;
253#else
254 devmode.s1.dmOrientation = arg4->s1.dmOrientation;
255 devmode.s1.dmPaperSize = arg4->s1.dmPaperSize;
256 devmode.s1.dmPaperLength = arg4->s1.dmPaperLength;
257 devmode.s1.dmPaperWidth = arg4->s1.dmPaperWidth;
258#endif
259 devmode.dmScale = arg4->dmScale;
260 devmode.dmCopies = arg4->dmCopies;
261 devmode.dmDefaultSource = arg4->dmDefaultSource;
262 devmode.dmPrintQuality = arg4->dmPrintQuality;
263 devmode.dmColor = arg4->dmColor;
264 devmode.dmDuplex = arg4->dmDuplex;
265 devmode.dmYResolution = arg4->dmYResolution;
266 devmode.dmTTOption = arg4->dmTTOption;
267 devmode.dmCollate = arg4->dmCollate;
268 devmode.dmLogPixels = arg4->dmLogPixels;
269 devmode.dmBitsPerPel = arg4->dmBitsPerPel;
270 devmode.dmPelsWidth = arg4->dmPelsWidth;
271 devmode.dmPelsHeight = arg4->dmPelsHeight;
272 devmode.dmDisplayFlags = arg4->dmDisplayFlags;
273 devmode.dmDisplayFrequency = arg4->dmDisplayFrequency;
274 devmode.dmICMMethod = arg4->dmICMMethod;
275 devmode.dmICMIntent = arg4->dmICMIntent;
276 devmode.dmMediaType = arg4->dmMediaType;
277 devmode.dmDitherType = arg4->dmDitherType;
278 devmode.dmReserved1 = arg4->dmReserved1;
279 devmode.dmReserved2 = arg4->dmReserved2;
280
281 rc = CreateICA(astring1,astring2,astring3,&devmode);
282 }
283 else
284 rc = CreateICA(astring1,astring2,astring3, NULL);
285
286 FreeAsciiString(astring1);
287 FreeAsciiString(astring2);
288 FreeAsciiString(astring3);
289 if(arg4)
290 {
291 FreeAsciiString(astring4);
292 FreeAsciiString(astring5);
293 }
294
295 return rc;
296}
297//******************************************************************************
298//******************************************************************************
299HDC WIN32API CreateCompatibleDC( HDC hdc)
300{
301 HDC newHdc;
302
303 newHdc = O32_CreateCompatibleDC(hdc);
304 ULONG oldcp = OSLibGpiQueryCp(hdc);
305 if (!oldcp) /* If new DC is to be created */
306 oldcp = GetDisplayCodepage();
307
308 if(newHdc) STATS_CreateCompatibleDC(hdc, newHdc);
309 OSLibGpiSetCp(newHdc, oldcp);
310 //PF Open32 seems not to move coordinates to 0,0 in newHdc
311 MoveToEx(newHdc, 0, 0 , NULL);
312
313 return newHdc;
314}
315//******************************************************************************
316//******************************************************************************
317BOOL WIN32API DeleteDC(HDC hdc)
318{
319 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
320 if(!pHps)
321 {
322 dprintf(("WARNING: DeleteDC %x; invalid hdc!", hdc));
323 SetLastError(ERROR_INVALID_HANDLE);
324 return 0;
325 }
326 SetLastError(ERROR_SUCCESS);
327
328 DIBSection *dsect = DIBSection::findHDC(hdc);
329 if(dsect)
330 {
331 //remove previously selected dibsection
332 dprintf(("DeleteDC %x, unselect DIB section %x", hdc, dsect->GetBitmapHandle()));
333 dsect->UnSelectDIBObject();
334 }
335
336 //Must call ReleaseDC for window dcs
337 if(pHps->hdcType == TYPE_1) {
338 return ReleaseDC(OS2ToWin32Handle(pHps->hwnd), hdc);
339 }
340
341 STATS_DeleteDC(hdc);
342 return O32_DeleteDC(hdc);
343}
344//******************************************************************************
345//******************************************************************************
346int WIN32API SaveDC( HDC hdc)
347{
348 int id;
349 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
350 if(!pHps)
351 {
352 dprintf(("WARNING: SaveDC %x; invalid hdc!", hdc));
353 SetLastError(ERROR_INVALID_HANDLE);
354 return 0;
355 }
356
357 HRGN hClipRgn = 0;
358 if(pHps->hrgnWin32Clip) {
359 // Make a copy of our current clip region
360 // (the visible region remains untouched!)
361 hClipRgn = GdiCopyClipRgn(pHps);
362 }
363
364 id = O32_SaveDC(hdc);
365 if(id == 0) {
366 dprintf(("ERROR: GDI32: SaveDC %x FAILED", hdc));
367 if(hClipRgn) GdiDestroyRgn(pHps, hClipRgn);
368 return 0;
369 }
370 //overwrite the current clip region with the copy
371 dprintf2(("New win32 clip region %x", hClipRgn));
372 pHps->hrgnWin32Clip = hClipRgn;
373 return id;
374}
375//******************************************************************************
376//******************************************************************************
377BOOL WIN32API RestoreDC(HDC hdc, int id)
378{
379 BOOL ret;
380 HRGN hrgnOldClip = 0;
381
382 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
383 if(!pHps)
384 {
385 dprintf(("WARNING: RestoreDC %x; invalid hdc!", hdc));
386 SetLastError(ERROR_INVALID_HANDLE);
387 return 0;
388 }
389
390 hrgnOldClip = pHps->hrgnWin32Clip;
391 ret = O32_RestoreDC(hdc, id);
392 if(ret == FALSE) {
393 dprintf(("ERROR: GDI32: RestoreDC %x %d FAILED", hdc, id));
394 }
395 else {
396 //Destroy copy of the clip region that we made in SaveDC
397 if(hrgnOldClip) GdiDestroyRgn(pHps, hrgnOldClip);
398
399 // Activate previous clip region
400 GdiCombineVisRgnClipRgn(pHps, pHps->hrgnWin32Clip, RGN_AND);
401
402 dprintf2(("New win32 clip region %x", pHps->hrgnWin32Clip));
403 }
404 return ret;
405}
406//******************************************************************************
407//******************************************************************************
408HDC WIN32API ResetDCA(HDC hdc, const DEVMODEA *lpInitData)
409{
410 if(lpInitData)
411 {
412 dprintfDEVMODE((DEVMODEA *)lpInitData);
413 }
414 HDC ret =O32_ResetDC(hdc, lpInitData);
415 return ret;
416}
417//******************************************************************************
418//******************************************************************************
419HDC WIN32API ResetDCW( HDC arg1, const DEVMODEW * arg2)
420{
421 dprintf(("GDI32: ResetDCW: not properly implemented"));
422 DebugInt3();
423 // NOTE: This will not work as is (needs UNICODE support)
424 return (HDC)O32_ResetDC(arg1, (const DEVMODEA *)arg2);
425}
426//******************************************************************************
427//******************************************************************************
428#ifdef DEBUG
429void dprintfDEVMODE(DEVMODEA *lpInitData)
430{
431 dprintf(("devmode.dmSpecVersion %x", lpInitData->dmSpecVersion));
432 dprintf(("devmode.dmDriverVersion %x",lpInitData->dmDriverVersion));
433 dprintf(("devmode.dmSize %x", lpInitData->dmSize));
434 dprintf(("devmode.dmDriverExtra %x", lpInitData->dmDriverExtra));
435 dprintf(("devmode.dmFields %x", lpInitData->dmFields));
436#if (__IBMCPP__ == 360)
437 dprintf(("devmode.dmOrientation %x", lpInitData->dmOrientation));
438 dprintf(("devmode.dmPaperSize %x", lpInitData->dmPaperSize));
439 dprintf(("devmode.dmPaperLength %x", lpInitData->dmPaperLength));
440 dprintf(("devmode.dmPaperWidth %x", lpInitData->dmPaperWidth));
441#else
442 dprintf(("devmode.dmOrientation %x", lpInitData->s1.dmOrientation));
443 dprintf(("devmode.dmPaperSize %x", lpInitData->s1.dmPaperSize));
444 dprintf(("devmode.dmPaperLength %x", lpInitData->s1.dmPaperLength));
445 dprintf(("devmode.dmPaperWidth %x", lpInitData->s1.dmPaperWidth));
446#endif
447 dprintf(("devmode.dmScale %x", lpInitData->dmScale));
448 dprintf(("devmode.dmCopies %x", lpInitData->dmCopies));
449 dprintf(("devmode.dmDefaultSource %x", lpInitData->dmDefaultSource));
450 dprintf(("devmode.dmPrintQuality %x", lpInitData->dmPrintQuality));
451 dprintf(("devmode.dmColor %x", lpInitData->dmColor));
452 dprintf(("devmode.dmDuplex %x", lpInitData->dmDuplex));
453 dprintf(("devmode.dmYResolution %x", lpInitData->dmYResolution));
454 dprintf(("devmode.dmTTOption %x", lpInitData->dmTTOption));
455 dprintf(("devmode.dmCollate %x", lpInitData->dmCollate));
456 dprintf(("devmode.dmLogPixels %x", lpInitData->dmLogPixels));
457 dprintf(("devmode.dmBitsPerPel %x", lpInitData->dmBitsPerPel));
458 dprintf(("devmode.dmPelsWidth %x", lpInitData->dmPelsWidth));
459 dprintf(("devmode.dmPelsHeight %x", lpInitData->dmPelsHeight));
460 dprintf(("devmode.dmDisplayFlags %x", lpInitData->dmDisplayFlags));
461 dprintf(("devmode.dmDisplayFrequency %x", lpInitData->dmDisplayFrequency));
462 dprintf(("devmode.dmICMMethod %x", lpInitData->dmICMMethod));
463 dprintf(("devmode.dmICMIntent %x", lpInitData->dmICMIntent));
464 dprintf(("devmode.dmMediaType %x", lpInitData->dmMediaType));
465 dprintf(("devmode.dmDitherType %x", lpInitData->dmDitherType));
466 dprintf(("devmode.dmReserved1 %x", lpInitData->dmReserved1));
467 dprintf(("devmode.dmReserved2 %x", lpInitData->dmReserved2));
468}
469#endif
470//******************************************************************************
471//******************************************************************************
Note: See TracBrowser for help on using the repository browser.