Moved SystemHeap allocations to the process heap.
[wine.git] / graphics / win16drv / init.c
blobe089035426bdc8dbb2343fb714a159baa290e195
1 /*
2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
5 * 1998 Huw Davies
6 */
8 #include <string.h>
9 #include <ctype.h>
10 #include "win16drv.h"
11 #include "gdi.h"
12 #include "bitmap.h"
13 #include "heap.h"
14 #include "font.h"
15 #include "options.h"
16 #include "xmalloc.h"
17 #include "debugtools.h"
18 #include "dc.h"
20 DEFAULT_DEBUG_CHANNEL(win16drv)
22 #define SUPPORT_REALIZED_FONTS 1
23 #include "pshpack1.h"
24 typedef struct
26 SHORT nSize;
27 SEGPTR lpindata;
28 SEGPTR lpFont;
29 SEGPTR lpXForm;
30 SEGPTR lpDrawMode;
31 } EXTTEXTDATA, *LPEXTTEXTDATA;
32 #include "poppack.h"
34 SEGPTR win16drv_SegPtr_TextXForm;
35 LPTEXTXFORM16 win16drv_TextXFormP;
36 SEGPTR win16drv_SegPtr_DrawMode;
37 LPDRAWMODE win16drv_DrawModeP;
40 static BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
41 LPCSTR output, const DEVMODEA* initData );
42 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
43 SEGPTR lpInData, SEGPTR lpOutData );
45 static const DC_FUNCTIONS WIN16DRV_Funcs =
47 NULL, /* pAbortDoc */
48 NULL, /* pAbortPath */
49 NULL, /* pAngleArc */
50 NULL, /* pArc */
51 NULL, /* pArcTo */
52 NULL, /* pBeginPath */
53 NULL, /* pBitBlt */
54 NULL, /* pBitmapBits */
55 NULL, /* pChord */
56 NULL, /* pCloseFigure */
57 NULL, /* pCreateBitmap */
58 WIN16DRV_CreateDC, /* pCreateDC */
59 NULL, /* pCreateDIBSection */
60 NULL, /* pCreateDIBSection16 */
61 NULL, /* pDeleteDC */
62 NULL, /* pDeleteObject */
63 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
64 WIN16DRV_Ellipse, /* pEllipse */
65 NULL, /* pEndDoc */
66 NULL, /* pEndPage */
67 NULL, /* pEndPath */
68 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
69 WIN16DRV_Escape, /* pEscape */
70 NULL, /* pExcludeClipRect */
71 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
72 NULL, /* pExtFloodFill */
73 WIN16DRV_ExtTextOut, /* pExtTextOut */
74 NULL, /* pFillPath */
75 NULL, /* pFillRgn */
76 NULL, /* pFlattenPath */
77 NULL, /* pFrameRgn */
78 WIN16DRV_GetCharWidth, /* pGetCharWidth */
79 NULL, /* pGetPixel */
80 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
81 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
82 NULL, /* pIntersectClipRect */
83 NULL, /* pInvertRgn */
84 WIN16DRV_LineTo, /* pLineTo */
85 NULL, /* pLoadOEMResource */
86 WIN16DRV_MoveToEx, /* pMoveToEx */
87 NULL, /* pOffsetClipRgn */
88 NULL, /* pOffsetViewportOrgEx */
89 NULL, /* pOffsetWindowOrgEx */
90 NULL, /* pPaintRgn */
91 WIN16DRV_PatBlt, /* pPatBlt */
92 NULL, /* pPie */
93 NULL, /* pPolyBezier */
94 NULL, /* pPolyBezierTo */
95 NULL, /* pPolyDraw */
96 NULL, /* pPolyPolygon */
97 NULL, /* pPolyPolyline */
98 WIN16DRV_Polygon, /* pPolygon */
99 WIN16DRV_Polyline, /* pPolyline */
100 NULL, /* pPolylineTo */
101 NULL, /* pRealizePalette */
102 WIN16DRV_Rectangle, /* pRectangle */
103 NULL, /* pRestoreDC */
104 NULL, /* pRoundRect */
105 NULL, /* pSaveDC */
106 NULL, /* pScaleViewportExtEx */
107 NULL, /* pScaleWindowExtEx */
108 NULL, /* pSelectClipPath */
109 NULL, /* pSelectClipRgn */
110 WIN16DRV_SelectObject, /* pSelectObject */
111 NULL, /* pSelectPalette */
112 NULL, /* pSetBkColor */
113 NULL, /* pSetBkMode */
114 NULL, /* pSetDeviceClipping */
115 NULL, /* pSetDIBitsToDevice */
116 NULL, /* pSetMapMode */
117 NULL, /* pSetMapperFlags */
118 NULL, /* pSetPixel */
119 NULL, /* pSetPolyFillMode */
120 NULL, /* pSetROP2 */
121 NULL, /* pSetRelAbs */
122 NULL, /* pSetStretchBltMode */
123 NULL, /* pSetTextAlign */
124 NULL, /* pSetTextCharacterExtra */
125 NULL, /* pSetTextColor */
126 NULL, /* pSetTextJustification */
127 NULL, /* pSetViewportExtEx */
128 NULL, /* pSetViewportOrgEx */
129 NULL, /* pSetWindowExtEx */
130 NULL, /* pSetWindowOrgEx */
131 NULL, /* pStartDoc */
132 NULL, /* pStartPage */
133 NULL, /* pStretchBlt */
134 NULL, /* pStretchDIBits */
135 NULL, /* pStrokeAndFillPath */
136 NULL, /* pStrokePath */
137 NULL /* pWidenPath */
144 /**********************************************************************
145 * WIN16DRV_Init
147 BOOL WIN16DRV_Init(void)
149 return DRIVER_RegisterDriver( NULL /* generic driver */, &WIN16DRV_Funcs );
153 /* Tempory functions, for initialising structures */
154 /* These values should be calculated, not hardcoded */
155 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
157 lpTextXForm->txfHeight = 0x0001;
158 lpTextXForm->txfWidth = 0x000c;
159 lpTextXForm->txfEscapement = 0x0000;
160 lpTextXForm->txfOrientation = 0x0000;
161 lpTextXForm->txfWeight = 0x0190;
162 lpTextXForm->txfItalic = 0x00;
163 lpTextXForm->txfUnderline = 0x00;
164 lpTextXForm->txfStrikeOut = 0x00;
165 lpTextXForm->txfOutPrecision = 0x02;
166 lpTextXForm->txfClipPrecision = 0x01;
167 lpTextXForm->txfAccelerator = 0x0001;
168 lpTextXForm->txfOverhang = 0x0000;
172 void InitDrawMode(LPDRAWMODE lpDrawMode)
174 lpDrawMode->Rop2 = 0x000d;
175 lpDrawMode->bkMode = 0x0001;
176 lpDrawMode->bkColor = 0x3fffffff;
177 lpDrawMode->TextColor = 0x20000000;
178 lpDrawMode->TBreakExtra = 0x0000;
179 lpDrawMode->BreakExtra = 0x0000;
180 lpDrawMode->BreakErr = 0x0000;
181 lpDrawMode->BreakRem = 0x0000;
182 lpDrawMode->BreakCount = 0x0000;
183 lpDrawMode->CharExtra = 0x0000;
184 lpDrawMode->LbkColor = 0x00ffffff;
185 lpDrawMode->LTextColor = 0x00000000;
186 lpDrawMode->ICMCXform = 0; /* ? */
187 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
188 lpDrawMode->eMiterLimit = 1;
191 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
192 const DEVMODEA* initData )
194 LOADED_PRINTER_DRIVER *pLPD;
195 WORD wRet;
196 DeviceCaps *printerDevCaps;
197 int nPDEVICEsize;
198 PDEVICE_HEADER *pPDH;
199 WIN16DRV_PDEVICE *physDev;
200 char printerEnabled[20];
201 PROFILE_GetWineIniString( "wine", "printer", "off",
202 printerEnabled, sizeof(printerEnabled) );
203 if (lstrcmpiA(printerEnabled,"on"))
205 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
206 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
207 return FALSE;
210 TRACE("In creatdc for (%s,%s,%s) initData 0x%p\n",
211 driver, device, output, initData);
213 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
214 if (!physDev) return FALSE;
215 dc->physDev = physDev;
217 pLPD = LoadPrinterDriver(driver);
218 if (pLPD == NULL)
220 WARN("Failed to find printer driver\n");
221 HeapFree( GetProcessHeap(), 0, physDev );
222 return FALSE;
224 TRACE("windevCreateDC pLPD 0x%p\n", pLPD);
226 /* Now Get the device capabilities from the printer driver */
228 printerDevCaps = (DeviceCaps *) xmalloc(sizeof(DeviceCaps));
229 memset(printerDevCaps, 0, sizeof(DeviceCaps));
231 if(!output) output = "LPT1:";
232 /* Get GDIINFO which is the same as a DeviceCaps structure */
233 wRet = PRTDRV_Enable(printerDevCaps, GETGDIINFO, device, driver, output,NULL);
235 /* Add this to the DC */
236 dc->w.devCaps = printerDevCaps;
237 dc->w.hVisRgn = CreateRectRgn(0, 0, dc->w.devCaps->horzRes, dc->w.devCaps->vertRes);
238 dc->w.bitsPerPixel = dc->w.devCaps->bitsPixel;
240 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
241 dc->w.devCaps->horzRes, dc->w.devCaps->vertRes,
242 dc->w.devCaps->bitsPixel, dc->w.devCaps->planes);
244 /* Now we allocate enough memory for the PDEVICE structure */
245 /* The size of this varies between printer drivers */
246 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
247 /* be accessable from 16 bit code */
248 nPDEVICEsize = dc->w.devCaps->pdeviceSize + sizeof(PDEVICE_HEADER);
250 /* TTD Shouldn't really do pointer arithmetic on segment points */
251 physDev->segptrPDEVICE = WIN16_GlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
252 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+0) = 'N';
253 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+1) = 'B';
255 /* Set up the header */
256 pPDH = (PDEVICE_HEADER *)((BYTE*)PTR_SEG_TO_LIN(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
257 pPDH->pLPD = pLPD;
259 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
261 /* Now get the printer driver to initialise this data */
262 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
264 physDev->FontInfo = NULL;
265 physDev->BrushInfo = NULL;
266 physDev->PenInfo = NULL;
267 win16drv_SegPtr_TextXForm = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
268 win16drv_TextXFormP = PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm);
270 InitTextXForm(win16drv_TextXFormP);
272 /* TTD Lots more to do here */
273 win16drv_SegPtr_DrawMode = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
274 win16drv_DrawModeP = PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode);
276 InitDrawMode(win16drv_DrawModeP);
278 return TRUE;
281 BOOL WIN16DRV_PatBlt( struct tagDC *dc, INT left, INT top,
282 INT width, INT height, DWORD rop )
285 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
286 BOOL bRet = 0;
288 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
289 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
291 return bRet;
294 * Escape (GDI.38)
296 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
297 SEGPTR lpInData, SEGPTR lpOutData )
299 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
300 int nRet = 0;
302 /* We should really process the nEscape parameter, but for now just
303 pass it all to the driver */
304 if (dc != NULL && physDev->segptrPDEVICE != 0)
306 switch(nEscape)
308 case ENABLEPAIRKERNING:
309 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
310 nRet = 1;
311 break;
312 case GETPAIRKERNTABLE:
313 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
314 nRet = 0;
315 break;
316 case SETABORTPROC: {
317 /* FIXME: The AbortProc should be called:
318 - After every write to printer port or spool file
319 - Several times when no more disk space
320 - Before every metafile record when GDI does banding
323 /* Call Control with hdc as lpInData */
324 HDC16 *seghdc = SEGPTR_NEW(HDC16);
325 *seghdc = dc->hSelf;
326 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
327 SEGPTR_GET(seghdc), lpOutData);
328 SEGPTR_FREE(seghdc);
329 break;
332 case NEXTBAND:
334 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
336 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
337 SEGPTR_GET(newInData), lpOutData);
338 SEGPTR_FREE(newInData);
339 break;
342 case GETEXTENDEDTEXTMETRICS:
344 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
346 textData->nSize = cbInput;
347 textData->lpindata = lpInData;
348 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
349 textData->lpXForm = win16drv_SegPtr_TextXForm;
350 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
351 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
352 SEGPTR_GET(textData), lpOutData);
353 SEGPTR_FREE(textData);
355 break;
356 case STARTDOC:
358 /* lpInData is not necessarily \0 terminated so make it so */
359 char *cp = SEGPTR_ALLOC(cbInput + 1);
360 memcpy(cp, PTR_SEG_TO_LIN(lpInData), cbInput);
361 cp[cbInput] = '\0';
363 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
364 SEGPTR_GET(cp), lpOutData);
365 SEGPTR_FREE(cp);
366 if (nRet != -1)
368 HDC *tmpHdc = SEGPTR_NEW(HDC);
370 #define SETPRINTERDC SETABORTPROC
372 *tmpHdc = dc->hSelf;
373 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
374 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
375 SEGPTR_FREE(tmpHdc);
378 break;
379 default:
380 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
381 lpInData, lpOutData);
382 break;
385 else
386 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
387 return nRet;