Added support for FreeBSD 3.0 to DEBUG_checkmap_bad().
[wine/wine-kai.git] / graphics / driver.c
blobe0d9f78047141a40ce66a14aaef8e13804c4737a
1 /*
2 * Graphics driver management functions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include <string.h>
8 #include "gdi.h"
9 #include "heap.h"
10 #include "debugtools.h"
12 DEFAULT_DEBUG_CHANNEL(driver)
14 typedef struct tagGRAPHICS_DRIVER
16 struct tagGRAPHICS_DRIVER *next;
17 LPSTR name;
18 const DC_FUNCTIONS *funcs;
19 } GRAPHICS_DRIVER;
21 static GRAPHICS_DRIVER *firstDriver = NULL;
22 static GRAPHICS_DRIVER *genericDriver = NULL;
24 /**********************************************************************
25 * DRIVER_RegisterDriver
27 BOOL DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs )
29 GRAPHICS_DRIVER *driver = HeapAlloc( SystemHeap, 0, sizeof(*driver) );
30 if (!driver) return FALSE;
31 driver->funcs = funcs;
32 if (name)
34 driver->name = HEAP_strdupA( SystemHeap, 0, name );
35 driver->next = firstDriver;
36 firstDriver = driver;
37 return TRUE;
39 /* No name -> it's the generic driver */
40 if (genericDriver)
42 WARN(" already a generic driver\n" );
43 HeapFree( SystemHeap, 0, driver );
44 return FALSE;
46 driver->name = NULL;
47 genericDriver = driver;
48 return TRUE;
52 /**********************************************************************
53 * DRIVER_FindDriver
55 const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name )
57 GRAPHICS_DRIVER *driver = firstDriver;
59 TRACE(": %s\n", name);
60 while (driver && name)
62 if (!strcasecmp( driver->name, name )) return driver->funcs;
63 driver = driver->next;
65 return genericDriver ? genericDriver->funcs : NULL;
69 /**********************************************************************
70 * DRIVER_UnregisterDriver
72 BOOL DRIVER_UnregisterDriver( LPCSTR name )
74 if (name)
76 GRAPHICS_DRIVER **ppDriver = &firstDriver;
77 while (*ppDriver)
79 if (!strcasecmp( (*ppDriver)->name, name ))
81 GRAPHICS_DRIVER *driver = *ppDriver;
82 (*ppDriver) = driver->next;
83 HeapFree( SystemHeap, 0, driver->name );
84 HeapFree( SystemHeap, 0, driver );
85 return TRUE;
87 ppDriver = &(*ppDriver)->next;
89 return FALSE;
91 else
93 if (!genericDriver) return FALSE;
94 HeapFree( SystemHeap, 0, genericDriver );
95 genericDriver = NULL;
96 return TRUE;
100 /*****************************************************************************
101 * DRIVER_GetDriverName
104 BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size )
106 char *p;
107 size = GetProfileStringA("devices", device, "", driver, size);
108 if(!size) return FALSE;
110 p = strchr(driver, ',');
111 if(!p) return FALSE;
112 *p = '\0';
113 TRACE("Found '%s' for '%s'\n", driver, device);
114 return TRUE;
117 /*****************************************************************************
118 * GDI_CallDevInstall16 [GDI32.100]
120 * This should thunk to 16-bit and simply call the proc with the given args.
122 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
123 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
125 FIXME("(%p, %04x, %s, %s, %s)\n",
126 lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
127 return -1;
130 /*****************************************************************************
131 * GDI_CallExtDeviceModePropSheet16 [GDI32.101]
133 * This should load the correct driver for lpszDevice and calls this driver's
134 * ExtDeviceModePropSheet proc.
136 * Note: The driver calls a callback routine for each property sheet page; these
137 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
138 * The layout of this structure is:
140 * struct
142 * DWORD nPages;
143 * DWORD unknown;
144 * HPROPSHEETPAGE pages[10];
145 * };
147 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
148 LPCSTR lpszPort, LPVOID lpPropSheet )
150 FIXME("(%04x, %s, %s, %p)\n",
151 hWnd, lpszDevice, lpszPort, lpPropSheet );
152 return -1;
155 /*****************************************************************************
156 * GDI_CallExtDeviceMode16 [GDI32.102]
158 * This should load the correct driver for lpszDevice and calls this driver's
159 * ExtDeviceMode proc.
161 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
162 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
163 LPSTR lpszPort, LPDEVMODEA lpdmInput,
164 LPSTR lpszProfile, DWORD fwMode )
166 char buf[300];
167 const DC_FUNCTIONS *funcs;
169 TRACE("(%04x, %p, %s, %s, %p, %s, %ld)\n",
170 hwnd, lpdmOutput, lpszDevice, lpszPort,
171 lpdmInput, lpszProfile, fwMode );
173 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
174 funcs = DRIVER_FindDriver( buf );
175 if(!funcs || !funcs->pExtDeviceMode) return -1;
176 return funcs->pExtDeviceMode(hwnd, lpdmOutput, lpszDevice, lpszPort,
177 lpdmInput, lpszProfile, fwMode);
180 /****************************************************************************
181 * GDI_CallAdvancedSetupDialog16 [GDI32.103]
183 * This should load the correct driver for lpszDevice and calls this driver's
184 * AdvancedSetupDialog proc.
186 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
187 LPDEVMODEA devin, LPDEVMODEA devout )
189 TRACE("(%04x, %s, %p, %p)\n",
190 hwnd, lpszDevice, devin, devout );
191 return -1;
194 /*****************************************************************************
195 * GDI_CallDeviceCapabilities16 [GDI32.104]
197 * This should load the correct driver for lpszDevice and calls this driver's
198 * DeviceCapabilities proc.
200 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
201 WORD fwCapability, LPSTR lpszOutput,
202 LPDEVMODEA lpdm )
204 char buf[300];
205 const DC_FUNCTIONS *funcs;
207 TRACE("(%s, %s, %d, %p, %p)\n",
208 lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
211 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
212 funcs = DRIVER_FindDriver( buf );
213 if(!funcs || !funcs->pDeviceCapabilities) return -1;
214 return funcs->pDeviceCapabilities( lpszDevice, lpszPort, fwCapability,
215 lpszOutput, lpdm);