Removed W->A from DEFWND_ImmIsUIMessageW.
[wine] / dlls / mscms / handle.c
1 /*
2  * MSCMS - Color Management System for Wine
3  *
4  * Copyright 2004 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "icm.h"
29
30 #include "mscms_priv.h"
31
32 #ifdef HAVE_LCMS_H
33
34 static CRITICAL_SECTION MSCMS_handle_cs;
35 static CRITICAL_SECTION_DEBUG MSCMS_handle_cs_debug =
36 {
37     0, 0, &MSCMS_handle_cs,
38     { &MSCMS_handle_cs_debug.ProcessLocksList,
39       &MSCMS_handle_cs_debug.ProcessLocksList },
40       0, 0, { 0, (DWORD)(__FILE__ ": MSCMS_handle_cs") }
41 };
42 static CRITICAL_SECTION MSCMS_handle_cs = { &MSCMS_handle_cs_debug, -1, 0, 0, 0, 0 };
43
44 /*  A simple structure to tie together Windows file handles and lcms color
45  *  profile handles. Windows color profile handles are built from indexes
46  *  into an array of these structures. The 'file' field is set to NULL in
47  *  case of a memory based profile
48  */
49
50 struct handlemap
51 {
52     HANDLE file;
53     cmsHPROFILE cmsprofile;
54 };
55
56 #define CMSMAXHANDLES 0x80
57
58 static struct handlemap handlemaptable[CMSMAXHANDLES];
59
60 HPROFILE MSCMS_cmsprofile2hprofile( cmsHPROFILE cmsprofile )
61 {
62     HPROFILE ret = NULL;
63     unsigned int i;
64
65     if (!cmsprofile) return ret;
66
67     EnterCriticalSection( &MSCMS_handle_cs );
68
69     for (i = 0; i <= CMSMAXHANDLES; i++)
70     {
71         if (handlemaptable[i].cmsprofile == cmsprofile)
72         {
73             ret = (HPROFILE)(i + 1); goto out;
74         }
75     }
76
77 out:
78     LeaveCriticalSection( &MSCMS_handle_cs );
79
80     return ret;
81 }
82
83 cmsHPROFILE MSCMS_hprofile2cmsprofile( HPROFILE profile )
84 {
85     HANDLE ret;
86     unsigned int i;
87
88     EnterCriticalSection( &MSCMS_handle_cs );
89
90     i = (unsigned int)profile - 1;
91     ret = handlemaptable[i].cmsprofile;
92
93     LeaveCriticalSection( &MSCMS_handle_cs );
94
95     return ret;
96 }
97
98 HANDLE MSCMS_hprofile2handle( HPROFILE profile )
99 {
100     HANDLE ret;
101     unsigned int i;
102
103     EnterCriticalSection( &MSCMS_handle_cs );
104
105     i = (unsigned int)profile - 1;
106     ret = handlemaptable[i].file;
107
108     LeaveCriticalSection( &MSCMS_handle_cs );
109
110     return ret;
111 }
112
113 HPROFILE MSCMS_create_hprofile_handle( HANDLE file, cmsHPROFILE cmsprofile )
114 {
115     HPROFILE ret = NULL;
116     unsigned int i;
117
118     if (!cmsprofile) return ret;
119
120     EnterCriticalSection( &MSCMS_handle_cs );
121
122     for (i = 0; i <= CMSMAXHANDLES; i++)
123     {
124         if (handlemaptable[i].cmsprofile == 0)
125         {
126             handlemaptable[i].file = file;
127             handlemaptable[i].cmsprofile = cmsprofile;
128
129             ret = (HPROFILE)(i + 1); goto out;
130         }
131     }
132
133 out:
134     LeaveCriticalSection( &MSCMS_handle_cs );
135
136     return ret;
137 }
138
139 void MSCMS_destroy_hprofile_handle( HPROFILE profile )
140 {
141     unsigned int i;
142
143     if (profile)
144     {
145         EnterCriticalSection( &MSCMS_handle_cs );
146
147         i = (unsigned int)profile - 1;
148         memset( &handlemaptable[i], 0, sizeof(struct handlemap) );
149
150         LeaveCriticalSection( &MSCMS_handle_cs );
151     }
152 }
153
154 #endif /* HAVE_LCMS_H */