blob: 9a5fd3d184b07e4c41f4a89ecc4a3bacc984055f [file] [log] [blame]
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001/*
2 * Implementation of some printer driver bits
3 *
4 * Copyright 1996 John Harvey
Huw D M Daviese39b6761999-05-17 16:20:51 +00005 * Copyright 1998 Huw Davies
Alexandre Julliard642d3131998-07-12 19:29:36 +00006 * Copyright 1998 Andreas Mohr
Klaas van Gend7f73a081999-03-28 12:37:34 +00007 * Copyright 1999 Klaas van Gend
Alexandre Julliard0e270f41996-08-24 18:26:35 +00008 */
9
10#include <stdlib.h>
Alexandre Julliard0e270f41996-08-24 18:26:35 +000011#include <string.h>
12#include <ctype.h>
Huw D M Daviese39b6761999-05-17 16:20:51 +000013#include <errno.h>
14#include <unistd.h>
15#include <fcntl.h>
16#include "ldt.h"
Huw D M Daviesa9f55c41999-05-08 12:45:18 +000017#include "winbase.h"
Alexandre Julliard83f52d12000-09-26 22:20:14 +000018#include "wine/winbase16.h"
Huw D M Daviesa9f55c41999-05-08 12:45:18 +000019#include "wine/wingdi16.h"
Huw D M Daviese39b6761999-05-17 16:20:51 +000020#include "winspool.h"
Alexandre Julliard0e270f41996-08-24 18:26:35 +000021#include "winerror.h"
Alexandre Julliardf90efa91998-06-14 15:24:15 +000022#include "winreg.h"
Alexandre Julliard06c275a1999-05-02 14:32:27 +000023#include "debugtools.h"
Huw D M Daviese39b6761999-05-17 16:20:51 +000024#include "gdi.h"
25#include "dc.h"
26#include "callback.h"
Huw D M Daviese39b6761999-05-17 16:20:51 +000027#include "options.h"
Huw D M Davies81561501999-07-25 11:25:59 +000028#include "heap.h"
Frederic Boulangerf93dcc22000-06-15 00:29:54 +000029#include "file.h"
Alexandre Julliardf90efa91998-06-14 15:24:15 +000030
Huw D M Daviese39b6761999-05-17 16:20:51 +000031DEFAULT_DEBUG_CHANNEL(print)
Klaas van Gend7f73a081999-03-28 12:37:34 +000032
Alexandre Julliardf90efa91998-06-14 15:24:15 +000033static char PrinterModel[] = "Printer Model";
34static char DefaultDevMode[] = "Default DevMode";
35static char PrinterDriverData[] = "PrinterDriverData";
36static char Printers[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\";
37
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +000038/******************************************************************
39 * StartDoc16 [GDI.377]
40 *
41 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000042INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
Alexandre Julliard889f7421997-04-15 17:19:52 +000043{
Huw D M Davies81561501999-07-25 11:25:59 +000044 DOCINFOA docA;
45
46 docA.cbSize = lpdoc->cbSize;
47 docA.lpszDocName = PTR_SEG_TO_LIN(lpdoc->lpszDocName);
48 docA.lpszOutput = PTR_SEG_TO_LIN(lpdoc->lpszOutput);
Huw D M Daviesc0da44e41999-10-31 01:49:30 +000049
50 if(lpdoc->cbSize >= 14)
51 docA.lpszDatatype = PTR_SEG_TO_LIN(lpdoc->lpszDatatype);
52 else
53 docA.lpszDatatype = NULL;
54
55 if(lpdoc->cbSize >= 18)
56 docA.fwType = lpdoc->fwType;
57 else
58 docA.fwType = 0;
Huw D M Davies81561501999-07-25 11:25:59 +000059
60 return StartDocA(hdc, &docA);
Alexandre Julliard889f7421997-04-15 17:19:52 +000061}
62
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +000063/******************************************************************
Huw D M Davies81561501999-07-25 11:25:59 +000064 * StartDocA [GDI32.347]
Nick Holloway36a806c1999-01-24 18:59:58 +000065 *
Huw D M Daviesc0da44e41999-10-31 01:49:30 +000066 * StartDoc calls the STARTDOC Escape with the input data pointing to DocName
67 * and the output data (which is used as a second input parameter).pointing at
68 * the whole docinfo structure. This seems to be an undocumented feature of
69 * the STARTDOC Escape.
Nick Holloway36a806c1999-01-24 18:59:58 +000070 */
Huw D M Davies81561501999-07-25 11:25:59 +000071INT WINAPI StartDocA(HDC hdc, const DOCINFOA* doc)
Nick Holloway36a806c1999-01-24 18:59:58 +000072{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000073 INT ret;
Huw D M Davies81561501999-07-25 11:25:59 +000074 DC *dc = DC_GetDCPtr( hdc );
Nick Holloway36a806c1999-01-24 18:59:58 +000075
Huw D M Daviesd016b0a1999-07-24 12:09:34 +000076 TRACE("DocName = '%s' Output = '%s' Datatype = '%s'\n",
77 doc->lpszDocName, doc->lpszOutput, doc->lpszDatatype);
Huw D M Davies81561501999-07-25 11:25:59 +000078
Patrik Stridvallcbab7702000-05-18 00:52:08 +000079 if(!dc) return SP_ERROR;
Huw D M Davies81561501999-07-25 11:25:59 +000080
81 if(dc->funcs->pStartDoc)
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000082 ret = dc->funcs->pStartDoc( dc, doc );
Huw D M Davies81561501999-07-25 11:25:59 +000083 else
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000084 ret = Escape(hdc, STARTDOC, strlen(doc->lpszDocName),
Huw D M Daviesc0da44e41999-10-31 01:49:30 +000085 doc->lpszDocName, (LPVOID)doc);
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000086 GDI_ReleaseObj( hdc );
87 return ret;
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +000088}
89
Huw D M Davies5a502731998-12-11 10:17:31 +000090/*************************************************************************
Huw D M Davies81561501999-07-25 11:25:59 +000091 * StartDocW [GDI32.348]
Huw D M Davies5a502731998-12-11 10:17:31 +000092 *
93 */
Huw D M Davies81561501999-07-25 11:25:59 +000094INT WINAPI StartDocW(HDC hdc, const DOCINFOW* doc)
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +000095{
Huw D M Davies81561501999-07-25 11:25:59 +000096 DOCINFOA docA;
97 INT ret;
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +000098
Huw D M Davies81561501999-07-25 11:25:59 +000099 docA.cbSize = doc->cbSize;
100 docA.lpszDocName = doc->lpszDocName ?
101 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDocName ) : NULL;
102 docA.lpszOutput = doc->lpszOutput ?
103 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszOutput ) : NULL;
104 docA.lpszDatatype = doc->lpszDatatype ?
105 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDatatype ) : NULL;
106 docA.fwType = doc->fwType;
107
108 ret = StartDocA(hdc, &docA);
109
110 if(docA.lpszDocName)
111 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDocName );
112 if(docA.lpszOutput)
113 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszOutput );
114 if(docA.lpszDatatype)
115 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDatatype );
116
117 return ret;
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +0000118}
119
120/******************************************************************
121 * EndDoc16 [GDI.378]
122 *
123 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000124INT16 WINAPI EndDoc16(HDC16 hdc)
Alexandre Julliard889f7421997-04-15 17:19:52 +0000125{
Huw D M Davies81561501999-07-25 11:25:59 +0000126 return EndDoc(hdc);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000127}
128
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +0000129/******************************************************************
Huw D M Davies81561501999-07-25 11:25:59 +0000130 * EndDoc [GDI32.76]
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +0000131 *
132 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000133INT WINAPI EndDoc(HDC hdc)
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +0000134{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000135 INT ret;
Huw D M Davies81561501999-07-25 11:25:59 +0000136 DC *dc = DC_GetDCPtr( hdc );
Patrik Stridvallcbab7702000-05-18 00:52:08 +0000137 if(!dc) return SP_ERROR;
Huw D M Davies81561501999-07-25 11:25:59 +0000138
139 if(dc->funcs->pEndDoc)
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000140 ret = dc->funcs->pEndDoc( dc );
Huw D M Davies81561501999-07-25 11:25:59 +0000141 else
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000142 ret = Escape(hdc, ENDDOC, 0, 0, 0);
143 GDI_ReleaseObj( hdc );
144 return ret;
Huw D M Davies81561501999-07-25 11:25:59 +0000145}
146
147/******************************************************************
148 * StartPage16 [GDI.379]
149 *
150 */
151INT16 WINAPI StartPage16(HDC16 hdc)
152{
153 return StartPage(hdc);
154}
155
156/******************************************************************
157 * StartPage [GDI32.349]
158 *
159 */
160INT WINAPI StartPage(HDC hdc)
161{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000162 INT ret = 1;
Huw D M Davies81561501999-07-25 11:25:59 +0000163 DC *dc = DC_GetDCPtr( hdc );
Patrik Stridvallcbab7702000-05-18 00:52:08 +0000164 if(!dc) return SP_ERROR;
Huw D M Davies81561501999-07-25 11:25:59 +0000165
166 if(dc->funcs->pStartPage)
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000167 ret = dc->funcs->pStartPage( dc );
168 else
169 FIXME("stub\n");
170 GDI_ReleaseObj( hdc );
171 return ret;
Huw D M Davies81561501999-07-25 11:25:59 +0000172}
173
174/******************************************************************
175 * EndPage16 [GDI.380]
176 *
177 */
178INT16 WINAPI EndPage16( HDC16 hdc )
179{
180 return EndPage(hdc);
181}
182
183/******************************************************************
184 * EndPage [GDI32.77]
185 *
186 */
187INT WINAPI EndPage(HDC hdc)
188{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000189 INT ret;
Huw D M Davies81561501999-07-25 11:25:59 +0000190 DC *dc = DC_GetDCPtr( hdc );
Patrik Stridvallcbab7702000-05-18 00:52:08 +0000191 if(!dc) return SP_ERROR;
Huw D M Davies81561501999-07-25 11:25:59 +0000192
193 if(dc->funcs->pEndPage)
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000194 ret = dc->funcs->pEndPage( dc );
Huw D M Davies81561501999-07-25 11:25:59 +0000195 else
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000196 ret = Escape(hdc, NEWFRAME, 0, 0, 0);
197 GDI_ReleaseObj( hdc );
198 return ret;
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +0000199}
200
Huw D M Davies5a502731998-12-11 10:17:31 +0000201/******************************************************************************
202 * AbortDoc16 [GDI.382]
203 */
204INT16 WINAPI AbortDoc16(HDC16 hdc)
205{
Huw D M Davies81561501999-07-25 11:25:59 +0000206 return AbortDoc(hdc);
Huw D M Davies5a502731998-12-11 10:17:31 +0000207}
208
209/******************************************************************************
Huw D M Davies81561501999-07-25 11:25:59 +0000210 * AbortDoc [GDI32.105]
Huw D M Davies5a502731998-12-11 10:17:31 +0000211 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000212INT WINAPI AbortDoc(HDC hdc)
Huw D M Davies5a502731998-12-11 10:17:31 +0000213{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000214 INT ret;
Huw D M Davies81561501999-07-25 11:25:59 +0000215 DC *dc = DC_GetDCPtr( hdc );
Patrik Stridvallcbab7702000-05-18 00:52:08 +0000216 if(!dc) return SP_ERROR;
Huw D M Davies81561501999-07-25 11:25:59 +0000217
218 if(dc->funcs->pAbortDoc)
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000219 ret = dc->funcs->pAbortDoc( dc );
Huw D M Davies81561501999-07-25 11:25:59 +0000220 else
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000221 ret = Escape(hdc, ABORTDOC, 0, 0, 0);
222 GDI_ReleaseObj( hdc );
223 return ret;
Huw D M Davies5a502731998-12-11 10:17:31 +0000224}
225
Huw D M Daviese39b6761999-05-17 16:20:51 +0000226/**********************************************************************
Huw D M Davies81561501999-07-25 11:25:59 +0000227 * QueryAbort16 (GDI.155)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000228 *
229 * Calls the app's AbortProc function if avail.
230 *
231 * RETURNS
232 * TRUE if no AbortProc avail or AbortProc wants to continue printing.
233 * FALSE if AbortProc wants to abort printing.
234 */
235BOOL16 WINAPI QueryAbort16(HDC16 hdc, INT16 reserved)
236{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000237 BOOL ret = TRUE;
Huw D M Daviese39b6761999-05-17 16:20:51 +0000238 DC *dc = DC_GetDCPtr( hdc );
239
Huw D M Daviesd016b0a1999-07-24 12:09:34 +0000240 if(!dc) {
241 ERR("Invalid hdc %04x\n", hdc);
242 return FALSE;
243 }
244
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000245 if (dc->w.pAbortProc) ret = dc->w.pAbortProc(hdc, 0);
246 GDI_ReleaseObj( hdc );
247 return ret;
Huw D M Daviese39b6761999-05-17 16:20:51 +0000248}
249
Huw D M Davies304d9a41999-09-13 15:15:45 +0000250/* ### start build ### */
251extern WORD CALLBACK PRTDRV_CallTo16_word_ww(FARPROC16,WORD,WORD);
252/* ### stop build ### */
253
Huw D M Daviese39b6761999-05-17 16:20:51 +0000254/**********************************************************************
255 * SetAbortProc16 (GDI.381)
256 *
257 */
258INT16 WINAPI SetAbortProc16(HDC16 hdc, SEGPTR abrtprc)
259{
Huw D M Davies304d9a41999-09-13 15:15:45 +0000260 ABORTPROC proc32 = (ABORTPROC)THUNK_Alloc((FARPROC16)abrtprc,
261 (RELAY)PRTDRV_CallTo16_word_ww);
262 return SetAbortProc(hdc, proc32);
Huw D M Daviesd016b0a1999-07-24 12:09:34 +0000263}
Huw D M Daviese39b6761999-05-17 16:20:51 +0000264
265/**********************************************************************
Patrik Stridvall39fc90a2000-03-28 19:30:06 +0000266 * SetAbortProc (GDI32.301)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000267 *
268 */
269INT WINAPI SetAbortProc(HDC hdc, ABORTPROC abrtprc)
270{
Huw D M Daviesd016b0a1999-07-24 12:09:34 +0000271 DC *dc = DC_GetDCPtr( hdc );
272
Huw D M Davies304d9a41999-09-13 15:15:45 +0000273 if(dc->w.pAbortProc) THUNK_Free((FARPROC)dc->w.pAbortProc);
274 dc->w.pAbortProc = abrtprc;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000275 GDI_ReleaseObj( hdc );
Huw D M Daviesd016b0a1999-07-24 12:09:34 +0000276 return TRUE;
Huw D M Daviese39b6761999-05-17 16:20:51 +0000277}
278
279
280/****************** misc. printer related functions */
281
282/*
283 * The following function should implement a queing system
284 */
Huw D M Daviese39b6761999-05-17 16:20:51 +0000285struct hpq
286{
287 struct hpq *next;
288 int tag;
289 int key;
290};
291
292static struct hpq *hpqueue;
293
294/**********************************************************************
295 * CreatePQ (GDI.230)
296 *
297 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000298HPQ16 WINAPI CreatePQ16(INT16 size)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000299{
300#if 0
301 HGLOBAL16 hpq = 0;
302 WORD tmp_size;
303 LPWORD pPQ;
304
305 tmp_size = size << 2;
306 if (!(hpq = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, tmp_size + 8)))
307 return 0xffff;
308 pPQ = GlobalLock16(hpq);
309 *pPQ++ = 0;
310 *pPQ++ = tmp_size;
311 *pPQ++ = 0;
312 *pPQ++ = 0;
313 GlobalUnlock16(hpq);
314
Patrik Stridvall8276f691999-09-23 11:48:02 +0000315 return (HPQ16)hpq;
Huw D M Daviese39b6761999-05-17 16:20:51 +0000316#else
317 FIXME("(%d): stub\n",size);
318 return 1;
319#endif
320}
321
322/**********************************************************************
323 * DeletePQ (GDI.235)
324 *
325 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000326INT16 WINAPI DeletePQ16(HPQ16 hPQ)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000327{
328 return GlobalFree16((HGLOBAL16)hPQ);
329}
330
331/**********************************************************************
332 * ExtractPQ (GDI.232)
333 *
334 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000335INT16 WINAPI ExtractPQ16(HPQ16 hPQ)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000336{
337 struct hpq *queue, *prev, *current, *currentPrev;
338 int key = 0, tag = -1;
339 currentPrev = prev = NULL;
340 queue = current = hpqueue;
341 if (current)
342 key = current->key;
343
344 while (current)
345 {
346 currentPrev = current;
347 current = current->next;
348 if (current)
349 {
350 if (current->key < key)
351 {
352 queue = current;
353 prev = currentPrev;
354 }
355 }
356 }
357 if (queue)
358 {
359 tag = queue->tag;
360
361 if (prev)
362 prev->next = queue->next;
363 else
364 hpqueue = queue->next;
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000365 HeapFree(GetProcessHeap(), 0, queue);
Huw D M Daviese39b6761999-05-17 16:20:51 +0000366 }
367
368 TRACE("%x got tag %d key %d\n", hPQ, tag, key);
369
370 return tag;
371}
372
373/**********************************************************************
374 * InsertPQ (GDI.233)
375 *
376 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000377INT16 WINAPI InsertPQ16(HPQ16 hPQ, INT16 tag, INT16 key)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000378{
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000379 struct hpq *queueItem = HeapAlloc(GetProcessHeap(), 0, sizeof(struct hpq));
380 if(queueItem == NULL) {
381 ERR("Memory exausted!");
382 return FALSE;
383 }
Huw D M Daviese39b6761999-05-17 16:20:51 +0000384 queueItem->next = hpqueue;
385 hpqueue = queueItem;
386 queueItem->key = key;
387 queueItem->tag = tag;
388
389 FIXME("(%x %d %d): stub???\n", hPQ, tag, key);
390 return TRUE;
391}
392
393/**********************************************************************
394 * MinPQ (GDI.231)
395 *
396 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000397INT16 WINAPI MinPQ16(HPQ16 hPQ)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000398{
399 FIXME("(%x): stub\n", hPQ);
400 return 0;
401}
402
403/**********************************************************************
404 * SizePQ (GDI.234)
405 *
406 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000407INT16 WINAPI SizePQ16(HPQ16 hPQ, INT16 sizechange)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000408{
409 FIXME("(%x %d): stub\n", hPQ, sizechange);
410 return -1;
411}
412
413
414
415/*
416 * The following functions implement part of the spooling process to
417 * print manager. I would like to see wine have a version of print managers
418 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
419 * now.
420 */
421typedef struct PRINTJOB
422{
423 char *pszOutput;
424 char *pszTitle;
425 HDC16 hDC;
426 HANDLE16 hHandle;
427 int nIndex;
428 int fd;
429} PRINTJOB, *PPRINTJOB;
430
431#define MAX_PRINT_JOBS 1
432#define SP_OK 1
433
434PPRINTJOB gPrintJobsTable[MAX_PRINT_JOBS];
435
436
437static PPRINTJOB FindPrintJobFromHandle(HANDLE16 hHandle)
438{
439 return gPrintJobsTable[0];
440}
441
Huw D M Davies81561501999-07-25 11:25:59 +0000442static int CreateSpoolFile(LPCSTR pszOutput)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000443{
444 int fd=-1;
445 char psCmd[1024];
446 char *psCmdP = psCmd;
447
448 /* TTD convert the 'output device' into a spool file name */
449
450 if (pszOutput == NULL || *pszOutput == '\0')
451 return -1;
452
453 PROFILE_GetWineIniString( "spooler", pszOutput, "", psCmd, sizeof(psCmd) );
454 TRACE("Got printerSpoolCommand '%s' for output device '%s'\n",
455 psCmd, pszOutput);
456 if (!*psCmd)
Huw D M Davies81561501999-07-25 11:25:59 +0000457 psCmdP = (char *)pszOutput;
Huw D M Daviese39b6761999-05-17 16:20:51 +0000458 else
459 {
460 while (*psCmdP && isspace(*psCmdP))
461 {
462 psCmdP++;
463 };
464 if (!*psCmdP)
465 return -1;
466 }
467 if (*psCmdP == '|')
468 {
469 int fds[2];
470 if (pipe(fds))
471 return -1;
472 if (fork() == 0)
473 {
474 psCmdP++;
475
476 TRACE("In child need to exec %s\n",psCmdP);
477 close(0);
478 dup2(fds[0],0);
479 close (fds[1]);
480 system(psCmdP);
481 exit(0);
482
483 }
484 close (fds[0]);
485 fd = fds[1];
486 TRACE("Need to execute a cmnd and pipe the output to it\n");
487 }
488 else
489 {
Frederic Boulangerf93dcc22000-06-15 00:29:54 +0000490 DOS_FULL_NAME fullName;
491
Andreas Mohr34965562000-08-26 20:31:48 +0000492 TRACE("Just assume it's a file\n");
Huw D M Daviese39b6761999-05-17 16:20:51 +0000493
Frederic Boulangerf93dcc22000-06-15 00:29:54 +0000494 /**
495 * The file name can be dos based, we have to find its
496 * Unix correspondant file name
497 */
498 DOSFS_GetFullName(psCmdP, FALSE, &fullName);
499
500 if ((fd = open(fullName.long_name, O_CREAT | O_TRUNC | O_WRONLY , 0600)) < 0)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000501 {
Andreas Mohr34965562000-08-26 20:31:48 +0000502 ERR("Failed to create spool file %s (%s)\n",
503 fullName.long_name, strerror(errno));
Huw D M Daviese39b6761999-05-17 16:20:51 +0000504 }
505 }
506 return fd;
507}
508
509static int FreePrintJob(HANDLE16 hJob)
510{
511 int nRet = SP_ERROR;
512 PPRINTJOB pPrintJob;
513
514 pPrintJob = FindPrintJobFromHandle(hJob);
515 if (pPrintJob != NULL)
516 {
517 gPrintJobsTable[pPrintJob->nIndex] = NULL;
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000518 HeapFree(GetProcessHeap(), 0, pPrintJob->pszOutput);
519 HeapFree(GetProcessHeap(), 0, pPrintJob->pszTitle);
Huw D M Daviese39b6761999-05-17 16:20:51 +0000520 if (pPrintJob->fd >= 0) close(pPrintJob->fd);
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000521 HeapFree(GetProcessHeap(), 0, pPrintJob);
Huw D M Daviese39b6761999-05-17 16:20:51 +0000522 nRet = SP_OK;
523 }
524 return nRet;
525}
526
527/**********************************************************************
528 * OpenJob (GDI.240)
529 *
530 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000531HPJOB16 WINAPI OpenJob16(LPCSTR lpOutput, LPCSTR lpTitle, HDC16 hDC)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000532{
Patrik Stridvall8276f691999-09-23 11:48:02 +0000533 HPJOB16 hHandle = (HPJOB16)SP_ERROR;
Huw D M Daviese39b6761999-05-17 16:20:51 +0000534 PPRINTJOB pPrintJob;
535
536 TRACE("'%s' '%s' %04x\n", lpOutput, lpTitle, hDC);
537
538 pPrintJob = gPrintJobsTable[0];
539 if (pPrintJob == NULL)
540 {
541 int fd;
542
543 /* Try an create a spool file */
544 fd = CreateSpoolFile(lpOutput);
545 if (fd >= 0)
546 {
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000547 pPrintJob = HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTJOB));
548 if(pPrintJob == NULL) {
549 WARN("Memory exausted!");
550 return hHandle;
551 }
552
553 hHandle = 1;
Huw D M Daviese39b6761999-05-17 16:20:51 +0000554
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000555 pPrintJob->pszOutput = HEAP_strdupA(GetProcessHeap(), 0, lpOutput);
Huw D M Daviese39b6761999-05-17 16:20:51 +0000556 if(lpTitle)
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000557 pPrintJob->pszTitle = HEAP_strdupA(GetProcessHeap(), 0, lpTitle);
Huw D M Daviese39b6761999-05-17 16:20:51 +0000558 pPrintJob->hDC = hDC;
559 pPrintJob->fd = fd;
560 pPrintJob->nIndex = 0;
561 pPrintJob->hHandle = hHandle;
562 gPrintJobsTable[pPrintJob->nIndex] = pPrintJob;
563 }
564 }
565 TRACE("return %04x\n", hHandle);
566 return hHandle;
567}
568
569/**********************************************************************
570 * CloseJob (GDI.243)
571 *
572 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000573INT16 WINAPI CloseJob16(HPJOB16 hJob)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000574{
575 int nRet = SP_ERROR;
576 PPRINTJOB pPrintJob = NULL;
577
578 TRACE("%04x\n", hJob);
579
580 pPrintJob = FindPrintJobFromHandle(hJob);
581 if (pPrintJob != NULL)
582 {
583 /* Close the spool file */
584 close(pPrintJob->fd);
585 FreePrintJob(hJob);
586 nRet = 1;
587 }
588 return nRet;
589}
590
591/**********************************************************************
592 * WriteSpool (GDI.241)
593 *
594 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000595INT16 WINAPI WriteSpool16(HPJOB16 hJob, LPSTR lpData, INT16 cch)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000596{
597 int nRet = SP_ERROR;
598 PPRINTJOB pPrintJob = NULL;
599
600 TRACE("%04x %08lx %04x\n", hJob, (DWORD)lpData, cch);
601
602 pPrintJob = FindPrintJobFromHandle(hJob);
603 if (pPrintJob != NULL && pPrintJob->fd >= 0 && cch)
604 {
605 if (write(pPrintJob->fd, lpData, cch) != cch)
606 nRet = SP_OUTOFDISK;
607 else
608 nRet = cch;
609 if (pPrintJob->hDC == 0) {
610 TRACE("hDC == 0 so no QueryAbort\n");
611 }
612 else if (!(QueryAbort16(pPrintJob->hDC, (nRet == SP_OUTOFDISK) ? nRet : 0 )))
613 {
614 CloseJob16(hJob); /* printing aborted */
615 nRet = SP_APPABORT;
616 }
617 }
618 return nRet;
619}
620
621/**********************************************************************
622 * WriteDialog (GDI.242)
623 *
624 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000625INT16 WINAPI WriteDialog16(HPJOB16 hJob, LPSTR lpMsg, INT16 cchMsg)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000626{
Huw D M Daviese39b6761999-05-17 16:20:51 +0000627 TRACE("%04x %04x '%s'\n", hJob, cchMsg, lpMsg);
628
Alexandre Julliard6ec108a2000-03-24 21:42:15 +0000629 return Callout.MessageBoxA(0, lpMsg, "Printing Error", MB_OKCANCEL);
Huw D M Daviese39b6761999-05-17 16:20:51 +0000630}
631
632
633/**********************************************************************
634 * DeleteJob (GDI.244)
635 *
636 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000637INT16 WINAPI DeleteJob16(HPJOB16 hJob, INT16 nNotUsed)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000638{
639 int nRet;
640
641 TRACE("%04x\n", hJob);
642
643 nRet = FreePrintJob(hJob);
644 return nRet;
645}
646
647/*
648 * The following two function would allow a page to be sent to the printer
649 * when it has been processed. For simplicity they havn't been implemented.
650 * This means a whole job has to be processed before it is sent to the printer.
651 */
652
653/**********************************************************************
654 * StartSpoolPage (GDI.246)
655 *
656 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000657INT16 WINAPI StartSpoolPage16(HPJOB16 hJob)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000658{
659 FIXME("StartSpoolPage GDI.246 unimplemented\n");
660 return 1;
661
662}
663
664
665/**********************************************************************
666 * EndSpoolPage (GDI.247)
667 *
668 */
Patrik Stridvall8276f691999-09-23 11:48:02 +0000669INT16 WINAPI EndSpoolPage16(HPJOB16 hJob)
Huw D M Daviese39b6761999-05-17 16:20:51 +0000670{
671 FIXME("EndSpoolPage GDI.247 unimplemented\n");
672 return 1;
673}
674
675
676/**********************************************************************
677 * GetSpoolJob (GDI.245)
678 *
679 */
680DWORD WINAPI GetSpoolJob16(int nOption, LONG param)
681{
682 DWORD retval = 0;
683 TRACE("In GetSpoolJob param 0x%lx noption %d\n",param, nOption);
684 return retval;
685}
686
687
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +0000688/******************************************************************
689 * DrvGetPrinterDataInternal
690 *
691 * Helper for DrvGetPrinterData
692 */
693static DWORD DrvGetPrinterDataInternal(LPSTR RegStr_Printer,
Huw D M Daviesd92c95d1999-01-26 10:07:39 +0000694LPBYTE lpPrinterData, int cbData, int what)
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000695{
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000696 DWORD res = -1;
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000697 HKEY hkey;
698 DWORD dwType, cbQueryData;
699
Alexandre Julliarda3960291999-02-26 11:11:13 +0000700 if (!(RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey))) {
Huw D M Daviesd92c95d1999-01-26 10:07:39 +0000701 if (what == INT_PD_DEFAULT_DEVMODE) { /* "Default DevMode" */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000702 if (!(RegQueryValueExA(hkey, DefaultDevMode, 0, &dwType, 0, &cbQueryData))) {
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000703 if (!lpPrinterData)
704 res = cbQueryData;
705 else if ((cbQueryData) && (cbQueryData <= cbData)) {
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000706 cbQueryData = cbData;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000707 if (RegQueryValueExA(hkey, DefaultDevMode, 0,
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000708 &dwType, lpPrinterData, &cbQueryData))
709 res = cbQueryData;
710 }
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000711 }
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000712 } else { /* "Printer Driver" */
713 cbQueryData = 32;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000714 RegQueryValueExA(hkey, "Printer Driver", 0,
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000715 &dwType, lpPrinterData, &cbQueryData);
716 res = cbQueryData;
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000717 }
718 }
719 if (hkey) RegCloseKey(hkey);
720 return res;
721}
Alexandre Julliard889f7421997-04-15 17:19:52 +0000722
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +0000723/******************************************************************
724 * DrvGetPrinterData [GDI.282]
725 *
726 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000727DWORD WINAPI DrvGetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000728 LPDWORD lpType, LPBYTE lpPrinterData,
729 int cbData, LPDWORD lpNeeded)
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000730{
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000731 LPSTR RegStr_Printer;
732 HKEY hkey = 0, hkey2 = 0;
733 DWORD res = 0;
734 DWORD dwType, PrinterAttr, cbPrinterAttr, SetData, size;
735
Alexandre Julliard33072e11997-06-29 18:08:02 +0000736 if (HIWORD(lpPrinter))
Huw D M Daviese39b6761999-05-17 16:20:51 +0000737 TRACE("printer %s\n",lpPrinter);
Alexandre Julliard33072e11997-06-29 18:08:02 +0000738 else
Huw D M Daviese39b6761999-05-17 16:20:51 +0000739 TRACE("printer %p\n",lpPrinter);
Alexandre Julliard33072e11997-06-29 18:08:02 +0000740 if (HIWORD(lpProfile))
Huw D M Daviese39b6761999-05-17 16:20:51 +0000741 TRACE("profile %s\n",lpProfile);
Alexandre Julliard33072e11997-06-29 18:08:02 +0000742 else
Huw D M Daviese39b6761999-05-17 16:20:51 +0000743 TRACE("profile %p\n",lpProfile);
744 TRACE("lpType %p\n",lpType);
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000745
746 if ((!lpPrinter) || (!lpProfile) || (!lpNeeded))
747 return ERROR_INVALID_PARAMETER;
748
749 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
750 strlen(Printers) + strlen(lpPrinter) + 2);
751 strcpy(RegStr_Printer, Printers);
752 strcat(RegStr_Printer, lpPrinter);
753
Alexandre Julliard642d3131998-07-12 19:29:36 +0000754 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
755 (!strcmp(lpProfile, DefaultDevMode)))) {
Huw D M Daviesd92c95d1999-01-26 10:07:39 +0000756 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData,
757 INT_PD_DEFAULT_DEVMODE);
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000758 if (size+1) {
759 *lpNeeded = size;
760 if ((lpPrinterData) && (*lpNeeded > cbData))
761 res = ERROR_MORE_DATA;
762 }
763 else res = ERROR_INVALID_PRINTER_NAME;
764 }
765 else
Alexandre Julliard642d3131998-07-12 19:29:36 +0000766 if (((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
767 (!strcmp(lpProfile, PrinterModel)))) {
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000768 *lpNeeded = 32;
769 if (!lpPrinterData) goto failed;
770 if (cbData < 32) {
771 res = ERROR_MORE_DATA;
772 goto failed;
773 }
Huw D M Daviesd92c95d1999-01-26 10:07:39 +0000774 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData,
775 INT_PD_DEFAULT_MODEL);
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000776 if ((size+1) && (lpType))
777 *lpType = REG_SZ;
778 else
779 res = ERROR_INVALID_PRINTER_NAME;
780 }
781 else
782 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000783 if ((res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)))
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000784 goto failed;
785 cbPrinterAttr = 4;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000786 if ((res = RegQueryValueExA(hkey, "Attributes", 0,
Alexandre Julliard642d3131998-07-12 19:29:36 +0000787 &dwType, (LPBYTE)&PrinterAttr, &cbPrinterAttr)))
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000788 goto failed;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000789 if ((res = RegOpenKeyA(hkey, PrinterDriverData, &hkey2)))
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000790 goto failed;
791 *lpNeeded = cbData;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000792 res = RegQueryValueExA(hkey2, lpProfile, 0,
Alexandre Julliard642d3131998-07-12 19:29:36 +0000793 lpType, lpPrinterData, lpNeeded);
794 if ((res != ERROR_CANTREAD) &&
795 ((PrinterAttr &
796 (PRINTER_ATTRIBUTE_ENABLE_BIDI|PRINTER_ATTRIBUTE_NETWORK))
797 == PRINTER_ATTRIBUTE_NETWORK))
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000798 {
799 if (!(res) && (*lpType == REG_DWORD) && (*(LPDWORD)lpPrinterData == -1))
800 res = ERROR_INVALID_DATA;
801 }
802 else
803 {
804 SetData = -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000805 RegSetValueExA(hkey2, lpProfile, 0, REG_DWORD, (LPBYTE)&SetData, 4); /* no result returned */
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000806 }
807 }
808
809failed:
810 if (hkey2) RegCloseKey(hkey2);
811 if (hkey) RegCloseKey(hkey);
812 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
813 return res;
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000814}
815
816
Huw D M Davies7d5fd8d1998-12-08 09:44:30 +0000817/******************************************************************
818 * DrvSetPrinterData [GDI.281]
819 *
820 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000821DWORD WINAPI DrvSetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000822 DWORD lpType, LPBYTE lpPrinterData,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000823 DWORD dwSize)
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000824{
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000825 LPSTR RegStr_Printer;
826 HKEY hkey = 0;
827 DWORD res = 0;
828
Alexandre Julliard33072e11997-06-29 18:08:02 +0000829 if (HIWORD(lpPrinter))
Huw D M Daviese39b6761999-05-17 16:20:51 +0000830 TRACE("printer %s\n",lpPrinter);
Alexandre Julliard33072e11997-06-29 18:08:02 +0000831 else
Huw D M Daviese39b6761999-05-17 16:20:51 +0000832 TRACE("printer %p\n",lpPrinter);
Alexandre Julliard33072e11997-06-29 18:08:02 +0000833 if (HIWORD(lpProfile))
Huw D M Daviese39b6761999-05-17 16:20:51 +0000834 TRACE("profile %s\n",lpProfile);
Alexandre Julliard33072e11997-06-29 18:08:02 +0000835 else
Huw D M Daviese39b6761999-05-17 16:20:51 +0000836 TRACE("profile %p\n",lpProfile);
837 TRACE("lpType %08lx\n",lpType);
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000838
839 if ((!lpPrinter) || (!lpProfile) ||
Alexandre Julliard642d3131998-07-12 19:29:36 +0000840 ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
841 (!strcmp(lpProfile, PrinterModel))))
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000842 return ERROR_INVALID_PARAMETER;
843
844 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
845 strlen(Printers) + strlen(lpPrinter) + 2);
846 strcpy(RegStr_Printer, Printers);
847 strcat(RegStr_Printer, lpPrinter);
848
Alexandre Julliard642d3131998-07-12 19:29:36 +0000849 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
850 (!strcmp(lpProfile, DefaultDevMode)))) {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000851 if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000852 != ERROR_SUCCESS ||
Alexandre Julliarda3960291999-02-26 11:11:13 +0000853 RegSetValueExA(hkey, DefaultDevMode, 0, REG_BINARY,
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000854 lpPrinterData, dwSize) != ERROR_SUCCESS )
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000855 res = ERROR_INVALID_PRINTER_NAME;
856 }
857 else
858 {
859 strcat(RegStr_Printer, "\\");
860
Alexandre Julliarda3960291999-02-26 11:11:13 +0000861 if( (res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ==
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000862 ERROR_SUCCESS ) {
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000863
864 if (!lpPrinterData)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000865 res = RegDeleteValueA(hkey, lpProfile);
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000866 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000867 res = RegSetValueExA(hkey, lpProfile, 0, lpType,
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000868 lpPrinterData, dwSize);
Alexandre Julliardf90efa91998-06-14 15:24:15 +0000869 }
870 }
871
872 if (hkey) RegCloseKey(hkey);
873 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
874 return res;
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000875}