[USER32]
[reactos.git] / reactos / dll / win32 / user32 / windows / clipboard.c
1 /* $Id$
2 *
3 * PROJECT: ReactOS user32.dll
4 * FILE: lib/user32/windows/clipboard.c
5 * PURPOSE: Input
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Pablo Borobia <pborobia@gmail.com>
8 * UPDATE HISTORY:
9 * 09-05-2001 CSH Created
10 *
11 */
12
13 /* INCLUDES ******************************************************************/
14
15 #include <user32.h>
16
17 #define NDEBUG
18
19 #include <wine/debug.h>
20 WINE_DEFAULT_DEBUG_CHANNEL(user32);
21
22 #define QUERY_SIZE 0
23
24 /* FUNCTIONS *****************************************************************/
25
26 /*
27 * @implemented
28 */
29 BOOL
30 WINAPI
31 OpenClipboard(HWND hWndNewOwner)
32 {
33 BOOL ret = NtUserOpenClipboard(hWndNewOwner, 0);
34 return ret;
35 }
36
37 /*
38 * @implemented
39 */
40 UINT
41 WINAPI
42 EnumClipboardFormats(UINT format)
43 {
44 UINT ret = NtUserCallOneParam(format, ONEPARAM_ROUTINE_ENUMCLIPBOARDFORMATS);
45 return ret;
46 }
47
48 /*
49 * @implemented
50 */
51 HANDLE
52 WINAPI
53 GetClipboardData(UINT uFormat)
54 {
55 HGLOBAL hGlobal = NULL;
56 PVOID pGlobal = NULL;
57 DWORD_PTR size = 0;
58
59 /* dealing with bitmap object */
60 if (uFormat != CF_BITMAP)
61 {
62 size = (DWORD_PTR)NtUserGetClipboardData(uFormat, NULL);
63
64 if (size)
65 {
66 hGlobal = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, size);
67 pGlobal = GlobalLock(hGlobal);
68
69 size = (DWORD_PTR)NtUserGetClipboardData(uFormat, pGlobal);
70
71 GlobalUnlock(hGlobal);
72 }
73 }
74 else
75 {
76 hGlobal = NtUserGetClipboardData(CF_BITMAP, NULL);
77 }
78
79 return hGlobal;
80 }
81
82 /*
83 * @implemented
84 */
85 INT
86 WINAPI
87 GetClipboardFormatNameA(UINT format,
88 LPSTR lpszFormatName,
89 int cchMaxCount)
90 {
91 LPWSTR lpBuffer;
92 UNICODE_STRING FormatName;
93 INT Length;
94
95 lpBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, cchMaxCount * sizeof(WCHAR));
96 if (!lpBuffer)
97 {
98 SetLastError(ERROR_OUTOFMEMORY);
99 return 0;
100 }
101
102 FormatName.Length = 0;
103 FormatName.MaximumLength = cchMaxCount * sizeof(WCHAR);
104 FormatName.Buffer = lpBuffer;
105
106 /* we need a UNICODE string */
107 Length = NtUserGetClipboardFormatName(format, &FormatName, cchMaxCount);
108
109 if (Length != 0)
110 {
111 if (!WideCharToMultiByte(CP_ACP, 0, lpBuffer, Length, lpszFormatName, cchMaxCount, NULL, NULL))
112 {
113 /* clear result string */
114 Length = 0;
115 }
116 lpszFormatName[Length] = '\0';
117 }
118
119 RtlFreeHeap(RtlGetProcessHeap(), 0, lpBuffer);
120 return Length;
121 }
122
123 /*
124 * @implemented
125 */
126 INT
127 WINAPI
128 GetClipboardFormatNameW(UINT format,
129 LPWSTR lpszFormatName,
130 INT cchMaxCount)
131 {
132 UNICODE_STRING FormatName;
133 ULONG Ret;
134
135 FormatName.Length = 0;
136 FormatName.MaximumLength = cchMaxCount * sizeof(WCHAR);
137 FormatName.Buffer = (PWSTR)lpszFormatName;
138 Ret = NtUserGetClipboardFormatName(format, &FormatName, cchMaxCount);
139 return Ret;
140
141 }
142
143 /*
144 * @implemented
145 */
146
147 UINT
148 WINAPI
149 RegisterClipboardFormatA(LPCSTR lpszFormat)
150 {
151 UINT ret = 0;
152 UNICODE_STRING usFormat = {0};
153
154 if (lpszFormat == NULL)
155 {
156 SetLastError(ERROR_INVALID_PARAMETER);
157 return 0;
158 }
159
160 /* check for "" */
161 if (*lpszFormat == 0) //NULL
162 {
163 SetLastError(ERROR_INVALID_NAME);
164 return 0;
165 }
166
167 ret = RtlCreateUnicodeStringFromAsciiz(&usFormat, lpszFormat);
168 if (ret)
169 {
170 ret = NtUserRegisterWindowMessage(&usFormat); //(LPCWSTR)
171 RtlFreeUnicodeString(&usFormat);
172 }
173
174 return ret;
175 }
176
177 /*
178 * @implemented
179 */
180 UINT
181 WINAPI
182 RegisterClipboardFormatW(LPCWSTR lpszFormat)
183 {
184 UINT ret = 0;
185 UNICODE_STRING usFormat = {0};
186
187 if (lpszFormat == NULL)
188 {
189 SetLastError(ERROR_INVALID_PARAMETER);
190 return 0;
191 }
192
193 /* check for "" */
194 if (*lpszFormat == 0) //NULL
195 {
196 SetLastError(ERROR_INVALID_NAME);
197 return 0;
198 }
199
200 RtlInitUnicodeString(&usFormat, lpszFormat);
201 ret = NtUserRegisterWindowMessage(&usFormat);
202
203 return ret;
204 }
205
206 HGLOBAL
207 renderLocale(DWORD Locale)
208 {
209 DWORD* pLocale;
210 HGLOBAL hGlobal;
211
212 hGlobal = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, sizeof(DWORD));
213
214 if(!hGlobal)
215 {
216 return hGlobal;
217 }
218
219 pLocale = (DWORD*)GlobalLock(hGlobal);
220
221 *pLocale = Locale;
222
223 GlobalUnlock(hGlobal);
224
225 return hGlobal;
226 }
227
228 /*
229 * @implemented
230 */
231 HANDLE
232 WINAPI
233 SetClipboardData(UINT uFormat, HANDLE hMem)
234 {
235 DWORD size;
236 LPVOID pMem;
237 HANDLE ret = NULL;
238
239 if (hMem == NULL)
240 {
241 return NtUserSetClipboardData(uFormat, 0, 0);
242 }
243
244 if (uFormat == CF_BITMAP)
245 {
246 /* GlobalLock should return 0 for GDI handles
247 pMem = GlobalLock(hMem);
248 if (pMem)
249 {
250 // not a GDI handle
251 GlobalUnlock(hMem);
252 return ret;
253 }
254 else
255 {
256 */
257 /* check if this GDI handle is a HBITMAP */
258 /* GetObject for HBITMAP not implemented in ReactOS */
259 //if (GetObject(hMem, 0, NULL) == sifeof(BITMAP))
260 //{
261 return NtUserSetClipboardData(CF_BITMAP, hMem, 0);
262 //}
263 /*}*/
264 }
265
266 size = GlobalSize(hMem);
267 pMem = GlobalLock(hMem);
268
269 if ((pMem) && (size))
270 {
271 size = GlobalSize(hMem);
272 ret = NtUserSetClipboardData(uFormat, pMem, size);
273
274 //On success NtUserSetClipboardData returns pMem
275 //however caller expects us to return hMem
276 if (ret == pMem)
277 ret = hMem;
278
279 //should i unlock hMem?
280 GlobalUnlock(hMem);
281 }
282 else
283 {
284 ERR("SetClipboardData failed\n");
285 }
286
287 return ret;
288
289 }
290
291 /*
292 * @unimplemented
293 */
294 BOOL
295 WINAPI
296 AddClipboardFormatListener(HWND hwnd)
297 {
298 UNIMPLEMENTED;
299 return FALSE;
300 }
301 /*
302 * @unimplemented
303 */
304 BOOL
305 WINAPI
306 RemoveClipboardFormatListener(HWND hwnd)
307 {
308 UNIMPLEMENTED;
309 return FALSE;
310 }
311
312 /*
313 * @unimplemented
314 */
315 BOOL
316 WINAPI
317 GetUpdatedClipboardFormats(PUINT lpuiFormats,
318 UINT cFormats,
319 PUINT pcFormatsOut)
320 {
321 UNIMPLEMENTED;
322 return FALSE;
323 }