riched20: Use WARN() not ERR() on unknown tokens.
[wine] / dlls / gdi32 / driver.c
1 /*
2  * Graphics driver management functions
3  *
4  * Copyright 1994 Bob Amstadt
5  * Copyright 1996, 2001 Alexandre Julliard
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31
32 #include "gdi.h"
33 #include "gdi_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(driver);
38
39 struct graphics_driver
40 {
41     struct graphics_driver *next;
42     struct graphics_driver *prev;
43     HMODULE                 module;  /* module handle */
44     unsigned int            count;   /* reference count */
45     DC_FUNCTIONS            funcs;
46 };
47
48 static struct graphics_driver *first_driver;
49 static struct graphics_driver *display_driver;
50
51 static CRITICAL_SECTION driver_section;
52 static CRITICAL_SECTION_DEBUG critsect_debug =
53 {
54     0, 0, &driver_section,
55     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
56       0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
57 };
58 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
59
60 /**********************************************************************
61  *           create_driver
62  *
63  * Allocate and fill the driver structure for a given module.
64  */
65 static struct graphics_driver *create_driver( HMODULE module )
66 {
67     struct graphics_driver *driver;
68
69     if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
70     driver->next   = NULL;
71     driver->prev   = NULL;
72     driver->module = module;
73     driver->count  = 1;
74
75     /* fill the function table */
76     if (module)
77     {
78 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
79         GET_FUNC(AbortDoc);
80         GET_FUNC(AbortPath);
81         GET_FUNC(AlphaBlend);
82         GET_FUNC(AngleArc);
83         GET_FUNC(Arc);
84         GET_FUNC(ArcTo);
85         GET_FUNC(BeginPath);
86         GET_FUNC(BitBlt);
87         GET_FUNC(ChoosePixelFormat);
88         GET_FUNC(Chord);
89         GET_FUNC(CloseFigure);
90         GET_FUNC(CreateBitmap);
91         GET_FUNC(CreateDC);
92         GET_FUNC(CreateDIBSection);
93         GET_FUNC(DeleteBitmap);
94         GET_FUNC(DeleteDC);
95         GET_FUNC(DescribePixelFormat);
96         GET_FUNC(DeviceCapabilities);
97         GET_FUNC(Ellipse);
98         GET_FUNC(EndDoc);
99         GET_FUNC(EndPage);
100         GET_FUNC(EndPath);
101         GET_FUNC(EnumDeviceFonts);
102         GET_FUNC(ExcludeClipRect);
103         GET_FUNC(ExtDeviceMode);
104         GET_FUNC(ExtEscape);
105         GET_FUNC(ExtFloodFill);
106         GET_FUNC(ExtSelectClipRgn);
107         GET_FUNC(ExtTextOut);
108         GET_FUNC(FillPath);
109         GET_FUNC(FillRgn);
110         GET_FUNC(FlattenPath);
111         GET_FUNC(FrameRgn);
112         GET_FUNC(GdiComment);
113         GET_FUNC(GetBitmapBits);
114         GET_FUNC(GetCharWidth);
115         GET_FUNC(GetDCOrgEx);
116         GET_FUNC(GetDIBColorTable);
117         GET_FUNC(GetDIBits);
118         GET_FUNC(GetDeviceCaps);
119         GET_FUNC(GetDeviceGammaRamp);
120         GET_FUNC(GetNearestColor);
121         GET_FUNC(GetPixel);
122         GET_FUNC(GetPixelFormat);
123         GET_FUNC(GetSystemPaletteEntries);
124         GET_FUNC(GetTextExtentExPoint);
125         GET_FUNC(GetTextMetrics);
126         GET_FUNC(IntersectClipRect);
127         GET_FUNC(InvertRgn);
128         GET_FUNC(LineTo);
129         GET_FUNC(MoveTo);
130         GET_FUNC(ModifyWorldTransform);
131         GET_FUNC(OffsetClipRgn);
132         GET_FUNC(OffsetViewportOrg);
133         GET_FUNC(OffsetWindowOrg);
134         GET_FUNC(PaintRgn);
135         GET_FUNC(PatBlt);
136         GET_FUNC(Pie);
137         GET_FUNC(PolyBezier);
138         GET_FUNC(PolyBezierTo);
139         GET_FUNC(PolyDraw);
140         GET_FUNC(PolyPolygon);
141         GET_FUNC(PolyPolyline);
142         GET_FUNC(Polygon);
143         GET_FUNC(Polyline);
144         GET_FUNC(PolylineTo);
145         GET_FUNC(RealizeDefaultPalette);
146         GET_FUNC(RealizePalette);
147         GET_FUNC(Rectangle);
148         GET_FUNC(ResetDC);
149         GET_FUNC(RestoreDC);
150         GET_FUNC(RoundRect);
151         GET_FUNC(SaveDC);
152         GET_FUNC(ScaleViewportExt);
153         GET_FUNC(ScaleWindowExt);
154         GET_FUNC(SelectBitmap);
155         GET_FUNC(SelectBrush);
156         GET_FUNC(SelectClipPath);
157         GET_FUNC(SelectFont);
158         GET_FUNC(SelectPalette);
159         GET_FUNC(SelectPen);
160         GET_FUNC(SetArcDirection);
161         GET_FUNC(SetBitmapBits);
162         GET_FUNC(SetBkColor);
163         GET_FUNC(SetBkMode);
164         GET_FUNC(SetDCBrushColor);
165         GET_FUNC(SetDCOrg);
166         GET_FUNC(SetDCPenColor);
167         GET_FUNC(SetDIBColorTable);
168         GET_FUNC(SetDIBits);
169         GET_FUNC(SetDIBitsToDevice);
170         GET_FUNC(SetDeviceClipping);
171         GET_FUNC(SetDeviceGammaRamp);
172         GET_FUNC(SetMapMode);
173         GET_FUNC(SetMapperFlags);
174         GET_FUNC(SetPixel);
175         GET_FUNC(SetPixelFormat);
176         GET_FUNC(SetPolyFillMode);
177         GET_FUNC(SetROP2);
178         GET_FUNC(SetRelAbs);
179         GET_FUNC(SetStretchBltMode);
180         GET_FUNC(SetTextAlign);
181         GET_FUNC(SetTextCharacterExtra);
182         GET_FUNC(SetTextColor);
183         GET_FUNC(SetTextJustification);
184         GET_FUNC(SetViewportExt);
185         GET_FUNC(SetViewportOrg);
186         GET_FUNC(SetWindowExt);
187         GET_FUNC(SetWindowOrg);
188         GET_FUNC(SetWorldTransform);
189         GET_FUNC(StartDoc);
190         GET_FUNC(StartPage);
191         GET_FUNC(StretchBlt);
192         GET_FUNC(StretchDIBits);
193         GET_FUNC(StrokeAndFillPath);
194         GET_FUNC(StrokePath);
195         GET_FUNC(SwapBuffers);
196         GET_FUNC(WidenPath);
197
198         /* OpenGL32 */
199         GET_FUNC(wglCreateContext);
200         GET_FUNC(wglDeleteContext);
201         GET_FUNC(wglGetProcAddress);
202         GET_FUNC(wglMakeContextCurrentARB);
203         GET_FUNC(wglMakeCurrent);
204         GET_FUNC(wglShareLists);
205         GET_FUNC(wglUseFontBitmapsA);
206         GET_FUNC(wglUseFontBitmapsW);
207 #undef GET_FUNC
208     }
209     else memset( &driver->funcs, 0, sizeof(driver->funcs) );
210
211     /* add it to the list */
212     driver->prev = NULL;
213     if ((driver->next = first_driver)) driver->next->prev = driver;
214     first_driver = driver;
215     return driver;
216 }
217
218
219 /**********************************************************************
220  *           load_display_driver
221  *
222  * Special case for loading the display driver: get the name from the config file
223  */
224 static struct graphics_driver *load_display_driver(void)
225 {
226     char buffer[MAX_PATH], libname[32], *name, *next;
227     HMODULE module = 0;
228     HKEY hkey;
229
230     if (display_driver)  /* already loaded */
231     {
232         display_driver->count++;
233         return display_driver;
234     }
235
236     strcpy( buffer, "x11" );  /* default value */
237     /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
238     if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
239     {
240         DWORD type, count = sizeof(buffer);
241         RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
242         RegCloseKey( hkey );
243     }
244
245     name = buffer;
246     while (name)
247     {
248         next = strchr( name, ',' );
249         if (next) *next++ = 0;
250
251         snprintf( libname, sizeof(libname), "wine%s.drv", name );
252         if ((module = LoadLibraryA( libname )) != 0) break;
253         name = next;
254     }
255
256     if (!(display_driver = create_driver( module )))
257     {
258         MESSAGE( "Could not create graphics driver '%s'\n", buffer );
259         FreeLibrary( module );
260         ExitProcess(1);
261     }
262
263     display_driver->count++;  /* we don't want to free it */
264     return display_driver;
265 }
266
267
268 /**********************************************************************
269  *           DRIVER_load_driver
270  */
271 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
272 {
273     HMODULE module;
274     struct graphics_driver *driver;
275     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
276     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
277
278     EnterCriticalSection( &driver_section );
279
280     /* display driver is a special case */
281     if (!strcmpiW( name, displayW ) || 
282         !strcmpiW( name, display1W ))
283     {
284         driver = load_display_driver();
285         LeaveCriticalSection( &driver_section );
286         return &driver->funcs;
287     }
288
289     if ((module = GetModuleHandleW( name )))
290     {
291         for (driver = first_driver; driver; driver = driver->next)
292         {
293             if (driver->module == module)
294             {
295                 driver->count++;
296                 LeaveCriticalSection( &driver_section );
297                 return &driver->funcs;
298             }
299         }
300     }
301
302     if (!(module = LoadLibraryW( name )))
303     {
304         LeaveCriticalSection( &driver_section );
305         return NULL;
306     }
307
308     if (!(driver = create_driver( module )))
309     {
310         FreeLibrary( module );
311         LeaveCriticalSection( &driver_section );
312         return NULL;
313     }
314
315     TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
316     LeaveCriticalSection( &driver_section );
317     return &driver->funcs;
318 }
319
320
321 /**********************************************************************
322  *           DRIVER_get_driver
323  *
324  * Get a new copy of an existing driver.
325  */
326 const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs )
327 {
328     struct graphics_driver *driver;
329
330     EnterCriticalSection( &driver_section );
331     for (driver = first_driver; driver; driver = driver->next)
332         if (&driver->funcs == funcs) break;
333     if (!driver) ERR( "driver not found, trouble ahead\n" );
334     driver->count++;
335     LeaveCriticalSection( &driver_section );
336     return funcs;
337 }
338
339
340 /**********************************************************************
341  *           DRIVER_release_driver
342  *
343  * Release a driver by decrementing ref count and freeing it if needed.
344  */
345 void DRIVER_release_driver( const DC_FUNCTIONS *funcs )
346 {
347     struct graphics_driver *driver;
348
349     EnterCriticalSection( &driver_section );
350
351     for (driver = first_driver; driver; driver = driver->next)
352         if (&driver->funcs == funcs) break;
353
354     if (!driver) goto done;
355     if (--driver->count) goto done;
356
357     /* removed last reference, free it */
358     if (driver->next) driver->next->prev = driver->prev;
359     if (driver->prev) driver->prev->next = driver->next;
360     else first_driver = driver->next;
361     if (driver == display_driver) display_driver = NULL;
362
363     FreeLibrary( driver->module );
364     HeapFree( GetProcessHeap(), 0, driver );
365  done:
366     LeaveCriticalSection( &driver_section );
367 }
368
369
370 /*****************************************************************************
371  *      DRIVER_GetDriverName
372  *
373  */
374 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
375 {
376     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
377     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
378     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
379     static const WCHAR empty_strW[] = { 0 };
380     WCHAR *p;
381
382     /* display is a special case */
383     if (!strcmpiW( device, displayW ) ||
384         !strcmpiW( device, display1W ))
385     {
386         lstrcpynW( driver, displayW, size );
387         return TRUE;
388     }
389
390     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
391     if(!size) {
392         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
393         return FALSE;
394     }
395     p = strchrW(driver, ',');
396     if(!p)
397     {
398         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
399         return FALSE;
400     }
401     *p = 0;
402     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
403     return TRUE;
404 }
405
406
407 /***********************************************************************
408  *           GdiConvertToDevmodeW    (GDI32.@)
409  */
410 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
411 {
412     DEVMODEW *dmW;
413     WORD dmW_size;
414
415     dmW_size = dmA->dmSize + CCHDEVICENAME;
416     if (dmA->dmSize >= (const char *)dmA->dmFormName - (const char *)dmA + CCHFORMNAME)
417         dmW_size += CCHFORMNAME;
418
419     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
420     if (!dmW) return NULL;
421
422     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, CCHDEVICENAME,
423                                    dmW->dmDeviceName, CCHDEVICENAME);
424     /* copy slightly more, to avoid long computations */
425     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA->dmSize - CCHDEVICENAME);
426
427     if (dmA->dmSize >= (const char *)dmA->dmFormName - (const char *)dmA + CCHFORMNAME)
428     {
429         MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, CCHFORMNAME,
430                                        dmW->dmFormName, CCHFORMNAME);
431         if (dmA->dmSize > (const char *)&dmA->dmLogPixels - (const char *)dmA)
432             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA->dmSize - ((const char *)&dmA->dmLogPixels - (const char *)dmA));
433     }
434
435     if (dmA->dmDriverExtra)
436         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA->dmSize, dmA->dmDriverExtra);
437
438     dmW->dmSize = dmW_size;
439
440     return dmW;
441 }
442
443
444 /*****************************************************************************
445  *      @ [GDI32.100]
446  *
447  * This should thunk to 16-bit and simply call the proc with the given args.
448  */
449 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
450                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
451 {
452     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
453     return -1;
454 }
455
456 /*****************************************************************************
457  *      @ [GDI32.101]
458  *
459  * This should load the correct driver for lpszDevice and calls this driver's
460  * ExtDeviceModePropSheet proc.
461  *
462  * Note: The driver calls a callback routine for each property sheet page; these
463  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
464  * The layout of this structure is:
465  *
466  * struct
467  * {
468  *   DWORD  nPages;
469  *   DWORD  unknown;
470  *   HPROPSHEETPAGE  pages[10];
471  * };
472  */
473 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
474                                              LPCSTR lpszPort, LPVOID lpPropSheet )
475 {
476     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
477     return -1;
478 }
479
480 /*****************************************************************************
481  *      @ [GDI32.102]
482  *
483  * This should load the correct driver for lpszDevice and calls this driver's
484  * ExtDeviceMode proc.
485  *
486  * FIXME: convert ExtDeviceMode to unicode in the driver interface
487  */
488 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
489                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
490                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
491                                     LPSTR lpszProfile, DWORD fwMode )
492 {
493     WCHAR deviceW[300];
494     WCHAR bufW[300];
495     char buf[300];
496     HDC hdc;
497     DC *dc;
498     INT ret = -1;
499     INT (*pExtDeviceMode)(LPSTR,HWND,LPDEVMODEA,LPSTR,LPSTR,LPDEVMODEA,LPSTR,DWORD);
500
501     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
502           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
503
504     if (!lpszDevice) return -1;
505     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
506
507     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
508
509     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
510
511     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
512
513     if ((dc = DC_GetDCPtr( hdc )))
514     {
515         pExtDeviceMode = dc->funcs->pExtDeviceMode;
516         GDI_ReleaseObj( hdc );
517         if (pExtDeviceMode)
518             ret = pExtDeviceMode(buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
519                                             lpdmInput, lpszProfile, fwMode);
520     }
521     DeleteDC( hdc );
522     return ret;
523 }
524
525 /****************************************************************************
526  *      @ [GDI32.103]
527  *
528  * This should load the correct driver for lpszDevice and calls this driver's
529  * AdvancedSetupDialog proc.
530  */
531 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
532                                           LPDEVMODEA devin, LPDEVMODEA devout )
533 {
534     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
535     return -1;
536 }
537
538 /*****************************************************************************
539  *      @ [GDI32.104]
540  *
541  * This should load the correct driver for lpszDevice and calls this driver's
542  * DeviceCapabilities proc.
543  *
544  * FIXME: convert DeviceCapabilities to unicode in the driver interface
545  */
546 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
547                                            WORD fwCapability, LPSTR lpszOutput,
548                                            LPDEVMODEA lpdm )
549 {
550     WCHAR deviceW[300];
551     WCHAR bufW[300];
552     char buf[300];
553     HDC hdc;
554     DC *dc;
555     INT ret = -1;
556
557     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
558
559     if (!lpszDevice) return -1;
560     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
561
562     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
563
564     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
565
566     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
567
568     if ((dc = DC_GetDCPtr( hdc )))
569     {
570         if (dc->funcs->pDeviceCapabilities)
571             ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
572                                                   fwCapability, lpszOutput, lpdm );
573         GDI_ReleaseObj( hdc );
574     }
575     DeleteDC( hdc );
576     return ret;
577 }
578
579
580 /************************************************************************
581  *             Escape  [GDI32.@]
582  */
583 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
584 {
585     INT ret;
586     POINT *pt;
587
588     switch (escape)
589     {
590     case ABORTDOC:
591         return AbortDoc( hdc );
592
593     case ENDDOC:
594         return EndDoc( hdc );
595
596     case GETPHYSPAGESIZE:
597         pt = out_data;
598         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
599         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
600         return 1;
601
602     case GETPRINTINGOFFSET:
603         pt = out_data;
604         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
605         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
606         return 1;
607
608     case GETSCALINGFACTOR:
609         pt = out_data;
610         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
611         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
612         return 1;
613
614     case NEWFRAME:
615         return EndPage( hdc );
616
617     case SETABORTPROC:
618         return SetAbortProc( hdc, (ABORTPROC)in_data );
619
620     case STARTDOC:
621         {
622             DOCINFOA doc;
623             char *name = NULL;
624
625             /* in_data may not be 0 terminated so we must copy it */
626             if (in_data)
627             {
628                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
629                 memcpy( name, in_data, in_count );
630                 name[in_count] = 0;
631             }
632             /* out_data is actually a pointer to the DocInfo structure and used as
633              * a second input parameter */
634             if (out_data) doc = *(DOCINFOA *)out_data;
635             else
636             {
637                 doc.cbSize = sizeof(doc);
638                 doc.lpszOutput = NULL;
639                 doc.lpszDatatype = NULL;
640                 doc.fwType = 0;
641             }
642             doc.lpszDocName = name;
643             ret = StartDocA( hdc, &doc );
644             HeapFree( GetProcessHeap(), 0, name );
645             if (ret > 0) ret = StartPage( hdc );
646             return ret;
647         }
648
649     case QUERYESCSUPPORT:
650         {
651             const INT *ptr = (const INT *)in_data;
652             if (in_count < sizeof(INT)) return 0;
653             switch(*ptr)
654             {
655             case ABORTDOC:
656             case ENDDOC:
657             case GETPHYSPAGESIZE:
658             case GETPRINTINGOFFSET:
659             case GETSCALINGFACTOR:
660             case NEWFRAME:
661             case QUERYESCSUPPORT:
662             case SETABORTPROC:
663             case STARTDOC:
664                 return TRUE;
665             }
666             break;
667         }
668     }
669
670     /* if not handled internally, pass it to the driver */
671     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
672 }
673
674
675 /******************************************************************************
676  *              ExtEscape       [GDI32.@]
677  *
678  * Access capabilities of a particular device that are not available through GDI.
679  *
680  * PARAMS
681  *    hdc         [I] Handle to device context
682  *    nEscape     [I] Escape function
683  *    cbInput     [I] Number of bytes in input structure
684  *    lpszInData  [I] Pointer to input structure
685  *    cbOutput    [I] Number of bytes in output structure
686  *    lpszOutData [O] Pointer to output structure
687  *
688  * RETURNS
689  *    Success: >0
690  *    Not implemented: 0
691  *    Failure: <0
692  */
693 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
694                       INT cbOutput, LPSTR lpszOutData )
695 {
696     INT ret = 0;
697     DC * dc = DC_GetDCPtr( hdc );
698     if (dc)
699     {
700         if (dc->funcs->pExtEscape)
701             ret = dc->funcs->pExtEscape( dc->physDev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
702         GDI_ReleaseObj( hdc );
703     }
704     return ret;
705 }
706
707
708 /*******************************************************************
709  *      DrawEscape [GDI32.@]
710  *
711  *
712  */
713 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
714 {
715     FIXME("DrawEscape, stub\n");
716     return 0;
717 }