wininet: Avoid a crash with traces on.
[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_private.h"
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(driver);
37
38 struct graphics_driver
39 {
40     struct graphics_driver *next;
41     struct graphics_driver *prev;
42     HMODULE                 module;  /* module handle */
43     unsigned int            count;   /* reference count */
44     DC_FUNCTIONS            funcs;
45 };
46
47 static struct graphics_driver *first_driver;
48 static struct graphics_driver *display_driver;
49
50 static CRITICAL_SECTION driver_section;
51 static CRITICAL_SECTION_DEBUG critsect_debug =
52 {
53     0, 0, &driver_section,
54     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
55       0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
56 };
57 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
58
59 /**********************************************************************
60  *           create_driver
61  *
62  * Allocate and fill the driver structure for a given module.
63  */
64 static struct graphics_driver *create_driver( HMODULE module )
65 {
66     struct graphics_driver *driver;
67
68     if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
69     driver->next   = NULL;
70     driver->prev   = NULL;
71     driver->module = module;
72     driver->count  = 1;
73
74     /* fill the function table */
75     if (module)
76     {
77 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
78         GET_FUNC(AbortDoc);
79         GET_FUNC(AbortPath);
80         GET_FUNC(AlphaBlend);
81         GET_FUNC(AngleArc);
82         GET_FUNC(Arc);
83         GET_FUNC(ArcTo);
84         GET_FUNC(BeginPath);
85         GET_FUNC(BitBlt);
86         GET_FUNC(ChoosePixelFormat);
87         GET_FUNC(Chord);
88         GET_FUNC(CloseFigure);
89         GET_FUNC(CreateBitmap);
90         GET_FUNC(CreateDC);
91         GET_FUNC(CreateDIBSection);
92         GET_FUNC(DeleteBitmap);
93         GET_FUNC(DeleteDC);
94         GET_FUNC(DescribePixelFormat);
95         GET_FUNC(DeviceCapabilities);
96         GET_FUNC(Ellipse);
97         GET_FUNC(EndDoc);
98         GET_FUNC(EndPage);
99         GET_FUNC(EndPath);
100         GET_FUNC(EnumDeviceFonts);
101         GET_FUNC(ExcludeClipRect);
102         GET_FUNC(ExtDeviceMode);
103         GET_FUNC(ExtEscape);
104         GET_FUNC(ExtFloodFill);
105         GET_FUNC(ExtSelectClipRgn);
106         GET_FUNC(ExtTextOut);
107         GET_FUNC(FillPath);
108         GET_FUNC(FillRgn);
109         GET_FUNC(FlattenPath);
110         GET_FUNC(FrameRgn);
111         GET_FUNC(GdiComment);
112         GET_FUNC(GetBitmapBits);
113         GET_FUNC(GetCharWidth);
114         GET_FUNC(GetDCOrgEx);
115         GET_FUNC(GetDIBColorTable);
116         GET_FUNC(GetDIBits);
117         GET_FUNC(GetDeviceCaps);
118         GET_FUNC(GetDeviceGammaRamp);
119         GET_FUNC(GetICMProfile);
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(UnrealizePalette);
197         GET_FUNC(WidenPath);
198
199         /* OpenGL32 */
200         GET_FUNC(wglCreateContext);
201         GET_FUNC(wglDeleteContext);
202         GET_FUNC(wglGetProcAddress);
203         GET_FUNC(wglGetPbufferDCARB);
204         GET_FUNC(wglMakeContextCurrentARB);
205         GET_FUNC(wglMakeCurrent);
206         GET_FUNC(wglShareLists);
207         GET_FUNC(wglUseFontBitmapsA);
208         GET_FUNC(wglUseFontBitmapsW);
209 #undef GET_FUNC
210     }
211     else memset( &driver->funcs, 0, sizeof(driver->funcs) );
212
213     /* add it to the list */
214     driver->prev = NULL;
215     if ((driver->next = first_driver)) driver->next->prev = driver;
216     first_driver = driver;
217     return driver;
218 }
219
220
221 /**********************************************************************
222  *           load_display_driver
223  *
224  * Special case for loading the display driver: get the name from the config file
225  */
226 static struct graphics_driver *load_display_driver(void)
227 {
228     char buffer[MAX_PATH], libname[32], *name, *next;
229     HMODULE module = 0;
230     HKEY hkey;
231
232     if (display_driver)  /* already loaded */
233     {
234         display_driver->count++;
235         return display_driver;
236     }
237
238     strcpy( buffer, "x11" );  /* default value */
239     /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
240     if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
241     {
242         DWORD type, count = sizeof(buffer);
243         RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
244         RegCloseKey( hkey );
245     }
246
247     name = buffer;
248     while (name)
249     {
250         next = strchr( name, ',' );
251         if (next) *next++ = 0;
252
253         snprintf( libname, sizeof(libname), "wine%s.drv", name );
254         if ((module = LoadLibraryA( libname )) != 0) break;
255         name = next;
256     }
257
258     if (!(display_driver = create_driver( module )))
259     {
260         MESSAGE( "Could not create graphics driver '%s'\n", buffer );
261         FreeLibrary( module );
262         ExitProcess(1);
263     }
264
265     display_driver->count++;  /* we don't want to free it */
266     return display_driver;
267 }
268
269
270 /**********************************************************************
271  *           DRIVER_load_driver
272  */
273 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
274 {
275     HMODULE module;
276     struct graphics_driver *driver;
277     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
278     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
279
280     EnterCriticalSection( &driver_section );
281
282     /* display driver is a special case */
283     if (!strcmpiW( name, displayW ) || 
284         !strcmpiW( name, display1W ))
285     {
286         driver = load_display_driver();
287         LeaveCriticalSection( &driver_section );
288         return &driver->funcs;
289     }
290
291     if ((module = GetModuleHandleW( name )))
292     {
293         for (driver = first_driver; driver; driver = driver->next)
294         {
295             if (driver->module == module)
296             {
297                 driver->count++;
298                 LeaveCriticalSection( &driver_section );
299                 return &driver->funcs;
300             }
301         }
302     }
303
304     if (!(module = LoadLibraryW( name )))
305     {
306         LeaveCriticalSection( &driver_section );
307         return NULL;
308     }
309
310     if (!(driver = create_driver( module )))
311     {
312         FreeLibrary( module );
313         LeaveCriticalSection( &driver_section );
314         return NULL;
315     }
316
317     TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
318     LeaveCriticalSection( &driver_section );
319     return &driver->funcs;
320 }
321
322
323 /**********************************************************************
324  *           DRIVER_get_driver
325  *
326  * Get a new copy of an existing driver.
327  */
328 const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs )
329 {
330     struct graphics_driver *driver;
331
332     EnterCriticalSection( &driver_section );
333     for (driver = first_driver; driver; driver = driver->next)
334         if (&driver->funcs == funcs) break;
335     if (!driver) ERR( "driver not found, trouble ahead\n" );
336     driver->count++;
337     LeaveCriticalSection( &driver_section );
338     return funcs;
339 }
340
341
342 /**********************************************************************
343  *           DRIVER_release_driver
344  *
345  * Release a driver by decrementing ref count and freeing it if needed.
346  */
347 void DRIVER_release_driver( const DC_FUNCTIONS *funcs )
348 {
349     struct graphics_driver *driver;
350
351     EnterCriticalSection( &driver_section );
352
353     for (driver = first_driver; driver; driver = driver->next)
354         if (&driver->funcs == funcs) break;
355
356     if (!driver) goto done;
357     if (--driver->count) goto done;
358
359     /* removed last reference, free it */
360     if (driver->next) driver->next->prev = driver->prev;
361     if (driver->prev) driver->prev->next = driver->next;
362     else first_driver = driver->next;
363     if (driver == display_driver) display_driver = NULL;
364
365     FreeLibrary( driver->module );
366     HeapFree( GetProcessHeap(), 0, driver );
367  done:
368     LeaveCriticalSection( &driver_section );
369 }
370
371
372 /*****************************************************************************
373  *      DRIVER_GetDriverName
374  *
375  */
376 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
377 {
378     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
379     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
380     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
381     static const WCHAR empty_strW[] = { 0 };
382     WCHAR *p;
383
384     /* display is a special case */
385     if (!strcmpiW( device, displayW ) ||
386         !strcmpiW( device, display1W ))
387     {
388         lstrcpynW( driver, displayW, size );
389         return TRUE;
390     }
391
392     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
393     if(!size) {
394         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
395         return FALSE;
396     }
397     p = strchrW(driver, ',');
398     if(!p)
399     {
400         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
401         return FALSE;
402     }
403     *p = 0;
404     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
405     return TRUE;
406 }
407
408
409 /***********************************************************************
410  *           GdiConvertToDevmodeW    (GDI32.@)
411  */
412 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
413 {
414     DEVMODEW *dmW;
415     WORD dmW_size, dmA_size;
416
417     dmA_size = dmA->dmSize;
418
419     /* this is the minimal dmSize that XP accepts */
420     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
421         return NULL;
422
423     if (dmA_size > sizeof(DEVMODEA))
424         dmA_size = sizeof(DEVMODEA);
425
426     dmW_size = dmA_size + CCHDEVICENAME;
427     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
428         dmW_size += CCHFORMNAME;
429
430     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
431     if (!dmW) return NULL;
432
433     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, CCHDEVICENAME,
434                                    dmW->dmDeviceName, CCHDEVICENAME);
435     /* copy slightly more, to avoid long computations */
436     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
437
438     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
439     {
440         MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, CCHFORMNAME,
441                                        dmW->dmFormName, CCHFORMNAME);
442         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
443             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
444     }
445
446     if (dmA->dmDriverExtra)
447         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
448
449     dmW->dmSize = dmW_size;
450
451     return dmW;
452 }
453
454
455 /*****************************************************************************
456  *      @ [GDI32.100]
457  *
458  * This should thunk to 16-bit and simply call the proc with the given args.
459  */
460 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
461                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
462 {
463     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
464     return -1;
465 }
466
467 /*****************************************************************************
468  *      @ [GDI32.101]
469  *
470  * This should load the correct driver for lpszDevice and calls this driver's
471  * ExtDeviceModePropSheet proc.
472  *
473  * Note: The driver calls a callback routine for each property sheet page; these
474  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
475  * The layout of this structure is:
476  *
477  * struct
478  * {
479  *   DWORD  nPages;
480  *   DWORD  unknown;
481  *   HPROPSHEETPAGE  pages[10];
482  * };
483  */
484 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
485                                              LPCSTR lpszPort, LPVOID lpPropSheet )
486 {
487     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
488     return -1;
489 }
490
491 /*****************************************************************************
492  *      @ [GDI32.102]
493  *
494  * This should load the correct driver for lpszDevice and calls this driver's
495  * ExtDeviceMode proc.
496  *
497  * FIXME: convert ExtDeviceMode to unicode in the driver interface
498  */
499 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
500                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
501                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
502                                     LPSTR lpszProfile, DWORD fwMode )
503 {
504     WCHAR deviceW[300];
505     WCHAR bufW[300];
506     char buf[300];
507     HDC hdc;
508     DC *dc;
509     INT ret = -1;
510
511     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
512           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
513
514     if (!lpszDevice) return -1;
515     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
516
517     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
518
519     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
520
521     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
522
523     if ((dc = get_dc_ptr( hdc )))
524     {
525         if (dc->funcs->pExtDeviceMode)
526             ret = dc->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
527                                              lpdmInput, lpszProfile, fwMode );
528         release_dc_ptr( dc );
529     }
530     DeleteDC( hdc );
531     return ret;
532 }
533
534 /****************************************************************************
535  *      @ [GDI32.103]
536  *
537  * This should load the correct driver for lpszDevice and calls this driver's
538  * AdvancedSetupDialog proc.
539  */
540 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
541                                           LPDEVMODEA devin, LPDEVMODEA devout )
542 {
543     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
544     return -1;
545 }
546
547 /*****************************************************************************
548  *      @ [GDI32.104]
549  *
550  * This should load the correct driver for lpszDevice and calls this driver's
551  * DeviceCapabilities proc.
552  *
553  * FIXME: convert DeviceCapabilities to unicode in the driver interface
554  */
555 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
556                                            WORD fwCapability, LPSTR lpszOutput,
557                                            LPDEVMODEA lpdm )
558 {
559     WCHAR deviceW[300];
560     WCHAR bufW[300];
561     char buf[300];
562     HDC hdc;
563     DC *dc;
564     INT ret = -1;
565
566     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
567
568     if (!lpszDevice) return -1;
569     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
570
571     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
572
573     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
574
575     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
576
577     if ((dc = get_dc_ptr( hdc )))
578     {
579         if (dc->funcs->pDeviceCapabilities)
580             ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
581                                                   fwCapability, lpszOutput, lpdm );
582         release_dc_ptr( dc );
583     }
584     DeleteDC( hdc );
585     return ret;
586 }
587
588
589 /************************************************************************
590  *             Escape  [GDI32.@]
591  */
592 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
593 {
594     INT ret;
595     POINT *pt;
596
597     switch (escape)
598     {
599     case ABORTDOC:
600         return AbortDoc( hdc );
601
602     case ENDDOC:
603         return EndDoc( hdc );
604
605     case GETPHYSPAGESIZE:
606         pt = out_data;
607         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
608         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
609         return 1;
610
611     case GETPRINTINGOFFSET:
612         pt = out_data;
613         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
614         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
615         return 1;
616
617     case GETSCALINGFACTOR:
618         pt = out_data;
619         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
620         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
621         return 1;
622
623     case NEWFRAME:
624         return EndPage( hdc );
625
626     case SETABORTPROC:
627         return SetAbortProc( hdc, (ABORTPROC)in_data );
628
629     case STARTDOC:
630         {
631             DOCINFOA doc;
632             char *name = NULL;
633
634             /* in_data may not be 0 terminated so we must copy it */
635             if (in_data)
636             {
637                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
638                 memcpy( name, in_data, in_count );
639                 name[in_count] = 0;
640             }
641             /* out_data is actually a pointer to the DocInfo structure and used as
642              * a second input parameter */
643             if (out_data) doc = *(DOCINFOA *)out_data;
644             else
645             {
646                 doc.cbSize = sizeof(doc);
647                 doc.lpszOutput = NULL;
648                 doc.lpszDatatype = NULL;
649                 doc.fwType = 0;
650             }
651             doc.lpszDocName = name;
652             ret = StartDocA( hdc, &doc );
653             HeapFree( GetProcessHeap(), 0, name );
654             if (ret > 0) ret = StartPage( hdc );
655             return ret;
656         }
657
658     case QUERYESCSUPPORT:
659         {
660             const INT *ptr = (const INT *)in_data;
661             if (in_count < sizeof(INT)) return 0;
662             switch(*ptr)
663             {
664             case ABORTDOC:
665             case ENDDOC:
666             case GETPHYSPAGESIZE:
667             case GETPRINTINGOFFSET:
668             case GETSCALINGFACTOR:
669             case NEWFRAME:
670             case QUERYESCSUPPORT:
671             case SETABORTPROC:
672             case STARTDOC:
673                 return TRUE;
674             }
675             break;
676         }
677     }
678
679     /* if not handled internally, pass it to the driver */
680     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
681 }
682
683
684 /******************************************************************************
685  *              ExtEscape       [GDI32.@]
686  *
687  * Access capabilities of a particular device that are not available through GDI.
688  *
689  * PARAMS
690  *    hdc         [I] Handle to device context
691  *    nEscape     [I] Escape function
692  *    cbInput     [I] Number of bytes in input structure
693  *    lpszInData  [I] Pointer to input structure
694  *    cbOutput    [I] Number of bytes in output structure
695  *    lpszOutData [O] Pointer to output structure
696  *
697  * RETURNS
698  *    Success: >0
699  *    Not implemented: 0
700  *    Failure: <0
701  */
702 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
703                       INT cbOutput, LPSTR lpszOutData )
704 {
705     INT ret = 0;
706     DC * dc = get_dc_ptr( hdc );
707     if (dc)
708     {
709         if (dc->funcs->pExtEscape)
710             ret = dc->funcs->pExtEscape( dc->physDev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
711         release_dc_ptr( dc );
712     }
713     return ret;
714 }
715
716
717 /*******************************************************************
718  *      DrawEscape [GDI32.@]
719  *
720  *
721  */
722 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
723 {
724     FIXME("DrawEscape, stub\n");
725     return 0;
726 }