Release 980104
[wine/multimedia.git] / graphics / win16drv / init.c
blobfaac26ef92438c6d85d338851c8cf66af263368f
1 /*
2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #include <ctype.h>
11 #include <fcntl.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include "windows.h"
15 #include "module.h"
16 #include "win16drv.h"
17 #include "gdi.h"
18 #include "bitmap.h"
19 #include "heap.h"
20 #include "color.h"
21 #include "font.h"
22 #include "callback.h"
23 #include "stddebug.h"
24 #include "debug.h"
26 #define SUPPORT_REALIZED_FONTS 1
27 #pragma pack(1)
28 typedef struct
30 SHORT nSize;
31 SEGPTR lpindata;
32 SEGPTR lpFont;
33 SEGPTR lpXForm;
34 SEGPTR lpDrawMode;
35 } EXTTEXTDATA, *LPEXTTEXTDATA;
36 #pragma pack(4)
38 SEGPTR win16drv_SegPtr_TextXForm;
39 LPTEXTXFORM16 win16drv_TextXFormP;
40 SEGPTR win16drv_SegPtr_DrawMode;
41 LPDRAWMODE win16drv_DrawModeP;
44 static BOOL32 WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
45 LPCSTR output, const DEVMODE16* initData );
46 static INT32 WIN16DRV_Escape( DC *dc, INT32 nEscape, INT32 cbInput,
47 SEGPTR lpInData, SEGPTR lpOutData );
49 static const DC_FUNCTIONS WIN16DRV_Funcs =
51 NULL, /* pArc */
52 NULL, /* pBitBlt */
53 NULL, /* pChord */
54 WIN16DRV_CreateDC, /* pCreateDC */
55 NULL, /* pDeleteDC */
56 NULL, /* pDeleteObject */
57 NULL, /* pEllipse */
58 NULL, /* pEnumDeviceFonts */
59 WIN16DRV_Escape, /* pEscape */
60 NULL, /* pExcludeClipRect */
61 NULL, /* pExcludeVisRect */
62 NULL, /* pExtFloodFill */
63 WIN16DRV_ExtTextOut, /* pExtTextOut */
64 WIN16DRV_GetCharWidth, /* pGetCharWidth */
65 NULL, /* pGetPixel */
66 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
67 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
68 NULL, /* pIntersectClipRect */
69 NULL, /* pIntersectVisRect */
70 WIN16DRV_LineTo, /* pLineTo */
71 WIN16DRV_MoveToEx, /* pMoveToEx */
72 NULL, /* pOffsetClipRgn */
73 NULL, /* pOffsetViewportOrgEx */
74 NULL, /* pOffsetWindowOrgEx */
75 NULL, /* pPaintRgn */
76 WIN16DRV_PatBlt, /* pPatBlt */
77 NULL, /* pPie */
78 NULL, /* pPolyPolygon */
79 WIN16DRV_Polygon, /* pPolygon */
80 NULL, /* pPolyline */
81 NULL, /* pRealizePalette */
82 WIN16DRV_Rectangle, /* pRectangle */
83 NULL, /* pRestoreDC */
84 NULL, /* pRoundRect */
85 NULL, /* pSaveDC */
86 NULL, /* pScaleViewportExtEx */
87 NULL, /* pScaleWindowExtEx */
88 NULL, /* pSelectClipRgn */
89 WIN16DRV_SelectObject, /* pSelectObject */
90 NULL, /* pSelectPalette */
91 NULL, /* pSetBkColor */
92 NULL, /* pSetBkMode */
93 NULL, /* pSetDeviceClipping */
94 NULL, /* pSetDIBitsToDevice */
95 NULL, /* pSetMapMode */
96 NULL, /* pSetMapperFlags */
97 NULL, /* pSetPixel */
98 NULL, /* pSetPolyFillMode */
99 NULL, /* pSetROP2 */
100 NULL, /* pSetRelAbs */
101 NULL, /* pSetStretchBltMode */
102 NULL, /* pSetTextAlign */
103 NULL, /* pSetTextCharacterExtra */
104 NULL, /* pSetTextColor */
105 NULL, /* pSetTextJustification */
106 NULL, /* pSetViewportExtEx */
107 NULL, /* pSetViewportOrgEx */
108 NULL, /* pSetWindowExtEx */
109 NULL, /* pSetWindowOrgEx */
110 NULL, /* pStretchBlt */
111 NULL /* pStretchDIBits */
118 /**********************************************************************
119 * WIN16DRV_Init
121 BOOL32 WIN16DRV_Init(void)
123 return DRIVER_RegisterDriver( NULL /* generic driver */, &WIN16DRV_Funcs );
127 /* Tempory functions, for initialising structures */
128 /* These values should be calculated, not hardcoded */
129 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
131 lpTextXForm->txfHeight = 0x0001;
132 lpTextXForm->txfWidth = 0x000c;
133 lpTextXForm->txfEscapement = 0x0000;
134 lpTextXForm->txfOrientation = 0x0000;
135 lpTextXForm->txfWeight = 0x0190;
136 lpTextXForm->txfItalic = 0x00;
137 lpTextXForm->txfUnderline = 0x00;
138 lpTextXForm->txfStrikeOut = 0x00;
139 lpTextXForm->txfOutPrecision = 0x02;
140 lpTextXForm->txfClipPrecision = 0x01;
141 lpTextXForm->txfAccelerator = 0x0001;
142 lpTextXForm->txfOverhang = 0x0000;
146 void InitDrawMode(LPDRAWMODE lpDrawMode)
148 lpDrawMode->Rop2 = 0x000d;
149 lpDrawMode->bkMode = 0x0001;
150 lpDrawMode->bkColor = 0x3fffffff;
151 lpDrawMode->TextColor = 0x20000000;
152 lpDrawMode->TBreakExtra = 0x0000;
153 lpDrawMode->BreakExtra = 0x0000;
154 lpDrawMode->BreakErr = 0x0000;
155 lpDrawMode->BreakRem = 0x0000;
156 lpDrawMode->BreakCount = 0x0000;
157 lpDrawMode->CharExtra = 0x0000;
158 lpDrawMode->LbkColor = 0x00ffffff;
159 lpDrawMode->LTextColor = 0x00000000;
163 * EnumCallback (GDI.158)
165 * This is the callback function used when EnumDFonts is called.
166 * (The printer drivers uses it to pass info on available fonts).
168 * lpvClientData is the pointer passed to EnumDFonts, which points to a WEPFC
169 * structure (WEPFC = WINE_ENUM_PRINTER_FONT_CALLBACK). This structure
170 * contains infomation on how to store the data passed .
172 * There are two modes:
173 * 1) Just count the number of fonts available.
174 * 2) Store all font data passed.
176 WORD WINAPI WineEnumDFontCallback(LPLOGFONT16 lpLogFont,
177 LPTEXTMETRIC16 lpTextMetrics,
178 WORD wFontType, LONG lpvClientData)
180 int wRet = 0;
181 WEPFC *pWEPFC = (WEPFC *)lpvClientData;
183 /* Make sure we have the right structure */
184 if (pWEPFC != NULL )
186 dprintf_win16drv(stddeb, "mode is 0x%x\n",pWEPFC->nMode);
188 switch (pWEPFC->nMode)
190 /* Count how many fonts */
191 case 1:
192 pWEPFC->nCount++;
193 break;
195 /* Store the fonts in the printer driver structure */
196 case 2:
198 PRINTER_FONTS_INFO *pPFI;
200 dprintf_win16drv(stddeb, "WineEnumDFontCallback: Found %s %x\n",
201 lpLogFont->lfFaceName, wFontType);
203 pPFI = &pWEPFC->pLPD->paPrinterFonts[pWEPFC->nCount];
204 memcpy(&(pPFI->lf), lpLogFont, sizeof(LOGFONT16));
205 memcpy(&(pPFI->tm), lpTextMetrics, sizeof(TEXTMETRIC16));
206 pWEPFC->nCount++;
209 break;
211 wRet = 1;
213 dprintf_win16drv(stddeb, "WineEnumDFontCallback: returnd %d\n", wRet);
214 return wRet;
217 BOOL32 WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
218 const DEVMODE16* initData )
220 LOADED_PRINTER_DRIVER *pLPD;
221 WORD wRet;
222 DeviceCaps *printerDevCaps;
223 FARPROC16 pfnCallback;
224 int nPDEVICEsize;
225 PDEVICE_HEADER *pPDH;
226 WIN16DRV_PDEVICE *physDev;
227 int numFonts;
228 /* Realizing fonts */
229 int nSize;
230 char printerEnabled[20];
231 PROFILE_GetWineIniString( "wine", "printer", "off",
232 printerEnabled, sizeof(printerEnabled) );
233 if (lstrcmpi32A(printerEnabled,"on"))
235 printf("WIN16DRV_CreateDC disabled in wine.conf file\n");
236 return FALSE;
239 dprintf_win16drv(stddeb, "In creatdc for (%s,%s,%s) initData 0x%p\n",driver, device, output, initData);
241 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( SystemHeap, 0, sizeof(*physDev) );
242 if (!physDev) return FALSE;
243 dc->physDev = physDev;
245 pLPD = LoadPrinterDriver(driver);
246 if (pLPD == NULL)
248 dprintf_win16drv(stddeb, "LPGDI_CreateDC: Failed to find printer driver\n");
249 HeapFree( SystemHeap, 0, physDev );
250 return FALSE;
252 dprintf_win16drv(stddeb, "windevCreateDC pLPD 0x%p\n", pLPD);
254 /* Now Get the device capabilities from the printer driver */
256 printerDevCaps = (DeviceCaps *) malloc(sizeof(DeviceCaps));
257 memset(printerDevCaps, 0, sizeof(DeviceCaps));
259 /* Get GDIINFO which is the same as a DeviceCaps structure */
260 wRet = PRTDRV_Enable(printerDevCaps, GETGDIINFO, device, driver, output,NULL);
262 /* Add this to the DC */
263 dc->w.devCaps = printerDevCaps;
264 dc->w.hVisRgn = CreateRectRgn32(0, 0, dc->w.devCaps->horzRes, dc->w.devCaps->vertRes);
265 dc->w.bitsPerPixel = dc->w.devCaps->bitsPixel;
267 printf("Got devcaps width %d height %d bits %d planes %d\n",
268 dc->w.devCaps->horzRes,
269 dc->w.devCaps->vertRes,
270 dc->w.devCaps->bitsPixel,
271 dc->w.devCaps->planes);
273 /* Now we allocate enough memory for the PDEVICE structure */
274 /* The size of this varies between printer drivers */
275 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
276 /* be accessable from 16 bit code */
277 nPDEVICEsize = dc->w.devCaps->pdeviceSize + sizeof(PDEVICE_HEADER);
279 /* TTD Shouldn't really do pointer arithmetic on segment points */
280 physDev->segptrPDEVICE = WIN16_GlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
281 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+0) = 'N';
282 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+1) = 'B';
284 /* Set up the header */
285 pPDH = (PDEVICE_HEADER *)((BYTE*)PTR_SEG_TO_LIN(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
286 pPDH->pLPD = pLPD;
288 dprintf_win16drv(stddeb, "PRTDRV_Enable: PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
290 /* Now get the printer driver to initialise this data */
291 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
293 /* Now enumerate the fonts supported by the printer driver*/
294 /* GDI.158 is EnumCallback, which is called by the 16bit printer driver */
295 /* passing information on the available fonts */
296 if (pLPD->paPrinterFonts == NULL)
298 pfnCallback = MODULE_GetEntryPoint( GetModuleHandle16("GDI"), 158 );
300 if (pfnCallback != NULL)
302 WEPFC wepfc;
304 wepfc.nMode = 1;
305 wepfc.nCount = 0;
306 wepfc.pLPD = pLPD;
308 /* First count the number of fonts */
310 PRTDRV_EnumDFonts(physDev->segptrPDEVICE, NULL, pfnCallback,
311 (void *)&wepfc);
313 /* Allocate a buffer to store all of the fonts */
314 pLPD->nPrinterFonts = wepfc.nCount;
315 dprintf_win16drv(stddeb, "Got %d fonts\n",wepfc.nCount);
317 if (wepfc.nCount > 0)
320 pLPD->paPrinterFonts = malloc(sizeof(PRINTER_FONTS_INFO) * wepfc.nCount);
322 /* Now get all of the fonts */
323 wepfc.nMode = 2;
324 wepfc.nCount = 0;
325 PRTDRV_EnumDFonts(physDev->segptrPDEVICE, NULL, pfnCallback,
326 (void *)&wepfc);
327 numFonts = wepfc.nCount;
329 else
331 /* If the number of fonts returned are zero we can not continue */
332 fprintf( stderr, "No fonts? Aborting CreateDC...\n");
333 return FALSE;
338 /* Select the first font into the DC */
339 /* Set up the logfont */
340 memcpy(&physDev->lf,
341 &pLPD->paPrinterFonts[0].lf,
342 sizeof(LOGFONT16));
344 /* Set up the textmetrics */
345 memcpy(&physDev->tm,
346 &pLPD->paPrinterFonts[0].tm,
347 sizeof(TEXTMETRIC16));
349 win16drv_SegPtr_TextXForm = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
350 win16drv_TextXFormP = PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm);
352 InitTextXForm(win16drv_TextXFormP);
353 #ifdef SUPPORT_REALIZED_FONTS
354 /* TTD should calculate this */
356 /* First get the size of the realized font */
357 nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, DRVOBJ_FONT,
358 &pLPD->paPrinterFonts[0], NULL,
361 physDev->segptrFontInfo = WIN16_GlobalLock16(GlobalAlloc16(GHND, nSize));
362 /* Realize the font */
363 PRTDRV_RealizeObject(physDev->segptrPDEVICE, DRVOBJ_FONT,
364 &pLPD->paPrinterFonts[0],
365 (LPVOID)physDev->segptrFontInfo,
366 win16drv_SegPtr_TextXForm);
367 /* Quick look at structure */
368 if (physDev->segptrFontInfo)
370 FONTINFO16 *p = (FONTINFO16 *)PTR_SEG_TO_LIN(physDev->segptrFontInfo);
372 dprintf_win16drv(stddeb, "T:%d VR:%d HR:%d, F:%d L:%d\n",
373 p->dfType,
374 p->dfVertRes, p->dfHorizRes,
375 p->dfFirstCHAR, p->dfLastCHAR
379 #endif
380 /* TTD Lots more to do here */
381 win16drv_SegPtr_DrawMode = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
382 win16drv_DrawModeP = PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode);
384 InitDrawMode(win16drv_DrawModeP);
386 return TRUE;
389 BOOL32 WIN16DRV_PatBlt( struct tagDC *dc, INT32 left, INT32 top,
390 INT32 width, INT32 height, DWORD rop )
393 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
394 BOOL32 bRet = 0;
396 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, NULL, 0, 0, width, height,
397 PATCOPY, physDev->segptrBrushInfo, win16drv_SegPtr_DrawMode, NULL);
399 return bRet;
402 * Escape (GDI.38)
404 static INT32 WIN16DRV_Escape( DC *dc, INT32 nEscape, INT32 cbInput,
405 SEGPTR lpInData, SEGPTR lpOutData )
407 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
408 int nRet = 0;
410 /* We should really process the nEscape parameter, but for now just
411 pass it all to the driver */
412 if (dc != NULL && physDev->segptrPDEVICE != 0)
414 switch(nEscape)
416 case ENABLEPAIRKERNING:
417 fprintf(stderr,"Escape: ENABLEPAIRKERNING ignored.\n");
418 nRet = 1;
419 break;
420 case SETABORTPROC:
421 printf("Escape: SetAbortProc ignored should be stored in dc somewhere\n");
422 /* Make calling application believe this worked */
423 nRet = 1;
424 break;
426 case NEXTBAND:
428 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
430 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
431 SEGPTR_GET(newInData), lpOutData);
432 SEGPTR_FREE(newInData);
433 break;
436 case GETEXTENDEDTEXTMETRICS:
438 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
440 textData->nSize = cbInput;
441 textData->lpindata = lpInData;
442 textData->lpFont = physDev->segptrFontInfo;
443 textData->lpXForm = win16drv_SegPtr_TextXForm;
444 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
445 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
446 SEGPTR_GET(textData), lpOutData);
447 SEGPTR_FREE(textData);
449 break;
450 case STARTDOC:
451 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
452 lpInData, lpOutData);
453 if (nRet != -1)
455 HDC32 *tmpHdc = SEGPTR_NEW(HDC32);
457 #define SETPRINTERDC SETABORTPROC
459 *tmpHdc = dc->hSelf;
460 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
461 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
462 SEGPTR_FREE(tmpHdc);
464 break;
465 default:
466 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
467 lpInData, lpOutData);
468 break;
471 else
472 fprintf(stderr, "Escape(nEscape = %04x)\n", nEscape);
473 return nRet;
479 /****************** misc. printer releated functions */
482 * The following function should implement a queing system
484 #ifndef HPQ
485 #define HPQ WORD
486 #endif
487 struct hpq
489 struct hpq *next;
490 int tag;
491 int key;
494 static struct hpq *hpqueue;
496 HPQ WINAPI CreatePQ(int size)
498 printf("CreatePQ: %d\n",size);
499 return 1;
501 int WINAPI DeletePQ(HPQ hPQ)
503 printf("DeletePQ: %x\n", hPQ);
504 return 0;
506 int WINAPI ExtractPQ(HPQ hPQ)
508 struct hpq *queue, *prev, *current, *currentPrev;
509 int key = 0, tag = -1;
510 currentPrev = prev = NULL;
511 queue = current = hpqueue;
512 if (current)
513 key = current->key;
515 while (current)
517 currentPrev = current;
518 current = current->next;
519 if (current)
521 if (current->key < key)
523 queue = current;
524 prev = currentPrev;
528 if (queue)
530 tag = queue->tag;
532 if (prev)
533 prev->next = queue->next;
534 else
535 hpqueue = queue->next;
536 free(queue);
539 printf("ExtractPQ: %x got tag %d key %d\n", hPQ, tag, key);
541 return tag;
544 int WINAPI InsertPQ(HPQ hPQ, int tag, int key)
546 struct hpq *queueItem = malloc(sizeof(struct hpq));
547 queueItem->next = hpqueue;
548 hpqueue = queueItem;
549 queueItem->key = key;
550 queueItem->tag = tag;
552 printf("InsertPQ: %x %d %d\n", hPQ, tag, key);
553 return TRUE;
555 int WINAPI MinPQ(HPQ hPQ)
557 printf("MinPQ: %x\n", hPQ);
558 return 0;
560 int WINAPI SizePQ(HPQ hPQ, int sizechange)
562 printf("SizePQ: %x %d\n", hPQ, sizechange);
563 return -1;
567 * The following functions implement part of the spooling process to
568 * print manager. I would like to see wine have a version of print managers
569 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
570 * now.
572 typedef struct PRINTJOB
574 char *pszOutput;
575 char *pszTitle;
576 HDC16 hDC;
577 HANDLE16 hHandle;
578 int nIndex;
579 int fd;
580 } PRINTJOB, *PPRINTJOB;
582 #define MAX_PRINT_JOBS 1
583 #define SP_OK 1
585 PPRINTJOB gPrintJobsTable[MAX_PRINT_JOBS];
588 static PPRINTJOB FindPrintJobFromHandle(HANDLE16 hHandle)
590 return gPrintJobsTable[0];
593 /* TTD Need to do some DOS->UNIX file conversion here */
594 static int CreateSpoolFile(LPSTR pszOutput)
596 int fd=-1;
597 char psCmd[1024];
598 char *psCmdP = psCmd;
600 /* TTD convert the 'output device' into a spool file name */
602 if (pszOutput == NULL || *pszOutput == '\0')
603 return -1;
605 PROFILE_GetWineIniString( "spooler", pszOutput, "",
606 psCmd, sizeof(psCmd) );
607 printf("Got printerSpoolCommand \"%s\"\n",psCmd);
608 if (!*psCmd)
609 psCmdP = pszOutput;
610 else
612 while (*psCmdP && isspace(*psCmdP))
614 psCmdP++;
616 if (!*psCmdP)
617 return -1;
619 if (*psCmdP == '|')
621 int fds[2];
622 if (pipe(fds))
623 return -1;
624 if (fork() == 0)
626 psCmdP++;
628 printf("In child need to exec %s\n",psCmdP);
629 close(0);
630 dup2(fds[0],0);
631 close (fds[1]);
632 system(psCmdP);
633 exit(0);
636 close (fds[0]);
637 fd = fds[1];
638 printf("Need to execute a command and pipe the output to it\n");
640 else
642 printf("Just assume its a file\n");
644 if ((fd = open(psCmdP, O_CREAT | O_TRUNC | O_WRONLY , 0600)) < 0)
646 printf("Failed to create spool file %s, errno = %d\n", psCmdP, errno);
649 return fd;
652 static int FreePrintJob(HANDLE16 hJob)
654 int nRet = SP_ERROR;
655 PPRINTJOB pPrintJob;
657 pPrintJob = FindPrintJobFromHandle(hJob);
658 if (pPrintJob != NULL)
660 gPrintJobsTable[pPrintJob->nIndex] = NULL;
661 free(pPrintJob->pszOutput);
662 free(pPrintJob->pszTitle);
663 if (pPrintJob->fd >= 0) close(pPrintJob->fd);
664 free(pPrintJob);
665 nRet = SP_OK;
667 return nRet;
670 HANDLE16 WINAPI OpenJob(LPSTR lpOutput, LPSTR lpTitle, HDC16 hDC)
672 HANDLE16 hHandle = (HANDLE16)SP_ERROR;
673 PPRINTJOB pPrintJob;
675 dprintf_win16drv(stddeb, "OpenJob: \"%s\" \"%s\" %04x\n", lpOutput, lpTitle, hDC);
677 pPrintJob = gPrintJobsTable[0];
678 if (pPrintJob == NULL)
680 int fd;
682 /* Try an create a spool file */
683 fd = CreateSpoolFile(lpOutput);
684 if (fd >= 0)
686 hHandle = 1;
688 pPrintJob = malloc(sizeof(PRINTJOB));
689 memset(pPrintJob, 0, sizeof(PRINTJOB));
691 pPrintJob->pszOutput = strdup(lpOutput);
692 pPrintJob->pszTitle = strdup(lpTitle);
693 pPrintJob->hDC = hDC;
694 pPrintJob->fd = fd;
695 pPrintJob->nIndex = 0;
696 pPrintJob->hHandle = hHandle;
697 gPrintJobsTable[pPrintJob->nIndex] = pPrintJob;
700 dprintf_win16drv(stddeb, "OpenJob: return %04x\n", hHandle);
701 return hHandle;
704 int WINAPI CloseJob(HANDLE16 hJob)
706 int nRet = SP_ERROR;
707 PPRINTJOB pPrintJob = NULL;
709 dprintf_win16drv(stddeb, "CloseJob: %04x\n", hJob);
711 pPrintJob = FindPrintJobFromHandle(hJob);
712 if (pPrintJob != NULL)
714 /* Close the spool file */
715 close(pPrintJob->fd);
716 FreePrintJob(hJob);
717 nRet = 1;
719 return nRet;
722 int WINAPI WriteSpool(HANDLE16 hJob, LPSTR lpData, WORD cch)
724 int nRet = SP_ERROR;
725 PPRINTJOB pPrintJob = NULL;
727 dprintf_win16drv(stddeb, "WriteSpool: %04x %08lx %04x\n", hJob, (DWORD)lpData, cch);
729 pPrintJob = FindPrintJobFromHandle(hJob);
730 if (pPrintJob != NULL && pPrintJob->fd >= 0 && cch)
732 if (write(pPrintJob->fd, lpData, cch) != cch)
733 nRet = SP_OUTOFDISK;
734 else
735 nRet = cch;
737 return nRet;
740 int WINAPI WriteDialog(HANDLE16 hJob, LPSTR lpMsg, WORD cchMsg)
742 int nRet = 0;
744 dprintf_win16drv(stddeb, "WriteDialog: %04x %04x \"%s\"\n", hJob, cchMsg, lpMsg);
746 nRet = MessageBox16(0, lpMsg, "Printing Error", MB_OKCANCEL);
747 return nRet;
750 int WINAPI DeleteJob(HANDLE16 hJob, WORD wNotUsed)
752 int nRet;
754 dprintf_win16drv(stddeb, "DeleteJob: %04x\n", hJob);
756 nRet = FreePrintJob(hJob);
757 return nRet;
761 * The following two function would allow a page to be sent to the printer
762 * when it has been processed. For simplicity they havn't been implemented.
763 * This means a whole job has to be processed before it is sent to the printer.
765 int WINAPI StartSpoolPage(HANDLE16 hJob)
767 dprintf_win16drv(stddeb, "StartSpoolPage GDI.246 unimplemented\n");
768 return 1;
771 int WINAPI EndSpoolPage(HANDLE16 hJob)
773 dprintf_win16drv(stddeb, "EndSpoolPage GDI.247 unimplemented\n");
774 return 1;
778 DWORD WINAPI GetSpoolJob(int nOption, LONG param)
780 DWORD retval = 0;
781 dprintf_win16drv(stddeb, "In GetSpoolJob param 0x%lx noption %d\n",param, nOption);
782 return retval;