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