Misc addendum to CORE-14271 (#1529)
[reactos.git] / win32ss / user / user32 / windows / clipboard.c
index 6e02427..d7cfb79 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * PROJECT:         ReactOS user32.dll
- * FILE:            lib/user32/windows/clipboard.c
+ * FILE:            win32ss/user/user32/windows/clipboard.c
  * PURPOSE:         Input
  * PROGRAMMER:      Casper S. Hornstrup (chorns@users.sourceforge.net)
  *                  Pablo Borobia <pborobia@gmail.com>
@@ -9,18 +9,17 @@
  *
  */
 
-/* INCLUDES ******************************************************************/
-
 #include <user32.h>
 
 #define NDEBUG
 
-#include <wine/debug.h>
 WINE_DEFAULT_DEBUG_CHANNEL(user32);
 
-#define QUERY_SIZE 0
+HANDLE WINAPI GdiConvertMetaFilePict(HANDLE);
+HANDLE WINAPI GdiConvertEnhMetaFile(HANDLE);
+HANDLE WINAPI GdiCreateLocalEnhMetaFile(HANDLE);
+HANDLE WINAPI GdiCreateLocalMetaFilePict(HANDLE);
 
-/* FUNCTIONS *****************************************************************/
 
 /*
  * @implemented
@@ -39,6 +38,7 @@ UINT
 WINAPI
 EnumClipboardFormats(UINT format)
 {
+    SetLastError(NO_ERROR);
     return NtUserxEnumClipboardFormats(format);
 }
 
@@ -71,7 +71,7 @@ GetClipboardFormatNameA(UINT format,
             /* clear result string */
             Length = 0;
         }
-        lpszFormatName[Length] = '\0';
+        lpszFormatName[Length] = ANSI_NULL;
     }
 
     RtlFreeHeap(RtlGetProcessHeap(), 0, lpBuffer);
@@ -97,7 +97,7 @@ UINT
 WINAPI
 RegisterClipboardFormatA(LPCSTR lpszFormat)
 {
-    UINT ret = 0;
+    UINT ret;
     UNICODE_STRING usFormat = {0};
 
     if (lpszFormat == NULL)
@@ -106,20 +106,22 @@ RegisterClipboardFormatA(LPCSTR lpszFormat)
         return 0;
     }
 
-    /* check for "" */
-    if (*lpszFormat == 0) //NULL
+    if (*lpszFormat == ANSI_NULL)
     {
         SetLastError(ERROR_INVALID_NAME);
         return 0;
     }
 
-    ret = RtlCreateUnicodeStringFromAsciiz(&usFormat, lpszFormat);
-    if (ret)
+    if (!RtlCreateUnicodeStringFromAsciiz(&usFormat, lpszFormat))
     {
-        ret = NtUserRegisterWindowMessage(&usFormat); //(LPCWSTR)
-        RtlFreeUnicodeString(&usFormat);
+        // FIXME: Shouldn't we 'SetLastError(ERROR_NOT_ENOUGH_MEMORY);'?
+        return 0;
     }
 
+    ret = NtUserRegisterWindowMessage(&usFormat); //(LPCWSTR)
+
+    RtlFreeUnicodeString(&usFormat);
+
     return ret;
 }
 
@@ -130,7 +132,6 @@ UINT
 WINAPI
 RegisterClipboardFormatW(LPCWSTR lpszFormat)
 {
-    UINT ret = 0;
     UNICODE_STRING usFormat = {0};
 
     if (lpszFormat == NULL)
@@ -139,17 +140,14 @@ RegisterClipboardFormatW(LPCWSTR lpszFormat)
         return 0;
     }
 
-    /* check for "" */
-    if (*lpszFormat == 0) //NULL
+    if (*lpszFormat == UNICODE_NULL)
     {
         SetLastError(ERROR_INVALID_NAME);
         return 0;
     }
 
     RtlInitUnicodeString(&usFormat, lpszFormat);
-    ret = NtUserRegisterWindowMessage(&usFormat);
-
-    return ret;
+    return NtUserRegisterWindowMessage(&usFormat);
 }
 
 static PVOID WINAPI
@@ -208,6 +206,16 @@ GetClipboardData(UINT uFormat)
     if (!hData)
         return NULL;
 
+    switch (uFormat)
+    {
+        case CF_DSPMETAFILEPICT:
+        case CF_METAFILEPICT:
+            return GdiCreateLocalMetaFilePict(hData);
+        case CF_DSPENHMETAFILE:
+        case CF_ENHMETAFILE:
+            return GdiCreateLocalEnhMetaFile(hData);
+    }
+
     if (gcd.fGlobalHandle)
     {
         HANDLE hGlobal;
@@ -263,7 +271,7 @@ GetClipboardData(UINT uFormat)
             pData = pNewData;
         }
 
-        /* Save synthesized format in clibboard */
+        /* Save synthesized format in clipboard */
         if (pData)
         {
             HANDLE hMem;
@@ -293,10 +301,10 @@ SetClipboardData(UINT uFormat, HANDLE hMem)
     DWORD dwSize;
     HANDLE hGlobal;
     LPVOID pMem;
-    HANDLE hRet = NULL;
+    HANDLE hRet = NULL, hTemp;
     SETCLIPBDATA scd = {FALSE, FALSE};
 
-    /* Check if this is delayed render */
+    /* Check if this is a delayed rendering */
     if (hMem == NULL)
         return NtUserSetClipboardData(uFormat, NULL, &scd);
 
@@ -306,9 +314,18 @@ SetClipboardData(UINT uFormat, HANDLE hMem)
     else if (uFormat == CF_BITMAP || uFormat == CF_DSPBITMAP || uFormat == CF_PALETTE)
         hRet = NtUserSetClipboardData(uFormat, hMem, &scd);
     /* Meta files are probably checked for validity */
-    else if (uFormat == CF_DSPMETAFILEPICT || uFormat == CF_METAFILEPICT ||
-             uFormat == CF_DSPENHMETAFILE || uFormat == CF_ENHMETAFILE)
-        hRet = NULL; // not supported yet
+    else if (uFormat == CF_DSPMETAFILEPICT || uFormat == CF_METAFILEPICT )
+    {
+        hTemp = GdiConvertMetaFilePict( hMem );
+        hRet = NtUserSetClipboardData(uFormat, hTemp, &scd); // Note : LOL, it returns a BOOL not a HANDLE!!!!
+        if (hRet == hTemp) hRet = hMem;                      // If successful "TRUE", return the original handle.
+    }
+    else if (uFormat == CF_DSPENHMETAFILE || uFormat == CF_ENHMETAFILE)
+    {
+        hTemp = GdiConvertEnhMetaFile( hMem );
+        hRet = NtUserSetClipboardData(uFormat, hTemp, &scd);
+        if (hRet == hTemp) hRet = hMem;
+    }
     else
     {
         /* Some formats accept only global handles, other accept global handles or integer values */