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);
45 ret
= NtUserCloseClipboard();
54 CountClipboardFormats(VOID
)
56 INT ret
= NtUserCountClipboardFormats();
67 return NtUserEmptyClipboard();
75 EnumClipboardFormats(UINT format
)
77 UINT ret
= NtUserCallOneParam(format
, ONEPARAM_ROUTINE_ENUMCLIPBOARDFORMATS
);
86 GetClipboardData(UINT uFormat
)
88 HGLOBAL hGlobal
= NULL
;
92 /* dealing with bitmap object */
93 if (uFormat
!= CF_BITMAP
)
95 size
= (DWORD
)NtUserGetClipboardData(uFormat
, NULL
);
99 hGlobal
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, size
);
100 pGlobal
= GlobalLock(hGlobal
);
102 size
= (DWORD
)NtUserGetClipboardData(uFormat
, pGlobal
);
104 GlobalUnlock(hGlobal
);
109 hGlobal
= NtUserGetClipboardData(CF_BITMAP
, NULL
);
120 GetClipboardFormatNameA(UINT format
,
121 LPSTR lpszFormatName
,
125 UNICODE_STRING FormatName
;
128 lpBuffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, cchMaxCount
* sizeof(WCHAR
));
131 SetLastError(ERROR_OUTOFMEMORY
);
135 FormatName
.Length
= 0;
136 FormatName
.MaximumLength
= cchMaxCount
* sizeof(WCHAR
);
137 FormatName
.Buffer
= lpBuffer
;
139 /* we need a UNICODE string */
140 Length
= NtUserGetClipboardFormatName(format
, &FormatName
, cchMaxCount
);
144 if (!WideCharToMultiByte(CP_ACP
, 0, lpBuffer
, Length
, lpszFormatName
, cchMaxCount
, NULL
, NULL
))
146 /* clear result string */
149 lpszFormatName
[Length
] = '\0';
152 RtlFreeHeap(RtlGetProcessHeap(), 0, lpBuffer
);
161 GetClipboardFormatNameW(UINT format
,
162 LPWSTR lpszFormatName
,
165 UNICODE_STRING FormatName
;
168 FormatName
.Length
= 0;
169 FormatName
.MaximumLength
= cchMaxCount
* sizeof(WCHAR
);
170 FormatName
.Buffer
= (PWSTR
)lpszFormatName
;
171 Ret
= NtUserGetClipboardFormatName(format
, &FormatName
, cchMaxCount
);
181 GetClipboardOwner(VOID
)
183 return NtUserGetClipboardOwner();
191 GetClipboardSequenceNumber(VOID
)
193 return NtUserGetClipboardSequenceNumber();
201 GetClipboardViewer(VOID
)
203 return NtUserGetClipboardViewer();
211 GetOpenClipboardWindow(VOID
)
213 return NtUserGetOpenClipboardWindow();
221 GetPriorityClipboardFormat(UINT
*paFormatPriorityList
, INT cFormats
)
223 INT ret
= NtUserGetPriorityClipboardFormat(paFormatPriorityList
, cFormats
);
232 IsClipboardFormatAvailable(UINT format
)
234 BOOL ret
= NtUserIsClipboardFormatAvailable(format
);
244 RegisterClipboardFormatA(LPCSTR lpszFormat
)
247 UNICODE_STRING usFormat
= {0};
249 if (lpszFormat
== NULL
)
251 SetLastError(ERROR_INVALID_PARAMETER
);
256 if (*lpszFormat
== 0) //NULL
258 SetLastError(ERROR_INVALID_NAME
);
262 ret
= RtlCreateUnicodeStringFromAsciiz(&usFormat
, lpszFormat
);
265 ret
= NtUserRegisterWindowMessage(&usFormat
); //(LPCWSTR)
266 RtlFreeUnicodeString(&usFormat
);
277 RegisterClipboardFormatW(LPCWSTR lpszFormat
)
280 UNICODE_STRING usFormat
= {0};
282 if (lpszFormat
== NULL
)
284 SetLastError(ERROR_INVALID_PARAMETER
);
289 if (*lpszFormat
== 0) //NULL
291 SetLastError(ERROR_INVALID_NAME
);
295 RtlInitUnicodeString(&usFormat
, lpszFormat
);
296 ret
= NtUserRegisterWindowMessage(&usFormat
);
302 renderLocale(DWORD Locale
)
307 hGlobal
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, sizeof(DWORD
));
314 pLocale
= (DWORD
*)GlobalLock(hGlobal
);
318 GlobalUnlock(hGlobal
);
328 SetClipboardData(UINT uFormat
, HANDLE hMem
)
336 return NtUserSetClipboardData(uFormat
, 0, 0);
339 if (uFormat
== CF_BITMAP
)
341 /* GlobalLock should return 0 for GDI handles
342 pMem = GlobalLock(hMem);
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))
356 return NtUserSetClipboardData(CF_BITMAP
, hMem
, 0);
361 size
= GlobalSize(hMem
);
362 pMem
= GlobalLock(hMem
);
364 if ((pMem
) && (size
))
366 size
= GlobalSize(hMem
);
367 ret
= NtUserSetClipboardData(uFormat
, pMem
, size
);
368 //should i unlock hMem?
373 ERR("SetClipboardData failed\n");
385 SetClipboardViewer(HWND hWndNewViewer
)
387 return NtUserSetClipboardViewer(hWndNewViewer
);
395 ChangeClipboardChain(HWND hWndRemove
,
398 return NtUserChangeClipboardChain(hWndRemove
, hWndNewNext
);
406 AddClipboardFormatListener(HWND hwnd
)
416 RemoveClipboardFormatListener(HWND hwnd
)
427 GetUpdatedClipboardFormats(PUINT lpuiFormats
,