vbscript: Implemented Sgn.
[wine/multimedia.git] / dlls / gdi32 / driver.c
blob4529562a9e261be0f4be4350cceef7b0c01bbfc0
1 /*
2 * Graphics driver management functions
4 * Copyright 1994 Bob Amstadt
5 * Copyright 1996, 2001 Alexandre Julliard
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.
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.
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
22 #include "config.h"
23 #include "wine/port.h"
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 "ddrawgdi.h"
32 #include "wine/winbase16.h"
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/list.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(driver);
41 struct graphics_driver
43 struct list entry;
44 HMODULE module; /* module handle */
45 const struct gdi_dc_funcs *funcs;
48 static struct list drivers = LIST_INIT( drivers );
49 static struct graphics_driver *display_driver;
51 const struct gdi_dc_funcs *font_driver = NULL;
53 static CRITICAL_SECTION driver_section;
54 static CRITICAL_SECTION_DEBUG critsect_debug =
56 0, 0, &driver_section,
57 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
58 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
60 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
62 /**********************************************************************
63 * create_driver
65 * Allocate and fill the driver structure for a given module.
67 static struct graphics_driver *create_driver( HMODULE module )
69 static const struct gdi_dc_funcs empty_funcs;
70 const struct gdi_dc_funcs *funcs = NULL;
71 struct graphics_driver *driver;
73 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
74 driver->module = module;
76 if (module)
78 const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
80 if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
81 funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
83 if (!funcs) funcs = &empty_funcs;
84 driver->funcs = funcs;
85 return driver;
89 /**********************************************************************
90 * get_display_driver
92 * Special case for loading the display driver: get the name from the config file
94 static const struct gdi_dc_funcs *get_display_driver(void)
96 if (!display_driver)
98 HMODULE user32 = LoadLibraryA( "user32.dll" );
99 HWND (WINAPI *pGetDesktopWindow)(void) = (void *)GetProcAddress( user32, "GetDesktopWindow" );
101 if (!pGetDesktopWindow() || !display_driver)
103 WARN( "failed to load the display driver, falling back to null driver\n" );
104 __wine_set_display_driver( 0 );
107 return display_driver->funcs;
111 /**********************************************************************
112 * DRIVER_load_driver
114 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
116 HMODULE module;
117 struct graphics_driver *driver, *new_driver;
118 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
119 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
121 /* display driver is a special case */
122 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return get_display_driver();
124 if ((module = GetModuleHandleW( name )))
126 if (display_driver && display_driver->module == module) return display_driver->funcs;
128 EnterCriticalSection( &driver_section );
129 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
131 if (driver->module == module) goto done;
133 LeaveCriticalSection( &driver_section );
136 if (!(module = LoadLibraryW( name ))) return NULL;
138 if (!(new_driver = create_driver( module )))
140 FreeLibrary( module );
141 return NULL;
144 /* check if someone else added it in the meantime */
145 EnterCriticalSection( &driver_section );
146 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
148 if (driver->module != module) continue;
149 FreeLibrary( module );
150 HeapFree( GetProcessHeap(), 0, new_driver );
151 goto done;
153 driver = new_driver;
154 list_add_head( &drivers, &driver->entry );
155 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
156 done:
157 LeaveCriticalSection( &driver_section );
158 return driver->funcs;
162 /***********************************************************************
163 * __wine_set_display_driver (GDI32.@)
165 void CDECL __wine_set_display_driver( HMODULE module )
167 struct graphics_driver *driver;
169 if (!(driver = create_driver( module )))
171 ERR( "Could not create graphics driver\n" );
172 ExitProcess(1);
174 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
175 HeapFree( GetProcessHeap(), 0, driver );
179 static INT nulldrv_AbortDoc( PHYSDEV dev )
181 return 0;
184 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
185 INT xstart, INT ystart, INT xend, INT yend )
187 return TRUE;
190 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
191 INT xstart, INT ystart, INT xend, INT yend )
193 return TRUE;
196 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
198 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
199 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
202 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
203 LPCWSTR output, const DEVMODEW *devmode )
205 assert(0); /* should never be called */
206 return FALSE;
209 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
211 assert(0); /* should never be called */
212 return TRUE;
215 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
217 return TRUE;
220 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
221 WORD cap, LPSTR output, DEVMODEA *devmode )
223 return -1;
226 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
228 return TRUE;
231 static INT nulldrv_EndDoc( PHYSDEV dev )
233 return 0;
236 static INT nulldrv_EndPage( PHYSDEV dev )
238 return 0;
241 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
243 return TRUE;
246 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
248 return -1;
251 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
252 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
254 return -1;
257 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
258 INT out_size, void *out_data )
260 return 0;
263 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
265 return TRUE;
268 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
270 return FALSE;
273 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
275 return FALSE;
278 static BOOL nulldrv_GdiRealizationInfo( PHYSDEV dev, void *info )
280 return FALSE;
283 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
285 return DCB_RESET;
288 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
290 return FALSE;
293 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
295 return FALSE;
298 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
300 return FALSE;
303 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
305 switch (cap) /* return meaningful values for some entries */
307 case HORZRES: return 640;
308 case VERTRES: return 480;
309 case BITSPIXEL: return 1;
310 case PLANES: return 1;
311 case NUMCOLORS: return 2;
312 case ASPECTX: return 36;
313 case ASPECTY: return 36;
314 case ASPECTXY: return 51;
315 case LOGPIXELSX: return 72;
316 case LOGPIXELSY: return 72;
317 case SIZEPALETTE: return 2;
318 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
319 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
320 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
321 default: return 0;
325 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
327 SetLastError( ERROR_INVALID_PARAMETER );
328 return FALSE;
331 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
333 return FALSE;
336 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
338 return 0;
341 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
343 return GDI_ERROR;
346 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
347 DWORD size, LPVOID buffer, const MAT2 *mat )
349 return GDI_ERROR;
352 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
354 return FALSE;
357 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
358 struct bitblt_coords *src )
360 return ERROR_NOT_SUPPORTED;
363 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
365 return 0;
368 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
370 return 0;
373 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
375 return 0;
378 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
380 return DEFAULT_CHARSET;
383 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
385 return FALSE;
388 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
390 return FALSE;
393 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
395 INT ret = 0;
396 LOGFONTW font;
397 HFONT hfont = GetCurrentObject( dev->hdc, OBJ_FONT );
399 if (GetObjectW( hfont, sizeof(font), &font ))
401 ret = strlenW( font.lfFaceName ) + 1;
402 if (name)
404 lstrcpynW( name, font.lfFaceName, size );
405 ret = min( size, ret );
408 return ret;
411 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
413 return FALSE;
416 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
418 return TRUE;
421 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
423 return TRUE;
426 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
428 return TRUE;
431 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
433 return TRUE;
436 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
437 INT xstart, INT ystart, INT xend, INT yend )
439 return TRUE;
442 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
444 return TRUE;
447 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
449 return TRUE;
452 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
454 INT counts[1] = { count };
456 return PolyPolygon( dev->hdc, points, counts, 1 );
459 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
461 DWORD counts[1] = { count };
463 if (count < 0) return FALSE;
464 return PolyPolyline( dev->hdc, points, counts, 1 );
467 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
468 const struct gdi_image_bits *bits, struct bitblt_coords *src,
469 struct bitblt_coords *dst, DWORD rop )
471 return ERROR_SUCCESS;
474 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
476 return 0;
479 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
481 return 0;
484 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
486 return TRUE;
489 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
491 return 0;
494 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
495 INT ell_width, INT ell_height )
497 return TRUE;
500 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
502 return bitmap;
505 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
507 return brush;
510 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
512 return palette;
515 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
517 return pen;
520 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
522 return dir;
525 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
527 return color;
530 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
532 return mode;
535 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
537 return DCB_RESET;
540 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
542 return color;
545 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
547 return color;
550 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
554 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
556 return layout;
559 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
561 SetLastError( ERROR_INVALID_PARAMETER );
562 return FALSE;
565 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
567 return flags;
570 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
572 return color;
575 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
577 return mode;
580 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
582 return rop;
585 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
587 return mode;
590 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
592 return mode;
595 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
597 return align;
600 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
602 return extra;
605 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
607 return color;
610 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
612 return TRUE;
615 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
617 return 0;
620 static INT nulldrv_StartPage( PHYSDEV dev )
622 return 1;
625 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
627 return FALSE;
630 static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
632 return (void *)-1;
635 const struct gdi_dc_funcs null_driver =
637 nulldrv_AbortDoc, /* pAbortDoc */
638 nulldrv_AbortPath, /* pAbortPath */
639 nulldrv_AlphaBlend, /* pAlphaBlend */
640 nulldrv_AngleArc, /* pAngleArc */
641 nulldrv_Arc, /* pArc */
642 nulldrv_ArcTo, /* pArcTo */
643 nulldrv_BeginPath, /* pBeginPath */
644 nulldrv_BlendImage, /* pBlendImage */
645 nulldrv_Chord, /* pChord */
646 nulldrv_CloseFigure, /* pCloseFigure */
647 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
648 nulldrv_CreateDC, /* pCreateDC */
649 nulldrv_DeleteDC, /* pDeleteDC */
650 nulldrv_DeleteObject, /* pDeleteObject */
651 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
652 nulldrv_Ellipse, /* pEllipse */
653 nulldrv_EndDoc, /* pEndDoc */
654 nulldrv_EndPage, /* pEndPage */
655 nulldrv_EndPath, /* pEndPath */
656 nulldrv_EnumFonts, /* pEnumFonts */
657 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
658 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
659 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
660 nulldrv_ExtEscape, /* pExtEscape */
661 nulldrv_ExtFloodFill, /* pExtFloodFill */
662 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
663 nulldrv_ExtTextOut, /* pExtTextOut */
664 nulldrv_FillPath, /* pFillPath */
665 nulldrv_FillRgn, /* pFillRgn */
666 nulldrv_FlattenPath, /* pFlattenPath */
667 nulldrv_FontIsLinked, /* pFontIsLinked */
668 nulldrv_FrameRgn, /* pFrameRgn */
669 nulldrv_GdiComment, /* pGdiComment */
670 nulldrv_GdiRealizationInfo, /* pGdiRealizationInfo */
671 nulldrv_GetBoundsRect, /* pGetBoundsRect */
672 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
673 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
674 nulldrv_GetCharWidth, /* pGetCharWidth */
675 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
676 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
677 nulldrv_GetFontData, /* pGetFontData */
678 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
679 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
680 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
681 nulldrv_GetICMProfile, /* pGetICMProfile */
682 nulldrv_GetImage, /* pGetImage */
683 nulldrv_GetKerningPairs, /* pGetKerningPairs */
684 nulldrv_GetNearestColor, /* pGetNearestColor */
685 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
686 nulldrv_GetPixel, /* pGetPixel */
687 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
688 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
689 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
690 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
691 nulldrv_GetTextFace, /* pGetTextFace */
692 nulldrv_GetTextMetrics, /* pGetTextMetrics */
693 nulldrv_GradientFill, /* pGradientFill */
694 nulldrv_IntersectClipRect, /* pIntersectClipRect */
695 nulldrv_InvertRgn, /* pInvertRgn */
696 nulldrv_LineTo, /* pLineTo */
697 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
698 nulldrv_MoveTo, /* pMoveTo */
699 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
700 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
701 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
702 nulldrv_PaintRgn, /* pPaintRgn */
703 nulldrv_PatBlt, /* pPatBlt */
704 nulldrv_Pie, /* pPie */
705 nulldrv_PolyBezier, /* pPolyBezier */
706 nulldrv_PolyBezierTo, /* pPolyBezierTo */
707 nulldrv_PolyDraw, /* pPolyDraw */
708 nulldrv_PolyPolygon, /* pPolyPolygon */
709 nulldrv_PolyPolyline, /* pPolyPolyline */
710 nulldrv_Polygon, /* pPolygon */
711 nulldrv_Polyline, /* pPolyline */
712 nulldrv_PolylineTo, /* pPolylineTo */
713 nulldrv_PutImage, /* pPutImage */
714 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
715 nulldrv_RealizePalette, /* pRealizePalette */
716 nulldrv_Rectangle, /* pRectangle */
717 nulldrv_ResetDC, /* pResetDC */
718 nulldrv_RestoreDC, /* pRestoreDC */
719 nulldrv_RoundRect, /* pRoundRect */
720 nulldrv_SaveDC, /* pSaveDC */
721 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
722 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
723 nulldrv_SelectBitmap, /* pSelectBitmap */
724 nulldrv_SelectBrush, /* pSelectBrush */
725 nulldrv_SelectClipPath, /* pSelectClipPath */
726 nulldrv_SelectFont, /* pSelectFont */
727 nulldrv_SelectPalette, /* pSelectPalette */
728 nulldrv_SelectPen, /* pSelectPen */
729 nulldrv_SetArcDirection, /* pSetArcDirection */
730 nulldrv_SetBkColor, /* pSetBkColor */
731 nulldrv_SetBkMode, /* pSetBkMode */
732 nulldrv_SetBoundsRect, /* pSetBoundsRect */
733 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
734 nulldrv_SetDCPenColor, /* pSetDCPenColor */
735 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
736 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
737 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
738 nulldrv_SetLayout, /* pSetLayout */
739 nulldrv_SetMapMode, /* pSetMapMode */
740 nulldrv_SetMapperFlags, /* pSetMapperFlags */
741 nulldrv_SetPixel, /* pSetPixel */
742 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
743 nulldrv_SetROP2, /* pSetROP2 */
744 nulldrv_SetRelAbs, /* pSetRelAbs */
745 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
746 nulldrv_SetTextAlign, /* pSetTextAlign */
747 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
748 nulldrv_SetTextColor, /* pSetTextColor */
749 nulldrv_SetTextJustification, /* pSetTextJustification */
750 nulldrv_SetViewportExtEx, /* pSetViewportExt */
751 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
752 nulldrv_SetWindowExtEx, /* pSetWindowExt */
753 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
754 nulldrv_SetWorldTransform, /* pSetWorldTransform */
755 nulldrv_StartDoc, /* pStartDoc */
756 nulldrv_StartPage, /* pStartPage */
757 nulldrv_StretchBlt, /* pStretchBlt */
758 nulldrv_StretchDIBits, /* pStretchDIBits */
759 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
760 nulldrv_StrokePath, /* pStrokePath */
761 nulldrv_UnrealizePalette, /* pUnrealizePalette */
762 nulldrv_WidenPath, /* pWidenPath */
763 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
765 GDI_PRIORITY_NULL_DRV /* priority */
769 /*****************************************************************************
770 * DRIVER_GetDriverName
773 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
775 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
776 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
777 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
778 static const WCHAR empty_strW[] = { 0 };
779 WCHAR *p;
781 /* display is a special case */
782 if (!strcmpiW( device, displayW ) ||
783 !strcmpiW( device, display1W ))
785 lstrcpynW( driver, displayW, size );
786 return TRUE;
789 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
790 if(!size) {
791 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
792 return FALSE;
794 p = strchrW(driver, ',');
795 if(!p)
797 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
798 return FALSE;
800 *p = 0;
801 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
802 return TRUE;
806 /***********************************************************************
807 * GdiConvertToDevmodeW (GDI32.@)
809 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
811 DEVMODEW *dmW;
812 WORD dmW_size, dmA_size;
814 dmA_size = dmA->dmSize;
816 /* this is the minimal dmSize that XP accepts */
817 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
818 return NULL;
820 if (dmA_size > sizeof(DEVMODEA))
821 dmA_size = sizeof(DEVMODEA);
823 dmW_size = dmA_size + CCHDEVICENAME;
824 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
825 dmW_size += CCHFORMNAME;
827 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
828 if (!dmW) return NULL;
830 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
831 dmW->dmDeviceName, CCHDEVICENAME);
832 /* copy slightly more, to avoid long computations */
833 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
835 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
837 if (dmA->dmFields & DM_FORMNAME)
838 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
839 dmW->dmFormName, CCHFORMNAME);
840 else
841 dmW->dmFormName[0] = 0;
843 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
844 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
847 if (dmA->dmDriverExtra)
848 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
850 dmW->dmSize = dmW_size;
852 return dmW;
856 /*****************************************************************************
857 * @ [GDI32.100]
859 * This should thunk to 16-bit and simply call the proc with the given args.
861 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
862 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
864 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
865 return -1;
868 /*****************************************************************************
869 * @ [GDI32.101]
871 * This should load the correct driver for lpszDevice and calls this driver's
872 * ExtDeviceModePropSheet proc.
874 * Note: The driver calls a callback routine for each property sheet page; these
875 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
876 * The layout of this structure is:
878 * struct
880 * DWORD nPages;
881 * DWORD unknown;
882 * HPROPSHEETPAGE pages[10];
883 * };
885 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
886 LPCSTR lpszPort, LPVOID lpPropSheet )
888 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
889 return -1;
892 /*****************************************************************************
893 * @ [GDI32.102]
895 * This should load the correct driver for lpszDevice and call this driver's
896 * ExtDeviceMode proc.
898 * FIXME: convert ExtDeviceMode to unicode in the driver interface
900 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
901 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
902 LPSTR lpszPort, LPDEVMODEA lpdmInput,
903 LPSTR lpszProfile, DWORD fwMode )
905 WCHAR deviceW[300];
906 WCHAR bufW[300];
907 char buf[300];
908 HDC hdc;
909 DC *dc;
910 INT ret = -1;
912 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
913 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
915 if (!lpszDevice) return -1;
916 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
918 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
920 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
922 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
924 if ((dc = get_dc_ptr( hdc )))
926 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
927 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
928 lpdmInput, lpszProfile, fwMode );
929 release_dc_ptr( dc );
931 DeleteDC( hdc );
932 return ret;
935 /****************************************************************************
936 * @ [GDI32.103]
938 * This should load the correct driver for lpszDevice and calls this driver's
939 * AdvancedSetupDialog proc.
941 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
942 LPDEVMODEA devin, LPDEVMODEA devout )
944 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
945 return -1;
948 /*****************************************************************************
949 * @ [GDI32.104]
951 * This should load the correct driver for lpszDevice and calls this driver's
952 * DeviceCapabilities proc.
954 * FIXME: convert DeviceCapabilities to unicode in the driver interface
956 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
957 WORD fwCapability, LPSTR lpszOutput,
958 LPDEVMODEA lpdm )
960 WCHAR deviceW[300];
961 WCHAR bufW[300];
962 char buf[300];
963 HDC hdc;
964 DC *dc;
965 INT ret = -1;
967 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
969 if (!lpszDevice) return -1;
970 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
972 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
974 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
976 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
978 if ((dc = get_dc_ptr( hdc )))
980 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
981 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
982 fwCapability, lpszOutput, lpdm );
983 release_dc_ptr( dc );
985 DeleteDC( hdc );
986 return ret;
990 /************************************************************************
991 * Escape [GDI32.@]
993 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
995 INT ret;
996 POINT *pt;
998 switch (escape)
1000 case ABORTDOC:
1001 return AbortDoc( hdc );
1003 case ENDDOC:
1004 return EndDoc( hdc );
1006 case GETPHYSPAGESIZE:
1007 pt = out_data;
1008 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1009 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1010 return 1;
1012 case GETPRINTINGOFFSET:
1013 pt = out_data;
1014 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1015 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1016 return 1;
1018 case GETSCALINGFACTOR:
1019 pt = out_data;
1020 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1021 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1022 return 1;
1024 case NEWFRAME:
1025 return EndPage( hdc );
1027 case SETABORTPROC:
1028 return SetAbortProc( hdc, (ABORTPROC)in_data );
1030 case STARTDOC:
1032 DOCINFOA doc;
1033 char *name = NULL;
1035 /* in_data may not be 0 terminated so we must copy it */
1036 if (in_data)
1038 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1039 memcpy( name, in_data, in_count );
1040 name[in_count] = 0;
1042 /* out_data is actually a pointer to the DocInfo structure and used as
1043 * a second input parameter */
1044 if (out_data) doc = *(DOCINFOA *)out_data;
1045 else
1047 doc.cbSize = sizeof(doc);
1048 doc.lpszOutput = NULL;
1049 doc.lpszDatatype = NULL;
1050 doc.fwType = 0;
1052 doc.lpszDocName = name;
1053 ret = StartDocA( hdc, &doc );
1054 HeapFree( GetProcessHeap(), 0, name );
1055 if (ret > 0) ret = StartPage( hdc );
1056 return ret;
1059 case QUERYESCSUPPORT:
1061 DWORD code;
1063 if (in_count < sizeof(SHORT)) return 0;
1064 code = (in_count < sizeof(DWORD)) ? *(const USHORT *)in_data : *(const DWORD *)in_data;
1065 switch (code)
1067 case ABORTDOC:
1068 case ENDDOC:
1069 case GETPHYSPAGESIZE:
1070 case GETPRINTINGOFFSET:
1071 case GETSCALINGFACTOR:
1072 case NEWFRAME:
1073 case QUERYESCSUPPORT:
1074 case SETABORTPROC:
1075 case STARTDOC:
1076 return TRUE;
1078 break;
1082 /* if not handled internally, pass it to the driver */
1083 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1087 /******************************************************************************
1088 * ExtEscape [GDI32.@]
1090 * Access capabilities of a particular device that are not available through GDI.
1092 * PARAMS
1093 * hdc [I] Handle to device context
1094 * nEscape [I] Escape function
1095 * cbInput [I] Number of bytes in input structure
1096 * lpszInData [I] Pointer to input structure
1097 * cbOutput [I] Number of bytes in output structure
1098 * lpszOutData [O] Pointer to output structure
1100 * RETURNS
1101 * Success: >0
1102 * Not implemented: 0
1103 * Failure: <0
1105 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1106 INT cbOutput, LPSTR lpszOutData )
1108 PHYSDEV physdev;
1109 INT ret;
1110 DC * dc = get_dc_ptr( hdc );
1112 if (!dc) return 0;
1113 update_dc( dc );
1114 physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1115 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1116 release_dc_ptr( dc );
1117 return ret;
1121 /*******************************************************************
1122 * DrawEscape [GDI32.@]
1126 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1128 FIXME("DrawEscape, stub\n");
1129 return 0;
1132 /*******************************************************************
1133 * NamedEscape [GDI32.@]
1135 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1136 INT cbOutput, LPSTR lpszOutData )
1138 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1139 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1140 lpszOutData);
1141 return 0;
1144 /*******************************************************************
1145 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1146 * GdiEntry13 [GDI32.@]
1148 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1150 static int warn_once;
1152 if (!warn_once++)
1153 FIXME("stub\n");
1154 return 0;