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 *****************************************************************/
30 OpenClipboard(HWND hWndNewOwner
)
32 BOOL ret
= NtUserOpenClipboard(hWndNewOwner
, 0);
43 ret
= NtUserCloseClipboard();
51 CountClipboardFormats(VOID
)
53 INT ret
= NtUserCountClipboardFormats();
63 return NtUserEmptyClipboard();
70 EnumClipboardFormats(UINT format
)
72 UINT ret
= NtUserCallOneParam(format
, ONEPARAM_ROUTINE_ENUMCLIPBOARDFORMATS
);
80 GetClipboardData(UINT uFormat
)
82 HGLOBAL hGlobal
= NULL
;
86 /* dealing with bitmap object */
87 if (uFormat
!= CF_BITMAP
)
89 size
= (DWORD
)NtUserGetClipboardData(uFormat
, NULL
);
93 hGlobal
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, size
);
94 pGlobal
= GlobalLock(hGlobal
);
96 size
= (DWORD
)NtUserGetClipboardData(uFormat
, pGlobal
);
98 GlobalUnlock(hGlobal
);
103 hGlobal
= NtUserGetClipboardData(CF_BITMAP
, NULL
);
113 GetClipboardFormatNameA(UINT format
, LPSTR lpszFormatName
, int cchMaxCount
)
116 UNICODE_STRING FormatName
;
119 lpBuffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, cchMaxCount
* sizeof(WCHAR
));
122 SetLastError(ERROR_OUTOFMEMORY
);
126 FormatName
.Length
= 0;
127 FormatName
.MaximumLength
= cchMaxCount
* sizeof(WCHAR
);
128 FormatName
.Buffer
= lpBuffer
;
130 /* we need a UNICODE string */
131 Length
= NtUserGetClipboardFormatName(format
, &FormatName
, cchMaxCount
);
135 if (!WideCharToMultiByte(CP_ACP
, 0, lpBuffer
, Length
, lpszFormatName
, cchMaxCount
, NULL
, NULL
))
137 /* clear result string */
140 lpszFormatName
[Length
] = '\0';
143 RtlFreeHeap(RtlGetProcessHeap(), 0, lpBuffer
);
151 GetClipboardFormatNameW(UINT format
, LPWSTR lpszFormatName
, INT cchMaxCount
)
153 UNICODE_STRING FormatName
;
156 FormatName
.Length
= 0;
157 FormatName
.MaximumLength
= cchMaxCount
* sizeof(WCHAR
);
158 FormatName
.Buffer
= (PWSTR
)lpszFormatName
;
159 Ret
= NtUserGetClipboardFormatName(format
, &FormatName
, cchMaxCount
);
168 GetClipboardOwner(VOID
)
170 return NtUserGetClipboardOwner();
177 GetClipboardSequenceNumber(VOID
)
179 return NtUserGetClipboardSequenceNumber();
186 GetClipboardViewer(VOID
)
188 return NtUserGetClipboardViewer();
195 GetOpenClipboardWindow(VOID
)
197 return NtUserGetOpenClipboardWindow();
204 GetPriorityClipboardFormat(UINT
*paFormatPriorityList
, INT cFormats
)
206 INT ret
= NtUserGetPriorityClipboardFormat(paFormatPriorityList
, cFormats
);
214 IsClipboardFormatAvailable(UINT format
)
216 BOOL ret
= NtUserIsClipboardFormatAvailable(format
);
225 RegisterClipboardFormatA(LPCSTR lpszFormat
)
228 UNICODE_STRING usFormat
= {0};
230 if (lpszFormat
== NULL
)
232 SetLastError(ERROR_INVALID_PARAMETER
);
237 if (*lpszFormat
== 0) //NULL
239 SetLastError(ERROR_INVALID_NAME
);
243 ret
= RtlCreateUnicodeStringFromAsciiz(&usFormat
, lpszFormat
);
246 ret
= NtUserRegisterWindowMessage(&usFormat
); //(LPCWSTR)
247 RtlFreeUnicodeString(&usFormat
);
257 RegisterClipboardFormatW(LPCWSTR lpszFormat
)
260 UNICODE_STRING usFormat
= {0};
262 if (lpszFormat
== NULL
)
264 SetLastError(ERROR_INVALID_PARAMETER
);
269 if (*lpszFormat
== 0) //NULL
271 SetLastError(ERROR_INVALID_NAME
);
275 RtlInitUnicodeString(&usFormat
, lpszFormat
);
276 ret
= NtUserRegisterWindowMessage(&usFormat
);
281 HGLOBAL
renderLocale (DWORD Locale
)
286 hGlobal
= GlobalAlloc(GMEM_DDESHARE
| GMEM_MOVEABLE
, sizeof(DWORD
));
293 pLocale
= (DWORD
*)GlobalLock(hGlobal
);
297 GlobalUnlock(hGlobal
);
306 SetClipboardData(UINT uFormat
, HANDLE hMem
)
314 return NtUserSetClipboardData(uFormat
, 0, 0);
317 if (uFormat
== CF_BITMAP
)
319 /* GlobalLock should return 0 for GDI handles
320 pMem = GlobalLock(hMem);
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))
334 return NtUserSetClipboardData(CF_BITMAP
, hMem
, 0);
339 size
= GlobalSize(hMem
);
340 pMem
= GlobalLock(hMem
);
342 if ((pMem
) && (size
))
344 size
= GlobalSize(hMem
);
345 ret
= NtUserSetClipboardData(uFormat
, pMem
, size
);
346 //should i unlock hMem?
351 ERR("SetClipboardData failed\n");
362 SetClipboardViewer(HWND hWndNewViewer
)
364 return NtUserSetClipboardViewer(hWndNewViewer
);
371 ChangeClipboardChain(HWND hWndRemove
, HWND hWndNewNext
)
373 return NtUserChangeClipboardChain(hWndRemove
, hWndNewNext
);
380 AddClipboardFormatListener(HWND hwnd
)
389 RemoveClipboardFormatListener(HWND hwnd
)
399 GetUpdatedClipboardFormats(