2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
10 #include <sys/types.h>
26 #define SUPPORT_REALIZED_FONTS 1
35 } EXTTEXTDATA
, *LPEXTTEXTDATA
;
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
=
54 WIN16DRV_CreateDC
, /* pCreateDC */
56 NULL
, /* pDeleteObject */
57 WIN16DRV_Ellipse
, /* pEllipse */
58 WIN16DRV_EnumDeviceFonts
, /* pEnumDeviceFonts */
59 WIN16DRV_Escape
, /* pEscape */
60 NULL
, /* pExcludeClipRect */
61 NULL
, /* pExcludeVisRect */
62 NULL
, /* pExtFloodFill */
63 WIN16DRV_ExtTextOut
, /* pExtTextOut */
64 WIN16DRV_GetCharWidth
, /* pGetCharWidth */
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 */
76 WIN16DRV_PatBlt
, /* pPatBlt */
78 NULL
, /* pPolyPolygon */
79 WIN16DRV_Polygon
, /* pPolygon */
80 WIN16DRV_Polyline
, /* pPolyline */
81 NULL
, /* pRealizePalette */
82 WIN16DRV_Rectangle
, /* pRectangle */
83 NULL
, /* pRestoreDC */
84 NULL
, /* pRoundRect */
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 */
98 NULL
, /* pSetPolyFillMode */
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 /**********************************************************************
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;
162 BOOL32
WIN16DRV_CreateDC( DC
*dc
, LPCSTR driver
, LPCSTR device
, LPCSTR output
,
163 const DEVMODE16
* initData
)
165 LOADED_PRINTER_DRIVER
*pLPD
;
167 DeviceCaps
*printerDevCaps
;
169 PDEVICE_HEADER
*pPDH
;
170 WIN16DRV_PDEVICE
*physDev
;
171 char printerEnabled
[20];
172 PROFILE_GetWineIniString( "wine", "printer", "off",
173 printerEnabled
, sizeof(printerEnabled
) );
174 if (lstrcmpi32A(printerEnabled
,"on"))
176 printf("WIN16DRV_CreateDC disabled in wine.conf file\n");
180 TRACE(win16drv
, "In creatdc for (%s,%s,%s) initData 0x%p\n",driver
, device
, output
, initData
);
182 physDev
= (WIN16DRV_PDEVICE
*)HeapAlloc( SystemHeap
, 0, sizeof(*physDev
) );
183 if (!physDev
) return FALSE
;
184 dc
->physDev
= physDev
;
186 pLPD
= LoadPrinterDriver(driver
);
189 WARN(win16drv
, "Failed to find printer driver\n");
190 HeapFree( SystemHeap
, 0, physDev
);
193 TRACE(win16drv
, "windevCreateDC pLPD 0x%p\n", pLPD
);
195 /* Now Get the device capabilities from the printer driver */
197 printerDevCaps
= (DeviceCaps
*) malloc(sizeof(DeviceCaps
));
198 memset(printerDevCaps
, 0, sizeof(DeviceCaps
));
200 /* Get GDIINFO which is the same as a DeviceCaps structure */
201 wRet
= PRTDRV_Enable(printerDevCaps
, GETGDIINFO
, device
, driver
, output
,NULL
);
203 /* Add this to the DC */
204 dc
->w
.devCaps
= printerDevCaps
;
205 dc
->w
.hVisRgn
= CreateRectRgn32(0, 0, dc
->w
.devCaps
->horzRes
, dc
->w
.devCaps
->vertRes
);
206 dc
->w
.bitsPerPixel
= dc
->w
.devCaps
->bitsPixel
;
208 printf("Got devcaps width %d height %d bits %d planes %d\n",
209 dc
->w
.devCaps
->horzRes
,
210 dc
->w
.devCaps
->vertRes
,
211 dc
->w
.devCaps
->bitsPixel
,
212 dc
->w
.devCaps
->planes
);
214 /* Now we allocate enough memory for the PDEVICE structure */
215 /* The size of this varies between printer drivers */
216 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
217 /* be accessable from 16 bit code */
218 nPDEVICEsize
= dc
->w
.devCaps
->pdeviceSize
+ sizeof(PDEVICE_HEADER
);
220 /* TTD Shouldn't really do pointer arithmetic on segment points */
221 physDev
->segptrPDEVICE
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, nPDEVICEsize
))+sizeof(PDEVICE_HEADER
);
222 *((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+0) = 'N';
223 *((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
)+1) = 'B';
225 /* Set up the header */
226 pPDH
= (PDEVICE_HEADER
*)((BYTE
*)PTR_SEG_TO_LIN(physDev
->segptrPDEVICE
) - sizeof(PDEVICE_HEADER
));
229 TRACE(win16drv
, "PDEVICE allocated %08lx\n",(DWORD
)(physDev
->segptrPDEVICE
));
231 /* Now get the printer driver to initialise this data */
232 wRet
= PRTDRV_Enable((LPVOID
)physDev
->segptrPDEVICE
, INITPDEVICE
, device
, driver
, output
, NULL
);
234 physDev
->FontInfo
= NULL
;
235 physDev
->BrushInfo
= NULL
;
236 physDev
->PenInfo
= NULL
;
237 win16drv_SegPtr_TextXForm
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(TEXTXFORM16
)));
238 win16drv_TextXFormP
= PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm
);
240 InitTextXForm(win16drv_TextXFormP
);
242 /* TTD Lots more to do here */
243 win16drv_SegPtr_DrawMode
= WIN16_GlobalLock16(GlobalAlloc16(GHND
, sizeof(DRAWMODE
)));
244 win16drv_DrawModeP
= PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode
);
246 InitDrawMode(win16drv_DrawModeP
);
251 BOOL32
WIN16DRV_PatBlt( struct tagDC
*dc
, INT32 left
, INT32 top
,
252 INT32 width
, INT32 height
, DWORD rop
)
255 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
258 bRet
= PRTDRV_StretchBlt( physDev
->segptrPDEVICE
, left
, top
, width
, height
, (SEGPTR
)NULL
, 0, 0, width
, height
,
259 PATCOPY
, physDev
->BrushInfo
, win16drv_SegPtr_DrawMode
, NULL
);
266 static INT32
WIN16DRV_Escape( DC
*dc
, INT32 nEscape
, INT32 cbInput
,
267 SEGPTR lpInData
, SEGPTR lpOutData
)
269 WIN16DRV_PDEVICE
*physDev
= (WIN16DRV_PDEVICE
*)dc
->physDev
;
272 /* We should really process the nEscape parameter, but for now just
273 pass it all to the driver */
274 if (dc
!= NULL
&& physDev
->segptrPDEVICE
!= 0)
278 case ENABLEPAIRKERNING
:
279 fprintf(stderr
,"Escape: ENABLEPAIRKERNING ignored.\n");
282 case GETPAIRKERNTABLE
:
283 fprintf(stderr
,"Escape: GETPAIRKERNTABLE ignored.\n");
287 printf("Escape: SetAbortProc ignored should be stored in dc somewhere\n");
288 /* Make calling application believe this worked */
294 LPPOINT16 newInData
= SEGPTR_NEW(POINT16
);
296 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
297 SEGPTR_GET(newInData
), lpOutData
);
298 SEGPTR_FREE(newInData
);
302 case GETEXTENDEDTEXTMETRICS
:
304 EXTTEXTDATA
*textData
= SEGPTR_NEW(EXTTEXTDATA
);
306 textData
->nSize
= cbInput
;
307 textData
->lpindata
= lpInData
;
308 textData
->lpFont
= SEGPTR_GET( physDev
->FontInfo
);
309 textData
->lpXForm
= win16drv_SegPtr_TextXForm
;
310 textData
->lpDrawMode
= win16drv_SegPtr_DrawMode
;
311 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
312 SEGPTR_GET(textData
), lpOutData
);
313 SEGPTR_FREE(textData
);
317 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
318 lpInData
, lpOutData
);
321 HDC32
*tmpHdc
= SEGPTR_NEW(HDC32
);
323 #define SETPRINTERDC SETABORTPROC
326 PRTDRV_Control(physDev
->segptrPDEVICE
, SETPRINTERDC
,
327 SEGPTR_GET(tmpHdc
), (SEGPTR
)NULL
);
332 nRet
= PRTDRV_Control(physDev
->segptrPDEVICE
, nEscape
,
333 lpInData
, lpOutData
);
338 fprintf(stderr
, "Escape(nEscape = %04x)\n", nEscape
);
345 /****************** misc. printer releated functions */
348 * The following function should implement a queing system
360 static struct hpq
*hpqueue
;
362 HPQ WINAPI
CreatePQ(int size
)
364 printf("CreatePQ: %d\n",size
);
367 int WINAPI
DeletePQ(HPQ hPQ
)
369 printf("DeletePQ: %x\n", hPQ
);
372 int WINAPI
ExtractPQ(HPQ hPQ
)
374 struct hpq
*queue
, *prev
, *current
, *currentPrev
;
375 int key
= 0, tag
= -1;
376 currentPrev
= prev
= NULL
;
377 queue
= current
= hpqueue
;
383 currentPrev
= current
;
384 current
= current
->next
;
387 if (current
->key
< key
)
399 prev
->next
= queue
->next
;
401 hpqueue
= queue
->next
;
405 printf("ExtractPQ: %x got tag %d key %d\n", hPQ
, tag
, key
);
410 int WINAPI
InsertPQ(HPQ hPQ
, int tag
, int key
)
412 struct hpq
*queueItem
= malloc(sizeof(struct hpq
));
413 queueItem
->next
= hpqueue
;
415 queueItem
->key
= key
;
416 queueItem
->tag
= tag
;
418 printf("InsertPQ: %x %d %d\n", hPQ
, tag
, key
);
421 int WINAPI
MinPQ(HPQ hPQ
)
423 printf("MinPQ: %x\n", hPQ
);
426 int WINAPI
SizePQ(HPQ hPQ
, int sizechange
)
428 printf("SizePQ: %x %d\n", hPQ
, sizechange
);
433 * The following functions implement part of the spooling process to
434 * print manager. I would like to see wine have a version of print managers
435 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
438 typedef struct PRINTJOB
446 } PRINTJOB
, *PPRINTJOB
;
448 #define MAX_PRINT_JOBS 1
451 PPRINTJOB gPrintJobsTable
[MAX_PRINT_JOBS
];
454 static PPRINTJOB
FindPrintJobFromHandle(HANDLE16 hHandle
)
456 return gPrintJobsTable
[0];
459 /* TTD Need to do some DOS->UNIX file conversion here */
460 static int CreateSpoolFile(LPSTR pszOutput
)
464 char *psCmdP
= psCmd
;
466 /* TTD convert the 'output device' into a spool file name */
468 if (pszOutput
== NULL
|| *pszOutput
== '\0')
471 PROFILE_GetWineIniString( "spooler", pszOutput
, "",
472 psCmd
, sizeof(psCmd
) );
473 printf("Got printerSpoolCommand \"%s\" for output device \"%s\"\n",psCmd
, pszOutput
);
478 while (*psCmdP
&& isspace(*psCmdP
))
494 printf("In child need to exec %s\n",psCmdP
);
504 printf("Need to execute a command and pipe the output to it\n");
508 printf("Just assume its a file\n");
510 if ((fd
= open(psCmdP
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600)) < 0)
512 printf("Failed to create spool file %s, errno = %d\n", psCmdP
, errno
);
518 static int FreePrintJob(HANDLE16 hJob
)
523 pPrintJob
= FindPrintJobFromHandle(hJob
);
524 if (pPrintJob
!= NULL
)
526 gPrintJobsTable
[pPrintJob
->nIndex
] = NULL
;
527 free(pPrintJob
->pszOutput
);
528 free(pPrintJob
->pszTitle
);
529 if (pPrintJob
->fd
>= 0) close(pPrintJob
->fd
);
536 HANDLE16 WINAPI
OpenJob(LPSTR lpOutput
, LPSTR lpTitle
, HDC16 hDC
)
538 HANDLE16 hHandle
= (HANDLE16
)SP_ERROR
;
541 TRACE(win16drv
, "\"%s\" \"%s\" %04x\n", lpOutput
, lpTitle
, hDC
);
543 pPrintJob
= gPrintJobsTable
[0];
544 if (pPrintJob
== NULL
)
548 /* Try an create a spool file */
549 fd
= CreateSpoolFile(lpOutput
);
554 pPrintJob
= malloc(sizeof(PRINTJOB
));
555 memset(pPrintJob
, 0, sizeof(PRINTJOB
));
557 pPrintJob
->pszOutput
= strdup(lpOutput
);
558 pPrintJob
->pszTitle
= strdup(lpTitle
);
559 pPrintJob
->hDC
= hDC
;
561 pPrintJob
->nIndex
= 0;
562 pPrintJob
->hHandle
= hHandle
;
563 gPrintJobsTable
[pPrintJob
->nIndex
] = pPrintJob
;
566 TRACE(win16drv
, "return %04x\n", hHandle
);
570 int WINAPI
CloseJob(HANDLE16 hJob
)
573 PPRINTJOB pPrintJob
= NULL
;
575 TRACE(win16drv
, "%04x\n", hJob
);
577 pPrintJob
= FindPrintJobFromHandle(hJob
);
578 if (pPrintJob
!= NULL
)
580 /* Close the spool file */
581 close(pPrintJob
->fd
);
588 int WINAPI
WriteSpool(HANDLE16 hJob
, LPSTR lpData
, WORD cch
)
591 PPRINTJOB pPrintJob
= NULL
;
593 TRACE(win16drv
, "%04x %08lx %04x\n", hJob
, (DWORD
)lpData
, cch
);
595 pPrintJob
= FindPrintJobFromHandle(hJob
);
596 if (pPrintJob
!= NULL
&& pPrintJob
->fd
>= 0 && cch
)
598 if (write(pPrintJob
->fd
, lpData
, cch
) != cch
)
606 int WINAPI
WriteDialog(HANDLE16 hJob
, LPSTR lpMsg
, WORD cchMsg
)
610 TRACE(win16drv
, "%04x %04x '%s'\n", hJob
, cchMsg
, lpMsg
);
612 nRet
= MessageBox16(0, lpMsg
, "Printing Error", MB_OKCANCEL
);
616 int WINAPI
DeleteJob(HANDLE16 hJob
, WORD wNotUsed
)
620 TRACE(win16drv
, "%04x\n", hJob
);
622 nRet
= FreePrintJob(hJob
);
627 * The following two function would allow a page to be sent to the printer
628 * when it has been processed. For simplicity they havn't been implemented.
629 * This means a whole job has to be processed before it is sent to the printer.
631 int WINAPI
StartSpoolPage(HANDLE16 hJob
)
633 FIXME(win16drv
, "StartSpoolPage GDI.246 unimplemented\n");
637 int WINAPI
EndSpoolPage(HANDLE16 hJob
)
639 FIXME(win16drv
, "EndSpoolPage GDI.247 unimplemented\n");
644 DWORD WINAPI
GetSpoolJob(int nOption
, LONG param
)
647 TRACE(win16drv
, "In GetSpoolJob param 0x%lx noption %d\n",param
, nOption
);