Use MapLS/UnMapLS instead of SEGPTR_* macros.
[wine/wine-kai.git] / graphics / win16drv / init.c
blobd561a8a567d3f590e42f4f398b803ba26ce1459f
1 /*
2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
5 * 1998 Huw Davies
6 */
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <string.h>
12 #include "winreg.h"
13 #include "win16drv.h"
14 #include "gdi.h"
15 #include "bitmap.h"
16 #include "font.h"
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(win16drv);
21 #define SUPPORT_REALIZED_FONTS 1
22 #include "pshpack1.h"
23 typedef struct
25 SHORT nSize;
26 SEGPTR lpindata;
27 SEGPTR lpFont;
28 SEGPTR lpXForm;
29 SEGPTR lpDrawMode;
30 } EXTTEXTDATA, *LPEXTTEXTDATA;
31 #include "poppack.h"
33 SEGPTR win16drv_SegPtr_TextXForm;
34 LPTEXTXFORM16 win16drv_TextXFormP;
35 SEGPTR win16drv_SegPtr_DrawMode;
36 LPDRAWMODE win16drv_DrawModeP;
39 static BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
40 LPCSTR output, const DEVMODEA* initData );
41 static INT WIN16DRV_GetDeviceCaps( DC *dc, INT cap );
42 static INT WIN16DRV_ExtEscape( DC *dc, INT escape, INT in_count, LPCVOID in_data,
43 INT out_count, LPVOID out_data );
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, /* pChoosePixelFormat */
56 NULL, /* pChord */
57 NULL, /* pCloseFigure */
58 NULL, /* pCreateBitmap */
59 WIN16DRV_CreateDC, /* pCreateDC */
60 NULL, /* pCreateDIBSection */
61 NULL, /* pDeleteDC */
62 NULL, /* pDeleteObject */
63 NULL, /* pDescribePixelFormat */
64 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
65 WIN16DRV_Ellipse, /* pEllipse */
66 NULL, /* pEndDoc */
67 NULL, /* pEndPage */
68 NULL, /* pEndPath */
69 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
70 NULL, /* pExcludeClipRect */
71 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
72 WIN16DRV_ExtEscape, /* pExtEscape */
73 NULL, /* pExtFloodFill */
74 WIN16DRV_ExtTextOut, /* pExtTextOut */
75 NULL, /* pFillPath */
76 NULL, /* pFillRgn */
77 NULL, /* pFlattenPath */
78 NULL, /* pFrameRgn */
79 WIN16DRV_GetCharWidth, /* pGetCharWidth */
80 NULL, /* pGetDCOrgEx */
81 WIN16DRV_GetDeviceCaps, /* pGetDeviceCaps */
82 NULL, /* pGetDeviceGammaRamp */
83 NULL, /* pGetPixel */
84 NULL, /* pGetPixelFormat */
85 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
86 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
87 NULL, /* pIntersectClipRect */
88 NULL, /* pInvertRgn */
89 WIN16DRV_LineTo, /* pLineTo */
90 NULL, /* pMoveTo */
91 NULL, /* pOffsetClipRgn */
92 NULL, /* pOffsetViewportOrgEx */
93 NULL, /* pOffsetWindowOrgEx */
94 NULL, /* pPaintRgn */
95 WIN16DRV_PatBlt, /* pPatBlt */
96 NULL, /* pPie */
97 NULL, /* pPolyBezier */
98 NULL, /* pPolyBezierTo */
99 NULL, /* pPolyDraw */
100 NULL, /* pPolyPolygon */
101 NULL, /* pPolyPolyline */
102 WIN16DRV_Polygon, /* pPolygon */
103 WIN16DRV_Polyline, /* pPolyline */
104 NULL, /* pPolylineTo */
105 NULL, /* pRealizePalette */
106 WIN16DRV_Rectangle, /* pRectangle */
107 NULL, /* pRestoreDC */
108 NULL, /* pRoundRect */
109 NULL, /* pSaveDC */
110 NULL, /* pScaleViewportExtEx */
111 NULL, /* pScaleWindowExtEx */
112 NULL, /* pSelectClipPath */
113 NULL, /* pSelectClipRgn */
114 WIN16DRV_SelectObject, /* pSelectObject */
115 NULL, /* pSelectPalette */
116 NULL, /* pSetBkColor */
117 NULL, /* pSetBkMode */
118 NULL, /* pSetDeviceClipping */
119 NULL, /* pSetDeviceGammaRamp */
120 NULL, /* pSetDIBitsToDevice */
121 NULL, /* pSetMapMode */
122 NULL, /* pSetMapperFlags */
123 NULL, /* pSetPixel */
124 NULL, /* pSetPixelFormat */
125 NULL, /* pSetPolyFillMode */
126 NULL, /* pSetROP2 */
127 NULL, /* pSetRelAbs */
128 NULL, /* pSetStretchBltMode */
129 NULL, /* pSetTextAlign */
130 NULL, /* pSetTextCharacterExtra */
131 NULL, /* pSetTextColor */
132 NULL, /* pSetTextJustification */
133 NULL, /* pSetViewportExtEx */
134 NULL, /* pSetViewportOrgEx */
135 NULL, /* pSetWindowExtEx */
136 NULL, /* pSetWindowOrgEx */
137 NULL, /* pStartDoc */
138 NULL, /* pStartPage */
139 NULL, /* pStretchBlt */
140 NULL, /* pStretchDIBits */
141 NULL, /* pStrokeAndFillPath */
142 NULL, /* pStrokePath */
143 NULL, /* pSwapBuffers */
144 NULL /* pWidenPath */
148 /**********************************************************************
149 * WIN16DRV_Init
151 const DC_FUNCTIONS *WIN16DRV_Init(void)
153 static int enabled = -1;
155 if (enabled == -1)
157 char printerEnabled[20];
158 HKEY hkey;
160 /* default value */
161 strcpy( printerEnabled, "off" );
162 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\wine", &hkey))
164 DWORD type, count = sizeof(printerEnabled);
165 RegQueryValueExA(hkey, "printer", 0, &type, printerEnabled, &count);
166 RegCloseKey(hkey);
168 enabled = !strcasecmp( printerEnabled, "on" );
169 if (!enabled)
171 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
172 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
176 return enabled ? &WIN16DRV_Funcs : NULL;
179 /* Tempory functions, for initialising structures */
180 /* These values should be calculated, not hardcoded */
181 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
183 lpTextXForm->txfHeight = 0x0001;
184 lpTextXForm->txfWidth = 0x000c;
185 lpTextXForm->txfEscapement = 0x0000;
186 lpTextXForm->txfOrientation = 0x0000;
187 lpTextXForm->txfWeight = 0x0190;
188 lpTextXForm->txfItalic = 0x00;
189 lpTextXForm->txfUnderline = 0x00;
190 lpTextXForm->txfStrikeOut = 0x00;
191 lpTextXForm->txfOutPrecision = 0x02;
192 lpTextXForm->txfClipPrecision = 0x01;
193 lpTextXForm->txfAccelerator = 0x0001;
194 lpTextXForm->txfOverhang = 0x0000;
198 void InitDrawMode(LPDRAWMODE lpDrawMode)
200 lpDrawMode->Rop2 = 0x000d;
201 lpDrawMode->bkMode = 0x0001;
202 lpDrawMode->bkColor = 0x3fffffff;
203 lpDrawMode->TextColor = 0x20000000;
204 lpDrawMode->TBreakExtra = 0x0000;
205 lpDrawMode->BreakExtra = 0x0000;
206 lpDrawMode->BreakErr = 0x0000;
207 lpDrawMode->BreakRem = 0x0000;
208 lpDrawMode->BreakCount = 0x0000;
209 lpDrawMode->CharExtra = 0x0000;
210 lpDrawMode->LbkColor = 0x00ffffff;
211 lpDrawMode->LTextColor = 0x00000000;
212 lpDrawMode->ICMCXform = 0; /* ? */
213 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
214 lpDrawMode->eMiterLimit = 1;
217 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
218 const DEVMODEA* initData )
220 LOADED_PRINTER_DRIVER *pLPD;
221 WORD wRet;
222 int nPDEVICEsize;
223 PDEVICE_HEADER *pPDH;
224 WIN16DRV_PDEVICE *physDev;
226 TRACE("In creatdc for (%s,%s,%s) initData %p\n",
227 driver, device, output, initData);
229 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
230 if (!physDev) return FALSE;
231 dc->physDev = physDev;
233 pLPD = LoadPrinterDriver(driver);
234 if (pLPD == NULL)
236 WARN("Failed to find printer driver\n");
237 HeapFree( GetProcessHeap(), 0, physDev );
238 return FALSE;
240 TRACE("windevCreateDC pLPD %p\n", pLPD);
242 /* Now Get the device capabilities from the printer driver */
243 memset( &physDev->DevCaps, 0, sizeof(physDev->DevCaps) );
244 if(!output) output = "LPT1:";
246 /* Get GDIINFO which is the same as a DeviceCaps structure */
247 wRet = PRTDRV_Enable(&physDev->DevCaps, GETGDIINFO, device, driver, output,NULL);
249 /* Add this to the DC */
250 dc->hVisRgn = CreateRectRgn(0, 0, physDev->DevCaps.horzRes, physDev->DevCaps.vertRes);
251 dc->bitsPerPixel = physDev->DevCaps.bitsPixel;
253 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
254 physDev->DevCaps.horzRes, physDev->DevCaps.vertRes,
255 physDev->DevCaps.bitsPixel, physDev->DevCaps.planes);
257 /* Now we allocate enough memory for the PDEVICE structure */
258 /* The size of this varies between printer drivers */
259 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
260 /* be accessable from 16 bit code */
261 nPDEVICEsize = physDev->DevCaps.pdeviceSize + sizeof(PDEVICE_HEADER);
263 /* TTD Shouldn't really do pointer arithmetic on segment points */
264 physDev->segptrPDEVICE = K32WOWGlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
265 *((BYTE *)MapSL(physDev->segptrPDEVICE)+0) = 'N';
266 *((BYTE *)MapSL(physDev->segptrPDEVICE)+1) = 'B';
268 /* Set up the header */
269 pPDH = (PDEVICE_HEADER *)((BYTE*)MapSL(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
270 pPDH->pLPD = pLPD;
272 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
274 /* Now get the printer driver to initialise this data */
275 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
277 physDev->FontInfo = NULL;
278 physDev->BrushInfo = NULL;
279 physDev->PenInfo = NULL;
280 win16drv_SegPtr_TextXForm = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
281 win16drv_TextXFormP = MapSL(win16drv_SegPtr_TextXForm);
283 InitTextXForm(win16drv_TextXFormP);
285 /* TTD Lots more to do here */
286 win16drv_SegPtr_DrawMode = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
287 win16drv_DrawModeP = MapSL(win16drv_SegPtr_DrawMode);
289 InitDrawMode(win16drv_DrawModeP);
291 return TRUE;
294 BOOL WIN16DRV_PatBlt( struct tagDC *dc, INT left, INT top,
295 INT width, INT height, DWORD rop )
298 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
299 BOOL bRet = 0;
301 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
302 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
304 return bRet;
308 /***********************************************************************
309 * WIN16DRV_GetDeviceCaps
311 static INT WIN16DRV_GetDeviceCaps( DC *dc, INT cap )
313 WIN16DRV_PDEVICE *physDev = dc->physDev;
314 if (cap >= PHYSICALWIDTH || (cap % 2))
316 FIXME("(%04x): unsupported capability %d, will return 0\n", dc->hSelf, cap );
317 return 0;
319 return *((WORD *)&physDev->DevCaps + (cap / 2));
323 /***********************************************************************
324 * WIN16DRV_ExtEscape
326 static INT WIN16DRV_ExtEscape( DC *dc, INT escape, INT in_count, LPCVOID in_data,
327 INT out_count, LPVOID out_data )
329 #if 0
330 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
331 int nRet = 0;
333 /* We should really process the nEscape parameter, but for now just
334 pass it all to the driver */
335 if (dc != NULL && physDev->segptrPDEVICE != 0)
337 switch(nEscape)
339 case ENABLEPAIRKERNING:
340 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
341 nRet = 1;
342 break;
343 case GETPAIRKERNTABLE:
344 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
345 nRet = 0;
346 break;
347 case SETABORTPROC: {
348 /* FIXME: The AbortProc should be called:
349 - After every write to printer port or spool file
350 - Several times when no more disk space
351 - Before every metafile record when GDI does banding
354 /* Call Control with hdc as lpInData */
355 HDC16 *seghdc = SEGPTR_NEW(HDC16);
356 *seghdc = dc->hSelf;
357 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
358 SEGPTR_GET(seghdc), lpOutData);
359 SEGPTR_FREE(seghdc);
360 break;
363 case NEXTBAND:
365 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
367 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
368 SEGPTR_GET(newInData), lpOutData);
369 SEGPTR_FREE(newInData);
370 break;
373 case GETEXTENDEDTEXTMETRICS:
375 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
377 textData->nSize = cbInput;
378 textData->lpindata = lpInData;
379 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
380 textData->lpXForm = win16drv_SegPtr_TextXForm;
381 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
382 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
383 SEGPTR_GET(textData), lpOutData);
384 SEGPTR_FREE(textData);
386 break;
387 case STARTDOC:
389 /* lpInData is not necessarily \0 terminated so make it so */
390 char *cp = SEGPTR_ALLOC(cbInput + 1);
391 memcpy(cp, MapSL(lpInData), cbInput);
392 cp[cbInput] = '\0';
394 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
395 SEGPTR_GET(cp), lpOutData);
396 SEGPTR_FREE(cp);
397 if (nRet != -1)
399 HDC *tmpHdc = SEGPTR_NEW(HDC);
401 #define SETPRINTERDC SETABORTPROC
403 *tmpHdc = dc->hSelf;
404 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
405 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
406 SEGPTR_FREE(tmpHdc);
409 break;
410 default:
411 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
412 lpInData, lpOutData);
413 break;
416 else
417 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
418 return nRet;
419 #endif
420 /* FIXME: should convert args to SEGPTR and redo all the above */
421 FIXME("temporarily broken, please fix\n");
422 return 0;