jscript: Don't pass 'this' argument to DISPID_VALUE of pure IDispatch interfaces.
[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     const struct gdi_dc_funcs *funcs;
47 };
48
49 static struct list drivers = LIST_INIT( drivers );
50 static struct graphics_driver *display_driver;
51 static DWORD display_driver_load_error;
52
53 const struct gdi_dc_funcs *font_driver = NULL;
54
55 static CRITICAL_SECTION driver_section;
56 static CRITICAL_SECTION_DEBUG critsect_debug =
57 {
58     0, 0, &driver_section,
59     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
60       0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
61 };
62 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
63
64 /**********************************************************************
65  *           create_driver
66  *
67  * Allocate and fill the driver structure for a given module.
68  */
69 static struct graphics_driver *create_driver( HMODULE module )
70 {
71     static const struct gdi_dc_funcs empty_funcs;
72     const struct gdi_dc_funcs *funcs = NULL;
73     struct graphics_driver *driver;
74
75     if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
76     driver->module = module;
77
78     if (module)
79     {
80         const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
81
82         if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
83             funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
84     }
85     if (!funcs) funcs = &empty_funcs;
86     driver->funcs = funcs;
87     return driver;
88 }
89
90
91 /**********************************************************************
92  *           get_display_driver
93  *
94  * Special case for loading the display driver: get the name from the config file
95  */
96 static const struct gdi_dc_funcs *get_display_driver( HMODULE *module_ret )
97 {
98     struct graphics_driver *driver;
99     char buffer[MAX_PATH], libname[32], *name, *next;
100     HMODULE module = 0;
101     HKEY hkey;
102
103     if (display_driver)
104     {
105         *module_ret = display_driver->module;
106         return display_driver->funcs;  /* already loaded */
107     }
108
109     strcpy( buffer, "x11" );  /* default value */
110     /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
111     if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
112     {
113         DWORD type, count = sizeof(buffer);
114         RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
115         RegCloseKey( hkey );
116     }
117
118     name = buffer;
119     while (name)
120     {
121         next = strchr( name, ',' );
122         if (next) *next++ = 0;
123
124         snprintf( libname, sizeof(libname), "wine%s.drv", name );
125         if ((module = LoadLibraryA( libname )) != 0) break;
126         name = next;
127     }
128
129     if (!module) display_driver_load_error = GetLastError();
130
131     if (!(driver = create_driver( module )))
132     {
133         MESSAGE( "Could not create graphics driver '%s'\n", buffer );
134         FreeLibrary( module );
135         ExitProcess(1);
136     }
137     if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
138     {
139         /* somebody beat us to it */
140         FreeLibrary( driver->module );
141         HeapFree( GetProcessHeap(), 0, driver );
142     }
143     return display_driver->funcs;
144 }
145
146
147 /**********************************************************************
148  *           DRIVER_load_driver
149  */
150 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name, HMODULE *module_ret )
151 {
152     HMODULE module;
153     struct graphics_driver *driver, *new_driver;
154     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
155     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
156
157     /* display driver is a special case */
158     if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W ))
159         return get_display_driver( module_ret );
160
161     if ((module = GetModuleHandleW( name )))
162     {
163         if (display_driver && display_driver->module == module)
164         {
165             *module_ret = module;
166             return display_driver->funcs;
167         }
168         EnterCriticalSection( &driver_section );
169         LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
170         {
171             if (driver->module == module) goto done;
172         }
173         LeaveCriticalSection( &driver_section );
174     }
175
176     if (!(module = LoadLibraryW( name ))) return NULL;
177
178     if (!(new_driver = create_driver( module )))
179     {
180         FreeLibrary( module );
181         return NULL;
182     }
183
184     /* check if someone else added it in the meantime */
185     EnterCriticalSection( &driver_section );
186     LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
187     {
188         if (driver->module != module) continue;
189         FreeLibrary( module );
190         HeapFree( GetProcessHeap(), 0, new_driver );
191         goto done;
192     }
193     driver = new_driver;
194     list_add_head( &drivers, &driver->entry );
195     TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
196 done:
197     *module_ret = driver->module;
198     LeaveCriticalSection( &driver_section );
199     return driver->funcs;
200 }
201
202
203 /***********************************************************************
204  *           __wine_get_driver_module    (GDI32.@)
205  */
206 HMODULE CDECL __wine_get_driver_module( HDC hdc )
207 {
208     DC *dc;
209     HMODULE ret = 0;
210
211     if ((dc = get_dc_ptr( hdc )))
212     {
213         ret = dc->module;
214         release_dc_ptr( dc );
215         if (!ret) SetLastError( display_driver_load_error );
216     }
217     else SetLastError( ERROR_INVALID_HANDLE );
218     return ret;
219 }
220
221
222 static INT nulldrv_AbortDoc( PHYSDEV dev )
223 {
224     return 0;
225 }
226
227 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
228                          INT xstart, INT ystart, INT xend, INT yend )
229 {
230     return TRUE;
231 }
232
233 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
234                            INT xstart, INT ystart, INT xend, INT yend )
235 {
236     return TRUE;
237 }
238
239 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
240 {
241     if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
242     return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
243 }
244
245 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
246                               LPCWSTR output, const DEVMODEW *devmode )
247 {
248     assert(0);  /* should never be called */
249     return FALSE;
250 }
251
252 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
253 {
254     assert(0);  /* should never be called */
255     return TRUE;
256 }
257
258 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
259 {
260     return TRUE;
261 }
262
263 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
264                                          WORD cap, LPSTR output, DEVMODEA *devmode )
265 {
266     return -1;
267 }
268
269 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
270 {
271     return TRUE;
272 }
273
274 static INT nulldrv_EndDoc( PHYSDEV dev )
275 {
276     return 0;
277 }
278
279 static INT nulldrv_EndPage( PHYSDEV dev )
280 {
281     return 0;
282 }
283
284 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
285 {
286     return TRUE;
287 }
288
289 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
290 {
291     return -1;
292 }
293
294 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
295                                   LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
296 {
297     return -1;
298 }
299
300 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
301                                     INT out_size, void *out_data )
302 {
303     return 0;
304 }
305
306 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
307 {
308     return TRUE;
309 }
310
311 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
312 {
313     return FALSE;
314 }
315
316 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
317 {
318     return FALSE;
319 }
320
321 static BOOL nulldrv_GdiRealizationInfo( PHYSDEV dev, void *info )
322 {
323     return FALSE;
324 }
325
326 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
327 {
328     return DCB_RESET;
329 }
330
331 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
332 {
333     return FALSE;
334 }
335
336 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
337 {
338     return FALSE;
339 }
340
341 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
342 {
343     return FALSE;
344 }
345
346 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
347 {
348     switch (cap)  /* return meaningful values for some entries */
349     {
350     case HORZRES:     return 640;
351     case VERTRES:     return 480;
352     case BITSPIXEL:   return 1;
353     case PLANES:      return 1;
354     case NUMCOLORS:   return 2;
355     case ASPECTX:     return 36;
356     case ASPECTY:     return 36;
357     case ASPECTXY:    return 51;
358     case LOGPIXELSX:  return 72;
359     case LOGPIXELSY:  return 72;
360     case SIZEPALETTE: return 2;
361     case TEXTCAPS:    return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
362                               TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
363                               TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
364     default:          return 0;
365     }
366 }
367
368 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
369 {
370     SetLastError( ERROR_INVALID_PARAMETER );
371     return FALSE;
372 }
373
374 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
375 {
376     return FALSE;
377 }
378
379 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
380 {
381     return 0;
382 }
383
384 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
385 {
386     return GDI_ERROR;
387 }
388
389 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
390                                       DWORD size, LPVOID buffer, const MAT2 *mat )
391 {
392     return GDI_ERROR;
393 }
394
395 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
396 {
397     return FALSE;
398 }
399
400 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
401                                struct bitblt_coords *src )
402 {
403     return ERROR_NOT_SUPPORTED;
404 }
405
406 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
407 {
408     return 0;
409 }
410
411 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
412 {
413     return 0;
414 }
415
416 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
417 {
418     return 0;
419 }
420
421 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
422 {
423     return DEFAULT_CHARSET;
424 }
425
426 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
427 {
428     return FALSE;
429 }
430
431 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
432 {
433     return FALSE;
434 }
435
436 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
437 {
438     INT ret = 0;
439     LOGFONTW font;
440     HFONT hfont = GetCurrentObject( dev->hdc, OBJ_FONT );
441
442     if (GetObjectW( hfont, sizeof(font), &font ))
443     {
444         ret = strlenW( font.lfFaceName ) + 1;
445         if (name)
446         {
447             lstrcpynW( name, font.lfFaceName, size );
448             ret = min( size, ret );
449         }
450     }
451     return ret;
452 }
453
454 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
455 {
456     return FALSE;
457 }
458
459 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
460 {
461     return TRUE;
462 }
463
464 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
465 {
466     return TRUE;
467 }
468
469 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
470 {
471     return TRUE;
472 }
473
474 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
475 {
476     return TRUE;
477 }
478
479 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
480                          INT xstart, INT ystart, INT xend, INT yend )
481 {
482     return TRUE;
483 }
484
485 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
486 {
487     return TRUE;
488 }
489
490 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
491 {
492     return TRUE;
493 }
494
495 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
496 {
497     INT counts[1] = { count };
498
499     return PolyPolygon( dev->hdc, points, counts, 1 );
500 }
501
502 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
503 {
504     DWORD counts[1] = { count };
505
506     if (count < 0) return FALSE;
507     return PolyPolyline( dev->hdc, points, counts, 1 );
508 }
509
510 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
511                                const struct gdi_image_bits *bits, struct bitblt_coords *src,
512                                struct bitblt_coords *dst, DWORD rop )
513 {
514     return ERROR_SUCCESS;
515 }
516
517 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
518 {
519     return 0;
520 }
521
522 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
523 {
524     return 0;
525 }
526
527 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
528 {
529     return TRUE;
530 }
531
532 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
533 {
534     return 0;
535 }
536
537 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
538                                INT ell_width, INT ell_height )
539 {
540     return TRUE;
541 }
542
543 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
544 {
545     return bitmap;
546 }
547
548 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
549 {
550     return brush;
551 }
552
553 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
554 {
555     return palette;
556 }
557
558 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
559 {
560     return pen;
561 }
562
563 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
564 {
565     return dir;
566 }
567
568 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
569 {
570     return color;
571 }
572
573 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
574 {
575     return mode;
576 }
577
578 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
579 {
580     return DCB_RESET;
581 }
582
583 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
584 {
585     return color;
586 }
587
588 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
589 {
590     return color;
591 }
592
593 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
594 {
595 }
596
597 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
598 {
599     return layout;
600 }
601
602 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
603 {
604     SetLastError( ERROR_INVALID_PARAMETER );
605     return FALSE;
606 }
607
608 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
609 {
610     return flags;
611 }
612
613 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
614 {
615     return color;
616 }
617
618 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
619 {
620     return mode;
621 }
622
623 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
624 {
625     return rop;
626 }
627
628 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
629 {
630     return mode;
631 }
632
633 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
634 {
635     return mode;
636 }
637
638 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
639 {
640     return align;
641 }
642
643 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
644 {
645     return extra;
646 }
647
648 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
649 {
650     return color;
651 }
652
653 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
654 {
655     return TRUE;
656 }
657
658 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
659 {
660     return 0;
661 }
662
663 static INT nulldrv_StartPage( PHYSDEV dev )
664 {
665     return 1;
666 }
667
668 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
669 {
670     return FALSE;
671 }
672
673 static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
674 {
675     return (void *)-1;
676 }
677
678 const struct gdi_dc_funcs null_driver =
679 {
680     nulldrv_AbortDoc,                   /* pAbortDoc */
681     nulldrv_AbortPath,                  /* pAbortPath */
682     nulldrv_AlphaBlend,                 /* pAlphaBlend */
683     nulldrv_AngleArc,                   /* pAngleArc */
684     nulldrv_Arc,                        /* pArc */
685     nulldrv_ArcTo,                      /* pArcTo */
686     nulldrv_BeginPath,                  /* pBeginPath */
687     nulldrv_BlendImage,                 /* pBlendImage */
688     nulldrv_Chord,                      /* pChord */
689     nulldrv_CloseFigure,                /* pCloseFigure */
690     nulldrv_CreateCompatibleDC,         /* pCreateCompatibleDC */
691     nulldrv_CreateDC,                   /* pCreateDC */
692     nulldrv_DeleteDC,                   /* pDeleteDC */
693     nulldrv_DeleteObject,               /* pDeleteObject */
694     nulldrv_DeviceCapabilities,         /* pDeviceCapabilities */
695     nulldrv_Ellipse,                    /* pEllipse */
696     nulldrv_EndDoc,                     /* pEndDoc */
697     nulldrv_EndPage,                    /* pEndPage */
698     nulldrv_EndPath,                    /* pEndPath */
699     nulldrv_EnumFonts,                  /* pEnumFonts */
700     nulldrv_EnumICMProfiles,            /* pEnumICMProfiles */
701     nulldrv_ExcludeClipRect,            /* pExcludeClipRect */
702     nulldrv_ExtDeviceMode,              /* pExtDeviceMode */
703     nulldrv_ExtEscape,                  /* pExtEscape */
704     nulldrv_ExtFloodFill,               /* pExtFloodFill */
705     nulldrv_ExtSelectClipRgn,           /* pExtSelectClipRgn */
706     nulldrv_ExtTextOut,                 /* pExtTextOut */
707     nulldrv_FillPath,                   /* pFillPath */
708     nulldrv_FillRgn,                    /* pFillRgn */
709     nulldrv_FlattenPath,                /* pFlattenPath */
710     nulldrv_FontIsLinked,               /* pFontIsLinked */
711     nulldrv_FrameRgn,                   /* pFrameRgn */
712     nulldrv_GdiComment,                 /* pGdiComment */
713     nulldrv_GdiRealizationInfo,         /* pGdiRealizationInfo */
714     nulldrv_GetBoundsRect,              /* pGetBoundsRect */
715     nulldrv_GetCharABCWidths,           /* pGetCharABCWidths */
716     nulldrv_GetCharABCWidthsI,          /* pGetCharABCWidthsI */
717     nulldrv_GetCharWidth,               /* pGetCharWidth */
718     nulldrv_GetDeviceCaps,              /* pGetDeviceCaps */
719     nulldrv_GetDeviceGammaRamp,         /* pGetDeviceGammaRamp */
720     nulldrv_GetFontData,                /* pGetFontData */
721     nulldrv_GetFontUnicodeRanges,       /* pGetFontUnicodeRanges */
722     nulldrv_GetGlyphIndices,            /* pGetGlyphIndices */
723     nulldrv_GetGlyphOutline,            /* pGetGlyphOutline */
724     nulldrv_GetICMProfile,              /* pGetICMProfile */
725     nulldrv_GetImage,                   /* pGetImage */
726     nulldrv_GetKerningPairs,            /* pGetKerningPairs */
727     nulldrv_GetNearestColor,            /* pGetNearestColor */
728     nulldrv_GetOutlineTextMetrics,      /* pGetOutlineTextMetrics */
729     nulldrv_GetPixel,                   /* pGetPixel */
730     nulldrv_GetSystemPaletteEntries,    /* pGetSystemPaletteEntries */
731     nulldrv_GetTextCharsetInfo,         /* pGetTextCharsetInfo */
732     nulldrv_GetTextExtentExPoint,       /* pGetTextExtentExPoint */
733     nulldrv_GetTextExtentExPointI,      /* pGetTextExtentExPointI */
734     nulldrv_GetTextFace,                /* pGetTextFace */
735     nulldrv_GetTextMetrics,             /* pGetTextMetrics */
736     nulldrv_GradientFill,               /* pGradientFill */
737     nulldrv_IntersectClipRect,          /* pIntersectClipRect */
738     nulldrv_InvertRgn,                  /* pInvertRgn */
739     nulldrv_LineTo,                     /* pLineTo */
740     nulldrv_ModifyWorldTransform,       /* pModifyWorldTransform */
741     nulldrv_MoveTo,                     /* pMoveTo */
742     nulldrv_OffsetClipRgn,              /* pOffsetClipRgn */
743     nulldrv_OffsetViewportOrgEx,        /* pOffsetViewportOrg */
744     nulldrv_OffsetWindowOrgEx,          /* pOffsetWindowOrg */
745     nulldrv_PaintRgn,                   /* pPaintRgn */
746     nulldrv_PatBlt,                     /* pPatBlt */
747     nulldrv_Pie,                        /* pPie */
748     nulldrv_PolyBezier,                 /* pPolyBezier */
749     nulldrv_PolyBezierTo,               /* pPolyBezierTo */
750     nulldrv_PolyDraw,                   /* pPolyDraw */
751     nulldrv_PolyPolygon,                /* pPolyPolygon */
752     nulldrv_PolyPolyline,               /* pPolyPolyline */
753     nulldrv_Polygon,                    /* pPolygon */
754     nulldrv_Polyline,                   /* pPolyline */
755     nulldrv_PolylineTo,                 /* pPolylineTo */
756     nulldrv_PutImage,                   /* pPutImage */
757     nulldrv_RealizeDefaultPalette,      /* pRealizeDefaultPalette */
758     nulldrv_RealizePalette,             /* pRealizePalette */
759     nulldrv_Rectangle,                  /* pRectangle */
760     nulldrv_ResetDC,                    /* pResetDC */
761     nulldrv_RestoreDC,                  /* pRestoreDC */
762     nulldrv_RoundRect,                  /* pRoundRect */
763     nulldrv_SaveDC,                     /* pSaveDC */
764     nulldrv_ScaleViewportExtEx,         /* pScaleViewportExt */
765     nulldrv_ScaleWindowExtEx,           /* pScaleWindowExt */
766     nulldrv_SelectBitmap,               /* pSelectBitmap */
767     nulldrv_SelectBrush,                /* pSelectBrush */
768     nulldrv_SelectClipPath,             /* pSelectClipPath */
769     nulldrv_SelectFont,                 /* pSelectFont */
770     nulldrv_SelectPalette,              /* pSelectPalette */
771     nulldrv_SelectPen,                  /* pSelectPen */
772     nulldrv_SetArcDirection,            /* pSetArcDirection */
773     nulldrv_SetBkColor,                 /* pSetBkColor */
774     nulldrv_SetBkMode,                  /* pSetBkMode */
775     nulldrv_SetBoundsRect,              /* pSetBoundsRect */
776     nulldrv_SetDCBrushColor,            /* pSetDCBrushColor */
777     nulldrv_SetDCPenColor,              /* pSetDCPenColor */
778     nulldrv_SetDIBitsToDevice,          /* pSetDIBitsToDevice */
779     nulldrv_SetDeviceClipping,          /* pSetDeviceClipping */
780     nulldrv_SetDeviceGammaRamp,         /* pSetDeviceGammaRamp */
781     nulldrv_SetLayout,                  /* pSetLayout */
782     nulldrv_SetMapMode,                 /* pSetMapMode */
783     nulldrv_SetMapperFlags,             /* pSetMapperFlags */
784     nulldrv_SetPixel,                   /* pSetPixel */
785     nulldrv_SetPolyFillMode,            /* pSetPolyFillMode */
786     nulldrv_SetROP2,                    /* pSetROP2 */
787     nulldrv_SetRelAbs,                  /* pSetRelAbs */
788     nulldrv_SetStretchBltMode,          /* pSetStretchBltMode */
789     nulldrv_SetTextAlign,               /* pSetTextAlign */
790     nulldrv_SetTextCharacterExtra,      /* pSetTextCharacterExtra */
791     nulldrv_SetTextColor,               /* pSetTextColor */
792     nulldrv_SetTextJustification,       /* pSetTextJustification */
793     nulldrv_SetViewportExtEx,           /* pSetViewportExt */
794     nulldrv_SetViewportOrgEx,           /* pSetViewportOrg */
795     nulldrv_SetWindowExtEx,             /* pSetWindowExt */
796     nulldrv_SetWindowOrgEx,             /* pSetWindowOrg */
797     nulldrv_SetWorldTransform,          /* pSetWorldTransform */
798     nulldrv_StartDoc,                   /* pStartDoc */
799     nulldrv_StartPage,                  /* pStartPage */
800     nulldrv_StretchBlt,                 /* pStretchBlt */
801     nulldrv_StretchDIBits,              /* pStretchDIBits */
802     nulldrv_StrokeAndFillPath,          /* pStrokeAndFillPath */
803     nulldrv_StrokePath,                 /* pStrokePath */
804     nulldrv_UnrealizePalette,           /* pUnrealizePalette */
805     nulldrv_WidenPath,                  /* pWidenPath */
806     nulldrv_wine_get_wgl_driver,        /* wine_get_wgl_driver */
807
808     GDI_PRIORITY_NULL_DRV               /* priority */
809 };
810
811
812 /*****************************************************************************
813  *      DRIVER_GetDriverName
814  *
815  */
816 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
817 {
818     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
819     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
820     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
821     static const WCHAR empty_strW[] = { 0 };
822     WCHAR *p;
823
824     /* display is a special case */
825     if (!strcmpiW( device, displayW ) ||
826         !strcmpiW( device, display1W ))
827     {
828         lstrcpynW( driver, displayW, size );
829         return TRUE;
830     }
831
832     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
833     if(!size) {
834         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
835         return FALSE;
836     }
837     p = strchrW(driver, ',');
838     if(!p)
839     {
840         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
841         return FALSE;
842     }
843     *p = 0;
844     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
845     return TRUE;
846 }
847
848
849 /***********************************************************************
850  *           GdiConvertToDevmodeW    (GDI32.@)
851  */
852 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
853 {
854     DEVMODEW *dmW;
855     WORD dmW_size, dmA_size;
856
857     dmA_size = dmA->dmSize;
858
859     /* this is the minimal dmSize that XP accepts */
860     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
861         return NULL;
862
863     if (dmA_size > sizeof(DEVMODEA))
864         dmA_size = sizeof(DEVMODEA);
865
866     dmW_size = dmA_size + CCHDEVICENAME;
867     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
868         dmW_size += CCHFORMNAME;
869
870     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
871     if (!dmW) return NULL;
872
873     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
874                                    dmW->dmDeviceName, CCHDEVICENAME);
875     /* copy slightly more, to avoid long computations */
876     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
877
878     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
879     {
880         if (dmA->dmFields & DM_FORMNAME)
881             MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
882                                        dmW->dmFormName, CCHFORMNAME);
883         else
884             dmW->dmFormName[0] = 0;
885
886         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
887             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
888     }
889
890     if (dmA->dmDriverExtra)
891         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
892
893     dmW->dmSize = dmW_size;
894
895     return dmW;
896 }
897
898
899 /*****************************************************************************
900  *      @ [GDI32.100]
901  *
902  * This should thunk to 16-bit and simply call the proc with the given args.
903  */
904 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
905                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
906 {
907     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
908     return -1;
909 }
910
911 /*****************************************************************************
912  *      @ [GDI32.101]
913  *
914  * This should load the correct driver for lpszDevice and calls this driver's
915  * ExtDeviceModePropSheet proc.
916  *
917  * Note: The driver calls a callback routine for each property sheet page; these
918  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
919  * The layout of this structure is:
920  *
921  * struct
922  * {
923  *   DWORD  nPages;
924  *   DWORD  unknown;
925  *   HPROPSHEETPAGE  pages[10];
926  * };
927  */
928 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
929                                              LPCSTR lpszPort, LPVOID lpPropSheet )
930 {
931     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
932     return -1;
933 }
934
935 /*****************************************************************************
936  *      @ [GDI32.102]
937  *
938  * This should load the correct driver for lpszDevice and call this driver's
939  * ExtDeviceMode proc.
940  *
941  * FIXME: convert ExtDeviceMode to unicode in the driver interface
942  */
943 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
944                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
945                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
946                                     LPSTR lpszProfile, DWORD fwMode )
947 {
948     WCHAR deviceW[300];
949     WCHAR bufW[300];
950     char buf[300];
951     HDC hdc;
952     DC *dc;
953     INT ret = -1;
954
955     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
956           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
957
958     if (!lpszDevice) return -1;
959     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
960
961     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
962
963     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
964
965     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
966
967     if ((dc = get_dc_ptr( hdc )))
968     {
969         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
970         ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
971                                               lpdmInput, lpszProfile, fwMode );
972         release_dc_ptr( dc );
973     }
974     DeleteDC( hdc );
975     return ret;
976 }
977
978 /****************************************************************************
979  *      @ [GDI32.103]
980  *
981  * This should load the correct driver for lpszDevice and calls this driver's
982  * AdvancedSetupDialog proc.
983  */
984 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
985                                           LPDEVMODEA devin, LPDEVMODEA devout )
986 {
987     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
988     return -1;
989 }
990
991 /*****************************************************************************
992  *      @ [GDI32.104]
993  *
994  * This should load the correct driver for lpszDevice and calls this driver's
995  * DeviceCapabilities proc.
996  *
997  * FIXME: convert DeviceCapabilities to unicode in the driver interface
998  */
999 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1000                                            WORD fwCapability, LPSTR lpszOutput,
1001                                            LPDEVMODEA lpdm )
1002 {
1003     WCHAR deviceW[300];
1004     WCHAR bufW[300];
1005     char buf[300];
1006     HDC hdc;
1007     DC *dc;
1008     INT ret = -1;
1009
1010     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1011
1012     if (!lpszDevice) return -1;
1013     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1014
1015     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1016
1017     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1018
1019     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1020
1021     if ((dc = get_dc_ptr( hdc )))
1022     {
1023         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1024         ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1025                                                    fwCapability, lpszOutput, lpdm );
1026         release_dc_ptr( dc );
1027     }
1028     DeleteDC( hdc );
1029     return ret;
1030 }
1031
1032
1033 /************************************************************************
1034  *             Escape  [GDI32.@]
1035  */
1036 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1037 {
1038     INT ret;
1039     POINT *pt;
1040
1041     switch (escape)
1042     {
1043     case ABORTDOC:
1044         return AbortDoc( hdc );
1045
1046     case ENDDOC:
1047         return EndDoc( hdc );
1048
1049     case GETPHYSPAGESIZE:
1050         pt = out_data;
1051         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1052         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1053         return 1;
1054
1055     case GETPRINTINGOFFSET:
1056         pt = out_data;
1057         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1058         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1059         return 1;
1060
1061     case GETSCALINGFACTOR:
1062         pt = out_data;
1063         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1064         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1065         return 1;
1066
1067     case NEWFRAME:
1068         return EndPage( hdc );
1069
1070     case SETABORTPROC:
1071         return SetAbortProc( hdc, (ABORTPROC)in_data );
1072
1073     case STARTDOC:
1074         {
1075             DOCINFOA doc;
1076             char *name = NULL;
1077
1078             /* in_data may not be 0 terminated so we must copy it */
1079             if (in_data)
1080             {
1081                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1082                 memcpy( name, in_data, in_count );
1083                 name[in_count] = 0;
1084             }
1085             /* out_data is actually a pointer to the DocInfo structure and used as
1086              * a second input parameter */
1087             if (out_data) doc = *(DOCINFOA *)out_data;
1088             else
1089             {
1090                 doc.cbSize = sizeof(doc);
1091                 doc.lpszOutput = NULL;
1092                 doc.lpszDatatype = NULL;
1093                 doc.fwType = 0;
1094             }
1095             doc.lpszDocName = name;
1096             ret = StartDocA( hdc, &doc );
1097             HeapFree( GetProcessHeap(), 0, name );
1098             if (ret > 0) ret = StartPage( hdc );
1099             return ret;
1100         }
1101
1102     case QUERYESCSUPPORT:
1103         {
1104             const INT *ptr = (const INT *)in_data;
1105             if (in_count < sizeof(INT)) return 0;
1106             switch(*ptr)
1107             {
1108             case ABORTDOC:
1109             case ENDDOC:
1110             case GETPHYSPAGESIZE:
1111             case GETPRINTINGOFFSET:
1112             case GETSCALINGFACTOR:
1113             case NEWFRAME:
1114             case QUERYESCSUPPORT:
1115             case SETABORTPROC:
1116             case STARTDOC:
1117                 return TRUE;
1118             }
1119             break;
1120         }
1121     }
1122
1123     /* if not handled internally, pass it to the driver */
1124     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1125 }
1126
1127
1128 /******************************************************************************
1129  *              ExtEscape       [GDI32.@]
1130  *
1131  * Access capabilities of a particular device that are not available through GDI.
1132  *
1133  * PARAMS
1134  *    hdc         [I] Handle to device context
1135  *    nEscape     [I] Escape function
1136  *    cbInput     [I] Number of bytes in input structure
1137  *    lpszInData  [I] Pointer to input structure
1138  *    cbOutput    [I] Number of bytes in output structure
1139  *    lpszOutData [O] Pointer to output structure
1140  *
1141  * RETURNS
1142  *    Success: >0
1143  *    Not implemented: 0
1144  *    Failure: <0
1145  */
1146 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1147                       INT cbOutput, LPSTR lpszOutData )
1148 {
1149     PHYSDEV physdev;
1150     INT ret;
1151     DC * dc = get_dc_ptr( hdc );
1152
1153     if (!dc) return 0;
1154     update_dc( dc );
1155     physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1156     ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1157     release_dc_ptr( dc );
1158     return ret;
1159 }
1160
1161
1162 /*******************************************************************
1163  *      DrawEscape [GDI32.@]
1164  *
1165  *
1166  */
1167 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1168 {
1169     FIXME("DrawEscape, stub\n");
1170     return 0;
1171 }
1172
1173 /*******************************************************************
1174  *      NamedEscape [GDI32.@]
1175  */
1176 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1177                         INT cbOutput, LPSTR lpszOutData )
1178 {
1179     FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1180           hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1181           lpszOutData);
1182     return 0;
1183 }
1184
1185 /*******************************************************************
1186  *      DdQueryDisplaySettingsUniqueness [GDI32.@]
1187  *      GdiEntry13                       [GDI32.@]
1188  */
1189 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1190 {
1191     static int warn_once;
1192
1193     if (!warn_once++)
1194         FIXME("stub\n");
1195     return 0;
1196 }