2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
10 #include <sys/types.h>
27 #define SUPPORT_REALIZED_FONTS 1
36 } EXTTEXTDATA
, *LPEXTTEXTDATA
;
39 SEGPTR win16drv_SegPtr_TextXForm
;
40 LPTEXTXFORM16 win16drv_TextXFormP
;
41 SEGPTR win16drv_SegPtr_DrawMode
;
42 LPDRAWMODE win16drv_DrawModeP
;
45 static BOOL32
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
,
46 LPCSTR output
, const DEVMODE16
* initData
);
47 static INT32
WIN16DRV_Escape( DC
*dc
, INT32 nEscape
, INT32 cbInput
,
48 SEGPTR lpInData
, SEGPTR lpOutData
);
50 static const DC_FUNCTIONS WIN16DRV_Funcs
=
55 WIN16DRV_CreateDC
, /* pCreateDC */
57 NULL
, /* pDeleteObject */
58 WIN16DRV_Ellipse
, /* pEllipse */
59 WIN16DRV_EnumDeviceFonts
, /* pEnumDeviceFonts */
60 WIN16DRV_Escape
, /* pEscape */
61 NULL
, /* pExcludeClipRect */
62 NULL
, /* pExcludeVisRect */
63 NULL
, /* pExtFloodFill */
64 WIN16DRV_ExtTextOut
, /* pExtTextOut */
65 WIN16DRV_GetCharWidth
, /* pGetCharWidth */
67 WIN16DRV_GetTextExtentPoint
, /* pGetTextExtentPoint */
68 WIN16DRV_GetTextMetrics
, /* pGetTextMetrics */
69 NULL
, /* pIntersectClipRect */
70 NULL
, /* pIntersectVisRect */
71 WIN16DRV_LineTo
, /* pLineTo */
72 WIN16DRV_MoveToEx
, /* pMoveToEx */
73 NULL
, /* pOffsetClipRgn */
74 NULL
, /* pOffsetViewportOrgEx */
75 NULL
, /* pOffsetWindowOrgEx */
77 WIN16DRV_PatBlt
, /* pPatBlt */
79 NULL
, /* pPolyPolygon */
80 WIN16DRV_Polygon
, /* pPolygon */
81 WIN16DRV_Polyline
, /* pPolyline */
82 NULL
, /* pRealizePalette */
83 WIN16DRV_Rectangle
, /* pRectangle */
84 NULL
, /* pRestoreDC */
85 NULL
, /* pRoundRect */
87 NULL
, /* pScaleViewportExtEx */
88 NULL
, /* pScaleWindowExtEx */
89 NULL
, /* pSelectClipRgn */
90 WIN16DRV_SelectObject
, /* pSelectObject */
91 NULL
, /* pSelectPalette */
92 NULL
, /* pSetBkColor */
93 NULL
, /* pSetBkMode */
94 NULL
, /* pSetDeviceClipping */
95 NULL
, /* pSetDIBitsToDevice */
96 NULL
, /* pSetMapMode */
97 NULL
, /* pSetMapperFlags */
99 NULL
, /* pSetPolyFillMode */
101 NULL
, /* pSetRelAbs */
102 NULL
, /* pSetStretchBltMode */
103 NULL
, /* pSetTextAlign */
104 NULL
, /* pSetTextCharacterExtra */
105 NULL
, /* pSetTextColor */
106 NULL
, /* pSetTextJustification */
107 NULL
, /* pSetViewportExtEx */
108 NULL
, /* pSetViewportOrgEx */
109 NULL
, /* pSetWindowExtEx */
110 NULL
, /* pSetWindowOrgEx */
111 NULL
, /* pStretchBlt */
112 NULL
/* pStretchDIBits */
119 /**********************************************************************
122 BOOL32
WIN16DRV_Init(void)
124 return DRIVER_RegisterDriver( NULL
/* generic driver */, &WIN16DRV_Funcs
);
128 /* Tempory functions, for initialising structures */
129 /* These values should be calculated, not hardcoded */
130 void InitTextXForm(LPTEXTXFORM16 lpTextXForm
)
132 lpTextXForm
->txfHeight
= 0x0001;
133 lpTextXForm
->txfWidth
= 0x000c;
134 lpTextXForm
->txfEscapement
= 0x0000;
135 lpTextXForm
->txfOrientation
= 0x0000;
136 lpTextXForm
->txfWeight
= 0x0190;
137 lpTextXForm
->txfItalic
= 0x00;
138 lpTextXForm
->txfUnderline
= 0x00;
139 lpTextXForm
->txfStrikeOut
= 0x00;
140 lpTextXForm
->txfOutPrecision
= 0x02;
141 lpTextXForm
->txfClipPrecision
= 0x01;
142 lpTextXForm
->txfAccelerator
= 0x0001;
143 lpTextXForm
->txfOverhang
= 0x0000;
147 void InitDrawMode(LPDRAWMODE lpDrawMode
)
149 lpDrawMode
->Rop2
= 0x000d;
150 lpDrawMode
->bkMode
= 0x0001;
151 lpDrawMode
->bkColor
= 0x3fffffff;
152 lpDrawMode
->TextColor
= 0x20000000;
153 lpDrawMode
->TBreakExtra
= 0x0000;
154 lpDrawMode
->BreakExtra
= 0x0000;
155 lpDrawMode
->BreakErr
= 0x0000;
156 lpDrawMode
->BreakRem
= 0x0000;
157 lpDrawMode
->BreakCount
= 0x0000;
158 lpDrawMode
->CharExtra
= 0x0000;
159 lpDrawMode
->LbkColor
= 0x00ffffff;
160 lpDrawMode
->LTextColor
= 0x00000000;
163 BOOL32
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
, LPCSTR output
,
164 const DEVMODE16
* initData
)
166 LOADED_PRINTER_DRIVER
*pLPD
;
168 DeviceCaps
*printerDevCaps
;
170 PDEVICE_HEADER
*pPDH
;
171 WIN16DRV_PDEVICE
*physDev
;
172 char printerEnabled
[20];
173 PROFILE_GetWineIniString( "wine", "printer", "off",
174 printerEnabled
, sizeof(printerEnabled
) );
175 if (lstrcmpi32A(printerEnabled
,"on"))
177 printf("WIN16DRV_CreateDC disabled in wine.conf file\n");
181 dprintf_win16drv(stddeb
, "In creatdc for (%s,%s,%s) initData 0x%p\n",driver
, device
, output
, initData
);
183 physDev
= (WIN16DRV_PDEVICE
*)HeapAlloc( SystemHeap
, 0, sizeof(*physDev
) );
184 if (!physDev
) return FALSE
;
185 dc
->physDev
= physDev
;
187 pLPD
= LoadPrinterDriver(driver
);
190 dprintf_win16drv(stddeb
, "LPGDI_CreateDC: Failed to find printer driver\n");
191 HeapFree( SystemHeap
, 0, physDev
);
194 dprintf_win16drv(stddeb
, "windevCreateDC pLPD 0x%p\n", pLPD
);
196 /* Now Get the device capabilities from the printer driver */
198 printerDevCaps
= (DeviceCaps
*) malloc(sizeof(DeviceCaps
));
199 memset(printerDevCaps
, 0, sizeof(DeviceCaps
));
201 /* Get GDIINFO which is the same as a DeviceCaps structure */
202 wRet
= PRTDRV_Enable(printerDevCaps
, GETGDIINFO
, device
, driver
, output
,NULL
);
204 /* Add this to the DC */
205 dc
->w
.devCaps
= printerDevCaps
;
206 dc
->w
.hVisRgn
= CreateRectRgn32(0, 0, dc
->w
.devCaps
->horzRes
, dc
->w
.devCaps
->vertRes
);
207 dc
->w
.bitsPerPixel
= dc
->w
.devCaps
->bitsPixel
;
209 printf("Got devcaps width %d height %d bits %d planes %d\n",
210 dc
->w
.devCaps
->horzRes
,
211 dc
->w
.devCaps
->vertRes
,
212 dc
->w
.devCaps
->bitsPixel
,
213 dc
->w
.devCaps
->planes
);
215 /* Now we allocate enough memory for the PDEVICE structure */
216 /* The size of this varies between printer drivers */
217 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
218 /* be accessable from 16 bit code */
219 nPDEVICEsize
= dc
->w
.devCaps
->pdeviceSize
+ sizeof(PDEVICE_HEADER
);
221 /* TTD Shouldn't really do pointer arithmetic on segment points */
222 physDev
->segptrPDEVICE
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nPDEVICEsize
))+sizeof(PDEVICE_HEADER
);
223 *((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+0) = 'N';
224 *((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+1) = 'B';
226 /* Set up the header */
227 pPDH
= (PDEVICE_HEADER
*)((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
) - sizeof(PDEVICE_HEADER
));
230 dprintf_win16drv(stddeb
, "PRTDRV_Enable: PDEVICE allocated %08lx\n",(DWORD
)(physDev
->segptrPDEVICE
));
232 /* Now get the printer driver to initialise this data */
233 wRet
= PRTDRV_Enable((LPVOID
)physDev
->segptrPDEVICE
, INITPDEVICE
, device
, driver
, output
, NULL
);
235 physDev
->FontInfo
= NULL
;
236 physDev
->BrushInfo
= NULL
;
237 physDev
->PenInfo
= NULL
;
238 win16drv_SegPtr_TextXForm
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(TEXTXFORM16
)));
239 win16drv_TextXFormP
= PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm
);
241 InitTextXForm(win16drv_TextXFormP
);
243 /* TTD Lots more to do here */
244 win16drv_SegPtr_DrawMode
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(DRAWMODE
)));
245 win16drv_DrawModeP
= PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode
);
247 InitDrawMode(win16drv_DrawModeP
);
252 BOOL32
WIN16DRV_PatBlt( struct tagDC
*dc
, INT32 left
, INT32 top
,
253 INT32 width
, INT32 height
, DWORD rop
)
256 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
259 bRet
= PRTDRV_StretchBlt( physDev
->segptrPDEVICE
, left
, top
, width
, height
, (SEGPTR
)NULL
, 0, 0, width
, height
,
260 PATCOPY
, physDev
->BrushInfo
, win16drv_SegPtr_DrawMode
, NULL
);
267 static INT32
WIN16DRV_Escape( DC
*dc
, INT32 nEscape
, INT32 cbInput
,
268 SEGPTR lpInData
, SEGPTR lpOutData
)
270 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
273 /* We should really process the nEscape parameter, but for now just
274 pass it all to the driver */
275 if (dc
!= NULL
&& physDev
->segptrPDEVICE
!= 0)
279 case ENABLEPAIRKERNING
:
280 fprintf(stderr
,"Escape: ENABLEPAIRKERNING ignored.\n");
283 case GETPAIRKERNTABLE
:
284 fprintf(stderr
,"Escape: GETPAIRKERNTABLE ignored.\n");
288 printf("Escape: SetAbortProc ignored should be stored in dc somewhere\n");
289 /* Make calling application believe this worked */
295 LPPOINT16 newInData
= SEGPTR_NEW(POINT16
);
297 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
298 SEGPTR_GET(newInData
), lpOutData
);
299 SEGPTR_FREE(newInData
);
303 case GETEXTENDEDTEXTMETRICS
:
305 EXTTEXTDATA
*textData
= SEGPTR_NEW(EXTTEXTDATA
);
307 textData
->nSize
= cbInput
;
308 textData
->lpindata
= lpInData
;
309 textData
->lpFont
= SEGPTR_GET( physDev
->FontInfo
);
310 textData
->lpXForm
= win16drv_SegPtr_TextXForm
;
311 textData
->lpDrawMode
= win16drv_SegPtr_DrawMode
;
312 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
313 SEGPTR_GET(textData
), lpOutData
);
314 SEGPTR_FREE(textData
);
318 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
319 lpInData
, lpOutData
);
322 HDC32
*tmpHdc
= SEGPTR_NEW(HDC32
);
324 #define SETPRINTERDC SETABORTPROC
327 PRTDRV_Control(physDev
->segptrPDEVICE
, SETPRINTERDC
,
328 SEGPTR_GET(tmpHdc
), (SEGPTR
)NULL
);
333 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
334 lpInData
, lpOutData
);
339 fprintf(stderr
, "Escape(nEscape = %04x)\n", nEscape
);
346 /****************** misc. printer releated functions */
349 * The following function should implement a queing system
361 static struct hpq
*hpqueue
;
363 HPQ WINAPI
CreatePQ(int size
)
365 printf("CreatePQ: %d\n",size
);
368 int WINAPI
DeletePQ(HPQ hPQ
)
370 printf("DeletePQ: %x\n", hPQ
);
373 int WINAPI
ExtractPQ(HPQ hPQ
)
375 struct hpq
*queue
, *prev
, *current
, *currentPrev
;
376 int key
= 0, tag
= -1;
377 currentPrev
= prev
= NULL
;
378 queue
= current
= hpqueue
;
384 currentPrev
= current
;
385 current
= current
->next
;
388 if (current
->key
< key
)
400 prev
->next
= queue
->next
;
402 hpqueue
= queue
->next
;
406 printf("ExtractPQ: %x got tag %d key %d\n", hPQ
, tag
, key
);
411 int WINAPI
InsertPQ(HPQ hPQ
, int tag
, int key
)
413 struct hpq
*queueItem
= malloc(sizeof(struct hpq
));
414 queueItem
->next
= hpqueue
;
416 queueItem
->key
= key
;
417 queueItem
->tag
= tag
;
419 printf("InsertPQ: %x %d %d\n", hPQ
, tag
, key
);
422 int WINAPI
MinPQ(HPQ hPQ
)
424 printf("MinPQ: %x\n", hPQ
);
427 int WINAPI
SizePQ(HPQ hPQ
, int sizechange
)
429 printf("SizePQ: %x %d\n", hPQ
, sizechange
);
434 * The following functions implement part of the spooling process to
435 * print manager. I would like to see wine have a version of print managers
436 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
439 typedef struct PRINTJOB
447 } PRINTJOB
, *PPRINTJOB
;
449 #define MAX_PRINT_JOBS 1
452 PPRINTJOB gPrintJobsTable
[MAX_PRINT_JOBS
];
455 static PPRINTJOB
FindPrintJobFromHandle(HANDLE16 hHandle
)
457 return gPrintJobsTable
[0];
460 /* TTD Need to do some DOS->UNIX file conversion here */
461 static int CreateSpoolFile(LPSTR pszOutput
)
465 char *psCmdP
= psCmd
;
467 /* TTD convert the 'output device' into a spool file name */
469 if (pszOutput
== NULL
|| *pszOutput
== '\0')
472 PROFILE_GetWineIniString( "spooler", pszOutput
, "",
473 psCmd
, sizeof(psCmd
) );
474 printf("Got printerSpoolCommand \"%s\"\n",psCmd
);
479 while (*psCmdP
&& isspace(*psCmdP
))
495 printf("In child need to exec %s\n",psCmdP
);
505 printf("Need to execute a command and pipe the output to it\n");
509 printf("Just assume its a file\n");
511 if ((fd
= open(psCmdP
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600)) < 0)
513 printf("Failed to create spool file %s, errno = %d\n", psCmdP
, errno
);
519 static int FreePrintJob(HANDLE16 hJob
)
524 pPrintJob
= FindPrintJobFromHandle(hJob
);
525 if (pPrintJob
!= NULL
)
527 gPrintJobsTable
[pPrintJob
->nIndex
] = NULL
;
528 free(pPrintJob
->pszOutput
);
529 free(pPrintJob
->pszTitle
);
530 if (pPrintJob
->fd
>= 0) close(pPrintJob
->fd
);
537 HANDLE16 WINAPI
OpenJob(LPSTR lpOutput
, LPSTR lpTitle
, HDC16 hDC
)
539 HANDLE16 hHandle
= (HANDLE16
)SP_ERROR
;
542 dprintf_win16drv(stddeb
, "OpenJob: \"%s\" \"%s\" %04x\n", lpOutput
, lpTitle
, hDC
);
544 pPrintJob
= gPrintJobsTable
[0];
545 if (pPrintJob
== NULL
)
549 /* Try an create a spool file */
550 fd
= CreateSpoolFile(lpOutput
);
555 pPrintJob
= malloc(sizeof(PRINTJOB
));
556 memset(pPrintJob
, 0, sizeof(PRINTJOB
));
558 pPrintJob
->pszOutput
= strdup(lpOutput
);
559 pPrintJob
->pszTitle
= strdup(lpTitle
);
560 pPrintJob
->hDC
= hDC
;
562 pPrintJob
->nIndex
= 0;
563 pPrintJob
->hHandle
= hHandle
;
564 gPrintJobsTable
[pPrintJob
->nIndex
] = pPrintJob
;
567 dprintf_win16drv(stddeb
, "OpenJob: return %04x\n", hHandle
);
571 int WINAPI
CloseJob(HANDLE16 hJob
)
574 PPRINTJOB pPrintJob
= NULL
;
576 dprintf_win16drv(stddeb
, "CloseJob: %04x\n", hJob
);
578 pPrintJob
= FindPrintJobFromHandle(hJob
);
579 if (pPrintJob
!= NULL
)
581 /* Close the spool file */
582 close(pPrintJob
->fd
);
589 int WINAPI
WriteSpool(HANDLE16 hJob
, LPSTR lpData
, WORD cch
)
592 PPRINTJOB pPrintJob
= NULL
;
594 dprintf_win16drv(stddeb
, "WriteSpool: %04x %08lx %04x\n", hJob
, (DWORD
)lpData
, cch
);
596 pPrintJob
= FindPrintJobFromHandle(hJob
);
597 if (pPrintJob
!= NULL
&& pPrintJob
->fd
>= 0 && cch
)
599 if (write(pPrintJob
->fd
, lpData
, cch
) != cch
)
607 int WINAPI
WriteDialog(HANDLE16 hJob
, LPSTR lpMsg
, WORD cchMsg
)
611 dprintf_win16drv(stddeb
, "WriteDialog: %04x %04x \"%s\"\n", hJob
, cchMsg
, lpMsg
);
613 nRet
= MessageBox16(0, lpMsg
, "Printing Error", MB_OKCANCEL
);
617 int WINAPI
DeleteJob(HANDLE16 hJob
, WORD wNotUsed
)
621 dprintf_win16drv(stddeb
, "DeleteJob: %04x\n", hJob
);
623 nRet
= FreePrintJob(hJob
);
628 * The following two function would allow a page to be sent to the printer
629 * when it has been processed. For simplicity they havn't been implemented.
630 * This means a whole job has to be processed before it is sent to the printer.
632 int WINAPI
StartSpoolPage(HANDLE16 hJob
)
634 dprintf_win16drv(stddeb
, "StartSpoolPage GDI.246 unimplemented\n");
638 int WINAPI
EndSpoolPage(HANDLE16 hJob
)
640 dprintf_win16drv(stddeb
, "EndSpoolPage GDI.247 unimplemented\n");
645 DWORD WINAPI
GetSpoolJob(int nOption
, LONG param
)
648 dprintf_win16drv(stddeb
, "In GetSpoolJob param 0x%lx noption %d\n",param
, nOption
);