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