Added function table to GDI objects for better encapsulation.
[wine.git] / dlls / gdi / win16drv / init.c
blob0550337ae92709cd219687f00dc9564e2caf0fba
1 /*
2 * Windows Device Context initialisation functions
4 * Copyright 1996 John Harvey
5 * 1998 Huw Davies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include "winreg.h"
27 #include "win16drv/win16drv.h"
28 #include "gdi.h"
29 #include "bitmap.h"
30 #include "font.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(win16drv);
35 #define SUPPORT_REALIZED_FONTS 1
36 #include "pshpack1.h"
37 typedef struct
39 SHORT nSize;
40 SEGPTR lpindata;
41 SEGPTR lpFont;
42 SEGPTR lpXForm;
43 SEGPTR lpDrawMode;
44 } EXTTEXTDATA, *LPEXTTEXTDATA;
45 #include "poppack.h"
47 SEGPTR win16drv_SegPtr_TextXForm;
48 LPTEXTXFORM16 win16drv_TextXFormP;
49 SEGPTR win16drv_SegPtr_DrawMode;
50 LPDRAWMODE win16drv_DrawModeP;
53 static BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
54 LPCSTR output, const DEVMODEA* initData );
55 static INT WIN16DRV_GetDeviceCaps( PHYSDEV dev, INT cap );
56 static INT WIN16DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
57 INT out_count, LPVOID out_data );
59 static const DC_FUNCTIONS WIN16DRV_Funcs =
61 NULL, /* pAbortDoc */
62 NULL, /* pAbortPath */
63 NULL, /* pAngleArc */
64 NULL, /* pArc */
65 NULL, /* pArcTo */
66 NULL, /* pBeginPath */
67 NULL, /* pBitBlt */
68 NULL, /* pChoosePixelFormat */
69 NULL, /* pChord */
70 NULL, /* pCloseFigure */
71 NULL, /* pCreateBitmap */
72 WIN16DRV_CreateDC, /* pCreateDC */
73 NULL, /* pCreateDIBSection */
74 NULL, /* pDeleteBitmap */
75 NULL, /* pDeleteDC */
76 NULL, /* pDescribePixelFormat */
77 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
78 WIN16DRV_Ellipse, /* pEllipse */
79 NULL, /* pEndDoc */
80 NULL, /* pEndPage */
81 NULL, /* pEndPath */
82 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
83 NULL, /* pExcludeClipRect */
84 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
85 WIN16DRV_ExtEscape, /* pExtEscape */
86 NULL, /* pExtFloodFill */
87 NULL, /* pExtSelectClipRgn */
88 WIN16DRV_ExtTextOut, /* pExtTextOut */
89 NULL, /* pFillPath */
90 NULL, /* pFillRgn */
91 NULL, /* pFlattenPath */
92 NULL, /* pFrameRgn */
93 NULL, /* pGetBitmapBits */
94 WIN16DRV_GetCharWidth, /* pGetCharWidth */
95 NULL, /* pGetDCOrgEx */
96 NULL, /* pGetDIBColorTable */
97 NULL, /* pGetDIBits */
98 WIN16DRV_GetDeviceCaps, /* pGetDeviceCaps */
99 NULL, /* pGetDeviceGammaRamp */
100 NULL, /* pGetPixel */
101 NULL, /* pGetPixelFormat */
102 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
103 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
104 NULL, /* pIntersectClipRect */
105 NULL, /* pInvertRgn */
106 WIN16DRV_LineTo, /* pLineTo */
107 NULL, /* pMoveTo */
108 NULL, /* pOffsetClipRgn */
109 NULL, /* pOffsetViewportOrgEx */
110 NULL, /* pOffsetWindowOrgEx */
111 NULL, /* pPaintRgn */
112 WIN16DRV_PatBlt, /* pPatBlt */
113 NULL, /* pPie */
114 NULL, /* pPolyBezier */
115 NULL, /* pPolyBezierTo */
116 NULL, /* pPolyDraw */
117 NULL, /* pPolyPolygon */
118 NULL, /* pPolyPolyline */
119 WIN16DRV_Polygon, /* pPolygon */
120 WIN16DRV_Polyline, /* pPolyline */
121 NULL, /* pPolylineTo */
122 NULL, /* pRealizePalette */
123 WIN16DRV_Rectangle, /* pRectangle */
124 NULL, /* pResetDC */
125 NULL, /* pRestoreDC */
126 NULL, /* pRoundRect */
127 NULL, /* pSaveDC */
128 NULL, /* pScaleViewportExtEx */
129 NULL, /* pScaleWindowExtEx */
130 WIN16DRV_SelectBitmap, /* pSelectBitmap */
131 WIN16DRV_SelectBrush, /* pSelectBrush */
132 NULL, /* pSelectClipPath */
133 WIN16DRV_SelectFont, /* pSelectFont */
134 NULL, /* pSelectPalette */
135 WIN16DRV_SelectPen, /* pSelectPen */
136 NULL, /* pSetBitmapBits */
137 NULL, /* pSetBkColor */
138 NULL, /* pSetBkMode */
139 NULL, /* pSetDIBColorTable */
140 NULL, /* pSetDIBits */
141 NULL, /* pSetDIBitsToDevice */
142 NULL, /* pSetDeviceClipping */
143 NULL, /* pSetDeviceGammaRamp */
144 NULL, /* pSetMapMode */
145 NULL, /* pSetMapperFlags */
146 NULL, /* pSetPixel */
147 NULL, /* pSetPixelFormat */
148 NULL, /* pSetPolyFillMode */
149 NULL, /* pSetROP2 */
150 NULL, /* pSetRelAbs */
151 NULL, /* pSetStretchBltMode */
152 NULL, /* pSetTextAlign */
153 NULL, /* pSetTextCharacterExtra */
154 NULL, /* pSetTextColor */
155 NULL, /* pSetTextJustification */
156 NULL, /* pSetViewportExtEx */
157 NULL, /* pSetViewportOrgEx */
158 NULL, /* pSetWindowExtEx */
159 NULL, /* pSetWindowOrgEx */
160 NULL, /* pStartDoc */
161 NULL, /* pStartPage */
162 NULL, /* pStretchBlt */
163 NULL, /* pStretchDIBits */
164 NULL, /* pStrokeAndFillPath */
165 NULL, /* pStrokePath */
166 NULL, /* pSwapBuffers */
167 NULL /* pWidenPath */
171 /**********************************************************************
172 * WIN16DRV_Init
174 const DC_FUNCTIONS *WIN16DRV_Init(void)
176 static int enabled = -1;
178 if (enabled == -1)
180 char printerEnabled[20];
181 HKEY hkey;
183 /* default value */
184 strcpy( printerEnabled, "off" );
185 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\wine", &hkey))
187 DWORD type, count = sizeof(printerEnabled);
188 RegQueryValueExA(hkey, "printer", 0, &type, printerEnabled, &count);
189 RegCloseKey(hkey);
191 enabled = !strcasecmp( printerEnabled, "on" );
192 if (!enabled)
194 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
195 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
199 return enabled ? &WIN16DRV_Funcs : NULL;
202 /* Tempory functions, for initialising structures */
203 /* These values should be calculated, not hardcoded */
204 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
206 lpTextXForm->txfHeight = 0x0001;
207 lpTextXForm->txfWidth = 0x000c;
208 lpTextXForm->txfEscapement = 0x0000;
209 lpTextXForm->txfOrientation = 0x0000;
210 lpTextXForm->txfWeight = 0x0190;
211 lpTextXForm->txfItalic = 0x00;
212 lpTextXForm->txfUnderline = 0x00;
213 lpTextXForm->txfStrikeOut = 0x00;
214 lpTextXForm->txfOutPrecision = 0x02;
215 lpTextXForm->txfClipPrecision = 0x01;
216 lpTextXForm->txfAccelerator = 0x0001;
217 lpTextXForm->txfOverhang = 0x0000;
221 void InitDrawMode(LPDRAWMODE lpDrawMode)
223 lpDrawMode->Rop2 = 0x000d;
224 lpDrawMode->bkMode = 0x0001;
225 lpDrawMode->bkColor = 0x3fffffff;
226 lpDrawMode->TextColor = 0x20000000;
227 lpDrawMode->TBreakExtra = 0x0000;
228 lpDrawMode->BreakExtra = 0x0000;
229 lpDrawMode->BreakErr = 0x0000;
230 lpDrawMode->BreakRem = 0x0000;
231 lpDrawMode->BreakCount = 0x0000;
232 lpDrawMode->CharExtra = 0x0000;
233 lpDrawMode->LbkColor = 0x00ffffff;
234 lpDrawMode->LTextColor = 0x00000000;
235 lpDrawMode->ICMCXform = 0; /* ? */
236 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
237 lpDrawMode->eMiterLimit = 1;
240 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
241 const DEVMODEA* initData )
243 LOADED_PRINTER_DRIVER *pLPD;
244 WORD wRet;
245 int nPDEVICEsize;
246 PDEVICE_HEADER *pPDH;
247 WIN16DRV_PDEVICE *physDev;
249 TRACE("In creatdc for (%s,%s,%s) initData %p\n",
250 driver, device, output, initData);
252 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
253 if (!physDev) return FALSE;
254 dc->physDev = (PHYSDEV)physDev;
255 physDev->hdc = dc->hSelf;
256 physDev->dc = dc;
258 pLPD = LoadPrinterDriver(driver);
259 if (pLPD == NULL)
261 WARN("Failed to find printer driver\n");
262 HeapFree( GetProcessHeap(), 0, physDev );
263 return FALSE;
265 TRACE("windevCreateDC pLPD %p\n", pLPD);
267 /* Now Get the device capabilities from the printer driver */
268 memset( &physDev->DevCaps, 0, sizeof(physDev->DevCaps) );
269 if(!output) output = "LPT1:";
271 /* Get GDIINFO which is the same as a DeviceCaps structure */
272 wRet = PRTDRV_Enable(&physDev->DevCaps, GETGDIINFO, device, driver, output,NULL);
274 /* Add this to the DC */
275 dc->bitsPerPixel = physDev->DevCaps.bitsPixel;
277 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
278 physDev->DevCaps.horzRes, physDev->DevCaps.vertRes,
279 physDev->DevCaps.bitsPixel, physDev->DevCaps.planes);
281 /* Now we allocate enough memory for the PDEVICE structure */
282 /* The size of this varies between printer drivers */
283 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
284 /* be accessable from 16 bit code */
285 nPDEVICEsize = physDev->DevCaps.pdeviceSize + sizeof(PDEVICE_HEADER);
287 /* TTD Shouldn't really do pointer arithmetic on segment points */
288 physDev->segptrPDEVICE = K32WOWGlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
289 *((BYTE *)MapSL(physDev->segptrPDEVICE)+0) = 'N';
290 *((BYTE *)MapSL(physDev->segptrPDEVICE)+1) = 'B';
292 /* Set up the header */
293 pPDH = (PDEVICE_HEADER *)((BYTE*)MapSL(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
294 pPDH->pLPD = pLPD;
296 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
298 /* Now get the printer driver to initialise this data */
299 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
301 physDev->FontInfo = NULL;
302 physDev->BrushInfo = NULL;
303 physDev->PenInfo = NULL;
304 win16drv_SegPtr_TextXForm = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
305 win16drv_TextXFormP = MapSL(win16drv_SegPtr_TextXForm);
307 InitTextXForm(win16drv_TextXFormP);
309 /* TTD Lots more to do here */
310 win16drv_SegPtr_DrawMode = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
311 win16drv_DrawModeP = MapSL(win16drv_SegPtr_DrawMode);
313 InitDrawMode(win16drv_DrawModeP);
315 return TRUE;
318 BOOL WIN16DRV_PatBlt( PHYSDEV dev, INT left, INT top, INT width, INT height, DWORD rop )
321 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
322 BOOL bRet = 0;
324 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
325 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
327 return bRet;
331 /***********************************************************************
332 * WIN16DRV_GetDeviceCaps
334 static INT WIN16DRV_GetDeviceCaps( PHYSDEV dev, INT cap )
336 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
337 if (cap >= PHYSICALWIDTH || (cap % 2))
339 FIXME("(%04x): unsupported capability %d, will return 0\n", physDev->hdc, cap );
340 return 0;
342 return *((WORD *)&physDev->DevCaps + (cap / 2));
346 /***********************************************************************
347 * WIN16DRV_ExtEscape
349 static INT WIN16DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
350 INT out_count, LPVOID out_data )
352 #if 0
353 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
354 int nRet = 0;
356 /* We should really process the nEscape parameter, but for now just
357 pass it all to the driver */
358 if (dc != NULL && physDev->segptrPDEVICE != 0)
360 switch(nEscape)
362 case ENABLEPAIRKERNING:
363 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
364 nRet = 1;
365 break;
366 case GETPAIRKERNTABLE:
367 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
368 nRet = 0;
369 break;
370 case SETABORTPROC: {
371 /* FIXME: The AbortProc should be called:
372 - After every write to printer port or spool file
373 - Several times when no more disk space
374 - Before every metafile record when GDI does banding
377 /* Call Control with hdc as lpInData */
378 HDC16 *seghdc = SEGPTR_NEW(HDC16);
379 *seghdc = dc->hSelf;
380 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
381 SEGPTR_GET(seghdc), lpOutData);
382 SEGPTR_FREE(seghdc);
383 break;
386 case NEXTBAND:
388 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
390 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
391 SEGPTR_GET(newInData), lpOutData);
392 SEGPTR_FREE(newInData);
393 break;
396 case GETEXTENDEDTEXTMETRICS:
398 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
400 textData->nSize = cbInput;
401 textData->lpindata = lpInData;
402 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
403 textData->lpXForm = win16drv_SegPtr_TextXForm;
404 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
405 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
406 SEGPTR_GET(textData), lpOutData);
407 SEGPTR_FREE(textData);
409 break;
410 case STARTDOC:
412 /* lpInData is not necessarily \0 terminated so make it so */
413 char *cp = SEGPTR_ALLOC(cbInput + 1);
414 memcpy(cp, MapSL(lpInData), cbInput);
415 cp[cbInput] = '\0';
417 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
418 SEGPTR_GET(cp), lpOutData);
419 SEGPTR_FREE(cp);
420 if (nRet != -1)
422 HDC *tmpHdc = SEGPTR_NEW(HDC);
424 #define SETPRINTERDC SETABORTPROC
426 *tmpHdc = dc->hSelf;
427 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
428 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
429 SEGPTR_FREE(tmpHdc);
432 break;
433 default:
434 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
435 lpInData, lpOutData);
436 break;
439 else
440 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
441 return nRet;
442 #endif
443 /* FIXME: should convert args to SEGPTR and redo all the above */
444 FIXME("temporarily broken, please fix\n");
445 return 0;