Fixed compiling with STRICT.
[wine/testsucceed.git] / graphics / win16drv / init.c
blob7f206afb0bc518d928564471a496b702f2419732
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, /* pArc */
49 NULL, /* pBitBlt */
50 NULL, /* pBitmapBits */
51 NULL, /* pChord */
52 NULL, /* pCreateBitmap */
53 WIN16DRV_CreateDC, /* pCreateDC */
54 NULL, /* pCreateDIBSection */
55 NULL, /* pCreateDIBSection16 */
56 NULL, /* pDeleteDC */
57 NULL, /* pDeleteObject */
58 WIN16DRV_DeviceCapabilities, /* pDeviceCapabilities */
59 WIN16DRV_Ellipse, /* pEllipse */
60 NULL, /* pEndDoc */
61 NULL, /* pEndPage */
62 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
63 WIN16DRV_Escape, /* pEscape */
64 NULL, /* pExcludeClipRect */
65 WIN16DRV_ExtDeviceMode, /* pExtDeviceMode */
66 NULL, /* pExtFloodFill */
67 WIN16DRV_ExtTextOut, /* pExtTextOut */
68 NULL, /* pFillRgn */
69 NULL, /* pFrameRgn */
70 WIN16DRV_GetCharWidth, /* pGetCharWidth */
71 NULL, /* pGetPixel */
72 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
73 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
74 NULL, /* pIntersectClipRect */
75 NULL, /* pInvertRgn */
76 WIN16DRV_LineTo, /* pLineTo */
77 NULL, /* pLoadOEMResource */
78 WIN16DRV_MoveToEx, /* pMoveToEx */
79 NULL, /* pOffsetClipRgn */
80 NULL, /* pOffsetViewportOrgEx */
81 NULL, /* pOffsetWindowOrgEx */
82 NULL, /* pPaintRgn */
83 WIN16DRV_PatBlt, /* pPatBlt */
84 NULL, /* pPie */
85 NULL, /* pPolyPolygon */
86 NULL, /* pPolyPolyline */
87 WIN16DRV_Polygon, /* pPolygon */
88 WIN16DRV_Polyline, /* pPolyline */
89 NULL, /* pPolyBezier */
90 NULL, /* pRealizePalette */
91 WIN16DRV_Rectangle, /* pRectangle */
92 NULL, /* pRestoreDC */
93 NULL, /* pRoundRect */
94 NULL, /* pSaveDC */
95 NULL, /* pScaleViewportExtEx */
96 NULL, /* pScaleWindowExtEx */
97 NULL, /* pSelectClipRgn */
98 WIN16DRV_SelectObject, /* pSelectObject */
99 NULL, /* pSelectPalette */
100 NULL, /* pSetBkColor */
101 NULL, /* pSetBkMode */
102 NULL, /* pSetDeviceClipping */
103 NULL, /* pSetDIBitsToDevice */
104 NULL, /* pSetMapMode */
105 NULL, /* pSetMapperFlags */
106 NULL, /* pSetPixel */
107 NULL, /* pSetPolyFillMode */
108 NULL, /* pSetROP2 */
109 NULL, /* pSetRelAbs */
110 NULL, /* pSetStretchBltMode */
111 NULL, /* pSetTextAlign */
112 NULL, /* pSetTextCharacterExtra */
113 NULL, /* pSetTextColor */
114 NULL, /* pSetTextJustification */
115 NULL, /* pSetViewportExtEx */
116 NULL, /* pSetViewportOrgEx */
117 NULL, /* pSetWindowExtEx */
118 NULL, /* pSetWindowOrgEx */
119 NULL, /* pStartDoc */
120 NULL, /* pStartPage */
121 NULL, /* pStretchBlt */
122 NULL /* pStretchDIBits */
129 /**********************************************************************
130 * WIN16DRV_Init
132 BOOL WIN16DRV_Init(void)
134 return DRIVER_RegisterDriver( NULL /* generic driver */, &WIN16DRV_Funcs );
138 /* Tempory functions, for initialising structures */
139 /* These values should be calculated, not hardcoded */
140 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
142 lpTextXForm->txfHeight = 0x0001;
143 lpTextXForm->txfWidth = 0x000c;
144 lpTextXForm->txfEscapement = 0x0000;
145 lpTextXForm->txfOrientation = 0x0000;
146 lpTextXForm->txfWeight = 0x0190;
147 lpTextXForm->txfItalic = 0x00;
148 lpTextXForm->txfUnderline = 0x00;
149 lpTextXForm->txfStrikeOut = 0x00;
150 lpTextXForm->txfOutPrecision = 0x02;
151 lpTextXForm->txfClipPrecision = 0x01;
152 lpTextXForm->txfAccelerator = 0x0001;
153 lpTextXForm->txfOverhang = 0x0000;
157 void InitDrawMode(LPDRAWMODE lpDrawMode)
159 lpDrawMode->Rop2 = 0x000d;
160 lpDrawMode->bkMode = 0x0001;
161 lpDrawMode->bkColor = 0x3fffffff;
162 lpDrawMode->TextColor = 0x20000000;
163 lpDrawMode->TBreakExtra = 0x0000;
164 lpDrawMode->BreakExtra = 0x0000;
165 lpDrawMode->BreakErr = 0x0000;
166 lpDrawMode->BreakRem = 0x0000;
167 lpDrawMode->BreakCount = 0x0000;
168 lpDrawMode->CharExtra = 0x0000;
169 lpDrawMode->LbkColor = 0x00ffffff;
170 lpDrawMode->LTextColor = 0x00000000;
171 lpDrawMode->ICMCXform = 0; /* ? */
172 lpDrawMode->StretchBltMode = STRETCH_ANDSCANS;
173 lpDrawMode->eMiterLimit = 1;
176 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
177 const DEVMODEA* initData )
179 LOADED_PRINTER_DRIVER *pLPD;
180 WORD wRet;
181 DeviceCaps *printerDevCaps;
182 int nPDEVICEsize;
183 PDEVICE_HEADER *pPDH;
184 WIN16DRV_PDEVICE *physDev;
185 char printerEnabled[20];
186 PROFILE_GetWineIniString( "wine", "printer", "off",
187 printerEnabled, sizeof(printerEnabled) );
188 if (lstrcmpiA(printerEnabled,"on"))
190 MESSAGE("Printing disabled in wine.conf or .winerc file\n");
191 MESSAGE("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
192 return FALSE;
195 TRACE("In creatdc for (%s,%s,%s) initData 0x%p\n",
196 driver, device, output, initData);
198 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( SystemHeap, 0, sizeof(*physDev) );
199 if (!physDev) return FALSE;
200 dc->physDev = physDev;
202 pLPD = LoadPrinterDriver(driver);
203 if (pLPD == NULL)
205 WARN("Failed to find printer driver\n");
206 HeapFree( SystemHeap, 0, physDev );
207 return FALSE;
209 TRACE("windevCreateDC pLPD 0x%p\n", pLPD);
211 /* Now Get the device capabilities from the printer driver */
213 printerDevCaps = (DeviceCaps *) xmalloc(sizeof(DeviceCaps));
214 memset(printerDevCaps, 0, sizeof(DeviceCaps));
216 if(!output) output = "LPT1:";
217 /* Get GDIINFO which is the same as a DeviceCaps structure */
218 wRet = PRTDRV_Enable(printerDevCaps, GETGDIINFO, device, driver, output,NULL);
220 /* Add this to the DC */
221 dc->w.devCaps = printerDevCaps;
222 dc->w.hVisRgn = CreateRectRgn(0, 0, dc->w.devCaps->horzRes, dc->w.devCaps->vertRes);
223 dc->w.bitsPerPixel = dc->w.devCaps->bitsPixel;
225 TRACE("Got devcaps width %d height %d bits %d planes %d\n",
226 dc->w.devCaps->horzRes, dc->w.devCaps->vertRes,
227 dc->w.devCaps->bitsPixel, dc->w.devCaps->planes);
229 /* Now we allocate enough memory for the PDEVICE structure */
230 /* The size of this varies between printer drivers */
231 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
232 /* be accessable from 16 bit code */
233 nPDEVICEsize = dc->w.devCaps->pdeviceSize + sizeof(PDEVICE_HEADER);
235 /* TTD Shouldn't really do pointer arithmetic on segment points */
236 physDev->segptrPDEVICE = WIN16_GlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
237 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+0) = 'N';
238 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+1) = 'B';
240 /* Set up the header */
241 pPDH = (PDEVICE_HEADER *)((BYTE*)PTR_SEG_TO_LIN(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
242 pPDH->pLPD = pLPD;
244 TRACE("PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
246 /* Now get the printer driver to initialise this data */
247 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
249 physDev->FontInfo = NULL;
250 physDev->BrushInfo = NULL;
251 physDev->PenInfo = NULL;
252 win16drv_SegPtr_TextXForm = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
253 win16drv_TextXFormP = PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm);
255 InitTextXForm(win16drv_TextXFormP);
257 /* TTD Lots more to do here */
258 win16drv_SegPtr_DrawMode = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
259 win16drv_DrawModeP = PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode);
261 InitDrawMode(win16drv_DrawModeP);
263 return TRUE;
266 BOOL WIN16DRV_PatBlt( struct tagDC *dc, INT left, INT top,
267 INT width, INT height, DWORD rop )
270 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
271 BOOL bRet = 0;
273 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
274 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
276 return bRet;
279 * Escape (GDI.38)
281 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
282 SEGPTR lpInData, SEGPTR lpOutData )
284 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
285 int nRet = 0;
287 /* We should really process the nEscape parameter, but for now just
288 pass it all to the driver */
289 if (dc != NULL && physDev->segptrPDEVICE != 0)
291 switch(nEscape)
293 case ENABLEPAIRKERNING:
294 FIXME("Escape: ENABLEPAIRKERNING ignored.\n");
295 nRet = 1;
296 break;
297 case GETPAIRKERNTABLE:
298 FIXME("Escape: GETPAIRKERNTABLE ignored.\n");
299 nRet = 0;
300 break;
301 case SETABORTPROC: {
302 /* FIXME: The AbortProc should be called:
303 - After every write to printer port or spool file
304 - Several times when no more disk space
305 - Before every metafile record when GDI does banding
308 /* Call Control with hdc as lpInData */
309 HDC16 *seghdc = SEGPTR_NEW(HDC16);
310 *seghdc = dc->hSelf;
311 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
312 SEGPTR_GET(seghdc), lpOutData);
313 SEGPTR_FREE(seghdc);
314 break;
317 case NEXTBAND:
319 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
321 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
322 SEGPTR_GET(newInData), lpOutData);
323 SEGPTR_FREE(newInData);
324 break;
327 case GETEXTENDEDTEXTMETRICS:
329 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
331 textData->nSize = cbInput;
332 textData->lpindata = lpInData;
333 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
334 textData->lpXForm = win16drv_SegPtr_TextXForm;
335 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
336 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
337 SEGPTR_GET(textData), lpOutData);
338 SEGPTR_FREE(textData);
340 break;
341 case STARTDOC:
342 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
343 lpInData, lpOutData);
344 if (nRet != -1)
346 HDC *tmpHdc = SEGPTR_NEW(HDC);
348 #define SETPRINTERDC SETABORTPROC
350 *tmpHdc = dc->hSelf;
351 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
352 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
353 SEGPTR_FREE(tmpHdc);
355 break;
356 default:
357 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
358 lpInData, lpOutData);
359 break;
362 else
363 WARN("Escape(nEscape = %04x) - ???\n", nEscape);
364 return nRet;