Store print dlg structure in a property instead of DWL_USER.
[wine/multimedia.git] / dlls / gdi / driver.c
blobea03910dbbcd8589e91f5288645ac52b1ba19e5b
1 /*
2 * Graphics driver management functions
4 * Copyright 1996 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <string.h>
22 #include "winbase.h"
23 #include "winreg.h"
24 #include "ntddk.h"
26 #include "gdi.h"
27 #include "win16drv/win16drv.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(driver);
32 struct graphics_driver
34 struct graphics_driver *next;
35 struct graphics_driver *prev;
36 HMODULE module; /* module handle */
37 unsigned int count; /* reference count */
38 DC_FUNCTIONS funcs;
41 static struct graphics_driver *first_driver;
42 static struct graphics_driver *display_driver;
43 static const DC_FUNCTIONS *win16_driver;
44 static CRITICAL_SECTION driver_section = CRITICAL_SECTION_INIT( "driver_section" );
46 /**********************************************************************
47 * create_driver
49 * Allocate and fill the driver structure for a given module.
51 static struct graphics_driver *create_driver( HMODULE module )
53 struct graphics_driver *driver;
55 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
56 driver->next = NULL;
57 driver->prev = NULL;
58 driver->module = module;
59 driver->count = 1;
61 /* fill the function table */
63 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
65 GET_FUNC(AbortDoc);
66 GET_FUNC(AbortPath);
67 GET_FUNC(AngleArc);
68 GET_FUNC(Arc);
69 GET_FUNC(ArcTo);
70 GET_FUNC(BeginPath);
71 GET_FUNC(BitBlt);
72 GET_FUNC(ChoosePixelFormat);
73 GET_FUNC(Chord);
74 GET_FUNC(CloseFigure);
75 GET_FUNC(CreateBitmap);
76 GET_FUNC(CreateDC);
77 GET_FUNC(CreateDIBSection);
78 GET_FUNC(DeleteBitmap);
79 GET_FUNC(DeleteDC);
80 GET_FUNC(DescribePixelFormat);
81 GET_FUNC(DeviceCapabilities);
82 GET_FUNC(Ellipse);
83 GET_FUNC(EndDoc);
84 GET_FUNC(EndPage);
85 GET_FUNC(EndPath);
86 GET_FUNC(EnumDeviceFonts);
87 GET_FUNC(ExcludeClipRect);
88 GET_FUNC(ExtDeviceMode);
89 GET_FUNC(ExtEscape);
90 GET_FUNC(ExtFloodFill);
91 GET_FUNC(ExtSelectClipRgn);
92 GET_FUNC(ExtTextOut);
93 GET_FUNC(FillPath);
94 GET_FUNC(FillRgn);
95 GET_FUNC(FlattenPath);
96 GET_FUNC(FrameRgn);
97 GET_FUNC(GetBitmapBits);
98 GET_FUNC(GetCharWidth);
99 GET_FUNC(GetDCOrgEx);
100 GET_FUNC(GetDIBColorTable);
101 GET_FUNC(GetDIBits);
102 GET_FUNC(GetDeviceCaps);
103 GET_FUNC(GetDeviceGammaRamp);
104 GET_FUNC(GetNearestColor);
105 GET_FUNC(GetPixel);
106 GET_FUNC(GetPixelFormat);
107 GET_FUNC(GetSystemPaletteEntries);
108 GET_FUNC(GetTextExtentPoint);
109 GET_FUNC(GetTextMetrics);
110 GET_FUNC(IntersectClipRect);
111 GET_FUNC(InvertRgn);
112 GET_FUNC(LineTo);
113 GET_FUNC(MoveTo);
114 GET_FUNC(OffsetClipRgn);
115 GET_FUNC(OffsetViewportOrg);
116 GET_FUNC(OffsetWindowOrg);
117 GET_FUNC(PaintRgn);
118 GET_FUNC(PatBlt);
119 GET_FUNC(Pie);
120 GET_FUNC(PolyBezier);
121 GET_FUNC(PolyBezierTo);
122 GET_FUNC(PolyDraw);
123 GET_FUNC(PolyPolygon);
124 GET_FUNC(PolyPolyline);
125 GET_FUNC(Polygon);
126 GET_FUNC(Polyline);
127 GET_FUNC(PolylineTo);
128 GET_FUNC(RealizeDefaultPalette);
129 GET_FUNC(RealizePalette);
130 GET_FUNC(Rectangle);
131 GET_FUNC(ResetDC);
132 GET_FUNC(RestoreDC);
133 GET_FUNC(RoundRect);
134 GET_FUNC(SaveDC);
135 GET_FUNC(ScaleViewportExt);
136 GET_FUNC(ScaleWindowExt);
137 GET_FUNC(SelectBitmap);
138 GET_FUNC(SelectBrush);
139 GET_FUNC(SelectClipPath);
140 GET_FUNC(SelectFont);
141 GET_FUNC(SelectPalette);
142 GET_FUNC(SelectPen);
143 GET_FUNC(SetBitmapBits);
144 GET_FUNC(SetBkColor);
145 GET_FUNC(SetBkMode);
146 GET_FUNC(SetDCOrg);
147 GET_FUNC(SetDIBColorTable);
148 GET_FUNC(SetDIBits);
149 GET_FUNC(SetDIBitsToDevice);
150 GET_FUNC(SetDeviceClipping);
151 GET_FUNC(SetDeviceGammaRamp);
152 GET_FUNC(SetMapMode);
153 GET_FUNC(SetMapperFlags);
154 GET_FUNC(SetPixel);
155 GET_FUNC(SetPixelFormat);
156 GET_FUNC(SetPolyFillMode);
157 GET_FUNC(SetROP2);
158 GET_FUNC(SetRelAbs);
159 GET_FUNC(SetStretchBltMode);
160 GET_FUNC(SetTextAlign);
161 GET_FUNC(SetTextCharacterExtra);
162 GET_FUNC(SetTextColor);
163 GET_FUNC(SetTextJustification);
164 GET_FUNC(SetViewportExt);
165 GET_FUNC(SetViewportOrg);
166 GET_FUNC(SetWindowExt);
167 GET_FUNC(SetWindowOrg);
168 GET_FUNC(StartDoc);
169 GET_FUNC(StartPage);
170 GET_FUNC(StretchBlt);
171 GET_FUNC(StretchDIBits);
172 GET_FUNC(StrokeAndFillPath);
173 GET_FUNC(StrokePath);
174 GET_FUNC(SwapBuffers);
175 GET_FUNC(WidenPath);
176 #undef GET_FUNC
178 /* add it to the list */
179 driver->prev = NULL;
180 if ((driver->next = first_driver)) driver->next->prev = driver;
181 first_driver = driver;
182 return driver;
186 /**********************************************************************
187 * load_display_driver
189 * Special case for loading the display driver: get the name from the config file
191 static struct graphics_driver *load_display_driver(void)
193 char buffer[MAX_PATH];
194 HMODULE module;
195 HKEY hkey;
197 if (display_driver) /* already loaded */
199 display_driver->count++;
200 return display_driver;
203 strcpy( buffer, "x11drv" ); /* default value */
204 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
206 DWORD type, count = sizeof(buffer);
207 RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
208 RegCloseKey( hkey );
211 if (!(module = LoadLibraryA( buffer )))
213 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
214 return NULL;
217 if (!(display_driver = create_driver( module )))
219 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
220 FreeLibrary( module );
221 return NULL;
224 display_driver->count++; /* we don't want to free it */
225 return display_driver;
229 /**********************************************************************
230 * DRIVER_load_driver
232 const DC_FUNCTIONS *DRIVER_load_driver( LPCSTR name )
234 HMODULE module;
235 struct graphics_driver *driver;
237 RtlEnterCriticalSection( &driver_section );
239 /* display driver is a special case */
240 if (!strcasecmp( name, "display" ))
242 driver = load_display_driver();
243 RtlLeaveCriticalSection( &driver_section );
244 return &driver->funcs;
247 if ((module = GetModuleHandleA( name )))
249 for (driver = first_driver; driver; driver = driver->next)
251 if (driver->module == module)
253 driver->count++;
254 RtlLeaveCriticalSection( &driver_section );
255 return &driver->funcs;
260 if (!(module = LoadLibraryA( name )))
262 if (!win16_driver) win16_driver = WIN16DRV_Init();
263 RtlLeaveCriticalSection( &driver_section );
264 return win16_driver;
267 if (!(driver = create_driver( module )))
269 FreeLibrary( module );
270 RtlLeaveCriticalSection( &driver_section );
271 return NULL;
274 TRACE( "loaded driver %p for %s\n", driver, name );
275 RtlLeaveCriticalSection( &driver_section );
276 return &driver->funcs;
280 /**********************************************************************
281 * DRIVER_get_driver
283 * Get a new copy of an existing driver.
285 const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs )
287 struct graphics_driver *driver;
289 RtlEnterCriticalSection( &driver_section );
290 if (funcs != win16_driver)
292 for (driver = first_driver; driver; driver = driver->next)
293 if (&driver->funcs == funcs) break;
294 if (!driver) ERR( "driver not found, trouble ahead\n" );
295 driver->count++;
297 RtlLeaveCriticalSection( &driver_section );
298 return funcs;
302 /**********************************************************************
303 * DRIVER_release_driver
305 * Release a driver by decrementing ref count and freeing it if needed.
307 void DRIVER_release_driver( const DC_FUNCTIONS *funcs )
309 struct graphics_driver *driver;
311 RtlEnterCriticalSection( &driver_section );
313 if (funcs == win16_driver) goto done;
315 for (driver = first_driver; driver; driver = driver->next)
316 if (&driver->funcs == funcs) break;
318 if (!driver) goto done;
319 if (--driver->count) goto done;
321 /* removed last reference, free it */
322 if (driver->next) driver->next->prev = driver->prev;
323 if (driver->prev) driver->prev->next = driver->next;
324 else first_driver = driver->next;
325 if (driver == display_driver) display_driver = NULL;
327 FreeLibrary( driver->module );
328 HeapFree( GetProcessHeap(), 0, driver );
329 done:
330 RtlLeaveCriticalSection( &driver_section );
334 /*****************************************************************************
335 * DRIVER_GetDriverName
338 BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size )
340 char *p;
341 size = GetProfileStringA("devices", device, "", driver, size);
342 if(!size) {
343 WARN("Unable to find '%s' in [devices] section of win.ini\n", device);
344 return FALSE;
346 p = strchr(driver, ',');
347 if(!p)
349 WARN("'%s' entry in [devices] section of win.ini is malformed.\n", device);
350 return FALSE;
352 *p = '\0';
353 TRACE("Found '%s' for '%s'\n", driver, device);
354 return TRUE;
357 /*****************************************************************************
358 * @ [GDI32.100]
360 * This should thunk to 16-bit and simply call the proc with the given args.
362 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
363 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
365 FIXME("(%p, %04x, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
366 return -1;
369 /*****************************************************************************
370 * @ [GDI32.101]
372 * This should load the correct driver for lpszDevice and calls this driver's
373 * ExtDeviceModePropSheet proc.
375 * Note: The driver calls a callback routine for each property sheet page; these
376 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
377 * The layout of this structure is:
379 * struct
381 * DWORD nPages;
382 * DWORD unknown;
383 * HPROPSHEETPAGE pages[10];
384 * };
386 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
387 LPCSTR lpszPort, LPVOID lpPropSheet )
389 FIXME("(%04x, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
390 return -1;
393 /*****************************************************************************
394 * @ [GDI32.102]
396 * This should load the correct driver for lpszDevice and calls this driver's
397 * ExtDeviceMode proc.
399 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
400 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
401 LPSTR lpszPort, LPDEVMODEA lpdmInput,
402 LPSTR lpszProfile, DWORD fwMode )
404 char buf[300];
405 HDC hdc;
406 DC *dc;
407 INT ret = -1;
408 INT (*pExtDeviceMode)(LPSTR,HWND,LPDEVMODEA,LPSTR,LPSTR,LPDEVMODEA,LPSTR,DWORD);
410 TRACE("(%04x, %p, %s, %s, %p, %s, %ld)\n",
411 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
413 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
415 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
417 if ((dc = DC_GetDCPtr( hdc )))
419 pExtDeviceMode = dc->funcs->pExtDeviceMode;
420 GDI_ReleaseObj( hdc );
421 if (pExtDeviceMode)
422 ret = pExtDeviceMode(buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
423 lpdmInput, lpszProfile, fwMode);
425 DeleteDC( hdc );
426 return ret;
429 /****************************************************************************
430 * @ [GDI32.103]
432 * This should load the correct driver for lpszDevice and calls this driver's
433 * AdvancedSetupDialog proc.
435 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
436 LPDEVMODEA devin, LPDEVMODEA devout )
438 TRACE("(%04x, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
439 return -1;
442 /*****************************************************************************
443 * @ [GDI32.104]
445 * This should load the correct driver for lpszDevice and calls this driver's
446 * DeviceCapabilities proc.
448 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
449 WORD fwCapability, LPSTR lpszOutput,
450 LPDEVMODEA lpdm )
452 char buf[300];
453 HDC hdc;
454 DC *dc;
455 INT ret = -1;
457 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
459 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
461 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
463 if ((dc = DC_GetDCPtr( hdc )))
465 if (dc->funcs->pDeviceCapabilities)
466 ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
467 fwCapability, lpszOutput, lpdm );
468 GDI_ReleaseObj( hdc );
470 DeleteDC( hdc );
471 return ret;