Large-scale renaming of all Win32 functions and types to use the
[wine/multimedia.git] / graphics / win16drv / init.c
blobd8ae969be6d0c0e7b0886d7b7993a37cde83a057
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 "debug.h"
18 #include "dc.h"
20 #define SUPPORT_REALIZED_FONTS 1
21 #pragma pack(1)
22 typedef struct
24 SHORT nSize;
25 SEGPTR lpindata;
26 SEGPTR lpFont;
27 SEGPTR lpXForm;
28 SEGPTR lpDrawMode;
29 } EXTTEXTDATA, *LPEXTTEXTDATA;
30 #pragma pack(4)
32 SEGPTR win16drv_SegPtr_TextXForm;
33 LPTEXTXFORM16 win16drv_TextXFormP;
34 SEGPTR win16drv_SegPtr_DrawMode;
35 LPDRAWMODE win16drv_DrawModeP;
38 static BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
39 LPCSTR output, const DEVMODE16* initData );
40 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
41 SEGPTR lpInData, SEGPTR lpOutData );
43 static const DC_FUNCTIONS WIN16DRV_Funcs =
45 NULL, /* pArc */
46 NULL, /* pBitBlt */
47 NULL, /* pBitmapBits */
48 NULL, /* pChord */
49 NULL, /* pCreateBitmap */
50 WIN16DRV_CreateDC, /* pCreateDC */
51 NULL, /* pDeleteDC */
52 NULL, /* pDeleteObject */
53 WIN16DRV_Ellipse, /* pEllipse */
54 WIN16DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
55 WIN16DRV_Escape, /* pEscape */
56 NULL, /* pExcludeClipRect */
57 NULL, /* pExcludeVisRect */
58 NULL, /* pExtFloodFill */
59 WIN16DRV_ExtTextOut, /* pExtTextOut */
60 WIN16DRV_GetCharWidth, /* pGetCharWidth */
61 NULL, /* pGetPixel */
62 WIN16DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
63 WIN16DRV_GetTextMetrics, /* pGetTextMetrics */
64 NULL, /* pIntersectClipRect */
65 NULL, /* pIntersectVisRect */
66 WIN16DRV_LineTo, /* pLineTo */
67 NULL, /* pLoadOEMResource */
68 WIN16DRV_MoveToEx, /* pMoveToEx */
69 NULL, /* pOffsetClipRgn */
70 NULL, /* pOffsetViewportOrgEx */
71 NULL, /* pOffsetWindowOrgEx */
72 NULL, /* pPaintRgn */
73 WIN16DRV_PatBlt, /* pPatBlt */
74 NULL, /* pPie */
75 NULL, /* pPolyPolygon */
76 NULL, /* pPolyPolyline */
77 WIN16DRV_Polygon, /* pPolygon */
78 WIN16DRV_Polyline, /* pPolyline */
79 NULL, /* pPolyBezier */
80 NULL, /* pRealizePalette */
81 WIN16DRV_Rectangle, /* pRectangle */
82 NULL, /* pRestoreDC */
83 NULL, /* pRoundRect */
84 NULL, /* pSaveDC */
85 NULL, /* pScaleViewportExtEx */
86 NULL, /* pScaleWindowExtEx */
87 NULL, /* pSelectClipRgn */
88 WIN16DRV_SelectObject, /* pSelectObject */
89 NULL, /* pSelectPalette */
90 NULL, /* pSetBkColor */
91 NULL, /* pSetBkMode */
92 NULL, /* pSetDeviceClipping */
93 NULL, /* pSetDIBitsToDevice */
94 NULL, /* pSetMapMode */
95 NULL, /* pSetMapperFlags */
96 NULL, /* pSetPixel */
97 NULL, /* pSetPolyFillMode */
98 NULL, /* pSetROP2 */
99 NULL, /* pSetRelAbs */
100 NULL, /* pSetStretchBltMode */
101 NULL, /* pSetTextAlign */
102 NULL, /* pSetTextCharacterExtra */
103 NULL, /* pSetTextColor */
104 NULL, /* pSetTextJustification */
105 NULL, /* pSetViewportExtEx */
106 NULL, /* pSetViewportOrgEx */
107 NULL, /* pSetWindowExtEx */
108 NULL, /* pSetWindowOrgEx */
109 NULL, /* pStretchBlt */
110 NULL /* pStretchDIBits */
117 /**********************************************************************
118 * WIN16DRV_Init
120 BOOL WIN16DRV_Init(void)
122 return DRIVER_RegisterDriver( NULL /* generic driver */, &WIN16DRV_Funcs );
126 /* Tempory functions, for initialising structures */
127 /* These values should be calculated, not hardcoded */
128 void InitTextXForm(LPTEXTXFORM16 lpTextXForm)
130 lpTextXForm->txfHeight = 0x0001;
131 lpTextXForm->txfWidth = 0x000c;
132 lpTextXForm->txfEscapement = 0x0000;
133 lpTextXForm->txfOrientation = 0x0000;
134 lpTextXForm->txfWeight = 0x0190;
135 lpTextXForm->txfItalic = 0x00;
136 lpTextXForm->txfUnderline = 0x00;
137 lpTextXForm->txfStrikeOut = 0x00;
138 lpTextXForm->txfOutPrecision = 0x02;
139 lpTextXForm->txfClipPrecision = 0x01;
140 lpTextXForm->txfAccelerator = 0x0001;
141 lpTextXForm->txfOverhang = 0x0000;
145 void InitDrawMode(LPDRAWMODE lpDrawMode)
147 lpDrawMode->Rop2 = 0x000d;
148 lpDrawMode->bkMode = 0x0001;
149 lpDrawMode->bkColor = 0x3fffffff;
150 lpDrawMode->TextColor = 0x20000000;
151 lpDrawMode->TBreakExtra = 0x0000;
152 lpDrawMode->BreakExtra = 0x0000;
153 lpDrawMode->BreakErr = 0x0000;
154 lpDrawMode->BreakRem = 0x0000;
155 lpDrawMode->BreakCount = 0x0000;
156 lpDrawMode->CharExtra = 0x0000;
157 lpDrawMode->LbkColor = 0x00ffffff;
158 lpDrawMode->LTextColor = 0x00000000;
161 BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output,
162 const DEVMODE16* initData )
164 LOADED_PRINTER_DRIVER *pLPD;
165 WORD wRet;
166 DeviceCaps *printerDevCaps;
167 int nPDEVICEsize;
168 PDEVICE_HEADER *pPDH;
169 WIN16DRV_PDEVICE *physDev;
170 char printerEnabled[20];
171 PROFILE_GetWineIniString( "wine", "printer", "off",
172 printerEnabled, sizeof(printerEnabled) );
173 if (lstrcmpiA(printerEnabled,"on"))
175 MSG("Printing disabled in wine.conf or .winerc file\n");
176 MSG("Use \"printer=on\" in the \"[wine]\" section to enable it.\n");
177 return FALSE;
180 TRACE(win16drv, "In creatdc for (%s,%s,%s) initData 0x%p\n",
181 driver, device, output, initData);
183 physDev = (WIN16DRV_PDEVICE *)HeapAlloc( SystemHeap, 0, sizeof(*physDev) );
184 if (!physDev) return FALSE;
185 dc->physDev = physDev;
187 pLPD = LoadPrinterDriver(driver);
188 if (pLPD == NULL)
190 WARN(win16drv, "Failed to find printer driver\n");
191 HeapFree( SystemHeap, 0, physDev );
192 return FALSE;
194 TRACE(win16drv, "windevCreateDC pLPD 0x%p\n", pLPD);
196 /* Now Get the device capabilities from the printer driver */
198 printerDevCaps = (DeviceCaps *) xmalloc(sizeof(DeviceCaps));
199 memset(printerDevCaps, 0, sizeof(DeviceCaps));
201 /* Get GDIINFO which is the same as a DeviceCaps structure */
202 wRet = PRTDRV_Enable(printerDevCaps, GETGDIINFO, device, driver, output,NULL);
204 /* Add this to the DC */
205 dc->w.devCaps = printerDevCaps;
206 dc->w.hVisRgn = CreateRectRgn(0, 0, dc->w.devCaps->horzRes, dc->w.devCaps->vertRes);
207 dc->w.bitsPerPixel = dc->w.devCaps->bitsPixel;
209 TRACE(win16drv, "Got devcaps width %d height %d bits %d planes %d\n",
210 dc->w.devCaps->horzRes, dc->w.devCaps->vertRes,
211 dc->w.devCaps->bitsPixel, dc->w.devCaps->planes);
213 /* Now we allocate enough memory for the PDEVICE structure */
214 /* The size of this varies between printer drivers */
215 /* This PDEVICE is used by the printer DRIVER not by the GDI so must */
216 /* be accessable from 16 bit code */
217 nPDEVICEsize = dc->w.devCaps->pdeviceSize + sizeof(PDEVICE_HEADER);
219 /* TTD Shouldn't really do pointer arithmetic on segment points */
220 physDev->segptrPDEVICE = WIN16_GlobalLock16(GlobalAlloc16(GHND, nPDEVICEsize))+sizeof(PDEVICE_HEADER);
221 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+0) = 'N';
222 *((BYTE *)PTR_SEG_TO_LIN(physDev->segptrPDEVICE)+1) = 'B';
224 /* Set up the header */
225 pPDH = (PDEVICE_HEADER *)((BYTE*)PTR_SEG_TO_LIN(physDev->segptrPDEVICE) - sizeof(PDEVICE_HEADER));
226 pPDH->pLPD = pLPD;
228 TRACE(win16drv, "PDEVICE allocated %08lx\n",(DWORD)(physDev->segptrPDEVICE));
230 /* Now get the printer driver to initialise this data */
231 wRet = PRTDRV_Enable((LPVOID)physDev->segptrPDEVICE, INITPDEVICE, device, driver, output, NULL);
233 physDev->FontInfo = NULL;
234 physDev->BrushInfo = NULL;
235 physDev->PenInfo = NULL;
236 win16drv_SegPtr_TextXForm = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(TEXTXFORM16)));
237 win16drv_TextXFormP = PTR_SEG_TO_LIN(win16drv_SegPtr_TextXForm);
239 InitTextXForm(win16drv_TextXFormP);
241 /* TTD Lots more to do here */
242 win16drv_SegPtr_DrawMode = WIN16_GlobalLock16(GlobalAlloc16(GHND, sizeof(DRAWMODE)));
243 win16drv_DrawModeP = PTR_SEG_TO_LIN(win16drv_SegPtr_DrawMode);
245 InitDrawMode(win16drv_DrawModeP);
247 return TRUE;
250 BOOL WIN16DRV_PatBlt( struct tagDC *dc, INT left, INT top,
251 INT width, INT height, DWORD rop )
254 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
255 BOOL bRet = 0;
257 bRet = PRTDRV_StretchBlt( physDev->segptrPDEVICE, left, top, width, height, (SEGPTR)NULL, 0, 0, width, height,
258 PATCOPY, physDev->BrushInfo, win16drv_SegPtr_DrawMode, NULL);
260 return bRet;
263 * Escape (GDI.38)
265 static INT WIN16DRV_Escape( DC *dc, INT nEscape, INT cbInput,
266 SEGPTR lpInData, SEGPTR lpOutData )
268 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
269 int nRet = 0;
271 /* We should really process the nEscape parameter, but for now just
272 pass it all to the driver */
273 if (dc != NULL && physDev->segptrPDEVICE != 0)
275 switch(nEscape)
277 case ENABLEPAIRKERNING:
278 FIXME(win16drv,"Escape: ENABLEPAIRKERNING ignored.\n");
279 nRet = 1;
280 break;
281 case GETPAIRKERNTABLE:
282 FIXME(win16drv,"Escape: GETPAIRKERNTABLE ignored.\n");
283 nRet = 0;
284 break;
285 case SETABORTPROC: {
286 /* FIXME: The AbortProc should be called:
287 - After every write to printer port or spool file
288 - Several times when no more disk space
289 - Before every metafile record when GDI does banding
292 /* save the callback address and call Control with hdc as lpInData */
293 HDC16 *seghdc = SEGPTR_NEW(HDC16);
294 *seghdc = dc->hSelf;
295 dc->w.lpfnPrint = (FARPROC16)lpInData;
296 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
297 SEGPTR_GET(seghdc), lpOutData);
298 SEGPTR_FREE(seghdc);
299 break;
302 case NEXTBAND:
304 LPPOINT16 newInData = SEGPTR_NEW(POINT16);
306 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
307 SEGPTR_GET(newInData), lpOutData);
308 SEGPTR_FREE(newInData);
309 break;
312 case GETEXTENDEDTEXTMETRICS:
314 EXTTEXTDATA *textData = SEGPTR_NEW(EXTTEXTDATA);
316 textData->nSize = cbInput;
317 textData->lpindata = lpInData;
318 textData->lpFont = SEGPTR_GET( physDev->FontInfo );
319 textData->lpXForm = win16drv_SegPtr_TextXForm;
320 textData->lpDrawMode = win16drv_SegPtr_DrawMode;
321 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
322 SEGPTR_GET(textData), lpOutData);
323 SEGPTR_FREE(textData);
325 break;
326 case STARTDOC:
327 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
328 lpInData, lpOutData);
329 if (nRet != -1)
331 HDC *tmpHdc = SEGPTR_NEW(HDC);
333 #define SETPRINTERDC SETABORTPROC
335 *tmpHdc = dc->hSelf;
336 PRTDRV_Control(physDev->segptrPDEVICE, SETPRINTERDC,
337 SEGPTR_GET(tmpHdc), (SEGPTR)NULL);
338 SEGPTR_FREE(tmpHdc);
340 break;
341 default:
342 nRet = PRTDRV_Control(physDev->segptrPDEVICE, nEscape,
343 lpInData, lpOutData);
344 break;
347 else
348 WARN(win16drv, "Escape(nEscape = %04x) - ???\n", nEscape);
349 return nRet;