msvcrt: Added _snscanf implementation.
[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, INT x_dst, INT y_dst, INT width_dst, INT height_dst,
322                                       PHYSDEV src_dev, INT x_src, INT y_src, INT width_src, INT height_src,
323                                       BLENDFUNCTION func)
324 {
325     return TRUE;
326 }
327
328 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
329                                INT xstart, INT ystart, INT xend, INT yend )
330 {
331     return TRUE;
332 }
333
334 static INT CDECL nulldrv_ChoosePixelFormat( PHYSDEV dev, const PIXELFORMATDESCRIPTOR *descr )
335 {
336     return 0;
337 }
338
339 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
340                                  INT xstart, INT ystart, INT xend, INT yend )
341 {
342     return TRUE;
343 }
344
345 static BOOL CDECL nulldrv_CreateBitmap( PHYSDEV dev, HBITMAP bitmap, LPVOID bits )
346 {
347     return TRUE;
348 }
349
350 static BOOL CDECL nulldrv_CreateDC( HDC hdc, PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
351                                     LPCWSTR output, const DEVMODEW *devmode )
352 {
353     assert(0);  /* should never be called */
354     return FALSE;
355 }
356
357 static HBITMAP CDECL nulldrv_CreateDIBSection( PHYSDEV dev, HBITMAP bitmap,
358                                                const BITMAPINFO *info, UINT usage )
359 {
360     return bitmap;
361 }
362
363 static BOOL CDECL nulldrv_DeleteBitmap( HBITMAP bitmap )
364 {
365     return TRUE;
366 }
367
368 static BOOL CDECL nulldrv_DeleteDC( PHYSDEV dev )
369 {
370     assert(0);  /* should never be called */
371     return TRUE;
372 }
373
374 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
375 {
376     return TRUE;
377 }
378
379 static INT CDECL nulldrv_DescribePixelFormat( PHYSDEV dev, INT format,
380                                               UINT size, PIXELFORMATDESCRIPTOR * descr )
381 {
382     return 0;
383 }
384
385 static DWORD CDECL nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
386                                                WORD cap, LPSTR output, DEVMODEA *devmode )
387 {
388     return -1;
389 }
390
391 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
392 {
393     return TRUE;
394 }
395
396 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
397 {
398     return 0;
399 }
400
401 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
402 {
403     return 0;
404 }
405
406 static BOOL CDECL nulldrv_EnumDeviceFonts( PHYSDEV dev, LOGFONTW *logfont,
407                                            FONTENUMPROCW proc, LPARAM lParam )
408 {
409     return FALSE;
410 }
411
412 static INT CDECL nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
413 {
414     return -1;
415 }
416
417 static INT CDECL nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
418                                         LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
419 {
420     return -1;
421 }
422
423 static INT CDECL nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
424                                     INT out_size, void *out_data )
425 {
426     return 0;
427 }
428
429 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
430 {
431     return TRUE;
432 }
433
434 static BOOL CDECL nulldrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect,
435                                       LPCWSTR str, UINT count, const INT *dx )
436 {
437     return TRUE;
438 }
439
440 static BOOL CDECL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
441 {
442     return FALSE;
443 }
444
445 static BOOL CDECL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
446 {
447     return FALSE;
448 }
449
450 static INT CDECL nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
451 {
452     switch (cap)  /* return meaningful values for some entries */
453     {
454     case HORZRES:     return 640;
455     case VERTRES:     return 480;
456     case BITSPIXEL:   return 1;
457     case PLANES:      return 1;
458     case NUMCOLORS:   return 2;
459     case ASPECTX:     return 36;
460     case ASPECTY:     return 36;
461     case ASPECTXY:    return 51;
462     case LOGPIXELSX:  return 72;
463     case LOGPIXELSY:  return 72;
464     case SIZEPALETTE: return 2;
465     case TEXTCAPS:    return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
466                               TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
467                               TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
468     default:          return 0;
469     }
470 }
471
472 static BOOL CDECL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
473 {
474     return FALSE;
475 }
476
477 static BOOL CDECL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
478 {
479     return FALSE;
480 }
481
482 static COLORREF CDECL nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
483 {
484     return 0;
485 }
486
487 static INT CDECL nulldrv_GetPixelFormat( PHYSDEV dev )
488 {
489     return 0;
490 }
491
492 static UINT CDECL nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start,
493                                                    UINT count, PALETTEENTRY *entries )
494 {
495     return 0;
496 }
497
498 static BOOL CDECL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
499                                                 INT *fit, INT *dx, SIZE *size )
500 {
501     return FALSE;
502 }
503
504 static BOOL CDECL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
505 {
506     return FALSE;
507 }
508
509 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
510 {
511     return TRUE;
512 }
513
514 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
515 {
516     return TRUE;
517 }
518
519 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
520 {
521     return TRUE;
522 }
523
524 static BOOL CDECL nulldrv_PatBlt( PHYSDEV dev, INT x, INT y, INT width, INT height, DWORD rop )
525 {
526     return TRUE;
527 }
528
529 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
530                                INT xstart, INT ystart, INT xend, INT yend )
531 {
532     return TRUE;
533 }
534
535 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
536 {
537     /* FIXME: could be implemented with Polygon */
538     return TRUE;
539 }
540
541 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
542 {
543     /* FIXME: could be implemented with Polyline */
544     return TRUE;
545 }
546
547 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
548 {
549     return TRUE;
550 }
551
552 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
553 {
554     return TRUE;
555 }
556
557 static UINT CDECL nulldrv_RealizeDefaultPalette( PHYSDEV dev )
558 {
559     return 0;
560 }
561
562 static UINT CDECL nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
563 {
564     return 0;
565 }
566
567 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
568 {
569     return TRUE;
570 }
571
572 static HDC CDECL nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
573 {
574     return 0;
575 }
576
577 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
578                                      INT ell_width, INT ell_height )
579 {
580     return TRUE;
581 }
582
583 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
584 {
585     return bitmap;
586 }
587
588 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
589 {
590     return brush;
591 }
592
593 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, HANDLE gdi_font )
594 {
595     return 0;
596 }
597
598 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
599 {
600     return palette;
601 }
602
603 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
604 {
605     return pen;
606 }
607
608 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
609 {
610     return dir;
611 }
612
613 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
614 {
615     return color;
616 }
617
618 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
619 {
620     return mode;
621 }
622
623 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
624 {
625     return color;
626 }
627
628 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
629 {
630     return color;
631 }
632
633 static UINT CDECL nulldrv_SetDIBColorTable( PHYSDEV dev, UINT pos, UINT count, const RGBQUAD *colors )
634 {
635     return 0;
636 }
637
638 static INT CDECL nulldrv_SetDIBitsToDevice( PHYSDEV dev, INT x_dst, INT y_dst, DWORD width, DWORD height,
639                                             INT x_src, INT y_src, UINT start, UINT lines,
640                                             const void *bits, const BITMAPINFO *info, UINT coloruse )
641 {
642     return 0;
643 }
644
645 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
646 {
647 }
648
649 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
650 {
651     return layout;
652 }
653
654 static BOOL CDECL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
655 {
656     return FALSE;
657 }
658
659 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
660 {
661     return flags;
662 }
663
664 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
665 {
666     return color;
667 }
668
669 static BOOL CDECL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
670 {
671     return FALSE;
672 }
673
674 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
675 {
676     return mode;
677 }
678
679 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
680 {
681     return rop;
682 }
683
684 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
685 {
686     return mode;
687 }
688
689 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
690 {
691     return mode;
692 }
693
694 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
695 {
696     return align;
697 }
698
699 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
700 {
701     return extra;
702 }
703
704 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
705 {
706     return color;
707 }
708
709 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
710 {
711     return TRUE;
712 }
713
714 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
715 {
716     return 0;
717 }
718
719 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
720 {
721     return 1;
722 }
723
724 static BOOL CDECL nulldrv_SwapBuffers( PHYSDEV dev )
725 {
726     return TRUE;
727 }
728
729 static BOOL CDECL nulldrv_UnrealizePalette( HPALETTE palette )
730 {
731     return FALSE;
732 }
733
734 static BOOL CDECL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
735 {
736     return FALSE;
737 }
738
739 static HGLRC CDECL nulldrv_wglCreateContext( PHYSDEV dev )
740 {
741     return 0;
742 }
743
744 static HGLRC CDECL nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
745 {
746     return 0;
747 }
748
749 static BOOL CDECL nulldrv_wglDeleteContext( HGLRC ctx )
750 {
751     return FALSE;
752 }
753
754 static PROC CDECL nulldrv_wglGetProcAddress( LPCSTR name )
755 {
756     return NULL;
757 }
758
759 static HDC CDECL nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
760 {
761     return 0;
762 }
763
764 static BOOL CDECL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
765 {
766     return FALSE;
767 }
768
769 static BOOL CDECL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
770 {
771     return FALSE;
772 }
773
774 static BOOL CDECL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format,
775                                                  const PIXELFORMATDESCRIPTOR *descr )
776 {
777     return FALSE;
778 }
779
780 static BOOL CDECL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
781 {
782     return FALSE;
783 }
784
785 static BOOL CDECL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
786 {
787     return FALSE;
788 }
789
790 static BOOL CDECL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
791 {
792     return FALSE;
793 }
794
795 const DC_FUNCTIONS null_driver =
796 {
797     nulldrv_AbortDoc,                   /* pAbortDoc */
798     nulldrv_AbortPath,                  /* pAbortPath */
799     nulldrv_AlphaBlend,                 /* pAlphaBlend */
800     nulldrv_AngleArc,                   /* pAngleArc */
801     nulldrv_Arc,                        /* pArc */
802     nulldrv_ArcTo,                      /* pArcTo */
803     nulldrv_BeginPath,                  /* pBeginPath */
804     nulldrv_ChoosePixelFormat,          /* pChoosePixelFormat */
805     nulldrv_Chord,                      /* pChord */
806     nulldrv_CloseFigure,                /* pCloseFigure */
807     nulldrv_CreateBitmap,               /* pCreateBitmap */
808     nulldrv_CreateDC,                   /* pCreateDC */
809     nulldrv_CreateDIBSection,           /* pCreateDIBSection */
810     nulldrv_DeleteBitmap,               /* pDeleteBitmap */
811     nulldrv_DeleteDC,                   /* pDeleteDC */
812     nulldrv_DeleteObject,               /* pDeleteObject */
813     nulldrv_DescribePixelFormat,        /* pDescribePixelFormat */
814     nulldrv_DeviceCapabilities,         /* pDeviceCapabilities */
815     nulldrv_Ellipse,                    /* pEllipse */
816     nulldrv_EndDoc,                     /* pEndDoc */
817     nulldrv_EndPage,                    /* pEndPage */
818     nulldrv_EndPath,                    /* pEndPath */
819     nulldrv_EnumDeviceFonts,            /* pEnumDeviceFonts */
820     nulldrv_EnumICMProfiles,            /* pEnumICMProfiles */
821     nulldrv_ExcludeClipRect,            /* pExcludeClipRect */
822     nulldrv_ExtDeviceMode,              /* pExtDeviceMode */
823     nulldrv_ExtEscape,                  /* pExtEscape */
824     nulldrv_ExtFloodFill,               /* pExtFloodFill */
825     nulldrv_ExtSelectClipRgn,           /* pExtSelectClipRgn */
826     nulldrv_ExtTextOut,                 /* pExtTextOut */
827     nulldrv_FillPath,                   /* pFillPath */
828     nulldrv_FillRgn,                    /* pFillRgn */
829     nulldrv_FlattenPath,                /* pFlattenPath */
830     nulldrv_FrameRgn,                   /* pFrameRgn */
831     nulldrv_GdiComment,                 /* pGdiComment */
832     nulldrv_GetBitmapBits,              /* pGetBitmapBits */
833     nulldrv_GetCharWidth,               /* pGetCharWidth */
834     nulldrv_GetDIBits,                  /* pGetDIBits */
835     nulldrv_GetDeviceCaps,              /* pGetDeviceCaps */
836     nulldrv_GetDeviceGammaRamp,         /* pGetDeviceGammaRamp */
837     nulldrv_GetICMProfile,              /* pGetICMProfile */
838     nulldrv_GetNearestColor,            /* pGetNearestColor */
839     nulldrv_GetPixel,                   /* pGetPixel */
840     nulldrv_GetPixelFormat,             /* pGetPixelFormat */
841     nulldrv_GetSystemPaletteEntries,    /* pGetSystemPaletteEntries */
842     nulldrv_GetTextExtentExPoint,       /* pGetTextExtentExPoint */
843     nulldrv_GetTextMetrics,             /* pGetTextMetrics */
844     nulldrv_IntersectClipRect,          /* pIntersectClipRect */
845     nulldrv_InvertRgn,                  /* pInvertRgn */
846     nulldrv_LineTo,                     /* pLineTo */
847     nulldrv_ModifyWorldTransform,       /* pModifyWorldTransform */
848     nulldrv_MoveTo,                     /* pMoveTo */
849     nulldrv_OffsetClipRgn,              /* pOffsetClipRgn */
850     nulldrv_OffsetViewportOrgEx,        /* pOffsetViewportOrg */
851     nulldrv_OffsetWindowOrgEx,          /* pOffsetWindowOrg */
852     nulldrv_PaintRgn,                   /* pPaintRgn */
853     nulldrv_PatBlt,                     /* pPatBlt */
854     nulldrv_Pie,                        /* pPie */
855     nulldrv_PolyBezier,                 /* pPolyBezier */
856     nulldrv_PolyBezierTo,               /* pPolyBezierTo */
857     nulldrv_PolyDraw,                   /* pPolyDraw */
858     nulldrv_PolyPolygon,                /* pPolyPolygon */
859     nulldrv_PolyPolyline,               /* pPolyPolyline */
860     nulldrv_Polygon,                    /* pPolygon */
861     nulldrv_Polyline,                   /* pPolyline */
862     nulldrv_PolylineTo,                 /* pPolylineTo */
863     nulldrv_RealizeDefaultPalette,      /* pRealizeDefaultPalette */
864     nulldrv_RealizePalette,             /* pRealizePalette */
865     nulldrv_Rectangle,                  /* pRectangle */
866     nulldrv_ResetDC,                    /* pResetDC */
867     nulldrv_RestoreDC,                  /* pRestoreDC */
868     nulldrv_RoundRect,                  /* pRoundRect */
869     nulldrv_SaveDC,                     /* pSaveDC */
870     nulldrv_ScaleViewportExtEx,         /* pScaleViewportExt */
871     nulldrv_ScaleWindowExtEx,           /* pScaleWindowExt */
872     nulldrv_SelectBitmap,               /* pSelectBitmap */
873     nulldrv_SelectBrush,                /* pSelectBrush */
874     nulldrv_SelectClipPath,             /* pSelectClipPath */
875     nulldrv_SelectFont,                 /* pSelectFont */
876     nulldrv_SelectPalette,              /* pSelectPalette */
877     nulldrv_SelectPen,                  /* pSelectPen */
878     nulldrv_SetArcDirection,            /* pSetArcDirection */
879     nulldrv_SetBitmapBits,              /* pSetBitmapBits */
880     nulldrv_SetBkColor,                 /* pSetBkColor */
881     nulldrv_SetBkMode,                  /* pSetBkMode */
882     nulldrv_SetDCBrushColor,            /* pSetDCBrushColor */
883     nulldrv_SetDCPenColor,              /* pSetDCPenColor */
884     nulldrv_SetDIBColorTable,           /* pSetDIBColorTable */
885     nulldrv_SetDIBits,                  /* pSetDIBits */
886     nulldrv_SetDIBitsToDevice,          /* pSetDIBitsToDevice */
887     nulldrv_SetDeviceClipping,          /* pSetDeviceClipping */
888     nulldrv_SetDeviceGammaRamp,         /* pSetDeviceGammaRamp */
889     nulldrv_SetLayout,                  /* pSetLayout */
890     nulldrv_SetMapMode,                 /* pSetMapMode */
891     nulldrv_SetMapperFlags,             /* pSetMapperFlags */
892     nulldrv_SetPixel,                   /* pSetPixel */
893     nulldrv_SetPixelFormat,             /* pSetPixelFormat */
894     nulldrv_SetPolyFillMode,            /* pSetPolyFillMode */
895     nulldrv_SetROP2,                    /* pSetROP2 */
896     nulldrv_SetRelAbs,                  /* pSetRelAbs */
897     nulldrv_SetStretchBltMode,          /* pSetStretchBltMode */
898     nulldrv_SetTextAlign,               /* pSetTextAlign */
899     nulldrv_SetTextCharacterExtra,      /* pSetTextCharacterExtra */
900     nulldrv_SetTextColor,               /* pSetTextColor */
901     nulldrv_SetTextJustification,       /* pSetTextJustification */
902     nulldrv_SetViewportExtEx,           /* pSetViewportExt */
903     nulldrv_SetViewportOrgEx,           /* pSetViewportOrg */
904     nulldrv_SetWindowExtEx,             /* pSetWindowExt */
905     nulldrv_SetWindowOrgEx,             /* pSetWindowOrg */
906     nulldrv_SetWorldTransform,          /* pSetWorldTransform */
907     nulldrv_StartDoc,                   /* pStartDoc */
908     nulldrv_StartPage,                  /* pStartPage */
909     nulldrv_StretchBlt,                 /* pStretchBlt */
910     nulldrv_StretchDIBits,              /* pStretchDIBits */
911     nulldrv_StrokeAndFillPath,          /* pStrokeAndFillPath */
912     nulldrv_StrokePath,                 /* pStrokePath */
913     nulldrv_SwapBuffers,                /* pSwapBuffers */
914     nulldrv_UnrealizePalette,           /* pUnrealizePalette */
915     nulldrv_WidenPath,                  /* pWidenPath */
916     nulldrv_wglCopyContext,             /* pwglCopyContext */
917     nulldrv_wglCreateContext,           /* pwglCreateContext */
918     nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
919     nulldrv_wglDeleteContext,           /* pwglDeleteContext */
920     nulldrv_wglGetProcAddress,          /* pwglGetProcAddress */
921     nulldrv_wglGetPbufferDCARB,         /* pwglGetPbufferDCARB */
922     nulldrv_wglMakeCurrent,             /* pwglMakeCurrent */
923     nulldrv_wglMakeContextCurrentARB,   /* pwglMakeContextCurrentARB */
924     nulldrv_wglSetPixelFormatWINE,      /* pwglSetPixelFormatWINE */
925     nulldrv_wglShareLists,              /* pwglShareLists */
926     nulldrv_wglUseFontBitmapsA,         /* pwglUseFontBitmapsA */
927     nulldrv_wglUseFontBitmapsW,         /* pwglUseFontBitmapsW */
928 };
929
930
931 /*****************************************************************************
932  *      DRIVER_GetDriverName
933  *
934  */
935 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
936 {
937     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
938     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
939     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
940     static const WCHAR empty_strW[] = { 0 };
941     WCHAR *p;
942
943     /* display is a special case */
944     if (!strcmpiW( device, displayW ) ||
945         !strcmpiW( device, display1W ))
946     {
947         lstrcpynW( driver, displayW, size );
948         return TRUE;
949     }
950
951     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
952     if(!size) {
953         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
954         return FALSE;
955     }
956     p = strchrW(driver, ',');
957     if(!p)
958     {
959         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
960         return FALSE;
961     }
962     *p = 0;
963     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
964     return TRUE;
965 }
966
967
968 /***********************************************************************
969  *           GdiConvertToDevmodeW    (GDI32.@)
970  */
971 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
972 {
973     DEVMODEW *dmW;
974     WORD dmW_size, dmA_size;
975
976     dmA_size = dmA->dmSize;
977
978     /* this is the minimal dmSize that XP accepts */
979     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
980         return NULL;
981
982     if (dmA_size > sizeof(DEVMODEA))
983         dmA_size = sizeof(DEVMODEA);
984
985     dmW_size = dmA_size + CCHDEVICENAME;
986     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
987         dmW_size += CCHFORMNAME;
988
989     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
990     if (!dmW) return NULL;
991
992     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
993                                    dmW->dmDeviceName, CCHDEVICENAME);
994     /* copy slightly more, to avoid long computations */
995     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
996
997     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
998     {
999         if (dmA->dmFields & DM_FORMNAME)
1000             MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
1001                                        dmW->dmFormName, CCHFORMNAME);
1002         else
1003             dmW->dmFormName[0] = 0;
1004
1005         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
1006             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
1007     }
1008
1009     if (dmA->dmDriverExtra)
1010         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
1011
1012     dmW->dmSize = dmW_size;
1013
1014     return dmW;
1015 }
1016
1017
1018 /*****************************************************************************
1019  *      @ [GDI32.100]
1020  *
1021  * This should thunk to 16-bit and simply call the proc with the given args.
1022  */
1023 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
1024                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
1025 {
1026     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
1027     return -1;
1028 }
1029
1030 /*****************************************************************************
1031  *      @ [GDI32.101]
1032  *
1033  * This should load the correct driver for lpszDevice and calls this driver's
1034  * ExtDeviceModePropSheet proc.
1035  *
1036  * Note: The driver calls a callback routine for each property sheet page; these
1037  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
1038  * The layout of this structure is:
1039  *
1040  * struct
1041  * {
1042  *   DWORD  nPages;
1043  *   DWORD  unknown;
1044  *   HPROPSHEETPAGE  pages[10];
1045  * };
1046  */
1047 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
1048                                              LPCSTR lpszPort, LPVOID lpPropSheet )
1049 {
1050     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
1051     return -1;
1052 }
1053
1054 /*****************************************************************************
1055  *      @ [GDI32.102]
1056  *
1057  * This should load the correct driver for lpszDevice and call this driver's
1058  * ExtDeviceMode proc.
1059  *
1060  * FIXME: convert ExtDeviceMode to unicode in the driver interface
1061  */
1062 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
1063                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
1064                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
1065                                     LPSTR lpszProfile, DWORD fwMode )
1066 {
1067     WCHAR deviceW[300];
1068     WCHAR bufW[300];
1069     char buf[300];
1070     HDC hdc;
1071     DC *dc;
1072     INT ret = -1;
1073
1074     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
1075           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
1076
1077     if (!lpszDevice) return -1;
1078     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1079
1080     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1081
1082     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1083
1084     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1085
1086     if ((dc = get_dc_ptr( hdc )))
1087     {
1088         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
1089         ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
1090                                               lpdmInput, lpszProfile, fwMode );
1091         release_dc_ptr( dc );
1092     }
1093     DeleteDC( hdc );
1094     return ret;
1095 }
1096
1097 /****************************************************************************
1098  *      @ [GDI32.103]
1099  *
1100  * This should load the correct driver for lpszDevice and calls this driver's
1101  * AdvancedSetupDialog proc.
1102  */
1103 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
1104                                           LPDEVMODEA devin, LPDEVMODEA devout )
1105 {
1106     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
1107     return -1;
1108 }
1109
1110 /*****************************************************************************
1111  *      @ [GDI32.104]
1112  *
1113  * This should load the correct driver for lpszDevice and calls this driver's
1114  * DeviceCapabilities proc.
1115  *
1116  * FIXME: convert DeviceCapabilities to unicode in the driver interface
1117  */
1118 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1119                                            WORD fwCapability, LPSTR lpszOutput,
1120                                            LPDEVMODEA lpdm )
1121 {
1122     WCHAR deviceW[300];
1123     WCHAR bufW[300];
1124     char buf[300];
1125     HDC hdc;
1126     DC *dc;
1127     INT ret = -1;
1128
1129     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1130
1131     if (!lpszDevice) return -1;
1132     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1133
1134     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1135
1136     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1137
1138     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1139
1140     if ((dc = get_dc_ptr( hdc )))
1141     {
1142         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1143         ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1144                                                    fwCapability, lpszOutput, lpdm );
1145         release_dc_ptr( dc );
1146     }
1147     DeleteDC( hdc );
1148     return ret;
1149 }
1150
1151
1152 /************************************************************************
1153  *             Escape  [GDI32.@]
1154  */
1155 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1156 {
1157     INT ret;
1158     POINT *pt;
1159
1160     switch (escape)
1161     {
1162     case ABORTDOC:
1163         return AbortDoc( hdc );
1164
1165     case ENDDOC:
1166         return EndDoc( hdc );
1167
1168     case GETPHYSPAGESIZE:
1169         pt = out_data;
1170         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1171         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1172         return 1;
1173
1174     case GETPRINTINGOFFSET:
1175         pt = out_data;
1176         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1177         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1178         return 1;
1179
1180     case GETSCALINGFACTOR:
1181         pt = out_data;
1182         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1183         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1184         return 1;
1185
1186     case NEWFRAME:
1187         return EndPage( hdc );
1188
1189     case SETABORTPROC:
1190         return SetAbortProc( hdc, (ABORTPROC)in_data );
1191
1192     case STARTDOC:
1193         {
1194             DOCINFOA doc;
1195             char *name = NULL;
1196
1197             /* in_data may not be 0 terminated so we must copy it */
1198             if (in_data)
1199             {
1200                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1201                 memcpy( name, in_data, in_count );
1202                 name[in_count] = 0;
1203             }
1204             /* out_data is actually a pointer to the DocInfo structure and used as
1205              * a second input parameter */
1206             if (out_data) doc = *(DOCINFOA *)out_data;
1207             else
1208             {
1209                 doc.cbSize = sizeof(doc);
1210                 doc.lpszOutput = NULL;
1211                 doc.lpszDatatype = NULL;
1212                 doc.fwType = 0;
1213             }
1214             doc.lpszDocName = name;
1215             ret = StartDocA( hdc, &doc );
1216             HeapFree( GetProcessHeap(), 0, name );
1217             if (ret > 0) ret = StartPage( hdc );
1218             return ret;
1219         }
1220
1221     case QUERYESCSUPPORT:
1222         {
1223             const INT *ptr = (const INT *)in_data;
1224             if (in_count < sizeof(INT)) return 0;
1225             switch(*ptr)
1226             {
1227             case ABORTDOC:
1228             case ENDDOC:
1229             case GETPHYSPAGESIZE:
1230             case GETPRINTINGOFFSET:
1231             case GETSCALINGFACTOR:
1232             case NEWFRAME:
1233             case QUERYESCSUPPORT:
1234             case SETABORTPROC:
1235             case STARTDOC:
1236                 return TRUE;
1237             }
1238             break;
1239         }
1240     }
1241
1242     /* if not handled internally, pass it to the driver */
1243     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1244 }
1245
1246
1247 /******************************************************************************
1248  *              ExtEscape       [GDI32.@]
1249  *
1250  * Access capabilities of a particular device that are not available through GDI.
1251  *
1252  * PARAMS
1253  *    hdc         [I] Handle to device context
1254  *    nEscape     [I] Escape function
1255  *    cbInput     [I] Number of bytes in input structure
1256  *    lpszInData  [I] Pointer to input structure
1257  *    cbOutput    [I] Number of bytes in output structure
1258  *    lpszOutData [O] Pointer to output structure
1259  *
1260  * RETURNS
1261  *    Success: >0
1262  *    Not implemented: 0
1263  *    Failure: <0
1264  */
1265 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1266                       INT cbOutput, LPSTR lpszOutData )
1267 {
1268     INT ret = 0;
1269     DC * dc = get_dc_ptr( hdc );
1270
1271     if (dc)
1272     {
1273         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1274         ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1275         release_dc_ptr( dc );
1276     }
1277     return ret;
1278 }
1279
1280
1281 /*******************************************************************
1282  *      DrawEscape [GDI32.@]
1283  *
1284  *
1285  */
1286 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1287 {
1288     FIXME("DrawEscape, stub\n");
1289     return 0;
1290 }
1291
1292 /*******************************************************************
1293  *      NamedEscape [GDI32.@]
1294  */
1295 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1296                         INT cbOutput, LPSTR lpszOutData )
1297 {
1298     FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1299           hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1300           lpszOutData);
1301     return 0;
1302 }
1303
1304 /*******************************************************************
1305  *      DdQueryDisplaySettingsUniqueness [GDI32.@]
1306  *      GdiEntry13                       [GDI32.@]
1307  */
1308 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1309 {
1310     static int warn_once;
1311
1312     if (!warn_once++)
1313         FIXME("stub\n");
1314     return 0;
1315 }