Better separation of the palette functions.
[wine/multimedia.git] / dlls / gdi / win16drv / init.c
blobcb6c39deca6775271d58ab809c98e950dcc00b24
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, /* pGetNearestColor */
101 NULL, /* pGetPixel */
102 NULL, /* pGetPixelFormat */
103 NULL, /* pGetSystemPaletteEntries */
104 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
105 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
106 NULL, /* pIntersectClipRect */
107 NULL, /* pInvertRgn */
108 WIN16DRV_LineTo, /* pLineTo */
109 NULL, /* pMoveTo */
110 NULL, /* pOffsetClipRgn */
111 NULL, /* pOffsetViewportOrgEx */
112 NULL, /* pOffsetWindowOrgEx */
113 NULL, /* pPaintRgn */
114 WIN16DRV_PatBlt, /* pPatBlt */
115 NULL, /* pPie */
116 NULL, /* pPolyBezier */
117 NULL, /* pPolyBezierTo */
118 NULL, /* pPolyDraw */
119 NULL, /* pPolyPolygon */
120 NULL, /* pPolyPolyline */
121 WIN16DRV_Polygon, /* pPolygon */
122 WIN16DRV_Polyline, /* pPolyline */
123 NULL, /* pPolylineTo */
124 NULL, /* pRealizeDefaultPalette */
125 NULL, /* pRealizePalette */
126 WIN16DRV_Rectangle, /* pRectangle */
127 NULL, /* pResetDC */
128 NULL, /* pRestoreDC */
129 NULL, /* pRoundRect */
130 NULL, /* pSaveDC */
131 NULL, /* pScaleViewportExtEx */
132 NULL, /* pScaleWindowExtEx */
133 WIN16DRV_SelectBitmap, /* pSelectBitmap */
134 WIN16DRV_SelectBrush, /* pSelectBrush */
135 NULL, /* pSelectClipPath */
136 WIN16DRV_SelectFont, /* pSelectFont */
137 NULL, /* pSelectPalette */
138 WIN16DRV_SelectPen, /* pSelectPen */
139 NULL, /* pSetBitmapBits */
140 NULL, /* pSetBkColor */
141 NULL, /* pSetBkMode */
142 NULL, /* pSetDIBColorTable */
143 NULL, /* pSetDIBits */
144 NULL, /* pSetDIBitsToDevice */
145 NULL, /* pSetDeviceClipping */
146 NULL, /* pSetDeviceGammaRamp */
147 NULL, /* pSetMapMode */
148 NULL, /* pSetMapperFlags */
149 NULL, /* pSetPixel */
150 NULL, /* pSetPixelFormat */
151 NULL, /* pSetPolyFillMode */
152 NULL, /* pSetROP2 */
153 NULL, /* pSetRelAbs */
154 NULL, /* pSetStretchBltMode */
155 NULL, /* pSetTextAlign */
156 NULL, /* pSetTextCharacterExtra */
157 NULL, /* pSetTextColor */
158 NULL, /* pSetTextJustification */
159 NULL, /* pSetViewportExtEx */
160 NULL, /* pSetViewportOrgEx */
161 NULL, /* pSetWindowExtEx */
162 NULL, /* pSetWindowOrgEx */
163 NULL, /* pStartDoc */
164 NULL, /* pStartPage */
165 NULL, /* pStretchBlt */
166 NULL, /* pStretchDIBits */
167 NULL, /* pStrokeAndFillPath */
168 NULL, /* pStrokePath */
169 NULL, /* pSwapBuffers */
170 NULL /* pWidenPath */
174 /**********************************************************************
175 * WIN16DRV_Init
177 const DC_FUNCTIONS *WIN16DRV_Init(void)
179 static int enabled = -1;
181 if (enabled == -1)
183 char printerEnabled[20];
184 HKEY hkey;
186 /* default value */
187 strcpy( printerEnabled, "off" );
188 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\wine", &hkey))
190 DWORD type, count = sizeof(printerEnabled);
191 RegQueryValueExA(hkey, "printer", 0, &type, printerEnabled, &count);
192 RegCloseKey(hkey);
194 enabled = !strcasecmp( printerEnabled, "on" );
195 if (!enabled)
197 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
198 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
202 return enabled ? &WIN16DRV_Funcs : NULL;
205 /* Tempory functions, for initialising structures */
206 /* These values should be calculated, not hardcoded */
207 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
209 lpTextXForm->txfHeight = 0x0001;
210 lpTextXForm->txfWidth = 0x000c;
211 lpTextXForm->txfEscapement = 0x0000;
212 lpTextXForm->txfOrientation = 0x0000;
213 lpTextXForm->txfWeight = 0x0190;
214 lpTextXForm->txfItalic = 0x00;
215 lpTextXForm->txfUnderline = 0x00;
216 lpTextXForm->txfStrikeOut = 0x00;
217 lpTextXForm->txfOutPrecision = 0x02;
218 lpTextXForm->txfClipPrecision = 0x01;
219 lpTextXForm->txfAccelerator = 0x0001;
220 lpTextXForm->txfOverhang = 0x0000;
224 void InitDrawMode(LPDRAWMODE lpDrawMode)
226 lpDrawMode->Rop2 = 0x000d;
227 lpDrawMode->bkMode = 0x0001;
228 lpDrawMode->bkColor = 0x3fffffff;
229 lpDrawMode->TextColor = 0x20000000;
230 lpDrawMode->TBreakExtra = 0x0000;
231 lpDrawMode->BreakExtra = 0x0000;
232 lpDrawMode->BreakErr = 0x0000;
233 lpDrawMode->BreakRem = 0x0000;
234 lpDrawMode->BreakCount = 0x0000;
235 lpDrawMode->CharExtra = 0x0000;
236 lpDrawMode->LbkColor = 0x00ffffff;
237 lpDrawMode->LTextColor = 0x00000000;
238 lpDrawMode->ICMCXform = 0; /* ? */
239 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
240 lpDrawMode->eMiterLimit = 1;
243 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
244 const DEVMODEA* initData )
246 LOADED_PRINTER_DRIVER *pLPD;
247 WORD wRet;
248 int nPDEVICEsize;
249 PDEVICE_HEADER *pPDH;
250 WIN16DRV_PDEVICE *physDev;
252 TRACE("In creatdc for (%s,%s,%s) initData %p\n",
253 driver, device, output, initData);
255 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
256 if (!physDev) return FALSE;
257 dc->physDev = (PHYSDEV)physDev;
258 physDev->hdc = dc->hSelf;
259 physDev->dc = dc;
261 pLPD = LoadPrinterDriver(driver);
262 if (pLPD == NULL)
264 WARN("Failed to find printer driver\n");
265 HeapFree( GetProcessHeap(), 0, physDev );
266 return FALSE;
268 TRACE("windevCreateDC pLPD %p\n", pLPD);
270 /* Now Get the device capabilities from the printer driver */
271 memset( &physDev->DevCaps, 0, sizeof(physDev->DevCaps) );
272 if(!output) output = "LPT1:";
274 /* Get GDIINFO which is the same as a DeviceCaps structure */
275 wRet = PRTDRV_Enable(&physDev->DevCaps, GETGDIINFO, device, driver, output,NULL);
277 /* Add this to the DC */
278 dc->bitsPerPixel = physDev->DevCaps.bitsPixel;
280 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
281 physDev->DevCaps.horzRes, physDev->DevCaps.vertRes,
282 physDev->DevCaps.bitsPixel, physDev->DevCaps.planes);
284 /* Now we allocate enough memory for the PDEVICE structure */
285 /* The size of this varies between printer drivers */
286 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
287 /* be accessable from 16 bit code */
288 nPDEVICEsize = physDev->DevCaps.pdeviceSize + sizeof(PDEVICE_HEADER);
290 /* TTD Shouldn't really do pointer arithmetic on segment points */
291 physDev->segptrPDEVICE = K32WOWGlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
292 *((BYTE *)MapSL(physDev->segptrPDEVICE)+0) = 'N';
293 *((BYTE *)MapSL(physDev->segptrPDEVICE)+1) = 'B';
295 /* Set up the header */
296 pPDH = (PDEVICE_HEADER *)((BYTE*)MapSL(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
297 pPDH->pLPD = pLPD;
299 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
301 /* Now get the printer driver to initialise this data */
302 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
304 physDev->FontInfo = NULL;
305 physDev->BrushInfo = NULL;
306 physDev->PenInfo = NULL;
307 win16drv_SegPtr_TextXForm = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
308 win16drv_TextXFormP = MapSL(win16drv_SegPtr_TextXForm);
310 InitTextXForm(win16drv_TextXFormP);
312 /* TTD Lots more to do here */
313 win16drv_SegPtr_DrawMode = K32WOWGlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
314 win16drv_DrawModeP = MapSL(win16drv_SegPtr_DrawMode);
316 InitDrawMode(win16drv_DrawModeP);
318 return TRUE;
321 BOOL WIN16DRV_PatBlt( PHYSDEV dev, INT left, INT top, INT width, INT height, DWORD rop )
324 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
325 BOOL bRet = 0;
327 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
328 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
330 return bRet;
334 /***********************************************************************
335 * WIN16DRV_GetDeviceCaps
337 static INT WIN16DRV_GetDeviceCaps( PHYSDEV dev, INT cap )
339 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
340 if (cap >= PHYSICALWIDTH || (cap % 2))
342 FIXME("(%04x): unsupported capability %d, will return 0\n", physDev->hdc, cap );
343 return 0;
345 return *((WORD *)&physDev->DevCaps + (cap / 2));
349 /***********************************************************************
350 * WIN16DRV_ExtEscape
352 static INT WIN16DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_data,
353 INT out_count, LPVOID out_data )
355 #if 0
356 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
357 int nRet = 0;
359 /* We should really process the nEscape parameter, but for now just
360 pass it all to the driver */
361 if (dc != NULL && physDev->segptrPDEVICE != 0)
363 switch(nEscape)
365 case ENABLEPAIRKERNING:
366 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
367 nRet = 1;
368 break;
369 case GETPAIRKERNTABLE:
370 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
371 nRet = 0;
372 break;
373 case SETABORTPROC: {
374 /* FIXME: The AbortProc should be called:
375 - After every write to printer port or spool file
376 - Several times when no more disk space
377 - Before every metafile record when GDI does banding
380 /* Call Control with hdc as lpInData */
381 HDC16 *seghdc = SEGPTR_NEW(HDC16);
382 *seghdc = dc->hSelf;
383 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
384 SEGPTR_GET(seghdc), lpOutData);
385 SEGPTR_FREE(seghdc);
386 break;
389 case NEXTBAND:
391 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
393 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
394 SEGPTR_GET(newInData), lpOutData);
395 SEGPTR_FREE(newInData);
396 break;
399 case GETEXTENDEDTEXTMETRICS:
401 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
403 textData->nSize = cbInput;
404 textData->lpindata = lpInData;
405 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
406 textData->lpXForm = win16drv_SegPtr_TextXForm;
407 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
408 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
409 SEGPTR_GET(textData), lpOutData);
410 SEGPTR_FREE(textData);
412 break;
413 case STARTDOC:
415 /* lpInData is not necessarily \0 terminated so make it so */
416 char *cp = SEGPTR_ALLOC(cbInput + 1);
417 memcpy(cp, MapSL(lpInData), cbInput);
418 cp[cbInput] = '\0';
420 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
421 SEGPTR_GET(cp), lpOutData);
422 SEGPTR_FREE(cp);
423 if (nRet != -1)
425 HDC *tmpHdc = SEGPTR_NEW(HDC);
427 #define SETPRINTERDC SETABORTPROC
429 *tmpHdc = dc->hSelf;
430 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
431 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
432 SEGPTR_FREE(tmpHdc);
435 break;
436 default:
437 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
438 lpInData, lpOutData);
439 break;
442 else
443 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
444 return nRet;
445 #endif
446 /* FIXME: should convert args to SEGPTR and redo all the above */
447 FIXME("temporarily broken, please fix\n");
448 return 0;