2 * Print spooler and PQ functions
4 * Copyright 1996 John Harvey
20 #include "wine/winuser16.h"
24 DEFAULT_DEBUG_CHANNEL(print
)
26 /**********************************************************************
27 * QueryAbort (GDI.155)
29 * Calls the app's AbortProc function if avail.
32 * TRUE if no AbortProc avail or AbortProc wants to continue printing.
33 * FALSE if AbortProc wants to abort printing.
35 BOOL16 WINAPI
QueryAbort16(HDC16 hdc
, INT16 reserved
)
37 DC
*dc
= DC_GetDCPtr( hdc
);
39 if ((!dc
) || (!dc
->w
.lpfnPrint
))
41 return Callbacks
->CallDrvAbortProc(dc
->w
.lpfnPrint
, hdc
, 0);
44 /**********************************************************************
45 * SetAbortProc16 (GDI.381)
48 INT16 WINAPI
SetAbortProc16(HDC16 hdc
, SEGPTR abrtprc
)
50 return Escape16(hdc
, SETABORTPROC
, 0, abrtprc
, (SEGPTR
)0);
53 /**********************************************************************
54 * SetAbortProc32 (GDI32.301)
57 INT WINAPI
SetAbortProc(HDC hdc
, ABORTPROC abrtprc
)
59 FIXME(print
, "stub\n");
60 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
65 /****************** misc. printer related functions */
68 * The following function should implement a queing system
80 static struct hpq
*hpqueue
;
82 /**********************************************************************
86 HPQ WINAPI
CreatePQ16(int size
)
94 if (!(hpq
= GlobalAlloc16(GMEM_SHARE
|GMEM_MOVEABLE
, tmp_size
+ 8)))
96 pPQ
= GlobalLock16(hpq
);
105 FIXME(print
, "(%d): stub\n",size
);
110 /**********************************************************************
114 int WINAPI
DeletePQ16(HPQ hPQ
)
116 return GlobalFree16((HGLOBAL16
)hPQ
);
119 /**********************************************************************
120 * ExtractPQ (GDI.232)
123 int WINAPI
ExtractPQ16(HPQ hPQ
)
125 struct hpq
*queue
, *prev
, *current
, *currentPrev
;
126 int key
= 0, tag
= -1;
127 currentPrev
= prev
= NULL
;
128 queue
= current
= hpqueue
;
134 currentPrev
= current
;
135 current
= current
->next
;
138 if (current
->key
< key
)
150 prev
->next
= queue
->next
;
152 hpqueue
= queue
->next
;
156 TRACE(print
, "%x got tag %d key %d\n", hPQ
, tag
, key
);
161 /**********************************************************************
165 int WINAPI
InsertPQ16(HPQ hPQ
, int tag
, int key
)
167 struct hpq
*queueItem
= xmalloc(sizeof(struct hpq
));
168 queueItem
->next
= hpqueue
;
170 queueItem
->key
= key
;
171 queueItem
->tag
= tag
;
173 FIXME(print
, "(%x %d %d): stub???\n", hPQ
, tag
, key
);
177 /**********************************************************************
181 int WINAPI
MinPQ16(HPQ hPQ
)
183 FIXME(print
, "(%x): stub\n", hPQ
);
187 /**********************************************************************
191 int WINAPI
SizePQ16(HPQ hPQ
, int sizechange
)
193 FIXME(print
, "(%x %d): stub\n", hPQ
, sizechange
);
200 * The following functions implement part of the spooling process to
201 * print manager. I would like to see wine have a version of print managers
202 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
205 typedef struct PRINTJOB
213 } PRINTJOB
, *PPRINTJOB
;
215 #define MAX_PRINT_JOBS 1
218 PPRINTJOB gPrintJobsTable
[MAX_PRINT_JOBS
];
221 static PPRINTJOB
FindPrintJobFromHandle(HANDLE16 hHandle
)
223 return gPrintJobsTable
[0];
226 /* TTD Need to do some DOS->UNIX file conversion here */
227 static int CreateSpoolFile(LPSTR pszOutput
)
231 char *psCmdP
= psCmd
;
233 /* TTD convert the 'output device' into a spool file name */
235 if (pszOutput
== NULL
|| *pszOutput
== '\0')
238 PROFILE_GetWineIniString( "spooler", pszOutput
, "", psCmd
, sizeof(psCmd
) );
239 TRACE(print
, "Got printerSpoolCommand '%s' for output device '%s'\n",
245 while (*psCmdP
&& isspace(*psCmdP
))
261 TRACE(print
, "In child need to exec %s\n",psCmdP
);
271 TRACE(print
,"Need to execute a cmnd and pipe the output to it\n");
275 TRACE(print
, "Just assume its a file\n");
277 if ((fd
= open(psCmdP
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600)) < 0)
279 ERR(print
, "Failed to create spool file %s, errno = %d\n",
286 static int FreePrintJob(HANDLE16 hJob
)
291 pPrintJob
= FindPrintJobFromHandle(hJob
);
292 if (pPrintJob
!= NULL
)
294 gPrintJobsTable
[pPrintJob
->nIndex
] = NULL
;
295 free(pPrintJob
->pszOutput
);
296 free(pPrintJob
->pszTitle
);
297 if (pPrintJob
->fd
>= 0) close(pPrintJob
->fd
);
304 /**********************************************************************
308 HANDLE16 WINAPI
OpenJob16(LPSTR lpOutput
, LPSTR lpTitle
, HDC16 hDC
)
310 HANDLE16 hHandle
= (HANDLE16
)SP_ERROR
;
313 TRACE(print
, "'%s' '%s' %04x\n", lpOutput
, lpTitle
, hDC
);
315 pPrintJob
= gPrintJobsTable
[0];
316 if (pPrintJob
== NULL
)
320 /* Try an create a spool file */
321 fd
= CreateSpoolFile(lpOutput
);
326 pPrintJob
= xmalloc(sizeof(PRINTJOB
));
327 memset(pPrintJob
, 0, sizeof(PRINTJOB
));
329 pPrintJob
->pszOutput
= strdup(lpOutput
);
331 pPrintJob
->pszTitle
= strdup(lpTitle
);
332 pPrintJob
->hDC
= hDC
;
334 pPrintJob
->nIndex
= 0;
335 pPrintJob
->hHandle
= hHandle
;
336 gPrintJobsTable
[pPrintJob
->nIndex
] = pPrintJob
;
339 TRACE(print
, "return %04x\n", hHandle
);
343 /**********************************************************************
347 int WINAPI
CloseJob16(HANDLE16 hJob
)
350 PPRINTJOB pPrintJob
= NULL
;
352 TRACE(print
, "%04x\n", hJob
);
354 pPrintJob
= FindPrintJobFromHandle(hJob
);
355 if (pPrintJob
!= NULL
)
357 /* Close the spool file */
358 close(pPrintJob
->fd
);
365 /**********************************************************************
366 * WriteSpool (GDI.241)
369 int WINAPI
WriteSpool16(HANDLE16 hJob
, LPSTR lpData
, WORD cch
)
372 PPRINTJOB pPrintJob
= NULL
;
374 TRACE(print
, "%04x %08lx %04x\n", hJob
, (DWORD
)lpData
, cch
);
376 pPrintJob
= FindPrintJobFromHandle(hJob
);
377 if (pPrintJob
!= NULL
&& pPrintJob
->fd
>= 0 && cch
)
379 if (write(pPrintJob
->fd
, lpData
, cch
) != cch
)
383 if (pPrintJob
->hDC
== 0) {
384 TRACE(print
, "hDC == 0 so no QueryAbort\n");
386 else if (!(QueryAbort16(pPrintJob
->hDC
, (nRet
== SP_OUTOFDISK
) ? nRet
: 0 )))
388 CloseJob16(hJob
); /* printing aborted */
395 /**********************************************************************
396 * WriteDialog (GDI.242)
399 int WINAPI
WriteDialog16(HANDLE16 hJob
, LPSTR lpMsg
, WORD cchMsg
)
403 TRACE(print
, "%04x %04x '%s'\n", hJob
, cchMsg
, lpMsg
);
405 nRet
= MessageBox16(0, lpMsg
, "Printing Error", MB_OKCANCEL
);
410 /**********************************************************************
411 * DeleteJob (GDI.244)
414 int WINAPI
DeleteJob16(HANDLE16 hJob
, WORD wNotUsed
)
418 TRACE(print
, "%04x\n", hJob
);
420 nRet
= FreePrintJob(hJob
);
425 * The following two function would allow a page to be sent to the printer
426 * when it has been processed. For simplicity they havn't been implemented.
427 * This means a whole job has to be processed before it is sent to the printer.
430 /**********************************************************************
431 * StartSpoolPage (GDI.246)
434 int WINAPI
StartSpoolPage16(HANDLE16 hJob
)
436 FIXME(print
, "StartSpoolPage GDI.246 unimplemented\n");
442 /**********************************************************************
443 * EndSpoolPage (GDI.247)
446 int WINAPI
EndSpoolPage16(HANDLE16 hJob
)
448 FIXME(print
, "EndSpoolPage GDI.247 unimplemented\n");
453 /**********************************************************************
454 * GetSpoolJob (GDI.245)
457 DWORD WINAPI
GetSpoolJob16(int nOption
, LONG param
)
460 TRACE(print
, "In GetSpoolJob param 0x%lx noption %d\n",param
, nOption
);