DOSFS_ToDosFCBFormat: fail if extension longer than 3 characters.
[wine/gsoc-2012-control.git] / graphics / win16drv / init.c
blob412d535460f70f83e8cf7de04459e18481727142
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 "win16drv.h"
13 #include "gdi.h"
14 #include "bitmap.h"
15 #include "heap.h"
16 #include "font.h"
17 #include "options.h"
18 #include "debugtools.h"
19 #include "dc.h"
21 DEFAULT_DEBUG_CHANNEL(win16drv)
23 #define SUPPORT_REALIZED_FONTS 1
24 #include "pshpack1.h"
25 typedef struct
27 SHORT nSize;
28 SEGPTR lpindata;
29 SEGPTR lpFont;
30 SEGPTR lpXForm;
31 SEGPTR lpDrawMode;
32 } EXTTEXTDATA, *LPEXTTEXTDATA;
33 #include "poppack.h"
35 SEGPTR win16drv_SegPtr_TextXForm;
36 LPTEXTXFORM16 win16drv_TextXFormP;
37 SEGPTR win16drv_SegPtr_DrawMode;
38 LPDRAWMODE win16drv_DrawModeP;
41 static BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
42 LPCSTR output, const DEVMODEA* initData );
43 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
44 SEGPTR lpInData, SEGPTR lpOutData );
46 static const DC_FUNCTIONS WIN16DRV_Funcs =
48 NULL, /* pAbortDoc */
49 NULL, /* pAbortPath */
50 NULL, /* pAngleArc */
51 NULL, /* pArc */
52 NULL, /* pArcTo */
53 NULL, /* pBeginPath */
54 NULL, /* pBitBlt */
55 NULL, /* pBitmapBits */
56 NULL, /* pChord */
57 NULL, /* pCloseFigure */
58 NULL, /* pCreateBitmap */
59 WIN16DRV_CreateDC, /* pCreateDC */
60 NULL, /* pCreateDIBSection */
61 NULL, /* pCreateDIBSection16 */
62 NULL, /* pDeleteDC */
63 NULL, /* pDeleteObject */
64 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
65 WIN16DRV_Ellipse, /* pEllipse */
66 NULL, /* pEndDoc */
67 NULL, /* pEndPage */
68 NULL, /* pEndPath */
69 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
70 WIN16DRV_Escape, /* pEscape */
71 NULL, /* pExcludeClipRect */
72 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
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 NULL, /* pGetPixel */
82 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
83 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
84 NULL, /* pIntersectClipRect */
85 NULL, /* pInvertRgn */
86 WIN16DRV_LineTo, /* pLineTo */
87 NULL, /* pLoadOEMResource */
88 WIN16DRV_MoveToEx, /* pMoveToEx */
89 NULL, /* pOffsetClipRgn */
90 NULL, /* pOffsetViewportOrgEx */
91 NULL, /* pOffsetWindowOrgEx */
92 NULL, /* pPaintRgn */
93 WIN16DRV_PatBlt, /* pPatBlt */
94 NULL, /* pPie */
95 NULL, /* pPolyBezier */
96 NULL, /* pPolyBezierTo */
97 NULL, /* pPolyDraw */
98 NULL, /* pPolyPolygon */
99 NULL, /* pPolyPolyline */
100 WIN16DRV_Polygon, /* pPolygon */
101 WIN16DRV_Polyline, /* pPolyline */
102 NULL, /* pPolylineTo */
103 NULL, /* pRealizePalette */
104 WIN16DRV_Rectangle, /* pRectangle */
105 NULL, /* pRestoreDC */
106 NULL, /* pRoundRect */
107 NULL, /* pSaveDC */
108 NULL, /* pScaleViewportExtEx */
109 NULL, /* pScaleWindowExtEx */
110 NULL, /* pSelectClipPath */
111 NULL, /* pSelectClipRgn */
112 WIN16DRV_SelectObject, /* pSelectObject */
113 NULL, /* pSelectPalette */
114 NULL, /* pSetBkColor */
115 NULL, /* pSetBkMode */
116 NULL, /* pSetDeviceClipping */
117 NULL, /* pSetDIBitsToDevice */
118 NULL, /* pSetMapMode */
119 NULL, /* pSetMapperFlags */
120 NULL, /* pSetPixel */
121 NULL, /* pSetPolyFillMode */
122 NULL, /* pSetROP2 */
123 NULL, /* pSetRelAbs */
124 NULL, /* pSetStretchBltMode */
125 NULL, /* pSetTextAlign */
126 NULL, /* pSetTextCharacterExtra */
127 NULL, /* pSetTextColor */
128 NULL, /* pSetTextJustification */
129 NULL, /* pSetViewportExtEx */
130 NULL, /* pSetViewportOrgEx */
131 NULL, /* pSetWindowExtEx */
132 NULL, /* pSetWindowOrgEx */
133 NULL, /* pStartDoc */
134 NULL, /* pStartPage */
135 NULL, /* pStretchBlt */
136 NULL, /* pStretchDIBits */
137 NULL, /* pStrokeAndFillPath */
138 NULL, /* pStrokePath */
139 NULL /* pWidenPath */
146 /**********************************************************************
147 * WIN16DRV_Init
149 BOOL WIN16DRV_Init(void)
151 return DRIVER_RegisterDriver( NULL /* generic driver */, &WIN16DRV_Funcs );
155 /* Tempory functions, for initialising structures */
156 /* These values should be calculated, not hardcoded */
157 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
159 lpTextXForm->txfHeight = 0x0001;
160 lpTextXForm->txfWidth = 0x000c;
161 lpTextXForm->txfEscapement = 0x0000;
162 lpTextXForm->txfOrientation = 0x0000;
163 lpTextXForm->txfWeight = 0x0190;
164 lpTextXForm->txfItalic = 0x00;
165 lpTextXForm->txfUnderline = 0x00;
166 lpTextXForm->txfStrikeOut = 0x00;
167 lpTextXForm->txfOutPrecision = 0x02;
168 lpTextXForm->txfClipPrecision = 0x01;
169 lpTextXForm->txfAccelerator = 0x0001;
170 lpTextXForm->txfOverhang = 0x0000;
174 void InitDrawMode(LPDRAWMODE lpDrawMode)
176 lpDrawMode->Rop2 = 0x000d;
177 lpDrawMode->bkMode = 0x0001;
178 lpDrawMode->bkColor = 0x3fffffff;
179 lpDrawMode->TextColor = 0x20000000;
180 lpDrawMode->TBreakExtra = 0x0000;
181 lpDrawMode->BreakExtra = 0x0000;
182 lpDrawMode->BreakErr = 0x0000;
183 lpDrawMode->BreakRem = 0x0000;
184 lpDrawMode->BreakCount = 0x0000;
185 lpDrawMode->CharExtra = 0x0000;
186 lpDrawMode->LbkColor = 0x00ffffff;
187 lpDrawMode->LTextColor = 0x00000000;
188 lpDrawMode->ICMCXform = 0; /* ? */
189 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
190 lpDrawMode->eMiterLimit = 1;
193 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
194 const DEVMODEA* initData )
196 LOADED_PRINTER_DRIVER *pLPD;
197 WORD wRet;
198 DeviceCaps *printerDevCaps;
199 int nPDEVICEsize;
200 PDEVICE_HEADER *pPDH;
201 WIN16DRV_PDEVICE *physDev;
202 char printerEnabled[20];
203 PROFILE_GetWineIniString( "wine", "printer", "off",
204 printerEnabled, sizeof(printerEnabled) );
205 if (lstrcmpiA(printerEnabled,"on"))
207 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
208 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
209 return FALSE;
212 TRACE("In creatdc for (%s,%s,%s) initData 0x%p\n",
213 driver, device, output, initData);
215 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev) );
216 if (!physDev) return FALSE;
217 dc->physDev = physDev;
219 pLPD = LoadPrinterDriver(driver);
220 if (pLPD == NULL)
222 WARN("Failed to find printer driver\n");
223 HeapFree( GetProcessHeap(), 0, physDev );
224 return FALSE;
226 TRACE("windevCreateDC pLPD 0x%p\n", pLPD);
228 /* Now Get the device capabilities from the printer driver */
230 printerDevCaps = (DeviceCaps *) calloc(1, sizeof(DeviceCaps));
231 if(printerDevCaps == NULL) {
232 ERR("No memory to read the device capabilities!");
233 HeapFree( GetProcessHeap(), 0, physDev );
234 return FALSE;
237 if(!output) output = "LPT1:";
238 /* Get GDIINFO which is the same as a DeviceCaps structure */
239 wRet = PRTDRV_Enable(printerDevCaps, GETGDIINFO, device, driver, output,NULL);
241 /* Add this to the DC */
242 dc->w.devCaps = printerDevCaps;
243 dc->w.hVisRgn = CreateRectRgn(0, 0, dc->w.devCaps->horzRes, dc->w.devCaps->vertRes);
244 dc->w.bitsPerPixel = dc->w.devCaps->bitsPixel;
246 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
247 dc->w.devCaps->horzRes, dc->w.devCaps->vertRes,
248 dc->w.devCaps->bitsPixel, dc->w.devCaps->planes);
250 /* Now we allocate enough memory for the PDEVICE structure */
251 /* The size of this varies between printer drivers */
252 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
253 /* be accessable from 16 bit code */
254 nPDEVICEsize = dc->w.devCaps->pdeviceSize + sizeof(PDEVICE_HEADER);
256 /* TTD Shouldn't really do pointer arithmetic on segment points */
257 physDev->segptrPDEVICE = WIN16_GlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
258 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+0) = 'N';
259 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+1) = 'B';
261 /* Set up the header */
262 pPDH = (PDEVICE_HEADER *)((BYTE*)PTR_SEG_TO_LIN(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
263 pPDH->pLPD = pLPD;
265 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
267 /* Now get the printer driver to initialise this data */
268 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
270 physDev->FontInfo = NULL;
271 physDev->BrushInfo = NULL;
272 physDev->PenInfo = NULL;
273 win16drv_SegPtr_TextXForm = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
274 win16drv_TextXFormP = PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm);
276 InitTextXForm(win16drv_TextXFormP);
278 /* TTD Lots more to do here */
279 win16drv_SegPtr_DrawMode = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
280 win16drv_DrawModeP = PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode);
282 InitDrawMode(win16drv_DrawModeP);
284 return TRUE;
287 BOOL WIN16DRV_PatBlt( struct tagDC *dc, INT left, INT top,
288 INT width, INT height, DWORD rop )
291 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
292 BOOL bRet = 0;
294 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
295 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
297 return bRet;
300 * Escape (GDI.38)
302 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
303 SEGPTR lpInData, SEGPTR lpOutData )
305 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
306 int nRet = 0;
308 /* We should really process the nEscape parameter, but for now just
309 pass it all to the driver */
310 if (dc != NULL && physDev->segptrPDEVICE != 0)
312 switch(nEscape)
314 case ENABLEPAIRKERNING:
315 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
316 nRet = 1;
317 break;
318 case GETPAIRKERNTABLE:
319 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
320 nRet = 0;
321 break;
322 case SETABORTPROC: {
323 /* FIXME: The AbortProc should be called:
324 - After every write to printer port or spool file
325 - Several times when no more disk space
326 - Before every metafile record when GDI does banding
329 /* Call Control with hdc as lpInData */
330 HDC16 *seghdc = SEGPTR_NEW(HDC16);
331 *seghdc = dc->hSelf;
332 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
333 SEGPTR_GET(seghdc), lpOutData);
334 SEGPTR_FREE(seghdc);
335 break;
338 case NEXTBAND:
340 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
342 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
343 SEGPTR_GET(newInData), lpOutData);
344 SEGPTR_FREE(newInData);
345 break;
348 case GETEXTENDEDTEXTMETRICS:
350 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
352 textData->nSize = cbInput;
353 textData->lpindata = lpInData;
354 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
355 textData->lpXForm = win16drv_SegPtr_TextXForm;
356 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
357 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
358 SEGPTR_GET(textData), lpOutData);
359 SEGPTR_FREE(textData);
361 break;
362 case STARTDOC:
364 /* lpInData is not necessarily \0 terminated so make it so */
365 char *cp = SEGPTR_ALLOC(cbInput + 1);
366 memcpy(cp, PTR_SEG_TO_LIN(lpInData), cbInput);
367 cp[cbInput] = '\0';
369 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
370 SEGPTR_GET(cp), lpOutData);
371 SEGPTR_FREE(cp);
372 if (nRet != -1)
374 HDC *tmpHdc = SEGPTR_NEW(HDC);
376 #define SETPRINTERDC SETABORTPROC
378 *tmpHdc = dc->hSelf;
379 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
380 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
381 SEGPTR_FREE(tmpHdc);
384 break;
385 default:
386 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
387 lpInData, lpOutData);
388 break;
391 else
392 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
393 return nRet;