msxml3: Ignore XML property ResolveExternals.
[wine] / dlls / gdi32 / driver.c
1 /*
2  * Graphics driver management functions
3  *
4  * Copyright 1994 Bob Amstadt
5  * Copyright 1996, 2001 Alexandre Julliard
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "ddrawgdi.h"
32 #include "wine/winbase16.h"
33
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/list.h"
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(driver);
40
41 struct graphics_driver
42 {
43     struct list             entry;
44     HMODULE                 module;  /* module handle */
45     DC_FUNCTIONS            funcs;
46 };
47
48 static struct list drivers = LIST_INIT( drivers );
49 static struct graphics_driver *display_driver;
50
51 static CRITICAL_SECTION driver_section;
52 static CRITICAL_SECTION_DEBUG critsect_debug =
53 {
54     0, 0, &driver_section,
55     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
56       0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
57 };
58 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
59
60 /**********************************************************************
61  *           create_driver
62  *
63  * Allocate and fill the driver structure for a given module.
64  */
65 static struct graphics_driver *create_driver( HMODULE module )
66 {
67     struct graphics_driver *driver;
68
69     if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
70     driver->module = module;
71
72     /* fill the function table */
73     if (module)
74     {
75 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
76         GET_FUNC(AbortDoc);
77         GET_FUNC(AbortPath);
78         GET_FUNC(AlphaBlend);
79         GET_FUNC(AngleArc);
80         GET_FUNC(Arc);
81         GET_FUNC(ArcTo);
82         GET_FUNC(BeginPath);
83         GET_FUNC(BitBlt);
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(SetMapMode);
169         GET_FUNC(SetMapperFlags);
170         GET_FUNC(SetPixel);
171         GET_FUNC(SetPixelFormat);
172         GET_FUNC(SetPolyFillMode);
173         GET_FUNC(SetROP2);
174         GET_FUNC(SetRelAbs);
175         GET_FUNC(SetStretchBltMode);
176         GET_FUNC(SetTextAlign);
177         GET_FUNC(SetTextCharacterExtra);
178         GET_FUNC(SetTextColor);
179         GET_FUNC(SetTextJustification);
180         GET_FUNC(SetViewportExtEx);
181         GET_FUNC(SetViewportOrgEx);
182         GET_FUNC(SetWindowExtEx);
183         GET_FUNC(SetWindowOrgEx);
184         GET_FUNC(SetWorldTransform);
185         GET_FUNC(StartDoc);
186         GET_FUNC(StartPage);
187         GET_FUNC(StretchBlt);
188         GET_FUNC(StretchDIBits);
189         GET_FUNC(StrokeAndFillPath);
190         GET_FUNC(StrokePath);
191         GET_FUNC(SwapBuffers);
192         GET_FUNC(UnrealizePalette);
193         GET_FUNC(WidenPath);
194
195         /* OpenGL32 */
196         GET_FUNC(wglCreateContext);
197         GET_FUNC(wglCreateContextAttribsARB);
198         GET_FUNC(wglDeleteContext);
199         GET_FUNC(wglGetProcAddress);
200         GET_FUNC(wglGetPbufferDCARB);
201         GET_FUNC(wglMakeContextCurrentARB);
202         GET_FUNC(wglMakeCurrent);
203         GET_FUNC(wglSetPixelFormatWINE);
204         GET_FUNC(wglShareLists);
205         GET_FUNC(wglUseFontBitmapsA);
206         GET_FUNC(wglUseFontBitmapsW);
207 #undef GET_FUNC
208     }
209     else memset( &driver->funcs, 0, sizeof(driver->funcs) );
210
211     return driver;
212 }
213
214
215 /**********************************************************************
216  *           DRIVER_get_display_driver
217  *
218  * Special case for loading the display driver: get the name from the config file
219  */
220 const DC_FUNCTIONS *DRIVER_get_display_driver(void)
221 {
222     struct graphics_driver *driver;
223     char buffer[MAX_PATH], libname[32], *name, *next;
224     HMODULE module = 0;
225     HKEY hkey;
226
227     if (display_driver) return &display_driver->funcs;  /* already loaded */
228
229     strcpy( buffer, "x11" );  /* default value */
230     /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
231     if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
232     {
233         DWORD type, count = sizeof(buffer);
234         RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
235         RegCloseKey( hkey );
236     }
237
238     name = buffer;
239     while (name)
240     {
241         next = strchr( name, ',' );
242         if (next) *next++ = 0;
243
244         snprintf( libname, sizeof(libname), "wine%s.drv", name );
245         if ((module = LoadLibraryA( libname )) != 0) break;
246         name = next;
247     }
248
249     if (!(driver = create_driver( module )))
250     {
251         MESSAGE( "Could not create graphics driver '%s'\n", buffer );
252         FreeLibrary( module );
253         ExitProcess(1);
254     }
255     if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
256     {
257         /* somebody beat us to it */
258         FreeLibrary( driver->module );
259         HeapFree( GetProcessHeap(), 0, driver );
260     }
261     return &display_driver->funcs;
262 }
263
264
265 /**********************************************************************
266  *           DRIVER_load_driver
267  */
268 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
269 {
270     HMODULE module;
271     struct graphics_driver *driver, *new_driver;
272     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
273     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
274
275     /* display driver is a special case */
276     if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return DRIVER_get_display_driver();
277
278     if ((module = GetModuleHandleW( name )))
279     {
280         if (display_driver && display_driver->module == module) return &display_driver->funcs;
281         EnterCriticalSection( &driver_section );
282         LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
283         {
284             if (driver->module == module) goto done;
285         }
286         LeaveCriticalSection( &driver_section );
287     }
288
289     if (!(module = LoadLibraryW( name ))) return NULL;
290
291     if (!(new_driver = create_driver( module )))
292     {
293         FreeLibrary( module );
294         return NULL;
295     }
296
297     /* check if someone else added it in the meantime */
298     EnterCriticalSection( &driver_section );
299     LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
300     {
301         if (driver->module != module) continue;
302         FreeLibrary( module );
303         HeapFree( GetProcessHeap(), 0, new_driver );
304         goto done;
305     }
306     driver = new_driver;
307     list_add_head( &drivers, &driver->entry );
308     TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
309 done:
310     LeaveCriticalSection( &driver_section );
311     return &driver->funcs;
312 }
313
314
315 static INT CDECL nulldrv_AbortDoc( PHYSDEV dev )
316 {
317     return 0;
318 }
319
320 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
321                                INT xstart, INT ystart, INT xend, INT yend )
322 {
323     return TRUE;
324 }
325
326 static INT CDECL nulldrv_ChoosePixelFormat( PHYSDEV dev, const PIXELFORMATDESCRIPTOR *descr )
327 {
328     return 0;
329 }
330
331 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
332                                  INT xstart, INT ystart, INT xend, INT yend )
333 {
334     return TRUE;
335 }
336
337 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
338 {
339     return TRUE;
340 }
341
342 static INT CDECL nulldrv_DescribePixelFormat( PHYSDEV dev, INT format,
343                                               UINT size, PIXELFORMATDESCRIPTOR * descr )
344 {
345     return 0;
346 }
347
348 static DWORD CDECL nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
349                                                WORD cap, LPSTR output, DEVMODEA *devmode )
350 {
351     return -1;
352 }
353
354 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
355 {
356     return TRUE;
357 }
358
359 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
360 {
361     return 0;
362 }
363
364 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
365 {
366     return 0;
367 }
368
369 static INT CDECL nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
370 {
371     return -1;
372 }
373
374 static INT CDECL nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
375                                         LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
376 {
377     return -1;
378 }
379
380 static INT CDECL nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
381                                     INT out_size, void *out_data )
382 {
383     return 0;
384 }
385
386 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
387 {
388     return TRUE;
389 }
390
391 static BOOL CDECL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
392 {
393     return FALSE;
394 }
395
396 static BOOL CDECL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
397 {
398     return FALSE;
399 }
400
401 static BOOL CDECL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
402 {
403     return FALSE;
404 }
405
406 static COLORREF CDECL nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
407 {
408     return 0;
409 }
410
411 static INT CDECL nulldrv_GetPixelFormat( PHYSDEV dev )
412 {
413     return 0;
414 }
415
416 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
417 {
418     return TRUE;
419 }
420
421 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
422 {
423     return TRUE;
424 }
425
426 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
427 {
428     return TRUE;
429 }
430
431 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
432                                INT xstart, INT ystart, INT xend, INT yend )
433 {
434     return TRUE;
435 }
436
437 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
438 {
439     /* FIXME: could be implemented with Polygon */
440     return TRUE;
441 }
442
443 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
444 {
445     /* FIXME: could be implemented with Polyline */
446     return TRUE;
447 }
448
449 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
450 {
451     return TRUE;
452 }
453
454 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
455 {
456     return TRUE;
457 }
458
459 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
460 {
461     return TRUE;
462 }
463
464 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
465                                      INT ell_width, INT ell_height )
466 {
467     return TRUE;
468 }
469
470 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
471 {
472     return bitmap;
473 }
474
475 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
476 {
477     return brush;
478 }
479
480 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, HANDLE gdi_font )
481 {
482     return 0;
483 }
484
485 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
486 {
487     return palette;
488 }
489
490 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
491 {
492     return pen;
493 }
494
495 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
496 {
497     return dir;
498 }
499
500 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
501 {
502     return color;
503 }
504
505 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
506 {
507     return mode;
508 }
509
510 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
511 {
512     return color;
513 }
514
515 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
516 {
517     return color;
518 }
519
520 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
521 {
522 }
523
524 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
525 {
526     return layout;
527 }
528
529 static BOOL CDECL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
530 {
531     return FALSE;
532 }
533
534 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
535 {
536     return flags;
537 }
538
539 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
540 {
541     return color;
542 }
543
544 static BOOL CDECL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
545 {
546     return FALSE;
547 }
548
549 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
550 {
551     return mode;
552 }
553
554 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
555 {
556     return rop;
557 }
558
559 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
560 {
561     return mode;
562 }
563
564 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
565 {
566     return mode;
567 }
568
569 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
570 {
571     return align;
572 }
573
574 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
575 {
576     return extra;
577 }
578
579 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
580 {
581     return color;
582 }
583
584 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
585 {
586     return TRUE;
587 }
588
589 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
590 {
591     return 0;
592 }
593
594 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
595 {
596     return 1;
597 }
598
599 static BOOL CDECL nulldrv_SwapBuffers( PHYSDEV dev )
600 {
601     return TRUE;
602 }
603
604 static BOOL CDECL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
605 {
606     return FALSE;
607 }
608
609 static HGLRC CDECL nulldrv_wglCreateContext( PHYSDEV dev )
610 {
611     return 0;
612 }
613
614 static HGLRC CDECL nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
615 {
616     return 0;
617 }
618
619 static BOOL CDECL nulldrv_wglDeleteContext( HGLRC ctx )
620 {
621     return FALSE;
622 }
623
624 static PROC CDECL nulldrv_wglGetProcAddress( LPCSTR name )
625 {
626     return NULL;
627 }
628
629 static HDC CDECL nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
630 {
631     return 0;
632 }
633
634 static BOOL CDECL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
635 {
636     return FALSE;
637 }
638
639 static BOOL CDECL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
640 {
641     return FALSE;
642 }
643
644 static BOOL CDECL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format,
645                                                  const PIXELFORMATDESCRIPTOR *descr )
646 {
647     return FALSE;
648 }
649
650 static BOOL CDECL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
651 {
652     return FALSE;
653 }
654
655 static BOOL CDECL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
656 {
657     return FALSE;
658 }
659
660 static BOOL CDECL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
661 {
662     return FALSE;
663 }
664
665 const DC_FUNCTIONS null_driver =
666 {
667     nulldrv_AbortDoc,                   /* pAbortDoc */
668     NULL,                               /* pAbortPath */
669     NULL,                               /* pAlphaBlend */
670     nulldrv_AngleArc,                   /* pAngleArc */
671     nulldrv_Arc,                        /* pArc */
672     nulldrv_ArcTo,                      /* pArcTo */
673     NULL,                               /* pBeginPath */
674     NULL,                               /* pBitBlt */
675     nulldrv_ChoosePixelFormat,          /* pChoosePixelFormat */
676     nulldrv_Chord,                      /* pChord */
677     NULL,                               /* pCloseFigure */
678     NULL,                               /* pCreateBitmap */
679     NULL,                               /* pCreateDC */
680     NULL,                               /* pCreateDIBSection */
681     NULL,                               /* pDeleteBitmap */
682     NULL,                               /* pDeleteDC */
683     nulldrv_DeleteObject,               /* pDeleteObject */
684     nulldrv_DescribePixelFormat,        /* pDescribePixelFormat */
685     nulldrv_DeviceCapabilities,         /* pDeviceCapabilities */
686     nulldrv_Ellipse,                    /* pEllipse */
687     nulldrv_EndDoc,                     /* pEndDoc */
688     nulldrv_EndPage,                    /* pEndPage */
689     NULL,                               /* pEndPath */
690     nulldrv_EnumICMProfiles,            /* pEnumICMProfiles */
691     NULL,                               /* pEnumDeviceFonts */
692     nulldrv_ExcludeClipRect,            /* pExcludeClipRect */
693     nulldrv_ExtDeviceMode,              /* pExtDeviceMode */
694     nulldrv_ExtEscape,                  /* pExtEscape */
695     nulldrv_ExtFloodFill,               /* pExtFloodFill */
696     nulldrv_ExtSelectClipRgn,           /* pExtSelectClipRgn */
697     NULL,                               /* pExtTextOut */
698     NULL,                               /* pFillPath */
699     nulldrv_FillRgn,                    /* pFillRgn */
700     NULL,                               /* pFlattenPath */
701     nulldrv_FrameRgn,                   /* pFrameRgn */
702     nulldrv_GdiComment,                 /* pGdiComment */
703     NULL,                               /* pGetBitmapBits */
704     NULL,                               /* pGetCharWidth */
705     NULL,                               /* pGetDIBits */
706     NULL,                               /* pGetDeviceCaps */
707     nulldrv_GetDeviceGammaRamp,         /* pGetDeviceGammaRamp */
708     nulldrv_GetICMProfile,              /* pGetICMProfile */
709     NULL,                               /* pGetNearestColor */
710     nulldrv_GetPixel,                   /* pGetPixel */
711     nulldrv_GetPixelFormat,             /* pGetPixelFormat */
712     NULL,                               /* pGetSystemPaletteEntries */
713     NULL,                               /* pGetTextExtentExPoint */
714     NULL,                               /* pGetTextMetrics */
715     nulldrv_IntersectClipRect,          /* pIntersectClipRect */
716     nulldrv_InvertRgn,                  /* pInvertRgn */
717     nulldrv_LineTo,                     /* pLineTo */
718     NULL,                               /* pModifyWorldTransform */
719     nulldrv_MoveTo,                     /* pMoveTo */
720     nulldrv_OffsetClipRgn,              /* pOffsetClipRgn */
721     nulldrv_OffsetViewportOrgEx,        /* pOffsetViewportOrg */
722     nulldrv_OffsetWindowOrgEx,          /* pOffsetWindowOrg */
723     nulldrv_PaintRgn,                   /* pPaintRgn */
724     NULL,                               /* pPatBlt */
725     nulldrv_Pie,                        /* pPie */
726     nulldrv_PolyBezier,                 /* pPolyBezier */
727     nulldrv_PolyBezierTo,               /* pPolyBezierTo */
728     nulldrv_PolyDraw,                   /* pPolyDraw */
729     nulldrv_PolyPolygon,                /* pPolyPolygon */
730     nulldrv_PolyPolyline,               /* pPolyPolyline */
731     nulldrv_Polygon,                    /* pPolygon */
732     nulldrv_Polyline,                   /* pPolyline */
733     nulldrv_PolylineTo,                 /* pPolylineTo */
734     NULL,                               /* pRealizeDefaultPalette */
735     NULL,                               /* pRealizePalette */
736     nulldrv_Rectangle,                  /* pRectangle */
737     NULL,                               /* pResetDC */
738     NULL,                               /* pRestoreDC */
739     nulldrv_RoundRect,                  /* pRoundRect */
740     NULL,                               /* pSaveDC */
741     nulldrv_ScaleViewportExtEx,         /* pScaleViewportExt */
742     nulldrv_ScaleWindowExtEx,           /* pScaleWindowExt */
743     nulldrv_SelectBitmap,               /* pSelectBitmap */
744     nulldrv_SelectBrush,                /* pSelectBrush */
745     NULL,                               /* pSelectClipPath */
746     nulldrv_SelectFont,                 /* pSelectFont */
747     nulldrv_SelectPalette,              /* pSelectPalette */
748     nulldrv_SelectPen,                  /* pSelectPen */
749     nulldrv_SetArcDirection,            /* pSetArcDirection */
750     NULL,                               /* pSetBitmapBits */
751     nulldrv_SetBkColor,                 /* pSetBkColor */
752     nulldrv_SetBkMode,                  /* pSetBkMode */
753     nulldrv_SetDCBrushColor,            /* pSetDCBrushColor */
754     nulldrv_SetDCPenColor,              /* pSetDCPenColor */
755     NULL,                               /* pSetDIBColorTable */
756     NULL,                               /* pSetDIBits */
757     NULL,                               /* pSetDIBitsToDevice */
758     nulldrv_SetDeviceClipping,          /* pSetDeviceClipping */
759     nulldrv_SetDeviceGammaRamp,         /* pSetDeviceGammaRamp */
760     nulldrv_SetLayout,                  /* pSetLayout */
761     nulldrv_SetMapMode,                 /* pSetMapMode */
762     nulldrv_SetMapperFlags,             /* pSetMapperFlags */
763     nulldrv_SetPixel,                   /* pSetPixel */
764     nulldrv_SetPixelFormat,             /* pSetPixelFormat */
765     nulldrv_SetPolyFillMode,            /* pSetPolyFillMode */
766     nulldrv_SetROP2,                    /* pSetROP2 */
767     nulldrv_SetRelAbs,                  /* pSetRelAbs */
768     nulldrv_SetStretchBltMode,          /* pSetStretchBltMode */
769     nulldrv_SetTextAlign,               /* pSetTextAlign */
770     nulldrv_SetTextCharacterExtra,      /* pSetTextCharacterExtra */
771     nulldrv_SetTextColor,               /* pSetTextColor */
772     nulldrv_SetTextJustification,       /* pSetTextJustification */
773     nulldrv_SetViewportExtEx,           /* pSetViewportExt */
774     nulldrv_SetViewportOrgEx,           /* pSetViewportOrg */
775     nulldrv_SetWindowExtEx,             /* pSetWindowExt */
776     nulldrv_SetWindowOrgEx,             /* pSetWindowOrg */
777     NULL,                               /* pSetWorldTransform */
778     nulldrv_StartDoc,                   /* pStartDoc */
779     nulldrv_StartPage,                  /* pStartPage */
780     NULL,                               /* pStretchBlt */
781     NULL,                               /* pStretchDIBits */
782     NULL,                               /* pStrokeAndFillPath */
783     NULL,                               /* pStrokePath */
784     nulldrv_SwapBuffers,                /* pSwapBuffers */
785     NULL,                               /* pUnrealizePalette */
786     NULL,                               /* pWidenPath */
787     nulldrv_wglCopyContext,             /* pwglCopyContext */
788     nulldrv_wglCreateContext,           /* pwglCreateContext */
789     nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
790     nulldrv_wglDeleteContext,           /* pwglDeleteContext */
791     nulldrv_wglGetProcAddress,          /* pwglGetProcAddress */
792     nulldrv_wglGetPbufferDCARB,         /* pwglGetPbufferDCARB */
793     nulldrv_wglMakeCurrent,             /* pwglMakeCurrent */
794     nulldrv_wglMakeContextCurrentARB,   /* pwglMakeContextCurrentARB */
795     nulldrv_wglSetPixelFormatWINE,      /* pwglSetPixelFormatWINE */
796     nulldrv_wglShareLists,              /* pwglShareLists */
797     nulldrv_wglUseFontBitmapsA,         /* pwglUseFontBitmapsA */
798     nulldrv_wglUseFontBitmapsW,         /* pwglUseFontBitmapsW */
799 };
800
801
802 /*****************************************************************************
803  *      DRIVER_GetDriverName
804  *
805  */
806 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
807 {
808     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
809     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
810     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
811     static const WCHAR empty_strW[] = { 0 };
812     WCHAR *p;
813
814     /* display is a special case */
815     if (!strcmpiW( device, displayW ) ||
816         !strcmpiW( device, display1W ))
817     {
818         lstrcpynW( driver, displayW, size );
819         return TRUE;
820     }
821
822     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
823     if(!size) {
824         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
825         return FALSE;
826     }
827     p = strchrW(driver, ',');
828     if(!p)
829     {
830         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
831         return FALSE;
832     }
833     *p = 0;
834     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
835     return TRUE;
836 }
837
838
839 /***********************************************************************
840  *           GdiConvertToDevmodeW    (GDI32.@)
841  */
842 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
843 {
844     DEVMODEW *dmW;
845     WORD dmW_size, dmA_size;
846
847     dmA_size = dmA->dmSize;
848
849     /* this is the minimal dmSize that XP accepts */
850     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
851         return NULL;
852
853     if (dmA_size > sizeof(DEVMODEA))
854         dmA_size = sizeof(DEVMODEA);
855
856     dmW_size = dmA_size + CCHDEVICENAME;
857     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
858         dmW_size += CCHFORMNAME;
859
860     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
861     if (!dmW) return NULL;
862
863     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
864                                    dmW->dmDeviceName, CCHDEVICENAME);
865     /* copy slightly more, to avoid long computations */
866     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
867
868     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
869     {
870         if (dmA->dmFields & DM_FORMNAME)
871             MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
872                                        dmW->dmFormName, CCHFORMNAME);
873         else
874             dmW->dmFormName[0] = 0;
875
876         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
877             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
878     }
879
880     if (dmA->dmDriverExtra)
881         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
882
883     dmW->dmSize = dmW_size;
884
885     return dmW;
886 }
887
888
889 /*****************************************************************************
890  *      @ [GDI32.100]
891  *
892  * This should thunk to 16-bit and simply call the proc with the given args.
893  */
894 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
895                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
896 {
897     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
898     return -1;
899 }
900
901 /*****************************************************************************
902  *      @ [GDI32.101]
903  *
904  * This should load the correct driver for lpszDevice and calls this driver's
905  * ExtDeviceModePropSheet proc.
906  *
907  * Note: The driver calls a callback routine for each property sheet page; these
908  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
909  * The layout of this structure is:
910  *
911  * struct
912  * {
913  *   DWORD  nPages;
914  *   DWORD  unknown;
915  *   HPROPSHEETPAGE  pages[10];
916  * };
917  */
918 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
919                                              LPCSTR lpszPort, LPVOID lpPropSheet )
920 {
921     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
922     return -1;
923 }
924
925 /*****************************************************************************
926  *      @ [GDI32.102]
927  *
928  * This should load the correct driver for lpszDevice and call this driver's
929  * ExtDeviceMode proc.
930  *
931  * FIXME: convert ExtDeviceMode to unicode in the driver interface
932  */
933 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
934                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
935                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
936                                     LPSTR lpszProfile, DWORD fwMode )
937 {
938     WCHAR deviceW[300];
939     WCHAR bufW[300];
940     char buf[300];
941     HDC hdc;
942     DC *dc;
943     INT ret = -1;
944
945     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
946           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
947
948     if (!lpszDevice) return -1;
949     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
950
951     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
952
953     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
954
955     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
956
957     if ((dc = get_dc_ptr( hdc )))
958     {
959         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
960         ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
961                                               lpdmInput, lpszProfile, fwMode );
962         release_dc_ptr( dc );
963     }
964     DeleteDC( hdc );
965     return ret;
966 }
967
968 /****************************************************************************
969  *      @ [GDI32.103]
970  *
971  * This should load the correct driver for lpszDevice and calls this driver's
972  * AdvancedSetupDialog proc.
973  */
974 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
975                                           LPDEVMODEA devin, LPDEVMODEA devout )
976 {
977     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
978     return -1;
979 }
980
981 /*****************************************************************************
982  *      @ [GDI32.104]
983  *
984  * This should load the correct driver for lpszDevice and calls this driver's
985  * DeviceCapabilities proc.
986  *
987  * FIXME: convert DeviceCapabilities to unicode in the driver interface
988  */
989 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
990                                            WORD fwCapability, LPSTR lpszOutput,
991                                            LPDEVMODEA lpdm )
992 {
993     WCHAR deviceW[300];
994     WCHAR bufW[300];
995     char buf[300];
996     HDC hdc;
997     DC *dc;
998     INT ret = -1;
999
1000     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1001
1002     if (!lpszDevice) return -1;
1003     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1004
1005     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1006
1007     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1008
1009     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1010
1011     if ((dc = get_dc_ptr( hdc )))
1012     {
1013         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1014         ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1015                                                    fwCapability, lpszOutput, lpdm );
1016         release_dc_ptr( dc );
1017     }
1018     DeleteDC( hdc );
1019     return ret;
1020 }
1021
1022
1023 /************************************************************************
1024  *             Escape  [GDI32.@]
1025  */
1026 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1027 {
1028     INT ret;
1029     POINT *pt;
1030
1031     switch (escape)
1032     {
1033     case ABORTDOC:
1034         return AbortDoc( hdc );
1035
1036     case ENDDOC:
1037         return EndDoc( hdc );
1038
1039     case GETPHYSPAGESIZE:
1040         pt = out_data;
1041         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1042         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1043         return 1;
1044
1045     case GETPRINTINGOFFSET:
1046         pt = out_data;
1047         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1048         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1049         return 1;
1050
1051     case GETSCALINGFACTOR:
1052         pt = out_data;
1053         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1054         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1055         return 1;
1056
1057     case NEWFRAME:
1058         return EndPage( hdc );
1059
1060     case SETABORTPROC:
1061         return SetAbortProc( hdc, (ABORTPROC)in_data );
1062
1063     case STARTDOC:
1064         {
1065             DOCINFOA doc;
1066             char *name = NULL;
1067
1068             /* in_data may not be 0 terminated so we must copy it */
1069             if (in_data)
1070             {
1071                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1072                 memcpy( name, in_data, in_count );
1073                 name[in_count] = 0;
1074             }
1075             /* out_data is actually a pointer to the DocInfo structure and used as
1076              * a second input parameter */
1077             if (out_data) doc = *(DOCINFOA *)out_data;
1078             else
1079             {
1080                 doc.cbSize = sizeof(doc);
1081                 doc.lpszOutput = NULL;
1082                 doc.lpszDatatype = NULL;
1083                 doc.fwType = 0;
1084             }
1085             doc.lpszDocName = name;
1086             ret = StartDocA( hdc, &doc );
1087             HeapFree( GetProcessHeap(), 0, name );
1088             if (ret > 0) ret = StartPage( hdc );
1089             return ret;
1090         }
1091
1092     case QUERYESCSUPPORT:
1093         {
1094             const INT *ptr = (const INT *)in_data;
1095             if (in_count < sizeof(INT)) return 0;
1096             switch(*ptr)
1097             {
1098             case ABORTDOC:
1099             case ENDDOC:
1100             case GETPHYSPAGESIZE:
1101             case GETPRINTINGOFFSET:
1102             case GETSCALINGFACTOR:
1103             case NEWFRAME:
1104             case QUERYESCSUPPORT:
1105             case SETABORTPROC:
1106             case STARTDOC:
1107                 return TRUE;
1108             }
1109             break;
1110         }
1111     }
1112
1113     /* if not handled internally, pass it to the driver */
1114     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1115 }
1116
1117
1118 /******************************************************************************
1119  *              ExtEscape       [GDI32.@]
1120  *
1121  * Access capabilities of a particular device that are not available through GDI.
1122  *
1123  * PARAMS
1124  *    hdc         [I] Handle to device context
1125  *    nEscape     [I] Escape function
1126  *    cbInput     [I] Number of bytes in input structure
1127  *    lpszInData  [I] Pointer to input structure
1128  *    cbOutput    [I] Number of bytes in output structure
1129  *    lpszOutData [O] Pointer to output structure
1130  *
1131  * RETURNS
1132  *    Success: >0
1133  *    Not implemented: 0
1134  *    Failure: <0
1135  */
1136 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1137                       INT cbOutput, LPSTR lpszOutData )
1138 {
1139     INT ret = 0;
1140     DC * dc = get_dc_ptr( hdc );
1141
1142     if (dc)
1143     {
1144         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1145         ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1146         release_dc_ptr( dc );
1147     }
1148     return ret;
1149 }
1150
1151
1152 /*******************************************************************
1153  *      DrawEscape [GDI32.@]
1154  *
1155  *
1156  */
1157 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1158 {
1159     FIXME("DrawEscape, stub\n");
1160     return 0;
1161 }
1162
1163 /*******************************************************************
1164  *      NamedEscape [GDI32.@]
1165  */
1166 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1167                         INT cbOutput, LPSTR lpszOutData )
1168 {
1169     FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1170           hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1171           lpszOutData);
1172     return 0;
1173 }
1174
1175 /*******************************************************************
1176  *      DdQueryDisplaySettingsUniqueness [GDI32.@]
1177  *      GdiEntry13                       [GDI32.@]
1178  */
1179 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1180 {
1181     static int warn_once;
1182
1183     if (!warn_once++)
1184         FIXME("stub\n");
1185     return 0;
1186 }