3 * PROJECT: ReactOS user32.dll
4 * FILE: lib/user32/windows/clipboard.c
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Pablo Borobia <pborobia@gmail.com>
9 * 09-05-2001 CSH Created
13 /* INCLUDES ******************************************************************/
19 #include <wine/debug.h>
20 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
24 /* FUNCTIONS *****************************************************************/
31 OpenClipboard(HWND hWndNewOwner
)
33 BOOL ret
= NtUserOpenClipboard(hWndNewOwner
, 0);
42 EnumClipboardFormats(UINT format
)
44 UINT ret
= NtUserCallOneParam(format
, ONEPARAM_ROUTINE_ENUMCLIPBOARDFORMATS
);
53 GetClipboardData(UINT uFormat
)
55 HGLOBAL hGlobal
= NULL
;
59 /* dealing with bitmap object */
60 if (uFormat
!= CF_BITMAP
)
62 size
= (DWORD_PTR
)NtUserGetClipboardData(uFormat
, NULL
);
66 hGlobal
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, size
);
67 pGlobal
= GlobalLock(hGlobal
);
69 size
= (DWORD_PTR
)NtUserGetClipboardData(uFormat
, pGlobal
);
71 GlobalUnlock(hGlobal
);
76 hGlobal
= NtUserGetClipboardData(CF_BITMAP
, NULL
);
87 GetClipboardFormatNameA(UINT format
,
92 UNICODE_STRING FormatName
;
95 lpBuffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, cchMaxCount
* sizeof(WCHAR
));
98 SetLastError(ERROR_OUTOFMEMORY
);
102 FormatName
.Length
= 0;
103 FormatName
.MaximumLength
= cchMaxCount
* sizeof(WCHAR
);
104 FormatName
.Buffer
= lpBuffer
;
106 /* we need a UNICODE string */
107 Length
= NtUserGetClipboardFormatName(format
, &FormatName
, cchMaxCount
);
111 if (!WideCharToMultiByte(CP_ACP
, 0, lpBuffer
, Length
, lpszFormatName
, cchMaxCount
, NULL
, NULL
))
113 /* clear result string */
116 lpszFormatName
[Length
] = '\0';
119 RtlFreeHeap(RtlGetProcessHeap(), 0, lpBuffer
);
128 GetClipboardFormatNameW(UINT format
,
129 LPWSTR lpszFormatName
,
132 UNICODE_STRING FormatName
;
135 FormatName
.Length
= 0;
136 FormatName
.MaximumLength
= cchMaxCount
* sizeof(WCHAR
);
137 FormatName
.Buffer
= (PWSTR
)lpszFormatName
;
138 Ret
= NtUserGetClipboardFormatName(format
, &FormatName
, cchMaxCount
);
149 RegisterClipboardFormatA(LPCSTR lpszFormat
)
152 UNICODE_STRING usFormat
= {0};
154 if (lpszFormat
== NULL
)
156 SetLastError(ERROR_INVALID_PARAMETER
);
161 if (*lpszFormat
== 0) //NULL
163 SetLastError(ERROR_INVALID_NAME
);
167 ret
= RtlCreateUnicodeStringFromAsciiz(&usFormat
, lpszFormat
);
170 ret
= NtUserRegisterWindowMessage(&usFormat
); //(LPCWSTR)
171 RtlFreeUnicodeString(&usFormat
);
182 RegisterClipboardFormatW(LPCWSTR lpszFormat
)
185 UNICODE_STRING usFormat
= {0};
187 if (lpszFormat
== NULL
)
189 SetLastError(ERROR_INVALID_PARAMETER
);
194 if (*lpszFormat
== 0) //NULL
196 SetLastError(ERROR_INVALID_NAME
);
200 RtlInitUnicodeString(&usFormat
, lpszFormat
);
201 ret
= NtUserRegisterWindowMessage(&usFormat
);
207 renderLocale(DWORD Locale
)
212 hGlobal
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, sizeof(DWORD
));
219 pLocale
= (DWORD
*)GlobalLock(hGlobal
);
223 GlobalUnlock(hGlobal
);
233 SetClipboardData(UINT uFormat
, HANDLE hMem
)
241 return NtUserSetClipboardData(uFormat
, 0, 0);
244 if (uFormat
== CF_BITMAP
)
246 /* GlobalLock should return 0 for GDI handles
247 pMem = GlobalLock(hMem);
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))
261 return NtUserSetClipboardData(CF_BITMAP
, hMem
, 0);
266 size
= GlobalSize(hMem
);
267 pMem
= GlobalLock(hMem
);
269 if ((pMem
) && (size
))
271 size
= GlobalSize(hMem
);
272 ret
= NtUserSetClipboardData(uFormat
, pMem
, size
);
274 //On success NtUserSetClipboardData returns pMem
275 //however caller expects us to return hMem
279 //should i unlock hMem?
284 ERR("SetClipboardData failed\n");
296 AddClipboardFormatListener(HWND hwnd
)
306 RemoveClipboardFormatListener(HWND hwnd
)
317 GetUpdatedClipboardFormats(PUINT lpuiFormats
,