msi: Leave room for the NULL terminator.
[wine] / dlls / gdi32 / icm.c
1 /*
2  * Image Color Management
3  *
4  * Copyright 2004 Marcus Meissner
5  * Copyright 2008 Hans Leidekker
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #include <string.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winnls.h"
31
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(icm);
36
37
38 /***********************************************************************
39  *           EnumICMProfilesA    (GDI32.@)
40  */
41 INT WINAPI EnumICMProfilesA(HDC hdc, ICMENUMPROCA func, LPARAM lparam)
42 {
43         FIXME("%p, %p, 0x%08lx stub\n", hdc, func, lparam);
44         return -1;
45 }
46
47 /***********************************************************************
48  *           EnumICMProfilesW    (GDI32.@)
49  */
50 INT WINAPI EnumICMProfilesW(HDC hdc, ICMENUMPROCW func, LPARAM lparam)
51 {
52         FIXME("%p, %p, 0x%08lx stub\n", hdc, func, lparam);
53         return -1;
54 }
55
56 /**********************************************************************
57  *           GetICMProfileA   (GDI32.@)
58  *
59  * Returns the filename of the specified device context's color
60  * management profile, even if color management is not enabled
61  * for that DC.
62  *
63  * RETURNS
64  *    TRUE if filename is copied successfully.
65  *    FALSE if the buffer length pointed to by size is too small.
66  *
67  * FIXME
68  *    How does Windows assign these? Some registry key?
69  */
70 BOOL WINAPI GetICMProfileA(HDC hdc, LPDWORD size, LPSTR filename)
71 {
72     WCHAR filenameW[MAX_PATH];
73     DWORD buflen = MAX_PATH;
74     BOOL ret = FALSE;
75
76     TRACE("%p, %p, %p\n", hdc, size, filename);
77
78     if (!hdc || !size || !filename) return FALSE;
79
80     if (GetICMProfileW(hdc, &buflen, filenameW))
81     {
82         int len = WideCharToMultiByte(CP_ACP, 0, filenameW, -1, NULL, 0, NULL, NULL);
83         if (*size >= len)
84         {
85             WideCharToMultiByte(CP_ACP, 0, filenameW, -1, filename, *size, NULL, NULL);
86             ret = TRUE;
87         }
88         else SetLastError(ERROR_INSUFFICIENT_BUFFER);
89         *size = len;
90     }
91     return ret;
92 }
93
94 /**********************************************************************
95  *           GetICMProfileW     (GDI32.@)
96  */
97 BOOL WINAPI GetICMProfileW(HDC hdc, LPDWORD size, LPWSTR filename)
98 {
99     DWORD required;
100     WCHAR systemdir[MAX_PATH];
101     static const WCHAR profile[] =
102         {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s',
103          '\\','c','o','l','o','r','\\','s','R','G','B',' ','C','o','l','o','r',' ',
104          'S','p','a','c','e',' ','P','r','o','f','i','l','e','.','i','c','m',0};
105
106     TRACE("%p, %p, %p\n", hdc, size, filename);
107
108     if (!hdc || !size) return FALSE;
109
110     required  = GetSystemDirectoryW(systemdir, MAX_PATH);
111     required += sizeof(profile) / sizeof(WCHAR);
112
113     if (*size < required)
114     {
115         *size = required;
116         SetLastError(ERROR_INSUFFICIENT_BUFFER);
117         return FALSE;
118     }
119     if (filename)
120     {
121         strcpyW(filename, systemdir);
122         strcatW(filename, profile);
123
124         if (GetFileAttributesW(filename) == INVALID_FILE_ATTRIBUTES)
125             WARN("color profile not found\n");
126     }
127     *size = required;
128     return TRUE;
129 }
130
131 /**********************************************************************
132  *           GetLogColorSpaceA     (GDI32.@)
133  */
134 BOOL WINAPI GetLogColorSpaceA(HCOLORSPACE colorspace, LPLOGCOLORSPACEA buffer, DWORD size)
135 {
136     FIXME("%p %p 0x%08x stub\n", colorspace, buffer, size);
137     return FALSE;
138 }
139
140 /**********************************************************************
141  *           GetLogColorSpaceW      (GDI32.@)
142  */
143 BOOL WINAPI GetLogColorSpaceW(HCOLORSPACE colorspace, LPLOGCOLORSPACEW buffer, DWORD size)
144 {
145     FIXME("%p %p 0x%08x stub\n", colorspace, buffer, size);
146     return FALSE;
147 }
148
149 /**********************************************************************
150  *           SetICMProfileA         (GDI32.@)
151  */
152 BOOL WINAPI SetICMProfileA(HDC hdc, LPSTR filename)
153 {
154     FIXME("%p %s stub\n", hdc, debugstr_a(filename));
155     return TRUE;
156 }
157
158 /**********************************************************************
159  *           SetICMProfileW         (GDI32.@)
160  */
161 BOOL WINAPI SetICMProfileW(HDC hdc, LPWSTR filename)
162 {
163     FIXME("%p %s stub\n", hdc, debugstr_w(filename));
164     return TRUE;
165 }
166
167 /**********************************************************************
168  *           UpdateICMRegKeyA       (GDI32.@)
169  */
170 BOOL WINAPI UpdateICMRegKeyA(DWORD reserved, LPSTR cmid, LPSTR filename, UINT command)
171 {
172     FIXME("0x%08x, %s, %s, 0x%08x stub\n", reserved, debugstr_a(cmid), debugstr_a(filename), command);
173     return TRUE;
174 }
175
176 /**********************************************************************
177  *           UpdateICMRegKeyW       (GDI32.@)
178  */
179 BOOL WINAPI UpdateICMRegKeyW(DWORD reserved, LPWSTR cmid, LPWSTR filename, UINT command)
180 {
181     FIXME("0x%08x, %s, %s, 0x%08x stub\n", reserved, debugstr_w(cmid), debugstr_w(filename), command);
182     return TRUE;
183 }