Use autoconf checks to check for various FreeType headers.
[wine] / graphics / driver.c
1 /*
2  * Graphics driver management functions
3  *
4  * Copyright 1996 Alexandre Julliard
5  */
6
7 #include <string.h>
8 #include "gdi.h"
9 #include "heap.h"
10 #include "debugtools.h"
11
12 DEFAULT_DEBUG_CHANNEL(driver);
13
14 typedef struct tagGRAPHICS_DRIVER
15 {
16     struct tagGRAPHICS_DRIVER *next;
17     LPSTR                      name;
18     const DC_FUNCTIONS        *funcs;
19 } GRAPHICS_DRIVER;
20
21 static GRAPHICS_DRIVER *firstDriver = NULL;
22 static GRAPHICS_DRIVER *genericDriver = NULL;
23
24 /**********************************************************************
25  *           DRIVER_RegisterDriver
26  */
27 BOOL DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs )
28 {
29     GRAPHICS_DRIVER *driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver) );
30     if (!driver) return FALSE;
31     driver->funcs = funcs;
32     if (name)
33     {
34         driver->name  = HEAP_strdupA( GetProcessHeap(), 0, name );
35         driver->next  = firstDriver;
36         firstDriver = driver;
37         return TRUE;
38     }
39     /* No name -> it's the generic driver */
40     if (genericDriver)
41     {
42         WARN(" already a generic driver\n" );
43         HeapFree( GetProcessHeap(), 0, driver );
44         return FALSE;
45     }
46     driver->name = NULL;
47     genericDriver = driver;
48     return TRUE;
49 }
50
51
52 /**********************************************************************
53  *           DRIVER_FindDriver
54  */
55 const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name )
56 {
57     GRAPHICS_DRIVER *driver;
58     HINSTANCE hDriver;
59
60     TRACE(": %s\n", name);
61
62     if (!name) return genericDriver ? genericDriver->funcs : NULL;
63
64     for (driver = firstDriver; driver; driver = driver->next)
65         if (!strcasecmp( driver->name, name )) return driver->funcs;
66
67     if (!(hDriver = LoadLibraryA (name))) return NULL;
68
69     for (driver = firstDriver; driver; driver = driver->next)
70         if (!strcasecmp( driver->name, name )) return driver->funcs;
71
72     FreeLibrary (hDriver);
73     return NULL;
74 }
75
76
77 /**********************************************************************
78  *           DRIVER_UnregisterDriver
79  */
80 BOOL DRIVER_UnregisterDriver( LPCSTR name )
81 {
82     if (name)
83     {
84         GRAPHICS_DRIVER **ppDriver = &firstDriver;
85         while (*ppDriver)
86         {
87             if (!strcasecmp( (*ppDriver)->name, name ))
88             {
89                 GRAPHICS_DRIVER *driver = *ppDriver;
90                 (*ppDriver) = driver->next;
91                 HeapFree( GetProcessHeap(), 0, driver->name );
92                 HeapFree( GetProcessHeap(), 0, driver );
93                 return TRUE;
94             }
95             ppDriver = &(*ppDriver)->next;
96         }
97         return FALSE;
98     }
99     else
100     {
101         if (!genericDriver) return FALSE;
102         HeapFree( GetProcessHeap(), 0, genericDriver );
103         genericDriver = NULL;
104         return TRUE;
105     }
106 }
107
108 /*****************************************************************************
109  *      DRIVER_GetDriverName
110  *
111  */
112 BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size )
113 {
114     char *p;
115     size = GetProfileStringA("devices", device, "", driver, size);
116     if(!size) {
117         WARN("Unable to find '%s' in [devices] section of win.ini\n", device);
118         return FALSE;
119     }
120     p = strchr(driver, ',');
121     if(!p) {
122         WARN("'%s' entry in [devices] section of win.ini is malformed.\n",
123              device);
124         return FALSE;
125     }
126     *p = '\0';
127     TRACE("Found '%s' for '%s'\n", driver, device);
128     return TRUE;
129 }
130     
131 /*****************************************************************************
132  *      GDI_CallDevInstall16   [GDI32.100]
133  *
134  * This should thunk to 16-bit and simply call the proc with the given args.
135  */
136 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd, 
137                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
138 {
139     FIXME("(%p, %04x, %s, %s, %s)\n", 
140           lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
141     return -1;
142 }
143
144 /*****************************************************************************
145  *      GDI_CallExtDeviceModePropSheet16   [GDI32.101]
146  *
147  * This should load the correct driver for lpszDevice and calls this driver's
148  * ExtDeviceModePropSheet proc. 
149  *
150  * Note: The driver calls a callback routine for each property sheet page; these 
151  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
152  * The layout of this structure is:
153  * 
154  * struct
155  * {
156  *   DWORD  nPages;
157  *   DWORD  unknown;
158  *   HPROPSHEETPAGE  pages[10];
159  * };
160  */
161 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice, 
162                                              LPCSTR lpszPort, LPVOID lpPropSheet )
163 {
164     FIXME("(%04x, %s, %s, %p)\n", 
165       hWnd, lpszDevice, lpszPort, lpPropSheet );
166     return -1;
167 }
168
169 /*****************************************************************************
170  *      GDI_CallExtDeviceMode16   [GDI32.102]
171  *
172  * This should load the correct driver for lpszDevice and calls this driver's
173  * ExtDeviceMode proc.
174  */
175 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd, 
176                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice, 
177                                     LPSTR lpszPort, LPDEVMODEA lpdmInput, 
178                                     LPSTR lpszProfile, DWORD fwMode )
179 {
180     char buf[300];
181     const DC_FUNCTIONS *funcs;
182
183     TRACE("(%04x, %p, %s, %s, %p, %s, %ld)\n", 
184           hwnd, lpdmOutput, lpszDevice, lpszPort, 
185           lpdmInput, lpszProfile, fwMode );
186
187     if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
188     funcs = DRIVER_FindDriver( buf );
189     if(!funcs || !funcs->pExtDeviceMode) return -1;
190     return funcs->pExtDeviceMode(buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
191                                  lpdmInput, lpszProfile, fwMode);
192 }
193
194 /****************************************************************************
195  *      GDI_CallAdvancedSetupDialog16     [GDI32.103]
196  *
197  * This should load the correct driver for lpszDevice and calls this driver's
198  * AdvancedSetupDialog proc.
199  */
200 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
201                                           LPDEVMODEA devin, LPDEVMODEA devout )
202 {
203     TRACE("(%04x, %s, %p, %p)\n", 
204           hwnd, lpszDevice, devin, devout );
205     return -1;
206 }
207
208 /*****************************************************************************
209  *      GDI_CallDeviceCapabilities16      [GDI32.104]
210  *
211  * This should load the correct driver for lpszDevice and calls this driver's
212  * DeviceCapabilities proc.
213  */
214 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
215                                            WORD fwCapability, LPSTR lpszOutput,
216                                            LPDEVMODEA lpdm )
217 {
218     char buf[300];
219     const DC_FUNCTIONS *funcs;
220
221     TRACE("(%s, %s, %d, %p, %p)\n", 
222           lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
223
224
225     if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
226     funcs = DRIVER_FindDriver( buf );
227     if(!funcs || !funcs->pDeviceCapabilities) return -1;
228     return funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
229                                        fwCapability, lpszOutput, lpdm);
230
231 }
232
233