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