-Fixed MESSAGE functions that were thunking down to 16 bits implementation.
[wine] / graphics / driver.c
1 /*
2  * Graphics driver management functions
3  *
4  * Copyright 1996 Alexandre Julliard
5  */
6
7 #include "gdi.h"
8 #include "heap.h"
9 #include "debug.h"
10 #include <string.h>
11
12 typedef struct tagGRAPHICS_DRIVER
13 {
14     struct tagGRAPHICS_DRIVER *next;
15     LPSTR                      name;
16     const DC_FUNCTIONS        *funcs;
17 } GRAPHICS_DRIVER;
18
19 static GRAPHICS_DRIVER *firstDriver = NULL;
20 static GRAPHICS_DRIVER *genericDriver = NULL;
21
22 /**********************************************************************
23  *           DRIVER_RegisterDriver
24  */
25 BOOL32 DRIVER_RegisterDriver( LPCSTR name, const DC_FUNCTIONS *funcs )
26 {
27     GRAPHICS_DRIVER *driver = HeapAlloc( SystemHeap, 0, sizeof(*driver) );
28     if (!driver) return FALSE;
29     driver->funcs = funcs;
30     if (name)
31     {
32         driver->name  = HEAP_strdupA( SystemHeap, 0, name );
33         driver->next  = firstDriver;
34         firstDriver = driver;
35         return TRUE;
36     }
37     /* No name -> it's the generic driver */
38     if (genericDriver)
39     {
40         WARN(driver, " already a generic driver\n" );
41         HeapFree( SystemHeap, 0, driver );
42         return FALSE;
43     }
44     driver->name = NULL;
45     genericDriver = driver;
46     return TRUE;
47 }
48
49
50 /**********************************************************************
51  *           DRIVER_FindDriver
52  */
53 const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name )
54 {
55     GRAPHICS_DRIVER *driver = firstDriver;
56
57     while (driver && name)
58     {
59         if (!strcasecmp( driver->name, name )) return driver->funcs;
60         driver = driver->next;
61     }
62     return genericDriver ? genericDriver->funcs : NULL;
63 }
64
65
66 /**********************************************************************
67  *           DRIVER_UnregisterDriver
68  */
69 BOOL32 DRIVER_UnregisterDriver( LPCSTR name )
70 {
71     if (name)
72     {
73         GRAPHICS_DRIVER **ppDriver = &firstDriver;
74         while (*ppDriver)
75         {
76             if (!strcasecmp( (*ppDriver)->name, name ))
77             {
78                 GRAPHICS_DRIVER *driver = *ppDriver;
79                 (*ppDriver) = driver->next;
80                 HeapFree( SystemHeap, 0, driver->name );
81                 HeapFree( SystemHeap, 0, driver );
82                 return TRUE;
83             }
84             ppDriver = &(*ppDriver)->next;
85         }
86         return FALSE;
87     }
88     else
89     {
90         if (!genericDriver) return FALSE;
91         HeapFree( SystemHeap, 0, genericDriver );
92         genericDriver = NULL;
93         return TRUE;
94     }
95 }