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