urlmon: Don't create stgmed_obj for binding to object.
[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(GetNearestColor);
120         GET_FUNC(GetPixel);
121         GET_FUNC(GetPixelFormat);
122         GET_FUNC(GetSystemPaletteEntries);
123         GET_FUNC(GetTextExtentExPoint);
124         GET_FUNC(GetTextMetrics);
125         GET_FUNC(IntersectClipRect);
126         GET_FUNC(InvertRgn);
127         GET_FUNC(LineTo);
128         GET_FUNC(MoveTo);
129         GET_FUNC(ModifyWorldTransform);
130         GET_FUNC(OffsetClipRgn);
131         GET_FUNC(OffsetViewportOrg);
132         GET_FUNC(OffsetWindowOrg);
133         GET_FUNC(PaintRgn);
134         GET_FUNC(PatBlt);
135         GET_FUNC(Pie);
136         GET_FUNC(PolyBezier);
137         GET_FUNC(PolyBezierTo);
138         GET_FUNC(PolyDraw);
139         GET_FUNC(PolyPolygon);
140         GET_FUNC(PolyPolyline);
141         GET_FUNC(Polygon);
142         GET_FUNC(Polyline);
143         GET_FUNC(PolylineTo);
144         GET_FUNC(RealizeDefaultPalette);
145         GET_FUNC(RealizePalette);
146         GET_FUNC(Rectangle);
147         GET_FUNC(ResetDC);
148         GET_FUNC(RestoreDC);
149         GET_FUNC(RoundRect);
150         GET_FUNC(SaveDC);
151         GET_FUNC(ScaleViewportExt);
152         GET_FUNC(ScaleWindowExt);
153         GET_FUNC(SelectBitmap);
154         GET_FUNC(SelectBrush);
155         GET_FUNC(SelectClipPath);
156         GET_FUNC(SelectFont);
157         GET_FUNC(SelectPalette);
158         GET_FUNC(SelectPen);
159         GET_FUNC(SetArcDirection);
160         GET_FUNC(SetBitmapBits);
161         GET_FUNC(SetBkColor);
162         GET_FUNC(SetBkMode);
163         GET_FUNC(SetDCBrushColor);
164         GET_FUNC(SetDCOrg);
165         GET_FUNC(SetDCPenColor);
166         GET_FUNC(SetDIBColorTable);
167         GET_FUNC(SetDIBits);
168         GET_FUNC(SetDIBitsToDevice);
169         GET_FUNC(SetDeviceClipping);
170         GET_FUNC(SetDeviceGammaRamp);
171         GET_FUNC(SetMapMode);
172         GET_FUNC(SetMapperFlags);
173         GET_FUNC(SetPixel);
174         GET_FUNC(SetPixelFormat);
175         GET_FUNC(SetPolyFillMode);
176         GET_FUNC(SetROP2);
177         GET_FUNC(SetRelAbs);
178         GET_FUNC(SetStretchBltMode);
179         GET_FUNC(SetTextAlign);
180         GET_FUNC(SetTextCharacterExtra);
181         GET_FUNC(SetTextColor);
182         GET_FUNC(SetTextJustification);
183         GET_FUNC(SetViewportExt);
184         GET_FUNC(SetViewportOrg);
185         GET_FUNC(SetWindowExt);
186         GET_FUNC(SetWindowOrg);
187         GET_FUNC(SetWorldTransform);
188         GET_FUNC(StartDoc);
189         GET_FUNC(StartPage);
190         GET_FUNC(StretchBlt);
191         GET_FUNC(StretchDIBits);
192         GET_FUNC(StrokeAndFillPath);
193         GET_FUNC(StrokePath);
194         GET_FUNC(SwapBuffers);
195         GET_FUNC(UnrealizePalette);
196         GET_FUNC(WidenPath);
197
198         /* OpenGL32 */
199         GET_FUNC(wglCreateContext);
200         GET_FUNC(wglDeleteContext);
201         GET_FUNC(wglGetProcAddress);
202         GET_FUNC(wglGetPbufferDCARB);
203         GET_FUNC(wglMakeContextCurrentARB);
204         GET_FUNC(wglMakeCurrent);
205         GET_FUNC(wglShareLists);
206         GET_FUNC(wglUseFontBitmapsA);
207         GET_FUNC(wglUseFontBitmapsW);
208 #undef GET_FUNC
209     }
210     else memset( &driver->funcs, 0, sizeof(driver->funcs) );
211
212     /* add it to the list */
213     driver->prev = NULL;
214     if ((driver->next = first_driver)) driver->next->prev = driver;
215     first_driver = driver;
216     return driver;
217 }
218
219
220 /**********************************************************************
221  *           load_display_driver
222  *
223  * Special case for loading the display driver: get the name from the config file
224  */
225 static struct graphics_driver *load_display_driver(void)
226 {
227     char buffer[MAX_PATH], libname[32], *name, *next;
228     HMODULE module = 0;
229     HKEY hkey;
230
231     if (display_driver)  /* already loaded */
232     {
233         display_driver->count++;
234         return display_driver;
235     }
236
237     strcpy( buffer, "x11" );  /* default value */
238     /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
239     if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
240     {
241         DWORD type, count = sizeof(buffer);
242         RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
243         RegCloseKey( hkey );
244     }
245
246     name = buffer;
247     while (name)
248     {
249         next = strchr( name, ',' );
250         if (next) *next++ = 0;
251
252         snprintf( libname, sizeof(libname), "wine%s.drv", name );
253         if ((module = LoadLibraryA( libname )) != 0) break;
254         name = next;
255     }
256
257     if (!(display_driver = create_driver( module )))
258     {
259         MESSAGE( "Could not create graphics driver '%s'\n", buffer );
260         FreeLibrary( module );
261         ExitProcess(1);
262     }
263
264     display_driver->count++;  /* we don't want to free it */
265     return display_driver;
266 }
267
268
269 /**********************************************************************
270  *           DRIVER_load_driver
271  */
272 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
273 {
274     HMODULE module;
275     struct graphics_driver *driver;
276     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
277     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
278
279     EnterCriticalSection( &driver_section );
280
281     /* display driver is a special case */
282     if (!strcmpiW( name, displayW ) || 
283         !strcmpiW( name, display1W ))
284     {
285         driver = load_display_driver();
286         LeaveCriticalSection( &driver_section );
287         return &driver->funcs;
288     }
289
290     if ((module = GetModuleHandleW( name )))
291     {
292         for (driver = first_driver; driver; driver = driver->next)
293         {
294             if (driver->module == module)
295             {
296                 driver->count++;
297                 LeaveCriticalSection( &driver_section );
298                 return &driver->funcs;
299             }
300         }
301     }
302
303     if (!(module = LoadLibraryW( name )))
304     {
305         LeaveCriticalSection( &driver_section );
306         return NULL;
307     }
308
309     if (!(driver = create_driver( module )))
310     {
311         FreeLibrary( module );
312         LeaveCriticalSection( &driver_section );
313         return NULL;
314     }
315
316     TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
317     LeaveCriticalSection( &driver_section );
318     return &driver->funcs;
319 }
320
321
322 /**********************************************************************
323  *           DRIVER_get_driver
324  *
325  * Get a new copy of an existing driver.
326  */
327 const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs )
328 {
329     struct graphics_driver *driver;
330
331     EnterCriticalSection( &driver_section );
332     for (driver = first_driver; driver; driver = driver->next)
333         if (&driver->funcs == funcs) break;
334     if (!driver) ERR( "driver not found, trouble ahead\n" );
335     driver->count++;
336     LeaveCriticalSection( &driver_section );
337     return funcs;
338 }
339
340
341 /**********************************************************************
342  *           DRIVER_release_driver
343  *
344  * Release a driver by decrementing ref count and freeing it if needed.
345  */
346 void DRIVER_release_driver( const DC_FUNCTIONS *funcs )
347 {
348     struct graphics_driver *driver;
349
350     EnterCriticalSection( &driver_section );
351
352     for (driver = first_driver; driver; driver = driver->next)
353         if (&driver->funcs == funcs) break;
354
355     if (!driver) goto done;
356     if (--driver->count) goto done;
357
358     /* removed last reference, free it */
359     if (driver->next) driver->next->prev = driver->prev;
360     if (driver->prev) driver->prev->next = driver->next;
361     else first_driver = driver->next;
362     if (driver == display_driver) display_driver = NULL;
363
364     FreeLibrary( driver->module );
365     HeapFree( GetProcessHeap(), 0, driver );
366  done:
367     LeaveCriticalSection( &driver_section );
368 }
369
370
371 /*****************************************************************************
372  *      DRIVER_GetDriverName
373  *
374  */
375 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
376 {
377     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
378     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
379     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
380     static const WCHAR empty_strW[] = { 0 };
381     WCHAR *p;
382
383     /* display is a special case */
384     if (!strcmpiW( device, displayW ) ||
385         !strcmpiW( device, display1W ))
386     {
387         lstrcpynW( driver, displayW, size );
388         return TRUE;
389     }
390
391     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
392     if(!size) {
393         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
394         return FALSE;
395     }
396     p = strchrW(driver, ',');
397     if(!p)
398     {
399         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
400         return FALSE;
401     }
402     *p = 0;
403     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
404     return TRUE;
405 }
406
407
408 /***********************************************************************
409  *           GdiConvertToDevmodeW    (GDI32.@)
410  */
411 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
412 {
413     DEVMODEW *dmW;
414     WORD dmW_size, dmA_size;
415
416     dmA_size = dmA->dmSize;
417
418     /* this is the minimal dmSize that XP accepts */
419     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
420         return NULL;
421
422     if (dmA_size > sizeof(DEVMODEA))
423         dmA_size = sizeof(DEVMODEA);
424
425     dmW_size = dmA_size + CCHDEVICENAME;
426     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
427         dmW_size += CCHFORMNAME;
428
429     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
430     if (!dmW) return NULL;
431
432     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, CCHDEVICENAME,
433                                    dmW->dmDeviceName, CCHDEVICENAME);
434     /* copy slightly more, to avoid long computations */
435     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
436
437     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
438     {
439         MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, CCHFORMNAME,
440                                        dmW->dmFormName, CCHFORMNAME);
441         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
442             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
443     }
444
445     if (dmA->dmDriverExtra)
446         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
447
448     dmW->dmSize = dmW_size;
449
450     return dmW;
451 }
452
453
454 /*****************************************************************************
455  *      @ [GDI32.100]
456  *
457  * This should thunk to 16-bit and simply call the proc with the given args.
458  */
459 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
460                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
461 {
462     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
463     return -1;
464 }
465
466 /*****************************************************************************
467  *      @ [GDI32.101]
468  *
469  * This should load the correct driver for lpszDevice and calls this driver's
470  * ExtDeviceModePropSheet proc.
471  *
472  * Note: The driver calls a callback routine for each property sheet page; these
473  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
474  * The layout of this structure is:
475  *
476  * struct
477  * {
478  *   DWORD  nPages;
479  *   DWORD  unknown;
480  *   HPROPSHEETPAGE  pages[10];
481  * };
482  */
483 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
484                                              LPCSTR lpszPort, LPVOID lpPropSheet )
485 {
486     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
487     return -1;
488 }
489
490 /*****************************************************************************
491  *      @ [GDI32.102]
492  *
493  * This should load the correct driver for lpszDevice and calls this driver's
494  * ExtDeviceMode proc.
495  *
496  * FIXME: convert ExtDeviceMode to unicode in the driver interface
497  */
498 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
499                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
500                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
501                                     LPSTR lpszProfile, DWORD fwMode )
502 {
503     WCHAR deviceW[300];
504     WCHAR bufW[300];
505     char buf[300];
506     HDC hdc;
507     DC *dc;
508     INT ret = -1;
509
510     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
511           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
512
513     if (!lpszDevice) return -1;
514     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
515
516     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
517
518     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
519
520     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
521
522     if ((dc = get_dc_ptr( hdc )))
523     {
524         if (dc->funcs->pExtDeviceMode)
525             ret = dc->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
526                                              lpdmInput, lpszProfile, fwMode );
527         release_dc_ptr( dc );
528     }
529     DeleteDC( hdc );
530     return ret;
531 }
532
533 /****************************************************************************
534  *      @ [GDI32.103]
535  *
536  * This should load the correct driver for lpszDevice and calls this driver's
537  * AdvancedSetupDialog proc.
538  */
539 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
540                                           LPDEVMODEA devin, LPDEVMODEA devout )
541 {
542     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
543     return -1;
544 }
545
546 /*****************************************************************************
547  *      @ [GDI32.104]
548  *
549  * This should load the correct driver for lpszDevice and calls this driver's
550  * DeviceCapabilities proc.
551  *
552  * FIXME: convert DeviceCapabilities to unicode in the driver interface
553  */
554 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
555                                            WORD fwCapability, LPSTR lpszOutput,
556                                            LPDEVMODEA lpdm )
557 {
558     WCHAR deviceW[300];
559     WCHAR bufW[300];
560     char buf[300];
561     HDC hdc;
562     DC *dc;
563     INT ret = -1;
564
565     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
566
567     if (!lpszDevice) return -1;
568     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
569
570     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
571
572     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
573
574     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
575
576     if ((dc = get_dc_ptr( hdc )))
577     {
578         if (dc->funcs->pDeviceCapabilities)
579             ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
580                                                   fwCapability, lpszOutput, lpdm );
581         release_dc_ptr( dc );
582     }
583     DeleteDC( hdc );
584     return ret;
585 }
586
587
588 /************************************************************************
589  *             Escape  [GDI32.@]
590  */
591 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
592 {
593     INT ret;
594     POINT *pt;
595
596     switch (escape)
597     {
598     case ABORTDOC:
599         return AbortDoc( hdc );
600
601     case ENDDOC:
602         return EndDoc( hdc );
603
604     case GETPHYSPAGESIZE:
605         pt = out_data;
606         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
607         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
608         return 1;
609
610     case GETPRINTINGOFFSET:
611         pt = out_data;
612         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
613         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
614         return 1;
615
616     case GETSCALINGFACTOR:
617         pt = out_data;
618         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
619         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
620         return 1;
621
622     case NEWFRAME:
623         return EndPage( hdc );
624
625     case SETABORTPROC:
626         return SetAbortProc( hdc, (ABORTPROC)in_data );
627
628     case STARTDOC:
629         {
630             DOCINFOA doc;
631             char *name = NULL;
632
633             /* in_data may not be 0 terminated so we must copy it */
634             if (in_data)
635             {
636                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
637                 memcpy( name, in_data, in_count );
638                 name[in_count] = 0;
639             }
640             /* out_data is actually a pointer to the DocInfo structure and used as
641              * a second input parameter */
642             if (out_data) doc = *(DOCINFOA *)out_data;
643             else
644             {
645                 doc.cbSize = sizeof(doc);
646                 doc.lpszOutput = NULL;
647                 doc.lpszDatatype = NULL;
648                 doc.fwType = 0;
649             }
650             doc.lpszDocName = name;
651             ret = StartDocA( hdc, &doc );
652             HeapFree( GetProcessHeap(), 0, name );
653             if (ret > 0) ret = StartPage( hdc );
654             return ret;
655         }
656
657     case QUERYESCSUPPORT:
658         {
659             const INT *ptr = (const INT *)in_data;
660             if (in_count < sizeof(INT)) return 0;
661             switch(*ptr)
662             {
663             case ABORTDOC:
664             case ENDDOC:
665             case GETPHYSPAGESIZE:
666             case GETPRINTINGOFFSET:
667             case GETSCALINGFACTOR:
668             case NEWFRAME:
669             case QUERYESCSUPPORT:
670             case SETABORTPROC:
671             case STARTDOC:
672                 return TRUE;
673             }
674             break;
675         }
676     }
677
678     /* if not handled internally, pass it to the driver */
679     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
680 }
681
682
683 /******************************************************************************
684  *              ExtEscape       [GDI32.@]
685  *
686  * Access capabilities of a particular device that are not available through GDI.
687  *
688  * PARAMS
689  *    hdc         [I] Handle to device context
690  *    nEscape     [I] Escape function
691  *    cbInput     [I] Number of bytes in input structure
692  *    lpszInData  [I] Pointer to input structure
693  *    cbOutput    [I] Number of bytes in output structure
694  *    lpszOutData [O] Pointer to output structure
695  *
696  * RETURNS
697  *    Success: >0
698  *    Not implemented: 0
699  *    Failure: <0
700  */
701 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
702                       INT cbOutput, LPSTR lpszOutData )
703 {
704     INT ret = 0;
705     DC * dc = get_dc_ptr( hdc );
706     if (dc)
707     {
708         if (dc->funcs->pExtEscape)
709             ret = dc->funcs->pExtEscape( dc->physDev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
710         release_dc_ptr( dc );
711     }
712     return ret;
713 }
714
715
716 /*******************************************************************
717  *      DrawEscape [GDI32.@]
718  *
719  *
720  */
721 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
722 {
723     FIXME("DrawEscape, stub\n");
724     return 0;
725 }