Copy the first 128 colors from the default colormap to Wine's private
[wine.git] / graphics / escape.c
blobd53f92360e4d82bf2b347111780d96f244c9172b
1 /*
2 * Escape() function.
4 * Copyright 1994 Bob Amstadt
5 */
7 #include <string.h>
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "gdi.h"
11 #include "heap.h"
12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(driver);
16 /***********************************************************************
17 * Escape16 [GDI.38]
19 INT16 WINAPI Escape16( HDC16 hdc, INT16 nEscape, INT16 cbInput,
20 SEGPTR lpszInData, SEGPTR lpvOutData )
22 INT16 ret = 0;
23 DC * dc = DC_GetDCPtr( hdc );
24 if (dc)
26 if (dc->funcs->pEscape)
28 if(nEscape == SETABORTPROC) SetAbortProc16(hdc, lpszInData);
29 ret = dc->funcs->pEscape( dc, nEscape, cbInput, lpszInData, lpvOutData );
31 GDI_ReleaseObj( hdc );
33 return ret;
36 /************************************************************************
37 * Escape [GDI32.@]
39 INT WINAPI Escape( HDC hdc, INT nEscape, INT cbInput,
40 LPCSTR lpszInData, LPVOID lpvOutData )
42 SEGPTR segin,segout;
43 INT ret = 0;
44 DC * dc = DC_GetDCPtr( hdc );
45 if (!dc) return 0;
46 if (!dc->funcs->pEscape) goto done;
48 segin = (SEGPTR)lpszInData;
49 segout = (SEGPTR)lpvOutData;
50 switch (nEscape) {
51 /* Escape(hdc,QUERYESCSUPPORT,LPINT,NULL) */
52 /* Escape(hdc,CLIP_TO_PATH,LPINT,NULL) */
53 case QUERYESCSUPPORT:
54 case CLIP_TO_PATH:
56 LPINT16 x = (LPINT16)SEGPTR_NEW(INT16);
57 *x = *(INT*)lpszInData;
58 segin = SEGPTR_GET(x);
59 cbInput = sizeof(INT16);
60 break;
63 /* Escape(hdc,GETSCALINGFACTOR,NULL,LPPOINT32) */
64 /* Escape(hdc,GETPHYSPAGESIZE,NULL,LPPOINT32) */
65 /* Escape(hdc,GETPRINTINGOFFSET,NULL,LPPOINT32) */
67 case GETSCALINGFACTOR:
68 case GETPHYSPAGESIZE:
69 case GETPRINTINGOFFSET:
70 segout = SEGPTR_GET(SEGPTR_NEW(POINT16));
71 cbInput = sizeof(POINT16);
72 break;
74 /* Escape(hdc,EXT_DEVICE_CAPS,LPINT,LPDWORD) */
75 case EXT_DEVICE_CAPS:
77 LPINT16 lpIndex = (LPINT16)SEGPTR_NEW(INT16);
78 LPDWORD lpCaps = (LPDWORD)SEGPTR_NEW(DWORD);
79 *lpIndex = *(INT*)lpszInData;
81 segin = SEGPTR_GET(lpIndex);
82 segout = SEGPTR_GET(lpCaps);
83 cbInput = sizeof(INT16);
84 break;
87 /* Escape(hdc,SETLINECAP,LPINT,LPINT) */
88 case SETLINECAP:
89 case SETLINEJOIN:
90 case SETMITERLIMIT:
92 LPINT16 new = (LPINT16)SEGPTR_NEW(INT16);
93 LPINT16 old = (LPINT16)SEGPTR_NEW(INT16);
94 *new = *(INT*)lpszInData;
95 segin = SEGPTR_GET(new);
96 segout = SEGPTR_GET(old);
97 cbInput = sizeof(INT16);
98 break;
100 /* Escape(hdc,GETTECHNOLOGY,NULL,LPSTR); */
101 case GETTECHNOLOGY: {
102 segout = SEGPTR_GET(SEGPTR_ALLOC(200)); /* enough I hope */
103 break;
107 /* Escape(hdc,ENABLEPAIRKERNING,LPINT16,LPINT16); */
109 case ENABLEPAIRKERNING: {
110 LPINT16 enab = SEGPTR_NEW(INT16);
111 segout = SEGPTR_GET(SEGPTR_NEW(INT16));
112 segin = SEGPTR_GET(enab);
113 *enab = *(INT*)lpszInData;
114 cbInput = sizeof(INT16);
115 break;
118 /* Escape(hdc,GETFACENAME,NULL,LPSTR); */
120 case GETFACENAME: {
121 segout = SEGPTR_GET(SEGPTR_ALLOC(200));
122 break;
125 /* Escape(hdc,STARTDOC,LPSTR,LPDOCINFOA);
126 * lpvOutData is actually a pointer to the DocInfo structure and used as
127 * a second input parameter
130 case STARTDOC: /* string may not be \0 terminated */
131 if(lpszInData) {
132 char *cp = SEGPTR_ALLOC(cbInput);
133 memcpy(cp, lpszInData, cbInput);
134 segin = SEGPTR_GET(cp);
135 } else
136 segin = 0;
138 if(lpvOutData) {
139 DOCINFO16 *lpsegdoc = SEGPTR_NEW(DOCINFO16);
140 DOCINFOA *lpdoc = lpvOutData;
141 memset(lpsegdoc, 0, sizeof(*lpsegdoc));
142 lpsegdoc->cbSize = sizeof(*lpsegdoc);
143 lpsegdoc->lpszDocName = SEGPTR_GET(SEGPTR_STRDUP(lpdoc->lpszDocName));
144 lpsegdoc->lpszOutput = SEGPTR_GET(SEGPTR_STRDUP(lpdoc->lpszOutput));
145 lpsegdoc->lpszDatatype = SEGPTR_GET(SEGPTR_STRDUP(lpdoc->lpszDatatype));
146 lpsegdoc->fwType = lpdoc->fwType;
147 segout = SEGPTR_GET(lpsegdoc);
149 break;
151 case SETABORTPROC:
152 SetAbortProc(hdc, (ABORTPROC)lpszInData);
153 break;
155 /* Escape(hdc,END_PATH,PATHINFO,NULL); */
156 case END_PATH:
158 BYTE *p = SEGPTR_ALLOC(cbInput);
159 memcpy(p, lpszInData, cbInput);
160 segin = SEGPTR_GET(p);
161 break;
164 default:
165 break;
169 ret = dc->funcs->pEscape( dc, nEscape, cbInput, segin, segout );
171 switch(nEscape) {
172 case QUERYESCSUPPORT:
173 if (ret)
174 TRACE("target DC implements Escape %d\n",nEscape);
175 SEGPTR_FREE(MapSL(segin));
176 break;
178 case SETLINECAP:
179 case SETLINEJOIN:
180 case SETMITERLIMIT:
181 *(LPINT)lpvOutData = *(LPINT16)MapSL(segout);
182 SEGPTR_FREE(MapSL(segin));
183 SEGPTR_FREE(MapSL(segout));
184 break;
185 case GETSCALINGFACTOR:
186 case GETPRINTINGOFFSET:
187 case GETPHYSPAGESIZE: {
188 LPPOINT16 x = MapSL(segout);
189 CONV_POINT16TO32(x,(LPPOINT)lpvOutData);
190 SEGPTR_FREE(x);
191 break;
193 case EXT_DEVICE_CAPS:
194 *(LPDWORD)lpvOutData = *(LPDWORD)MapSL(segout);
195 SEGPTR_FREE(MapSL(segin));
196 SEGPTR_FREE(MapSL(segout));
197 break;
199 case GETTECHNOLOGY: {
200 LPSTR x=MapSL(segout);
201 strcpy(lpvOutData,x);
202 SEGPTR_FREE(x);
203 break;
205 case ENABLEPAIRKERNING: {
206 LPINT16 enab = MapSL(segout);
208 *(LPINT)lpvOutData = *enab;
209 SEGPTR_FREE(enab);
210 SEGPTR_FREE(MapSL(segin));
211 break;
213 case GETFACENAME: {
214 LPSTR x = (LPSTR)MapSL(segout);
215 strcpy(lpvOutData,x);
216 SEGPTR_FREE(x);
217 break;
219 case STARTDOC: {
220 DOCINFO16 *doc = MapSL(segout);
221 SEGPTR_FREE(MapSL(doc->lpszDocName));
222 SEGPTR_FREE(MapSL(doc->lpszOutput));
223 SEGPTR_FREE(MapSL(doc->lpszDatatype));
224 SEGPTR_FREE(doc);
225 SEGPTR_FREE(MapSL(segin));
226 break;
229 case CLIP_TO_PATH:
230 case END_PATH:
231 SEGPTR_FREE(MapSL(segin));
232 break;
234 default:
235 break;
237 done:
238 GDI_ReleaseObj( hdc );
239 return ret;
242 /******************************************************************************
243 * ExtEscape [GDI32.@]
245 * PARAMS
246 * hdc [I] Handle to device context
247 * nEscape [I] Escape function
248 * cbInput [I] Number of bytes in input structure
249 * lpszInData [I] Pointer to input structure
250 * cbOutput [I] Number of bytes in output structure
251 * lpszOutData [O] Pointer to output structure
253 * RETURNS
254 * Success: >0
255 * Not implemented: 0
256 * Failure: <0
258 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput,
259 LPCSTR lpszInData, INT cbOutput, LPSTR lpszOutData )
261 char *inBuf, *outBuf;
262 INT ret;
264 inBuf = SEGPTR_ALLOC(cbInput);
265 memcpy(inBuf, lpszInData, cbInput);
266 outBuf = cbOutput ? SEGPTR_ALLOC(cbOutput) : NULL;
267 ret = Escape16( hdc, nEscape, cbInput, SEGPTR_GET(inBuf),
268 SEGPTR_GET(outBuf) );
269 SEGPTR_FREE(inBuf);
270 if(outBuf) {
271 memcpy(lpszOutData, outBuf, cbOutput);
272 SEGPTR_FREE(outBuf);
274 return ret;
277 /*******************************************************************
278 * DrawEscape [GDI32.@]
282 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
284 FIXME("DrawEscape, stub\n");
285 return 0;