ReactOS  0.4.13-dev-257-gfabbd7c
clipboard.c File Reference
#include <user32.h>
Include dependency graph for clipboard.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (user32)
 
BOOL WINAPI OpenClipboard (HWND hWndNewOwner)
 
UINT WINAPI EnumClipboardFormats (UINT format)
 
INT WINAPI GetClipboardFormatNameA (UINT format, LPSTR lpszFormatName, int cchMaxCount)
 
INT WINAPI GetClipboardFormatNameW (UINT uFormat, LPWSTR lpszFormatName, INT cchMaxCount)
 
UINT WINAPI RegisterClipboardFormatA (LPCSTR lpszFormat)
 
UINT WINAPI RegisterClipboardFormatW (LPCWSTR lpszFormat)
 
static PVOID WINAPI IntSynthesizeMultiByte (PVOID pwStr, DWORD cbStr, BOOL bOem)
 
static PVOID WINAPI IntSynthesizeWideChar (PVOID pwStr, DWORD cbStr, BOOL bOem)
 
HANDLE WINAPI GetClipboardData (UINT uFormat)
 
HANDLE WINAPI SetClipboardData (UINT uFormat, HANDLE hMem)
 
BOOL WINAPI AddClipboardFormatListener (HWND hwnd)
 
BOOL WINAPI RemoveClipboardFormatListener (HWND hwnd)
 
BOOL WINAPI GetUpdatedClipboardFormats (PUINT lpuiFormats, UINT cFormats, PUINT pcFormatsOut)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file clipboard.c.

Function Documentation

◆ AddClipboardFormatListener()

BOOL WINAPI AddClipboardFormatListener ( HWND  hwnd)

Definition at line 362 of file clipboard.c.

363 {
365  return FALSE;
366 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ EnumClipboardFormats()

UINT WINAPI EnumClipboardFormats ( UINT  format)

Definition at line 33 of file clipboard.c.

34 {
37 }
#define NO_ERROR
Definition: dderror.h:5
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define SetLastError(x)
Definition: compat.h:409
EXTINLINE UINT NtUserxEnumClipboardFormats(UINT format)
Definition: ntwrapper.h:611

Referenced by get_priv_data(), test_cf_dataobject(), test_RegisterClipboardFormatA(), and test_synthesized().

◆ GetClipboardData()

HANDLE WINAPI GetClipboardData ( UINT  uFormat)

Definition at line 194 of file clipboard.c.

195 {
196  HANDLE hData = NULL;
197  PVOID pData = NULL;
198  DWORD cbData = 0;
200 
201  hData = NtUserGetClipboardData(uFormat, &gcd);
202  if (!hData)
203  return NULL;
204 
205  if (gcd.fGlobalHandle)
206  {
207  HANDLE hGlobal;
208 
209  NtUserCreateLocalMemHandle(hData, NULL, 0, &cbData);
210  hGlobal = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, cbData);
211  pData = GlobalLock(hGlobal);
212  NtUserCreateLocalMemHandle(hData, pData, cbData, NULL);
213  hData = hGlobal;
214  }
215 
216  if (gcd.uFmtRet != uFormat)
217  {
218  SETCLIPBDATA scd = {FALSE, FALSE};
219  HANDLE hNewData = NULL;
220  PVOID pNewData = NULL;
221 
222  /* Synthesize requested format */
223  switch (uFormat)
224  {
225  case CF_TEXT:
226  if (gcd.uFmtRet == CF_UNICODETEXT)
227  pNewData = IntSynthesizeMultiByte(pData, cbData, uFormat == CF_OEMTEXT);
228  else // CF_OEMTEXT
229  OemToCharBuffA(pData, pData, cbData);
230  break;
231  case CF_OEMTEXT:
232  if (gcd.uFmtRet == CF_UNICODETEXT)
233  pNewData = IntSynthesizeMultiByte(pData, cbData, uFormat == CF_OEMTEXT);
234  else
235  CharToOemBuffA(pData, pData, cbData);
236  break;
237  case CF_UNICODETEXT:
238  pNewData = IntSynthesizeWideChar(pData, cbData, gcd.uFmtRet == CF_OEMTEXT);
239  break;
240  default:
241  FIXME("Format: %u != %u\n", uFormat, gcd.uFmtRet);
242  }
243 
244  /* Is it a global handle? */
245  if (pNewData)
246  hNewData = GlobalHandle(pNewData);
247 
248  if (hNewData)
249  {
250  /* Free old data */
251  if (pData)
252  {
253  GlobalUnlock(hData);
254  GlobalFree(hData);
255  }
256  hData = hNewData;
257  pData = pNewData;
258  }
259 
260  /* Save synthesized format in clipboard */
261  if (pData)
262  {
263  HANDLE hMem;
264 
265  scd.fGlobalHandle = TRUE;
266  hMem = NtUserConvertMemHandle(pData, GlobalSize(hData));
267  NtUserSetClipboardData(uFormat, hMem, &scd);
268  }
269  else if (hData)
270  NtUserSetClipboardData(uFormat, hData, &scd);
271  }
272 
273  /* Unlock global handle */
274  if (pData)
275  GlobalUnlock(hData);
276 
277  return hData;
278 }
#define TRUE
Definition: types.h:120
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
HGLOBAL NTAPI GlobalHandle(LPCVOID pMem)
Definition: heapmem.c:705
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
BOOL WINAPI CharToOemBuffA(_In_ LPCSTR lpszSrc, _Out_writes_(cchDstLength) LPSTR lpszDst, _In_ DWORD cchDstLength)
HANDLE APIENTRY NtUserGetClipboardData(UINT fmt, PGETCLIPBDATA pgcd)
Definition: clipboard.c:879
#define FIXME(fmt,...)
Definition: debug.h:110
BOOL fGlobalHandle
Definition: ntuser.h:1117
#define CF_UNICODETEXT
Definition: constants.h:408
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS APIENTRY NtUserCreateLocalMemHandle(HANDLE hMem, PVOID pData, DWORD cbData, DWORD *pcbData)
Definition: clipboard.c:1204
#define CF_TEXT
Definition: constants.h:396
static PVOID WINAPI IntSynthesizeMultiByte(PVOID pwStr, DWORD cbStr, BOOL bOem)
Definition: clipboard.c:150
static PVOID WINAPI IntSynthesizeWideChar(PVOID pwStr, DWORD cbStr, BOOL bOem)
Definition: clipboard.c:171
HANDLE APIENTRY NtUserSetClipboardData(UINT fmt, HANDLE hData, PSETCLIPBDATA pUnsafeScd)
Definition: clipboard.c:1056
HANDLE APIENTRY NtUserConvertMemHandle(PVOID pData, DWORD cbData)
Definition: clipboard.c:1159
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define CF_OEMTEXT
Definition: constants.h:402
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
#define GMEM_DDESHARE
Definition: winbase.h:295
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
BOOL WINAPI OemToCharBuffA(_In_ LPCSTR lpszSrc, _Out_writes_(cchDstLength) LPSTR lpszDst, _In_ DWORD cchDstLength)
#define GMEM_MOVEABLE
Definition: winbase.h:291
static int gcd(int, int)
Definition: getopt.c:86

Referenced by clipboard_thread(), get_clipboard_data_process(), get_current_dataobject(), get_current_ole_clip_window(), get_priv_data(), set_clipboard_data_thread(), snapshot_GetData(), snapshot_GetDataHere(), test_cf_dataobject(), test_ClipboardOwner(), test_data_handles(), test_handles(), test_handles_process(), test_handles_process_dib(), test_handles_thread2(), test_no_cf_dataobject(), test_set_clipboard(), test_string_data_process(), and test_synthesized().

◆ GetClipboardFormatNameA()

INT WINAPI GetClipboardFormatNameA ( UINT  format,
LPSTR  lpszFormatName,
int  cchMaxCount 
)

Definition at line 44 of file clipboard.c.

47 {
49  INT Length;
50 
51  lpBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, cchMaxCount * sizeof(WCHAR));
52  if (!lpBuffer)
53  {
55  return 0;
56  }
57 
58  /* we need a UNICODE string */
60 
61  if (Length != 0)
62  {
63  if (!WideCharToMultiByte(CP_ACP, 0, lpBuffer, Length, lpszFormatName, cchMaxCount, NULL, NULL))
64  {
65  /* clear result string */
66  Length = 0;
67  }
68  lpszFormatName[Length] = '\0';
69  }
70 
71  RtlFreeHeap(RtlGetProcessHeap(), 0, lpBuffer);
72  return Length;
73 }
INT APIENTRY NtUserGetClipboardFormatName(UINT fmt, LPWSTR lpszFormatName, INT cchMaxCount)
Definition: clipboard.c:718
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
int32_t INT
Definition: typedefs.h:56
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SetLastError(x)
Definition: compat.h:409
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by test_RegisterClipboardFormatA().

◆ GetClipboardFormatNameW()

INT WINAPI GetClipboardFormatNameW ( UINT  uFormat,
LPWSTR  lpszFormatName,
INT  cchMaxCount 
)

Definition at line 80 of file clipboard.c.

83 {
84  return NtUserGetClipboardFormatName(uFormat, lpszFormatName, cchMaxCount);
85 }
INT APIENTRY NtUserGetClipboardFormatName(UINT fmt, LPWSTR lpszFormatName, INT cchMaxCount)
Definition: clipboard.c:718

Referenced by get_priv_data().

◆ GetUpdatedClipboardFormats()

BOOL WINAPI GetUpdatedClipboardFormats ( PUINT  lpuiFormats,
UINT  cFormats,
PUINT  pcFormatsOut 
)

Definition at line 383 of file clipboard.c.

386 {
388  return FALSE;
389 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ IntSynthesizeMultiByte()

static PVOID WINAPI IntSynthesizeMultiByte ( PVOID  pwStr,
DWORD  cbStr,
BOOL  bOem 
)
static

Definition at line 150 of file clipboard.c.

151 {
152  HANDLE hGlobal;
153  PVOID pGlobal;
154  INT cbGlobal;
155 
156  cbGlobal = WideCharToMultiByte(bOem ? CP_OEMCP : CP_ACP,
157  0, pwStr, cbStr / sizeof(WCHAR),
158  NULL, 0, NULL, NULL);
159  hGlobal = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, cbGlobal);
160  if (!hGlobal)
161  return NULL;
162 
163  pGlobal = GlobalLock(hGlobal);
165  0, pwStr, cbStr / sizeof(WCHAR),
166  pGlobal, cbGlobal, NULL, NULL);
167  return pGlobal;
168 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define GMEM_DDESHARE
Definition: winbase.h:295
#define CP_OEMCP
Definition: winnls.h:228
#define GMEM_MOVEABLE
Definition: winbase.h:291

Referenced by GetClipboardData().

◆ IntSynthesizeWideChar()

static PVOID WINAPI IntSynthesizeWideChar ( PVOID  pwStr,
DWORD  cbStr,
BOOL  bOem 
)
static

Definition at line 171 of file clipboard.c.

172 {
173  HANDLE hGlobal;
174  PVOID pGlobal;
175  INT cbGlobal;
176 
177  cbGlobal = MultiByteToWideChar(bOem ? CP_OEMCP : CP_ACP,
178  0, pwStr, cbStr, NULL, 0) * sizeof(WCHAR);
179  hGlobal = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, cbGlobal);
180  if (!hGlobal)
181  return NULL;
182 
183  pGlobal = GlobalLock(hGlobal);
185  0, pwStr, cbStr, pGlobal, cbGlobal);
186  return pGlobal;
187 }
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define CP_ACP
Definition: compat.h:99
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define MultiByteToWideChar
Definition: compat.h:100
#define GMEM_DDESHARE
Definition: winbase.h:295
#define CP_OEMCP
Definition: winnls.h:228
#define GMEM_MOVEABLE
Definition: winbase.h:291

Referenced by GetClipboardData().

◆ OpenClipboard()

◆ RegisterClipboardFormatA()

UINT WINAPI RegisterClipboardFormatA ( LPCSTR  lpszFormat)

Definition at line 92 of file clipboard.c.

93 {
94  UINT ret = 0;
95  UNICODE_STRING usFormat = {0};
96 
97  if (lpszFormat == NULL)
98  {
100  return 0;
101  }
102 
103  /* check for "" */
104  if (*lpszFormat == 0) //NULL
105  {
107  return 0;
108  }
109 
110  ret = RtlCreateUnicodeStringFromAsciiz(&usFormat, lpszFormat);
111  if (ret)
112  {
113  ret = NtUserRegisterWindowMessage(&usFormat); //(LPCWSTR)
114  RtlFreeUnicodeString(&usFormat);
115  }
116 
117  return ret;
118 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define SetLastError(x)
Definition: compat.h:409
int ret
UINT NTAPI NtUserRegisterWindowMessage(PUNICODE_STRING MessageName)
Definition: window.c:4069
unsigned int UINT
Definition: ndis.h:50
#define ERROR_INVALID_NAME
Definition: compat.h:93

Referenced by ME_GetDataObject(), test_cf_dataobject(), test_data_handles(), test_handles(), test_handles_process(), test_no_cf_dataobject(), test_RegisterClipboardFormatA(), and test_set_clipboard().

◆ RegisterClipboardFormatW()

UINT WINAPI RegisterClipboardFormatW ( LPCWSTR  lpszFormat)

Definition at line 125 of file clipboard.c.

126 {
127  UINT ret = 0;
128  UNICODE_STRING usFormat = {0};
129 
130  if (lpszFormat == NULL)
131  {
133  return 0;
134  }
135 
136  /* check for "" */
137  if (*lpszFormat == 0) //NULL
138  {
140  return 0;
141  }
142 
143  RtlInitUnicodeString(&usFormat, lpszFormat);
144  ret = NtUserRegisterWindowMessage(&usFormat);
145 
146  return ret;
147 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:409
int ret
UINT NTAPI NtUserRegisterWindowMessage(PUNICODE_STRING MessageName)
Definition: window.c:4069
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_INVALID_NAME
Definition: compat.h:93

Referenced by register_clipboard_formats().

◆ RemoveClipboardFormatListener()

BOOL WINAPI RemoveClipboardFormatListener ( HWND  hwnd)

Definition at line 372 of file clipboard.c.

373 {
375  return FALSE;
376 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ SetClipboardData()

HANDLE WINAPI SetClipboardData ( UINT  uFormat,
HANDLE  hMem 
)

Definition at line 285 of file clipboard.c.

286 {
287  DWORD dwSize;
288  HANDLE hGlobal;
289  LPVOID pMem;
290  HANDLE hRet = NULL;
291  SETCLIPBDATA scd = {FALSE, FALSE};
292 
293  /* Check if this is a delayed rendering */
294  if (hMem == NULL)
295  return NtUserSetClipboardData(uFormat, NULL, &scd);
296 
297  if (hMem <= (HANDLE)4)
299  /* Bitmaps and palette does not use global handles */
300  else if (uFormat == CF_BITMAP || uFormat == CF_DSPBITMAP || uFormat == CF_PALETTE)
301  hRet = NtUserSetClipboardData(uFormat, hMem, &scd);
302  /* Meta files are probably checked for validity */
303  else if (uFormat == CF_DSPMETAFILEPICT || uFormat == CF_METAFILEPICT ||
304  uFormat == CF_DSPENHMETAFILE || uFormat == CF_ENHMETAFILE)
305  {
307  hRet = NULL; // not supported yet
308  }
309  else
310  {
311  /* Some formats accept only global handles, other accept global handles or integer values */
312  pMem = GlobalLock(hMem);
313  dwSize = GlobalSize(hMem);
314 
315  if (pMem || uFormat == CF_DIB || uFormat == CF_DIBV5 ||
316  uFormat == CF_DSPTEXT || uFormat == CF_LOCALE ||
317  uFormat == CF_OEMTEXT || uFormat == CF_TEXT ||
318  uFormat == CF_UNICODETEXT)
319  {
320  if (pMem)
321  {
322  /* This is a local memory. Make global memory object */
323  hGlobal = NtUserConvertMemHandle(pMem, dwSize);
324 
325  /* Unlock memory */
326  GlobalUnlock(hMem);
327  /* FIXME: free hMem when CloseClipboard is called */
328 
329  if (hGlobal)
330  {
331  /* Save data */
332  scd.fGlobalHandle = TRUE;
333  hRet = NtUserSetClipboardData(uFormat, hGlobal, &scd);
334  }
335 
336  /* On success NtUserSetClipboardData returns pMem
337  however caller expects us to return hMem */
338  if (hRet == hGlobal)
339  hRet = hMem;
340  }
341  else
343  }
344  else
345  {
346  /* Save a number */
347  hRet = NtUserSetClipboardData(uFormat, hMem, &scd);
348  }
349  }
350 
351  if (!hRet)
352  ERR("SetClipboardData(%u, %p) failed\n", uFormat, hMem);
353 
354  return hRet;
355 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
#define CF_ENHMETAFILE
Definition: constants.h:409
#define CF_DSPMETAFILEPICT
Definition: constants.h:416
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
#define CF_METAFILEPICT
Definition: constants.h:398
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
#define CF_DSPENHMETAFILE
Definition: constants.h:417
BOOL fGlobalHandle
Definition: ntuser.h:1117
#define CF_UNICODETEXT
Definition: constants.h:408
#define CF_BITMAP
Definition: constants.h:397
smooth NULL
Definition: ftsmooth.c:416
#define CF_TEXT
Definition: constants.h:396
HANDLE APIENTRY NtUserSetClipboardData(UINT fmt, HANDLE hData, PSETCLIPBDATA pUnsafeScd)
Definition: clipboard.c:1056
HANDLE APIENTRY NtUserConvertMemHandle(PVOID pData, DWORD cbData)
Definition: clipboard.c:1159
#define CF_DSPBITMAP
Definition: constants.h:415
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define CF_PALETTE
Definition: constants.h:404
#define CF_LOCALE
Definition: constants.h:411
#define ERR(fmt,...)
Definition: debug.h:109
#define CF_OEMTEXT
Definition: constants.h:402
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
#define UNIMPLEMENTED
Definition: debug.h:114
#define CF_DSPTEXT
Definition: constants.h:414
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define CF_DIB
Definition: constants.h:403

Referenced by clipboard_render_data_thread(), clipboard_thread(), clipboard_wnd_proc(), expose_marshalled_dataobject(), grab_clipboard_process(), render_embed_source_hack(), render_format(), set_clipboard_data_process(), set_clipboard_data_thread(), set_clipboard_formats(), set_clipboard_thread(), set_dataobject_format(), test_ClipboardOwner(), test_data_handles(), test_GetUpdatedClipboardFormats(), test_handles(), test_handles_process_open(), test_nonole_clipboard(), test_RegisterClipboardFormatA(), test_set_clipboard(), test_string_data(), and test_synthesized().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( user32  )