dinput: BuildActionMap and SetActionMap stubs for generic joystick.
[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 <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winreg.h"
32 #include "ddrawgdi.h"
33 #include "wine/winbase16.h"
34
35 #include "gdi_private.h"
36 #include "wine/unicode.h"
37 #include "wine/list.h"
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(driver);
41
42 struct graphics_driver
43 {
44     struct list             entry;
45     HMODULE                 module;  /* module handle */
46     DC_FUNCTIONS            funcs;
47 };
48
49 static struct list drivers = LIST_INIT( drivers );
50 static struct graphics_driver *display_driver;
51
52 static CRITICAL_SECTION driver_section;
53 static CRITICAL_SECTION_DEBUG critsect_debug =
54 {
55     0, 0, &driver_section,
56     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
57       0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
58 };
59 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
60
61 /**********************************************************************
62  *           create_driver
63  *
64  * Allocate and fill the driver structure for a given module.
65  */
66 static struct graphics_driver *create_driver( HMODULE module )
67 {
68     struct graphics_driver *driver;
69
70     if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
71     driver->module = module;
72
73     /* fill the function table */
74     if (module)
75     {
76 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
77         GET_FUNC(AbortDoc);
78         GET_FUNC(AbortPath);
79         GET_FUNC(AlphaBlend);
80         GET_FUNC(AngleArc);
81         GET_FUNC(Arc);
82         GET_FUNC(ArcTo);
83         GET_FUNC(BeginPath);
84         GET_FUNC(ChoosePixelFormat);
85         GET_FUNC(Chord);
86         GET_FUNC(CloseFigure);
87         GET_FUNC(CreateBitmap);
88         GET_FUNC(CreateDC);
89         GET_FUNC(CreateDIBSection);
90         GET_FUNC(DeleteBitmap);
91         GET_FUNC(DeleteDC);
92         GET_FUNC(DescribePixelFormat);
93         GET_FUNC(DeviceCapabilities);
94         GET_FUNC(Ellipse);
95         GET_FUNC(EndDoc);
96         GET_FUNC(EndPage);
97         GET_FUNC(EndPath);
98         GET_FUNC(EnumDeviceFonts);
99         GET_FUNC(EnumICMProfiles);
100         GET_FUNC(ExcludeClipRect);
101         GET_FUNC(ExtDeviceMode);
102         GET_FUNC(ExtEscape);
103         GET_FUNC(ExtFloodFill);
104         GET_FUNC(ExtSelectClipRgn);
105         GET_FUNC(ExtTextOut);
106         GET_FUNC(FillPath);
107         GET_FUNC(FillRgn);
108         GET_FUNC(FlattenPath);
109         GET_FUNC(FrameRgn);
110         GET_FUNC(GdiComment);
111         GET_FUNC(GetBitmapBits);
112         GET_FUNC(GetCharWidth);
113         GET_FUNC(GetDIBits);
114         GET_FUNC(GetDeviceCaps);
115         GET_FUNC(GetDeviceGammaRamp);
116         GET_FUNC(GetICMProfile);
117         GET_FUNC(GetNearestColor);
118         GET_FUNC(GetPixel);
119         GET_FUNC(GetPixelFormat);
120         GET_FUNC(GetSystemPaletteEntries);
121         GET_FUNC(GetTextExtentExPoint);
122         GET_FUNC(GetTextMetrics);
123         GET_FUNC(IntersectClipRect);
124         GET_FUNC(InvertRgn);
125         GET_FUNC(LineTo);
126         GET_FUNC(MoveTo);
127         GET_FUNC(ModifyWorldTransform);
128         GET_FUNC(OffsetClipRgn);
129         GET_FUNC(OffsetViewportOrgEx);
130         GET_FUNC(OffsetWindowOrgEx);
131         GET_FUNC(PaintRgn);
132         GET_FUNC(PatBlt);
133         GET_FUNC(Pie);
134         GET_FUNC(PolyBezier);
135         GET_FUNC(PolyBezierTo);
136         GET_FUNC(PolyDraw);
137         GET_FUNC(PolyPolygon);
138         GET_FUNC(PolyPolyline);
139         GET_FUNC(Polygon);
140         GET_FUNC(Polyline);
141         GET_FUNC(PolylineTo);
142         GET_FUNC(RealizeDefaultPalette);
143         GET_FUNC(RealizePalette);
144         GET_FUNC(Rectangle);
145         GET_FUNC(ResetDC);
146         GET_FUNC(RestoreDC);
147         GET_FUNC(RoundRect);
148         GET_FUNC(SaveDC);
149         GET_FUNC(ScaleViewportExtEx);
150         GET_FUNC(ScaleWindowExtEx);
151         GET_FUNC(SelectBitmap);
152         GET_FUNC(SelectBrush);
153         GET_FUNC(SelectClipPath);
154         GET_FUNC(SelectFont);
155         GET_FUNC(SelectPalette);
156         GET_FUNC(SelectPen);
157         GET_FUNC(SetArcDirection);
158         GET_FUNC(SetBitmapBits);
159         GET_FUNC(SetBkColor);
160         GET_FUNC(SetBkMode);
161         GET_FUNC(SetDCBrushColor);
162         GET_FUNC(SetDCPenColor);
163         GET_FUNC(SetDIBColorTable);
164         GET_FUNC(SetDIBits);
165         GET_FUNC(SetDIBitsToDevice);
166         GET_FUNC(SetDeviceClipping);
167         GET_FUNC(SetDeviceGammaRamp);
168         GET_FUNC(SetLayout);
169         GET_FUNC(SetMapMode);
170         GET_FUNC(SetMapperFlags);
171         GET_FUNC(SetPixel);
172         GET_FUNC(SetPixelFormat);
173         GET_FUNC(SetPolyFillMode);
174         GET_FUNC(SetROP2);
175         GET_FUNC(SetRelAbs);
176         GET_FUNC(SetStretchBltMode);
177         GET_FUNC(SetTextAlign);
178         GET_FUNC(SetTextCharacterExtra);
179         GET_FUNC(SetTextColor);
180         GET_FUNC(SetTextJustification);
181         GET_FUNC(SetViewportExtEx);
182         GET_FUNC(SetViewportOrgEx);
183         GET_FUNC(SetWindowExtEx);
184         GET_FUNC(SetWindowOrgEx);
185         GET_FUNC(SetWorldTransform);
186         GET_FUNC(StartDoc);
187         GET_FUNC(StartPage);
188         GET_FUNC(StretchBlt);
189         GET_FUNC(StretchDIBits);
190         GET_FUNC(StrokeAndFillPath);
191         GET_FUNC(StrokePath);
192         GET_FUNC(SwapBuffers);
193         GET_FUNC(UnrealizePalette);
194         GET_FUNC(WidenPath);
195
196         /* OpenGL32 */
197         GET_FUNC(wglCreateContext);
198         GET_FUNC(wglCreateContextAttribsARB);
199         GET_FUNC(wglDeleteContext);
200         GET_FUNC(wglGetProcAddress);
201         GET_FUNC(wglGetPbufferDCARB);
202         GET_FUNC(wglMakeContextCurrentARB);
203         GET_FUNC(wglMakeCurrent);
204         GET_FUNC(wglSetPixelFormatWINE);
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     return driver;
213 }
214
215
216 /**********************************************************************
217  *           DRIVER_get_display_driver
218  *
219  * Special case for loading the display driver: get the name from the config file
220  */
221 const DC_FUNCTIONS *DRIVER_get_display_driver(void)
222 {
223     struct graphics_driver *driver;
224     char buffer[MAX_PATH], libname[32], *name, *next;
225     HMODULE module = 0;
226     HKEY hkey;
227
228     if (display_driver) return &display_driver->funcs;  /* already loaded */
229
230     strcpy( buffer, "x11" );  /* default value */
231     /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
232     if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
233     {
234         DWORD type, count = sizeof(buffer);
235         RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
236         RegCloseKey( hkey );
237     }
238
239     name = buffer;
240     while (name)
241     {
242         next = strchr( name, ',' );
243         if (next) *next++ = 0;
244
245         snprintf( libname, sizeof(libname), "wine%s.drv", name );
246         if ((module = LoadLibraryA( libname )) != 0) break;
247         name = next;
248     }
249
250     if (!(driver = create_driver( module )))
251     {
252         MESSAGE( "Could not create graphics driver '%s'\n", buffer );
253         FreeLibrary( module );
254         ExitProcess(1);
255     }
256     if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
257     {
258         /* somebody beat us to it */
259         FreeLibrary( driver->module );
260         HeapFree( GetProcessHeap(), 0, driver );
261     }
262     return &display_driver->funcs;
263 }
264
265
266 /**********************************************************************
267  *           DRIVER_load_driver
268  */
269 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
270 {
271     HMODULE module;
272     struct graphics_driver *driver, *new_driver;
273     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
274     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
275
276     /* display driver is a special case */
277     if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return DRIVER_get_display_driver();
278
279     if ((module = GetModuleHandleW( name )))
280     {
281         if (display_driver && display_driver->module == module) return &display_driver->funcs;
282         EnterCriticalSection( &driver_section );
283         LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
284         {
285             if (driver->module == module) goto done;
286         }
287         LeaveCriticalSection( &driver_section );
288     }
289
290     if (!(module = LoadLibraryW( name ))) return NULL;
291
292     if (!(new_driver = create_driver( module )))
293     {
294         FreeLibrary( module );
295         return NULL;
296     }
297
298     /* check if someone else added it in the meantime */
299     EnterCriticalSection( &driver_section );
300     LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
301     {
302         if (driver->module != module) continue;
303         FreeLibrary( module );
304         HeapFree( GetProcessHeap(), 0, new_driver );
305         goto done;
306     }
307     driver = new_driver;
308     list_add_head( &drivers, &driver->entry );
309     TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
310 done:
311     LeaveCriticalSection( &driver_section );
312     return &driver->funcs;
313 }
314
315
316 static INT CDECL nulldrv_AbortDoc( PHYSDEV dev )
317 {
318     return 0;
319 }
320
321 static BOOL CDECL nulldrv_AlphaBlend( PHYSDEV dst_dev, struct bitblt_coords *dst,
322                                       PHYSDEV src_dev, struct bitblt_coords *src, BLENDFUNCTION func)
323 {
324     return TRUE;
325 }
326
327 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
328                                INT xstart, INT ystart, INT xend, INT yend )
329 {
330     return TRUE;
331 }
332
333 static INT CDECL nulldrv_ChoosePixelFormat( PHYSDEV dev, const PIXELFORMATDESCRIPTOR *descr )
334 {
335     return 0;
336 }
337
338 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
339                                  INT xstart, INT ystart, INT xend, INT yend )
340 {
341     return TRUE;
342 }
343
344 static BOOL CDECL nulldrv_CreateBitmap( PHYSDEV dev, HBITMAP bitmap, LPVOID bits )
345 {
346     return TRUE;
347 }
348
349 static BOOL CDECL nulldrv_CreateDC( HDC hdc, PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
350                                     LPCWSTR output, const DEVMODEW *devmode )
351 {
352     assert(0);  /* should never be called */
353     return FALSE;
354 }
355
356 static HBITMAP CDECL nulldrv_CreateDIBSection( PHYSDEV dev, HBITMAP bitmap,
357                                                const BITMAPINFO *info, UINT usage )
358 {
359     return bitmap;
360 }
361
362 static BOOL CDECL nulldrv_DeleteBitmap( HBITMAP bitmap )
363 {
364     return TRUE;
365 }
366
367 static BOOL CDECL nulldrv_DeleteDC( PHYSDEV dev )
368 {
369     assert(0);  /* should never be called */
370     return TRUE;
371 }
372
373 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
374 {
375     return TRUE;
376 }
377
378 static INT CDECL nulldrv_DescribePixelFormat( PHYSDEV dev, INT format,
379                                               UINT size, PIXELFORMATDESCRIPTOR * descr )
380 {
381     return 0;
382 }
383
384 static DWORD CDECL nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
385                                                WORD cap, LPSTR output, DEVMODEA *devmode )
386 {
387     return -1;
388 }
389
390 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
391 {
392     return TRUE;
393 }
394
395 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
396 {
397     return 0;
398 }
399
400 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
401 {
402     return 0;
403 }
404
405 static BOOL CDECL nulldrv_EnumDeviceFonts( PHYSDEV dev, LOGFONTW *logfont,
406                                            FONTENUMPROCW proc, LPARAM lParam )
407 {
408     return FALSE;
409 }
410
411 static INT CDECL nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
412 {
413     return -1;
414 }
415
416 static INT CDECL nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
417                                         LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
418 {
419     return -1;
420 }
421
422 static INT CDECL nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
423                                     INT out_size, void *out_data )
424 {
425     return 0;
426 }
427
428 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
429 {
430     return TRUE;
431 }
432
433 static BOOL CDECL nulldrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect,
434                                       LPCWSTR str, UINT count, const INT *dx )
435 {
436     return TRUE;
437 }
438
439 static BOOL CDECL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
440 {
441     return FALSE;
442 }
443
444 static BOOL CDECL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
445 {
446     return FALSE;
447 }
448
449 static INT CDECL nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
450 {
451     switch (cap)  /* return meaningful values for some entries */
452     {
453     case HORZRES:     return 640;
454     case VERTRES:     return 480;
455     case BITSPIXEL:   return 1;
456     case PLANES:      return 1;
457     case NUMCOLORS:   return 2;
458     case ASPECTX:     return 36;
459     case ASPECTY:     return 36;
460     case ASPECTXY:    return 51;
461     case LOGPIXELSX:  return 72;
462     case LOGPIXELSY:  return 72;
463     case SIZEPALETTE: return 2;
464     case TEXTCAPS:    return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
465                               TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
466                               TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
467     default:          return 0;
468     }
469 }
470
471 static BOOL CDECL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
472 {
473     return FALSE;
474 }
475
476 static BOOL CDECL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
477 {
478     return FALSE;
479 }
480
481 static COLORREF CDECL nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
482 {
483     return 0;
484 }
485
486 static INT CDECL nulldrv_GetPixelFormat( PHYSDEV dev )
487 {
488     return 0;
489 }
490
491 static UINT CDECL nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start,
492                                                    UINT count, PALETTEENTRY *entries )
493 {
494     return 0;
495 }
496
497 static BOOL CDECL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
498                                                 INT *fit, INT *dx, SIZE *size )
499 {
500     return FALSE;
501 }
502
503 static BOOL CDECL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
504 {
505     return FALSE;
506 }
507
508 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
509 {
510     return TRUE;
511 }
512
513 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
514 {
515     return TRUE;
516 }
517
518 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
519 {
520     return TRUE;
521 }
522
523 static BOOL CDECL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
524 {
525     return TRUE;
526 }
527
528 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
529                                INT xstart, INT ystart, INT xend, INT yend )
530 {
531     return TRUE;
532 }
533
534 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
535 {
536     /* FIXME: could be implemented with Polygon */
537     return TRUE;
538 }
539
540 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
541 {
542     /* FIXME: could be implemented with Polyline */
543     return TRUE;
544 }
545
546 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
547 {
548     return TRUE;
549 }
550
551 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
552 {
553     return TRUE;
554 }
555
556 static UINT CDECL nulldrv_RealizeDefaultPalette( PHYSDEV dev )
557 {
558     return 0;
559 }
560
561 static UINT CDECL nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
562 {
563     return 0;
564 }
565
566 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
567 {
568     return TRUE;
569 }
570
571 static HDC CDECL nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
572 {
573     return 0;
574 }
575
576 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
577                                      INT ell_width, INT ell_height )
578 {
579     return TRUE;
580 }
581
582 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
583 {
584     return bitmap;
585 }
586
587 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
588 {
589     return brush;
590 }
591
592 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, HANDLE gdi_font )
593 {
594     return 0;
595 }
596
597 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
598 {
599     return palette;
600 }
601
602 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
603 {
604     return pen;
605 }
606
607 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
608 {
609     return dir;
610 }
611
612 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
613 {
614     return color;
615 }
616
617 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
618 {
619     return mode;
620 }
621
622 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
623 {
624     return color;
625 }
626
627 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
628 {
629     return color;
630 }
631
632 static UINT CDECL nulldrv_SetDIBColorTable( PHYSDEV dev, UINT pos, UINT count, const RGBQUAD *colors )
633 {
634     return 0;
635 }
636
637 static INT CDECL nulldrv_SetDIBitsToDevice( PHYSDEV dev, INT x_dst, INT y_dst, DWORD width, DWORD height,
638                                             INT x_src, INT y_src, UINT start, UINT lines,
639                                             const void *bits, const BITMAPINFO *info, UINT coloruse )
640 {
641     return 0;
642 }
643
644 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
645 {
646 }
647
648 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
649 {
650     return layout;
651 }
652
653 static BOOL CDECL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
654 {
655     return FALSE;
656 }
657
658 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
659 {
660     return flags;
661 }
662
663 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
664 {
665     return color;
666 }
667
668 static BOOL CDECL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
669 {
670     return FALSE;
671 }
672
673 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
674 {
675     return mode;
676 }
677
678 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
679 {
680     return rop;
681 }
682
683 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
684 {
685     return mode;
686 }
687
688 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
689 {
690     return mode;
691 }
692
693 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
694 {
695     return align;
696 }
697
698 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
699 {
700     return extra;
701 }
702
703 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
704 {
705     return color;
706 }
707
708 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
709 {
710     return TRUE;
711 }
712
713 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
714 {
715     return 0;
716 }
717
718 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
719 {
720     return 1;
721 }
722
723 static BOOL CDECL nulldrv_SwapBuffers( PHYSDEV dev )
724 {
725     return TRUE;
726 }
727
728 static BOOL CDECL nulldrv_UnrealizePalette( HPALETTE palette )
729 {
730     return FALSE;
731 }
732
733 static BOOL CDECL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
734 {
735     return FALSE;
736 }
737
738 static HGLRC CDECL nulldrv_wglCreateContext( PHYSDEV dev )
739 {
740     return 0;
741 }
742
743 static HGLRC CDECL nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
744 {
745     return 0;
746 }
747
748 static BOOL CDECL nulldrv_wglDeleteContext( HGLRC ctx )
749 {
750     return FALSE;
751 }
752
753 static PROC CDECL nulldrv_wglGetProcAddress( LPCSTR name )
754 {
755     return NULL;
756 }
757
758 static HDC CDECL nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
759 {
760     return 0;
761 }
762
763 static BOOL CDECL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
764 {
765     return FALSE;
766 }
767
768 static BOOL CDECL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
769 {
770     return FALSE;
771 }
772
773 static BOOL CDECL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format,
774                                                  const PIXELFORMATDESCRIPTOR *descr )
775 {
776     return FALSE;
777 }
778
779 static BOOL CDECL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
780 {
781     return FALSE;
782 }
783
784 static BOOL CDECL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
785 {
786     return FALSE;
787 }
788
789 static BOOL CDECL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
790 {
791     return FALSE;
792 }
793
794 const DC_FUNCTIONS null_driver =
795 {
796     nulldrv_AbortDoc,                   /* pAbortDoc */
797     nulldrv_AbortPath,                  /* pAbortPath */
798     nulldrv_AlphaBlend,                 /* pAlphaBlend */
799     nulldrv_AngleArc,                   /* pAngleArc */
800     nulldrv_Arc,                        /* pArc */
801     nulldrv_ArcTo,                      /* pArcTo */
802     nulldrv_BeginPath,                  /* pBeginPath */
803     nulldrv_ChoosePixelFormat,          /* pChoosePixelFormat */
804     nulldrv_Chord,                      /* pChord */
805     nulldrv_CloseFigure,                /* pCloseFigure */
806     nulldrv_CreateBitmap,               /* pCreateBitmap */
807     nulldrv_CreateDC,                   /* pCreateDC */
808     nulldrv_CreateDIBSection,           /* pCreateDIBSection */
809     nulldrv_DeleteBitmap,               /* pDeleteBitmap */
810     nulldrv_DeleteDC,                   /* pDeleteDC */
811     nulldrv_DeleteObject,               /* pDeleteObject */
812     nulldrv_DescribePixelFormat,        /* pDescribePixelFormat */
813     nulldrv_DeviceCapabilities,         /* pDeviceCapabilities */
814     nulldrv_Ellipse,                    /* pEllipse */
815     nulldrv_EndDoc,                     /* pEndDoc */
816     nulldrv_EndPage,                    /* pEndPage */
817     nulldrv_EndPath,                    /* pEndPath */
818     nulldrv_EnumDeviceFonts,            /* pEnumDeviceFonts */
819     nulldrv_EnumICMProfiles,            /* pEnumICMProfiles */
820     nulldrv_ExcludeClipRect,            /* pExcludeClipRect */
821     nulldrv_ExtDeviceMode,              /* pExtDeviceMode */
822     nulldrv_ExtEscape,                  /* pExtEscape */
823     nulldrv_ExtFloodFill,               /* pExtFloodFill */
824     nulldrv_ExtSelectClipRgn,           /* pExtSelectClipRgn */
825     nulldrv_ExtTextOut,                 /* pExtTextOut */
826     nulldrv_FillPath,                   /* pFillPath */
827     nulldrv_FillRgn,                    /* pFillRgn */
828     nulldrv_FlattenPath,                /* pFlattenPath */
829     nulldrv_FrameRgn,                   /* pFrameRgn */
830     nulldrv_GdiComment,                 /* pGdiComment */
831     nulldrv_GetBitmapBits,              /* pGetBitmapBits */
832     nulldrv_GetCharWidth,               /* pGetCharWidth */
833     nulldrv_GetDIBits,                  /* pGetDIBits */
834     nulldrv_GetDeviceCaps,              /* pGetDeviceCaps */
835     nulldrv_GetDeviceGammaRamp,         /* pGetDeviceGammaRamp */
836     nulldrv_GetICMProfile,              /* pGetICMProfile */
837     nulldrv_GetNearestColor,            /* pGetNearestColor */
838     nulldrv_GetPixel,                   /* pGetPixel */
839     nulldrv_GetPixelFormat,             /* pGetPixelFormat */
840     nulldrv_GetSystemPaletteEntries,    /* pGetSystemPaletteEntries */
841     nulldrv_GetTextExtentExPoint,       /* pGetTextExtentExPoint */
842     nulldrv_GetTextMetrics,             /* pGetTextMetrics */
843     nulldrv_IntersectClipRect,          /* pIntersectClipRect */
844     nulldrv_InvertRgn,                  /* pInvertRgn */
845     nulldrv_LineTo,                     /* pLineTo */
846     nulldrv_ModifyWorldTransform,       /* pModifyWorldTransform */
847     nulldrv_MoveTo,                     /* pMoveTo */
848     nulldrv_OffsetClipRgn,              /* pOffsetClipRgn */
849     nulldrv_OffsetViewportOrgEx,        /* pOffsetViewportOrg */
850     nulldrv_OffsetWindowOrgEx,          /* pOffsetWindowOrg */
851     nulldrv_PaintRgn,                   /* pPaintRgn */
852     nulldrv_PatBlt,                     /* pPatBlt */
853     nulldrv_Pie,                        /* pPie */
854     nulldrv_PolyBezier,                 /* pPolyBezier */
855     nulldrv_PolyBezierTo,               /* pPolyBezierTo */
856     nulldrv_PolyDraw,                   /* pPolyDraw */
857     nulldrv_PolyPolygon,                /* pPolyPolygon */
858     nulldrv_PolyPolyline,               /* pPolyPolyline */
859     nulldrv_Polygon,                    /* pPolygon */
860     nulldrv_Polyline,                   /* pPolyline */
861     nulldrv_PolylineTo,                 /* pPolylineTo */
862     nulldrv_RealizeDefaultPalette,      /* pRealizeDefaultPalette */
863     nulldrv_RealizePalette,             /* pRealizePalette */
864     nulldrv_Rectangle,                  /* pRectangle */
865     nulldrv_ResetDC,                    /* pResetDC */
866     nulldrv_RestoreDC,                  /* pRestoreDC */
867     nulldrv_RoundRect,                  /* pRoundRect */
868     nulldrv_SaveDC,                     /* pSaveDC */
869     nulldrv_ScaleViewportExtEx,         /* pScaleViewportExt */
870     nulldrv_ScaleWindowExtEx,           /* pScaleWindowExt */
871     nulldrv_SelectBitmap,               /* pSelectBitmap */
872     nulldrv_SelectBrush,                /* pSelectBrush */
873     nulldrv_SelectClipPath,             /* pSelectClipPath */
874     nulldrv_SelectFont,                 /* pSelectFont */
875     nulldrv_SelectPalette,              /* pSelectPalette */
876     nulldrv_SelectPen,                  /* pSelectPen */
877     nulldrv_SetArcDirection,            /* pSetArcDirection */
878     nulldrv_SetBitmapBits,              /* pSetBitmapBits */
879     nulldrv_SetBkColor,                 /* pSetBkColor */
880     nulldrv_SetBkMode,                  /* pSetBkMode */
881     nulldrv_SetDCBrushColor,            /* pSetDCBrushColor */
882     nulldrv_SetDCPenColor,              /* pSetDCPenColor */
883     nulldrv_SetDIBColorTable,           /* pSetDIBColorTable */
884     nulldrv_SetDIBits,                  /* pSetDIBits */
885     nulldrv_SetDIBitsToDevice,          /* pSetDIBitsToDevice */
886     nulldrv_SetDeviceClipping,          /* pSetDeviceClipping */
887     nulldrv_SetDeviceGammaRamp,         /* pSetDeviceGammaRamp */
888     nulldrv_SetLayout,                  /* pSetLayout */
889     nulldrv_SetMapMode,                 /* pSetMapMode */
890     nulldrv_SetMapperFlags,             /* pSetMapperFlags */
891     nulldrv_SetPixel,                   /* pSetPixel */
892     nulldrv_SetPixelFormat,             /* pSetPixelFormat */
893     nulldrv_SetPolyFillMode,            /* pSetPolyFillMode */
894     nulldrv_SetROP2,                    /* pSetROP2 */
895     nulldrv_SetRelAbs,                  /* pSetRelAbs */
896     nulldrv_SetStretchBltMode,          /* pSetStretchBltMode */
897     nulldrv_SetTextAlign,               /* pSetTextAlign */
898     nulldrv_SetTextCharacterExtra,      /* pSetTextCharacterExtra */
899     nulldrv_SetTextColor,               /* pSetTextColor */
900     nulldrv_SetTextJustification,       /* pSetTextJustification */
901     nulldrv_SetViewportExtEx,           /* pSetViewportExt */
902     nulldrv_SetViewportOrgEx,           /* pSetViewportOrg */
903     nulldrv_SetWindowExtEx,             /* pSetWindowExt */
904     nulldrv_SetWindowOrgEx,             /* pSetWindowOrg */
905     nulldrv_SetWorldTransform,          /* pSetWorldTransform */
906     nulldrv_StartDoc,                   /* pStartDoc */
907     nulldrv_StartPage,                  /* pStartPage */
908     nulldrv_StretchBlt,                 /* pStretchBlt */
909     nulldrv_StretchDIBits,              /* pStretchDIBits */
910     nulldrv_StrokeAndFillPath,          /* pStrokeAndFillPath */
911     nulldrv_StrokePath,                 /* pStrokePath */
912     nulldrv_SwapBuffers,                /* pSwapBuffers */
913     nulldrv_UnrealizePalette,           /* pUnrealizePalette */
914     nulldrv_WidenPath,                  /* pWidenPath */
915     nulldrv_wglCopyContext,             /* pwglCopyContext */
916     nulldrv_wglCreateContext,           /* pwglCreateContext */
917     nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
918     nulldrv_wglDeleteContext,           /* pwglDeleteContext */
919     nulldrv_wglGetProcAddress,          /* pwglGetProcAddress */
920     nulldrv_wglGetPbufferDCARB,         /* pwglGetPbufferDCARB */
921     nulldrv_wglMakeCurrent,             /* pwglMakeCurrent */
922     nulldrv_wglMakeContextCurrentARB,   /* pwglMakeContextCurrentARB */
923     nulldrv_wglSetPixelFormatWINE,      /* pwglSetPixelFormatWINE */
924     nulldrv_wglShareLists,              /* pwglShareLists */
925     nulldrv_wglUseFontBitmapsA,         /* pwglUseFontBitmapsA */
926     nulldrv_wglUseFontBitmapsW,         /* pwglUseFontBitmapsW */
927 };
928
929
930 /*****************************************************************************
931  *      DRIVER_GetDriverName
932  *
933  */
934 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
935 {
936     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
937     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
938     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
939     static const WCHAR empty_strW[] = { 0 };
940     WCHAR *p;
941
942     /* display is a special case */
943     if (!strcmpiW( device, displayW ) ||
944         !strcmpiW( device, display1W ))
945     {
946         lstrcpynW( driver, displayW, size );
947         return TRUE;
948     }
949
950     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
951     if(!size) {
952         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
953         return FALSE;
954     }
955     p = strchrW(driver, ',');
956     if(!p)
957     {
958         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
959         return FALSE;
960     }
961     *p = 0;
962     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
963     return TRUE;
964 }
965
966
967 /***********************************************************************
968  *           GdiConvertToDevmodeW    (GDI32.@)
969  */
970 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
971 {
972     DEVMODEW *dmW;
973     WORD dmW_size, dmA_size;
974
975     dmA_size = dmA->dmSize;
976
977     /* this is the minimal dmSize that XP accepts */
978     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
979         return NULL;
980
981     if (dmA_size > sizeof(DEVMODEA))
982         dmA_size = sizeof(DEVMODEA);
983
984     dmW_size = dmA_size + CCHDEVICENAME;
985     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
986         dmW_size += CCHFORMNAME;
987
988     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
989     if (!dmW) return NULL;
990
991     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
992                                    dmW->dmDeviceName, CCHDEVICENAME);
993     /* copy slightly more, to avoid long computations */
994     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
995
996     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
997     {
998         if (dmA->dmFields & DM_FORMNAME)
999             MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
1000                                        dmW->dmFormName, CCHFORMNAME);
1001         else
1002             dmW->dmFormName[0] = 0;
1003
1004         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
1005             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
1006     }
1007
1008     if (dmA->dmDriverExtra)
1009         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
1010
1011     dmW->dmSize = dmW_size;
1012
1013     return dmW;
1014 }
1015
1016
1017 /*****************************************************************************
1018  *      @ [GDI32.100]
1019  *
1020  * This should thunk to 16-bit and simply call the proc with the given args.
1021  */
1022 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
1023                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
1024 {
1025     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
1026     return -1;
1027 }
1028
1029 /*****************************************************************************
1030  *      @ [GDI32.101]
1031  *
1032  * This should load the correct driver for lpszDevice and calls this driver's
1033  * ExtDeviceModePropSheet proc.
1034  *
1035  * Note: The driver calls a callback routine for each property sheet page; these
1036  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
1037  * The layout of this structure is:
1038  *
1039  * struct
1040  * {
1041  *   DWORD  nPages;
1042  *   DWORD  unknown;
1043  *   HPROPSHEETPAGE  pages[10];
1044  * };
1045  */
1046 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
1047                                              LPCSTR lpszPort, LPVOID lpPropSheet )
1048 {
1049     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
1050     return -1;
1051 }
1052
1053 /*****************************************************************************
1054  *      @ [GDI32.102]
1055  *
1056  * This should load the correct driver for lpszDevice and call this driver's
1057  * ExtDeviceMode proc.
1058  *
1059  * FIXME: convert ExtDeviceMode to unicode in the driver interface
1060  */
1061 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
1062                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
1063                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
1064                                     LPSTR lpszProfile, DWORD fwMode )
1065 {
1066     WCHAR deviceW[300];
1067     WCHAR bufW[300];
1068     char buf[300];
1069     HDC hdc;
1070     DC *dc;
1071     INT ret = -1;
1072
1073     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
1074           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
1075
1076     if (!lpszDevice) return -1;
1077     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1078
1079     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1080
1081     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1082
1083     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1084
1085     if ((dc = get_dc_ptr( hdc )))
1086     {
1087         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
1088         ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
1089                                               lpdmInput, lpszProfile, fwMode );
1090         release_dc_ptr( dc );
1091     }
1092     DeleteDC( hdc );
1093     return ret;
1094 }
1095
1096 /****************************************************************************
1097  *      @ [GDI32.103]
1098  *
1099  * This should load the correct driver for lpszDevice and calls this driver's
1100  * AdvancedSetupDialog proc.
1101  */
1102 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
1103                                           LPDEVMODEA devin, LPDEVMODEA devout )
1104 {
1105     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
1106     return -1;
1107 }
1108
1109 /*****************************************************************************
1110  *      @ [GDI32.104]
1111  *
1112  * This should load the correct driver for lpszDevice and calls this driver's
1113  * DeviceCapabilities proc.
1114  *
1115  * FIXME: convert DeviceCapabilities to unicode in the driver interface
1116  */
1117 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1118                                            WORD fwCapability, LPSTR lpszOutput,
1119                                            LPDEVMODEA lpdm )
1120 {
1121     WCHAR deviceW[300];
1122     WCHAR bufW[300];
1123     char buf[300];
1124     HDC hdc;
1125     DC *dc;
1126     INT ret = -1;
1127
1128     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1129
1130     if (!lpszDevice) return -1;
1131     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1132
1133     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1134
1135     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1136
1137     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1138
1139     if ((dc = get_dc_ptr( hdc )))
1140     {
1141         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1142         ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1143                                                    fwCapability, lpszOutput, lpdm );
1144         release_dc_ptr( dc );
1145     }
1146     DeleteDC( hdc );
1147     return ret;
1148 }
1149
1150
1151 /************************************************************************
1152  *             Escape  [GDI32.@]
1153  */
1154 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1155 {
1156     INT ret;
1157     POINT *pt;
1158
1159     switch (escape)
1160     {
1161     case ABORTDOC:
1162         return AbortDoc( hdc );
1163
1164     case ENDDOC:
1165         return EndDoc( hdc );
1166
1167     case GETPHYSPAGESIZE:
1168         pt = out_data;
1169         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1170         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1171         return 1;
1172
1173     case GETPRINTINGOFFSET:
1174         pt = out_data;
1175         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1176         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1177         return 1;
1178
1179     case GETSCALINGFACTOR:
1180         pt = out_data;
1181         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1182         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1183         return 1;
1184
1185     case NEWFRAME:
1186         return EndPage( hdc );
1187
1188     case SETABORTPROC:
1189         return SetAbortProc( hdc, (ABORTPROC)in_data );
1190
1191     case STARTDOC:
1192         {
1193             DOCINFOA doc;
1194             char *name = NULL;
1195
1196             /* in_data may not be 0 terminated so we must copy it */
1197             if (in_data)
1198             {
1199                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1200                 memcpy( name, in_data, in_count );
1201                 name[in_count] = 0;
1202             }
1203             /* out_data is actually a pointer to the DocInfo structure and used as
1204              * a second input parameter */
1205             if (out_data) doc = *(DOCINFOA *)out_data;
1206             else
1207             {
1208                 doc.cbSize = sizeof(doc);
1209                 doc.lpszOutput = NULL;
1210                 doc.lpszDatatype = NULL;
1211                 doc.fwType = 0;
1212             }
1213             doc.lpszDocName = name;
1214             ret = StartDocA( hdc, &doc );
1215             HeapFree( GetProcessHeap(), 0, name );
1216             if (ret > 0) ret = StartPage( hdc );
1217             return ret;
1218         }
1219
1220     case QUERYESCSUPPORT:
1221         {
1222             const INT *ptr = (const INT *)in_data;
1223             if (in_count < sizeof(INT)) return 0;
1224             switch(*ptr)
1225             {
1226             case ABORTDOC:
1227             case ENDDOC:
1228             case GETPHYSPAGESIZE:
1229             case GETPRINTINGOFFSET:
1230             case GETSCALINGFACTOR:
1231             case NEWFRAME:
1232             case QUERYESCSUPPORT:
1233             case SETABORTPROC:
1234             case STARTDOC:
1235                 return TRUE;
1236             }
1237             break;
1238         }
1239     }
1240
1241     /* if not handled internally, pass it to the driver */
1242     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1243 }
1244
1245
1246 /******************************************************************************
1247  *              ExtEscape       [GDI32.@]
1248  *
1249  * Access capabilities of a particular device that are not available through GDI.
1250  *
1251  * PARAMS
1252  *    hdc         [I] Handle to device context
1253  *    nEscape     [I] Escape function
1254  *    cbInput     [I] Number of bytes in input structure
1255  *    lpszInData  [I] Pointer to input structure
1256  *    cbOutput    [I] Number of bytes in output structure
1257  *    lpszOutData [O] Pointer to output structure
1258  *
1259  * RETURNS
1260  *    Success: >0
1261  *    Not implemented: 0
1262  *    Failure: <0
1263  */
1264 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1265                       INT cbOutput, LPSTR lpszOutData )
1266 {
1267     INT ret = 0;
1268     DC * dc = get_dc_ptr( hdc );
1269
1270     if (dc)
1271     {
1272         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1273         ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1274         release_dc_ptr( dc );
1275     }
1276     return ret;
1277 }
1278
1279
1280 /*******************************************************************
1281  *      DrawEscape [GDI32.@]
1282  *
1283  *
1284  */
1285 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1286 {
1287     FIXME("DrawEscape, stub\n");
1288     return 0;
1289 }
1290
1291 /*******************************************************************
1292  *      NamedEscape [GDI32.@]
1293  */
1294 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1295                         INT cbOutput, LPSTR lpszOutData )
1296 {
1297     FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1298           hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1299           lpszOutData);
1300     return 0;
1301 }
1302
1303 /*******************************************************************
1304  *      DdQueryDisplaySettingsUniqueness [GDI32.@]
1305  *      GdiEntry13                       [GDI32.@]
1306  */
1307 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1308 {
1309     static int warn_once;
1310
1311     if (!warn_once++)
1312         FIXME("stub\n");
1313     return 0;
1314 }