- Go away STDCALL, time has come for WINAPI and NTAPI
[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 BOOL
41 WINAPI
42 CloseClipboard(VOID)
43 {
44 BOOL ret;
45 ret = NtUserCloseClipboard();
46 return ret;
47 }
48
49 /*
50 * @implemented
51 */
52 INT
53 WINAPI
54 CountClipboardFormats(VOID)
55 {
56 INT ret = NtUserCountClipboardFormats();
57 return ret;
58 }
59
60 /*
61 * @implemented
62 */
63 BOOL
64 WINAPI
65 EmptyClipboard(VOID)
66 {
67 return NtUserEmptyClipboard();
68 }
69
70 /*
71 * @implemented
72 */
73 UINT
74 WINAPI
75 EnumClipboardFormats(UINT format)
76 {
77 UINT ret = NtUserCallOneParam(format, ONEPARAM_ROUTINE_ENUMCLIPBOARDFORMATS);
78 return ret;
79 }
80
81 /*
82 * @implemented
83 */
84 HANDLE
85 WINAPI
86 GetClipboardData(UINT uFormat)
87 {
88 HGLOBAL hGlobal = NULL;
89 PVOID pGlobal = NULL;
90 DWORD size = 0;
91
92 /* dealing with bitmap object */
93 if (uFormat != CF_BITMAP)
94 {
95 size = (DWORD)NtUserGetClipboardData(uFormat, NULL);
96
97 if (size)
98 {
99 hGlobal = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, size);
100 pGlobal = GlobalLock(hGlobal);
101
102 size = (DWORD)NtUserGetClipboardData(uFormat, pGlobal);
103
104 GlobalUnlock(hGlobal);
105 }
106 }
107 else
108 {
109 hGlobal = NtUserGetClipboardData(CF_BITMAP, NULL);
110 }
111
112 return hGlobal;
113 }
114
115 /*
116 * @implemented
117 */
118 INT
119 WINAPI
120 GetClipboardFormatNameA(UINT format,
121 LPSTR lpszFormatName,
122 int cchMaxCount)
123 {
124 LPWSTR lpBuffer;
125 UNICODE_STRING FormatName;
126 INT Length;
127
128 lpBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, cchMaxCount * sizeof(WCHAR));
129 if (!lpBuffer)
130 {
131 SetLastError(ERROR_OUTOFMEMORY);
132 return 0;
133 }
134
135 FormatName.Length = 0;
136 FormatName.MaximumLength = cchMaxCount * sizeof(WCHAR);
137 FormatName.Buffer = lpBuffer;
138
139 /* we need a UNICODE string */
140 Length = NtUserGetClipboardFormatName(format, &FormatName, cchMaxCount);
141
142 if (Length != 0)
143 {
144 if (!WideCharToMultiByte(CP_ACP, 0, lpBuffer, Length, lpszFormatName, cchMaxCount, NULL, NULL))
145 {
146 /* clear result string */
147 Length = 0;
148 }
149 lpszFormatName[Length] = '\0';
150 }
151
152 RtlFreeHeap(RtlGetProcessHeap(), 0, lpBuffer);
153 return Length;
154 }
155
156 /*
157 * @implemented
158 */
159 INT
160 WINAPI
161 GetClipboardFormatNameW(UINT format,
162 LPWSTR lpszFormatName,
163 INT cchMaxCount)
164 {
165 UNICODE_STRING FormatName;
166 ULONG Ret;
167
168 FormatName.Length = 0;
169 FormatName.MaximumLength = cchMaxCount * sizeof(WCHAR);
170 FormatName.Buffer = (PWSTR)lpszFormatName;
171 Ret = NtUserGetClipboardFormatName(format, &FormatName, cchMaxCount);
172 return Ret;
173
174 }
175
176 /*
177 * @implemented
178 */
179 HWND
180 WINAPI
181 GetClipboardOwner(VOID)
182 {
183 return NtUserGetClipboardOwner();
184 }
185
186 /*
187 * @implemented
188 */
189 DWORD
190 WINAPI
191 GetClipboardSequenceNumber(VOID)
192 {
193 return NtUserGetClipboardSequenceNumber();
194 }
195
196 /*
197 * @implemented
198 */
199 HWND
200 WINAPI
201 GetClipboardViewer(VOID)
202 {
203 return NtUserGetClipboardViewer();
204 }
205
206 /*
207 * @implemented
208 */
209 HWND
210 WINAPI
211 GetOpenClipboardWindow(VOID)
212 {
213 return NtUserGetOpenClipboardWindow();
214 }
215
216 /*
217 * @implemented
218 */
219 INT
220 WINAPI
221 GetPriorityClipboardFormat(UINT *paFormatPriorityList, INT cFormats)
222 {
223 INT ret = NtUserGetPriorityClipboardFormat(paFormatPriorityList, cFormats);
224 return ret;
225 }
226
227 /*
228 * @implemented
229 */
230 BOOL
231 WINAPI
232 IsClipboardFormatAvailable(UINT format)
233 {
234 BOOL ret = NtUserIsClipboardFormatAvailable(format);
235 return ret;
236 }
237
238 /*
239 * @implemented
240 */
241
242 UINT
243 WINAPI
244 RegisterClipboardFormatA(LPCSTR lpszFormat)
245 {
246 UINT ret = 0;
247 UNICODE_STRING usFormat = {0};
248
249 if (lpszFormat == NULL)
250 {
251 SetLastError(ERROR_INVALID_PARAMETER);
252 return 0;
253 }
254
255 /* check for "" */
256 if (*lpszFormat == 0) //NULL
257 {
258 SetLastError(ERROR_INVALID_NAME);
259 return 0;
260 }
261
262 ret = RtlCreateUnicodeStringFromAsciiz(&usFormat, lpszFormat);
263 if (ret)
264 {
265 ret = NtUserRegisterWindowMessage(&usFormat); //(LPCWSTR)
266 RtlFreeUnicodeString(&usFormat);
267 }
268
269 return ret;
270 }
271
272 /*
273 * @implemented
274 */
275 UINT
276 WINAPI
277 RegisterClipboardFormatW(LPCWSTR lpszFormat)
278 {
279 UINT ret = 0;
280 UNICODE_STRING usFormat = {0};
281
282 if (lpszFormat == NULL)
283 {
284 SetLastError(ERROR_INVALID_PARAMETER);
285 return 0;
286 }
287
288 /* check for "" */
289 if (*lpszFormat == 0) //NULL
290 {
291 SetLastError(ERROR_INVALID_NAME);
292 return 0;
293 }
294
295 RtlInitUnicodeString(&usFormat, lpszFormat);
296 ret = NtUserRegisterWindowMessage(&usFormat);
297
298 return ret;
299 }
300
301 HGLOBAL
302 renderLocale(DWORD Locale)
303 {
304 DWORD* pLocale;
305 HGLOBAL hGlobal;
306
307 hGlobal = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, sizeof(DWORD));
308
309 if(!hGlobal)
310 {
311 return hGlobal;
312 }
313
314 pLocale = (DWORD*)GlobalLock(hGlobal);
315
316 *pLocale = Locale;
317
318 GlobalUnlock(hGlobal);
319
320 return hGlobal;
321 }
322
323 /*
324 * @implemented
325 */
326 HANDLE
327 WINAPI
328 SetClipboardData(UINT uFormat, HANDLE hMem)
329 {
330 DWORD size;
331 LPVOID pMem;
332 HANDLE ret = NULL;
333
334 if (hMem == NULL)
335 {
336 return NtUserSetClipboardData(uFormat, 0, 0);
337 }
338
339 if (uFormat == CF_BITMAP)
340 {
341 /* GlobalLock should return 0 for GDI handles
342 pMem = GlobalLock(hMem);
343 if (pMem)
344 {
345 // not a GDI handle
346 GlobalUnlock(hMem);
347 return ret;
348 }
349 else
350 {
351 */
352 /* check if this GDI handle is a HBITMAP */
353 /* GetObject for HBITMAP not implemented in ReactOS */
354 //if (GetObject(hMem, 0, NULL) == sifeof(BITMAP))
355 //{
356 return NtUserSetClipboardData(CF_BITMAP, hMem, 0);
357 //}
358 /*}*/
359 }
360
361 size = GlobalSize(hMem);
362 pMem = GlobalLock(hMem);
363
364 if ((pMem) && (size))
365 {
366 size = GlobalSize(hMem);
367 ret = NtUserSetClipboardData(uFormat, pMem, size);
368 //should i unlock hMem?
369 GlobalUnlock(hMem);
370 }
371 else
372 {
373 ERR("SetClipboardData failed\n");
374 }
375
376 return ret;
377
378 }
379
380 /*
381 * @implemented
382 */
383 HWND
384 WINAPI
385 SetClipboardViewer(HWND hWndNewViewer)
386 {
387 return NtUserSetClipboardViewer(hWndNewViewer);
388 }
389
390 /*
391 * @implemented
392 */
393 BOOL
394 WINAPI
395 ChangeClipboardChain(HWND hWndRemove,
396 HWND hWndNewNext)
397 {
398 return NtUserChangeClipboardChain(hWndRemove, hWndNewNext);
399 }
400
401 /*
402 * @unimplemented
403 */
404 BOOL
405 WINAPI
406 AddClipboardFormatListener(HWND hwnd)
407 {
408 UNIMPLEMENTED;
409 return FALSE;
410 }
411 /*
412 * @unimplemented
413 */
414 BOOL
415 WINAPI
416 RemoveClipboardFormatListener(HWND hwnd)
417 {
418 UNIMPLEMENTED;
419 return FALSE;
420 }
421
422 /*
423 * @unimplemented
424 */
425 BOOL
426 WINAPI
427 GetUpdatedClipboardFormats(PUINT lpuiFormats,
428 UINT cFormats,
429 PUINT pcFormatsOut)
430 {
431 UNIMPLEMENTED;
432 return FALSE;
433 }