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

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

Wrong GdiCopyClipRgn return value; Implemented SelectClipPath

File size: 17.0 KB
Line 
1/* $Id: devcontext.cpp,v 1.2 2004-02-10 15:35:38 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 //Must ignore port name here or else the wrong queue might be used
81 lpszOutput = NULL;
82 }
83 }
84
85 //SvL: Open32 tests lpszDriver for NULL even though it's ignored
86 if(lpszDriver == NULL) {
87 lpszDriver = lpszDevice;
88 }
89
90 if(lpInitData) {
91 dprintfDEVMODE((DEVMODEA *)lpInitData);
92 }
93
94 hdc = O32_CreateDC(lpszDriver, lpszDevice, lpszOutput, lpInitData);
95 if(hdc) {
96 OSLibGpiSetCp(hdc, GetDisplayCodepage());
97 STATS_CreateDCA(hdc, lpszDriver, lpszDevice, lpszOutput, lpInitData);
98 }
99
100 dprintf(("GDI32: CreateDCA %s %s %s %x returned %x", lpszDriver, lpszDevice, lpszOutput, lpInitData, hdc));
101 return hdc;
102}
103//******************************************************************************
104//******************************************************************************
105HDC WIN32API CreateDCW( LPCWSTR arg1, LPCWSTR arg2, LPCWSTR arg3, const DEVMODEW * arg4)
106{
107 char *astring4, *astring5;
108
109 char *astring1 = UnicodeToAsciiString((LPWSTR)arg1);
110 char *astring2 = UnicodeToAsciiString((LPWSTR)arg2);
111 char *astring3 = UnicodeToAsciiString((LPWSTR)arg3);
112
113 if(arg4)
114 {
115 astring4 = UnicodeToAsciiString((LPWSTR)(arg4->dmDeviceName));
116 astring5 = UnicodeToAsciiString((LPWSTR)(arg4->dmFormName));
117 }
118
119 HDC rc;
120 DEVMODEA devmode;
121
122 if(arg4)
123 {
124 strcpy((char*)devmode.dmDeviceName, astring4);
125 strcpy((char*)devmode.dmFormName, astring5);
126
127 devmode.dmSpecVersion = arg4->dmSpecVersion;
128 devmode.dmDriverVersion = arg4->dmDriverVersion;
129 devmode.dmSize = arg4->dmSize;
130 devmode.dmDriverExtra = arg4->dmDriverExtra;
131 devmode.dmFields = arg4->dmFields;
132#if (__IBMCPP__ == 360)
133 devmode.dmOrientation = arg4->dmOrientation;
134 devmode.dmPaperSize = arg4->dmPaperSize;
135 devmode.dmPaperLength = arg4->dmPaperLength;
136 devmode.dmPaperWidth = arg4->dmPaperWidth;
137#else
138 devmode.s1.dmOrientation = arg4->s1.dmOrientation;
139 devmode.s1.dmPaperSize = arg4->s1.dmPaperSize;
140 devmode.s1.dmPaperLength = arg4->s1.dmPaperLength;
141 devmode.s1.dmPaperWidth = arg4->s1.dmPaperWidth;
142#endif
143 devmode.dmScale = arg4->dmScale;
144 devmode.dmCopies = arg4->dmCopies;
145 devmode.dmDefaultSource = arg4->dmDefaultSource;
146 devmode.dmPrintQuality = arg4->dmPrintQuality;
147 devmode.dmColor = arg4->dmColor;
148 devmode.dmDuplex = arg4->dmDuplex;
149 devmode.dmYResolution = arg4->dmYResolution;
150 devmode.dmTTOption = arg4->dmTTOption;
151 devmode.dmCollate = arg4->dmCollate;
152 devmode.dmLogPixels = arg4->dmLogPixels;
153 devmode.dmBitsPerPel = arg4->dmBitsPerPel;
154 devmode.dmPelsWidth = arg4->dmPelsWidth;
155 devmode.dmPelsHeight = arg4->dmPelsHeight;
156 devmode.dmDisplayFlags = arg4->dmDisplayFlags;
157 devmode.dmDisplayFrequency = arg4->dmDisplayFrequency;
158 devmode.dmICMMethod = arg4->dmICMMethod;
159 devmode.dmICMIntent = arg4->dmICMIntent;
160 devmode.dmMediaType = arg4->dmMediaType;
161 devmode.dmDitherType = arg4->dmDitherType;
162 devmode.dmReserved1 = arg4->dmReserved1;
163 devmode.dmReserved2 = arg4->dmReserved2;
164 rc = CreateDCA(astring1,astring2,astring3,&devmode);
165 }
166 else
167 rc = CreateDCA(astring1,astring2,astring3, NULL);
168
169 FreeAsciiString(astring1);
170 FreeAsciiString(astring2);
171 FreeAsciiString(astring3);
172
173 if(arg4)
174 {
175 FreeAsciiString(astring4);
176 FreeAsciiString(astring5);
177 }
178
179 return rc;
180}
181//******************************************************************************
182//******************************************************************************
183HDC WIN32API CreateICA(LPCSTR lpszDriver, LPCSTR lpszDevice, LPCSTR lpszOutput,
184 const DEVMODEA *lpdvmInit)
185{
186 HDC hdc;
187 char szDevice[256];
188
189 //SvL: Open32 tests for "DISPLAY"
190 if(lpszDriver && !stricmp(lpszDriver, szDisplay)) {
191 lpszDriver = szDisplay;
192 }
193 else
194 { //Check if it's a printer device
195 if(GetPMQueueName((LPSTR)lpszDevice, szDevice, sizeof(szDevice)) == TRUE)
196 {
197 dprintf(("Rename printer %s to PM Queue %s", lpszDevice, szDevice));
198 lpszDevice = szDevice;
199 //Must ignore port name here or else the wrong queue might be used
200 lpszOutput = NULL;
201 }
202 }
203
204 //SvL: Open32 tests lpszDriver for NULL even though it's ignored
205 if(lpszDriver == NULL) {
206 lpszDriver = lpszDevice;
207 }
208 hdc = O32_CreateIC(lpszDriver, lpszDevice, lpszOutput, lpdvmInit);
209
210 dprintf(("GDI32: CreateICA %s %s %s %x returned %x", lpszDriver, lpszDevice, lpszOutput, lpdvmInit, hdc));
211
212 if(hdc) STATS_CreateICA(hdc, lpszDriver, lpszDevice, lpszOutput, lpdvmInit);
213 return hdc;
214}
215//******************************************************************************
216//******************************************************************************
217HDC WIN32API CreateICW( LPCWSTR arg1, LPCWSTR arg2, LPCWSTR arg3, const DEVMODEW * arg4)
218{
219 char *astring4, *astring5;
220
221 char *astring1 = UnicodeToAsciiString((LPWSTR)arg1);
222 char *astring2 = UnicodeToAsciiString((LPWSTR)arg2);
223 char *astring3 = UnicodeToAsciiString((LPWSTR)arg3);
224 if(arg4)
225 {
226 astring4 = UnicodeToAsciiString((LPWSTR)(arg4->dmDeviceName));
227 astring5 = UnicodeToAsciiString((LPWSTR)(arg4->dmFormName));
228 }
229
230 HDC rc;
231 DEVMODEA devmode;
232
233 if(arg4)
234 {
235 strcpy((char*)devmode.dmDeviceName, astring4);
236 strcpy((char*)devmode.dmFormName, astring5);
237
238 devmode.dmSpecVersion = arg4->dmSpecVersion;
239 devmode.dmDriverVersion = arg4->dmDriverVersion;
240 devmode.dmSize = arg4->dmSize;
241 devmode.dmDriverExtra = arg4->dmDriverExtra;
242 devmode.dmFields = arg4->dmFields;
243#if (__IBMCPP__ == 360)
244 devmode.dmOrientation = arg4->dmOrientation;
245 devmode.dmPaperSize = arg4->dmPaperSize;
246 devmode.dmPaperLength = arg4->dmPaperLength;
247 devmode.dmPaperWidth = arg4->dmPaperWidth;
248#else
249 devmode.s1.dmOrientation = arg4->s1.dmOrientation;
250 devmode.s1.dmPaperSize = arg4->s1.dmPaperSize;
251 devmode.s1.dmPaperLength = arg4->s1.dmPaperLength;
252 devmode.s1.dmPaperWidth = arg4->s1.dmPaperWidth;
253#endif
254 devmode.dmScale = arg4->dmScale;
255 devmode.dmCopies = arg4->dmCopies;
256 devmode.dmDefaultSource = arg4->dmDefaultSource;
257 devmode.dmPrintQuality = arg4->dmPrintQuality;
258 devmode.dmColor = arg4->dmColor;
259 devmode.dmDuplex = arg4->dmDuplex;
260 devmode.dmYResolution = arg4->dmYResolution;
261 devmode.dmTTOption = arg4->dmTTOption;
262 devmode.dmCollate = arg4->dmCollate;
263 devmode.dmLogPixels = arg4->dmLogPixels;
264 devmode.dmBitsPerPel = arg4->dmBitsPerPel;
265 devmode.dmPelsWidth = arg4->dmPelsWidth;
266 devmode.dmPelsHeight = arg4->dmPelsHeight;
267 devmode.dmDisplayFlags = arg4->dmDisplayFlags;
268 devmode.dmDisplayFrequency = arg4->dmDisplayFrequency;
269 devmode.dmICMMethod = arg4->dmICMMethod;
270 devmode.dmICMIntent = arg4->dmICMIntent;
271 devmode.dmMediaType = arg4->dmMediaType;
272 devmode.dmDitherType = arg4->dmDitherType;
273 devmode.dmReserved1 = arg4->dmReserved1;
274 devmode.dmReserved2 = arg4->dmReserved2;
275
276 rc = CreateICA(astring1,astring2,astring3,&devmode);
277 }
278 else
279 rc = CreateICA(astring1,astring2,astring3, NULL);
280
281 FreeAsciiString(astring1);
282 FreeAsciiString(astring2);
283 FreeAsciiString(astring3);
284 if(arg4)
285 {
286 FreeAsciiString(astring4);
287 FreeAsciiString(astring5);
288 }
289
290 return rc;
291}
292//******************************************************************************
293//******************************************************************************
294HDC WIN32API CreateCompatibleDC( HDC hdc)
295{
296 HDC newHdc;
297
298 newHdc = O32_CreateCompatibleDC(hdc);
299 ULONG oldcp = OSLibGpiQueryCp(hdc);
300 if (!oldcp) /* If new DC is to be created */
301 oldcp = GetDisplayCodepage();
302
303 if(newHdc) STATS_CreateCompatibleDC(hdc, newHdc);
304 OSLibGpiSetCp(newHdc, oldcp);
305 //PF Open32 seems not to move coordinates to 0,0 in newHdc
306 MoveToEx(newHdc, 0, 0 , NULL);
307
308 return newHdc;
309}
310//******************************************************************************
311//******************************************************************************
312BOOL WIN32API DeleteDC(HDC hdc)
313{
314 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
315 if(!pHps)
316 {
317 dprintf(("WARNING: DeleteDC %x; invalid hdc!", hdc));
318 SetLastError(ERROR_INVALID_HANDLE);
319 return 0;
320 }
321 SetLastError(ERROR_SUCCESS);
322
323 DIBSection *dsect = DIBSection::findHDC(hdc);
324 if(dsect)
325 {
326 //remove previously selected dibsection
327 dprintf(("DeleteDC %x, unselect DIB section %x", hdc, dsect->GetBitmapHandle()));
328 dsect->UnSelectDIBObject();
329 }
330
331 //Must call ReleaseDC for window dcs
332 if(pHps->hdcType == TYPE_1) {
333 return ReleaseDC(OS2ToWin32Handle(pHps->hwnd), hdc);
334 }
335
336 STATS_DeleteDC(hdc);
337 return O32_DeleteDC(hdc);
338}
339//******************************************************************************
340//******************************************************************************
341int WIN32API SaveDC( HDC hdc)
342{
343 int id;
344 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
345 if(!pHps)
346 {
347 dprintf(("WARNING: SaveDC %x; invalid hdc!", hdc));
348 SetLastError(ERROR_INVALID_HANDLE);
349 return 0;
350 }
351
352 HRGN hClipRgn = 0;
353 if(pHps->hrgnWin32Clip) {
354 // Make a copy of our current clip region
355 // (the visible region remains untouched!)
356 hClipRgn = GdiCopyClipRgn(pHps);
357 }
358
359 id = O32_SaveDC(hdc);
360 if(id == 0) {
361 dprintf(("ERROR: GDI32: SaveDC %x FAILED", hdc));
362 if(hClipRgn) GdiDestroyRgn(pHps, hClipRgn);
363 return 0;
364 }
365 //overwrite the current clip region with the copy
366 dprintf2(("New win32 clip region %x", hClipRgn));
367 pHps->hrgnWin32Clip = hClipRgn;
368 return id;
369}
370//******************************************************************************
371//******************************************************************************
372BOOL WIN32API RestoreDC(HDC hdc, int id)
373{
374 BOOL ret;
375 HRGN hrgnOldClip = 0;
376
377 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
378 if(!pHps)
379 {
380 dprintf(("WARNING: RestoreDC %x; invalid hdc!", hdc));
381 SetLastError(ERROR_INVALID_HANDLE);
382 return 0;
383 }
384
385 hrgnOldClip = pHps->hrgnWin32Clip;
386 ret = O32_RestoreDC(hdc, id);
387 if(ret == FALSE) {
388 dprintf(("ERROR: GDI32: RestoreDC %x %d FAILED", hdc, id));
389 }
390 else {
391 //Destroy copy of the clip region that we made in SaveDC
392 if(hrgnOldClip) GdiDestroyRgn(pHps, hrgnOldClip);
393
394 // Activate previous clip region
395 GdiCombineVisRgnClipRgn(pHps, pHps->hrgnWin32Clip, RGN_AND);
396
397 dprintf2(("New win32 clip region %x", pHps->hrgnWin32Clip));
398 }
399 return ret;
400}
401//******************************************************************************
402//******************************************************************************
403HDC WIN32API ResetDCA(HDC hdc, const DEVMODEA *lpInitData)
404{
405 if(lpInitData)
406 {
407 dprintfDEVMODE((DEVMODEA *)lpInitData);
408 }
409 HDC ret =O32_ResetDC(hdc, lpInitData);
410 return ret;
411}
412//******************************************************************************
413//******************************************************************************
414HDC WIN32API ResetDCW( HDC arg1, const DEVMODEW * arg2)
415{
416 dprintf(("GDI32: ResetDCW: not properly implemented"));
417 DebugInt3();
418 // NOTE: This will not work as is (needs UNICODE support)
419 return (HDC)O32_ResetDC(arg1, (const DEVMODEA *)arg2);
420}
421//******************************************************************************
422//******************************************************************************
423#ifdef DEBUG
424void dprintfDEVMODE(DEVMODEA *lpInitData)
425{
426 dprintf(("devmode.dmSpecVersion %x", lpInitData->dmSpecVersion));
427 dprintf(("devmode.dmDriverVersion %x",lpInitData->dmDriverVersion));
428 dprintf(("devmode.dmSize %x", lpInitData->dmSize));
429 dprintf(("devmode.dmDriverExtra %x", lpInitData->dmDriverExtra));
430 dprintf(("devmode.dmFields %x", lpInitData->dmFields));
431#if (__IBMCPP__ == 360)
432 dprintf(("devmode.dmOrientation %x", lpInitData->dmOrientation));
433 dprintf(("devmode.dmPaperSize %x", lpInitData->dmPaperSize));
434 dprintf(("devmode.dmPaperLength %x", lpInitData->dmPaperLength));
435 dprintf(("devmode.dmPaperWidth %x", lpInitData->dmPaperWidth));
436#else
437 dprintf(("devmode.dmOrientation %x", lpInitData->s1.dmOrientation));
438 dprintf(("devmode.dmPaperSize %x", lpInitData->s1.dmPaperSize));
439 dprintf(("devmode.dmPaperLength %x", lpInitData->s1.dmPaperLength));
440 dprintf(("devmode.dmPaperWidth %x", lpInitData->s1.dmPaperWidth));
441#endif
442 dprintf(("devmode.dmScale %x", lpInitData->dmScale));
443 dprintf(("devmode.dmCopies %x", lpInitData->dmCopies));
444 dprintf(("devmode.dmDefaultSource %x", lpInitData->dmDefaultSource));
445 dprintf(("devmode.dmPrintQuality %x", lpInitData->dmPrintQuality));
446 dprintf(("devmode.dmColor %x", lpInitData->dmColor));
447 dprintf(("devmode.dmDuplex %x", lpInitData->dmDuplex));
448 dprintf(("devmode.dmYResolution %x", lpInitData->dmYResolution));
449 dprintf(("devmode.dmTTOption %x", lpInitData->dmTTOption));
450 dprintf(("devmode.dmCollate %x", lpInitData->dmCollate));
451 dprintf(("devmode.dmLogPixels %x", lpInitData->dmLogPixels));
452 dprintf(("devmode.dmBitsPerPel %x", lpInitData->dmBitsPerPel));
453 dprintf(("devmode.dmPelsWidth %x", lpInitData->dmPelsWidth));
454 dprintf(("devmode.dmPelsHeight %x", lpInitData->dmPelsHeight));
455 dprintf(("devmode.dmDisplayFlags %x", lpInitData->dmDisplayFlags));
456 dprintf(("devmode.dmDisplayFrequency %x", lpInitData->dmDisplayFrequency));
457 dprintf(("devmode.dmICMMethod %x", lpInitData->dmICMMethod));
458 dprintf(("devmode.dmICMIntent %x", lpInitData->dmICMIntent));
459 dprintf(("devmode.dmMediaType %x", lpInitData->dmMediaType));
460 dprintf(("devmode.dmDitherType %x", lpInitData->dmDitherType));
461 dprintf(("devmode.dmReserved1 %x", lpInitData->dmReserved1));
462 dprintf(("devmode.dmReserved2 %x", lpInitData->dmReserved2));
463}
464#endif
465//******************************************************************************
466//******************************************************************************
Note: See TracBrowser for help on using the repository browser.